diff --git a/README.md b/README.md index aaf34c00..ae1fae5a 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,9 @@ [![LENIS](https://assets.studiofreight.com/lenis/header.png)](https://github.com/studio-freight/lenis) -[![npm version](https://img.shields.io/badge/dynamic/json?color=blue&label=npm&prefix=v&query=version&suffix=%20&url=https%3A%2F%2Fraw.githubusercontent.com%2Fstudio-freight%2Flenis%2Fmain%2Fpackage.json)](https://www.npmjs.com/package/@studio-freight/lenis) -[![size](https://img.shields.io/bundlephobia/minzip/@studio-freight/lenis?label=bundle)](https://bundlephobia.com/package/@studio-freight/lenis) +[![npm version](https://img.shields.io/badge/dynamic/json?color=blue&label=npm&prefix=v&query=version&suffix=%20&url=https://raw.githubusercontent.com/studio-freight/lenis/main/packages/lenis/package.json)](https://www.npmjs.com/package/@studio-freight/lenis) +[![download](https://img.shields.io/npm/dm/%40studio-freight%2Flenis +)](https://www.npmjs.com/package/@studio-freight/lenis) +[![gzip](https://img.shields.io/bundlephobia/minzip/@studio-freight/lenis?label=size)](https://bundlephobia.com/package/@studio-freight/lenis) ## Introduction diff --git a/packages/lenis/dist/lenis.cjs.js b/packages/lenis/dist/lenis.cjs.js index c5e8475f..2e2b4499 100644 --- a/packages/lenis/dist/lenis.cjs.js +++ b/packages/lenis/dist/lenis.cjs.js @@ -1,2 +1,2 @@ -"use strict";function t(t,e,i){return Math.max(t,Math.min(e,i))}class Animate{advance(e){if(!this.isRunning)return;let i=!1;if(this.lerp)this.value=(s=this.value,o=this.to,n=60*this.lerp,r=e,function(t,e,i){return(1-i)*t+i*e}(s,o,1-Math.exp(-n*r))),Math.round(this.value)===this.to&&(this.value=this.to,i=!0);else{this.currentTime+=e;const s=t(0,this.currentTime/this.duration,1);i=s>=1;const o=i?1:this.easing(s);this.value=this.from+(this.to-this.from)*o}var s,o,n,r;this.onUpdate?.(this.value,i),i&&this.stop()}stop(){this.isRunning=!1}fromTo(t,e,{lerp:i=.1,duration:s=1,easing:o=(t=>t),onStart:n,onUpdate:r}){this.from=this.value=t,this.to=e,this.lerp=i,this.duration=s,this.easing=o,this.currentTime=0,this.isRunning=!0,n?.(),this.onUpdate=r}}class Dimensions{constructor({wrapper:t,content:e,autoResize:i=!0}={}){if(this.wrapper=t,this.content=e,i){const t=function(t,e){let i;return function(){let s=arguments,o=this;clearTimeout(i),i=setTimeout((function(){t.apply(o,s)}),e)}}(this.resize,250);this.wrapper!==window&&(this.wrapperResizeObserver=new ResizeObserver(t),this.wrapperResizeObserver.observe(this.wrapper)),this.contentResizeObserver=new ResizeObserver(t),this.contentResizeObserver.observe(this.content)}this.resize()}destroy(){this.wrapperResizeObserver?.disconnect(),this.contentResizeObserver?.disconnect()}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.scrollHeight=this.content.scrollHeight,this.scrollWidth=this.content.scrollWidth};get limit(){return{x:this.scrollWidth-this.width,y:this.scrollHeight-this.height}}}class Emitter{constructor(){this.events={}}emit(t,...e){let i=this.events[t]||[];for(let t=0,s=i.length;t{this.events[t]=this.events[t]?.filter((t=>e!==t))}}off(t,e){this.events[t]=this.events[t]?.filter((t=>e!==t))}destroy(){this.events={}}}class VirtualScroll{constructor(t,{wheelMultiplier:e=1,touchMultiplier:i=2,normalizeWheel:s=!1}){this.element=t,this.wheelMultiplier=e,this.touchMultiplier=i,this.normalizeWheel=s,this.touchStart={x:null,y:null},this.emitter=new Emitter,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,e){return this.emitter.on(t,e)}destroy(){this.emitter.destroy(),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=>{const{clientX:e,clientY:i}=t.targetTouches?t.targetTouches[0]:t;this.touchStart.x=e,this.touchStart.y=i,this.lastDelta={x:0,y:0}};onTouchMove=t=>{const{clientX:e,clientY:i}=t.targetTouches?t.targetTouches[0]:t,s=-(e-this.touchStart.x)*this.touchMultiplier,o=-(i-this.touchStart.y)*this.touchMultiplier;this.touchStart.x=e,this.touchStart.y=i,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=e=>{let{deltaX:i,deltaY:s}=e;this.normalizeWheel&&(i=t(-100,i,100),s=t(-100,s,100)),i*=this.wheelMultiplier,s*=this.wheelMultiplier,this.emitter.emit("scroll",{deltaX:i,deltaY:s,event:e})}}module.exports=class Lenis{constructor({wrapper:t=window,content:e=document.documentElement,wheelEventsTarget:i=t,eventsTarget:s=i,smoothWheel:o=!0,smoothTouch:n=!1,syncTouch:r=!1,syncTouchLerp:l=.1,__iosNoInertiaSyncTouchLerp:h=.4,touchInertiaMultiplier:a=35,duration:c,easing:u=(t=>Math.min(1,1.001-Math.pow(2,-10*t))),lerp:p=!c&&.1,infinite:m=!1,orientation:d="vertical",gestureOrientation:g="vertical",touchMultiplier:v=1,wheelMultiplier:S=1,normalizeWheel:w=!1,autoResize:f=!0}={}){window.lenisVersion="0.0.4",t!==document.documentElement&&t!==document.body||(t=window),this.options={wrapper:t,content:e,wheelEventsTarget:i,eventsTarget:s,smoothWheel:o,smoothTouch:n,syncTouch:r,syncTouchLerp:l,__iosNoInertiaSyncTouchLerp:h,touchInertiaMultiplier:a,duration:c,easing:u,lerp:p,infinite:m,gestureOrientation:g,orientation:d,touchMultiplier:v,wheelMultiplier:S,normalizeWheel:w,autoResize:f},this.animate=new Animate,this.emitter=new Emitter,this.dimensions=new Dimensions({wrapper:t,content:e,autoResize:f}),this.toggleClass("lenis",!0),this.velocity=0,this.isLocked=!1,this.isStopped=!1,this.isSmooth=r||o||n,this.isScrolling=!1,this.targetScroll=this.animatedScroll=this.actualScroll,this.options.wrapper.addEventListener("scroll",this.onNativeScroll,{passive:!1}),this.virtualScroll=new VirtualScroll(s,{touchMultiplier:v,wheelMultiplier:S,normalizeWheel:w}),this.virtualScroll.on("scroll",this.onVirtualScroll)}destroy(){this.emitter.destroy(),this.options.wrapper.removeEventListener("scroll",this.onNativeScroll,{passive:!1}),this.virtualScroll.destroy(),this.dimensions.destroy(),this.toggleClass("lenis",!1),this.toggleClass("lenis-smooth",!1),this.toggleClass("lenis-scrolling",!1),this.toggleClass("lenis-stopped",!1),this.toggleClass("lenis-locked",!1)}on(t,e){return this.emitter.on(t,e)}off(t,e){return this.emitter.off(t,e)}setScroll(t){this.isHorizontal?this.rootElement.scrollLeft=t:this.rootElement.scrollTop=t}onVirtualScroll=({deltaX:t,deltaY:e,event:i})=>{if(i.ctrlKey)return;const s=i.type.includes("touch"),o=i.type.includes("wheel");if("both"===this.options.gestureOrientation&&0===t&&0===e||"vertical"===this.options.gestureOrientation&&0===e||"horizontal"===this.options.gestureOrientation&&0===t||s&&"vertical"===this.options.gestureOrientation&&0===this.scroll&&!this.options.infinite&&e<=0)return;let n=i.composedPath();if(n=n.slice(0,n.indexOf(this.rootElement)),n.find((t=>t.hasAttribute?.("data-lenis-prevent")||s&&t.hasAttribute?.("data-lenis-prevent-touch")||o&&t.hasAttribute?.("data-lenis-prevent-wheel")||t.classList?.contains("lenis"))))return;if(this.isStopped||this.isLocked)return void i.preventDefault();if(this.isSmooth=(this.options.smoothTouch||this.options.syncTouch)&&s||this.options.smoothWheel&&o,!this.isSmooth)return this.isScrolling=!1,void this.animate.stop();i.preventDefault();let r=e;"both"===this.options.gestureOrientation?r=Math.abs(e)>Math.abs(t)?e:t:"horizontal"===this.options.gestureOrientation&&(r=t);const l=s&&this.options.syncTouch,h=s&&"touchend"===i.type&&Math.abs(r)>1;h&&(r=this.velocity*this.options.touchInertiaMultiplier),this.scrollTo(this.targetScroll+r,{programmatic:!1,...l&&{lerp:h?this.syncTouchLerp:this.options.__iosNoInertiaSyncTouchLerp}})};resize(){this.dimensions.resize()}emit(){this.emitter.emit("scroll",this)}onNativeScroll=()=>{if(!this.__preventNextScrollEvent&&!this.isScrolling){const t=this.animatedScroll;this.animatedScroll=this.targetScroll=this.actualScroll,this.velocity=0,this.direction=Math.sign(this.animatedScroll-t),this.emit()}};reset(){this.isLocked=!1,this.isScrolling=!1,this.animatedScroll=this.targetScroll=this.actualScroll,this.velocity=0,this.animate.stop()}start(){this.isStopped=!1,this.reset()}stop(){this.isStopped=!0,this.animate.stop(),this.reset()}raf(t){const e=t-(this.time||t);this.time=t,this.animate.advance(.001*e)}scrollTo(e,{offset:i=0,immediate:s=!1,lock:o=!1,duration:n=this.options.duration,easing:r=this.options.easing,lerp:l=!n&&this.options.lerp,onComplete:h=null,force:a=!1,programmatic:c=!0}={}){if(!this.isStopped&&!this.isLocked||a){if(["top","left","start"].includes(e))e=0;else if(["bottom","right","end"].includes(e))e=this.limit;else{let t;if("string"==typeof e?t=document.querySelector(e):e?.nodeType&&(t=e),t){if(this.options.wrapper!==window){const t=this.options.wrapper.getBoundingClientRect();i-=this.isHorizontal?t.left:t.top}const s=t.getBoundingClientRect();e=(this.isHorizontal?s.left:s.top)+this.animatedScroll}}if("number"==typeof e){if(e+=i,e=Math.round(e),this.options.infinite?c&&(this.targetScroll=this.animatedScroll=this.scroll):e=t(0,e,this.limit),s)return this.animatedScroll=this.targetScroll=e,this.setScroll(this.scroll),this.reset(),void h?.(this);if(!c){if(e===this.targetScroll)return;this.targetScroll=e}this.animate.fromTo(this.animatedScroll,e,{duration:n,easing:r,lerp:l,onStart:()=>{o&&(this.isLocked=!0),this.isScrolling=!0},onUpdate:(t,e)=>{this.isScrolling=!0,this.velocity=t-this.animatedScroll,this.direction=Math.sign(this.velocity),this.animatedScroll=t,this.setScroll(this.scroll),c&&(this.targetScroll=t),e||this.emit(),e&&(this.reset(),this.emit(),h?.(this),this.__preventNextScrollEvent=!0,requestAnimationFrame((()=>{delete this.__preventNextScrollEvent})))}})}}}get rootElement(){return this.options.wrapper===window?document.documentElement:this.options.wrapper}get limit(){return 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(){return this.options.infinite?(t=this.animatedScroll,e=this.limit,(t%e+e)%e):this.animatedScroll;var t,e}get progress(){return 0===this.limit?1:this.scroll/this.limit}get isSmooth(){return this.__isSmooth}set isSmooth(t){this.__isSmooth!==t&&(this.__isSmooth=t,this.toggleClass("lenis-smooth",t))}get isScrolling(){return this.__isScrolling}set isScrolling(t){this.__isScrolling!==t&&(this.__isScrolling=t,this.toggleClass("lenis-scrolling",t))}get isStopped(){return this.__isStopped}set isStopped(t){this.__isStopped!==t&&(this.__isStopped=t,this.toggleClass("lenis-stopped",t))}get isLocked(){return this.__isLocked}set isLocked(t){this.__isLocked!==t&&(this.__isLocked=t,this.toggleClass("lenis-locked",t))}get className(){let t="lenis";return this.isStopped&&(t+=" lenis-stopped"),this.isLocked&&(t+=" lenis-locked"),this.isScrolling&&(t+=" lenis-scrolling"),this.isSmooth&&(t+=" lenis-smooth"),t}toggleClass(t,e){this.rootElement.classList.toggle(t,e),this.emitter.emit("className change",this)}}; +"use strict";function t(t,e,i){return Math.max(t,Math.min(e,i))}class Animate{advance(e){if(!this.isRunning)return;let i=!1;if(this.lerp)this.value=(s=this.value,o=this.to,n=60*this.lerp,r=e,function(t,e,i){return(1-i)*t+i*e}(s,o,1-Math.exp(-n*r))),Math.round(this.value)===this.to&&(this.value=this.to,i=!0);else{this.currentTime+=e;const s=t(0,this.currentTime/this.duration,1);i=s>=1;const o=i?1:this.easing(s);this.value=this.from+(this.to-this.from)*o}var s,o,n,r;this.onUpdate?.(this.value,i),i&&this.stop()}stop(){this.isRunning=!1}fromTo(t,e,{lerp:i=.1,duration:s=1,easing:o=(t=>t),onStart:n,onUpdate:r}){this.from=this.value=t,this.to=e,this.lerp=i,this.duration=s,this.easing=o,this.currentTime=0,this.isRunning=!0,n?.(),this.onUpdate=r}}class Dimensions{constructor({wrapper:t,content:e,autoResize:i=!0}={}){if(this.wrapper=t,this.content=e,i){const t=function(t,e){let i;return function(){let s=arguments,o=this;clearTimeout(i),i=setTimeout((function(){t.apply(o,s)}),e)}}(this.resize,250);this.wrapper!==window&&(this.wrapperResizeObserver=new ResizeObserver(t),this.wrapperResizeObserver.observe(this.wrapper)),this.contentResizeObserver=new ResizeObserver(t),this.contentResizeObserver.observe(this.content)}this.resize()}destroy(){this.wrapperResizeObserver?.disconnect(),this.contentResizeObserver?.disconnect()}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.scrollHeight=this.content.scrollHeight,this.scrollWidth=this.content.scrollWidth};get limit(){return{x:this.scrollWidth-this.width,y:this.scrollHeight-this.height}}}class Emitter{constructor(){this.events={}}emit(t,...e){let i=this.events[t]||[];for(let t=0,s=i.length;t{this.events[t]=this.events[t]?.filter((t=>e!==t))}}off(t,e){this.events[t]=this.events[t]?.filter((t=>e!==t))}destroy(){this.events={}}}class VirtualScroll{constructor(t,{wheelMultiplier:e=1,touchMultiplier:i=2,normalizeWheel:s=!1}){this.element=t,this.wheelMultiplier=e,this.touchMultiplier=i,this.normalizeWheel=s,this.touchStart={x:null,y:null},this.emitter=new Emitter,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,e){return this.emitter.on(t,e)}destroy(){this.emitter.destroy(),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=>{const{clientX:e,clientY:i}=t.targetTouches?t.targetTouches[0]:t;this.touchStart.x=e,this.touchStart.y=i,this.lastDelta={x:0,y:0},this.emitter.emit("scroll",{deltaX:0,deltaY:0,event:t})};onTouchMove=t=>{const{clientX:e,clientY:i}=t.targetTouches?t.targetTouches[0]:t,s=-(e-this.touchStart.x)*this.touchMultiplier,o=-(i-this.touchStart.y)*this.touchMultiplier;this.touchStart.x=e,this.touchStart.y=i,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=e=>{let{deltaX:i,deltaY:s}=e;this.normalizeWheel&&(i=t(-100,i,100),s=t(-100,s,100)),i*=this.wheelMultiplier,s*=this.wheelMultiplier,this.emitter.emit("scroll",{deltaX:i,deltaY:s,event:e})}}module.exports=class Lenis{constructor({wrapper:t=window,content:e=document.documentElement,wheelEventsTarget:i=t,eventsTarget:s=i,smoothWheel:o=!0,smoothTouch:n=!1,syncTouch:r=!1,syncTouchLerp:l=.075,touchInertiaMultiplier:h=35,duration:a,easing:c=(t=>Math.min(1,1.001-Math.pow(2,-10*t))),lerp:u=!a&&.1,infinite:p=!1,orientation:m="vertical",gestureOrientation:d="vertical",touchMultiplier:g=1,wheelMultiplier:v=1,normalizeWheel:S=!1,autoResize:w=!0}={}){window.lenisVersion="1.0.29",t!==document.documentElement&&t!==document.body||(t=window),this.options={wrapper:t,content:e,wheelEventsTarget:i,eventsTarget:s,smoothWheel:o,smoothTouch:n,syncTouch:r,syncTouchLerp:l,touchInertiaMultiplier:h,duration:a,easing:c,lerp:u,infinite:p,gestureOrientation:d,orientation:m,touchMultiplier:g,wheelMultiplier:v,normalizeWheel:S,autoResize:w},this.animate=new Animate,this.emitter=new Emitter,this.dimensions=new Dimensions({wrapper:t,content:e,autoResize:w}),this.toggleClass("lenis",!0),this.velocity=0,this.isLocked=!1,this.isStopped=!1,this.isSmooth=r||o||n,this.isScrolling=!1,this.targetScroll=this.animatedScroll=this.actualScroll,this.options.wrapper.addEventListener("scroll",this.onNativeScroll,{passive:!1}),this.virtualScroll=new VirtualScroll(s,{touchMultiplier:g,wheelMultiplier:v,normalizeWheel:S}),this.virtualScroll.on("scroll",this.onVirtualScroll)}destroy(){this.emitter.destroy(),this.options.wrapper.removeEventListener("scroll",this.onNativeScroll,{passive:!1}),this.virtualScroll.destroy(),this.dimensions.destroy(),this.toggleClass("lenis",!1),this.toggleClass("lenis-smooth",!1),this.toggleClass("lenis-scrolling",!1),this.toggleClass("lenis-stopped",!1),this.toggleClass("lenis-locked",!1)}on(t,e){return this.emitter.on(t,e)}off(t,e){return this.emitter.off(t,e)}setScroll(t){this.isHorizontal?this.rootElement.scrollLeft=t:this.rootElement.scrollTop=t}onVirtualScroll=({deltaX:t,deltaY:e,event:i})=>{if(i.ctrlKey)return;const s=i.type.includes("touch"),o=i.type.includes("wheel");if((this.options.smoothTouch||this.options.syncTouch)&&s&&"touchstart"===i.type)return void this.reset();const n=0===t&&0===e,r="vertical"===this.options.gestureOrientation&&0===e||"horizontal"===this.options.gestureOrientation&&0===t;if(n||r)return;let l=i.composedPath();if(l=l.slice(0,l.indexOf(this.rootElement)),l.find((t=>t.hasAttribute?.("data-lenis-prevent")||s&&t.hasAttribute?.("data-lenis-prevent-touch")||o&&t.hasAttribute?.("data-lenis-prevent-wheel")||t.classList?.contains("lenis"))))return;if(this.isStopped||this.isLocked)return void i.preventDefault();if(this.isSmooth=(this.options.smoothTouch||this.options.syncTouch)&&s||this.options.smoothWheel&&o,!this.isSmooth)return this.isScrolling=!1,void this.animate.stop();i.preventDefault();let h=e;"both"===this.options.gestureOrientation?h=Math.abs(e)>Math.abs(t)?e:t:"horizontal"===this.options.gestureOrientation&&(h=t);const a=s&&this.options.syncTouch,c=s&&"touchend"===i.type&&Math.abs(h)>5;c&&(h=this.velocity*this.options.touchInertiaMultiplier),this.scrollTo(this.targetScroll+h,{programmatic:!1,...a?{lerp:c?this.options.syncTouchLerp:1}:{lerp:this.options.lerp,duration:this.options.duration,easing:this.options.easing}})};resize(){this.dimensions.resize()}emit(){this.emitter.emit("scroll",this)}onNativeScroll=()=>{if(!this.__preventNextScrollEvent&&!this.isScrolling){const t=this.animatedScroll;this.animatedScroll=this.targetScroll=this.actualScroll,this.velocity=0,this.direction=Math.sign(this.animatedScroll-t),this.emit()}};reset(){this.isLocked=!1,this.isScrolling=!1,this.animatedScroll=this.targetScroll=this.actualScroll,this.velocity=0,this.animate.stop()}start(){this.isStopped=!1,this.reset()}stop(){this.isStopped=!0,this.animate.stop(),this.reset()}raf(t){const e=t-(this.time||t);this.time=t,this.animate.advance(.001*e)}scrollTo(e,{offset:i=0,immediate:s=!1,lock:o=!1,duration:n=this.options.duration,easing:r=this.options.easing,lerp:l=!n&&this.options.lerp,onComplete:h=null,force:a=!1,programmatic:c=!0}={}){if(!this.isStopped&&!this.isLocked||a){if(["top","left","start"].includes(e))e=0;else if(["bottom","right","end"].includes(e))e=this.limit;else{let t;if("string"==typeof e?t=document.querySelector(e):e?.nodeType&&(t=e),t){if(this.options.wrapper!==window){const t=this.options.wrapper.getBoundingClientRect();i-=this.isHorizontal?t.left:t.top}const s=t.getBoundingClientRect();e=(this.isHorizontal?s.left:s.top)+this.animatedScroll}}if("number"==typeof e){if(e+=i,e=Math.round(e),this.options.infinite?c&&(this.targetScroll=this.animatedScroll=this.scroll):e=t(0,e,this.limit),s)return this.animatedScroll=this.targetScroll=e,this.setScroll(this.scroll),this.reset(),void h?.(this);if(!c){if(e===this.targetScroll)return;this.targetScroll=e}this.animate.fromTo(this.animatedScroll,e,{duration:n,easing:r,lerp:l,onStart:()=>{o&&(this.isLocked=!0),this.isScrolling=!0},onUpdate:(t,e)=>{this.isScrolling=!0,this.velocity=t-this.animatedScroll,this.direction=Math.sign(this.velocity),this.animatedScroll=t,this.setScroll(this.scroll),c&&(this.targetScroll=t),e||this.emit(),e&&(this.reset(),this.emit(),h?.(this),this.__preventNextScrollEvent=!0,requestAnimationFrame((()=>{delete this.__preventNextScrollEvent})))}})}}}get rootElement(){return this.options.wrapper===window?document.documentElement:this.options.wrapper}get limit(){return 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(){return this.options.infinite?(t=this.animatedScroll,e=this.limit,(t%e+e)%e):this.animatedScroll;var t,e}get progress(){return 0===this.limit?1:this.scroll/this.limit}get isSmooth(){return this.__isSmooth}set isSmooth(t){this.__isSmooth!==t&&(this.__isSmooth=t,this.toggleClass("lenis-smooth",t))}get isScrolling(){return this.__isScrolling}set isScrolling(t){this.__isScrolling!==t&&(this.__isScrolling=t,this.toggleClass("lenis-scrolling",t))}get isStopped(){return this.__isStopped}set isStopped(t){this.__isStopped!==t&&(this.__isStopped=t,this.toggleClass("lenis-stopped",t))}get isLocked(){return this.__isLocked}set isLocked(t){this.__isLocked!==t&&(this.__isLocked=t,this.toggleClass("lenis-locked",t))}get className(){let t="lenis";return this.isStopped&&(t+=" lenis-stopped"),this.isLocked&&(t+=" lenis-locked"),this.isScrolling&&(t+=" lenis-scrolling"),this.isSmooth&&(t+=" lenis-smooth"),t}toggleClass(t,e){this.rootElement.classList.toggle(t,e),this.emitter.emit("className change",this)}}; //# sourceMappingURL=lenis.cjs.js.map diff --git a/packages/lenis/dist/lenis.cjs.js.map b/packages/lenis/dist/lenis.cjs.js.map index 98b35c07..35a68d93 100644 --- a/packages/lenis/dist/lenis.cjs.js.map +++ b/packages/lenis/dist/lenis.cjs.js.map @@ -1 +1 @@ -{"version":3,"file":"lenis.cjs.js","sources":["../src/maths.js","../src/animate.js","../src/dimensions.js","../src/debounce.js","../src/emitter.js","../src/virtual-scroll.js","../src/index.js"],"sourcesContent":["// Clamp a value between a minimum and maximum value\r\nexport function clamp(min, input, max) {\r\n return Math.max(min, Math.min(input, max))\r\n}\r\n\r\n// Truncate a floating-point number to a specified number of decimal places\r\nexport function truncate(value, decimals = 0) {\r\n return parseFloat(value.toFixed(decimals))\r\n}\r\n\r\n// Linearly interpolate between two values using an amount (0 <= t <= 1)\r\nexport function lerp(x, y, t) {\r\n return (1 - t) * x + t * y\r\n}\r\n\r\n// http://www.rorydriscoll.com/2016/03/07/frame-rate-independent-damping-using-lerp/\r\nexport function damp(x, y, lambda, dt) {\r\n return lerp(x, y, 1 - Math.exp(-lambda * dt))\r\n}\r\n\r\n// Calculate the modulo of the dividend and divisor while keeping the result within the same sign as the divisor\r\n// https://anguscroll.com/just/just-modulo\r\nexport function modulo(n, d) {\r\n return ((n % d) + d) % d\r\n}\r\n","import { clamp, damp } from './maths'\r\n\r\n// Animate class to handle value animations with lerping or easing\r\nexport class Animate {\r\n // Advance the animation by the given delta time\r\n advance(deltaTime) {\r\n if (!this.isRunning) return\r\n\r\n let completed = false\r\n\r\n if (this.lerp) {\r\n this.value = damp(this.value, this.to, this.lerp * 60, deltaTime)\r\n if (Math.round(this.value) === this.to) {\r\n this.value = this.to\r\n completed = true\r\n }\r\n } else {\r\n this.currentTime += deltaTime\r\n const linearProgress = clamp(0, this.currentTime / this.duration, 1)\r\n\r\n completed = linearProgress >= 1\r\n const easedProgress = completed ? 1 : this.easing(linearProgress)\r\n this.value = this.from + (this.to - this.from) * easedProgress\r\n }\r\n\r\n // Call the onUpdate callback with the current value and completed status\r\n this.onUpdate?.(this.value, completed)\r\n\r\n if (completed) {\r\n this.stop()\r\n }\r\n }\r\n\r\n // Stop the animation\r\n stop() {\r\n this.isRunning = false\r\n }\r\n\r\n // Set up the animation from a starting value to an ending value\r\n // with optional parameters for lerping, duration, easing, and onUpdate callback\r\n fromTo(\r\n from,\r\n to,\r\n { lerp = 0.1, duration = 1, easing = (t) => t, onStart, onUpdate }\r\n ) {\r\n this.from = this.value = from\r\n this.to = to\r\n this.lerp = lerp\r\n this.duration = duration\r\n this.easing = easing\r\n this.currentTime = 0\r\n this.isRunning = true\r\n\r\n onStart?.()\r\n this.onUpdate = onUpdate\r\n }\r\n}\r\n","import { debounce } from './debounce'\r\n\r\nexport class Dimensions {\r\n constructor({ wrapper, content, autoResize = true } = {}) {\r\n this.wrapper = wrapper\r\n this.content = content\r\n\r\n if (autoResize) {\r\n const resize = debounce(this.resize, 250)\r\n\r\n if (this.wrapper !== window) {\r\n this.wrapperResizeObserver = new ResizeObserver(resize)\r\n this.wrapperResizeObserver.observe(this.wrapper)\r\n }\r\n\r\n this.contentResizeObserver = new ResizeObserver(resize)\r\n this.contentResizeObserver.observe(this.content)\r\n }\r\n\r\n this.resize()\r\n }\r\n\r\n destroy() {\r\n this.wrapperResizeObserver?.disconnect()\r\n this.contentResizeObserver?.disconnect()\r\n }\r\n\r\n resize = () => {\r\n this.onWrapperResize()\r\n this.onContentResize()\r\n }\r\n\r\n onWrapperResize = () => {\r\n if (this.wrapper === window) {\r\n this.width = window.innerWidth\r\n this.height = window.innerHeight\r\n } else {\r\n this.width = this.wrapper.clientWidth\r\n this.height = this.wrapper.clientHeight\r\n }\r\n }\r\n\r\n onContentResize = () => {\r\n this.scrollHeight = this.content.scrollHeight\r\n this.scrollWidth = this.content.scrollWidth\r\n }\r\n\r\n get limit() {\r\n return {\r\n x: this.scrollWidth - this.width,\r\n y: this.scrollHeight - this.height,\r\n }\r\n }\r\n}\r\n","export function debounce(callback, delay) {\r\n let timer\r\n return function () {\r\n let args = arguments\r\n let context = this\r\n clearTimeout(timer)\r\n timer = setTimeout(function () {\r\n callback.apply(context, args)\r\n }, delay)\r\n }\r\n}\r\n","export class Emitter {\r\n constructor() {\r\n this.events = {}\r\n }\r\n\r\n emit(event, ...args) {\r\n let callbacks = this.events[event] || []\r\n for (let i = 0, length = callbacks.length; i < length; i++) {\r\n callbacks[i](...args)\r\n }\r\n }\r\n\r\n on(event, cb) {\r\n // Add the callback to the event's callback list, or create a new list with the callback\r\n this.events[event]?.push(cb) || (this.events[event] = [cb])\r\n\r\n // Return an unsubscribe function\r\n return () => {\r\n this.events[event] = this.events[event]?.filter((i) => cb !== i)\r\n }\r\n }\r\n\r\n off(event, callback) {\r\n this.events[event] = this.events[event]?.filter((i) => callback !== i)\r\n }\r\n\r\n destroy() {\r\n this.events = {}\r\n }\r\n}\r\n","import { Emitter } from './emitter'\r\nimport { clamp } from './maths'\r\n\r\nexport class VirtualScroll {\r\n constructor(\r\n element,\r\n { wheelMultiplier = 1, touchMultiplier = 2, normalizeWheel = false }\r\n ) {\r\n this.element = element\r\n this.wheelMultiplier = wheelMultiplier\r\n this.touchMultiplier = touchMultiplier\r\n this.normalizeWheel = normalizeWheel\r\n\r\n this.touchStart = {\r\n x: null,\r\n y: null,\r\n }\r\n\r\n this.emitter = new Emitter()\r\n\r\n this.element.addEventListener('wheel', this.onWheel, { passive: false })\r\n this.element.addEventListener('touchstart', this.onTouchStart, {\r\n passive: false,\r\n })\r\n this.element.addEventListener('touchmove', this.onTouchMove, {\r\n passive: false,\r\n })\r\n this.element.addEventListener('touchend', this.onTouchEnd, {\r\n passive: false,\r\n })\r\n }\r\n\r\n // Add an event listener for the given event and callback\r\n on(event, callback) {\r\n return this.emitter.on(event, callback)\r\n }\r\n\r\n // Remove all event listeners and clean up\r\n destroy() {\r\n this.emitter.destroy()\r\n\r\n this.element.removeEventListener('wheel', this.onWheel, {\r\n passive: false,\r\n })\r\n this.element.removeEventListener('touchstart', this.onTouchStart, {\r\n passive: false,\r\n })\r\n this.element.removeEventListener('touchmove', this.onTouchMove, {\r\n passive: false,\r\n })\r\n this.element.removeEventListener('touchend', this.onTouchEnd, {\r\n passive: false,\r\n })\r\n }\r\n\r\n // Event handler for 'touchstart' event\r\n onTouchStart = (event) => {\r\n const { clientX, clientY } = event.targetTouches\r\n ? event.targetTouches[0]\r\n : event\r\n\r\n this.touchStart.x = clientX\r\n this.touchStart.y = clientY\r\n\r\n this.lastDelta = {\r\n x: 0,\r\n y: 0,\r\n }\r\n }\r\n\r\n // Event handler for 'touchmove' event\r\n onTouchMove = (event) => {\r\n const { clientX, clientY } = event.targetTouches\r\n ? event.targetTouches[0]\r\n : event\r\n\r\n const deltaX = -(clientX - this.touchStart.x) * this.touchMultiplier\r\n const deltaY = -(clientY - this.touchStart.y) * this.touchMultiplier\r\n\r\n this.touchStart.x = clientX\r\n this.touchStart.y = clientY\r\n\r\n this.lastDelta = {\r\n x: deltaX,\r\n y: deltaY,\r\n }\r\n\r\n this.emitter.emit('scroll', {\r\n deltaX,\r\n deltaY,\r\n event,\r\n })\r\n }\r\n\r\n onTouchEnd = (event) => {\r\n this.emitter.emit('scroll', {\r\n deltaX: this.lastDelta.x,\r\n deltaY: this.lastDelta.y,\r\n event,\r\n })\r\n }\r\n\r\n // Event handler for 'wheel' event\r\n onWheel = (event) => {\r\n let { deltaX, deltaY } = event\r\n\r\n if (this.normalizeWheel) {\r\n deltaX = clamp(-100, deltaX, 100)\r\n deltaY = clamp(-100, deltaY, 100)\r\n }\r\n\r\n deltaX *= this.wheelMultiplier\r\n deltaY *= this.wheelMultiplier\r\n\r\n this.emitter.emit('scroll', { deltaX, deltaY, event })\r\n }\r\n}\r\n","import { version } from '../package.json'\r\nimport { Animate } from './animate'\r\nimport { Dimensions } from './dimensions'\r\nimport { Emitter } from './emitter'\r\nimport { clamp, modulo } from './maths'\r\nimport { VirtualScroll } from './virtual-scroll'\r\n\r\n// Technical explanation\r\n// - listen to 'wheel' events\r\n// - prevent 'wheel' event to prevent scroll\r\n// - normalize wheel delta\r\n// - add delta to targetScroll\r\n// - animate scroll to targetScroll (smooth context)\r\n// - if animation is not running, listen to 'scroll' events (native context)\r\n\r\nexport default class Lenis {\r\n // isScrolling = true when scroll is animating\r\n // isStopped = true if user should not be able to scroll - enable/disable programmatically\r\n // isSmooth = true if scroll should be animated\r\n // isLocked = same as isStopped but enabled/disabled when scroll reaches target\r\n\r\n /**\r\n * @typedef {(t: number) => number} EasingFunction\r\n * @typedef {'vertical' | 'horizontal'} Orientation\r\n * @typedef {'vertical' | 'horizontal' | 'both'} GestureOrientation\r\n *\r\n * @typedef LenisOptions\r\n * @property {Window | HTMLElement} [wrapper]\r\n * @property {HTMLElement} [content]\r\n * @property {Window | HTMLElement} [wheelEventsTarget] // deprecated\r\n * @property {Window | HTMLElement} [eventsTarget]\r\n * @property {boolean} [smoothWheel]\r\n * @property {boolean} [smoothTouch]\r\n * @property {boolean} [syncTouch]\r\n * @property {number} [syncTouchLerp]\r\n * @property {number} [__iosNoInertiaSyncTouchLerp]\r\n * @property {number} [touchInertiaMultiplier]\r\n * @property {number} [duration]\r\n * @property {EasingFunction} [easing]\r\n * @property {number} [lerp]\r\n * @property {boolean} [infinite]\r\n * @property {Orientation} [orientation]\r\n * @property {GestureOrientation} [gestureOrientation]\r\n * @property {number} [touchMultiplier]\r\n * @property {number} [wheelMultiplier]\r\n * @property {boolean} [normalizeWheel]\r\n * @property {boolean} [autoResize]\r\n *\r\n * @param {LenisOptions}\r\n */\r\n constructor({\r\n wrapper = window,\r\n content = document.documentElement,\r\n wheelEventsTarget = wrapper, // deprecated\r\n eventsTarget = wheelEventsTarget,\r\n smoothWheel = true,\r\n smoothTouch = false,\r\n syncTouch = false,\r\n syncTouchLerp = 0.1,\r\n __iosNoInertiaSyncTouchLerp = 0.4, // should be 1 but had to leave 0.4 for iOS (testing purpose)\r\n touchInertiaMultiplier = 35,\r\n duration, // in seconds\r\n easing = (t) => Math.min(1, 1.001 - Math.pow(2, -10 * t)),\r\n lerp = !duration && 0.1,\r\n infinite = false,\r\n orientation = 'vertical', // vertical, horizontal\r\n gestureOrientation = 'vertical', // vertical, horizontal, both\r\n touchMultiplier = 1,\r\n wheelMultiplier = 1,\r\n normalizeWheel = false,\r\n autoResize = true,\r\n } = {}) {\r\n window.lenisVersion = version\r\n\r\n // if wrapper is html or body, fallback to window\r\n if (wrapper === document.documentElement || wrapper === document.body) {\r\n wrapper = window\r\n }\r\n\r\n this.options = {\r\n wrapper,\r\n content,\r\n wheelEventsTarget,\r\n eventsTarget,\r\n smoothWheel,\r\n smoothTouch,\r\n syncTouch,\r\n syncTouchLerp,\r\n __iosNoInertiaSyncTouchLerp,\r\n touchInertiaMultiplier,\r\n duration,\r\n easing,\r\n lerp,\r\n infinite,\r\n gestureOrientation,\r\n orientation,\r\n touchMultiplier,\r\n wheelMultiplier,\r\n normalizeWheel,\r\n autoResize,\r\n }\r\n\r\n this.animate = new Animate()\r\n this.emitter = new Emitter()\r\n this.dimensions = new Dimensions({ wrapper, content, autoResize })\r\n this.toggleClass('lenis', true)\r\n\r\n this.velocity = 0\r\n this.isLocked = false\r\n this.isStopped = false\r\n this.isSmooth = syncTouch || smoothWheel || smoothTouch\r\n this.isScrolling = false\r\n this.targetScroll = this.animatedScroll = this.actualScroll\r\n\r\n this.options.wrapper.addEventListener('scroll', this.onNativeScroll, {\r\n passive: false,\r\n })\r\n\r\n this.virtualScroll = new VirtualScroll(eventsTarget, {\r\n touchMultiplier,\r\n wheelMultiplier,\r\n normalizeWheel,\r\n })\r\n this.virtualScroll.on('scroll', this.onVirtualScroll)\r\n }\r\n\r\n destroy() {\r\n this.emitter.destroy()\r\n\r\n this.options.wrapper.removeEventListener('scroll', this.onNativeScroll, {\r\n passive: false,\r\n })\r\n\r\n this.virtualScroll.destroy()\r\n this.dimensions.destroy()\r\n\r\n this.toggleClass('lenis', false)\r\n this.toggleClass('lenis-smooth', false)\r\n this.toggleClass('lenis-scrolling', false)\r\n this.toggleClass('lenis-stopped', false)\r\n this.toggleClass('lenis-locked', false)\r\n }\r\n\r\n on(event, callback) {\r\n return this.emitter.on(event, callback)\r\n }\r\n\r\n off(event, callback) {\r\n return this.emitter.off(event, callback)\r\n }\r\n\r\n setScroll(scroll) {\r\n // apply scroll value immediately\r\n if (this.isHorizontal) {\r\n this.rootElement.scrollLeft = scroll\r\n } else {\r\n this.rootElement.scrollTop = scroll\r\n }\r\n }\r\n\r\n onVirtualScroll = ({ deltaX, deltaY, event }) => {\r\n // keep zoom feature\r\n if (event.ctrlKey) return\r\n\r\n const isTouch = event.type.includes('touch')\r\n const isWheel = event.type.includes('wheel')\r\n\r\n if (\r\n (this.options.gestureOrientation === 'both' &&\r\n deltaX === 0 &&\r\n deltaY === 0) || // \"touchend\" events prevents \"click\"\r\n (this.options.gestureOrientation === 'vertical' && deltaY === 0) || // trackpad previous/next page gesture\r\n (this.options.gestureOrientation === 'horizontal' && deltaX === 0) ||\r\n (isTouch &&\r\n this.options.gestureOrientation === 'vertical' &&\r\n this.scroll === 0 &&\r\n !this.options.infinite &&\r\n deltaY <= 0) // touch pull to refresh\r\n )\r\n return\r\n\r\n // catch if scrolling on nested scroll elements\r\n let composedPath = event.composedPath()\r\n composedPath = composedPath.slice(0, composedPath.indexOf(this.rootElement)) // remove parents elements\r\n\r\n if (\r\n !!composedPath.find(\r\n (node) =>\r\n node.hasAttribute?.('data-lenis-prevent') ||\r\n (isTouch && node.hasAttribute?.('data-lenis-prevent-touch')) ||\r\n (isWheel && node.hasAttribute?.('data-lenis-prevent-wheel')) ||\r\n node.classList?.contains('lenis') // nested lenis instance\r\n )\r\n )\r\n return\r\n\r\n if (this.isStopped || this.isLocked) {\r\n event.preventDefault()\r\n return\r\n }\r\n\r\n this.isSmooth =\r\n ((this.options.smoothTouch || this.options.syncTouch) && isTouch) ||\r\n (this.options.smoothWheel && isWheel)\r\n\r\n if (!this.isSmooth) {\r\n this.isScrolling = false\r\n this.animate.stop()\r\n return\r\n }\r\n\r\n event.preventDefault()\r\n\r\n let delta = deltaY\r\n if (this.options.gestureOrientation === 'both') {\r\n delta = Math.abs(deltaY) > Math.abs(deltaX) ? deltaY : deltaX\r\n } else if (this.options.gestureOrientation === 'horizontal') {\r\n delta = deltaX\r\n }\r\n\r\n const syncTouch = isTouch && this.options.syncTouch\r\n const isTouchEnd = isTouch && event.type === 'touchend'\r\n const hasTouchInertia = isTouchEnd && Math.abs(delta) > 1\r\n if (hasTouchInertia) {\r\n delta = this.velocity * this.options.touchInertiaMultiplier\r\n }\r\n\r\n this.scrollTo(this.targetScroll + delta, {\r\n programmatic: false,\r\n ...(syncTouch && {\r\n lerp: hasTouchInertia\r\n ? this.syncTouchLerp\r\n : this.options.__iosNoInertiaSyncTouchLerp,\r\n }),\r\n })\r\n }\r\n\r\n resize() {\r\n this.dimensions.resize()\r\n }\r\n\r\n emit() {\r\n this.emitter.emit('scroll', this)\r\n }\r\n\r\n onNativeScroll = () => {\r\n if (this.__preventNextScrollEvent) return\r\n\r\n if (!this.isScrolling) {\r\n const lastScroll = this.animatedScroll\r\n this.animatedScroll = this.targetScroll = this.actualScroll\r\n this.velocity = 0\r\n this.direction = Math.sign(this.animatedScroll - lastScroll)\r\n this.emit()\r\n }\r\n }\r\n\r\n reset() {\r\n this.isLocked = false\r\n this.isScrolling = false\r\n this.animatedScroll = this.targetScroll = this.actualScroll\r\n this.velocity = 0\r\n this.animate.stop()\r\n }\r\n\r\n start() {\r\n this.isStopped = false\r\n\r\n this.reset()\r\n }\r\n\r\n stop() {\r\n this.isStopped = true\r\n this.animate.stop()\r\n\r\n this.reset()\r\n }\r\n\r\n raf(time) {\r\n const deltaTime = time - (this.time || time)\r\n this.time = time\r\n\r\n this.animate.advance(deltaTime * 0.001)\r\n }\r\n\r\n scrollTo(\r\n target,\r\n {\r\n offset = 0,\r\n immediate = false,\r\n lock = false,\r\n duration = this.options.duration,\r\n easing = this.options.easing,\r\n lerp = !duration && this.options.lerp,\r\n onComplete = null,\r\n force = false, // scroll even if stopped\r\n programmatic = true, // called from outside of the class\r\n } = {}\r\n ) {\r\n if ((this.isStopped || this.isLocked) && !force) return\r\n\r\n // keywords\r\n if (['top', 'left', 'start'].includes(target)) {\r\n target = 0\r\n } else if (['bottom', 'right', 'end'].includes(target)) {\r\n target = this.limit\r\n } else {\r\n let node\r\n\r\n if (typeof target === 'string') {\r\n // CSS selector\r\n node = document.querySelector(target)\r\n } else if (target?.nodeType) {\r\n // Node element\r\n node = target\r\n }\r\n\r\n if (node) {\r\n if (this.options.wrapper !== window) {\r\n // nested scroll offset correction\r\n const wrapperRect = this.options.wrapper.getBoundingClientRect()\r\n offset -= this.isHorizontal ? wrapperRect.left : wrapperRect.top\r\n }\r\n\r\n const rect = node.getBoundingClientRect()\r\n\r\n target =\r\n (this.isHorizontal ? rect.left : rect.top) + this.animatedScroll\r\n }\r\n }\r\n\r\n if (typeof target !== 'number') return\r\n\r\n target += offset\r\n target = Math.round(target)\r\n\r\n if (this.options.infinite) {\r\n if (programmatic) {\r\n this.targetScroll = this.animatedScroll = this.scroll\r\n }\r\n } else {\r\n target = clamp(0, target, this.limit)\r\n }\r\n\r\n if (immediate) {\r\n this.animatedScroll = this.targetScroll = target\r\n this.setScroll(this.scroll)\r\n this.reset()\r\n onComplete?.(this)\r\n return\r\n }\r\n\r\n if (!programmatic) {\r\n if (target === this.targetScroll) return\r\n\r\n this.targetScroll = target\r\n }\r\n\r\n this.animate.fromTo(this.animatedScroll, target, {\r\n duration,\r\n easing,\r\n lerp,\r\n onStart: () => {\r\n // started\r\n if (lock) this.isLocked = true\r\n this.isScrolling = true\r\n },\r\n onUpdate: (value, completed) => {\r\n this.isScrolling = true\r\n\r\n // updated\r\n this.velocity = value - this.animatedScroll\r\n this.direction = Math.sign(this.velocity)\r\n\r\n this.animatedScroll = value\r\n this.setScroll(this.scroll)\r\n\r\n if (programmatic) {\r\n // wheel during programmatic should stop it\r\n this.targetScroll = value\r\n }\r\n\r\n if (!completed) this.emit()\r\n\r\n if (completed) {\r\n this.reset()\r\n this.emit()\r\n onComplete?.(this)\r\n\r\n // avoid emitting event twice\r\n this.__preventNextScrollEvent = true\r\n requestAnimationFrame(() => {\r\n delete this.__preventNextScrollEvent\r\n })\r\n }\r\n },\r\n })\r\n }\r\n\r\n get rootElement() {\r\n return this.options.wrapper === window\r\n ? document.documentElement\r\n : this.options.wrapper\r\n }\r\n\r\n get limit() {\r\n return this.dimensions.limit[this.isHorizontal ? 'x' : 'y']\r\n }\r\n\r\n get isHorizontal() {\r\n return this.options.orientation === 'horizontal'\r\n }\r\n\r\n get actualScroll() {\r\n // value browser takes into account\r\n return this.isHorizontal\r\n ? this.rootElement.scrollLeft\r\n : this.rootElement.scrollTop\r\n }\r\n\r\n get scroll() {\r\n return this.options.infinite\r\n ? modulo(this.animatedScroll, this.limit)\r\n : this.animatedScroll\r\n }\r\n\r\n get progress() {\r\n // avoid progress to be NaN\r\n return this.limit === 0 ? 1 : this.scroll / this.limit\r\n }\r\n\r\n get isSmooth() {\r\n return this.__isSmooth\r\n }\r\n\r\n set isSmooth(value) {\r\n if (this.__isSmooth !== value) {\r\n this.__isSmooth = value\r\n this.toggleClass('lenis-smooth', value)\r\n }\r\n }\r\n\r\n get isScrolling() {\r\n return this.__isScrolling\r\n }\r\n\r\n set isScrolling(value) {\r\n if (this.__isScrolling !== value) {\r\n this.__isScrolling = value\r\n this.toggleClass('lenis-scrolling', value)\r\n }\r\n }\r\n\r\n get isStopped() {\r\n return this.__isStopped\r\n }\r\n\r\n set isStopped(value) {\r\n if (this.__isStopped !== value) {\r\n this.__isStopped = value\r\n this.toggleClass('lenis-stopped', value)\r\n }\r\n }\r\n\r\n get isLocked() {\r\n return this.__isLocked\r\n }\r\n\r\n set isLocked(value) {\r\n if (this.__isLocked !== value) {\r\n this.__isLocked = value\r\n this.toggleClass('lenis-locked', value)\r\n }\r\n }\r\n\r\n get className() {\r\n let className = 'lenis'\r\n if (this.isStopped) className += ' lenis-stopped'\r\n if (this.isLocked) className += ' lenis-locked'\r\n if (this.isScrolling) className += ' lenis-scrolling'\r\n if (this.isSmooth) className += ' lenis-smooth'\r\n return className\r\n }\r\n\r\n toggleClass(name, value) {\r\n this.rootElement.classList.toggle(name, value)\r\n this.emitter.emit('className change', this)\r\n }\r\n}\r\n"],"names":["clamp","min","input","max","Math","Animate","advance","deltaTime","this","isRunning","completed","lerp","value","x","y","to","lambda","dt","t","exp","round","currentTime","linearProgress","duration","easedProgress","easing","from","onUpdate","stop","fromTo","onStart","Dimensions","constructor","wrapper","content","autoResize","resize","callback","delay","timer","args","arguments","context","clearTimeout","setTimeout","apply","debounce","window","wrapperResizeObserver","ResizeObserver","observe","contentResizeObserver","destroy","disconnect","onWrapperResize","onContentResize","width","innerWidth","height","innerHeight","clientWidth","clientHeight","scrollHeight","scrollWidth","limit","Emitter","events","emit","event","callbacks","i","length","on","cb","push","filter","off","VirtualScroll","element","wheelMultiplier","touchMultiplier","normalizeWheel","touchStart","emitter","addEventListener","onWheel","passive","onTouchStart","onTouchMove","onTouchEnd","removeEventListener","clientX","clientY","targetTouches","lastDelta","deltaX","deltaY","Lenis","document","documentElement","wheelEventsTarget","eventsTarget","smoothWheel","smoothTouch","syncTouch","syncTouchLerp","__iosNoInertiaSyncTouchLerp","touchInertiaMultiplier","pow","infinite","orientation","gestureOrientation","lenisVersion","body","options","animate","dimensions","toggleClass","velocity","isLocked","isStopped","isSmooth","isScrolling","targetScroll","animatedScroll","actualScroll","onNativeScroll","virtualScroll","onVirtualScroll","setScroll","scroll","isHorizontal","rootElement","scrollLeft","scrollTop","ctrlKey","isTouch","type","includes","isWheel","composedPath","slice","indexOf","find","node","hasAttribute","classList","contains","preventDefault","delta","abs","hasTouchInertia","scrollTo","programmatic","__preventNextScrollEvent","lastScroll","direction","sign","reset","start","raf","time","target","offset","immediate","lock","onComplete","force","querySelector","nodeType","wrapperRect","getBoundingClientRect","left","top","rect","requestAnimationFrame","n","d","progress","__isSmooth","__isScrolling","__isStopped","__isLocked","className","name","toggle"],"mappings":"aACO,SAASA,EAAMC,EAAKC,EAAOC,GAChC,OAAOC,KAAKD,IAAIF,EAAKG,KAAKH,IAAIC,EAAOC,GACvC,CCAO,MAAME,QAEX,OAAAC,CAAQC,GACN,IAA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KACvC"} \ No newline at end of file +{"version":3,"file":"lenis.cjs.js","sources":["../src/maths.js","../src/animate.js","../src/dimensions.js","../src/debounce.js","../src/emitter.js","../src/virtual-scroll.js","../src/index.js"],"sourcesContent":["// Clamp a value between a minimum and maximum value\r\nexport function clamp(min, input, max) {\r\n return Math.max(min, Math.min(input, max))\r\n}\r\n\r\n// Truncate a floating-point number to a specified number of decimal places\r\nexport function truncate(value, decimals = 0) {\r\n return parseFloat(value.toFixed(decimals))\r\n}\r\n\r\n// Linearly interpolate between two values using an amount (0 <= t <= 1)\r\nexport function lerp(x, y, t) {\r\n return (1 - t) * x + t * y\r\n}\r\n\r\n// http://www.rorydriscoll.com/2016/03/07/frame-rate-independent-damping-using-lerp/\r\nexport function damp(x, y, lambda, dt) {\r\n return lerp(x, y, 1 - Math.exp(-lambda * dt))\r\n}\r\n\r\n// Calculate the modulo of the dividend and divisor while keeping the result within the same sign as the divisor\r\n// https://anguscroll.com/just/just-modulo\r\nexport function modulo(n, d) {\r\n return ((n % d) + d) % d\r\n}\r\n","import { clamp, damp } from './maths'\r\n\r\n// Animate class to handle value animations with lerping or easing\r\nexport class Animate {\r\n // Advance the animation by the given delta time\r\n advance(deltaTime) {\r\n if (!this.isRunning) return\r\n\r\n let completed = false\r\n\r\n if (this.lerp) {\r\n this.value = damp(this.value, this.to, this.lerp * 60, deltaTime)\r\n if (Math.round(this.value) === this.to) {\r\n this.value = this.to\r\n completed = true\r\n }\r\n } else {\r\n this.currentTime += deltaTime\r\n const linearProgress = clamp(0, this.currentTime / this.duration, 1)\r\n\r\n completed = linearProgress >= 1\r\n const easedProgress = completed ? 1 : this.easing(linearProgress)\r\n this.value = this.from + (this.to - this.from) * easedProgress\r\n }\r\n\r\n // Call the onUpdate callback with the current value and completed status\r\n this.onUpdate?.(this.value, completed)\r\n\r\n if (completed) {\r\n this.stop()\r\n }\r\n }\r\n\r\n // Stop the animation\r\n stop() {\r\n this.isRunning = false\r\n }\r\n\r\n // Set up the animation from a starting value to an ending value\r\n // with optional parameters for lerping, duration, easing, and onUpdate callback\r\n fromTo(\r\n from,\r\n to,\r\n { lerp = 0.1, duration = 1, easing = (t) => t, onStart, onUpdate }\r\n ) {\r\n this.from = this.value = from\r\n this.to = to\r\n this.lerp = lerp\r\n this.duration = duration\r\n this.easing = easing\r\n this.currentTime = 0\r\n this.isRunning = true\r\n\r\n onStart?.()\r\n this.onUpdate = onUpdate\r\n }\r\n}\r\n","import { debounce } from './debounce'\r\n\r\nexport class Dimensions {\r\n constructor({ wrapper, content, autoResize = true } = {}) {\r\n this.wrapper = wrapper\r\n this.content = content\r\n\r\n if (autoResize) {\r\n const resize = debounce(this.resize, 250)\r\n\r\n if (this.wrapper !== window) {\r\n this.wrapperResizeObserver = new ResizeObserver(resize)\r\n this.wrapperResizeObserver.observe(this.wrapper)\r\n }\r\n\r\n this.contentResizeObserver = new ResizeObserver(resize)\r\n this.contentResizeObserver.observe(this.content)\r\n }\r\n\r\n this.resize()\r\n }\r\n\r\n destroy() {\r\n this.wrapperResizeObserver?.disconnect()\r\n this.contentResizeObserver?.disconnect()\r\n }\r\n\r\n resize = () => {\r\n this.onWrapperResize()\r\n this.onContentResize()\r\n }\r\n\r\n onWrapperResize = () => {\r\n if (this.wrapper === window) {\r\n this.width = window.innerWidth\r\n this.height = window.innerHeight\r\n } else {\r\n this.width = this.wrapper.clientWidth\r\n this.height = this.wrapper.clientHeight\r\n }\r\n }\r\n\r\n onContentResize = () => {\r\n this.scrollHeight = this.content.scrollHeight\r\n this.scrollWidth = this.content.scrollWidth\r\n }\r\n\r\n get limit() {\r\n return {\r\n x: this.scrollWidth - this.width,\r\n y: this.scrollHeight - this.height,\r\n }\r\n }\r\n}\r\n","export function debounce(callback, delay) {\r\n let timer\r\n return function () {\r\n let args = arguments\r\n let context = this\r\n clearTimeout(timer)\r\n timer = setTimeout(function () {\r\n callback.apply(context, args)\r\n }, delay)\r\n }\r\n}\r\n","export class Emitter {\r\n constructor() {\r\n this.events = {}\r\n }\r\n\r\n emit(event, ...args) {\r\n let callbacks = this.events[event] || []\r\n for (let i = 0, length = callbacks.length; i < length; i++) {\r\n callbacks[i](...args)\r\n }\r\n }\r\n\r\n on(event, cb) {\r\n // Add the callback to the event's callback list, or create a new list with the callback\r\n this.events[event]?.push(cb) || (this.events[event] = [cb])\r\n\r\n // Return an unsubscribe function\r\n return () => {\r\n this.events[event] = this.events[event]?.filter((i) => cb !== i)\r\n }\r\n }\r\n\r\n off(event, callback) {\r\n this.events[event] = this.events[event]?.filter((i) => callback !== i)\r\n }\r\n\r\n destroy() {\r\n this.events = {}\r\n }\r\n}\r\n","import { Emitter } from './emitter'\r\nimport { clamp } from './maths'\r\n\r\nexport class VirtualScroll {\r\n constructor(\r\n element,\r\n { wheelMultiplier = 1, touchMultiplier = 2, normalizeWheel = false }\r\n ) {\r\n this.element = element\r\n this.wheelMultiplier = wheelMultiplier\r\n this.touchMultiplier = touchMultiplier\r\n this.normalizeWheel = normalizeWheel\r\n\r\n this.touchStart = {\r\n x: null,\r\n y: null,\r\n }\r\n\r\n this.emitter = new Emitter()\r\n\r\n this.element.addEventListener('wheel', this.onWheel, { passive: false })\r\n this.element.addEventListener('touchstart', this.onTouchStart, {\r\n passive: false,\r\n })\r\n this.element.addEventListener('touchmove', this.onTouchMove, {\r\n passive: false,\r\n })\r\n this.element.addEventListener('touchend', this.onTouchEnd, {\r\n passive: false,\r\n })\r\n }\r\n\r\n // Add an event listener for the given event and callback\r\n on(event, callback) {\r\n return this.emitter.on(event, callback)\r\n }\r\n\r\n // Remove all event listeners and clean up\r\n destroy() {\r\n this.emitter.destroy()\r\n\r\n this.element.removeEventListener('wheel', this.onWheel, {\r\n passive: false,\r\n })\r\n this.element.removeEventListener('touchstart', this.onTouchStart, {\r\n passive: false,\r\n })\r\n this.element.removeEventListener('touchmove', this.onTouchMove, {\r\n passive: false,\r\n })\r\n this.element.removeEventListener('touchend', this.onTouchEnd, {\r\n passive: false,\r\n })\r\n }\r\n\r\n // Event handler for 'touchstart' event\r\n onTouchStart = (event) => {\r\n const { clientX, clientY } = event.targetTouches\r\n ? event.targetTouches[0]\r\n : event\r\n\r\n this.touchStart.x = clientX\r\n this.touchStart.y = clientY\r\n\r\n this.lastDelta = {\r\n x: 0,\r\n y: 0,\r\n }\r\n\r\n this.emitter.emit('scroll', {\r\n deltaX: 0,\r\n deltaY: 0,\r\n event,\r\n })\r\n }\r\n\r\n // Event handler for 'touchmove' event\r\n onTouchMove = (event) => {\r\n const { clientX, clientY } = event.targetTouches\r\n ? event.targetTouches[0]\r\n : event\r\n\r\n const deltaX = -(clientX - this.touchStart.x) * this.touchMultiplier\r\n const deltaY = -(clientY - this.touchStart.y) * this.touchMultiplier\r\n\r\n this.touchStart.x = clientX\r\n this.touchStart.y = clientY\r\n\r\n this.lastDelta = {\r\n x: deltaX,\r\n y: deltaY,\r\n }\r\n\r\n this.emitter.emit('scroll', {\r\n deltaX,\r\n deltaY,\r\n event,\r\n })\r\n }\r\n\r\n onTouchEnd = (event) => {\r\n this.emitter.emit('scroll', {\r\n deltaX: this.lastDelta.x,\r\n deltaY: this.lastDelta.y,\r\n event,\r\n })\r\n }\r\n\r\n // Event handler for 'wheel' event\r\n onWheel = (event) => {\r\n let { deltaX, deltaY } = event\r\n\r\n if (this.normalizeWheel) {\r\n deltaX = clamp(-100, deltaX, 100)\r\n deltaY = clamp(-100, deltaY, 100)\r\n }\r\n\r\n deltaX *= this.wheelMultiplier\r\n deltaY *= this.wheelMultiplier\r\n\r\n this.emitter.emit('scroll', { deltaX, deltaY, event })\r\n }\r\n}\r\n","import { version } from '../package.json'\r\nimport { Animate } from './animate'\r\nimport { Dimensions } from './dimensions'\r\nimport { Emitter } from './emitter'\r\nimport { clamp, modulo } from './maths'\r\nimport { VirtualScroll } from './virtual-scroll'\r\n\r\n// Technical explanation\r\n// - listen to 'wheel' events\r\n// - prevent 'wheel' event to prevent scroll\r\n// - normalize wheel delta\r\n// - add delta to targetScroll\r\n// - animate scroll to targetScroll (smooth context)\r\n// - if animation is not running, listen to 'scroll' events (native context)\r\n\r\nexport default class Lenis {\r\n // isScrolling = true when scroll is animating\r\n // isStopped = true if user should not be able to scroll - enable/disable programmatically\r\n // isSmooth = true if scroll should be animated\r\n // isLocked = same as isStopped but enabled/disabled when scroll reaches target\r\n\r\n /**\r\n * @typedef {(t: number) => number} EasingFunction\r\n * @typedef {'vertical' | 'horizontal'} Orientation\r\n * @typedef {'vertical' | 'horizontal' | 'both'} GestureOrientation\r\n *\r\n * @typedef LenisOptions\r\n * @property {Window | HTMLElement} [wrapper]\r\n * @property {HTMLElement} [content]\r\n * @property {Window | HTMLElement} [wheelEventsTarget] // deprecated\r\n * @property {Window | HTMLElement} [eventsTarget]\r\n * @property {boolean} [smoothWheel]\r\n * @property {boolean} [smoothTouch]\r\n * @property {boolean} [syncTouch]\r\n * @property {number} [syncTouchLerp]\r\n // * @property {number} [__iosNoInertiaSyncTouchLerp]\r\n * @property {number} [touchInertiaMultiplier]\r\n * @property {number} [duration]\r\n * @property {EasingFunction} [easing]\r\n * @property {number} [lerp]\r\n * @property {boolean} [infinite]\r\n * @property {Orientation} [orientation]\r\n * @property {GestureOrientation} [gestureOrientation]\r\n * @property {number} [touchMultiplier]\r\n * @property {number} [wheelMultiplier]\r\n * @property {boolean} [normalizeWheel]\r\n * @property {boolean} [autoResize]\r\n *\r\n * @param {LenisOptions}\r\n */\r\n constructor({\r\n wrapper = window,\r\n content = document.documentElement,\r\n wheelEventsTarget = wrapper, // deprecated\r\n eventsTarget = wheelEventsTarget,\r\n smoothWheel = true,\r\n smoothTouch = false,\r\n syncTouch = false,\r\n syncTouchLerp = 0.075,\r\n // __iosNoInertiaSyncTouchLerp = 0.4, // should be 1 but had to leave 0.4 for iOS (testing purpose)\r\n touchInertiaMultiplier = 35,\r\n duration, // in seconds\r\n easing = (t) => Math.min(1, 1.001 - Math.pow(2, -10 * t)),\r\n lerp = !duration && 0.1,\r\n infinite = false,\r\n orientation = 'vertical', // vertical, horizontal\r\n gestureOrientation = 'vertical', // vertical, horizontal, both\r\n touchMultiplier = 1,\r\n wheelMultiplier = 1,\r\n normalizeWheel = false,\r\n autoResize = true,\r\n } = {}) {\r\n window.lenisVersion = version\r\n\r\n // if wrapper is html or body, fallback to window\r\n if (wrapper === document.documentElement || wrapper === document.body) {\r\n wrapper = window\r\n }\r\n\r\n this.options = {\r\n wrapper,\r\n content,\r\n wheelEventsTarget,\r\n eventsTarget,\r\n smoothWheel,\r\n smoothTouch,\r\n syncTouch,\r\n syncTouchLerp,\r\n // __iosNoInertiaSyncTouchLerp,\r\n touchInertiaMultiplier,\r\n duration,\r\n easing,\r\n lerp,\r\n infinite,\r\n gestureOrientation,\r\n orientation,\r\n touchMultiplier,\r\n wheelMultiplier,\r\n normalizeWheel,\r\n autoResize,\r\n }\r\n\r\n this.animate = new Animate()\r\n this.emitter = new Emitter()\r\n this.dimensions = new Dimensions({ wrapper, content, autoResize })\r\n this.toggleClass('lenis', true)\r\n\r\n this.velocity = 0\r\n this.isLocked = false\r\n this.isStopped = false\r\n this.isSmooth = syncTouch || smoothWheel || smoothTouch\r\n this.isScrolling = false\r\n this.targetScroll = this.animatedScroll = this.actualScroll\r\n\r\n this.options.wrapper.addEventListener('scroll', this.onNativeScroll, {\r\n passive: false,\r\n })\r\n\r\n this.virtualScroll = new VirtualScroll(eventsTarget, {\r\n touchMultiplier,\r\n wheelMultiplier,\r\n normalizeWheel,\r\n })\r\n this.virtualScroll.on('scroll', this.onVirtualScroll)\r\n }\r\n\r\n destroy() {\r\n this.emitter.destroy()\r\n\r\n this.options.wrapper.removeEventListener('scroll', this.onNativeScroll, {\r\n passive: false,\r\n })\r\n\r\n this.virtualScroll.destroy()\r\n this.dimensions.destroy()\r\n\r\n this.toggleClass('lenis', false)\r\n this.toggleClass('lenis-smooth', false)\r\n this.toggleClass('lenis-scrolling', false)\r\n this.toggleClass('lenis-stopped', false)\r\n this.toggleClass('lenis-locked', false)\r\n }\r\n\r\n on(event, callback) {\r\n return this.emitter.on(event, callback)\r\n }\r\n\r\n off(event, callback) {\r\n return this.emitter.off(event, callback)\r\n }\r\n\r\n setScroll(scroll) {\r\n // apply scroll value immediately\r\n if (this.isHorizontal) {\r\n this.rootElement.scrollLeft = scroll\r\n } else {\r\n this.rootElement.scrollTop = scroll\r\n }\r\n }\r\n\r\n onVirtualScroll = ({ deltaX, deltaY, event }) => {\r\n // keep zoom feature\r\n if (event.ctrlKey) return\r\n\r\n const isTouch = event.type.includes('touch')\r\n const isWheel = event.type.includes('wheel')\r\n\r\n const isTapToStop =\r\n (this.options.smoothTouch || this.options.syncTouch) &&\r\n isTouch &&\r\n event.type === 'touchstart'\r\n\r\n if (isTapToStop) {\r\n this.reset()\r\n return\r\n }\r\n\r\n const isClick = deltaX === 0 && deltaY === 0 // click event\r\n\r\n // const isPullToRefresh =\r\n // this.options.gestureOrientation === 'vertical' &&\r\n // this.scroll === 0 &&\r\n // !this.options.infinite &&\r\n // deltaY <= 5 // touch pull to refresh, not reliable yet\r\n\r\n const isUnknownGesture =\r\n (this.options.gestureOrientation === 'vertical' && deltaY === 0) ||\r\n (this.options.gestureOrientation === 'horizontal' && deltaX === 0)\r\n\r\n if (isClick || isUnknownGesture) {\r\n // console.log('prevent')\r\n return\r\n }\r\n\r\n // catch if scrolling on nested scroll elements\r\n let composedPath = event.composedPath()\r\n composedPath = composedPath.slice(0, composedPath.indexOf(this.rootElement)) // remove parents elements\r\n\r\n if (\r\n !!composedPath.find(\r\n (node) =>\r\n node.hasAttribute?.('data-lenis-prevent') ||\r\n (isTouch && node.hasAttribute?.('data-lenis-prevent-touch')) ||\r\n (isWheel && node.hasAttribute?.('data-lenis-prevent-wheel')) ||\r\n node.classList?.contains('lenis') // nested lenis instance\r\n )\r\n )\r\n return\r\n\r\n if (this.isStopped || this.isLocked) {\r\n event.preventDefault()\r\n return\r\n }\r\n\r\n this.isSmooth =\r\n ((this.options.smoothTouch || this.options.syncTouch) && isTouch) ||\r\n (this.options.smoothWheel && isWheel)\r\n\r\n if (!this.isSmooth) {\r\n this.isScrolling = false\r\n this.animate.stop()\r\n return\r\n }\r\n\r\n event.preventDefault()\r\n\r\n let delta = deltaY\r\n if (this.options.gestureOrientation === 'both') {\r\n delta = Math.abs(deltaY) > Math.abs(deltaX) ? deltaY : deltaX\r\n } else if (this.options.gestureOrientation === 'horizontal') {\r\n delta = deltaX\r\n }\r\n\r\n const syncTouch = isTouch && this.options.syncTouch\r\n const isTouchEnd = isTouch && event.type === 'touchend'\r\n\r\n const hasTouchInertia = isTouchEnd && Math.abs(delta) > 5\r\n\r\n if (hasTouchInertia) {\r\n delta = this.velocity * this.options.touchInertiaMultiplier\r\n }\r\n\r\n this.scrollTo(this.targetScroll + delta, {\r\n programmatic: false,\r\n ...(syncTouch\r\n ? {\r\n lerp: hasTouchInertia ? this.options.syncTouchLerp : 1,\r\n }\r\n : {\r\n lerp: this.options.lerp,\r\n duration: this.options.duration,\r\n easing: this.options.easing,\r\n }),\r\n })\r\n }\r\n\r\n resize() {\r\n this.dimensions.resize()\r\n }\r\n\r\n emit() {\r\n this.emitter.emit('scroll', this)\r\n }\r\n\r\n onNativeScroll = () => {\r\n if (this.__preventNextScrollEvent) return\r\n\r\n if (!this.isScrolling) {\r\n const lastScroll = this.animatedScroll\r\n this.animatedScroll = this.targetScroll = this.actualScroll\r\n this.velocity = 0\r\n this.direction = Math.sign(this.animatedScroll - lastScroll)\r\n this.emit()\r\n }\r\n }\r\n\r\n reset() {\r\n this.isLocked = false\r\n this.isScrolling = false\r\n this.animatedScroll = this.targetScroll = this.actualScroll\r\n this.velocity = 0\r\n this.animate.stop()\r\n }\r\n\r\n start() {\r\n this.isStopped = false\r\n\r\n this.reset()\r\n }\r\n\r\n stop() {\r\n this.isStopped = true\r\n this.animate.stop()\r\n\r\n this.reset()\r\n }\r\n\r\n raf(time) {\r\n const deltaTime = time - (this.time || time)\r\n this.time = time\r\n\r\n this.animate.advance(deltaTime * 0.001)\r\n }\r\n\r\n scrollTo(\r\n target,\r\n {\r\n offset = 0,\r\n immediate = false,\r\n lock = false,\r\n duration = this.options.duration,\r\n easing = this.options.easing,\r\n lerp = !duration && this.options.lerp,\r\n onComplete = null,\r\n force = false, // scroll even if stopped\r\n programmatic = true, // called from outside of the class\r\n } = {}\r\n ) {\r\n if ((this.isStopped || this.isLocked) && !force) return\r\n\r\n // keywords\r\n if (['top', 'left', 'start'].includes(target)) {\r\n target = 0\r\n } else if (['bottom', 'right', 'end'].includes(target)) {\r\n target = this.limit\r\n } else {\r\n let node\r\n\r\n if (typeof target === 'string') {\r\n // CSS selector\r\n node = document.querySelector(target)\r\n } else if (target?.nodeType) {\r\n // Node element\r\n node = target\r\n }\r\n\r\n if (node) {\r\n if (this.options.wrapper !== window) {\r\n // nested scroll offset correction\r\n const wrapperRect = this.options.wrapper.getBoundingClientRect()\r\n offset -= this.isHorizontal ? wrapperRect.left : wrapperRect.top\r\n }\r\n\r\n const rect = node.getBoundingClientRect()\r\n\r\n target =\r\n (this.isHorizontal ? rect.left : rect.top) + this.animatedScroll\r\n }\r\n }\r\n\r\n if (typeof target !== 'number') return\r\n\r\n target += offset\r\n target = Math.round(target)\r\n\r\n if (this.options.infinite) {\r\n if (programmatic) {\r\n this.targetScroll = this.animatedScroll = this.scroll\r\n }\r\n } else {\r\n target = clamp(0, target, this.limit)\r\n }\r\n\r\n if (immediate) {\r\n this.animatedScroll = this.targetScroll = target\r\n this.setScroll(this.scroll)\r\n this.reset()\r\n onComplete?.(this)\r\n return\r\n }\r\n\r\n if (!programmatic) {\r\n if (target === this.targetScroll) return\r\n\r\n this.targetScroll = target\r\n }\r\n\r\n this.animate.fromTo(this.animatedScroll, target, {\r\n duration,\r\n easing,\r\n lerp,\r\n onStart: () => {\r\n // started\r\n if (lock) this.isLocked = true\r\n this.isScrolling = true\r\n },\r\n onUpdate: (value, completed) => {\r\n this.isScrolling = true\r\n\r\n // updated\r\n this.velocity = value - this.animatedScroll\r\n this.direction = Math.sign(this.velocity)\r\n\r\n this.animatedScroll = value\r\n this.setScroll(this.scroll)\r\n\r\n if (programmatic) {\r\n // wheel during programmatic should stop it\r\n this.targetScroll = value\r\n }\r\n\r\n if (!completed) this.emit()\r\n\r\n if (completed) {\r\n this.reset()\r\n this.emit()\r\n onComplete?.(this)\r\n\r\n // avoid emitting event twice\r\n this.__preventNextScrollEvent = true\r\n requestAnimationFrame(() => {\r\n delete this.__preventNextScrollEvent\r\n })\r\n }\r\n },\r\n })\r\n }\r\n\r\n get rootElement() {\r\n return this.options.wrapper === window\r\n ? document.documentElement\r\n : this.options.wrapper\r\n }\r\n\r\n get limit() {\r\n return this.dimensions.limit[this.isHorizontal ? 'x' : 'y']\r\n }\r\n\r\n get isHorizontal() {\r\n return this.options.orientation === 'horizontal'\r\n }\r\n\r\n get actualScroll() {\r\n // value browser takes into account\r\n return this.isHorizontal\r\n ? this.rootElement.scrollLeft\r\n : this.rootElement.scrollTop\r\n }\r\n\r\n get scroll() {\r\n return this.options.infinite\r\n ? modulo(this.animatedScroll, this.limit)\r\n : this.animatedScroll\r\n }\r\n\r\n get progress() {\r\n // avoid progress to be NaN\r\n return this.limit === 0 ? 1 : this.scroll / this.limit\r\n }\r\n\r\n get isSmooth() {\r\n return this.__isSmooth\r\n }\r\n\r\n set isSmooth(value) {\r\n if (this.__isSmooth !== value) {\r\n this.__isSmooth = value\r\n this.toggleClass('lenis-smooth', value)\r\n }\r\n }\r\n\r\n get isScrolling() {\r\n return this.__isScrolling\r\n }\r\n\r\n set isScrolling(value) {\r\n if (this.__isScrolling !== value) {\r\n this.__isScrolling = value\r\n this.toggleClass('lenis-scrolling', value)\r\n }\r\n }\r\n\r\n get isStopped() {\r\n return this.__isStopped\r\n }\r\n\r\n set isStopped(value) {\r\n if (this.__isStopped !== value) {\r\n this.__isStopped = value\r\n this.toggleClass('lenis-stopped', value)\r\n }\r\n }\r\n\r\n get isLocked() {\r\n return this.__isLocked\r\n }\r\n\r\n set isLocked(value) {\r\n if (this.__isLocked !== value) {\r\n this.__isLocked = value\r\n this.toggleClass('lenis-locked', value)\r\n }\r\n }\r\n\r\n get className() {\r\n let className = 'lenis'\r\n if (this.isStopped) className += ' lenis-stopped'\r\n if (this.isLocked) className += ' lenis-locked'\r\n if (this.isScrolling) className += ' lenis-scrolling'\r\n if (this.isSmooth) className += ' lenis-smooth'\r\n return className\r\n }\r\n\r\n toggleClass(name, value) {\r\n this.rootElement.classList.toggle(name, value)\r\n this.emitter.emit('className change', this)\r\n }\r\n}\r\n"],"names":["clamp","min","input","max","Math","Animate","advance","deltaTime","this","isRunning","completed","lerp","value","x","y","to","lambda","dt","t","exp","round","currentTime","linearProgress","duration","easedProgress","easing","from","onUpdate","stop","fromTo","onStart","Dimensions","constructor","wrapper","content","autoResize","resize","callback","delay","timer","args","arguments","context","clearTimeout","setTimeout","apply","debounce","window","wrapperResizeObserver","ResizeObserver","observe","contentResizeObserver","destroy","disconnect","onWrapperResize","onContentResize","width","innerWidth","height","innerHeight","clientWidth","clientHeight","scrollHeight","scrollWidth","limit","Emitter","events","emit","event","callbacks","i","length","on","cb","push","filter","off","VirtualScroll","element","wheelMultiplier","touchMultiplier","normalizeWheel","touchStart","emitter","addEventListener","onWheel","passive","onTouchStart","onTouchMove","onTouchEnd","removeEventListener","clientX","clientY","targetTouches","lastDelta","deltaX","deltaY","Lenis","document","documentElement","wheelEventsTarget","eventsTarget","smoothWheel","smoothTouch","syncTouch","syncTouchLerp","touchInertiaMultiplier","pow","infinite","orientation","gestureOrientation","lenisVersion","body","options","animate","dimensions","toggleClass","velocity","isLocked","isStopped","isSmooth","isScrolling","targetScroll","animatedScroll","actualScroll","onNativeScroll","virtualScroll","onVirtualScroll","setScroll","scroll","isHorizontal","rootElement","scrollLeft","scrollTop","ctrlKey","isTouch","type","includes","isWheel","reset","isClick","isUnknownGesture","composedPath","slice","indexOf","find","node","hasAttribute","classList","contains","preventDefault","delta","abs","hasTouchInertia","scrollTo","programmatic","__preventNextScrollEvent","lastScroll","direction","sign","start","raf","time","target","offset","immediate","lock","onComplete","force","querySelector","nodeType","wrapperRect","getBoundingClientRect","left","top","rect","requestAnimationFrame","n","d","progress","__isSmooth","__isScrolling","__isStopped","__isLocked","className","name","toggle"],"mappings":"aACO,SAASA,EAAMC,EAAKC,EAAOC,GAChC,OAAOC,KAAKD,IAAIF,EAAKG,KAAKH,IAAIC,EAAOC,GACvC,CCAO,MAAME,QAEX,OAAAC,CAAQC,GACN,IAAKC,KAAKC,UAAW,OAErB,IAAIC,GAAY,EAEhB,GAAIF,KAAKG,KACPH,KAAKI,ODKUC,ECLGL,KAAKI,MDKLE,ECLYN,KAAKO,GDKdC,ECL8B,GAAZR,KAAKG,KDKfM,ECL0BV,EDAtD,SAAcM,EAAGC,EAAGI,GACzB,OAAQ,EAAIA,GAAKL,EAAIK,EAAIJ,CAC3B,CAISH,CAAKE,EAAGC,EAAG,EAAIV,KAAKe,KAAKH,EAASC,KCLjCb,KAAKgB,MAAMZ,KAAKI,SAAWJ,KAAKO,KAClCP,KAAKI,MAAQJ,KAAKO,GAClBL,GAAY,OAET,CACLF,KAAKa,aAAed,EACpB,MAAMe,EAAiBtB,EAAM,EAAGQ,KAAKa,YAAcb,KAAKe,SAAU,GAElEb,EAAYY,GAAkB,EAC9B,MAAME,EAAgBd,EAAY,EAAIF,KAAKiB,OAAOH,GAClDd,KAAKI,MAAQJ,KAAKkB,MAAQlB,KAAKO,GAAKP,KAAKkB,MAAQF,CAClD,CDPE,IAAcX,EAAGC,EAAGE,EAAQC,ECU/BT,KAAKmB,WAAWnB,KAAKI,MAAOF,GAExBA,GACFF,KAAKoB,MAER,CAGD,IAAAA,GACEpB,KAAKC,WAAY,CAClB,CAID,MAAAoB,CACEH,EACAX,GACAJ,KAAEA,EAAO,GAAGY,SAAEA,EAAW,EAACE,OAAEA,EAAS,CAACP,GAAMA,GAACY,QAAEA,EAAOH,SAAEA,IAExDnB,KAAKkB,KAAOlB,KAAKI,MAAQc,EACzBlB,KAAKO,GAAKA,EACVP,KAAKG,KAAO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AED,YAAIjE,CAAS1G,GACPJ,KAAK+K,aAAe3K,IACtBJ,KAAK+K,WAAa3K,EAClBJ,KAAK4G,YAAY,eAAgBxG,GAEpC,CAED,aAAI4K,GACF,IAAIA,EAAY,QAKhB,OAJIhL,KAAK+G,YAAWiE,GAAa,kBAC7BhL,KAAK8G,WAAUkE,GAAa,iBAC5BhL,KAAKiH,cAAa+D,GAAa,oBAC/BhL,KAAKgH,WAAUgE,GAAa,iBACzBA,CACR,CAED,WAAApE,CAAYqE,EAAM7K,GAChBJ,KAAK2H,YAAYiB,UAAUsC,OAAOD,EAAM7K,GACxCJ,KAAK2E,QAAQhB,KAAK,mBAAoB3D,KACvC"} \ No newline at end of file diff --git a/packages/lenis/dist/lenis.esm.js b/packages/lenis/dist/lenis.esm.js index 55cf7f59..92a744b5 100644 --- a/packages/lenis/dist/lenis.esm.js +++ b/packages/lenis/dist/lenis.esm.js @@ -1,2 +1,2 @@ -function t(t,e,i){return Math.max(t,Math.min(e,i))}class Animate{advance(e){if(!this.isRunning)return;let i=!1;if(this.lerp)this.value=(s=this.value,o=this.to,n=60*this.lerp,r=e,function(t,e,i){return(1-i)*t+i*e}(s,o,1-Math.exp(-n*r))),Math.round(this.value)===this.to&&(this.value=this.to,i=!0);else{this.currentTime+=e;const s=t(0,this.currentTime/this.duration,1);i=s>=1;const o=i?1:this.easing(s);this.value=this.from+(this.to-this.from)*o}var s,o,n,r;this.onUpdate?.(this.value,i),i&&this.stop()}stop(){this.isRunning=!1}fromTo(t,e,{lerp:i=.1,duration:s=1,easing:o=(t=>t),onStart:n,onUpdate:r}){this.from=this.value=t,this.to=e,this.lerp=i,this.duration=s,this.easing=o,this.currentTime=0,this.isRunning=!0,n?.(),this.onUpdate=r}}class Dimensions{constructor({wrapper:t,content:e,autoResize:i=!0}={}){if(this.wrapper=t,this.content=e,i){const t=function(t,e){let i;return function(){let s=arguments,o=this;clearTimeout(i),i=setTimeout((function(){t.apply(o,s)}),e)}}(this.resize,250);this.wrapper!==window&&(this.wrapperResizeObserver=new ResizeObserver(t),this.wrapperResizeObserver.observe(this.wrapper)),this.contentResizeObserver=new ResizeObserver(t),this.contentResizeObserver.observe(this.content)}this.resize()}destroy(){this.wrapperResizeObserver?.disconnect(),this.contentResizeObserver?.disconnect()}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.scrollHeight=this.content.scrollHeight,this.scrollWidth=this.content.scrollWidth};get limit(){return{x:this.scrollWidth-this.width,y:this.scrollHeight-this.height}}}class Emitter{constructor(){this.events={}}emit(t,...e){let i=this.events[t]||[];for(let t=0,s=i.length;t{this.events[t]=this.events[t]?.filter((t=>e!==t))}}off(t,e){this.events[t]=this.events[t]?.filter((t=>e!==t))}destroy(){this.events={}}}class VirtualScroll{constructor(t,{wheelMultiplier:e=1,touchMultiplier:i=2,normalizeWheel:s=!1}){this.element=t,this.wheelMultiplier=e,this.touchMultiplier=i,this.normalizeWheel=s,this.touchStart={x:null,y:null},this.emitter=new Emitter,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,e){return this.emitter.on(t,e)}destroy(){this.emitter.destroy(),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=>{const{clientX:e,clientY:i}=t.targetTouches?t.targetTouches[0]:t;this.touchStart.x=e,this.touchStart.y=i,this.lastDelta={x:0,y:0}};onTouchMove=t=>{const{clientX:e,clientY:i}=t.targetTouches?t.targetTouches[0]:t,s=-(e-this.touchStart.x)*this.touchMultiplier,o=-(i-this.touchStart.y)*this.touchMultiplier;this.touchStart.x=e,this.touchStart.y=i,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=e=>{let{deltaX:i,deltaY:s}=e;this.normalizeWheel&&(i=t(-100,i,100),s=t(-100,s,100)),i*=this.wheelMultiplier,s*=this.wheelMultiplier,this.emitter.emit("scroll",{deltaX:i,deltaY:s,event:e})}}class Lenis{constructor({wrapper:t=window,content:e=document.documentElement,wheelEventsTarget:i=t,eventsTarget:s=i,smoothWheel:o=!0,smoothTouch:n=!1,syncTouch:r=!1,syncTouchLerp:l=.1,__iosNoInertiaSyncTouchLerp:h=.4,touchInertiaMultiplier:a=35,duration:c,easing:u=(t=>Math.min(1,1.001-Math.pow(2,-10*t))),lerp:p=!c&&.1,infinite:m=!1,orientation:d="vertical",gestureOrientation:g="vertical",touchMultiplier:v=1,wheelMultiplier:S=1,normalizeWheel:w=!1,autoResize:f=!0}={}){window.lenisVersion="0.0.4",t!==document.documentElement&&t!==document.body||(t=window),this.options={wrapper:t,content:e,wheelEventsTarget:i,eventsTarget:s,smoothWheel:o,smoothTouch:n,syncTouch:r,syncTouchLerp:l,__iosNoInertiaSyncTouchLerp:h,touchInertiaMultiplier:a,duration:c,easing:u,lerp:p,infinite:m,gestureOrientation:g,orientation:d,touchMultiplier:v,wheelMultiplier:S,normalizeWheel:w,autoResize:f},this.animate=new Animate,this.emitter=new Emitter,this.dimensions=new Dimensions({wrapper:t,content:e,autoResize:f}),this.toggleClass("lenis",!0),this.velocity=0,this.isLocked=!1,this.isStopped=!1,this.isSmooth=r||o||n,this.isScrolling=!1,this.targetScroll=this.animatedScroll=this.actualScroll,this.options.wrapper.addEventListener("scroll",this.onNativeScroll,{passive:!1}),this.virtualScroll=new VirtualScroll(s,{touchMultiplier:v,wheelMultiplier:S,normalizeWheel:w}),this.virtualScroll.on("scroll",this.onVirtualScroll)}destroy(){this.emitter.destroy(),this.options.wrapper.removeEventListener("scroll",this.onNativeScroll,{passive:!1}),this.virtualScroll.destroy(),this.dimensions.destroy(),this.toggleClass("lenis",!1),this.toggleClass("lenis-smooth",!1),this.toggleClass("lenis-scrolling",!1),this.toggleClass("lenis-stopped",!1),this.toggleClass("lenis-locked",!1)}on(t,e){return this.emitter.on(t,e)}off(t,e){return this.emitter.off(t,e)}setScroll(t){this.isHorizontal?this.rootElement.scrollLeft=t:this.rootElement.scrollTop=t}onVirtualScroll=({deltaX:t,deltaY:e,event:i})=>{if(i.ctrlKey)return;const s=i.type.includes("touch"),o=i.type.includes("wheel");if("both"===this.options.gestureOrientation&&0===t&&0===e||"vertical"===this.options.gestureOrientation&&0===e||"horizontal"===this.options.gestureOrientation&&0===t||s&&"vertical"===this.options.gestureOrientation&&0===this.scroll&&!this.options.infinite&&e<=0)return;let n=i.composedPath();if(n=n.slice(0,n.indexOf(this.rootElement)),n.find((t=>t.hasAttribute?.("data-lenis-prevent")||s&&t.hasAttribute?.("data-lenis-prevent-touch")||o&&t.hasAttribute?.("data-lenis-prevent-wheel")||t.classList?.contains("lenis"))))return;if(this.isStopped||this.isLocked)return void i.preventDefault();if(this.isSmooth=(this.options.smoothTouch||this.options.syncTouch)&&s||this.options.smoothWheel&&o,!this.isSmooth)return this.isScrolling=!1,void this.animate.stop();i.preventDefault();let r=e;"both"===this.options.gestureOrientation?r=Math.abs(e)>Math.abs(t)?e:t:"horizontal"===this.options.gestureOrientation&&(r=t);const l=s&&this.options.syncTouch,h=s&&"touchend"===i.type&&Math.abs(r)>1;h&&(r=this.velocity*this.options.touchInertiaMultiplier),this.scrollTo(this.targetScroll+r,{programmatic:!1,...l&&{lerp:h?this.syncTouchLerp:this.options.__iosNoInertiaSyncTouchLerp}})};resize(){this.dimensions.resize()}emit(){this.emitter.emit("scroll",this)}onNativeScroll=()=>{if(!this.__preventNextScrollEvent&&!this.isScrolling){const t=this.animatedScroll;this.animatedScroll=this.targetScroll=this.actualScroll,this.velocity=0,this.direction=Math.sign(this.animatedScroll-t),this.emit()}};reset(){this.isLocked=!1,this.isScrolling=!1,this.animatedScroll=this.targetScroll=this.actualScroll,this.velocity=0,this.animate.stop()}start(){this.isStopped=!1,this.reset()}stop(){this.isStopped=!0,this.animate.stop(),this.reset()}raf(t){const e=t-(this.time||t);this.time=t,this.animate.advance(.001*e)}scrollTo(e,{offset:i=0,immediate:s=!1,lock:o=!1,duration:n=this.options.duration,easing:r=this.options.easing,lerp:l=!n&&this.options.lerp,onComplete:h=null,force:a=!1,programmatic:c=!0}={}){if(!this.isStopped&&!this.isLocked||a){if(["top","left","start"].includes(e))e=0;else if(["bottom","right","end"].includes(e))e=this.limit;else{let t;if("string"==typeof e?t=document.querySelector(e):e?.nodeType&&(t=e),t){if(this.options.wrapper!==window){const t=this.options.wrapper.getBoundingClientRect();i-=this.isHorizontal?t.left:t.top}const s=t.getBoundingClientRect();e=(this.isHorizontal?s.left:s.top)+this.animatedScroll}}if("number"==typeof e){if(e+=i,e=Math.round(e),this.options.infinite?c&&(this.targetScroll=this.animatedScroll=this.scroll):e=t(0,e,this.limit),s)return this.animatedScroll=this.targetScroll=e,this.setScroll(this.scroll),this.reset(),void h?.(this);if(!c){if(e===this.targetScroll)return;this.targetScroll=e}this.animate.fromTo(this.animatedScroll,e,{duration:n,easing:r,lerp:l,onStart:()=>{o&&(this.isLocked=!0),this.isScrolling=!0},onUpdate:(t,e)=>{this.isScrolling=!0,this.velocity=t-this.animatedScroll,this.direction=Math.sign(this.velocity),this.animatedScroll=t,this.setScroll(this.scroll),c&&(this.targetScroll=t),e||this.emit(),e&&(this.reset(),this.emit(),h?.(this),this.__preventNextScrollEvent=!0,requestAnimationFrame((()=>{delete this.__preventNextScrollEvent})))}})}}}get rootElement(){return this.options.wrapper===window?document.documentElement:this.options.wrapper}get limit(){return 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(){return this.options.infinite?(t=this.animatedScroll,e=this.limit,(t%e+e)%e):this.animatedScroll;var t,e}get progress(){return 0===this.limit?1:this.scroll/this.limit}get isSmooth(){return this.__isSmooth}set isSmooth(t){this.__isSmooth!==t&&(this.__isSmooth=t,this.toggleClass("lenis-smooth",t))}get isScrolling(){return this.__isScrolling}set isScrolling(t){this.__isScrolling!==t&&(this.__isScrolling=t,this.toggleClass("lenis-scrolling",t))}get isStopped(){return this.__isStopped}set isStopped(t){this.__isStopped!==t&&(this.__isStopped=t,this.toggleClass("lenis-stopped",t))}get isLocked(){return this.__isLocked}set isLocked(t){this.__isLocked!==t&&(this.__isLocked=t,this.toggleClass("lenis-locked",t))}get className(){let t="lenis";return this.isStopped&&(t+=" lenis-stopped"),this.isLocked&&(t+=" lenis-locked"),this.isScrolling&&(t+=" lenis-scrolling"),this.isSmooth&&(t+=" lenis-smooth"),t}toggleClass(t,e){this.rootElement.classList.toggle(t,e),this.emitter.emit("className change",this)}}export{Lenis as default}; +function t(t,e,i){return Math.max(t,Math.min(e,i))}class Animate{advance(e){if(!this.isRunning)return;let i=!1;if(this.lerp)this.value=(s=this.value,o=this.to,n=60*this.lerp,r=e,function(t,e,i){return(1-i)*t+i*e}(s,o,1-Math.exp(-n*r))),Math.round(this.value)===this.to&&(this.value=this.to,i=!0);else{this.currentTime+=e;const s=t(0,this.currentTime/this.duration,1);i=s>=1;const o=i?1:this.easing(s);this.value=this.from+(this.to-this.from)*o}var s,o,n,r;this.onUpdate?.(this.value,i),i&&this.stop()}stop(){this.isRunning=!1}fromTo(t,e,{lerp:i=.1,duration:s=1,easing:o=(t=>t),onStart:n,onUpdate:r}){this.from=this.value=t,this.to=e,this.lerp=i,this.duration=s,this.easing=o,this.currentTime=0,this.isRunning=!0,n?.(),this.onUpdate=r}}class Dimensions{constructor({wrapper:t,content:e,autoResize:i=!0}={}){if(this.wrapper=t,this.content=e,i){const t=function(t,e){let i;return function(){let s=arguments,o=this;clearTimeout(i),i=setTimeout((function(){t.apply(o,s)}),e)}}(this.resize,250);this.wrapper!==window&&(this.wrapperResizeObserver=new ResizeObserver(t),this.wrapperResizeObserver.observe(this.wrapper)),this.contentResizeObserver=new ResizeObserver(t),this.contentResizeObserver.observe(this.content)}this.resize()}destroy(){this.wrapperResizeObserver?.disconnect(),this.contentResizeObserver?.disconnect()}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.scrollHeight=this.content.scrollHeight,this.scrollWidth=this.content.scrollWidth};get limit(){return{x:this.scrollWidth-this.width,y:this.scrollHeight-this.height}}}class Emitter{constructor(){this.events={}}emit(t,...e){let i=this.events[t]||[];for(let t=0,s=i.length;t{this.events[t]=this.events[t]?.filter((t=>e!==t))}}off(t,e){this.events[t]=this.events[t]?.filter((t=>e!==t))}destroy(){this.events={}}}class VirtualScroll{constructor(t,{wheelMultiplier:e=1,touchMultiplier:i=2,normalizeWheel:s=!1}){this.element=t,this.wheelMultiplier=e,this.touchMultiplier=i,this.normalizeWheel=s,this.touchStart={x:null,y:null},this.emitter=new Emitter,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,e){return this.emitter.on(t,e)}destroy(){this.emitter.destroy(),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=>{const{clientX:e,clientY:i}=t.targetTouches?t.targetTouches[0]:t;this.touchStart.x=e,this.touchStart.y=i,this.lastDelta={x:0,y:0},this.emitter.emit("scroll",{deltaX:0,deltaY:0,event:t})};onTouchMove=t=>{const{clientX:e,clientY:i}=t.targetTouches?t.targetTouches[0]:t,s=-(e-this.touchStart.x)*this.touchMultiplier,o=-(i-this.touchStart.y)*this.touchMultiplier;this.touchStart.x=e,this.touchStart.y=i,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=e=>{let{deltaX:i,deltaY:s}=e;this.normalizeWheel&&(i=t(-100,i,100),s=t(-100,s,100)),i*=this.wheelMultiplier,s*=this.wheelMultiplier,this.emitter.emit("scroll",{deltaX:i,deltaY:s,event:e})}}class Lenis{constructor({wrapper:t=window,content:e=document.documentElement,wheelEventsTarget:i=t,eventsTarget:s=i,smoothWheel:o=!0,smoothTouch:n=!1,syncTouch:r=!1,syncTouchLerp:l=.075,touchInertiaMultiplier:h=35,duration:a,easing:c=(t=>Math.min(1,1.001-Math.pow(2,-10*t))),lerp:p=!a&&.1,infinite:u=!1,orientation:d="vertical",gestureOrientation:m="vertical",touchMultiplier:g=1,wheelMultiplier:v=1,normalizeWheel:S=!1,autoResize:w=!0}={}){window.lenisVersion="1.0.29",t!==document.documentElement&&t!==document.body||(t=window),this.options={wrapper:t,content:e,wheelEventsTarget:i,eventsTarget:s,smoothWheel:o,smoothTouch:n,syncTouch:r,syncTouchLerp:l,touchInertiaMultiplier:h,duration:a,easing:c,lerp:p,infinite:u,gestureOrientation:m,orientation:d,touchMultiplier:g,wheelMultiplier:v,normalizeWheel:S,autoResize:w},this.animate=new Animate,this.emitter=new Emitter,this.dimensions=new Dimensions({wrapper:t,content:e,autoResize:w}),this.toggleClass("lenis",!0),this.velocity=0,this.isLocked=!1,this.isStopped=!1,this.isSmooth=r||o||n,this.isScrolling=!1,this.targetScroll=this.animatedScroll=this.actualScroll,this.options.wrapper.addEventListener("scroll",this.onNativeScroll,{passive:!1}),this.virtualScroll=new VirtualScroll(s,{touchMultiplier:g,wheelMultiplier:v,normalizeWheel:S}),this.virtualScroll.on("scroll",this.onVirtualScroll)}destroy(){this.emitter.destroy(),this.options.wrapper.removeEventListener("scroll",this.onNativeScroll,{passive:!1}),this.virtualScroll.destroy(),this.dimensions.destroy(),this.toggleClass("lenis",!1),this.toggleClass("lenis-smooth",!1),this.toggleClass("lenis-scrolling",!1),this.toggleClass("lenis-stopped",!1),this.toggleClass("lenis-locked",!1)}on(t,e){return this.emitter.on(t,e)}off(t,e){return this.emitter.off(t,e)}setScroll(t){this.isHorizontal?this.rootElement.scrollLeft=t:this.rootElement.scrollTop=t}onVirtualScroll=({deltaX:t,deltaY:e,event:i})=>{if(i.ctrlKey)return;const s=i.type.includes("touch"),o=i.type.includes("wheel");if((this.options.smoothTouch||this.options.syncTouch)&&s&&"touchstart"===i.type)return void this.reset();const n=0===t&&0===e,r="vertical"===this.options.gestureOrientation&&0===e||"horizontal"===this.options.gestureOrientation&&0===t;if(n||r)return;let l=i.composedPath();if(l=l.slice(0,l.indexOf(this.rootElement)),l.find((t=>t.hasAttribute?.("data-lenis-prevent")||s&&t.hasAttribute?.("data-lenis-prevent-touch")||o&&t.hasAttribute?.("data-lenis-prevent-wheel")||t.classList?.contains("lenis"))))return;if(this.isStopped||this.isLocked)return void i.preventDefault();if(this.isSmooth=(this.options.smoothTouch||this.options.syncTouch)&&s||this.options.smoothWheel&&o,!this.isSmooth)return this.isScrolling=!1,void this.animate.stop();i.preventDefault();let h=e;"both"===this.options.gestureOrientation?h=Math.abs(e)>Math.abs(t)?e:t:"horizontal"===this.options.gestureOrientation&&(h=t);const a=s&&this.options.syncTouch,c=s&&"touchend"===i.type&&Math.abs(h)>5;c&&(h=this.velocity*this.options.touchInertiaMultiplier),this.scrollTo(this.targetScroll+h,{programmatic:!1,...a?{lerp:c?this.options.syncTouchLerp:1}:{lerp:this.options.lerp,duration:this.options.duration,easing:this.options.easing}})};resize(){this.dimensions.resize()}emit(){this.emitter.emit("scroll",this)}onNativeScroll=()=>{if(!this.__preventNextScrollEvent&&!this.isScrolling){const t=this.animatedScroll;this.animatedScroll=this.targetScroll=this.actualScroll,this.velocity=0,this.direction=Math.sign(this.animatedScroll-t),this.emit()}};reset(){this.isLocked=!1,this.isScrolling=!1,this.animatedScroll=this.targetScroll=this.actualScroll,this.velocity=0,this.animate.stop()}start(){this.isStopped=!1,this.reset()}stop(){this.isStopped=!0,this.animate.stop(),this.reset()}raf(t){const e=t-(this.time||t);this.time=t,this.animate.advance(.001*e)}scrollTo(e,{offset:i=0,immediate:s=!1,lock:o=!1,duration:n=this.options.duration,easing:r=this.options.easing,lerp:l=!n&&this.options.lerp,onComplete:h=null,force:a=!1,programmatic:c=!0}={}){if(!this.isStopped&&!this.isLocked||a){if(["top","left","start"].includes(e))e=0;else if(["bottom","right","end"].includes(e))e=this.limit;else{let t;if("string"==typeof e?t=document.querySelector(e):e?.nodeType&&(t=e),t){if(this.options.wrapper!==window){const t=this.options.wrapper.getBoundingClientRect();i-=this.isHorizontal?t.left:t.top}const s=t.getBoundingClientRect();e=(this.isHorizontal?s.left:s.top)+this.animatedScroll}}if("number"==typeof e){if(e+=i,e=Math.round(e),this.options.infinite?c&&(this.targetScroll=this.animatedScroll=this.scroll):e=t(0,e,this.limit),s)return this.animatedScroll=this.targetScroll=e,this.setScroll(this.scroll),this.reset(),void h?.(this);if(!c){if(e===this.targetScroll)return;this.targetScroll=e}this.animate.fromTo(this.animatedScroll,e,{duration:n,easing:r,lerp:l,onStart:()=>{o&&(this.isLocked=!0),this.isScrolling=!0},onUpdate:(t,e)=>{this.isScrolling=!0,this.velocity=t-this.animatedScroll,this.direction=Math.sign(this.velocity),this.animatedScroll=t,this.setScroll(this.scroll),c&&(this.targetScroll=t),e||this.emit(),e&&(this.reset(),this.emit(),h?.(this),this.__preventNextScrollEvent=!0,requestAnimationFrame((()=>{delete this.__preventNextScrollEvent})))}})}}}get rootElement(){return this.options.wrapper===window?document.documentElement:this.options.wrapper}get limit(){return 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(){return this.options.infinite?(t=this.animatedScroll,e=this.limit,(t%e+e)%e):this.animatedScroll;var t,e}get progress(){return 0===this.limit?1:this.scroll/this.limit}get isSmooth(){return this.__isSmooth}set isSmooth(t){this.__isSmooth!==t&&(this.__isSmooth=t,this.toggleClass("lenis-smooth",t))}get isScrolling(){return this.__isScrolling}set isScrolling(t){this.__isScrolling!==t&&(this.__isScrolling=t,this.toggleClass("lenis-scrolling",t))}get isStopped(){return this.__isStopped}set isStopped(t){this.__isStopped!==t&&(this.__isStopped=t,this.toggleClass("lenis-stopped",t))}get isLocked(){return this.__isLocked}set isLocked(t){this.__isLocked!==t&&(this.__isLocked=t,this.toggleClass("lenis-locked",t))}get className(){let t="lenis";return this.isStopped&&(t+=" lenis-stopped"),this.isLocked&&(t+=" lenis-locked"),this.isScrolling&&(t+=" lenis-scrolling"),this.isSmooth&&(t+=" lenis-smooth"),t}toggleClass(t,e){this.rootElement.classList.toggle(t,e),this.emitter.emit("className change",this)}}export{Lenis as default}; //# sourceMappingURL=lenis.esm.js.map diff --git a/packages/lenis/dist/lenis.esm.js.map b/packages/lenis/dist/lenis.esm.js.map index 498acf60..a032a22a 100644 --- a/packages/lenis/dist/lenis.esm.js.map +++ b/packages/lenis/dist/lenis.esm.js.map @@ -1 +1 @@ -{"version":3,"file":"lenis.esm.js","sources":["../src/maths.js","../src/animate.js","../src/dimensions.js","../src/debounce.js","../src/emitter.js","../src/virtual-scroll.js","../src/index.js"],"sourcesContent":["// Clamp a value between a minimum and maximum value\r\nexport function clamp(min, input, max) {\r\n return Math.max(min, Math.min(input, max))\r\n}\r\n\r\n// Truncate a floating-point number to a specified number of decimal places\r\nexport function truncate(value, decimals = 0) {\r\n return parseFloat(value.toFixed(decimals))\r\n}\r\n\r\n// Linearly interpolate between two values using an amount (0 <= t <= 1)\r\nexport function lerp(x, y, t) {\r\n return (1 - t) * x + t * y\r\n}\r\n\r\n// http://www.rorydriscoll.com/2016/03/07/frame-rate-independent-damping-using-lerp/\r\nexport function damp(x, y, lambda, dt) {\r\n return lerp(x, y, 1 - Math.exp(-lambda * dt))\r\n}\r\n\r\n// Calculate the modulo of the dividend and divisor while keeping the result within the same sign as the divisor\r\n// https://anguscroll.com/just/just-modulo\r\nexport function modulo(n, d) {\r\n return ((n % d) + d) % d\r\n}\r\n","import { clamp, damp } from './maths'\r\n\r\n// Animate class to handle value animations with lerping or easing\r\nexport class Animate {\r\n // Advance the animation by the given delta time\r\n advance(deltaTime) {\r\n if (!this.isRunning) return\r\n\r\n let completed = false\r\n\r\n if (this.lerp) {\r\n this.value = damp(this.value, this.to, this.lerp * 60, deltaTime)\r\n if (Math.round(this.value) === this.to) {\r\n this.value = this.to\r\n completed = true\r\n }\r\n } else {\r\n this.currentTime += deltaTime\r\n const linearProgress = clamp(0, this.currentTime / this.duration, 1)\r\n\r\n completed = linearProgress >= 1\r\n const easedProgress = completed ? 1 : this.easing(linearProgress)\r\n this.value = this.from + (this.to - this.from) * easedProgress\r\n }\r\n\r\n // Call the onUpdate callback with the current value and completed status\r\n this.onUpdate?.(this.value, completed)\r\n\r\n if (completed) {\r\n this.stop()\r\n }\r\n }\r\n\r\n // Stop the animation\r\n stop() {\r\n this.isRunning = false\r\n }\r\n\r\n // Set up the animation from a starting value to an ending value\r\n // with optional parameters for lerping, duration, easing, and onUpdate callback\r\n fromTo(\r\n from,\r\n to,\r\n { lerp = 0.1, duration = 1, easing = (t) => t, onStart, onUpdate }\r\n ) {\r\n this.from = this.value = from\r\n this.to = to\r\n this.lerp = lerp\r\n this.duration = duration\r\n this.easing = easing\r\n this.currentTime = 0\r\n this.isRunning = true\r\n\r\n onStart?.()\r\n this.onUpdate = onUpdate\r\n }\r\n}\r\n","import { debounce } from './debounce'\r\n\r\nexport class Dimensions {\r\n constructor({ wrapper, content, autoResize = true } = {}) {\r\n this.wrapper = wrapper\r\n this.content = content\r\n\r\n if (autoResize) {\r\n const resize = debounce(this.resize, 250)\r\n\r\n if (this.wrapper !== window) {\r\n this.wrapperResizeObserver = new ResizeObserver(resize)\r\n this.wrapperResizeObserver.observe(this.wrapper)\r\n }\r\n\r\n this.contentResizeObserver = new ResizeObserver(resize)\r\n this.contentResizeObserver.observe(this.content)\r\n }\r\n\r\n this.resize()\r\n }\r\n\r\n destroy() {\r\n this.wrapperResizeObserver?.disconnect()\r\n this.contentResizeObserver?.disconnect()\r\n }\r\n\r\n resize = () => {\r\n this.onWrapperResize()\r\n this.onContentResize()\r\n }\r\n\r\n onWrapperResize = () => {\r\n if (this.wrapper === window) {\r\n this.width = window.innerWidth\r\n this.height = window.innerHeight\r\n } else {\r\n this.width = this.wrapper.clientWidth\r\n this.height = this.wrapper.clientHeight\r\n }\r\n }\r\n\r\n onContentResize = () => {\r\n this.scrollHeight = this.content.scrollHeight\r\n this.scrollWidth = this.content.scrollWidth\r\n }\r\n\r\n get limit() {\r\n return {\r\n x: this.scrollWidth - this.width,\r\n y: this.scrollHeight - this.height,\r\n }\r\n }\r\n}\r\n","export function debounce(callback, delay) {\r\n let timer\r\n return function () {\r\n let args = arguments\r\n let context = this\r\n clearTimeout(timer)\r\n timer = setTimeout(function () {\r\n callback.apply(context, args)\r\n }, delay)\r\n }\r\n}\r\n","export class Emitter {\r\n constructor() {\r\n this.events = {}\r\n }\r\n\r\n emit(event, ...args) {\r\n let callbacks = this.events[event] || []\r\n for (let i = 0, length = callbacks.length; i < length; i++) {\r\n callbacks[i](...args)\r\n }\r\n }\r\n\r\n on(event, cb) {\r\n // Add the callback to the event's callback list, or create a new list with the callback\r\n this.events[event]?.push(cb) || (this.events[event] = [cb])\r\n\r\n // Return an unsubscribe function\r\n return () => {\r\n this.events[event] = this.events[event]?.filter((i) => cb !== i)\r\n }\r\n }\r\n\r\n off(event, callback) {\r\n this.events[event] = this.events[event]?.filter((i) => callback !== i)\r\n }\r\n\r\n destroy() {\r\n this.events = {}\r\n }\r\n}\r\n","import { Emitter } from './emitter'\r\nimport { clamp } from './maths'\r\n\r\nexport class VirtualScroll {\r\n constructor(\r\n element,\r\n { wheelMultiplier = 1, touchMultiplier = 2, normalizeWheel = false }\r\n ) {\r\n this.element = element\r\n this.wheelMultiplier = wheelMultiplier\r\n this.touchMultiplier = touchMultiplier\r\n this.normalizeWheel = normalizeWheel\r\n\r\n this.touchStart = {\r\n x: null,\r\n y: null,\r\n }\r\n\r\n this.emitter = new Emitter()\r\n\r\n this.element.addEventListener('wheel', this.onWheel, { passive: false })\r\n this.element.addEventListener('touchstart', this.onTouchStart, {\r\n passive: false,\r\n })\r\n this.element.addEventListener('touchmove', this.onTouchMove, {\r\n passive: false,\r\n })\r\n this.element.addEventListener('touchend', this.onTouchEnd, {\r\n passive: false,\r\n })\r\n }\r\n\r\n // Add an event listener for the given event and callback\r\n on(event, callback) {\r\n return this.emitter.on(event, callback)\r\n }\r\n\r\n // Remove all event listeners and clean up\r\n destroy() {\r\n this.emitter.destroy()\r\n\r\n this.element.removeEventListener('wheel', this.onWheel, {\r\n passive: false,\r\n })\r\n this.element.removeEventListener('touchstart', this.onTouchStart, {\r\n passive: false,\r\n })\r\n this.element.removeEventListener('touchmove', this.onTouchMove, {\r\n passive: false,\r\n })\r\n this.element.removeEventListener('touchend', this.onTouchEnd, {\r\n passive: false,\r\n })\r\n }\r\n\r\n // Event handler for 'touchstart' event\r\n onTouchStart = (event) => {\r\n const { clientX, clientY } = event.targetTouches\r\n ? event.targetTouches[0]\r\n : event\r\n\r\n this.touchStart.x = clientX\r\n this.touchStart.y = clientY\r\n\r\n this.lastDelta = {\r\n x: 0,\r\n y: 0,\r\n }\r\n }\r\n\r\n // Event handler for 'touchmove' event\r\n onTouchMove = (event) => {\r\n const { clientX, clientY } = event.targetTouches\r\n ? event.targetTouches[0]\r\n : event\r\n\r\n const deltaX = -(clientX - this.touchStart.x) * this.touchMultiplier\r\n const deltaY = -(clientY - this.touchStart.y) * this.touchMultiplier\r\n\r\n this.touchStart.x = clientX\r\n this.touchStart.y = clientY\r\n\r\n this.lastDelta = {\r\n x: deltaX,\r\n y: deltaY,\r\n }\r\n\r\n this.emitter.emit('scroll', {\r\n deltaX,\r\n deltaY,\r\n event,\r\n })\r\n }\r\n\r\n onTouchEnd = (event) => {\r\n this.emitter.emit('scroll', {\r\n deltaX: this.lastDelta.x,\r\n deltaY: this.lastDelta.y,\r\n event,\r\n })\r\n }\r\n\r\n // Event handler for 'wheel' event\r\n onWheel = (event) => {\r\n let { deltaX, deltaY } = event\r\n\r\n if (this.normalizeWheel) {\r\n deltaX = clamp(-100, deltaX, 100)\r\n deltaY = clamp(-100, deltaY, 100)\r\n }\r\n\r\n deltaX *= this.wheelMultiplier\r\n deltaY *= this.wheelMultiplier\r\n\r\n this.emitter.emit('scroll', { deltaX, deltaY, event })\r\n }\r\n}\r\n","import { version } from '../package.json'\r\nimport { Animate } from './animate'\r\nimport { Dimensions } from './dimensions'\r\nimport { Emitter } from './emitter'\r\nimport { clamp, modulo } from './maths'\r\nimport { VirtualScroll } from './virtual-scroll'\r\n\r\n// Technical explanation\r\n// - listen to 'wheel' events\r\n// - prevent 'wheel' event to prevent scroll\r\n// - normalize wheel delta\r\n// - add delta to targetScroll\r\n// - animate scroll to targetScroll (smooth context)\r\n// - if animation is not running, listen to 'scroll' events (native context)\r\n\r\nexport default class Lenis {\r\n // isScrolling = true when scroll is animating\r\n // isStopped = true if user should not be able to scroll - enable/disable programmatically\r\n // isSmooth = true if scroll should be animated\r\n // isLocked = same as isStopped but enabled/disabled when scroll reaches target\r\n\r\n /**\r\n * @typedef {(t: number) => number} EasingFunction\r\n * @typedef {'vertical' | 'horizontal'} Orientation\r\n * @typedef {'vertical' | 'horizontal' | 'both'} GestureOrientation\r\n *\r\n * @typedef LenisOptions\r\n * @property {Window | HTMLElement} [wrapper]\r\n * @property {HTMLElement} [content]\r\n * @property {Window | HTMLElement} [wheelEventsTarget] // deprecated\r\n * @property {Window | HTMLElement} [eventsTarget]\r\n * @property {boolean} [smoothWheel]\r\n * @property {boolean} [smoothTouch]\r\n * @property {boolean} [syncTouch]\r\n * @property {number} [syncTouchLerp]\r\n * @property {number} [__iosNoInertiaSyncTouchLerp]\r\n * @property {number} [touchInertiaMultiplier]\r\n * @property {number} [duration]\r\n * @property {EasingFunction} [easing]\r\n * @property {number} [lerp]\r\n * @property {boolean} [infinite]\r\n * @property {Orientation} [orientation]\r\n * @property {GestureOrientation} [gestureOrientation]\r\n * @property {number} [touchMultiplier]\r\n * @property {number} [wheelMultiplier]\r\n * @property {boolean} [normalizeWheel]\r\n * @property {boolean} [autoResize]\r\n *\r\n * @param {LenisOptions}\r\n */\r\n constructor({\r\n wrapper = window,\r\n content = document.documentElement,\r\n wheelEventsTarget = wrapper, // deprecated\r\n eventsTarget = wheelEventsTarget,\r\n smoothWheel = true,\r\n smoothTouch = false,\r\n syncTouch = false,\r\n syncTouchLerp = 0.1,\r\n __iosNoInertiaSyncTouchLerp = 0.4, // should be 1 but had to leave 0.4 for iOS (testing purpose)\r\n touchInertiaMultiplier = 35,\r\n duration, // in seconds\r\n easing = (t) => Math.min(1, 1.001 - Math.pow(2, -10 * t)),\r\n lerp = !duration && 0.1,\r\n infinite = false,\r\n orientation = 'vertical', // vertical, horizontal\r\n gestureOrientation = 'vertical', // vertical, horizontal, both\r\n touchMultiplier = 1,\r\n wheelMultiplier = 1,\r\n normalizeWheel = false,\r\n autoResize = true,\r\n } = {}) {\r\n window.lenisVersion = version\r\n\r\n // if wrapper is html or body, fallback to window\r\n if (wrapper === document.documentElement || wrapper === document.body) {\r\n wrapper = window\r\n }\r\n\r\n this.options = {\r\n wrapper,\r\n content,\r\n wheelEventsTarget,\r\n eventsTarget,\r\n smoothWheel,\r\n smoothTouch,\r\n syncTouch,\r\n syncTouchLerp,\r\n __iosNoInertiaSyncTouchLerp,\r\n touchInertiaMultiplier,\r\n duration,\r\n easing,\r\n lerp,\r\n infinite,\r\n gestureOrientation,\r\n orientation,\r\n touchMultiplier,\r\n wheelMultiplier,\r\n normalizeWheel,\r\n autoResize,\r\n }\r\n\r\n this.animate = new Animate()\r\n this.emitter = new Emitter()\r\n this.dimensions = new Dimensions({ wrapper, content, autoResize })\r\n this.toggleClass('lenis', true)\r\n\r\n this.velocity = 0\r\n this.isLocked = false\r\n this.isStopped = false\r\n this.isSmooth = syncTouch || smoothWheel || smoothTouch\r\n this.isScrolling = false\r\n this.targetScroll = this.animatedScroll = this.actualScroll\r\n\r\n this.options.wrapper.addEventListener('scroll', this.onNativeScroll, {\r\n passive: false,\r\n })\r\n\r\n this.virtualScroll = new VirtualScroll(eventsTarget, {\r\n touchMultiplier,\r\n wheelMultiplier,\r\n normalizeWheel,\r\n })\r\n this.virtualScroll.on('scroll', this.onVirtualScroll)\r\n }\r\n\r\n destroy() {\r\n this.emitter.destroy()\r\n\r\n this.options.wrapper.removeEventListener('scroll', this.onNativeScroll, {\r\n passive: false,\r\n })\r\n\r\n this.virtualScroll.destroy()\r\n this.dimensions.destroy()\r\n\r\n this.toggleClass('lenis', false)\r\n this.toggleClass('lenis-smooth', false)\r\n this.toggleClass('lenis-scrolling', false)\r\n this.toggleClass('lenis-stopped', false)\r\n this.toggleClass('lenis-locked', false)\r\n }\r\n\r\n on(event, callback) {\r\n return this.emitter.on(event, callback)\r\n }\r\n\r\n off(event, callback) {\r\n return this.emitter.off(event, callback)\r\n }\r\n\r\n setScroll(scroll) {\r\n // apply scroll value immediately\r\n if (this.isHorizontal) {\r\n this.rootElement.scrollLeft = scroll\r\n } else {\r\n this.rootElement.scrollTop = scroll\r\n }\r\n }\r\n\r\n onVirtualScroll = ({ deltaX, deltaY, event }) => {\r\n // keep zoom feature\r\n if (event.ctrlKey) return\r\n\r\n const isTouch = event.type.includes('touch')\r\n const isWheel = event.type.includes('wheel')\r\n\r\n if (\r\n (this.options.gestureOrientation === 'both' &&\r\n deltaX === 0 &&\r\n deltaY === 0) || // \"touchend\" events prevents \"click\"\r\n (this.options.gestureOrientation === 'vertical' && deltaY === 0) || // trackpad previous/next page gesture\r\n (this.options.gestureOrientation === 'horizontal' && deltaX === 0) ||\r\n (isTouch &&\r\n this.options.gestureOrientation === 'vertical' &&\r\n this.scroll === 0 &&\r\n !this.options.infinite &&\r\n deltaY <= 0) // touch pull to refresh\r\n )\r\n return\r\n\r\n // catch if scrolling on nested scroll elements\r\n let composedPath = event.composedPath()\r\n composedPath = composedPath.slice(0, composedPath.indexOf(this.rootElement)) // remove parents elements\r\n\r\n if (\r\n !!composedPath.find(\r\n (node) =>\r\n node.hasAttribute?.('data-lenis-prevent') ||\r\n (isTouch && node.hasAttribute?.('data-lenis-prevent-touch')) ||\r\n (isWheel && node.hasAttribute?.('data-lenis-prevent-wheel')) ||\r\n node.classList?.contains('lenis') // nested lenis instance\r\n )\r\n )\r\n return\r\n\r\n if (this.isStopped || this.isLocked) {\r\n event.preventDefault()\r\n return\r\n }\r\n\r\n this.isSmooth =\r\n ((this.options.smoothTouch || this.options.syncTouch) && isTouch) ||\r\n (this.options.smoothWheel && isWheel)\r\n\r\n if (!this.isSmooth) {\r\n this.isScrolling = false\r\n this.animate.stop()\r\n return\r\n }\r\n\r\n event.preventDefault()\r\n\r\n let delta = deltaY\r\n if (this.options.gestureOrientation === 'both') {\r\n delta = Math.abs(deltaY) > Math.abs(deltaX) ? deltaY : deltaX\r\n } else if (this.options.gestureOrientation === 'horizontal') {\r\n delta = deltaX\r\n }\r\n\r\n const syncTouch = isTouch && this.options.syncTouch\r\n const isTouchEnd = isTouch && event.type === 'touchend'\r\n const hasTouchInertia = isTouchEnd && Math.abs(delta) > 1\r\n if (hasTouchInertia) {\r\n delta = this.velocity * this.options.touchInertiaMultiplier\r\n }\r\n\r\n this.scrollTo(this.targetScroll + delta, {\r\n programmatic: false,\r\n ...(syncTouch && {\r\n lerp: hasTouchInertia\r\n ? this.syncTouchLerp\r\n : this.options.__iosNoInertiaSyncTouchLerp,\r\n }),\r\n })\r\n }\r\n\r\n resize() {\r\n this.dimensions.resize()\r\n }\r\n\r\n emit() {\r\n this.emitter.emit('scroll', this)\r\n }\r\n\r\n onNativeScroll = () => {\r\n if (this.__preventNextScrollEvent) return\r\n\r\n if (!this.isScrolling) {\r\n const lastScroll = this.animatedScroll\r\n this.animatedScroll = this.targetScroll = this.actualScroll\r\n this.velocity = 0\r\n this.direction = Math.sign(this.animatedScroll - lastScroll)\r\n this.emit()\r\n }\r\n }\r\n\r\n reset() {\r\n this.isLocked = false\r\n this.isScrolling = false\r\n this.animatedScroll = this.targetScroll = this.actualScroll\r\n this.velocity = 0\r\n this.animate.stop()\r\n }\r\n\r\n start() {\r\n this.isStopped = false\r\n\r\n this.reset()\r\n }\r\n\r\n stop() {\r\n this.isStopped = true\r\n this.animate.stop()\r\n\r\n this.reset()\r\n }\r\n\r\n raf(time) {\r\n const deltaTime = time - (this.time || time)\r\n this.time = time\r\n\r\n this.animate.advance(deltaTime * 0.001)\r\n }\r\n\r\n scrollTo(\r\n target,\r\n {\r\n offset = 0,\r\n immediate = false,\r\n lock = false,\r\n duration = this.options.duration,\r\n easing = this.options.easing,\r\n lerp = !duration && this.options.lerp,\r\n onComplete = null,\r\n force = false, // scroll even if stopped\r\n programmatic = true, // called from outside of the class\r\n } = {}\r\n ) {\r\n if ((this.isStopped || this.isLocked) && !force) return\r\n\r\n // keywords\r\n if (['top', 'left', 'start'].includes(target)) {\r\n target = 0\r\n } else if (['bottom', 'right', 'end'].includes(target)) {\r\n target = this.limit\r\n } else {\r\n let node\r\n\r\n if (typeof target === 'string') {\r\n // CSS selector\r\n node = document.querySelector(target)\r\n } else if (target?.nodeType) {\r\n // Node element\r\n node = target\r\n }\r\n\r\n if (node) {\r\n if (this.options.wrapper !== window) {\r\n // nested scroll offset correction\r\n const wrapperRect = this.options.wrapper.getBoundingClientRect()\r\n offset -= this.isHorizontal ? wrapperRect.left : wrapperRect.top\r\n }\r\n\r\n const rect = node.getBoundingClientRect()\r\n\r\n target =\r\n (this.isHorizontal ? rect.left : rect.top) + this.animatedScroll\r\n }\r\n }\r\n\r\n if (typeof target !== 'number') return\r\n\r\n target += offset\r\n target = Math.round(target)\r\n\r\n if (this.options.infinite) {\r\n if (programmatic) {\r\n this.targetScroll = this.animatedScroll = this.scroll\r\n }\r\n } else {\r\n target = clamp(0, target, this.limit)\r\n }\r\n\r\n if (immediate) {\r\n this.animatedScroll = this.targetScroll = target\r\n this.setScroll(this.scroll)\r\n this.reset()\r\n onComplete?.(this)\r\n return\r\n }\r\n\r\n if (!programmatic) {\r\n if (target === this.targetScroll) return\r\n\r\n this.targetScroll = target\r\n }\r\n\r\n this.animate.fromTo(this.animatedScroll, target, {\r\n duration,\r\n easing,\r\n lerp,\r\n onStart: () => {\r\n // started\r\n if (lock) this.isLocked = true\r\n this.isScrolling = true\r\n },\r\n onUpdate: (value, completed) => {\r\n this.isScrolling = true\r\n\r\n // updated\r\n this.velocity = value - this.animatedScroll\r\n this.direction = Math.sign(this.velocity)\r\n\r\n this.animatedScroll = value\r\n this.setScroll(this.scroll)\r\n\r\n if (programmatic) {\r\n // wheel during programmatic should stop it\r\n this.targetScroll = value\r\n }\r\n\r\n if (!completed) this.emit()\r\n\r\n if (completed) {\r\n this.reset()\r\n this.emit()\r\n onComplete?.(this)\r\n\r\n // avoid emitting event twice\r\n this.__preventNextScrollEvent = true\r\n requestAnimationFrame(() => {\r\n delete this.__preventNextScrollEvent\r\n })\r\n }\r\n },\r\n })\r\n }\r\n\r\n get rootElement() {\r\n return this.options.wrapper === window\r\n ? document.documentElement\r\n : this.options.wrapper\r\n }\r\n\r\n get limit() {\r\n return this.dimensions.limit[this.isHorizontal ? 'x' : 'y']\r\n }\r\n\r\n get isHorizontal() {\r\n return this.options.orientation === 'horizontal'\r\n }\r\n\r\n get actualScroll() {\r\n // value browser takes into account\r\n return this.isHorizontal\r\n ? this.rootElement.scrollLeft\r\n : this.rootElement.scrollTop\r\n }\r\n\r\n get scroll() {\r\n return this.options.infinite\r\n ? modulo(this.animatedScroll, this.limit)\r\n : this.animatedScroll\r\n }\r\n\r\n get progress() {\r\n // avoid progress to be NaN\r\n return this.limit === 0 ? 1 : this.scroll / this.limit\r\n }\r\n\r\n get isSmooth() {\r\n return this.__isSmooth\r\n }\r\n\r\n set isSmooth(value) {\r\n if (this.__isSmooth !== value) {\r\n this.__isSmooth = value\r\n this.toggleClass('lenis-smooth', value)\r\n }\r\n }\r\n\r\n get isScrolling() {\r\n return this.__isScrolling\r\n }\r\n\r\n set isScrolling(value) {\r\n if (this.__isScrolling !== value) {\r\n this.__isScrolling = value\r\n this.toggleClass('lenis-scrolling', value)\r\n }\r\n }\r\n\r\n get isStopped() {\r\n return this.__isStopped\r\n }\r\n\r\n set isStopped(value) {\r\n if (this.__isStopped !== value) {\r\n this.__isStopped = value\r\n this.toggleClass('lenis-stopped', value)\r\n }\r\n }\r\n\r\n get isLocked() {\r\n return this.__isLocked\r\n }\r\n\r\n set isLocked(value) {\r\n if (this.__isLocked !== value) {\r\n this.__isLocked = value\r\n this.toggleClass('lenis-locked', value)\r\n }\r\n }\r\n\r\n get className() {\r\n let className = 'lenis'\r\n if (this.isStopped) className += ' lenis-stopped'\r\n if (this.isLocked) className += ' lenis-locked'\r\n if (this.isScrolling) className += ' lenis-scrolling'\r\n if (this.isSmooth) className += ' lenis-smooth'\r\n return className\r\n }\r\n\r\n toggleClass(name, value) {\r\n this.rootElement.classList.toggle(name, value)\r\n this.emitter.emit('className change', this)\r\n }\r\n}\r\n"],"names":["clamp","min","input","max","Math","Animate","advance","deltaTime","this","isRunning","completed","lerp","value","x","y","to","lambda","dt","t","exp","round","currentTime","linearProgress","duration","easedProgress","easing","from","onUpdate","stop","fromTo","onStart","Dimensions","constructor","wrapper","content","autoResize","resize","callback","delay","timer","args","arguments","context","clearTimeout","setTimeout","apply","debounce","window","wrapperResizeObserver","ResizeObserver","observe","contentResizeObserver","destroy","disconnect","onWrapperResize","onContentResize","width","innerWidth","height","innerHeight","clientWidth","clientHeight","scrollHeight","scrollWidth","limit","Emitter","events","emit","event","callbacks","i","length","on","cb","push","filter","off","VirtualScroll","element","wheelMultiplier","touchMultiplier","normalizeWheel","touchStart","emitter","addEventListener","onWheel","passive","onTouchStart","onTouchMove","onTouchEnd","removeEventListener","clientX","clientY","targetTouches","lastDelta","deltaX","deltaY","Lenis","document","documentElement","wheelEventsTarget","eventsTarget","smoothWheel","smoothTouch","syncTouch","syncTouchLerp","__iosNoInertiaSyncTouchLerp","touchInertiaMultiplier","pow","infinite","orientation","gestureOrientation","lenisVersion","body","options","animate","dimensions","toggleClass","velocity","isLocked","isStopped","isSmooth","isScrolling","targetScroll","animatedScroll","actualScroll","onNativeScroll","virtualScroll","onVirtualScroll","setScroll","scroll","isHorizontal","rootElement","scrollLeft","scrollTop","ctrlKey","isTouch","type","includes","isWheel","composedPath","slice","indexOf","find","node","hasAttribute","classList","contains","preventDefault","delta","abs","hasTouchInertia","scrollTo","programmatic","__preventNextScrollEvent","lastScroll","direction","sign","reset","start","raf","time","target","offset","immediate","lock","onComplete","force","querySelector","nodeType","wrapperRect","getBoundingClientRect","left","top","rect","requestAnimationFrame","n","d","progress","__isSmooth","__isScrolling","__isStopped","__isLocked","className","name","toggle"],"mappings":"AACO,SAASA,EAAMC,EAAKC,EAAOC,GAChC,OAAOC,KAAKD,IAAIF,EAAKG,KAAKH,IAAIC,EAAOC,GACvC,CCAO,MAAME,QAEX,OAAAC,CAAQC,GACN,IAAKC,KAAKC,UAAW,OAErB,IAAIC,GAAY,EAEhB,GAAIF,KAAKG,KACPH,KAAKI,ODKUC,ECLGL,KAAKI,MDKLE,ECLYN,KAAKO,GDKdC,ECL8B,GAAZR,KAAKG,KDKfM,ECL0BV,EDAtD,SAAcM,EAAGC,EAAGI,GACzB,OAAQ,EAAIA,GAAKL,EAAIK,EAAIJ,CAC3B,CAISH,CAAKE,EAAGC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B,IAAf1K,KAAKwD,MAAc,EAAIxD,KAAK0H,OAAS1H,KAAKwD,KAClD,CAED,YAAIyD,GACF,OAAOjH,KAAK2K,UACb,CAED,YAAI1D,CAAS7G,GACPJ,KAAK2K,aAAevK,IACtBJ,KAAK2K,WAAavK,EAClBJ,KAAK6G,YAAY,eAAgBzG,GAEpC,CAED,eAAI8G,GACF,OAAOlH,KAAK4K,aACb,CAED,eAAI1D,CAAY9G,GACVJ,KAAK4K,gBAAkBxK,IACzBJ,KAAK4K,cAAgBxK,EACrBJ,KAAK6G,YAAY,kBAAmBzG,GAEvC,CAED,aAAI4G,GACF,OAAOhH,KAAK6K,WACb,CAED,aAAI7D,CAAU5G,GACRJ,KAAK6K,cAAgBzK,IACvBJ,KAAK6K,YAAczK,EACnBJ,KAAK6G,YAAY,gBAAiBzG,GAErC,CAED,YAAI2G,GACF,OAAO/G,KAAK8K,UACb,CAED,YAAI/D,CAAS3G,GACPJ,KAAK8K,aAAe1K,IACtBJ,KAAK8K,WAAa1K,EAClBJ,KAAK6G,YAAY,eAAgBzG,GAEpC,CAED,aAAI2K,GACF,IAAIA,EAAY,QAKhB,OAJI/K,KAAKgH,YAAW+D,GAAa,kBAC7B/K,KAAK+G,WAAUgE,GAAa,iBAC5B/K,KAAKkH,cAAa6D,GAAa,oBAC/B/K,KAAKiH,WAAU8D,GAAa,iBACzBA,CACR,CAED,WAAAlE,CAAYmE,EAAM5K,GAChBJ,KAAK4H,YAAYc,UAAUuC,OAAOD,EAAM5K,GACxCJ,KAAK2E,QAAQhB,KAAK,mBAAoB3D,KACvC"} \ No newline at end of file +{"version":3,"file":"lenis.esm.js","sources":["../src/maths.js","../src/animate.js","../src/dimensions.js","../src/debounce.js","../src/emitter.js","../src/virtual-scroll.js","../src/index.js"],"sourcesContent":["// Clamp a value between a minimum and maximum value\r\nexport function clamp(min, input, max) {\r\n return Math.max(min, Math.min(input, max))\r\n}\r\n\r\n// Truncate a floating-point number to a specified number of decimal places\r\nexport function truncate(value, decimals = 0) {\r\n return parseFloat(value.toFixed(decimals))\r\n}\r\n\r\n// Linearly interpolate between two values using an amount (0 <= t <= 1)\r\nexport function lerp(x, y, t) {\r\n return (1 - t) * x + t * y\r\n}\r\n\r\n// http://www.rorydriscoll.com/2016/03/07/frame-rate-independent-damping-using-lerp/\r\nexport function damp(x, y, lambda, dt) {\r\n return lerp(x, y, 1 - Math.exp(-lambda * dt))\r\n}\r\n\r\n// Calculate the modulo of the dividend and divisor while keeping the result within the same sign as the divisor\r\n// https://anguscroll.com/just/just-modulo\r\nexport function modulo(n, d) {\r\n return ((n % d) + d) % d\r\n}\r\n","import { clamp, damp } from './maths'\r\n\r\n// Animate class to handle value animations with lerping or easing\r\nexport class Animate {\r\n // Advance the animation by the given delta time\r\n advance(deltaTime) {\r\n if (!this.isRunning) return\r\n\r\n let completed = false\r\n\r\n if (this.lerp) {\r\n this.value = damp(this.value, this.to, this.lerp * 60, deltaTime)\r\n if (Math.round(this.value) === this.to) {\r\n this.value = this.to\r\n completed = true\r\n }\r\n } else {\r\n this.currentTime += deltaTime\r\n const linearProgress = clamp(0, this.currentTime / this.duration, 1)\r\n\r\n completed = linearProgress >= 1\r\n const easedProgress = completed ? 1 : this.easing(linearProgress)\r\n this.value = this.from + (this.to - this.from) * easedProgress\r\n }\r\n\r\n // Call the onUpdate callback with the current value and completed status\r\n this.onUpdate?.(this.value, completed)\r\n\r\n if (completed) {\r\n this.stop()\r\n }\r\n }\r\n\r\n // Stop the animation\r\n stop() {\r\n this.isRunning = false\r\n }\r\n\r\n // Set up the animation from a starting value to an ending value\r\n // with optional parameters for lerping, duration, easing, and onUpdate callback\r\n fromTo(\r\n from,\r\n to,\r\n { lerp = 0.1, duration = 1, easing = (t) => t, onStart, onUpdate }\r\n ) {\r\n this.from = this.value = from\r\n this.to = to\r\n this.lerp = lerp\r\n this.duration = duration\r\n this.easing = easing\r\n this.currentTime = 0\r\n this.isRunning = true\r\n\r\n onStart?.()\r\n this.onUpdate = onUpdate\r\n }\r\n}\r\n","import { debounce } from './debounce'\r\n\r\nexport class Dimensions {\r\n constructor({ wrapper, content, autoResize = true } = {}) {\r\n this.wrapper = wrapper\r\n this.content = content\r\n\r\n if (autoResize) {\r\n const resize = debounce(this.resize, 250)\r\n\r\n if (this.wrapper !== window) {\r\n this.wrapperResizeObserver = new ResizeObserver(resize)\r\n this.wrapperResizeObserver.observe(this.wrapper)\r\n }\r\n\r\n this.contentResizeObserver = new ResizeObserver(resize)\r\n this.contentResizeObserver.observe(this.content)\r\n }\r\n\r\n this.resize()\r\n }\r\n\r\n destroy() {\r\n this.wrapperResizeObserver?.disconnect()\r\n this.contentResizeObserver?.disconnect()\r\n }\r\n\r\n resize = () => {\r\n this.onWrapperResize()\r\n this.onContentResize()\r\n }\r\n\r\n onWrapperResize = () => {\r\n if (this.wrapper === window) {\r\n this.width = window.innerWidth\r\n this.height = window.innerHeight\r\n } else {\r\n this.width = this.wrapper.clientWidth\r\n this.height = this.wrapper.clientHeight\r\n }\r\n }\r\n\r\n onContentResize = () => {\r\n this.scrollHeight = this.content.scrollHeight\r\n this.scrollWidth = this.content.scrollWidth\r\n }\r\n\r\n get limit() {\r\n return {\r\n x: this.scrollWidth - this.width,\r\n y: this.scrollHeight - this.height,\r\n }\r\n }\r\n}\r\n","export function debounce(callback, delay) {\r\n let timer\r\n return function () {\r\n let args = arguments\r\n let context = this\r\n clearTimeout(timer)\r\n timer = setTimeout(function () {\r\n callback.apply(context, args)\r\n }, delay)\r\n }\r\n}\r\n","export class Emitter {\r\n constructor() {\r\n this.events = {}\r\n }\r\n\r\n emit(event, ...args) {\r\n let callbacks = this.events[event] || []\r\n for (let i = 0, length = callbacks.length; i < length; i++) {\r\n callbacks[i](...args)\r\n }\r\n }\r\n\r\n on(event, cb) {\r\n // Add the callback to the event's callback list, or create a new list with the callback\r\n this.events[event]?.push(cb) || (this.events[event] = [cb])\r\n\r\n // Return an unsubscribe function\r\n return () => {\r\n this.events[event] = this.events[event]?.filter((i) => cb !== i)\r\n }\r\n }\r\n\r\n off(event, callback) {\r\n this.events[event] = this.events[event]?.filter((i) => callback !== i)\r\n }\r\n\r\n destroy() {\r\n this.events = {}\r\n }\r\n}\r\n","import { Emitter } from './emitter'\r\nimport { clamp } from './maths'\r\n\r\nexport class VirtualScroll {\r\n constructor(\r\n element,\r\n { wheelMultiplier = 1, touchMultiplier = 2, normalizeWheel = false }\r\n ) {\r\n this.element = element\r\n this.wheelMultiplier = wheelMultiplier\r\n this.touchMultiplier = touchMultiplier\r\n this.normalizeWheel = normalizeWheel\r\n\r\n this.touchStart = {\r\n x: null,\r\n y: null,\r\n }\r\n\r\n this.emitter = new Emitter()\r\n\r\n this.element.addEventListener('wheel', this.onWheel, { passive: false })\r\n this.element.addEventListener('touchstart', this.onTouchStart, {\r\n passive: false,\r\n })\r\n this.element.addEventListener('touchmove', this.onTouchMove, {\r\n passive: false,\r\n })\r\n this.element.addEventListener('touchend', this.onTouchEnd, {\r\n passive: false,\r\n })\r\n }\r\n\r\n // Add an event listener for the given event and callback\r\n on(event, callback) {\r\n return this.emitter.on(event, callback)\r\n }\r\n\r\n // Remove all event listeners and clean up\r\n destroy() {\r\n this.emitter.destroy()\r\n\r\n this.element.removeEventListener('wheel', this.onWheel, {\r\n passive: false,\r\n })\r\n this.element.removeEventListener('touchstart', this.onTouchStart, {\r\n passive: false,\r\n })\r\n this.element.removeEventListener('touchmove', this.onTouchMove, {\r\n passive: false,\r\n })\r\n this.element.removeEventListener('touchend', this.onTouchEnd, {\r\n passive: false,\r\n })\r\n }\r\n\r\n // Event handler for 'touchstart' event\r\n onTouchStart = (event) => {\r\n const { clientX, clientY } = event.targetTouches\r\n ? event.targetTouches[0]\r\n : event\r\n\r\n this.touchStart.x = clientX\r\n this.touchStart.y = clientY\r\n\r\n this.lastDelta = {\r\n x: 0,\r\n y: 0,\r\n }\r\n\r\n this.emitter.emit('scroll', {\r\n deltaX: 0,\r\n deltaY: 0,\r\n event,\r\n })\r\n }\r\n\r\n // Event handler for 'touchmove' event\r\n onTouchMove = (event) => {\r\n const { clientX, clientY } = event.targetTouches\r\n ? event.targetTouches[0]\r\n : event\r\n\r\n const deltaX = -(clientX - this.touchStart.x) * this.touchMultiplier\r\n const deltaY = -(clientY - this.touchStart.y) * this.touchMultiplier\r\n\r\n this.touchStart.x = clientX\r\n this.touchStart.y = clientY\r\n\r\n this.lastDelta = {\r\n x: deltaX,\r\n y: deltaY,\r\n }\r\n\r\n this.emitter.emit('scroll', {\r\n deltaX,\r\n deltaY,\r\n event,\r\n })\r\n }\r\n\r\n onTouchEnd = (event) => {\r\n this.emitter.emit('scroll', {\r\n deltaX: this.lastDelta.x,\r\n deltaY: this.lastDelta.y,\r\n event,\r\n })\r\n }\r\n\r\n // Event handler for 'wheel' event\r\n onWheel = (event) => {\r\n let { deltaX, deltaY } = event\r\n\r\n if (this.normalizeWheel) {\r\n deltaX = clamp(-100, deltaX, 100)\r\n deltaY = clamp(-100, deltaY, 100)\r\n }\r\n\r\n deltaX *= this.wheelMultiplier\r\n deltaY *= this.wheelMultiplier\r\n\r\n this.emitter.emit('scroll', { deltaX, deltaY, event })\r\n }\r\n}\r\n","import { version } from '../package.json'\r\nimport { Animate } from './animate'\r\nimport { Dimensions } from './dimensions'\r\nimport { Emitter } from './emitter'\r\nimport { clamp, modulo } from './maths'\r\nimport { VirtualScroll } from './virtual-scroll'\r\n\r\n// Technical explanation\r\n// - listen to 'wheel' events\r\n// - prevent 'wheel' event to prevent scroll\r\n// - normalize wheel delta\r\n// - add delta to targetScroll\r\n// - animate scroll to targetScroll (smooth context)\r\n// - if animation is not running, listen to 'scroll' events (native context)\r\n\r\nexport default class Lenis {\r\n // isScrolling = true when scroll is animating\r\n // isStopped = true if user should not be able to scroll - enable/disable programmatically\r\n // isSmooth = true if scroll should be animated\r\n // isLocked = same as isStopped but enabled/disabled when scroll reaches target\r\n\r\n /**\r\n * @typedef {(t: number) => number} EasingFunction\r\n * @typedef {'vertical' | 'horizontal'} Orientation\r\n * @typedef {'vertical' | 'horizontal' | 'both'} GestureOrientation\r\n *\r\n * @typedef LenisOptions\r\n * @property {Window | HTMLElement} [wrapper]\r\n * @property {HTMLElement} [content]\r\n * @property {Window | HTMLElement} [wheelEventsTarget] // deprecated\r\n * @property {Window | HTMLElement} [eventsTarget]\r\n * @property {boolean} [smoothWheel]\r\n * @property {boolean} [smoothTouch]\r\n * @property {boolean} [syncTouch]\r\n * @property {number} [syncTouchLerp]\r\n // * @property {number} [__iosNoInertiaSyncTouchLerp]\r\n * @property {number} [touchInertiaMultiplier]\r\n * @property {number} [duration]\r\n * @property {EasingFunction} [easing]\r\n * @property {number} [lerp]\r\n * @property {boolean} [infinite]\r\n * @property {Orientation} [orientation]\r\n * @property {GestureOrientation} [gestureOrientation]\r\n * @property {number} [touchMultiplier]\r\n * @property {number} [wheelMultiplier]\r\n * @property {boolean} [normalizeWheel]\r\n * @property {boolean} [autoResize]\r\n *\r\n * @param {LenisOptions}\r\n */\r\n constructor({\r\n wrapper = window,\r\n content = document.documentElement,\r\n wheelEventsTarget = wrapper, // deprecated\r\n eventsTarget = wheelEventsTarget,\r\n smoothWheel = true,\r\n smoothTouch = false,\r\n syncTouch = false,\r\n syncTouchLerp = 0.075,\r\n // __iosNoInertiaSyncTouchLerp = 0.4, // should be 1 but had to leave 0.4 for iOS (testing purpose)\r\n touchInertiaMultiplier = 35,\r\n duration, // in seconds\r\n easing = (t) => Math.min(1, 1.001 - Math.pow(2, -10 * t)),\r\n lerp = !duration && 0.1,\r\n infinite = false,\r\n orientation = 'vertical', // vertical, horizontal\r\n gestureOrientation = 'vertical', // vertical, horizontal, both\r\n touchMultiplier = 1,\r\n wheelMultiplier = 1,\r\n normalizeWheel = false,\r\n autoResize = true,\r\n } = {}) {\r\n window.lenisVersion = version\r\n\r\n // if wrapper is html or body, fallback to window\r\n if (wrapper === document.documentElement || wrapper === document.body) {\r\n wrapper = window\r\n }\r\n\r\n this.options = {\r\n wrapper,\r\n content,\r\n wheelEventsTarget,\r\n eventsTarget,\r\n smoothWheel,\r\n smoothTouch,\r\n syncTouch,\r\n syncTouchLerp,\r\n // __iosNoInertiaSyncTouchLerp,\r\n touchInertiaMultiplier,\r\n duration,\r\n easing,\r\n lerp,\r\n infinite,\r\n gestureOrientation,\r\n orientation,\r\n touchMultiplier,\r\n wheelMultiplier,\r\n normalizeWheel,\r\n autoResize,\r\n }\r\n\r\n this.animate = new Animate()\r\n this.emitter = new Emitter()\r\n this.dimensions = new Dimensions({ wrapper, content, autoResize })\r\n this.toggleClass('lenis', true)\r\n\r\n this.velocity = 0\r\n this.isLocked = false\r\n this.isStopped = false\r\n this.isSmooth = syncTouch || smoothWheel || smoothTouch\r\n this.isScrolling = false\r\n this.targetScroll = this.animatedScroll = this.actualScroll\r\n\r\n this.options.wrapper.addEventListener('scroll', this.onNativeScroll, {\r\n passive: false,\r\n })\r\n\r\n this.virtualScroll = new VirtualScroll(eventsTarget, {\r\n touchMultiplier,\r\n wheelMultiplier,\r\n normalizeWheel,\r\n })\r\n this.virtualScroll.on('scroll', this.onVirtualScroll)\r\n }\r\n\r\n destroy() {\r\n this.emitter.destroy()\r\n\r\n this.options.wrapper.removeEventListener('scroll', this.onNativeScroll, {\r\n passive: false,\r\n })\r\n\r\n this.virtualScroll.destroy()\r\n this.dimensions.destroy()\r\n\r\n this.toggleClass('lenis', false)\r\n this.toggleClass('lenis-smooth', false)\r\n this.toggleClass('lenis-scrolling', false)\r\n this.toggleClass('lenis-stopped', false)\r\n this.toggleClass('lenis-locked', false)\r\n }\r\n\r\n on(event, callback) {\r\n return this.emitter.on(event, callback)\r\n }\r\n\r\n off(event, callback) {\r\n return this.emitter.off(event, callback)\r\n }\r\n\r\n setScroll(scroll) {\r\n // apply scroll value immediately\r\n if (this.isHorizontal) {\r\n this.rootElement.scrollLeft = scroll\r\n } else {\r\n this.rootElement.scrollTop = scroll\r\n }\r\n }\r\n\r\n onVirtualScroll = ({ deltaX, deltaY, event }) => {\r\n // keep zoom feature\r\n if (event.ctrlKey) return\r\n\r\n const isTouch = event.type.includes('touch')\r\n const isWheel = event.type.includes('wheel')\r\n\r\n const isTapToStop =\r\n (this.options.smoothTouch || this.options.syncTouch) &&\r\n isTouch &&\r\n event.type === 'touchstart'\r\n\r\n if (isTapToStop) {\r\n this.reset()\r\n return\r\n }\r\n\r\n const isClick = deltaX === 0 && deltaY === 0 // click event\r\n\r\n // const isPullToRefresh =\r\n // this.options.gestureOrientation === 'vertical' &&\r\n // this.scroll === 0 &&\r\n // !this.options.infinite &&\r\n // deltaY <= 5 // touch pull to refresh, not reliable yet\r\n\r\n const isUnknownGesture =\r\n (this.options.gestureOrientation === 'vertical' && deltaY === 0) ||\r\n (this.options.gestureOrientation === 'horizontal' && deltaX === 0)\r\n\r\n if (isClick || isUnknownGesture) {\r\n // console.log('prevent')\r\n return\r\n }\r\n\r\n // catch if scrolling on nested scroll elements\r\n let composedPath = event.composedPath()\r\n composedPath = composedPath.slice(0, composedPath.indexOf(this.rootElement)) // remove parents elements\r\n\r\n if (\r\n !!composedPath.find(\r\n (node) =>\r\n node.hasAttribute?.('data-lenis-prevent') ||\r\n (isTouch && node.hasAttribute?.('data-lenis-prevent-touch')) ||\r\n (isWheel && node.hasAttribute?.('data-lenis-prevent-wheel')) ||\r\n node.classList?.contains('lenis') // nested lenis instance\r\n )\r\n )\r\n return\r\n\r\n if (this.isStopped || this.isLocked) {\r\n event.preventDefault()\r\n return\r\n }\r\n\r\n this.isSmooth =\r\n ((this.options.smoothTouch || this.options.syncTouch) && isTouch) ||\r\n (this.options.smoothWheel && isWheel)\r\n\r\n if (!this.isSmooth) {\r\n this.isScrolling = false\r\n this.animate.stop()\r\n return\r\n }\r\n\r\n event.preventDefault()\r\n\r\n let delta = deltaY\r\n if (this.options.gestureOrientation === 'both') {\r\n delta = Math.abs(deltaY) > Math.abs(deltaX) ? deltaY : deltaX\r\n } else if (this.options.gestureOrientation === 'horizontal') {\r\n delta = deltaX\r\n }\r\n\r\n const syncTouch = isTouch && this.options.syncTouch\r\n const isTouchEnd = isTouch && event.type === 'touchend'\r\n\r\n const hasTouchInertia = isTouchEnd && Math.abs(delta) > 5\r\n\r\n if (hasTouchInertia) {\r\n delta = this.velocity * this.options.touchInertiaMultiplier\r\n }\r\n\r\n this.scrollTo(this.targetScroll + delta, {\r\n programmatic: false,\r\n ...(syncTouch\r\n ? {\r\n lerp: hasTouchInertia ? this.options.syncTouchLerp : 1,\r\n }\r\n : {\r\n lerp: this.options.lerp,\r\n duration: this.options.duration,\r\n easing: this.options.easing,\r\n }),\r\n })\r\n }\r\n\r\n resize() {\r\n this.dimensions.resize()\r\n }\r\n\r\n emit() {\r\n this.emitter.emit('scroll', this)\r\n }\r\n\r\n onNativeScroll = () => {\r\n if (this.__preventNextScrollEvent) return\r\n\r\n if (!this.isScrolling) {\r\n const lastScroll = this.animatedScroll\r\n this.animatedScroll = this.targetScroll = this.actualScroll\r\n this.velocity = 0\r\n this.direction = Math.sign(this.animatedScroll - lastScroll)\r\n this.emit()\r\n }\r\n }\r\n\r\n reset() {\r\n this.isLocked = false\r\n this.isScrolling = false\r\n this.animatedScroll = this.targetScroll = this.actualScroll\r\n this.velocity = 0\r\n this.animate.stop()\r\n }\r\n\r\n start() {\r\n this.isStopped = false\r\n\r\n this.reset()\r\n }\r\n\r\n stop() {\r\n this.isStopped = true\r\n this.animate.stop()\r\n\r\n this.reset()\r\n }\r\n\r\n raf(time) {\r\n const deltaTime = time - (this.time || time)\r\n this.time = time\r\n\r\n this.animate.advance(deltaTime * 0.001)\r\n }\r\n\r\n scrollTo(\r\n target,\r\n {\r\n offset = 0,\r\n immediate = false,\r\n lock = false,\r\n duration = this.options.duration,\r\n easing = this.options.easing,\r\n lerp = !duration && this.options.lerp,\r\n onComplete = null,\r\n force = false, // scroll even if stopped\r\n programmatic = true, // called from outside of the class\r\n } = {}\r\n ) {\r\n if ((this.isStopped || this.isLocked) && !force) return\r\n\r\n // keywords\r\n if (['top', 'left', 'start'].includes(target)) {\r\n target = 0\r\n } else if (['bottom', 'right', 'end'].includes(target)) {\r\n target = this.limit\r\n } else {\r\n let node\r\n\r\n if (typeof target === 'string') {\r\n // CSS selector\r\n node = document.querySelector(target)\r\n } else if (target?.nodeType) {\r\n // Node element\r\n node = target\r\n }\r\n\r\n if (node) {\r\n if (this.options.wrapper !== window) {\r\n // nested scroll offset correction\r\n const wrapperRect = this.options.wrapper.getBoundingClientRect()\r\n offset -= this.isHorizontal ? wrapperRect.left : wrapperRect.top\r\n }\r\n\r\n const rect = node.getBoundingClientRect()\r\n\r\n target =\r\n (this.isHorizontal ? rect.left : rect.top) + this.animatedScroll\r\n }\r\n }\r\n\r\n if (typeof target !== 'number') return\r\n\r\n target += offset\r\n target = Math.round(target)\r\n\r\n if (this.options.infinite) {\r\n if (programmatic) {\r\n this.targetScroll = this.animatedScroll = this.scroll\r\n }\r\n } else {\r\n target = clamp(0, target, this.limit)\r\n }\r\n\r\n if (immediate) {\r\n this.animatedScroll = this.targetScroll = target\r\n this.setScroll(this.scroll)\r\n this.reset()\r\n onComplete?.(this)\r\n return\r\n }\r\n\r\n if (!programmatic) {\r\n if (target === this.targetScroll) return\r\n\r\n this.targetScroll = target\r\n }\r\n\r\n this.animate.fromTo(this.animatedScroll, target, {\r\n duration,\r\n easing,\r\n lerp,\r\n onStart: () => {\r\n // started\r\n if (lock) this.isLocked = true\r\n this.isScrolling = true\r\n },\r\n onUpdate: (value, completed) => {\r\n this.isScrolling = true\r\n\r\n // updated\r\n this.velocity = value - this.animatedScroll\r\n this.direction = Math.sign(this.velocity)\r\n\r\n this.animatedScroll = value\r\n this.setScroll(this.scroll)\r\n\r\n if (programmatic) {\r\n // wheel during programmatic should stop it\r\n this.targetScroll = value\r\n }\r\n\r\n if (!completed) this.emit()\r\n\r\n if (completed) {\r\n this.reset()\r\n this.emit()\r\n onComplete?.(this)\r\n\r\n // avoid emitting event twice\r\n this.__preventNextScrollEvent = true\r\n requestAnimationFrame(() => {\r\n delete this.__preventNextScrollEvent\r\n })\r\n }\r\n },\r\n })\r\n }\r\n\r\n get rootElement() {\r\n return this.options.wrapper === window\r\n ? document.documentElement\r\n : this.options.wrapper\r\n }\r\n\r\n get limit() {\r\n return this.dimensions.limit[this.isHorizontal ? 'x' : 'y']\r\n }\r\n\r\n get isHorizontal() {\r\n return this.options.orientation === 'horizontal'\r\n }\r\n\r\n get actualScroll() {\r\n // value browser takes into account\r\n return this.isHorizontal\r\n ? this.rootElement.scrollLeft\r\n : this.rootElement.scrollTop\r\n }\r\n\r\n get scroll() {\r\n return this.options.infinite\r\n ? modulo(this.animatedScroll, this.limit)\r\n : this.animatedScroll\r\n }\r\n\r\n get progress() {\r\n // avoid progress to be NaN\r\n return this.limit === 0 ? 1 : this.scroll / this.limit\r\n }\r\n\r\n get isSmooth() {\r\n return this.__isSmooth\r\n }\r\n\r\n set isSmooth(value) {\r\n if (this.__isSmooth !== value) {\r\n this.__isSmooth = value\r\n this.toggleClass('lenis-smooth', value)\r\n }\r\n }\r\n\r\n get isScrolling() {\r\n return this.__isScrolling\r\n }\r\n\r\n set isScrolling(value) {\r\n if (this.__isScrolling !== value) {\r\n this.__isScrolling = value\r\n this.toggleClass('lenis-scrolling', value)\r\n }\r\n }\r\n\r\n get isStopped() {\r\n return this.__isStopped\r\n }\r\n\r\n set isStopped(value) {\r\n if (this.__isStopped !== value) {\r\n this.__isStopped = value\r\n this.toggleClass('lenis-stopped', value)\r\n }\r\n }\r\n\r\n get isLocked() {\r\n return this.__isLocked\r\n }\r\n\r\n set isLocked(value) {\r\n if (this.__isLocked !== value) {\r\n this.__isLocked = value\r\n this.toggleClass('lenis-locked', value)\r\n }\r\n }\r\n\r\n get className() {\r\n let className = 'lenis'\r\n if (this.isStopped) className += ' lenis-stopped'\r\n if (this.isLocked) className += ' lenis-locked'\r\n if (this.isScrolling) className += ' lenis-scrolling'\r\n if (this.isSmooth) className += ' lenis-smooth'\r\n return className\r\n }\r\n\r\n toggleClass(name, value) {\r\n this.rootElement.classList.toggle(name, value)\r\n this.emitter.emit('className change', this)\r\n }\r\n}\r\n"],"names":["clamp","min","input","max","Math","Animate","advance","deltaTime","this","isRunning","completed","lerp","value","x","y","to","lambda","dt","t","exp","round","currentTime","linearProgress","duration","easedProgress","easing","from","onUpdate","stop","fromTo","onStart","Dimensions","constructor","wrapper","content","autoResize","resize","callback","delay","timer","args","arguments","context","clearTimeout","setTimeout","apply","debounce","window","wrapperResizeObserver","ResizeObserver","observe","contentResizeObserver","destroy","disconnect","onWrapperResize","onContentResize","width","innerWidth","height","innerHeight","clientWidth","clientHeight","scrollHeight","scrollWidth","limit","Emitter","events","emit","event","callbacks","i","length","on","cb","push","filter","off","VirtualScroll","element","wheelMultiplier","touchMultiplier","normalizeWheel","touchStart","emitter","addEventListener","onWheel","passive","onTouchStart","onTouchMove","onTouchEnd","removeEventListener","clientX","clientY","targetTouches","lastDelta","deltaX","deltaY","Lenis","document","documentElement","wheelEventsTarget","eventsTarget","smoothWheel","smoothTouch","syncTouch","syncTouchLerp","touchInertiaMultiplier","pow","infinite","orientation","gestureOrientation","lenisVersion","body","options","animate","dimensions","toggleClass","velocity","isLocked","isStopped","isSmooth","isScrolling","targetScroll","animatedScroll","actualScroll","onNativeScroll","virtualScroll","onVirtualScroll","setScroll","scroll","isHorizontal","rootElement","scrollLeft","scrollTop","ctrlKey","isTouch","type","includes","isWheel","reset","isClick","isUnknownGesture","composedPath","slice","indexOf","find","node","hasAttribute","classList","contains","preventDefault","delta","abs","hasTouchInertia","scrollTo","programmatic","__preventNextScrollEvent","lastScroll","direction","sign","start","raf","time","target","offset","immediate","lock","onComplete","force","querySelector","nodeType","wrapperRect","getBoundingClientRect","left","top","rect","requestAnimationFrame","n","d","progress","__isSmooth","__isScrolling","__isStopped","__isLocked","className","name","toggle"],"mappings":"AACO,SAASA,EAAMC,EAAKC,EAAOC,GAChC,OAAOC,KAAKD,IAAIF,EAAKG,KAAKH,IAAIC,EAAOC,GACvC,CCAO,MAAME,QAEX,OAAAC,CAAQC,GACN,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KgH,WAAUgE,GAAa,iBACzBA,CACR,CAED,WAAApE,CAAYqE,EAAM7K,GAChBJ,KAAK2H,YAAYiB,UAAUsC,OAAOD,EAAM7K,GACxCJ,KAAK2E,QAAQhB,KAAK,mBAAoB3D,KACvC"} \ No newline at end of file diff --git a/packages/lenis/dist/lenis.min.js b/packages/lenis/dist/lenis.min.js index 2b3fa290..ead332df 100644 --- a/packages/lenis/dist/lenis.min.js +++ b/packages/lenis/dist/lenis.min.js @@ -1 +1 @@ -var t,e;t=this,e=function(){function t(t,e,i){return Math.max(t,Math.min(e,i))}class e{advance(e){if(!this.isRunning)return;let i=!1;if(this.lerp)this.value=(s=this.value,o=this.to,n=60*this.lerp,r=e,function(t,e,i){return(1-i)*t+i*e}(s,o,1-Math.exp(-n*r))),Math.round(this.value)===this.to&&(this.value=this.to,i=!0);else{this.currentTime+=e;const s=t(0,this.currentTime/this.duration,1);i=s>=1;const o=i?1:this.easing(s);this.value=this.from+(this.to-this.from)*o}var s,o,n,r;this.onUpdate?.(this.value,i),i&&this.stop()}stop(){this.isRunning=!1}fromTo(t,e,{lerp:i=.1,duration:s=1,easing:o=(t=>t),onStart:n,onUpdate:r}){this.from=this.value=t,this.to=e,this.lerp=i,this.duration=s,this.easing=o,this.currentTime=0,this.isRunning=!0,n?.(),this.onUpdate=r}}class i{constructor({wrapper:t,content:e,autoResize:i=!0}={}){if(this.wrapper=t,this.content=e,i){const t=function(t,e){let i;return function(){let e=arguments,s=this;clearTimeout(i),i=setTimeout((function(){t.apply(s,e)}),250)}}(this.resize);this.wrapper!==window&&(this.wrapperResizeObserver=new ResizeObserver(t),this.wrapperResizeObserver.observe(this.wrapper)),this.contentResizeObserver=new ResizeObserver(t),this.contentResizeObserver.observe(this.content)}this.resize()}destroy(){this.wrapperResizeObserver?.disconnect(),this.contentResizeObserver?.disconnect()}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.scrollHeight=this.content.scrollHeight,this.scrollWidth=this.content.scrollWidth};get limit(){return{x:this.scrollWidth-this.width,y:this.scrollHeight-this.height}}}class s{constructor(){this.events={}}emit(t,...e){let i=this.events[t]||[];for(let t=0,s=i.length;t{this.events[t]=this.events[t]?.filter((t=>e!==t))}}off(t,e){this.events[t]=this.events[t]?.filter((t=>e!==t))}destroy(){this.events={}}}class o{constructor(t,{wheelMultiplier:e=1,touchMultiplier:i=2,normalizeWheel:o=!1}){this.element=t,this.wheelMultiplier=e,this.touchMultiplier=i,this.normalizeWheel=o,this.touchStart={x:null,y:null},this.emitter=new s,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,e){return this.emitter.on(t,e)}destroy(){this.emitter.destroy(),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=>{const{clientX:e,clientY:i}=t.targetTouches?t.targetTouches[0]:t;this.touchStart.x=e,this.touchStart.y=i,this.lastDelta={x:0,y:0}};onTouchMove=t=>{const{clientX:e,clientY:i}=t.targetTouches?t.targetTouches[0]:t,s=-(e-this.touchStart.x)*this.touchMultiplier,o=-(i-this.touchStart.y)*this.touchMultiplier;this.touchStart.x=e,this.touchStart.y=i,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=e=>{let{deltaX:i,deltaY:s}=e;this.normalizeWheel&&(i=t(-100,i,100),s=t(-100,s,100)),i*=this.wheelMultiplier,s*=this.wheelMultiplier,this.emitter.emit("scroll",{deltaX:i,deltaY:s,event:e})}}return class{constructor({wrapper:t=window,content:n=document.documentElement,wheelEventsTarget:r=t,eventsTarget:l=r,smoothWheel:h=!0,smoothTouch:a=!1,syncTouch:c=!1,syncTouchLerp:p=.1,__iosNoInertiaSyncTouchLerp:u=.4,touchInertiaMultiplier:d=35,duration:m,easing:g=(t=>Math.min(1,1.001-Math.pow(2,-10*t))),lerp:v=!m&&.1,infinite:S=!1,orientation:f="vertical",gestureOrientation:w="vertical",touchMultiplier:y=1,wheelMultiplier:T=1,normalizeWheel:z=!1,autoResize:_=!0}={}){window.lenisVersion="0.0.4",t!==document.documentElement&&t!==document.body||(t=window),this.options={wrapper:t,content:n,wheelEventsTarget:r,eventsTarget:l,smoothWheel:h,smoothTouch:a,syncTouch:c,syncTouchLerp:p,__iosNoInertiaSyncTouchLerp:u,touchInertiaMultiplier:d,duration:m,easing:g,lerp:v,infinite:S,gestureOrientation:w,orientation:f,touchMultiplier:y,wheelMultiplier:T,normalizeWheel:z,autoResize:_},this.animate=new e,this.emitter=new s,this.dimensions=new i({wrapper:t,content:n,autoResize:_}),this.toggleClass("lenis",!0),this.velocity=0,this.isLocked=!1,this.isStopped=!1,this.isSmooth=c||h||a,this.isScrolling=!1,this.targetScroll=this.animatedScroll=this.actualScroll,this.options.wrapper.addEventListener("scroll",this.onNativeScroll,{passive:!1}),this.virtualScroll=new o(l,{touchMultiplier:y,wheelMultiplier:T,normalizeWheel:z}),this.virtualScroll.on("scroll",this.onVirtualScroll)}destroy(){this.emitter.destroy(),this.options.wrapper.removeEventListener("scroll",this.onNativeScroll,{passive:!1}),this.virtualScroll.destroy(),this.dimensions.destroy(),this.toggleClass("lenis",!1),this.toggleClass("lenis-smooth",!1),this.toggleClass("lenis-scrolling",!1),this.toggleClass("lenis-stopped",!1),this.toggleClass("lenis-locked",!1)}on(t,e){return this.emitter.on(t,e)}off(t,e){return this.emitter.off(t,e)}setScroll(t){this.isHorizontal?this.rootElement.scrollLeft=t:this.rootElement.scrollTop=t}onVirtualScroll=({deltaX:t,deltaY:e,event:i})=>{if(i.ctrlKey)return;const s=i.type.includes("touch"),o=i.type.includes("wheel");if("both"===this.options.gestureOrientation&&0===t&&0===e||"vertical"===this.options.gestureOrientation&&0===e||"horizontal"===this.options.gestureOrientation&&0===t||s&&"vertical"===this.options.gestureOrientation&&0===this.scroll&&!this.options.infinite&&e<=0)return;let n=i.composedPath();if(n=n.slice(0,n.indexOf(this.rootElement)),n.find((t=>t.hasAttribute?.("data-lenis-prevent")||s&&t.hasAttribute?.("data-lenis-prevent-touch")||o&&t.hasAttribute?.("data-lenis-prevent-wheel")||t.classList?.contains("lenis"))))return;if(this.isStopped||this.isLocked)return void i.preventDefault();if(this.isSmooth=(this.options.smoothTouch||this.options.syncTouch)&&s||this.options.smoothWheel&&o,!this.isSmooth)return this.isScrolling=!1,void this.animate.stop();i.preventDefault();let r=e;"both"===this.options.gestureOrientation?r=Math.abs(e)>Math.abs(t)?e:t:"horizontal"===this.options.gestureOrientation&&(r=t);const l=s&&this.options.syncTouch,h=s&&"touchend"===i.type&&Math.abs(r)>1;h&&(r=this.velocity*this.options.touchInertiaMultiplier),this.scrollTo(this.targetScroll+r,{programmatic:!1,...l&&{lerp:h?this.syncTouchLerp:this.options.__iosNoInertiaSyncTouchLerp}})};resize(){this.dimensions.resize()}emit(){this.emitter.emit("scroll",this)}onNativeScroll=()=>{if(!this.__preventNextScrollEvent&&!this.isScrolling){const t=this.animatedScroll;this.animatedScroll=this.targetScroll=this.actualScroll,this.velocity=0,this.direction=Math.sign(this.animatedScroll-t),this.emit()}};reset(){this.isLocked=!1,this.isScrolling=!1,this.animatedScroll=this.targetScroll=this.actualScroll,this.velocity=0,this.animate.stop()}start(){this.isStopped=!1,this.reset()}stop(){this.isStopped=!0,this.animate.stop(),this.reset()}raf(t){const e=t-(this.time||t);this.time=t,this.animate.advance(.001*e)}scrollTo(e,{offset:i=0,immediate:s=!1,lock:o=!1,duration:n=this.options.duration,easing:r=this.options.easing,lerp:l=!n&&this.options.lerp,onComplete:h=null,force:a=!1,programmatic:c=!0}={}){if(!this.isStopped&&!this.isLocked||a){if(["top","left","start"].includes(e))e=0;else if(["bottom","right","end"].includes(e))e=this.limit;else{let t;if("string"==typeof e?t=document.querySelector(e):e?.nodeType&&(t=e),t){if(this.options.wrapper!==window){const t=this.options.wrapper.getBoundingClientRect();i-=this.isHorizontal?t.left:t.top}const s=t.getBoundingClientRect();e=(this.isHorizontal?s.left:s.top)+this.animatedScroll}}if("number"==typeof e){if(e+=i,e=Math.round(e),this.options.infinite?c&&(this.targetScroll=this.animatedScroll=this.scroll):e=t(0,e,this.limit),s)return this.animatedScroll=this.targetScroll=e,this.setScroll(this.scroll),this.reset(),void h?.(this);if(!c){if(e===this.targetScroll)return;this.targetScroll=e}this.animate.fromTo(this.animatedScroll,e,{duration:n,easing:r,lerp:l,onStart:()=>{o&&(this.isLocked=!0),this.isScrolling=!0},onUpdate:(t,e)=>{this.isScrolling=!0,this.velocity=t-this.animatedScroll,this.direction=Math.sign(this.velocity),this.animatedScroll=t,this.setScroll(this.scroll),c&&(this.targetScroll=t),e||this.emit(),e&&(this.reset(),this.emit(),h?.(this),this.__preventNextScrollEvent=!0,requestAnimationFrame((()=>{delete this.__preventNextScrollEvent})))}})}}}get rootElement(){return this.options.wrapper===window?document.documentElement:this.options.wrapper}get limit(){return 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(){return this.options.infinite?(this.animatedScroll%(t=this.limit)+t)%t:this.animatedScroll;var t}get progress(){return 0===this.limit?1:this.scroll/this.limit}get isSmooth(){return this.__isSmooth}set isSmooth(t){this.__isSmooth!==t&&(this.__isSmooth=t,this.toggleClass("lenis-smooth",t))}get isScrolling(){return this.__isScrolling}set isScrolling(t){this.__isScrolling!==t&&(this.__isScrolling=t,this.toggleClass("lenis-scrolling",t))}get isStopped(){return this.__isStopped}set isStopped(t){this.__isStopped!==t&&(this.__isStopped=t,this.toggleClass("lenis-stopped",t))}get isLocked(){return this.__isLocked}set isLocked(t){this.__isLocked!==t&&(this.__isLocked=t,this.toggleClass("lenis-locked",t))}get className(){let t="lenis";return this.isStopped&&(t+=" lenis-stopped"),this.isLocked&&(t+=" lenis-locked"),this.isScrolling&&(t+=" lenis-scrolling"),this.isSmooth&&(t+=" lenis-smooth"),t}toggleClass(t,e){this.rootElement.classList.toggle(t,e),this.emitter.emit("className change",this)}}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).Lenis=e(); +var t,e;t=this,e=function(){function t(t,e,i){return Math.max(t,Math.min(e,i))}class e{advance(e){if(!this.isRunning)return;let i=!1;if(this.lerp)this.value=(s=this.value,o=this.to,n=60*this.lerp,r=e,function(t,e,i){return(1-i)*t+i*e}(s,o,1-Math.exp(-n*r))),Math.round(this.value)===this.to&&(this.value=this.to,i=!0);else{this.currentTime+=e;const s=t(0,this.currentTime/this.duration,1);i=s>=1;const o=i?1:this.easing(s);this.value=this.from+(this.to-this.from)*o}var s,o,n,r;this.onUpdate?.(this.value,i),i&&this.stop()}stop(){this.isRunning=!1}fromTo(t,e,{lerp:i=.1,duration:s=1,easing:o=(t=>t),onStart:n,onUpdate:r}){this.from=this.value=t,this.to=e,this.lerp=i,this.duration=s,this.easing=o,this.currentTime=0,this.isRunning=!0,n?.(),this.onUpdate=r}}class i{constructor({wrapper:t,content:e,autoResize:i=!0}={}){if(this.wrapper=t,this.content=e,i){const t=function(t,e){let i;return function(){let e=arguments,s=this;clearTimeout(i),i=setTimeout((function(){t.apply(s,e)}),250)}}(this.resize);this.wrapper!==window&&(this.wrapperResizeObserver=new ResizeObserver(t),this.wrapperResizeObserver.observe(this.wrapper)),this.contentResizeObserver=new ResizeObserver(t),this.contentResizeObserver.observe(this.content)}this.resize()}destroy(){this.wrapperResizeObserver?.disconnect(),this.contentResizeObserver?.disconnect()}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.scrollHeight=this.content.scrollHeight,this.scrollWidth=this.content.scrollWidth};get limit(){return{x:this.scrollWidth-this.width,y:this.scrollHeight-this.height}}}class s{constructor(){this.events={}}emit(t,...e){let i=this.events[t]||[];for(let t=0,s=i.length;t{this.events[t]=this.events[t]?.filter((t=>e!==t))}}off(t,e){this.events[t]=this.events[t]?.filter((t=>e!==t))}destroy(){this.events={}}}class o{constructor(t,{wheelMultiplier:e=1,touchMultiplier:i=2,normalizeWheel:o=!1}){this.element=t,this.wheelMultiplier=e,this.touchMultiplier=i,this.normalizeWheel=o,this.touchStart={x:null,y:null},this.emitter=new s,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,e){return this.emitter.on(t,e)}destroy(){this.emitter.destroy(),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=>{const{clientX:e,clientY:i}=t.targetTouches?t.targetTouches[0]:t;this.touchStart.x=e,this.touchStart.y=i,this.lastDelta={x:0,y:0},this.emitter.emit("scroll",{deltaX:0,deltaY:0,event:t})};onTouchMove=t=>{const{clientX:e,clientY:i}=t.targetTouches?t.targetTouches[0]:t,s=-(e-this.touchStart.x)*this.touchMultiplier,o=-(i-this.touchStart.y)*this.touchMultiplier;this.touchStart.x=e,this.touchStart.y=i,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=e=>{let{deltaX:i,deltaY:s}=e;this.normalizeWheel&&(i=t(-100,i,100),s=t(-100,s,100)),i*=this.wheelMultiplier,s*=this.wheelMultiplier,this.emitter.emit("scroll",{deltaX:i,deltaY:s,event:e})}}return class{constructor({wrapper:t=window,content:n=document.documentElement,wheelEventsTarget:r=t,eventsTarget:l=r,smoothWheel:h=!0,smoothTouch:a=!1,syncTouch:c=!1,syncTouchLerp:p=.075,touchInertiaMultiplier:u=35,duration:d,easing:m=(t=>Math.min(1,1.001-Math.pow(2,-10*t))),lerp:g=!d&&.1,infinite:v=!1,orientation:S="vertical",gestureOrientation:f="vertical",touchMultiplier:w=1,wheelMultiplier:y=1,normalizeWheel:T=!1,autoResize:z=!0}={}){window.lenisVersion="1.0.29",t!==document.documentElement&&t!==document.body||(t=window),this.options={wrapper:t,content:n,wheelEventsTarget:r,eventsTarget:l,smoothWheel:h,smoothTouch:a,syncTouch:c,syncTouchLerp:p,touchInertiaMultiplier:u,duration:d,easing:m,lerp:g,infinite:v,gestureOrientation:f,orientation:S,touchMultiplier:w,wheelMultiplier:y,normalizeWheel:T,autoResize:z},this.animate=new e,this.emitter=new s,this.dimensions=new i({wrapper:t,content:n,autoResize:z}),this.toggleClass("lenis",!0),this.velocity=0,this.isLocked=!1,this.isStopped=!1,this.isSmooth=c||h||a,this.isScrolling=!1,this.targetScroll=this.animatedScroll=this.actualScroll,this.options.wrapper.addEventListener("scroll",this.onNativeScroll,{passive:!1}),this.virtualScroll=new o(l,{touchMultiplier:w,wheelMultiplier:y,normalizeWheel:T}),this.virtualScroll.on("scroll",this.onVirtualScroll)}destroy(){this.emitter.destroy(),this.options.wrapper.removeEventListener("scroll",this.onNativeScroll,{passive:!1}),this.virtualScroll.destroy(),this.dimensions.destroy(),this.toggleClass("lenis",!1),this.toggleClass("lenis-smooth",!1),this.toggleClass("lenis-scrolling",!1),this.toggleClass("lenis-stopped",!1),this.toggleClass("lenis-locked",!1)}on(t,e){return this.emitter.on(t,e)}off(t,e){return this.emitter.off(t,e)}setScroll(t){this.isHorizontal?this.rootElement.scrollLeft=t:this.rootElement.scrollTop=t}onVirtualScroll=({deltaX:t,deltaY:e,event:i})=>{if(i.ctrlKey)return;const s=i.type.includes("touch"),o=i.type.includes("wheel");if((this.options.smoothTouch||this.options.syncTouch)&&s&&"touchstart"===i.type)return void this.reset();const n=0===t&&0===e,r="vertical"===this.options.gestureOrientation&&0===e||"horizontal"===this.options.gestureOrientation&&0===t;if(n||r)return;let l=i.composedPath();if(l=l.slice(0,l.indexOf(this.rootElement)),l.find((t=>t.hasAttribute?.("data-lenis-prevent")||s&&t.hasAttribute?.("data-lenis-prevent-touch")||o&&t.hasAttribute?.("data-lenis-prevent-wheel")||t.classList?.contains("lenis"))))return;if(this.isStopped||this.isLocked)return void i.preventDefault();if(this.isSmooth=(this.options.smoothTouch||this.options.syncTouch)&&s||this.options.smoothWheel&&o,!this.isSmooth)return this.isScrolling=!1,void this.animate.stop();i.preventDefault();let h=e;"both"===this.options.gestureOrientation?h=Math.abs(e)>Math.abs(t)?e:t:"horizontal"===this.options.gestureOrientation&&(h=t);const a=s&&this.options.syncTouch,c=s&&"touchend"===i.type&&Math.abs(h)>5;c&&(h=this.velocity*this.options.touchInertiaMultiplier),this.scrollTo(this.targetScroll+h,{programmatic:!1,...a?{lerp:c?this.options.syncTouchLerp:1}:{lerp:this.options.lerp,duration:this.options.duration,easing:this.options.easing}})};resize(){this.dimensions.resize()}emit(){this.emitter.emit("scroll",this)}onNativeScroll=()=>{if(!this.__preventNextScrollEvent&&!this.isScrolling){const t=this.animatedScroll;this.animatedScroll=this.targetScroll=this.actualScroll,this.velocity=0,this.direction=Math.sign(this.animatedScroll-t),this.emit()}};reset(){this.isLocked=!1,this.isScrolling=!1,this.animatedScroll=this.targetScroll=this.actualScroll,this.velocity=0,this.animate.stop()}start(){this.isStopped=!1,this.reset()}stop(){this.isStopped=!0,this.animate.stop(),this.reset()}raf(t){const e=t-(this.time||t);this.time=t,this.animate.advance(.001*e)}scrollTo(e,{offset:i=0,immediate:s=!1,lock:o=!1,duration:n=this.options.duration,easing:r=this.options.easing,lerp:l=!n&&this.options.lerp,onComplete:h=null,force:a=!1,programmatic:c=!0}={}){if(!this.isStopped&&!this.isLocked||a){if(["top","left","start"].includes(e))e=0;else if(["bottom","right","end"].includes(e))e=this.limit;else{let t;if("string"==typeof e?t=document.querySelector(e):e?.nodeType&&(t=e),t){if(this.options.wrapper!==window){const t=this.options.wrapper.getBoundingClientRect();i-=this.isHorizontal?t.left:t.top}const s=t.getBoundingClientRect();e=(this.isHorizontal?s.left:s.top)+this.animatedScroll}}if("number"==typeof e){if(e+=i,e=Math.round(e),this.options.infinite?c&&(this.targetScroll=this.animatedScroll=this.scroll):e=t(0,e,this.limit),s)return this.animatedScroll=this.targetScroll=e,this.setScroll(this.scroll),this.reset(),void h?.(this);if(!c){if(e===this.targetScroll)return;this.targetScroll=e}this.animate.fromTo(this.animatedScroll,e,{duration:n,easing:r,lerp:l,onStart:()=>{o&&(this.isLocked=!0),this.isScrolling=!0},onUpdate:(t,e)=>{this.isScrolling=!0,this.velocity=t-this.animatedScroll,this.direction=Math.sign(this.velocity),this.animatedScroll=t,this.setScroll(this.scroll),c&&(this.targetScroll=t),e||this.emit(),e&&(this.reset(),this.emit(),h?.(this),this.__preventNextScrollEvent=!0,requestAnimationFrame((()=>{delete this.__preventNextScrollEvent})))}})}}}get rootElement(){return this.options.wrapper===window?document.documentElement:this.options.wrapper}get limit(){return 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(){return this.options.infinite?(this.animatedScroll%(t=this.limit)+t)%t:this.animatedScroll;var t}get progress(){return 0===this.limit?1:this.scroll/this.limit}get isSmooth(){return this.__isSmooth}set isSmooth(t){this.__isSmooth!==t&&(this.__isSmooth=t,this.toggleClass("lenis-smooth",t))}get isScrolling(){return this.__isScrolling}set isScrolling(t){this.__isScrolling!==t&&(this.__isScrolling=t,this.toggleClass("lenis-scrolling",t))}get isStopped(){return this.__isStopped}set isStopped(t){this.__isStopped!==t&&(this.__isStopped=t,this.toggleClass("lenis-stopped",t))}get isLocked(){return this.__isLocked}set isLocked(t){this.__isLocked!==t&&(this.__isLocked=t,this.toggleClass("lenis-locked",t))}get className(){let t="lenis";return this.isStopped&&(t+=" lenis-stopped"),this.isLocked&&(t+=" lenis-locked"),this.isScrolling&&(t+=" lenis-scrolling"),this.isSmooth&&(t+=" lenis-smooth"),t}toggleClass(t,e){this.rootElement.classList.toggle(t,e),this.emitter.emit("className change",this)}}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).Lenis=e(); diff --git a/packages/lenis/dist/lenis.umd.js b/packages/lenis/dist/lenis.umd.js index 73a61329..bfa16738 100644 --- a/packages/lenis/dist/lenis.umd.js +++ b/packages/lenis/dist/lenis.umd.js @@ -1,2 +1,2 @@ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).Lenis=e()}(this,(function(){"use strict";function t(t,e,i){return Math.max(t,Math.min(e,i))}class Animate{advance(e){if(!this.isRunning)return;let i=!1;if(this.lerp)this.value=(s=this.value,o=this.to,n=60*this.lerp,r=e,function(t,e,i){return(1-i)*t+i*e}(s,o,1-Math.exp(-n*r))),Math.round(this.value)===this.to&&(this.value=this.to,i=!0);else{this.currentTime+=e;const s=t(0,this.currentTime/this.duration,1);i=s>=1;const o=i?1:this.easing(s);this.value=this.from+(this.to-this.from)*o}var s,o,n,r;this.onUpdate?.(this.value,i),i&&this.stop()}stop(){this.isRunning=!1}fromTo(t,e,{lerp:i=.1,duration:s=1,easing:o=(t=>t),onStart:n,onUpdate:r}){this.from=this.value=t,this.to=e,this.lerp=i,this.duration=s,this.easing=o,this.currentTime=0,this.isRunning=!0,n?.(),this.onUpdate=r}}class Dimensions{constructor({wrapper:t,content:e,autoResize:i=!0}={}){if(this.wrapper=t,this.content=e,i){const t=function(t,e){let i;return function(){let s=arguments,o=this;clearTimeout(i),i=setTimeout((function(){t.apply(o,s)}),e)}}(this.resize,250);this.wrapper!==window&&(this.wrapperResizeObserver=new ResizeObserver(t),this.wrapperResizeObserver.observe(this.wrapper)),this.contentResizeObserver=new ResizeObserver(t),this.contentResizeObserver.observe(this.content)}this.resize()}destroy(){this.wrapperResizeObserver?.disconnect(),this.contentResizeObserver?.disconnect()}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.scrollHeight=this.content.scrollHeight,this.scrollWidth=this.content.scrollWidth};get limit(){return{x:this.scrollWidth-this.width,y:this.scrollHeight-this.height}}}class Emitter{constructor(){this.events={}}emit(t,...e){let i=this.events[t]||[];for(let t=0,s=i.length;t{this.events[t]=this.events[t]?.filter((t=>e!==t))}}off(t,e){this.events[t]=this.events[t]?.filter((t=>e!==t))}destroy(){this.events={}}}class VirtualScroll{constructor(t,{wheelMultiplier:e=1,touchMultiplier:i=2,normalizeWheel:s=!1}){this.element=t,this.wheelMultiplier=e,this.touchMultiplier=i,this.normalizeWheel=s,this.touchStart={x:null,y:null},this.emitter=new Emitter,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,e){return this.emitter.on(t,e)}destroy(){this.emitter.destroy(),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=>{const{clientX:e,clientY:i}=t.targetTouches?t.targetTouches[0]:t;this.touchStart.x=e,this.touchStart.y=i,this.lastDelta={x:0,y:0}};onTouchMove=t=>{const{clientX:e,clientY:i}=t.targetTouches?t.targetTouches[0]:t,s=-(e-this.touchStart.x)*this.touchMultiplier,o=-(i-this.touchStart.y)*this.touchMultiplier;this.touchStart.x=e,this.touchStart.y=i,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=e=>{let{deltaX:i,deltaY:s}=e;this.normalizeWheel&&(i=t(-100,i,100),s=t(-100,s,100)),i*=this.wheelMultiplier,s*=this.wheelMultiplier,this.emitter.emit("scroll",{deltaX:i,deltaY:s,event:e})}}return class Lenis{constructor({wrapper:t=window,content:e=document.documentElement,wheelEventsTarget:i=t,eventsTarget:s=i,smoothWheel:o=!0,smoothTouch:n=!1,syncTouch:r=!1,syncTouchLerp:l=.1,__iosNoInertiaSyncTouchLerp:h=.4,touchInertiaMultiplier:a=35,duration:c,easing:u=(t=>Math.min(1,1.001-Math.pow(2,-10*t))),lerp:p=!c&&.1,infinite:d=!1,orientation:m="vertical",gestureOrientation:g="vertical",touchMultiplier:v=1,wheelMultiplier:S=1,normalizeWheel:f=!1,autoResize:w=!0}={}){window.lenisVersion="0.0.4",t!==document.documentElement&&t!==document.body||(t=window),this.options={wrapper:t,content:e,wheelEventsTarget:i,eventsTarget:s,smoothWheel:o,smoothTouch:n,syncTouch:r,syncTouchLerp:l,__iosNoInertiaSyncTouchLerp:h,touchInertiaMultiplier:a,duration:c,easing:u,lerp:p,infinite:d,gestureOrientation:g,orientation:m,touchMultiplier:v,wheelMultiplier:S,normalizeWheel:f,autoResize:w},this.animate=new Animate,this.emitter=new Emitter,this.dimensions=new Dimensions({wrapper:t,content:e,autoResize:w}),this.toggleClass("lenis",!0),this.velocity=0,this.isLocked=!1,this.isStopped=!1,this.isSmooth=r||o||n,this.isScrolling=!1,this.targetScroll=this.animatedScroll=this.actualScroll,this.options.wrapper.addEventListener("scroll",this.onNativeScroll,{passive:!1}),this.virtualScroll=new VirtualScroll(s,{touchMultiplier:v,wheelMultiplier:S,normalizeWheel:f}),this.virtualScroll.on("scroll",this.onVirtualScroll)}destroy(){this.emitter.destroy(),this.options.wrapper.removeEventListener("scroll",this.onNativeScroll,{passive:!1}),this.virtualScroll.destroy(),this.dimensions.destroy(),this.toggleClass("lenis",!1),this.toggleClass("lenis-smooth",!1),this.toggleClass("lenis-scrolling",!1),this.toggleClass("lenis-stopped",!1),this.toggleClass("lenis-locked",!1)}on(t,e){return this.emitter.on(t,e)}off(t,e){return this.emitter.off(t,e)}setScroll(t){this.isHorizontal?this.rootElement.scrollLeft=t:this.rootElement.scrollTop=t}onVirtualScroll=({deltaX:t,deltaY:e,event:i})=>{if(i.ctrlKey)return;const s=i.type.includes("touch"),o=i.type.includes("wheel");if("both"===this.options.gestureOrientation&&0===t&&0===e||"vertical"===this.options.gestureOrientation&&0===e||"horizontal"===this.options.gestureOrientation&&0===t||s&&"vertical"===this.options.gestureOrientation&&0===this.scroll&&!this.options.infinite&&e<=0)return;let n=i.composedPath();if(n=n.slice(0,n.indexOf(this.rootElement)),n.find((t=>t.hasAttribute?.("data-lenis-prevent")||s&&t.hasAttribute?.("data-lenis-prevent-touch")||o&&t.hasAttribute?.("data-lenis-prevent-wheel")||t.classList?.contains("lenis"))))return;if(this.isStopped||this.isLocked)return void i.preventDefault();if(this.isSmooth=(this.options.smoothTouch||this.options.syncTouch)&&s||this.options.smoothWheel&&o,!this.isSmooth)return this.isScrolling=!1,void this.animate.stop();i.preventDefault();let r=e;"both"===this.options.gestureOrientation?r=Math.abs(e)>Math.abs(t)?e:t:"horizontal"===this.options.gestureOrientation&&(r=t);const l=s&&this.options.syncTouch,h=s&&"touchend"===i.type&&Math.abs(r)>1;h&&(r=this.velocity*this.options.touchInertiaMultiplier),this.scrollTo(this.targetScroll+r,{programmatic:!1,...l&&{lerp:h?this.syncTouchLerp:this.options.__iosNoInertiaSyncTouchLerp}})};resize(){this.dimensions.resize()}emit(){this.emitter.emit("scroll",this)}onNativeScroll=()=>{if(!this.__preventNextScrollEvent&&!this.isScrolling){const t=this.animatedScroll;this.animatedScroll=this.targetScroll=this.actualScroll,this.velocity=0,this.direction=Math.sign(this.animatedScroll-t),this.emit()}};reset(){this.isLocked=!1,this.isScrolling=!1,this.animatedScroll=this.targetScroll=this.actualScroll,this.velocity=0,this.animate.stop()}start(){this.isStopped=!1,this.reset()}stop(){this.isStopped=!0,this.animate.stop(),this.reset()}raf(t){const e=t-(this.time||t);this.time=t,this.animate.advance(.001*e)}scrollTo(e,{offset:i=0,immediate:s=!1,lock:o=!1,duration:n=this.options.duration,easing:r=this.options.easing,lerp:l=!n&&this.options.lerp,onComplete:h=null,force:a=!1,programmatic:c=!0}={}){if(!this.isStopped&&!this.isLocked||a){if(["top","left","start"].includes(e))e=0;else if(["bottom","right","end"].includes(e))e=this.limit;else{let t;if("string"==typeof e?t=document.querySelector(e):e?.nodeType&&(t=e),t){if(this.options.wrapper!==window){const t=this.options.wrapper.getBoundingClientRect();i-=this.isHorizontal?t.left:t.top}const s=t.getBoundingClientRect();e=(this.isHorizontal?s.left:s.top)+this.animatedScroll}}if("number"==typeof e){if(e+=i,e=Math.round(e),this.options.infinite?c&&(this.targetScroll=this.animatedScroll=this.scroll):e=t(0,e,this.limit),s)return this.animatedScroll=this.targetScroll=e,this.setScroll(this.scroll),this.reset(),void h?.(this);if(!c){if(e===this.targetScroll)return;this.targetScroll=e}this.animate.fromTo(this.animatedScroll,e,{duration:n,easing:r,lerp:l,onStart:()=>{o&&(this.isLocked=!0),this.isScrolling=!0},onUpdate:(t,e)=>{this.isScrolling=!0,this.velocity=t-this.animatedScroll,this.direction=Math.sign(this.velocity),this.animatedScroll=t,this.setScroll(this.scroll),c&&(this.targetScroll=t),e||this.emit(),e&&(this.reset(),this.emit(),h?.(this),this.__preventNextScrollEvent=!0,requestAnimationFrame((()=>{delete this.__preventNextScrollEvent})))}})}}}get rootElement(){return this.options.wrapper===window?document.documentElement:this.options.wrapper}get limit(){return 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(){return this.options.infinite?(t=this.animatedScroll,e=this.limit,(t%e+e)%e):this.animatedScroll;var t,e}get progress(){return 0===this.limit?1:this.scroll/this.limit}get isSmooth(){return this.__isSmooth}set isSmooth(t){this.__isSmooth!==t&&(this.__isSmooth=t,this.toggleClass("lenis-smooth",t))}get isScrolling(){return this.__isScrolling}set isScrolling(t){this.__isScrolling!==t&&(this.__isScrolling=t,this.toggleClass("lenis-scrolling",t))}get isStopped(){return this.__isStopped}set isStopped(t){this.__isStopped!==t&&(this.__isStopped=t,this.toggleClass("lenis-stopped",t))}get isLocked(){return this.__isLocked}set isLocked(t){this.__isLocked!==t&&(this.__isLocked=t,this.toggleClass("lenis-locked",t))}get className(){let t="lenis";return this.isStopped&&(t+=" lenis-stopped"),this.isLocked&&(t+=" lenis-locked"),this.isScrolling&&(t+=" lenis-scrolling"),this.isSmooth&&(t+=" lenis-smooth"),t}toggleClass(t,e){this.rootElement.classList.toggle(t,e),this.emitter.emit("className change",this)}}})); +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).Lenis=e()}(this,(function(){"use strict";function t(t,e,i){return Math.max(t,Math.min(e,i))}class Animate{advance(e){if(!this.isRunning)return;let i=!1;if(this.lerp)this.value=(s=this.value,o=this.to,n=60*this.lerp,r=e,function(t,e,i){return(1-i)*t+i*e}(s,o,1-Math.exp(-n*r))),Math.round(this.value)===this.to&&(this.value=this.to,i=!0);else{this.currentTime+=e;const s=t(0,this.currentTime/this.duration,1);i=s>=1;const o=i?1:this.easing(s);this.value=this.from+(this.to-this.from)*o}var s,o,n,r;this.onUpdate?.(this.value,i),i&&this.stop()}stop(){this.isRunning=!1}fromTo(t,e,{lerp:i=.1,duration:s=1,easing:o=(t=>t),onStart:n,onUpdate:r}){this.from=this.value=t,this.to=e,this.lerp=i,this.duration=s,this.easing=o,this.currentTime=0,this.isRunning=!0,n?.(),this.onUpdate=r}}class Dimensions{constructor({wrapper:t,content:e,autoResize:i=!0}={}){if(this.wrapper=t,this.content=e,i){const t=function(t,e){let i;return function(){let s=arguments,o=this;clearTimeout(i),i=setTimeout((function(){t.apply(o,s)}),e)}}(this.resize,250);this.wrapper!==window&&(this.wrapperResizeObserver=new ResizeObserver(t),this.wrapperResizeObserver.observe(this.wrapper)),this.contentResizeObserver=new ResizeObserver(t),this.contentResizeObserver.observe(this.content)}this.resize()}destroy(){this.wrapperResizeObserver?.disconnect(),this.contentResizeObserver?.disconnect()}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.scrollHeight=this.content.scrollHeight,this.scrollWidth=this.content.scrollWidth};get limit(){return{x:this.scrollWidth-this.width,y:this.scrollHeight-this.height}}}class Emitter{constructor(){this.events={}}emit(t,...e){let i=this.events[t]||[];for(let t=0,s=i.length;t{this.events[t]=this.events[t]?.filter((t=>e!==t))}}off(t,e){this.events[t]=this.events[t]?.filter((t=>e!==t))}destroy(){this.events={}}}class VirtualScroll{constructor(t,{wheelMultiplier:e=1,touchMultiplier:i=2,normalizeWheel:s=!1}){this.element=t,this.wheelMultiplier=e,this.touchMultiplier=i,this.normalizeWheel=s,this.touchStart={x:null,y:null},this.emitter=new Emitter,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,e){return this.emitter.on(t,e)}destroy(){this.emitter.destroy(),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=>{const{clientX:e,clientY:i}=t.targetTouches?t.targetTouches[0]:t;this.touchStart.x=e,this.touchStart.y=i,this.lastDelta={x:0,y:0},this.emitter.emit("scroll",{deltaX:0,deltaY:0,event:t})};onTouchMove=t=>{const{clientX:e,clientY:i}=t.targetTouches?t.targetTouches[0]:t,s=-(e-this.touchStart.x)*this.touchMultiplier,o=-(i-this.touchStart.y)*this.touchMultiplier;this.touchStart.x=e,this.touchStart.y=i,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=e=>{let{deltaX:i,deltaY:s}=e;this.normalizeWheel&&(i=t(-100,i,100),s=t(-100,s,100)),i*=this.wheelMultiplier,s*=this.wheelMultiplier,this.emitter.emit("scroll",{deltaX:i,deltaY:s,event:e})}}return class Lenis{constructor({wrapper:t=window,content:e=document.documentElement,wheelEventsTarget:i=t,eventsTarget:s=i,smoothWheel:o=!0,smoothTouch:n=!1,syncTouch:r=!1,syncTouchLerp:l=.075,touchInertiaMultiplier:h=35,duration:a,easing:c=(t=>Math.min(1,1.001-Math.pow(2,-10*t))),lerp:u=!a&&.1,infinite:p=!1,orientation:d="vertical",gestureOrientation:m="vertical",touchMultiplier:g=1,wheelMultiplier:v=1,normalizeWheel:S=!1,autoResize:f=!0}={}){window.lenisVersion="1.0.29",t!==document.documentElement&&t!==document.body||(t=window),this.options={wrapper:t,content:e,wheelEventsTarget:i,eventsTarget:s,smoothWheel:o,smoothTouch:n,syncTouch:r,syncTouchLerp:l,touchInertiaMultiplier:h,duration:a,easing:c,lerp:u,infinite:p,gestureOrientation:m,orientation:d,touchMultiplier:g,wheelMultiplier:v,normalizeWheel:S,autoResize:f},this.animate=new Animate,this.emitter=new Emitter,this.dimensions=new Dimensions({wrapper:t,content:e,autoResize:f}),this.toggleClass("lenis",!0),this.velocity=0,this.isLocked=!1,this.isStopped=!1,this.isSmooth=r||o||n,this.isScrolling=!1,this.targetScroll=this.animatedScroll=this.actualScroll,this.options.wrapper.addEventListener("scroll",this.onNativeScroll,{passive:!1}),this.virtualScroll=new VirtualScroll(s,{touchMultiplier:g,wheelMultiplier:v,normalizeWheel:S}),this.virtualScroll.on("scroll",this.onVirtualScroll)}destroy(){this.emitter.destroy(),this.options.wrapper.removeEventListener("scroll",this.onNativeScroll,{passive:!1}),this.virtualScroll.destroy(),this.dimensions.destroy(),this.toggleClass("lenis",!1),this.toggleClass("lenis-smooth",!1),this.toggleClass("lenis-scrolling",!1),this.toggleClass("lenis-stopped",!1),this.toggleClass("lenis-locked",!1)}on(t,e){return this.emitter.on(t,e)}off(t,e){return this.emitter.off(t,e)}setScroll(t){this.isHorizontal?this.rootElement.scrollLeft=t:this.rootElement.scrollTop=t}onVirtualScroll=({deltaX:t,deltaY:e,event:i})=>{if(i.ctrlKey)return;const s=i.type.includes("touch"),o=i.type.includes("wheel");if((this.options.smoothTouch||this.options.syncTouch)&&s&&"touchstart"===i.type)return void this.reset();const n=0===t&&0===e,r="vertical"===this.options.gestureOrientation&&0===e||"horizontal"===this.options.gestureOrientation&&0===t;if(n||r)return;let l=i.composedPath();if(l=l.slice(0,l.indexOf(this.rootElement)),l.find((t=>t.hasAttribute?.("data-lenis-prevent")||s&&t.hasAttribute?.("data-lenis-prevent-touch")||o&&t.hasAttribute?.("data-lenis-prevent-wheel")||t.classList?.contains("lenis"))))return;if(this.isStopped||this.isLocked)return void i.preventDefault();if(this.isSmooth=(this.options.smoothTouch||this.options.syncTouch)&&s||this.options.smoothWheel&&o,!this.isSmooth)return this.isScrolling=!1,void this.animate.stop();i.preventDefault();let h=e;"both"===this.options.gestureOrientation?h=Math.abs(e)>Math.abs(t)?e:t:"horizontal"===this.options.gestureOrientation&&(h=t);const a=s&&this.options.syncTouch,c=s&&"touchend"===i.type&&Math.abs(h)>5;c&&(h=this.velocity*this.options.touchInertiaMultiplier),this.scrollTo(this.targetScroll+h,{programmatic:!1,...a?{lerp:c?this.options.syncTouchLerp:1}:{lerp:this.options.lerp,duration:this.options.duration,easing:this.options.easing}})};resize(){this.dimensions.resize()}emit(){this.emitter.emit("scroll",this)}onNativeScroll=()=>{if(!this.__preventNextScrollEvent&&!this.isScrolling){const t=this.animatedScroll;this.animatedScroll=this.targetScroll=this.actualScroll,this.velocity=0,this.direction=Math.sign(this.animatedScroll-t),this.emit()}};reset(){this.isLocked=!1,this.isScrolling=!1,this.animatedScroll=this.targetScroll=this.actualScroll,this.velocity=0,this.animate.stop()}start(){this.isStopped=!1,this.reset()}stop(){this.isStopped=!0,this.animate.stop(),this.reset()}raf(t){const e=t-(this.time||t);this.time=t,this.animate.advance(.001*e)}scrollTo(e,{offset:i=0,immediate:s=!1,lock:o=!1,duration:n=this.options.duration,easing:r=this.options.easing,lerp:l=!n&&this.options.lerp,onComplete:h=null,force:a=!1,programmatic:c=!0}={}){if(!this.isStopped&&!this.isLocked||a){if(["top","left","start"].includes(e))e=0;else if(["bottom","right","end"].includes(e))e=this.limit;else{let t;if("string"==typeof e?t=document.querySelector(e):e?.nodeType&&(t=e),t){if(this.options.wrapper!==window){const t=this.options.wrapper.getBoundingClientRect();i-=this.isHorizontal?t.left:t.top}const s=t.getBoundingClientRect();e=(this.isHorizontal?s.left:s.top)+this.animatedScroll}}if("number"==typeof e){if(e+=i,e=Math.round(e),this.options.infinite?c&&(this.targetScroll=this.animatedScroll=this.scroll):e=t(0,e,this.limit),s)return this.animatedScroll=this.targetScroll=e,this.setScroll(this.scroll),this.reset(),void h?.(this);if(!c){if(e===this.targetScroll)return;this.targetScroll=e}this.animate.fromTo(this.animatedScroll,e,{duration:n,easing:r,lerp:l,onStart:()=>{o&&(this.isLocked=!0),this.isScrolling=!0},onUpdate:(t,e)=>{this.isScrolling=!0,this.velocity=t-this.animatedScroll,this.direction=Math.sign(this.velocity),this.animatedScroll=t,this.setScroll(this.scroll),c&&(this.targetScroll=t),e||this.emit(),e&&(this.reset(),this.emit(),h?.(this),this.__preventNextScrollEvent=!0,requestAnimationFrame((()=>{delete this.__preventNextScrollEvent})))}})}}}get rootElement(){return this.options.wrapper===window?document.documentElement:this.options.wrapper}get limit(){return 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(){return this.options.infinite?(t=this.animatedScroll,e=this.limit,(t%e+e)%e):this.animatedScroll;var t,e}get progress(){return 0===this.limit?1:this.scroll/this.limit}get isSmooth(){return this.__isSmooth}set isSmooth(t){this.__isSmooth!==t&&(this.__isSmooth=t,this.toggleClass("lenis-smooth",t))}get isScrolling(){return this.__isScrolling}set isScrolling(t){this.__isScrolling!==t&&(this.__isScrolling=t,this.toggleClass("lenis-scrolling",t))}get isStopped(){return this.__isStopped}set isStopped(t){this.__isStopped!==t&&(this.__isStopped=t,this.toggleClass("lenis-stopped",t))}get isLocked(){return this.__isLocked}set isLocked(t){this.__isLocked!==t&&(this.__isLocked=t,this.toggleClass("lenis-locked",t))}get className(){let t="lenis";return this.isStopped&&(t+=" lenis-stopped"),this.isLocked&&(t+=" lenis-locked"),this.isScrolling&&(t+=" lenis-scrolling"),this.isSmooth&&(t+=" lenis-smooth"),t}toggleClass(t,e){this.rootElement.classList.toggle(t,e),this.emitter.emit("className change",this)}}})); //# sourceMappingURL=lenis.umd.js.map diff --git a/packages/lenis/dist/lenis.umd.js.map b/packages/lenis/dist/lenis.umd.js.map index 436e1352..0305af10 100644 --- a/packages/lenis/dist/lenis.umd.js.map +++ b/packages/lenis/dist/lenis.umd.js.map @@ -1 +1 @@ -{"version":3,"file":"lenis.umd.js","sources":["../src/maths.js","../src/animate.js","../src/dimensions.js","../src/debounce.js","../src/emitter.js","../src/virtual-scroll.js","../src/index.js"],"sourcesContent":["// Clamp a value between a minimum and maximum value\r\nexport function clamp(min, input, max) {\r\n return Math.max(min, Math.min(input, max))\r\n}\r\n\r\n// Truncate a floating-point number to a specified number of decimal places\r\nexport function truncate(value, decimals = 0) {\r\n return parseFloat(value.toFixed(decimals))\r\n}\r\n\r\n// Linearly interpolate between two values using an amount (0 <= t <= 1)\r\nexport function lerp(x, y, t) {\r\n return (1 - t) * x + t * y\r\n}\r\n\r\n// http://www.rorydriscoll.com/2016/03/07/frame-rate-independent-damping-using-lerp/\r\nexport function damp(x, y, lambda, dt) {\r\n return lerp(x, y, 1 - Math.exp(-lambda * dt))\r\n}\r\n\r\n// Calculate the modulo of the dividend and divisor while keeping the result within the same sign as the divisor\r\n// https://anguscroll.com/just/just-modulo\r\nexport function modulo(n, d) {\r\n return ((n % d) + d) % d\r\n}\r\n","import { clamp, damp } from './maths'\r\n\r\n// Animate class to handle value animations with lerping or easing\r\nexport class Animate {\r\n // Advance the animation by the given delta time\r\n advance(deltaTime) {\r\n if (!this.isRunning) return\r\n\r\n let completed = false\r\n\r\n if (this.lerp) {\r\n this.value = damp(this.value, this.to, this.lerp * 60, deltaTime)\r\n if (Math.round(this.value) === this.to) {\r\n this.value = this.to\r\n completed = true\r\n }\r\n } else {\r\n this.currentTime += deltaTime\r\n const linearProgress = clamp(0, this.currentTime / this.duration, 1)\r\n\r\n completed = linearProgress >= 1\r\n const easedProgress = completed ? 1 : this.easing(linearProgress)\r\n this.value = this.from + (this.to - this.from) * easedProgress\r\n }\r\n\r\n // Call the onUpdate callback with the current value and completed status\r\n this.onUpdate?.(this.value, completed)\r\n\r\n if (completed) {\r\n this.stop()\r\n }\r\n }\r\n\r\n // Stop the animation\r\n stop() {\r\n this.isRunning = false\r\n }\r\n\r\n // Set up the animation from a starting value to an ending value\r\n // with optional parameters for lerping, duration, easing, and onUpdate callback\r\n fromTo(\r\n from,\r\n to,\r\n { lerp = 0.1, duration = 1, easing = (t) => t, onStart, onUpdate }\r\n ) {\r\n this.from = this.value = from\r\n this.to = to\r\n this.lerp = lerp\r\n this.duration = duration\r\n this.easing = easing\r\n this.currentTime = 0\r\n this.isRunning = true\r\n\r\n onStart?.()\r\n this.onUpdate = onUpdate\r\n }\r\n}\r\n","import { debounce } from './debounce'\r\n\r\nexport class Dimensions {\r\n constructor({ wrapper, content, autoResize = true } = {}) {\r\n this.wrapper = wrapper\r\n this.content = content\r\n\r\n if (autoResize) {\r\n const resize = debounce(this.resize, 250)\r\n\r\n if (this.wrapper !== window) {\r\n this.wrapperResizeObserver = new ResizeObserver(resize)\r\n this.wrapperResizeObserver.observe(this.wrapper)\r\n }\r\n\r\n this.contentResizeObserver = new ResizeObserver(resize)\r\n this.contentResizeObserver.observe(this.content)\r\n }\r\n\r\n this.resize()\r\n }\r\n\r\n destroy() {\r\n this.wrapperResizeObserver?.disconnect()\r\n this.contentResizeObserver?.disconnect()\r\n }\r\n\r\n resize = () => {\r\n this.onWrapperResize()\r\n this.onContentResize()\r\n }\r\n\r\n onWrapperResize = () => {\r\n if (this.wrapper === window) {\r\n this.width = window.innerWidth\r\n this.height = window.innerHeight\r\n } else {\r\n this.width = this.wrapper.clientWidth\r\n this.height = this.wrapper.clientHeight\r\n }\r\n }\r\n\r\n onContentResize = () => {\r\n this.scrollHeight = this.content.scrollHeight\r\n this.scrollWidth = this.content.scrollWidth\r\n }\r\n\r\n get limit() {\r\n return {\r\n x: this.scrollWidth - this.width,\r\n y: this.scrollHeight - this.height,\r\n }\r\n }\r\n}\r\n","export function debounce(callback, delay) {\r\n let timer\r\n return function () {\r\n let args = arguments\r\n let context = this\r\n clearTimeout(timer)\r\n timer = setTimeout(function () {\r\n callback.apply(context, args)\r\n }, delay)\r\n }\r\n}\r\n","export class Emitter {\r\n constructor() {\r\n this.events = {}\r\n }\r\n\r\n emit(event, ...args) {\r\n let callbacks = this.events[event] || []\r\n for (let i = 0, length = callbacks.length; i < length; i++) {\r\n callbacks[i](...args)\r\n }\r\n }\r\n\r\n on(event, cb) {\r\n // Add the callback to the event's callback list, or create a new list with the callback\r\n this.events[event]?.push(cb) || (this.events[event] = [cb])\r\n\r\n // Return an unsubscribe function\r\n return () => {\r\n this.events[event] = this.events[event]?.filter((i) => cb !== i)\r\n }\r\n }\r\n\r\n off(event, callback) {\r\n this.events[event] = this.events[event]?.filter((i) => callback !== i)\r\n }\r\n\r\n destroy() {\r\n this.events = {}\r\n }\r\n}\r\n","import { Emitter } from './emitter'\r\nimport { clamp } from './maths'\r\n\r\nexport class VirtualScroll {\r\n constructor(\r\n element,\r\n { wheelMultiplier = 1, touchMultiplier = 2, normalizeWheel = false }\r\n ) {\r\n this.element = element\r\n this.wheelMultiplier = wheelMultiplier\r\n this.touchMultiplier = touchMultiplier\r\n this.normalizeWheel = normalizeWheel\r\n\r\n this.touchStart = {\r\n x: null,\r\n y: null,\r\n }\r\n\r\n this.emitter = new Emitter()\r\n\r\n this.element.addEventListener('wheel', this.onWheel, { passive: false })\r\n this.element.addEventListener('touchstart', this.onTouchStart, {\r\n passive: false,\r\n })\r\n this.element.addEventListener('touchmove', this.onTouchMove, {\r\n passive: false,\r\n })\r\n this.element.addEventListener('touchend', this.onTouchEnd, {\r\n passive: false,\r\n })\r\n }\r\n\r\n // Add an event listener for the given event and callback\r\n on(event, callback) {\r\n return this.emitter.on(event, callback)\r\n }\r\n\r\n // Remove all event listeners and clean up\r\n destroy() {\r\n this.emitter.destroy()\r\n\r\n this.element.removeEventListener('wheel', this.onWheel, {\r\n passive: false,\r\n })\r\n this.element.removeEventListener('touchstart', this.onTouchStart, {\r\n passive: false,\r\n })\r\n this.element.removeEventListener('touchmove', this.onTouchMove, {\r\n passive: false,\r\n })\r\n this.element.removeEventListener('touchend', this.onTouchEnd, {\r\n passive: false,\r\n })\r\n }\r\n\r\n // Event handler for 'touchstart' event\r\n onTouchStart = (event) => {\r\n const { clientX, clientY } = event.targetTouches\r\n ? event.targetTouches[0]\r\n : event\r\n\r\n this.touchStart.x = clientX\r\n this.touchStart.y = clientY\r\n\r\n this.lastDelta = {\r\n x: 0,\r\n y: 0,\r\n }\r\n }\r\n\r\n // Event handler for 'touchmove' event\r\n onTouchMove = (event) => {\r\n const { clientX, clientY } = event.targetTouches\r\n ? event.targetTouches[0]\r\n : event\r\n\r\n const deltaX = -(clientX - this.touchStart.x) * this.touchMultiplier\r\n const deltaY = -(clientY - this.touchStart.y) * this.touchMultiplier\r\n\r\n this.touchStart.x = clientX\r\n this.touchStart.y = clientY\r\n\r\n this.lastDelta = {\r\n x: deltaX,\r\n y: deltaY,\r\n }\r\n\r\n this.emitter.emit('scroll', {\r\n deltaX,\r\n deltaY,\r\n event,\r\n })\r\n }\r\n\r\n onTouchEnd = (event) => {\r\n this.emitter.emit('scroll', {\r\n deltaX: this.lastDelta.x,\r\n deltaY: this.lastDelta.y,\r\n event,\r\n })\r\n }\r\n\r\n // Event handler for 'wheel' event\r\n onWheel = (event) => {\r\n let { deltaX, deltaY } = event\r\n\r\n if (this.normalizeWheel) {\r\n deltaX = clamp(-100, deltaX, 100)\r\n deltaY = clamp(-100, deltaY, 100)\r\n }\r\n\r\n deltaX *= this.wheelMultiplier\r\n deltaY *= this.wheelMultiplier\r\n\r\n this.emitter.emit('scroll', { deltaX, deltaY, event })\r\n }\r\n}\r\n","import { version } from '../package.json'\r\nimport { Animate } from './animate'\r\nimport { Dimensions } from './dimensions'\r\nimport { Emitter } from './emitter'\r\nimport { clamp, modulo } from './maths'\r\nimport { VirtualScroll } from './virtual-scroll'\r\n\r\n// Technical explanation\r\n// - listen to 'wheel' events\r\n// - prevent 'wheel' event to prevent scroll\r\n// - normalize wheel delta\r\n// - add delta to targetScroll\r\n// - animate scroll to targetScroll (smooth context)\r\n// - if animation is not running, listen to 'scroll' events (native context)\r\n\r\nexport default class Lenis {\r\n // isScrolling = true when scroll is animating\r\n // isStopped = true if user should not be able to scroll - enable/disable programmatically\r\n // isSmooth = true if scroll should be animated\r\n // isLocked = same as isStopped but enabled/disabled when scroll reaches target\r\n\r\n /**\r\n * @typedef {(t: number) => number} EasingFunction\r\n * @typedef {'vertical' | 'horizontal'} Orientation\r\n * @typedef {'vertical' | 'horizontal' | 'both'} GestureOrientation\r\n *\r\n * @typedef LenisOptions\r\n * @property {Window | HTMLElement} [wrapper]\r\n * @property {HTMLElement} [content]\r\n * @property {Window | HTMLElement} [wheelEventsTarget] // deprecated\r\n * @property {Window | HTMLElement} [eventsTarget]\r\n * @property {boolean} [smoothWheel]\r\n * @property {boolean} [smoothTouch]\r\n * @property {boolean} [syncTouch]\r\n * @property {number} [syncTouchLerp]\r\n * @property {number} [__iosNoInertiaSyncTouchLerp]\r\n * @property {number} [touchInertiaMultiplier]\r\n * @property {number} [duration]\r\n * @property {EasingFunction} [easing]\r\n * @property {number} [lerp]\r\n * @property {boolean} [infinite]\r\n * @property {Orientation} [orientation]\r\n * @property {GestureOrientation} [gestureOrientation]\r\n * @property {number} [touchMultiplier]\r\n * @property {number} [wheelMultiplier]\r\n * @property {boolean} [normalizeWheel]\r\n * @property {boolean} [autoResize]\r\n *\r\n * @param {LenisOptions}\r\n */\r\n constructor({\r\n wrapper = window,\r\n content = document.documentElement,\r\n wheelEventsTarget = wrapper, // deprecated\r\n eventsTarget = wheelEventsTarget,\r\n smoothWheel = true,\r\n smoothTouch = false,\r\n syncTouch = false,\r\n syncTouchLerp = 0.1,\r\n __iosNoInertiaSyncTouchLerp = 0.4, // should be 1 but had to leave 0.4 for iOS (testing purpose)\r\n touchInertiaMultiplier = 35,\r\n duration, // in seconds\r\n easing = (t) => Math.min(1, 1.001 - Math.pow(2, -10 * t)),\r\n lerp = !duration && 0.1,\r\n infinite = false,\r\n orientation = 'vertical', // vertical, horizontal\r\n gestureOrientation = 'vertical', // vertical, horizontal, both\r\n touchMultiplier = 1,\r\n wheelMultiplier = 1,\r\n normalizeWheel = false,\r\n autoResize = true,\r\n } = {}) {\r\n window.lenisVersion = version\r\n\r\n // if wrapper is html or body, fallback to window\r\n if (wrapper === document.documentElement || wrapper === document.body) {\r\n wrapper = window\r\n }\r\n\r\n this.options = {\r\n wrapper,\r\n content,\r\n wheelEventsTarget,\r\n eventsTarget,\r\n smoothWheel,\r\n smoothTouch,\r\n syncTouch,\r\n syncTouchLerp,\r\n __iosNoInertiaSyncTouchLerp,\r\n touchInertiaMultiplier,\r\n duration,\r\n easing,\r\n lerp,\r\n infinite,\r\n gestureOrientation,\r\n orientation,\r\n touchMultiplier,\r\n wheelMultiplier,\r\n normalizeWheel,\r\n autoResize,\r\n }\r\n\r\n this.animate = new Animate()\r\n this.emitter = new Emitter()\r\n this.dimensions = new Dimensions({ wrapper, content, autoResize })\r\n this.toggleClass('lenis', true)\r\n\r\n this.velocity = 0\r\n this.isLocked = false\r\n this.isStopped = false\r\n this.isSmooth = syncTouch || smoothWheel || smoothTouch\r\n this.isScrolling = false\r\n this.targetScroll = this.animatedScroll = this.actualScroll\r\n\r\n this.options.wrapper.addEventListener('scroll', this.onNativeScroll, {\r\n passive: false,\r\n })\r\n\r\n this.virtualScroll = new VirtualScroll(eventsTarget, {\r\n touchMultiplier,\r\n wheelMultiplier,\r\n normalizeWheel,\r\n })\r\n this.virtualScroll.on('scroll', this.onVirtualScroll)\r\n }\r\n\r\n destroy() {\r\n this.emitter.destroy()\r\n\r\n this.options.wrapper.removeEventListener('scroll', this.onNativeScroll, {\r\n passive: false,\r\n })\r\n\r\n this.virtualScroll.destroy()\r\n this.dimensions.destroy()\r\n\r\n this.toggleClass('lenis', false)\r\n this.toggleClass('lenis-smooth', false)\r\n this.toggleClass('lenis-scrolling', false)\r\n this.toggleClass('lenis-stopped', false)\r\n this.toggleClass('lenis-locked', false)\r\n }\r\n\r\n on(event, callback) {\r\n return this.emitter.on(event, callback)\r\n }\r\n\r\n off(event, callback) {\r\n return this.emitter.off(event, callback)\r\n }\r\n\r\n setScroll(scroll) {\r\n // apply scroll value immediately\r\n if (this.isHorizontal) {\r\n this.rootElement.scrollLeft = scroll\r\n } else {\r\n this.rootElement.scrollTop = scroll\r\n }\r\n }\r\n\r\n onVirtualScroll = ({ deltaX, deltaY, event }) => {\r\n // keep zoom feature\r\n if (event.ctrlKey) return\r\n\r\n const isTouch = event.type.includes('touch')\r\n const isWheel = event.type.includes('wheel')\r\n\r\n if (\r\n (this.options.gestureOrientation === 'both' &&\r\n deltaX === 0 &&\r\n deltaY === 0) || // \"touchend\" events prevents \"click\"\r\n (this.options.gestureOrientation === 'vertical' && deltaY === 0) || // trackpad previous/next page gesture\r\n (this.options.gestureOrientation === 'horizontal' && deltaX === 0) ||\r\n (isTouch &&\r\n this.options.gestureOrientation === 'vertical' &&\r\n this.scroll === 0 &&\r\n !this.options.infinite &&\r\n deltaY <= 0) // touch pull to refresh\r\n )\r\n return\r\n\r\n // catch if scrolling on nested scroll elements\r\n let composedPath = event.composedPath()\r\n composedPath = composedPath.slice(0, composedPath.indexOf(this.rootElement)) // remove parents elements\r\n\r\n if (\r\n !!composedPath.find(\r\n (node) =>\r\n node.hasAttribute?.('data-lenis-prevent') ||\r\n (isTouch && node.hasAttribute?.('data-lenis-prevent-touch')) ||\r\n (isWheel && node.hasAttribute?.('data-lenis-prevent-wheel')) ||\r\n node.classList?.contains('lenis') // nested lenis instance\r\n )\r\n )\r\n return\r\n\r\n if (this.isStopped || this.isLocked) {\r\n event.preventDefault()\r\n return\r\n }\r\n\r\n this.isSmooth =\r\n ((this.options.smoothTouch || this.options.syncTouch) && isTouch) ||\r\n (this.options.smoothWheel && isWheel)\r\n\r\n if (!this.isSmooth) {\r\n this.isScrolling = false\r\n this.animate.stop()\r\n return\r\n }\r\n\r\n event.preventDefault()\r\n\r\n let delta = deltaY\r\n if (this.options.gestureOrientation === 'both') {\r\n delta = Math.abs(deltaY) > Math.abs(deltaX) ? deltaY : deltaX\r\n } else if (this.options.gestureOrientation === 'horizontal') {\r\n delta = deltaX\r\n }\r\n\r\n const syncTouch = isTouch && this.options.syncTouch\r\n const isTouchEnd = isTouch && event.type === 'touchend'\r\n const hasTouchInertia = isTouchEnd && Math.abs(delta) > 1\r\n if (hasTouchInertia) {\r\n delta = this.velocity * this.options.touchInertiaMultiplier\r\n }\r\n\r\n this.scrollTo(this.targetScroll + delta, {\r\n programmatic: false,\r\n ...(syncTouch && {\r\n lerp: hasTouchInertia\r\n ? this.syncTouchLerp\r\n : this.options.__iosNoInertiaSyncTouchLerp,\r\n }),\r\n })\r\n }\r\n\r\n resize() {\r\n this.dimensions.resize()\r\n }\r\n\r\n emit() {\r\n this.emitter.emit('scroll', this)\r\n }\r\n\r\n onNativeScroll = () => {\r\n if (this.__preventNextScrollEvent) return\r\n\r\n if (!this.isScrolling) {\r\n const lastScroll = this.animatedScroll\r\n this.animatedScroll = this.targetScroll = this.actualScroll\r\n this.velocity = 0\r\n this.direction = Math.sign(this.animatedScroll - lastScroll)\r\n this.emit()\r\n }\r\n }\r\n\r\n reset() {\r\n this.isLocked = false\r\n this.isScrolling = false\r\n this.animatedScroll = this.targetScroll = this.actualScroll\r\n this.velocity = 0\r\n this.animate.stop()\r\n }\r\n\r\n start() {\r\n this.isStopped = false\r\n\r\n this.reset()\r\n }\r\n\r\n stop() {\r\n this.isStopped = true\r\n this.animate.stop()\r\n\r\n this.reset()\r\n }\r\n\r\n raf(time) {\r\n const deltaTime = time - (this.time || time)\r\n this.time = time\r\n\r\n this.animate.advance(deltaTime * 0.001)\r\n }\r\n\r\n scrollTo(\r\n target,\r\n {\r\n offset = 0,\r\n immediate = false,\r\n lock = false,\r\n duration = this.options.duration,\r\n easing = this.options.easing,\r\n lerp = !duration && this.options.lerp,\r\n onComplete = null,\r\n force = false, // scroll even if stopped\r\n programmatic = true, // called from outside of the class\r\n } = {}\r\n ) {\r\n if ((this.isStopped || this.isLocked) && !force) return\r\n\r\n // keywords\r\n if (['top', 'left', 'start'].includes(target)) {\r\n target = 0\r\n } else if (['bottom', 'right', 'end'].includes(target)) {\r\n target = this.limit\r\n } else {\r\n let node\r\n\r\n if (typeof target === 'string') {\r\n // CSS selector\r\n node = document.querySelector(target)\r\n } else if (target?.nodeType) {\r\n // Node element\r\n node = target\r\n }\r\n\r\n if (node) {\r\n if (this.options.wrapper !== window) {\r\n // nested scroll offset correction\r\n const wrapperRect = this.options.wrapper.getBoundingClientRect()\r\n offset -= this.isHorizontal ? wrapperRect.left : wrapperRect.top\r\n }\r\n\r\n const rect = node.getBoundingClientRect()\r\n\r\n target =\r\n (this.isHorizontal ? rect.left : rect.top) + this.animatedScroll\r\n }\r\n }\r\n\r\n if (typeof target !== 'number') return\r\n\r\n target += offset\r\n target = Math.round(target)\r\n\r\n if (this.options.infinite) {\r\n if (programmatic) {\r\n this.targetScroll = this.animatedScroll = this.scroll\r\n }\r\n } else {\r\n target = clamp(0, target, this.limit)\r\n }\r\n\r\n if (immediate) {\r\n this.animatedScroll = this.targetScroll = target\r\n this.setScroll(this.scroll)\r\n this.reset()\r\n onComplete?.(this)\r\n return\r\n }\r\n\r\n if (!programmatic) {\r\n if (target === this.targetScroll) return\r\n\r\n this.targetScroll = target\r\n }\r\n\r\n this.animate.fromTo(this.animatedScroll, target, {\r\n duration,\r\n easing,\r\n lerp,\r\n onStart: () => {\r\n // started\r\n if (lock) this.isLocked = true\r\n this.isScrolling = true\r\n },\r\n onUpdate: (value, completed) => {\r\n this.isScrolling = true\r\n\r\n // updated\r\n this.velocity = value - this.animatedScroll\r\n this.direction = Math.sign(this.velocity)\r\n\r\n this.animatedScroll = value\r\n this.setScroll(this.scroll)\r\n\r\n if (programmatic) {\r\n // wheel during programmatic should stop it\r\n this.targetScroll = value\r\n }\r\n\r\n if (!completed) this.emit()\r\n\r\n if (completed) {\r\n this.reset()\r\n this.emit()\r\n onComplete?.(this)\r\n\r\n // avoid emitting event twice\r\n this.__preventNextScrollEvent = true\r\n requestAnimationFrame(() => {\r\n delete this.__preventNextScrollEvent\r\n })\r\n }\r\n },\r\n })\r\n }\r\n\r\n get rootElement() {\r\n return this.options.wrapper === window\r\n ? document.documentElement\r\n : this.options.wrapper\r\n }\r\n\r\n get limit() {\r\n return this.dimensions.limit[this.isHorizontal ? 'x' : 'y']\r\n }\r\n\r\n get isHorizontal() {\r\n return this.options.orientation === 'horizontal'\r\n }\r\n\r\n get actualScroll() {\r\n // value browser takes into account\r\n return this.isHorizontal\r\n ? this.rootElement.scrollLeft\r\n : this.rootElement.scrollTop\r\n }\r\n\r\n get scroll() {\r\n return this.options.infinite\r\n ? modulo(this.animatedScroll, this.limit)\r\n : this.animatedScroll\r\n }\r\n\r\n get progress() {\r\n // avoid progress to be NaN\r\n return this.limit === 0 ? 1 : this.scroll / this.limit\r\n }\r\n\r\n get isSmooth() {\r\n return this.__isSmooth\r\n }\r\n\r\n set isSmooth(value) {\r\n if (this.__isSmooth !== value) {\r\n this.__isSmooth = value\r\n this.toggleClass('lenis-smooth', value)\r\n }\r\n }\r\n\r\n get isScrolling() {\r\n return this.__isScrolling\r\n }\r\n\r\n set isScrolling(value) {\r\n if (this.__isScrolling !== value) {\r\n this.__isScrolling = value\r\n this.toggleClass('lenis-scrolling', value)\r\n }\r\n }\r\n\r\n get isStopped() {\r\n return this.__isStopped\r\n }\r\n\r\n set isStopped(value) {\r\n if (this.__isStopped !== value) {\r\n this.__isStopped = value\r\n this.toggleClass('lenis-stopped', value)\r\n }\r\n }\r\n\r\n get isLocked() {\r\n return this.__isLocked\r\n }\r\n\r\n set isLocked(value) {\r\n if (this.__isLocked !== value) {\r\n this.__isLocked = value\r\n this.toggleClass('lenis-locked', value)\r\n }\r\n }\r\n\r\n get className() {\r\n let className = 'lenis'\r\n if (this.isStopped) className += ' lenis-stopped'\r\n if (this.isLocked) className += ' lenis-locked'\r\n if (this.isScrolling) className += ' lenis-scrolling'\r\n if (this.isSmooth) className += ' lenis-smooth'\r\n return className\r\n }\r\n\r\n toggleClass(name, value) {\r\n this.rootElement.classList.toggle(name, value)\r\n this.emitter.emit('className change', this)\r\n }\r\n}\r\n"],"names":["clamp","min","input","max","Math","Animate","advance","deltaTime","this","isRunning","completed","lerp","value","x","y","to","lambda","dt","t","exp","round","currentTime","linearProgress","duration","easedProgress","easing","from","onUpdate","stop","fromTo","onStart","Dimensions","constructor","wrapper","content","autoResize","resize","callback","delay","timer","args","arguments","context","clearTimeout","setTimeout","apply","debounce","window","wrapperResizeObserver","ResizeObserver","observe","contentResizeObserver","destroy","disconnect","onWrapperResize","onContentResize","width","innerWidth","height","innerHeight","clientWidth","clientHeight","scrollHeight","scrollWidth","limit","Emitter","events","emit","event","callbacks","i","length","on","cb","push","filter","off","VirtualScroll","element","wheelMultiplier","touchMultiplier","normalizeWheel","touchStart","emitter","addEventListener","onWheel","passive","onTouchStart","onTouchMove","onTouchEnd","removeEventListener","clientX","clientY","targetTouches","lastDelta","deltaX","deltaY","Lenis","document","documentElement","wheelEventsTarget","eventsTarget","smoothWheel","smoothTouch","syncTouch","syncTouchLerp","__iosNoInertiaSyncTouchLerp","touchInertiaMultiplier","pow","infinite","orientation","gestureOrientation","lenisVersion","body","options","animate","dimensions","toggleClass","velocity","isLocked","isStopped","isSmooth","isScrolling","targetScroll","animatedScroll","actualScroll","onNativeScroll","virtualScroll","onVirtualScroll","setScroll","scroll","isHorizontal","rootElement","scrollLeft","scrollTop","ctrlKey","isTouch","type","includes","isWheel","composedPath","slice","indexOf","find","node","hasAttribute","classList","contains","preventDefault","delta","abs","hasTouchInertia","scrollTo","programmatic","__preventNextScrollEvent","lastScroll","direction","sign","reset","start","raf","time","target","offset","immediate","lock","onComplete","force","querySelector","nodeType","wrapperRect","getBoundingClientRect","left","top","rect","requestAnimationFrame","n","d","progress","__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H,cAAa6D,GAAa,oBAC/B/K,KAAKiH,WAAU8D,GAAa,iBACzBA,CACR,CAED,WAAAlE,CAAYmE,EAAM5K,GAChBJ,KAAK4H,YAAYc,UAAUuC,OAAOD,EAAM5K,GACxCJ,KAAK2E,QAAQhB,KAAK,mBAAoB3D,KACvC"} \ No newline at end of file +{"version":3,"file":"lenis.umd.js","sources":["../src/maths.js","../src/animate.js","../src/dimensions.js","../src/debounce.js","../src/emitter.js","../src/virtual-scroll.js","../src/index.js"],"sourcesContent":["// Clamp a value between a minimum and maximum value\r\nexport function clamp(min, input, max) {\r\n return Math.max(min, Math.min(input, max))\r\n}\r\n\r\n// Truncate a floating-point number to a specified number of decimal places\r\nexport function truncate(value, decimals = 0) {\r\n return parseFloat(value.toFixed(decimals))\r\n}\r\n\r\n// Linearly interpolate between two values using an amount (0 <= t <= 1)\r\nexport function lerp(x, y, t) {\r\n return (1 - t) * x + t * y\r\n}\r\n\r\n// http://www.rorydriscoll.com/2016/03/07/frame-rate-independent-damping-using-lerp/\r\nexport function damp(x, y, lambda, dt) {\r\n return lerp(x, y, 1 - Math.exp(-lambda * dt))\r\n}\r\n\r\n// Calculate the modulo of the dividend and divisor while keeping the result within the same sign as the divisor\r\n// https://anguscroll.com/just/just-modulo\r\nexport function modulo(n, d) {\r\n return ((n % d) + d) % d\r\n}\r\n","import { clamp, damp } from './maths'\r\n\r\n// Animate class to handle value animations with lerping or easing\r\nexport class Animate {\r\n // Advance the animation by the given delta time\r\n advance(deltaTime) {\r\n if (!this.isRunning) return\r\n\r\n let completed = false\r\n\r\n if (this.lerp) {\r\n this.value = damp(this.value, this.to, this.lerp * 60, deltaTime)\r\n if (Math.round(this.value) === this.to) {\r\n this.value = this.to\r\n completed = true\r\n }\r\n } else {\r\n this.currentTime += deltaTime\r\n const linearProgress = clamp(0, this.currentTime / this.duration, 1)\r\n\r\n completed = linearProgress >= 1\r\n const easedProgress = completed ? 1 : this.easing(linearProgress)\r\n this.value = this.from + (this.to - this.from) * easedProgress\r\n }\r\n\r\n // Call the onUpdate callback with the current value and completed status\r\n this.onUpdate?.(this.value, completed)\r\n\r\n if (completed) {\r\n this.stop()\r\n }\r\n }\r\n\r\n // Stop the animation\r\n stop() {\r\n this.isRunning = false\r\n }\r\n\r\n // Set up the animation from a starting value to an ending value\r\n // with optional parameters for lerping, duration, easing, and onUpdate callback\r\n fromTo(\r\n from,\r\n to,\r\n { lerp = 0.1, duration = 1, easing = (t) => t, onStart, onUpdate }\r\n ) {\r\n this.from = this.value = from\r\n this.to = to\r\n this.lerp = lerp\r\n this.duration = duration\r\n this.easing = easing\r\n this.currentTime = 0\r\n this.isRunning = true\r\n\r\n onStart?.()\r\n this.onUpdate = onUpdate\r\n }\r\n}\r\n","import { debounce } from './debounce'\r\n\r\nexport class Dimensions {\r\n constructor({ wrapper, content, autoResize = true } = {}) {\r\n this.wrapper = wrapper\r\n this.content = content\r\n\r\n if (autoResize) {\r\n const resize = debounce(this.resize, 250)\r\n\r\n if (this.wrapper !== window) {\r\n this.wrapperResizeObserver = new ResizeObserver(resize)\r\n this.wrapperResizeObserver.observe(this.wrapper)\r\n }\r\n\r\n this.contentResizeObserver = new ResizeObserver(resize)\r\n this.contentResizeObserver.observe(this.content)\r\n }\r\n\r\n this.resize()\r\n }\r\n\r\n destroy() {\r\n this.wrapperResizeObserver?.disconnect()\r\n this.contentResizeObserver?.disconnect()\r\n }\r\n\r\n resize = () => {\r\n this.onWrapperResize()\r\n this.onContentResize()\r\n }\r\n\r\n onWrapperResize = () => {\r\n if (this.wrapper === window) {\r\n this.width = window.innerWidth\r\n this.height = window.innerHeight\r\n } else {\r\n this.width = this.wrapper.clientWidth\r\n this.height = this.wrapper.clientHeight\r\n }\r\n }\r\n\r\n onContentResize = () => {\r\n this.scrollHeight = this.content.scrollHeight\r\n this.scrollWidth = this.content.scrollWidth\r\n }\r\n\r\n get limit() {\r\n return {\r\n x: this.scrollWidth - this.width,\r\n y: this.scrollHeight - this.height,\r\n }\r\n }\r\n}\r\n","export function debounce(callback, delay) {\r\n let timer\r\n return function () {\r\n let args = arguments\r\n let context = this\r\n clearTimeout(timer)\r\n timer = setTimeout(function () {\r\n callback.apply(context, args)\r\n }, delay)\r\n }\r\n}\r\n","export class Emitter {\r\n constructor() {\r\n this.events = {}\r\n }\r\n\r\n emit(event, ...args) {\r\n let callbacks = this.events[event] || []\r\n for (let i = 0, length = callbacks.length; i < length; i++) {\r\n callbacks[i](...args)\r\n }\r\n }\r\n\r\n on(event, cb) {\r\n // Add the callback to the event's callback list, or create a new list with the callback\r\n this.events[event]?.push(cb) || (this.events[event] = [cb])\r\n\r\n // Return an unsubscribe function\r\n return () => {\r\n this.events[event] = this.events[event]?.filter((i) => cb !== i)\r\n }\r\n }\r\n\r\n off(event, callback) {\r\n this.events[event] = this.events[event]?.filter((i) => callback !== i)\r\n }\r\n\r\n destroy() {\r\n this.events = {}\r\n }\r\n}\r\n","import { Emitter } from './emitter'\r\nimport { clamp } from './maths'\r\n\r\nexport class VirtualScroll {\r\n constructor(\r\n element,\r\n { wheelMultiplier = 1, touchMultiplier = 2, normalizeWheel = false }\r\n ) {\r\n this.element = element\r\n this.wheelMultiplier = wheelMultiplier\r\n this.touchMultiplier = touchMultiplier\r\n this.normalizeWheel = normalizeWheel\r\n\r\n this.touchStart = {\r\n x: null,\r\n y: null,\r\n }\r\n\r\n this.emitter = new Emitter()\r\n\r\n this.element.addEventListener('wheel', this.onWheel, { passive: false })\r\n this.element.addEventListener('touchstart', this.onTouchStart, {\r\n passive: false,\r\n })\r\n this.element.addEventListener('touchmove', this.onTouchMove, {\r\n passive: false,\r\n })\r\n this.element.addEventListener('touchend', this.onTouchEnd, {\r\n passive: false,\r\n })\r\n }\r\n\r\n // Add an event listener for the given event and callback\r\n on(event, callback) {\r\n return this.emitter.on(event, callback)\r\n }\r\n\r\n // Remove all event listeners and clean up\r\n destroy() {\r\n this.emitter.destroy()\r\n\r\n this.element.removeEventListener('wheel', this.onWheel, {\r\n passive: false,\r\n })\r\n this.element.removeEventListener('touchstart', this.onTouchStart, {\r\n passive: false,\r\n })\r\n this.element.removeEventListener('touchmove', this.onTouchMove, {\r\n passive: false,\r\n })\r\n this.element.removeEventListener('touchend', this.onTouchEnd, {\r\n passive: false,\r\n })\r\n }\r\n\r\n // Event handler for 'touchstart' event\r\n onTouchStart = (event) => {\r\n const { clientX, clientY } = event.targetTouches\r\n ? event.targetTouches[0]\r\n : event\r\n\r\n this.touchStart.x = clientX\r\n this.touchStart.y = clientY\r\n\r\n this.lastDelta = {\r\n x: 0,\r\n y: 0,\r\n }\r\n\r\n this.emitter.emit('scroll', {\r\n deltaX: 0,\r\n deltaY: 0,\r\n event,\r\n })\r\n }\r\n\r\n // Event handler for 'touchmove' event\r\n onTouchMove = (event) => {\r\n const { clientX, clientY } = event.targetTouches\r\n ? event.targetTouches[0]\r\n : event\r\n\r\n const deltaX = -(clientX - this.touchStart.x) * this.touchMultiplier\r\n const deltaY = -(clientY - this.touchStart.y) * this.touchMultiplier\r\n\r\n this.touchStart.x = clientX\r\n this.touchStart.y = clientY\r\n\r\n this.lastDelta = {\r\n x: deltaX,\r\n y: deltaY,\r\n }\r\n\r\n this.emitter.emit('scroll', {\r\n deltaX,\r\n deltaY,\r\n event,\r\n })\r\n }\r\n\r\n onTouchEnd = (event) => {\r\n this.emitter.emit('scroll', {\r\n deltaX: this.lastDelta.x,\r\n deltaY: this.lastDelta.y,\r\n event,\r\n })\r\n }\r\n\r\n // Event handler for 'wheel' event\r\n onWheel = (event) => {\r\n let { deltaX, deltaY } = event\r\n\r\n if (this.normalizeWheel) {\r\n deltaX = clamp(-100, deltaX, 100)\r\n deltaY = clamp(-100, deltaY, 100)\r\n }\r\n\r\n deltaX *= this.wheelMultiplier\r\n deltaY *= this.wheelMultiplier\r\n\r\n this.emitter.emit('scroll', { deltaX, deltaY, event })\r\n }\r\n}\r\n","import { version } from '../package.json'\r\nimport { Animate } from './animate'\r\nimport { Dimensions } from './dimensions'\r\nimport { Emitter } from './emitter'\r\nimport { clamp, modulo } from './maths'\r\nimport { VirtualScroll } from './virtual-scroll'\r\n\r\n// Technical explanation\r\n// - listen to 'wheel' events\r\n// - prevent 'wheel' event to prevent scroll\r\n// - normalize wheel delta\r\n// - add delta to targetScroll\r\n// - animate scroll to targetScroll (smooth context)\r\n// - if animation is not running, listen to 'scroll' events (native context)\r\n\r\nexport default class Lenis {\r\n // isScrolling = true when scroll is animating\r\n // isStopped = true if user should not be able to scroll - enable/disable programmatically\r\n // isSmooth = true if scroll should be animated\r\n // isLocked = same as isStopped but enabled/disabled when scroll reaches target\r\n\r\n /**\r\n * @typedef {(t: number) => number} EasingFunction\r\n * @typedef {'vertical' | 'horizontal'} Orientation\r\n * @typedef {'vertical' | 'horizontal' | 'both'} GestureOrientation\r\n *\r\n * @typedef LenisOptions\r\n * @property {Window | HTMLElement} [wrapper]\r\n * @property {HTMLElement} [content]\r\n * @property {Window | HTMLElement} [wheelEventsTarget] // deprecated\r\n * @property {Window | HTMLElement} [eventsTarget]\r\n * @property {boolean} [smoothWheel]\r\n * @property {boolean} [smoothTouch]\r\n * @property {boolean} [syncTouch]\r\n * @property {number} [syncTouchLerp]\r\n // * @property {number} [__iosNoInertiaSyncTouchLerp]\r\n * @property {number} [touchInertiaMultiplier]\r\n * @property {number} [duration]\r\n * @property {EasingFunction} [easing]\r\n * @property {number} [lerp]\r\n * @property {boolean} [infinite]\r\n * @property {Orientation} [orientation]\r\n * @property {GestureOrientation} [gestureOrientation]\r\n * @property {number} [touchMultiplier]\r\n * @property {number} [wheelMultiplier]\r\n * @property {boolean} [normalizeWheel]\r\n * @property {boolean} [autoResize]\r\n *\r\n * @param {LenisOptions}\r\n */\r\n constructor({\r\n wrapper = window,\r\n content = document.documentElement,\r\n wheelEventsTarget = wrapper, // deprecated\r\n eventsTarget = wheelEventsTarget,\r\n smoothWheel = true,\r\n smoothTouch = false,\r\n syncTouch = false,\r\n syncTouchLerp = 0.075,\r\n // __iosNoInertiaSyncTouchLerp = 0.4, // should be 1 but had to leave 0.4 for iOS (testing purpose)\r\n touchInertiaMultiplier = 35,\r\n duration, // in seconds\r\n easing = (t) => Math.min(1, 1.001 - Math.pow(2, -10 * t)),\r\n lerp = !duration && 0.1,\r\n infinite = false,\r\n orientation = 'vertical', // vertical, horizontal\r\n gestureOrientation = 'vertical', // vertical, horizontal, both\r\n touchMultiplier = 1,\r\n wheelMultiplier = 1,\r\n normalizeWheel = false,\r\n autoResize = true,\r\n } = {}) {\r\n window.lenisVersion = version\r\n\r\n // if wrapper is html or body, fallback to window\r\n if (wrapper === document.documentElement || wrapper === document.body) {\r\n wrapper = window\r\n }\r\n\r\n this.options = {\r\n wrapper,\r\n content,\r\n wheelEventsTarget,\r\n eventsTarget,\r\n smoothWheel,\r\n smoothTouch,\r\n syncTouch,\r\n syncTouchLerp,\r\n // __iosNoInertiaSyncTouchLerp,\r\n touchInertiaMultiplier,\r\n duration,\r\n easing,\r\n lerp,\r\n infinite,\r\n gestureOrientation,\r\n orientation,\r\n touchMultiplier,\r\n wheelMultiplier,\r\n normalizeWheel,\r\n autoResize,\r\n }\r\n\r\n this.animate = new Animate()\r\n this.emitter = new Emitter()\r\n this.dimensions = new Dimensions({ wrapper, content, autoResize })\r\n this.toggleClass('lenis', true)\r\n\r\n this.velocity = 0\r\n this.isLocked = false\r\n this.isStopped = false\r\n this.isSmooth = syncTouch || smoothWheel || smoothTouch\r\n this.isScrolling = false\r\n this.targetScroll = this.animatedScroll = this.actualScroll\r\n\r\n this.options.wrapper.addEventListener('scroll', this.onNativeScroll, {\r\n passive: false,\r\n })\r\n\r\n this.virtualScroll = new VirtualScroll(eventsTarget, {\r\n touchMultiplier,\r\n wheelMultiplier,\r\n normalizeWheel,\r\n })\r\n this.virtualScroll.on('scroll', this.onVirtualScroll)\r\n }\r\n\r\n destroy() {\r\n this.emitter.destroy()\r\n\r\n this.options.wrapper.removeEventListener('scroll', this.onNativeScroll, {\r\n passive: false,\r\n })\r\n\r\n this.virtualScroll.destroy()\r\n this.dimensions.destroy()\r\n\r\n this.toggleClass('lenis', false)\r\n this.toggleClass('lenis-smooth', false)\r\n this.toggleClass('lenis-scrolling', false)\r\n this.toggleClass('lenis-stopped', false)\r\n this.toggleClass('lenis-locked', false)\r\n }\r\n\r\n on(event, callback) {\r\n return this.emitter.on(event, callback)\r\n }\r\n\r\n off(event, callback) {\r\n return this.emitter.off(event, callback)\r\n }\r\n\r\n setScroll(scroll) {\r\n // apply scroll value immediately\r\n if (this.isHorizontal) {\r\n this.rootElement.scrollLeft = scroll\r\n } else {\r\n this.rootElement.scrollTop = scroll\r\n }\r\n }\r\n\r\n onVirtualScroll = ({ deltaX, deltaY, event }) => {\r\n // keep zoom feature\r\n if (event.ctrlKey) return\r\n\r\n const isTouch = event.type.includes('touch')\r\n const isWheel = event.type.includes('wheel')\r\n\r\n const isTapToStop =\r\n (this.options.smoothTouch || this.options.syncTouch) &&\r\n isTouch &&\r\n event.type === 'touchstart'\r\n\r\n if (isTapToStop) {\r\n this.reset()\r\n return\r\n }\r\n\r\n const isClick = deltaX === 0 && deltaY === 0 // click event\r\n\r\n // const isPullToRefresh =\r\n // this.options.gestureOrientation === 'vertical' &&\r\n // this.scroll === 0 &&\r\n // !this.options.infinite &&\r\n // deltaY <= 5 // touch pull to refresh, not reliable yet\r\n\r\n const isUnknownGesture =\r\n (this.options.gestureOrientation === 'vertical' && deltaY === 0) ||\r\n (this.options.gestureOrientation === 'horizontal' && deltaX === 0)\r\n\r\n if (isClick || isUnknownGesture) {\r\n // console.log('prevent')\r\n return\r\n }\r\n\r\n // catch if scrolling on nested scroll elements\r\n let composedPath = event.composedPath()\r\n composedPath = composedPath.slice(0, composedPath.indexOf(this.rootElement)) // remove parents elements\r\n\r\n if (\r\n !!composedPath.find(\r\n (node) =>\r\n node.hasAttribute?.('data-lenis-prevent') ||\r\n (isTouch && node.hasAttribute?.('data-lenis-prevent-touch')) ||\r\n (isWheel && node.hasAttribute?.('data-lenis-prevent-wheel')) ||\r\n node.classList?.contains('lenis') // nested lenis instance\r\n )\r\n )\r\n return\r\n\r\n if (this.isStopped || this.isLocked) {\r\n event.preventDefault()\r\n return\r\n }\r\n\r\n this.isSmooth =\r\n ((this.options.smoothTouch || this.options.syncTouch) && isTouch) ||\r\n (this.options.smoothWheel && isWheel)\r\n\r\n if (!this.isSmooth) {\r\n this.isScrolling = false\r\n this.animate.stop()\r\n return\r\n }\r\n\r\n event.preventDefault()\r\n\r\n let delta = deltaY\r\n if (this.options.gestureOrientation === 'both') {\r\n delta = Math.abs(deltaY) > Math.abs(deltaX) ? deltaY : deltaX\r\n } else if (this.options.gestureOrientation === 'horizontal') {\r\n delta = deltaX\r\n }\r\n\r\n const syncTouch = isTouch && this.options.syncTouch\r\n const isTouchEnd = isTouch && event.type === 'touchend'\r\n\r\n const hasTouchInertia = isTouchEnd && Math.abs(delta) > 5\r\n\r\n if (hasTouchInertia) {\r\n delta = this.velocity * this.options.touchInertiaMultiplier\r\n }\r\n\r\n this.scrollTo(this.targetScroll + delta, {\r\n programmatic: false,\r\n ...(syncTouch\r\n ? {\r\n lerp: hasTouchInertia ? this.options.syncTouchLerp : 1,\r\n }\r\n : {\r\n lerp: this.options.lerp,\r\n duration: this.options.duration,\r\n easing: this.options.easing,\r\n }),\r\n })\r\n }\r\n\r\n resize() {\r\n this.dimensions.resize()\r\n }\r\n\r\n emit() {\r\n this.emitter.emit('scroll', this)\r\n }\r\n\r\n onNativeScroll = () => {\r\n if (this.__preventNextScrollEvent) return\r\n\r\n if (!this.isScrolling) {\r\n const lastScroll = this.animatedScroll\r\n this.animatedScroll = this.targetScroll = this.actualScroll\r\n this.velocity = 0\r\n this.direction = Math.sign(this.animatedScroll - lastScroll)\r\n this.emit()\r\n }\r\n }\r\n\r\n reset() {\r\n this.isLocked = false\r\n this.isScrolling = false\r\n this.animatedScroll = this.targetScroll = this.actualScroll\r\n this.velocity = 0\r\n this.animate.stop()\r\n }\r\n\r\n start() {\r\n this.isStopped = false\r\n\r\n this.reset()\r\n }\r\n\r\n stop() {\r\n this.isStopped = true\r\n this.animate.stop()\r\n\r\n this.reset()\r\n }\r\n\r\n raf(time) {\r\n const deltaTime = time - (this.time || time)\r\n this.time = time\r\n\r\n this.animate.advance(deltaTime * 0.001)\r\n }\r\n\r\n scrollTo(\r\n target,\r\n {\r\n offset = 0,\r\n immediate = false,\r\n lock = false,\r\n duration = this.options.duration,\r\n easing = this.options.easing,\r\n lerp = !duration && this.options.lerp,\r\n onComplete = null,\r\n force = false, // scroll even if stopped\r\n programmatic = true, // called from outside of the class\r\n } = {}\r\n ) {\r\n if ((this.isStopped || this.isLocked) && !force) return\r\n\r\n // keywords\r\n if (['top', 'left', 'start'].includes(target)) {\r\n target = 0\r\n } else if (['bottom', 'right', 'end'].includes(target)) {\r\n target = this.limit\r\n } else {\r\n let node\r\n\r\n if (typeof target === 'string') {\r\n // CSS selector\r\n node = document.querySelector(target)\r\n } else if (target?.nodeType) {\r\n // Node element\r\n node = target\r\n }\r\n\r\n if (node) {\r\n if (this.options.wrapper !== window) {\r\n // nested scroll offset correction\r\n const wrapperRect = this.options.wrapper.getBoundingClientRect()\r\n offset -= this.isHorizontal ? wrapperRect.left : wrapperRect.top\r\n }\r\n\r\n const rect = node.getBoundingClientRect()\r\n\r\n target =\r\n (this.isHorizontal ? rect.left : rect.top) + this.animatedScroll\r\n }\r\n }\r\n\r\n if (typeof target !== 'number') return\r\n\r\n target += offset\r\n target = Math.round(target)\r\n\r\n if (this.options.infinite) {\r\n if (programmatic) {\r\n this.targetScroll = this.animatedScroll = this.scroll\r\n }\r\n } else {\r\n target = clamp(0, target, this.limit)\r\n }\r\n\r\n if (immediate) {\r\n this.animatedScroll = this.targetScroll = target\r\n this.setScroll(this.scroll)\r\n this.reset()\r\n onComplete?.(this)\r\n return\r\n }\r\n\r\n if (!programmatic) {\r\n if (target === this.targetScroll) return\r\n\r\n this.targetScroll = target\r\n }\r\n\r\n this.animate.fromTo(this.animatedScroll, target, {\r\n duration,\r\n easing,\r\n lerp,\r\n onStart: () => {\r\n // started\r\n if (lock) this.isLocked = true\r\n this.isScrolling = true\r\n },\r\n onUpdate: (value, completed) => {\r\n this.isScrolling = true\r\n\r\n // updated\r\n this.velocity = value - this.animatedScroll\r\n this.direction = Math.sign(this.velocity)\r\n\r\n this.animatedScroll = value\r\n this.setScroll(this.scroll)\r\n\r\n if (programmatic) {\r\n // wheel during programmatic should stop it\r\n this.targetScroll = value\r\n }\r\n\r\n if (!completed) this.emit()\r\n\r\n if (completed) {\r\n this.reset()\r\n this.emit()\r\n onComplete?.(this)\r\n\r\n // avoid emitting event twice\r\n this.__preventNextScrollEvent = true\r\n requestAnimationFrame(() => {\r\n delete this.__preventNextScrollEvent\r\n })\r\n }\r\n },\r\n })\r\n }\r\n\r\n get rootElement() {\r\n return this.options.wrapper === window\r\n ? document.documentElement\r\n : this.options.wrapper\r\n }\r\n\r\n get limit() {\r\n return this.dimensions.limit[this.isHorizontal ? 'x' : 'y']\r\n }\r\n\r\n get isHorizontal() {\r\n return this.options.orientation === 'horizontal'\r\n }\r\n\r\n get actualScroll() {\r\n // value browser takes into account\r\n return this.isHorizontal\r\n ? this.rootElement.scrollLeft\r\n : this.rootElement.scrollTop\r\n }\r\n\r\n get scroll() {\r\n return this.options.infinite\r\n ? modulo(this.animatedScroll, this.limit)\r\n : this.animatedScroll\r\n }\r\n\r\n get progress() {\r\n // avoid progress to be NaN\r\n return this.limit === 0 ? 1 : this.scroll / this.limit\r\n }\r\n\r\n get isSmooth() {\r\n return this.__isSmooth\r\n }\r\n\r\n set isSmooth(value) {\r\n if (this.__isSmooth !== value) {\r\n this.__isSmooth = value\r\n this.toggleClass('lenis-smooth', value)\r\n }\r\n }\r\n\r\n get isScrolling() {\r\n return this.__isScrolling\r\n }\r\n\r\n set isScrolling(value) {\r\n if (this.__isScrolling !== value) {\r\n this.__isScrolling = value\r\n this.toggleClass('lenis-scrolling', value)\r\n }\r\n }\r\n\r\n get isStopped() {\r\n return this.__isStopped\r\n }\r\n\r\n set isStopped(value) {\r\n if (this.__isStopped !== value) {\r\n this.__isStopped = value\r\n this.toggleClass('lenis-stopped', value)\r\n }\r\n }\r\n\r\n get isLocked() {\r\n return this.__isLocked\r\n }\r\n\r\n set isLocked(value) {\r\n if (this.__isLocked !== value) {\r\n this.__isLocked = value\r\n this.toggleClass('lenis-locked', value)\r\n }\r\n }\r\n\r\n get className() {\r\n let className = 'lenis'\r\n if (this.isStopped) className += ' lenis-stopped'\r\n if (this.isLocked) className += ' lenis-locked'\r\n if (this.isScrolling) className += ' lenis-scrolling'\r\n if (this.isSmooth) className += ' lenis-smooth'\r\n return className\r\n }\r\n\r\n toggleClass(name, value) {\r\n this.rootElement.classList.toggle(name, value)\r\n this.emitter.emit('className change', this)\r\n }\r\n}\r\n"],"names":["clamp","min","input","max","Math","Animate","advance","deltaTime","this","isRunning","completed","lerp","value","x","y","to","lambda","dt","t","exp","round","currentTime","linearProgress","duration","easedProgress","easing","from","onUpdate","stop","fromTo","onStart","Dimensions","constructor","wrapper","content","autoResize","resize","callback","delay","timer","args","arguments","context","clearTimeout","setTimeout","apply","debounce","window","wrapperResizeObserver","ResizeObserver","observe","contentResizeObserver","destroy","disconnect","onWrapperResize","onContentResize","width","innerWidth","height","innerHeight","clientWidth","clientHeight","scrollHeight","scrollWidth","limit","Emitter","events","emit","event","callbacks","i","length","on","cb","push","filter","off","VirtualScroll","element","wheelMultiplier","touchMultiplier","normalizeWheel","touchStart","emitter","addEventListener","onWheel","passive","onTouchStart","onTouchMove","onTouchEnd","removeEventListener","clientX","clientY","targetTouches","lastDelta","deltaX","deltaY","Lenis","document","documentElement","wheelEventsTarget","eventsTarget","smoothWheel","smoothTouch","syncTouch","syncTouchLerp","touchInertiaMultiplier","pow","infinite","orientation","gestureOrientation","lenisVersion","body","options","animate","dimensions","toggleClass","velocity","isLocked","isStopped","isSmooth","isScrolling","targetScroll","animatedScroll","actualScroll","onNativeScroll","virtualScroll","onVirtualScroll","setScroll","scroll","isHorizontal","rootElement","scrollLeft","scrollTop","ctrlKey","isTouch","type","includes","isWheel","reset","isClick","isUnknownGesture","composedPath","slice","indexOf","find","node","hasAttribute","classList","contains","preventDefault","delta","abs","hasTouchInertia","scrollTo","programmatic","__preventNextScrollEvent","lastScroll","direction","sign","start","raf","time","target","offset","immediate","lock","onComplete","force","querySelector","nodeType","wrapperRect","getBoundingClientRect","left","top","rect","requestAnimationFrame","n","d","progress","__isSmooth","__isScrolling","__isStopped","__isLocked","className","name","toggle"],"mappings":"sOACO,SAASA,EAAMC,EAAKC,EAAOC,GAChC,OAAOC,KAAKD,IAAIF,EAAKG,KAAKH,IAAIC,EAAOC,GACvC,CCAO,MAAME,QAEX,OAAAC,CAAQC,GACN,IAAKC,KAAKC,UAAW,OAErB,IAAIC,GAAY,EAEhB,GAAIF,KAAKG,KACPH,KAAKI,ODKUC,ECLGL,KAAKI,MDKLE,ECLYN,KAAKO,GDKdC,ECL8B,GAAZR,KAAKG,KDKfM,ECL0BV,EDAtD,SAAcM,EAAGC,EAAGI,GACzB,OAAQ,EAAIA,GAAKL,EAAIK,EAAIJ,CAC3B,CAISH,CAAKE,EAAGC,EAAG,EAAIV,KAAKe,KAAKH,EAASC,KCLjCb,KAAKgB,MAAMZ,KAAKI,SAAWJ,KAAKO,KAClCP,KAAKI,MAAQJ,KAAKO,GAClBL,GAAY,OAET,CACLF,KAAKa,aAAed,EACpB,MAAMe,EAAiBtB,EAAM,EAAGQ,KAAKa,YAAcb,KAAKe,SAAU,GAElEb,EAAYY,GAAkB,EAC9B,MAAME,EAAgBd,EAAY,EAAIF,KAAKiB,OAAOH,GAClDd,KAAKI,MAAQJ,KAAKkB,MAAQlB,KAAKO,GAAKP,KAAKkB,MAAQF,CAClD,CDPE,IAAcX,EAAGC,EAAGE,EAAQC,ECU/BT,KAAKmB,WAAWnB,KAAKI,MAAOF,GAExBA,GACFF,KAAKoB,MAER,CAGD,IAAAA,GACEpB,KAAKC,WAAY,CAClB,CAID,MAAAoB,CACEH,EACA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2G,GACF,OAAO/G,KAAK8K,WACb,CAED,aAAI/D,CAAU3G,GACRJ,KAAK8K,cAAgB1K,IACvBJ,KAAK8K,YAAc1K,EACnBJ,KAAK4G,YAAY,gBAAiBxG,GAErC,CAED,YAAI0G,GACF,OAAO9G,KAAK+K,UACb,CAED,YAAIjE,CAAS1G,GACPJ,KAAK+K,aAAe3K,IACtBJ,KAAK+K,WAAa3K,EAClBJ,KAAK4G,YAAY,eAAgBxG,GAEpC,CAED,aAAI4K,GACF,IAAIA,EAAY,QAKhB,OAJIhL,KAAK+G,YAAWiE,GAAa,kBAC7BhL,KAAK8G,WAAUkE,GAAa,iBAC5BhL,KAAKiH,cAAa+D,GAAa,oBAC/BhL,KAAKgH,WAAUgE,GAAa,iBACzBA,CACR,CAED,WAAApE,CAAYqE,EAAM7K,GAChBJ,KAAK2H,YAAYiB,UAAUsC,OAAOD,EAAM7K,GACxCJ,KAAK2E,QAAQhB,KAAK,mBAAoB3D,KACvC"} \ No newline at end of file diff --git a/packages/lenis/dist/types/index.d.ts b/packages/lenis/dist/types/index.d.ts index 4e5c492e..042d76fa 100644 --- a/packages/lenis/dist/types/index.d.ts +++ b/packages/lenis/dist/types/index.d.ts @@ -1,5 +1,5 @@ export default class Lenis { - constructor({ wrapper, content, wheelEventsTarget, eventsTarget, smoothWheel, smoothTouch, syncTouch, syncTouchLerp, __iosNoInertiaSyncTouchLerp, touchInertiaMultiplier, duration, easing, lerp, infinite, orientation, gestureOrientation, touchMultiplier, wheelMultiplier, normalizeWheel, autoResize, }?: { + constructor({ wrapper, content, wheelEventsTarget, eventsTarget, smoothWheel, smoothTouch, syncTouch, syncTouchLerp, touchInertiaMultiplier, duration, easing, lerp, infinite, orientation, gestureOrientation, touchMultiplier, wheelMultiplier, normalizeWheel, autoResize, }?: { wrapper?: Window | HTMLElement; content?: HTMLElement; wheelEventsTarget?: Window | HTMLElement; @@ -8,7 +8,6 @@ export default class Lenis { smoothTouch?: boolean; syncTouch?: boolean; syncTouchLerp?: number; - __iosNoInertiaSyncTouchLerp?: number; touchInertiaMultiplier?: number; duration?: number; easing?: (t: number) => number; @@ -30,7 +29,6 @@ export default class Lenis { smoothTouch: boolean; syncTouch: boolean; syncTouchLerp: number; - __iosNoInertiaSyncTouchLerp: number; touchInertiaMultiplier: number; duration: number; easing: (t: number) => number; diff --git a/packages/lenis/playground/jank.js b/packages/lenis/playground/jank.js new file mode 100644 index 00000000..37b34ef3 --- /dev/null +++ b/packages/lenis/playground/jank.js @@ -0,0 +1,174 @@ +;(function (window) { + 'use strict' + + const html = ` + +
+ + + + + + + +
+ ` + + document.body.insertAdjacentHTML('beforeend', html) + + var app = {}, + proto = document.querySelector('.proto'), + movers, + bodySize = document.body.getBoundingClientRect(), + ballSize = proto.getBoundingClientRect(), + maxHeight = Math.floor(bodySize.height - ballSize.height), + maxWidth = 97, // 100vw - width of square (3vw) + incrementor = 10, + distance = 3, + frame, + minimum = 10, + subtract = document.querySelector('.subtract'), + add = document.querySelector('.add') + + app.optimize = false + app.count = minimum + app.enableApp = true + + app.init = function () { + if (movers) { + bodySize = document.body.getBoundingClientRect() + for (var i = 0; i < movers.length; i++) { + document.body.removeChild(movers[i]) + } + document.body.appendChild(proto) + ballSize = proto.getBoundingClientRect() + document.body.removeChild(proto) + maxHeight = Math.floor(bodySize.height - ballSize.height) + } + for (var i = 0; i < app.count; i++) { + var m = proto.cloneNode() + var top = Math.floor(Math.random() * maxHeight) + if (top === maxHeight) { + m.classList.add('up') + } else { + m.classList.add('down') + } + m.style.left = i / (app.count / maxWidth) + 'vw' + m.style.top = top + 'px' + document.body.appendChild(m) + } + movers = document.querySelectorAll('.mover') + } + + app.update = function (timestamp) { + for (var i = 0; i < app.count; i++) { + var m = movers[i] + if (!app.optimize) { + var pos = m.classList.contains('down') + ? m.offsetTop + distance + : m.offsetTop - distance + if (pos < 0) pos = 0 + if (pos > maxHeight) pos = maxHeight + m.style.top = pos + 'px' + if (m.offsetTop === 0) { + m.classList.remove('up') + m.classList.add('down') + } + if (m.offsetTop === maxHeight) { + m.classList.remove('down') + m.classList.add('up') + } + } else { + var pos = parseInt(m.style.top.slice(0, m.style.top.indexOf('px'))) + m.classList.contains('down') ? (pos += distance) : (pos -= distance) + if (pos < 0) pos = 0 + if (pos > maxHeight) pos = maxHeight + m.style.top = pos + 'px' + if (pos === 0) { + m.classList.remove('up') + m.classList.add('down') + } + if (pos === maxHeight) { + m.classList.remove('down') + m.classList.add('up') + } + } + } + frame = window.requestAnimationFrame(app.update) + } + + document.querySelector('.stop').addEventListener('click', function (e) { + if (app.enableApp) { + cancelAnimationFrame(frame) + e.target.textContent = 'Start' + app.enableApp = false + } else { + frame = window.requestAnimationFrame(app.update) + e.target.textContent = 'Stop' + app.enableApp = true + } + }) + + document.querySelector('.optimize').addEventListener('click', function (e) { + if (e.target.textContent === 'Optimize') { + app.optimize = true + e.target.textContent = 'Un-Optimize' + } else { + app.optimize = false + e.target.textContent = 'Optimize' + } + }) + + add.addEventListener('click', function (e) { + cancelAnimationFrame(frame) + app.count += incrementor + subtract.disabled = false + app.init() + frame = requestAnimationFrame(app.update) + }) + + subtract.addEventListener('click', function () { + cancelAnimationFrame(frame) + app.count -= incrementor + app.init() + frame = requestAnimationFrame(app.update) + if (app.count === minimum) { + subtract.disabled = true + } + }) + + function debounce(func, wait, immediate) { + var timeout + return function () { + var context = this, + args = arguments + var later = function () { + timeout = null + if (!immediate) func.apply(context, args) + } + var callNow = immediate && !timeout + clearTimeout(timeout) + timeout = setTimeout(later, wait) + if (callNow) func.apply(context, args) + } + } + + var onResize = debounce(function () { + if (app.enableApp) { + cancelAnimationFrame(frame) + app.init() + frame = requestAnimationFrame(app.update) + } + }, 500) + + window.addEventListener('resize', onResize) + + add.textContent = 'Add ' + incrementor + subtract.textContent = 'Subtract ' + incrementor + document.body.removeChild(proto) + proto.classList.remove('.proto') + app.init() + window.app = app + frame = window.requestAnimationFrame(app.update) +})(window) diff --git a/packages/lenis/playground/main.js b/packages/lenis/playground/main.js index 66af9de0..56941815 100644 --- a/packages/lenis/playground/main.js +++ b/packages/lenis/playground/main.js @@ -1,21 +1,80 @@ -import "./style.css" -import javascriptLogo from "./javascript.svg" -import viteLogo from "/vite.svg" -import { setupCounter } from "./counter.js" -import Lenis from "../dist/lenis.esm.js" +import Lenis from '../dist/lenis.esm.js' +import { setupCounter } from './counter.js' +// import './jank.js' +import javascriptLogo from './javascript.svg' +import './style.css' +import viteLogo from '/vite.svg' -const lenis = new Lenis() +const lenis = new Lenis({ + smoothWheel: true, + syncTouch: true, +}) + +window.lenis = lenis function update(deltaTime) { lenis.raf(deltaTime) requestAnimationFrame(update) + + // console.log(window.scrollY, Math.floor(lenis.scroll)) + // if (window.scrollY !== Math.floor(lenis.scroll)) { + // console.log('unsynced', window.scrollY, lenis.scroll) + // } + + // console.log(window.scrollY, lenis.scroll) } requestAnimationFrame((deltaTime) => { update(deltaTime) }) -document.querySelector("#app").innerHTML = ` +document.querySelector('#app').innerHTML = ` +
+
+ + + + + + +

Hello Vite!

+
+ +
+

+ Click on the Vite logo to learn more +

+
+
+ + + + + + +

Hello Vite!

+
+ +
+

+ Click on the Vite logo to learn more +

+
+
+ + + + + + +

Hello Vite!

+
+ +
+

+ Click on the Vite logo to learn more +

+
+
` -setupCounter(document.querySelector("#counter")) +setupCounter(document.querySelector('#counter')) diff --git a/packages/lenis/playground/package.json b/packages/lenis/playground/package.json index 646e0813..ec34743b 100644 --- a/packages/lenis/playground/package.json +++ b/packages/lenis/playground/package.json @@ -4,7 +4,7 @@ "version": "0.0.0", "type": "module", "scripts": { - "dev": "vite", + "dev": "vite --host", "build": "vite build", "preview": "vite preview" }, diff --git a/packages/lenis/playground/style.css b/packages/lenis/playground/style.css index 30aa8141..97fe0dd3 100644 --- a/packages/lenis/playground/style.css +++ b/packages/lenis/playground/style.css @@ -28,6 +28,8 @@ body { place-items: center; min-width: 320px; min-height: 100vh; + height: 300vh; + background-color: red; } h1 { @@ -38,7 +40,7 @@ h1 { #app { max-width: 1280px; margin: 0 auto; - padding: 2rem; + /* padding: 2rem; */ text-align: center; } @@ -94,3 +96,38 @@ button:focus-visible { background-color: #f9f9f9; } } + +.controls { + position: fixed; + inset: 0; + z-index: 1; +} + +.controls button { + display: block; + font-size: 1em; + padding: 1em; + margin: 1em; + background-color: beige; + color: black; +} + +.subtract:disabled { + opacity: 0.2; +} + +.mover { + height: 3vw; + position: absolute; + z-index: 0; +} + +.border { + border: 1px solid black; +} + +@media (max-width: 600px) { + .controls button { + min-width: 20vw; + } +} diff --git a/packages/lenis/src/index.js b/packages/lenis/src/index.js index 840ad861..c777ce65 100644 --- a/packages/lenis/src/index.js +++ b/packages/lenis/src/index.js @@ -33,7 +33,7 @@ export default class Lenis { * @property {boolean} [smoothTouch] * @property {boolean} [syncTouch] * @property {number} [syncTouchLerp] - * @property {number} [__iosNoInertiaSyncTouchLerp] + // * @property {number} [__iosNoInertiaSyncTouchLerp] * @property {number} [touchInertiaMultiplier] * @property {number} [duration] * @property {EasingFunction} [easing] @@ -56,8 +56,8 @@ export default class Lenis { smoothWheel = true, smoothTouch = false, syncTouch = false, - syncTouchLerp = 0.1, - __iosNoInertiaSyncTouchLerp = 0.4, // should be 1 but had to leave 0.4 for iOS (testing purpose) + syncTouchLerp = 0.075, + // __iosNoInertiaSyncTouchLerp = 0.4, // should be 1 but had to leave 0.4 for iOS (testing purpose) touchInertiaMultiplier = 35, duration, // in seconds easing = (t) => Math.min(1, 1.001 - Math.pow(2, -10 * t)), @@ -86,7 +86,7 @@ export default class Lenis { smoothTouch, syncTouch, syncTouchLerp, - __iosNoInertiaSyncTouchLerp, + // __iosNoInertiaSyncTouchLerp, touchInertiaMultiplier, duration, easing, @@ -165,19 +165,32 @@ export default class Lenis { const isTouch = event.type.includes('touch') const isWheel = event.type.includes('wheel') - if ( - (this.options.gestureOrientation === 'both' && - deltaX === 0 && - deltaY === 0) || // "touchend" events prevents "click" - (this.options.gestureOrientation === 'vertical' && deltaY === 0) || // trackpad previous/next page gesture - (this.options.gestureOrientation === 'horizontal' && deltaX === 0) || - (isTouch && - this.options.gestureOrientation === 'vertical' && - this.scroll === 0 && - !this.options.infinite && - deltaY <= 0) // touch pull to refresh - ) + const isTapToStop = + (this.options.smoothTouch || this.options.syncTouch) && + isTouch && + event.type === 'touchstart' + + if (isTapToStop) { + this.reset() return + } + + const isClick = deltaX === 0 && deltaY === 0 // click event + + // const isPullToRefresh = + // this.options.gestureOrientation === 'vertical' && + // this.scroll === 0 && + // !this.options.infinite && + // deltaY <= 5 // touch pull to refresh, not reliable yet + + const isUnknownGesture = + (this.options.gestureOrientation === 'vertical' && deltaY === 0) || + (this.options.gestureOrientation === 'horizontal' && deltaX === 0) + + if (isClick || isUnknownGesture) { + // console.log('prevent') + return + } // catch if scrolling on nested scroll elements let composedPath = event.composedPath() @@ -220,18 +233,24 @@ export default class Lenis { const syncTouch = isTouch && this.options.syncTouch const isTouchEnd = isTouch && event.type === 'touchend' - const hasTouchInertia = isTouchEnd && Math.abs(delta) > 1 + + const hasTouchInertia = isTouchEnd && Math.abs(delta) > 5 + if (hasTouchInertia) { delta = this.velocity * this.options.touchInertiaMultiplier } this.scrollTo(this.targetScroll + delta, { programmatic: false, - ...(syncTouch && { - lerp: hasTouchInertia - ? this.syncTouchLerp - : this.options.__iosNoInertiaSyncTouchLerp, - }), + ...(syncTouch + ? { + lerp: hasTouchInertia ? this.options.syncTouchLerp : 1, + } + : { + lerp: this.options.lerp, + duration: this.options.duration, + easing: this.options.easing, + }), }) } diff --git a/packages/lenis/src/virtual-scroll.js b/packages/lenis/src/virtual-scroll.js index f30c447a..1d8934cd 100644 --- a/packages/lenis/src/virtual-scroll.js +++ b/packages/lenis/src/virtual-scroll.js @@ -66,6 +66,12 @@ export class VirtualScroll { x: 0, y: 0, } + + this.emitter.emit('scroll', { + deltaX: 0, + deltaY: 0, + event, + }) } // Event handler for 'touchmove' event