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

wheel-gestures

Package Overview
Dependencies
Maintainers
1
Versions
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wheel-gestures - npm Package Compare versions

Comparing version 1.0.3 to 1.1.0

1

dist/wheel-analyzer/wheel-analyzer-types.d.ts

@@ -20,2 +20,3 @@ export declare type Vector3D = number[];

axisVelocity: Vector3D;
event: WheelEvent | WheelEventData;
}

@@ -22,0 +23,0 @@ export interface ScrollPoint {

14

dist/wheel-gestures.cjs.development.js

@@ -130,3 +130,4 @@ 'use strict';

var subscriptions = [];
var targets = []; // merge passed options with defaults (filter undefined option values)
var targets = [];
var currentEvent; // merge passed options with defaults (filter undefined option values)

@@ -181,4 +182,4 @@ var options = Object.entries(optionsParam).filter(function (_ref) {

var publish = function publish(type) {
var data = {
var publish = function publish(type, additionalData) {
var data = _extends({
type: type,

@@ -188,4 +189,6 @@ willEndSoon: willEndSoon(),

axisMovement: state.axisMovement,
axisVelocity: state.axisVelocity
};
axisVelocity: state.axisVelocity,
event: currentEvent
}, additionalData);
subscriptions.forEach(function (fn) {

@@ -248,2 +251,3 @@ return fn(type, data);

currentEvent = wheelEvent;
state.axisMovement = state.axisMovement.map(function (prevDelta, i) {

@@ -250,0 +254,0 @@ return prevDelta + clampDelta(normalizedWheel[deltaProp[axes[i]]]);

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

"use strict";function e(){return(e=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}function t(e){return e.reduce((function(e,t){return e+t}))/e.length}Object.defineProperty(exports,"__esModule",{value:!0});var n,r=[1,18,"undefined"!=typeof window&&window.innerHeight||800];(n=exports.WheelPhase||(exports.WheelPhase={})).ANY_WHEEL_START="ANY_WHEEL_START",n.ANY_WHEEL="ANY_WHEEL",n.ANY_WHEEL_END="ANY_WHEEL_END",n.WHEEL_START="WHEEL_START",n.WHEEL="WHEEL",n.WHEEL_END="WHEEL_END",n.MOMENTUM_WHEEL_START="MOMENTUM_WHEEL_START",n.MOMENTUM_WHEEL="MOMENTUM_WHEEL",n.MOMENTUM_WHEEL_CANCEL="MOMENTUM_WHEEL_CANCEL",n.MOMENTUM_WHEEL_END="MOMENTUM_WHEEL_END";var o,s,a=["x","y"],i={x:"deltaX",y:"deltaY"},l={preventWheelAction:"all"};function c(n){void 0===n&&(n={});var o,s={isStarted:!1,isStartPublished:!1,isMomentum:!1,lastAbsDelta:Infinity,axisMovement:[0,0],axisVelocity:[0,0],accelerationFactors:[],scrollPoints:[],scrollPointsToMerge:[],willEndTimeout:400},c=[],u=[],E=Object.entries(n).filter((function(e){return void 0!==e[1]})).reduce((function(e,t){var n;return Object.assign(e,((n={})[t[0]]=t[1],n))}),e({},l)),h=function(e){e.removeEventListener("wheel",m),u=u.filter((function(t){return t!==e}))},f=function(e){if(!e)throw new Error("please pass the callback which was used to subscribe");c=c.filter((function(t){return t!==e}))},M=function(e){var t={type:e,willEndSoon:N(),isMomentum:s.isMomentum,axisMovement:s.axisMovement,axisVelocity:s.axisVelocity};c.forEach((function(n){return n(e,t)}))},m=function(e){Array.isArray(e)?e.forEach((function(e){return p(e)})):p(e)},d=function(e){return Math.min(150,Math.max(-150,e))},p=function(e){var n,o={deltaX:(n=e).deltaX*r[n.deltaMode],deltaY:n.deltaY*r[n.deltaMode],deltaZ:(n.deltaZ||0)*r[n.deltaMode],deltaMode:0,timestamp:n.timeStamp};e.preventDefault&&function(e){var t=e.deltaX,n=e.deltaY;switch(E.preventWheelAction){case"all":return!0;case"x":return Math.abs(t)>=Math.abs(n);case"y":return Math.abs(n)>=Math.abs(t)}}(e)&&e.preventDefault(),s.isStarted||b();var l=d(Math.abs(o.deltaY)>Math.abs(o.deltaX)?o.deltaY:o.deltaX),c=Math.abs(l);if(s.isMomentum&&c>s.lastAbsDelta&&(L(),b()),s.axisMovement=s.axisMovement.map((function(e,t){return e+d(o[i[a[t]]])})),s.lastAbsDelta=c,s.scrollPointsToMerge.push({currentAbsDelta:c,axisDeltaUnclampt:[o.deltaX,o.deltaY],timestamp:e.timeStamp}),2===s.scrollPointsToMerge.length){var u=s.scrollPointsToMerge,h={currentAbsDelta:t(u.map((function(e){return e.currentAbsDelta}))),axisDeltaUnclampt:u.reduce((function(e,t){var n=t.axisDeltaUnclampt;return[e[0]+n[0],e[1]+n[1]]}),[0,0]),timestamp:t(u.map((function(e){return e.timestamp})))};s.scrollPoints.push(h),x(),s.isMomentum||T(),s.scrollPointsToMerge=[]}s.scrollPoints.length||W(),s.isStartPublished||(M(exports.WheelPhase.ANY_WHEEL_START),M(exports.WheelPhase.WHEEL_START),s.isStartPublished=!0),M(exports.WheelPhase.ANY_WHEEL),M(s.isMomentum?exports.WheelPhase.MOMENTUM_WHEEL:exports.WheelPhase.WHEEL),A()},W=function(){s.axisVelocity=s.scrollPointsToMerge[s.scrollPointsToMerge.length-1].axisDeltaUnclampt.map((function(e){return e/s.willEndTimeout}))},x=function(){var e=s.scrollPoints.slice(-2),t=e[0],n=e[1];if(t&&n){var r=n.timestamp-t.timestamp;if(!(r<=0)){var o=n.axisDeltaUnclampt.map((function(e){return e/r})),a=o.map((function(e,t){return e/(s.axisVelocity[t]||1)}));s.axisVelocity=o,s.accelerationFactors.push(a),v(r)}}},v=function(e){var t=10*Math.ceil(e/10)*1.2;s.isMomentum||(t=Math.max(100,2*t)),s.willEndTimeout=Math.min(1e3,Math.round(t))},_=function(e){return 0===e||e<=.96&&e>=.6},T=function(){if(s.accelerationFactors.length<5)return s.isMomentum;var e=s.accelerationFactors.slice(-5),t=e.reduce((function(e,t){if(!e)return!1;var n=!!t.reduce((function(e,t){return e&&e<1&&e===t?1:0})),r=t.filter(_).length===t.length;return n||r}),!0);return s.accelerationFactors=e,t&&!s.isMomentum&&(M(exports.WheelPhase.WHEEL_END),s.isMomentum=!0,M(exports.WheelPhase.MOMENTUM_WHEEL_START)),s.isMomentum},b=function(){(s={isStarted:!1,isStartPublished:!1,isMomentum:!1,lastAbsDelta:Infinity,axisMovement:[0,0],axisVelocity:[0,0],accelerationFactors:[],scrollPoints:[],scrollPointsToMerge:[],willEndTimeout:400}).isStarted=!0},A=function(){clearTimeout(o),o=setTimeout(L,s.willEndTimeout)},L=function(){s.isStarted&&(s.isMomentum?N()?M(exports.WheelPhase.MOMENTUM_WHEEL_END):M(exports.WheelPhase.MOMENTUM_WHEEL_CANCEL):M(exports.WheelPhase.WHEEL_END),M(exports.WheelPhase.ANY_WHEEL_END),s.isMomentum=!1,s.isStarted=!1)},N=function(){var e=s.scrollPoints.slice(-3).map((function(e){return e.currentAbsDelta}));return e.reduce((function(e,t){return e+t}),0)/e.length<=1.4};return Object.freeze({observe:function(e){return e.addEventListener("wheel",m,{passive:!1}),u.push(e),function(){return h(e)}},unobserve:h,disconnect:function(){u.forEach(h)},subscribe:function(e){return c.push(e),function(){return f(e)}},unsubscribe:f,feedWheel:m})}(o=exports.WheelReason||(exports.WheelReason={})).USER="USER",o.ANY="ANY";var u=((s={})[exports.WheelReason.USER]={start:exports.WheelPhase.WHEEL_START,wheel:exports.WheelPhase.WHEEL,end:exports.WheelPhase.WHEEL_END},s[exports.WheelReason.ANY]={start:exports.WheelPhase.ANY_WHEEL_START,wheel:exports.WheelPhase.ANY_WHEEL,end:exports.WheelPhase.ANY_WHEEL_END},s);exports.WheelAnalyzer=c,exports.WheelGestures=function(t){var n=void 0===t?{}:t,r=n.axis,o=n.wheelReason,s=void 0===o?exports.WheelReason.USER:o,a={down:!1,axisMovement:[0,0],axisVelocity:[0,0]},i=c({preventWheelAction:void 0===r?"all":r}),l=i.observe,E=i.unobserve,h=i.disconnect,f=function(){var e={};function t(t,n){e[t]=(e[t]||[]).filter((function(e){return e!==n}))}return Object.freeze({on:function(n,r){return e[n]=(e[n]||[]).concat(r),function(){return t(n,r)}},off:t,dispatch:function(t,n){t in e&&e[t].forEach((function(e){return e(n)}))}})}(),M=f.on,m=f.off,d=f.dispatch;return i.subscribe((function(t,n){switch(a={down:!0,axisMovement:n.axisMovement.map((function(e){return-1*e})),axisVelocity:[-1*n.axisVelocity[0],-1*n.axisVelocity[1]]},t){case u[s].start:a=e({},a,{down:!0}),d("wheelstart",a);break;case u[s].wheel:a=e({},a,{down:!0}),d("wheelmove",a);break;case u[s].end:a=e({},a,{down:!1}),d("wheelend",a);break;default:return}})),Object.freeze({observe:l,unobserve:E,disconnect:h,on:M,off:m})};
"use strict";function e(){return(e=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}function t(e){return e.reduce((function(e,t){return e+t}))/e.length}Object.defineProperty(exports,"__esModule",{value:!0});var n,r=[1,18,"undefined"!=typeof window&&window.innerHeight||800];(n=exports.WheelPhase||(exports.WheelPhase={})).ANY_WHEEL_START="ANY_WHEEL_START",n.ANY_WHEEL="ANY_WHEEL",n.ANY_WHEEL_END="ANY_WHEEL_END",n.WHEEL_START="WHEEL_START",n.WHEEL="WHEEL",n.WHEEL_END="WHEEL_END",n.MOMENTUM_WHEEL_START="MOMENTUM_WHEEL_START",n.MOMENTUM_WHEEL="MOMENTUM_WHEEL",n.MOMENTUM_WHEEL_CANCEL="MOMENTUM_WHEEL_CANCEL",n.MOMENTUM_WHEEL_END="MOMENTUM_WHEEL_END";var o,s,a=["x","y"],i={x:"deltaX",y:"deltaY"},l={preventWheelAction:"all"};function c(n){void 0===n&&(n={});var o,s,c={isStarted:!1,isStartPublished:!1,isMomentum:!1,lastAbsDelta:Infinity,axisMovement:[0,0],axisVelocity:[0,0],accelerationFactors:[],scrollPoints:[],scrollPointsToMerge:[],willEndTimeout:400},u=[],E=[],h=Object.entries(n).filter((function(e){return void 0!==e[1]})).reduce((function(e,t){var n;return Object.assign(e,((n={})[t[0]]=t[1],n))}),e({},l)),f=function(e){e.removeEventListener("wheel",d),E=E.filter((function(t){return t!==e}))},M=function(e){if(!e)throw new Error("please pass the callback which was used to subscribe");u=u.filter((function(t){return t!==e}))},m=function(t,n){var r=e({type:t,willEndSoon:P(),isMomentum:c.isMomentum,axisMovement:c.axisMovement,axisVelocity:c.axisVelocity,event:o},n);u.forEach((function(e){return e(t,r)}))},d=function(e){Array.isArray(e)?e.forEach((function(e){return W(e)})):W(e)},p=function(e){return Math.min(150,Math.max(-150,e))},W=function(e){var n,s={deltaX:(n=e).deltaX*r[n.deltaMode],deltaY:n.deltaY*r[n.deltaMode],deltaZ:(n.deltaZ||0)*r[n.deltaMode],deltaMode:0,timestamp:n.timeStamp};e.preventDefault&&function(e){var t=e.deltaX,n=e.deltaY;switch(h.preventWheelAction){case"all":return!0;case"x":return Math.abs(t)>=Math.abs(n);case"y":return Math.abs(n)>=Math.abs(t)}}(e)&&e.preventDefault(),c.isStarted||A();var l=p(Math.abs(s.deltaY)>Math.abs(s.deltaX)?s.deltaY:s.deltaX),u=Math.abs(l);if(c.isMomentum&&u>c.lastAbsDelta&&(N(),A()),o=e,c.axisMovement=c.axisMovement.map((function(e,t){return e+p(s[i[a[t]]])})),c.lastAbsDelta=u,c.scrollPointsToMerge.push({currentAbsDelta:u,axisDeltaUnclampt:[s.deltaX,s.deltaY],timestamp:e.timeStamp}),2===c.scrollPointsToMerge.length){var E=c.scrollPointsToMerge,f={currentAbsDelta:t(E.map((function(e){return e.currentAbsDelta}))),axisDeltaUnclampt:E.reduce((function(e,t){var n=t.axisDeltaUnclampt;return[e[0]+n[0],e[1]+n[1]]}),[0,0]),timestamp:t(E.map((function(e){return e.timestamp})))};c.scrollPoints.push(f),v(),c.isMomentum||b(),c.scrollPointsToMerge=[]}c.scrollPoints.length||x(),c.isStartPublished||(m(exports.WheelPhase.ANY_WHEEL_START),m(exports.WheelPhase.WHEEL_START),c.isStartPublished=!0),m(exports.WheelPhase.ANY_WHEEL),m(c.isMomentum?exports.WheelPhase.MOMENTUM_WHEEL:exports.WheelPhase.WHEEL),L()},x=function(){c.axisVelocity=c.scrollPointsToMerge[c.scrollPointsToMerge.length-1].axisDeltaUnclampt.map((function(e){return e/c.willEndTimeout}))},v=function(){var e=c.scrollPoints.slice(-2),t=e[0],n=e[1];if(t&&n){var r=n.timestamp-t.timestamp;if(!(r<=0)){var o=n.axisDeltaUnclampt.map((function(e){return e/r})),s=o.map((function(e,t){return e/(c.axisVelocity[t]||1)}));c.axisVelocity=o,c.accelerationFactors.push(s),_(r)}}},_=function(e){var t=10*Math.ceil(e/10)*1.2;c.isMomentum||(t=Math.max(100,2*t)),c.willEndTimeout=Math.min(1e3,Math.round(t))},T=function(e){return 0===e||e<=.96&&e>=.6},b=function(){if(c.accelerationFactors.length<5)return c.isMomentum;var e=c.accelerationFactors.slice(-5),t=e.reduce((function(e,t){if(!e)return!1;var n=!!t.reduce((function(e,t){return e&&e<1&&e===t?1:0})),r=t.filter(T).length===t.length;return n||r}),!0);return c.accelerationFactors=e,t&&!c.isMomentum&&(m(exports.WheelPhase.WHEEL_END),c.isMomentum=!0,m(exports.WheelPhase.MOMENTUM_WHEEL_START)),c.isMomentum},A=function(){(c={isStarted:!1,isStartPublished:!1,isMomentum:!1,lastAbsDelta:Infinity,axisMovement:[0,0],axisVelocity:[0,0],accelerationFactors:[],scrollPoints:[],scrollPointsToMerge:[],willEndTimeout:400}).isStarted=!0},L=function(){clearTimeout(s),s=setTimeout(N,c.willEndTimeout)},N=function(){c.isStarted&&(c.isMomentum?P()?m(exports.WheelPhase.MOMENTUM_WHEEL_END):m(exports.WheelPhase.MOMENTUM_WHEEL_CANCEL):m(exports.WheelPhase.WHEEL_END),m(exports.WheelPhase.ANY_WHEEL_END),c.isMomentum=!1,c.isStarted=!1)},P=function(){var e=c.scrollPoints.slice(-3).map((function(e){return e.currentAbsDelta}));return e.reduce((function(e,t){return e+t}),0)/e.length<=1.4};return Object.freeze({observe:function(e){return e.addEventListener("wheel",d,{passive:!1}),E.push(e),function(){return f(e)}},unobserve:f,disconnect:function(){E.forEach(f)},subscribe:function(e){return u.push(e),function(){return M(e)}},unsubscribe:M,feedWheel:d})}(o=exports.WheelReason||(exports.WheelReason={})).USER="USER",o.ANY="ANY";var u=((s={})[exports.WheelReason.USER]={start:exports.WheelPhase.WHEEL_START,wheel:exports.WheelPhase.WHEEL,end:exports.WheelPhase.WHEEL_END},s[exports.WheelReason.ANY]={start:exports.WheelPhase.ANY_WHEEL_START,wheel:exports.WheelPhase.ANY_WHEEL,end:exports.WheelPhase.ANY_WHEEL_END},s);exports.WheelAnalyzer=c,exports.WheelGestures=function(t){var n=void 0===t?{}:t,r=n.axis,o=n.wheelReason,s=void 0===o?exports.WheelReason.USER:o,a={down:!1,axisMovement:[0,0],axisVelocity:[0,0]},i=c({preventWheelAction:void 0===r?"all":r}),l=i.observe,E=i.unobserve,h=i.disconnect,f=function(){var e={};function t(t,n){e[t]=(e[t]||[]).filter((function(e){return e!==n}))}return Object.freeze({on:function(n,r){return e[n]=(e[n]||[]).concat(r),function(){return t(n,r)}},off:t,dispatch:function(t,n){t in e&&e[t].forEach((function(e){return e(n)}))}})}(),M=f.on,m=f.off,d=f.dispatch;return i.subscribe((function(t,n){switch(a={down:!0,axisMovement:n.axisMovement.map((function(e){return-1*e})),axisVelocity:[-1*n.axisVelocity[0],-1*n.axisVelocity[1]]},t){case u[s].start:a=e({},a,{down:!0}),d("wheelstart",a);break;case u[s].wheel:a=e({},a,{down:!0}),d("wheelmove",a);break;case u[s].end:a=e({},a,{down:!1}),d("wheelend",a);break;default:return}})),Object.freeze({observe:l,unobserve:E,disconnect:h,on:M,off:m})};
//# sourceMappingURL=wheel-gestures.cjs.production.min.js.map

@@ -129,3 +129,4 @@ function _extends() {

var subscriptions = [];
var targets = []; // merge passed options with defaults (filter undefined option values)
var targets = [];
var currentEvent; // merge passed options with defaults (filter undefined option values)

@@ -180,4 +181,4 @@ var options = Object.entries(optionsParam).filter(function (_ref) {

var publish = function publish(type) {
var data = {
var publish = function publish(type, additionalData) {
var data = _extends({
type: type,

@@ -187,4 +188,6 @@ willEndSoon: willEndSoon(),

axisMovement: state.axisMovement,
axisVelocity: state.axisVelocity
};
axisVelocity: state.axisVelocity,
event: currentEvent
}, additionalData);
subscriptions.forEach(function (fn) {

@@ -247,2 +250,3 @@ return fn(type, data);

currentEvent = wheelEvent;
state.axisMovement = state.axisMovement.map(function (prevDelta, i) {

@@ -249,0 +253,0 @@ return prevDelta + clampDelta(normalizedWheel[deltaProp[axes[i]]]);

{
"name": "wheel-gestures",
"version": "1.0.3",
"version": "1.1.0",
"description": "wheel gestures and momentum detection",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

Sorry, the diff of this file is not supported yet

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