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