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