diff --git a/bundled/lenis.js b/bundled/lenis.js index 15bf516f..b6c8c2d8 100644 --- a/bundled/lenis.js +++ b/bundled/lenis.js @@ -1,2 +1,2 @@ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t||self)["'Lenis'"]=e()}(this,function(){function t(t,e){for(var i=0;i1,hasPointer:!!window.navigator.msPointerEnabled,hasKeyDown:"onkeydown"in document,isFirefox:navigator.userAgent.indexOf("Firefox")>-1}),i(this,l)[l]=Object.assign({mouseMultiplier:1,touchMultiplier:2,firefoxMultiplier:15,keyStep:120,preventTouch:!1,unpreventTouchClass:"vs-touchmove-allowed",useKeyboard:!0,useTouch:!0},t),i(this,a)[a]=new n,i(this,c)[c]={y:0,x:0,deltaX:0,deltaY:0},i(this,u)[u]={x:null,y:null},i(this,d)[d]=null,void 0!==i(this,l)[l].passive&&(this.listenerOptions={passive:i(this,l)[l].passive})}var e=t.prototype;return e._notify=function(t){var e=i(this,c)[c];e.x+=e.deltaX,e.y+=e.deltaY,i(this,a)[a].emit(s,{x:e.x,y:e.y,deltaX:e.deltaX,deltaY:e.deltaY,originalEvent:t})},e._bind=function(){r.hasWheelEvent&&i(this,h)[h].addEventListener("wheel",this._onWheel,this.listenerOptions),r.hasMouseWheelEvent&&i(this,h)[h].addEventListener("mousewheel",this._onMouseWheel,this.listenerOptions),r.hasTouch&&i(this,l)[l].useTouch&&(i(this,h)[h].addEventListener("touchstart",this._onTouchStart,this.listenerOptions),i(this,h)[h].addEventListener("touchmove",this._onTouchMove,this.listenerOptions)),r.hasPointer&&r.hasTouchWin&&(i(this,d)[d]=document.body.style.msTouchAction,document.body.style.msTouchAction="none",i(this,h)[h].addEventListener("MSPointerDown",this._onTouchStart,!0),i(this,h)[h].addEventListener("MSPointerMove",this._onTouchMove,!0)),r.hasKeyDown&&i(this,l)[l].useKeyboard&&document.addEventListener("keydown",this._onKeyDown)},e._unbind=function(){r.hasWheelEvent&&i(this,h)[h].removeEventListener("wheel",this._onWheel),r.hasMouseWheelEvent&&i(this,h)[h].removeEventListener("mousewheel",this._onMouseWheel),r.hasTouch&&(i(this,h)[h].removeEventListener("touchstart",this._onTouchStart),i(this,h)[h].removeEventListener("touchmove",this._onTouchMove)),r.hasPointer&&r.hasTouchWin&&(document.body.style.msTouchAction=i(this,d)[d],i(this,h)[h].removeEventListener("MSPointerDown",this._onTouchStart,!0),i(this,h)[h].removeEventListener("MSPointerMove",this._onTouchMove,!0)),r.hasKeyDown&&i(this,l)[l].useKeyboard&&document.removeEventListener("keydown",this._onKeyDown)},e.on=function(t,e){i(this,a)[a].on(s,t,e);var o=i(this,a)[a].e;o&&o[s]&&1===o[s].length&&this._bind()},e.off=function(t,e){i(this,a)[a].off(s,t,e);var o=i(this,a)[a].e;(!o[s]||o[s].length<=0)&&this._unbind()},e.destroy=function(){i(this,a)[a].off(),this._unbind()},t}()}()}(e),e.exports}();function l(t,e,i){return Math.max(t,Math.min(e,i))}var h=["duration","easing"],a=/*#__PURE__*/function(){function t(){}var o=t.prototype;return o.to=function(t,e){var o=this,n=void 0===e?{}:e,r=n.duration,s=void 0===r?1:r,l=n.easing,a=void 0===l?function(t){return t}:l,c=function(t,e){if(null==t)return{};var i,o,n={},r=Object.keys(t);for(o=0;o=0||(n[i]=t[i]);return n}(n,h);this.target=t,this.fromKeys=i({},c),this.toKeys=i({},c),this.keys=Object.keys(i({},c)),this.keys.forEach(function(e){o.fromKeys[e]=t[e]}),this.duration=s,this.easing=a,this.currentTime=0,this.isRunning=!0},o.stop=function(){this.isRunning=!1},o.raf=function(t){var e=this;if(this.isRunning){this.currentTime=Math.min(this.currentTime+t,this.duration);var i=this.easing(this.progress);this.keys.forEach(function(t){var o=e.fromKeys[t];e.target[t]=o+(e.toKeys[t]-o)*i}),1===i&&this.stop()}},e(t,[{key:"progress",get:function(){return this.currentTime/this.duration}}]),t}();/*#__PURE__*/ -return function(t){var i,n;function r(e){var i,o,n,r,h=void 0===e?{}:e,c=h.duration,u=void 0===c?1.2:c,d=h.easing,p=void 0===d?function(t){return 1===t?1:1-Math.pow(2,-10*t)}:d,f=h.smooth,v=void 0===f||f,y=h.smoothTouch,w=void 0!==y&&y,g=h.touchMultiplier,m=void 0===g?2:g,b=h.direction,T=void 0===b?"vertical":b,S=h.gestureDirection,_=void 0===S?"vertical":S,M=h.wrapper,O=void 0===M?window:M,E=h.content,W=void 0===E?document.body:E;(r=t.call(this)||this).onWindowResize=function(){r.wrapperWidth=window.innerWidth,r.wrapperHeight=window.innerHeight},r.onWrapperResize=function(t){var e=t[0];if(e){var i=e.contentRect;r.wrapperWidth=i.width,r.wrapperHeight=i.height}},r.onContentResize=function(t){var e=t[0];if(e){var i=e.contentRect;r.contentWidth=i.width,r.contentHeight=i.height}},r.onVirtualScroll=function(t){var e=t.deltaY,i=t.deltaX,o=t.originalEvent;o.ctrlKey||(r.smooth=o.changedTouches?r.smoothTouch:r.options.smooth,r.stopped?o.preventDefault():r.smooth&&4!==o.buttons&&(r.smooth&&o.preventDefault(),r.targetScroll-="both"===r.gestureDirection?i+e:"horizontal"===r.gestureDirection?i:e,r.targetScroll=l(0,r.targetScroll,r.limit),r.scrollTo(r.targetScroll)))},r.onScroll=function(t){r.isScrolling&&r.smooth||(r.targetScroll=r.scroll=r.lastScroll=r.wrapperNode[r.scrollProperty],r.notify())},window.lenisVersion="0.2.10",r.options={duration:u,easing:p,smooth:v,smoothTouch:w,touchMultiplier:m,direction:T,gestureDirection:_,wrapper:O,content:W},r.duration=u,r.easing=p,r.smooth=v,r.smoothTouch=w,r.touchMultiplier=m,r.direction=T,r.gestureDirection=_,r.wrapperNode=O,r.contentNode=W,r.wrapperNode.addEventListener("scroll",r.onScroll),r.wrapperNode===window?(r.wrapperNode.addEventListener("resize",r.onWindowResize),r.onWindowResize()):(r.wrapperHeight=r.wrapperNode.offsetHeight,r.wrapperWidth=r.wrapperNode.offsetWidth,r.wrapperObserver=new ResizeObserver(r.onWrapperResize),r.wrapperObserver.observe(r.wrapperNode)),r.contentHeight=r.contentNode.offsetHeight,r.contentWidth=r.contentNode.offsetWidth,r.contentObserver=new ResizeObserver(r.onContentResize),r.contentObserver.observe(r.contentNode),r.targetScroll=r.scroll=r.lastScroll=r.wrapperNode[r.scrollProperty],r.animate=new a;var x=(null==(i=navigator)||null==(o=i.userAgentData)?void 0:o.platform)||(null==(n=navigator)?void 0:n.platform)||"unknown";return r.virtualScroll=new s({el:r.wrapperNode,firefoxMultiplier:50,mouseMultiplier:x.includes("Win")?1:.4,useKeyboard:!1,touchMultiplier:r.touchMultiplier,useTouch:!0,passive:!1}),r.virtualScroll.on(r.onVirtualScroll),r}n=t,(i=r).prototype=Object.create(n.prototype),i.prototype.constructor=i,o(i,n);var h=r.prototype;return h.start=function(){this.stopped=!1},h.stop=function(){this.stopped=!0,this.animate.stop()},h.destroy=function(){var t;this.wrapperNode===window&&this.wrapperNode.removeEventListener("resize",this.onWindowResize),this.wrapperNode.removeEventListener("scroll",this.onScroll),this.virtualScroll.destroy(),null==(t=this.wrapperObserver)||t.disconnect(),this.contentObserver.disconnect()},h.raf=function(t){var e=t-(this.now||0);this.now=t,!this.stopped&&this.smooth&&(this.lastScroll=this.scroll,this.animate.raf(.001*e),this.scroll===this.targetScroll&&(this.lastScroll=this.scroll),this.isScrolling&&(this.setScroll(this.scroll),this.notify()),this.isScrolling=this.scroll!==this.targetScroll)},h.setScroll=function(t){"horizontal"===this.direction?this.wrapperNode.scrollTo(t,0):this.wrapperNode.scrollTo(0,t)},h.notify=function(){this.emit("scroll",{scroll:this.scroll,limit:this.limit,velocity:this.velocity,direction:this.direction,progress:this.scroll/this.limit})},h.scrollTo=function(t,e){var i=void 0===e?{}:e,o=i.offset,n=void 0===o?0:o,r=i.immediate,s=void 0!==r&&r,h=i.duration,a=void 0===h?this.duration:h,c=i.easing,u=void 0===c?this.easing:c;if(null!=t){var d;if("number"==typeof t)d=t;else if("top"===t||"#top"===t)d=0;else if("bottom"===t)d=this.limit;else{var p;if("string"==typeof t)p=document.querySelector(t);else{if(null==t||!t.nodeType)return;p=t}if(!p)return;var f=0;if(this.wrapperNode!==window){var v=this.wrapperNode.getBoundingClientRect();f="horizontal"===this.direction?v.left:v.top}var y=p.getBoundingClientRect();d=("horizontal"===this.direction?y.left:y.top)+this.scroll-f}this.targetScroll=l(0,d+=n,this.limit),!this.smooth||s?this.setScroll(this.targetScroll):this.animate.to(this,{duration:a,easing:u,scroll:this.targetScroll})}},e(r,[{key:"scrollProperty",get:function(){return this.wrapperNode===window?"horizontal"===this.direction?"scrollX":"scrollY":"horizontal"===this.direction?"scrollLeft":"scrollTop"}},{key:"limit",get:function(){return"horizontal"===this.direction?this.contentWidth-this.wrapperWidth:this.contentHeight-this.wrapperHeight}},{key:"velocity",get:function(){return this.scroll-this.lastScroll}}]),r}(r)}); +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t||self).Lenis=e()}(this,function(){function t(t,e){for(var i=0;i1,hasPointer:!!window.navigator.msPointerEnabled,hasKeyDown:"onkeydown"in document,isFirefox:navigator.userAgent.indexOf("Firefox")>-1}),i(this,l)[l]=Object.assign({mouseMultiplier:1,touchMultiplier:2,firefoxMultiplier:15,keyStep:120,preventTouch:!1,unpreventTouchClass:"vs-touchmove-allowed",useKeyboard:!0,useTouch:!0},t),i(this,a)[a]=new n,i(this,c)[c]={y:0,x:0,deltaX:0,deltaY:0},i(this,u)[u]={x:null,y:null},i(this,d)[d]=null,void 0!==i(this,l)[l].passive&&(this.listenerOptions={passive:i(this,l)[l].passive})}var e=t.prototype;return e._notify=function(t){var e=i(this,c)[c];e.x+=e.deltaX,e.y+=e.deltaY,i(this,a)[a].emit(s,{x:e.x,y:e.y,deltaX:e.deltaX,deltaY:e.deltaY,originalEvent:t})},e._bind=function(){r.hasWheelEvent&&i(this,h)[h].addEventListener("wheel",this._onWheel,this.listenerOptions),r.hasMouseWheelEvent&&i(this,h)[h].addEventListener("mousewheel",this._onMouseWheel,this.listenerOptions),r.hasTouch&&i(this,l)[l].useTouch&&(i(this,h)[h].addEventListener("touchstart",this._onTouchStart,this.listenerOptions),i(this,h)[h].addEventListener("touchmove",this._onTouchMove,this.listenerOptions)),r.hasPointer&&r.hasTouchWin&&(i(this,d)[d]=document.body.style.msTouchAction,document.body.style.msTouchAction="none",i(this,h)[h].addEventListener("MSPointerDown",this._onTouchStart,!0),i(this,h)[h].addEventListener("MSPointerMove",this._onTouchMove,!0)),r.hasKeyDown&&i(this,l)[l].useKeyboard&&document.addEventListener("keydown",this._onKeyDown)},e._unbind=function(){r.hasWheelEvent&&i(this,h)[h].removeEventListener("wheel",this._onWheel),r.hasMouseWheelEvent&&i(this,h)[h].removeEventListener("mousewheel",this._onMouseWheel),r.hasTouch&&(i(this,h)[h].removeEventListener("touchstart",this._onTouchStart),i(this,h)[h].removeEventListener("touchmove",this._onTouchMove)),r.hasPointer&&r.hasTouchWin&&(document.body.style.msTouchAction=i(this,d)[d],i(this,h)[h].removeEventListener("MSPointerDown",this._onTouchStart,!0),i(this,h)[h].removeEventListener("MSPointerMove",this._onTouchMove,!0)),r.hasKeyDown&&i(this,l)[l].useKeyboard&&document.removeEventListener("keydown",this._onKeyDown)},e.on=function(t,e){i(this,a)[a].on(s,t,e);var o=i(this,a)[a].e;o&&o[s]&&1===o[s].length&&this._bind()},e.off=function(t,e){i(this,a)[a].off(s,t,e);var o=i(this,a)[a].e;(!o[s]||o[s].length<=0)&&this._unbind()},e.destroy=function(){i(this,a)[a].off(),this._unbind()},t}()}()}(e),e.exports}();function l(t,e,i){return Math.max(t,Math.min(e,i))}var h=["duration","easing"],a=/*#__PURE__*/function(){function t(){}var o=t.prototype;return o.to=function(t,e){var o=this,n=void 0===e?{}:e,r=n.duration,s=void 0===r?1:r,l=n.easing,a=void 0===l?function(t){return t}:l,c=function(t,e){if(null==t)return{};var i,o,n={},r=Object.keys(t);for(o=0;o=0||(n[i]=t[i]);return n}(n,h);this.target=t,this.fromKeys=i({},c),this.toKeys=i({},c),this.keys=Object.keys(i({},c)),this.keys.forEach(function(e){o.fromKeys[e]=t[e]}),this.duration=s,this.easing=a,this.currentTime=0,this.isRunning=!0},o.stop=function(){this.isRunning=!1},o.raf=function(t){var e=this;if(this.isRunning){this.currentTime=Math.min(this.currentTime+t,this.duration);var i=this.easing(this.progress);this.keys.forEach(function(t){var o=e.fromKeys[t];e.target[t]=o+(e.toKeys[t]-o)*i}),1===i&&this.stop()}},e(t,[{key:"progress",get:function(){return this.currentTime/this.duration}}]),t}();/*#__PURE__*/ +return function(t){var i,n;function r(e){var i,o,n,r,h=void 0===e?{}:e,c=h.duration,u=void 0===c?1.2:c,d=h.easing,p=void 0===d?function(t){return 1===t?1:1-Math.pow(2,-10*t)}:d,f=h.smooth,v=void 0===f||f,y=h.smoothTouch,w=void 0!==y&&y,g=h.touchMultiplier,m=void 0===g?2:g,b=h.direction,T=void 0===b?"vertical":b,S=h.gestureDirection,_=void 0===S?"vertical":S,M=h.wrapper,O=void 0===M?window:M,E=h.content,W=void 0===E?document.body:E;(r=t.call(this)||this).onWindowResize=function(){r.wrapperWidth=window.innerWidth,r.wrapperHeight=window.innerHeight},r.onWrapperResize=function(t){var e=t[0];if(e){var i=e.contentRect;r.wrapperWidth=i.width,r.wrapperHeight=i.height}},r.onContentResize=function(t){var e=t[0];if(e){var i=e.contentRect;r.contentWidth=i.width,r.contentHeight=i.height}},r.onVirtualScroll=function(t){var e=t.deltaY,i=t.deltaX,o=t.originalEvent;o.ctrlKey||(r.smooth=o.changedTouches?r.smoothTouch:r.options.smooth,r.stopped?o.preventDefault():r.smooth&&4!==o.buttons&&(r.smooth&&o.preventDefault(),r.targetScroll-="both"===r.gestureDirection?i+e:"horizontal"===r.gestureDirection?i:e,r.targetScroll=l(0,r.targetScroll,r.limit),r.scrollTo(r.targetScroll)))},r.onScroll=function(t){r.isScrolling&&r.smooth||(r.targetScroll=r.scroll=r.lastScroll=r.wrapperNode[r.scrollProperty],r.notify())},window.lenisVersion="0.2.11",r.options={duration:u,easing:p,smooth:v,smoothTouch:w,touchMultiplier:m,direction:T,gestureDirection:_,wrapper:O,content:W},r.duration=u,r.easing=p,r.smooth=v,r.smoothTouch=w,r.touchMultiplier=m,r.direction=T,r.gestureDirection=_,r.wrapperNode=O,r.contentNode=W,r.wrapperNode.addEventListener("scroll",r.onScroll),r.wrapperNode===window?(r.wrapperNode.addEventListener("resize",r.onWindowResize),r.onWindowResize()):(r.wrapperHeight=r.wrapperNode.offsetHeight,r.wrapperWidth=r.wrapperNode.offsetWidth,r.wrapperObserver=new ResizeObserver(r.onWrapperResize),r.wrapperObserver.observe(r.wrapperNode)),r.contentHeight=r.contentNode.offsetHeight,r.contentWidth=r.contentNode.offsetWidth,r.contentObserver=new ResizeObserver(r.onContentResize),r.contentObserver.observe(r.contentNode),r.targetScroll=r.scroll=r.lastScroll=r.wrapperNode[r.scrollProperty],r.animate=new a;var x=(null==(i=navigator)||null==(o=i.userAgentData)?void 0:o.platform)||(null==(n=navigator)?void 0:n.platform)||"unknown";return r.virtualScroll=new s({el:r.wrapperNode,firefoxMultiplier:50,mouseMultiplier:x.includes("Win")?1:.4,useKeyboard:!1,touchMultiplier:r.touchMultiplier,useTouch:!0,passive:!1}),r.virtualScroll.on(r.onVirtualScroll),r}n=t,(i=r).prototype=Object.create(n.prototype),i.prototype.constructor=i,o(i,n);var h=r.prototype;return h.start=function(){this.stopped=!1},h.stop=function(){this.stopped=!0,this.animate.stop()},h.destroy=function(){var t;this.wrapperNode===window&&this.wrapperNode.removeEventListener("resize",this.onWindowResize),this.wrapperNode.removeEventListener("scroll",this.onScroll),this.virtualScroll.destroy(),null==(t=this.wrapperObserver)||t.disconnect(),this.contentObserver.disconnect()},h.raf=function(t){var e=t-(this.now||0);this.now=t,!this.stopped&&this.smooth&&(this.lastScroll=this.scroll,this.animate.raf(.001*e),this.scroll===this.targetScroll&&(this.lastScroll=this.scroll),this.isScrolling&&(this.setScroll(this.scroll),this.notify()),this.isScrolling=this.scroll!==this.targetScroll)},h.setScroll=function(t){"horizontal"===this.direction?this.wrapperNode.scrollTo(t,0):this.wrapperNode.scrollTo(0,t)},h.notify=function(){this.emit("scroll",{scroll:this.scroll,limit:this.limit,velocity:this.velocity,direction:this.direction,progress:this.scroll/this.limit})},h.scrollTo=function(t,e){var i=void 0===e?{}:e,o=i.offset,n=void 0===o?0:o,r=i.immediate,s=void 0!==r&&r,h=i.duration,a=void 0===h?this.duration:h,c=i.easing,u=void 0===c?this.easing:c;if(null!=t){var d;if("number"==typeof t)d=t;else if("top"===t||"#top"===t)d=0;else if("bottom"===t)d=this.limit;else{var p;if("string"==typeof t)p=document.querySelector(t);else{if(null==t||!t.nodeType)return;p=t}if(!p)return;var f=0;if(this.wrapperNode!==window){var v=this.wrapperNode.getBoundingClientRect();f="horizontal"===this.direction?v.left:v.top}var y=p.getBoundingClientRect();d=("horizontal"===this.direction?y.left:y.top)+this.scroll-f}this.targetScroll=l(0,d+=n,this.limit),!this.smooth||s?this.setScroll(this.targetScroll):this.animate.to(this,{duration:a,easing:u,scroll:this.targetScroll})}},e(r,[{key:"scrollProperty",get:function(){return this.wrapperNode===window?"horizontal"===this.direction?"scrollX":"scrollY":"horizontal"===this.direction?"scrollLeft":"scrollTop"}},{key:"limit",get:function(){return"horizontal"===this.direction?this.contentWidth-this.wrapperWidth:this.contentHeight-this.wrapperHeight}},{key:"velocity",get:function(){return this.scroll-this.lastScroll}}]),r}(r)}); diff --git a/dist/lenis.d.ts b/dist/lenis.d.ts index 304a4d5a..c687e932 100644 --- a/dist/lenis.d.ts +++ b/dist/lenis.d.ts @@ -1,22 +1,4 @@ export default class Lenis { - /** - * @typedef {(t: number) => number} EasingFunction - * @typedef {'vertical' | 'horizontal'} Direction - * @typedef {'vertical' | 'horizontal' | 'both'} GestureDirection - * - * @typedef LenisOptions - * @property {number} [duration] - * @property {EasingFunction} [easing] - * @property {boolean} [smooth] - * @property {boolean} [smoothTouch] - * @property {number} [touchMultiplier] - * @property {Direction} [direction] - * @property {GestureDirection} [gestureDirection] - * @property {Window | HTMLElement} [wrapper] - * @property {HTMLElement} [content] - * - * @param {LenisOptions} - */ constructor({ duration, easing, smooth, smoothTouch, touchMultiplier, direction, gestureDirection, wrapper, content, }?: { duration?: number; easing?: (t: number) => number; @@ -24,7 +6,7 @@ export default class Lenis { smoothTouch?: boolean; touchMultiplier?: number; direction?: "vertical" | "horizontal"; - gestureDirection?: "vertical" | "horizontal" | "both"; + gestureDirection?: "both" | "vertical" | "horizontal"; wrapper?: Window | HTMLElement; content?: HTMLElement; }); @@ -35,8 +17,8 @@ export default class Lenis { smoothTouch: boolean; touchMultiplier: number; direction: "vertical" | "horizontal"; - gestureDirection: "vertical" | "horizontal" | "both"; - wrapper: Window | HTMLElement; + gestureDirection: "both" | "vertical" | "horizontal"; + wrapper: HTMLElement | Window; content: HTMLElement; }; duration: number; @@ -45,8 +27,8 @@ export default class Lenis { smoothTouch: boolean; touchMultiplier: number; direction: "vertical" | "horizontal"; - gestureDirection: "vertical" | "horizontal" | "both"; - wrapperNode: Window | HTMLElement; + gestureDirection: "both" | "vertical" | "horizontal"; + wrapperNode: HTMLElement | Window; contentNode: HTMLElement; wrapperHeight: any; wrapperWidth: any; diff --git a/dist/lenis.js b/dist/lenis.js index 335d2ef4..4caa0052 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,h);this.target=t,this.fromKeys=l({},a),this.toKeys=l({},a),this.keys=Object.keys(l({},a)),this.keys.forEach(function(e){o.fromKeys[e]=t[e]}),this.duration=n,this.easing=c,this.currentTime=0,this.isRunning=!0},e.stop=function(){this.isRunning=!1},e.raf=function(t){var e=this;if(this.isRunning){this.currentTime=Math.min(this.currentTime+t,this.duration);var o=this.easing(this.progress);this.keys.forEach(function(t){var i=e.fromKeys[t];e.target[t]=i+(e.toKeys[t]-i)*o}),1===o&&this.stop()}},s(t,[{key:"progress",get:function(){return this.currentTime/this.duration}}]),t}();module.exports=/*#__PURE__*/function(t){var e,o;function i(e){var o,i,n,s,l=void 0===e?{}:e,c=l.duration,h=void 0===c?1.2:c,p=l.easing,d=void 0===p?function(t){return 1===t?1:1-Math.pow(2,-10*t)}:p,f=l.smooth,v=void 0===f||f,g=l.smoothTouch,w=void 0!==g&&g,m=l.touchMultiplier,y=void 0===m?2:m,b=l.direction,S=void 0===b?"vertical":b,N=l.gestureDirection,O=void 0===N?"vertical":N,z=l.wrapper,R=void 0===z?window:z,W=l.content,T=void 0===W?document.body:W;(s=t.call(this)||this).onWindowResize=function(){s.wrapperWidth=window.innerWidth,s.wrapperHeight=window.innerHeight},s.onWrapperResize=function(t){var e=t[0];if(e){var o=e.contentRect;s.wrapperWidth=o.width,s.wrapperHeight=o.height}},s.onContentResize=function(t){var e=t[0];if(e){var o=e.contentRect;s.contentWidth=o.width,s.contentHeight=o.height}},s.onVirtualScroll=function(t){var e=t.deltaY,o=t.deltaX,i=t.originalEvent;i.ctrlKey||(s.smooth=i.changedTouches?s.smoothTouch:s.options.smooth,s.stopped?i.preventDefault():s.smooth&&4!==i.buttons&&(s.smooth&&i.preventDefault(),s.targetScroll-="both"===s.gestureDirection?o+e:"horizontal"===s.gestureDirection?o:e,s.targetScroll=a(0,s.targetScroll,s.limit),s.scrollTo(s.targetScroll)))},s.onScroll=function(t){s.isScrolling&&s.smooth||(s.targetScroll=s.scroll=s.lastScroll=s.wrapperNode[s.scrollProperty],s.notify())},window.lenisVersion="0.2.10",s.options={duration:h,easing:d,smooth:v,smoothTouch:w,touchMultiplier:y,direction:S,gestureDirection:O,wrapper:R,content:T},s.duration=h,s.easing=d,s.smooth=v,s.smoothTouch=w,s.touchMultiplier=y,s.direction=S,s.gestureDirection=O,s.wrapperNode=R,s.contentNode=T,s.wrapperNode.addEventListener("scroll",s.onScroll),s.wrapperNode===window?(s.wrapperNode.addEventListener("resize",s.onWindowResize),s.onWindowResize()):(s.wrapperHeight=s.wrapperNode.offsetHeight,s.wrapperWidth=s.wrapperNode.offsetWidth,s.wrapperObserver=new ResizeObserver(s.onWrapperResize),s.wrapperObserver.observe(s.wrapperNode)),s.contentHeight=s.contentNode.offsetHeight,s.contentWidth=s.contentNode.offsetWidth,s.contentObserver=new ResizeObserver(s.onContentResize),s.contentObserver.observe(s.contentNode),s.targetScroll=s.scroll=s.lastScroll=s.wrapperNode[s.scrollProperty],s.animate=new u;var j=(null==(o=navigator)||null==(i=o.userAgentData)?void 0:i.platform)||(null==(n=navigator)?void 0:n.platform)||"unknown";return s.virtualScroll=new r.default({el:s.wrapperNode,firefoxMultiplier:50,mouseMultiplier:j.includes("Win")?1:.4,useKeyboard:!1,touchMultiplier:s.touchMultiplier,useTouch:!0,passive:!1}),s.virtualScroll.on(s.onVirtualScroll),s}o=t,(e=i).prototype=Object.create(o.prototype),e.prototype.constructor=e,c(e,o);var n=i.prototype;return n.start=function(){this.stopped=!1},n.stop=function(){this.stopped=!0,this.animate.stop()},n.destroy=function(){var t;this.wrapperNode===window&&this.wrapperNode.removeEventListener("resize",this.onWindowResize),this.wrapperNode.removeEventListener("scroll",this.onScroll),this.virtualScroll.destroy(),null==(t=this.wrapperObserver)||t.disconnect(),this.contentObserver.disconnect()},n.raf=function(t){var e=t-(this.now||0);this.now=t,!this.stopped&&this.smooth&&(this.lastScroll=this.scroll,this.animate.raf(.001*e),this.scroll===this.targetScroll&&(this.lastScroll=this.scroll),this.isScrolling&&(this.setScroll(this.scroll),this.notify()),this.isScrolling=this.scroll!==this.targetScroll)},n.setScroll=function(t){"horizontal"===this.direction?this.wrapperNode.scrollTo(t,0):this.wrapperNode.scrollTo(0,t)},n.notify=function(){this.emit("scroll",{scroll:this.scroll,limit:this.limit,velocity:this.velocity,direction:this.direction,progress:this.scroll/this.limit})},n.scrollTo=function(t,e){var o=void 0===e?{}:e,i=o.offset,r=void 0===i?0:i,n=o.immediate,s=void 0!==n&&n,l=o.duration,c=void 0===l?this.duration:l,h=o.easing,u=void 0===h?this.easing:h;if(null!=t){var p;if("number"==typeof t)p=t;else if("top"===t||"#top"===t)p=0;else if("bottom"===t)p=this.limit;else{var d;if("string"==typeof t)d=document.querySelector(t);else{if(null==t||!t.nodeType)return;d=t}if(!d)return;var f=0;if(this.wrapperNode!==window){var v=this.wrapperNode.getBoundingClientRect();f="horizontal"===this.direction?v.left:v.top}var g=d.getBoundingClientRect();p=("horizontal"===this.direction?g.left:g.top)+this.scroll-f}this.targetScroll=a(0,p+=r,this.limit),!this.smooth||s?this.setScroll(this.targetScroll):this.animate.to(this,{duration:c,easing:u,scroll:this.targetScroll})}},s(i,[{key:"scrollProperty",get:function(){return this.wrapperNode===window?"horizontal"===this.direction?"scrollX":"scrollY":"horizontal"===this.direction?"scrollLeft":"scrollTop"}},{key:"limit",get:function(){return"horizontal"===this.direction?this.contentWidth-this.wrapperWidth:this.contentHeight-this.wrapperHeight}},{key:"velocity",get:function(){return this.scroll-this.lastScroll}}]),i}(i.default); +var t=require("tiny-emitter"),e=require("virtual-scroll");function o(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var i=/*#__PURE__*/o(t),r=/*#__PURE__*/o(e);function n(t,e){for(var o=0;o=0||(r[o]=t[o]);return r}(i,h);this.target=t,this.fromKeys=l({},a),this.toKeys=l({},a),this.keys=Object.keys(l({},a)),this.keys.forEach(function(e){o.fromKeys[e]=t[e]}),this.duration=n,this.easing=c,this.currentTime=0,this.isRunning=!0},e.stop=function(){this.isRunning=!1},e.raf=function(t){var e=this;if(this.isRunning){this.currentTime=Math.min(this.currentTime+t,this.duration);var o=this.easing(this.progress);this.keys.forEach(function(t){var i=e.fromKeys[t];e.target[t]=i+(e.toKeys[t]-i)*o}),1===o&&this.stop()}},s(t,[{key:"progress",get:function(){return this.currentTime/this.duration}}]),t}();module.exports=/*#__PURE__*/function(t){var e,o;function i(e){var o,i,n,s,l=void 0===e?{}:e,c=l.duration,h=void 0===c?1.2:c,p=l.easing,d=void 0===p?function(t){return 1===t?1:1-Math.pow(2,-10*t)}:p,f=l.smooth,v=void 0===f||f,g=l.smoothTouch,w=void 0!==g&&g,m=l.touchMultiplier,y=void 0===m?2:m,b=l.direction,S=void 0===b?"vertical":b,N=l.gestureDirection,O=void 0===N?"vertical":N,z=l.wrapper,R=void 0===z?window:z,W=l.content,T=void 0===W?document.body:W;(s=t.call(this)||this).onWindowResize=function(){s.wrapperWidth=window.innerWidth,s.wrapperHeight=window.innerHeight},s.onWrapperResize=function(t){var e=t[0];if(e){var o=e.contentRect;s.wrapperWidth=o.width,s.wrapperHeight=o.height}},s.onContentResize=function(t){var e=t[0];if(e){var o=e.contentRect;s.contentWidth=o.width,s.contentHeight=o.height}},s.onVirtualScroll=function(t){var e=t.deltaY,o=t.deltaX,i=t.originalEvent;i.ctrlKey||(s.smooth=i.changedTouches?s.smoothTouch:s.options.smooth,s.stopped?i.preventDefault():s.smooth&&4!==i.buttons&&(s.smooth&&i.preventDefault(),s.targetScroll-="both"===s.gestureDirection?o+e:"horizontal"===s.gestureDirection?o:e,s.targetScroll=a(0,s.targetScroll,s.limit),s.scrollTo(s.targetScroll)))},s.onScroll=function(t){s.isScrolling&&s.smooth||(s.targetScroll=s.scroll=s.lastScroll=s.wrapperNode[s.scrollProperty],s.notify())},window.lenisVersion="0.2.11",s.options={duration:h,easing:d,smooth:v,smoothTouch:w,touchMultiplier:y,direction:S,gestureDirection:O,wrapper:R,content:T},s.duration=h,s.easing=d,s.smooth=v,s.smoothTouch=w,s.touchMultiplier=y,s.direction=S,s.gestureDirection=O,s.wrapperNode=R,s.contentNode=T,s.wrapperNode.addEventListener("scroll",s.onScroll),s.wrapperNode===window?(s.wrapperNode.addEventListener("resize",s.onWindowResize),s.onWindowResize()):(s.wrapperHeight=s.wrapperNode.offsetHeight,s.wrapperWidth=s.wrapperNode.offsetWidth,s.wrapperObserver=new ResizeObserver(s.onWrapperResize),s.wrapperObserver.observe(s.wrapperNode)),s.contentHeight=s.contentNode.offsetHeight,s.contentWidth=s.contentNode.offsetWidth,s.contentObserver=new ResizeObserver(s.onContentResize),s.contentObserver.observe(s.contentNode),s.targetScroll=s.scroll=s.lastScroll=s.wrapperNode[s.scrollProperty],s.animate=new u;var j=(null==(o=navigator)||null==(i=o.userAgentData)?void 0:i.platform)||(null==(n=navigator)?void 0:n.platform)||"unknown";return s.virtualScroll=new r.default({el:s.wrapperNode,firefoxMultiplier:50,mouseMultiplier:j.includes("Win")?1:.4,useKeyboard:!1,touchMultiplier:s.touchMultiplier,useTouch:!0,passive:!1}),s.virtualScroll.on(s.onVirtualScroll),s}o=t,(e=i).prototype=Object.create(o.prototype),e.prototype.constructor=e,c(e,o);var n=i.prototype;return n.start=function(){this.stopped=!1},n.stop=function(){this.stopped=!0,this.animate.stop()},n.destroy=function(){var t;this.wrapperNode===window&&this.wrapperNode.removeEventListener("resize",this.onWindowResize),this.wrapperNode.removeEventListener("scroll",this.onScroll),this.virtualScroll.destroy(),null==(t=this.wrapperObserver)||t.disconnect(),this.contentObserver.disconnect()},n.raf=function(t){var e=t-(this.now||0);this.now=t,!this.stopped&&this.smooth&&(this.lastScroll=this.scroll,this.animate.raf(.001*e),this.scroll===this.targetScroll&&(this.lastScroll=this.scroll),this.isScrolling&&(this.setScroll(this.scroll),this.notify()),this.isScrolling=this.scroll!==this.targetScroll)},n.setScroll=function(t){"horizontal"===this.direction?this.wrapperNode.scrollTo(t,0):this.wrapperNode.scrollTo(0,t)},n.notify=function(){this.emit("scroll",{scroll:this.scroll,limit:this.limit,velocity:this.velocity,direction:this.direction,progress:this.scroll/this.limit})},n.scrollTo=function(t,e){var o=void 0===e?{}:e,i=o.offset,r=void 0===i?0:i,n=o.immediate,s=void 0!==n&&n,l=o.duration,c=void 0===l?this.duration:l,h=o.easing,u=void 0===h?this.easing:h;if(null!=t){var p;if("number"==typeof t)p=t;else if("top"===t||"#top"===t)p=0;else if("bottom"===t)p=this.limit;else{var d;if("string"==typeof t)d=document.querySelector(t);else{if(null==t||!t.nodeType)return;d=t}if(!d)return;var f=0;if(this.wrapperNode!==window){var v=this.wrapperNode.getBoundingClientRect();f="horizontal"===this.direction?v.left:v.top}var g=d.getBoundingClientRect();p=("horizontal"===this.direction?g.left:g.top)+this.scroll-f}this.targetScroll=a(0,p+=r,this.limit),!this.smooth||s?this.setScroll(this.targetScroll):this.animate.to(this,{duration:c,easing:u,scroll:this.targetScroll})}},s(i,[{key:"scrollProperty",get:function(){return this.wrapperNode===window?"horizontal"===this.direction?"scrollX":"scrollY":"horizontal"===this.direction?"scrollLeft":"scrollTop"}},{key:"limit",get:function(){return"horizontal"===this.direction?this.contentWidth-this.wrapperWidth:this.contentHeight-this.wrapperHeight}},{key:"velocity",get:function(){return this.scroll-this.lastScroll}}]),i}(i.default); //# sourceMappingURL=lenis.js.map diff --git a/dist/lenis.mjs b/dist/lenis.mjs index d4ab610c..1fbb3fbf 100644 --- a/dist/lenis.mjs +++ b/dist/lenis.mjs @@ -1,2 +1,2 @@ -import t from"tiny-emitter";import e from"virtual-scroll";function o(t,e){for(var o=0;o=0||(r[o]=t[o]);return r}(i,l);this.target=t,this.fromKeys=r({},h),this.toKeys=r({},h),this.keys=Object.keys(r({},h)),this.keys.forEach(function(e){o.fromKeys[e]=t[e]}),this.duration=s,this.easing=a,this.currentTime=0,this.isRunning=!0},e.stop=function(){this.isRunning=!1},e.raf=function(t){var e=this;if(this.isRunning){this.currentTime=Math.min(this.currentTime+t,this.duration);var o=this.easing(this.progress);this.keys.forEach(function(t){var i=e.fromKeys[t];e.target[t]=i+(e.toKeys[t]-i)*o}),1===o&&this.stop()}},i(t,[{key:"progress",get:function(){return this.currentTime/this.duration}}]),t}(),a=/*#__PURE__*/function(t){var o,r;function l(o){var i,r,n,l,a=void 0===o?{}:o,h=a.duration,p=void 0===h?1.2:h,u=a.easing,d=void 0===u?function(t){return 1===t?1:1-Math.pow(2,-10*t)}:u,f=a.smooth,v=void 0===f||f,g=a.smoothTouch,w=void 0!==g&&g,m=a.touchMultiplier,y=void 0===m?2:m,b=a.direction,S=void 0===b?"vertical":b,N=a.gestureDirection,O=void 0===N?"vertical":N,z=a.wrapper,R=void 0===z?window:z,W=a.content,T=void 0===W?document.body:W;(l=t.call(this)||this).onWindowResize=function(){l.wrapperWidth=window.innerWidth,l.wrapperHeight=window.innerHeight},l.onWrapperResize=function(t){var e=t[0];if(e){var o=e.contentRect;l.wrapperWidth=o.width,l.wrapperHeight=o.height}},l.onContentResize=function(t){var e=t[0];if(e){var o=e.contentRect;l.contentWidth=o.width,l.contentHeight=o.height}},l.onVirtualScroll=function(t){var e=t.deltaY,o=t.deltaX,i=t.originalEvent;i.ctrlKey||(l.smooth=i.changedTouches?l.smoothTouch:l.options.smooth,l.stopped?i.preventDefault():l.smooth&&4!==i.buttons&&(l.smooth&&i.preventDefault(),l.targetScroll-="both"===l.gestureDirection?o+e:"horizontal"===l.gestureDirection?o:e,l.targetScroll=s(0,l.targetScroll,l.limit),l.scrollTo(l.targetScroll)))},l.onScroll=function(t){l.isScrolling&&l.smooth||(l.targetScroll=l.scroll=l.lastScroll=l.wrapperNode[l.scrollProperty],l.notify())},window.lenisVersion="0.2.10",l.options={duration:p,easing:d,smooth:v,smoothTouch:w,touchMultiplier:y,direction:S,gestureDirection:O,wrapper:R,content:T},l.duration=p,l.easing=d,l.smooth=v,l.smoothTouch=w,l.touchMultiplier=y,l.direction=S,l.gestureDirection=O,l.wrapperNode=R,l.contentNode=T,l.wrapperNode.addEventListener("scroll",l.onScroll),l.wrapperNode===window?(l.wrapperNode.addEventListener("resize",l.onWindowResize),l.onWindowResize()):(l.wrapperHeight=l.wrapperNode.offsetHeight,l.wrapperWidth=l.wrapperNode.offsetWidth,l.wrapperObserver=new ResizeObserver(l.onWrapperResize),l.wrapperObserver.observe(l.wrapperNode)),l.contentHeight=l.contentNode.offsetHeight,l.contentWidth=l.contentNode.offsetWidth,l.contentObserver=new ResizeObserver(l.onContentResize),l.contentObserver.observe(l.contentNode),l.targetScroll=l.scroll=l.lastScroll=l.wrapperNode[l.scrollProperty],l.animate=new c;var k=(null==(i=navigator)||null==(r=i.userAgentData)?void 0:r.platform)||(null==(n=navigator)?void 0:n.platform)||"unknown";return l.virtualScroll=new e({el:l.wrapperNode,firefoxMultiplier:50,mouseMultiplier:k.includes("Win")?1:.4,useKeyboard:!1,touchMultiplier:l.touchMultiplier,useTouch:!0,passive:!1}),l.virtualScroll.on(l.onVirtualScroll),l}r=t,(o=l).prototype=Object.create(r.prototype),o.prototype.constructor=o,n(o,r);var a=l.prototype;return a.start=function(){this.stopped=!1},a.stop=function(){this.stopped=!0,this.animate.stop()},a.destroy=function(){var t;this.wrapperNode===window&&this.wrapperNode.removeEventListener("resize",this.onWindowResize),this.wrapperNode.removeEventListener("scroll",this.onScroll),this.virtualScroll.destroy(),null==(t=this.wrapperObserver)||t.disconnect(),this.contentObserver.disconnect()},a.raf=function(t){var e=t-(this.now||0);this.now=t,!this.stopped&&this.smooth&&(this.lastScroll=this.scroll,this.animate.raf(.001*e),this.scroll===this.targetScroll&&(this.lastScroll=this.scroll),this.isScrolling&&(this.setScroll(this.scroll),this.notify()),this.isScrolling=this.scroll!==this.targetScroll)},a.setScroll=function(t){"horizontal"===this.direction?this.wrapperNode.scrollTo(t,0):this.wrapperNode.scrollTo(0,t)},a.notify=function(){this.emit("scroll",{scroll:this.scroll,limit:this.limit,velocity:this.velocity,direction:this.direction,progress:this.scroll/this.limit})},a.scrollTo=function(t,e){var o=void 0===e?{}:e,i=o.offset,r=void 0===i?0:i,n=o.immediate,l=void 0!==n&&n,c=o.duration,a=void 0===c?this.duration:c,h=o.easing,p=void 0===h?this.easing:h;if(null!=t){var u;if("number"==typeof t)u=t;else if("top"===t||"#top"===t)u=0;else if("bottom"===t)u=this.limit;else{var d;if("string"==typeof t)d=document.querySelector(t);else{if(null==t||!t.nodeType)return;d=t}if(!d)return;var f=0;if(this.wrapperNode!==window){var v=this.wrapperNode.getBoundingClientRect();f="horizontal"===this.direction?v.left:v.top}var g=d.getBoundingClientRect();u=("horizontal"===this.direction?g.left:g.top)+this.scroll-f}this.targetScroll=s(0,u+=r,this.limit),!this.smooth||l?this.setScroll(this.targetScroll):this.animate.to(this,{duration:a,easing:p,scroll:this.targetScroll})}},i(l,[{key:"scrollProperty",get:function(){return this.wrapperNode===window?"horizontal"===this.direction?"scrollX":"scrollY":"horizontal"===this.direction?"scrollLeft":"scrollTop"}},{key:"limit",get:function(){return"horizontal"===this.direction?this.contentWidth-this.wrapperWidth:this.contentHeight-this.wrapperHeight}},{key:"velocity",get:function(){return this.scroll-this.lastScroll}}]),l}(t);export{a as default}; +import t from"tiny-emitter";import e from"virtual-scroll";function o(t,e){for(var o=0;o=0||(r[o]=t[o]);return r}(i,l);this.target=t,this.fromKeys=r({},h),this.toKeys=r({},h),this.keys=Object.keys(r({},h)),this.keys.forEach(function(e){o.fromKeys[e]=t[e]}),this.duration=s,this.easing=a,this.currentTime=0,this.isRunning=!0},e.stop=function(){this.isRunning=!1},e.raf=function(t){var e=this;if(this.isRunning){this.currentTime=Math.min(this.currentTime+t,this.duration);var o=this.easing(this.progress);this.keys.forEach(function(t){var i=e.fromKeys[t];e.target[t]=i+(e.toKeys[t]-i)*o}),1===o&&this.stop()}},i(t,[{key:"progress",get:function(){return this.currentTime/this.duration}}]),t}(),a=/*#__PURE__*/function(t){var o,r;function l(o){var i,r,n,l,a=void 0===o?{}:o,h=a.duration,p=void 0===h?1.2:h,u=a.easing,d=void 0===u?function(t){return 1===t?1:1-Math.pow(2,-10*t)}:u,f=a.smooth,v=void 0===f||f,g=a.smoothTouch,w=void 0!==g&&g,m=a.touchMultiplier,y=void 0===m?2:m,b=a.direction,S=void 0===b?"vertical":b,N=a.gestureDirection,O=void 0===N?"vertical":N,z=a.wrapper,R=void 0===z?window:z,W=a.content,T=void 0===W?document.body:W;(l=t.call(this)||this).onWindowResize=function(){l.wrapperWidth=window.innerWidth,l.wrapperHeight=window.innerHeight},l.onWrapperResize=function(t){var e=t[0];if(e){var o=e.contentRect;l.wrapperWidth=o.width,l.wrapperHeight=o.height}},l.onContentResize=function(t){var e=t[0];if(e){var o=e.contentRect;l.contentWidth=o.width,l.contentHeight=o.height}},l.onVirtualScroll=function(t){var e=t.deltaY,o=t.deltaX,i=t.originalEvent;i.ctrlKey||(l.smooth=i.changedTouches?l.smoothTouch:l.options.smooth,l.stopped?i.preventDefault():l.smooth&&4!==i.buttons&&(l.smooth&&i.preventDefault(),l.targetScroll-="both"===l.gestureDirection?o+e:"horizontal"===l.gestureDirection?o:e,l.targetScroll=s(0,l.targetScroll,l.limit),l.scrollTo(l.targetScroll)))},l.onScroll=function(t){l.isScrolling&&l.smooth||(l.targetScroll=l.scroll=l.lastScroll=l.wrapperNode[l.scrollProperty],l.notify())},window.lenisVersion="0.2.11",l.options={duration:p,easing:d,smooth:v,smoothTouch:w,touchMultiplier:y,direction:S,gestureDirection:O,wrapper:R,content:T},l.duration=p,l.easing=d,l.smooth=v,l.smoothTouch=w,l.touchMultiplier=y,l.direction=S,l.gestureDirection=O,l.wrapperNode=R,l.contentNode=T,l.wrapperNode.addEventListener("scroll",l.onScroll),l.wrapperNode===window?(l.wrapperNode.addEventListener("resize",l.onWindowResize),l.onWindowResize()):(l.wrapperHeight=l.wrapperNode.offsetHeight,l.wrapperWidth=l.wrapperNode.offsetWidth,l.wrapperObserver=new ResizeObserver(l.onWrapperResize),l.wrapperObserver.observe(l.wrapperNode)),l.contentHeight=l.contentNode.offsetHeight,l.contentWidth=l.contentNode.offsetWidth,l.contentObserver=new ResizeObserver(l.onContentResize),l.contentObserver.observe(l.contentNode),l.targetScroll=l.scroll=l.lastScroll=l.wrapperNode[l.scrollProperty],l.animate=new c;var k=(null==(i=navigator)||null==(r=i.userAgentData)?void 0:r.platform)||(null==(n=navigator)?void 0:n.platform)||"unknown";return l.virtualScroll=new e({el:l.wrapperNode,firefoxMultiplier:50,mouseMultiplier:k.includes("Win")?1:.4,useKeyboard:!1,touchMultiplier:l.touchMultiplier,useTouch:!0,passive:!1}),l.virtualScroll.on(l.onVirtualScroll),l}r=t,(o=l).prototype=Object.create(r.prototype),o.prototype.constructor=o,n(o,r);var a=l.prototype;return a.start=function(){this.stopped=!1},a.stop=function(){this.stopped=!0,this.animate.stop()},a.destroy=function(){var t;this.wrapperNode===window&&this.wrapperNode.removeEventListener("resize",this.onWindowResize),this.wrapperNode.removeEventListener("scroll",this.onScroll),this.virtualScroll.destroy(),null==(t=this.wrapperObserver)||t.disconnect(),this.contentObserver.disconnect()},a.raf=function(t){var e=t-(this.now||0);this.now=t,!this.stopped&&this.smooth&&(this.lastScroll=this.scroll,this.animate.raf(.001*e),this.scroll===this.targetScroll&&(this.lastScroll=this.scroll),this.isScrolling&&(this.setScroll(this.scroll),this.notify()),this.isScrolling=this.scroll!==this.targetScroll)},a.setScroll=function(t){"horizontal"===this.direction?this.wrapperNode.scrollTo(t,0):this.wrapperNode.scrollTo(0,t)},a.notify=function(){this.emit("scroll",{scroll:this.scroll,limit:this.limit,velocity:this.velocity,direction:this.direction,progress:this.scroll/this.limit})},a.scrollTo=function(t,e){var o=void 0===e?{}:e,i=o.offset,r=void 0===i?0:i,n=o.immediate,l=void 0!==n&&n,c=o.duration,a=void 0===c?this.duration:c,h=o.easing,p=void 0===h?this.easing:h;if(null!=t){var u;if("number"==typeof t)u=t;else if("top"===t||"#top"===t)u=0;else if("bottom"===t)u=this.limit;else{var d;if("string"==typeof t)d=document.querySelector(t);else{if(null==t||!t.nodeType)return;d=t}if(!d)return;var f=0;if(this.wrapperNode!==window){var v=this.wrapperNode.getBoundingClientRect();f="horizontal"===this.direction?v.left:v.top}var g=d.getBoundingClientRect();u=("horizontal"===this.direction?g.left:g.top)+this.scroll-f}this.targetScroll=s(0,u+=r,this.limit),!this.smooth||l?this.setScroll(this.targetScroll):this.animate.to(this,{duration:a,easing:p,scroll:this.targetScroll})}},i(l,[{key:"scrollProperty",get:function(){return this.wrapperNode===window?"horizontal"===this.direction?"scrollX":"scrollY":"horizontal"===this.direction?"scrollLeft":"scrollTop"}},{key:"limit",get:function(){return"horizontal"===this.direction?this.contentWidth-this.wrapperWidth:this.contentHeight-this.wrapperHeight}},{key:"velocity",get:function(){return this.scroll-this.lastScroll}}]),l}(t);export{a as default}; //# sourceMappingURL=lenis.mjs.map diff --git a/dist/lenis.modern.mjs b/dist/lenis.modern.mjs index 7eb1d070..8350d496 100644 --- a/dist/lenis.modern.mjs +++ b/dist/lenis.modern.mjs @@ -1,2 +1,2 @@ -import t from"tiny-emitter";import i from"virtual-scroll";function e(){return e=Object.assign?Object.assign.bind():function(t){for(var i=1;it)}=i,n=function(t,i){if(null==t)return{};var e,s,r={},o=Object.keys(t);for(s=0;s=0||(r[e]=t[e]);return r}(i,r);this.target=t,this.fromKeys=e({},n),this.toKeys=e({},n),this.keys=Object.keys(e({},n)),this.keys.forEach(i=>{this.fromKeys[i]=t[i]}),this.duration=s,this.easing=o,this.currentTime=0,this.isRunning=!0}stop(){this.isRunning=!1}raf(t){if(!this.isRunning)return;this.currentTime=Math.min(this.currentTime+t,this.duration);const i=this.easing(this.progress);this.keys.forEach(t=>{const e=this.fromKeys[t];this.target[t]=e+(this.toKeys[t]-e)*i}),1===i&&this.stop()}get progress(){return this.currentTime/this.duration}}class n extends t{constructor({duration:t=1.2,easing:e=(t=>1===t?1:1-Math.pow(2,-10*t)),smooth:r=!0,smoothTouch:n=!1,touchMultiplier:h=2,direction:l="vertical",gestureDirection:c="vertical",wrapper:a=window,content:p=document.body}={}){var d,u,g;super(),this.onWindowResize=()=>{this.wrapperWidth=window.innerWidth,this.wrapperHeight=window.innerHeight},this.onWrapperResize=([t])=>{if(t){const i=t.contentRect;this.wrapperWidth=i.width,this.wrapperHeight=i.height}},this.onContentResize=([t])=>{if(t){const i=t.contentRect;this.contentWidth=i.width,this.contentHeight=i.height}},this.onVirtualScroll=({deltaY:t,deltaX:i,originalEvent:e})=>{if(e.ctrlKey)return;if(this.smooth=e.changedTouches?this.smoothTouch:this.options.smooth,this.stopped)return void e.preventDefault();if(!this.smooth)return;if(4===e.buttons)return;this.smooth&&e.preventDefault();let r=0;r="both"===this.gestureDirection?i+t:"horizontal"===this.gestureDirection?i:t,this.targetScroll-=r,this.targetScroll=s(0,this.targetScroll,this.limit),this.scrollTo(this.targetScroll)},this.onScroll=t=>{this.isScrolling&&this.smooth||(this.targetScroll=this.scroll=this.lastScroll=this.wrapperNode[this.scrollProperty],this.notify())},window.lenisVersion="0.2.10",this.options={duration:t,easing:e,smooth:r,smoothTouch:n,touchMultiplier:h,direction:l,gestureDirection:c,wrapper:a,content:p},this.duration=t,this.easing=e,this.smooth=r,this.smoothTouch=n,this.touchMultiplier=h,this.direction=l,this.gestureDirection=c,this.wrapperNode=a,this.contentNode=p,this.wrapperNode.addEventListener("scroll",this.onScroll),this.wrapperNode===window?(this.wrapperNode.addEventListener("resize",this.onWindowResize),this.onWindowResize()):(this.wrapperHeight=this.wrapperNode.offsetHeight,this.wrapperWidth=this.wrapperNode.offsetWidth,this.wrapperObserver=new ResizeObserver(this.onWrapperResize),this.wrapperObserver.observe(this.wrapperNode)),this.contentHeight=this.contentNode.offsetHeight,this.contentWidth=this.contentNode.offsetWidth,this.contentObserver=new ResizeObserver(this.onContentResize),this.contentObserver.observe(this.contentNode),this.targetScroll=this.scroll=this.lastScroll=this.wrapperNode[this.scrollProperty],this.animate=new o;const w=(null==(d=navigator)||null==(u=d.userAgentData)?void 0:u.platform)||(null==(g=navigator)?void 0:g.platform)||"unknown";this.virtualScroll=new i({el:this.wrapperNode,firefoxMultiplier:50,mouseMultiplier:w.includes("Win")?1:.4,useKeyboard:!1,touchMultiplier:this.touchMultiplier,useTouch:!0,passive:!1}),this.virtualScroll.on(this.onVirtualScroll)}get scrollProperty(){let t;return t=this.wrapperNode===window?"horizontal"===this.direction?"scrollX":"scrollY":"horizontal"===this.direction?"scrollLeft":"scrollTop",t}start(){this.stopped=!1}stop(){this.stopped=!0,this.animate.stop()}destroy(){var t;this.wrapperNode===window&&this.wrapperNode.removeEventListener("resize",this.onWindowResize),this.wrapperNode.removeEventListener("scroll",this.onScroll),this.virtualScroll.destroy(),null==(t=this.wrapperObserver)||t.disconnect(),this.contentObserver.disconnect()}get limit(){return"horizontal"===this.direction?this.contentWidth-this.wrapperWidth:this.contentHeight-this.wrapperHeight}raf(t){const i=t-(this.now||0);this.now=t,!this.stopped&&this.smooth&&(this.lastScroll=this.scroll,this.animate.raf(.001*i),this.scroll===this.targetScroll&&(this.lastScroll=this.scroll),this.isScrolling&&(this.setScroll(this.scroll),this.notify()),this.isScrolling=this.scroll!==this.targetScroll)}get velocity(){return this.scroll-this.lastScroll}setScroll(t){"horizontal"===this.direction?this.wrapperNode.scrollTo(t,0):this.wrapperNode.scrollTo(0,t)}notify(){this.emit("scroll",{scroll:this.scroll,limit:this.limit,velocity:this.velocity,direction:this.direction,progress:this.scroll/this.limit})}scrollTo(t,{offset:i=0,immediate:e=!1,duration:r=this.duration,easing:o=this.easing}={}){if(null==t)return;let n;if("number"==typeof t)n=t;else if("top"===t||"#top"===t)n=0;else if("bottom"===t)n=this.limit;else{let i;if("string"==typeof t)i=document.querySelector(t);else{if(null==t||!t.nodeType)return;i=t}if(!i)return;let e=0;if(this.wrapperNode!==window){const t=this.wrapperNode.getBoundingClientRect();e="horizontal"===this.direction?t.left:t.top}const s=i.getBoundingClientRect();n=("horizontal"===this.direction?s.left:s.top)+this.scroll-e}n+=i,this.targetScroll=s(0,n,this.limit),!this.smooth||e?this.setScroll(this.targetScroll):this.animate.to(this,{duration:r,easing:o,scroll:this.targetScroll})}}export{n as default}; +import t from"tiny-emitter";import i from"virtual-scroll";function e(){return e=Object.assign?Object.assign.bind():function(t){for(var i=1;it)}=i,n=function(t,i){if(null==t)return{};var e,s,r={},o=Object.keys(t);for(s=0;s=0||(r[e]=t[e]);return r}(i,r);this.target=t,this.fromKeys=e({},n),this.toKeys=e({},n),this.keys=Object.keys(e({},n)),this.keys.forEach(i=>{this.fromKeys[i]=t[i]}),this.duration=s,this.easing=o,this.currentTime=0,this.isRunning=!0}stop(){this.isRunning=!1}raf(t){if(!this.isRunning)return;this.currentTime=Math.min(this.currentTime+t,this.duration);const i=this.easing(this.progress);this.keys.forEach(t=>{const e=this.fromKeys[t];this.target[t]=e+(this.toKeys[t]-e)*i}),1===i&&this.stop()}get progress(){return this.currentTime/this.duration}}class n extends t{constructor({duration:t=1.2,easing:e=(t=>1===t?1:1-Math.pow(2,-10*t)),smooth:r=!0,smoothTouch:n=!1,touchMultiplier:h=2,direction:l="vertical",gestureDirection:c="vertical",wrapper:a=window,content:p=document.body}={}){var d,u,g;super(),this.onWindowResize=()=>{this.wrapperWidth=window.innerWidth,this.wrapperHeight=window.innerHeight},this.onWrapperResize=([t])=>{if(t){const i=t.contentRect;this.wrapperWidth=i.width,this.wrapperHeight=i.height}},this.onContentResize=([t])=>{if(t){const i=t.contentRect;this.contentWidth=i.width,this.contentHeight=i.height}},this.onVirtualScroll=({deltaY:t,deltaX:i,originalEvent:e})=>{if(e.ctrlKey)return;if(this.smooth=e.changedTouches?this.smoothTouch:this.options.smooth,this.stopped)return void e.preventDefault();if(!this.smooth)return;if(4===e.buttons)return;this.smooth&&e.preventDefault();let r=0;r="both"===this.gestureDirection?i+t:"horizontal"===this.gestureDirection?i:t,this.targetScroll-=r,this.targetScroll=s(0,this.targetScroll,this.limit),this.scrollTo(this.targetScroll)},this.onScroll=t=>{this.isScrolling&&this.smooth||(this.targetScroll=this.scroll=this.lastScroll=this.wrapperNode[this.scrollProperty],this.notify())},window.lenisVersion="0.2.11",this.options={duration:t,easing:e,smooth:r,smoothTouch:n,touchMultiplier:h,direction:l,gestureDirection:c,wrapper:a,content:p},this.duration=t,this.easing=e,this.smooth=r,this.smoothTouch=n,this.touchMultiplier=h,this.direction=l,this.gestureDirection=c,this.wrapperNode=a,this.contentNode=p,this.wrapperNode.addEventListener("scroll",this.onScroll),this.wrapperNode===window?(this.wrapperNode.addEventListener("resize",this.onWindowResize),this.onWindowResize()):(this.wrapperHeight=this.wrapperNode.offsetHeight,this.wrapperWidth=this.wrapperNode.offsetWidth,this.wrapperObserver=new ResizeObserver(this.onWrapperResize),this.wrapperObserver.observe(this.wrapperNode)),this.contentHeight=this.contentNode.offsetHeight,this.contentWidth=this.contentNode.offsetWidth,this.contentObserver=new ResizeObserver(this.onContentResize),this.contentObserver.observe(this.contentNode),this.targetScroll=this.scroll=this.lastScroll=this.wrapperNode[this.scrollProperty],this.animate=new o;const w=(null==(d=navigator)||null==(u=d.userAgentData)?void 0:u.platform)||(null==(g=navigator)?void 0:g.platform)||"unknown";this.virtualScroll=new i({el:this.wrapperNode,firefoxMultiplier:50,mouseMultiplier:w.includes("Win")?1:.4,useKeyboard:!1,touchMultiplier:this.touchMultiplier,useTouch:!0,passive:!1}),this.virtualScroll.on(this.onVirtualScroll)}get scrollProperty(){let t;return t=this.wrapperNode===window?"horizontal"===this.direction?"scrollX":"scrollY":"horizontal"===this.direction?"scrollLeft":"scrollTop",t}start(){this.stopped=!1}stop(){this.stopped=!0,this.animate.stop()}destroy(){var t;this.wrapperNode===window&&this.wrapperNode.removeEventListener("resize",this.onWindowResize),this.wrapperNode.removeEventListener("scroll",this.onScroll),this.virtualScroll.destroy(),null==(t=this.wrapperObserver)||t.disconnect(),this.contentObserver.disconnect()}get limit(){return"horizontal"===this.direction?this.contentWidth-this.wrapperWidth:this.contentHeight-this.wrapperHeight}raf(t){const i=t-(this.now||0);this.now=t,!this.stopped&&this.smooth&&(this.lastScroll=this.scroll,this.animate.raf(.001*i),this.scroll===this.targetScroll&&(this.lastScroll=this.scroll),this.isScrolling&&(this.setScroll(this.scroll),this.notify()),this.isScrolling=this.scroll!==this.targetScroll)}get velocity(){return this.scroll-this.lastScroll}setScroll(t){"horizontal"===this.direction?this.wrapperNode.scrollTo(t,0):this.wrapperNode.scrollTo(0,t)}notify(){this.emit("scroll",{scroll:this.scroll,limit:this.limit,velocity:this.velocity,direction:this.direction,progress:this.scroll/this.limit})}scrollTo(t,{offset:i=0,immediate:e=!1,duration:r=this.duration,easing:o=this.easing}={}){if(null==t)return;let n;if("number"==typeof t)n=t;else if("top"===t||"#top"===t)n=0;else if("bottom"===t)n=this.limit;else{let i;if("string"==typeof t)i=document.querySelector(t);else{if(null==t||!t.nodeType)return;i=t}if(!i)return;let e=0;if(this.wrapperNode!==window){const t=this.wrapperNode.getBoundingClientRect();e="horizontal"===this.direction?t.left:t.top}const s=i.getBoundingClientRect();n=("horizontal"===this.direction?s.left:s.top)+this.scroll-e}n+=i,this.targetScroll=s(0,n,this.limit),!this.smooth||e?this.setScroll(this.targetScroll):this.animate.to(this,{duration:r,easing:o,scroll:this.targetScroll})}}export{n as default}; //# sourceMappingURL=lenis.modern.mjs.map diff --git a/dist/lenis.umd.js b/dist/lenis.umd.js index f489606e..90fa47d7 100644 --- a/dist/lenis.umd.js +++ b/dist/lenis.umd.js @@ -1,3 +1,3 @@ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("tiny-emitter"),require("virtual-scroll")):"function"==typeof define&&define.amd?define(["tiny-emitter","virtual-scroll"],e):(t||self).lenis=e(t.tinyEmitter,t.virtualScroll)}(this,function(t,e){function i(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var o=/*#__PURE__*/i(t),r=/*#__PURE__*/i(e);function n(t,e){for(var i=0;i=0||(r[i]=t[i]);return r}(o,h);this.target=t,this.fromKeys=l({},a),this.toKeys=l({},a),this.keys=Object.keys(l({},a)),this.keys.forEach(function(e){i.fromKeys[e]=t[e]}),this.duration=n,this.easing=c,this.currentTime=0,this.isRunning=!0},e.stop=function(){this.isRunning=!1},e.raf=function(t){var e=this;if(this.isRunning){this.currentTime=Math.min(this.currentTime+t,this.duration);var i=this.easing(this.progress);this.keys.forEach(function(t){var o=e.fromKeys[t];e.target[t]=o+(e.toKeys[t]-o)*i}),1===i&&this.stop()}},s(t,[{key:"progress",get:function(){return this.currentTime/this.duration}}]),t}();/*#__PURE__*/ -return function(t){var e,i;function o(e){var i,o,n,s,l=void 0===e?{}:e,c=l.duration,h=void 0===c?1.2:c,p=l.easing,d=void 0===p?function(t){return 1===t?1:1-Math.pow(2,-10*t)}:p,f=l.smooth,v=void 0===f||f,g=l.smoothTouch,w=void 0!==g&&g,m=l.touchMultiplier,y=void 0===m?2:m,b=l.direction,S=void 0===b?"vertical":b,N=l.gestureDirection,O=void 0===N?"vertical":N,z=l.wrapper,T=void 0===z?window:z,R=l.content,W=void 0===R?document.body:R;(s=t.call(this)||this).onWindowResize=function(){s.wrapperWidth=window.innerWidth,s.wrapperHeight=window.innerHeight},s.onWrapperResize=function(t){var e=t[0];if(e){var i=e.contentRect;s.wrapperWidth=i.width,s.wrapperHeight=i.height}},s.onContentResize=function(t){var e=t[0];if(e){var i=e.contentRect;s.contentWidth=i.width,s.contentHeight=i.height}},s.onVirtualScroll=function(t){var e=t.deltaY,i=t.deltaX,o=t.originalEvent;o.ctrlKey||(s.smooth=o.changedTouches?s.smoothTouch:s.options.smooth,s.stopped?o.preventDefault():s.smooth&&4!==o.buttons&&(s.smooth&&o.preventDefault(),s.targetScroll-="both"===s.gestureDirection?i+e:"horizontal"===s.gestureDirection?i:e,s.targetScroll=a(0,s.targetScroll,s.limit),s.scrollTo(s.targetScroll)))},s.onScroll=function(t){s.isScrolling&&s.smooth||(s.targetScroll=s.scroll=s.lastScroll=s.wrapperNode[s.scrollProperty],s.notify())},window.lenisVersion="0.2.10",s.options={duration:h,easing:d,smooth:v,smoothTouch:w,touchMultiplier:y,direction:S,gestureDirection:O,wrapper:T,content:W},s.duration=h,s.easing=d,s.smooth=v,s.smoothTouch=w,s.touchMultiplier=y,s.direction=S,s.gestureDirection=O,s.wrapperNode=T,s.contentNode=W,s.wrapperNode.addEventListener("scroll",s.onScroll),s.wrapperNode===window?(s.wrapperNode.addEventListener("resize",s.onWindowResize),s.onWindowResize()):(s.wrapperHeight=s.wrapperNode.offsetHeight,s.wrapperWidth=s.wrapperNode.offsetWidth,s.wrapperObserver=new ResizeObserver(s.onWrapperResize),s.wrapperObserver.observe(s.wrapperNode)),s.contentHeight=s.contentNode.offsetHeight,s.contentWidth=s.contentNode.offsetWidth,s.contentObserver=new ResizeObserver(s.onContentResize),s.contentObserver.observe(s.contentNode),s.targetScroll=s.scroll=s.lastScroll=s.wrapperNode[s.scrollProperty],s.animate=new u;var j=(null==(i=navigator)||null==(o=i.userAgentData)?void 0:o.platform)||(null==(n=navigator)?void 0:n.platform)||"unknown";return s.virtualScroll=new r.default({el:s.wrapperNode,firefoxMultiplier:50,mouseMultiplier:j.includes("Win")?1:.4,useKeyboard:!1,touchMultiplier:s.touchMultiplier,useTouch:!0,passive:!1}),s.virtualScroll.on(s.onVirtualScroll),s}i=t,(e=o).prototype=Object.create(i.prototype),e.prototype.constructor=e,c(e,i);var n=o.prototype;return n.start=function(){this.stopped=!1},n.stop=function(){this.stopped=!0,this.animate.stop()},n.destroy=function(){var t;this.wrapperNode===window&&this.wrapperNode.removeEventListener("resize",this.onWindowResize),this.wrapperNode.removeEventListener("scroll",this.onScroll),this.virtualScroll.destroy(),null==(t=this.wrapperObserver)||t.disconnect(),this.contentObserver.disconnect()},n.raf=function(t){var e=t-(this.now||0);this.now=t,!this.stopped&&this.smooth&&(this.lastScroll=this.scroll,this.animate.raf(.001*e),this.scroll===this.targetScroll&&(this.lastScroll=this.scroll),this.isScrolling&&(this.setScroll(this.scroll),this.notify()),this.isScrolling=this.scroll!==this.targetScroll)},n.setScroll=function(t){"horizontal"===this.direction?this.wrapperNode.scrollTo(t,0):this.wrapperNode.scrollTo(0,t)},n.notify=function(){this.emit("scroll",{scroll:this.scroll,limit:this.limit,velocity:this.velocity,direction:this.direction,progress:this.scroll/this.limit})},n.scrollTo=function(t,e){var i=void 0===e?{}:e,o=i.offset,r=void 0===o?0:o,n=i.immediate,s=void 0!==n&&n,l=i.duration,c=void 0===l?this.duration:l,h=i.easing,u=void 0===h?this.easing:h;if(null!=t){var p;if("number"==typeof t)p=t;else if("top"===t||"#top"===t)p=0;else if("bottom"===t)p=this.limit;else{var d;if("string"==typeof t)d=document.querySelector(t);else{if(null==t||!t.nodeType)return;d=t}if(!d)return;var f=0;if(this.wrapperNode!==window){var v=this.wrapperNode.getBoundingClientRect();f="horizontal"===this.direction?v.left:v.top}var g=d.getBoundingClientRect();p=("horizontal"===this.direction?g.left:g.top)+this.scroll-f}this.targetScroll=a(0,p+=r,this.limit),!this.smooth||s?this.setScroll(this.targetScroll):this.animate.to(this,{duration:c,easing:u,scroll:this.targetScroll})}},s(o,[{key:"scrollProperty",get:function(){return this.wrapperNode===window?"horizontal"===this.direction?"scrollX":"scrollY":"horizontal"===this.direction?"scrollLeft":"scrollTop"}},{key:"limit",get:function(){return"horizontal"===this.direction?this.contentWidth-this.wrapperWidth:this.contentHeight-this.wrapperHeight}},{key:"velocity",get:function(){return this.scroll-this.lastScroll}}]),o}(o.default)}); +return function(t){var e,i;function o(e){var i,o,n,s,l=void 0===e?{}:e,c=l.duration,h=void 0===c?1.2:c,p=l.easing,d=void 0===p?function(t){return 1===t?1:1-Math.pow(2,-10*t)}:p,f=l.smooth,v=void 0===f||f,g=l.smoothTouch,w=void 0!==g&&g,m=l.touchMultiplier,y=void 0===m?2:m,b=l.direction,S=void 0===b?"vertical":b,N=l.gestureDirection,O=void 0===N?"vertical":N,z=l.wrapper,T=void 0===z?window:z,R=l.content,W=void 0===R?document.body:R;(s=t.call(this)||this).onWindowResize=function(){s.wrapperWidth=window.innerWidth,s.wrapperHeight=window.innerHeight},s.onWrapperResize=function(t){var e=t[0];if(e){var i=e.contentRect;s.wrapperWidth=i.width,s.wrapperHeight=i.height}},s.onContentResize=function(t){var e=t[0];if(e){var i=e.contentRect;s.contentWidth=i.width,s.contentHeight=i.height}},s.onVirtualScroll=function(t){var e=t.deltaY,i=t.deltaX,o=t.originalEvent;o.ctrlKey||(s.smooth=o.changedTouches?s.smoothTouch:s.options.smooth,s.stopped?o.preventDefault():s.smooth&&4!==o.buttons&&(s.smooth&&o.preventDefault(),s.targetScroll-="both"===s.gestureDirection?i+e:"horizontal"===s.gestureDirection?i:e,s.targetScroll=a(0,s.targetScroll,s.limit),s.scrollTo(s.targetScroll)))},s.onScroll=function(t){s.isScrolling&&s.smooth||(s.targetScroll=s.scroll=s.lastScroll=s.wrapperNode[s.scrollProperty],s.notify())},window.lenisVersion="0.2.11",s.options={duration:h,easing:d,smooth:v,smoothTouch:w,touchMultiplier:y,direction:S,gestureDirection:O,wrapper:T,content:W},s.duration=h,s.easing=d,s.smooth=v,s.smoothTouch=w,s.touchMultiplier=y,s.direction=S,s.gestureDirection=O,s.wrapperNode=T,s.contentNode=W,s.wrapperNode.addEventListener("scroll",s.onScroll),s.wrapperNode===window?(s.wrapperNode.addEventListener("resize",s.onWindowResize),s.onWindowResize()):(s.wrapperHeight=s.wrapperNode.offsetHeight,s.wrapperWidth=s.wrapperNode.offsetWidth,s.wrapperObserver=new ResizeObserver(s.onWrapperResize),s.wrapperObserver.observe(s.wrapperNode)),s.contentHeight=s.contentNode.offsetHeight,s.contentWidth=s.contentNode.offsetWidth,s.contentObserver=new ResizeObserver(s.onContentResize),s.contentObserver.observe(s.contentNode),s.targetScroll=s.scroll=s.lastScroll=s.wrapperNode[s.scrollProperty],s.animate=new u;var j=(null==(i=navigator)||null==(o=i.userAgentData)?void 0:o.platform)||(null==(n=navigator)?void 0:n.platform)||"unknown";return s.virtualScroll=new r.default({el:s.wrapperNode,firefoxMultiplier:50,mouseMultiplier:j.includes("Win")?1:.4,useKeyboard:!1,touchMultiplier:s.touchMultiplier,useTouch:!0,passive:!1}),s.virtualScroll.on(s.onVirtualScroll),s}i=t,(e=o).prototype=Object.create(i.prototype),e.prototype.constructor=e,c(e,i);var n=o.prototype;return n.start=function(){this.stopped=!1},n.stop=function(){this.stopped=!0,this.animate.stop()},n.destroy=function(){var t;this.wrapperNode===window&&this.wrapperNode.removeEventListener("resize",this.onWindowResize),this.wrapperNode.removeEventListener("scroll",this.onScroll),this.virtualScroll.destroy(),null==(t=this.wrapperObserver)||t.disconnect(),this.contentObserver.disconnect()},n.raf=function(t){var e=t-(this.now||0);this.now=t,!this.stopped&&this.smooth&&(this.lastScroll=this.scroll,this.animate.raf(.001*e),this.scroll===this.targetScroll&&(this.lastScroll=this.scroll),this.isScrolling&&(this.setScroll(this.scroll),this.notify()),this.isScrolling=this.scroll!==this.targetScroll)},n.setScroll=function(t){"horizontal"===this.direction?this.wrapperNode.scrollTo(t,0):this.wrapperNode.scrollTo(0,t)},n.notify=function(){this.emit("scroll",{scroll:this.scroll,limit:this.limit,velocity:this.velocity,direction:this.direction,progress:this.scroll/this.limit})},n.scrollTo=function(t,e){var i=void 0===e?{}:e,o=i.offset,r=void 0===o?0:o,n=i.immediate,s=void 0!==n&&n,l=i.duration,c=void 0===l?this.duration:l,h=i.easing,u=void 0===h?this.easing:h;if(null!=t){var p;if("number"==typeof t)p=t;else if("top"===t||"#top"===t)p=0;else if("bottom"===t)p=this.limit;else{var d;if("string"==typeof t)d=document.querySelector(t);else{if(null==t||!t.nodeType)return;d=t}if(!d)return;var f=0;if(this.wrapperNode!==window){var v=this.wrapperNode.getBoundingClientRect();f="horizontal"===this.direction?v.left:v.top}var g=d.getBoundingClientRect();p=("horizontal"===this.direction?g.left:g.top)+this.scroll-f}this.targetScroll=a(0,p+=r,this.limit),!this.smooth||s?this.setScroll(this.targetScroll):this.animate.to(this,{duration:c,easing:u,scroll:this.targetScroll})}},s(o,[{key:"scrollProperty",get:function(){return this.wrapperNode===window?"horizontal"===this.direction?"scrollX":"scrollY":"horizontal"===this.direction?"scrollLeft":"scrollTop"}},{key:"limit",get:function(){return"horizontal"===this.direction?this.contentWidth-this.wrapperWidth:this.contentHeight-this.wrapperHeight}},{key:"velocity",get:function(){return this.scroll-this.lastScroll}}]),o}(o.default)}); //# sourceMappingURL=lenis.umd.js.map diff --git a/package.json b/package.json index cd753271..2d679d18 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@studio-freight/lenis", - "version": "0.2.10", + "version": "0.2.11", "description": "Lenis is a smooth scroll library to normalize the scrolling experience across devices", "files": [ "dist"