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