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

scrollfeatures

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

scrollfeatures - npm Package Compare versions

Comparing version 1.1.0 to 1.4.0

dist/scrollfeatures.opti.js

453

dist/scrollfeatures.js

@@ -7,10 +7,4 @@ 'use strict';

var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } };
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _delegatejs = require('delegatejs');
var _delegatejs2 = _interopRequireDefault(_delegatejs);
var _eventdispatcher = require('eventdispatcher');

@@ -32,54 +26,34 @@

var unprefixAnimationFrame = function unprefixAnimationFrame() {
if (!window.requestAnimationFrame) {
window.requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;
window.cancelAnimationFrame = window.cancelAnimationFrame || window.mozCancelAnimationFrame || window.webkitCancelAnimationFrame || window.msCancelAnimationFrame;
}
};
var ScrollFeatures = function (_EventDispatcher) {
_inherits(ScrollFeatures, _EventDispatcher);
ScrollFeatures.getInstance = function getInstance(scrollTarget, options) {
if (!scrollTarget.scrollFeatures) {
return new ScrollFeatures(scrollTarget, options);
}
return scrollTarget.scrollFeatures;
};
ScrollFeatures.hasInstance = function hasInstance(scrollTarget) {
return typeof scrollTarget.scrollFeatures !== 'undefined';
};
ScrollFeatures.getScrollParent = function getScrollParent(element) {
return (0, _scrollParent2.default)(element);
};
_createClass(ScrollFeatures, null, [{
key: 'getInstance',
value: function getInstance(scrollTarget, options) {
if (!scrollTarget.scrollFeatures) {
return new ScrollFeatures(scrollTarget, options);
}
return scrollTarget.scrollFeatures;
}
}, {
key: 'hasInstance',
value: function hasInstance(scrollTarget) {
return typeof scrollTarget.scrollFeatures !== 'undefined';
}
}, {
key: 'getScrollParent',
value: function getScrollParent(element) {
return (0, _scrollParent2.default)(element);
}
}, {
key: 'unprefixAnimationFrame',
value: function unprefixAnimationFrame() {
if (!window.requestAnimationFrame) {
window.requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;
window.cancelAnimationFrame = window.cancelAnimationFrame || window.mozCancelAnimationFrame || window.webkitCancelAnimationFrame || window.msCancelAnimationFrame;
}
}
}, {
key: 'directionToString',
value: function directionToString(direction) {
switch (direction) {
case ScrollFeatures.UP:
return 'up';
case ScrollFeatures.DOWN:
return 'down';
case ScrollFeatures.NONE:
return 'none';
case ScrollFeatures.LEFT:
return 'left';
case ScrollFeatures.RIGHT:
return 'right';
}
}
}, {
key: 'windowScrollY',
key: 'windowY',
get: function get() {
return window.pageYOffset || window.scrollY || 0;
return window.pageYOffset || window.y || 0;
}
}, {
key: 'windowScrollX',
key: 'windowX',
get: function get() {

@@ -101,4 +75,4 @@ return window.pageXOffset || window.scrollX || 0;

function ScrollFeatures() {
var scrollTarget = arguments.length <= 0 || arguments[0] === undefined ? window : arguments[0];
var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
var scrollTarget = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : window;
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};

@@ -113,4 +87,23 @@ _classCallCheck(this, ScrollFeatures);

var _this = _possibleConstructorReturn(this, (ScrollFeatures.__proto__ || Object.getPrototypeOf(ScrollFeatures)).call(this, { target: scrollTarget }));
var _this = _possibleConstructorReturn(this, _EventDispatcher.call(this, { target: scrollTarget }));
_this._scrollTarget = null;
_this._destroyed = false;
_this._y = 0;
_this._x = 0;
_this._speedY = 0;
_this._speedX = 0;
_this._lastSpeed = 0;
_this._lastDirectionY = ScrollFeatures.direction.none;
_this._lastDirectionX = ScrollFeatures.direction.none;
_this._stopFrames = 3;
_this._currentStopFrames = 0;
_this._firstRender = true;
_this._directionY = ScrollFeatures.direction.none;
_this._directionX = ScrollFeatures.direction.none;
_this._scrolling = false;
_this._canScrollY = false;
_this._canScrollX = false;
scrollTarget.scrollFeatures = _this;

@@ -121,3 +114,3 @@ _this._scrollTarget = scrollTarget;

if (Can.animationFrame) {
ScrollFeatures.unprefixAnimationFrame();
unprefixAnimationFrame();
}

@@ -129,199 +122,160 @@

_createClass(ScrollFeatures, [{
key: 'init',
value: function init() {
var _this2 = this;
ScrollFeatures.prototype.init = function init() {
this._destroyed = false;
this._scrollY = 0;
this._scrollX = 0;
this._speedY = 0;
this._speedX = 0;
this._lastSpeed = 0;
this._lastDirectionY = ScrollFeatures.NONE;
this._lastDirectionX = ScrollFeatures.NONE;
this._stopFrames = 3;
this._currentStopFrames = 0;
this._firstRender = true;
this._directionY = ScrollFeatures.NONE;
this._directionX = ScrollFeatures.NONE;
this._scrolling = false;
this._canScrollY = false;
this._canScrollX = false;
this.getScrollPosition = this._scrollTarget === window ? function () {
return { y: ScrollFeatures.windowY, x: ScrollFeatures.windowX };
}.bind(this) : function () {
return { y: this._scrollTarget.scrollTop, x: this._scrollTarget.scrollLeft };
}.bind(this);
this.getScrollPosition = (0, _delegatejs2.default)(this, this._scrollTarget === window ? this._getWindowScrollPosition : this._getElementScrollPosition);
this.onResize = this.trigger.bind(this, ScrollFeatures.events.SCROLL_RESIZE);
this.onScroll = this.onScroll.bind(this);
this.onNextFrame = this.onNextFrame.bind(this);
this.onResize = (0, _delegatejs2.default)(this, function () {
return _this2.trigger(ScrollFeatures.EVENT_SCROLL_RESIZE);
});
this.onScroll = (0, _delegatejs2.default)(this, this.onScroll);
this.onNextFrame = (0, _delegatejs2.default)(this, this.onNextFrame);
this.updateScrollPosition();
this.updateScrollPosition();
if (this._scrollTarget !== window) {
var regex = /(auto|scroll)/;
var style = window.getComputedStyle(this._scrollTarget, null);
this._canScrollY = regex.test(style.getPropertyValue('overflow-y'));
this._canScrollX = regex.test(style.getPropertyValue('overflow-x'));
} else {
this._canScrollY = this.clientHeight < this.scrollHeight;
this._canScrollX = this.clientWidth < this.scrollWidth;
}
if (this._scrollTarget !== window) {
var regex = /(auto|scroll)/;
var style = window.getComputedStyle(this._scrollTarget, null);
this._canScrollY = regex.test(style.getPropertyValue('overflow-y'));
this._canScrollX = regex.test(style.getPropertyValue('overflow-x'));
} else {
this._canScrollY = this.clientHeight < this.scrollHeight;
this._canScrollX = this.clientWidth < this.scrollWidth;
}
if (this._scrollTarget.addEventListener) {
this._scrollTarget.addEventListener('scroll', this.onScroll, false);
this._scrollTarget.addEventListener('resize', this.onResize, false);
} else if (this._scrollTarget.attachEvent) {
this._scrollTarget.attachEvent('scroll', this.onScroll);
this._scrollTarget.attachEvent('resize', this.onResize);
}
};
ScrollFeatures.prototype.destroy = function destroy() {
if (!this._destroyed) {
this._cancelNextFrame();
_EventDispatcher.prototype.destroy.call(this);
if (this._scrollTarget.addEventListener) {
this._scrollTarget.addEventListener('scroll', this.onScroll, false);
this._scrollTarget.addEventListener('resize', this.onResize, false);
this._scrollTarget.removeEventListener('scroll', this.onScroll);
this._scrollTarget.removeEventListener('resize', this.onResize);
} else if (this._scrollTarget.attachEvent) {
this._scrollTarget.attachEvent('scroll', this.onScroll);
this._scrollTarget.attachEvent('resize', this.onResize);
this._scrollTarget.detachEvent('scroll', this.onScroll);
this._scrollTarget.detachEvent('resize', this.onResize);
}
this.onResize = null;
this.onScroll = null;
this.getScrollPosition = null;
this.onNextFrame = null;
delete this._scrollTarget.scrollFeatures;
this._scrollTarget = null;
this._destroyed = true;
}
}, {
key: 'destroy',
value: function destroy() {
if (!this._destroyed) {
this._cancelNextFrame();
};
_get(ScrollFeatures.prototype.__proto__ || Object.getPrototypeOf(ScrollFeatures.prototype), 'destroy', this).call(this);
ScrollFeatures.prototype.updateScrollPosition = function updateScrollPosition() {
this._y = this.y;
this._x = this.x;
};
if (this._scrollTarget.addEventListener) {
this._scrollTarget.removeEventListener('scroll', this.onScroll);
this._scrollTarget.removeEventListener('resize', this.onResize);
} else if (this._scrollTarget.attachEvent) {
this._scrollTarget.detachEvent('scroll', this.onScroll);
this._scrollTarget.detachEvent('resize', this.onResize);
}
this.onResize = null;
this.onScroll = null;
this.getScrollPosition = null;
this.onNextFrame = null;
delete this._scrollTarget.scrollFeatures;
this._scrollTarget = null;
this._destroyed = true;
ScrollFeatures.prototype.onScroll = function onScroll() {
this._currentStopFrames = 0;
if (this._firstRender) {
this._firstRender = false;
if (this.y > 1 || this.x > 1) {
this.updateScrollPosition();
this.trigger(ScrollFeatures.events.SCROLL_PROGRESS);
return;
}
}
}, {
key: 'updateScrollPosition',
value: function updateScrollPosition() {
this._scrollY = this.scrollY;
this._scrollX = this.scrollX;
}
}, {
key: '_getWindowScrollPosition',
value: function _getWindowScrollPosition() {
return {
y: ScrollFeatures.windowScrollY,
x: ScrollFeatures.windowScrollX
};
}
}, {
key: '_getElementScrollPosition',
value: function _getElementScrollPosition() {
return {
y: this._scrollTarget.scrollTop,
x: this._scrollTarget.scrollLeft
};
}
}, {
key: 'onScroll',
value: function onScroll() {
this._currentStopFrames = 0;
if (this._firstRender) {
this._firstRender = false;
if (this.y > 1 || this.x > 1) {
this.updateScrollPosition();
this.trigger(ScrollFeatures.EVENT_SCROLL_PROGRESS);
return;
}
}
if (!this._scrolling) {
this._scrolling = true;
this._lastDirectionY = ScrollFeatures.NONE;
this._lastDirectionX = ScrollFeatures.NONE;
this.trigger(ScrollFeatures.EVENT_SCROLL_START);
if (Can.animationFrame) {
this.nextFrameID = window.requestAnimationFrame(this.onNextFrame);
} else {
this.onNextFrame();
}
if (!this._scrolling) {
this._scrolling = true;
this._lastDirectionY = ScrollFeatures.direction.none;
this._lastDirectionX = ScrollFeatures.direction.none;
this.trigger(ScrollFeatures.events.SCROLL_START);
if (Can.animationFrame) {
this.nextFrameID = window.requestAnimationFrame(this.onNextFrame);
} else {
this.onNextFrame();
}
}
}, {
key: 'onNextFrame',
value: function onNextFrame() {
var _this3 = this;
};
this._speedY = this._scrollY - this.scrollY;
this._speedX = this._scrollX - this.scrollX;
ScrollFeatures.prototype.onNextFrame = function onNextFrame() {
var _this2 = this;
var speed = +this.speedY + +this.speedX;
if (this._scrolling && speed === 0 && this._currentStopFrames++ > this._stopFrames) {
this.onScrollStop();
return;
}
this._speedY = this._y - this.y;
this._speedX = this._x - this.x;
this.updateScrollPosition();
var speed = +this.speedY + +this.speedX;
if (this._scrolling && speed === 0 && this._currentStopFrames++ > this._stopFrames) {
this.onScrollStop();
return;
}
if (this._lastDirectionY !== this.directionY) {
this.trigger('scroll:' + ScrollFeatures.directionToString(this.directionY));
}
if (this._lastDirectionX !== this.directionX) {
this.trigger('scroll:' + ScrollFeatures.directionToString(this.directionX));
}
this.updateScrollPosition();
this._lastDirectionY = this.directionY;
this._lastDirectionX = this.directionX;
if (this._lastDirectionY !== this.directionY) {
this.trigger('scroll:' + (this.directionY === ScrollFeatures.direction.down ? 'down' : 'up'));
}
if (this._lastDirectionX !== this.directionX) {
this.trigger('scroll:' + (this.directionX === ScrollFeatures.direction.right ? 'right' : 'left'));
}
this.trigger(ScrollFeatures.EVENT_SCROLL_PROGRESS);
this._lastDirectionY = this.directionY;
this._lastDirectionX = this.directionX;
if (Can.animationFrame) {
this.nextFrameID = window.requestAnimationFrame(this.onNextFrame);
} else {
this._nextTimeout = setTimeout(function () {
_this3.onNextFrame();
}, 1000 / 60);
}
this.trigger(ScrollFeatures.events.SCROLL_PROGRESS);
if (Can.animationFrame) {
this.nextFrameID = window.requestAnimationFrame(this.onNextFrame);
} else {
this._nextTimeout = setTimeout(function () {
_this2.onNextFrame();
}, 1000 / 60);
}
}, {
key: 'onScrollStop',
value: function onScrollStop() {
};
this._scrolling = false;
this.updateScrollPosition();
ScrollFeatures.prototype.onScrollStop = function onScrollStop() {
this.trigger(ScrollFeatures.EVENT_SCROLL_STOP);
this._scrolling = false;
this.updateScrollPosition();
if (this._canScrollY) {
if (this.y <= 0) {
this.trigger(ScrollFeatures.EVENT_SCROLL_MIN);
} else if (this.y + this.clientHeight >= this.scrollHeight) {
this.trigger(ScrollFeatures.EVENT_SCROLL_MAX);
}
this.trigger(ScrollFeatures.events.SCROLL_STOP);
if (this._canScrollY) {
if (this.y <= 0) {
this.trigger(ScrollFeatures.events.SCROLL_MIN);
} else if (this.y + this.clientHeight >= this.scrollHeight) {
this.trigger(ScrollFeatures.events.SCROLL_MAX);
}
}
if (this._canScrollX) {
if (this.x <= 0) {
this.trigger(ScrollFeatures.EVENT_SCROLL_MIN);
} else if (this.x + this.clientWidth >= this.scrollWidth) {
this.trigger(ScrollFeatures.EVENT_SCROLL_MAX);
}
if (this._canScrollX) {
if (this.x <= 0) {
this.trigger(ScrollFeatures.events.SCROLL_MIN);
} else if (this.x + this.clientWidth >= this.scrollWidth) {
this.trigger(ScrollFeatures.events.SCROLL_MAX);
}
}
this._currentStopFrames = 0;
this._cancelNextFrame();
this._cancelNextFrame();
};
ScrollFeatures.prototype._cancelNextFrame = function _cancelNextFrame() {
this._currentStopFrames = 0;
if (Can.animationFrame) {
window.cancelAnimationFrame(this.nextFrameID);
this.nextFrameID = -1;
} else {
clearTimeout(this._nextTimeout);
}
}, {
key: '_cancelNextFrame',
value: function _cancelNextFrame() {
if (Can.animationFrame) {
window.cancelAnimationFrame(this.nextFrameID);
this.nextFrameID = -1;
} else {
clearTimeout(this._nextTimeout);
}
}
}, {
};
_createClass(ScrollFeatures, [{
key: 'destroyed',

@@ -340,8 +294,8 @@ get: function get() {

if (!this._canScrollY || this.speedY === 0 && !this._scrolling) {
this._directionY = ScrollFeatures.NONE;
this._directionY = ScrollFeatures.direction.none;
} else {
if (this.speedY > 0) {
this._directionY = ScrollFeatures.UP;
this._directionY = ScrollFeatures.direction.up;
} else if (this.speedY < 0) {
this._directionY = ScrollFeatures.DOWN;
this._directionY = ScrollFeatures.direction.down;
}

@@ -355,8 +309,8 @@ }

if (!this._canScrollX || this.speedX === 0 && !this._scrolling) {
this._directionX = ScrollFeatures.NONE;
this._directionX = ScrollFeatures.direction.none;
} else {
if (this.speedX > 0) {
this._directionX = ScrollFeatures.LEFT;
this._directionX = ScrollFeatures.direction.left;
} else if (this.speedX < 0) {
this._directionX = ScrollFeatures.RIGHT;
this._directionX = ScrollFeatures.direction.right;
}

@@ -372,7 +326,2 @@ }

}, {
key: 'delta',
get: function get() {
return this.directionY;
}
}, {
key: 'scrolling',

@@ -403,3 +352,3 @@ get: function get() {

}, {
key: 'scrollY',
key: 'y',
get: function get() {

@@ -409,17 +358,7 @@ return this.scrollPosition.y;

}, {
key: 'y',
key: 'x',
get: function get() {
return this.scrollY;
}
}, {
key: 'scrollX',
get: function get() {
return this.scrollPosition.x;
}
}, {
key: 'x',
get: function get() {
return this.scrollX;
}
}, {
key: 'clientHeight',

@@ -449,15 +388,19 @@ get: function get() {

ScrollFeatures.UP = -1;
ScrollFeatures.DOWN = 1;
ScrollFeatures.NONE = 0;
ScrollFeatures.RIGHT = 2;
ScrollFeatures.LEFT = -2;
ScrollFeatures.EVENT_SCROLL_PROGRESS = 'scroll:progress';
ScrollFeatures.EVENT_SCROLL_START = 'scroll:start';
ScrollFeatures.EVENT_SCROLL_STOP = 'scroll:stop';
ScrollFeatures.EVENT_SCROLL_DOWN = 'scroll:down';
ScrollFeatures.EVENT_SCROLL_UP = 'scroll:up';
ScrollFeatures.EVENT_SCROLL_MIN = 'scroll:min';
ScrollFeatures.EVENT_SCROLL_MAX = 'scroll:max';
ScrollFeatures.EVENT_SCROLL_RESIZE = 'scroll:resize';
ScrollFeatures.direction = {
up: -1,
down: 1,
none: 0,
right: 2,
left: -2
};
ScrollFeatures.events = {
SCROLL_PROGRESS: 'scroll:progress',
SCROLL_START: 'scroll:start',
SCROLL_STOP: 'scroll:stop',
SCROLL_DOWN: 'scroll:down',
SCROLL_UP: 'scroll:up',
SCROLL_MIN: 'scroll:min',
SCROLL_MAX: 'scroll:max',
SCROLL_RESIZE: 'scroll:resize'
};
exports.default = ScrollFeatures;

@@ -464,0 +407,0 @@

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

!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,e.ScrollFeatures=t()}}(function(){return function t(e,i,n){function r(s,l){if(!i[s]){if(!e[s]){var c="function"==typeof require&&require;if(!l&&c)return c(s,!0);if(o)return o(s,!0);var a=new Error("Cannot find module '"+s+"'");throw a.code="MODULE_NOT_FOUND",a}var u=i[s]={exports:{}};e[s][0].call(u.exports,function(t){var i=e[s][1][t];return r(i?i:t)},u,u.exports,t,e,i,n)}return i[s].exports}for(var o="function"==typeof require&&require,s=0;s<n.length;s++)r(n[s]);return r}({1:[function(t,e){var i=function(t,e){var i=arguments.length<=2?[]:[].slice.call(arguments,2);return function(){return e.apply(t,arguments.length?i.slice().concat([].slice.call(arguments)):i)}};e.exports=i},{}],2:[function(t,e,i){"use strict";function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function r(t){for(var e in t)if(t.hasOwnProperty(e))return!1;return!0}Object.defineProperty(i,"__esModule",{value:!0});var o=function(){function t(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],i=e.target,r=e.currentTarget;n(this,t),this._eventMap={},this._destroyed=!1,this._target=i||this,this._currentTarget=r||this,this.on=this.bind=this.addEventListener=this.addListener,this.off=this.unbind=this.removeEventListener=this.removeListener,this.once=this.one=this.addListenerOnce,this.emit=this.trigger=this.dispatchEvent=this.dispatch}return t.prototype.addListener=function(t,e){var i=this.getListener(t);return i?-1===i.indexOf(e)&&i.push(e):this._eventMap[t]=[e],this},t.prototype.addListenerOnce=function(t,e){var i=this,n=function(r){e(r),i.off(t,n),e=null,n=null};return this.on(t,n)},t.prototype.removeListener=function(t,e){if(!e)return this.removeAllListener(t);var i=this.getListener(t);if(i){var n=i.indexOf(e);n>-1&&(i=i.splice(n,1),i.length||delete this._eventMap[t])}return this},t.prototype.removeAllListener=function(t){var e=this.getListener(t);return e&&(this._eventMap[t].length=0,delete this._eventMap[t]),this},t.prototype.hasListener=function(t){return null!==this.getListener(t)},t.prototype.hasListeners=function(){return null!==this._eventMap&&void 0!==this._eventMap&&!r(this._eventMap)},t.prototype.dispatch=function(t,e){var i=this.getListener(t);if(i){e=e||{},e.type=t,e.target=e.target||this._target,e.currentTarget=e.currentTarget||this._currentTarget;for(var n=-1;++n<i.length;)i[n](e)}return this},t.prototype.getListener=function(t){var e=this._eventMap?this._eventMap[t]:null;return e||null},t.prototype.destroy=function(){if(this._eventMap){for(var t in this._eventMap)this.removeAllListener(t);this._eventMap=null}return this._destroyed=!0,this},t}();i["default"]=o,e.exports=i["default"]},{}],3:[function(t,e){"use strict";var i=/(auto|scroll)/,n=function(t){var e=window.getComputedStyle(t,null);return i.test(e.getPropertyValue("overflow")+e.getPropertyValue("overflow-y")+e.getPropertyValue("overflow-x"))};e.exports=n},{}],4:[function(t,e){"use strict";var i=t("./has-overflow"),n=function(t){if(!(t instanceof HTMLElement))return window;for(;t.parentNode;){if(t.parentNode===document.body)return window;if(i(t.parentNode))return t.parentNode;t=t.parentNode}return window};e.exports=n},{"./has-overflow":3}],5:[function(t,e,i){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function o(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function s(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}Object.defineProperty(i,"__esModule",{value:!0});var l=function v(t,e,i){null===t&&(t=Function.prototype);var n=Object.getOwnPropertyDescriptor(t,e);if(void 0===n){var r=Object.getPrototypeOf(t);return null===r?void 0:v(r,e,i)}if("value"in n)return n.value;var o=n.get;return void 0===o?void 0:o.call(i)},c=function(){function t(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,i,n){return i&&t(e.prototype,i),n&&t(e,n),e}}(),a=t("delegatejs"),u=n(a),h=t("eventdispatcher"),d=n(h),f=t("./scroll-parent"),g=n(f),_=function(t){function e(){var t=arguments.length<=0||void 0===arguments[0]?window:arguments[0],i=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];if(r(this,e),e.hasInstance(t)){var n;return n=e.getInstance(t),o(s,n)}var s=o(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,{target:t}));return t.scrollFeatures=s,s._scrollTarget=t,s.options=i,m.animationFrame&&e.unprefixAnimationFrame(),s.init(),s}return s(e,t),c(e,null,[{key:"getInstance",value:function(t,i){return t.scrollFeatures?t.scrollFeatures:new e(t,i)}},{key:"hasInstance",value:function(t){return"undefined"!=typeof t.scrollFeatures}},{key:"getScrollParent",value:function(t){return g["default"](t)}},{key:"unprefixAnimationFrame",value:function(){window.requestAnimationFrame||(window.requestAnimationFrame=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.msRequestAnimationFrame,window.cancelAnimationFrame=window.cancelAnimationFrame||window.mozCancelAnimationFrame||window.webkitCancelAnimationFrame||window.msCancelAnimationFrame)}},{key:"directionToString",value:function(t){switch(t){case e.UP:return"up";case e.DOWN:return"down";case e.NONE:return"none";case e.LEFT:return"left";case e.RIGHT:return"right"}}},{key:"windowScrollY",get:function(){return window.pageYOffset||window.scrollY||0}},{key:"windowScrollX",get:function(){return window.pageXOffset||window.scrollX||0}},{key:"documentHeight",get:function(){return Math.max(document.body.scrollHeight,document.body.offsetHeight,document.documentElement.clientHeight,document.documentElement.scrollHeight,document.documentElement.offsetHeight)}},{key:"documentWidth",get:function(){return Math.max(document.body.scrollWidth,document.body.offsetWidth,document.documentElement.clientWidth,document.documentElement.scrollWidth,document.documentElement.offsetWidth)}}]),c(e,[{key:"init",value:function(){var t=this;if(this._destroyed=!1,this._scrollY=0,this._scrollX=0,this._speedY=0,this._speedX=0,this._lastSpeed=0,this._lastDirectionY=e.NONE,this._lastDirectionX=e.NONE,this._stopFrames=3,this._currentStopFrames=0,this._firstRender=!0,this._directionY=e.NONE,this._directionX=e.NONE,this._scrolling=!1,this._canScrollY=!1,this._canScrollX=!1,this.getScrollPosition=u["default"](this,this._scrollTarget===window?this._getWindowScrollPosition:this._getElementScrollPosition),this.onResize=u["default"](this,function(){return t.trigger(e.EVENT_SCROLL_RESIZE)}),this.onScroll=u["default"](this,this.onScroll),this.onNextFrame=u["default"](this,this.onNextFrame),this.updateScrollPosition(),this._scrollTarget!==window){var i=/(auto|scroll)/,n=window.getComputedStyle(this._scrollTarget,null);this._canScrollY=i.test(n.getPropertyValue("overflow-y")),this._canScrollX=i.test(n.getPropertyValue("overflow-x"))}else this._canScrollY=this.clientHeight<this.scrollHeight,this._canScrollX=this.clientWidth<this.scrollWidth;this._scrollTarget.addEventListener?(this._scrollTarget.addEventListener("scroll",this.onScroll,!1),this._scrollTarget.addEventListener("resize",this.onResize,!1)):this._scrollTarget.attachEvent&&(this._scrollTarget.attachEvent("scroll",this.onScroll),this._scrollTarget.attachEvent("resize",this.onResize))}},{key:"destroy",value:function(){this._destroyed||(this._cancelNextFrame(),l(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"destroy",this).call(this),this._scrollTarget.addEventListener?(this._scrollTarget.removeEventListener("scroll",this.onScroll),this._scrollTarget.removeEventListener("resize",this.onResize)):this._scrollTarget.attachEvent&&(this._scrollTarget.detachEvent("scroll",this.onScroll),this._scrollTarget.detachEvent("resize",this.onResize)),this.onResize=null,this.onScroll=null,this.getScrollPosition=null,this.onNextFrame=null,delete this._scrollTarget.scrollFeatures,this._scrollTarget=null,this._destroyed=!0)}},{key:"updateScrollPosition",value:function(){this._scrollY=this.scrollY,this._scrollX=this.scrollX}},{key:"_getWindowScrollPosition",value:function(){return{y:e.windowScrollY,x:e.windowScrollX}}},{key:"_getElementScrollPosition",value:function(){return{y:this._scrollTarget.scrollTop,x:this._scrollTarget.scrollLeft}}},{key:"onScroll",value:function(){return this._currentStopFrames=0,this._firstRender&&(this._firstRender=!1,this.y>1||this.x>1)?(this.updateScrollPosition(),void this.trigger(e.EVENT_SCROLL_PROGRESS)):void(this._scrolling||(this._scrolling=!0,this._lastDirectionY=e.NONE,this._lastDirectionX=e.NONE,this.trigger(e.EVENT_SCROLL_START),m.animationFrame?this.nextFrameID=window.requestAnimationFrame(this.onNextFrame):this.onNextFrame()))}},{key:"onNextFrame",value:function(){var t=this;this._speedY=this._scrollY-this.scrollY,this._speedX=this._scrollX-this.scrollX;var i=+this.speedY+ +this.speedX;return this._scrolling&&0===i&&this._currentStopFrames++>this._stopFrames?void this.onScrollStop():(this.updateScrollPosition(),this._lastDirectionY!==this.directionY&&this.trigger("scroll:"+e.directionToString(this.directionY)),this._lastDirectionX!==this.directionX&&this.trigger("scroll:"+e.directionToString(this.directionX)),this._lastDirectionY=this.directionY,this._lastDirectionX=this.directionX,this.trigger(e.EVENT_SCROLL_PROGRESS),void(m.animationFrame?this.nextFrameID=window.requestAnimationFrame(this.onNextFrame):this._nextTimeout=setTimeout(function(){t.onNextFrame()},1e3/60)))}},{key:"onScrollStop",value:function(){this._scrolling=!1,this.updateScrollPosition(),this.trigger(e.EVENT_SCROLL_STOP),this._canScrollY&&(this.y<=0?this.trigger(e.EVENT_SCROLL_MIN):this.y+this.clientHeight>=this.scrollHeight&&this.trigger(e.EVENT_SCROLL_MAX)),this._canScrollX&&(this.x<=0?this.trigger(e.EVENT_SCROLL_MIN):this.x+this.clientWidth>=this.scrollWidth&&this.trigger(e.EVENT_SCROLL_MAX)),this._currentStopFrames=0,this._cancelNextFrame()}},{key:"_cancelNextFrame",value:function(){m.animationFrame?(window.cancelAnimationFrame(this.nextFrameID),this.nextFrameID=-1):clearTimeout(this._nextTimeout)}},{key:"destroyed",get:function(){return this._destroyed}},{key:"scrollPosition",get:function(){return this.getScrollPosition()}},{key:"directionY",get:function(){return!this._canScrollY||0===this.speedY&&!this._scrolling?this._directionY=e.NONE:this.speedY>0?this._directionY=e.UP:this.speedY<0&&(this._directionY=e.DOWN),this._directionY}},{key:"directionX",get:function(){return!this._canScrollX||0===this.speedX&&!this._scrolling?this._directionX=e.NONE:this.speedX>0?this._directionX=e.LEFT:this.speedX<0&&(this._directionX=e.RIGHT),this._directionX}},{key:"scrollTarget",get:function(){return this._scrollTarget}},{key:"delta",get:function(){return this.directionY}},{key:"scrolling",get:function(){return this._scrolling}},{key:"speedY",get:function(){return this._speedY}},{key:"speedX",get:function(){return this._speedX}},{key:"canScrollY",get:function(){return this._canScrollY}},{key:"canScrollX",get:function(){return this._canScrollX}},{key:"scrollY",get:function(){return this.scrollPosition.y}},{key:"y",get:function(){return this.scrollY}},{key:"scrollX",get:function(){return this.scrollPosition.x}},{key:"x",get:function(){return this.scrollX}},{key:"clientHeight",get:function(){return this._scrollTarget===window?window.innerHeight:this._scrollTarget.clientHeight}},{key:"clientWidth",get:function(){return this._scrollTarget===window?window.innerWidth:this._scrollTarget.clientWidth}},{key:"scrollHeight",get:function(){return this._scrollTarget===window?e.documentHeight:this._scrollTarget.scrollHeight}},{key:"scrollWidth",get:function(){return this._scrollTarget===window?e.documentWidth:this._scrollTarget.scrollWidth}}]),e}(d["default"]);_.UP=-1,_.DOWN=1,_.NONE=0,_.RIGHT=2,_.LEFT=-2,_.EVENT_SCROLL_PROGRESS="scroll:progress",_.EVENT_SCROLL_START="scroll:start",_.EVENT_SCROLL_STOP="scroll:stop",_.EVENT_SCROLL_DOWN="scroll:down",_.EVENT_SCROLL_UP="scroll:up",_.EVENT_SCROLL_MIN="scroll:min",_.EVENT_SCROLL_MAX="scroll:max",_.EVENT_SCROLL_RESIZE="scroll:resize",i["default"]=_;var p=null,m=function(){function t(){r(this,t)}return c(t,null,[{key:"animationFrame",get:function(){return null===p&&(p=!!(window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.msRequestAnimationFrame)),p}}]),t}();e.exports=i["default"]},{"./scroll-parent":4,delegatejs:1,eventdispatcher:2}]},{},[5])(5)});
!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,e.ScrollFeatures=t()}}(function(){return function t(e,n,i){function r(s,l){if(!n[s]){if(!e[s]){var c="function"==typeof require&&require;if(!l&&c)return c(s,!0);if(o)return o(s,!0);var a=new Error("Cannot find module '"+s+"'");throw a.code="MODULE_NOT_FOUND",a}var h=n[s]={exports:{}};e[s][0].call(h.exports,function(t){var n=e[s][1][t];return r(n?n:t)},h,h.exports,t,e,n,i)}return n[s].exports}for(var o="function"==typeof require&&require,s=0;s<i.length;s++)r(i[s]);return r}({1:[function(t,e,n){"use strict";function i(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function r(t){for(var e in t)if(t.hasOwnProperty(e))return!1;return!0}Object.defineProperty(n,"__esModule",{value:!0});var o=function(){function t(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],n=e.target,r=e.currentTarget;i(this,t),this._eventMap={},this._destroyed=!1,this._target=n||this,this._currentTarget=r||this,this.on=this.bind=this.addEventListener=this.addListener,this.off=this.unbind=this.removeEventListener=this.removeListener,this.once=this.one=this.addListenerOnce,this.emit=this.trigger=this.dispatchEvent=this.dispatch}return t.prototype.addListener=function(t,e){var n=this.getListener(t);return n?-1===n.indexOf(e)&&n.push(e):this._eventMap[t]=[e],this},t.prototype.addListenerOnce=function(t,e){var n=this,i=function(r){e(r),n.off(t,i),e=null,i=null};return this.on(t,i)},t.prototype.removeListener=function(t,e){if(!e)return this.removeAllListener(t);var n=this.getListener(t);if(n){var i=n.indexOf(e);i>-1&&(n=n.splice(i,1),n.length||delete this._eventMap[t])}return this},t.prototype.removeAllListener=function(t){var e=this.getListener(t);return e&&(this._eventMap[t].length=0,delete this._eventMap[t]),this},t.prototype.hasListener=function(t){return null!==this.getListener(t)},t.prototype.hasListeners=function(){return null!==this._eventMap&&void 0!==this._eventMap&&!r(this._eventMap)},t.prototype.dispatch=function(t,e){var n=this.getListener(t);if(n){e=e||{},e.type=t,e.target=e.target||this._target,e.currentTarget=e.currentTarget||this._currentTarget;for(var i=-1;++i<n.length;)n[i](e)}return this},t.prototype.getListener=function(t){var e=this._eventMap?this._eventMap[t]:null;return e||null},t.prototype.destroy=function(){if(this._eventMap){for(var t in this._eventMap)this.removeAllListener(t);this._eventMap=null}return this._destroyed=!0,this},t}();n["default"]=o,e.exports=n["default"]},{}],2:[function(t,e){"use strict";e.exports=t("./dist/eventdispatcher")},{"./dist/eventdispatcher":1}],3:[function(t,e){"use strict";var n=/(auto|scroll)/,i=function(t){var e=window.getComputedStyle(t,null);return n.test(e.getPropertyValue("overflow")+e.getPropertyValue("overflow-y")+e.getPropertyValue("overflow-x"))};e.exports=i},{}],4:[function(t,e){"use strict";var n=t("./has-overflow"),i=function(t){if(!(t instanceof HTMLElement))return window;for(;t.parentNode;){if(t.parentNode===document.body)return window;if(n(t.parentNode))return t.parentNode;t=t.parentNode}return window};e.exports=i},{"./has-overflow":3}],5:[function(t,e,n){"use strict";function i(t){return t&&t.__esModule?t:{"default":t}}function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function o(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!==("undefined"==typeof e?"undefined":l(e))&&"function"!=typeof e?t:e}function s(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+("undefined"==typeof e?"undefined":l(e)));t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}var l="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};Object.defineProperty(n,"__esModule",{value:!0});var c=function(){function t(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(e,n,i){return n&&t(e.prototype,n),i&&t(e,i),e}}(),a=t("eventdispatcher"),h=i(a),u=t("./scroll-parent"),d=i(u),f=function(){window.requestAnimationFrame||(window.requestAnimationFrame=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.msRequestAnimationFrame,window.cancelAnimationFrame=window.cancelAnimationFrame||window.mozCancelAnimationFrame||window.webkitCancelAnimationFrame||window.msCancelAnimationFrame)},p=function(t){function e(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:window,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(r(this,e),e.hasInstance(n)){var s;return s=e.getInstance(n),o(l,s)}var l=o(this,t.call(this,{target:n}));return l._scrollTarget=null,l._destroyed=!1,l._y=0,l._x=0,l._speedY=0,l._speedX=0,l._lastSpeed=0,l._lastDirectionY=e.direction.none,l._lastDirectionX=e.direction.none,l._stopFrames=3,l._currentStopFrames=0,l._firstRender=!0,l._directionY=e.direction.none,l._directionX=e.direction.none,l._scrolling=!1,l._canScrollY=!1,l._canScrollX=!1,n.scrollFeatures=l,l._scrollTarget=n,l.options=i,_.animationFrame&&f(),l.init(),l}return s(e,t),e.getInstance=function(t,n){return t.scrollFeatures?t.scrollFeatures:new e(t,n)},e.hasInstance=function(t){return"undefined"!=typeof t.scrollFeatures},e.getScrollParent=function(t){return d["default"](t)},c(e,null,[{key:"windowY",get:function(){return window.pageYOffset||window.y||0}},{key:"windowX",get:function(){return window.pageXOffset||window.scrollX||0}},{key:"documentHeight",get:function(){return Math.max(document.body.scrollHeight,document.body.offsetHeight,document.documentElement.clientHeight,document.documentElement.scrollHeight,document.documentElement.offsetHeight)}},{key:"documentWidth",get:function(){return Math.max(document.body.scrollWidth,document.body.offsetWidth,document.documentElement.clientWidth,document.documentElement.scrollWidth,document.documentElement.offsetWidth)}}]),e.prototype.init=function(){if(this.getScrollPosition=this._scrollTarget===window?function(){return{y:e.windowY,x:e.windowX}}.bind(this):function(){return{y:this._scrollTarget.scrollTop,x:this._scrollTarget.scrollLeft}}.bind(this),this.onResize=this.trigger.bind(this,e.events.SCROLL_RESIZE),this.onScroll=this.onScroll.bind(this),this.onNextFrame=this.onNextFrame.bind(this),this.updateScrollPosition(),this._scrollTarget!==window){var t=/(auto|scroll)/,n=window.getComputedStyle(this._scrollTarget,null);this._canScrollY=t.test(n.getPropertyValue("overflow-y")),this._canScrollX=t.test(n.getPropertyValue("overflow-x"))}else this._canScrollY=this.clientHeight<this.scrollHeight,this._canScrollX=this.clientWidth<this.scrollWidth;this._scrollTarget.addEventListener?(this._scrollTarget.addEventListener("scroll",this.onScroll,!1),this._scrollTarget.addEventListener("resize",this.onResize,!1)):this._scrollTarget.attachEvent&&(this._scrollTarget.attachEvent("scroll",this.onScroll),this._scrollTarget.attachEvent("resize",this.onResize))},e.prototype.destroy=function(){this._destroyed||(this._cancelNextFrame(),t.prototype.destroy.call(this),this._scrollTarget.addEventListener?(this._scrollTarget.removeEventListener("scroll",this.onScroll),this._scrollTarget.removeEventListener("resize",this.onResize)):this._scrollTarget.attachEvent&&(this._scrollTarget.detachEvent("scroll",this.onScroll),this._scrollTarget.detachEvent("resize",this.onResize)),this.onResize=null,this.onScroll=null,this.getScrollPosition=null,this.onNextFrame=null,delete this._scrollTarget.scrollFeatures,this._scrollTarget=null,this._destroyed=!0)},e.prototype.updateScrollPosition=function(){this._y=this.y,this._x=this.x},e.prototype.onScroll=function(){return this._currentStopFrames=0,this._firstRender&&(this._firstRender=!1,this.y>1||this.x>1)?(this.updateScrollPosition(),void this.trigger(e.events.SCROLL_PROGRESS)):void(this._scrolling||(this._scrolling=!0,this._lastDirectionY=e.direction.none,this._lastDirectionX=e.direction.none,this.trigger(e.events.SCROLL_START),_.animationFrame?this.nextFrameID=window.requestAnimationFrame(this.onNextFrame):this.onNextFrame()))},e.prototype.onNextFrame=function(){var t=this;this._speedY=this._y-this.y,this._speedX=this._x-this.x;var n=+this.speedY+ +this.speedX;return this._scrolling&&0===n&&this._currentStopFrames++>this._stopFrames?void this.onScrollStop():(this.updateScrollPosition(),this._lastDirectionY!==this.directionY&&this.trigger("scroll:"+(this.directionY===e.direction.down?"down":"up")),this._lastDirectionX!==this.directionX&&this.trigger("scroll:"+(this.directionX===e.direction.right?"right":"left")),this._lastDirectionY=this.directionY,this._lastDirectionX=this.directionX,this.trigger(e.events.SCROLL_PROGRESS),void(_.animationFrame?this.nextFrameID=window.requestAnimationFrame(this.onNextFrame):this._nextTimeout=setTimeout(function(){t.onNextFrame()},1e3/60)))},e.prototype.onScrollStop=function(){this._scrolling=!1,this.updateScrollPosition(),this.trigger(e.events.SCROLL_STOP),this._canScrollY&&(this.y<=0?this.trigger(e.events.SCROLL_MIN):this.y+this.clientHeight>=this.scrollHeight&&this.trigger(e.events.SCROLL_MAX)),this._canScrollX&&(this.x<=0?this.trigger(e.events.SCROLL_MIN):this.x+this.clientWidth>=this.scrollWidth&&this.trigger(e.events.SCROLL_MAX)),this._cancelNextFrame()},e.prototype._cancelNextFrame=function(){this._currentStopFrames=0,_.animationFrame?(window.cancelAnimationFrame(this.nextFrameID),this.nextFrameID=-1):clearTimeout(this._nextTimeout)},c(e,[{key:"destroyed",get:function(){return this._destroyed}},{key:"scrollPosition",get:function(){return this.getScrollPosition()}},{key:"directionY",get:function(){return!this._canScrollY||0===this.speedY&&!this._scrolling?this._directionY=e.direction.none:this.speedY>0?this._directionY=e.direction.up:this.speedY<0&&(this._directionY=e.direction.down),this._directionY}},{key:"directionX",get:function(){return!this._canScrollX||0===this.speedX&&!this._scrolling?this._directionX=e.direction.none:this.speedX>0?this._directionX=e.direction.left:this.speedX<0&&(this._directionX=e.direction.right),this._directionX}},{key:"scrollTarget",get:function(){return this._scrollTarget}},{key:"scrolling",get:function(){return this._scrolling}},{key:"speedY",get:function(){return this._speedY}},{key:"speedX",get:function(){return this._speedX}},{key:"canScrollY",get:function(){return this._canScrollY}},{key:"canScrollX",get:function(){return this._canScrollX}},{key:"y",get:function(){return this.scrollPosition.y}},{key:"x",get:function(){return this.scrollPosition.x}},{key:"clientHeight",get:function(){return this._scrollTarget===window?window.innerHeight:this._scrollTarget.clientHeight}},{key:"clientWidth",get:function(){return this._scrollTarget===window?window.innerWidth:this._scrollTarget.clientWidth}},{key:"scrollHeight",get:function(){return this._scrollTarget===window?e.documentHeight:this._scrollTarget.scrollHeight}},{key:"scrollWidth",get:function(){return this._scrollTarget===window?e.documentWidth:this._scrollTarget.scrollWidth}}]),e}(h["default"]);p.direction={up:-1,down:1,none:0,right:2,left:-2},p.events={SCROLL_PROGRESS:"scroll:progress",SCROLL_START:"scroll:start",SCROLL_STOP:"scroll:stop",SCROLL_DOWN:"scroll:down",SCROLL_UP:"scroll:up",SCROLL_MIN:"scroll:min",SCROLL_MAX:"scroll:max",SCROLL_RESIZE:"scroll:resize"},n["default"]=p;var g=null,_=function(){function t(){r(this,t)}return c(t,null,[{key:"animationFrame",get:function(){return null===g&&(g=!!(window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.msRequestAnimationFrame)),g}}]),t}();e.exports=n["default"]},{"./scroll-parent":4,eventdispatcher:2}]},{},[5])(5)});
{
"name": "scrollfeatures",
"version": "1.1.0",
"version": "1.4.0",
"description": "Performant Custom Scroll Features and Events",
"main": "dist/scrollfeatures.js",
"jsnext:main": "src/scrollfeatures.js",
"scripts": {

@@ -24,22 +22,22 @@ "test": "echo \"Error: no test specified\" && exit 1",

"scroll",
"scroll direction",
"scroll speed",
"scrolling",
"scroll features",
"browser",
"enhanced",
"onscroll",
"animationframe",
"animation",
"enhanced scroll",
"scrollevents",
"scroll event",
"scroll behavior",
"fast",
"jankfree",
"jank",
"jank-free",
"perfomance",
"scroll perfomance",
"perfomant"
"scroll direction",
"scroll speed",
"scrolling",
"scroll features",
"browser",
"enhanced",
"onscroll",
"animationframe",
"animation",
"enhanced scroll",
"scrollevents",
"scroll event",
"scroll behavior",
"fast",
"jankfree",
"jank",
"jank-free",
"perfomance",
"scroll perfomance",
"perfomant"
],

@@ -52,20 +50,27 @@ "author": "Sönke Kluth <soenke.kluth@gmail.com> (http://soenkekluth.com/)",

"homepage": "https://github.com/soenkekluth/scrollfeatures#readme",
"browserify": {
"transform": [
"babelify"
]
},
"dependencies": {
"delegatejs": "1.1.0",
"eventdispatcher": "1.6.0"
"eventdispatcher": "2.1.0"
},
"devDependencies": {
"babel-cli": "6.14.0",
"babel-core": "6.14.0",
"babel-cli": "6.16.0",
"babel-core": "6.17.0",
"babel-plugin-add-module-exports": "0.2.1",
"babel-plugin-transform-class-constructor-call": "6.8.0",
"babel-plugin-transform-class-properties": "6.11.5",
"babel-plugin-transform-class-properties": "6.16.0",
"babel-plugin-transform-decorators-legacy": "1.3.4",
"babel-plugin-transform-es2015-classes": "6.14.0",
"babel-plugin-transform-es2015-modules-commonjs": "6.16.0",
"babel-plugin-transform-es5-property-mutators": "6.8.0",
"babel-plugin-transform-proto-to-assign": "6.9.0",
"babel-plugin-transform-remove-console": "6.8.0",
"babel-preset-es2015": "6.14.0",
"babel-preset-stage-0": "6.5.0",
"babel-preset-es2015": "6.16.0",
"babel-preset-es2015-allow-top-level-this": "0.0.1",
"babel-preset-stage-0": "6.16.0",
"babelify": "7.3.0",
"browser-sync": "2.15.0",
"browser-sync": "2.17.0",
"browserify": "13.1.0",

@@ -72,0 +77,0 @@ "derequire": "2.0.3",

@@ -1,7 +0,32 @@

import delegate from 'delegatejs';
import EventDispatcher from 'eventdispatcher';
import scrollParent from './scroll-parent';
const unprefixAnimationFrame = () => {
if (!window.requestAnimationFrame) {
window.requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;
window.cancelAnimationFrame = window.cancelAnimationFrame || window.mozCancelAnimationFrame || window.webkitCancelAnimationFrame || window.msCancelAnimationFrame;
}
}
export default class ScrollFeatures extends EventDispatcher {
_scrollTarget = null;
_destroyed = false;
_y = 0;
_x = 0;
_speedY = 0;
_speedX = 0;
_lastSpeed = 0;
_lastDirectionY = ScrollFeatures.direction.none;
_lastDirectionX = ScrollFeatures.direction.none;
_stopFrames = 3;
_currentStopFrames = 0;
_firstRender = true;
_directionY = ScrollFeatures.direction.none;
_directionX = ScrollFeatures.direction.none;
_scrolling = false;
_canScrollY = false;
_canScrollX = false;
static getInstance(scrollTarget, options) {

@@ -22,7 +47,7 @@ if (!scrollTarget.scrollFeatures) {

static get windowScrollY() {
return (window.pageYOffset || window.scrollY || 0);
static get windowY() {
return (window.pageYOffset || window.y || 0);
}
static get windowScrollX() {
static get windowX() {
return (window.pageXOffset || window.scrollX || 0);

@@ -39,40 +64,22 @@ }

static unprefixAnimationFrame() {
if (!window.requestAnimationFrame) {
window.requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;
window.cancelAnimationFrame = window.cancelAnimationFrame || window.mozCancelAnimationFrame || window.webkitCancelAnimationFrame || window.msCancelAnimationFrame;
}
}
static direction = {
up: -1,
down: 1,
none: 0,
right: 2,
left: -2
};
static UP = -1;
static DOWN = 1;
static NONE = 0;
static RIGHT = 2;
static LEFT = -2;
static events = {
SCROLL_PROGRESS: 'scroll:progress',
SCROLL_START: 'scroll:start',
SCROLL_STOP: 'scroll:stop',
SCROLL_DOWN: 'scroll:down',
SCROLL_UP: 'scroll:up',
SCROLL_MIN: 'scroll:min',
SCROLL_MAX: 'scroll:max',
SCROLL_RESIZE: 'scroll:resize'
};
static EVENT_SCROLL_PROGRESS = 'scroll:progress';
static EVENT_SCROLL_START = 'scroll:start';
static EVENT_SCROLL_STOP = 'scroll:stop';
static EVENT_SCROLL_DOWN = 'scroll:down';
static EVENT_SCROLL_UP = 'scroll:up';
static EVENT_SCROLL_MIN = 'scroll:min';
static EVENT_SCROLL_MAX = 'scroll:max';
static EVENT_SCROLL_RESIZE = 'scroll:resize';
static directionToString(direction) {
switch (direction) {
case ScrollFeatures.UP:
return 'up';
case ScrollFeatures.DOWN:
return 'down';
case ScrollFeatures.NONE:
return 'none';
case ScrollFeatures.LEFT:
return 'left';
case ScrollFeatures.RIGHT:
return 'right';
}
}
constructor(scrollTarget = window, options = {}) {

@@ -91,3 +98,3 @@

if (Can.animationFrame) {
ScrollFeatures.unprefixAnimationFrame();
unprefixAnimationFrame();
}

@@ -100,25 +107,8 @@

this._destroyed = false;
this._scrollY = 0;
this._scrollX = 0;
this._speedY = 0;
this._speedX = 0;
this._lastSpeed = 0;
this._lastDirectionY = ScrollFeatures.NONE;
this._lastDirectionX = ScrollFeatures.NONE;
this._stopFrames = 3;
this._currentStopFrames = 0;
this._firstRender = true;
this._directionY = ScrollFeatures.NONE;
this._directionX = ScrollFeatures.NONE;
this._scrolling = false;
this._canScrollY = false;
this._canScrollX = false;
this.getScrollPosition = (this._scrollTarget === window ? (function() {return { y: ScrollFeatures.windowY, x: ScrollFeatures.windowX }}.bind(this)) : (function() {return{ y: this._scrollTarget.scrollTop, x: this._scrollTarget.scrollLeft}}.bind(this)));
this.getScrollPosition = delegate(this, (this._scrollTarget === window ? this._getWindowScrollPosition : this._getElementScrollPosition));
this.onResize = this.trigger.bind(this, ScrollFeatures.events.SCROLL_RESIZE);
this.onScroll = this.onScroll.bind(this);
this.onNextFrame = this.onNextFrame.bind(this);
this.onResize = delegate(this, () => this.trigger(ScrollFeatures.EVENT_SCROLL_RESIZE));
this.onScroll = delegate(this, this.onScroll);
this.onNextFrame = delegate(this, this.onNextFrame);
this.updateScrollPosition();

@@ -131,3 +121,3 @@

this._canScrollX = regex.test(style.getPropertyValue('overflow-x'));
}else{
} else {
this._canScrollY = this.clientHeight < this.scrollHeight;

@@ -176,7 +166,6 @@ this._canScrollX = this.clientWidth < this.scrollWidth;

updateScrollPosition() {
this._scrollY = this.scrollY;
this._scrollX = this.scrollX;
this._y = this.y;
this._x = this.x;
}
get scrollPosition() {

@@ -186,11 +175,10 @@ return this.getScrollPosition();

get directionY() {
if (!this._canScrollY || (this.speedY === 0 && !this._scrolling)) {
this._directionY = ScrollFeatures.NONE;
this._directionY = ScrollFeatures.direction.none;
} else {
if (this.speedY > 0) {
this._directionY = ScrollFeatures.UP;
this._directionY = ScrollFeatures.direction.up;
} else if (this.speedY < 0) {
this._directionY = ScrollFeatures.DOWN;
this._directionY = ScrollFeatures.direction.down;
}

@@ -203,8 +191,8 @@ }

if (!this._canScrollX || (this.speedX === 0 && !this._scrolling)) {
this._directionX = ScrollFeatures.NONE;
this._directionX = ScrollFeatures.direction.none;
} else {
if (this.speedX > 0) {
this._directionX = ScrollFeatures.LEFT;
this._directionX = ScrollFeatures.direction.left;
} else if (this.speedX < 0) {
this._directionX = ScrollFeatures.RIGHT;
this._directionX = ScrollFeatures.direction.right;
}

@@ -219,6 +207,2 @@ }

get delta() {
return this.directionY;
}
get scrolling() {

@@ -244,19 +228,10 @@ return this._scrolling;

get scrollY() {
get y() {
return this.scrollPosition.y;
}
get y() {
return this.scrollY;
}
get scrollX() {
get x() {
return this.scrollPosition.x;
}
get x() {
return this.scrollX;
}
get clientHeight() {

@@ -270,3 +245,2 @@ return (this._scrollTarget === window ? window.innerHeight : this._scrollTarget.clientHeight);

get scrollHeight() {

@@ -280,15 +254,3 @@ return (this._scrollTarget === window ? ScrollFeatures.documentHeight : this._scrollTarget.scrollHeight);

_getWindowScrollPosition() {
return {
y: ScrollFeatures.windowScrollY,
x: ScrollFeatures.windowScrollX
};
}
_getElementScrollPosition() {
return {
y: this._scrollTarget.scrollTop,
x: this._scrollTarget.scrollLeft
};
}

@@ -302,3 +264,3 @@

this.updateScrollPosition();
this.trigger(ScrollFeatures.EVENT_SCROLL_PROGRESS);
this.trigger(ScrollFeatures.events.SCROLL_PROGRESS);
return;

@@ -310,5 +272,5 @@ }

this._scrolling = true;
this._lastDirectionY = ScrollFeatures.NONE;
this._lastDirectionX = ScrollFeatures.NONE;
this.trigger(ScrollFeatures.EVENT_SCROLL_START);
this._lastDirectionY = ScrollFeatures.direction.none;
this._lastDirectionX = ScrollFeatures.direction.none;
this.trigger(ScrollFeatures.events.SCROLL_START);
if (Can.animationFrame) {

@@ -323,4 +285,4 @@ this.nextFrameID = window.requestAnimationFrame(this.onNextFrame);

onNextFrame() {
this._speedY = this._scrollY - this.scrollY;
this._speedX = this._scrollX - this.scrollX;
this._speedY = this._y - this.y;
this._speedX = this._x - this.x;

@@ -336,6 +298,6 @@ var speed = (+this.speedY) + (+this.speedX);

if (this._lastDirectionY !== this.directionY) {
this.trigger('scroll:' + ScrollFeatures.directionToString(this.directionY));
this.trigger('scroll:' + (this.directionY === ScrollFeatures.direction.down ? 'down' : 'up'));
}
if (this._lastDirectionX !== this.directionX) {
this.trigger('scroll:' + ScrollFeatures.directionToString(this.directionX));
this.trigger('scroll:' + (this.directionX === ScrollFeatures.direction.right ? 'right' : 'left'));
}

@@ -346,3 +308,3 @@

this.trigger(ScrollFeatures.EVENT_SCROLL_PROGRESS);
this.trigger(ScrollFeatures.events.SCROLL_PROGRESS);

@@ -363,9 +325,9 @@ if (Can.animationFrame) {

this.trigger(ScrollFeatures.EVENT_SCROLL_STOP);
this.trigger(ScrollFeatures.events.SCROLL_STOP);
if (this._canScrollY) {
if (this.y <= 0) {
this.trigger(ScrollFeatures.EVENT_SCROLL_MIN);
this.trigger(ScrollFeatures.events.SCROLL_MIN);
} else if (this.y + this.clientHeight >= this.scrollHeight) {
this.trigger(ScrollFeatures.EVENT_SCROLL_MAX);
this.trigger(ScrollFeatures.events.SCROLL_MAX);
}

@@ -376,9 +338,8 @@ }

if (this.x <= 0) {
this.trigger(ScrollFeatures.EVENT_SCROLL_MIN);
this.trigger(ScrollFeatures.events.SCROLL_MIN);
} else if (this.x + this.clientWidth >= this.scrollWidth) {
this.trigger(ScrollFeatures.EVENT_SCROLL_MAX);
this.trigger(ScrollFeatures.events.SCROLL_MAX);
}
}
this._currentStopFrames = 0;
this._cancelNextFrame();

@@ -388,2 +349,3 @@ }

_cancelNextFrame() {
this._currentStopFrames = 0;
if (Can.animationFrame) {

@@ -390,0 +352,0 @@ window.cancelAnimationFrame(this.nextFrameID);

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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