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