import{t,i,l,s,e,r,p}from"./chunk-p42kdtn4.js";var D=25;function B(o,a){let n=a>0?1-Math.abs(o)/a:0;return n>0?a*n*n*n*(4-n)/16:0}var O=new Set(["auto","scroll","hidden"]);function P(o){let a=o.parentElement;if(!a||getComputedStyle(a).display==="contents")return!1;let n=a;while(n&&n!==document.body){let u=getComputedStyle(n);if(u.position==="sticky"||O.has(u.overflowY)||O.has(u.overflowX))return!1;n=n.parentElement}return!0}function F(o,a={}){let n=a.distance??D,u=a.targets??[o],m=a.property??null,y=null,C=0,h=0,E=0,H=0,T=0,v=1,S=!1,b=0,M=(c)=>{b=c;let f=c?`0 ${c}px`:"";if(u.forEach((d)=>{d.style.translate=f}),m)if(c)o.style.setProperty(m,`${c}px`);else o.style.removeProperty(m)},w=()=>{if(b)M(0)},I=()=>{w();let c=getComputedStyle(o);if(S=!i&&n>0&&c.position==="sticky"&&c.top!=="auto"&&o.getClientRects().length>0&&P(o),!S)return;y=o.parentElement;let f=getComputedStyle(y),d=parseFloat(c.top);o.style.position="static";let x=o.getBoundingClientRect(),k=y.getBoundingClientRect();o.style.position="";let A=k.bottom-parseFloat(f.borderBottomWidth)-parseFloat(f.paddingBottom);C=x.top-k.top-d,h=A-x.bottom-parseFloat(c.marginBottom),E=window.scrollY+x.top-d,H=document.documentElement.scrollHeight-window.innerHeight-E-h,T=window.innerHeight/100,v=window.devicePixelRatio||1,S=h>0},R=()=>{if(!S||!y)return;let c=-y.getBoundingClientRect().top-C,f=Math.min(n*T,h/2),d=B(c,Math.min(f,E))-B(c-h,Math.min(f,H));if(d=Math.round(d*v)/v,d!==b)M(d)},g=()=>{I(),R()},L=new ResizeObserver(g);if(L.observe(o),o.parentElement)L.observe(o.parentElement);g(),t.addEventListener("refreshInit",w),t.addEventListener("refresh",g);let N=[s.add(R),l.add(g),p("preloader-complete",g),()=>t.removeEventListener("refreshInit",w),()=>t.removeEventListener("refresh",g),()=>L.disconnect()];return()=>{N.splice(0).forEach((c)=>c()),S=!1,M(0)}}function z(o,a){let n=null,u=Number(a.distance),m=a.target?Array.from(o.querySelectorAll(a.target)):void 0;e(()=>{n=F(o,{distance:a.distance&&Number.isFinite(u)?u:void 0,targets:m?.length?m:void 0})}),r(()=>{n?.(),n=null})}export{z as default};