import{computed as s,ref as E}from"vue";import{FocusableMode as d,isFocusableElement as p}from'../utils/focus-management.js';import{dom as C}from'../utils/dom.js';import{useDocumentEvent as a}from'./use-document-event.js';import{useWindowEvent as v}from'./use-window-event.js';function F(f,m,l=s(()=>!0)){function i(e,u){if(!l.value||e.defaultPrevented)return;let n=u(e);if(n===null||!n.getRootNode().contains(n))return;let c=function o(t){return typeof t=="function"?o(t()):Array.isArray(t)||t instanceof Set?t:[t]}(f);for(let o of c){if(o===null)continue;let t=o instanceof HTMLElement?o:C(o);if(t!=null&&t.contains(n)||e.composed&&e.composedPath().includes(t))return}return!p(n,d.Loose)&&n.tabIndex!==-1&&e.preventDefault(),m(e,n)}let r=E(null);a("mousedown",e=>{var u,n;l.value&&(r.value=((n=(u=e.composedPath)==null?void 0:u.call(e))==null?void 0:n[0])||e.target)},!0),a("click",e=>{r.value&&(i(e,()=>r.value),r.value=null)},!0),v("blur",e=>i(e,()=>window.document.activeElement instanceof HTMLIFrameElement?window.document.activeElement:null),!0)}export{F as useOutsideClick};
