import{at as x,ao as Z,U as O,G as ee,j as _,H as me,f as Ee,K as ye,k as j,u as g,r as we,C as te,av as he,__tla as Le}from"./entry.7ac74952.js";import{i as Te}from"./isNil.c75b1b34.js";let ne,D,be=Promise.all([(()=>{try{return Le}catch{}})()]).then(async()=>{let f=[],R,H,m,E,U,K,q,P,S,y,v,w;R=e=>{const n=e;n.key===ee.esc&&f.forEach(o=>o(n))},H=e=>{x(()=>{f.length===0&&document.addEventListener("keydown",R),Z&&f.push(e)}),O(()=>{f=f.filter(n=>n!==e),f.length===0&&Z&&document.removeEventListener("keydown",R)})},m="focus-trap.focus-after-trapped",E="focus-trap.focus-after-released",U="focus-trap.focusout-prevented",K={cancelable:!0,bubbles:!1},q={cancelable:!0,bubbles:!1},P="focusAfterTrapped",S="focusAfterReleased",D=Symbol("elFocusTrap"),y=_(),v=_(0),w=_(0);let h=0;const B=e=>{const n=[],o=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:s=>{const p=s.tagName==="INPUT"&&s.type==="hidden";return s.disabled||s.hidden||p?NodeFilter.FILTER_SKIP:s.tabIndex>=0||s===document.activeElement?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;o.nextNode();)n.push(o.currentNode);return n},M=(e,n)=>{for(const o of e)if(!oe(o,n))return o},oe=(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},se=e=>{const n=B(e),o=M(n,e),s=M(n.reverse(),e);return[o,s]},ae=e=>e instanceof HTMLInputElement&&"select"in e,c=(e,n)=>{if(e&&e.focus){const o=document.activeElement;e.focus({preventScroll:!0}),w.value=window.performance.now(),e!==o&&ae(e)&&n&&e.select()}};function W(e,n){const o=[...e],s=e.indexOf(n);return s!==-1&&o.splice(s,1),o}const re=()=>{let e=[];return{push:n=>{const o=e[0];o&&n!==o&&o.pause(),e=W(e,n),e.unshift(n)},remove:n=>{var o,s;e=W(e,n),(s=(o=e[0])==null?void 0:o.resume)==null||s.call(o)}}},ue=(e,n=!1)=>{const o=document.activeElement;for(const s of e)if(c(s,n),document.activeElement!==o)return},G=re(),ce=()=>v.value>w.value,L=()=>{y.value="pointer",v.value=window.performance.now()},$=()=>{y.value="keyboard",v.value=window.performance.now()},de=()=>(x(()=>{h===0&&(document.addEventListener("mousedown",L),document.addEventListener("touchstart",L),document.addEventListener("keydown",$)),h++}),O(()=>{h--,h<=0&&(document.removeEventListener("mousedown",L),document.removeEventListener("touchstart",L),document.removeEventListener("keydown",$))}),{focusReason:y,lastUserFocusTimestamp:v,lastAutomatedFocusTimestamp:w}),T=e=>new CustomEvent(U,{...q,detail:e}),ie=Ee({name:"ElFocusTrap",inheritAttrs:!1,props:{loop:Boolean,trapped:Boolean,focusTrapEl:Object,focusStartEl:{type:[Object,String],default:"first"}},emits:[P,S,"focusin","focusout","focusout-prevented","release-requested"],setup(e,{emit:n}){const o=_();let s,p;const{focusReason:i}=de();H(t=>{e.trapped&&!l.paused&&n("release-requested",t)});const l={paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}},b=t=>{if(!e.loop&&!e.trapped||l.paused)return;const{key:a,altKey:u,ctrlKey:r,metaKey:k,currentTarget:pe,shiftKey:X}=t,{loop:Y}=e,ve=a===ee.tab&&!u&&!r&&!k,F=document.activeElement;if(ve&&F){const I=pe,[C,A]=se(I);if(C&&A){if(!X&&F===A){const d=T({focusReason:i.value});n("focusout-prevented",d),d.defaultPrevented||(t.preventDefault(),Y&&c(C,!0))}else if(X&&[C,I].includes(F)){const d=T({focusReason:i.value});n("focusout-prevented",d),d.defaultPrevented||(t.preventDefault(),Y&&c(A,!0))}}else if(F===I){const d=T({focusReason:i.value});n("focusout-prevented",d),d.defaultPrevented||t.preventDefault()}}};ye(D,{focusTrapRef:o,onKeydown:b}),j(()=>e.focusTrapEl,t=>{t&&(o.value=t)},{immediate:!0}),j([o],([t],[a])=>{t&&(t.addEventListener("keydown",b),t.addEventListener("focusin",z),t.addEventListener("focusout",J)),a&&(a.removeEventListener("keydown",b),a.removeEventListener("focusin",z),a.removeEventListener("focusout",J))});const N=t=>{n(P,t)},fe=t=>n(S,t),z=t=>{const a=g(o);if(!a)return;const u=t.target,r=t.relatedTarget,k=u&&a.contains(u);e.trapped||r&&a.contains(r)||(s=r),k&&n("focusin",t),!l.paused&&e.trapped&&(k?p=u:c(p,!0))},J=t=>{const a=g(o);if(!(l.paused||!a))if(e.trapped){const u=t.relatedTarget;!Te(u)&&!a.contains(u)&&setTimeout(()=>{if(!l.paused&&e.trapped){const r=T({focusReason:i.value});n("focusout-prevented",r),r.defaultPrevented||c(p,!0)}},0)}else{const u=t.target;u&&a.contains(u)||n("focusout",t)}};async function Q(){await te();const t=g(o);if(t){G.push(l);const a=t.contains(document.activeElement)?s:document.activeElement;if(s=a,!t.contains(a)){const u=new Event(m,K);t.addEventListener(m,N),t.dispatchEvent(u),u.defaultPrevented||te(()=>{let r=e.focusStartEl;he(r)||(c(r),document.activeElement!==r&&(r="first")),r==="first"&&ue(B(t),!0),(document.activeElement===a||r==="container")&&c(t)})}}}function V(){const t=g(o);if(t){t.removeEventListener(m,N);const a=new CustomEvent(E,{...K,detail:{focusReason:i.value}});t.addEventListener(E,fe),t.dispatchEvent(a),!a.defaultPrevented&&(i.value=="keyboard"||!ce()||t.contains(document.activeElement))&&c(s??document.body),t.removeEventListener(E,N),G.remove(l)}}return x(()=>{e.trapped&&Q(),j(()=>e.trapped,t=>{t?Q():V()})}),O(()=>{e.trapped&&V()}),{onKeydown:b}}});function le(e,n,o,s,p,i){return we(e.$slots,"default",{handleKeydown:e.onKeydown})}ne=me(ie,[["render",le],["__file","/home/runner/work/element-plus/element-plus/packages/components/focus-trap/src/focus-trap.vue"]])});export{ne as E,D as F,be as __tla};