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