diff --git a/README.md b/README.md index ff8ba314..e053037f 100644 --- a/README.md +++ b/README.md @@ -11,23 +11,46 @@ This is our take on smooth scroll, lightweight, hard working, smooth as butter s ## Features - Performant -- Lightweight [(~2Kb gzipped)](https://bundle.js.org/?q=@studio-freight/lenis) +- Lightweight [(~2Kb gzipped)](https://bundlejs.com/?q=%40studio-freight%2Flenis) - Run scroll in main thread - Accessibility (CMD+F page search, Tab and arrow navigation, keep scroll position on page refresh, etc.) - External RAF - SSR proof +- Not opinionated +- Tree-shakable +- Custom scroll easing/duration
-## Installing +| Feature | [Locomotive-scroll](https://github.com/locomotivemtl/locomotive-scroll) | [GSAP ScrollSmoother](https://greensock.com/scrollsmoother/) | [Lenis](https://github.com/studio-freight/lenis) | +|-----------------------------|-------------------|---------------------|--------| +| Native scrollbar | ❌ | ✅ | ✅ | +| Native scroll inputs | ❌ | ✅ | ❌ | +| Normalize scroll experience | ✅ | ❌ | ✅ | +| Accessibility | ❌ | ❌ | ✅ | +| CSS Sticky | ❌ | ❌ | ✅ | +| IntsersectionObserver | ❌ | ❌ | ✅ | +| Open source | ✅ | ❌ | ✅ | +| Built-in animation system | ✅ | ✅ | ❌ | +| Size (gzip) | [12.33KB](https://bundlejs.com/?q=locomotive-scroll) | [26.08KB](https://bundlejs.com/?q=gsap%2FScrollSmoother&treeshake=%5B%7BScrollSmoother%7D%5D) | [2.13kb](https://bundlejs.com/?q=%40studio-freight%2Flenis) | -just the usual: +
+## Installing + +using package manager: ```bash $ npm i @studio-freight/lenis ``` -or replace `npm` with your package manager of choice :) +
+ +using scripts: +```html + +``` + +
@@ -141,6 +164,9 @@ body { - [Repeat](https://getrepeat.io/) by [Studio Freight](https://www.studiofreight.com/) - [Dragonfly](https://dragonfly.xyz/) by [Studio Freight](https://www.studiofreight.com/) - [Yuga Labs](https://yuga.com/) by [Antinomy Studio](https://antinomy.studio/) +- [Quentin Hocde's Portfolio](https://quentinhocde.com) by [Quentin Hocde](https://twitter.com/QuentinHocde) +- [Houses Of](https://housesof.world) by [Félix P.](https://flayks.com/) & [Shelby Kay](https://shelbykay.dev/) +- [Shelby Kay's Portfolio](https://shelbykay.dev) by [Shelby Kay](https://shelbykay.dev/)
diff --git a/bundled/lenis.js b/bundled/lenis.js index d9c0a04d..60a28c77 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}(),l=["duration","easing"],h=/*#__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,h=n.easing,a=void 0===h?function(t){return t}:h,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,l);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+.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)}},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,l=void 0===e?{}:e,a=l.duration,c=void 0===a?1.2:a,u=l.easing,d=void 0===u?function(t){return 1===t?1:1-Math.pow(2,-10*t)}:u,p=l.smooth,f=void 0===p||p,v=l.smoothTouch,y=void 0!==v&&v,w=l.touchMultiplier,g=void 0===w?2:w,m=l.direction,b=void 0===m?"vertical":m,T=l.wrapper,S=void 0===T?window:T,_=l.content,M=void 0===_?document.body:_;(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.originalEvent;i.ctrlKey||(r.smooth=i.changedTouches?r.smoothTouch:r.options.smooth,r.stopped?i.preventDefault():r.smooth&&4!==i.buttons&&(r.smooth&&i.preventDefault(),r.targetScroll-=e,r.targetScroll=Math.max(0,Math.min(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.6",r.options={duration:c,easing:d,smooth:f,smoothTouch:y,touchMultiplier:g,direction:b,wrapper:S,content:M},r.wrapperNode=S,r.contentNode=M,r.duration=c,r.easing=d,r.smooth=f,r.smoothTouch=y,r.touchMultiplier=g,r.direction=b,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 h;var O=(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:O.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 l=r.prototype;return l.start=function(){this.stopped=!1},l.stop=function(){this.stopped=!0,this.animate.stop()},l.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()},l.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)},l.setScroll=function(t){"horizontal"===this.direction?this.wrapperNode.scrollTo(t,0):this.wrapperNode.scrollTo(0,t)},l.notify=function(){this.emit("scroll",{scroll:this.scroll,limit:this.limit,velocity:this.velocity,direction:this.direction,progress:this.scroll/this.limit})},l.scrollTo=function(t,e){var i,o=void 0===e?{}:e,n=o.offset,r=void 0===n?0:n,s=o.immediate,l=void 0!==s&&s,h=o.duration,a=void 0===h?this.duration:h,c=o.easing,u=void 0===c?this.easing:c;if("number"==typeof t)i=t;else if("top"===t||"#top"===t)i=0;else if("bottom"===t)i=this.limit;else{var d;if("string"==typeof t)d=document.querySelector(t);else{if(null==t||!t.nodeType)return;d=t}if(!t)return;var p=0;if(this.wrapperNode!==window){var f=this.wrapperNode.getBoundingClientRect();p="horizontal"===this.direction?f.left:f.top}var v=d.getBoundingClientRect();i=("horizontal"===this.direction?v.left:v.top)+this.scroll-p}this.targetScroll=i+=r,!this.smooth||l?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}(),l=["duration","easing"],h=/*#__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,h=n.easing,a=void 0===h?function(t){return t}:h,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,l);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+.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)}},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,l=void 0===e?{}:e,a=l.duration,c=void 0===a?1.2:a,u=l.easing,d=void 0===u?function(t){return 1===t?1:1-Math.pow(2,-10*t)}:u,p=l.smooth,f=void 0===p||p,v=l.smoothTouch,y=void 0!==v&&v,w=l.touchMultiplier,g=void 0===w?2:w,m=l.direction,b=void 0===m?"vertical":m,T=l.wrapper,S=void 0===T?window:T,_=l.content,M=void 0===_?document.body:_;(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.originalEvent;i.ctrlKey||(r.smooth=i.changedTouches?r.smoothTouch:r.options.smooth,r.stopped?i.preventDefault():r.smooth&&4!==i.buttons&&(r.smooth&&i.preventDefault(),r.targetScroll-=e,r.targetScroll=Math.max(0,Math.min(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.8",r.options={duration:c,easing:d,smooth:f,smoothTouch:y,touchMultiplier:g,direction:b,wrapper:S,content:M},r.wrapperNode=S,r.contentNode=M,r.duration=c,r.easing=d,r.smooth=f,r.smoothTouch=y,r.touchMultiplier=g,r.direction=b,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 h;var O=(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:O.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 l=r.prototype;return l.start=function(){this.stopped=!1},l.stop=function(){this.stopped=!0,this.animate.stop()},l.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()},l.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)},l.setScroll=function(t){"horizontal"===this.direction?this.wrapperNode.scrollTo(t,0):this.wrapperNode.scrollTo(0,t)},l.notify=function(){this.emit("scroll",{scroll:this.scroll,limit:this.limit,velocity:this.velocity,direction:this.direction,progress:this.scroll/this.limit})},l.scrollTo=function(t,e){var i,o=void 0===e?{}:e,n=o.offset,r=void 0===n?0:n,s=o.immediate,l=void 0!==s&&s,h=o.duration,a=void 0===h?this.duration:h,c=o.easing,u=void 0===c?this.easing:c;if("number"==typeof t)i=t;else if("top"===t||"#top"===t)i=0;else if("bottom"===t)i=this.limit;else{var d;if("string"==typeof t)d=document.querySelector(t);else{if(null==t||!t.nodeType)return;d=t}if(!t)return;var p=0;if(this.wrapperNode!==window){var f=this.wrapperNode.getBoundingClientRect();p="horizontal"===this.direction?f.left:f.top}var v=d.getBoundingClientRect();i=("horizontal"===this.direction?v.left:v.top)+this.scroll-p}this.targetScroll=i+=r,!this.smooth||l?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 f0162187..07fd4a78 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 r=/*#__PURE__*/o(t),i=/*#__PURE__*/o(e);function n(t,e){for(var o=0;o=0||(i[o]=t[o]);return i}(r,h);this.target=t,this.fromKeys=l({},c),this.toKeys=l({},c),this.keys=Object.keys(l({},c)),this.keys.forEach(function(e){o.fromKeys[e]=t[e]}),this.duration=n,this.easing=a,this.currentTime=0,this.isRunning=!0},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 r=e.fromKeys[t];e.target[t]=r+(e.toKeys[t]-r)*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 r(e){var o,r,n,s,l=void 0===e?{}:e,a=l.duration,h=void 0===a?1.2:a,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.wrapper,O=void 0===N?window:N,z=l.content,R=void 0===z?document.body:z;(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.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-=e,s.targetScroll=c(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())},void 0!==arguments[0].lerp&&console.warn("Lenis: lerp option is deprecated, you must use duration and easing options instead. See documentation https://github.com/studio-freight/lenis"),window.lenisVersion="0.2.6",s.options={duration:h,easing:d,smooth:v,smoothTouch:w,touchMultiplier:y,direction:S,wrapper:O,content:R},s.wrapperNode=O,s.contentNode=R,s.duration=h,s.easing=d,s.smooth=v,s.smoothTouch=w,s.touchMultiplier=y,s.direction=S,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 W=(null==(o=navigator)||null==(r=o.userAgentData)?void 0:r.platform)||(null==(n=navigator)?void 0:n.platform)||"unknown";return s.virtualScroll=new i.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}o=t,(e=r).prototype=Object.create(o.prototype),e.prototype.constructor=e,a(e,o);var n=r.prototype;return n.start=function(){this.stopped=!1},n.stop=function(){this.stopped=!0},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),Math.round(this.scroll)===Math.round(this.targetScroll)&&(this.lastScroll=this.targetScroll),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,r=void 0===e?{}:e,i=r.offset,n=void 0===i?0:i,s=r.immediate,l=void 0!==s&&s,a=r.duration,c=void 0===a?this.duration:a,h=r.easing,u=void 0===h?this.easing:h;if("number"==typeof t)o=t;else if("top"===t||"#top"===t)o=0;else if("bottom"===t)o=this.limit;else{var p;if("string"==typeof t)p=document.querySelector(t);else{if(null==t||!t.nodeType)return;p=t}if(!t)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();o=("horizontal"===this.direction?v.left:v.top)+this.scroll-d}this.targetScroll=o+=n,!this.smooth||l?this.setScroll(this.targetScroll):this.animate.to(this,{duration:c,easing:u,scroll:this.targetScroll})},s(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.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,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,p=l.easing,u=void 0===p?function(t){return 1===t?1:1-Math.pow(2,-10*t)}:p,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.wrapper,N=void 0===S?window:S,O=l.content,z=void 0===O?document.body:O;(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.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-=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.8",s.options={duration:a,easing:u,smooth:f,smoothTouch:g,touchMultiplier:m,direction:b,wrapper:N,content:z},s.wrapperNode=N,s.contentNode=z,s.duration=a,s.easing=u,s.smooth=f,s.smoothTouch=g,s.touchMultiplier=m,s.direction=b,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 R=(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:R.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,i=void 0===e?{}:e,r=i.offset,n=void 0===r?0:r,s=i.immediate,l=void 0!==s&&s,c=i.duration,a=void 0===c?this.duration:c,h=i.easing,p=void 0===h?this.easing:h;if("number"==typeof t)o=t;else if("top"===t||"#top"===t)o=0;else if("bottom"===t)o=this.limit;else{var u;if("string"==typeof t)u=document.querySelector(t);else{if(null==t||!t.nodeType)return;u=t}if(!t)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();o=("horizontal"===this.direction?v.left:v.top)+this.scroll-d}this.targetScroll=o+=n,!this.smooth||l?this.setScroll(this.targetScroll):this.animate.to(this,{duration:a,easing:p,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 75741a83..af363974 100644 --- a/dist/lenis.js.map +++ b/dist/lenis.js.map @@ -1 +1 @@ -{"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\n// simple animation tool\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 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',\r\n wrapper = window,\r\n content = document.body,\r\n } = {}) {\r\n super()\r\n\r\n if (arguments[0].lerp !== undefined) {\r\n console.warn(\r\n 'Lenis: lerp option is deprecated, you must use duration and easing options instead. See documentation https://github.com/studio-freight/lenis'\r\n )\r\n }\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 wrapper,\r\n content,\r\n }\r\n\r\n this.wrapperNode = wrapper\r\n this.contentNode = content\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\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 }\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, 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 this.targetScroll -= deltaY\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 // where smooth scroll happens\r\n this.lastScroll = this.scroll\r\n\r\n this.animate.raf(deltaTime)\r\n\r\n // fixes velocity when sometimes final native event is not notified\r\n if (Math.round(this.scroll) === Math.round(this.targetScroll)) {\r\n this.lastScroll = this.targetScroll\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 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 (!target) 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"],"names":["min","input","max","Math","_excluded","Animate","Lenis","to","target","_this","this","_ref","_temp","duration","_ref$duration","easing","_ref$easing","t","keys","fromKeys","toKeys","_extends","Object","forEach","key","currentTime","isRunning","raf","deltaTime","progress","from","_this2","_temp2","_navigator","_navigator$userAgentD","_navigator2","_this3","_ref2","_ref2$duration","_ref2$easing","pow","smooth","_ref2$smooth","smoothTouch","_ref2$smoothTouch","touchMultiplier","_ref2$touchMultiplier","direction","_ref2$direction","_ref2$wrapper","wrapper","window","_ref2$content","content","document","body","_EventEmitter","call","onWindowResize","wrapperWidth","innerWidth","wrapperHeight","innerHeight","onWrapperResize","_ref3","entry","contentRect","rect","width","height","onContentResize","_ref4","contentWidth","contentHeight","onVirtualScroll","deltaY","e","originalEvent","ctrlKey","changedTouches","options","stopped","preventDefault","buttons","targetScroll","clamp","limit","scrollTo","onScroll","isScrolling","scroll","lastScroll","wrapperNode","scrollProperty","notify","undefined","arguments","lerp","console","warn","lenisVersion","contentNode","addEventListener","offsetHeight","offsetWidth","wrapperObserver","ResizeObserver","observe","contentObserver","animate","navigator","userAgentData","platform","virtualScroll","VirtualScroll","el","firefoxMultiplier","mouseMultiplier","includes","useKeyboard","useTouch","passive","on","EventEmitter","start","stop","destroy","_this$wrapperObserver","removeEventListener","disconnect","now","round","setScroll","value","emit","velocity","_temp3","_ref6$offset","_ref6","offset","immediate","_ref6$immediate","_ref6$duration","_ref6$easing","node","querySelector","nodeType","wrapperOffset","getBoundingClientRect","wrapperRect","left","top","_createClass","get"],"mappings":"6xBAAO,WAAeA,EAAKC,EAAOC,GAChC,OAAWC,KAACD,IAAIF,EAAKG,KAAKH,IAAIC,EAAOC,GACtC,CCFD,IAAAE,EAAA,CAAA,WAAA,UAMMC,0DA+CeC,SA9CnBC,GAAA,SAAGC,KAAuD,IAAAC,EAAAC,KAAAC,OAAA,IAAAC,EAAA,CAAI,EAAjDC,EAAAA,EAAAA,EAAAA,SAAAA,OAAiD,IAAAC,EAAtC,EAAGC,EAAAA,EAAAA,EAAAA,OAAAA,OAAmC,IAAAC,EAA1B,SAACC,UAADA,CAAA,EAAaC,EAAAA,0IAC/CR,KAAKF,OAASA,EACdE,KAAKS,cAAgBD,GACrBR,KAAKU,OAALC,EAAA,CAAA,EAAmBH,GACnBR,KAAKQ,KAAOI,OAAOJ,UAAUA,IAG7BR,KAAKQ,KAAKK,QAAQ,SAACC,GACjBf,EAAKU,SAASK,GAAOhB,EAA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,EAEA,GAAsB,iBAAXxI,EAETwI,EAAO1F,SAAS2F,cAAczI,OACrBA,IAAAA,MAAAA,IAAAA,EAAQ0I,SAIjB,OAFAF,EAAOxI,CAGR,CAED,IAAKA,EAAQ,OACb,IAAI2I,EAAgB,EAEpB,GAAIzI,KAAKkF,cAAgBzC,OAAQ,CAC/B,MAAoBzC,KAAKkF,YAAYwD,wBACrCD,EACqB,eAAnBzI,KAAKqC,UAA6BsG,EAAYC,KAAOD,EAAYE,GACpE,CAED,MAAaP,EAAKI,wBAElBf,GACsB,eAAnB3H,KAAKqC,UAA6BoB,EAAKmF,KAAOnF,EAAKoF,KACpD7I,KAAKgF,OACLyD,CACH,CAIDzI,KAAK0E,aAFLiD,GAASM,GAIJjI,KAAK+B,QAAUmG,EAClBlI,KAAK0H,UAAU1H,KAAK0E,cAEpB1E,KAAKmG,QAAQtG,GAAGG,KAAM,CACpBG,SAAAA,EACAE,OAAAA,EACA2E,OAAQhF,KAAK0E,cAGlB,EAtMDoE,EAAAlJ,EAAA,CAAA,CAAAkB,IAAA,iBAAAiI,IAAA,WAOE,OALI/I,KAAKkF,cAAgBzC,OACO,eAAnBzC,KAAKqC,UAA6B,UAAY,UAE3B,eAAnBrC,KAAKqC,UAA6B,aAAe,WAG/D,oBA0CD,WACE,MAA0B,eAAnBrC,KAAKqC,UACRrC,KAAK8D,aAAe9D,KAAKiD,aACzBjD,KAAK+D,cAAgB/D,KAAKmD,aAC/B,uBAmDD,WACE,OAAY6B,KAAAA,OAAShF,KAAKiF,UAC3B,KApMgCgC,CAAAA,EAAAA"} \ No newline at end of file +{"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',\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 wrapper,\r\n content,\r\n }\r\n\r\n this.wrapperNode = wrapper\r\n this.contentNode = content\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\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 // TODO: stop scroll animation\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, 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 this.targetScroll -= deltaY\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 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 (!target) 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","Lenis","to","target","_this","this","_ref","_temp","duration","_ref$duration","easing","_ref$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","wrapper","_ref2$wrapper","window","_ref2$content","content","document","body","_EventEmitter","call","onWindowResize","wrapperWidth","innerWidth","wrapperHeight","innerHeight","onWrapperResize","_ref3","entry","rect","contentRect","width","height","onContentResize","contentWidth","contentHeight","onVirtualScroll","_ref5","deltaY","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","ResizeObserver","observe","contentObserver","animate","navigator","platform","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$offset","_ref6","offset","immediate","_ref6$immediate","_ref6$easing","node","querySelector","nodeType","wrapperRect","getBoundingClientRect","wrapperOffset","left","top"],"mappings":"6xBAAA,IAAAA,EAAA,CAAA,WAAA,UAKMC,0DAmDeC,SAlDnBC,GAAA,SAAGC,KAAuD,IAAAC,EAAAC,KAAAC,OAAA,IAAAC,EAAA,CAAI,EAAjDC,EAAAA,EAAAA,EAAAA,SAAAA,OAAiD,IAAAC,EAA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C3B,KAhMgC2B,CAAAA,EAAAA"} \ No newline at end of file diff --git a/dist/lenis.mjs b/dist/lenis.mjs index a389c732..091f186c 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,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.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}(),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.wrapper,O=void 0===N?window:N,z=a.content,R=void 0===z?document.body:z;(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.originalEvent;o.ctrlKey||(l.smooth=o.changedTouches?l.smoothTouch:l.options.smooth,l.stopped?o.preventDefault():l.smooth&&4!==o.buttons&&(l.smooth&&o.preventDefault(),l.targetScroll-=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())},void 0!==arguments[0].lerp&&console.warn("Lenis: lerp option is deprecated, you must use duration and easing options instead. See documentation https://github.com/studio-freight/lenis"),window.lenisVersion="0.2.6",l.options={duration:p,easing:d,smooth:v,smoothTouch:w,touchMultiplier:y,direction:S,wrapper:O,content:R},l.wrapperNode=O,l.contentNode=R,l.duration=p,l.easing=d,l.smooth=v,l.smoothTouch=w,l.touchMultiplier=y,l.direction=S,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 W=(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:W.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},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(e),Math.round(this.scroll)===Math.round(this.targetScroll)&&(this.lastScroll=this.targetScroll),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,i=void 0===e?{}:e,r=i.offset,n=void 0===r?0:r,s=i.immediate,l=void 0!==s&&s,c=i.duration,a=void 0===c?this.duration:c,h=i.easing,p=void 0===h?this.easing:h;if("number"==typeof t)o=t;else if("top"===t||"#top"===t)o=0;else if("bottom"===t)o=this.limit;else{var u;if("string"==typeof t)u=document.querySelector(t);else{if(null==t||!t.nodeType)return;u=t}if(!t)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();o=("horizontal"===this.direction?v.left:v.top)+this.scroll-d}this.targetScroll=o+=n,!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}; +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.wrapper,N=void 0===S?window:S,O=c.content,z=void 0===O?document.body:O;(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.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-=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.8",s.options={duration:h,easing:u,smooth:f,smoothTouch:g,touchMultiplier:m,direction:b,wrapper:N,content:z},s.wrapperNode=N,s.contentNode=z,s.duration=h,s.easing=u,s.smooth=f,s.smoothTouch=g,s.touchMultiplier=m,s.direction=b,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 R=(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:R.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,i=void 0===e?{}:e,r=i.offset,n=void 0===r?0:r,s=i.immediate,l=void 0!==s&&s,c=i.duration,a=void 0===c?this.duration:c,h=i.easing,p=void 0===h?this.easing:h;if("number"==typeof t)o=t;else if("top"===t||"#top"===t)o=0;else if("bottom"===t)o=this.limit;else{var u;if("string"==typeof t)u=document.querySelector(t);else{if(null==t||!t.nodeType)return;u=t}if(!t)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();o=("horizontal"===this.direction?v.left:v.top)+this.scroll-d}this.targetScroll=o+=n,!this.smooth||l?this.setScroll(this.targetScroll):this.animate.to(this,{duration:a,easing:p,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}; //# sourceMappingURL=lenis.mjs.map diff --git a/dist/lenis.mjs.map b/dist/lenis.mjs.map index 598e204d..2ce1a5eb 100644 --- a/dist/lenis.mjs.map +++ b/dist/lenis.mjs.map @@ -1 +1 @@ -{"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\n// simple animation tool\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 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',\r\n wrapper = window,\r\n content = document.body,\r\n } = {}) {\r\n super()\r\n\r\n if (arguments[0].lerp !== undefined) {\r\n console.warn(\r\n 'Lenis: lerp option is deprecated, you must use duration and easing options instead. See documentation https://github.com/studio-freight/lenis'\r\n )\r\n }\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 wrapper,\r\n content,\r\n }\r\n\r\n this.wrapperNode = wrapper\r\n this.contentNode = content\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\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 }\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, 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 this.targetScroll -= deltaY\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 // where smooth scroll happens\r\n this.lastScroll = this.scroll\r\n\r\n this.animate.raf(deltaTime)\r\n\r\n // fixes velocity when sometimes final native event is not notified\r\n if (Math.round(this.scroll) === Math.round(this.targetScroll)) {\r\n this.lastScroll = this.targetScroll\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 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 (!target) 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"],"names":["min","input","max","Math","_excluded","Animate","Lenis","to","target","_this","this","_ref","_temp","duration","_ref$duration","easing","_ref$easing","t","keys","fromKeys","toKeys","_extends","Object","forEach","key","currentTime","isRunning","raf","deltaTime","progress","from","_this2","_temp2","_navigator","_navigator$userAgentD","_navigator2","_this3","_ref2","_ref2$duration","_ref2$easing","pow","smooth","_ref2$smooth","smoothTouch","_ref2$smoothTouch","touchMultiplier","_ref2$touchMultiplier","direction","_ref2$direction","_ref2$wrapper","wrapper","window","_ref2$content","content","document","body","_EventEmitter","call","onWindowResize","wrapperWidth","innerWidth","wrapperHeight","innerHeight","onWrapperResize","_ref3","entry","contentRect","rect","width","height","onContentResize","_ref4","contentWidth","contentHeight","onVirtualScroll","deltaY","e","originalEvent","ctrlKey","changedTouches","options","stopped","preventDefault","buttons","targetScroll","clamp","limit","scrollTo","onScroll","isScrolling","scroll","lastScroll","wrapperNode","scrollProperty","notify","undefined","arguments","lerp","console","warn","lenisVersion","contentNode","addEventListener","offsetHeight","offsetWidth","wrapperObserver","ResizeObserver","observe","contentObserver","animate","navigator","userAgentData","platform","virtualScroll","VirtualScroll","el","firefoxMultiplier","mouseMultiplier","includes","useKeyboard","useTouch","passive","on","EventEmitter","start","stop","destroy","_this$wrapperObserver","removeEventListener","disconnect","now","round","setScroll","value","emit","velocity","_temp3","_ref6$offset","_ref6","offset","immediate","_ref6$immediate","_ref6$duration","_ref6$easing","node","querySelector","nodeType","wrapperOffset","getBoundingClientRect","wrapperRect","left","top","_createClass","get"],"mappings":"yqBAAO,WAAeA,EAAKC,EAAOC,GAChC,OAAWC,KAACD,IAAIF,EAAKG,KAAKH,IAAIC,EAAOC,GACtC,CCFD,IAAAE,EAAA,CAAA,WAAA,UAMMC,0DA+CeC,SA9C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AAKqC,UACRrC,KAAK8D,aAAe9D,KAAKiD,aACzBjD,KAAK+D,cAAgB/D,KAAKmD,aAC/B,uBAmDD,WACE,OAAY6B,KAAAA,OAAShF,KAAKiF,UAC3B,KApMgCgC,CAAAA,EAAAA"} \ No newline at end of file +{"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',\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 wrapper,\r\n content,\r\n }\r\n\r\n this.wrapperNode = wrapper\r\n this.contentNode = content\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\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 // TODO: stop scroll animation\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, 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 this.targetScroll -= deltaY\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 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 (!target) 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","Lenis","to","target","_this","this","_ref","_temp","duration","_ref$duration","easing","_ref$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","wrapper","_ref2$wrapper","window","_ref2$content","content","document","body","_EventEmitter","call","onWindowResize","wrapperWidth","innerWidth","wrapperHeight","innerHeight","onWrapperResize","_ref3","entry","rect","contentRect","width","height","onContentResize","contentWidth","contentHeight","onVirtualScroll","_ref5","deltaY","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","ResizeObserver","observe","contentObserver","animate","navigator","platform","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$offset","_ref6","offset","immediate","_ref6$immediate","_ref6$easing","node","querySelector","nodeType","wrapperRect","getBoundingClientRect","wrapperOffset","left","top"],"mappings":"yqBAAA,IAAAA,EAAA,CAAA,WAAA,UAKMC,0DAmDeC,SAlDnBC,GAAA,SAAGC,KAAuD,IAAAC,EAAAC,KAAAC,OAAA,IAAAC,EAAA,CAAI,EAAjDC,EAAAA,EAAAA,EAAAA,SAAAA,OAAiD,IAAAC,EAAtC,EAAGC,EAAAA,EAAAA,EAAAA,OAAAA,OAAmC,IAAAC,EAA1B,SAACC,UAADA,CAAA,EAAaC,EAAAA,0IAC/CR,KAAKF,OAASA,EACdE,KAAKS,cAAgBD,GACrBR,KAAKU,OAALC,EAAA,CAAA,EAAmBH,GACnBR,KAAKQ,KAAOI,OAAOJ,UAAUA,IAG7BR,KAAKQ,KAAKK,QAAQ,SAACC,GACjBf,EAAKU,SAASK,GAAOhB,EAAOgB,EAC7B,GAEDd,KAAKG,SAAWA,EAChBH,KAAKK,OAASA,EACdL,KAAKe,YAAc,EACnBf,KAAKgB,WAAY,CAClB,EAEDC,EAAAA,KAAA,WACEjB,KAAKgB,WAAY,CAClB,IAEDE,IAAA,SAAIC,GACF,IAAAC,EAAApB,KAAA,GAAKA,KAAKgB,UAAV,CAEAhB,KAAKe,YAAcM,KAAKC,IACtBtB,KAAKe,YAA0B,KAAZI,EACnBnB,KAAKG,UAGP,IAAMoB,EAAWvB,KAAKK,OAAOL,KAAKuB,UAElCvB,KAAKQ,KAAKK,QAAQ,SAACC,GACjB,MAAaM,EAAKX,SAASK,GAK3BM,EAAKtB,OAAOgB,GAFEU,GAFHJ,EAAKV,OAAOI,GAEIU,GAAQD,CAGpC,GAEgB,IAAbA,IACFvB,KAAKgB,WAAY,EAnBE,CAqB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4F,EAClB9H,KAAKsH,UAAUtH,KAAK6E,cAEpB7E,KAAKiG,QAAQpG,GAAGG,KAAM,CACpBG,SAAAA,EACAE,OAAAA,EACA8E,OAAQnF,KAAK6E,cAGlB,iCAxMD,WAOE,OALI7E,KAAKqF,cAAgBzC,OACO,eAAnB5C,KAAKyC,UAA6B,UAAY,UAE3B,eAAnBzC,KAAKyC,UAA6B,aAAe,WAG/D,oBA4CD,WACE,MAA0B,eAAnBzC,KAAKyC,UACRzC,KAAKgE,aAAehE,KAAKoD,aACzBpD,KAAKiE,cAAgBjE,KAAKsD,aAC/B,uBAmDD,WACE,OAAY6B,KAAAA,OAASnF,KAAKoF,UAC3B,KAhMgC2B,CAAAA,EAAAA"} \ No newline at end of file diff --git a/dist/lenis.modern.mjs b/dist/lenis.modern.mjs index 7969f0b7..4321271e 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,o={},r=Object.keys(t);for(s=0;s=0||(o[e]=t[e]);return o}(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=o,this.easing=r,this.currentTime=0,this.isRunning=!0}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 r extends t{constructor({duration:t=1.2,easing:e=(t=>1===t?1:1-Math.pow(2,-10*t)),smooth:s=!0,smoothTouch:r=!1,touchMultiplier:n=2,direction:h="vertical",wrapper:l=window,content:c=document.body}={}){var a,p,d;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,originalEvent:i})=>{i.ctrlKey||(this.smooth=i.changedTouches?this.smoothTouch:this.options.smooth,this.stopped?i.preventDefault():this.smooth&&4!==i.buttons&&(this.smooth&&i.preventDefault(),this.targetScroll-=t,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())},void 0!==arguments[0].lerp&&console.warn("Lenis: lerp option is deprecated, you must use duration and easing options instead. See documentation https://github.com/studio-freight/lenis"),window.lenisVersion="0.2.6",this.options={duration:t,easing:e,smooth:s,smoothTouch:r,touchMultiplier:n,direction:h,wrapper:l,content:c},this.wrapperNode=l,this.contentNode=c,this.duration=t,this.easing=e,this.smooth=s,this.smoothTouch=r,this.touchMultiplier=n,this.direction=h,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 u=(null==(a=navigator)||null==(p=a.userAgentData)?void 0:p.platform)||(null==(d=navigator)?void 0:d.platform)||"unknown";this.virtualScroll=new i({el:this.wrapperNode,firefoxMultiplier:50,mouseMultiplier:u.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}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),Math.round(this.scroll)===Math.round(this.targetScroll)&&(this.lastScroll=this.targetScroll),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:o=this.easing}={}){let r;if("number"==typeof t)r=t;else if("top"===t||"#top"===t)r=0;else if("bottom"===t)r=this.limit;else{let i;if("string"==typeof t)i=document.querySelector(t);else{if(null==t||!t.nodeType)return;i=t}if(!t)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();r=("horizontal"===this.direction?s.left:s.top)+this.scroll-e}r+=i,this.targetScroll=r,!this.smooth||e?this.setScroll(this.targetScroll):this.animate.to(this,{duration:s,easing:o,scroll:this.targetScroll})}}export{r 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,h=function(t,i){if(null==t)return{};var e,s,o={},r=Object.keys(t);for(s=0;s=0||(o[e]=t[e]);return o}(i,s);this.target=t,this.fromKeys=e({},h),this.toKeys=e({},h),this.keys=Object.keys(e({},h)),this.keys.forEach(i=>{this.fromKeys[i]=t[i]}),this.duration=o,this.easing=r,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 r extends t{constructor({duration:t=1.2,easing:e=(t=>1===t?1:1-Math.pow(2,-10*t)),smooth:s=!0,smoothTouch:r=!1,touchMultiplier:h=2,direction:n="vertical",wrapper:l=window,content:c=document.body}={}){var a,p,d;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,originalEvent:i})=>{i.ctrlKey||(this.smooth=i.changedTouches?this.smoothTouch:this.options.smooth,this.stopped?i.preventDefault():this.smooth&&4!==i.buttons&&(this.smooth&&i.preventDefault(),this.targetScroll-=t,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.8",this.options={duration:t,easing:e,smooth:s,smoothTouch:r,touchMultiplier:h,direction:n,wrapper:l,content:c},this.wrapperNode=l,this.contentNode=c,this.duration=t,this.easing=e,this.smooth=s,this.smoothTouch=r,this.touchMultiplier=h,this.direction=n,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 u=(null==(a=navigator)||null==(p=a.userAgentData)?void 0:p.platform)||(null==(d=navigator)?void 0:d.platform)||"unknown";this.virtualScroll=new i({el:this.wrapperNode,firefoxMultiplier:50,mouseMultiplier:u.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:o=this.easing}={}){let r;if("number"==typeof t)r=t;else if("top"===t||"#top"===t)r=0;else if("bottom"===t)r=this.limit;else{let i;if("string"==typeof t)i=document.querySelector(t);else{if(null==t||!t.nodeType)return;i=t}if(!t)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();r=("horizontal"===this.direction?s.left:s.top)+this.scroll-e}r+=i,this.targetScroll=r,!this.smooth||e?this.setScroll(this.targetScroll):this.animate.to(this,{duration:s,easing:o,scroll:this.targetScroll})}}export{r as default}; //# sourceMappingURL=lenis.modern.mjs.map diff --git a/dist/lenis.modern.mjs.map b/dist/lenis.modern.mjs.map index ec61a35c..3f7b44ce 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\n// simple animation tool\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 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',\r\n wrapper = window,\r\n content = document.body,\r\n } = {}) {\r\n super()\r\n\r\n if (arguments[0].lerp !== undefined) {\r\n console.warn(\r\n 'Lenis: lerp option is deprecated, you must use duration and easing options instead. See documentation https://github.com/studio-freight/lenis'\r\n )\r\n }\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 wrapper,\r\n content,\r\n }\r\n\r\n this.wrapperNode = wrapper\r\n this.contentNode = content\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\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 }\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, 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 this.targetScroll -= deltaY\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 // where smooth scroll happens\r\n this.lastScroll = this.scroll\r\n\r\n this.animate.raf(deltaTime)\r\n\r\n // fixes velocity when sometimes final native event is not notified\r\n if (Math.round(this.scroll) === Math.round(this.targetScroll)) {\r\n this.lastScroll = this.targetScroll\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 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 (!target) 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","to","target","_ref","duration","easing","t","keys","_objectWithoutPropertiesLoose","this","fromKeys","toKeys","Object","forEach","key","currentTime","isRunning","raf","deltaTime","Math","min","progress","from","EventEmitter","constructor","pow","smooth","smoothTouch","touchMultiplier","direction","wrapper","window","content","document","body","super","onWindowResize","wrapperWidth","innerWidth","wrapperHeight","innerHeight","onWrapperResize","entry","contentRect","rect","width","height","onContentResize","contentWidth","contentHeight","onVirtualScroll","deltaY","originalEvent","e","ctrlKey","changedTouches","options","stopped","preventDefault","buttons","targetScroll","max","limit","scrollTo","onScroll","isScrolling","scroll","lastScroll","wrapperNode","scrollProperty","notify","undefined","arguments","lerp","console","warn","lenisVersion","contentNode","addEventListener","offsetHeight","offsetWidth","wrapperObserver","observe","contentObserver","ResizeObserver","animate","Animate","platform","navigator","userAgentData","_navigator2","virtualScroll","VirtualScroll","el","firefoxMultiplier","mouseMultiplier","includes","useKeyboard","useTouch","passive","on","property","start","stop","destroy","removeEventListener","disconnect","now","round","setScroll","velocity","value","emit","offset","immediate","node","querySelector","nodeType","wrapperRect","getBoundingClientRect","wrapperOffset","left","top"],"mappings":"8RAAA,MAAAA,EAAA,CAAA,WAAA,UAMA,QACEC,GAAGC,EAAQC,EAA+C,CAAxD,GAA4D,IAAnDC,SAAEA,EAAW,EAAbC,OAAgBA,EAAUC,IAAMA,IAAMC,EAAAA,oIAC/CC,CAAAL,EAAAH,GAAAS,KAAKP,OAASA,EACdO,KAAKC,SAAgBH,EAAAA,CAAAA,EAAAA,GACrBE,KAAKE,OAAcJ,EAAAA,GAAAA,GACnBE,KAAKF,KAAOK,OAAOL,UAAUA,IAG7BE,KAAKF,KAAKM,QAASC,IACjBL,KAAKC,SAASI,GAAOZ,EAAOY,KAG9BL,KAAKL,SAAWA,EAChBK,KAAKJ,OAASA,EACdI,KAAKM,YAAc,EACnBN,KAAKO,WAAY,CAClB,CAEDC,IAAIC,GACF,IAAKT,KAAKO,UAAW,OAErBP,KAAKM,YAAcI,KAAKC,IACtBX,KAAKM,YAA0B,KAAZG,EACnBT,KAAKL,UA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AC,SACA6D,OAAQzD,KAAKmD,cAGlB"} \ No newline at end of file +{"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',\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 wrapper,\r\n content,\r\n }\r\n\r\n this.wrapperNode = wrapper\r\n this.contentNode = content\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\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 // TODO: stop scroll animation\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, 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 this.targetScroll -= deltaY\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 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 (!target) 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","to","target","_ref","duration","easing","t","keys","_objectWithoutPropertiesLoose","this","fromKeys","toKeys","Object","forEach","key","currentTime","isRunning","stop","raf","deltaTime","Math","min","progress","from","Lenis","EventEmitter","constructor","pow","smooth","smoothTouch","touchMultiplier","direction","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","originalEvent","e","ctrlKey","changedTouches","options","stopped","preventDefault","buttons","targetScroll","max","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","value","emit","offset","immediate","node","querySelector","nodeType","wrapperOffset","wrapperRect","getBoundingClientRect","left","top"],"mappings":"8RAAA,MAAAA,EAAA,CAAA,WAAA,UAKA,QACEC,GAAGC,EAAQC,EAA+C,CA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AAsB,iBAAX9G,EAET8G,EAAO7E,SAAS8E,cAAc/G,OACzB,IAAA,MAAIA,IAAAA,EAAQgH,SAIjB,OAFAF,EAAO9G,CAGR,CAED,IAAKA,EAAQ,OACb,IAAIiH,EAAgB,EAEpB,GAAI1G,KAAKgE,cAAgBxC,OAAQ,CAC/B,MAAiBmF,EAAG3G,KAAKgE,YAAY4C,wBACrCF,EACqB,eAAnB1G,KAAKsB,UAA6BqF,EAAYE,KAAOF,EAAYG,GACpE,CAED,MAAMvE,EAAOgE,EAAKK,wBAElBT,GACsB,eAAnBnG,KAAKsB,UAA6BiB,EAAKsE,KAAOtE,EAAKuE,KACpD9G,KAAK8D,OACL4C,CACH,CAEDP,GAASE,EAETrG,KAAKwD,aAAe2C,GAEfnG,KAAKmB,QAAUmF,EAClBtG,KAAKiG,UAAUjG,KAAKwD,cAEpBxD,KAAK4E,QAAQpF,GAAGQ,KAAM,CACpBL,WACAC,SACAkE,OAAQ9D,KAAKwD,cAGlB"} \ No newline at end of file diff --git a/dist/lenis.umd.js b/dist/lenis.umd.js index 33e4e8f2..d65f82ad 100644 --- a/dist/lenis.umd.js +++ b/dist/lenis.umd.js @@ -1,2 +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 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,u);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.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}(),d=/*#__PURE__*/function(t){var e,o;function i(e){var o,i,n,s,l=void 0===e?{}:e,c=l.duration,u=void 0===c?1.2:c,d=l.easing,f=void 0===d?function(t){return 1===t?1:1-Math.pow(2,-10*t)}:d,v=l.smooth,g=void 0===v||v,w=l.smoothTouch,m=void 0!==w&&w,y=l.touchMultiplier,b=void 0===y?2:y,S=l.direction,N=void 0===S?"vertical":S,O=l.wrapper,z=void 0===O?window:O,T=l.content,R=void 0===T?document.body:T;(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.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-=e,s.targetScroll=h(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())},void 0!==arguments[0].lerp&&console.warn("Lenis: lerp option is deprecated, you must use duration and easing options instead. See documentation https://github.com/studio-freight/lenis"),window.lenisVersion=a,s.options={duration:u,easing:f,smooth:g,smoothTouch:m,touchMultiplier:b,direction:N,wrapper:z,content:R},s.wrapperNode=z,s.contentNode=R,s.duration=u,s.easing=f,s.smooth=g,s.smoothTouch=m,s.touchMultiplier=b,s.direction=N,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 p;var W=(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:W.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},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),Math.round(this.scroll)===Math.round(this.targetScroll)&&(this.lastScroll=this.targetScroll),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,i=void 0===e?{}:e,r=i.offset,n=void 0===r?0:r,s=i.immediate,l=void 0!==s&&s,c=i.duration,a=void 0===c?this.duration:c,h=i.easing,u=void 0===h?this.easing:h;if("number"==typeof t)o=t;else if("top"===t||"#top"===t)o=0;else if("bottom"===t)o=this.limit;else{var p;if("string"==typeof t)p=document.querySelector(t);else{if(null==t||!t.nodeType)return;p=t}if(!t)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();o=("horizontal"===this.direction?v.left:v.top)+this.scroll-d}this.targetScroll=o+=n,!this.smooth||l?this.setScroll(this.targetScroll):this.animate.to(this,{duration:a,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);return d}); +!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 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}();/*#__PURE__*/ +return 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,y=void 0===w?2:w,m=l.direction,b=void 0===m?"vertical":m,S=l.wrapper,N=void 0===S?window:S,O=l.content,z=void 0===O?document.body:O;(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.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-=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.8",s.options={duration:a,easing:p,smooth:f,smoothTouch:g,touchMultiplier:y,direction:b,wrapper:N,content:z},s.wrapperNode=N,s.contentNode=z,s.duration=a,s.easing=p,s.smooth=f,s.smoothTouch=g,s.touchMultiplier=y,s.direction=b,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 R=(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:R.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,i=void 0===e?{}:e,r=i.offset,n=void 0===r?0:r,s=i.immediate,l=void 0!==s&&s,c=i.duration,a=void 0===c?this.duration:c,h=i.easing,u=void 0===h?this.easing:h;if("number"==typeof t)o=t;else if("top"===t||"#top"===t)o=0;else if("bottom"===t)o=this.limit;else{var p;if("string"==typeof t)p=document.querySelector(t);else{if(null==t||!t.nodeType)return;p=t}if(!t)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();o=("horizontal"===this.direction?v.left:v.top)+this.scroll-d}this.targetScroll=o+=n,!this.smooth||l?this.setScroll(this.targetScroll):this.animate.to(this,{duration:a,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.umd.js.map diff --git a/dist/lenis.umd.js.map b/dist/lenis.umd.js.map index f283c5b8..0ab4ab3e 100644 --- a/dist/lenis.umd.js.map +++ b/dist/lenis.umd.js.map @@ -1 +1 @@ -{"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\n// simple animation tool\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 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',\r\n wrapper = window,\r\n content = document.body,\r\n } = {}) {\r\n super()\r\n\r\n if (arguments[0].lerp !== undefined) {\r\n console.warn(\r\n 'Lenis: lerp option is deprecated, you must use duration and easing options instead. See documentation https://github.com/studio-freight/lenis'\r\n )\r\n }\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 wrapper,\r\n content,\r\n }\r\n\r\n this.wrapperNode = wrapper\r\n this.contentNode = content\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\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 }\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, 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 this.targetScroll -= deltaY\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 // where smooth scroll happens\r\n this.lastScroll = this.scroll\r\n\r\n this.animate.raf(deltaTime)\r\n\r\n // fixes velocity when sometimes final native event is not notified\r\n if (Math.round(this.scroll) === Math.round(this.targetScroll)) {\r\n this.lastScroll = this.targetScroll\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 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 (!target) 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"],"names":["min","input","max","Math","_excluded","Animate","Lenis","to","target","_this","this","_ref","_temp","duration","_ref$duration","easing","_ref$easing","t","keys","fromKeys","toKeys","_extends","Object","forEach","key","currentTime","isRunning","raf","deltaTime","progress","from","_this2","_temp2","_navigator","_navigator$userAgentD","_navigator2","_this3","_ref2","_ref2$duration","_ref2$easing","pow","smooth","_ref2$smooth","smoothTouch","_ref2$smoothTouch","touchMultiplier","_ref2$touchMultiplier","direction","_ref2$direction","_ref2$wrapper","wrapper","window","_ref2$content","content","document","body","_EventEmitter","call","onWindowResize","wrapperWidth","innerWidth","wrapperHeight","innerHeight","onWrapperResize","_ref3","entry","contentRect","rect","width","height","onContentResize","_ref4","contentWidth","contentHeight","onVirtualScroll","deltaY","e","originalEvent","ctrlKey","changedTouches","options","stopped","preventDefault","buttons","targetScroll","clamp","limit","scrollTo","onScroll","isScrolling","scroll","lastScroll","wrapperNode","scrollProperty","notify","undefined","arguments","lerp","console","warn","lenisVersion","version","contentNode","addEventListener","offsetHeight","offsetWidth","wrapperObserver","ResizeObserver","observe","contentObserver","animate","navigator","userAgentData","platform","virtualScroll","VirtualScroll","el","firefoxMultiplier","mouseMultiplier","includes","useKeyboard","useTouch","passive","on","EventEmitter","start","stop","destroy","_this$wrapperObserver","removeEventListener","disconnect","now","round","setScroll","value","emit","velocity","_temp3","_ref6$offset","_ref6","offset","immediate","_ref6$immediate","_ref6$duration","_ref6$easing","node","querySelector","nodeType","wrapperOffset","getBoundingClientRect","wrapperRect","left","top","_createClass","get"],"mappings":"4jCAAO,WAAeA,EAAKC,EAAOC,GAChC,OAAWC,KAACD,IAAIF,EAAKG,KAAKH,IAAIC,EAAOC,GACtC,CCFD,IAAAE,EAAA,CAAA,WAAA,UAMMC,0DA+CeC,SA9CnBC,GAAA,SAAGC,KAAuD,IAAAC,EAAAC,KAAAC,OAAA,IAAAC,EAAA,CAAI,EAAjDC,EAAAA,EAAAA,EAAAA,SAAAA,OAAiD,IAAAC,EAAtC,EAAGC,EAAAA,EAAAA,EAAAA,OAAAA,OAAmC,IAAAC,EAA1B,SAACC,UAADA,CA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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',\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 wrapper,\r\n content,\r\n }\r\n\r\n this.wrapperNode = wrapper\r\n this.contentNode = content\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\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 // TODO: stop scroll animation\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, 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 this.targetScroll -= deltaY\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 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 (!target) 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","Lenis","to","target","_this","this","_ref","_temp","duration","_ref$duration","easing","_ref$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","wrapper","_ref2$wrapper","window","_ref2$content","content","document","body","_EventEmitter","call","onWindowResize","wrapperWidth","innerWidth","wrapperHeight","innerHeight","onWrapperResize","_ref3","entry","rect","contentRect","width","height","onContentResize","contentWidth","contentHeight","onVirtualScroll","_ref5","deltaY","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","ResizeObserver","observe","contentObserver","animate","navigator","platform","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$offset","_ref6","offset","immediate","_ref6$immediate","_ref6$easing","node","querySelector","n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B5C,KAAKyC,UAA6B,UAAY,UAE3B,eAAnBzC,KAAKyC,UAA6B,aAAe,WAG/D,oBA4CD,WACE,MAA0B,eAAnBzC,KAAKyC,UACRzC,KAAKgE,aAAehE,KAAKoD,aACzBpD,KAAKiE,cAAgBjE,KAAKsD,aAC/B,uBAmDD,WACE,OAAY6B,KAAAA,OAASnF,KAAKoF,UAC3B,KAhMgC2B,CAAAA,EAAAA"} \ No newline at end of file diff --git a/package.json b/package.json index 5fce2ce1..bb88b703 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@studio-freight/lenis", - "version": "0.2.6", + "version": "0.2.8", "description": "Lenis is a smooth scroll library to normalize the scrolling experience across devices", "files": [ "dist" @@ -41,7 +41,7 @@ "clean": "rimraf dist && rimraf bundled", "build": "npm run clean && npm run build:light && npm run build:bundle", "build:light": "microbundle", - "build:bundle": "microbundle build -i src/lenis.js --format umd --compress --no-sourcemap --no-pkg-main --external none --output ./bundled --name 'Lenis'", + "build:bundle": "microbundle build -i src/lenis.js --format umd --compress --no-sourcemap --no-pkg-main --external none --output ./bundled --name Lenis", "build:website": "vite build", "prebuild": "npm run clean", "preversion": "npm run build", diff --git a/src/lenis.js b/src/lenis.js index fe616d13..98e2f010 100644 --- a/src/lenis.js +++ b/src/lenis.js @@ -3,7 +3,6 @@ import VirtualScroll from 'virtual-scroll' import { version } from '../package.json' import { clamp } from './maths.js' -// simple animation tool class Animate { to(target, { duration = 1, easing = (t) => t, ...keys } = {}) { this.target = target