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.1.2 to 0.1.3

2

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

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

@@ -413,3 +413,3 @@ sweet-scroll.js

Start the development.
You I can access the `http://localhost:3000/`.
You can access to the `http://localhost:3000/`.

@@ -416,0 +416,0 @@ ```bash

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

* @license MIT
* @version 0.1.2
* @version 0.1.3
*/

@@ -17,9 +17,9 @@ (function (global, factory) {

var babelHelpers = {};
babelHelpers.typeof = function (obj) {
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
var babelHelpers_typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
return typeof obj;
} : function (obj) {
return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj;
};
babelHelpers.classCallCheck = function (instance, Constructor) {
var babelHelpers_classCallCheck = function (instance, Constructor) {
if (!(instance instanceof Constructor)) {

@@ -30,3 +30,3 @@ throw new TypeError("Cannot call a class as a function");

babelHelpers.createClass = (function () {
var babelHelpers_createClass = function () {
function defineProperties(target, props) {

@@ -47,5 +47,4 @@ for (var i = 0; i < props.length; i++) {

};
})();
}();
babelHelpers;
var MAX_ARRAY_INDEX = Math.pow(2, 53) - 1;

@@ -63,3 +62,3 @@ var classTypeList = ["Boolean", "Number", "String", "Function", "Array", "Date", "RegExp", "Object", "Error", "Symbol"];

}
return (typeof obj === "undefined" ? "undefined" : babelHelpers.typeof(obj)) === "object" || typeof obj === "function" ? classTypes[Object.prototype.toString.call(obj)] || "object" : typeof obj === "undefined" ? "undefined" : babelHelpers.typeof(obj);
return (typeof obj === "undefined" ? "undefined" : babelHelpers_typeof(obj)) === "object" || typeof obj === "function" ? classTypes[Object.prototype.toString.call(obj)] || "object" : typeof obj === "undefined" ? "undefined" : babelHelpers_typeof(obj);
}

@@ -514,5 +513,5 @@

var ScrollTween = (function () {
var ScrollTween = function () {
function ScrollTween(el) {
babelHelpers.classCallCheck(this, ScrollTween);
babelHelpers_classCallCheck(this, ScrollTween);

@@ -525,3 +524,3 @@ this.el = el;

babelHelpers.createClass(ScrollTween, [{
babelHelpers_createClass(ScrollTween, [{
key: "run",

@@ -613,3 +612,3 @@ value: function run(x, y, duration, delay, easing) {

return ScrollTween;
})();
}();

@@ -620,3 +619,3 @@ var win = window;

var SweetScroll = (function () {
var SweetScroll = function () {

@@ -632,3 +631,3 @@ /**

var container = arguments.length <= 1 || arguments[1] === undefined ? "body, html" : arguments[1];
babelHelpers.classCallCheck(this, SweetScroll);
babelHelpers_classCallCheck(this, SweetScroll);

@@ -652,3 +651,3 @@ this.options = merge({}, SweetScroll.defaults, options);

babelHelpers.createClass(SweetScroll, [{
babelHelpers_createClass(SweetScroll, [{
key: "to",

@@ -1083,3 +1082,3 @@ value: function to(distance) {

return SweetScroll;
})();
}();

@@ -1086,0 +1085,0 @@ // Export SweetScroll class

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

* @license MIT
* @version 0.1.2
* @version 0.1.3
*/
!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=t instanceof HTMLElement?[t]:p(t),o=[],a=document.createElement("div"),s=0;s<i.length;s++){var u=i[s];if(u[r]>0?o.push(u):(a.style.width=u.clientWidth+1+"px",a.style.height=u.clientHeight+1+"px",u.appendChild(a),u[r]=1,u[r]>0&&o.push(u),u[r]=0,u.removeChild(a)),!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 C(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 w(t){return t}function k(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 x(t,e,n,r,i){return r*(e/=i)*e*e*e+n}function E(t,e,n,r,i){return-r*((e=e/i-1)*e*e*e-1)+n}function T(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 P(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 z(t,e,n,r,i){return-r/2*(Math.cos(Math.PI*e/i)-1)+n}function B(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 H(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 R(t,e,n,r,i){return-r*(Math.sqrt(1-(e/=i)*e)-1)+n}function F(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:w,easeInQuad:k,easeOutQuad:M,easeInOutQuad:_,easeInCubic:O,easeOutCubic:I,easeInOutCubic:L,easeInQuart:x,easeOutQuart:E,easeInOutQuart:T,easeInQuint:P,easeOutQuint:A,easeInOutQuint:j,easeInSine:q,easeOutSine:Q,easeInOutSine:z,easeInExpo:B,easeOutExpo:D,easeInOutExpo:H,easeInCirc:R,easeOutCirc:F,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=window,ct=document,ht="onwheel"in ct?"wheel":"onmousewheel"in ct?"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=this._getContainer(n),this.header=f(this.options.header),this.tween=new ut(this.container),this._trigger=null,this._bindContainerClick()}return Z.createClass(t,[{key:"to",value:function(t){var e=this,n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],r=this.container,i=l({},this.options,n),a=this._parseCoodinate(i.offset),s=this._trigger,u=this._parseCoodinate(t);if(this._trigger=null,this.stop(),r){if(!u&&o(t))if("#"===t)u={top:0,left:0};else if(!/[:,]/.test(t)){var c=f(t),h=C(c,r);if(!h)return;u=h}if(u){a&&(u.top+=a.top,u.left+=a.left),this.header&&(u.top=Math.max(0,u.top-this.header.clientHeight));var p=void 0,d=void 0;g(r)?(p={width:lt.innerWidth,height:lt.innerHeight},d={width:ct.body.scrollWidth,height:ct.body.scrollHeight}):(p={width:r.clientWidth,height:r.clientHeight},d={width:r.scrollWidth,height:r.scrollHeight}),i.verticalScroll?u.top=Math.max(0,Math.min(d.height-p.height,u.top)):u.top=S(r,"y"),i.horizontalScroll?u.left=Math.max(0,Math.min(d.width-p.width,u.left)):u.left=S(r,"x"),this._hook(i.beforeScroll,u,s)!==!1&&(this.tween.run(u.left,u.top,i.duration,i.delay,i.easing,function(){e._unbindContainerStop(),e._hook(i.afterScroll,u,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:"update",value:function(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];this.stop(),this._unbindContainerClick(),this._unbindContainerStop(),this.options=l({},this.options,t),this.header=f(this.options.header),this._bindContainerClick()}},{key:"destroy",value:function(){this.stop(),this._unbindContainerClick(),this._unbindContainerStop(),this.container=null,this.header=null,this.tween=null}},{key:"_getContainer",value:function(t){var e=this.options,n=e.verticalScroll,r=e.horizontalScroll,i=void 0;return n&&(i=m(t,"y")),!i&&r&&(i=m(t,"x")),i}},{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(!this.container||!/^(\+|-)=(\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!==ct;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(),this._trigger=n,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});
!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(t))||"function"==typeof t?it[Object.prototype.toString.call(t)]||"object":"undefined"==typeof t?"undefined":Z(t)}function e(t){return Array.isArray(t)}function n(t){var e=null==t?null:t.length;return i(e)&&e>=0&&nt>=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 m(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=ot[e],i=t instanceof HTMLElement?[t]:p(t),o=[],a=document.createElement("div"),s=0;s<i.length;s++){var u=i[s];if(u[r]>0?o.push(u):(a.style.width=u.clientWidth+1+"px",a.style.height=u.clientHeight+1+"px",u.appendChild(a),u[r]=1,u[r]>0&&o.push(u),u[r]=0,u.removeChild(a)),!n&&o.length>0)break}return o}function v(t,e){var n=m(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 b(t){var e=arguments.length<=1||void 0===arguments[1]?"y":arguments[1],n=ot[e],r=at[e],i=y(t);return i?i[r]:t[n]}function S(t,e){var n=arguments.length<=2||void 0===arguments[2]?"y":arguments[2],r=ot[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 M(t,e,n,r,i){return r*(e/=i)*e+n}function _(t,e,n,r,i){return-r*(e/=i)*(e-2)+n}function C(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 x(t,e,n,r,i){return r*(e/=i)*e*e*e+n}function E(t,e,n,r,i){return-r*((e=e/i-1)*e*e*e-1)+n}function T(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 P(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 z(t,e,n,r,i){return-r/2*(Math.cos(Math.PI*e/i)-1)+n}function B(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 H(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 R(t,e,n,r,i){return-r*(Math.sqrt(1-(e/=i)*e)-1)+n}function F(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="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},tt=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},et=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}}(),nt=Math.pow(2,53)-1,rt=["Boolean","Number","String","Function","Array","Date","RegExp","Object","Error","Symbol"],it={};rt.forEach(function(t){it["[object "+t+"]"]=t.toLowerCase()});var ot={y:"scrollTop",x:"scrollLeft"},at={y:"pageYOffset",x:"pageXOffset"},st=0,ut=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(t){var e=Date.now(),n=Math.max(0,16-(e-st)),r=window.setTimeout(function(){t(e+n)},n);return st=e+n,r},lt=Object.freeze({linear:k,easeInQuad:M,easeOutQuad:_,easeInOutQuad:C,easeInCubic:O,easeOutCubic:I,easeInOutCubic:L,easeInQuart:x,easeOutQuart:E,easeInOutQuart:T,easeInQuint:P,easeOutQuint:A,easeInOutQuint:j,easeInSine:q,easeOutSine:Q,easeInOutSine:z,easeInExpo:B,easeOutExpo:D,easeInOutExpo:H,easeInCirc:R,easeOutCirc:F,easeInOutCirc:W,easeInElastic:$,easeOutElastic:N,easeInOutElastic:X,easeInBack:Y,easeOutBack:J,easeInOutBack:V,easeInBounce:G,easeOutBounce:K,easeInOutBounce:U}),ct=function(){function t(e){tt(this,t),this.el=e,this.props={},this.progress=!1,this.startTime=null}return et(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:b(o.el,"x"),y:b(o.el,"y")},ut(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&&(S(this.el,this.props.x,"x"),S(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=lt[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){S(n,t,e)}),i>=l?ut(function(t){return e._loop(t)}):this.stop(!0)}}]),t}(),ht=window,ft=document,pt="onwheel"in ft?"wheel":"onmousewheel"in ft?"mousewheel":"DOMMouseScroll",dt=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];tt(this,t),this.options=l({},t.defaults,e),this.container=this._getContainer(n),this.header=f(this.options.header),this.tween=new ct(this.container),this._trigger=null,this._bindContainerClick()}return et(t,[{key:"to",value:function(t){var e=this,n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],r=this.container,i=l({},this.options,n),a=this._parseCoodinate(i.offset),s=this._trigger,u=this._parseCoodinate(t);if(this._trigger=null,this.stop(),r){if(!u&&o(t))if("#"===t)u={top:0,left:0};else if(!/[:,]/.test(t)){var c=f(t),h=w(c,r);if(!h)return;u=h}if(u){a&&(u.top+=a.top,u.left+=a.left),this.header&&(u.top=Math.max(0,u.top-this.header.clientHeight));var p=void 0,d=void 0;g(r)?(p={width:ht.innerWidth,height:ht.innerHeight},d={width:ft.body.scrollWidth,height:ft.body.scrollHeight}):(p={width:r.clientWidth,height:r.clientHeight},d={width:r.scrollWidth,height:r.scrollHeight}),i.verticalScroll?u.top=Math.max(0,Math.min(d.height-p.height,u.top)):u.top=b(r,"y"),i.horizontalScroll?u.left=Math.max(0,Math.min(d.width-p.width,u.left)):u.left=b(r,"x"),this._hook(i.beforeScroll,u,s)!==!1&&(this.tween.run(u.left,u.top,i.duration,i.delay,i.easing,function(){e._unbindContainerStop(),e._hook(i.afterScroll,u,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:"update",value:function(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];this.stop(),this._unbindContainerClick(),this._unbindContainerStop(),this.options=l({},this.options,t),this.header=f(this.options.header),this._bindContainerClick()}},{key:"destroy",value:function(){this.stop(),this._unbindContainerClick(),this._unbindContainerStop(),this.container=null,this.header=null,this.tween=null}},{key:"_getContainer",value:function(t){var e=this.options,n=e.verticalScroll,r=e.horizontalScroll,i=void 0;return n&&(i=v(t,"y")),!i&&r&&(i=v(t,"x")),i}},{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(pt,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(pt,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(!this.container||!/^(\+|-)=(\d+)$/.test(t))return null;var c=b(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!==ft;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(),this._trigger=n,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 dt.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},dt});
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