import{watchEffect as h,onMounted as p,watch as g,onBeforeUnmount as w,computed as I}from"vue";import f from"../../_util/hooks/useState.mjs";import{isInViewPort as E}from"../util.mjs";function S(n,u,a,v){const[o,d]=f(void 0);h(()=>{const e=typeof n.value=="function"?n.value():n.value;d(e||null)},{flush:"post"});const[t,l]=f(null),s=()=>{if(!u.value){l(null);return}if(o.value){!E(o.value)&&u.value&&o.value.scrollIntoView(v.value);const{left:e,top:i,width:c,height:m}=o.value.getBoundingClientRect(),r={left:e,top:i,width:c,height:m,radius:0};JSON.stringify(t.value)!==JSON.stringify(r)&&l(r)}else l(null)};return p(()=>{g([u,o],()=>{s()},{flush:"post",immediate:!0}),window.addEventListener("resize",s)}),w(()=>{window.removeEventListener("resize",s)}),[I(()=>{if(!t.value)return t.value;const e=a.value?.offset||6,i=a.value?.radius||2;return{left:t.value.left-e,top:t.value.top-e,width:t.value.width+e*2,height:t.value.height+e*2,radius:i}}),o]}export{S as default};
