diff --git a/bundled/lenis.js b/bundled/lenis.js index a0c110fc..2b0a0b09 100644 --- a/bundled/lenis.js +++ b/bundled/lenis.js @@ -1,7 +1,7 @@ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : - (global = global || self, global["'Lenis'"] = factory()); + (global = global || self, global.Lenis = factory()); })(this, (function () { function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { diff --git a/bundled/lenis.min.js b/bundled/lenis.min.js index e0891282..f5685127 100644 --- a/bundled/lenis.min.js +++ b/bundled/lenis.min.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||self)["'Lenis'"]=e()}(this,function(){function t(){return t=Object.assign?Object.assign.bind():function(t){for(var e=1;e({events:{},emit(t,...e){let i=this.events[t]||[];for(let t=0,n=i.length;t{this.events[t]=this.events[t]?.filter(t=>e!==t)}}});function s(t,e,i){return Math.max(t,Math.min(e,i))}var r=/*#__PURE__*/function(){function t(){}var e=t.prototype;return e.advance=function(t){var e;if(this.isRunning){var i;this.value===this.from&&(null==(i=this.onStart)||i.call(this,this.from));var n,o,r=!1;if(this.lerp)this.value=(1-(n=this.lerp))*this.value+n*this.to,Math.round(this.value)===this.to&&(this.value=this.to,r=!0);else{this.currentTime+=t;var l=s(0,this.currentTime/this.duration,1),h=(r=l>=1)?1:this.easing(l);this.value=this.from+(this.to-this.from)*h}null==(e=this.onUpdate)||e.call(this,this.value),r&&(null==(o=this.onComplete)||o.call(this,this.to),this.stop())}},e.stop=function(){this.isRunning=!1},e.fromTo=function(t,e,i){var n=i.lerp,o=void 0===n?.1:n,s=i.duration,r=void 0===s?1:s,l=i.easing,h=void 0===l?function(t){return t}:l,a=i.onStart,u=i.onUpdate,c=i.onComplete;this.from=this.value=t,this.to=e,this.lerp=o,this.duration=r,this.easing=h,this.currentTime=0,this.isRunning=!0,this.onStart=a,this.onUpdate=u,this.onComplete=c},t}(),l=/*#__PURE__*/i("resizeObserver"),h=/*#__PURE__*/i("onResize"),a=/*#__PURE__*/i("onWindowResize"),u=/*#__PURE__*/function(){function t(t){var e=this;Object.defineProperty(this,l,{writable:!0,value:void 0}),Object.defineProperty(this,h,{writable:!0,value:function(t){var i=t[0];if(i){var n=i.contentRect,o=n.height;e.width=n.width,e.height=o}}}),Object.defineProperty(this,a,{writable:!0,value:function(){e.width=window.innerWidth,e.height=window.innerHeight}}),this.element=t,t===window?(window.addEventListener("resize",n(this,a)[a]),n(this,a)[a]()):(this.width=this.element.offsetWidth,this.height=this.element.offsetHeight,n(this,l)[l]=new ResizeObserver(n(this,h)[h]),n(this,l)[l].observe(this.element))}return t.prototype.destroy=function(){window.removeEventListener("resize",this.onWindowResize),n(this,l)[l].disconnect()},t}(),c=/*#__PURE__*/i("wheelMultiplier"),d=/*#__PURE__*/i("touchMultiplier"),v=/*#__PURE__*/i("touchStart"),f=/*#__PURE__*/i("emitter"),p=/*#__PURE__*/i("onTouchStart"),m=/*#__PURE__*/i("onTouchMove"),y=/*#__PURE__*/i("onWheel"),b=/*#__PURE__*/function(){function t(t,e){var i=this,s=e.wheelMultiplier,r=void 0===s?1:s,l=e.touchMultiplier,h=void 0===l?2:l;Object.defineProperty(this,c,{writable:!0,value:void 0}),Object.defineProperty(this,d,{writable:!0,value:void 0}),Object.defineProperty(this,v,{writable:!0,value:void 0}),Object.defineProperty(this,f,{writable:!0,value:void 0}),Object.defineProperty(this,p,{writable:!0,value:function(t){var e=t.targetTouches?t.targetTouches[0]:t,o=e.pageX,s=e.pageY;n(i,v)[v].x=o,n(i,v)[v].y=s}}),Object.defineProperty(this,m,{writable:!0,value:function(t){var e=t.targetTouches?t.targetTouches[0]:t,o=e.pageX,s=e.pageY,r=-(o-n(i,v)[v].x)*n(i,d)[d],l=-(s-n(i,v)[v].y)*n(i,d)[d];n(i,v)[v].x=o,n(i,v)[v].y=s,n(i,f)[f].emit("scroll",{type:"touch",deltaX:r,deltaY:l,event:t})}}),Object.defineProperty(this,y,{writable:!0,value:function(t){var e=t.deltaX,o=t.deltaY;e*=n(i,c)[c],o*=n(i,c)[c],n(i,f)[f].emit("scroll",{type:"wheel",deltaX:e,deltaY:o,event:t})}}),this.element=t,n(this,c)[c]=r,n(this,d)[d]=h,n(this,v)[v]={x:null,y:null},n(this,f)[f]=o(),this.element.addEventListener("wheel",n(this,y)[y],{passive:!1}),this.element.addEventListener("touchstart",n(this,p)[p],{passive:!1}),this.element.addEventListener("touchmove",n(this,m)[m],{passive:!1})}var e=t.prototype;return e.on=function(t,e){return n(this,f)[f].on(t,e)},e.destroy=function(){n(this,f)[f].events={},this.element.removeEventListener("wheel",n(this,y)[y],{passive:!1}),this.element.removeEventListener("touchstart",n(this,p)[p],{passive:!1}),this.element.removeEventListener("touchmove",n(this,m)[m],{passive:!1})},t}(),w=/*#__PURE__*/i("options"),g=/*#__PURE__*/i("wrapper"),O=/*#__PURE__*/i("content"),j=/*#__PURE__*/i("animate"),P=/*#__PURE__*/i("emitter"),S=/*#__PURE__*/i("virtualScroll"),T=/*#__PURE__*/i("time"),M=/*#__PURE__*/i("velocity"),L=/*#__PURE__*/i("direction"),z=/*#__PURE__*/i("animatedScroll"),E=/*#__PURE__*/i("targetScroll"),k=/*#__PURE__*/i("isScrolling"),R=/*#__PURE__*/i("isStopped"),W=/*#__PURE__*/i("isLocked"),x=/*#__PURE__*/i("isSmooth"),C=/*#__PURE__*/i("setScroll"),H=/*#__PURE__*/i("onVirtualScroll"),X=/*#__PURE__*/i("onScroll"),Y=/*#__PURE__*/i("classElement"),U=/*#__PURE__*/i("actualScroll");function _(t){n(this,w)[w].infinite&&(t=this.scroll),this.isHorizontal?n(this,Y)[Y].scrollLeft=t:n(this,Y)[Y].scrollTop=t}function A(){return n(this,g)[g].element===window?n(this,O)[O].element:n(this,g)[g].element}function D(){return n(this,Y)[Y].scrollTop}/*#__PURE__*/ +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t||self).Lenis=e()}(this,function(){function t(){return t=Object.assign?Object.assign.bind():function(t){for(var e=1;e({events:{},emit(t,...e){let i=this.events[t]||[];for(let t=0,n=i.length;t{this.events[t]=this.events[t]?.filter(t=>e!==t)}}});function s(t,e,i){return Math.max(t,Math.min(e,i))}var r=/*#__PURE__*/function(){function t(){}var e=t.prototype;return e.advance=function(t){var e;if(this.isRunning){var i;this.value===this.from&&(null==(i=this.onStart)||i.call(this,this.from));var n,o,r=!1;if(this.lerp)this.value=(1-(n=this.lerp))*this.value+n*this.to,Math.round(this.value)===this.to&&(this.value=this.to,r=!0);else{this.currentTime+=t;var l=s(0,this.currentTime/this.duration,1),h=(r=l>=1)?1:this.easing(l);this.value=this.from+(this.to-this.from)*h}null==(e=this.onUpdate)||e.call(this,this.value),r&&(null==(o=this.onComplete)||o.call(this,this.to),this.stop())}},e.stop=function(){this.isRunning=!1},e.fromTo=function(t,e,i){var n=i.lerp,o=void 0===n?.1:n,s=i.duration,r=void 0===s?1:s,l=i.easing,h=void 0===l?function(t){return t}:l,a=i.onStart,u=i.onUpdate,c=i.onComplete;this.from=this.value=t,this.to=e,this.lerp=o,this.duration=r,this.easing=h,this.currentTime=0,this.isRunning=!0,this.onStart=a,this.onUpdate=u,this.onComplete=c},t}(),l=/*#__PURE__*/i("resizeObserver"),h=/*#__PURE__*/i("onResize"),a=/*#__PURE__*/i("onWindowResize"),u=/*#__PURE__*/function(){function t(t){var e=this;Object.defineProperty(this,l,{writable:!0,value:void 0}),Object.defineProperty(this,h,{writable:!0,value:function(t){var i=t[0];if(i){var n=i.contentRect,o=n.height;e.width=n.width,e.height=o}}}),Object.defineProperty(this,a,{writable:!0,value:function(){e.width=window.innerWidth,e.height=window.innerHeight}}),this.element=t,t===window?(window.addEventListener("resize",n(this,a)[a]),n(this,a)[a]()):(this.width=this.element.offsetWidth,this.height=this.element.offsetHeight,n(this,l)[l]=new ResizeObserver(n(this,h)[h]),n(this,l)[l].observe(this.element))}return t.prototype.destroy=function(){window.removeEventListener("resize",this.onWindowResize),n(this,l)[l].disconnect()},t}(),c=/*#__PURE__*/i("wheelMultiplier"),d=/*#__PURE__*/i("touchMultiplier"),v=/*#__PURE__*/i("touchStart"),f=/*#__PURE__*/i("emitter"),p=/*#__PURE__*/i("onTouchStart"),m=/*#__PURE__*/i("onTouchMove"),y=/*#__PURE__*/i("onWheel"),b=/*#__PURE__*/function(){function t(t,e){var i=this,s=e.wheelMultiplier,r=void 0===s?1:s,l=e.touchMultiplier,h=void 0===l?2:l;Object.defineProperty(this,c,{writable:!0,value:void 0}),Object.defineProperty(this,d,{writable:!0,value:void 0}),Object.defineProperty(this,v,{writable:!0,value:void 0}),Object.defineProperty(this,f,{writable:!0,value:void 0}),Object.defineProperty(this,p,{writable:!0,value:function(t){var e=t.targetTouches?t.targetTouches[0]:t,o=e.pageX,s=e.pageY;n(i,v)[v].x=o,n(i,v)[v].y=s}}),Object.defineProperty(this,m,{writable:!0,value:function(t){var e=t.targetTouches?t.targetTouches[0]:t,o=e.pageX,s=e.pageY,r=-(o-n(i,v)[v].x)*n(i,d)[d],l=-(s-n(i,v)[v].y)*n(i,d)[d];n(i,v)[v].x=o,n(i,v)[v].y=s,n(i,f)[f].emit("scroll",{type:"touch",deltaX:r,deltaY:l,event:t})}}),Object.defineProperty(this,y,{writable:!0,value:function(t){var e=t.deltaX,o=t.deltaY;e*=n(i,c)[c],o*=n(i,c)[c],n(i,f)[f].emit("scroll",{type:"wheel",deltaX:e,deltaY:o,event:t})}}),this.element=t,n(this,c)[c]=r,n(this,d)[d]=h,n(this,v)[v]={x:null,y:null},n(this,f)[f]=o(),this.element.addEventListener("wheel",n(this,y)[y],{passive:!1}),this.element.addEventListener("touchstart",n(this,p)[p],{passive:!1}),this.element.addEventListener("touchmove",n(this,m)[m],{passive:!1})}var e=t.prototype;return e.on=function(t,e){return n(this,f)[f].on(t,e)},e.destroy=function(){n(this,f)[f].events={},this.element.removeEventListener("wheel",n(this,y)[y],{passive:!1}),this.element.removeEventListener("touchstart",n(this,p)[p],{passive:!1}),this.element.removeEventListener("touchmove",n(this,m)[m],{passive:!1})},t}(),w=/*#__PURE__*/i("options"),g=/*#__PURE__*/i("wrapper"),O=/*#__PURE__*/i("content"),j=/*#__PURE__*/i("animate"),P=/*#__PURE__*/i("emitter"),S=/*#__PURE__*/i("virtualScroll"),T=/*#__PURE__*/i("time"),M=/*#__PURE__*/i("velocity"),L=/*#__PURE__*/i("direction"),z=/*#__PURE__*/i("animatedScroll"),E=/*#__PURE__*/i("targetScroll"),k=/*#__PURE__*/i("isScrolling"),R=/*#__PURE__*/i("isStopped"),W=/*#__PURE__*/i("isLocked"),x=/*#__PURE__*/i("isSmooth"),C=/*#__PURE__*/i("setScroll"),H=/*#__PURE__*/i("onVirtualScroll"),X=/*#__PURE__*/i("onScroll"),Y=/*#__PURE__*/i("classElement"),U=/*#__PURE__*/i("actualScroll");function _(t){n(this,w)[w].infinite&&(t=this.scroll),this.isHorizontal?n(this,Y)[Y].scrollLeft=t:n(this,Y)[Y].scrollTop=t}function A(){return n(this,g)[g].element===window?n(this,O)[O].element:n(this,g)[g].element}function D(){return n(this,Y)[Y].scrollTop}/*#__PURE__*/ return function(){function e(t){var e=this,i=void 0===t?{}:t,s=i.direction,l=i.gestureDirection,h=i.mouseMultiplier,a=i.smooth,c=i.wrapper,d=void 0===c?window:c,v=i.content,f=void 0===v?document.documentElement:v,p=i.smoothWheel,m=void 0===p?null==a||a:p,y=i.smoothTouch,q=void 0!==y&&y,B=i.duration,V=i.easing,F=void 0===V?function(t){return Math.min(1,1.001-Math.pow(2,-10*t))}:V,K=i.lerp,G=void 0===K?B?null:.1:K,I=i.infinite,J=void 0!==I&&I,N=i.orientation,Q=void 0===N?null!=s?s:"vertical":N,Z=i.gestureOrientation,$=void 0===Z?null!=l?l:"vertical":Z,tt=i.touchMultiplier,et=void 0===tt?2:tt,it=i.wheelMultiplier,nt=void 0===it?null!=h?h:1:it;Object.defineProperty(this,U,{get:D,set:void 0}),Object.defineProperty(this,Y,{get:A,set:void 0}),Object.defineProperty(this,C,{value:_}),Object.defineProperty(this,w,{writable:!0,value:void 0}),Object.defineProperty(this,g,{writable:!0,value:void 0}),Object.defineProperty(this,O,{writable:!0,value:void 0}),Object.defineProperty(this,j,{writable:!0,value:void 0}),Object.defineProperty(this,P,{writable:!0,value:void 0}),Object.defineProperty(this,S,{writable:!0,value:void 0}),Object.defineProperty(this,T,{writable:!0,value:void 0}),Object.defineProperty(this,M,{writable:!0,value:void 0}),Object.defineProperty(this,L,{writable:!0,value:void 0}),Object.defineProperty(this,z,{writable:!0,value:void 0}),Object.defineProperty(this,E,{writable:!0,value:void 0}),Object.defineProperty(this,k,{writable:!0,value:void 0}),Object.defineProperty(this,R,{writable:!0,value:void 0}),Object.defineProperty(this,W,{writable:!0,value:void 0}),Object.defineProperty(this,x,{writable:!0,value:void 0}),Object.defineProperty(this,H,{writable:!0,value:function(t){var i=t.type,o=t.deltaX,s=t.deltaY,r=t.event;if(!r.ctrlKey&&!("vertical"===n(e,w)[w].gestureOrientation&&0===s||"horizontal"===n(e,w)[w].gestureOrientation&&0===o||r.composedPath().find(function(t){return null==t||null==t.hasAttribute?void 0:t.hasAttribute("data-lenis-prevent")})))if(e.isStopped||n(e,W)[W])r.preventDefault();else if(e.isSmooth=n(e,w)[w].smoothTouch&&"touch"===i||n(e,w)[w].smoothWheel&&"wheel"===i,e.isSmooth){r.preventDefault();var l=s;"both"===n(e,w)[w].gestureOrientation?l=o+s:"horizontal"===n(e,w)[w].gestureOrientation&&(l=o),e.scrollTo(n(e,E)[E]+l,{},!1)}}}),Object.defineProperty(this,X,{writable:!0,value:function(){e.isScrolling||(n(e,z)[z]=n(e,E)[E]=n(e,U)[U],e.velocity=0,e.emit())}}),window.lenisVersion="1.0.0-dev.1",d!==document.documentElement&&d!==document.body||(d=window),n(this,w)[w]={wrapper:d,content:f,smoothWheel:m,smoothTouch:q,duration:B,easing:F,lerp:G,infinite:J,gestureOrientation:$,orientation:Q,touchMultiplier:et,wheelMultiplier:nt},n(this,g)[g]=new u(d),n(this,O)[O]=new u(f),n(this,Y)[Y].classList.add("lenis"),this.velocity=0,this.isStopped=!1,this.isSmooth=m||q,this.isScrolling=!1,n(this,E)[E]=n(this,z)[z]=n(this,U)[U],n(this,j)[j]=new r,n(this,P)[P]=o(),n(this,g)[g].element.addEventListener("scroll",n(this,X)[X],{passive:!1}),n(this,S)[S]=new b(d,{touchMultiplier:et,wheelMultiplier:nt}),n(this,S)[S].on("scroll",n(this,H)[H])}var i,l,h=e.prototype;return h.destroy=function(){n(this,P)[P].events={},n(this,g)[g].element.removeEventListener("scroll",n(this,X)[X],{passive:!1}),n(this,S)[S].destroy()},h.on=function(t,e){return n(this,P)[P].on(t,e)},h.emit=function(){n(this,P)[P].emit("scroll",this)},h.start=function(){this.isStopped=!1},h.stop=function(){this.isStopped=!0},h.raf=function(t){var e=t-(n(this,T)[T]||t);n(this,T)[T]=t,n(this,j)[j].advance(.001*e)},h.scrollTo=function(t,e,i){var o=this,r=void 0===e?{}:e,l=r.offset,h=void 0===l?0:l,a=r.immediate,u=void 0!==a&&a,c=r.lock,d=void 0!==c&&c,v=r.duration,f=void 0===v?n(this,w)[w].duration:v,p=r.easing,m=void 0===p?n(this,w)[w].easing:p,y=r.lerp,b=void 0===y?n(this,w)[w].lerp:y,O=r.onComplete;if(void 0===i&&(i=!0),["top","left","start"].includes(t))t=0;else if(["bottom","right","end"].includes(t))t=this.limit;else{var P,S;if("string"==typeof t?S=document.querySelector(t):null!=(P=t)&&P.nodeType&&(S=t),S){if(n(this,g)[g].element!==window){var T=n(this,g)[g].element.getBoundingClientRect();h-=this.isHorizontal?T.left:T.top}var M=S.getBoundingClientRect();t=(this.isHorizontal?M.left:M.top)+n(this,z)[z]}}if("number"==typeof t)if(t+=h,n(this,w)[w].infinite?i&&(n(this,E)[E]=n(this,z)[z]=this.scroll):t=s(0,t,this.limit),n(this,z)[z]!==t){if(u)return n(this,z)[z]=n(this,E)[E]=t,n(this,C)[C](t),this.emit(),void(null==O||O());i||(n(this,E)[E]=t),n(this,j)[j].fromTo(n(this,z)[z],t,{duration:f,easing:m,lerp:b,onStart:function(){d&&(n(o,W)[W]=!0),o.isScrolling=!0},onUpdate:function(t){o.velocity=t-n(o,z)[z],n(o,z)[z]=t,n(o,C)[C](t),i&&(n(o,E)[E]=t),o.emit()},onComplete:function(t){d&&(n(o,W)[W]=!1),requestAnimationFrame(function(){o.isScrolling=!1}),o.velocity=0,o.emit(),null==O||O()}})}else null==O||O()},i=e,(l=[{key:"options",get:function(){return t({},n(this,w)[w])}},{key:"limit",get:function(){return this.isHorizontal?n(this,O)[O].width-n(this,g)[g].width:n(this,O)[O].height-n(this,g)[g].height}},{key:"isHorizontal",get:function(){return"horizontal"===n(this,w)[w].orientation}},{key:"scroll",get:function(){return e=n(this,z)[z]%(t=this.limit),(t>0&&e<0||t<0&&e>0)&&(e+=t),e;var t,e}},{key:"progress",get:function(){return this.scroll/this.limit}},{key:"velocity",get:function(){return n(this,M)[M]},set:function(t){n(this,M)[M]=t,0!==t&&(n(this,L)[L]=Math.sign(t))}},{key:"direction",get:function(){return n(this,L)[L]}},{key:"isSmooth",get:function(){return n(this,x)[x]},set:function(t){n(this,x)[x]=t,n(this,Y)[Y].classList.toggle("lenis-smooth",t)}},{key:"isScrolling",get:function(){return n(this,k)[k]},set:function(t){n(this,k)[k]=t,n(this,Y)[Y].classList.toggle("lenis-scrolling",t)}},{key:"isStopped",get:function(){return n(this,R)[R]},set:function(t){n(this,R)[R]=t,n(this,Y)[Y].classList.toggle("lenis-stopped",t)}}])&&function(t,e){for(var i=0;i