Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sweet-scroll

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sweet-scroll - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

2

package.json
{
"name": "sweet-scroll",
"version": "0.0.1",
"version": "0.0.2",
"description": "Modern and the sweet smooth scroll library.",

@@ -5,0 +5,0 @@ "main": "sweet-scroll.js",

@@ -86,3 +86,2 @@ sweet-scroll.js

stopScroll: true, // When fired wheel or touchstart events to stop scrolling
stopPropagation: true, // Stop the bubbling of trigger element click events

@@ -89,0 +88,0 @@ // Callbacks

@@ -8,3 +8,3 @@ /*!

* @license MIT
* @version 0.0.1
* @version 0.0.2
*/

@@ -834,3 +834,3 @@ (function (global, factory) {

} else {
e.stopPropagation();
e.preventDefault();
}

@@ -854,3 +854,3 @@ }

e.preventDefault();
if (options.stopPropagation) e.stopPropagation();
e.stopPropagation();

@@ -886,3 +886,2 @@ if (options.horizontalScroll && options.verticalScroll) {

stopScroll: true,
stopPropagation: true,
beforeScroll: null,

@@ -889,0 +888,0 @@ afterScroll: null,

@@ -8,4 +8,4 @@ /*!

* @license MIT
* @version 0.0.1
* @version 0.0.2
*/
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.SweetScroll=e()}(this,function(){"use strict";function t(t){return null==t?t+"":"object"===("undefined"==typeof t?"undefined":Z["typeof"](t))||"function"==typeof t?nt[Object.prototype.toString.call(t)]||"object":"undefined"==typeof t?"undefined":Z["typeof"](t)}function e(t){return Array.isArray(t)}function n(t){var e=null==t?null:t.length;return i(e)&&e>=0&&tt>=e}function r(n){return!e(n)&&"object"===t(n)}function i(e){return"number"===t(e)}function o(e){return"string"===t(e)}function a(e){return"function"===t(e)}function s(t){return!e(t)&&t-parseFloat(t)+1>=0}function u(t,e){return t&&Object.prototype.hasOwnProperty.call(t,e)}function l(t){for(var e=arguments.length,n=Array(e>1?e-1:0),r=1;e>r;r++)n[r-1]=arguments[r];return c(n,function(e){c(e,function(e,n){t[n]=e})}),t}function c(t,e,i){if(null==t)return t;if(i=i||t,r(t)){for(var o in t)if(u(t,o)&&e.call(i,t[o],o)===!1)break}else if(n(t)){var a=void 0,s=t.length;for(a=0;s>a&&e.call(i,t[a],a)!==!1;a++);}return t}function h(t){return t.replace(/\s*/g,"")||""}function f(t){var e=arguments.length<=1||void 0===arguments[1]?null:arguments[1];if(t)return(null==e?document:e).querySelector(t)}function p(t){var e=arguments.length<=1||void 0===arguments[1]?null:arguments[1];if(t)return(null==e?document:e).querySelectorAll(t)}function g(t,e){for(var n=(t.document||t.ownerDocument).querySelectorAll(e),r=n.length;--r>=0&&n.item(r)!==t;);return r>-1}function d(t){var e=document;return t===e.documentElement||t===e.body}function v(t){for(var e=arguments.length<=1||void 0===arguments[1]?"y":arguments[1],n=arguments.length<=2||void 0===arguments[2]?!0:arguments[2],r=rt[e],i=p(t),o=[],a=0;a<i.length;a++){var s=i[a];if(s[r]>0?o.push(s):(s[r]=1,s[r]>0&&o.push(s),s[r]=0),!n&&o.length>0)break}return o}function m(t,e){var n=v(t,e,!1);return n.length>=1?n[0]:void 0}function y(t){return null!=t&&t===t.window?t:9===t.nodeType&&t.defaultView}function S(t){var e=arguments.length<=1||void 0===arguments[1]?"y":arguments[1],n=rt[e],r=it[e],i=y(t);return i?i[r]:t[n]}function b(t,e){var n=arguments.length<=2||void 0===arguments[2]?"y":arguments[2],r=rt[n],i=y(t),o="y"===n;i?i.scrollTo(o?i.pageXOffset:e,o?e:i.pageYOffset):t[r]=e}function w(t){var e=arguments.length<=1||void 0===arguments[1]?null:arguments[1];if(!t||t&&!t.getClientRects().length)return{top:0,left:0};var n=t.getBoundingClientRect();if(n.width||n.height){var r={},i=void 0;if(null==e||d(e))i=t.ownerDocument.documentElement,r.top=window.pageYOffset,r.left=window.pageXOffset;else{i=e;var o=i.getBoundingClientRect();r.top=-1*o.top+i.scrollTop,r.left=-1*o.left+i.scrollLeft}return{top:n.top+r.top-i.clientTop,left:n.left+r.left-i.clientLeft}}return n}function k(t){return t}function C(t,e,n,r,i){return r*(e/=i)*e+n}function M(t,e,n,r,i){return-r*(e/=i)*(e-2)+n}function _(t,e,n,r,i){return(e/=i/2)<1?r/2*e*e+n:-r/2*(--e*(e-2)-1)+n}function O(t,e,n,r,i){return r*(e/=i)*e*e+n}function I(t,e,n,r,i){return r*((e=e/i-1)*e*e+1)+n}function L(t,e,n,r,i){return(e/=i/2)<1?r/2*e*e*e+n:r/2*((e-=2)*e*e+2)+n}function E(t,e,n,r,i){return r*(e/=i)*e*e*e+n}function P(t,e,n,r,i){return-r*((e=e/i-1)*e*e*e-1)+n}function x(t,e,n,r,i){return(e/=i/2)<1?r/2*e*e*e*e+n:-r/2*((e-=2)*e*e*e-2)+n}function T(t,e,n,r,i){return r*(e/=i)*e*e*e*e+n}function A(t,e,n,r,i){return r*((e=e/i-1)*e*e*e*e+1)+n}function j(t,e,n,r,i){return(e/=i/2)<1?r/2*e*e*e*e*e+n:r/2*((e-=2)*e*e*e*e+2)+n}function q(t,e,n,r,i){return-r*Math.cos(e/i*(Math.PI/2))+r+n}function Q(t,e,n,r,i){return r*Math.sin(e/i*(Math.PI/2))+n}function B(t,e,n,r,i){return-r/2*(Math.cos(Math.PI*e/i)-1)+n}function z(t,e,n,r,i){return 0===e?n:r*Math.pow(2,10*(e/i-1))+n}function D(t,e,n,r,i){return e===i?n+r:r*(-Math.pow(2,-10*e/i)+1)+n}function R(t,e,n,r,i){return 0===e?n:e===i?n+r:(e/=i/2)<1?r/2*Math.pow(2,10*(e-1))+n:r/2*(-Math.pow(2,-10*--e)+2)+n}function F(t,e,n,r,i){return-r*(Math.sqrt(1-(e/=i)*e)-1)+n}function H(t,e,n,r,i){return r*Math.sqrt(1-(e=e/i-1)*e)+n}function W(t,e,n,r,i){return(e/=i/2)<1?-r/2*(Math.sqrt(1-e*e)-1)+n:r/2*(Math.sqrt(1-(e-=2)*e)+1)+n}function $(t,e,n,r,i){var o=1.70158,a=0,s=r;return 0===e?n:1===(e/=i)?n+r:(a||(a=.3*i),s<Math.abs(r)?(s=r,o=a/4):o=a/(2*Math.PI)*Math.asin(r/s),-(s*Math.pow(2,10*(e-=1))*Math.sin((e*i-o)*(2*Math.PI)/a))+n)}function N(t,e,n,r,i){var o=1.70158,a=0,s=r;return 0===e?n:1===(e/=i)?n+r:(a||(a=.3*i),s<Math.abs(r)?(s=r,o=a/4):o=a/(2*Math.PI)*Math.asin(r/s),s*Math.pow(2,-10*e)*Math.sin((e*i-o)*(2*Math.PI)/a)+r+n)}function X(t,e,n,r,i){var o=1.70158,a=0,s=r;return 0===e?n:2===(e/=i/2)?n+r:(a||(a=i*(.3*1.5)),s<Math.abs(r)?(s=r,o=a/4):o=a/(2*Math.PI)*Math.asin(r/s),1>e?-.5*(s*Math.pow(2,10*(e-=1))*Math.sin((e*i-o)*(2*Math.PI)/a))+n:s*Math.pow(2,-10*(e-=1))*Math.sin((e*i-o)*(2*Math.PI)/a)*.5+r+n)}function Y(t,e,n,r,i){var o=arguments.length<=5||void 0===arguments[5]?1.70158:arguments[5];return r*(e/=i)*e*((o+1)*e-o)+n}function J(t,e,n,r,i){var o=arguments.length<=5||void 0===arguments[5]?1.70158:arguments[5];return r*((e=e/i-1)*e*((o+1)*e+o)+1)+n}function V(t,e,n,r,i){var o=arguments.length<=5||void 0===arguments[5]?1.70158:arguments[5];return(e/=i/2)<1?r/2*(e*e*(((o*=1.525)+1)*e-o))+n:r/2*((e-=2)*e*(((o*=1.525)+1)*e+o)+2)+n}function G(t,e,n,r,i){return r-K(t,i-e,0,r,i)+n}function K(t,e,n,r,i){return(e/=i)<1/2.75?r*(7.5625*e*e)+n:2/2.75>e?r*(7.5625*(e-=1.5/2.75)*e+.75)+n:2.5/2.75>e?r*(7.5625*(e-=2.25/2.75)*e+.9375)+n:r*(7.5625*(e-=2.625/2.75)*e+.984375)+n}function U(t,e,n,r,i){return i/2>e?.5*G(t,2*e,0,r,i)+n:.5*K(t,2*e-i,0,r,i)+.5*r+n}var Z={};Z["typeof"]=function(t){return t&&"undefined"!=typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},Z.classCallCheck=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},Z.createClass=function(){function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}}();var tt=Math.pow(2,53)-1,et=["Boolean","Number","String","Function","Array","Date","RegExp","Object","Error","Symbol"],nt={};et.forEach(function(t){nt["[object "+t+"]"]=t.toLowerCase()});var rt={y:"scrollTop",x:"scrollLeft"},it={y:"pageYOffset",x:"pageXOffset"},ot=0,at=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(t){var e=Date.now(),n=Math.max(0,16-(e-ot)),r=window.setTimeout(function(){t(e+n)},n);return ot=e+n,r},st=Object.freeze({linear:k,easeInQuad:C,easeOutQuad:M,easeInOutQuad:_,easeInCubic:O,easeOutCubic:I,easeInOutCubic:L,easeInQuart:E,easeOutQuart:P,easeInOutQuart:x,easeInQuint:T,easeOutQuint:A,easeInOutQuint:j,easeInSine:q,easeOutSine:Q,easeInOutSine:B,easeInExpo:z,easeOutExpo:D,easeInOutExpo:R,easeInCirc:F,easeOutCirc:H,easeInOutCirc:W,easeInElastic:$,easeOutElastic:N,easeInOutElastic:X,easeInBack:Y,easeOutBack:J,easeInOutBack:V,easeInBounce:G,easeOutBounce:K,easeInOutBounce:U}),ut=function(){function t(e){Z.classCallCheck(this,t),this.el=e,this.props={},this.progress=!1,this.startTime=null}return Z.createClass(t,[{key:"run",value:function(t,e,n,r,i){var o=this,a=arguments.length<=5||void 0===arguments[5]?function(){}:arguments[5];this.progress||(this.props={x:t,y:e},this.duration=n,this.delay=r,this.easing=i,this.callback=a,this.progress=!0,setTimeout(function(){o.startProps={x:S(o.el,"x"),y:S(o.el,"y")},at(function(t){return o._loop(t)})},r))}},{key:"stop",value:function(){var t=arguments.length<=0||void 0===arguments[0]?!0:arguments[0];this.startTime=null,this.progress=!1,t&&(b(this.el,this.props.x,"x"),b(this.el,this.props.y,"y")),a(this.callback)&&(this.callback(),this.callback=null)}},{key:"_loop",value:function(t){var e=this;if(this.startTime||(this.startTime=t),!this.progress)return void this.stop(!1);var n=this.el,r=this.props,i=this.duration,o=this.startTime,a=this.startProps,s={},u=st[this.easing],l=t-o,h=Math.min(1,Math.max(l/i,0));c(r,function(t,e){var n=a[e],r=t-n;if(0===r)return!0;var o=u(h,i*h,0,1,i);s[e]=Math.round(n+r*o)}),c(s,function(t,e){b(n,t,e)}),i>=l?at(function(t){return e._loop(t)}):this.stop(!0)}}]),t}(),lt=document,ct=window,ht="onwheel"in lt?"wheel":"onmousewheel"in lt?"mousewheel":"DOMMouseScroll",ft=function(){function t(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],n=arguments.length<=1||void 0===arguments[1]?"body, html":arguments[1];Z.classCallCheck(this,t),this.options=l({},t.defaults,e),this.container=m(n),this.header=f(this.options.header),this.el=p(this.options.trigger),this.tween=new ut(this.container),this._bindContainerClick()}return Z.createClass(t,[{key:"to",value:function(t){var e=this,n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];this.stop();var r=this.container,i=l({},this.options,n),a=this._parseCoodinate(i.offset),s=this._parseCoodinate(t);if(r){if(!s&&o(t))if("#"===t)s={top:0,left:0};else if(!/[:,]/.test(t)){var u=f(t),c=w(u,r);if(!c)return;s=c}if(s){a&&(s.top+=a.top,s.left+=a.left),this.header&&(s.top-=this.header.clientHeight);var h=void 0,p=void 0;d(r)?(h={width:ct.innerWidth,height:ct.innerHeight},p={width:lt.body.scrollWidth,height:lt.body.scrollHeight}):(h={width:r.clientWidth,height:r.clientHeight},p={width:r.scrollWidth,height:r.scrollHeight}),i.verticalScroll?s.top=s.top+h.height>p.height?p.height-h.height:s.top:s.top=S(r,"y"),i.horizontalScroll?s.left=s.left+h.width>p.width?p.width-h.width:s.left:s.left=S(r,"x"),this._hook(i.beforeScroll,s)!==!1&&(this.tween.run(s.left,s.top,i.duration,i.delay,i.easing,function(){e._unbindContainerStop(),e._hook(i.afterScroll,s)}),this._bindContainerStop())}}}},{key:"toTop",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];this.to(t,l({},e,{verticalScroll:!0,horizontalScroll:!1}))}},{key:"toLeft",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];this.to(t,l({},e,{verticalScroll:!1,horizontalScroll:!0}))}},{key:"stop",value:function(){var t=arguments.length<=0||void 0===arguments[0]?!1:arguments[0];this.tween.stop(t)}},{key:"destroy",value:function(){this.stop(),this._unbindContainerClick(),this._unbindContainerStop()}},{key:"_bindContainerClick",value:function(){this.container&&(this._containerClickListener=this._handleContainerClick.bind(this),this.container.addEventListener("click",this._containerClickListener,!1))}},{key:"_unbindContainerClick",value:function(){this.container&&this._containerClickListener&&(this.container.removeEventListener("click",this._containerClickListener,!1),this._containerClickListener=null)}},{key:"_bindContainerStop",value:function(){if(this.container){var t=this.container;this._stopScrollListener=this._handleStopScroll.bind(this),t.addEventListener(ht,this._stopScrollListener,!1),t.addEventListener("touchstart",this._stopScrollListener,!1),t.addEventListener("touchmove",this._stopScrollListener,!1)}}},{key:"_unbindContainerStop",value:function(){if(this.container&&this._stopScrollListener){var t=this.container;t.removeEventListener(ht,this._stopScrollListener,!1),t.removeEventListener("touchstart",this._stopScrollListener,!1),t.removeEventListener("touchmove",this._stopScrollListener,!1),this._stopScrollListener=null}}},{key:"_hook",value:function(t){if(a(t)){for(var e=arguments.length,n=Array(e>1?e-1:0),r=1;e>r;r++)n[r-1]=arguments[r];return t.apply(this,n)}}},{key:"_parseCoodinate",value:function(t){var n=this.options.verticalScroll,r={top:0,left:0};if(u(t,"top")||u(t,"left"))r=l(r,t);else if(e(t))2===t.length?(r.top=t[0],r.left=t[1]):(r.top=n?t[0]:0,r.left=n?0:t[0]);else if(s(t))r.top=n?t:0,r.left=n?0:t;else{if(!o(t))return null;if(t=h(t),/^\d+,\d+$/.test(t))t=t.split(","),r.top=t[0],r.left=t[1];else if(/^(top|left):\d+,?(?:(top|left):\d+)?$/.test(t)){var i=t.match(/top:(\d+)/),a=t.match(/left:(\d+)/);r.top=i?i[1]:0,r.left=a?a[1]:0}else{if(!/^(\+|-)=(\d+)$/.test(t))return null;var c=S(this.container,n?"y":"x"),f=t.match(/^(\+|-)\=(\d+)$/),p=f[1],g=parseInt(f[2],10);"+"===p?(r.top=n?c+g:0,r.left=n?0:c+g):(r.top=n?c-g:0,r.left=n?0:c-g)}}return r.top=parseInt(r.top),r.left=parseInt(r.left),r}},{key:"_handleStopScroll",value:function(t){this.options.stopScroll?this._hook(this.options.cancelScroll)!==!1&&this.stop():t.stopPropagation()}},{key:"_handleContainerClick",value:function(t){for(var e=this.options,n=t.target;n&&n!==lt;n=n.parentNode)if(g(n,e.trigger)){var r=n.getAttribute("data-scroll"),i=this._parseDataOptions(n),o=r||n.getAttribute("href");e=l({},e,i),t.preventDefault(),e.stopPropagation&&t.stopPropagation(),e.horizontalScroll&&e.verticalScroll?this.to(o,e):e.verticalScroll?this.toTop(o,e):e.horizontalScroll&&this.toLeft(o,e)}}},{key:"_parseDataOptions",value:function(t){var e=t.getAttribute("data-scroll-options");return e?JSON.parse(e):{}}}]),t}();return ft.defaults={trigger:"[data-scroll]",header:"[data-scroll-header]",duration:1e3,delay:0,easing:"easeOutQuint",offset:0,verticalScroll:!0,horizontalScroll:!1,stopScroll:!0,stopPropagation:!0,beforeScroll:null,afterScroll:null,cancelScroll:null},ft});
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.SweetScroll=e()}(this,function(){"use strict";function t(t){return null==t?t+"":"object"===("undefined"==typeof t?"undefined":Z["typeof"](t))||"function"==typeof t?nt[Object.prototype.toString.call(t)]||"object":"undefined"==typeof t?"undefined":Z["typeof"](t)}function e(t){return Array.isArray(t)}function n(t){var e=null==t?null:t.length;return i(e)&&e>=0&&tt>=e}function r(n){return!e(n)&&"object"===t(n)}function i(e){return"number"===t(e)}function o(e){return"string"===t(e)}function a(e){return"function"===t(e)}function s(t){return!e(t)&&t-parseFloat(t)+1>=0}function u(t,e){return t&&Object.prototype.hasOwnProperty.call(t,e)}function l(t){for(var e=arguments.length,n=Array(e>1?e-1:0),r=1;e>r;r++)n[r-1]=arguments[r];return c(n,function(e){c(e,function(e,n){t[n]=e})}),t}function c(t,e,i){if(null==t)return t;if(i=i||t,r(t)){for(var o in t)if(u(t,o)&&e.call(i,t[o],o)===!1)break}else if(n(t)){var a=void 0,s=t.length;for(a=0;s>a&&e.call(i,t[a],a)!==!1;a++);}return t}function h(t){return t.replace(/\s*/g,"")||""}function f(t){var e=arguments.length<=1||void 0===arguments[1]?null:arguments[1];if(t)return(null==e?document:e).querySelector(t)}function p(t){var e=arguments.length<=1||void 0===arguments[1]?null:arguments[1];if(t)return(null==e?document:e).querySelectorAll(t)}function d(t,e){for(var n=(t.document||t.ownerDocument).querySelectorAll(e),r=n.length;--r>=0&&n.item(r)!==t;);return r>-1}function g(t){var e=document;return t===e.documentElement||t===e.body}function v(t){for(var e=arguments.length<=1||void 0===arguments[1]?"y":arguments[1],n=arguments.length<=2||void 0===arguments[2]?!0:arguments[2],r=rt[e],i=p(t),o=[],a=0;a<i.length;a++){var s=i[a];if(s[r]>0?o.push(s):(s[r]=1,s[r]>0&&o.push(s),s[r]=0),!n&&o.length>0)break}return o}function m(t,e){var n=v(t,e,!1);return n.length>=1?n[0]:void 0}function y(t){return null!=t&&t===t.window?t:9===t.nodeType&&t.defaultView}function S(t){var e=arguments.length<=1||void 0===arguments[1]?"y":arguments[1],n=rt[e],r=it[e],i=y(t);return i?i[r]:t[n]}function b(t,e){var n=arguments.length<=2||void 0===arguments[2]?"y":arguments[2],r=rt[n],i=y(t),o="y"===n;i?i.scrollTo(o?i.pageXOffset:e,o?e:i.pageYOffset):t[r]=e}function w(t){var e=arguments.length<=1||void 0===arguments[1]?null:arguments[1];if(!t||t&&!t.getClientRects().length)return{top:0,left:0};var n=t.getBoundingClientRect();if(n.width||n.height){var r={},i=void 0;if(null==e||g(e))i=t.ownerDocument.documentElement,r.top=window.pageYOffset,r.left=window.pageXOffset;else{i=e;var o=i.getBoundingClientRect();r.top=-1*o.top+i.scrollTop,r.left=-1*o.left+i.scrollLeft}return{top:n.top+r.top-i.clientTop,left:n.left+r.left-i.clientLeft}}return n}function k(t){return t}function C(t,e,n,r,i){return r*(e/=i)*e+n}function M(t,e,n,r,i){return-r*(e/=i)*(e-2)+n}function _(t,e,n,r,i){return(e/=i/2)<1?r/2*e*e+n:-r/2*(--e*(e-2)-1)+n}function O(t,e,n,r,i){return r*(e/=i)*e*e+n}function I(t,e,n,r,i){return r*((e=e/i-1)*e*e+1)+n}function L(t,e,n,r,i){return(e/=i/2)<1?r/2*e*e*e+n:r/2*((e-=2)*e*e+2)+n}function E(t,e,n,r,i){return r*(e/=i)*e*e*e+n}function x(t,e,n,r,i){return-r*((e=e/i-1)*e*e*e-1)+n}function P(t,e,n,r,i){return(e/=i/2)<1?r/2*e*e*e*e+n:-r/2*((e-=2)*e*e*e-2)+n}function T(t,e,n,r,i){return r*(e/=i)*e*e*e*e+n}function A(t,e,n,r,i){return r*((e=e/i-1)*e*e*e*e+1)+n}function j(t,e,n,r,i){return(e/=i/2)<1?r/2*e*e*e*e*e+n:r/2*((e-=2)*e*e*e*e+2)+n}function q(t,e,n,r,i){return-r*Math.cos(e/i*(Math.PI/2))+r+n}function Q(t,e,n,r,i){return r*Math.sin(e/i*(Math.PI/2))+n}function B(t,e,n,r,i){return-r/2*(Math.cos(Math.PI*e/i)-1)+n}function D(t,e,n,r,i){return 0===e?n:r*Math.pow(2,10*(e/i-1))+n}function z(t,e,n,r,i){return e===i?n+r:r*(-Math.pow(2,-10*e/i)+1)+n}function R(t,e,n,r,i){return 0===e?n:e===i?n+r:(e/=i/2)<1?r/2*Math.pow(2,10*(e-1))+n:r/2*(-Math.pow(2,-10*--e)+2)+n}function F(t,e,n,r,i){return-r*(Math.sqrt(1-(e/=i)*e)-1)+n}function H(t,e,n,r,i){return r*Math.sqrt(1-(e=e/i-1)*e)+n}function W(t,e,n,r,i){return(e/=i/2)<1?-r/2*(Math.sqrt(1-e*e)-1)+n:r/2*(Math.sqrt(1-(e-=2)*e)+1)+n}function $(t,e,n,r,i){var o=1.70158,a=0,s=r;return 0===e?n:1===(e/=i)?n+r:(a||(a=.3*i),s<Math.abs(r)?(s=r,o=a/4):o=a/(2*Math.PI)*Math.asin(r/s),-(s*Math.pow(2,10*(e-=1))*Math.sin((e*i-o)*(2*Math.PI)/a))+n)}function N(t,e,n,r,i){var o=1.70158,a=0,s=r;return 0===e?n:1===(e/=i)?n+r:(a||(a=.3*i),s<Math.abs(r)?(s=r,o=a/4):o=a/(2*Math.PI)*Math.asin(r/s),s*Math.pow(2,-10*e)*Math.sin((e*i-o)*(2*Math.PI)/a)+r+n)}function X(t,e,n,r,i){var o=1.70158,a=0,s=r;return 0===e?n:2===(e/=i/2)?n+r:(a||(a=i*(.3*1.5)),s<Math.abs(r)?(s=r,o=a/4):o=a/(2*Math.PI)*Math.asin(r/s),1>e?-.5*(s*Math.pow(2,10*(e-=1))*Math.sin((e*i-o)*(2*Math.PI)/a))+n:s*Math.pow(2,-10*(e-=1))*Math.sin((e*i-o)*(2*Math.PI)/a)*.5+r+n)}function Y(t,e,n,r,i){var o=arguments.length<=5||void 0===arguments[5]?1.70158:arguments[5];return r*(e/=i)*e*((o+1)*e-o)+n}function J(t,e,n,r,i){var o=arguments.length<=5||void 0===arguments[5]?1.70158:arguments[5];return r*((e=e/i-1)*e*((o+1)*e+o)+1)+n}function V(t,e,n,r,i){var o=arguments.length<=5||void 0===arguments[5]?1.70158:arguments[5];return(e/=i/2)<1?r/2*(e*e*(((o*=1.525)+1)*e-o))+n:r/2*((e-=2)*e*(((o*=1.525)+1)*e+o)+2)+n}function G(t,e,n,r,i){return r-K(t,i-e,0,r,i)+n}function K(t,e,n,r,i){return(e/=i)<1/2.75?r*(7.5625*e*e)+n:2/2.75>e?r*(7.5625*(e-=1.5/2.75)*e+.75)+n:2.5/2.75>e?r*(7.5625*(e-=2.25/2.75)*e+.9375)+n:r*(7.5625*(e-=2.625/2.75)*e+.984375)+n}function U(t,e,n,r,i){return i/2>e?.5*G(t,2*e,0,r,i)+n:.5*K(t,2*e-i,0,r,i)+.5*r+n}var Z={};Z["typeof"]=function(t){return t&&"undefined"!=typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},Z.classCallCheck=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},Z.createClass=function(){function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}}();var tt=Math.pow(2,53)-1,et=["Boolean","Number","String","Function","Array","Date","RegExp","Object","Error","Symbol"],nt={};et.forEach(function(t){nt["[object "+t+"]"]=t.toLowerCase()});var rt={y:"scrollTop",x:"scrollLeft"},it={y:"pageYOffset",x:"pageXOffset"},ot=0,at=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(t){var e=Date.now(),n=Math.max(0,16-(e-ot)),r=window.setTimeout(function(){t(e+n)},n);return ot=e+n,r},st=Object.freeze({linear:k,easeInQuad:C,easeOutQuad:M,easeInOutQuad:_,easeInCubic:O,easeOutCubic:I,easeInOutCubic:L,easeInQuart:E,easeOutQuart:x,easeInOutQuart:P,easeInQuint:T,easeOutQuint:A,easeInOutQuint:j,easeInSine:q,easeOutSine:Q,easeInOutSine:B,easeInExpo:D,easeOutExpo:z,easeInOutExpo:R,easeInCirc:F,easeOutCirc:H,easeInOutCirc:W,easeInElastic:$,easeOutElastic:N,easeInOutElastic:X,easeInBack:Y,easeOutBack:J,easeInOutBack:V,easeInBounce:G,easeOutBounce:K,easeInOutBounce:U}),ut=function(){function t(e){Z.classCallCheck(this,t),this.el=e,this.props={},this.progress=!1,this.startTime=null}return Z.createClass(t,[{key:"run",value:function(t,e,n,r,i){var o=this,a=arguments.length<=5||void 0===arguments[5]?function(){}:arguments[5];this.progress||(this.props={x:t,y:e},this.duration=n,this.delay=r,this.easing=i,this.callback=a,this.progress=!0,setTimeout(function(){o.startProps={x:S(o.el,"x"),y:S(o.el,"y")},at(function(t){return o._loop(t)})},r))}},{key:"stop",value:function(){var t=arguments.length<=0||void 0===arguments[0]?!0:arguments[0];this.startTime=null,this.progress=!1,t&&(b(this.el,this.props.x,"x"),b(this.el,this.props.y,"y")),a(this.callback)&&(this.callback(),this.callback=null)}},{key:"_loop",value:function(t){var e=this;if(this.startTime||(this.startTime=t),!this.progress)return void this.stop(!1);var n=this.el,r=this.props,i=this.duration,o=this.startTime,a=this.startProps,s={},u=st[this.easing],l=t-o,h=Math.min(1,Math.max(l/i,0));c(r,function(t,e){var n=a[e],r=t-n;if(0===r)return!0;var o=u(h,i*h,0,1,i);s[e]=Math.round(n+r*o)}),c(s,function(t,e){b(n,t,e)}),i>=l?at(function(t){return e._loop(t)}):this.stop(!0)}}]),t}(),lt=document,ct=window,ht="onwheel"in lt?"wheel":"onmousewheel"in lt?"mousewheel":"DOMMouseScroll",ft=function(){function t(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],n=arguments.length<=1||void 0===arguments[1]?"body, html":arguments[1];Z.classCallCheck(this,t),this.options=l({},t.defaults,e),this.container=m(n),this.header=f(this.options.header),this.el=p(this.options.trigger),this.tween=new ut(this.container),this._bindContainerClick()}return Z.createClass(t,[{key:"to",value:function(t){var e=this,n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];this.stop();var r=this.container,i=l({},this.options,n),a=this._parseCoodinate(i.offset),s=this._parseCoodinate(t);if(r){if(!s&&o(t))if("#"===t)s={top:0,left:0};else if(!/[:,]/.test(t)){var u=f(t),c=w(u,r);if(!c)return;s=c}if(s){a&&(s.top+=a.top,s.left+=a.left),this.header&&(s.top-=this.header.clientHeight);var h=void 0,p=void 0;g(r)?(h={width:ct.innerWidth,height:ct.innerHeight},p={width:lt.body.scrollWidth,height:lt.body.scrollHeight}):(h={width:r.clientWidth,height:r.clientHeight},p={width:r.scrollWidth,height:r.scrollHeight}),i.verticalScroll?s.top=s.top+h.height>p.height?p.height-h.height:s.top:s.top=S(r,"y"),i.horizontalScroll?s.left=s.left+h.width>p.width?p.width-h.width:s.left:s.left=S(r,"x"),this._hook(i.beforeScroll,s)!==!1&&(this.tween.run(s.left,s.top,i.duration,i.delay,i.easing,function(){e._unbindContainerStop(),e._hook(i.afterScroll,s)}),this._bindContainerStop())}}}},{key:"toTop",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];this.to(t,l({},e,{verticalScroll:!0,horizontalScroll:!1}))}},{key:"toLeft",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];this.to(t,l({},e,{verticalScroll:!1,horizontalScroll:!0}))}},{key:"stop",value:function(){var t=arguments.length<=0||void 0===arguments[0]?!1:arguments[0];this.tween.stop(t)}},{key:"destroy",value:function(){this.stop(),this._unbindContainerClick(),this._unbindContainerStop()}},{key:"_bindContainerClick",value:function(){this.container&&(this._containerClickListener=this._handleContainerClick.bind(this),this.container.addEventListener("click",this._containerClickListener,!1))}},{key:"_unbindContainerClick",value:function(){this.container&&this._containerClickListener&&(this.container.removeEventListener("click",this._containerClickListener,!1),this._containerClickListener=null)}},{key:"_bindContainerStop",value:function(){if(this.container){var t=this.container;this._stopScrollListener=this._handleStopScroll.bind(this),t.addEventListener(ht,this._stopScrollListener,!1),t.addEventListener("touchstart",this._stopScrollListener,!1),t.addEventListener("touchmove",this._stopScrollListener,!1)}}},{key:"_unbindContainerStop",value:function(){if(this.container&&this._stopScrollListener){var t=this.container;t.removeEventListener(ht,this._stopScrollListener,!1),t.removeEventListener("touchstart",this._stopScrollListener,!1),t.removeEventListener("touchmove",this._stopScrollListener,!1),this._stopScrollListener=null}}},{key:"_hook",value:function(t){if(a(t)){for(var e=arguments.length,n=Array(e>1?e-1:0),r=1;e>r;r++)n[r-1]=arguments[r];return t.apply(this,n)}}},{key:"_parseCoodinate",value:function(t){var n=this.options.verticalScroll,r={top:0,left:0};if(u(t,"top")||u(t,"left"))r=l(r,t);else if(e(t))2===t.length?(r.top=t[0],r.left=t[1]):(r.top=n?t[0]:0,r.left=n?0:t[0]);else if(s(t))r.top=n?t:0,r.left=n?0:t;else{if(!o(t))return null;if(t=h(t),/^\d+,\d+$/.test(t))t=t.split(","),r.top=t[0],r.left=t[1];else if(/^(top|left):\d+,?(?:(top|left):\d+)?$/.test(t)){var i=t.match(/top:(\d+)/),a=t.match(/left:(\d+)/);r.top=i?i[1]:0,r.left=a?a[1]:0}else{if(!/^(\+|-)=(\d+)$/.test(t))return null;var c=S(this.container,n?"y":"x"),f=t.match(/^(\+|-)\=(\d+)$/),p=f[1],d=parseInt(f[2],10);"+"===p?(r.top=n?c+d:0,r.left=n?0:c+d):(r.top=n?c-d:0,r.left=n?0:c-d)}}return r.top=parseInt(r.top),r.left=parseInt(r.left),r}},{key:"_handleStopScroll",value:function(t){this.options.stopScroll?this._hook(this.options.cancelScroll)!==!1&&this.stop():t.preventDefault()}},{key:"_handleContainerClick",value:function(t){for(var e=this.options,n=t.target;n&&n!==lt;n=n.parentNode)if(d(n,e.trigger)){var r=n.getAttribute("data-scroll"),i=this._parseDataOptions(n),o=r||n.getAttribute("href");e=l({},e,i),t.preventDefault(),t.stopPropagation(),e.horizontalScroll&&e.verticalScroll?this.to(o,e):e.verticalScroll?this.toTop(o,e):e.horizontalScroll&&this.toLeft(o,e)}}},{key:"_parseDataOptions",value:function(t){var e=t.getAttribute("data-scroll-options");return e?JSON.parse(e):{}}}]),t}();return ft.defaults={trigger:"[data-scroll]",header:"[data-scroll-header]",duration:1e3,delay:0,easing:"easeOutQuint",offset:0,verticalScroll:!0,horizontalScroll:!1,stopScroll:!0,beforeScroll:null,afterScroll:null,cancelScroll:null},ft});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc