class SmoothScroll{constructor(t={}){this.options={lerp:t.lerp??.1,wheelMultiplier:t.wheelMultiplier??1,touchMultiplier:t.touchMultiplier??1.5,offset:t.offset??0},this.targetY=window.scrollY,this.currentY=window.scrollY,this.running=!1,this.isTouching=!1,this.touchStartY=0,this.touchStartScroll=0,this.init()}init(){window.addEventListener("wheel",this.onWheel.bind(this),{passive:!1}),window.addEventListener("touchstart",this.onTouchStart.bind(this),{passive:!1}),window.addEventListener("touchmove",this.onTouchMove.bind(this),{passive:!1}),window.addEventListener("touchend",this.onTouchEnd.bind(this)),window.addEventListener("scroll",this.onNativeScroll.bind(this)),window.addEventListener("resize",this.clamp.bind(this))}onWheel(t){t.preventDefault();let i=t.deltaY;1===t.deltaMode?i*=40:2===t.deltaMode&&(i*=window.innerHeight),this.targetY+=i*this.options.wheelMultiplier,this.clamp(),this.running||(this.running=!0,this.raf())}onTouchStart(t){this.isTouching=!0,this.touchStartY=t.touches[0].clientY,this.touchStartScroll=this.targetY}onTouchMove(t){if(!this.isTouching)return;t.preventDefault();const i=(this.touchStartY-t.touches[0].clientY)*this.options.touchMultiplier;this.targetY=this.touchStartScroll+i,this.clamp(),this.running||(this.running=!0,this.raf())}onTouchEnd(){this.isTouching=!1}onNativeScroll(){this.running||(this.targetY=window.scrollY,this.currentY=window.scrollY)}clamp(){const t=document.documentElement.scrollHeight-window.innerHeight;this.targetY=Math.max(0,Math.min(this.targetY,t))}raf(){if(!this.running)return;const t=this.targetY-this.currentY;if(Math.abs(t)<.5&&!this.isTouching)return this.currentY=this.targetY,window.scrollTo(0,this.currentY),void(this.running=!1);this.currentY+=t*this.options.lerp,window.scrollTo(0,this.currentY),requestAnimationFrame(this.raf.bind(this))}scrollTo(t,i){let s=0;const o=void 0!==i?i:this.options.offset;if("number"==typeof t)s=t;else if("string"==typeof t){const e=document.querySelector(t);if(!e)return;s=e.getBoundingClientRect().top+window.scrollY+o}else t instanceof Element&&(s=t.getBoundingClientRect().top+window.scrollY+o);this.targetY=s,this.clamp(),this.running||(this.running=!0,this.raf())}getScrollY(){return this.currentY}}"undefined"!=typeof module&&module.exports&&(module.exports=SmoothScroll);