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