const $=t=>typeof t=="object"&&t!=null&&t.nodeType===1,tt=(t,o)=>(!o||t!=="hidden")&&t!=="visible"&&t!=="clip",S=(t,o)=>{if(t.clientHeight<t.scrollHeight||t.clientWidth<t.scrollWidth){const d=getComputedStyle(t,null);return tt(d.overflowY,o)||tt(d.overflowX,o)||(h=>{const c=(l=>{if(!l.ownerDocument||!l.ownerDocument.defaultView)return null;try{return l.ownerDocument.defaultView.frameElement}catch{return null}})(h);return!!c&&(c.clientHeight<h.scrollHeight||c.clientWidth<h.scrollWidth)})(t)}return!1},X=(t,o,d,h,c,l,f,n)=>l<t&&f>o||l>t&&f<o?0:l<=t&&n<=d||f>=o&&n>=d?l-t-h:f>o&&n<d||l<t&&n>d?f-o+c:0,nt=t=>{const o=t.parentElement;return o??(t.getRootNode().host||null)},lt=(t,o)=>{var d,h,c,l;if(typeof document>"u")return[];const{scrollMode:f,block:n,inline:a,boundary:Y,skipOverflowHiddenElements:et}=o,ot=typeof Y=="function"?Y:p=>p!==Y;if(!$(t))throw new TypeError("Invalid target");const j=document.scrollingElement||document.documentElement,M=[];let r=t;for(;$(r)&&ot(r);){if(r=nt(r),r===j){M.push(r);break}r!=null&&r===document.body&&S(r)&&!S(document.documentElement)||r!=null&&S(r,et)&&M.push(r)}const m=(h=(d=window.visualViewport)==null?void 0:d.width)!=null?h:innerWidth,w=(l=(c=window.visualViewport)==null?void 0:c.height)!=null?l:innerHeight,{scrollX:W,scrollY:b}=window,{height:H,width:y,top:v,right:N,bottom:O,left:E}=t.getBoundingClientRect(),{top:K,right:P,bottom:Q,left:U}=(p=>{const e=window.getComputedStyle(p);return{top:parseFloat(e.scrollMarginTop)||0,right:parseFloat(e.scrollMarginRight)||0,bottom:parseFloat(e.scrollMarginBottom)||0,left:parseFloat(e.scrollMarginLeft)||0}})(t);let i=n==="start"||n==="nearest"?v-K:n==="end"?O+Q:v+H/2-K+Q,s=a==="center"?E+y/2-U+P:a==="end"?N+P:E-U;const q=[];for(let p=0;p<M.length;p++){const e=M[p],{height:T,width:x,top:B,right:z,bottom:A,left:C}=e.getBoundingClientRect();if(f==="if-needed"&&v>=0&&E>=0&&O<=w&&N<=m&&(e===j&&!S(e)||v>=B&&O<=A&&E>=C&&N<=z))return q;const F=getComputedStyle(e),I=parseInt(F.borderLeftWidth,10),R=parseInt(F.borderTopWidth,10),V=parseInt(F.borderRightWidth,10),k=parseInt(F.borderBottomWidth,10);let u=0,g=0;const D="offsetWidth"in e?e.offsetWidth-e.clientWidth-I-V:0,L="offsetHeight"in e?e.offsetHeight-e.clientHeight-R-k:0,G="offsetWidth"in e?e.offsetWidth===0?0:x/e.offsetWidth:0,J="offsetHeight"in e?e.offsetHeight===0?0:T/e.offsetHeight:0;if(j===e)u=n==="start"?i:n==="end"?i-w:n==="nearest"?X(b,b+w,w,R,k,b+i,b+i+H,H):i-w/2,g=a==="start"?s:a==="center"?s-m/2:a==="end"?s-m:X(W,W+m,m,I,V,W+s,W+s+y,y),u=Math.max(0,u+b),g=Math.max(0,g+W);else{u=n==="start"?i-B-R:n==="end"?i-A+k+L:n==="nearest"?X(B,A,T,R,k+L,i,i+H,H):i-(B+T/2)+L/2,g=a==="start"?s-C-I:a==="center"?s-(C+x/2)+D/2:a==="end"?s-z+V+D:X(C,z,x,I,V+D,s,s+y,y);const{scrollLeft:Z,scrollTop:_}=e;u=J===0?0:Math.max(0,Math.min(_+u/J,e.scrollHeight-T/J+L)),g=G===0?0:Math.max(0,Math.min(Z+g/G,e.scrollWidth-x/G+D)),i+=_-u,s+=Z-g}q.push({el:e,top:u,left:g})}return q};export{lt as compute};
