import{r as b,j as A,C as _,k as q,h as C,o as O,b as u,n as F,f as V,T as Y}from"./C9RGyKra.js";const R={__name:"BackToTop",props:{threshold:{type:Number,default:200},sentinelSelector:{type:String,default:".scroll-sentinel"}},setup(v){const a=v,d=b(!1),E=b(null);let e=null,s=null,i=null;const m=()=>{if(typeof window>"u"||typeof document>"u")return;const n=document.scrollingElement||document.documentElement||document.body,t=[window.pageYOffset,window.scrollY,n?n.scrollTop:void 0,document.documentElement?document.documentElement.scrollTop:void 0,document.body?document.body.scrollTop:void 0,document.getElementById("app")?document.getElementById("app").scrollTop:void 0],o=Math.max(0,...t.map(l=>typeof l=="number"?l:0));d.value=o>a.threshold},g=()=>{typeof window>"u"||typeof document>"u"||e||(e=()=>{m()},window.addEventListener("scroll",e,{passive:!0}),document.addEventListener("scroll",e,{passive:!0}),window.addEventListener("touchmove",e,{passive:!0}))},p=()=>{typeof window>"u"||typeof document>"u"||!e||(window.removeEventListener("scroll",e),document.removeEventListener("scroll",e),window.removeEventListener("touchmove",e),e=null)},f=()=>{s&&(cancelAnimationFrame(s),s=null)},w=()=>{i&&(i.disconnect(),i=null)},k=()=>{if(typeof window>"u"||typeof document>"u")return;const n=document.querySelector(a.sentinelSelector);"IntersectionObserver"in window&&n?(w(),i=new IntersectionObserver(t=>{const o=t[0];d.value=!(o&&o.isIntersecting)},{root:null,rootMargin:"-80px 0px 0px 0px",threshold:0}),i.observe(n),p()):(g(),m())},B=()=>{if(typeof window>"u"||typeof document>"u")return;f();const n=document.scrollingElement||document.documentElement||document.body,t=[n,document.body,document.documentElement,document.getElementById("app")].filter(Boolean),o=[...new Set(t)].filter(r=>typeof r.scrollTop=="number");if(o.length===0){window.scrollTo({top:0});return}const l=new Map;o.forEach(r=>{l.set(r,r.scrollTop)});const L=600,x=r=>1-Math.pow(1-r,3);requestAnimationFrame(r=>{const y=M=>{const S=M-r,h=Math.min(S/L,1),T=x(h);if(o.forEach(c=>{const I=l.get(c)||0;c.scrollTop=I*(1-T)}),typeof window.scrollTo=="function"&&n===document.documentElement){const c=l.get(n)||window.scrollY||0;window.scrollTo(0,c*(1-T))}h<1?s=requestAnimationFrame(y):(o.forEach(c=>c.scrollTop=0),s=null)};s=requestAnimationFrame(y)})};return A(()=>{_(()=>{k()})}),q(()=>{p(),w(),f()}),(n,t)=>(O(),C(Y,{to:"body"},[u("button",{ref_key:"buttonRef",ref:E,class:F(["back-to-top",{show:V(d)}]),onClick:B,"aria-label":"返回顶部"},[...t[0]||(t[0]=[u("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[u("path",{d:"M12 19V5M12 5L5 12M12 5L19 12",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])],2)]))}};export{R as _};
