From 55580f6c8eebd9c9aba07e5f03886abd1cf345a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Roche?= Date: Tue, 11 Oct 2022 14:22:14 +0200 Subject: [PATCH] v0.2.10 --- bundled/lenis.js | 4 ++-- dist/lenis.js | 2 +- dist/lenis.js.map | 2 +- dist/lenis.mjs | 2 +- dist/lenis.mjs.map | 2 +- dist/lenis.modern.mjs | 2 +- dist/lenis.modern.mjs.map | 2 +- dist/lenis.umd.js | 4 ++-- dist/lenis.umd.js.map | 2 +- package.json | 2 +- 10 files changed, 12 insertions(+), 12 deletions(-) diff --git a/bundled/lenis.js b/bundled/lenis.js index 6232a51c..46535b8b 100644 --- a/bundled/lenis.js +++ b/bundled/lenis.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(t,e){for(var i=0;i1,hasPointer:!!window.navigator.msPointerEnabled,hasKeyDown:"onkeydown"in document,isFirefox:navigator.userAgent.indexOf("Firefox")>-1}),i(this,l)[l]=Object.assign({mouseMultiplier:1,touchMultiplier:2,firefoxMultiplier:15,keyStep:120,preventTouch:!1,unpreventTouchClass:"vs-touchmove-allowed",useKeyboard:!0,useTouch:!0},t),i(this,a)[a]=new n,i(this,c)[c]={y:0,x:0,deltaX:0,deltaY:0},i(this,u)[u]={x:null,y:null},i(this,d)[d]=null,void 0!==i(this,l)[l].passive&&(this.listenerOptions={passive:i(this,l)[l].passive})}var e=t.prototype;return e._notify=function(t){var e=i(this,c)[c];e.x+=e.deltaX,e.y+=e.deltaY,i(this,a)[a].emit(s,{x:e.x,y:e.y,deltaX:e.deltaX,deltaY:e.deltaY,originalEvent:t})},e._bind=function(){r.hasWheelEvent&&i(this,h)[h].addEventListener("wheel",this._onWheel,this.listenerOptions),r.hasMouseWheelEvent&&i(this,h)[h].addEventListener("mousewheel",this._onMouseWheel,this.listenerOptions),r.hasTouch&&i(this,l)[l].useTouch&&(i(this,h)[h].addEventListener("touchstart",this._onTouchStart,this.listenerOptions),i(this,h)[h].addEventListener("touchmove",this._onTouchMove,this.listenerOptions)),r.hasPointer&&r.hasTouchWin&&(i(this,d)[d]=document.body.style.msTouchAction,document.body.style.msTouchAction="none",i(this,h)[h].addEventListener("MSPointerDown",this._onTouchStart,!0),i(this,h)[h].addEventListener("MSPointerMove",this._onTouchMove,!0)),r.hasKeyDown&&i(this,l)[l].useKeyboard&&document.addEventListener("keydown",this._onKeyDown)},e._unbind=function(){r.hasWheelEvent&&i(this,h)[h].removeEventListener("wheel",this._onWheel),r.hasMouseWheelEvent&&i(this,h)[h].removeEventListener("mousewheel",this._onMouseWheel),r.hasTouch&&(i(this,h)[h].removeEventListener("touchstart",this._onTouchStart),i(this,h)[h].removeEventListener("touchmove",this._onTouchMove)),r.hasPointer&&r.hasTouchWin&&(document.body.style.msTouchAction=i(this,d)[d],i(this,h)[h].removeEventListener("MSPointerDown",this._onTouchStart,!0),i(this,h)[h].removeEventListener("MSPointerMove",this._onTouchMove,!0)),r.hasKeyDown&&i(this,l)[l].useKeyboard&&document.removeEventListener("keydown",this._onKeyDown)},e.on=function(t,e){i(this,a)[a].on(s,t,e);var o=i(this,a)[a].e;o&&o[s]&&1===o[s].length&&this._bind()},e.off=function(t,e){i(this,a)[a].off(s,t,e);var o=i(this,a)[a].e;(!o[s]||o[s].length<=0)&&this._unbind()},e.destroy=function(){i(this,a)[a].off(),this._unbind()},t}()}()}(e),e.exports}();function l(t,e,i){return Math.max(t,Math.min(e,i))}var h=["duration","easing"],a=/*#__PURE__*/function(){function t(){}var o=t.prototype;return o.to=function(t,e){var o=this,n=void 0===e?{}:e,r=n.duration,s=void 0===r?1:r,l=n.easing,a=void 0===l?function(t){return t}:l,c=function(t,e){if(null==t)return{};var i,o,n={},r=Object.keys(t);for(o=0;o=0||(n[i]=t[i]);return n}(n,h);this.target=t,this.fromKeys=i({},c),this.toKeys=i({},c),this.keys=Object.keys(i({},c)),this.keys.forEach(function(e){o.fromKeys[e]=t[e]}),this.duration=s,this.easing=a,this.currentTime=0,this.isRunning=!0},o.stop=function(){this.isRunning=!1},o.raf=function(t){var e=this;if(this.isRunning){this.currentTime=Math.min(this.currentTime+t,this.duration);var i=this.easing(this.progress);this.keys.forEach(function(t){var o=e.fromKeys[t];e.target[t]=o+(e.toKeys[t]-o)*i}),1===i&&this.stop()}},e(t,[{key:"progress",get:function(){return this.currentTime/this.duration}}]),t}();/*#__PURE__*/ -return function(t){var i,n;function r(e){var i,o,n,r,h=void 0===e?{}:e,c=h.duration,u=void 0===c?1.2:c,d=h.easing,p=void 0===d?function(t){return 1===t?1:1-Math.pow(2,-10*t)}:d,f=h.smooth,v=void 0===f||f,y=h.smoothTouch,w=void 0!==y&&y,g=h.touchMultiplier,m=void 0===g?2:g,b=h.direction,T=void 0===b?"vertical":b,S=h.gestureDirection,_=void 0===S?"vertical":S,M=h.wrapper,O=void 0===M?window:M,E=h.content,W=void 0===E?document.body:E;(r=t.call(this)||this).onWindowResize=function(){r.wrapperWidth=window.innerWidth,r.wrapperHeight=window.innerHeight},r.onWrapperResize=function(t){var e=t[0];if(e){var i=e.contentRect;r.wrapperWidth=i.width,r.wrapperHeight=i.height}},r.onContentResize=function(t){var e=t[0];if(e){var i=e.contentRect;r.contentWidth=i.width,r.contentHeight=i.height}},r.onVirtualScroll=function(t){var e=t.deltaY,i=t.deltaX,o=t.originalEvent;o.ctrlKey||(r.smooth=o.changedTouches?r.smoothTouch:r.options.smooth,r.stopped?o.preventDefault():r.smooth&&4!==o.buttons&&(r.smooth&&o.preventDefault(),r.targetScroll-="both"===r.gestureDirection?i+e:"horizontal"===r.gestureDirection?i:e,r.targetScroll=l(0,r.targetScroll,r.limit),r.scrollTo(r.targetScroll)))},r.onScroll=function(t){r.isScrolling&&r.smooth||(r.targetScroll=r.scroll=r.lastScroll=r.wrapperNode[r.scrollProperty],r.notify())},window.lenisVersion="0.2.9",r.options={duration:u,easing:p,smooth:v,smoothTouch:w,touchMultiplier:m,direction:T,gestureDirection:_,wrapper:O,content:W},r.duration=u,r.easing=p,r.smooth=v,r.smoothTouch=w,r.touchMultiplier=m,r.direction=T,r.gestureDirection=_,r.wrapperNode=O,r.contentNode=W,r.wrapperNode.addEventListener("scroll",r.onScroll),r.wrapperNode===window?(r.wrapperNode.addEventListener("resize",r.onWindowResize),r.onWindowResize()):(r.wrapperHeight=r.wrapperNode.offsetHeight,r.wrapperWidth=r.wrapperNode.offsetWidth,r.wrapperObserver=new ResizeObserver(r.onWrapperResize),r.wrapperObserver.observe(r.wrapperNode)),r.contentHeight=r.contentNode.offsetHeight,r.contentWidth=r.contentNode.offsetWidth,r.contentObserver=new ResizeObserver(r.onContentResize),r.contentObserver.observe(r.contentNode),r.targetScroll=r.scroll=r.lastScroll=r.wrapperNode[r.scrollProperty],r.animate=new a;var x=(null==(i=navigator)||null==(o=i.userAgentData)?void 0:o.platform)||(null==(n=navigator)?void 0:n.platform)||"unknown";return r.virtualScroll=new s({el:r.wrapperNode,firefoxMultiplier:50,mouseMultiplier:x.includes("Win")?1:.4,useKeyboard:!1,touchMultiplier:r.touchMultiplier,useTouch:!0,passive:!1}),r.virtualScroll.on(r.onVirtualScroll),r}n=t,(i=r).prototype=Object.create(n.prototype),i.prototype.constructor=i,o(i,n);var h=r.prototype;return h.start=function(){this.stopped=!1},h.stop=function(){this.stopped=!0,this.animate.stop()},h.destroy=function(){var t;this.wrapperNode===window&&this.wrapperNode.removeEventListener("resize",this.onWindowResize),this.wrapperNode.removeEventListener("scroll",this.onScroll),this.virtualScroll.destroy(),null==(t=this.wrapperObserver)||t.disconnect(),this.contentObserver.disconnect()},h.raf=function(t){var e=t-(this.now||0);this.now=t,!this.stopped&&this.smooth&&(this.lastScroll=this.scroll,this.animate.raf(.001*e),this.scroll===this.targetScroll&&(this.lastScroll=this.scroll),this.isScrolling&&(this.setScroll(this.scroll),this.notify()),this.isScrolling=this.scroll!==this.targetScroll)},h.setScroll=function(t){"horizontal"===this.direction?this.wrapperNode.scrollTo(t,0):this.wrapperNode.scrollTo(0,t)},h.notify=function(){this.emit("scroll",{scroll:this.scroll,limit:this.limit,velocity:this.velocity,direction:this.direction,progress:this.scroll/this.limit})},h.scrollTo=function(t,e){var i=void 0===e?{}:e,o=i.offset,n=void 0===o?0:o,r=i.immediate,s=void 0!==r&&r,h=i.duration,a=void 0===h?this.duration:h,c=i.easing,u=void 0===c?this.easing:c;if(null!=t){var d;if("number"==typeof t)d=t;else if("top"===t||"#top"===t)d=0;else if("bottom"===t)d=this.limit;else{var p;if("string"==typeof t)p=document.querySelector(t);else{if(null==t||!t.nodeType)return;p=t}if(!p)return;var f=0;if(this.wrapperNode!==window){var v=this.wrapperNode.getBoundingClientRect();f="horizontal"===this.direction?v.left:v.top}var y=p.getBoundingClientRect();d=("horizontal"===this.direction?y.left:y.top)+this.scroll-f}this.targetScroll=l(0,d+=n,this.limit),!this.smooth||s?this.setScroll(this.targetScroll):this.animate.to(this,{duration:a,easing:u,scroll:this.targetScroll})}},e(r,[{key:"scrollProperty",get:function(){return this.wrapperNode===window?"horizontal"===this.direction?"scrollX":"scrollY":"horizontal"===this.direction?"scrollLeft":"scrollTop"}},{key:"limit",get:function(){return"horizontal"===this.direction?this.contentWidth-this.wrapperWidth:this.contentHeight-this.wrapperHeight}},{key:"velocity",get:function(){return this.scroll-this.lastScroll}}]),r}(r)}); +!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(t,e){for(var i=0;i1,hasPointer:!!window.navigator.msPointerEnabled,hasKeyDown:"onkeydown"in document,isFirefox:navigator.userAgent.indexOf("Firefox")>-1}),i(this,l)[l]=Object.assign({mouseMultiplier:1,touchMultiplier:2,firefoxMultiplier:15,keyStep:120,preventTouch:!1,unpreventTouchClass:"vs-touchmove-allowed",useKeyboard:!0,useTouch:!0},t),i(this,a)[a]=new n,i(this,c)[c]={y:0,x:0,deltaX:0,deltaY:0},i(this,u)[u]={x:null,y:null},i(this,d)[d]=null,void 0!==i(this,l)[l].passive&&(this.listenerOptions={passive:i(this,l)[l].passive})}var e=t.prototype;return e._notify=function(t){var e=i(this,c)[c];e.x+=e.deltaX,e.y+=e.deltaY,i(this,a)[a].emit(s,{x:e.x,y:e.y,deltaX:e.deltaX,deltaY:e.deltaY,originalEvent:t})},e._bind=function(){r.hasWheelEvent&&i(this,h)[h].addEventListener("wheel",this._onWheel,this.listenerOptions),r.hasMouseWheelEvent&&i(this,h)[h].addEventListener("mousewheel",this._onMouseWheel,this.listenerOptions),r.hasTouch&&i(this,l)[l].useTouch&&(i(this,h)[h].addEventListener("touchstart",this._onTouchStart,this.listenerOptions),i(this,h)[h].addEventListener("touchmove",this._onTouchMove,this.listenerOptions)),r.hasPointer&&r.hasTouchWin&&(i(this,d)[d]=document.body.style.msTouchAction,document.body.style.msTouchAction="none",i(this,h)[h].addEventListener("MSPointerDown",this._onTouchStart,!0),i(this,h)[h].addEventListener("MSPointerMove",this._onTouchMove,!0)),r.hasKeyDown&&i(this,l)[l].useKeyboard&&document.addEventListener("keydown",this._onKeyDown)},e._unbind=function(){r.hasWheelEvent&&i(this,h)[h].removeEventListener("wheel",this._onWheel),r.hasMouseWheelEvent&&i(this,h)[h].removeEventListener("mousewheel",this._onMouseWheel),r.hasTouch&&(i(this,h)[h].removeEventListener("touchstart",this._onTouchStart),i(this,h)[h].removeEventListener("touchmove",this._onTouchMove)),r.hasPointer&&r.hasTouchWin&&(document.body.style.msTouchAction=i(this,d)[d],i(this,h)[h].removeEventListener("MSPointerDown",this._onTouchStart,!0),i(this,h)[h].removeEventListener("MSPointerMove",this._onTouchMove,!0)),r.hasKeyDown&&i(this,l)[l].useKeyboard&&document.removeEventListener("keydown",this._onKeyDown)},e.on=function(t,e){i(this,a)[a].on(s,t,e);var o=i(this,a)[a].e;o&&o[s]&&1===o[s].length&&this._bind()},e.off=function(t,e){i(this,a)[a].off(s,t,e);var o=i(this,a)[a].e;(!o[s]||o[s].length<=0)&&this._unbind()},e.destroy=function(){i(this,a)[a].off(),this._unbind()},t}()}()}(e),e.exports}();function l(t,e,i){return Math.max(t,Math.min(e,i))}var h=["duration","easing"],a=/*#__PURE__*/function(){function t(){}var o=t.prototype;return o.to=function(t,e){var o=this,n=void 0===e?{}:e,r=n.duration,s=void 0===r?1:r,l=n.easing,a=void 0===l?function(t){return t}:l,c=function(t,e){if(null==t)return{};var i,o,n={},r=Object.keys(t);for(o=0;o=0||(n[i]=t[i]);return n}(n,h);this.target=t,this.fromKeys=i({},c),this.toKeys=i({},c),this.keys=Object.keys(i({},c)),this.keys.forEach(function(e){o.fromKeys[e]=t[e]}),this.duration=s,this.easing=a,this.currentTime=0,this.isRunning=!0},o.stop=function(){this.isRunning=!1},o.raf=function(t){var e=this;if(this.isRunning){this.currentTime=Math.min(this.currentTime+t,this.duration);var i=this.easing(this.progress);this.keys.forEach(function(t){var o=e.fromKeys[t];e.target[t]=o+(e.toKeys[t]-o)*i}),1===i&&this.stop()}},e(t,[{key:"progress",get:function(){return this.currentTime/this.duration}}]),t}();/*#__PURE__*/ +return function(t){var i,n;function r(e){var i,o,n,r,h=void 0===e?{}:e,c=h.duration,u=void 0===c?1.2:c,d=h.easing,p=void 0===d?function(t){return 1===t?1:1-Math.pow(2,-10*t)}:d,f=h.smooth,v=void 0===f||f,y=h.smoothTouch,w=void 0!==y&&y,g=h.touchMultiplier,m=void 0===g?2:g,b=h.direction,T=void 0===b?"vertical":b,S=h.gestureDirection,_=void 0===S?"vertical":S,M=h.wrapper,O=void 0===M?window:M,E=h.content,W=void 0===E?document.body:E;(r=t.call(this)||this).onWindowResize=function(){r.wrapperWidth=window.innerWidth,r.wrapperHeight=window.innerHeight},r.onWrapperResize=function(t){var e=t[0];if(e){var i=e.contentRect;r.wrapperWidth=i.width,r.wrapperHeight=i.height}},r.onContentResize=function(t){var e=t[0];if(e){var i=e.contentRect;r.contentWidth=i.width,r.contentHeight=i.height}},r.onVirtualScroll=function(t){var e=t.deltaY,i=t.deltaX,o=t.originalEvent;o.ctrlKey||(r.smooth=o.changedTouches?r.smoothTouch:r.options.smooth,r.stopped?o.preventDefault():r.smooth&&4!==o.buttons&&(r.smooth&&o.preventDefault(),r.targetScroll-="both"===r.gestureDirection?i+e:"horizontal"===r.gestureDirection?i:e,r.targetScroll=l(0,r.targetScroll,r.limit),r.scrollTo(r.targetScroll)))},r.onScroll=function(t){r.isScrolling&&r.smooth||(r.targetScroll=r.scroll=r.lastScroll=r.wrapperNode[r.scrollProperty],r.notify())},window.lenisVersion="0.2.10",r.options={duration:u,easing:p,smooth:v,smoothTouch:w,touchMultiplier:m,direction:T,gestureDirection:_,wrapper:O,content:W},r.duration=u,r.easing=p,r.smooth=v,r.smoothTouch=w,r.touchMultiplier=m,r.direction=T,r.gestureDirection=_,r.wrapperNode=O,r.contentNode=W,r.wrapperNode.addEventListener("scroll",r.onScroll),r.wrapperNode===window?(r.wrapperNode.addEventListener("resize",r.onWindowResize),r.onWindowResize()):(r.wrapperHeight=r.wrapperNode.offsetHeight,r.wrapperWidth=r.wrapperNode.offsetWidth,r.wrapperObserver=new ResizeObserver(r.onWrapperResize),r.wrapperObserver.observe(r.wrapperNode)),r.contentHeight=r.contentNode.offsetHeight,r.contentWidth=r.contentNode.offsetWidth,r.contentObserver=new ResizeObserver(r.onContentResize),r.contentObserver.observe(r.contentNode),r.targetScroll=r.scroll=r.lastScroll=r.wrapperNode[r.scrollProperty],r.animate=new a;var x=(null==(i=navigator)||null==(o=i.userAgentData)?void 0:o.platform)||(null==(n=navigator)?void 0:n.platform)||"unknown";return r.virtualScroll=new s({el:r.wrapperNode,firefoxMultiplier:50,mouseMultiplier:x.includes("Win")?1:.4,useKeyboard:!1,touchMultiplier:r.touchMultiplier,useTouch:!0,passive:!1}),r.virtualScroll.on(r.onVirtualScroll),r}n=t,(i=r).prototype=Object.create(n.prototype),i.prototype.constructor=i,o(i,n);var h=r.prototype;return h.start=function(){this.stopped=!1},h.stop=function(){this.stopped=!0,this.animate.stop()},h.destroy=function(){var t;this.wrapperNode===window&&this.wrapperNode.removeEventListener("resize",this.onWindowResize),this.wrapperNode.removeEventListener("scroll",this.onScroll),this.virtualScroll.destroy(),null==(t=this.wrapperObserver)||t.disconnect(),this.contentObserver.disconnect()},h.raf=function(t){var e=t-(this.now||0);this.now=t,!this.stopped&&this.smooth&&(this.lastScroll=this.scroll,this.animate.raf(.001*e),this.scroll===this.targetScroll&&(this.lastScroll=this.scroll),this.isScrolling&&(this.setScroll(this.scroll),this.notify()),this.isScrolling=this.scroll!==this.targetScroll)},h.setScroll=function(t){"horizontal"===this.direction?this.wrapperNode.scrollTo(t,0):this.wrapperNode.scrollTo(0,t)},h.notify=function(){this.emit("scroll",{scroll:this.scroll,limit:this.limit,velocity:this.velocity,direction:this.direction,progress:this.scroll/this.limit})},h.scrollTo=function(t,e){var i=void 0===e?{}:e,o=i.offset,n=void 0===o?0:o,r=i.immediate,s=void 0!==r&&r,h=i.duration,a=void 0===h?this.duration:h,c=i.easing,u=void 0===c?this.easing:c;if(null!=t){var d;if("number"==typeof t)d=t;else if("top"===t||"#top"===t)d=0;else if("bottom"===t)d=this.limit;else{var p;if("string"==typeof t)p=document.querySelector(t);else{if(null==t||!t.nodeType)return;p=t}if(!p)return;var f=0;if(this.wrapperNode!==window){var v=this.wrapperNode.getBoundingClientRect();f="horizontal"===this.direction?v.left:v.top}var y=p.getBoundingClientRect();d=("horizontal"===this.direction?y.left:y.top)+this.scroll-f}this.targetScroll=l(0,d+=n,this.limit),!this.smooth||s?this.setScroll(this.targetScroll):this.animate.to(this,{duration:a,easing:u,scroll:this.targetScroll})}},e(r,[{key:"scrollProperty",get:function(){return this.wrapperNode===window?"horizontal"===this.direction?"scrollX":"scrollY":"horizontal"===this.direction?"scrollLeft":"scrollTop"}},{key:"limit",get:function(){return"horizontal"===this.direction?this.contentWidth-this.wrapperWidth:this.contentHeight-this.wrapperHeight}},{key:"velocity",get:function(){return this.scroll-this.lastScroll}}]),r}(r)}); diff --git a/dist/lenis.js b/dist/lenis.js index c88d98c5..335d2ef4 100644 --- a/dist/lenis.js +++ b/dist/lenis.js @@ -1,2 +1,2 @@ -var t=require("tiny-emitter"),e=require("virtual-scroll");function o(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var i=/*#__PURE__*/o(t),r=/*#__PURE__*/o(e);function n(t,e){for(var o=0;o=0||(r[o]=t[o]);return r}(i,a);this.target=t,this.fromKeys=l({},h),this.toKeys=l({},h),this.keys=Object.keys(l({},h)),this.keys.forEach(function(e){o.fromKeys[e]=t[e]}),this.duration=n,this.easing=c,this.currentTime=0,this.isRunning=!0},e.stop=function(){this.isRunning=!1},e.raf=function(t){var e=this;if(this.isRunning){this.currentTime=Math.min(this.currentTime+.001*t,this.duration);var o=this.easing(this.progress);this.keys.forEach(function(t){var i=e.fromKeys[t];e.target[t]=i+(e.toKeys[t]-i)*o}),1===o&&(this.isRunning=!1)}},s(t,[{key:"progress",get:function(){return this.currentTime/this.duration}}]),t}();module.exports=/*#__PURE__*/function(t){var e,o;function i(e){var o,i,n,s,l=void 0===e?{}:e,c=l.duration,a=void 0===c?1.2:c,u=l.easing,p=void 0===u?function(t){return 1===t?1:1-Math.pow(2,-10*t)}:u,d=l.smooth,f=void 0===d||d,v=l.smoothTouch,g=void 0!==v&&v,w=l.touchMultiplier,m=void 0===w?2:w,y=l.direction,b=void 0===y?"vertical":y,S=l.gestureDirection,N=void 0===S?"vertical":S,O=l.wrapper,z=void 0===O?window:O,R=l.content,W=void 0===R?document.body:R;(s=t.call(this)||this).onWindowResize=function(){s.wrapperWidth=window.innerWidth,s.wrapperHeight=window.innerHeight},s.onWrapperResize=function(t){var e=t[0];if(e){var o=e.contentRect;s.wrapperWidth=o.width,s.wrapperHeight=o.height}},s.onContentResize=function(t){var e=t[0];if(e){var o=e.contentRect;s.contentWidth=o.width,s.contentHeight=o.height}},s.onVirtualScroll=function(t){var e=t.deltaY,o=t.deltaX,i=t.originalEvent;i.ctrlKey||(s.smooth=i.changedTouches?s.smoothTouch:s.options.smooth,s.stopped?i.preventDefault():s.smooth&&4!==i.buttons&&(s.smooth&&i.preventDefault(),s.targetScroll-="both"===s.gestureDirection?o+e:"horizontal"===s.gestureDirection?o:e,s.targetScroll=Math.max(0,Math.min(s.targetScroll,s.limit)),s.scrollTo(s.targetScroll)))},s.onScroll=function(t){s.isScrolling&&s.smooth||(s.targetScroll=s.scroll=s.lastScroll=s.wrapperNode[s.scrollProperty],s.notify())},window.lenisVersion="0.2.9",s.options={duration:a,easing:p,smooth:f,smoothTouch:g,touchMultiplier:m,direction:b,gestureDirection:N,wrapper:z,content:W},s.duration=a,s.easing=p,s.smooth=f,s.smoothTouch=g,s.touchMultiplier=m,s.direction=b,s.gestureDirection=N,s.wrapperNode=z,s.contentNode=W,s.wrapperNode.addEventListener("scroll",s.onScroll),s.wrapperNode===window?(s.wrapperNode.addEventListener("resize",s.onWindowResize),s.onWindowResize()):(s.wrapperHeight=s.wrapperNode.offsetHeight,s.wrapperWidth=s.wrapperNode.offsetWidth,s.wrapperObserver=new ResizeObserver(s.onWrapperResize),s.wrapperObserver.observe(s.wrapperNode)),s.contentHeight=s.contentNode.offsetHeight,s.contentWidth=s.contentNode.offsetWidth,s.contentObserver=new ResizeObserver(s.onContentResize),s.contentObserver.observe(s.contentNode),s.targetScroll=s.scroll=s.lastScroll=s.wrapperNode[s.scrollProperty],s.animate=new h;var T=(null==(o=navigator)||null==(i=o.userAgentData)?void 0:i.platform)||(null==(n=navigator)?void 0:n.platform)||"unknown";return s.virtualScroll=new r.default({el:s.wrapperNode,firefoxMultiplier:50,mouseMultiplier:T.includes("Win")?1:.4,useKeyboard:!1,touchMultiplier:s.touchMultiplier,useTouch:!0,passive:!1}),s.virtualScroll.on(s.onVirtualScroll),s}o=t,(e=i).prototype=Object.create(o.prototype),e.prototype.constructor=e,c(e,o);var n=i.prototype;return n.start=function(){this.stopped=!1},n.stop=function(){this.stopped=!0,this.animate.stop()},n.destroy=function(){var t;this.wrapperNode===window&&this.wrapperNode.removeEventListener("resize",this.onWindowResize),this.wrapperNode.removeEventListener("scroll",this.onScroll),this.virtualScroll.destroy(),null==(t=this.wrapperObserver)||t.disconnect(),this.contentObserver.disconnect()},n.raf=function(t){var e=t-(this.now||0);this.now=t,!this.stopped&&this.smooth&&(this.lastScroll=this.scroll,this.animate.raf(e),this.scroll===this.targetScroll&&(this.lastScroll=this.scroll),this.isScrolling&&(this.setScroll(this.scroll),this.notify()),this.isScrolling=this.scroll!==this.targetScroll)},n.setScroll=function(t){"horizontal"===this.direction?this.wrapperNode.scrollTo(t,0):this.wrapperNode.scrollTo(0,t)},n.notify=function(){this.emit("scroll",{scroll:this.scroll,limit:this.limit,velocity:this.velocity,direction:this.direction,progress:this.scroll/this.limit})},n.scrollTo=function(t,e){var o=void 0===e?{}:e,i=o.offset,r=void 0===i?0:i,n=o.immediate,s=void 0!==n&&n,l=o.duration,c=void 0===l?this.duration:l,a=o.easing,h=void 0===a?this.easing:a;if(null!=t){var u;if("number"==typeof t)u=t;else if("top"===t||"#top"===t)u=0;else if("bottom"===t)u=this.limit;else{var p;if("string"==typeof t)p=document.querySelector(t);else{if(null==t||!t.nodeType)return;p=t}if(!p)return;var d=0;if(this.wrapperNode!==window){var f=this.wrapperNode.getBoundingClientRect();d="horizontal"===this.direction?f.left:f.top}var v=p.getBoundingClientRect();u=("horizontal"===this.direction?v.left:v.top)+this.scroll-d}this.targetScroll=u+=r,!this.smooth||s?this.setScroll(this.targetScroll):this.animate.to(this,{duration:c,easing:h,scroll:this.targetScroll})}},s(i,[{key:"scrollProperty",get:function(){return this.wrapperNode===window?"horizontal"===this.direction?"scrollX":"scrollY":"horizontal"===this.direction?"scrollLeft":"scrollTop"}},{key:"limit",get:function(){return"horizontal"===this.direction?this.contentWidth-this.wrapperWidth:this.contentHeight-this.wrapperHeight}},{key:"velocity",get:function(){return this.scroll-this.lastScroll}}]),i}(i.default); +var t=require("tiny-emitter"),e=require("virtual-scroll");function o(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var i=/*#__PURE__*/o(t),r=/*#__PURE__*/o(e);function n(t,e){for(var o=0;o=0||(r[o]=t[o]);return r}(i,h);this.target=t,this.fromKeys=l({},a),this.toKeys=l({},a),this.keys=Object.keys(l({},a)),this.keys.forEach(function(e){o.fromKeys[e]=t[e]}),this.duration=n,this.easing=c,this.currentTime=0,this.isRunning=!0},e.stop=function(){this.isRunning=!1},e.raf=function(t){var e=this;if(this.isRunning){this.currentTime=Math.min(this.currentTime+t,this.duration);var o=this.easing(this.progress);this.keys.forEach(function(t){var i=e.fromKeys[t];e.target[t]=i+(e.toKeys[t]-i)*o}),1===o&&this.stop()}},s(t,[{key:"progress",get:function(){return this.currentTime/this.duration}}]),t}();module.exports=/*#__PURE__*/function(t){var e,o;function i(e){var o,i,n,s,l=void 0===e?{}:e,c=l.duration,h=void 0===c?1.2:c,p=l.easing,d=void 0===p?function(t){return 1===t?1:1-Math.pow(2,-10*t)}:p,f=l.smooth,v=void 0===f||f,g=l.smoothTouch,w=void 0!==g&&g,m=l.touchMultiplier,y=void 0===m?2:m,b=l.direction,S=void 0===b?"vertical":b,N=l.gestureDirection,O=void 0===N?"vertical":N,z=l.wrapper,R=void 0===z?window:z,W=l.content,T=void 0===W?document.body:W;(s=t.call(this)||this).onWindowResize=function(){s.wrapperWidth=window.innerWidth,s.wrapperHeight=window.innerHeight},s.onWrapperResize=function(t){var e=t[0];if(e){var o=e.contentRect;s.wrapperWidth=o.width,s.wrapperHeight=o.height}},s.onContentResize=function(t){var e=t[0];if(e){var o=e.contentRect;s.contentWidth=o.width,s.contentHeight=o.height}},s.onVirtualScroll=function(t){var e=t.deltaY,o=t.deltaX,i=t.originalEvent;i.ctrlKey||(s.smooth=i.changedTouches?s.smoothTouch:s.options.smooth,s.stopped?i.preventDefault():s.smooth&&4!==i.buttons&&(s.smooth&&i.preventDefault(),s.targetScroll-="both"===s.gestureDirection?o+e:"horizontal"===s.gestureDirection?o:e,s.targetScroll=a(0,s.targetScroll,s.limit),s.scrollTo(s.targetScroll)))},s.onScroll=function(t){s.isScrolling&&s.smooth||(s.targetScroll=s.scroll=s.lastScroll=s.wrapperNode[s.scrollProperty],s.notify())},window.lenisVersion="0.2.10",s.options={duration:h,easing:d,smooth:v,smoothTouch:w,touchMultiplier:y,direction:S,gestureDirection:O,wrapper:R,content:T},s.duration=h,s.easing=d,s.smooth=v,s.smoothTouch=w,s.touchMultiplier=y,s.direction=S,s.gestureDirection=O,s.wrapperNode=R,s.contentNode=T,s.wrapperNode.addEventListener("scroll",s.onScroll),s.wrapperNode===window?(s.wrapperNode.addEventListener("resize",s.onWindowResize),s.onWindowResize()):(s.wrapperHeight=s.wrapperNode.offsetHeight,s.wrapperWidth=s.wrapperNode.offsetWidth,s.wrapperObserver=new ResizeObserver(s.onWrapperResize),s.wrapperObserver.observe(s.wrapperNode)),s.contentHeight=s.contentNode.offsetHeight,s.contentWidth=s.contentNode.offsetWidth,s.contentObserver=new ResizeObserver(s.onContentResize),s.contentObserver.observe(s.contentNode),s.targetScroll=s.scroll=s.lastScroll=s.wrapperNode[s.scrollProperty],s.animate=new u;var j=(null==(o=navigator)||null==(i=o.userAgentData)?void 0:i.platform)||(null==(n=navigator)?void 0:n.platform)||"unknown";return s.virtualScroll=new r.default({el:s.wrapperNode,firefoxMultiplier:50,mouseMultiplier:j.includes("Win")?1:.4,useKeyboard:!1,touchMultiplier:s.touchMultiplier,useTouch:!0,passive:!1}),s.virtualScroll.on(s.onVirtualScroll),s}o=t,(e=i).prototype=Object.create(o.prototype),e.prototype.constructor=e,c(e,o);var n=i.prototype;return n.start=function(){this.stopped=!1},n.stop=function(){this.stopped=!0,this.animate.stop()},n.destroy=function(){var t;this.wrapperNode===window&&this.wrapperNode.removeEventListener("resize",this.onWindowResize),this.wrapperNode.removeEventListener("scroll",this.onScroll),this.virtualScroll.destroy(),null==(t=this.wrapperObserver)||t.disconnect(),this.contentObserver.disconnect()},n.raf=function(t){var e=t-(this.now||0);this.now=t,!this.stopped&&this.smooth&&(this.lastScroll=this.scroll,this.animate.raf(.001*e),this.scroll===this.targetScroll&&(this.lastScroll=this.scroll),this.isScrolling&&(this.setScroll(this.scroll),this.notify()),this.isScrolling=this.scroll!==this.targetScroll)},n.setScroll=function(t){"horizontal"===this.direction?this.wrapperNode.scrollTo(t,0):this.wrapperNode.scrollTo(0,t)},n.notify=function(){this.emit("scroll",{scroll:this.scroll,limit:this.limit,velocity:this.velocity,direction:this.direction,progress:this.scroll/this.limit})},n.scrollTo=function(t,e){var o=void 0===e?{}:e,i=o.offset,r=void 0===i?0:i,n=o.immediate,s=void 0!==n&&n,l=o.duration,c=void 0===l?this.duration:l,h=o.easing,u=void 0===h?this.easing:h;if(null!=t){var p;if("number"==typeof t)p=t;else if("top"===t||"#top"===t)p=0;else if("bottom"===t)p=this.limit;else{var d;if("string"==typeof t)d=document.querySelector(t);else{if(null==t||!t.nodeType)return;d=t}if(!d)return;var f=0;if(this.wrapperNode!==window){var v=this.wrapperNode.getBoundingClientRect();f="horizontal"===this.direction?v.left:v.top}var g=d.getBoundingClientRect();p=("horizontal"===this.direction?g.left:g.top)+this.scroll-f}this.targetScroll=a(0,p+=r,this.limit),!this.smooth||s?this.setScroll(this.targetScroll):this.animate.to(this,{duration:c,easing:u,scroll:this.targetScroll})}},s(i,[{key:"scrollProperty",get:function(){return this.wrapperNode===window?"horizontal"===this.direction?"scrollX":"scrollY":"horizontal"===this.direction?"scrollLeft":"scrollTop"}},{key:"limit",get:function(){return"horizontal"===this.direction?this.contentWidth-this.wrapperWidth:this.contentHeight-this.wrapperHeight}},{key:"velocity",get:function(){return this.scroll-this.lastScroll}}]),i}(i.default); //# sourceMappingURL=lenis.js.map diff --git a/dist/lenis.js.map b/dist/lenis.js.map index 352641d7..4f6a910b 100644 --- a/dist/lenis.js.map +++ b/dist/lenis.js.map @@ -1 +1 @@ -{"version":3,"file":"lenis.js","sources":["../src/lenis.js","../src/maths.js"],"sourcesContent":["import EventEmitter from 'tiny-emitter'\r\nimport VirtualScroll from 'virtual-scroll'\r\nimport { version } from '../package.json'\r\nimport { clamp } from './maths.js'\r\n\r\nclass Animate {\r\n to(target, { duration = 1, easing = (t) => t, ...keys } = {}) {\r\n this.target = target\r\n this.fromKeys = { ...keys }\r\n this.toKeys = { ...keys }\r\n this.keys = Object.keys({ ...keys })\r\n\r\n // get initial values\r\n this.keys.forEach((key) => {\r\n this.fromKeys[key] = target[key]\r\n })\r\n\r\n this.duration = duration\r\n this.easing = easing\r\n this.currentTime = 0\r\n this.isRunning = true\r\n }\r\n\r\n stop() {\r\n this.isRunning = false\r\n }\r\n\r\n raf(deltaTime) {\r\n if (!this.isRunning) return\r\n\r\n this.currentTime = Math.min(\r\n this.currentTime + deltaTime * 0.001,\r\n this.duration\r\n )\r\n\r\n const progress = this.easing(this.progress)\r\n\r\n this.keys.forEach((key) => {\r\n const from = this.fromKeys[key]\r\n const to = this.toKeys[key]\r\n\r\n const value = from + (to - from) * progress\r\n\r\n this.target[key] = value\r\n })\r\n\r\n if (progress === 1) {\r\n this.isRunning = false\r\n }\r\n }\r\n\r\n get progress() {\r\n return this.currentTime / this.duration\r\n }\r\n}\r\n\r\nexport default class Lenis extends EventEmitter {\r\n constructor({\r\n duration = 1.2,\r\n easing = (t) => (t === 1 ? 1 : 1 - Math.pow(2, -10 * t)), // https://easings.net/en#easeOutExpo\r\n smooth = true,\r\n smoothTouch = false,\r\n touchMultiplier = 2,\r\n direction = 'vertical', // vertical, horizontal\r\n gestureDirection = 'vertical', // vertical, horizontal, both\r\n wrapper = window,\r\n content = document.body,\r\n } = {}) {\r\n super()\r\n\r\n window.lenisVersion = version\r\n\r\n this.options = {\r\n duration,\r\n easing,\r\n smooth,\r\n smoothTouch,\r\n touchMultiplier,\r\n direction,\r\n gestureDirection,\r\n wrapper,\r\n content,\r\n }\r\n\r\n this.duration = duration\r\n this.easing = easing\r\n this.smooth = smooth\r\n this.smoothTouch = smoothTouch\r\n this.touchMultiplier = touchMultiplier\r\n this.direction = direction\r\n this.gestureDirection = gestureDirection\r\n this.wrapperNode = wrapper\r\n this.contentNode = content\r\n\r\n this.wrapperNode.addEventListener('scroll', this.onScroll)\r\n\r\n //observe wrapper node size\r\n if (this.wrapperNode === window) {\r\n this.wrapperNode.addEventListener('resize', this.onWindowResize)\r\n this.onWindowResize()\r\n } else {\r\n this.wrapperHeight = this.wrapperNode.offsetHeight\r\n this.wrapperWidth = this.wrapperNode.offsetWidth\r\n\r\n //observe wrapper node size\r\n this.wrapperObserver = new ResizeObserver(this.onWrapperResize)\r\n this.wrapperObserver.observe(this.wrapperNode)\r\n }\r\n\r\n this.contentHeight = this.contentNode.offsetHeight\r\n this.contentWidth = this.contentNode.offsetWidth\r\n\r\n //observe content node size\r\n this.contentObserver = new ResizeObserver(this.onContentResize)\r\n this.contentObserver.observe(this.contentNode)\r\n\r\n //set initial scroll position\r\n this.targetScroll =\r\n this.scroll =\r\n this.lastScroll =\r\n this.wrapperNode[this.scrollProperty]\r\n\r\n this.animate = new Animate()\r\n\r\n const platform =\r\n navigator?.userAgentData?.platform || navigator?.platform || 'unknown'\r\n\r\n // listen and normalize wheel event cross-browser\r\n this.virtualScroll = new VirtualScroll({\r\n el: this.wrapperNode,\r\n firefoxMultiplier: 50,\r\n mouseMultiplier: platform.includes('Win') ? 1 : 0.4,\r\n useKeyboard: false,\r\n touchMultiplier: this.touchMultiplier,\r\n useTouch: true,\r\n passive: false,\r\n })\r\n\r\n this.virtualScroll.on(this.onVirtualScroll)\r\n }\r\n\r\n get scrollProperty() {\r\n let property\r\n if (this.wrapperNode === window) {\r\n property = this.direction === 'horizontal' ? 'scrollX' : 'scrollY'\r\n } else {\r\n property = this.direction === 'horizontal' ? 'scrollLeft' : 'scrollTop'\r\n }\r\n return property\r\n }\r\n\r\n start() {\r\n this.stopped = false\r\n }\r\n\r\n stop() {\r\n this.stopped = true\r\n this.animate.stop()\r\n }\r\n\r\n destroy() {\r\n if (this.wrapperNode === window) {\r\n this.wrapperNode.removeEventListener('resize', this.onWindowResize)\r\n }\r\n this.wrapperNode.removeEventListener('scroll', this.onScroll)\r\n\r\n this.virtualScroll.destroy()\r\n this.wrapperObserver?.disconnect()\r\n this.contentObserver.disconnect()\r\n }\r\n\r\n onWindowResize = () => {\r\n this.wrapperWidth = window.innerWidth\r\n this.wrapperHeight = window.innerHeight\r\n }\r\n\r\n onWrapperResize = ([entry]) => {\r\n if (entry) {\r\n const rect = entry.contentRect\r\n this.wrapperWidth = rect.width\r\n this.wrapperHeight = rect.height\r\n }\r\n }\r\n\r\n onContentResize = ([entry]) => {\r\n if (entry) {\r\n const rect = entry.contentRect\r\n this.contentWidth = rect.width\r\n this.contentHeight = rect.height\r\n }\r\n }\r\n\r\n get limit() {\r\n return this.direction === 'horizontal'\r\n ? this.contentWidth - this.wrapperWidth\r\n : this.contentHeight - this.wrapperHeight\r\n }\r\n\r\n onVirtualScroll = ({ deltaY, deltaX, originalEvent: e }) => {\r\n if (e.ctrlKey) return\r\n\r\n // switch to smooth if event is touch and touch is true\r\n this.smooth = !!e.changedTouches ? this.smoothTouch : this.options.smooth\r\n\r\n if (this.stopped) {\r\n e.preventDefault()\r\n return\r\n }\r\n\r\n if (!this.smooth) return\r\n\r\n // fix wheel holding scroll https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/buttons\r\n if (e.buttons === 4) return\r\n\r\n // prevent native wheel scrolling\r\n if (this.smooth) e.preventDefault()\r\n\r\n let delta = 0\r\n if (this.gestureDirection === 'both') {\r\n delta = deltaX + deltaY\r\n } else if (this.gestureDirection === 'horizontal') {\r\n delta = deltaX\r\n } else {\r\n // vertical\r\n delta = deltaY\r\n }\r\n\r\n this.targetScroll -= delta\r\n this.targetScroll = clamp(0, this.targetScroll, this.limit)\r\n\r\n this.scrollTo(this.targetScroll)\r\n }\r\n\r\n raf(now) {\r\n const deltaTime = now - (this.now || 0)\r\n this.now = now\r\n\r\n if (this.stopped || !this.smooth) return\r\n\r\n this.lastScroll = this.scroll\r\n\r\n // where this.scroll is updated\r\n this.animate.raf(deltaTime)\r\n\r\n if (this.scroll === this.targetScroll) {\r\n // if target reached velocity should be 0\r\n this.lastScroll = this.scroll\r\n }\r\n\r\n if (this.isScrolling) {\r\n this.setScroll(this.scroll)\r\n this.notify()\r\n }\r\n\r\n this.isScrolling = this.scroll !== this.targetScroll\r\n }\r\n\r\n get velocity() {\r\n return this.scroll - this.lastScroll\r\n }\r\n\r\n setScroll(value) {\r\n this.direction === 'horizontal'\r\n ? this.wrapperNode.scrollTo(value, 0)\r\n : this.wrapperNode.scrollTo(0, value)\r\n }\r\n\r\n onScroll = (e) => {\r\n // if isScrolling false we can consider user isn't scrolling with wheel (cmd+F, keyboard or whatever). So we must scroll to value immediately\r\n if (!this.isScrolling || !this.smooth) {\r\n // where native scroll happens\r\n this.targetScroll =\r\n this.scroll =\r\n this.lastScroll =\r\n this.wrapperNode[this.scrollProperty]\r\n\r\n this.notify()\r\n }\r\n }\r\n\r\n notify() {\r\n this.emit('scroll', {\r\n scroll: this.scroll,\r\n limit: this.limit,\r\n velocity: this.velocity,\r\n direction: this.direction,\r\n progress: this.scroll / this.limit,\r\n })\r\n }\r\n\r\n scrollTo(\r\n target,\r\n {\r\n offset = 0,\r\n immediate = false,\r\n duration = this.duration,\r\n easing = this.easing,\r\n } = {}\r\n ) {\r\n if (target === undefined || target === null) return\r\n let value\r\n\r\n if (typeof target === 'number') {\r\n value = target\r\n } else if (target === 'top' || target === '#top') {\r\n value = 0\r\n } else if (target === 'bottom') {\r\n value = 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 } else {\r\n return\r\n }\r\n\r\n if (!node) return\r\n let wrapperOffset = 0\r\n\r\n if (this.wrapperNode !== window) {\r\n const wrapperRect = this.wrapperNode.getBoundingClientRect()\r\n wrapperOffset =\r\n this.direction === 'horizontal' ? wrapperRect.left : wrapperRect.top\r\n }\r\n\r\n const rect = node.getBoundingClientRect()\r\n\r\n value =\r\n (this.direction === 'horizontal' ? rect.left : rect.top) +\r\n this.scroll -\r\n wrapperOffset\r\n }\r\n\r\n value += offset\r\n\r\n this.targetScroll = value\r\n\r\n if (!this.smooth || immediate) {\r\n this.setScroll(this.targetScroll)\r\n } else {\r\n this.animate.to(this, {\r\n duration,\r\n easing,\r\n scroll: this.targetScroll,\r\n })\r\n }\r\n }\r\n}\r\n","export function clamp(min, input, max) {\r\n return Math.max(min, Math.min(input, max))\r\n}\r\n\r\nexport function mapRange(in_min, in_max, input, out_min, out_max) {\r\n return ((input - in_min) * (out_max - out_min)) / (in_max - in_min) + out_min\r\n}\r\n\r\nexport function lerp(start, end, amt) {\r\n return (1 - amt) * start + amt * end\r\n}\r\n\r\nexport function truncate(value, decimals) {\r\n return parseFloat(value.toFixed(decimals))\r\n}\r\n"],"names":["_excluded","Lenis","to","target","_temp","_this","this","_ref","duration","_ref$duration","_ref$easing","easing","t","keys","fromKeys","toKeys","_extends","Object","forEach","key","currentTime","isRunning","stop","raf","deltaTime","_this2","Math","min","progress","from","_temp2","_navigator","_navigator$userAgentD","_navigator2","_this3","_ref2","_ref2$duration","_ref2$easing","pow","smooth","_ref2$smooth","smoothTouch","_ref2$smoothTouch","_ref2$touchMultiplier","touchMultiplier","_ref2$direction","direction","gestureDirection","_ref2$gestureDirectio","wrapper","_ref2$wrapper","window","content","_ref2$content","document","body","_EventEmitter","call","onWindowResize","wrapperWidth","innerWidth","wrapperHeight","innerHeight","onWrapperResize","_ref3","entry","rect","contentRect","width","height","onContentResize","_ref4","contentWidth","contentHeight","onVirtualScroll","_ref5","deltaY","deltaX","e","originalEvent","ctrlKey","changedTouches","options","stopped","preventDefault","buttons","targetScroll","max","limit","scrollTo","onScroll","isScrolling","scroll","lastScroll","wrapperNode","scrollProperty","notify","lenisVersion","contentNode","addEventListener","offsetHeight","offsetWidth","wrapperObserver","observe","contentObserver","ResizeObserver","animate","Animate","platform","navigator","userAgentData","virtualScroll","VirtualScroll","el","firefoxMultiplier","mouseMultiplier","includes","useKeyboard","useTouch","passive","on","EventEmitter","start","destroy","_this$wrapperObserver","removeEventListener","disconnect","now","setScroll","value","emit","velocity","_temp3","_ref6","_ref6$offset","offset","_ref6$immediate","immediate","_ref6$duration","node","querySelector","nodeType","wrapperOffset","wrapperRect","getBoundingClientRect","left","top","_createClass","get"],"mappings":"6xBAAA,IAAAA,EAAA,CAAA,WAAA,oEAwDqBC,SAlDnBC,GAAA,SAAGC,EAA2DC,GAAA,IAAAC,EAAAC,KAAAC,OAAA,IAAAH,EAAJ,CAAA,EAA7CI,EAAAA,EAAAA,EAAAA,SAAAA,aAAW,EAAsCC,EAAAC,EAAAH,EAAnCI,OAAAA,aAAS,SAACC,GAAMA,OAAAA,CAAP,EAAaC,EAAAA,0IAC/CP,KAAKH,OAASA,EACdG,KAAKQ,cAAgBD,GACrBP,KAAKS,OAALC,EAAA,CAAA,EAAmBH,GACnBP,KAAKO,KAAOI,OAAOJ,UAAUA,IAG7BP,KAAKO,KAAKK,QAAQ,SAACC,GACjBd,EAAKS,SAASK,GAAOhB,EAAOgB,EAC7B,GAEDb,KAAKE,SAAWA,EAChBF,KAAKK,OAASA,EACdL,KAAKc,YAAc,EACnBd,KAAKe,WAAY,CAClB,IAEDC,KAAA,WACEhB,KAAKe,WAAY,CAClB,IAEDE,IAAA,SAAIC,GAAW,IAAAC,EAAAnB,KACb,GAAKA,KAAKe,UAAV,CAEAf,KAAKc,YAAcM,KAAKC,IACtBrB,KAAKc,YAA0B,KAAZI,EACnBlB,KAAKE,UAGP,IAAcoB,EAAGtB,KAAKK,OAAOL,KAAKsB,UAElCtB,KAAKO,KAAKK,QAAQ,SAACC,GACjB,IAAMU,EAAOJ,EAAKX,SAASK,GAK3BM,EAAKtB,OAAOgB,GAFEU,GAFHJ,EAAKV,OAAOI,GAEIU,GAAQD,CAGpC,GAEgB,IAA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AczI,KAAKwF,YAAYkD,wBACrCF,EACqB,eAAnBxI,KAAKwC,UAA6BiG,EAAYE,KAAOF,EAAYG,GACpE,CAED,IAAUhF,EAAGyE,EAAKK,wBAElBf,GACsB,eAAnB3H,KAAKwC,UAA6BoB,EAAK+E,KAAO/E,EAAKgF,KACpD5I,KAAKsF,OACLkD,CACH,CAIDxI,KAAKgF,aAFL2C,GAASM,GAIJjI,KAAKiC,QAAUkG,EAClBnI,KAAK0H,UAAU1H,KAAKgF,cAEpBhF,KAAKoG,QAAQxG,GAAGI,KAAM,CACpBE,SAAAA,EACAG,OAAAA,EACAiF,OAAQtF,KAAKgF,cAjD4B,CAoD9C,EAlND6D,EAAAlJ,EAAA,CAAA,CAAAkB,IAAA,iBAAAiI,IAAA,WAOE,OALI9I,KAAKwF,cAAgB3C,OACO,eAAnB7C,KAAKwC,UAA6B,UAAY,UAE3B,eAAnBxC,KAAKwC,UAA6B,aAAe,WAG/D,GA2CD,CAAA3B,IAAA,QAAAiI,IAAA,WACE,MAA0B,oBAAdtG,UACRxC,KAAKkE,aAAelE,KAAKqD,aACzBrD,KAAKmE,cAAgBnE,KAAKuD,aAC/B,uBA6DD,WACE,OAAY+B,KAAAA,OAAStF,KAAKuF,UAC3B,KA3MgC4B,CAAAA,EAAAA"} \ No newline at end of file +{"version":3,"file":"lenis.js","sources":["../src/maths.js","../src/lenis.js"],"sourcesContent":["export function clamp(min, input, max) {\r\n return Math.max(min, Math.min(input, max))\r\n}\r\n\r\nexport function mapRange(in_min, in_max, input, out_min, out_max) {\r\n return ((input - in_min) * (out_max - out_min)) / (in_max - in_min) + out_min\r\n}\r\n\r\nexport function lerp(start, end, amt) {\r\n return (1 - amt) * start + amt * end\r\n}\r\n\r\nexport function truncate(value, decimals) {\r\n return parseFloat(value.toFixed(decimals))\r\n}\r\n","import EventEmitter from 'tiny-emitter'\r\nimport VirtualScroll from 'virtual-scroll'\r\nimport { version } from '../package.json'\r\nimport { clamp } from './maths.js'\r\n\r\nclass Animate {\r\n to(target, { duration = 1, easing = (t) => t, ...keys } = {}) {\r\n this.target = target\r\n this.fromKeys = { ...keys }\r\n this.toKeys = { ...keys }\r\n this.keys = Object.keys({ ...keys })\r\n\r\n // get initial values\r\n this.keys.forEach((key) => {\r\n this.fromKeys[key] = target[key]\r\n })\r\n\r\n this.duration = duration\r\n this.easing = easing\r\n this.currentTime = 0\r\n this.isRunning = true\r\n }\r\n\r\n stop() {\r\n this.isRunning = false\r\n }\r\n\r\n raf(deltaTime) {\r\n if (!this.isRunning) return\r\n\r\n this.currentTime = Math.min(this.currentTime + deltaTime, this.duration)\r\n\r\n const progress = this.easing(this.progress)\r\n\r\n this.keys.forEach((key) => {\r\n const from = this.fromKeys[key]\r\n const to = this.toKeys[key]\r\n\r\n const value = from + (to - from) * progress\r\n\r\n this.target[key] = value\r\n })\r\n\r\n if (progress === 1) {\r\n this.stop()\r\n }\r\n }\r\n\r\n get progress() {\r\n return this.currentTime / this.duration\r\n }\r\n}\r\n\r\nexport default class Lenis extends EventEmitter {\r\n constructor({\r\n duration = 1.2,\r\n easing = (t) => (t === 1 ? 1 : 1 - Math.pow(2, -10 * t)), // https://easings.net/en#easeOutExpo\r\n smooth = true,\r\n smoothTouch = false,\r\n touchMultiplier = 2,\r\n direction = 'vertical', // vertical, horizontal\r\n gestureDirection = 'vertical', // vertical, horizontal, both\r\n wrapper = window,\r\n content = document.body,\r\n } = {}) {\r\n super()\r\n\r\n window.lenisVersion = version\r\n\r\n this.options = {\r\n duration,\r\n easing,\r\n smooth,\r\n smoothTouch,\r\n touchMultiplier,\r\n direction,\r\n gestureDirection,\r\n wrapper,\r\n content,\r\n }\r\n\r\n this.duration = duration\r\n this.easing = easing\r\n this.smooth = smooth\r\n this.smoothTouch = smoothTouch\r\n this.touchMultiplier = touchMultiplier\r\n this.direction = direction\r\n this.gestureDirection = gestureDirection\r\n this.wrapperNode = wrapper\r\n this.contentNode = content\r\n\r\n this.wrapperNode.addEventListener('scroll', this.onScroll)\r\n\r\n //observe wrapper node size\r\n if (this.wrapperNode === window) {\r\n this.wrapperNode.addEventListener('resize', this.onWindowResize)\r\n this.onWindowResize()\r\n } else {\r\n this.wrapperHeight = this.wrapperNode.offsetHeight\r\n this.wrapperWidth = this.wrapperNode.offsetWidth\r\n\r\n //observe wrapper node size\r\n this.wrapperObserver = new ResizeObserver(this.onWrapperResize)\r\n this.wrapperObserver.observe(this.wrapperNode)\r\n }\r\n\r\n this.contentHeight = this.contentNode.offsetHeight\r\n this.contentWidth = this.contentNode.offsetWidth\r\n\r\n //observe content node size\r\n this.contentObserver = new ResizeObserver(this.onContentResize)\r\n this.contentObserver.observe(this.contentNode)\r\n\r\n //set initial scroll position\r\n this.targetScroll =\r\n this.scroll =\r\n this.lastScroll =\r\n this.wrapperNode[this.scrollProperty]\r\n\r\n this.animate = new Animate()\r\n\r\n const platform =\r\n navigator?.userAgentData?.platform || navigator?.platform || 'unknown'\r\n\r\n // listen and normalize wheel event cross-browser\r\n this.virtualScroll = new VirtualScroll({\r\n el: this.wrapperNode,\r\n firefoxMultiplier: 50,\r\n mouseMultiplier: platform.includes('Win') ? 1 : 0.4,\r\n useKeyboard: false,\r\n touchMultiplier: this.touchMultiplier,\r\n useTouch: true,\r\n passive: false,\r\n })\r\n\r\n this.virtualScroll.on(this.onVirtualScroll)\r\n }\r\n\r\n get scrollProperty() {\r\n let property\r\n if (this.wrapperNode === window) {\r\n property = this.direction === 'horizontal' ? 'scrollX' : 'scrollY'\r\n } else {\r\n property = this.direction === 'horizontal' ? 'scrollLeft' : 'scrollTop'\r\n }\r\n return property\r\n }\r\n\r\n start() {\r\n this.stopped = false\r\n }\r\n\r\n stop() {\r\n this.stopped = true\r\n this.animate.stop()\r\n }\r\n\r\n destroy() {\r\n if (this.wrapperNode === window) {\r\n this.wrapperNode.removeEventListener('resize', this.onWindowResize)\r\n }\r\n this.wrapperNode.removeEventListener('scroll', this.onScroll)\r\n\r\n this.virtualScroll.destroy()\r\n this.wrapperObserver?.disconnect()\r\n this.contentObserver.disconnect()\r\n }\r\n\r\n onWindowResize = () => {\r\n this.wrapperWidth = window.innerWidth\r\n this.wrapperHeight = window.innerHeight\r\n }\r\n\r\n onWrapperResize = ([entry]) => {\r\n if (entry) {\r\n const rect = entry.contentRect\r\n this.wrapperWidth = rect.width\r\n this.wrapperHeight = rect.height\r\n }\r\n }\r\n\r\n onContentResize = ([entry]) => {\r\n if (entry) {\r\n const rect = entry.contentRect\r\n this.contentWidth = rect.width\r\n this.contentHeight = rect.height\r\n }\r\n }\r\n\r\n get limit() {\r\n return this.direction === 'horizontal'\r\n ? this.contentWidth - this.wrapperWidth\r\n : this.contentHeight - this.wrapperHeight\r\n }\r\n\r\n onVirtualScroll = ({ deltaY, deltaX, originalEvent: e }) => {\r\n if (e.ctrlKey) return\r\n\r\n // switch to smooth if event is touch and touch is true\r\n this.smooth = !!e.changedTouches ? this.smoothTouch : this.options.smooth\r\n\r\n if (this.stopped) {\r\n e.preventDefault()\r\n return\r\n }\r\n\r\n if (!this.smooth) return\r\n\r\n // fix wheel holding scroll https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/buttons\r\n if (e.buttons === 4) return\r\n\r\n // prevent native wheel scrolling\r\n if (this.smooth) e.preventDefault()\r\n\r\n let delta = 0\r\n if (this.gestureDirection === 'both') {\r\n delta = deltaX + deltaY\r\n } else if (this.gestureDirection === 'horizontal') {\r\n delta = deltaX\r\n } else {\r\n // vertical\r\n delta = deltaY\r\n }\r\n\r\n this.targetScroll -= delta\r\n this.targetScroll = clamp(0, this.targetScroll, this.limit)\r\n\r\n this.scrollTo(this.targetScroll)\r\n }\r\n\r\n raf(now) {\r\n const deltaTime = now - (this.now || 0)\r\n this.now = now\r\n\r\n if (this.stopped || !this.smooth) return\r\n\r\n this.lastScroll = this.scroll\r\n\r\n // where this.scroll is updated\r\n this.animate.raf(deltaTime * 0.001)\r\n\r\n if (this.scroll === this.targetScroll) {\r\n // if target reached velocity should be 0\r\n this.lastScroll = this.scroll\r\n }\r\n\r\n if (this.isScrolling) {\r\n this.setScroll(this.scroll)\r\n this.notify()\r\n }\r\n\r\n this.isScrolling = this.scroll !== this.targetScroll\r\n }\r\n\r\n get velocity() {\r\n return this.scroll - this.lastScroll\r\n }\r\n\r\n setScroll(value) {\r\n this.direction === 'horizontal'\r\n ? this.wrapperNode.scrollTo(value, 0)\r\n : this.wrapperNode.scrollTo(0, value)\r\n }\r\n\r\n onScroll = (e) => {\r\n // if isScrolling false we can consider user isn't scrolling with wheel (cmd+F, keyboard or whatever). So we must scroll to value immediately\r\n if (!this.isScrolling || !this.smooth) {\r\n // where native scroll happens\r\n this.targetScroll =\r\n this.scroll =\r\n this.lastScroll =\r\n this.wrapperNode[this.scrollProperty]\r\n\r\n this.notify()\r\n }\r\n }\r\n\r\n notify() {\r\n this.emit('scroll', {\r\n scroll: this.scroll,\r\n limit: this.limit,\r\n velocity: this.velocity,\r\n direction: this.direction,\r\n progress: this.scroll / this.limit,\r\n })\r\n }\r\n\r\n scrollTo(\r\n target,\r\n {\r\n offset = 0,\r\n immediate = false,\r\n duration = this.duration,\r\n easing = this.easing,\r\n } = {}\r\n ) {\r\n if (target === undefined || target === null) return\r\n let value\r\n\r\n if (typeof target === 'number') {\r\n value = target\r\n } else if (target === 'top' || target === '#top') {\r\n value = 0\r\n } else if (target === 'bottom') {\r\n value = 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 } else {\r\n return\r\n }\r\n\r\n if (!node) return\r\n let wrapperOffset = 0\r\n\r\n if (this.wrapperNode !== window) {\r\n const wrapperRect = this.wrapperNode.getBoundingClientRect()\r\n wrapperOffset =\r\n this.direction === 'horizontal' ? wrapperRect.left : wrapperRect.top\r\n }\r\n\r\n const rect = node.getBoundingClientRect()\r\n\r\n value =\r\n (this.direction === 'horizontal' ? rect.left : rect.top) +\r\n this.scroll -\r\n wrapperOffset\r\n }\r\n\r\n value += offset\r\n\r\n this.targetScroll = clamp(0, value, this.limit)\r\n\r\n if (!this.smooth || immediate) {\r\n this.setScroll(this.targetScroll)\r\n } else {\r\n this.animate.to(this, {\r\n duration,\r\n easing,\r\n scroll: this.targetScroll,\r\n })\r\n }\r\n }\r\n}\r\n"],"names":["min","input","max","Math","_excluded","to","target","_temp","_this","this","_ref","duration","_ref$duration","_ref$easing","easing","t","keys","fromKeys","toKeys","_extends","Object","forEach","key","currentTime","isRunning","stop","raf","deltaTime","_this2","progress","from","_createClass","Animate","get","_navigator","_navigator$userAgentD","_navigator2","_this3","_ref2","_temp2","_ref2$duration","_ref2$easing","pow","_ref2$smooth","smooth","smoothTouch","_ref2$smoothTouch","touchMultiplier","_ref2$touchMultiplier","direction","_ref2$direction","gestureDirection","_ref2$gestureDirectio","wrapper","_ref2$wrapper","window","content","document","body","_ref2$content","_EventEmitter","call","onWindowResize","wrapperWidth","innerWidth","wrapperHeight","innerHeight","onWrapperResize","entry","contentRect","rect","width","height","onContentResize","_ref4","contentWidth","contentHeight","onVirtualScroll","_ref5","deltaY","deltaX","e","originalEvent","ctrlKey","changedTouches","options","stopped","preventDefault","buttons","targetScroll","clamp","limit","scrollTo","onScroll","isScrolling","scroll","lastScroll","wrapperNode","scrollProperty","notify","lenisVersion","contentNode","addEventListener","offsetHeight","offsetWidth","wrapperObserver","ResizeObserver","observe","contentObserver","animate","platform","navigator","userAgentData","virtualScroll","el","firefoxMultiplier","mouseMultiplier","includes","useKeyboard","useTouch","passive","on","EventEmitter","start","destroy","_this$wrapperObserver","removeEventListener","disconnect","now","setScroll","value","emit","velocity","_ref6","_temp3","offset","_ref6$offset","immediate","_ref6$immediate","_ref6$duration","_ref6$easing","node","querySelector","nodeType","wrapperOffset","wrapperRect","getBoundingClientRect","left","top","Lenis"],"mappings":"6xBAAO,WAAeA,EAAKC,EAAOC,GAChC,OAAWC,KAACD,IAAIF,EAAKG,KAAKH,IAAIC,EAAOC,GACtC,CCFD,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AAKoG,QAAQxG,GAAGI,KAAM,CACpBE,SAAAA,EACAG,OAAAA,EACAiF,OAAQtF,KAAKgF,cAjD4B,CAoD9C,EAlND1D,EAAAsH,EAAA,CAAA,CAAA/H,IAAA,iBAAAW,IAAA,WAOE,OALIxB,KAAKwF,cAAgB1C,OACO,eAAnB9C,KAAKwC,UAA6B,UAAY,UAE3B,eAAnBxC,KAAKwC,UAA6B,aAAe,WAG/D,GA2CD,CAAA3B,IAAA,QAAAW,IAAA,WACE,MAA0B,oBAAdgB,UACRxC,KAAKkE,aAAelE,KAAKsD,aACzBtD,KAAKmE,cAAgBnE,KAAKwD,aAC/B,uBA6DD,WACE,OAAY8B,KAAAA,OAAStF,KAAKuF,UAC3B,KA3MgC0B,CAAAA,EAAAA"} \ No newline at end of file diff --git a/dist/lenis.mjs b/dist/lenis.mjs index a29c05f8..d4ab610c 100644 --- a/dist/lenis.mjs +++ b/dist/lenis.mjs @@ -1,2 +1,2 @@ -import t from"tiny-emitter";import e from"virtual-scroll";function o(t,e){for(var o=0;o=0||(r[o]=t[o]);return r}(i,s);this.target=t,this.fromKeys=r({},h),this.toKeys=r({},h),this.keys=Object.keys(r({},h)),this.keys.forEach(function(e){o.fromKeys[e]=t[e]}),this.duration=l,this.easing=a,this.currentTime=0,this.isRunning=!0},e.stop=function(){this.isRunning=!1},e.raf=function(t){var e=this;if(this.isRunning){this.currentTime=Math.min(this.currentTime+.001*t,this.duration);var o=this.easing(this.progress);this.keys.forEach(function(t){var i=e.fromKeys[t];e.target[t]=i+(e.toKeys[t]-i)*o}),1===o&&(this.isRunning=!1)}},i(t,[{key:"progress",get:function(){return this.currentTime/this.duration}}]),t}(),c=/*#__PURE__*/function(t){var o,r;function s(o){var i,r,n,s,c=void 0===o?{}:o,a=c.duration,h=void 0===a?1.2:a,p=c.easing,u=void 0===p?function(t){return 1===t?1:1-Math.pow(2,-10*t)}:p,d=c.smooth,f=void 0===d||d,v=c.smoothTouch,g=void 0!==v&&v,w=c.touchMultiplier,m=void 0===w?2:w,y=c.direction,b=void 0===y?"vertical":y,S=c.gestureDirection,N=void 0===S?"vertical":S,O=c.wrapper,z=void 0===O?window:O,R=c.content,W=void 0===R?document.body:R;(s=t.call(this)||this).onWindowResize=function(){s.wrapperWidth=window.innerWidth,s.wrapperHeight=window.innerHeight},s.onWrapperResize=function(t){var e=t[0];if(e){var o=e.contentRect;s.wrapperWidth=o.width,s.wrapperHeight=o.height}},s.onContentResize=function(t){var e=t[0];if(e){var o=e.contentRect;s.contentWidth=o.width,s.contentHeight=o.height}},s.onVirtualScroll=function(t){var e=t.deltaY,o=t.deltaX,i=t.originalEvent;i.ctrlKey||(s.smooth=i.changedTouches?s.smoothTouch:s.options.smooth,s.stopped?i.preventDefault():s.smooth&&4!==i.buttons&&(s.smooth&&i.preventDefault(),s.targetScroll-="both"===s.gestureDirection?o+e:"horizontal"===s.gestureDirection?o:e,s.targetScroll=Math.max(0,Math.min(s.targetScroll,s.limit)),s.scrollTo(s.targetScroll)))},s.onScroll=function(t){s.isScrolling&&s.smooth||(s.targetScroll=s.scroll=s.lastScroll=s.wrapperNode[s.scrollProperty],s.notify())},window.lenisVersion="0.2.9",s.options={duration:h,easing:u,smooth:f,smoothTouch:g,touchMultiplier:m,direction:b,gestureDirection:N,wrapper:z,content:W},s.duration=h,s.easing=u,s.smooth=f,s.smoothTouch=g,s.touchMultiplier=m,s.direction=b,s.gestureDirection=N,s.wrapperNode=z,s.contentNode=W,s.wrapperNode.addEventListener("scroll",s.onScroll),s.wrapperNode===window?(s.wrapperNode.addEventListener("resize",s.onWindowResize),s.onWindowResize()):(s.wrapperHeight=s.wrapperNode.offsetHeight,s.wrapperWidth=s.wrapperNode.offsetWidth,s.wrapperObserver=new ResizeObserver(s.onWrapperResize),s.wrapperObserver.observe(s.wrapperNode)),s.contentHeight=s.contentNode.offsetHeight,s.contentWidth=s.contentNode.offsetWidth,s.contentObserver=new ResizeObserver(s.onContentResize),s.contentObserver.observe(s.contentNode),s.targetScroll=s.scroll=s.lastScroll=s.wrapperNode[s.scrollProperty],s.animate=new l;var T=(null==(i=navigator)||null==(r=i.userAgentData)?void 0:r.platform)||(null==(n=navigator)?void 0:n.platform)||"unknown";return s.virtualScroll=new e({el:s.wrapperNode,firefoxMultiplier:50,mouseMultiplier:T.includes("Win")?1:.4,useKeyboard:!1,touchMultiplier:s.touchMultiplier,useTouch:!0,passive:!1}),s.virtualScroll.on(s.onVirtualScroll),s}r=t,(o=s).prototype=Object.create(r.prototype),o.prototype.constructor=o,n(o,r);var c=s.prototype;return c.start=function(){this.stopped=!1},c.stop=function(){this.stopped=!0,this.animate.stop()},c.destroy=function(){var t;this.wrapperNode===window&&this.wrapperNode.removeEventListener("resize",this.onWindowResize),this.wrapperNode.removeEventListener("scroll",this.onScroll),this.virtualScroll.destroy(),null==(t=this.wrapperObserver)||t.disconnect(),this.contentObserver.disconnect()},c.raf=function(t){var e=t-(this.now||0);this.now=t,!this.stopped&&this.smooth&&(this.lastScroll=this.scroll,this.animate.raf(e),this.scroll===this.targetScroll&&(this.lastScroll=this.scroll),this.isScrolling&&(this.setScroll(this.scroll),this.notify()),this.isScrolling=this.scroll!==this.targetScroll)},c.setScroll=function(t){"horizontal"===this.direction?this.wrapperNode.scrollTo(t,0):this.wrapperNode.scrollTo(0,t)},c.notify=function(){this.emit("scroll",{scroll:this.scroll,limit:this.limit,velocity:this.velocity,direction:this.direction,progress:this.scroll/this.limit})},c.scrollTo=function(t,e){var o=void 0===e?{}:e,i=o.offset,r=void 0===i?0:i,n=o.immediate,s=void 0!==n&&n,l=o.duration,c=void 0===l?this.duration:l,a=o.easing,h=void 0===a?this.easing:a;if(null!=t){var p;if("number"==typeof t)p=t;else if("top"===t||"#top"===t)p=0;else if("bottom"===t)p=this.limit;else{var u;if("string"==typeof t)u=document.querySelector(t);else{if(null==t||!t.nodeType)return;u=t}if(!u)return;var d=0;if(this.wrapperNode!==window){var f=this.wrapperNode.getBoundingClientRect();d="horizontal"===this.direction?f.left:f.top}var v=u.getBoundingClientRect();p=("horizontal"===this.direction?v.left:v.top)+this.scroll-d}this.targetScroll=p+=r,!this.smooth||s?this.setScroll(this.targetScroll):this.animate.to(this,{duration:c,easing:h,scroll:this.targetScroll})}},i(s,[{key:"scrollProperty",get:function(){return this.wrapperNode===window?"horizontal"===this.direction?"scrollX":"scrollY":"horizontal"===this.direction?"scrollLeft":"scrollTop"}},{key:"limit",get:function(){return"horizontal"===this.direction?this.contentWidth-this.wrapperWidth:this.contentHeight-this.wrapperHeight}},{key:"velocity",get:function(){return this.scroll-this.lastScroll}}]),s}(t);export{c as default}; +import t from"tiny-emitter";import e from"virtual-scroll";function o(t,e){for(var o=0;o=0||(r[o]=t[o]);return r}(i,l);this.target=t,this.fromKeys=r({},h),this.toKeys=r({},h),this.keys=Object.keys(r({},h)),this.keys.forEach(function(e){o.fromKeys[e]=t[e]}),this.duration=s,this.easing=a,this.currentTime=0,this.isRunning=!0},e.stop=function(){this.isRunning=!1},e.raf=function(t){var e=this;if(this.isRunning){this.currentTime=Math.min(this.currentTime+t,this.duration);var o=this.easing(this.progress);this.keys.forEach(function(t){var i=e.fromKeys[t];e.target[t]=i+(e.toKeys[t]-i)*o}),1===o&&this.stop()}},i(t,[{key:"progress",get:function(){return this.currentTime/this.duration}}]),t}(),a=/*#__PURE__*/function(t){var o,r;function l(o){var i,r,n,l,a=void 0===o?{}:o,h=a.duration,p=void 0===h?1.2:h,u=a.easing,d=void 0===u?function(t){return 1===t?1:1-Math.pow(2,-10*t)}:u,f=a.smooth,v=void 0===f||f,g=a.smoothTouch,w=void 0!==g&&g,m=a.touchMultiplier,y=void 0===m?2:m,b=a.direction,S=void 0===b?"vertical":b,N=a.gestureDirection,O=void 0===N?"vertical":N,z=a.wrapper,R=void 0===z?window:z,W=a.content,T=void 0===W?document.body:W;(l=t.call(this)||this).onWindowResize=function(){l.wrapperWidth=window.innerWidth,l.wrapperHeight=window.innerHeight},l.onWrapperResize=function(t){var e=t[0];if(e){var o=e.contentRect;l.wrapperWidth=o.width,l.wrapperHeight=o.height}},l.onContentResize=function(t){var e=t[0];if(e){var o=e.contentRect;l.contentWidth=o.width,l.contentHeight=o.height}},l.onVirtualScroll=function(t){var e=t.deltaY,o=t.deltaX,i=t.originalEvent;i.ctrlKey||(l.smooth=i.changedTouches?l.smoothTouch:l.options.smooth,l.stopped?i.preventDefault():l.smooth&&4!==i.buttons&&(l.smooth&&i.preventDefault(),l.targetScroll-="both"===l.gestureDirection?o+e:"horizontal"===l.gestureDirection?o:e,l.targetScroll=s(0,l.targetScroll,l.limit),l.scrollTo(l.targetScroll)))},l.onScroll=function(t){l.isScrolling&&l.smooth||(l.targetScroll=l.scroll=l.lastScroll=l.wrapperNode[l.scrollProperty],l.notify())},window.lenisVersion="0.2.10",l.options={duration:p,easing:d,smooth:v,smoothTouch:w,touchMultiplier:y,direction:S,gestureDirection:O,wrapper:R,content:T},l.duration=p,l.easing=d,l.smooth=v,l.smoothTouch=w,l.touchMultiplier=y,l.direction=S,l.gestureDirection=O,l.wrapperNode=R,l.contentNode=T,l.wrapperNode.addEventListener("scroll",l.onScroll),l.wrapperNode===window?(l.wrapperNode.addEventListener("resize",l.onWindowResize),l.onWindowResize()):(l.wrapperHeight=l.wrapperNode.offsetHeight,l.wrapperWidth=l.wrapperNode.offsetWidth,l.wrapperObserver=new ResizeObserver(l.onWrapperResize),l.wrapperObserver.observe(l.wrapperNode)),l.contentHeight=l.contentNode.offsetHeight,l.contentWidth=l.contentNode.offsetWidth,l.contentObserver=new ResizeObserver(l.onContentResize),l.contentObserver.observe(l.contentNode),l.targetScroll=l.scroll=l.lastScroll=l.wrapperNode[l.scrollProperty],l.animate=new c;var k=(null==(i=navigator)||null==(r=i.userAgentData)?void 0:r.platform)||(null==(n=navigator)?void 0:n.platform)||"unknown";return l.virtualScroll=new e({el:l.wrapperNode,firefoxMultiplier:50,mouseMultiplier:k.includes("Win")?1:.4,useKeyboard:!1,touchMultiplier:l.touchMultiplier,useTouch:!0,passive:!1}),l.virtualScroll.on(l.onVirtualScroll),l}r=t,(o=l).prototype=Object.create(r.prototype),o.prototype.constructor=o,n(o,r);var a=l.prototype;return a.start=function(){this.stopped=!1},a.stop=function(){this.stopped=!0,this.animate.stop()},a.destroy=function(){var t;this.wrapperNode===window&&this.wrapperNode.removeEventListener("resize",this.onWindowResize),this.wrapperNode.removeEventListener("scroll",this.onScroll),this.virtualScroll.destroy(),null==(t=this.wrapperObserver)||t.disconnect(),this.contentObserver.disconnect()},a.raf=function(t){var e=t-(this.now||0);this.now=t,!this.stopped&&this.smooth&&(this.lastScroll=this.scroll,this.animate.raf(.001*e),this.scroll===this.targetScroll&&(this.lastScroll=this.scroll),this.isScrolling&&(this.setScroll(this.scroll),this.notify()),this.isScrolling=this.scroll!==this.targetScroll)},a.setScroll=function(t){"horizontal"===this.direction?this.wrapperNode.scrollTo(t,0):this.wrapperNode.scrollTo(0,t)},a.notify=function(){this.emit("scroll",{scroll:this.scroll,limit:this.limit,velocity:this.velocity,direction:this.direction,progress:this.scroll/this.limit})},a.scrollTo=function(t,e){var o=void 0===e?{}:e,i=o.offset,r=void 0===i?0:i,n=o.immediate,l=void 0!==n&&n,c=o.duration,a=void 0===c?this.duration:c,h=o.easing,p=void 0===h?this.easing:h;if(null!=t){var u;if("number"==typeof t)u=t;else if("top"===t||"#top"===t)u=0;else if("bottom"===t)u=this.limit;else{var d;if("string"==typeof t)d=document.querySelector(t);else{if(null==t||!t.nodeType)return;d=t}if(!d)return;var f=0;if(this.wrapperNode!==window){var v=this.wrapperNode.getBoundingClientRect();f="horizontal"===this.direction?v.left:v.top}var g=d.getBoundingClientRect();u=("horizontal"===this.direction?g.left:g.top)+this.scroll-f}this.targetScroll=s(0,u+=r,this.limit),!this.smooth||l?this.setScroll(this.targetScroll):this.animate.to(this,{duration:a,easing:p,scroll:this.targetScroll})}},i(l,[{key:"scrollProperty",get:function(){return this.wrapperNode===window?"horizontal"===this.direction?"scrollX":"scrollY":"horizontal"===this.direction?"scrollLeft":"scrollTop"}},{key:"limit",get:function(){return"horizontal"===this.direction?this.contentWidth-this.wrapperWidth:this.contentHeight-this.wrapperHeight}},{key:"velocity",get:function(){return this.scroll-this.lastScroll}}]),l}(t);export{a as default}; //# sourceMappingURL=lenis.mjs.map diff --git a/dist/lenis.mjs.map b/dist/lenis.mjs.map index de8071c2..8af1f169 100644 --- a/dist/lenis.mjs.map +++ b/dist/lenis.mjs.map @@ -1 +1 @@ -{"version":3,"file":"lenis.mjs","sources":["../src/lenis.js","../src/maths.js"],"sourcesContent":["import EventEmitter from 'tiny-emitter'\r\nimport VirtualScroll from 'virtual-scroll'\r\nimport { version } from '../package.json'\r\nimport { clamp } from './maths.js'\r\n\r\nclass Animate {\r\n to(target, { duration = 1, easing = (t) => t, ...keys } = {}) {\r\n this.target = target\r\n this.fromKeys = { ...keys }\r\n this.toKeys = { ...keys }\r\n this.keys = Object.keys({ ...keys })\r\n\r\n // get initial values\r\n this.keys.forEach((key) => {\r\n this.fromKeys[key] = target[key]\r\n })\r\n\r\n this.duration = duration\r\n this.easing = easing\r\n this.currentTime = 0\r\n this.isRunning = true\r\n }\r\n\r\n stop() {\r\n this.isRunning = false\r\n }\r\n\r\n raf(deltaTime) {\r\n if (!this.isRunning) return\r\n\r\n this.currentTime = Math.min(\r\n this.currentTime + deltaTime * 0.001,\r\n this.duration\r\n )\r\n\r\n const progress = this.easing(this.progress)\r\n\r\n this.keys.forEach((key) => {\r\n const from = this.fromKeys[key]\r\n const to = this.toKeys[key]\r\n\r\n const value = from + (to - from) * progress\r\n\r\n this.target[key] = value\r\n })\r\n\r\n if (progress === 1) {\r\n this.isRunning = false\r\n }\r\n }\r\n\r\n get progress() {\r\n return this.currentTime / this.duration\r\n }\r\n}\r\n\r\nexport default class Lenis extends EventEmitter {\r\n constructor({\r\n duration = 1.2,\r\n easing = (t) => (t === 1 ? 1 : 1 - Math.pow(2, -10 * t)), // https://easings.net/en#easeOutExpo\r\n smooth = true,\r\n smoothTouch = false,\r\n touchMultiplier = 2,\r\n direction = 'vertical', // vertical, horizontal\r\n gestureDirection = 'vertical', // vertical, horizontal, both\r\n wrapper = window,\r\n content = document.body,\r\n } = {}) {\r\n super()\r\n\r\n window.lenisVersion = version\r\n\r\n this.options = {\r\n duration,\r\n easing,\r\n smooth,\r\n smoothTouch,\r\n touchMultiplier,\r\n direction,\r\n gestureDirection,\r\n wrapper,\r\n content,\r\n }\r\n\r\n this.duration = duration\r\n this.easing = easing\r\n this.smooth = smooth\r\n this.smoothTouch = smoothTouch\r\n this.touchMultiplier = touchMultiplier\r\n this.direction = direction\r\n this.gestureDirection = gestureDirection\r\n this.wrapperNode = wrapper\r\n this.contentNode = content\r\n\r\n this.wrapperNode.addEventListener('scroll', this.onScroll)\r\n\r\n //observe wrapper node size\r\n if (this.wrapperNode === window) {\r\n this.wrapperNode.addEventListener('resize', this.onWindowResize)\r\n this.onWindowResize()\r\n } else {\r\n this.wrapperHeight = this.wrapperNode.offsetHeight\r\n this.wrapperWidth = this.wrapperNode.offsetWidth\r\n\r\n //observe wrapper node size\r\n this.wrapperObserver = new ResizeObserver(this.onWrapperResize)\r\n this.wrapperObserver.observe(this.wrapperNode)\r\n }\r\n\r\n this.contentHeight = this.contentNode.offsetHeight\r\n this.contentWidth = this.contentNode.offsetWidth\r\n\r\n //observe content node size\r\n this.contentObserver = new ResizeObserver(this.onContentResize)\r\n this.contentObserver.observe(this.contentNode)\r\n\r\n //set initial scroll position\r\n this.targetScroll =\r\n this.scroll =\r\n this.lastScroll =\r\n this.wrapperNode[this.scrollProperty]\r\n\r\n this.animate = new Animate()\r\n\r\n const platform =\r\n navigator?.userAgentData?.platform || navigator?.platform || 'unknown'\r\n\r\n // listen and normalize wheel event cross-browser\r\n this.virtualScroll = new VirtualScroll({\r\n el: this.wrapperNode,\r\n firefoxMultiplier: 50,\r\n mouseMultiplier: platform.includes('Win') ? 1 : 0.4,\r\n useKeyboard: false,\r\n touchMultiplier: this.touchMultiplier,\r\n useTouch: true,\r\n passive: false,\r\n })\r\n\r\n this.virtualScroll.on(this.onVirtualScroll)\r\n }\r\n\r\n get scrollProperty() {\r\n let property\r\n if (this.wrapperNode === window) {\r\n property = this.direction === 'horizontal' ? 'scrollX' : 'scrollY'\r\n } else {\r\n property = this.direction === 'horizontal' ? 'scrollLeft' : 'scrollTop'\r\n }\r\n return property\r\n }\r\n\r\n start() {\r\n this.stopped = false\r\n }\r\n\r\n stop() {\r\n this.stopped = true\r\n this.animate.stop()\r\n }\r\n\r\n destroy() {\r\n if (this.wrapperNode === window) {\r\n this.wrapperNode.removeEventListener('resize', this.onWindowResize)\r\n }\r\n this.wrapperNode.removeEventListener('scroll', this.onScroll)\r\n\r\n this.virtualScroll.destroy()\r\n this.wrapperObserver?.disconnect()\r\n this.contentObserver.disconnect()\r\n }\r\n\r\n onWindowResize = () => {\r\n this.wrapperWidth = window.innerWidth\r\n this.wrapperHeight = window.innerHeight\r\n }\r\n\r\n onWrapperResize = ([entry]) => {\r\n if (entry) {\r\n const rect = entry.contentRect\r\n this.wrapperWidth = rect.width\r\n this.wrapperHeight = rect.height\r\n }\r\n }\r\n\r\n onContentResize = ([entry]) => {\r\n if (entry) {\r\n const rect = entry.contentRect\r\n this.contentWidth = rect.width\r\n this.contentHeight = rect.height\r\n }\r\n }\r\n\r\n get limit() {\r\n return this.direction === 'horizontal'\r\n ? this.contentWidth - this.wrapperWidth\r\n : this.contentHeight - this.wrapperHeight\r\n }\r\n\r\n onVirtualScroll = ({ deltaY, deltaX, originalEvent: e }) => {\r\n if (e.ctrlKey) return\r\n\r\n // switch to smooth if event is touch and touch is true\r\n this.smooth = !!e.changedTouches ? this.smoothTouch : this.options.smooth\r\n\r\n if (this.stopped) {\r\n e.preventDefault()\r\n return\r\n }\r\n\r\n if (!this.smooth) return\r\n\r\n // fix wheel holding scroll https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/buttons\r\n if (e.buttons === 4) return\r\n\r\n // prevent native wheel scrolling\r\n if (this.smooth) e.preventDefault()\r\n\r\n let delta = 0\r\n if (this.gestureDirection === 'both') {\r\n delta = deltaX + deltaY\r\n } else if (this.gestureDirection === 'horizontal') {\r\n delta = deltaX\r\n } else {\r\n // vertical\r\n delta = deltaY\r\n }\r\n\r\n this.targetScroll -= delta\r\n this.targetScroll = clamp(0, this.targetScroll, this.limit)\r\n\r\n this.scrollTo(this.targetScroll)\r\n }\r\n\r\n raf(now) {\r\n const deltaTime = now - (this.now || 0)\r\n this.now = now\r\n\r\n if (this.stopped || !this.smooth) return\r\n\r\n this.lastScroll = this.scroll\r\n\r\n // where this.scroll is updated\r\n this.animate.raf(deltaTime)\r\n\r\n if (this.scroll === this.targetScroll) {\r\n // if target reached velocity should be 0\r\n this.lastScroll = this.scroll\r\n }\r\n\r\n if (this.isScrolling) {\r\n this.setScroll(this.scroll)\r\n this.notify()\r\n }\r\n\r\n this.isScrolling = this.scroll !== this.targetScroll\r\n }\r\n\r\n get velocity() {\r\n return this.scroll - this.lastScroll\r\n }\r\n\r\n setScroll(value) {\r\n this.direction === 'horizontal'\r\n ? this.wrapperNode.scrollTo(value, 0)\r\n : this.wrapperNode.scrollTo(0, value)\r\n }\r\n\r\n onScroll = (e) => {\r\n // if isScrolling false we can consider user isn't scrolling with wheel (cmd+F, keyboard or whatever). So we must scroll to value immediately\r\n if (!this.isScrolling || !this.smooth) {\r\n // where native scroll happens\r\n this.targetScroll =\r\n this.scroll =\r\n this.lastScroll =\r\n this.wrapperNode[this.scrollProperty]\r\n\r\n this.notify()\r\n }\r\n }\r\n\r\n notify() {\r\n this.emit('scroll', {\r\n scroll: this.scroll,\r\n limit: this.limit,\r\n velocity: this.velocity,\r\n direction: this.direction,\r\n progress: this.scroll / this.limit,\r\n })\r\n }\r\n\r\n scrollTo(\r\n target,\r\n {\r\n offset = 0,\r\n immediate = false,\r\n duration = this.duration,\r\n easing = this.easing,\r\n } = {}\r\n ) {\r\n if (target === undefined || target === null) return\r\n let value\r\n\r\n if (typeof target === 'number') {\r\n value = target\r\n } else if (target === 'top' || target === '#top') {\r\n value = 0\r\n } else if (target === 'bottom') {\r\n value = 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 } else {\r\n return\r\n }\r\n\r\n if (!node) return\r\n let wrapperOffset = 0\r\n\r\n if (this.wrapperNode !== window) {\r\n const wrapperRect = this.wrapperNode.getBoundingClientRect()\r\n wrapperOffset =\r\n this.direction === 'horizontal' ? wrapperRect.left : wrapperRect.top\r\n }\r\n\r\n const rect = node.getBoundingClientRect()\r\n\r\n value =\r\n (this.direction === 'horizontal' ? rect.left : rect.top) +\r\n this.scroll -\r\n wrapperOffset\r\n }\r\n\r\n value += offset\r\n\r\n this.targetScroll = value\r\n\r\n if (!this.smooth || immediate) {\r\n this.setScroll(this.targetScroll)\r\n } else {\r\n this.animate.to(this, {\r\n duration,\r\n easing,\r\n scroll: this.targetScroll,\r\n })\r\n }\r\n }\r\n}\r\n","export function clamp(min, input, max) {\r\n return Math.max(min, Math.min(input, max))\r\n}\r\n\r\nexport function mapRange(in_min, in_max, input, out_min, out_max) {\r\n return ((input - in_min) * (out_max - out_min)) / (in_max - in_min) + out_min\r\n}\r\n\r\nexport function lerp(start, end, amt) {\r\n return (1 - amt) * start + amt * end\r\n}\r\n\r\nexport function truncate(value, decimals) {\r\n return parseFloat(value.toFixed(decimals))\r\n}\r\n"],"names":["_excluded","Lenis","to","target","_temp","_this","this","_ref","duration","_ref$duration","_ref$easing","easing","t","keys","fromKeys","toKeys","_extends","Object","forEach","key","currentTime","isRunning","stop","raf","deltaTime","_this2","Math","min","progress","from","_temp2","_navigator","_navigator$userAgentD","_navigator2","_this3","_ref2","_ref2$duration","_ref2$easing","pow","smooth","_ref2$smooth","smoothTouch","_ref2$smoothTouch","_ref2$touchMultiplier","touchMultiplier","_ref2$direction","direction","gestureDirection","_ref2$gestureDirectio","wrapper","_ref2$wrapper","window","content","_ref2$content","document","body","_EventEmitter","call","onWindowResize","wrapperWidth","innerWidth","wrapperHeight","innerHeight","onWrapperResize","_ref3","entry","rect","contentRect","width","height","onContentResize","_ref4","contentWidth","contentHeight","onVirtualScroll","_ref5","deltaY","deltaX","e","originalEvent","ctrlKey","changedTouches","options","stopped","preventDefault","buttons","targetScroll","max","limit","scrollTo","onScroll","isScrolling","scroll","lastScroll","wrapperNode","scrollProperty","notify","lenisVersion","contentNode","addEventListener","offsetHeight","offsetWidth","wrapperObserver","observe","contentObserver","ResizeObserver","animate","Animate","platform","navigator","userAgentData","virtualScroll","VirtualScroll","el","firefoxMultiplier","mouseMultiplier","includes","useKeyboard","useTouch","passive","on","EventEmitter","start","destroy","_this$wrapperObserver","removeEventListener","disconnect","now","setScroll","value","emit","velocity","_temp3","_ref6","_ref6$offset","offset","_ref6$immediate","immediate","_ref6$duration","node","querySelector","nodeType","wrapperOffset","wrapperRect","getBoundingClientRect","left","top","_createClass","get"],"mappings":"yqBAAA,IAAAA,EAAA,CAAA,WAAA,oEAwDqBC,SAlDnBC,GAAA,SAAGC,EAA2DC,GAAA,IAAAC,EAAAC,KAAAC,OAAA,IAAAH,EAAJ,CAAA,EAA7CI,EAAAA,EAAAA,EAAAA,SAAAA,aAAW,EAAsCC,EAAAC,EAAAH,EAAnCI,OAAAA,aAAS,SAACC,GAAMA,OAAAA,CAAP,EAAaC,EAAAA,0IAC/CP,KAAKH,OAASA,EACdG,KAAKQ,cAAgBD,GACrBP,KAAKS,OAALC,EAAA,CAAA,EAAmBH,GACnBP,KAAKO,KAAOI,OAAOJ,UAAUA,IAG7BP,KAAKO,KAAKK,QAAQ,SAACC,GACjBd,EAAKS,SAASK,GAAOhB,EAAOgB,EAC7B,GAEDb,KAAKE,SAAWA,EAChBF,KAAKK,OAASA,EACdL,KAAKc,YAAc,EACnBd,KAAKe,WAAY,CAClB,IAEDC,KAAA,WACEhB,KAAKe,WAAY,CAClB,IAEDE,IAAA,SAAIC,GAAW,IAAAC,EAA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AAXA,GAA+B,SAAXA,EAC7B8H,EAAQ,OACH,GAAe,WAAX9H,EACT8H,EAAQ3H,KAAKkF,UACR,CACL,IAAImD,EAEJ,GAAsB,mBAEpBA,EAAOrF,SAASsF,cAAczI,OACzB,IAAIA,MAAAA,IAAAA,EAAQ0I,SAIjB,OAFAF,EAAOxI,CAGR,CAED,IAAKwI,EAAM,OACX,IAAiBG,EAAG,EAEpB,GAAIxI,KAAKwF,cAAgB3C,OAAQ,CAC/B,IAAM4F,EAAczI,KAAKwF,YAAYkD,wBACrCF,EACqB,eAAnBxI,KAAKwC,UAA6BiG,EAAYE,KAAOF,EAAYG,GACpE,CAED,IAAUhF,EAAGyE,EAAKK,wBAElBf,GACsB,eAAnB3H,KAAKwC,UAA6BoB,EAAK+E,KAAO/E,EAAKgF,KACpD5I,KAAKsF,OACLkD,CACH,CAIDxI,KAAKgF,aAFL2C,GAASM,GAIJjI,KAAKiC,QAAUkG,EAClBnI,KAAK0H,UAAU1H,KAAKgF,cAEpBhF,KAAKoG,QAAQxG,GAAGI,KAAM,CACpBE,SAAAA,EACAG,OAAAA,EACAiF,OAAQtF,KAAKgF,cAjD4B,CAoD9C,EAlND6D,EAAAlJ,EAAA,CAAA,CAAAkB,IAAA,iBAAAiI,IAAA,WAOE,OALI9I,KAAKwF,cAAgB3C,OACO,eAAnB7C,KAAKwC,UAA6B,UAAY,UAE3B,eAAnBxC,KAAKwC,UAA6B,aAAe,WAG/D,GA2CD,CAAA3B,IAAA,QAAAiI,IAAA,WACE,MAA0B,oBAAdtG,UACRxC,KAAKkE,aAAelE,KAAKqD,aACzBrD,KAAKmE,cAAgBnE,KAAKuD,aAC/B,uBA6DD,WACE,OAAY+B,KAAAA,OAAStF,KAAKuF,UAC3B,KA3MgC4B,CAAAA,EAAAA"} \ No newline at end of file +{"version":3,"file":"lenis.mjs","sources":["../src/maths.js","../src/lenis.js"],"sourcesContent":["export function clamp(min, input, max) {\r\n return Math.max(min, Math.min(input, max))\r\n}\r\n\r\nexport function mapRange(in_min, in_max, input, out_min, out_max) {\r\n return ((input - in_min) * (out_max - out_min)) / (in_max - in_min) + out_min\r\n}\r\n\r\nexport function lerp(start, end, amt) {\r\n return (1 - amt) * start + amt * end\r\n}\r\n\r\nexport function truncate(value, decimals) {\r\n return parseFloat(value.toFixed(decimals))\r\n}\r\n","import EventEmitter from 'tiny-emitter'\r\nimport VirtualScroll from 'virtual-scroll'\r\nimport { version } from '../package.json'\r\nimport { clamp } from './maths.js'\r\n\r\nclass Animate {\r\n to(target, { duration = 1, easing = (t) => t, ...keys } = {}) {\r\n this.target = target\r\n this.fromKeys = { ...keys }\r\n this.toKeys = { ...keys }\r\n this.keys = Object.keys({ ...keys })\r\n\r\n // get initial values\r\n this.keys.forEach((key) => {\r\n this.fromKeys[key] = target[key]\r\n })\r\n\r\n this.duration = duration\r\n this.easing = easing\r\n this.currentTime = 0\r\n this.isRunning = true\r\n }\r\n\r\n stop() {\r\n this.isRunning = false\r\n }\r\n\r\n raf(deltaTime) {\r\n if (!this.isRunning) return\r\n\r\n this.currentTime = Math.min(this.currentTime + deltaTime, this.duration)\r\n\r\n const progress = this.easing(this.progress)\r\n\r\n this.keys.forEach((key) => {\r\n const from = this.fromKeys[key]\r\n const to = this.toKeys[key]\r\n\r\n const value = from + (to - from) * progress\r\n\r\n this.target[key] = value\r\n })\r\n\r\n if (progress === 1) {\r\n this.stop()\r\n }\r\n }\r\n\r\n get progress() {\r\n return this.currentTime / this.duration\r\n }\r\n}\r\n\r\nexport default class Lenis extends EventEmitter {\r\n constructor({\r\n duration = 1.2,\r\n easing = (t) => (t === 1 ? 1 : 1 - Math.pow(2, -10 * t)), // https://easings.net/en#easeOutExpo\r\n smooth = true,\r\n smoothTouch = false,\r\n touchMultiplier = 2,\r\n direction = 'vertical', // vertical, horizontal\r\n gestureDirection = 'vertical', // vertical, horizontal, both\r\n wrapper = window,\r\n content = document.body,\r\n } = {}) {\r\n super()\r\n\r\n window.lenisVersion = version\r\n\r\n this.options = {\r\n duration,\r\n easing,\r\n smooth,\r\n smoothTouch,\r\n touchMultiplier,\r\n direction,\r\n gestureDirection,\r\n wrapper,\r\n content,\r\n }\r\n\r\n this.duration = duration\r\n this.easing = easing\r\n this.smooth = smooth\r\n this.smoothTouch = smoothTouch\r\n this.touchMultiplier = touchMultiplier\r\n this.direction = direction\r\n this.gestureDirection = gestureDirection\r\n this.wrapperNode = wrapper\r\n this.contentNode = content\r\n\r\n this.wrapperNode.addEventListener('scroll', this.onScroll)\r\n\r\n //observe wrapper node size\r\n if (this.wrapperNode === window) {\r\n this.wrapperNode.addEventListener('resize', this.onWindowResize)\r\n this.onWindowResize()\r\n } else {\r\n this.wrapperHeight = this.wrapperNode.offsetHeight\r\n this.wrapperWidth = this.wrapperNode.offsetWidth\r\n\r\n //observe wrapper node size\r\n this.wrapperObserver = new ResizeObserver(this.onWrapperResize)\r\n this.wrapperObserver.observe(this.wrapperNode)\r\n }\r\n\r\n this.contentHeight = this.contentNode.offsetHeight\r\n this.contentWidth = this.contentNode.offsetWidth\r\n\r\n //observe content node size\r\n this.contentObserver = new ResizeObserver(this.onContentResize)\r\n this.contentObserver.observe(this.contentNode)\r\n\r\n //set initial scroll position\r\n this.targetScroll =\r\n this.scroll =\r\n this.lastScroll =\r\n this.wrapperNode[this.scrollProperty]\r\n\r\n this.animate = new Animate()\r\n\r\n const platform =\r\n navigator?.userAgentData?.platform || navigator?.platform || 'unknown'\r\n\r\n // listen and normalize wheel event cross-browser\r\n this.virtualScroll = new VirtualScroll({\r\n el: this.wrapperNode,\r\n firefoxMultiplier: 50,\r\n mouseMultiplier: platform.includes('Win') ? 1 : 0.4,\r\n useKeyboard: false,\r\n touchMultiplier: this.touchMultiplier,\r\n useTouch: true,\r\n passive: false,\r\n })\r\n\r\n this.virtualScroll.on(this.onVirtualScroll)\r\n }\r\n\r\n get scrollProperty() {\r\n let property\r\n if (this.wrapperNode === window) {\r\n property = this.direction === 'horizontal' ? 'scrollX' : 'scrollY'\r\n } else {\r\n property = this.direction === 'horizontal' ? 'scrollLeft' : 'scrollTop'\r\n }\r\n return property\r\n }\r\n\r\n start() {\r\n this.stopped = false\r\n }\r\n\r\n stop() {\r\n this.stopped = true\r\n this.animate.stop()\r\n }\r\n\r\n destroy() {\r\n if (this.wrapperNode === window) {\r\n this.wrapperNode.removeEventListener('resize', this.onWindowResize)\r\n }\r\n this.wrapperNode.removeEventListener('scroll', this.onScroll)\r\n\r\n this.virtualScroll.destroy()\r\n this.wrapperObserver?.disconnect()\r\n this.contentObserver.disconnect()\r\n }\r\n\r\n onWindowResize = () => {\r\n this.wrapperWidth = window.innerWidth\r\n this.wrapperHeight = window.innerHeight\r\n }\r\n\r\n onWrapperResize = ([entry]) => {\r\n if (entry) {\r\n const rect = entry.contentRect\r\n this.wrapperWidth = rect.width\r\n this.wrapperHeight = rect.height\r\n }\r\n }\r\n\r\n onContentResize = ([entry]) => {\r\n if (entry) {\r\n const rect = entry.contentRect\r\n this.contentWidth = rect.width\r\n this.contentHeight = rect.height\r\n }\r\n }\r\n\r\n get limit() {\r\n return this.direction === 'horizontal'\r\n ? this.contentWidth - this.wrapperWidth\r\n : this.contentHeight - this.wrapperHeight\r\n }\r\n\r\n onVirtualScroll = ({ deltaY, deltaX, originalEvent: e }) => {\r\n if (e.ctrlKey) return\r\n\r\n // switch to smooth if event is touch and touch is true\r\n this.smooth = !!e.changedTouches ? this.smoothTouch : this.options.smooth\r\n\r\n if (this.stopped) {\r\n e.preventDefault()\r\n return\r\n }\r\n\r\n if (!this.smooth) return\r\n\r\n // fix wheel holding scroll https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/buttons\r\n if (e.buttons === 4) return\r\n\r\n // prevent native wheel scrolling\r\n if (this.smooth) e.preventDefault()\r\n\r\n let delta = 0\r\n if (this.gestureDirection === 'both') {\r\n delta = deltaX + deltaY\r\n } else if (this.gestureDirection === 'horizontal') {\r\n delta = deltaX\r\n } else {\r\n // vertical\r\n delta = deltaY\r\n }\r\n\r\n this.targetScroll -= delta\r\n this.targetScroll = clamp(0, this.targetScroll, this.limit)\r\n\r\n this.scrollTo(this.targetScroll)\r\n }\r\n\r\n raf(now) {\r\n const deltaTime = now - (this.now || 0)\r\n this.now = now\r\n\r\n if (this.stopped || !this.smooth) return\r\n\r\n this.lastScroll = this.scroll\r\n\r\n // where this.scroll is updated\r\n this.animate.raf(deltaTime * 0.001)\r\n\r\n if (this.scroll === this.targetScroll) {\r\n // if target reached velocity should be 0\r\n this.lastScroll = this.scroll\r\n }\r\n\r\n if (this.isScrolling) {\r\n this.setScroll(this.scroll)\r\n this.notify()\r\n }\r\n\r\n this.isScrolling = this.scroll !== this.targetScroll\r\n }\r\n\r\n get velocity() {\r\n return this.scroll - this.lastScroll\r\n }\r\n\r\n setScroll(value) {\r\n this.direction === 'horizontal'\r\n ? this.wrapperNode.scrollTo(value, 0)\r\n : this.wrapperNode.scrollTo(0, value)\r\n }\r\n\r\n onScroll = (e) => {\r\n // if isScrolling false we can consider user isn't scrolling with wheel (cmd+F, keyboard or whatever). So we must scroll to value immediately\r\n if (!this.isScrolling || !this.smooth) {\r\n // where native scroll happens\r\n this.targetScroll =\r\n this.scroll =\r\n this.lastScroll =\r\n this.wrapperNode[this.scrollProperty]\r\n\r\n this.notify()\r\n }\r\n }\r\n\r\n notify() {\r\n this.emit('scroll', {\r\n scroll: this.scroll,\r\n limit: this.limit,\r\n velocity: this.velocity,\r\n direction: this.direction,\r\n progress: this.scroll / this.limit,\r\n })\r\n }\r\n\r\n scrollTo(\r\n target,\r\n {\r\n offset = 0,\r\n immediate = false,\r\n duration = this.duration,\r\n easing = this.easing,\r\n } = {}\r\n ) {\r\n if (target === undefined || target === null) return\r\n let value\r\n\r\n if (typeof target === 'number') {\r\n value = target\r\n } else if (target === 'top' || target === '#top') {\r\n value = 0\r\n } else if (target === 'bottom') {\r\n value = 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 } else {\r\n return\r\n }\r\n\r\n if (!node) return\r\n let wrapperOffset = 0\r\n\r\n if (this.wrapperNode !== window) {\r\n const wrapperRect = this.wrapperNode.getBoundingClientRect()\r\n wrapperOffset =\r\n this.direction === 'horizontal' ? wrapperRect.left : wrapperRect.top\r\n }\r\n\r\n const rect = node.getBoundingClientRect()\r\n\r\n value =\r\n (this.direction === 'horizontal' ? rect.left : rect.top) +\r\n this.scroll -\r\n wrapperOffset\r\n }\r\n\r\n value += offset\r\n\r\n this.targetScroll = clamp(0, value, this.limit)\r\n\r\n if (!this.smooth || immediate) {\r\n this.setScroll(this.targetScroll)\r\n } else {\r\n this.animate.to(this, {\r\n duration,\r\n easing,\r\n scroll: this.targetScroll,\r\n })\r\n }\r\n }\r\n}\r\n"],"names":["min","input","max","Math","_excluded","to","target","_temp","_this","this","_ref","duration","_ref$duration","_ref$easing","easing","t","keys","fromKeys","toKeys","_extends","Object","forEach","key","currentTime","isRunning","stop","raf","deltaTime","_this2","progress","from","_createClass","Animate","get","_navigator","_navigator$userAgentD","_navigator2","_this3","_ref2","_temp2","_ref2$duration","_ref2$easing","pow","_ref2$smooth","smooth","smoothTouch","_ref2$smoothTouch","touchMultiplier","_ref2$touchMultiplier","direction","_ref2$direction","gestureDirection","_ref2$gestureDirectio","wrapper","_ref2$wrapper","window","content","document","body","_ref2$content","_EventEmitter","call","onWindowResize","wrapperWidth","innerWidth","wrapperHeight","innerHeight","onWrapperResize","entry","contentRect","rect","width","height","onContentResize","_ref4","contentWidth","contentHeight","onVirtualScroll","_ref5","deltaY","deltaX","e","originalEvent","ctrlKey","changedTouches","options","stopped","preventDefault","buttons","targetScroll","clamp","limit","scrollTo","onScroll","isScrolling","scroll","lastScroll","wrapperNode","scrollProperty","notify","lenisVersion","contentNode","addEventListener","offsetHeight","offsetWidth","wrapperObserver","ResizeObserver","observe","contentObserver","animate","platform","navigator","userAgentData","virtualScroll","el","firefoxMultiplier","mouseMultiplier","includes","useKeyboard","useTouch","passive","on","EventEmitter","start","destroy","_this$wrapperObserver","removeEventListener","disconnect","now","setScroll","value","emit","velocity","_ref6","_temp3","offset","_ref6$offset","immediate","_ref6$immediate","_ref6$duration","_ref6$easing","node","querySelector","nodeType","wrapperOffset","wrapperRect","getBoundingClientRect","left","top","Lenis"],"mappings":"yqBAAO,WAAeA,EAAKC,EAAOC,GAChC,OAAWC,KAACD,IAAIF,EAAKG,KAAKH,IAAIC,EAAOC,GACtC,CCFD,IAAAE,EAAA,CAAA,WAAA,6EAMEC,GAAA,SAAGC,EAA2DC,GAAA,IAAAC,EAAAC,KAAAC,OAAA,IAAAH,EAAJ,CAAA,EAA7CI,EAAAA,EAAAA,EAAAA,SAAAA,aAAW,EAAsCC,EAAAC,EAAAH,EAAnCI,OAAAA,aAAS,SAACC,GAAMA,OAAAA,CAAP,EAAaC,EAAAA,0IAC/CP,KAAKH,OAASA,EACdG,KAAKQ,cAAgBD,GACrBP,KAAKS,OAALC,EAAA,CAAA,EAAmBH,GACnBP,KAAKO,KAAOI,OAAOJ,UAAUA,IAG7BP,KAAKO,KAAKK,QAAQ,SAACC,GACjBd,EAAKS,SAASK,GAAOhB,EAAOgB,EAC7B,GAEDb,KAAKE,SAAWA,EAChBF,KAAKK,OAASA,EACdL,KAAKc,YAAc,EACnBd,KAAKe,WAAY,CAClB,IAEDC,KAAA,WACEhB,KAAKe,WAAY,CAClB,EAEDE,EAAAA,IAAA,SAAIC,GACF,IAAAC,EAAAnB,KAAA,GAAKA,KAAKe,UAAV,CAEAf,KAAKc,YAAcpB,KAAKH,IAAIS,KAAKc,YAAcI,EAAWlB,KAAKE,UAE/D,IAAckB,EAAGpB,KAAKK,OAAOL,KAAKoB,UAElCpB,KAAKO,KAAKK,QAAQ,SAACC,GACjB,IAAMQ,EAAOF,EAAKX,SAASK,GAK3BM,EAAKtB,OAAOgB,GAFEQ,GAFHF,EAAKV,OAAOI,GAEIQ,GAAQD,CAGpC,GAEgB,IAAbA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nBvI,KAAKwC,UAA6BgG,EAAYE,KAAOF,EAAYG,GACpE,CAED,IAAU9E,EAAGuE,EAAKK,wBAElBhB,GACsB,eAAnBzH,KAAKwC,UAA6BqB,EAAK6E,KAAO7E,EAAK8E,KACpD3I,KAAKsF,OACLiD,CACH,CAIDvI,KAAKgF,aAAeC,EAAM,EAF1BwC,GAASK,EAE2B9H,KAAKkF,QAEpClF,KAAKmC,QAAU6F,EAClBhI,KAAKwH,UAAUxH,KAAKgF,cAEpBhF,KAAKoG,QAAQxG,GAAGI,KAAM,CACpBE,SAAAA,EACAG,OAAAA,EACAiF,OAAQtF,KAAKgF,cAjD4B,CAoD9C,EAlND1D,EAAAsH,EAAA,CAAA,CAAA/H,IAAA,iBAAAW,IAAA,WAOE,OALIxB,KAAKwF,cAAgB1C,OACO,eAAnB9C,KAAKwC,UAA6B,UAAY,UAE3B,eAAnBxC,KAAKwC,UAA6B,aAAe,WAG/D,GA2CD,CAAA3B,IAAA,QAAAW,IAAA,WACE,MAA0B,oBAAdgB,UACRxC,KAAKkE,aAAelE,KAAKsD,aACzBtD,KAAKmE,cAAgBnE,KAAKwD,aAC/B,uBA6DD,WACE,OAAY8B,KAAAA,OAAStF,KAAKuF,UAC3B,KA3MgC0B,CAAAA,EAAAA"} \ No newline at end of file diff --git a/dist/lenis.modern.mjs b/dist/lenis.modern.mjs index e0fc56ea..7eb1d070 100644 --- a/dist/lenis.modern.mjs +++ b/dist/lenis.modern.mjs @@ -1,2 +1,2 @@ -import t from"tiny-emitter";import i from"virtual-scroll";function e(){return e=Object.assign?Object.assign.bind():function(t){for(var i=1;it)}=i,n=function(t,i){if(null==t)return{};var e,s,r={},o=Object.keys(t);for(s=0;s=0||(r[e]=t[e]);return r}(i,s);this.target=t,this.fromKeys=e({},n),this.toKeys=e({},n),this.keys=Object.keys(e({},n)),this.keys.forEach(i=>{this.fromKeys[i]=t[i]}),this.duration=r,this.easing=o,this.currentTime=0,this.isRunning=!0}stop(){this.isRunning=!1}raf(t){if(!this.isRunning)return;this.currentTime=Math.min(this.currentTime+.001*t,this.duration);const i=this.easing(this.progress);this.keys.forEach(t=>{const e=this.fromKeys[t];this.target[t]=e+(this.toKeys[t]-e)*i}),1===i&&(this.isRunning=!1)}get progress(){return this.currentTime/this.duration}}class o extends t{constructor({duration:t=1.2,easing:e=(t=>1===t?1:1-Math.pow(2,-10*t)),smooth:s=!0,smoothTouch:o=!1,touchMultiplier:n=2,direction:h="vertical",gestureDirection:l="vertical",wrapper:c=window,content:a=document.body}={}){var p,d,u;super(),this.onWindowResize=()=>{this.wrapperWidth=window.innerWidth,this.wrapperHeight=window.innerHeight},this.onWrapperResize=([t])=>{if(t){const i=t.contentRect;this.wrapperWidth=i.width,this.wrapperHeight=i.height}},this.onContentResize=([t])=>{if(t){const i=t.contentRect;this.contentWidth=i.width,this.contentHeight=i.height}},this.onVirtualScroll=({deltaY:t,deltaX:i,originalEvent:e})=>{if(e.ctrlKey)return;if(this.smooth=e.changedTouches?this.smoothTouch:this.options.smooth,this.stopped)return void e.preventDefault();if(!this.smooth)return;if(4===e.buttons)return;this.smooth&&e.preventDefault();let s=0;s="both"===this.gestureDirection?i+t:"horizontal"===this.gestureDirection?i:t,this.targetScroll-=s,this.targetScroll=Math.max(0,Math.min(this.targetScroll,this.limit)),this.scrollTo(this.targetScroll)},this.onScroll=t=>{this.isScrolling&&this.smooth||(this.targetScroll=this.scroll=this.lastScroll=this.wrapperNode[this.scrollProperty],this.notify())},window.lenisVersion="0.2.9",this.options={duration:t,easing:e,smooth:s,smoothTouch:o,touchMultiplier:n,direction:h,gestureDirection:l,wrapper:c,content:a},this.duration=t,this.easing=e,this.smooth=s,this.smoothTouch=o,this.touchMultiplier=n,this.direction=h,this.gestureDirection=l,this.wrapperNode=c,this.contentNode=a,this.wrapperNode.addEventListener("scroll",this.onScroll),this.wrapperNode===window?(this.wrapperNode.addEventListener("resize",this.onWindowResize),this.onWindowResize()):(this.wrapperHeight=this.wrapperNode.offsetHeight,this.wrapperWidth=this.wrapperNode.offsetWidth,this.wrapperObserver=new ResizeObserver(this.onWrapperResize),this.wrapperObserver.observe(this.wrapperNode)),this.contentHeight=this.contentNode.offsetHeight,this.contentWidth=this.contentNode.offsetWidth,this.contentObserver=new ResizeObserver(this.onContentResize),this.contentObserver.observe(this.contentNode),this.targetScroll=this.scroll=this.lastScroll=this.wrapperNode[this.scrollProperty],this.animate=new r;const g=(null==(p=navigator)||null==(d=p.userAgentData)?void 0:d.platform)||(null==(u=navigator)?void 0:u.platform)||"unknown";this.virtualScroll=new i({el:this.wrapperNode,firefoxMultiplier:50,mouseMultiplier:g.includes("Win")?1:.4,useKeyboard:!1,touchMultiplier:this.touchMultiplier,useTouch:!0,passive:!1}),this.virtualScroll.on(this.onVirtualScroll)}get scrollProperty(){let t;return t=this.wrapperNode===window?"horizontal"===this.direction?"scrollX":"scrollY":"horizontal"===this.direction?"scrollLeft":"scrollTop",t}start(){this.stopped=!1}stop(){this.stopped=!0,this.animate.stop()}destroy(){var t;this.wrapperNode===window&&this.wrapperNode.removeEventListener("resize",this.onWindowResize),this.wrapperNode.removeEventListener("scroll",this.onScroll),this.virtualScroll.destroy(),null==(t=this.wrapperObserver)||t.disconnect(),this.contentObserver.disconnect()}get limit(){return"horizontal"===this.direction?this.contentWidth-this.wrapperWidth:this.contentHeight-this.wrapperHeight}raf(t){const i=t-(this.now||0);this.now=t,!this.stopped&&this.smooth&&(this.lastScroll=this.scroll,this.animate.raf(i),this.scroll===this.targetScroll&&(this.lastScroll=this.scroll),this.isScrolling&&(this.setScroll(this.scroll),this.notify()),this.isScrolling=this.scroll!==this.targetScroll)}get velocity(){return this.scroll-this.lastScroll}setScroll(t){"horizontal"===this.direction?this.wrapperNode.scrollTo(t,0):this.wrapperNode.scrollTo(0,t)}notify(){this.emit("scroll",{scroll:this.scroll,limit:this.limit,velocity:this.velocity,direction:this.direction,progress:this.scroll/this.limit})}scrollTo(t,{offset:i=0,immediate:e=!1,duration:s=this.duration,easing:r=this.easing}={}){if(null==t)return;let o;if("number"==typeof t)o=t;else if("top"===t||"#top"===t)o=0;else if("bottom"===t)o=this.limit;else{let i;if("string"==typeof t)i=document.querySelector(t);else{if(null==t||!t.nodeType)return;i=t}if(!i)return;let e=0;if(this.wrapperNode!==window){const t=this.wrapperNode.getBoundingClientRect();e="horizontal"===this.direction?t.left:t.top}const s=i.getBoundingClientRect();o=("horizontal"===this.direction?s.left:s.top)+this.scroll-e}o+=i,this.targetScroll=o,!this.smooth||e?this.setScroll(this.targetScroll):this.animate.to(this,{duration:s,easing:r,scroll:this.targetScroll})}}export{o as default}; +import t from"tiny-emitter";import i from"virtual-scroll";function e(){return e=Object.assign?Object.assign.bind():function(t){for(var i=1;it)}=i,n=function(t,i){if(null==t)return{};var e,s,r={},o=Object.keys(t);for(s=0;s=0||(r[e]=t[e]);return r}(i,r);this.target=t,this.fromKeys=e({},n),this.toKeys=e({},n),this.keys=Object.keys(e({},n)),this.keys.forEach(i=>{this.fromKeys[i]=t[i]}),this.duration=s,this.easing=o,this.currentTime=0,this.isRunning=!0}stop(){this.isRunning=!1}raf(t){if(!this.isRunning)return;this.currentTime=Math.min(this.currentTime+t,this.duration);const i=this.easing(this.progress);this.keys.forEach(t=>{const e=this.fromKeys[t];this.target[t]=e+(this.toKeys[t]-e)*i}),1===i&&this.stop()}get progress(){return this.currentTime/this.duration}}class n extends t{constructor({duration:t=1.2,easing:e=(t=>1===t?1:1-Math.pow(2,-10*t)),smooth:r=!0,smoothTouch:n=!1,touchMultiplier:h=2,direction:l="vertical",gestureDirection:c="vertical",wrapper:a=window,content:p=document.body}={}){var d,u,g;super(),this.onWindowResize=()=>{this.wrapperWidth=window.innerWidth,this.wrapperHeight=window.innerHeight},this.onWrapperResize=([t])=>{if(t){const i=t.contentRect;this.wrapperWidth=i.width,this.wrapperHeight=i.height}},this.onContentResize=([t])=>{if(t){const i=t.contentRect;this.contentWidth=i.width,this.contentHeight=i.height}},this.onVirtualScroll=({deltaY:t,deltaX:i,originalEvent:e})=>{if(e.ctrlKey)return;if(this.smooth=e.changedTouches?this.smoothTouch:this.options.smooth,this.stopped)return void e.preventDefault();if(!this.smooth)return;if(4===e.buttons)return;this.smooth&&e.preventDefault();let r=0;r="both"===this.gestureDirection?i+t:"horizontal"===this.gestureDirection?i:t,this.targetScroll-=r,this.targetScroll=s(0,this.targetScroll,this.limit),this.scrollTo(this.targetScroll)},this.onScroll=t=>{this.isScrolling&&this.smooth||(this.targetScroll=this.scroll=this.lastScroll=this.wrapperNode[this.scrollProperty],this.notify())},window.lenisVersion="0.2.10",this.options={duration:t,easing:e,smooth:r,smoothTouch:n,touchMultiplier:h,direction:l,gestureDirection:c,wrapper:a,content:p},this.duration=t,this.easing=e,this.smooth=r,this.smoothTouch=n,this.touchMultiplier=h,this.direction=l,this.gestureDirection=c,this.wrapperNode=a,this.contentNode=p,this.wrapperNode.addEventListener("scroll",this.onScroll),this.wrapperNode===window?(this.wrapperNode.addEventListener("resize",this.onWindowResize),this.onWindowResize()):(this.wrapperHeight=this.wrapperNode.offsetHeight,this.wrapperWidth=this.wrapperNode.offsetWidth,this.wrapperObserver=new ResizeObserver(this.onWrapperResize),this.wrapperObserver.observe(this.wrapperNode)),this.contentHeight=this.contentNode.offsetHeight,this.contentWidth=this.contentNode.offsetWidth,this.contentObserver=new ResizeObserver(this.onContentResize),this.contentObserver.observe(this.contentNode),this.targetScroll=this.scroll=this.lastScroll=this.wrapperNode[this.scrollProperty],this.animate=new o;const w=(null==(d=navigator)||null==(u=d.userAgentData)?void 0:u.platform)||(null==(g=navigator)?void 0:g.platform)||"unknown";this.virtualScroll=new i({el:this.wrapperNode,firefoxMultiplier:50,mouseMultiplier:w.includes("Win")?1:.4,useKeyboard:!1,touchMultiplier:this.touchMultiplier,useTouch:!0,passive:!1}),this.virtualScroll.on(this.onVirtualScroll)}get scrollProperty(){let t;return t=this.wrapperNode===window?"horizontal"===this.direction?"scrollX":"scrollY":"horizontal"===this.direction?"scrollLeft":"scrollTop",t}start(){this.stopped=!1}stop(){this.stopped=!0,this.animate.stop()}destroy(){var t;this.wrapperNode===window&&this.wrapperNode.removeEventListener("resize",this.onWindowResize),this.wrapperNode.removeEventListener("scroll",this.onScroll),this.virtualScroll.destroy(),null==(t=this.wrapperObserver)||t.disconnect(),this.contentObserver.disconnect()}get limit(){return"horizontal"===this.direction?this.contentWidth-this.wrapperWidth:this.contentHeight-this.wrapperHeight}raf(t){const i=t-(this.now||0);this.now=t,!this.stopped&&this.smooth&&(this.lastScroll=this.scroll,this.animate.raf(.001*i),this.scroll===this.targetScroll&&(this.lastScroll=this.scroll),this.isScrolling&&(this.setScroll(this.scroll),this.notify()),this.isScrolling=this.scroll!==this.targetScroll)}get velocity(){return this.scroll-this.lastScroll}setScroll(t){"horizontal"===this.direction?this.wrapperNode.scrollTo(t,0):this.wrapperNode.scrollTo(0,t)}notify(){this.emit("scroll",{scroll:this.scroll,limit:this.limit,velocity:this.velocity,direction:this.direction,progress:this.scroll/this.limit})}scrollTo(t,{offset:i=0,immediate:e=!1,duration:r=this.duration,easing:o=this.easing}={}){if(null==t)return;let n;if("number"==typeof t)n=t;else if("top"===t||"#top"===t)n=0;else if("bottom"===t)n=this.limit;else{let i;if("string"==typeof t)i=document.querySelector(t);else{if(null==t||!t.nodeType)return;i=t}if(!i)return;let e=0;if(this.wrapperNode!==window){const t=this.wrapperNode.getBoundingClientRect();e="horizontal"===this.direction?t.left:t.top}const s=i.getBoundingClientRect();n=("horizontal"===this.direction?s.left:s.top)+this.scroll-e}n+=i,this.targetScroll=s(0,n,this.limit),!this.smooth||e?this.setScroll(this.targetScroll):this.animate.to(this,{duration:r,easing:o,scroll:this.targetScroll})}}export{n as default}; //# sourceMappingURL=lenis.modern.mjs.map diff --git a/dist/lenis.modern.mjs.map b/dist/lenis.modern.mjs.map index 1daf36e3..72c419a2 100644 --- a/dist/lenis.modern.mjs.map +++ b/dist/lenis.modern.mjs.map @@ -1 +1 @@ -{"version":3,"file":"lenis.modern.mjs","sources":["../src/lenis.js","../src/maths.js"],"sourcesContent":["import EventEmitter from 'tiny-emitter'\r\nimport VirtualScroll from 'virtual-scroll'\r\nimport { version } from '../package.json'\r\nimport { clamp } from './maths.js'\r\n\r\nclass Animate {\r\n to(target, { duration = 1, easing = (t) => t, ...keys } = {}) {\r\n this.target = target\r\n this.fromKeys = { ...keys }\r\n this.toKeys = { ...keys }\r\n this.keys = Object.keys({ ...keys })\r\n\r\n // get initial values\r\n this.keys.forEach((key) => {\r\n this.fromKeys[key] = target[key]\r\n })\r\n\r\n this.duration = duration\r\n this.easing = easing\r\n this.currentTime = 0\r\n this.isRunning = true\r\n }\r\n\r\n stop() {\r\n this.isRunning = false\r\n }\r\n\r\n raf(deltaTime) {\r\n if (!this.isRunning) return\r\n\r\n this.currentTime = Math.min(\r\n this.currentTime + deltaTime * 0.001,\r\n this.duration\r\n )\r\n\r\n const progress = this.easing(this.progress)\r\n\r\n this.keys.forEach((key) => {\r\n const from = this.fromKeys[key]\r\n const to = this.toKeys[key]\r\n\r\n const value = from + (to - from) * progress\r\n\r\n this.target[key] = value\r\n })\r\n\r\n if (progress === 1) {\r\n this.isRunning = false\r\n }\r\n }\r\n\r\n get progress() {\r\n return this.currentTime / this.duration\r\n }\r\n}\r\n\r\nexport default class Lenis extends EventEmitter {\r\n constructor({\r\n duration = 1.2,\r\n easing = (t) => (t === 1 ? 1 : 1 - Math.pow(2, -10 * t)), // https://easings.net/en#easeOutExpo\r\n smooth = true,\r\n smoothTouch = false,\r\n touchMultiplier = 2,\r\n direction = 'vertical', // vertical, horizontal\r\n gestureDirection = 'vertical', // vertical, horizontal, both\r\n wrapper = window,\r\n content = document.body,\r\n } = {}) {\r\n super()\r\n\r\n window.lenisVersion = version\r\n\r\n this.options = {\r\n duration,\r\n easing,\r\n smooth,\r\n smoothTouch,\r\n touchMultiplier,\r\n direction,\r\n gestureDirection,\r\n wrapper,\r\n content,\r\n }\r\n\r\n this.duration = duration\r\n this.easing = easing\r\n this.smooth = smooth\r\n this.smoothTouch = smoothTouch\r\n this.touchMultiplier = touchMultiplier\r\n this.direction = direction\r\n this.gestureDirection = gestureDirection\r\n this.wrapperNode = wrapper\r\n this.contentNode = content\r\n\r\n this.wrapperNode.addEventListener('scroll', this.onScroll)\r\n\r\n //observe wrapper node size\r\n if (this.wrapperNode === window) {\r\n this.wrapperNode.addEventListener('resize', this.onWindowResize)\r\n this.onWindowResize()\r\n } else {\r\n this.wrapperHeight = this.wrapperNode.offsetHeight\r\n this.wrapperWidth = this.wrapperNode.offsetWidth\r\n\r\n //observe wrapper node size\r\n this.wrapperObserver = new ResizeObserver(this.onWrapperResize)\r\n this.wrapperObserver.observe(this.wrapperNode)\r\n }\r\n\r\n this.contentHeight = this.contentNode.offsetHeight\r\n this.contentWidth = this.contentNode.offsetWidth\r\n\r\n //observe content node size\r\n this.contentObserver = new ResizeObserver(this.onContentResize)\r\n this.contentObserver.observe(this.contentNode)\r\n\r\n //set initial scroll position\r\n this.targetScroll =\r\n this.scroll =\r\n this.lastScroll =\r\n this.wrapperNode[this.scrollProperty]\r\n\r\n this.animate = new Animate()\r\n\r\n const platform =\r\n navigator?.userAgentData?.platform || navigator?.platform || 'unknown'\r\n\r\n // listen and normalize wheel event cross-browser\r\n this.virtualScroll = new VirtualScroll({\r\n el: this.wrapperNode,\r\n firefoxMultiplier: 50,\r\n mouseMultiplier: platform.includes('Win') ? 1 : 0.4,\r\n useKeyboard: false,\r\n touchMultiplier: this.touchMultiplier,\r\n useTouch: true,\r\n passive: false,\r\n })\r\n\r\n this.virtualScroll.on(this.onVirtualScroll)\r\n }\r\n\r\n get scrollProperty() {\r\n let property\r\n if (this.wrapperNode === window) {\r\n property = this.direction === 'horizontal' ? 'scrollX' : 'scrollY'\r\n } else {\r\n property = this.direction === 'horizontal' ? 'scrollLeft' : 'scrollTop'\r\n }\r\n return property\r\n }\r\n\r\n start() {\r\n this.stopped = false\r\n }\r\n\r\n stop() {\r\n this.stopped = true\r\n this.animate.stop()\r\n }\r\n\r\n destroy() {\r\n if (this.wrapperNode === window) {\r\n this.wrapperNode.removeEventListener('resize', this.onWindowResize)\r\n }\r\n this.wrapperNode.removeEventListener('scroll', this.onScroll)\r\n\r\n this.virtualScroll.destroy()\r\n this.wrapperObserver?.disconnect()\r\n this.contentObserver.disconnect()\r\n }\r\n\r\n onWindowResize = () => {\r\n this.wrapperWidth = window.innerWidth\r\n this.wrapperHeight = window.innerHeight\r\n }\r\n\r\n onWrapperResize = ([entry]) => {\r\n if (entry) {\r\n const rect = entry.contentRect\r\n this.wrapperWidth = rect.width\r\n this.wrapperHeight = rect.height\r\n }\r\n }\r\n\r\n onContentResize = ([entry]) => {\r\n if (entry) {\r\n const rect = entry.contentRect\r\n this.contentWidth = rect.width\r\n this.contentHeight = rect.height\r\n }\r\n }\r\n\r\n get limit() {\r\n return this.direction === 'horizontal'\r\n ? this.contentWidth - this.wrapperWidth\r\n : this.contentHeight - this.wrapperHeight\r\n }\r\n\r\n onVirtualScroll = ({ deltaY, deltaX, originalEvent: e }) => {\r\n if (e.ctrlKey) return\r\n\r\n // switch to smooth if event is touch and touch is true\r\n this.smooth = !!e.changedTouches ? this.smoothTouch : this.options.smooth\r\n\r\n if (this.stopped) {\r\n e.preventDefault()\r\n return\r\n }\r\n\r\n if (!this.smooth) return\r\n\r\n // fix wheel holding scroll https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/buttons\r\n if (e.buttons === 4) return\r\n\r\n // prevent native wheel scrolling\r\n if (this.smooth) e.preventDefault()\r\n\r\n let delta = 0\r\n if (this.gestureDirection === 'both') {\r\n delta = deltaX + deltaY\r\n } else if (this.gestureDirection === 'horizontal') {\r\n delta = deltaX\r\n } else {\r\n // vertical\r\n delta = deltaY\r\n }\r\n\r\n this.targetScroll -= delta\r\n this.targetScroll = clamp(0, this.targetScroll, this.limit)\r\n\r\n this.scrollTo(this.targetScroll)\r\n }\r\n\r\n raf(now) {\r\n const deltaTime = now - (this.now || 0)\r\n this.now = now\r\n\r\n if (this.stopped || !this.smooth) return\r\n\r\n this.lastScroll = this.scroll\r\n\r\n // where this.scroll is updated\r\n this.animate.raf(deltaTime)\r\n\r\n if (this.scroll === this.targetScroll) {\r\n // if target reached velocity should be 0\r\n this.lastScroll = this.scroll\r\n }\r\n\r\n if (this.isScrolling) {\r\n this.setScroll(this.scroll)\r\n this.notify()\r\n }\r\n\r\n this.isScrolling = this.scroll !== this.targetScroll\r\n }\r\n\r\n get velocity() {\r\n return this.scroll - this.lastScroll\r\n }\r\n\r\n setScroll(value) {\r\n this.direction === 'horizontal'\r\n ? this.wrapperNode.scrollTo(value, 0)\r\n : this.wrapperNode.scrollTo(0, value)\r\n }\r\n\r\n onScroll = (e) => {\r\n // if isScrolling false we can consider user isn't scrolling with wheel (cmd+F, keyboard or whatever). So we must scroll to value immediately\r\n if (!this.isScrolling || !this.smooth) {\r\n // where native scroll happens\r\n this.targetScroll =\r\n this.scroll =\r\n this.lastScroll =\r\n this.wrapperNode[this.scrollProperty]\r\n\r\n this.notify()\r\n }\r\n }\r\n\r\n notify() {\r\n this.emit('scroll', {\r\n scroll: this.scroll,\r\n limit: this.limit,\r\n velocity: this.velocity,\r\n direction: this.direction,\r\n progress: this.scroll / this.limit,\r\n })\r\n }\r\n\r\n scrollTo(\r\n target,\r\n {\r\n offset = 0,\r\n immediate = false,\r\n duration = this.duration,\r\n easing = this.easing,\r\n } = {}\r\n ) {\r\n if (target === undefined || target === null) return\r\n let value\r\n\r\n if (typeof target === 'number') {\r\n value = target\r\n } else if (target === 'top' || target === '#top') {\r\n value = 0\r\n } else if (target === 'bottom') {\r\n value = 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 } else {\r\n return\r\n }\r\n\r\n if (!node) return\r\n let wrapperOffset = 0\r\n\r\n if (this.wrapperNode !== window) {\r\n const wrapperRect = this.wrapperNode.getBoundingClientRect()\r\n wrapperOffset =\r\n this.direction === 'horizontal' ? wrapperRect.left : wrapperRect.top\r\n }\r\n\r\n const rect = node.getBoundingClientRect()\r\n\r\n value =\r\n (this.direction === 'horizontal' ? rect.left : rect.top) +\r\n this.scroll -\r\n wrapperOffset\r\n }\r\n\r\n value += offset\r\n\r\n this.targetScroll = value\r\n\r\n if (!this.smooth || immediate) {\r\n this.setScroll(this.targetScroll)\r\n } else {\r\n this.animate.to(this, {\r\n duration,\r\n easing,\r\n scroll: this.targetScroll,\r\n })\r\n }\r\n }\r\n}\r\n","export function clamp(min, input, max) {\r\n return Math.max(min, Math.min(input, max))\r\n}\r\n\r\nexport function mapRange(in_min, in_max, input, out_min, out_max) {\r\n return ((input - in_min) * (out_max - out_min)) / (in_max - in_min) + out_min\r\n}\r\n\r\nexport function lerp(start, end, amt) {\r\n return (1 - amt) * start + amt * end\r\n}\r\n\r\nexport function truncate(value, decimals) {\r\n return parseFloat(value.toFixed(decimals))\r\n}\r\n"],"names":["_excluded","Animate","to","target","_ref","duration","easing","t","keys","_objectWithoutPropertiesLoose","this","fromKeys","_extends","toKeys","Object","forEach","key","currentTime","isRunning","stop","raf","deltaTime","Math","min","progress","from","value","EventEmitter","constructor","pow","smooth","smoothTouch","touchMultiplier","direction","gestureDirection","wrapper","window","content","document","body","_navigator","_navigator$userAgentD","_navigator2","super","onWindowResize","wrapperWidth","innerWidth","wrapperHeight","innerHeight","onWrapperResize","entry","rect","contentRect","width","height","onContentResize","contentWidth","contentHeight","onVirtualScroll","deltaY","deltaX","originalEvent","e","ctrlKey","changedTouches","options","stopped","preventDefault","buttons","delta","targetScroll","max","limit","scrollTo","onScroll","isScrolling","scroll","lastScroll","wrapperNode","scrollProperty","notify","lenisVersion","contentNode","addEventListener","offsetHeight","offsetWidth","wrapperObserver","observe","contentObserver","ResizeObserver","animate","platform","navigator","userAgentData","virtualScroll","VirtualScroll","el","firefoxMultiplier","mouseMultiplier","includes","useKeyboard","useTouch","passive","on","property","start","destroy","_this$wrapperObserver","removeEventListener","disconnect","now","setScroll","emit","velocity","offset","immediate","node","querySelector","nodeType","wrapperOffset","getBoundingClientRect","wrapperRect","left","top"],"mappings":"8RAAA,MAAAA,EAAA,CAAA,WAAA,UAKA,MAAMC,EACJC,GAAGC,EAAQC,EAA+C,CAAxD,GAAS,IAAAC,SAAEA,EAAW,EAAbC,OAAgBA,EAAUC,IAAMA,IAAmBH,EAAbI,oIAC/CC,CAAAL,EAAAJ,GAAAU,KAAKP,OAASA,EACdO,KAAKC,SAALC,EAAA,CAAA,EAAqBJ,GACrBE,KAAKG,OAAcL,EAAAA,CAAAA,EAAAA,GACnBE,KAAKF,KAAOM,OAAON,KAAPI,EAAA,GAAiBJ,IAG7BE,KAAKF,KAAKO,QAASC,IACjBN,KAAKC,SAASK,GAAOb,EAAOa,KAG9BN,KAAKL,SAAWA,EAChBK,KAAKJ,OAASA,EACdI,KAAKO,YAAc,EACnBP,KAAKQ,WAAY,CAClB,CAEDC,OACET,KAAKQ,WAAY,CAClB,CAEDE,IAAIC,GACF,IAAKX,KAAKQ,UAAW,OAErBR,KAAKO,YAAcK,KAAKC,IACtBb,KAAKO,YAA0B,KAAZI,EACnBX,KAAKL,UAGP,MAAMmB,EAAWd,KAAKJ,OAAOI,KAAKc,UAElCd,KAAKF,KAAKO,QAASC,IACjB,QAAaN,KAAKC,SAASK,GAK3BN,KAAKP,OAAOa,GAFES,GAFHf,KAAKG,OAAOG,GAEIS,GAAQD,CAEhBE,GAGJ,IAAbF,IACFd,KAAKQ,WAAY,EAEpB,CAEWM,eACV,OAAOd,KAAKO,YAAcP,KAAKL,QAChC,EAGY,gBAAoBsB,EACjCC,aAAYvB,SACVA,EAAW,IADDC,OAEVA,EAAUC,IAAa,IAANA,EAAU,EAAI,EAAIe,KAAKO,IAAI,GAAI,GAAKtB,IAF3CuB,OAGVA,GAAS,EAHCC,YAIVA,GAAc,EAJJC,gBAKVA,EAAkB,EALRC,UAMVA,EAAY,WANFC,iBAOVA,EAAmB,WAPTC,QAQV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ACbJ,MAAO9D,KAAK8D,MACZyC,SAAUvG,KAAKuG,SACfhF,UAAWvB,KAAKuB,UAChBT,SAAUd,KAAKkE,OAASlE,KAAK8D,OAEhC,CAEDC,SACEtE,GACA+G,OACEA,EAAS,EADXC,UAEEA,GAAY,EAFd9G,SAGEA,EAAWK,KAAKL,SAHlBC,OAIEA,EAASI,KAAKJ,QACZ,CAPE,GASN,GAAIH,QAAyC,OAC7C,MAEA,GAAsB,iBAAXA,EACTuB,EAAQvB,OACCA,GAAW,QAAXA,GAA+B,SAAXA,EAC7BuB,EAAQ,OACH,GAAe,WAAXvB,EACTuB,EAAQhB,KAAK8D,UACR,CACL,MAEA,GAAsB,iBAAXrE,EAETiH,EAAO9E,SAAS+E,cAAclH,OACrBA,UAAAA,IAAAA,EAAQmH,SAIjB,OAFAF,EAAOjH,CAGR,CAED,IAAKiH,EAAM,OACX,IAAIG,EAAgB,EAEpB,GAAI7G,KAAKoE,cAAgB1C,OAAQ,CAC/B,QAAoB1B,KAAKoE,YAAY0C,wBACrCD,EACqB,eAAnB7G,KAAKuB,UAA6BwF,EAAYC,KAAOD,EAAYE,GACpE,CAED,MAAUxE,EAAGiE,EAAKI,wBAElB9F,GACsB,eAAnBhB,KAAKuB,UAA6BkB,EAAKuE,KAAOvE,EAAKwE,KACpDjH,KAAKkE,OACL2C,CACH,CAED7F,GAASwF,EAETxG,KAAK4D,aAAe5C,GAEfhB,KAAKoB,QAAUqF,EAClBzG,KAAKqG,UAAUrG,KAAK4D,cAEpB5D,KAAKgF,QAAQxF,GAAGQ,KAAM,CACpBL,WACAC,SACAsE,OAAQlE,KAAK4D,cAGlB"} \ No newline at end of file +{"version":3,"file":"lenis.modern.mjs","sources":["../src/maths.js","../src/lenis.js"],"sourcesContent":["export function clamp(min, input, max) {\r\n return Math.max(min, Math.min(input, max))\r\n}\r\n\r\nexport function mapRange(in_min, in_max, input, out_min, out_max) {\r\n return ((input - in_min) * (out_max - out_min)) / (in_max - in_min) + out_min\r\n}\r\n\r\nexport function lerp(start, end, amt) {\r\n return (1 - amt) * start + amt * end\r\n}\r\n\r\nexport function truncate(value, decimals) {\r\n return parseFloat(value.toFixed(decimals))\r\n}\r\n","import EventEmitter from 'tiny-emitter'\r\nimport VirtualScroll from 'virtual-scroll'\r\nimport { version } from '../package.json'\r\nimport { clamp } from './maths.js'\r\n\r\nclass Animate {\r\n to(target, { duration = 1, easing = (t) => t, ...keys } = {}) {\r\n this.target = target\r\n this.fromKeys = { ...keys }\r\n this.toKeys = { ...keys }\r\n this.keys = Object.keys({ ...keys })\r\n\r\n // get initial values\r\n this.keys.forEach((key) => {\r\n this.fromKeys[key] = target[key]\r\n })\r\n\r\n this.duration = duration\r\n this.easing = easing\r\n this.currentTime = 0\r\n this.isRunning = true\r\n }\r\n\r\n stop() {\r\n this.isRunning = false\r\n }\r\n\r\n raf(deltaTime) {\r\n if (!this.isRunning) return\r\n\r\n this.currentTime = Math.min(this.currentTime + deltaTime, this.duration)\r\n\r\n const progress = this.easing(this.progress)\r\n\r\n this.keys.forEach((key) => {\r\n const from = this.fromKeys[key]\r\n const to = this.toKeys[key]\r\n\r\n const value = from + (to - from) * progress\r\n\r\n this.target[key] = value\r\n })\r\n\r\n if (progress === 1) {\r\n this.stop()\r\n }\r\n }\r\n\r\n get progress() {\r\n return this.currentTime / this.duration\r\n }\r\n}\r\n\r\nexport default class Lenis extends EventEmitter {\r\n constructor({\r\n duration = 1.2,\r\n easing = (t) => (t === 1 ? 1 : 1 - Math.pow(2, -10 * t)), // https://easings.net/en#easeOutExpo\r\n smooth = true,\r\n smoothTouch = false,\r\n touchMultiplier = 2,\r\n direction = 'vertical', // vertical, horizontal\r\n gestureDirection = 'vertical', // vertical, horizontal, both\r\n wrapper = window,\r\n content = document.body,\r\n } = {}) {\r\n super()\r\n\r\n window.lenisVersion = version\r\n\r\n this.options = {\r\n duration,\r\n easing,\r\n smooth,\r\n smoothTouch,\r\n touchMultiplier,\r\n direction,\r\n gestureDirection,\r\n wrapper,\r\n content,\r\n }\r\n\r\n this.duration = duration\r\n this.easing = easing\r\n this.smooth = smooth\r\n this.smoothTouch = smoothTouch\r\n this.touchMultiplier = touchMultiplier\r\n this.direction = direction\r\n this.gestureDirection = gestureDirection\r\n this.wrapperNode = wrapper\r\n this.contentNode = content\r\n\r\n this.wrapperNode.addEventListener('scroll', this.onScroll)\r\n\r\n //observe wrapper node size\r\n if (this.wrapperNode === window) {\r\n this.wrapperNode.addEventListener('resize', this.onWindowResize)\r\n this.onWindowResize()\r\n } else {\r\n this.wrapperHeight = this.wrapperNode.offsetHeight\r\n this.wrapperWidth = this.wrapperNode.offsetWidth\r\n\r\n //observe wrapper node size\r\n this.wrapperObserver = new ResizeObserver(this.onWrapperResize)\r\n this.wrapperObserver.observe(this.wrapperNode)\r\n }\r\n\r\n this.contentHeight = this.contentNode.offsetHeight\r\n this.contentWidth = this.contentNode.offsetWidth\r\n\r\n //observe content node size\r\n this.contentObserver = new ResizeObserver(this.onContentResize)\r\n this.contentObserver.observe(this.contentNode)\r\n\r\n //set initial scroll position\r\n this.targetScroll =\r\n this.scroll =\r\n this.lastScroll =\r\n this.wrapperNode[this.scrollProperty]\r\n\r\n this.animate = new Animate()\r\n\r\n const platform =\r\n navigator?.userAgentData?.platform || navigator?.platform || 'unknown'\r\n\r\n // listen and normalize wheel event cross-browser\r\n this.virtualScroll = new VirtualScroll({\r\n el: this.wrapperNode,\r\n firefoxMultiplier: 50,\r\n mouseMultiplier: platform.includes('Win') ? 1 : 0.4,\r\n useKeyboard: false,\r\n touchMultiplier: this.touchMultiplier,\r\n useTouch: true,\r\n passive: false,\r\n })\r\n\r\n this.virtualScroll.on(this.onVirtualScroll)\r\n }\r\n\r\n get scrollProperty() {\r\n let property\r\n if (this.wrapperNode === window) {\r\n property = this.direction === 'horizontal' ? 'scrollX' : 'scrollY'\r\n } else {\r\n property = this.direction === 'horizontal' ? 'scrollLeft' : 'scrollTop'\r\n }\r\n return property\r\n }\r\n\r\n start() {\r\n this.stopped = false\r\n }\r\n\r\n stop() {\r\n this.stopped = true\r\n this.animate.stop()\r\n }\r\n\r\n destroy() {\r\n if (this.wrapperNode === window) {\r\n this.wrapperNode.removeEventListener('resize', this.onWindowResize)\r\n }\r\n this.wrapperNode.removeEventListener('scroll', this.onScroll)\r\n\r\n this.virtualScroll.destroy()\r\n this.wrapperObserver?.disconnect()\r\n this.contentObserver.disconnect()\r\n }\r\n\r\n onWindowResize = () => {\r\n this.wrapperWidth = window.innerWidth\r\n this.wrapperHeight = window.innerHeight\r\n }\r\n\r\n onWrapperResize = ([entry]) => {\r\n if (entry) {\r\n const rect = entry.contentRect\r\n this.wrapperWidth = rect.width\r\n this.wrapperHeight = rect.height\r\n }\r\n }\r\n\r\n onContentResize = ([entry]) => {\r\n if (entry) {\r\n const rect = entry.contentRect\r\n this.contentWidth = rect.width\r\n this.contentHeight = rect.height\r\n }\r\n }\r\n\r\n get limit() {\r\n return this.direction === 'horizontal'\r\n ? this.contentWidth - this.wrapperWidth\r\n : this.contentHeight - this.wrapperHeight\r\n }\r\n\r\n onVirtualScroll = ({ deltaY, deltaX, originalEvent: e }) => {\r\n if (e.ctrlKey) return\r\n\r\n // switch to smooth if event is touch and touch is true\r\n this.smooth = !!e.changedTouches ? this.smoothTouch : this.options.smooth\r\n\r\n if (this.stopped) {\r\n e.preventDefault()\r\n return\r\n }\r\n\r\n if (!this.smooth) return\r\n\r\n // fix wheel holding scroll https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/buttons\r\n if (e.buttons === 4) return\r\n\r\n // prevent native wheel scrolling\r\n if (this.smooth) e.preventDefault()\r\n\r\n let delta = 0\r\n if (this.gestureDirection === 'both') {\r\n delta = deltaX + deltaY\r\n } else if (this.gestureDirection === 'horizontal') {\r\n delta = deltaX\r\n } else {\r\n // vertical\r\n delta = deltaY\r\n }\r\n\r\n this.targetScroll -= delta\r\n this.targetScroll = clamp(0, this.targetScroll, this.limit)\r\n\r\n this.scrollTo(this.targetScroll)\r\n }\r\n\r\n raf(now) {\r\n const deltaTime = now - (this.now || 0)\r\n this.now = now\r\n\r\n if (this.stopped || !this.smooth) return\r\n\r\n this.lastScroll = this.scroll\r\n\r\n // where this.scroll is updated\r\n this.animate.raf(deltaTime * 0.001)\r\n\r\n if (this.scroll === this.targetScroll) {\r\n // if target reached velocity should be 0\r\n this.lastScroll = this.scroll\r\n }\r\n\r\n if (this.isScrolling) {\r\n this.setScroll(this.scroll)\r\n this.notify()\r\n }\r\n\r\n this.isScrolling = this.scroll !== this.targetScroll\r\n }\r\n\r\n get velocity() {\r\n return this.scroll - this.lastScroll\r\n }\r\n\r\n setScroll(value) {\r\n this.direction === 'horizontal'\r\n ? this.wrapperNode.scrollTo(value, 0)\r\n : this.wrapperNode.scrollTo(0, value)\r\n }\r\n\r\n onScroll = (e) => {\r\n // if isScrolling false we can consider user isn't scrolling with wheel (cmd+F, keyboard or whatever). So we must scroll to value immediately\r\n if (!this.isScrolling || !this.smooth) {\r\n // where native scroll happens\r\n this.targetScroll =\r\n this.scroll =\r\n this.lastScroll =\r\n this.wrapperNode[this.scrollProperty]\r\n\r\n this.notify()\r\n }\r\n }\r\n\r\n notify() {\r\n this.emit('scroll', {\r\n scroll: this.scroll,\r\n limit: this.limit,\r\n velocity: this.velocity,\r\n direction: this.direction,\r\n progress: this.scroll / this.limit,\r\n })\r\n }\r\n\r\n scrollTo(\r\n target,\r\n {\r\n offset = 0,\r\n immediate = false,\r\n duration = this.duration,\r\n easing = this.easing,\r\n } = {}\r\n ) {\r\n if (target === undefined || target === null) return\r\n let value\r\n\r\n if (typeof target === 'number') {\r\n value = target\r\n } else if (target === 'top' || target === '#top') {\r\n value = 0\r\n } else if (target === 'bottom') {\r\n value = 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 } else {\r\n return\r\n }\r\n\r\n if (!node) return\r\n let wrapperOffset = 0\r\n\r\n if (this.wrapperNode !== window) {\r\n const wrapperRect = this.wrapperNode.getBoundingClientRect()\r\n wrapperOffset =\r\n this.direction === 'horizontal' ? wrapperRect.left : wrapperRect.top\r\n }\r\n\r\n const rect = node.getBoundingClientRect()\r\n\r\n value =\r\n (this.direction === 'horizontal' ? rect.left : rect.top) +\r\n this.scroll -\r\n wrapperOffset\r\n }\r\n\r\n value += offset\r\n\r\n this.targetScroll = clamp(0, value, this.limit)\r\n\r\n if (!this.smooth || immediate) {\r\n this.setScroll(this.targetScroll)\r\n } else {\r\n this.animate.to(this, {\r\n duration,\r\n easing,\r\n scroll: this.targetScroll,\r\n })\r\n }\r\n }\r\n}\r\n"],"names":["min","input","max","Math","_excluded","Animate","to","target","_ref","duration","easing","t","keys","_objectWithoutPropertiesLoose","this","fromKeys","_extends","toKeys","Object","forEach","key","currentTime","isRunning","stop","raf","deltaTime","progress","from","value","Lenis","EventEmitter","constructor","pow","smooth","smoothTouch","touchMultiplier","direction","gestureDirection","wrapper","window","content","document","body","_navigator","_navigator$userAgentD","_navigator2","super","onWindowResize","wrapperWidth","innerWidth","wrapperHeight","innerHeight","onWrapperResize","entry","rect","contentRect","width","height","onContentResize","contentWidth","contentHeight","onVirtualScroll","deltaY","deltaX","originalEvent","e","ctrlKey","changedTouches","options","stopped","preventDefault","buttons","delta","targetScroll","clamp","limit","scrollTo","onScroll","isScrolling","scroll","lastScroll","wrapperNode","scrollProperty","notify","lenisVersion","contentNode","addEventListener","offsetHeight","offsetWidth","wrapperObserver","ResizeObserver","observe","contentObserver","animate","platform","navigator","userAgentData","virtualScroll","VirtualScroll","el","firefoxMultiplier","mouseMultiplier","includes","useKeyboard","useTouch","passive","on","property","start","destroy","_this$wrapperObserver","removeEventListener","disconnect","now","setScroll","velocity","emit","offset","immediate","node","querySelector","nodeType","wrapperOffset","wrapperRect","getBoundingClientRect","left","top"],"mappings":"8RAAO,WAAeA,EAAKC,EAAOC,GAChC,OAAWC,KAACD,IAAIF,EAAKG,KAAKH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ChBV,SAAUZ,KAAKiE,OAASjE,KAAK6D,OAEhC,CAEDC,SACErE,GACA8G,OACEA,EAAS,EADXC,UAEEA,GAAY,EAFd7G,SAGEA,EAAWK,KAAKL,SAHlBC,OAIEA,EAASI,KAAKJ,QACZ,CAPE,GASN,GAAIH,QAAyC,OAC7C,IAAIqB,EAEJ,GAAsB,mBACpBA,EAAQrB,OACH,GAAe,QAAXA,GAA+B,SAAXA,EAC7BqB,EAAQ,UACY,WAAXrB,EACTqB,EAAQd,KAAK6D,UACR,CACL,IAAI4C,EAEJ,GAAsB,mBAEpBA,EAAO9E,SAAS+E,cAAcjH,OACzB,IAAA,MAAIA,IAAAA,EAAQkH,SAIjB,OAFAF,EAAOhH,CAGR,CAED,IAAKgH,EAAM,OACX,IAAiBG,EAAG,EAEpB,GAAI5G,KAAKmE,cAAgB1C,OAAQ,CAC/B,MAAMoF,EAAc7G,KAAKmE,YAAY2C,wBACrCF,EACqB,eAAnB5G,KAAKsB,UAA6BuF,EAAYE,KAAOF,EAAYG,GACpE,CAED,MAAUxE,EAAGiE,EAAKK,wBAElBhG,GACsB,eAAnBd,KAAKsB,UAA6BkB,EAAKuE,KAAOvE,EAAKwE,KACpDhH,KAAKiE,OACL2C,CACH,CAED9F,GAASyF,EAETvG,KAAK2D,aAAeC,EAAM,EAAG9C,EAAOd,KAAK6D,QAEpC7D,KAAKmB,QAAUqF,EAClBxG,KAAKoG,UAAUpG,KAAK2D,cAEpB3D,KAAK+E,QAAQvF,GAAGQ,KAAM,CACpBL,WACAC,SACAqE,OAAQjE,KAAK2D,cAGlB"} \ No newline at end of file diff --git a/dist/lenis.umd.js b/dist/lenis.umd.js index af3a682a..f489606e 100644 --- a/dist/lenis.umd.js +++ b/dist/lenis.umd.js @@ -1,3 +1,3 @@ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("tiny-emitter"),require("virtual-scroll")):"function"==typeof define&&define.amd?define(["tiny-emitter","virtual-scroll"],e):(t||self).lenis=e(t.tinyEmitter,t.virtualScroll)}(this,function(t,e){function i(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var o=/*#__PURE__*/i(t),r=/*#__PURE__*/i(e);function n(t,e){for(var i=0;i=0||(r[i]=t[i]);return r}(o,a);this.target=t,this.fromKeys=l({},h),this.toKeys=l({},h),this.keys=Object.keys(l({},h)),this.keys.forEach(function(e){i.fromKeys[e]=t[e]}),this.duration=n,this.easing=c,this.currentTime=0,this.isRunning=!0},e.stop=function(){this.isRunning=!1},e.raf=function(t){var e=this;if(this.isRunning){this.currentTime=Math.min(this.currentTime+.001*t,this.duration);var i=this.easing(this.progress);this.keys.forEach(function(t){var o=e.fromKeys[t];e.target[t]=o+(e.toKeys[t]-o)*i}),1===i&&(this.isRunning=!1)}},s(t,[{key:"progress",get:function(){return this.currentTime/this.duration}}]),t}();/*#__PURE__*/ -return function(t){var e,i;function o(e){var i,o,n,s,l=void 0===e?{}:e,c=l.duration,a=void 0===c?1.2:c,u=l.easing,p=void 0===u?function(t){return 1===t?1:1-Math.pow(2,-10*t)}:u,d=l.smooth,f=void 0===d||d,v=l.smoothTouch,g=void 0!==v&&v,w=l.touchMultiplier,y=void 0===w?2:w,m=l.direction,b=void 0===m?"vertical":m,S=l.gestureDirection,N=void 0===S?"vertical":S,O=l.wrapper,z=void 0===O?window:O,R=l.content,T=void 0===R?document.body:R;(s=t.call(this)||this).onWindowResize=function(){s.wrapperWidth=window.innerWidth,s.wrapperHeight=window.innerHeight},s.onWrapperResize=function(t){var e=t[0];if(e){var i=e.contentRect;s.wrapperWidth=i.width,s.wrapperHeight=i.height}},s.onContentResize=function(t){var e=t[0];if(e){var i=e.contentRect;s.contentWidth=i.width,s.contentHeight=i.height}},s.onVirtualScroll=function(t){var e=t.deltaY,i=t.deltaX,o=t.originalEvent;o.ctrlKey||(s.smooth=o.changedTouches?s.smoothTouch:s.options.smooth,s.stopped?o.preventDefault():s.smooth&&4!==o.buttons&&(s.smooth&&o.preventDefault(),s.targetScroll-="both"===s.gestureDirection?i+e:"horizontal"===s.gestureDirection?i:e,s.targetScroll=Math.max(0,Math.min(s.targetScroll,s.limit)),s.scrollTo(s.targetScroll)))},s.onScroll=function(t){s.isScrolling&&s.smooth||(s.targetScroll=s.scroll=s.lastScroll=s.wrapperNode[s.scrollProperty],s.notify())},window.lenisVersion="0.2.9",s.options={duration:a,easing:p,smooth:f,smoothTouch:g,touchMultiplier:y,direction:b,gestureDirection:N,wrapper:z,content:T},s.duration=a,s.easing=p,s.smooth=f,s.smoothTouch=g,s.touchMultiplier=y,s.direction=b,s.gestureDirection=N,s.wrapperNode=z,s.contentNode=T,s.wrapperNode.addEventListener("scroll",s.onScroll),s.wrapperNode===window?(s.wrapperNode.addEventListener("resize",s.onWindowResize),s.onWindowResize()):(s.wrapperHeight=s.wrapperNode.offsetHeight,s.wrapperWidth=s.wrapperNode.offsetWidth,s.wrapperObserver=new ResizeObserver(s.onWrapperResize),s.wrapperObserver.observe(s.wrapperNode)),s.contentHeight=s.contentNode.offsetHeight,s.contentWidth=s.contentNode.offsetWidth,s.contentObserver=new ResizeObserver(s.onContentResize),s.contentObserver.observe(s.contentNode),s.targetScroll=s.scroll=s.lastScroll=s.wrapperNode[s.scrollProperty],s.animate=new h;var W=(null==(i=navigator)||null==(o=i.userAgentData)?void 0:o.platform)||(null==(n=navigator)?void 0:n.platform)||"unknown";return s.virtualScroll=new r.default({el:s.wrapperNode,firefoxMultiplier:50,mouseMultiplier:W.includes("Win")?1:.4,useKeyboard:!1,touchMultiplier:s.touchMultiplier,useTouch:!0,passive:!1}),s.virtualScroll.on(s.onVirtualScroll),s}i=t,(e=o).prototype=Object.create(i.prototype),e.prototype.constructor=e,c(e,i);var n=o.prototype;return n.start=function(){this.stopped=!1},n.stop=function(){this.stopped=!0,this.animate.stop()},n.destroy=function(){var t;this.wrapperNode===window&&this.wrapperNode.removeEventListener("resize",this.onWindowResize),this.wrapperNode.removeEventListener("scroll",this.onScroll),this.virtualScroll.destroy(),null==(t=this.wrapperObserver)||t.disconnect(),this.contentObserver.disconnect()},n.raf=function(t){var e=t-(this.now||0);this.now=t,!this.stopped&&this.smooth&&(this.lastScroll=this.scroll,this.animate.raf(e),this.scroll===this.targetScroll&&(this.lastScroll=this.scroll),this.isScrolling&&(this.setScroll(this.scroll),this.notify()),this.isScrolling=this.scroll!==this.targetScroll)},n.setScroll=function(t){"horizontal"===this.direction?this.wrapperNode.scrollTo(t,0):this.wrapperNode.scrollTo(0,t)},n.notify=function(){this.emit("scroll",{scroll:this.scroll,limit:this.limit,velocity:this.velocity,direction:this.direction,progress:this.scroll/this.limit})},n.scrollTo=function(t,e){var i=void 0===e?{}:e,o=i.offset,r=void 0===o?0:o,n=i.immediate,s=void 0!==n&&n,l=i.duration,c=void 0===l?this.duration:l,a=i.easing,h=void 0===a?this.easing:a;if(null!=t){var u;if("number"==typeof t)u=t;else if("top"===t||"#top"===t)u=0;else if("bottom"===t)u=this.limit;else{var p;if("string"==typeof t)p=document.querySelector(t);else{if(null==t||!t.nodeType)return;p=t}if(!p)return;var d=0;if(this.wrapperNode!==window){var f=this.wrapperNode.getBoundingClientRect();d="horizontal"===this.direction?f.left:f.top}var v=p.getBoundingClientRect();u=("horizontal"===this.direction?v.left:v.top)+this.scroll-d}this.targetScroll=u+=r,!this.smooth||s?this.setScroll(this.targetScroll):this.animate.to(this,{duration:c,easing:h,scroll:this.targetScroll})}},s(o,[{key:"scrollProperty",get:function(){return this.wrapperNode===window?"horizontal"===this.direction?"scrollX":"scrollY":"horizontal"===this.direction?"scrollLeft":"scrollTop"}},{key:"limit",get:function(){return"horizontal"===this.direction?this.contentWidth-this.wrapperWidth:this.contentHeight-this.wrapperHeight}},{key:"velocity",get:function(){return this.scroll-this.lastScroll}}]),o}(o.default)}); +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("tiny-emitter"),require("virtual-scroll")):"function"==typeof define&&define.amd?define(["tiny-emitter","virtual-scroll"],e):(t||self).lenis=e(t.tinyEmitter,t.virtualScroll)}(this,function(t,e){function i(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var o=/*#__PURE__*/i(t),r=/*#__PURE__*/i(e);function n(t,e){for(var i=0;i=0||(r[i]=t[i]);return r}(o,h);this.target=t,this.fromKeys=l({},a),this.toKeys=l({},a),this.keys=Object.keys(l({},a)),this.keys.forEach(function(e){i.fromKeys[e]=t[e]}),this.duration=n,this.easing=c,this.currentTime=0,this.isRunning=!0},e.stop=function(){this.isRunning=!1},e.raf=function(t){var e=this;if(this.isRunning){this.currentTime=Math.min(this.currentTime+t,this.duration);var i=this.easing(this.progress);this.keys.forEach(function(t){var o=e.fromKeys[t];e.target[t]=o+(e.toKeys[t]-o)*i}),1===i&&this.stop()}},s(t,[{key:"progress",get:function(){return this.currentTime/this.duration}}]),t}();/*#__PURE__*/ +return function(t){var e,i;function o(e){var i,o,n,s,l=void 0===e?{}:e,c=l.duration,h=void 0===c?1.2:c,p=l.easing,d=void 0===p?function(t){return 1===t?1:1-Math.pow(2,-10*t)}:p,f=l.smooth,v=void 0===f||f,g=l.smoothTouch,w=void 0!==g&&g,m=l.touchMultiplier,y=void 0===m?2:m,b=l.direction,S=void 0===b?"vertical":b,N=l.gestureDirection,O=void 0===N?"vertical":N,z=l.wrapper,T=void 0===z?window:z,R=l.content,W=void 0===R?document.body:R;(s=t.call(this)||this).onWindowResize=function(){s.wrapperWidth=window.innerWidth,s.wrapperHeight=window.innerHeight},s.onWrapperResize=function(t){var e=t[0];if(e){var i=e.contentRect;s.wrapperWidth=i.width,s.wrapperHeight=i.height}},s.onContentResize=function(t){var e=t[0];if(e){var i=e.contentRect;s.contentWidth=i.width,s.contentHeight=i.height}},s.onVirtualScroll=function(t){var e=t.deltaY,i=t.deltaX,o=t.originalEvent;o.ctrlKey||(s.smooth=o.changedTouches?s.smoothTouch:s.options.smooth,s.stopped?o.preventDefault():s.smooth&&4!==o.buttons&&(s.smooth&&o.preventDefault(),s.targetScroll-="both"===s.gestureDirection?i+e:"horizontal"===s.gestureDirection?i:e,s.targetScroll=a(0,s.targetScroll,s.limit),s.scrollTo(s.targetScroll)))},s.onScroll=function(t){s.isScrolling&&s.smooth||(s.targetScroll=s.scroll=s.lastScroll=s.wrapperNode[s.scrollProperty],s.notify())},window.lenisVersion="0.2.10",s.options={duration:h,easing:d,smooth:v,smoothTouch:w,touchMultiplier:y,direction:S,gestureDirection:O,wrapper:T,content:W},s.duration=h,s.easing=d,s.smooth=v,s.smoothTouch=w,s.touchMultiplier=y,s.direction=S,s.gestureDirection=O,s.wrapperNode=T,s.contentNode=W,s.wrapperNode.addEventListener("scroll",s.onScroll),s.wrapperNode===window?(s.wrapperNode.addEventListener("resize",s.onWindowResize),s.onWindowResize()):(s.wrapperHeight=s.wrapperNode.offsetHeight,s.wrapperWidth=s.wrapperNode.offsetWidth,s.wrapperObserver=new ResizeObserver(s.onWrapperResize),s.wrapperObserver.observe(s.wrapperNode)),s.contentHeight=s.contentNode.offsetHeight,s.contentWidth=s.contentNode.offsetWidth,s.contentObserver=new ResizeObserver(s.onContentResize),s.contentObserver.observe(s.contentNode),s.targetScroll=s.scroll=s.lastScroll=s.wrapperNode[s.scrollProperty],s.animate=new u;var j=(null==(i=navigator)||null==(o=i.userAgentData)?void 0:o.platform)||(null==(n=navigator)?void 0:n.platform)||"unknown";return s.virtualScroll=new r.default({el:s.wrapperNode,firefoxMultiplier:50,mouseMultiplier:j.includes("Win")?1:.4,useKeyboard:!1,touchMultiplier:s.touchMultiplier,useTouch:!0,passive:!1}),s.virtualScroll.on(s.onVirtualScroll),s}i=t,(e=o).prototype=Object.create(i.prototype),e.prototype.constructor=e,c(e,i);var n=o.prototype;return n.start=function(){this.stopped=!1},n.stop=function(){this.stopped=!0,this.animate.stop()},n.destroy=function(){var t;this.wrapperNode===window&&this.wrapperNode.removeEventListener("resize",this.onWindowResize),this.wrapperNode.removeEventListener("scroll",this.onScroll),this.virtualScroll.destroy(),null==(t=this.wrapperObserver)||t.disconnect(),this.contentObserver.disconnect()},n.raf=function(t){var e=t-(this.now||0);this.now=t,!this.stopped&&this.smooth&&(this.lastScroll=this.scroll,this.animate.raf(.001*e),this.scroll===this.targetScroll&&(this.lastScroll=this.scroll),this.isScrolling&&(this.setScroll(this.scroll),this.notify()),this.isScrolling=this.scroll!==this.targetScroll)},n.setScroll=function(t){"horizontal"===this.direction?this.wrapperNode.scrollTo(t,0):this.wrapperNode.scrollTo(0,t)},n.notify=function(){this.emit("scroll",{scroll:this.scroll,limit:this.limit,velocity:this.velocity,direction:this.direction,progress:this.scroll/this.limit})},n.scrollTo=function(t,e){var i=void 0===e?{}:e,o=i.offset,r=void 0===o?0:o,n=i.immediate,s=void 0!==n&&n,l=i.duration,c=void 0===l?this.duration:l,h=i.easing,u=void 0===h?this.easing:h;if(null!=t){var p;if("number"==typeof t)p=t;else if("top"===t||"#top"===t)p=0;else if("bottom"===t)p=this.limit;else{var d;if("string"==typeof t)d=document.querySelector(t);else{if(null==t||!t.nodeType)return;d=t}if(!d)return;var f=0;if(this.wrapperNode!==window){var v=this.wrapperNode.getBoundingClientRect();f="horizontal"===this.direction?v.left:v.top}var g=d.getBoundingClientRect();p=("horizontal"===this.direction?g.left:g.top)+this.scroll-f}this.targetScroll=a(0,p+=r,this.limit),!this.smooth||s?this.setScroll(this.targetScroll):this.animate.to(this,{duration:c,easing:u,scroll:this.targetScroll})}},s(o,[{key:"scrollProperty",get:function(){return this.wrapperNode===window?"horizontal"===this.direction?"scrollX":"scrollY":"horizontal"===this.direction?"scrollLeft":"scrollTop"}},{key:"limit",get:function(){return"horizontal"===this.direction?this.contentWidth-this.wrapperWidth:this.contentHeight-this.wrapperHeight}},{key:"velocity",get:function(){return this.scroll-this.lastScroll}}]),o}(o.default)}); //# sourceMappingURL=lenis.umd.js.map diff --git a/dist/lenis.umd.js.map b/dist/lenis.umd.js.map index 19b70ad3..c518b726 100644 --- a/dist/lenis.umd.js.map +++ b/dist/lenis.umd.js.map @@ -1 +1 @@ -{"version":3,"file":"lenis.umd.js","sources":["../src/lenis.js","../src/maths.js"],"sourcesContent":["import EventEmitter from 'tiny-emitter'\r\nimport VirtualScroll from 'virtual-scroll'\r\nimport { version } from '../package.json'\r\nimport { clamp } from './maths.js'\r\n\r\nclass Animate {\r\n to(target, { duration = 1, easing = (t) => t, ...keys } = {}) {\r\n this.target = target\r\n this.fromKeys = { ...keys }\r\n this.toKeys = { ...keys }\r\n this.keys = Object.keys({ ...keys })\r\n\r\n // get initial values\r\n this.keys.forEach((key) => {\r\n this.fromKeys[key] = target[key]\r\n })\r\n\r\n this.duration = duration\r\n this.easing = easing\r\n this.currentTime = 0\r\n this.isRunning = true\r\n }\r\n\r\n stop() {\r\n this.isRunning = false\r\n }\r\n\r\n raf(deltaTime) {\r\n if (!this.isRunning) return\r\n\r\n this.currentTime = Math.min(\r\n this.currentTime + deltaTime * 0.001,\r\n this.duration\r\n )\r\n\r\n const progress = this.easing(this.progress)\r\n\r\n this.keys.forEach((key) => {\r\n const from = this.fromKeys[key]\r\n const to = this.toKeys[key]\r\n\r\n const value = from + (to - from) * progress\r\n\r\n this.target[key] = value\r\n })\r\n\r\n if (progress === 1) {\r\n this.isRunning = false\r\n }\r\n }\r\n\r\n get progress() {\r\n return this.currentTime / this.duration\r\n }\r\n}\r\n\r\nexport default class Lenis extends EventEmitter {\r\n constructor({\r\n duration = 1.2,\r\n easing = (t) => (t === 1 ? 1 : 1 - Math.pow(2, -10 * t)), // https://easings.net/en#easeOutExpo\r\n smooth = true,\r\n smoothTouch = false,\r\n touchMultiplier = 2,\r\n direction = 'vertical', // vertical, horizontal\r\n gestureDirection = 'vertical', // vertical, horizontal, both\r\n wrapper = window,\r\n content = document.body,\r\n } = {}) {\r\n super()\r\n\r\n window.lenisVersion = version\r\n\r\n this.options = {\r\n duration,\r\n easing,\r\n smooth,\r\n smoothTouch,\r\n touchMultiplier,\r\n direction,\r\n gestureDirection,\r\n wrapper,\r\n content,\r\n }\r\n\r\n this.duration = duration\r\n this.easing = easing\r\n this.smooth = smooth\r\n this.smoothTouch = smoothTouch\r\n this.touchMultiplier = touchMultiplier\r\n this.direction = direction\r\n this.gestureDirection = gestureDirection\r\n this.wrapperNode = wrapper\r\n this.contentNode = content\r\n\r\n this.wrapperNode.addEventListener('scroll', this.onScroll)\r\n\r\n //observe wrapper node size\r\n if (this.wrapperNode === window) {\r\n this.wrapperNode.addEventListener('resize', this.onWindowResize)\r\n this.onWindowResize()\r\n } else {\r\n this.wrapperHeight = this.wrapperNode.offsetHeight\r\n this.wrapperWidth = this.wrapperNode.offsetWidth\r\n\r\n //observe wrapper node size\r\n this.wrapperObserver = new ResizeObserver(this.onWrapperResize)\r\n this.wrapperObserver.observe(this.wrapperNode)\r\n }\r\n\r\n this.contentHeight = this.contentNode.offsetHeight\r\n this.contentWidth = this.contentNode.offsetWidth\r\n\r\n //observe content node size\r\n this.contentObserver = new ResizeObserver(this.onContentResize)\r\n this.contentObserver.observe(this.contentNode)\r\n\r\n //set initial scroll position\r\n this.targetScroll =\r\n this.scroll =\r\n this.lastScroll =\r\n this.wrapperNode[this.scrollProperty]\r\n\r\n this.animate = new Animate()\r\n\r\n const platform =\r\n navigator?.userAgentData?.platform || navigator?.platform || 'unknown'\r\n\r\n // listen and normalize wheel event cross-browser\r\n this.virtualScroll = new VirtualScroll({\r\n el: this.wrapperNode,\r\n firefoxMultiplier: 50,\r\n mouseMultiplier: platform.includes('Win') ? 1 : 0.4,\r\n useKeyboard: false,\r\n touchMultiplier: this.touchMultiplier,\r\n useTouch: true,\r\n passive: false,\r\n })\r\n\r\n this.virtualScroll.on(this.onVirtualScroll)\r\n }\r\n\r\n get scrollProperty() {\r\n let property\r\n if (this.wrapperNode === window) {\r\n property = this.direction === 'horizontal' ? 'scrollX' : 'scrollY'\r\n } else {\r\n property = this.direction === 'horizontal' ? 'scrollLeft' : 'scrollTop'\r\n }\r\n return property\r\n }\r\n\r\n start() {\r\n this.stopped = false\r\n }\r\n\r\n stop() {\r\n this.stopped = true\r\n this.animate.stop()\r\n }\r\n\r\n destroy() {\r\n if (this.wrapperNode === window) {\r\n this.wrapperNode.removeEventListener('resize', this.onWindowResize)\r\n }\r\n this.wrapperNode.removeEventListener('scroll', this.onScroll)\r\n\r\n this.virtualScroll.destroy()\r\n this.wrapperObserver?.disconnect()\r\n this.contentObserver.disconnect()\r\n }\r\n\r\n onWindowResize = () => {\r\n this.wrapperWidth = window.innerWidth\r\n this.wrapperHeight = window.innerHeight\r\n }\r\n\r\n onWrapperResize = ([entry]) => {\r\n if (entry) {\r\n const rect = entry.contentRect\r\n this.wrapperWidth = rect.width\r\n this.wrapperHeight = rect.height\r\n }\r\n }\r\n\r\n onContentResize = ([entry]) => {\r\n if (entry) {\r\n const rect = entry.contentRect\r\n this.contentWidth = rect.width\r\n this.contentHeight = rect.height\r\n }\r\n }\r\n\r\n get limit() {\r\n return this.direction === 'horizontal'\r\n ? this.contentWidth - this.wrapperWidth\r\n : this.contentHeight - this.wrapperHeight\r\n }\r\n\r\n onVirtualScroll = ({ deltaY, deltaX, originalEvent: e }) => {\r\n if (e.ctrlKey) return\r\n\r\n // switch to smooth if event is touch and touch is true\r\n this.smooth = !!e.changedTouches ? this.smoothTouch : this.options.smooth\r\n\r\n if (this.stopped) {\r\n e.preventDefault()\r\n return\r\n }\r\n\r\n if (!this.smooth) return\r\n\r\n // fix wheel holding scroll https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/buttons\r\n if (e.buttons === 4) return\r\n\r\n // prevent native wheel scrolling\r\n if (this.smooth) e.preventDefault()\r\n\r\n let delta = 0\r\n if (this.gestureDirection === 'both') {\r\n delta = deltaX + deltaY\r\n } else if (this.gestureDirection === 'horizontal') {\r\n delta = deltaX\r\n } else {\r\n // vertical\r\n delta = deltaY\r\n }\r\n\r\n this.targetScroll -= delta\r\n this.targetScroll = clamp(0, this.targetScroll, this.limit)\r\n\r\n this.scrollTo(this.targetScroll)\r\n }\r\n\r\n raf(now) {\r\n const deltaTime = now - (this.now || 0)\r\n this.now = now\r\n\r\n if (this.stopped || !this.smooth) return\r\n\r\n this.lastScroll = this.scroll\r\n\r\n // where this.scroll is updated\r\n this.animate.raf(deltaTime)\r\n\r\n if (this.scroll === this.targetScroll) {\r\n // if target reached velocity should be 0\r\n this.lastScroll = this.scroll\r\n }\r\n\r\n if (this.isScrolling) {\r\n this.setScroll(this.scroll)\r\n this.notify()\r\n }\r\n\r\n this.isScrolling = this.scroll !== this.targetScroll\r\n }\r\n\r\n get velocity() {\r\n return this.scroll - this.lastScroll\r\n }\r\n\r\n setScroll(value) {\r\n this.direction === 'horizontal'\r\n ? this.wrapperNode.scrollTo(value, 0)\r\n : this.wrapperNode.scrollTo(0, value)\r\n }\r\n\r\n onScroll = (e) => {\r\n // if isScrolling false we can consider user isn't scrolling with wheel (cmd+F, keyboard or whatever). So we must scroll to value immediately\r\n if (!this.isScrolling || !this.smooth) {\r\n // where native scroll happens\r\n this.targetScroll =\r\n this.scroll =\r\n this.lastScroll =\r\n this.wrapperNode[this.scrollProperty]\r\n\r\n this.notify()\r\n }\r\n }\r\n\r\n notify() {\r\n this.emit('scroll', {\r\n scroll: this.scroll,\r\n limit: this.limit,\r\n velocity: this.velocity,\r\n direction: this.direction,\r\n progress: this.scroll / this.limit,\r\n })\r\n }\r\n\r\n scrollTo(\r\n target,\r\n {\r\n offset = 0,\r\n immediate = false,\r\n duration = this.duration,\r\n easing = this.easing,\r\n } = {}\r\n ) {\r\n if (target === undefined || target === null) return\r\n let value\r\n\r\n if (typeof target === 'number') {\r\n value = target\r\n } else if (target === 'top' || target === '#top') {\r\n value = 0\r\n } else if (target === 'bottom') {\r\n value = 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 } else {\r\n return\r\n }\r\n\r\n if (!node) return\r\n let wrapperOffset = 0\r\n\r\n if (this.wrapperNode !== window) {\r\n const wrapperRect = this.wrapperNode.getBoundingClientRect()\r\n wrapperOffset =\r\n this.direction === 'horizontal' ? wrapperRect.left : wrapperRect.top\r\n }\r\n\r\n const rect = node.getBoundingClientRect()\r\n\r\n value =\r\n (this.direction === 'horizontal' ? rect.left : rect.top) +\r\n this.scroll -\r\n wrapperOffset\r\n }\r\n\r\n value += offset\r\n\r\n this.targetScroll = value\r\n\r\n if (!this.smooth || immediate) {\r\n this.setScroll(this.targetScroll)\r\n } else {\r\n this.animate.to(this, {\r\n duration,\r\n easing,\r\n scroll: this.targetScroll,\r\n })\r\n }\r\n }\r\n}\r\n","export function clamp(min, input, max) {\r\n return Math.max(min, Math.min(input, max))\r\n}\r\n\r\nexport function mapRange(in_min, in_max, input, out_min, out_max) {\r\n return ((input - in_min) * (out_max - out_min)) / (in_max - in_min) + out_min\r\n}\r\n\r\nexport function lerp(start, end, amt) {\r\n return (1 - amt) * start + amt * end\r\n}\r\n\r\nexport function truncate(value, decimals) {\r\n return parseFloat(value.toFixed(decimals))\r\n}\r\n"],"names":["_excluded","Lenis","to","target","_temp","_this","this","_ref","duration","_ref$duration","_ref$easing","easing","t","keys","fromKeys","toKeys","_extends","Object","forEach","key","currentTime","isRunning","stop","raf","deltaTime","_this2","Math","min","progress","from","_temp2","_navigator","_navigator$userAgentD","_navigator2","_this3","_ref2","_ref2$duration","_ref2$easing","pow","smooth","_ref2$smooth","smoothTouch","_ref2$smoothTouch","_ref2$touchMultiplier","touchMultiplier","_ref2$direction","direction","gestureDirection","_ref2$gestureDirectio","wrapper","_ref2$wrapper","window","content","_ref2$content","document","body","_EventEmitter","call","onWindowResize","wrapperWidth","innerWidth","wrapperHeight","innerHeight","onWrapperResize","_ref3","entry","rect","contentRect","width","height","onContentResize","_ref4","contentWidth","contentHeight","onVirtualScroll","_ref5","deltaY","deltaX","e","originalEvent","ctrlKey","changedTouches","options","stopped","preventDefault","buttons","targetScroll","max","limit","scrollTo","onScroll","isScrolling","scroll","lastScroll","wrapperNode","scrollProperty","notify","lenisVersion","contentNode","addEventListener","offsetHeight","offsetWidth","wrapperObserver","observe","contentObserver","ResizeObserver","animate","Animate","platform","navigator","userAgentData","virtualScroll","VirtualScroll","el","firefoxMultiplier","mouseMultiplier","includes","useKeyboard","useTouch","passive","on","EventEmitter","start","destroy","_this$wrapperObserver","removeEventListener","disconnect","now","setScroll","value","emit","velocity","_temp3","_ref6","_ref6$offset","offset","_ref6$immediate","immediate","_ref6$duration","node","querySelector","nodeType","wrapperOffset","wrapperRect","getBoundingClientRect","left","top","_createClass","get"],"mappings":"8iCAAA,IAAAA,EAAA,CAAA,WAAA,oEAwDqBC,SAlDnBC,GAAA,SAAGC,EAA2DC,GAAA,IAAAC,EAAAC,KAAAC,OAAA,IAAAH,EAAJ,CAAA,EAA7CI,EAAAA,EAAAA,EAAAA,SAAAA,aAAW,EAAsCC,EAAAC,EAAAH,EAAnCI,OAAAA,aAAS,SAACC,GAAMA,OAAAA,CAAP,EAAaC,EAAAA,0IAC/CP,KAAKH,OAASA,EACdG,KAAKQ,cAAgBD,GACrBP,KAAKS,OAALC,EAAA,CAAA,EAAmBH,GACnBP,KAAKO,KAAOI,OAAOJ,UAAUA,IAG7BP,KAAKO,KAAKK,QAAQ,SAACC,GACjBd,EAAKS,SAASK,GAAOhB,EAAOgB,EAC7B,GAEDb,KAAKE,SAAWA,EAChBF,KAAKK,OAASA,EACdL,KAAKc,YAAc,EACnBd,KAAKe,WAAY,CAClB,IAEDC,KAAA,WACEhB,KAAKe,WAAY,CAClB,IAEDE,IAAA,SAAIC,GAAW,IAAAC,EAAAnB,KACb,GAAKA,KAAKe,UAAV,CAEAf,KAAKc,YAAcM,KAAKC,IACtBrB,KAAKc,YAA0B,KAAZI,EACnBlB,KAAKE,UAGP,IAAcoB,EAAGtB,KAAKK,OAAOL,KAAKsB,UAElCtB,KAAKO,KAAKK,QAAQ,SAACC,GACjB,IAAMU,EAAOJ,EAAKX,SAASK,GAK3BM,EAAKtB,OAAOgB,GAFEU,GAFHJ,EAAKV,OAAOI,GAEIU,GAAQD,C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AC/B,IAAM4F,EAAczI,KAAKwF,YAAYkD,wBACrCF,EACqB,eAAnBxI,KAAKwC,UAA6BiG,EAAYE,KAAOF,EAAYG,GACpE,CAED,IAAUhF,EAAGyE,EAAKK,wBAElBf,GACsB,eAAnB3H,KAAKwC,UAA6BoB,EAAK+E,KAAO/E,EAAKgF,KACpD5I,KAAKsF,OACLkD,CACH,CAIDxI,KAAKgF,aAFL2C,GAASM,GAIJjI,KAAKiC,QAAUkG,EAClBnI,KAAK0H,UAAU1H,KAAKgF,cAEpBhF,KAAKoG,QAAQxG,GAAGI,KAAM,CACpBE,SAAAA,EACAG,OAAAA,EACAiF,OAAQtF,KAAKgF,cAjD4B,CAoD9C,EAlND6D,EAAAlJ,EAAA,CAAA,CAAAkB,IAAA,iBAAAiI,IAAA,WAOE,OALI9I,KAAKwF,cAAgB3C,OACO,eAAnB7C,KAAKwC,UAA6B,UAAY,UAE3B,eAAnBxC,KAAKwC,UAA6B,aAAe,WAG/D,GA2CD,CAAA3B,IAAA,QAAAiI,IAAA,WACE,MAA0B,oBAAdtG,UACRxC,KAAKkE,aAAelE,KAAKqD,aACzBrD,KAAKmE,cAAgBnE,KAAKuD,aAC/B,uBA6DD,WACE,OAAY+B,KAAAA,OAAStF,KAAKuF,UAC3B,KA3MgC4B,CAAAA,EAAAA"} \ No newline at end of file +{"version":3,"file":"lenis.umd.js","sources":["../src/maths.js","../src/lenis.js"],"sourcesContent":["export function clamp(min, input, max) {\r\n return Math.max(min, Math.min(input, max))\r\n}\r\n\r\nexport function mapRange(in_min, in_max, input, out_min, out_max) {\r\n return ((input - in_min) * (out_max - out_min)) / (in_max - in_min) + out_min\r\n}\r\n\r\nexport function lerp(start, end, amt) {\r\n return (1 - amt) * start + amt * end\r\n}\r\n\r\nexport function truncate(value, decimals) {\r\n return parseFloat(value.toFixed(decimals))\r\n}\r\n","import EventEmitter from 'tiny-emitter'\r\nimport VirtualScroll from 'virtual-scroll'\r\nimport { version } from '../package.json'\r\nimport { clamp } from './maths.js'\r\n\r\nclass Animate {\r\n to(target, { duration = 1, easing = (t) => t, ...keys } = {}) {\r\n this.target = target\r\n this.fromKeys = { ...keys }\r\n this.toKeys = { ...keys }\r\n this.keys = Object.keys({ ...keys })\r\n\r\n // get initial values\r\n this.keys.forEach((key) => {\r\n this.fromKeys[key] = target[key]\r\n })\r\n\r\n this.duration = duration\r\n this.easing = easing\r\n this.currentTime = 0\r\n this.isRunning = true\r\n }\r\n\r\n stop() {\r\n this.isRunning = false\r\n }\r\n\r\n raf(deltaTime) {\r\n if (!this.isRunning) return\r\n\r\n this.currentTime = Math.min(this.currentTime + deltaTime, this.duration)\r\n\r\n const progress = this.easing(this.progress)\r\n\r\n this.keys.forEach((key) => {\r\n const from = this.fromKeys[key]\r\n const to = this.toKeys[key]\r\n\r\n const value = from + (to - from) * progress\r\n\r\n this.target[key] = value\r\n })\r\n\r\n if (progress === 1) {\r\n this.stop()\r\n }\r\n }\r\n\r\n get progress() {\r\n return this.currentTime / this.duration\r\n }\r\n}\r\n\r\nexport default class Lenis extends EventEmitter {\r\n constructor({\r\n duration = 1.2,\r\n easing = (t) => (t === 1 ? 1 : 1 - Math.pow(2, -10 * t)), // https://easings.net/en#easeOutExpo\r\n smooth = true,\r\n smoothTouch = false,\r\n touchMultiplier = 2,\r\n direction = 'vertical', // vertical, horizontal\r\n gestureDirection = 'vertical', // vertical, horizontal, both\r\n wrapper = window,\r\n content = document.body,\r\n } = {}) {\r\n super()\r\n\r\n window.lenisVersion = version\r\n\r\n this.options = {\r\n duration,\r\n easing,\r\n smooth,\r\n smoothTouch,\r\n touchMultiplier,\r\n direction,\r\n gestureDirection,\r\n wrapper,\r\n content,\r\n }\r\n\r\n this.duration = duration\r\n this.easing = easing\r\n this.smooth = smooth\r\n this.smoothTouch = smoothTouch\r\n this.touchMultiplier = touchMultiplier\r\n this.direction = direction\r\n this.gestureDirection = gestureDirection\r\n this.wrapperNode = wrapper\r\n this.contentNode = content\r\n\r\n this.wrapperNode.addEventListener('scroll', this.onScroll)\r\n\r\n //observe wrapper node size\r\n if (this.wrapperNode === window) {\r\n this.wrapperNode.addEventListener('resize', this.onWindowResize)\r\n this.onWindowResize()\r\n } else {\r\n this.wrapperHeight = this.wrapperNode.offsetHeight\r\n this.wrapperWidth = this.wrapperNode.offsetWidth\r\n\r\n //observe wrapper node size\r\n this.wrapperObserver = new ResizeObserver(this.onWrapperResize)\r\n this.wrapperObserver.observe(this.wrapperNode)\r\n }\r\n\r\n this.contentHeight = this.contentNode.offsetHeight\r\n this.contentWidth = this.contentNode.offsetWidth\r\n\r\n //observe content node size\r\n this.contentObserver = new ResizeObserver(this.onContentResize)\r\n this.contentObserver.observe(this.contentNode)\r\n\r\n //set initial scroll position\r\n this.targetScroll =\r\n this.scroll =\r\n this.lastScroll =\r\n this.wrapperNode[this.scrollProperty]\r\n\r\n this.animate = new Animate()\r\n\r\n const platform =\r\n navigator?.userAgentData?.platform || navigator?.platform || 'unknown'\r\n\r\n // listen and normalize wheel event cross-browser\r\n this.virtualScroll = new VirtualScroll({\r\n el: this.wrapperNode,\r\n firefoxMultiplier: 50,\r\n mouseMultiplier: platform.includes('Win') ? 1 : 0.4,\r\n useKeyboard: false,\r\n touchMultiplier: this.touchMultiplier,\r\n useTouch: true,\r\n passive: false,\r\n })\r\n\r\n this.virtualScroll.on(this.onVirtualScroll)\r\n }\r\n\r\n get scrollProperty() {\r\n let property\r\n if (this.wrapperNode === window) {\r\n property = this.direction === 'horizontal' ? 'scrollX' : 'scrollY'\r\n } else {\r\n property = this.direction === 'horizontal' ? 'scrollLeft' : 'scrollTop'\r\n }\r\n return property\r\n }\r\n\r\n start() {\r\n this.stopped = false\r\n }\r\n\r\n stop() {\r\n this.stopped = true\r\n this.animate.stop()\r\n }\r\n\r\n destroy() {\r\n if (this.wrapperNode === window) {\r\n this.wrapperNode.removeEventListener('resize', this.onWindowResize)\r\n }\r\n this.wrapperNode.removeEventListener('scroll', this.onScroll)\r\n\r\n this.virtualScroll.destroy()\r\n this.wrapperObserver?.disconnect()\r\n this.contentObserver.disconnect()\r\n }\r\n\r\n onWindowResize = () => {\r\n this.wrapperWidth = window.innerWidth\r\n this.wrapperHeight = window.innerHeight\r\n }\r\n\r\n onWrapperResize = ([entry]) => {\r\n if (entry) {\r\n const rect = entry.contentRect\r\n this.wrapperWidth = rect.width\r\n this.wrapperHeight = rect.height\r\n }\r\n }\r\n\r\n onContentResize = ([entry]) => {\r\n if (entry) {\r\n const rect = entry.contentRect\r\n this.contentWidth = rect.width\r\n this.contentHeight = rect.height\r\n }\r\n }\r\n\r\n get limit() {\r\n return this.direction === 'horizontal'\r\n ? this.contentWidth - this.wrapperWidth\r\n : this.contentHeight - this.wrapperHeight\r\n }\r\n\r\n onVirtualScroll = ({ deltaY, deltaX, originalEvent: e }) => {\r\n if (e.ctrlKey) return\r\n\r\n // switch to smooth if event is touch and touch is true\r\n this.smooth = !!e.changedTouches ? this.smoothTouch : this.options.smooth\r\n\r\n if (this.stopped) {\r\n e.preventDefault()\r\n return\r\n }\r\n\r\n if (!this.smooth) return\r\n\r\n // fix wheel holding scroll https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/buttons\r\n if (e.buttons === 4) return\r\n\r\n // prevent native wheel scrolling\r\n if (this.smooth) e.preventDefault()\r\n\r\n let delta = 0\r\n if (this.gestureDirection === 'both') {\r\n delta = deltaX + deltaY\r\n } else if (this.gestureDirection === 'horizontal') {\r\n delta = deltaX\r\n } else {\r\n // vertical\r\n delta = deltaY\r\n }\r\n\r\n this.targetScroll -= delta\r\n this.targetScroll = clamp(0, this.targetScroll, this.limit)\r\n\r\n this.scrollTo(this.targetScroll)\r\n }\r\n\r\n raf(now) {\r\n const deltaTime = now - (this.now || 0)\r\n this.now = now\r\n\r\n if (this.stopped || !this.smooth) return\r\n\r\n this.lastScroll = this.scroll\r\n\r\n // where this.scroll is updated\r\n this.animate.raf(deltaTime * 0.001)\r\n\r\n if (this.scroll === this.targetScroll) {\r\n // if target reached velocity should be 0\r\n this.lastScroll = this.scroll\r\n }\r\n\r\n if (this.isScrolling) {\r\n this.setScroll(this.scroll)\r\n this.notify()\r\n }\r\n\r\n this.isScrolling = this.scroll !== this.targetScroll\r\n }\r\n\r\n get velocity() {\r\n return this.scroll - this.lastScroll\r\n }\r\n\r\n setScroll(value) {\r\n this.direction === 'horizontal'\r\n ? this.wrapperNode.scrollTo(value, 0)\r\n : this.wrapperNode.scrollTo(0, value)\r\n }\r\n\r\n onScroll = (e) => {\r\n // if isScrolling false we can consider user isn't scrolling with wheel (cmd+F, keyboard or whatever). So we must scroll to value immediately\r\n if (!this.isScrolling || !this.smooth) {\r\n // where native scroll happens\r\n this.targetScroll =\r\n this.scroll =\r\n this.lastScroll =\r\n this.wrapperNode[this.scrollProperty]\r\n\r\n this.notify()\r\n }\r\n }\r\n\r\n notify() {\r\n this.emit('scroll', {\r\n scroll: this.scroll,\r\n limit: this.limit,\r\n velocity: this.velocity,\r\n direction: this.direction,\r\n progress: this.scroll / this.limit,\r\n })\r\n }\r\n\r\n scrollTo(\r\n target,\r\n {\r\n offset = 0,\r\n immediate = false,\r\n duration = this.duration,\r\n easing = this.easing,\r\n } = {}\r\n ) {\r\n if (target === undefined || target === null) return\r\n let value\r\n\r\n if (typeof target === 'number') {\r\n value = target\r\n } else if (target === 'top' || target === '#top') {\r\n value = 0\r\n } else if (target === 'bottom') {\r\n value = 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 } else {\r\n return\r\n }\r\n\r\n if (!node) return\r\n let wrapperOffset = 0\r\n\r\n if (this.wrapperNode !== window) {\r\n const wrapperRect = this.wrapperNode.getBoundingClientRect()\r\n wrapperOffset =\r\n this.direction === 'horizontal' ? wrapperRect.left : wrapperRect.top\r\n }\r\n\r\n const rect = node.getBoundingClientRect()\r\n\r\n value =\r\n (this.direction === 'horizontal' ? rect.left : rect.top) +\r\n this.scroll -\r\n wrapperOffset\r\n }\r\n\r\n value += offset\r\n\r\n this.targetScroll = clamp(0, value, this.limit)\r\n\r\n if (!this.smooth || immediate) {\r\n this.setScroll(this.targetScroll)\r\n } else {\r\n this.animate.to(this, {\r\n duration,\r\n easing,\r\n scroll: this.targetScroll,\r\n })\r\n }\r\n }\r\n}\r\n"],"names":["min","input","max","Math","_excluded","to","target","_temp","_this","this","_ref","duration","_ref$duration","_ref$easing","easing","t","keys","fromKeys","toKeys","_extends","Object","forEach","key","currentTime","isRunning","stop","raf","deltaTime","_this2","progress","from","_createClass","Animate","get","_navigator","_navigator$userAgentD","_navigator2","_this3","_ref2","_temp2","_ref2$duration","_ref2$easing","pow","_ref2$smooth","smooth","smoothTouch","_ref2$smoothTouch","touchMultiplier","_ref2$touchMultiplier","direction","_ref2$direction","gestureDirection","_ref2$gestureDirectio","wrapper","_ref2$wrapper","window","content","document","body","_ref2$content","_EventEmitter","call","onWindowResize","wrapperWidth","innerWidth","wrapperHeight","innerHeight","onWrapperResize","entry","contentRect","rect","width","height","onContentResize","_ref4","contentWidth","contentHeight","onVirtualScroll","_ref5","deltaY","deltaX","e","originalEvent","ctrlKey","changedTouches","options","stopped","preventDefault","buttons","targetScroll","clamp","limit","scrollTo","onScroll","isScrolling","scroll","lastScroll","wrapperNode","scrollProperty","notify","lenisVersion","contentNode","addEventListener","offsetHeight","offsetWidth","wrapperObserver","ResizeObserver","observe","contentObserver","animate","platform","navigator","userAgentData","virtualScroll","el","firefoxMultiplier","mouseMultiplier","includes","useKeyboard","useTouch","passive","on","EventEmitter","start","destroy","_this$wrapperObserver","removeEventListener","disconnect","now","setScroll","value","emit","velocity","_ref6","_temp3","offset","_ref6$offset","immediate","_ref6$immediate","_ref6$duration","_ref6$easing","node","querySelector","nodeType","wrapperOffset","wrapperRect","getBoundingClientRect","left","top","Lenis"],"mappings":"8iCAAO,WAAeA,EAAKC,EAAOC,GAChC,OAAWC,KAACD,IAAIF,EAAKG,KAAKH,IAAIC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,KAAKgF,cAEpBhF,KAAKoG,QAAQxG,GAAGI,KAAM,CACpBE,SAAAA,EACAG,OAAAA,EACAiF,OAAQtF,KAAKgF,cAjD4B,CAoD9C,EAlND1D,EAAAsH,EAAA,CAAA,CAAA/H,IAAA,iBAAAW,IAAA,WAOE,OALIxB,KAAKwF,cAAgB1C,OACO,eAAnB9C,KAAKwC,UAA6B,UAAY,UAE3B,eAAnBxC,KAAKwC,UAA6B,aAAe,WAG/D,GA2CD,CAAA3B,IAAA,QAAAW,IAAA,WACE,MAA0B,oBAAdgB,UACRxC,KAAKkE,aAAelE,KAAKsD,aACzBtD,KAAKmE,cAAgBnE,KAAKwD,aAC/B,uBA6DD,WACE,OAAY8B,KAAAA,OAAStF,KAAKuF,UAC3B,KA3MgC0B,CAAAA,EAAAA"} \ No newline at end of file diff --git a/package.json b/package.json index 8d653bc8..f8f1d0c8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@studio-freight/lenis", - "version": "0.2.9", + "version": "0.2.10", "description": "Lenis is a smooth scroll library to normalize the scrolling experience across devices", "files": [ "dist"