From 19b6908548455c808cc02adbab04d340c3da8d97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Roche?= Date: Mon, 3 Oct 2022 12:57:00 +0200 Subject: [PATCH] v0.2.9 --- bundled/lenis.js | 4 ++-- dist/lenis.js | 2 +- dist/lenis.js.map | 2 +- dist/lenis.mjs | 2 +- dist/lenis.mjs.map | 2 +- dist/lenis.modern.mjs | 2 +- dist/lenis.modern.mjs.map | 2 +- dist/lenis.umd.js | 4 ++-- dist/lenis.umd.js.map | 2 +- package.json | 2 +- 10 files changed, 12 insertions(+), 12 deletions(-) diff --git a/bundled/lenis.js b/bundled/lenis.js index 079c78dd..1f63d979 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.gestureDirection,S=void 0===T?"vertical":T,_=l.wrapper,M=void 0===_?window:_,O=l.content,E=void 0===O?document.body:O;(r=t.call(this)||this).onWindowResize=function(){r.wrapperWidth=window.innerWidth,r.wrapperHeight=window.innerHeight},r.onWrapperResize=function(t){var e=t[0];if(e){var i=e.contentRect;r.wrapperWidth=i.width,r.wrapperHeight=i.height}},r.onContentResize=function(t){var e=t[0];if(e){var i=e.contentRect;r.contentWidth=i.width,r.contentHeight=i.height}},r.onVirtualScroll=function(t){var e=t.deltaY,i=t.deltaX,o=t.originalEvent;o.ctrlKey||(r.smooth=o.changedTouches?r.smoothTouch:r.options.smooth,r.stopped?o.preventDefault():r.smooth&&4!==o.buttons&&(r.smooth&&o.preventDefault(),r.targetScroll-="both"===r.gestureDirection?i+e:"horizontal"===r.gestureDirection?i:e,r.targetScroll=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,gestureDirection:S,wrapper:M,content:E},r.duration=c,r.easing=d,r.smooth=f,r.smoothTouch=y,r.touchMultiplier=g,r.direction=b,r.gestureDirection=S,r.wrapperNode=M,r.contentNode=E,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 W=(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:W.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=void 0===e?{}:e,o=i.offset,n=void 0===o?0:o,r=i.immediate,s=void 0!==r&&r,l=i.duration,h=void 0===l?this.duration:l,a=i.easing,c=void 0===a?this.easing:a;if(null!=t){var u;if("number"==typeof t)u=t;else if("top"===t||"#top"===t)u=0;else if("bottom"===t)u=this.limit;else{var d;if("string"==typeof t)d=document.querySelector(t);else{if(null==t||!t.nodeType)return;d=t}if(!d)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();u=("horizontal"===this.direction?v.left:v.top)+this.scroll-p}this.targetScroll=u+=n,!this.smooth||s?this.setScroll(this.targetScroll):this.animate.to(this,{duration:h,easing:c,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.gestureDirection,S=void 0===T?"vertical":T,_=l.wrapper,M=void 0===_?window:_,O=l.content,E=void 0===O?document.body:O;(r=t.call(this)||this).onWindowResize=function(){r.wrapperWidth=window.innerWidth,r.wrapperHeight=window.innerHeight},r.onWrapperResize=function(t){var e=t[0];if(e){var i=e.contentRect;r.wrapperWidth=i.width,r.wrapperHeight=i.height}},r.onContentResize=function(t){var e=t[0];if(e){var i=e.contentRect;r.contentWidth=i.width,r.contentHeight=i.height}},r.onVirtualScroll=function(t){var e=t.deltaY,i=t.deltaX,o=t.originalEvent;o.ctrlKey||(r.smooth=o.changedTouches?r.smoothTouch:r.options.smooth,r.stopped?o.preventDefault():r.smooth&&4!==o.buttons&&(r.smooth&&o.preventDefault(),r.targetScroll-="both"===r.gestureDirection?i+e:"horizontal"===r.gestureDirection?i:e,r.targetScroll=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.9",r.options={duration:c,easing:d,smooth:f,smoothTouch:y,touchMultiplier:g,direction:b,gestureDirection:S,wrapper:M,content:E},r.duration=c,r.easing=d,r.smooth=f,r.smoothTouch=y,r.touchMultiplier=g,r.direction=b,r.gestureDirection=S,r.wrapperNode=M,r.contentNode=E,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 W=(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:W.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=void 0===e?{}:e,o=i.offset,n=void 0===o?0:o,r=i.immediate,s=void 0!==r&&r,l=i.duration,h=void 0===l?this.duration:l,a=i.easing,c=void 0===a?this.easing:a;if(null!=t){var u;if("number"==typeof t)u=t;else if("top"===t||"#top"===t)u=0;else if("bottom"===t)u=this.limit;else{var d;if("string"==typeof t)d=document.querySelector(t);else{if(null==t||!t.nodeType)return;d=t}if(!d)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();u=("horizontal"===this.direction?v.left:v.top)+this.scroll-p}this.targetScroll=u+=n,!this.smooth||s?this.setScroll(this.targetScroll):this.animate.to(this,{duration:h,easing:c,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 07fd4a78..c88d98c5 100644 --- a/dist/lenis.js +++ b/dist/lenis.js @@ -1,2 +1,2 @@ -var t=require("tiny-emitter"),e=require("virtual-scroll");function o(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var i=/*#__PURE__*/o(t),r=/*#__PURE__*/o(e);function n(t,e){for(var o=0;o=0||(r[o]=t[o]);return r}(i,a);this.target=t,this.fromKeys=l({},h),this.toKeys=l({},h),this.keys=Object.keys(l({},h)),this.keys.forEach(function(e){o.fromKeys[e]=t[e]}),this.duration=n,this.easing=c,this.currentTime=0,this.isRunning=!0},e.stop=function(){this.isRunning=!1},e.raf=function(t){var e=this;if(this.isRunning){this.currentTime=Math.min(this.currentTime+.001*t,this.duration);var o=this.easing(this.progress);this.keys.forEach(function(t){var i=e.fromKeys[t];e.target[t]=i+(e.toKeys[t]-i)*o}),1===o&&(this.isRunning=!1)}},s(t,[{key:"progress",get:function(){return this.currentTime/this.duration}}]),t}();module.exports=/*#__PURE__*/function(t){var e,o;function i(e){var o,i,n,s,l=void 0===e?{}:e,c=l.duration,a=void 0===c?1.2:c,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); +var t=require("tiny-emitter"),e=require("virtual-scroll");function o(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var i=/*#__PURE__*/o(t),r=/*#__PURE__*/o(e);function n(t,e){for(var o=0;o=0||(r[o]=t[o]);return r}(i,a);this.target=t,this.fromKeys=l({},h),this.toKeys=l({},h),this.keys=Object.keys(l({},h)),this.keys.forEach(function(e){o.fromKeys[e]=t[e]}),this.duration=n,this.easing=c,this.currentTime=0,this.isRunning=!0},e.stop=function(){this.isRunning=!1},e.raf=function(t){var e=this;if(this.isRunning){this.currentTime=Math.min(this.currentTime+.001*t,this.duration);var o=this.easing(this.progress);this.keys.forEach(function(t){var i=e.fromKeys[t];e.target[t]=i+(e.toKeys[t]-i)*o}),1===o&&(this.isRunning=!1)}},s(t,[{key:"progress",get:function(){return this.currentTime/this.duration}}]),t}();module.exports=/*#__PURE__*/function(t){var e,o;function i(e){var o,i,n,s,l=void 0===e?{}:e,c=l.duration,a=void 0===c?1.2:c,u=l.easing,p=void 0===u?function(t){return 1===t?1:1-Math.pow(2,-10*t)}:u,d=l.smooth,f=void 0===d||d,v=l.smoothTouch,g=void 0!==v&&v,w=l.touchMultiplier,m=void 0===w?2:w,y=l.direction,b=void 0===y?"vertical":y,S=l.gestureDirection,N=void 0===S?"vertical":S,O=l.wrapper,z=void 0===O?window:O,R=l.content,W=void 0===R?document.body:R;(s=t.call(this)||this).onWindowResize=function(){s.wrapperWidth=window.innerWidth,s.wrapperHeight=window.innerHeight},s.onWrapperResize=function(t){var e=t[0];if(e){var o=e.contentRect;s.wrapperWidth=o.width,s.wrapperHeight=o.height}},s.onContentResize=function(t){var e=t[0];if(e){var o=e.contentRect;s.contentWidth=o.width,s.contentHeight=o.height}},s.onVirtualScroll=function(t){var e=t.deltaY,o=t.deltaX,i=t.originalEvent;i.ctrlKey||(s.smooth=i.changedTouches?s.smoothTouch:s.options.smooth,s.stopped?i.preventDefault():s.smooth&&4!==i.buttons&&(s.smooth&&i.preventDefault(),s.targetScroll-="both"===s.gestureDirection?o+e:"horizontal"===s.gestureDirection?o:e,s.targetScroll=Math.max(0,Math.min(s.targetScroll,s.limit)),s.scrollTo(s.targetScroll)))},s.onScroll=function(t){s.isScrolling&&s.smooth||(s.targetScroll=s.scroll=s.lastScroll=s.wrapperNode[s.scrollProperty],s.notify())},window.lenisVersion="0.2.9",s.options={duration:a,easing:p,smooth:f,smoothTouch:g,touchMultiplier:m,direction:b,gestureDirection:N,wrapper:z,content:W},s.duration=a,s.easing=p,s.smooth=f,s.smoothTouch=g,s.touchMultiplier=m,s.direction=b,s.gestureDirection=N,s.wrapperNode=z,s.contentNode=W,s.wrapperNode.addEventListener("scroll",s.onScroll),s.wrapperNode===window?(s.wrapperNode.addEventListener("resize",s.onWindowResize),s.onWindowResize()):(s.wrapperHeight=s.wrapperNode.offsetHeight,s.wrapperWidth=s.wrapperNode.offsetWidth,s.wrapperObserver=new ResizeObserver(s.onWrapperResize),s.wrapperObserver.observe(s.wrapperNode)),s.contentHeight=s.contentNode.offsetHeight,s.contentWidth=s.contentNode.offsetWidth,s.contentObserver=new ResizeObserver(s.onContentResize),s.contentObserver.observe(s.contentNode),s.targetScroll=s.scroll=s.lastScroll=s.wrapperNode[s.scrollProperty],s.animate=new h;var T=(null==(o=navigator)||null==(i=o.userAgentData)?void 0:i.platform)||(null==(n=navigator)?void 0:n.platform)||"unknown";return s.virtualScroll=new r.default({el:s.wrapperNode,firefoxMultiplier:50,mouseMultiplier:T.includes("Win")?1:.4,useKeyboard:!1,touchMultiplier:s.touchMultiplier,useTouch:!0,passive:!1}),s.virtualScroll.on(s.onVirtualScroll),s}o=t,(e=i).prototype=Object.create(o.prototype),e.prototype.constructor=e,c(e,o);var n=i.prototype;return n.start=function(){this.stopped=!1},n.stop=function(){this.stopped=!0,this.animate.stop()},n.destroy=function(){var t;this.wrapperNode===window&&this.wrapperNode.removeEventListener("resize",this.onWindowResize),this.wrapperNode.removeEventListener("scroll",this.onScroll),this.virtualScroll.destroy(),null==(t=this.wrapperObserver)||t.disconnect(),this.contentObserver.disconnect()},n.raf=function(t){var e=t-(this.now||0);this.now=t,!this.stopped&&this.smooth&&(this.lastScroll=this.scroll,this.animate.raf(e),this.scroll===this.targetScroll&&(this.lastScroll=this.scroll),this.isScrolling&&(this.setScroll(this.scroll),this.notify()),this.isScrolling=this.scroll!==this.targetScroll)},n.setScroll=function(t){"horizontal"===this.direction?this.wrapperNode.scrollTo(t,0):this.wrapperNode.scrollTo(0,t)},n.notify=function(){this.emit("scroll",{scroll:this.scroll,limit:this.limit,velocity:this.velocity,direction:this.direction,progress:this.scroll/this.limit})},n.scrollTo=function(t,e){var o=void 0===e?{}:e,i=o.offset,r=void 0===i?0:i,n=o.immediate,s=void 0!==n&&n,l=o.duration,c=void 0===l?this.duration:l,a=o.easing,h=void 0===a?this.easing:a;if(null!=t){var u;if("number"==typeof t)u=t;else if("top"===t||"#top"===t)u=0;else if("bottom"===t)u=this.limit;else{var p;if("string"==typeof t)p=document.querySelector(t);else{if(null==t||!t.nodeType)return;p=t}if(!p)return;var d=0;if(this.wrapperNode!==window){var f=this.wrapperNode.getBoundingClientRect();d="horizontal"===this.direction?f.left:f.top}var v=p.getBoundingClientRect();u=("horizontal"===this.direction?v.left:v.top)+this.scroll-d}this.targetScroll=u+=r,!this.smooth||s?this.setScroll(this.targetScroll):this.animate.to(this,{duration:c,easing:h,scroll:this.targetScroll})}},s(i,[{key:"scrollProperty",get:function(){return this.wrapperNode===window?"horizontal"===this.direction?"scrollX":"scrollY":"horizontal"===this.direction?"scrollLeft":"scrollTop"}},{key:"limit",get:function(){return"horizontal"===this.direction?this.contentWidth-this.wrapperWidth:this.contentHeight-this.wrapperHeight}},{key:"velocity",get:function(){return this.scroll-this.lastScroll}}]),i}(i.default); //# sourceMappingURL=lenis.js.map diff --git a/dist/lenis.js.map b/dist/lenis.js.map index af363974..352641d7 100644 --- a/dist/lenis.js.map +++ b/dist/lenis.js.map @@ -1 +1 @@ -{"version":3,"file":"lenis.js","sources":["../src/lenis.js","../src/maths.js"],"sourcesContent":["import EventEmitter from 'tiny-emitter'\r\nimport VirtualScroll from 'virtual-scroll'\r\nimport { version } from '../package.json'\r\nimport { clamp } from './maths.js'\r\n\r\nclass Animate {\r\n to(target, { duration = 1, easing = (t) => t, ...keys } = {}) {\r\n this.target = target\r\n this.fromKeys = { ...keys }\r\n this.toKeys = { ...keys }\r\n this.keys = Object.keys({ ...keys })\r\n\r\n // get initial values\r\n this.keys.forEach((key) => {\r\n this.fromKeys[key] = target[key]\r\n })\r\n\r\n this.duration = duration\r\n this.easing = easing\r\n this.currentTime = 0\r\n this.isRunning = true\r\n }\r\n\r\n stop() {\r\n this.isRunning = false\r\n }\r\n\r\n raf(deltaTime) {\r\n if (!this.isRunning) return\r\n\r\n this.currentTime = Math.min(\r\n this.currentTime + deltaTime * 0.001,\r\n this.duration\r\n )\r\n\r\n const progress = this.easing(this.progress)\r\n\r\n this.keys.forEach((key) => {\r\n const from = this.fromKeys[key]\r\n const to = this.toKeys[key]\r\n\r\n const value = from + (to - from) * progress\r\n\r\n this.target[key] = value\r\n })\r\n\r\n if (progress === 1) {\r\n this.isRunning = false\r\n }\r\n }\r\n\r\n get progress() {\r\n return this.currentTime / this.duration\r\n }\r\n}\r\n\r\nexport default class Lenis extends EventEmitter {\r\n constructor({\r\n duration = 1.2,\r\n easing = (t) => (t === 1 ? 1 : 1 - Math.pow(2, -10 * t)), // https://easings.net/en#easeOutExpo\r\n smooth = true,\r\n smoothTouch = false,\r\n touchMultiplier = 2,\r\n direction = 'vertical',\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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D,WACE,OAAY6B,KAAAA,OAASnF,KAAKoF,UAC3B,KAhMgC2B,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', // vertical, horizontal\r\n gestureDirection = 'vertical', // vertical, horizontal, both\r\n wrapper = window,\r\n content = document.body,\r\n } = {}) {\r\n super()\r\n\r\n window.lenisVersion = version\r\n\r\n this.options = {\r\n duration,\r\n easing,\r\n smooth,\r\n smoothTouch,\r\n touchMultiplier,\r\n direction,\r\n gestureDirection,\r\n wrapper,\r\n content,\r\n }\r\n\r\n this.duration = duration\r\n this.easing = easing\r\n this.smooth = smooth\r\n this.smoothTouch = smoothTouch\r\n this.touchMultiplier = touchMultiplier\r\n this.direction = direction\r\n this.gestureDirection = gestureDirection\r\n this.wrapperNode = wrapper\r\n this.contentNode = content\r\n\r\n this.wrapperNode.addEventListener('scroll', this.onScroll)\r\n\r\n //observe wrapper node size\r\n if (this.wrapperNode === window) {\r\n this.wrapperNode.addEventListener('resize', this.onWindowResize)\r\n this.onWindowResize()\r\n } else {\r\n this.wrapperHeight = this.wrapperNode.offsetHeight\r\n this.wrapperWidth = this.wrapperNode.offsetWidth\r\n\r\n //observe wrapper node size\r\n this.wrapperObserver = new ResizeObserver(this.onWrapperResize)\r\n this.wrapperObserver.observe(this.wrapperNode)\r\n }\r\n\r\n this.contentHeight = this.contentNode.offsetHeight\r\n this.contentWidth = this.contentNode.offsetWidth\r\n\r\n //observe content node size\r\n this.contentObserver = new ResizeObserver(this.onContentResize)\r\n this.contentObserver.observe(this.contentNode)\r\n\r\n //set initial scroll position\r\n this.targetScroll =\r\n this.scroll =\r\n this.lastScroll =\r\n this.wrapperNode[this.scrollProperty]\r\n\r\n this.animate = new Animate()\r\n\r\n const platform =\r\n navigator?.userAgentData?.platform || navigator?.platform || 'unknown'\r\n\r\n // listen and normalize wheel event cross-browser\r\n this.virtualScroll = new VirtualScroll({\r\n el: this.wrapperNode,\r\n firefoxMultiplier: 50,\r\n mouseMultiplier: platform.includes('Win') ? 1 : 0.4,\r\n useKeyboard: false,\r\n touchMultiplier: this.touchMultiplier,\r\n useTouch: true,\r\n passive: false,\r\n })\r\n\r\n this.virtualScroll.on(this.onVirtualScroll)\r\n }\r\n\r\n get scrollProperty() {\r\n let property\r\n if (this.wrapperNode === window) {\r\n property = this.direction === 'horizontal' ? 'scrollX' : 'scrollY'\r\n } else {\r\n property = this.direction === 'horizontal' ? 'scrollLeft' : 'scrollTop'\r\n }\r\n return property\r\n }\r\n\r\n start() {\r\n this.stopped = false\r\n }\r\n\r\n stop() {\r\n this.stopped = true\r\n this.animate.stop()\r\n }\r\n\r\n destroy() {\r\n if (this.wrapperNode === window) {\r\n this.wrapperNode.removeEventListener('resize', this.onWindowResize)\r\n }\r\n this.wrapperNode.removeEventListener('scroll', this.onScroll)\r\n\r\n this.virtualScroll.destroy()\r\n this.wrapperObserver?.disconnect()\r\n this.contentObserver.disconnect()\r\n }\r\n\r\n onWindowResize = () => {\r\n this.wrapperWidth = window.innerWidth\r\n this.wrapperHeight = window.innerHeight\r\n }\r\n\r\n onWrapperResize = ([entry]) => {\r\n if (entry) {\r\n const rect = entry.contentRect\r\n this.wrapperWidth = rect.width\r\n this.wrapperHeight = rect.height\r\n }\r\n }\r\n\r\n onContentResize = ([entry]) => {\r\n if (entry) {\r\n const rect = entry.contentRect\r\n this.contentWidth = rect.width\r\n this.contentHeight = rect.height\r\n }\r\n }\r\n\r\n get limit() {\r\n return this.direction === 'horizontal'\r\n ? this.contentWidth - this.wrapperWidth\r\n : this.contentHeight - this.wrapperHeight\r\n }\r\n\r\n onVirtualScroll = ({ deltaY, deltaX, originalEvent: e }) => {\r\n if (e.ctrlKey) return\r\n\r\n // switch to smooth if event is touch and touch is true\r\n this.smooth = !!e.changedTouches ? this.smoothTouch : this.options.smooth\r\n\r\n if (this.stopped) {\r\n e.preventDefault()\r\n return\r\n }\r\n\r\n if (!this.smooth) return\r\n\r\n // fix wheel holding scroll https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/buttons\r\n if (e.buttons === 4) return\r\n\r\n // prevent native wheel scrolling\r\n if (this.smooth) e.preventDefault()\r\n\r\n let delta = 0\r\n if (this.gestureDirection === 'both') {\r\n delta = deltaX + deltaY\r\n } else if (this.gestureDirection === 'horizontal') {\r\n delta = deltaX\r\n } else {\r\n // vertical\r\n delta = deltaY\r\n }\r\n\r\n this.targetScroll -= delta\r\n this.targetScroll = clamp(0, this.targetScroll, this.limit)\r\n\r\n this.scrollTo(this.targetScroll)\r\n }\r\n\r\n raf(now) {\r\n const deltaTime = now - (this.now || 0)\r\n this.now = now\r\n\r\n if (this.stopped || !this.smooth) return\r\n\r\n this.lastScroll = this.scroll\r\n\r\n // where this.scroll is updated\r\n this.animate.raf(deltaTime)\r\n\r\n if (this.scroll === this.targetScroll) {\r\n // if target reached velocity should be 0\r\n this.lastScroll = this.scroll\r\n }\r\n\r\n if (this.isScrolling) {\r\n this.setScroll(this.scroll)\r\n this.notify()\r\n }\r\n\r\n this.isScrolling = this.scroll !== this.targetScroll\r\n }\r\n\r\n get velocity() {\r\n return this.scroll - this.lastScroll\r\n }\r\n\r\n setScroll(value) {\r\n this.direction === 'horizontal'\r\n ? this.wrapperNode.scrollTo(value, 0)\r\n : this.wrapperNode.scrollTo(0, value)\r\n }\r\n\r\n onScroll = (e) => {\r\n // if isScrolling false we can consider user isn't scrolling with wheel (cmd+F, keyboard or whatever). So we must scroll to value immediately\r\n if (!this.isScrolling || !this.smooth) {\r\n // where native scroll happens\r\n this.targetScroll =\r\n this.scroll =\r\n this.lastScroll =\r\n this.wrapperNode[this.scrollProperty]\r\n\r\n this.notify()\r\n }\r\n }\r\n\r\n notify() {\r\n this.emit('scroll', {\r\n scroll: this.scroll,\r\n limit: this.limit,\r\n velocity: this.velocity,\r\n direction: this.direction,\r\n progress: this.scroll / this.limit,\r\n })\r\n }\r\n\r\n scrollTo(\r\n target,\r\n {\r\n offset = 0,\r\n immediate = false,\r\n duration = this.duration,\r\n easing = this.easing,\r\n } = {}\r\n ) {\r\n if (target === undefined || target === null) return\r\n let value\r\n\r\n if (typeof target === 'number') {\r\n value = target\r\n } else if (target === 'top' || target === '#top') {\r\n value = 0\r\n } else if (target === 'bottom') {\r\n value = this.limit\r\n } else {\r\n let node\r\n\r\n if (typeof target === 'string') {\r\n // CSS selector\r\n node = document.querySelector(target)\r\n } else if (target?.nodeType) {\r\n // Node element\r\n node = target\r\n } else {\r\n return\r\n }\r\n\r\n if (!node) return\r\n let wrapperOffset = 0\r\n\r\n if (this.wrapperNode !== window) {\r\n const wrapperRect = this.wrapperNode.getBoundingClientRect()\r\n wrapperOffset =\r\n this.direction === 'horizontal' ? wrapperRect.left : wrapperRect.top\r\n }\r\n\r\n const rect = node.getBoundingClientRect()\r\n\r\n value =\r\n (this.direction === 'horizontal' ? rect.left : rect.top) +\r\n this.scroll -\r\n wrapperOffset\r\n }\r\n\r\n value += offset\r\n\r\n this.targetScroll = value\r\n\r\n if (!this.smooth || immediate) {\r\n this.setScroll(this.targetScroll)\r\n } else {\r\n this.animate.to(this, {\r\n duration,\r\n easing,\r\n scroll: this.targetScroll,\r\n })\r\n }\r\n }\r\n}\r\n","export function clamp(min, input, max) {\r\n return Math.max(min, Math.min(input, max))\r\n}\r\n\r\nexport function mapRange(in_min, in_max, input, out_min, out_max) {\r\n return ((input - in_min) * (out_max - out_min)) / (in_max - in_min) + out_min\r\n}\r\n\r\nexport function lerp(start, end, amt) {\r\n return (1 - amt) * start + amt * end\r\n}\r\n\r\nexport function truncate(value, decimals) {\r\n return parseFloat(value.toFixed(decimals))\r\n}\r\n"],"names":["_excluded","Lenis","to","target","_temp","_this","this","_ref","duration","_ref$duration","_ref$easing","easing","t","keys","fromKeys","toKeys","_extends","Object","forEach","key","currentTime","isRunning","stop","raf","deltaTime","_this2","Math","min","progress","from","_temp2","_navigator","_navigator$userAgentD","_navigator2","_this3","_ref2","_ref2$duration","_ref2$easing","pow","smooth","_ref2$smooth","smoothTouch","_ref2$smoothTouch","_ref2$touchMultiplier","touchMultiplier","_ref2$direction","direction","gestureDirection","_ref2$gestureDirectio","wrapper","_ref2$wrapper","window","content","_ref2$content","document","body","_EventEmitter","call","onWindowResize","wrapperWidth","innerWidth","wrapperHeight","innerHeight","onWrapperResize","_ref3","entry","rect","contentRect","width","height","onContentResize","_ref4","contentWidth","contentHeight","onVirtualScroll","_ref5","deltaY","deltaX","e","originalEvent","ctrlKey","changedTouches","options","stopped","preventDefault","buttons","targetScroll","max","limit","scrollTo","onScroll","isScrolling","scroll","lastScroll","wrapperNode","scrollProperty","notify","lenisVersion","contentNode","addEventListener","offsetHeight","offsetWidth","wrapperObserver","observe","contentObserver","ResizeObserver","animate","Animate","platform","navigator","userAgentData","virtualScroll","VirtualScroll","el","firefoxMultiplier","mouseMultiplier","includes","useKeyboard","useTouch","passive","on","EventEmitter","start","destroy","_this$wrapperObserver","removeEventListener","disconnect","now","setScroll","value","emit","velocity","_temp3","_ref6","_ref6$offset","offset","_ref6$immediate","immediate","_ref6$duration","node","querySelector","nodeType","wrapperOffset","wrapperRect","getBoundingClientRect","left","top","_createClass","get"],"mappings":"6xBAAA,IAAAA,EAAA,CAAA,WAAA,oEAwDqBC,SAlDnBC,GAAA,SAAGC,EAA2DC,GAAA,IAAAC,EAAAC,KAAAC,OAAA,IAAAH,EAAJ,CAAA,EAA7CI,EAAAA,EAAAA,EAAAA,SAAAA,aAAW,EAAsCC,EAAAC,EAAAH,EAAnCI,OAAAA,aAAS,SAACC,GAAMA,OAAAA,CAAP,EAAaC,EAAAA,0IAC/CP,KAAKH,OAASA,EACdG,KAAKQ,cAAgBD,GACrBP,KAAKS,OAALC,EAAA,CAAA,EAAmBH,GACnBP,KAAKO,KAAOI,OAAOJ,UAAUA,IAG7BP,KAAKO,KAAKK,QAAQ,SAACC,GACjBd,EAAKS,SAASK,GAAOhB,EAAOgB,EAC7B,GAEDb,KAAKE,SAAWA,EAChBF,KAAKK,OAASA,EACdL,KAAKc,YAAc,EACnBd,KAAKe,WAAY,CAClB,IAEDC,KAAA,WACEhB,KAAKe,WAAY,CAClB,IAEDE,IAAA,SAAIC,GAAW,IAAAC,EAAAnB,KACb,GAAKA,KAAKe,UAAV,CAEAf,KAAKc,YAAcM,KAAKC,IACtBrB,KAAKc,YAA0B,KAAZI,EACnBlB,KAAKE,UAGP,IAAcoB,EAAGtB,KAAKK,OAAOL,KAAKsB,UAElCtB,KAAKO,KAAKK,QAAQ,SAACC,GACjB,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FAF,EAAOxI,CAGR,CAED,IAAKwI,EAAM,OACX,IAAiBG,EAAG,EAEpB,GAAIxI,KAAKwF,cAAgB3C,OAAQ,CAC/B,IAAM4F,EAAczI,KAAKwF,YAAYkD,wBACrCF,EACqB,eAAnBxI,KAAKwC,UAA6BiG,EAAYE,KAAOF,EAAYG,GACpE,CAED,IAAUhF,EAAGyE,EAAKK,wBAElBf,GACsB,eAAnB3H,KAAKwC,UAA6BoB,EAAK+E,KAAO/E,EAAKgF,KACpD5I,KAAKsF,OACLkD,CACH,CAIDxI,KAAKgF,aAFL2C,GAASM,GAIJjI,KAAKiC,QAAUkG,EAClBnI,KAAK0H,UAAU1H,KAAKgF,cAEpBhF,KAAKoG,QAAQxG,GAAGI,KAAM,CACpBE,SAAAA,EACAG,OAAAA,EACAiF,OAAQtF,KAAKgF,cAjD4B,CAoD9C,EAlND6D,EAAAlJ,EAAA,CAAA,CAAAkB,IAAA,iBAAAiI,IAAA,WAOE,OALI9I,KAAKwF,cAAgB3C,OACO,eAAnB7C,KAAKwC,UAA6B,UAAY,UAE3B,eAAnBxC,KAAKwC,UAA6B,aAAe,WAG/D,GA2CD,CAAA3B,IAAA,QAAAiI,IAAA,WACE,MAA0B,oBAAdtG,UACRxC,KAAKkE,aAAelE,KAAKqD,aACzBrD,KAAKmE,cAAgBnE,KAAKuD,aAC/B,uBA6DD,WACE,OAAY+B,KAAAA,OAAStF,KAAKuF,UAC3B,KA3MgC4B,CAAAA,EAAAA"} \ No newline at end of file diff --git a/dist/lenis.mjs b/dist/lenis.mjs index 091f186c..a29c05f8 100644 --- a/dist/lenis.mjs +++ b/dist/lenis.mjs @@ -1,2 +1,2 @@ -import t from"tiny-emitter";import e from"virtual-scroll";function o(t,e){for(var o=0;o=0||(r[o]=t[o]);return r}(i,s);this.target=t,this.fromKeys=r({},h),this.toKeys=r({},h),this.keys=Object.keys(r({},h)),this.keys.forEach(function(e){o.fromKeys[e]=t[e]}),this.duration=l,this.easing=a,this.currentTime=0,this.isRunning=!0},e.stop=function(){this.isRunning=!1},e.raf=function(t){var e=this;if(this.isRunning){this.currentTime=Math.min(this.currentTime+.001*t,this.duration);var o=this.easing(this.progress);this.keys.forEach(function(t){var i=e.fromKeys[t];e.target[t]=i+(e.toKeys[t]-i)*o}),1===o&&(this.isRunning=!1)}},i(t,[{key:"progress",get:function(){return this.currentTime/this.duration}}]),t}(),c=/*#__PURE__*/function(t){var o,r;function s(o){var i,r,n,s,c=void 0===o?{}:o,a=c.duration,h=void 0===a?1.2:a,p=c.easing,u=void 0===p?function(t){return 1===t?1:1-Math.pow(2,-10*t)}:p,d=c.smooth,f=void 0===d||d,v=c.smoothTouch,g=void 0!==v&&v,w=c.touchMultiplier,m=void 0===w?2:w,y=c.direction,b=void 0===y?"vertical":y,S=c.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}; +import t from"tiny-emitter";import e from"virtual-scroll";function o(t,e){for(var o=0;o=0||(r[o]=t[o]);return r}(i,s);this.target=t,this.fromKeys=r({},h),this.toKeys=r({},h),this.keys=Object.keys(r({},h)),this.keys.forEach(function(e){o.fromKeys[e]=t[e]}),this.duration=l,this.easing=a,this.currentTime=0,this.isRunning=!0},e.stop=function(){this.isRunning=!1},e.raf=function(t){var e=this;if(this.isRunning){this.currentTime=Math.min(this.currentTime+.001*t,this.duration);var o=this.easing(this.progress);this.keys.forEach(function(t){var i=e.fromKeys[t];e.target[t]=i+(e.toKeys[t]-i)*o}),1===o&&(this.isRunning=!1)}},i(t,[{key:"progress",get:function(){return this.currentTime/this.duration}}]),t}(),c=/*#__PURE__*/function(t){var o,r;function s(o){var i,r,n,s,c=void 0===o?{}:o,a=c.duration,h=void 0===a?1.2:a,p=c.easing,u=void 0===p?function(t){return 1===t?1:1-Math.pow(2,-10*t)}:p,d=c.smooth,f=void 0===d||d,v=c.smoothTouch,g=void 0!==v&&v,w=c.touchMultiplier,m=void 0===w?2:w,y=c.direction,b=void 0===y?"vertical":y,S=c.gestureDirection,N=void 0===S?"vertical":S,O=c.wrapper,z=void 0===O?window:O,R=c.content,W=void 0===R?document.body:R;(s=t.call(this)||this).onWindowResize=function(){s.wrapperWidth=window.innerWidth,s.wrapperHeight=window.innerHeight},s.onWrapperResize=function(t){var e=t[0];if(e){var o=e.contentRect;s.wrapperWidth=o.width,s.wrapperHeight=o.height}},s.onContentResize=function(t){var e=t[0];if(e){var o=e.contentRect;s.contentWidth=o.width,s.contentHeight=o.height}},s.onVirtualScroll=function(t){var e=t.deltaY,o=t.deltaX,i=t.originalEvent;i.ctrlKey||(s.smooth=i.changedTouches?s.smoothTouch:s.options.smooth,s.stopped?i.preventDefault():s.smooth&&4!==i.buttons&&(s.smooth&&i.preventDefault(),s.targetScroll-="both"===s.gestureDirection?o+e:"horizontal"===s.gestureDirection?o:e,s.targetScroll=Math.max(0,Math.min(s.targetScroll,s.limit)),s.scrollTo(s.targetScroll)))},s.onScroll=function(t){s.isScrolling&&s.smooth||(s.targetScroll=s.scroll=s.lastScroll=s.wrapperNode[s.scrollProperty],s.notify())},window.lenisVersion="0.2.9",s.options={duration:h,easing:u,smooth:f,smoothTouch:g,touchMultiplier:m,direction:b,gestureDirection:N,wrapper:z,content:W},s.duration=h,s.easing=u,s.smooth=f,s.smoothTouch=g,s.touchMultiplier=m,s.direction=b,s.gestureDirection=N,s.wrapperNode=z,s.contentNode=W,s.wrapperNode.addEventListener("scroll",s.onScroll),s.wrapperNode===window?(s.wrapperNode.addEventListener("resize",s.onWindowResize),s.onWindowResize()):(s.wrapperHeight=s.wrapperNode.offsetHeight,s.wrapperWidth=s.wrapperNode.offsetWidth,s.wrapperObserver=new ResizeObserver(s.onWrapperResize),s.wrapperObserver.observe(s.wrapperNode)),s.contentHeight=s.contentNode.offsetHeight,s.contentWidth=s.contentNode.offsetWidth,s.contentObserver=new ResizeObserver(s.onContentResize),s.contentObserver.observe(s.contentNode),s.targetScroll=s.scroll=s.lastScroll=s.wrapperNode[s.scrollProperty],s.animate=new l;var T=(null==(i=navigator)||null==(r=i.userAgentData)?void 0:r.platform)||(null==(n=navigator)?void 0:n.platform)||"unknown";return s.virtualScroll=new e({el:s.wrapperNode,firefoxMultiplier:50,mouseMultiplier:T.includes("Win")?1:.4,useKeyboard:!1,touchMultiplier:s.touchMultiplier,useTouch:!0,passive:!1}),s.virtualScroll.on(s.onVirtualScroll),s}r=t,(o=s).prototype=Object.create(r.prototype),o.prototype.constructor=o,n(o,r);var c=s.prototype;return c.start=function(){this.stopped=!1},c.stop=function(){this.stopped=!0,this.animate.stop()},c.destroy=function(){var t;this.wrapperNode===window&&this.wrapperNode.removeEventListener("resize",this.onWindowResize),this.wrapperNode.removeEventListener("scroll",this.onScroll),this.virtualScroll.destroy(),null==(t=this.wrapperObserver)||t.disconnect(),this.contentObserver.disconnect()},c.raf=function(t){var e=t-(this.now||0);this.now=t,!this.stopped&&this.smooth&&(this.lastScroll=this.scroll,this.animate.raf(e),this.scroll===this.targetScroll&&(this.lastScroll=this.scroll),this.isScrolling&&(this.setScroll(this.scroll),this.notify()),this.isScrolling=this.scroll!==this.targetScroll)},c.setScroll=function(t){"horizontal"===this.direction?this.wrapperNode.scrollTo(t,0):this.wrapperNode.scrollTo(0,t)},c.notify=function(){this.emit("scroll",{scroll:this.scroll,limit:this.limit,velocity:this.velocity,direction:this.direction,progress:this.scroll/this.limit})},c.scrollTo=function(t,e){var o=void 0===e?{}:e,i=o.offset,r=void 0===i?0:i,n=o.immediate,s=void 0!==n&&n,l=o.duration,c=void 0===l?this.duration:l,a=o.easing,h=void 0===a?this.easing:a;if(null!=t){var p;if("number"==typeof t)p=t;else if("top"===t||"#top"===t)p=0;else if("bottom"===t)p=this.limit;else{var u;if("string"==typeof t)u=document.querySelector(t);else{if(null==t||!t.nodeType)return;u=t}if(!u)return;var d=0;if(this.wrapperNode!==window){var f=this.wrapperNode.getBoundingClientRect();d="horizontal"===this.direction?f.left:f.top}var v=u.getBoundingClientRect();p=("horizontal"===this.direction?v.left:v.top)+this.scroll-d}this.targetScroll=p+=r,!this.smooth||s?this.setScroll(this.targetScroll):this.animate.to(this,{duration:c,easing:h,scroll:this.targetScroll})}},i(s,[{key:"scrollProperty",get:function(){return this.wrapperNode===window?"horizontal"===this.direction?"scrollX":"scrollY":"horizontal"===this.direction?"scrollLeft":"scrollTop"}},{key:"limit",get:function(){return"horizontal"===this.direction?this.contentWidth-this.wrapperWidth:this.contentHeight-this.wrapperHeight}},{key:"velocity",get:function(){return this.scroll-this.lastScroll}}]),s}(t);export{c as default}; //# sourceMappingURL=lenis.mjs.map diff --git a/dist/lenis.mjs.map b/dist/lenis.mjs.map index 2ce1a5eb..de8071c2 100644 --- a/dist/lenis.mjs.map +++ b/dist/lenis.mjs.map @@ -1 +1 @@ -{"version":3,"file":"lenis.mjs","sources":["../src/lenis.js","../src/maths.js"],"sourcesContent":["import EventEmitter from 'tiny-emitter'\r\nimport VirtualScroll from 'virtual-scroll'\r\nimport { version } from '../package.json'\r\nimport { clamp } from './maths.js'\r\n\r\nclass Animate {\r\n to(target, { duration = 1, easing = (t) => t, ...keys } = {}) {\r\n this.target = target\r\n this.fromKeys = { ...keys }\r\n this.toKeys = { ...keys }\r\n this.keys = Object.keys({ ...keys })\r\n\r\n // get initial values\r\n this.keys.forEach((key) => {\r\n this.fromKeys[key] = target[key]\r\n })\r\n\r\n this.duration = duration\r\n this.easing = easing\r\n this.currentTime = 0\r\n this.isRunning = true\r\n }\r\n\r\n stop() {\r\n this.isRunning = false\r\n }\r\n\r\n raf(deltaTime) {\r\n if (!this.isRunning) return\r\n\r\n this.currentTime = Math.min(\r\n this.currentTime + deltaTime * 0.001,\r\n this.duration\r\n )\r\n\r\n const progress = this.easing(this.progress)\r\n\r\n this.keys.forEach((key) => {\r\n const from = this.fromKeys[key]\r\n const to = this.toKeys[key]\r\n\r\n const value = from + (to - from) * progress\r\n\r\n this.target[key] = value\r\n })\r\n\r\n if (progress === 1) {\r\n this.isRunning = false\r\n }\r\n }\r\n\r\n get progress() {\r\n return this.currentTime / this.duration\r\n }\r\n}\r\n\r\nexport default class Lenis extends EventEmitter {\r\n constructor({\r\n duration = 1.2,\r\n easing = (t) => (t === 1 ? 1 : 1 - Math.pow(2, -10 * t)), // https://easings.net/en#easeOutExpo\r\n smooth = true,\r\n smoothTouch = false,\r\n touchMultiplier = 2,\r\n direction = 'vertical',\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,WAA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AAcpI,OACzB,IAAIA,MAAAA,IAAAA,EAAQqI,SAIjB,OAFAF,EAAOnI,CAGR,CAED,IAAKA,EAAQ,OACb,MAAoB,EAEpB,GAAIE,KAAKqF,cAAgBzC,OAAQ,CAC/B,IAAiBwF,EAAGpI,KAAKqF,YAAYgD,wBACrCC,EACqB,eAAnBtI,KAAKyC,UAA6B2F,EAAYG,KAAOH,EAAYI,GACpE,CAED,IAAU7E,EAAGsE,EAAKI,wBAElBd,GACsB,eAAnBvH,KAAKyC,UAA6BkB,EAAK4E,KAAO5E,EAAK6E,KACpDxI,KAAKmF,OACLmD,CACH,CAIDtI,KAAK6E,aAFL0C,GAASM,GAIJ7H,KAAKkC,QAAU4F,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 +{"version":3,"file":"lenis.mjs","sources":["../src/lenis.js","../src/maths.js"],"sourcesContent":["import EventEmitter from 'tiny-emitter'\r\nimport VirtualScroll from 'virtual-scroll'\r\nimport { version } from '../package.json'\r\nimport { clamp } from './maths.js'\r\n\r\nclass Animate {\r\n to(target, { duration = 1, easing = (t) => t, ...keys } = {}) {\r\n this.target = target\r\n this.fromKeys = { ...keys }\r\n this.toKeys = { ...keys }\r\n this.keys = Object.keys({ ...keys })\r\n\r\n // get initial values\r\n this.keys.forEach((key) => {\r\n this.fromKeys[key] = target[key]\r\n })\r\n\r\n this.duration = duration\r\n this.easing = easing\r\n this.currentTime = 0\r\n this.isRunning = true\r\n }\r\n\r\n stop() {\r\n this.isRunning = false\r\n }\r\n\r\n raf(deltaTime) {\r\n if (!this.isRunning) return\r\n\r\n this.currentTime = Math.min(\r\n this.currentTime + deltaTime * 0.001,\r\n this.duration\r\n )\r\n\r\n const progress = this.easing(this.progress)\r\n\r\n this.keys.forEach((key) => {\r\n const from = this.fromKeys[key]\r\n const to = this.toKeys[key]\r\n\r\n const value = from + (to - from) * progress\r\n\r\n this.target[key] = value\r\n })\r\n\r\n if (progress === 1) {\r\n this.isRunning = false\r\n }\r\n }\r\n\r\n get progress() {\r\n return this.currentTime / this.duration\r\n }\r\n}\r\n\r\nexport default class Lenis extends EventEmitter {\r\n constructor({\r\n duration = 1.2,\r\n easing = (t) => (t === 1 ? 1 : 1 - Math.pow(2, -10 * t)), // https://easings.net/en#easeOutExpo\r\n smooth = true,\r\n smoothTouch = false,\r\n touchMultiplier = 2,\r\n direction = 'vertical', // vertical, horizontal\r\n gestureDirection = 'vertical', // vertical, horizontal, both\r\n wrapper = window,\r\n content = document.body,\r\n } = {}) {\r\n super()\r\n\r\n window.lenisVersion = version\r\n\r\n this.options = {\r\n duration,\r\n easing,\r\n smooth,\r\n smoothTouch,\r\n touchMultiplier,\r\n direction,\r\n gestureDirection,\r\n wrapper,\r\n content,\r\n }\r\n\r\n this.duration = duration\r\n this.easing = easing\r\n this.smooth = smooth\r\n this.smoothTouch = smoothTouch\r\n this.touchMultiplier = touchMultiplier\r\n this.direction = direction\r\n this.gestureDirection = gestureDirection\r\n this.wrapperNode = wrapper\r\n this.contentNode = content\r\n\r\n this.wrapperNode.addEventListener('scroll', this.onScroll)\r\n\r\n //observe wrapper node size\r\n if (this.wrapperNode === window) {\r\n this.wrapperNode.addEventListener('resize', this.onWindowResize)\r\n this.onWindowResize()\r\n } else {\r\n this.wrapperHeight = this.wrapperNode.offsetHeight\r\n this.wrapperWidth = this.wrapperNode.offsetWidth\r\n\r\n //observe wrapper node size\r\n this.wrapperObserver = new ResizeObserver(this.onWrapperResize)\r\n this.wrapperObserver.observe(this.wrapperNode)\r\n }\r\n\r\n this.contentHeight = this.contentNode.offsetHeight\r\n this.contentWidth = this.contentNode.offsetWidth\r\n\r\n //observe content node size\r\n this.contentObserver = new ResizeObserver(this.onContentResize)\r\n this.contentObserver.observe(this.contentNode)\r\n\r\n //set initial scroll position\r\n this.targetScroll =\r\n this.scroll =\r\n this.lastScroll =\r\n this.wrapperNode[this.scrollProperty]\r\n\r\n this.animate = new Animate()\r\n\r\n const platform =\r\n navigator?.userAgentData?.platform || navigator?.platform || 'unknown'\r\n\r\n // listen and normalize wheel event cross-browser\r\n this.virtualScroll = new VirtualScroll({\r\n el: this.wrapperNode,\r\n firefoxMultiplier: 50,\r\n mouseMultiplier: platform.includes('Win') ? 1 : 0.4,\r\n useKeyboard: false,\r\n touchMultiplier: this.touchMultiplier,\r\n useTouch: true,\r\n passive: false,\r\n })\r\n\r\n this.virtualScroll.on(this.onVirtualScroll)\r\n }\r\n\r\n get scrollProperty() {\r\n let property\r\n if (this.wrapperNode === window) {\r\n property = this.direction === 'horizontal' ? 'scrollX' : 'scrollY'\r\n } else {\r\n property = this.direction === 'horizontal' ? 'scrollLeft' : 'scrollTop'\r\n }\r\n return property\r\n }\r\n\r\n start() {\r\n this.stopped = false\r\n }\r\n\r\n stop() {\r\n this.stopped = true\r\n this.animate.stop()\r\n }\r\n\r\n destroy() {\r\n if (this.wrapperNode === window) {\r\n this.wrapperNode.removeEventListener('resize', this.onWindowResize)\r\n }\r\n this.wrapperNode.removeEventListener('scroll', this.onScroll)\r\n\r\n this.virtualScroll.destroy()\r\n this.wrapperObserver?.disconnect()\r\n this.contentObserver.disconnect()\r\n }\r\n\r\n onWindowResize = () => {\r\n this.wrapperWidth = window.innerWidth\r\n this.wrapperHeight = window.innerHeight\r\n }\r\n\r\n onWrapperResize = ([entry]) => {\r\n if (entry) {\r\n const rect = entry.contentRect\r\n this.wrapperWidth = rect.width\r\n this.wrapperHeight = rect.height\r\n }\r\n }\r\n\r\n onContentResize = ([entry]) => {\r\n if (entry) {\r\n const rect = entry.contentRect\r\n this.contentWidth = rect.width\r\n this.contentHeight = rect.height\r\n }\r\n }\r\n\r\n get limit() {\r\n return this.direction === 'horizontal'\r\n ? this.contentWidth - this.wrapperWidth\r\n : this.contentHeight - this.wrapperHeight\r\n }\r\n\r\n onVirtualScroll = ({ deltaY, deltaX, originalEvent: e }) => {\r\n if (e.ctrlKey) return\r\n\r\n // switch to smooth if event is touch and touch is true\r\n this.smooth = !!e.changedTouches ? this.smoothTouch : this.options.smooth\r\n\r\n if (this.stopped) {\r\n e.preventDefault()\r\n return\r\n }\r\n\r\n if (!this.smooth) return\r\n\r\n // fix wheel holding scroll https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/buttons\r\n if (e.buttons === 4) return\r\n\r\n // prevent native wheel scrolling\r\n if (this.smooth) e.preventDefault()\r\n\r\n let delta = 0\r\n if (this.gestureDirection === 'both') {\r\n delta = deltaX + deltaY\r\n } else if (this.gestureDirection === 'horizontal') {\r\n delta = deltaX\r\n } else {\r\n // vertical\r\n delta = deltaY\r\n }\r\n\r\n this.targetScroll -= delta\r\n this.targetScroll = clamp(0, this.targetScroll, this.limit)\r\n\r\n this.scrollTo(this.targetScroll)\r\n }\r\n\r\n raf(now) {\r\n const deltaTime = now - (this.now || 0)\r\n this.now = now\r\n\r\n if (this.stopped || !this.smooth) return\r\n\r\n this.lastScroll = this.scroll\r\n\r\n // where this.scroll is updated\r\n this.animate.raf(deltaTime)\r\n\r\n if (this.scroll === this.targetScroll) {\r\n // if target reached velocity should be 0\r\n this.lastScroll = this.scroll\r\n }\r\n\r\n if (this.isScrolling) {\r\n this.setScroll(this.scroll)\r\n this.notify()\r\n }\r\n\r\n this.isScrolling = this.scroll !== this.targetScroll\r\n }\r\n\r\n get velocity() {\r\n return this.scroll - this.lastScroll\r\n }\r\n\r\n setScroll(value) {\r\n this.direction === 'horizontal'\r\n ? this.wrapperNode.scrollTo(value, 0)\r\n : this.wrapperNode.scrollTo(0, value)\r\n }\r\n\r\n onScroll = (e) => {\r\n // if isScrolling false we can consider user isn't scrolling with wheel (cmd+F, keyboard or whatever). So we must scroll to value immediately\r\n if (!this.isScrolling || !this.smooth) {\r\n // where native scroll happens\r\n this.targetScroll =\r\n this.scroll =\r\n this.lastScroll =\r\n this.wrapperNode[this.scrollProperty]\r\n\r\n this.notify()\r\n }\r\n }\r\n\r\n notify() {\r\n this.emit('scroll', {\r\n scroll: this.scroll,\r\n limit: this.limit,\r\n velocity: this.velocity,\r\n direction: this.direction,\r\n progress: this.scroll / this.limit,\r\n })\r\n }\r\n\r\n scrollTo(\r\n target,\r\n {\r\n offset = 0,\r\n immediate = false,\r\n duration = this.duration,\r\n easing = this.easing,\r\n } = {}\r\n ) {\r\n if (target === undefined || target === null) return\r\n let value\r\n\r\n if (typeof target === 'number') {\r\n value = target\r\n } else if (target === 'top' || target === '#top') {\r\n value = 0\r\n } else if (target === 'bottom') {\r\n value = this.limit\r\n } else {\r\n let node\r\n\r\n if (typeof target === 'string') {\r\n // CSS selector\r\n node = document.querySelector(target)\r\n } else if (target?.nodeType) {\r\n // Node element\r\n node = target\r\n } else {\r\n return\r\n }\r\n\r\n if (!node) return\r\n let wrapperOffset = 0\r\n\r\n if (this.wrapperNode !== window) {\r\n const wrapperRect = this.wrapperNode.getBoundingClientRect()\r\n wrapperOffset =\r\n this.direction === 'horizontal' ? wrapperRect.left : wrapperRect.top\r\n }\r\n\r\n const rect = node.getBoundingClientRect()\r\n\r\n value =\r\n (this.direction === 'horizontal' ? rect.left : rect.top) +\r\n this.scroll -\r\n wrapperOffset\r\n }\r\n\r\n value += offset\r\n\r\n this.targetScroll = value\r\n\r\n if (!this.smooth || immediate) {\r\n this.setScroll(this.targetScroll)\r\n } else {\r\n this.animate.to(this, {\r\n duration,\r\n easing,\r\n scroll: this.targetScroll,\r\n })\r\n }\r\n }\r\n}\r\n","export function clamp(min, input, max) {\r\n return Math.max(min, Math.min(input, max))\r\n}\r\n\r\nexport function mapRange(in_min, in_max, input, out_min, out_max) {\r\n return ((input - in_min) * (out_max - out_min)) / (in_max - in_min) + out_min\r\n}\r\n\r\nexport function lerp(start, end, amt) {\r\n return (1 - amt) * start + amt * end\r\n}\r\n\r\nexport function truncate(value, decimals) {\r\n return parseFloat(value.toFixed(decimals))\r\n}\r\n"],"names":["_excluded","Lenis","to","target","_temp","_this","this","_ref","duration","_ref$duration","_ref$easing","easing","t","keys","fromKeys","toKeys","_extends","Object","forEach","key","currentTime","isRunning","stop","raf","deltaTime","_this2","Math","min","progress","from","_temp2","_navigator","_navigator$userAgentD","_navigator2","_this3","_ref2","_ref2$duration","_ref2$easing","pow","smooth","_ref2$smooth","smoothTouch","_ref2$smoothTouch","_ref2$touchMultiplier","touchMultiplier","_ref2$direction","direction","gestureDirection","_ref2$gestureDirectio","wrapper","_ref2$wrapper","window","content","_ref2$content","document","body","_EventEmitter","call","onWindowResize","wrapperWidth","innerWidth","wrapperHeight","innerHeight","onWrapperResize","_ref3","entry","rect","contentRect","width","height","onContentResize","_ref4","contentWidth","contentHeight","onVirtualScroll","_ref5","deltaY","deltaX","e","originalEvent","ctrlKey","changedTouches","options","stopped","preventDefault","buttons","targetScroll","max","limit","scrollTo","onScroll","isScrolling","scroll","lastScroll","wrapperNode","scrollProperty","notify","lenisVersion","contentNode","addEventListener","offsetHeight","offsetWidth","wrapperObserver","observe","contentObserver","ResizeObserver","animate","Animate","platform","navigator","userAgentData","virtualScroll","VirtualScroll","el","firefoxMultiplier","mouseMultiplier","includes","useKeyboard","useTouch","passive","on","EventEmitter","start","destroy","_this$wrapperObserver","removeEventListener","disconnect","now","setScroll","value","emit","velocity","_temp3","_ref6","_ref6$offset","offset","_ref6$immediate","immediate","_ref6$duration","node","querySelector","nodeType","wrapperOffset","wrapperRect","getBoundingClientRect","left","top","_createClass","get"],"mappings":"yqBAAA,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gF,cAEpBhF,KAAKoG,QAAQxG,GAAGI,KAAM,CACpBE,SAAAA,EACAG,OAAAA,EACAiF,OAAQtF,KAAKgF,cAjD4B,CAoD9C,EAlND6D,EAAAlJ,EAAA,CAAA,CAAAkB,IAAA,iBAAAiI,IAAA,WAOE,OALI9I,KAAKwF,cAAgB3C,OACO,eAAnB7C,KAAKwC,UAA6B,UAAY,UAE3B,eAAnBxC,KAAKwC,UAA6B,aAAe,WAG/D,GA2CD,CAAA3B,IAAA,QAAAiI,IAAA,WACE,MAA0B,oBAAdtG,UACRxC,KAAKkE,aAAelE,KAAKqD,aACzBrD,KAAKmE,cAAgBnE,KAAKuD,aAC/B,uBA6DD,WACE,OAAY+B,KAAAA,OAAStF,KAAKuF,UAC3B,KA3MgC4B,CAAAA,EAAAA"} \ No newline at end of file diff --git a/dist/lenis.modern.mjs b/dist/lenis.modern.mjs index 4321271e..e0fc56ea 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,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}; +import t from"tiny-emitter";import i from"virtual-scroll";function e(){return e=Object.assign?Object.assign.bind():function(t){for(var i=1;it)}=i,n=function(t,i){if(null==t)return{};var e,s,r={},o=Object.keys(t);for(s=0;s=0||(r[e]=t[e]);return r}(i,s);this.target=t,this.fromKeys=e({},n),this.toKeys=e({},n),this.keys=Object.keys(e({},n)),this.keys.forEach(i=>{this.fromKeys[i]=t[i]}),this.duration=r,this.easing=o,this.currentTime=0,this.isRunning=!0}stop(){this.isRunning=!1}raf(t){if(!this.isRunning)return;this.currentTime=Math.min(this.currentTime+.001*t,this.duration);const i=this.easing(this.progress);this.keys.forEach(t=>{const e=this.fromKeys[t];this.target[t]=e+(this.toKeys[t]-e)*i}),1===i&&(this.isRunning=!1)}get progress(){return this.currentTime/this.duration}}class o extends t{constructor({duration:t=1.2,easing:e=(t=>1===t?1:1-Math.pow(2,-10*t)),smooth:s=!0,smoothTouch:o=!1,touchMultiplier:n=2,direction:h="vertical",gestureDirection:l="vertical",wrapper:c=window,content:a=document.body}={}){var p,d,u;super(),this.onWindowResize=()=>{this.wrapperWidth=window.innerWidth,this.wrapperHeight=window.innerHeight},this.onWrapperResize=([t])=>{if(t){const i=t.contentRect;this.wrapperWidth=i.width,this.wrapperHeight=i.height}},this.onContentResize=([t])=>{if(t){const i=t.contentRect;this.contentWidth=i.width,this.contentHeight=i.height}},this.onVirtualScroll=({deltaY:t,deltaX:i,originalEvent:e})=>{if(e.ctrlKey)return;if(this.smooth=e.changedTouches?this.smoothTouch:this.options.smooth,this.stopped)return void e.preventDefault();if(!this.smooth)return;if(4===e.buttons)return;this.smooth&&e.preventDefault();let s=0;s="both"===this.gestureDirection?i+t:"horizontal"===this.gestureDirection?i:t,this.targetScroll-=s,this.targetScroll=Math.max(0,Math.min(this.targetScroll,this.limit)),this.scrollTo(this.targetScroll)},this.onScroll=t=>{this.isScrolling&&this.smooth||(this.targetScroll=this.scroll=this.lastScroll=this.wrapperNode[this.scrollProperty],this.notify())},window.lenisVersion="0.2.9",this.options={duration:t,easing:e,smooth:s,smoothTouch:o,touchMultiplier:n,direction:h,gestureDirection:l,wrapper:c,content:a},this.duration=t,this.easing=e,this.smooth=s,this.smoothTouch=o,this.touchMultiplier=n,this.direction=h,this.gestureDirection=l,this.wrapperNode=c,this.contentNode=a,this.wrapperNode.addEventListener("scroll",this.onScroll),this.wrapperNode===window?(this.wrapperNode.addEventListener("resize",this.onWindowResize),this.onWindowResize()):(this.wrapperHeight=this.wrapperNode.offsetHeight,this.wrapperWidth=this.wrapperNode.offsetWidth,this.wrapperObserver=new ResizeObserver(this.onWrapperResize),this.wrapperObserver.observe(this.wrapperNode)),this.contentHeight=this.contentNode.offsetHeight,this.contentWidth=this.contentNode.offsetWidth,this.contentObserver=new ResizeObserver(this.onContentResize),this.contentObserver.observe(this.contentNode),this.targetScroll=this.scroll=this.lastScroll=this.wrapperNode[this.scrollProperty],this.animate=new r;const g=(null==(p=navigator)||null==(d=p.userAgentData)?void 0:d.platform)||(null==(u=navigator)?void 0:u.platform)||"unknown";this.virtualScroll=new i({el:this.wrapperNode,firefoxMultiplier:50,mouseMultiplier:g.includes("Win")?1:.4,useKeyboard:!1,touchMultiplier:this.touchMultiplier,useTouch:!0,passive:!1}),this.virtualScroll.on(this.onVirtualScroll)}get scrollProperty(){let t;return t=this.wrapperNode===window?"horizontal"===this.direction?"scrollX":"scrollY":"horizontal"===this.direction?"scrollLeft":"scrollTop",t}start(){this.stopped=!1}stop(){this.stopped=!0,this.animate.stop()}destroy(){var t;this.wrapperNode===window&&this.wrapperNode.removeEventListener("resize",this.onWindowResize),this.wrapperNode.removeEventListener("scroll",this.onScroll),this.virtualScroll.destroy(),null==(t=this.wrapperObserver)||t.disconnect(),this.contentObserver.disconnect()}get limit(){return"horizontal"===this.direction?this.contentWidth-this.wrapperWidth:this.contentHeight-this.wrapperHeight}raf(t){const i=t-(this.now||0);this.now=t,!this.stopped&&this.smooth&&(this.lastScroll=this.scroll,this.animate.raf(i),this.scroll===this.targetScroll&&(this.lastScroll=this.scroll),this.isScrolling&&(this.setScroll(this.scroll),this.notify()),this.isScrolling=this.scroll!==this.targetScroll)}get velocity(){return this.scroll-this.lastScroll}setScroll(t){"horizontal"===this.direction?this.wrapperNode.scrollTo(t,0):this.wrapperNode.scrollTo(0,t)}notify(){this.emit("scroll",{scroll:this.scroll,limit:this.limit,velocity:this.velocity,direction:this.direction,progress:this.scroll/this.limit})}scrollTo(t,{offset:i=0,immediate:e=!1,duration:s=this.duration,easing:r=this.easing}={}){if(null==t)return;let o;if("number"==typeof t)o=t;else if("top"===t||"#top"===t)o=0;else if("bottom"===t)o=this.limit;else{let i;if("string"==typeof t)i=document.querySelector(t);else{if(null==t||!t.nodeType)return;i=t}if(!i)return;let e=0;if(this.wrapperNode!==window){const t=this.wrapperNode.getBoundingClientRect();e="horizontal"===this.direction?t.left:t.top}const s=i.getBoundingClientRect();o=("horizontal"===this.direction?s.left:s.top)+this.scroll-e}o+=i,this.targetScroll=o,!this.smooth||e?this.setScroll(this.targetScroll):this.animate.to(this,{duration:s,easing:r,scroll:this.targetScroll})}}export{o as default}; //# sourceMappingURL=lenis.modern.mjs.map diff --git a/dist/lenis.modern.mjs.map b/dist/lenis.modern.mjs.map index 3f7b44ce..1daf36e3 100644 --- a/dist/lenis.modern.mjs.map +++ b/dist/lenis.modern.mjs.map @@ -1 +1 @@ -{"version":3,"file":"lenis.modern.mjs","sources":["../src/lenis.js","../src/maths.js"],"sourcesContent":["import EventEmitter from 'tiny-emitter'\r\nimport VirtualScroll from 'virtual-scroll'\r\nimport { version } from '../package.json'\r\nimport { clamp } from './maths.js'\r\n\r\nclass Animate {\r\n to(target, { duration = 1, easing = (t) => t, ...keys } = {}) {\r\n this.target = target\r\n this.fromKeys = { ...keys }\r\n this.toKeys = { ...keys }\r\n this.keys = Object.keys({ ...keys })\r\n\r\n // get initial values\r\n this.keys.forEach((key) => {\r\n this.fromKeys[key] = target[key]\r\n })\r\n\r\n this.duration = duration\r\n this.easing = easing\r\n this.currentTime = 0\r\n this.isRunning = true\r\n }\r\n\r\n stop() {\r\n this.isRunning = false\r\n }\r\n\r\n raf(deltaTime) {\r\n if (!this.isRunning) return\r\n\r\n this.currentTime = Math.min(\r\n this.currentTime + deltaTime * 0.001,\r\n this.duration\r\n )\r\n\r\n const progress = this.easing(this.progress)\r\n\r\n this.keys.forEach((key) => {\r\n const from = this.fromKeys[key]\r\n const to = this.toKeys[key]\r\n\r\n const value = from + (to - from) * progress\r\n\r\n this.target[key] = value\r\n })\r\n\r\n if (progress === 1) {\r\n this.isRunning = false\r\n }\r\n }\r\n\r\n get progress() {\r\n return this.currentTime / this.duration\r\n }\r\n}\r\n\r\nexport default class Lenis extends EventEmitter {\r\n constructor({\r\n duration = 1.2,\r\n easing = (t) => (t === 1 ? 1 : 1 - Math.pow(2, -10 * t)), // https://easings.net/en#easeOutExpo\r\n smooth = true,\r\n smoothTouch = false,\r\n touchMultiplier = 2,\r\n direction = 'vertical',\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,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,EAC7B,GAEDL,KAAKL,SAAWA,EAChBK,KAAKJ,OAASA,EACdI,KAAKM,YAAc,EACnBN,KAAKO,WAAY,CAClB,CAEDC,OACER,KAAKO,WAAY,CAClB,CAEDE,IAAIC,GACF,IAAKV,KAAKO,UAAW,OAErBP,KAAKM,Y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UmF,EAClBtG,KAAKiG,UAAUjG,KAAKwD,cAEpBxD,KAAK4E,QAAQpF,GAAGQ,KAAM,CACpBL,WACAC,SACAkE,OAAQ9D,KAAKwD,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', // vertical, horizontal\r\n gestureDirection = 'vertical', // vertical, horizontal, both\r\n wrapper = window,\r\n content = document.body,\r\n } = {}) {\r\n super()\r\n\r\n window.lenisVersion = version\r\n\r\n this.options = {\r\n duration,\r\n easing,\r\n smooth,\r\n smoothTouch,\r\n touchMultiplier,\r\n direction,\r\n gestureDirection,\r\n wrapper,\r\n content,\r\n }\r\n\r\n this.duration = duration\r\n this.easing = easing\r\n this.smooth = smooth\r\n this.smoothTouch = smoothTouch\r\n this.touchMultiplier = touchMultiplier\r\n this.direction = direction\r\n this.gestureDirection = gestureDirection\r\n this.wrapperNode = wrapper\r\n this.contentNode = content\r\n\r\n this.wrapperNode.addEventListener('scroll', this.onScroll)\r\n\r\n //observe wrapper node size\r\n if (this.wrapperNode === window) {\r\n this.wrapperNode.addEventListener('resize', this.onWindowResize)\r\n this.onWindowResize()\r\n } else {\r\n this.wrapperHeight = this.wrapperNode.offsetHeight\r\n this.wrapperWidth = this.wrapperNode.offsetWidth\r\n\r\n //observe wrapper node size\r\n this.wrapperObserver = new ResizeObserver(this.onWrapperResize)\r\n this.wrapperObserver.observe(this.wrapperNode)\r\n }\r\n\r\n this.contentHeight = this.contentNode.offsetHeight\r\n this.contentWidth = this.contentNode.offsetWidth\r\n\r\n //observe content node size\r\n this.contentObserver = new ResizeObserver(this.onContentResize)\r\n this.contentObserver.observe(this.contentNode)\r\n\r\n //set initial scroll position\r\n this.targetScroll =\r\n this.scroll =\r\n this.lastScroll =\r\n this.wrapperNode[this.scrollProperty]\r\n\r\n this.animate = new Animate()\r\n\r\n const platform =\r\n navigator?.userAgentData?.platform || navigator?.platform || 'unknown'\r\n\r\n // listen and normalize wheel event cross-browser\r\n this.virtualScroll = new VirtualScroll({\r\n el: this.wrapperNode,\r\n firefoxMultiplier: 50,\r\n mouseMultiplier: platform.includes('Win') ? 1 : 0.4,\r\n useKeyboard: false,\r\n touchMultiplier: this.touchMultiplier,\r\n useTouch: true,\r\n passive: false,\r\n })\r\n\r\n this.virtualScroll.on(this.onVirtualScroll)\r\n }\r\n\r\n get scrollProperty() {\r\n let property\r\n if (this.wrapperNode === window) {\r\n property = this.direction === 'horizontal' ? 'scrollX' : 'scrollY'\r\n } else {\r\n property = this.direction === 'horizontal' ? 'scrollLeft' : 'scrollTop'\r\n }\r\n return property\r\n }\r\n\r\n start() {\r\n this.stopped = false\r\n }\r\n\r\n stop() {\r\n this.stopped = true\r\n this.animate.stop()\r\n }\r\n\r\n destroy() {\r\n if (this.wrapperNode === window) {\r\n this.wrapperNode.removeEventListener('resize', this.onWindowResize)\r\n }\r\n this.wrapperNode.removeEventListener('scroll', this.onScroll)\r\n\r\n this.virtualScroll.destroy()\r\n this.wrapperObserver?.disconnect()\r\n this.contentObserver.disconnect()\r\n }\r\n\r\n onWindowResize = () => {\r\n this.wrapperWidth = window.innerWidth\r\n this.wrapperHeight = window.innerHeight\r\n }\r\n\r\n onWrapperResize = ([entry]) => {\r\n if (entry) {\r\n const rect = entry.contentRect\r\n this.wrapperWidth = rect.width\r\n this.wrapperHeight = rect.height\r\n }\r\n }\r\n\r\n onContentResize = ([entry]) => {\r\n if (entry) {\r\n const rect = entry.contentRect\r\n this.contentWidth = rect.width\r\n this.contentHeight = rect.height\r\n }\r\n }\r\n\r\n get limit() {\r\n return this.direction === 'horizontal'\r\n ? this.contentWidth - this.wrapperWidth\r\n : this.contentHeight - this.wrapperHeight\r\n }\r\n\r\n onVirtualScroll = ({ deltaY, deltaX, originalEvent: e }) => {\r\n if (e.ctrlKey) return\r\n\r\n // switch to smooth if event is touch and touch is true\r\n this.smooth = !!e.changedTouches ? this.smoothTouch : this.options.smooth\r\n\r\n if (this.stopped) {\r\n e.preventDefault()\r\n return\r\n }\r\n\r\n if (!this.smooth) return\r\n\r\n // fix wheel holding scroll https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/buttons\r\n if (e.buttons === 4) return\r\n\r\n // prevent native wheel scrolling\r\n if (this.smooth) e.preventDefault()\r\n\r\n let delta = 0\r\n if (this.gestureDirection === 'both') {\r\n delta = deltaX + deltaY\r\n } else if (this.gestureDirection === 'horizontal') {\r\n delta = deltaX\r\n } else {\r\n // vertical\r\n delta = deltaY\r\n }\r\n\r\n this.targetScroll -= delta\r\n this.targetScroll = clamp(0, this.targetScroll, this.limit)\r\n\r\n this.scrollTo(this.targetScroll)\r\n }\r\n\r\n raf(now) {\r\n const deltaTime = now - (this.now || 0)\r\n this.now = now\r\n\r\n if (this.stopped || !this.smooth) return\r\n\r\n this.lastScroll = this.scroll\r\n\r\n // where this.scroll is updated\r\n this.animate.raf(deltaTime)\r\n\r\n if (this.scroll === this.targetScroll) {\r\n // if target reached velocity should be 0\r\n this.lastScroll = this.scroll\r\n }\r\n\r\n if (this.isScrolling) {\r\n this.setScroll(this.scroll)\r\n this.notify()\r\n }\r\n\r\n this.isScrolling = this.scroll !== this.targetScroll\r\n }\r\n\r\n get velocity() {\r\n return this.scroll - this.lastScroll\r\n }\r\n\r\n setScroll(value) {\r\n this.direction === 'horizontal'\r\n ? this.wrapperNode.scrollTo(value, 0)\r\n : this.wrapperNode.scrollTo(0, value)\r\n }\r\n\r\n onScroll = (e) => {\r\n // if isScrolling false we can consider user isn't scrolling with wheel (cmd+F, keyboard or whatever). So we must scroll to value immediately\r\n if (!this.isScrolling || !this.smooth) {\r\n // where native scroll happens\r\n this.targetScroll =\r\n this.scroll =\r\n this.lastScroll =\r\n this.wrapperNode[this.scrollProperty]\r\n\r\n this.notify()\r\n }\r\n }\r\n\r\n notify() {\r\n this.emit('scroll', {\r\n scroll: this.scroll,\r\n limit: this.limit,\r\n velocity: this.velocity,\r\n direction: this.direction,\r\n progress: this.scroll / this.limit,\r\n })\r\n }\r\n\r\n scrollTo(\r\n target,\r\n {\r\n offset = 0,\r\n immediate = false,\r\n duration = this.duration,\r\n easing = this.easing,\r\n } = {}\r\n ) {\r\n if (target === undefined || target === null) return\r\n let value\r\n\r\n if (typeof target === 'number') {\r\n value = target\r\n } else if (target === 'top' || target === '#top') {\r\n value = 0\r\n } else if (target === 'bottom') {\r\n value = this.limit\r\n } else {\r\n let node\r\n\r\n if (typeof target === 'string') {\r\n // CSS selector\r\n node = document.querySelector(target)\r\n } else if (target?.nodeType) {\r\n // Node element\r\n node = target\r\n } else {\r\n return\r\n }\r\n\r\n if (!node) return\r\n let wrapperOffset = 0\r\n\r\n if (this.wrapperNode !== window) {\r\n const wrapperRect = this.wrapperNode.getBoundingClientRect()\r\n wrapperOffset =\r\n this.direction === 'horizontal' ? wrapperRect.left : wrapperRect.top\r\n }\r\n\r\n const rect = node.getBoundingClientRect()\r\n\r\n value =\r\n (this.direction === 'horizontal' ? rect.left : rect.top) +\r\n this.scroll -\r\n wrapperOffset\r\n }\r\n\r\n value += offset\r\n\r\n this.targetScroll = value\r\n\r\n if (!this.smooth || immediate) {\r\n this.setScroll(this.targetScroll)\r\n } else {\r\n this.animate.to(this, {\r\n duration,\r\n easing,\r\n scroll: this.targetScroll,\r\n })\r\n }\r\n }\r\n}\r\n","export function clamp(min, input, max) {\r\n return Math.max(min, Math.min(input, max))\r\n}\r\n\r\nexport function mapRange(in_min, in_max, input, out_min, out_max) {\r\n return ((input - in_min) * (out_max - out_min)) / (in_max - in_min) + out_min\r\n}\r\n\r\nexport function lerp(start, end, amt) {\r\n return (1 - amt) * start + amt * end\r\n}\r\n\r\nexport function truncate(value, decimals) {\r\n return parseFloat(value.toFixed(decimals))\r\n}\r\n"],"names":["_excluded","Animate","to","target","_ref","duration","easing","t","keys","_objectWithoutPropertiesLoose","this","fromKeys","_extends","toKeys","Object","forEach","key","currentTime","isRunning","stop","raf","deltaTime","Math","min","progress","from","value","EventEmitter","constructor","pow","smooth","smoothTouch","touchMultiplier","direction","gestureDirection","wrapper","window","content","document","body","_navigator","_navigator$userAgentD","_navigator2","super","onWindowResize","wrapperWidth","innerWidth","wrapperHeight","innerHeight","onWrapperResize","entry","rect","contentRect","width","height","onContentResize","contentWidth","contentHeight","onVirtualScroll","deltaY","deltaX","originalEvent","e","ctrlKey","changedTouches","options","stopped","preventDefault","buttons","delta","targetScroll","max","limit","scrollTo","onScroll","isScrolling","scroll","lastScroll","wrapperNode","scrollProperty","notify","lenisVersion","contentNode","addEventListener","offsetHeight","offsetWidth","wrapperObserver","observe","contentObserver","ResizeObserver","animate","platform","navigator","userAgentData","virtualScroll","VirtualScroll","el","firefoxMultiplier","mouseMultiplier","includes","useKeyboard","useTouch","passive","on","property","start","destroy","_this$wrapperObserver","removeEventListener","disconnect","now","setScroll","emit","velocity","offset","immediate","node","querySelector","nodeType","wrapperOffset","getBoundingClientRect","wrapperRect","left","top"],"mappings":"8RAAA,MAAAA,EAAA,CAAA,WAAA,UAKA,MAAMC,EACJC,GAAGC,EAAQC,EAA+C,CAAxD,GAAS,IAAAC,SAAEA,EAAW,EAAbC,OAAgBA,EAAUC,IAAMA,IAAmBH,EAAbI,oIAC/CC,CAAAL,EAAAJ,GAAAU,KAAKP,OAASA,EACdO,KAAKC,SAALC,EAAA,CAAA,EAAqBJ,GACrBE,KAAKG,OAAcL,EAAAA,CAAAA,EAAAA,GACnBE,KAAKF,KAAOM,OAAON,KAAPI,EAAA,GAAiBJ,IAG7BE,KAAKF,KAAKO,QAASC,IACjBN,KAAKC,SAASK,GAAOb,EAAOa,KAG9BN,KAAKL,SAAWA,EAChBK,KAAKJ,OAASA,EACdI,KAAKO,YAAc,EACnBP,KAAKQ,WAAY,CAClB,CAEDC,OACET,KAAKQ,WAAY,CAClB,CAEDE,IAAIC,GACF,IAAKX,KAAKQ,UAAW,OAErBR,KAAKO,YAAcK,KAAKC,IACtBb,KAAKO,YAA0B,KAAZI,EACnBX,KAAKL,UAGP,MAAMmB,EAAWd,KAAKJ,OAAOI,KAAKc,UAElCd,KAAKF,KAAKO,QAASC,IACjB,QAAaN,KAAKC,SAASK,GAK3BN,KAAKP,OAAOa,GAFES,GAFHf,KAAKG,OAAOG,GAEIS,GAAQD,CAEhBE,GAGJ,IAAbF,IACFd,KAAKQ,WAAY,EAEpB,CAEWM,eACV,OAAOd,KAAKO,YAAcP,KAAKL,QAChC,EAGY,gBAAoBsB,EACjCC,aAAYvB,SACVA,EAAW,IADDC,OAEVA,EAAUC,IAAa,I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js index d65f82ad..af3a682a 100644 --- a/dist/lenis.umd.js +++ b/dist/lenis.umd.js @@ -1,3 +1,3 @@ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("tiny-emitter"),require("virtual-scroll")):"function"==typeof define&&define.amd?define(["tiny-emitter","virtual-scroll"],e):(t||self).lenis=e(t.tinyEmitter,t.virtualScroll)}(this,function(t,e){function 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)}); +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("tiny-emitter"),require("virtual-scroll")):"function"==typeof define&&define.amd?define(["tiny-emitter","virtual-scroll"],e):(t||self).lenis=e(t.tinyEmitter,t.virtualScroll)}(this,function(t,e){function i(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var o=/*#__PURE__*/i(t),r=/*#__PURE__*/i(e);function n(t,e){for(var i=0;i=0||(r[i]=t[i]);return r}(o,a);this.target=t,this.fromKeys=l({},h),this.toKeys=l({},h),this.keys=Object.keys(l({},h)),this.keys.forEach(function(e){i.fromKeys[e]=t[e]}),this.duration=n,this.easing=c,this.currentTime=0,this.isRunning=!0},e.stop=function(){this.isRunning=!1},e.raf=function(t){var e=this;if(this.isRunning){this.currentTime=Math.min(this.currentTime+.001*t,this.duration);var i=this.easing(this.progress);this.keys.forEach(function(t){var o=e.fromKeys[t];e.target[t]=o+(e.toKeys[t]-o)*i}),1===i&&(this.isRunning=!1)}},s(t,[{key:"progress",get:function(){return this.currentTime/this.duration}}]),t}();/*#__PURE__*/ +return function(t){var e,i;function o(e){var i,o,n,s,l=void 0===e?{}:e,c=l.duration,a=void 0===c?1.2:c,u=l.easing,p=void 0===u?function(t){return 1===t?1:1-Math.pow(2,-10*t)}:u,d=l.smooth,f=void 0===d||d,v=l.smoothTouch,g=void 0!==v&&v,w=l.touchMultiplier,y=void 0===w?2:w,m=l.direction,b=void 0===m?"vertical":m,S=l.gestureDirection,N=void 0===S?"vertical":S,O=l.wrapper,z=void 0===O?window:O,R=l.content,T=void 0===R?document.body:R;(s=t.call(this)||this).onWindowResize=function(){s.wrapperWidth=window.innerWidth,s.wrapperHeight=window.innerHeight},s.onWrapperResize=function(t){var e=t[0];if(e){var i=e.contentRect;s.wrapperWidth=i.width,s.wrapperHeight=i.height}},s.onContentResize=function(t){var e=t[0];if(e){var i=e.contentRect;s.contentWidth=i.width,s.contentHeight=i.height}},s.onVirtualScroll=function(t){var e=t.deltaY,i=t.deltaX,o=t.originalEvent;o.ctrlKey||(s.smooth=o.changedTouches?s.smoothTouch:s.options.smooth,s.stopped?o.preventDefault():s.smooth&&4!==o.buttons&&(s.smooth&&o.preventDefault(),s.targetScroll-="both"===s.gestureDirection?i+e:"horizontal"===s.gestureDirection?i:e,s.targetScroll=Math.max(0,Math.min(s.targetScroll,s.limit)),s.scrollTo(s.targetScroll)))},s.onScroll=function(t){s.isScrolling&&s.smooth||(s.targetScroll=s.scroll=s.lastScroll=s.wrapperNode[s.scrollProperty],s.notify())},window.lenisVersion="0.2.9",s.options={duration:a,easing:p,smooth:f,smoothTouch:g,touchMultiplier:y,direction:b,gestureDirection:N,wrapper:z,content:T},s.duration=a,s.easing=p,s.smooth=f,s.smoothTouch=g,s.touchMultiplier=y,s.direction=b,s.gestureDirection=N,s.wrapperNode=z,s.contentNode=T,s.wrapperNode.addEventListener("scroll",s.onScroll),s.wrapperNode===window?(s.wrapperNode.addEventListener("resize",s.onWindowResize),s.onWindowResize()):(s.wrapperHeight=s.wrapperNode.offsetHeight,s.wrapperWidth=s.wrapperNode.offsetWidth,s.wrapperObserver=new ResizeObserver(s.onWrapperResize),s.wrapperObserver.observe(s.wrapperNode)),s.contentHeight=s.contentNode.offsetHeight,s.contentWidth=s.contentNode.offsetWidth,s.contentObserver=new ResizeObserver(s.onContentResize),s.contentObserver.observe(s.contentNode),s.targetScroll=s.scroll=s.lastScroll=s.wrapperNode[s.scrollProperty],s.animate=new h;var W=(null==(i=navigator)||null==(o=i.userAgentData)?void 0:o.platform)||(null==(n=navigator)?void 0:n.platform)||"unknown";return s.virtualScroll=new r.default({el:s.wrapperNode,firefoxMultiplier:50,mouseMultiplier:W.includes("Win")?1:.4,useKeyboard:!1,touchMultiplier:s.touchMultiplier,useTouch:!0,passive:!1}),s.virtualScroll.on(s.onVirtualScroll),s}i=t,(e=o).prototype=Object.create(i.prototype),e.prototype.constructor=e,c(e,i);var n=o.prototype;return n.start=function(){this.stopped=!1},n.stop=function(){this.stopped=!0,this.animate.stop()},n.destroy=function(){var t;this.wrapperNode===window&&this.wrapperNode.removeEventListener("resize",this.onWindowResize),this.wrapperNode.removeEventListener("scroll",this.onScroll),this.virtualScroll.destroy(),null==(t=this.wrapperObserver)||t.disconnect(),this.contentObserver.disconnect()},n.raf=function(t){var e=t-(this.now||0);this.now=t,!this.stopped&&this.smooth&&(this.lastScroll=this.scroll,this.animate.raf(e),this.scroll===this.targetScroll&&(this.lastScroll=this.scroll),this.isScrolling&&(this.setScroll(this.scroll),this.notify()),this.isScrolling=this.scroll!==this.targetScroll)},n.setScroll=function(t){"horizontal"===this.direction?this.wrapperNode.scrollTo(t,0):this.wrapperNode.scrollTo(0,t)},n.notify=function(){this.emit("scroll",{scroll:this.scroll,limit:this.limit,velocity:this.velocity,direction:this.direction,progress:this.scroll/this.limit})},n.scrollTo=function(t,e){var i=void 0===e?{}:e,o=i.offset,r=void 0===o?0:o,n=i.immediate,s=void 0!==n&&n,l=i.duration,c=void 0===l?this.duration:l,a=i.easing,h=void 0===a?this.easing:a;if(null!=t){var u;if("number"==typeof t)u=t;else if("top"===t||"#top"===t)u=0;else if("bottom"===t)u=this.limit;else{var p;if("string"==typeof t)p=document.querySelector(t);else{if(null==t||!t.nodeType)return;p=t}if(!p)return;var d=0;if(this.wrapperNode!==window){var f=this.wrapperNode.getBoundingClientRect();d="horizontal"===this.direction?f.left:f.top}var v=p.getBoundingClientRect();u=("horizontal"===this.direction?v.left:v.top)+this.scroll-d}this.targetScroll=u+=r,!this.smooth||s?this.setScroll(this.targetScroll):this.animate.to(this,{duration:c,easing:h,scroll:this.targetScroll})}},s(o,[{key:"scrollProperty",get:function(){return this.wrapperNode===window?"horizontal"===this.direction?"scrollX":"scrollY":"horizontal"===this.direction?"scrollLeft":"scrollTop"}},{key:"limit",get:function(){return"horizontal"===this.direction?this.contentWidth-this.wrapperWidth:this.contentHeight-this.wrapperHeight}},{key:"velocity",get:function(){return this.scroll-this.lastScroll}}]),o}(o.default)}); //# sourceMappingURL=lenis.umd.js.map diff --git a/dist/lenis.umd.js.map b/dist/lenis.umd.js.map index 0ab4ab3e..19b70ad3 100644 --- a/dist/lenis.umd.js.map +++ b/dist/lenis.umd.js.map @@ -1 +1 @@ -{"version":3,"file":"lenis.umd.js","sources":["../src/lenis.js","../src/maths.js"],"sourcesContent":["import EventEmitter from 'tiny-emitter'\r\nimport VirtualScroll from 'virtual-scroll'\r\nimport { version } from '../package.json'\r\nimport { clamp } from './maths.js'\r\n\r\nclass Animate {\r\n to(target, { duration = 1, easing = (t) => t, ...keys } = {}) {\r\n this.target = target\r\n this.fromKeys = { ...keys }\r\n this.toKeys = { ...keys }\r\n this.keys = Object.keys({ ...keys })\r\n\r\n // get initial values\r\n this.keys.forEach((key) => {\r\n this.fromKeys[key] = target[key]\r\n })\r\n\r\n this.duration = duration\r\n this.easing = easing\r\n this.currentTime = 0\r\n this.isRunning = true\r\n }\r\n\r\n stop() {\r\n this.isRunning = false\r\n }\r\n\r\n raf(deltaTime) {\r\n if (!this.isRunning) return\r\n\r\n this.currentTime = Math.min(\r\n this.currentTime + deltaTime * 0.001,\r\n this.duration\r\n )\r\n\r\n const progress = this.easing(this.progress)\r\n\r\n this.keys.forEach((key) => {\r\n const from = this.fromKeys[key]\r\n const to = this.toKeys[key]\r\n\r\n const value = from + (to - from) * progress\r\n\r\n this.target[key] = value\r\n })\r\n\r\n if (progress === 1) {\r\n this.isRunning = false\r\n }\r\n }\r\n\r\n get progress() {\r\n return this.currentTime / this.duration\r\n }\r\n}\r\n\r\nexport default class Lenis extends EventEmitter {\r\n constructor({\r\n duration = 1.2,\r\n easing = (t) => (t === 1 ? 1 : 1 - Math.pow(2, -10 * t)), // https://easings.net/en#easeOutExpo\r\n smooth = true,\r\n smoothTouch = false,\r\n touchMultiplier = 2,\r\n direction = 'vertical',\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":"8iCAAA,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,CAqBtB,2BAED,WACE,OAAYD,KAAAA,YAAcf,KAAKG,QAChC,KAGkBP,CAAAA;2BACnB,SASQA,EAAA6B,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AAAA,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 +{"version":3,"file":"lenis.umd.js","sources":["../src/lenis.js","../src/maths.js"],"sourcesContent":["import EventEmitter from 'tiny-emitter'\r\nimport VirtualScroll from 'virtual-scroll'\r\nimport { version } from '../package.json'\r\nimport { clamp } from './maths.js'\r\n\r\nclass Animate {\r\n to(target, { duration = 1, easing = (t) => t, ...keys } = {}) {\r\n this.target = target\r\n this.fromKeys = { ...keys }\r\n this.toKeys = { ...keys }\r\n this.keys = Object.keys({ ...keys })\r\n\r\n // get initial values\r\n this.keys.forEach((key) => {\r\n this.fromKeys[key] = target[key]\r\n })\r\n\r\n this.duration = duration\r\n this.easing = easing\r\n this.currentTime = 0\r\n this.isRunning = true\r\n }\r\n\r\n stop() {\r\n this.isRunning = false\r\n }\r\n\r\n raf(deltaTime) {\r\n if (!this.isRunning) return\r\n\r\n this.currentTime = Math.min(\r\n this.currentTime + deltaTime * 0.001,\r\n this.duration\r\n )\r\n\r\n const progress = this.easing(this.progress)\r\n\r\n this.keys.forEach((key) => {\r\n const from = this.fromKeys[key]\r\n const to = this.toKeys[key]\r\n\r\n const value = from + (to - from) * progress\r\n\r\n this.target[key] = value\r\n })\r\n\r\n if (progress === 1) {\r\n this.isRunning = false\r\n }\r\n }\r\n\r\n get progress() {\r\n return this.currentTime / this.duration\r\n }\r\n}\r\n\r\nexport default class Lenis extends EventEmitter {\r\n constructor({\r\n duration = 1.2,\r\n easing = (t) => (t === 1 ? 1 : 1 - Math.pow(2, -10 * t)), // https://easings.net/en#easeOutExpo\r\n smooth = true,\r\n smoothTouch = false,\r\n touchMultiplier = 2,\r\n direction = 'vertical', // vertical, horizontal\r\n gestureDirection = 'vertical', // vertical, horizontal, both\r\n wrapper = window,\r\n content = document.body,\r\n } = {}) {\r\n super()\r\n\r\n window.lenisVersion = version\r\n\r\n this.options = {\r\n duration,\r\n easing,\r\n smooth,\r\n smoothTouch,\r\n touchMultiplier,\r\n direction,\r\n gestureDirection,\r\n wrapper,\r\n content,\r\n }\r\n\r\n this.duration = duration\r\n this.easing = easing\r\n this.smooth = smooth\r\n this.smoothTouch = smoothTouch\r\n this.touchMultiplier = touchMultiplier\r\n this.direction = direction\r\n this.gestureDirection = gestureDirection\r\n this.wrapperNode = wrapper\r\n this.contentNode = content\r\n\r\n this.wrapperNode.addEventListener('scroll', this.onScroll)\r\n\r\n //observe wrapper node size\r\n if (this.wrapperNode === window) {\r\n this.wrapperNode.addEventListener('resize', this.onWindowResize)\r\n this.onWindowResize()\r\n } else {\r\n this.wrapperHeight = this.wrapperNode.offsetHeight\r\n this.wrapperWidth = this.wrapperNode.offsetWidth\r\n\r\n //observe wrapper node size\r\n this.wrapperObserver = new ResizeObserver(this.onWrapperResize)\r\n this.wrapperObserver.observe(this.wrapperNode)\r\n }\r\n\r\n this.contentHeight = this.contentNode.offsetHeight\r\n this.contentWidth = this.contentNode.offsetWidth\r\n\r\n //observe content node size\r\n this.contentObserver = new ResizeObserver(this.onContentResize)\r\n this.contentObserver.observe(this.contentNode)\r\n\r\n //set initial scroll position\r\n this.targetScroll =\r\n this.scroll =\r\n this.lastScroll =\r\n this.wrapperNode[this.scrollProperty]\r\n\r\n this.animate = new Animate()\r\n\r\n const platform =\r\n navigator?.userAgentData?.platform || navigator?.platform || 'unknown'\r\n\r\n // listen and normalize wheel event cross-browser\r\n this.virtualScroll = new VirtualScroll({\r\n el: this.wrapperNode,\r\n firefoxMultiplier: 50,\r\n mouseMultiplier: platform.includes('Win') ? 1 : 0.4,\r\n useKeyboard: false,\r\n touchMultiplier: this.touchMultiplier,\r\n useTouch: true,\r\n passive: false,\r\n })\r\n\r\n this.virtualScroll.on(this.onVirtualScroll)\r\n }\r\n\r\n get scrollProperty() {\r\n let property\r\n if (this.wrapperNode === window) {\r\n property = this.direction === 'horizontal' ? 'scrollX' : 'scrollY'\r\n } else {\r\n property = this.direction === 'horizontal' ? 'scrollLeft' : 'scrollTop'\r\n }\r\n return property\r\n }\r\n\r\n start() {\r\n this.stopped = false\r\n }\r\n\r\n stop() {\r\n this.stopped = true\r\n this.animate.stop()\r\n }\r\n\r\n destroy() {\r\n if (this.wrapperNode === window) {\r\n this.wrapperNode.removeEventListener('resize', this.onWindowResize)\r\n }\r\n this.wrapperNode.removeEventListener('scroll', this.onScroll)\r\n\r\n this.virtualScroll.destroy()\r\n this.wrapperObserver?.disconnect()\r\n this.contentObserver.disconnect()\r\n }\r\n\r\n onWindowResize = () => {\r\n this.wrapperWidth = window.innerWidth\r\n this.wrapperHeight = window.innerHeight\r\n }\r\n\r\n onWrapperResize = ([entry]) => {\r\n if (entry) {\r\n const rect = entry.contentRect\r\n this.wrapperWidth = rect.width\r\n this.wrapperHeight = rect.height\r\n }\r\n }\r\n\r\n onContentResize = ([entry]) => {\r\n if (entry) {\r\n const rect = entry.contentRect\r\n this.contentWidth = rect.width\r\n this.contentHeight = rect.height\r\n }\r\n }\r\n\r\n get limit() {\r\n return this.direction === 'horizontal'\r\n ? this.contentWidth - this.wrapperWidth\r\n : this.contentHeight - this.wrapperHeight\r\n }\r\n\r\n onVirtualScroll = ({ deltaY, deltaX, originalEvent: e }) => {\r\n if (e.ctrlKey) return\r\n\r\n // switch to smooth if event is touch and touch is true\r\n this.smooth = !!e.changedTouches ? this.smoothTouch : this.options.smooth\r\n\r\n if (this.stopped) {\r\n e.preventDefault()\r\n return\r\n }\r\n\r\n if (!this.smooth) return\r\n\r\n // fix wheel holding scroll https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/buttons\r\n if (e.buttons === 4) return\r\n\r\n // prevent native wheel scrolling\r\n if (this.smooth) e.preventDefault()\r\n\r\n let delta = 0\r\n if (this.gestureDirection === 'both') {\r\n delta = deltaX + deltaY\r\n } else if (this.gestureDirection === 'horizontal') {\r\n delta = deltaX\r\n } else {\r\n // vertical\r\n delta = deltaY\r\n }\r\n\r\n this.targetScroll -= delta\r\n this.targetScroll = clamp(0, this.targetScroll, this.limit)\r\n\r\n this.scrollTo(this.targetScroll)\r\n }\r\n\r\n raf(now) {\r\n const deltaTime = now - (this.now || 0)\r\n this.now = now\r\n\r\n if (this.stopped || !this.smooth) return\r\n\r\n this.lastScroll = this.scroll\r\n\r\n // where this.scroll is updated\r\n this.animate.raf(deltaTime)\r\n\r\n if (this.scroll === this.targetScroll) {\r\n // if target reached velocity should be 0\r\n this.lastScroll = this.scroll\r\n }\r\n\r\n if (this.isScrolling) {\r\n this.setScroll(this.scroll)\r\n this.notify()\r\n }\r\n\r\n this.isScrolling = this.scroll !== this.targetScroll\r\n }\r\n\r\n get velocity() {\r\n return this.scroll - this.lastScroll\r\n }\r\n\r\n setScroll(value) {\r\n this.direction === 'horizontal'\r\n ? this.wrapperNode.scrollTo(value, 0)\r\n : this.wrapperNode.scrollTo(0, value)\r\n }\r\n\r\n onScroll = (e) => {\r\n // if isScrolling false we can consider user isn't scrolling with wheel (cmd+F, keyboard or whatever). So we must scroll to value immediately\r\n if (!this.isScrolling || !this.smooth) {\r\n // where native scroll happens\r\n this.targetScroll =\r\n this.scroll =\r\n this.lastScroll =\r\n this.wrapperNode[this.scrollProperty]\r\n\r\n this.notify()\r\n }\r\n }\r\n\r\n notify() {\r\n this.emit('scroll', {\r\n scroll: this.scroll,\r\n limit: this.limit,\r\n velocity: this.velocity,\r\n direction: this.direction,\r\n progress: this.scroll / this.limit,\r\n })\r\n }\r\n\r\n scrollTo(\r\n target,\r\n {\r\n offset = 0,\r\n immediate = false,\r\n duration = this.duration,\r\n easing = this.easing,\r\n } = {}\r\n ) {\r\n if (target === undefined || target === null) return\r\n let value\r\n\r\n if (typeof target === 'number') {\r\n value = target\r\n } else if (target === 'top' || target === '#top') {\r\n value = 0\r\n } else if (target === 'bottom') {\r\n value = this.limit\r\n } else {\r\n let node\r\n\r\n if (typeof target === 'string') {\r\n // CSS selector\r\n node = document.querySelector(target)\r\n } else if (target?.nodeType) {\r\n // Node element\r\n node = target\r\n } else {\r\n return\r\n }\r\n\r\n if (!node) return\r\n let wrapperOffset = 0\r\n\r\n if (this.wrapperNode !== window) {\r\n const wrapperRect = this.wrapperNode.getBoundingClientRect()\r\n wrapperOffset =\r\n this.direction === 'horizontal' ? wrapperRect.left : wrapperRect.top\r\n }\r\n\r\n const rect = node.getBoundingClientRect()\r\n\r\n value =\r\n (this.direction === 'horizontal' ? rect.left : rect.top) +\r\n this.scroll -\r\n wrapperOffset\r\n }\r\n\r\n value += offset\r\n\r\n this.targetScroll = value\r\n\r\n if (!this.smooth || immediate) {\r\n this.setScroll(this.targetScroll)\r\n } else {\r\n this.animate.to(this, {\r\n duration,\r\n easing,\r\n scroll: this.targetScroll,\r\n })\r\n }\r\n }\r\n}\r\n","export function clamp(min, input, max) {\r\n return Math.max(min, Math.min(input, max))\r\n}\r\n\r\nexport function mapRange(in_min, in_max, input, out_min, out_max) {\r\n return ((input - in_min) * (out_max - out_min)) / (in_max - in_min) + out_min\r\n}\r\n\r\nexport function lerp(start, end, amt) {\r\n return (1 - amt) * start + amt * end\r\n}\r\n\r\nexport function truncate(value, decimals) {\r\n return parseFloat(value.toFixed(decimals))\r\n}\r\n"],"names":["_excluded","Lenis","to","target","_temp","_this","this","_ref","duration","_ref$duration","_ref$easing","easing","t","keys","fromKeys","toKeys","_extends","Object","forEach","key","currentTime","isRunning","stop","raf","deltaTime","_this2","Math","min","progress","from","_temp2","_navigator","_navigator$userAgentD","_navigator2","_this3","_ref2","_ref2$duration","_ref2$easing","pow","smooth","_ref2$smooth","smoothTouch","_ref2$smoothTouch","_ref2$touchMultiplier","touchMultiplier","_ref2$direction","direction","gestureDirection","_ref2$gestureDirectio","wrapper","_ref2$wrapper","window","content","_ref2$content","document","body","_EventEmitter","call","onWindowResize","wrapperWidth","innerWidth","wrapperHeight","innerHeight","onWrapperResize","_ref3","entry","rect","contentRect","width","height","onContentResize","_ref4","contentWidth","contentHeight","onVirtualScroll","_ref5","deltaY","deltaX","e","originalEvent","ctrlKey","changedTouches","options","stopped","preventDefault","buttons","targetScroll","max","limit","scrollTo","onScroll","isScrolling","scroll","lastScroll","wrapperNode","scrollProperty","notify","lenisVersion","contentNode","addEventListener","offsetHeight","offsetWidth","wrapperObserver","observe","contentObserver","ResizeObserver","animate","Animate","platform","navigator","userAgentData","virtualScroll","VirtualScroll","el","firefoxMultiplier","mouseMultiplier","includes","useKeyboard","useTouch","passive","on","EventEmitter","start","destroy","_this$wrapperObserver","removeEventListener","disconnect","now","setScroll","value","emit","velocity","_temp3","_ref6","_ref6$offset","offset","_ref6$immediate","immediate","_ref6$duration","node","querySelector","nodeType","wrapperOffset","wrapperRect","getBoundingClientRect","left","top","_createClass","get"],"mappings":"8iCAAA,IAAAA,EAAA,CAAA,WAAA,oEAwDqBC,SAlDnBC,GAAA,SAAGC,EAA2DC,GAAA,IAAAC,EAAAC,KAAAC,OAAA,IAAAH,EAAJ,CAAA,EAA7CI,EAAAA,EAAAA,EAAAA,SAAAA,aAAW,EAAsCC,EAAAC,EAAAH,EAAnCI,OAAAA,aAAS,SAACC,GAAMA,OAAAA,CAAP,EAAaC,EAAAA,0IAC/CP,KAAKH,OAASA,EACdG,KAAKQ,cAAgBD,GACrBP,KAAKS,OAALC,EAAA,CAAA,EAAmBH,GACnBP,KAAKO,KAAOI,OAAOJ,UAAUA,IAG7BP,KAAKO,KAAKK,QAAQ,SAACC,GACjBd,EAAKS,SAASK,GAAOhB,EAAOgB,EAC7B,GAEDb,KAAKE,SAAWA,EAChBF,KAAKK,OAASA,EACdL,KAAKc,YAAc,EAC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package.json index bb88b703..8d653bc8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@studio-freight/lenis", - "version": "0.2.8", + "version": "0.2.9", "description": "Lenis is a smooth scroll library to normalize the scrolling experience across devices", "files": [ "dist"