import{alignElement as M,alignPoint as O}from"../node_modules/.pnpm/dom-align@1.12.4/node_modules/dom-align/dist-web/index.mjs";import P from"lodash-es/isEqual";import{defineComponent as T,ref as s,computed as j,onMounted as W,nextTick as b,onUpdated as x,watch as R,onUnmounted as y}from"vue";import{cloneElement as C}from"../_util/vnode.mjs";import D from"../vc-util/Dom/addEventListener.mjs";import U from"../vc-util/Dom/isVisible.mjs";import k from"./hooks/useBuffer.mjs";import{restoreFocus as q,monitorResize as z,isSamePoint as L}from"./util.mjs";const N={align:Object,target:[Object,Function],onAlign:Function,monitorBufferTime:Number,monitorWindowResize:Boolean,disabled:Boolean};function E(e){return typeof e!="function"?null:e()}function w(e){return typeof e!="object"||!e?null:e}const X=T({compatConfig:{MODE:3},name:"Align",props:N,emits:["align"],setup(e,{expose:h,slots:B}){const o=s({}),i=s(),[a,d]=k(()=>{const{disabled:n,target:t,align:c,onAlign:A}=e;if(!n&&t&&i.value){const m=i.value;let f;const v=E(t),g=w(t);o.value.element=v,o.value.point=g,o.value.align=c;const{activeElement:F}=document;return v&&U(v)?f=M(m,v,c):g&&(f=O(m,g,c)),q(F,m),A&&f&&A(m,f),!0}return!1},j(()=>e.monitorBufferTime)),u=s({cancel:()=>{}}),r=s({cancel:()=>{}}),p=()=>{const n=e.target,t=E(n),c=w(n);i.value!==r.value.element&&(r.value.cancel(),r.value.element=i.value,r.value.cancel=z(i.value,a)),(o.value.element!==t||!L(o.value.point,c)||!P(o.value.align,e.align))&&(a(),u.value.element!==t&&(u.value.cancel(),u.value.element=t,u.value.cancel=z(t,a)))};W(()=>{b(()=>{p()})}),x(()=>{b(()=>{p()})}),R(()=>e.disabled,n=>{n?d():a()},{immediate:!0,flush:"post"});const l=s(null);return R(()=>e.monitorWindowResize,n=>{n?l.value||(l.value=D(window,"resize",a)):l.value&&(l.value.remove(),l.value=null)},{flush:"post"}),y(()=>{u.value.cancel(),r.value.cancel(),l.value&&l.value.remove(),d()}),h({forceAlign:()=>a(!0)}),()=>{const n=B?.default();return n?C(n[0],{ref:i},!0,!0):null}}});export{N as alignProps,X as default};
