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 1.0.2 to 1.0.3

5

CHANGELOG.md

@@ -0,1 +1,6 @@

## 1.0.3
* Fix Chrome/Safari: scroll doesn't fire when browser zoom is less than 100% (ref: #23)
## 1.0.2

@@ -2,0 +7,0 @@

10

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

@@ -55,4 +55,4 @@ "main": "sweet-scroll.js",

"copyfiles": "^1.0.0",
"eslint": "^3.0.0",
"karma": "^1.1.0",
"eslint": "^3.0.1",
"karma": "^1.1.1",
"karma-browserify": "^5.0.5",

@@ -71,5 +71,5 @@ "karma-cli": "^1.0.1",

"power-assert": "^1.4.1",
"rollup": "^0.33.0",
"rollup": "^0.33.1",
"rollup-plugin-babel": "^2.6.1",
"uglify-js": "^2.6.4",
"uglify-js": "^2.7.0",
"watchify": "^3.7.0"

@@ -76,0 +76,0 @@ },

@@ -19,2 +19,8 @@ import { $$ } from "./selectors";

function getZoomLevel() {
const { outerWidth, innerWidth } = window;
return outerWidth ? outerWidth / innerWidth : 1;
}
function getScrollable(selectors, direction = "y", all = true) {

@@ -36,3 +42,3 @@ const method = directionMethodMap[direction];

el[method] = 1;
el[method] = 1.5 / getZoomLevel();
if (el[method] > 0) {

@@ -39,0 +45,0 @@ scrollables.push(el);

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

* @license MIT
* @version 1.0.2
* @version 1.0.3
*/

@@ -185,2 +185,11 @@

function getZoomLevel() {
var _window = window;
var outerWidth = _window.outerWidth;
var innerWidth = _window.innerWidth;
return outerWidth ? outerWidth / innerWidth : 1;
}
function getScrollable(selectors) {

@@ -205,3 +214,3 @@ var direction = arguments.length <= 1 || arguments[1] === undefined ? "y" : arguments[1];

el[method] = 1;
el[method] = 1.5 / getZoomLevel();
if (el[method] > 0) {

@@ -208,0 +217,0 @@ scrollables.push(el);

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

* @license MIT
* @version 1.0.2
* @version 1.0.3
*/
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):t.SweetScroll=n()}(this,function(){"use strict";function t(t){return null==t?"":"object"===("undefined"==typeof t?"undefined":gt(t))||"function"==typeof t?kt[Object.prototype.toString.call(t)]||"object":"undefined"==typeof t?"undefined":gt(t)}function n(n){return"number"===t(n)}function e(n){return"string"===t(n)}function i(n){return"function"===t(n)}function o(t){return Array.isArray(t)}function r(t){var e=null==t?null:t.length;return n(e)&&e>=0&&e<=mt}function l(t){return!o(t)&&t-parseFloat(t)+1>=0}function u(n){return!o(n)&&"object"===t(n)}function a(t,n){return t&&t.hasOwnProperty(n)}function c(t,n,e){if(null==t)return t;var i=e||t;if(u(t)){for(var o in t)if(a(t,o)&&n.call(i,t[o],o)===!1)break}else if(r(t))for(var l=0;l<t.length&&n.call(i,t[l],l)!==!1;l++);return t}function s(t){for(var n=arguments.length,e=Array(n>1?n-1:0),i=1;i<n;i++)e[i-1]=arguments[i];return c(e,function(n){c(n,function(n,e){t[e]=n})}),t}function f(t){return t.replace(/\s*/g,"")||""}function h(t){var n=arguments.length<=1||void 0===arguments[1]?null:arguments[1];if(t)return(null==n?wt:n).querySelector(t)}function p(t){var n=arguments.length<=1||void 0===arguments[1]?null:arguments[1];if(t)return(null==n?wt:n).querySelectorAll(t)}function d(t,n){for(var e=(t.document||t.ownerDocument).querySelectorAll(n),i=e.length;--i>=0&&e.item(i)!==t;);return i>-1}function v(t){return t===wt.documentElement||t===wt.body}function g(t){for(var n=arguments.length<=1||void 0===arguments[1]?"y":arguments[1],e=arguments.length<=2||void 0===arguments[2]||arguments[2],i=Ot[n],o=t instanceof Element?[t]:p(t),r=[],l=wt.createElement("div"),u=0;u<o.length;u++){var a=o[u];if(a[i]>0?r.push(a):(l.style.width=a.clientWidth+1+"px",l.style.height=a.clientHeight+1+"px",a.appendChild(l),a[i]=1,a[i]>0&&r.push(a),a[i]=0,a.removeChild(l)),!e&&r.length>0)break}return r}function y(t,n){var e=g(t,n,!1);return e.length>=1?e[0]:null}function S(t){return null!=t&&t===t.window?t:9===t.nodeType&&t.defaultView}function m(t){return pt(t.scrollHeight,t.clientHeight,t.offsetHeight)}function C(t){return pt(t.scrollWidth,t.clientWidth,t.offsetWidth)}function k(t){return{width:C(t),height:m(t)}}function b(){return{width:pt(C(wt.body),C(wt.documentElement)),height:pt(m(wt.body),m(wt.documentElement))}}function w(t){return v(t)?{viewport:{width:dt(bt.innerWidth,wt.documentElement.clientWidth),height:bt.innerHeight},size:b()}:{viewport:{width:t.clientWidth,height:t.clientHeight},size:k(t)}}function O(t){var n=arguments.length<=1||void 0===arguments[1]?"y":arguments[1],e=S(t);return e?e[_t[n]]:t[Ot[n]]}function _(t,n){var e=arguments.length<=2||void 0===arguments[2]?"y":arguments[2],i=S(t),o="y"===e;i?i.scrollTo(o?i[_t.x]:n,o?n:i[_t.y]):t[Ot[e]]=n}function I(t){var n=arguments.length<=1||void 0===arguments[1]?null:arguments[1];if(!t||t&&!t.getClientRects().length)return{top:0,left:0};var e=t.getBoundingClientRect();if(e.width||e.height){var i={},o=null;if(null==n||v(n))o=t.ownerDocument.documentElement,i.top=bt.pageYOffset,i.left=bt.pageXOffset;else{o=n;var r=o.getBoundingClientRect();i.top=r.top*-1+o.scrollTop,i.left=r.left*-1+o.scrollLeft}return{top:e.top+i.top-o.clientTop,left:e.left+i.left-o.clientLeft}}return e}function x(t,n,e){var i=n.split(",");i.forEach(function(n){t.addEventListener(n.trim(),e,!1)})}function L(t,n,e){var i=n.split(",");i.forEach(function(n){t.removeEventListener(n.trim(),e,!1)})}function E(t){return t}function A(t,n,e,i,o){return i*(n/=o)*n+e}function T(t,n,e,i,o){return-i*(n/=o)*(n-2)+e}function z(t,n,e,i,o){return(n/=o/2)<1?i/2*n*n+e:-i/2*(--n*(n-2)-1)+e}function M(t,n,e,i,o){return i*(n/=o)*n*n+e}function D(t,n,e,i,o){return i*((n=n/o-1)*n*n+1)+e}function Q(t,n,e,i,o){return(n/=o/2)<1?i/2*n*n*n+e:i/2*((n-=2)*n*n+2)+e}function j(t,n,e,i,o){return i*(n/=o)*n*n*n+e}function B(t,n,e,i,o){return-i*((n=n/o-1)*n*n*n-1)+e}function P(t,n,e,i,o){return(n/=o/2)<1?i/2*n*n*n*n+e:-i/2*((n-=2)*n*n*n-2)+e}function R(t,n,e,i,o){return i*(n/=o)*n*n*n*n+e}function H(t,n,e,i,o){return i*((n=n/o-1)*n*n*n*n+1)+e}function W(t,n,e,i,o){return(n/=o/2)<1?i/2*n*n*n*n*n+e:i/2*((n-=2)*n*n*n*n+2)+e}function q(t,n,e,i,o){return-i*lt(n/o*(ht/2))+i+e}function F(t,n,e,i,o){return i*ut(n/o*(ht/2))+e}function U(t,n,e,i,o){return-i/2*(lt(ht*n/o)-1)+e}function $(t,n,e,i,o){return 0===n?e:i*at(2,10*(n/o-1))+e}function N(t,n,e,i,o){return n===o?e+i:i*(-at(2,-10*n/o)+1)+e}function X(t,n,e,i,o){return 0===n?e:n===o?e+i:(n/=o/2)<1?i/2*at(2,10*(n-1))+e:i/2*(-at(2,-10*--n)+2)+e}function Y(t,n,e,i,o){return-i*(st(1-(n/=o)*n)-1)+e}function J(t,n,e,i,o){return i*st(1-(n=n/o-1)*n)+e}function V(t,n,e,i,o){return(n/=o/2)<1?-i/2*(st(1-n*n)-1)+e:i/2*(st(1-(n-=2)*n)+1)+e}function G(t,n,e,i,o){var r=1.70158,l=0,u=i;return 0===n?e:1===(n/=o)?e+i:(l||(l=.3*o),u<ct(i)?(u=i,r=l/4):r=l/(2*ht)*ft(i/u),-(u*at(2,10*(n-=1))*ut((n*o-r)*(2*ht)/l))+e)}function K(t,n,e,i,o){var r=1.70158,l=0,u=i;return 0===n?e:1===(n/=o)?e+i:(l||(l=.3*o),u<ct(i)?(u=i,r=l/4):r=l/(2*ht)*ft(i/u),u*at(2,-10*n)*ut((n*o-r)*(2*ht)/l)+i+e)}function Z(t,n,e,i,o){var r=1.70158,l=0,u=i;return 0===n?e:2===(n/=o/2)?e+i:(l||(l=o*(.3*1.5)),u<ct(i)?(u=i,r=l/4):r=l/(2*ht)*ft(i/u),n<1?-.5*(u*at(2,10*(n-=1))*ut((n*o-r)*(2*ht)/l))+e:u*at(2,-10*(n-=1))*ut((n*o-r)*(2*ht)/l)*.5+i+e)}function tt(t,n,e,i,o){var r=arguments.length<=5||void 0===arguments[5]?1.70158:arguments[5];return i*(n/=o)*n*((r+1)*n-r)+e}function nt(t,n,e,i,o){var r=arguments.length<=5||void 0===arguments[5]?1.70158:arguments[5];return i*((n=n/o-1)*n*((r+1)*n+r)+1)+e}function et(t,n,e,i,o){var r=arguments.length<=5||void 0===arguments[5]?1.70158:arguments[5];return(n/=o/2)<1?i/2*(n*n*(((r*=1.525)+1)*n-r))+e:i/2*((n-=2)*n*(((r*=1.525)+1)*n+r)+2)+e}function it(t,n,e,i,o){return(n/=o)<1/2.75?i*(7.5625*n*n)+e:n<2/2.75?i*(7.5625*(n-=1.5/2.75)*n+.75)+e:n<2.5/2.75?i*(7.5625*(n-=2.25/2.75)*n+.9375)+e:i*(7.5625*(n-=2.625/2.75)*n+.984375)+e}function ot(t,n,e,i,o){return i-it(t,o-n,0,i,o)+e}function rt(t,n,e,i,o){return n<o/2?.5*ot(t,2*n,0,i,o)+e:.5*it(t,2*n-o,0,i,o)+.5*i+e}var lt=Math.cos,ut=Math.sin,at=Math.pow,ct=Math.abs,st=Math.sqrt,ft=Math.asin,ht=Math.PI,pt=Math.max,dt=Math.min,vt=Math.round,gt="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},yt=function(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")},St=function(){function t(t,n){for(var e=0;e<n.length;e++){var i=n[e];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(n,e,i){return e&&t(n.prototype,e),i&&t(n,i),n}}(),mt=at(2,53)-1,Ct=["Boolean","Number","String","Function","Array","Object"],kt={};Ct.forEach(function(t){kt["[object "+t+"]"]=t.toLowerCase()});for(var bt=window,wt=document,Ot={y:"scrollTop",x:"scrollLeft"},_t={y:"pageYOffset",x:"pageXOffset"},It=(function(){var t=navigator.userAgent;return(t.indexOf("Android 2.")===-1&&t.indexOf("Android 4.0")===-1||t.indexOf("Mobile Safari")===-1||t.indexOf("Chrome")!==-1||t.indexOf("Windows Phone")!==-1)&&(window.history&&"pushState"in window.history&&"file:"!==window.location.protocol)}()),xt=Object.freeze({linear:E,InQuad:A,OutQuad:T,InOutQuad:z,InCubic:M,OutCubic:D,InOutCubic:Q,InQuart:j,OutQuart:B,InOutQuart:P,InQuint:R,OutQuint:H,InOutQuint:W,InSine:q,OutSine:F,InOutSine:U,InExpo:$,OutExpo:N,InOutExpo:X,InCirc:Y,OutCirc:J,InOutCirc:V,InElastic:G,OutElastic:K,InOutElastic:Z,InBack:tt,OutBack:nt,InOutBack:et,OutBounce:it,InBounce:ot,InOutBounce:rt}),Lt=["ms","moz","webkit"],Et=0,At=bt.requestAnimationFrame,Tt=bt.cancelAnimationFrame,zt=0;zt<Lt.length&&!At;++zt)At=bt[Lt[zt]+"RequestAnimationFrame"],Tt=bt[Lt[zt]+"CancelAnimationFrame"]||bt[Lt[zt]+"CancelRequestAnimationFrame"];At||(At=function(t){var n=Date.now(),e=pt(0,16-(n-Et)),i=setTimeout(function(){t(n+e)},e);return Et=n+e,i}),Tt||(Tt=function(t){clearTimeout(t)});var Mt=function(){function t(n){yt(this,t),this.el=n,this.props={},this.options={},this.progress=!1,this.easing=null,this.startTime=null,this.rafId=null}return St(t,[{key:"run",value:function(t,n,e){var o=this;this.progress||(this.props={x:t,y:n},this.options=e,this.easing=i(e.easing)?e.easing:xt[e.easing.replace("ease","")],this.progress=!0,setTimeout(function(){o.startProps={x:O(o.el,"x"),y:O(o.el,"y")},o.rafId=At(function(t){return o._loop(t)})},this.options.delay))}},{key:"stop",value:function(){var t=arguments.length<=0||void 0===arguments[0]||arguments[0],n=this.options.complete;this.startTime=null,this.progress=!1,Tt(this.rafId),t&&(_(this.el,this.props.x,"x"),_(this.el,this.props.y,"y")),i(n)&&(n.call(this),this.options.complete=null)}},{key:"_loop",value:function(t){var n=this;if(this.startTime||(this.startTime=t),!this.progress)return void this.stop(!1);var e=this.el,i=this.props,o=this.options,r=this.startTime,l=this.startProps,u=this.easing,a=o.duration,s=o.step,f={},h=t-r,p=dt(1,pt(h/a,0));c(i,function(t,n){var e=l[n],i=t-e;if(0===i)return!0;var o=u(p,a*p,0,1,a);f[n]=vt(e+i*o)}),c(f,function(t,n){_(e,t,n)}),h<=a?(s.call(this,p,f),this.rafId=At(function(t){return n._loop(t)})):this.stop(!0)}}]),t}(),Dt=function(){return"onwheel"in wt?"wheel":"onmousewheel"in wt?"mousewheel":"DOMMouseScroll"}(),Qt=Dt+", touchstart, touchmove",jt="DOMContentLoaded",Bt=!1;x(wt,jt,function(){Bt=!0});var Pt=function(){function t(){var n=this,e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],i=arguments.length<=1||void 0===arguments[1]?"body, html":arguments[1];yt(this,t);var o=s({},t.defaults,e);this.options=o,this.getContainer(i,function(t){n.container=t,n.header=h(o.header),n.tween=new Mt(t),n._trigger=null,n._shouldCallCancelScroll=!1,n.bindContainerClick(),n.hook(o,"initialized")})}return St(t,[{key:"to",value:function(t){var n=this,i=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],o=this.container,r=this.header,l=s({},this.options,i);this._options=l;var u=this.parseCoodinate(l.offset),a=this._trigger,c=this.parseCoodinate(t),f=null;if(this._trigger=null,this._shouldCallCancelScroll=!1,this.stop(),o){if(!c&&e(t))if(f=/^#/.test(t)?t:null,"#"===t)c={top:0,left:0};else{var p=h(t),d=I(p,o);if(!d)return;c=d}if(c){u&&(c.top+=u.top,c.left+=u.left),r&&(c.top=pt(0,c.top-k(r).height));var v=w(o),g=v.viewport,y=v.size;this.hook(l,"beforeScroll",c,a)!==!1&&(c.top=l.verticalScroll?pt(0,dt(y.height-g.height,c.top)):O(o,"y"),c.left=l.horizontalScroll?pt(0,dt(y.width-g.width,c.left)):O(o,"x"),this.tween.run(c.left,c.top,{duration:l.duration,delay:l.delay,easing:l.easing,complete:function(){null!=f&&f!==window.location.hash&&n.updateURLHash(f,l.updateURL),n.unbindContainerStop(),n._options=null,n._shouldCallCancelScroll?n.hook(l,"cancelScroll"):n.hook(l,"afterScroll",c,a),n.hook(l,"completeScroll",n._shouldCallCancelScroll)},step:function(t,e){n.hook(l,"stepScroll",t,e)}}),this.bindContainerStop())}}}},{key:"toTop",value:function(t){var n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];this.to(t,s({},n,{verticalScroll:!0,horizontalScroll:!1}))}},{key:"toLeft",value:function(t){var n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];this.to(t,s({},n,{verticalScroll:!1,horizontalScroll:!0}))}},{key:"toElement",value:function(t){var n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];if(t instanceof Element){var e=I(t,this.container);this.to(e,s({},n))}}},{key:"stop",value:function(){var t=!(arguments.length<=0||void 0===arguments[0])&&arguments[0];this._stopScrollListener&&(this._shouldCallCancelScroll=!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=s({},this.options,t),this.header=h(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:"initialized",value:function(){}},{key:"beforeScroll",value:function(t,n){return!0}},{key:"cancelScroll",value:function(){}},{key:"afterScroll",value:function(t,n){}},{key:"completeScroll",value:function(t){}},{key:"stepScroll",value:function(t,n){}},{key:"parseCoodinate",value:function(t){var n=this._options?this._options.verticalScroll:this.options.verticalScroll,i={top:0,left:0};if(a(t,"top")||a(t,"left"))i=s(i,t);else if(o(t))2===t.length?(i.top=t[0],i.left=t[1]):(i.top=n?t[0]:0,i.left=n?0:t[0]);else if(l(t))i.top=n?t:0,i.left=n?0:t;else{if(!e(t))return null;var r=f(t);if(/^\d+,\d+$/.test(r))r=r.split(","),i.top=r[0],i.left=r[1];else if(/^(top|left):\d+,?(?:(top|left):\d+)?$/.test(r)){var u=r.match(/top:(\d+)/),c=r.match(/left:(\d+)/);i.top=u?u[1]:0,i.left=c?c[1]:0}else{if(!this.container||!/^(\+|-)=(\d+)$/.test(r))return null;var h=O(this.container,n?"y":"x"),p=r.match(/^(\+|-)=(\d+)$/),d=p[1],v=parseInt(p[2],10);"+"===d?(i.top=n?h+v:0,i.left=n?0:h+v):(i.top=n?h-v:0,i.left=n?0:h-v)}}return i.top=parseInt(i.top,10),i.left=parseInt(i.left,10),i}},{key:"updateURLHash",value:function(t,n){It&&n&&window.history["replace"===n?"replaceState":"pushState"](null,null,t)}},{key:"getContainer",value:function(t,n){var e=this,i=this.options,o=i.verticalScroll,r=i.horizontalScroll,l=null;o&&(l=y(t,"y")),!l&&r&&(l=y(t,"x")),l||Bt?n.call(this,l):!function(){var i=!1;x(wt,jt,function(){i=!0,e.getContainer(t,n)}),x(bt,"load",function(){i||e.getContainer(t,n)})}()}},{key:"bindContainerClick",value:function(){var t=this.container;t&&(this._containerClickListener=this.handleContainerClick.bind(this),x(t,"click",this._containerClickListener))}},{key:"unbindContainerClick",value:function(){var t=this.container;t&&this._containerClickListener&&(L(t,"click",this._containerClickListener),this._containerClickListener=null)}},{key:"bindContainerStop",value:function(){var t=this.container;t&&(this._stopScrollListener=this.handleStopScroll.bind(this),x(t,Qt,this._stopScrollListener))}},{key:"unbindContainerStop",value:function(){var t=this.container;t&&this._stopScrollListener&&(L(t,Qt,this._stopScrollListener),this._stopScrollListener=null)}},{key:"hook",value:function(t,n){for(var e=t[n],o=arguments.length,r=Array(o>2?o-2:0),l=2;l<o;l++)r[l-2]=arguments[l];if(i(e)){var u=e.apply(this,r);if("undefined"==typeof u)return u}return this[n].apply(this,r)}},{key:"handleStopScroll",value:function(t){var n=this._options?this._options.stopScroll:this.options.stopScroll;n?this.stop():t.preventDefault()}},{key:"handleContainerClick",value:function(t){for(var n=this.options,e=t.target;e&&e!==wt;e=e.parentNode)if(d(e,n.trigger)){var i=e.getAttribute("data-scroll"),o=this.parseDataOptions(e),r=i||e.getAttribute("href");n=s({},n,o),n.preventDefault&&t.preventDefault(),n.stopPropagation&&t.stopPropagation(),this._trigger=e,n.horizontalScroll&&n.verticalScroll?this.to(r,n):n.verticalScroll?this.toTop(r,n):n.horizontalScroll&&this.toLeft(r,n)}}},{key:"parseDataOptions",value:function(t){var n=t.getAttribute("data-scroll-options");return n?JSON.parse(n):{}}}]),t}();return Pt.defaults={trigger:"[data-scroll]",header:"[data-scroll-header]",duration:1e3,delay:0,easing:"easeOutQuint",offset:0,verticalScroll:!0,horizontalScroll:!1,stopScroll:!0,updateURL:!1,preventDefault:!0,stopPropagation:!0,initialized:null,beforeScroll:null,afterScroll:null,cancelScroll:null,completeScroll:null,stepScroll:null},Pt});
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):t.SweetScroll=n()}(this,function(){"use strict";function t(t){return null==t?"":"object"===("undefined"==typeof t?"undefined":yt(t))||"function"==typeof t?bt[Object.prototype.toString.call(t)]||"object":"undefined"==typeof t?"undefined":yt(t)}function n(n){return"number"===t(n)}function e(n){return"string"===t(n)}function i(n){return"function"===t(n)}function o(t){return Array.isArray(t)}function r(t){var e=null==t?null:t.length;return n(e)&&e>=0&&e<=Ct}function l(t){return!o(t)&&t-parseFloat(t)+1>=0}function u(n){return!o(n)&&"object"===t(n)}function a(t,n){return t&&t.hasOwnProperty(n)}function c(t,n,e){if(null==t)return t;var i=e||t;if(u(t)){for(var o in t)if(a(t,o)&&n.call(i,t[o],o)===!1)break}else if(r(t))for(var l=0;l<t.length&&n.call(i,t[l],l)!==!1;l++);return t}function s(t){for(var n=arguments.length,e=Array(n>1?n-1:0),i=1;i<n;i++)e[i-1]=arguments[i];return c(e,function(n){c(n,function(n,e){t[e]=n})}),t}function f(t){return t.replace(/\s*/g,"")||""}function h(t){var n=arguments.length<=1||void 0===arguments[1]?null:arguments[1];if(t)return(null==n?Ot:n).querySelector(t)}function p(t){var n=arguments.length<=1||void 0===arguments[1]?null:arguments[1];if(t)return(null==n?Ot:n).querySelectorAll(t)}function d(t,n){for(var e=(t.document||t.ownerDocument).querySelectorAll(n),i=e.length;--i>=0&&e.item(i)!==t;);return i>-1}function v(t){return t===Ot.documentElement||t===Ot.body}function g(){var t=window,n=t.outerWidth,e=t.innerWidth;return n?n/e:1}function y(t){for(var n=arguments.length<=1||void 0===arguments[1]?"y":arguments[1],e=arguments.length<=2||void 0===arguments[2]||arguments[2],i=_t[n],o=t instanceof Element?[t]:p(t),r=[],l=Ot.createElement("div"),u=0;u<o.length;u++){var a=o[u];if(a[i]>0?r.push(a):(l.style.width=a.clientWidth+1+"px",l.style.height=a.clientHeight+1+"px",a.appendChild(l),a[i]=1.5/g(),a[i]>0&&r.push(a),a[i]=0,a.removeChild(l)),!e&&r.length>0)break}return r}function S(t,n){var e=y(t,n,!1);return e.length>=1?e[0]:null}function m(t){return null!=t&&t===t.window?t:9===t.nodeType&&t.defaultView}function C(t){return dt(t.scrollHeight,t.clientHeight,t.offsetHeight)}function k(t){return dt(t.scrollWidth,t.clientWidth,t.offsetWidth)}function b(t){return{width:k(t),height:C(t)}}function w(){return{width:dt(k(Ot.body),k(Ot.documentElement)),height:dt(C(Ot.body),C(Ot.documentElement))}}function O(t){return v(t)?{viewport:{width:vt(wt.innerWidth,Ot.documentElement.clientWidth),height:wt.innerHeight},size:w()}:{viewport:{width:t.clientWidth,height:t.clientHeight},size:b(t)}}function _(t){var n=arguments.length<=1||void 0===arguments[1]?"y":arguments[1],e=m(t);return e?e[It[n]]:t[_t[n]]}function I(t,n){var e=arguments.length<=2||void 0===arguments[2]?"y":arguments[2],i=m(t),o="y"===e;i?i.scrollTo(o?i[It.x]:n,o?n:i[It.y]):t[_t[e]]=n}function x(t){var n=arguments.length<=1||void 0===arguments[1]?null:arguments[1];if(!t||t&&!t.getClientRects().length)return{top:0,left:0};var e=t.getBoundingClientRect();if(e.width||e.height){var i={},o=null;if(null==n||v(n))o=t.ownerDocument.documentElement,i.top=wt.pageYOffset,i.left=wt.pageXOffset;else{o=n;var r=o.getBoundingClientRect();i.top=r.top*-1+o.scrollTop,i.left=r.left*-1+o.scrollLeft}return{top:e.top+i.top-o.clientTop,left:e.left+i.left-o.clientLeft}}return e}function L(t,n,e){var i=n.split(",");i.forEach(function(n){t.addEventListener(n.trim(),e,!1)})}function E(t,n,e){var i=n.split(",");i.forEach(function(n){t.removeEventListener(n.trim(),e,!1)})}function A(t){return t}function T(t,n,e,i,o){return i*(n/=o)*n+e}function z(t,n,e,i,o){return-i*(n/=o)*(n-2)+e}function M(t,n,e,i,o){return(n/=o/2)<1?i/2*n*n+e:-i/2*(--n*(n-2)-1)+e}function D(t,n,e,i,o){return i*(n/=o)*n*n+e}function Q(t,n,e,i,o){return i*((n=n/o-1)*n*n+1)+e}function W(t,n,e,i,o){return(n/=o/2)<1?i/2*n*n*n+e:i/2*((n-=2)*n*n+2)+e}function j(t,n,e,i,o){return i*(n/=o)*n*n*n+e}function B(t,n,e,i,o){return-i*((n=n/o-1)*n*n*n-1)+e}function P(t,n,e,i,o){return(n/=o/2)<1?i/2*n*n*n*n+e:-i/2*((n-=2)*n*n*n-2)+e}function R(t,n,e,i,o){return i*(n/=o)*n*n*n*n+e}function H(t,n,e,i,o){return i*((n=n/o-1)*n*n*n*n+1)+e}function q(t,n,e,i,o){return(n/=o/2)<1?i/2*n*n*n*n*n+e:i/2*((n-=2)*n*n*n*n+2)+e}function F(t,n,e,i,o){return-i*ut(n/o*(pt/2))+i+e}function U(t,n,e,i,o){return i*at(n/o*(pt/2))+e}function $(t,n,e,i,o){return-i/2*(ut(pt*n/o)-1)+e}function N(t,n,e,i,o){return 0===n?e:i*ct(2,10*(n/o-1))+e}function X(t,n,e,i,o){return n===o?e+i:i*(-ct(2,-10*n/o)+1)+e}function Y(t,n,e,i,o){return 0===n?e:n===o?e+i:(n/=o/2)<1?i/2*ct(2,10*(n-1))+e:i/2*(-ct(2,-10*--n)+2)+e}function J(t,n,e,i,o){return-i*(ft(1-(n/=o)*n)-1)+e}function V(t,n,e,i,o){return i*ft(1-(n=n/o-1)*n)+e}function G(t,n,e,i,o){return(n/=o/2)<1?-i/2*(ft(1-n*n)-1)+e:i/2*(ft(1-(n-=2)*n)+1)+e}function K(t,n,e,i,o){var r=1.70158,l=0,u=i;return 0===n?e:1===(n/=o)?e+i:(l||(l=.3*o),u<st(i)?(u=i,r=l/4):r=l/(2*pt)*ht(i/u),-(u*ct(2,10*(n-=1))*at((n*o-r)*(2*pt)/l))+e)}function Z(t,n,e,i,o){var r=1.70158,l=0,u=i;return 0===n?e:1===(n/=o)?e+i:(l||(l=.3*o),u<st(i)?(u=i,r=l/4):r=l/(2*pt)*ht(i/u),u*ct(2,-10*n)*at((n*o-r)*(2*pt)/l)+i+e)}function tt(t,n,e,i,o){var r=1.70158,l=0,u=i;return 0===n?e:2===(n/=o/2)?e+i:(l||(l=o*(.3*1.5)),u<st(i)?(u=i,r=l/4):r=l/(2*pt)*ht(i/u),n<1?-.5*(u*ct(2,10*(n-=1))*at((n*o-r)*(2*pt)/l))+e:u*ct(2,-10*(n-=1))*at((n*o-r)*(2*pt)/l)*.5+i+e)}function nt(t,n,e,i,o){var r=arguments.length<=5||void 0===arguments[5]?1.70158:arguments[5];return i*(n/=o)*n*((r+1)*n-r)+e}function et(t,n,e,i,o){var r=arguments.length<=5||void 0===arguments[5]?1.70158:arguments[5];return i*((n=n/o-1)*n*((r+1)*n+r)+1)+e}function it(t,n,e,i,o){var r=arguments.length<=5||void 0===arguments[5]?1.70158:arguments[5];return(n/=o/2)<1?i/2*(n*n*(((r*=1.525)+1)*n-r))+e:i/2*((n-=2)*n*(((r*=1.525)+1)*n+r)+2)+e}function ot(t,n,e,i,o){return(n/=o)<1/2.75?i*(7.5625*n*n)+e:n<2/2.75?i*(7.5625*(n-=1.5/2.75)*n+.75)+e:n<2.5/2.75?i*(7.5625*(n-=2.25/2.75)*n+.9375)+e:i*(7.5625*(n-=2.625/2.75)*n+.984375)+e}function rt(t,n,e,i,o){return i-ot(t,o-n,0,i,o)+e}function lt(t,n,e,i,o){return n<o/2?.5*rt(t,2*n,0,i,o)+e:.5*ot(t,2*n-o,0,i,o)+.5*i+e}var ut=Math.cos,at=Math.sin,ct=Math.pow,st=Math.abs,ft=Math.sqrt,ht=Math.asin,pt=Math.PI,dt=Math.max,vt=Math.min,gt=Math.round,yt="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},St=function(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")},mt=function(){function t(t,n){for(var e=0;e<n.length;e++){var i=n[e];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(n,e,i){return e&&t(n.prototype,e),i&&t(n,i),n}}(),Ct=ct(2,53)-1,kt=["Boolean","Number","String","Function","Array","Object"],bt={};kt.forEach(function(t){bt["[object "+t+"]"]=t.toLowerCase()});for(var wt=window,Ot=document,_t={y:"scrollTop",x:"scrollLeft"},It={y:"pageYOffset",x:"pageXOffset"},xt=(function(){var t=navigator.userAgent;return(t.indexOf("Android 2.")===-1&&t.indexOf("Android 4.0")===-1||t.indexOf("Mobile Safari")===-1||t.indexOf("Chrome")!==-1||t.indexOf("Windows Phone")!==-1)&&(window.history&&"pushState"in window.history&&"file:"!==window.location.protocol)}()),Lt=Object.freeze({linear:A,InQuad:T,OutQuad:z,InOutQuad:M,InCubic:D,OutCubic:Q,InOutCubic:W,InQuart:j,OutQuart:B,InOutQuart:P,InQuint:R,OutQuint:H,InOutQuint:q,InSine:F,OutSine:U,InOutSine:$,InExpo:N,OutExpo:X,InOutExpo:Y,InCirc:J,OutCirc:V,InOutCirc:G,InElastic:K,OutElastic:Z,InOutElastic:tt,InBack:nt,OutBack:et,InOutBack:it,OutBounce:ot,InBounce:rt,InOutBounce:lt}),Et=["ms","moz","webkit"],At=0,Tt=wt.requestAnimationFrame,zt=wt.cancelAnimationFrame,Mt=0;Mt<Et.length&&!Tt;++Mt)Tt=wt[Et[Mt]+"RequestAnimationFrame"],zt=wt[Et[Mt]+"CancelAnimationFrame"]||wt[Et[Mt]+"CancelRequestAnimationFrame"];Tt||(Tt=function(t){var n=Date.now(),e=dt(0,16-(n-At)),i=setTimeout(function(){t(n+e)},e);return At=n+e,i}),zt||(zt=function(t){clearTimeout(t)});var Dt=function(){function t(n){St(this,t),this.el=n,this.props={},this.options={},this.progress=!1,this.easing=null,this.startTime=null,this.rafId=null}return mt(t,[{key:"run",value:function(t,n,e){var o=this;this.progress||(this.props={x:t,y:n},this.options=e,this.easing=i(e.easing)?e.easing:Lt[e.easing.replace("ease","")],this.progress=!0,setTimeout(function(){o.startProps={x:_(o.el,"x"),y:_(o.el,"y")},o.rafId=Tt(function(t){return o._loop(t)})},this.options.delay))}},{key:"stop",value:function(){var t=arguments.length<=0||void 0===arguments[0]||arguments[0],n=this.options.complete;this.startTime=null,this.progress=!1,zt(this.rafId),t&&(I(this.el,this.props.x,"x"),I(this.el,this.props.y,"y")),i(n)&&(n.call(this),this.options.complete=null)}},{key:"_loop",value:function(t){var n=this;if(this.startTime||(this.startTime=t),!this.progress)return void this.stop(!1);var e=this.el,i=this.props,o=this.options,r=this.startTime,l=this.startProps,u=this.easing,a=o.duration,s=o.step,f={},h=t-r,p=vt(1,dt(h/a,0));c(i,function(t,n){var e=l[n],i=t-e;if(0===i)return!0;var o=u(p,a*p,0,1,a);f[n]=gt(e+i*o)}),c(f,function(t,n){I(e,t,n)}),h<=a?(s.call(this,p,f),this.rafId=Tt(function(t){return n._loop(t)})):this.stop(!0)}}]),t}(),Qt=function(){return"onwheel"in Ot?"wheel":"onmousewheel"in Ot?"mousewheel":"DOMMouseScroll"}(),Wt=Qt+", touchstart, touchmove",jt="DOMContentLoaded",Bt=!1;L(Ot,jt,function(){Bt=!0});var Pt=function(){function t(){var n=this,e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],i=arguments.length<=1||void 0===arguments[1]?"body, html":arguments[1];St(this,t);var o=s({},t.defaults,e);this.options=o,this.getContainer(i,function(t){n.container=t,n.header=h(o.header),n.tween=new Dt(t),n._trigger=null,n._shouldCallCancelScroll=!1,n.bindContainerClick(),n.hook(o,"initialized")})}return mt(t,[{key:"to",value:function(t){var n=this,i=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],o=this.container,r=this.header,l=s({},this.options,i);this._options=l;var u=this.parseCoodinate(l.offset),a=this._trigger,c=this.parseCoodinate(t),f=null;if(this._trigger=null,this._shouldCallCancelScroll=!1,this.stop(),o){if(!c&&e(t))if(f=/^#/.test(t)?t:null,"#"===t)c={top:0,left:0};else{var p=h(t),d=x(p,o);if(!d)return;c=d}if(c){u&&(c.top+=u.top,c.left+=u.left),r&&(c.top=dt(0,c.top-b(r).height));var v=O(o),g=v.viewport,y=v.size;this.hook(l,"beforeScroll",c,a)!==!1&&(c.top=l.verticalScroll?dt(0,vt(y.height-g.height,c.top)):_(o,"y"),c.left=l.horizontalScroll?dt(0,vt(y.width-g.width,c.left)):_(o,"x"),this.tween.run(c.left,c.top,{duration:l.duration,delay:l.delay,easing:l.easing,complete:function(){null!=f&&f!==window.location.hash&&n.updateURLHash(f,l.updateURL),n.unbindContainerStop(),n._options=null,n._shouldCallCancelScroll?n.hook(l,"cancelScroll"):n.hook(l,"afterScroll",c,a),n.hook(l,"completeScroll",n._shouldCallCancelScroll)},step:function(t,e){n.hook(l,"stepScroll",t,e)}}),this.bindContainerStop())}}}},{key:"toTop",value:function(t){var n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];this.to(t,s({},n,{verticalScroll:!0,horizontalScroll:!1}))}},{key:"toLeft",value:function(t){var n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];this.to(t,s({},n,{verticalScroll:!1,horizontalScroll:!0}))}},{key:"toElement",value:function(t){var n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];if(t instanceof Element){var e=x(t,this.container);this.to(e,s({},n))}}},{key:"stop",value:function(){var t=!(arguments.length<=0||void 0===arguments[0])&&arguments[0];this._stopScrollListener&&(this._shouldCallCancelScroll=!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=s({},this.options,t),this.header=h(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:"initialized",value:function(){}},{key:"beforeScroll",value:function(t,n){return!0}},{key:"cancelScroll",value:function(){}},{key:"afterScroll",value:function(t,n){}},{key:"completeScroll",value:function(t){}},{key:"stepScroll",value:function(t,n){}},{key:"parseCoodinate",value:function(t){var n=this._options?this._options.verticalScroll:this.options.verticalScroll,i={top:0,left:0};if(a(t,"top")||a(t,"left"))i=s(i,t);else if(o(t))2===t.length?(i.top=t[0],i.left=t[1]):(i.top=n?t[0]:0,i.left=n?0:t[0]);else if(l(t))i.top=n?t:0,i.left=n?0:t;else{if(!e(t))return null;var r=f(t);if(/^\d+,\d+$/.test(r))r=r.split(","),i.top=r[0],i.left=r[1];else if(/^(top|left):\d+,?(?:(top|left):\d+)?$/.test(r)){var u=r.match(/top:(\d+)/),c=r.match(/left:(\d+)/);i.top=u?u[1]:0,i.left=c?c[1]:0}else{if(!this.container||!/^(\+|-)=(\d+)$/.test(r))return null;var h=_(this.container,n?"y":"x"),p=r.match(/^(\+|-)=(\d+)$/),d=p[1],v=parseInt(p[2],10);"+"===d?(i.top=n?h+v:0,i.left=n?0:h+v):(i.top=n?h-v:0,i.left=n?0:h-v)}}return i.top=parseInt(i.top,10),i.left=parseInt(i.left,10),i}},{key:"updateURLHash",value:function(t,n){xt&&n&&window.history["replace"===n?"replaceState":"pushState"](null,null,t)}},{key:"getContainer",value:function(t,n){var e=this,i=this.options,o=i.verticalScroll,r=i.horizontalScroll,l=null;o&&(l=S(t,"y")),!l&&r&&(l=S(t,"x")),l||Bt?n.call(this,l):!function(){var i=!1;L(Ot,jt,function(){i=!0,e.getContainer(t,n)}),L(wt,"load",function(){i||e.getContainer(t,n)})}()}},{key:"bindContainerClick",value:function(){var t=this.container;t&&(this._containerClickListener=this.handleContainerClick.bind(this),L(t,"click",this._containerClickListener))}},{key:"unbindContainerClick",value:function(){var t=this.container;t&&this._containerClickListener&&(E(t,"click",this._containerClickListener),this._containerClickListener=null)}},{key:"bindContainerStop",value:function(){var t=this.container;t&&(this._stopScrollListener=this.handleStopScroll.bind(this),L(t,Wt,this._stopScrollListener))}},{key:"unbindContainerStop",value:function(){var t=this.container;t&&this._stopScrollListener&&(E(t,Wt,this._stopScrollListener),this._stopScrollListener=null)}},{key:"hook",value:function(t,n){for(var e=t[n],o=arguments.length,r=Array(o>2?o-2:0),l=2;l<o;l++)r[l-2]=arguments[l];if(i(e)){var u=e.apply(this,r);if("undefined"==typeof u)return u}return this[n].apply(this,r)}},{key:"handleStopScroll",value:function(t){var n=this._options?this._options.stopScroll:this.options.stopScroll;n?this.stop():t.preventDefault()}},{key:"handleContainerClick",value:function(t){for(var n=this.options,e=t.target;e&&e!==Ot;e=e.parentNode)if(d(e,n.trigger)){var i=e.getAttribute("data-scroll"),o=this.parseDataOptions(e),r=i||e.getAttribute("href");n=s({},n,o),n.preventDefault&&t.preventDefault(),n.stopPropagation&&t.stopPropagation(),this._trigger=e,n.horizontalScroll&&n.verticalScroll?this.to(r,n):n.verticalScroll?this.toTop(r,n):n.horizontalScroll&&this.toLeft(r,n)}}},{key:"parseDataOptions",value:function(t){var n=t.getAttribute("data-scroll-options");return n?JSON.parse(n):{}}}]),t}();return Pt.defaults={trigger:"[data-scroll]",header:"[data-scroll-header]",duration:1e3,delay:0,easing:"easeOutQuint",offset:0,verticalScroll:!0,horizontalScroll:!1,stopScroll:!0,updateURL:!1,preventDefault:!0,stopPropagation:!0,initialized:null,beforeScroll:null,afterScroll:null,cancelScroll:null,completeScroll:null,stepScroll:null},Pt});
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