!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?module.exports=i():"function"==typeof define&&define.amd?define(i):(t="undefined"!=typeof globalThis?globalThis:t||self).Lenis=i()}(this,function(){"use strict";function t(t,i,e){return Math.max(t,Math.min(i,e))}class i{constructor(){this.events={}}emit(t,...i){let e=this.events[t]||[];for(let s=0,o=e.length;s{this.events[t]=this.events[t]?.filter(t=>i!==t)}}off(t,i){this.events[t]=this.events[t]?.filter(t=>i!==t)}destroy(){this.events={}}}let e=100/6;return class s{constructor({wrapper:s=window,content:o=document.documentElement,wheelEventsTarget:l=s,eventsTarget:h=l,smoothWheel:n=!0,syncTouch:r=!1,syncTouchLerp:a=.075,touchInertiaMultiplier:c=35,duration:p,easing:d=t=>Math.min(1,1.001-Math.pow(2,-10*t)),lerp:u=.1,infinite:m=!1,orientation:v="vertical",gestureOrientation:S="vertical",touchMultiplier:g=1,wheelMultiplier:f=1,autoResize:$=!0,prevent:y=!1,__experimental__naiveDimensions:_=!1}={}){this.__isScrolling=!1,this.__isStopped=!1,this.__isLocked=!1,this.direction=0,this.onVirtualScroll=({deltaX:t,deltaY:i,event:e})=>{if(e.ctrlKey)return;let s=e.type.includes("touch"),o=e.type.includes("wheel");this.isTouching="touchstart"===e.type||"touchmove"===e.type;let l=this.options.syncTouch&&s&&"touchstart"===e.type&&!this.isStopped&&!this.isLocked;if(l){this.reset();return}let h="vertical"===this.options.gestureOrientation&&0===i||"horizontal"===this.options.gestureOrientation&&0===t;if(0===t&&0===i||h)return;let n=e.composedPath();n=n.slice(0,n.indexOf(this.rootElement));let r=this.options.prevent;if(n.find(t=>{var i,e,l,h,n;return t instanceof Element&&(("function"==typeof r?null==r?void 0:r(t):r)||(null===(i=t.hasAttribute)||void 0===i?void 0:i.call(t,"data-lenis-prevent"))||s&&(null===(e=t.hasAttribute)||void 0===e?void 0:e.call(t,"data-lenis-prevent-touch"))||o&&(null===(l=t.hasAttribute)||void 0===l?void 0:l.call(t,"data-lenis-prevent-wheel"))||(null===(h=t.classList)||void 0===h?void 0:h.contains("lenis"))&&!(null===(n=t.classList)||void 0===n?void 0:n.contains("lenis-stopped")))}))return;if(this.isStopped||this.isLocked){e.preventDefault();return}let a=this.options.syncTouch&&s||this.options.smoothWheel&&o;if(!a){this.isScrolling="native",this.animate.stop();return}e.preventDefault();let c=i;"both"===this.options.gestureOrientation?c=Math.abs(i)>Math.abs(t)?i:t:"horizontal"===this.options.gestureOrientation&&(c=t);let p=s&&this.options.syncTouch,d=s&&"touchend"===e.type,u=d&&Math.abs(c)>5;u&&(c=this.velocity*this.options.touchInertiaMultiplier),this.scrollTo(this.targetScroll+c,Object.assign({programmatic:!1},p?{lerp:u?this.options.syncTouchLerp:1}:{lerp:this.options.lerp,duration:this.options.duration,easing:this.options.easing}))},this.onNativeScroll=()=>{if(clearTimeout(this.__resetVelocityTimeout),delete this.__resetVelocityTimeout,this.__preventNextNativeScrollEvent){delete this.__preventNextNativeScrollEvent;return}if(!1===this.isScrolling||"native"===this.isScrolling){let t=this.animatedScroll;this.animatedScroll=this.targetScroll=this.actualScroll,this.lastVelocity=this.velocity,this.velocity=this.animatedScroll-t,this.direction=Math.sign(this.animatedScroll-t),this.isScrolling="native",this.emit(),0!==this.velocity&&(this.__resetVelocityTimeout=setTimeout(()=>{this.lastVelocity=this.velocity,this.velocity=0,this.isScrolling=!1,this.emit()},400))}},window.lenisVersion="1.1.3",s&&s!==document.documentElement&&s!==document.body||(s=window),this.options={wrapper:s,content:o,wheelEventsTarget:l,eventsTarget:h,smoothWheel:n,syncTouch:r,syncTouchLerp:a,touchInertiaMultiplier:c,duration:p,easing:d,lerp:u,infinite:m,gestureOrientation:S,orientation:v,touchMultiplier:g,wheelMultiplier:f,autoResize:$,prevent:y,__experimental__naiveDimensions:_},this.animate=new class i{advance(i){if(!this.isRunning)return;let e=!1;if(this.duration&&this.easing){this.currentTime+=i;let s=t(0,this.currentTime/this.duration,1);e=s>=1;let o=e?1:this.easing(s);this.value=this.from+(this.to-this.from)*o}else if(this.lerp){var l,h,n,r,a,c,p;this.value=(l=this.value,h=this.to,n=60*this.lerp,r=i,a=l,c=h,(1-(p=1-Math.exp(-n*r)))*a+p*c),Math.round(this.value)===this.to&&(this.value=this.to,e=!0)}else this.value=this.to,e=!0;e&&this.stop(),this.onUpdate?.(this.value,e)}stop(){this.isRunning=!1}fromTo(t,i,{lerp:e,duration:s,easing:o,onStart:l,onUpdate:h}){this.from=this.value=t,this.to=i,this.lerp=e,this.duration=s,this.easing=o,this.currentTime=0,this.isRunning=!0,l?.(),this.onUpdate=h}},this.emitter=new i,this.dimensions=new class t{constructor({wrapper:t,content:i,autoResize:e=!0,debounce:s=250}={}){if(this.wrapper=t,this.content=i,e){var o,l;let h;this.debouncedResize=(o=this.resize,l=s,function(){let t=arguments,i=this;clearTimeout(h),h=setTimeout(function(){o.apply(i,t)},l)}),this.wrapper===window?window.addEventListener("resize",this.debouncedResize,!1):(this.wrapperResizeObserver=new ResizeObserver(this.debouncedResize),this.wrapperResizeObserver.observe(this.wrapper)),this.contentResizeObserver=new ResizeObserver(this.debouncedResize),this.contentResizeObserver.observe(this.content)}this.resize()}destroy(){this.wrapperResizeObserver?.disconnect(),this.contentResizeObserver?.disconnect(),window.removeEventListener("resize",this.debouncedResize,!1)}resize=()=>{this.onWrapperResize(),this.onContentResize()};onWrapperResize=()=>{this.wrapper===window?(this.width=window.innerWidth,this.height=window.innerHeight):(this.width=this.wrapper.clientWidth,this.height=this.wrapper.clientHeight)};onContentResize=()=>{this.wrapper===window?(this.scrollHeight=this.content.scrollHeight,this.scrollWidth=this.content.scrollWidth):(this.scrollHeight=this.wrapper.scrollHeight,this.scrollWidth=this.wrapper.scrollWidth)};get limit(){return{x:this.scrollWidth-this.width,y:this.scrollHeight-this.height}}}({wrapper:s,content:o,autoResize:$}),this.updateClassName(),this.userData={},this.time=0,this.velocity=this.lastVelocity=0,this.isLocked=!1,this.isStopped=!1,this.isScrolling=!1,this.targetScroll=this.animatedScroll=this.actualScroll,this.options.wrapper.addEventListener("scroll",this.onNativeScroll,!1),this.virtualScroll=new class t{constructor(t,{wheelMultiplier:e=1,touchMultiplier:s=1}){this.element=t,this.wheelMultiplier=e,this.touchMultiplier=s,this.touchStart={x:null,y:null},this.emitter=new i,window.addEventListener("resize",this.onWindowResize,!1),this.onWindowResize(),this.element.addEventListener("wheel",this.onWheel,{passive:!1}),this.element.addEventListener("touchstart",this.onTouchStart,{passive:!1}),this.element.addEventListener("touchmove",this.onTouchMove,{passive:!1}),this.element.addEventListener("touchend",this.onTouchEnd,{passive:!1})}on(t,i){return this.emitter.on(t,i)}destroy(){this.emitter.destroy(),window.removeEventListener("resize",this.onWindowResize,!1),this.element.removeEventListener("wheel",this.onWheel,{passive:!1}),this.element.removeEventListener("touchstart",this.onTouchStart,{passive:!1}),this.element.removeEventListener("touchmove",this.onTouchMove,{passive:!1}),this.element.removeEventListener("touchend",this.onTouchEnd,{passive:!1})}onTouchStart=t=>{let{clientX:i,clientY:e}=t.targetTouches?t.targetTouches[0]:t;this.touchStart.x=i,this.touchStart.y=e,this.lastDelta={x:0,y:0},this.emitter.emit("scroll",{deltaX:0,deltaY:0,event:t})};onTouchMove=t=>{let{clientX:i,clientY:e}=t.targetTouches?t.targetTouches[0]:t,s=-(i-this.touchStart.x)*this.touchMultiplier,o=-(e-this.touchStart.y)*this.touchMultiplier;this.touchStart.x=i,this.touchStart.y=e,this.lastDelta={x:s,y:o},this.emitter.emit("scroll",{deltaX:s,deltaY:o,event:t})};onTouchEnd=t=>{this.emitter.emit("scroll",{deltaX:this.lastDelta.x,deltaY:this.lastDelta.y,event:t})};onWheel=t=>{let{deltaX:i,deltaY:s,deltaMode:o}=t,l=1===o?e:2===o?this.windowWidth:1,h=1===o?e:2===o?this.windowHeight:1;i*=l,s*=h,i*=this.wheelMultiplier,s*=this.wheelMultiplier,this.emitter.emit("scroll",{deltaX:i,deltaY:s,event:t})};onWindowResize=()=>{this.windowWidth=window.innerWidth,this.windowHeight=window.innerHeight}}(h,{touchMultiplier:g,wheelMultiplier:f}),this.virtualScroll.on("scroll",this.onVirtualScroll)}destroy(){this.emitter.destroy(),this.options.wrapper.removeEventListener("scroll",this.onNativeScroll,!1),this.virtualScroll.destroy(),this.dimensions.destroy(),this.cleanUpClassName()}on(t,i){return this.emitter.on(t,i)}off(t,i){return this.emitter.off(t,i)}setScroll(t){this.isHorizontal?this.rootElement.scrollLeft=t:this.rootElement.scrollTop=t}resize(){this.dimensions.resize()}emit(){this.emitter.emit("scroll",this)}reset(){this.isLocked=!1,this.isScrolling=!1,this.animatedScroll=this.targetScroll=this.actualScroll,this.lastVelocity=this.velocity=0,this.animate.stop()}start(){this.isStopped&&(this.isStopped=!1,this.reset())}stop(){this.isStopped||(this.isStopped=!0,this.animate.stop(),this.reset())}raf(t){let i=t-(this.time||t);this.time=t,this.animate.advance(.001*i)}scrollTo(i,{offset:e=0,immediate:s=!1,lock:o=!1,duration:l=this.options.duration,easing:h=this.options.easing,lerp:n=this.options.lerp,onStart:r,onComplete:a,force:c=!1,programmatic:p=!0,userData:d={}}={}){if(!this.isStopped&&!this.isLocked||c){if("string"==typeof i&&["top","left","start"].includes(i))i=0;else if("string"==typeof i&&["bottom","right","end"].includes(i))i=this.limit;else{let u;if("string"==typeof i?u=document.querySelector(i):i instanceof HTMLElement&&(null==i?void 0:i.nodeType)&&(u=i),u){if(this.options.wrapper!==window){let m=this.rootElement.getBoundingClientRect();e-=this.isHorizontal?m.left:m.top}let v=u.getBoundingClientRect();i=(this.isHorizontal?v.left:v.top)+this.animatedScroll}}if("number"==typeof i&&(i+=e,i=Math.round(i),this.options.infinite?p&&(this.targetScroll=this.animatedScroll=this.scroll):i=t(0,i,this.limit),i!==this.targetScroll)){if(this.userData=d,s){this.animatedScroll=this.targetScroll=i,this.setScroll(this.scroll),this.reset(),this.preventNextNativeScrollEvent(),this.emit(),null==a||a(this),this.userData={};return}p||(this.targetScroll=i),this.animate.fromTo(this.animatedScroll,i,{duration:l,easing:h,lerp:n,onStart:()=>{o&&(this.isLocked=!0),this.isScrolling="smooth",null==r||r(this)},onUpdate:(t,i)=>{this.isScrolling="smooth",this.lastVelocity=this.velocity,this.velocity=t-this.animatedScroll,this.direction=Math.sign(this.velocity),this.animatedScroll=t,this.setScroll(this.scroll),p&&(this.targetScroll=t),i||this.emit(),i&&(this.reset(),this.emit(),null==a||a(this),this.userData={},this.preventNextNativeScrollEvent())}})}}}preventNextNativeScrollEvent(){this.__preventNextNativeScrollEvent=!0,requestAnimationFrame(()=>{delete this.__preventNextNativeScrollEvent})}get rootElement(){return this.options.wrapper===window?document.documentElement:this.options.wrapper}get limit(){return this.options.__experimental__naiveDimensions?this.isHorizontal?this.rootElement.scrollWidth-this.rootElement.clientWidth:this.rootElement.scrollHeight-this.rootElement.clientHeight:this.dimensions.limit[this.isHorizontal?"x":"y"]}get isHorizontal(){return"horizontal"===this.options.orientation}get actualScroll(){return this.isHorizontal?this.rootElement.scrollLeft:this.rootElement.scrollTop}get scroll(){var t,i;return this.options.infinite?(t=this.animatedScroll,(t%(i=this.limit)+i)%i):this.animatedScroll}get progress(){return 0===this.limit?1:this.scroll/this.limit}get isScrolling(){return this.__isScrolling}set isScrolling(t){this.__isScrolling!==t&&(this.__isScrolling=t,this.updateClassName())}get isStopped(){return this.__isStopped}set isStopped(t){this.__isStopped!==t&&(this.__isStopped=t,this.updateClassName())}get isLocked(){return this.__isLocked}set isLocked(t){this.__isLocked!==t&&(this.__isLocked=t,this.updateClassName())}get isSmooth(){return"smooth"===this.isScrolling}get className(){let t="lenis";return this.isStopped&&(t+=" lenis-stopped"),this.isLocked&&(t+=" lenis-locked"),this.isScrolling&&(t+=" lenis-scrolling"),"smooth"===this.isScrolling&&(t+=" lenis-smooth"),t}updateClassName(){this.cleanUpClassName(),this.rootElement.className=`${this.rootElement.className} ${this.className}`.trim()}cleanUpClassName(){this.rootElement.className=this.rootElement.className.replace(/lenis(-\w+)?/g,"").trim()}}});