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 2.2.0 to 2.2.1

LICENSE

62

dist/wheel-gestures.cjs.development.js

@@ -23,32 +23,2 @@ 'use strict';

function EventBus() {
var listeners = {};
function on(type, listener) {
listeners[type] = (listeners[type] || []).concat(listener);
return function () {
return off(type, listener);
};
}
function off(type, listener) {
listeners[type] = (listeners[type] || []).filter(function (l) {
return l !== listener;
});
}
function dispatch(type, data) {
if (!(type in listeners)) return;
listeners[type].forEach(function (l) {
return l(data);
});
}
return Object.freeze({
on: on,
off: off,
dispatch: dispatch
});
}
var DECAY = 0.996;

@@ -95,3 +65,3 @@ /**

Object.values(o).forEach(function (value) {
if (value !== null && (typeof value === 'object' || typeof value === 'function') && !Object.isFrozen(value)) {
if (value !== null && typeof value === 'object' && !Object.isFrozen(value)) {
deepFreeze(value);

@@ -103,2 +73,32 @@ }

function EventBus() {
var listeners = {};
function on(type, listener) {
listeners[type] = (listeners[type] || []).concat(listener);
return function () {
return off(type, listener);
};
}
function off(type, listener) {
listeners[type] = (listeners[type] || []).filter(function (l) {
return l !== listener;
});
}
function dispatch(type, data) {
if (!(type in listeners)) return;
listeners[type].forEach(function (l) {
return l(data);
});
}
return deepFreeze({
on: on,
off: off,
dispatch: dispatch
});
}
function WheelTargetObserver(eventListener) {

@@ -105,0 +105,0 @@ var targets = []; // add event listener to target element

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

"use strict";function t(){return(t=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(t[i]=n[i])}return t}).apply(this,arguments)}Object.defineProperty(exports,"__esModule",{value:!0});var e=function(t,e){return void 0===e&&(e=.996),t*e/(1-e)};function n(t){return t[t.length-1]}function i(t){return t.reduce((function(t,e){return t+e}))/t.length}var r=function(t,e,n){return Math.min(Math.max(e,t),n)};function o(t,e){if(t.length!==e.length)throw new Error("vectors must be same length");return t.map((function(t,n){return t+e[n]}))}function a(t){return Math.max.apply(Math,t.map(Math.abs))}function s(t){return Object.freeze(t),Object.values(t).forEach((function(t){null===t||"object"!=typeof t&&"function"!=typeof t||Object.isFrozen(t)||s(t)})),t}var u=[1,18,"undefined"!=typeof window&&window.innerHeight||800],c=[-1,-1,-1],l=s({preventWheelAction:!0,reverseSign:[!0,!0,!1]});function f(f){void 0===f&&(f={});var m,d,p,v=function(){var t={};function e(e,n){t[e]=(t[e]||[]).filter((function(t){return t!==n}))}return Object.freeze({on:function(n,i){return t[n]=(t[n]||[]).concat(i),function(){return e(n,i)}},off:e,dispatch:function(e,n){e in t&&t[e].forEach((function(t){return t(n)}))}})}(),h=v.on,x=v.off,M=v.dispatch,b=l,g={isStarted:!1,isStartPublished:!1,isMomentum:!1,startTime:0,lastAbsDelta:Infinity,axisMovement:[0,0,0],axisVelocity:[0,0,0],accelerationFactors:[],scrollPoints:[],scrollPointsToMerge:[],willEndTimeout:400},S=!1,y=function(t){Array.isArray(t)?t.forEach((function(t){return T(t)})):T(t)},D=function(e){return void 0===e&&(e={}),Object.values(e).some((function(t){return null==t}))?b:b=s(t({},l,{},b,{},e))},P=function(n){var i=t({event:m,isStart:!1,isEnding:!1,isMomentumCancel:!1,isMomentum:g.isMomentum,axisDelta:[0,0,0],axisVelocity:g.axisVelocity,axisMovement:g.axisMovement,get axisMovementProjection(){return o(i.axisMovement,i.axisVelocity.map((function(t){return e(t)})))}},n);M("wheel",t({},i,{previous:d})),d=i},T=function(e){var n,i=function(e){return t({},e,{axisDelta:e.axisDelta.map((function(t){return r(t,-700,700)}))})}(function(e,n){if(!n)return e;var i=!0===n?c:n.map((function(t){return t?-1:1}));return t({},e,{axisDelta:e.axisDelta.map((function(t,e){return t*i[e]}))})}({timeStamp:(n=e).timeStamp,axisDelta:[n.deltaX*u[n.deltaMode],n.deltaY*u[n.deltaMode],(n.deltaZ||0)*u[n.deltaMode]]},b.reverseSign)),s=i.axisDelta,l=i.timeStamp,f=a(s);e.preventDefault&&function(t,e){var n=b.preventWheelAction,i=e[0],r=e[1],o=e[2];if("boolean"==typeof n)return n;switch(n){case"x":return Math.abs(i)>=t;case"y":return Math.abs(r)>=t;case"z":return Math.abs(o)>=t;default:return!1}}(f,s)&&e.preventDefault(),g.isStarted?g.isMomentum&&f>Math.max(2,2*g.lastAbsDelta)&&(C(!0),z()):z(),0===f&&Object.is&&Object.is(e.deltaX,-0)?S=!0:(m=e,g.axisMovement=o(g.axisMovement,s),g.lastAbsDelta=f,g.scrollPointsToMerge.push({axisDelta:s,timeStamp:l}),w(),P({axisDelta:s,isStart:!g.isStartPublished}),g.isStartPublished=!0,W())},w=function(){2===g.scrollPointsToMerge.length?(g.scrollPoints.unshift({axisDeltaSum:g.scrollPointsToMerge.map((function(t){return t.axisDelta})).reduce(o),timeStamp:i(g.scrollPointsToMerge.map((function(t){return t.timeStamp})))}),j(),g.scrollPointsToMerge.length=0,g.scrollPoints.length=1,g.isMomentum||A()):g.isStartPublished||E()},E=function(){g.axisVelocity=n(g.scrollPointsToMerge).axisDelta.map((function(t){return t/g.willEndTimeout}))},j=function(){var t=g.scrollPoints,e=t[0],n=t[1];if(n&&e){var i=e.timeStamp-n.timeStamp;if(!(i<=0)){var r=e.axisDeltaSum.map((function(t){return t/i})),o=r.map((function(t,e){return t/(g.axisVelocity[e]||1)}));g.axisVelocity=r,g.accelerationFactors.push(o),O(i)}}},O=function(t){var e=10*Math.ceil(t/10)*1.2;g.isMomentum||(e=Math.max(100,2*e)),g.willEndTimeout=Math.min(1e3,Math.round(e))},V=function(t){return 0===t||t<=.96&&t>=.6},A=function(){if(g.accelerationFactors.length>=5){if(S&&(S=!1,a(g.axisVelocity)>=.2))return void F();var t=g.accelerationFactors.slice(-5);t.every((function(t){var e=!!t.reduce((function(t,e){return t&&t<1&&t===e?1:0})),n=t.filter(V).length===t.length;return e||n}))&&F(),g.accelerationFactors=t}},F=function(){g.isMomentum=!0},z=function(){(g={isStarted:!1,isStartPublished:!1,isMomentum:!1,startTime:0,lastAbsDelta:Infinity,axisMovement:[0,0,0],axisVelocity:[0,0,0],accelerationFactors:[],scrollPoints:[],scrollPointsToMerge:[],willEndTimeout:400}).isStarted=!0,g.startTime=Date.now(),d=void 0,S=!1},W=function(){clearTimeout(p),p=setTimeout(C,g.willEndTimeout)},C=function(t){void 0===t&&(t=!1),g.isStarted&&(P(g.isMomentum&&t?{isEnding:!0,isMomentumCancel:!0}:{isEnding:!0}),g.isMomentum=!1,g.isStarted=!1)},I=function(t){var e=[],n=function(n){n.removeEventListener("wheel",t),e=e.filter((function(t){return t!==n}))};return s({observe:function(i){return i.addEventListener("wheel",t,{passive:!1}),e.push(i),function(){return n(i)}},unobserve:n,disconnect:function(){e.forEach(n)}})}(y),L=I.observe,X=I.unobserve,_=I.disconnect;return D(f),s({on:h,off:x,observe:L,unobserve:X,disconnect:_,feedWheel:y,updateOptions:D})}exports.WheelGestures=f,exports.absMax=a,exports.addVectors=o,exports.average=i,exports.clamp=r,exports.configDefaults=l,exports.deepFreeze=s,exports.default=f,exports.lastOf=n,exports.projection=e;
"use strict";function t(){return(t=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(t[i]=n[i])}return t}).apply(this,arguments)}Object.defineProperty(exports,"__esModule",{value:!0});var e=function(t,e){return void 0===e&&(e=.996),t*e/(1-e)};function n(t){return t[t.length-1]}function i(t){return t.reduce((function(t,e){return t+e}))/t.length}var r=function(t,e,n){return Math.min(Math.max(e,t),n)};function o(t,e){if(t.length!==e.length)throw new Error("vectors must be same length");return t.map((function(t,n){return t+e[n]}))}function a(t){return Math.max.apply(Math,t.map(Math.abs))}function s(t){return Object.freeze(t),Object.values(t).forEach((function(t){null===t||"object"!=typeof t||Object.isFrozen(t)||s(t)})),t}var u=[1,18,"undefined"!=typeof window&&window.innerHeight||800],c=[-1,-1,-1],l=s({preventWheelAction:!0,reverseSign:[!0,!0,!1]});function f(f){void 0===f&&(f={});var m,d,p,v=function(){var t={};function e(e,n){t[e]=(t[e]||[]).filter((function(t){return t!==n}))}return s({on:function(n,i){return t[n]=(t[n]||[]).concat(i),function(){return e(n,i)}},off:e,dispatch:function(e,n){e in t&&t[e].forEach((function(t){return t(n)}))}})}(),h=v.on,x=v.off,M=v.dispatch,b=l,g={isStarted:!1,isStartPublished:!1,isMomentum:!1,startTime:0,lastAbsDelta:Infinity,axisMovement:[0,0,0],axisVelocity:[0,0,0],accelerationFactors:[],scrollPoints:[],scrollPointsToMerge:[],willEndTimeout:400},S=!1,y=function(t){Array.isArray(t)?t.forEach((function(t){return T(t)})):T(t)},D=function(e){return void 0===e&&(e={}),Object.values(e).some((function(t){return null==t}))?b:b=s(t({},l,{},b,{},e))},P=function(n){var i=t({event:m,isStart:!1,isEnding:!1,isMomentumCancel:!1,isMomentum:g.isMomentum,axisDelta:[0,0,0],axisVelocity:g.axisVelocity,axisMovement:g.axisMovement,get axisMovementProjection(){return o(i.axisMovement,i.axisVelocity.map((function(t){return e(t)})))}},n);M("wheel",t({},i,{previous:d})),d=i},T=function(e){var n,i=function(e){return t({},e,{axisDelta:e.axisDelta.map((function(t){return r(t,-700,700)}))})}(function(e,n){if(!n)return e;var i=!0===n?c:n.map((function(t){return t?-1:1}));return t({},e,{axisDelta:e.axisDelta.map((function(t,e){return t*i[e]}))})}({timeStamp:(n=e).timeStamp,axisDelta:[n.deltaX*u[n.deltaMode],n.deltaY*u[n.deltaMode],(n.deltaZ||0)*u[n.deltaMode]]},b.reverseSign)),s=i.axisDelta,l=i.timeStamp,f=a(s);e.preventDefault&&function(t,e){var n=b.preventWheelAction,i=e[0],r=e[1],o=e[2];if("boolean"==typeof n)return n;switch(n){case"x":return Math.abs(i)>=t;case"y":return Math.abs(r)>=t;case"z":return Math.abs(o)>=t;default:return!1}}(f,s)&&e.preventDefault(),g.isStarted?g.isMomentum&&f>Math.max(2,2*g.lastAbsDelta)&&(C(!0),z()):z(),0===f&&Object.is&&Object.is(e.deltaX,-0)?S=!0:(m=e,g.axisMovement=o(g.axisMovement,s),g.lastAbsDelta=f,g.scrollPointsToMerge.push({axisDelta:s,timeStamp:l}),w(),P({axisDelta:s,isStart:!g.isStartPublished}),g.isStartPublished=!0,W())},w=function(){2===g.scrollPointsToMerge.length?(g.scrollPoints.unshift({axisDeltaSum:g.scrollPointsToMerge.map((function(t){return t.axisDelta})).reduce(o),timeStamp:i(g.scrollPointsToMerge.map((function(t){return t.timeStamp})))}),j(),g.scrollPointsToMerge.length=0,g.scrollPoints.length=1,g.isMomentum||A()):g.isStartPublished||E()},E=function(){g.axisVelocity=n(g.scrollPointsToMerge).axisDelta.map((function(t){return t/g.willEndTimeout}))},j=function(){var t=g.scrollPoints,e=t[0],n=t[1];if(n&&e){var i=e.timeStamp-n.timeStamp;if(!(i<=0)){var r=e.axisDeltaSum.map((function(t){return t/i})),o=r.map((function(t,e){return t/(g.axisVelocity[e]||1)}));g.axisVelocity=r,g.accelerationFactors.push(o),O(i)}}},O=function(t){var e=10*Math.ceil(t/10)*1.2;g.isMomentum||(e=Math.max(100,2*e)),g.willEndTimeout=Math.min(1e3,Math.round(e))},V=function(t){return 0===t||t<=.96&&t>=.6},A=function(){if(g.accelerationFactors.length>=5){if(S&&(S=!1,a(g.axisVelocity)>=.2))return void F();var t=g.accelerationFactors.slice(-5);t.every((function(t){var e=!!t.reduce((function(t,e){return t&&t<1&&t===e?1:0})),n=t.filter(V).length===t.length;return e||n}))&&F(),g.accelerationFactors=t}},F=function(){g.isMomentum=!0},z=function(){(g={isStarted:!1,isStartPublished:!1,isMomentum:!1,startTime:0,lastAbsDelta:Infinity,axisMovement:[0,0,0],axisVelocity:[0,0,0],accelerationFactors:[],scrollPoints:[],scrollPointsToMerge:[],willEndTimeout:400}).isStarted=!0,g.startTime=Date.now(),d=void 0,S=!1},W=function(){clearTimeout(p),p=setTimeout(C,g.willEndTimeout)},C=function(t){void 0===t&&(t=!1),g.isStarted&&(P(g.isMomentum&&t?{isEnding:!0,isMomentumCancel:!0}:{isEnding:!0}),g.isMomentum=!1,g.isStarted=!1)},I=function(t){var e=[],n=function(n){n.removeEventListener("wheel",t),e=e.filter((function(t){return t!==n}))};return s({observe:function(i){return i.addEventListener("wheel",t,{passive:!1}),e.push(i),function(){return n(i)}},unobserve:n,disconnect:function(){e.forEach(n)}})}(y),L=I.observe,X=I.unobserve,_=I.disconnect;return D(f),s({on:h,off:x,observe:L,unobserve:X,disconnect:_,feedWheel:y,updateOptions:D})}exports.WheelGestures=f,exports.absMax=a,exports.addVectors=o,exports.average=i,exports.clamp=r,exports.configDefaults=l,exports.deepFreeze=s,exports.default=f,exports.lastOf=n,exports.projection=e;
//# sourceMappingURL=wheel-gestures.cjs.production.min.js.map

@@ -19,32 +19,2 @@ function _extends() {

function EventBus() {
var listeners = {};
function on(type, listener) {
listeners[type] = (listeners[type] || []).concat(listener);
return function () {
return off(type, listener);
};
}
function off(type, listener) {
listeners[type] = (listeners[type] || []).filter(function (l) {
return l !== listener;
});
}
function dispatch(type, data) {
if (!(type in listeners)) return;
listeners[type].forEach(function (l) {
return l(data);
});
}
return Object.freeze({
on: on,
off: off,
dispatch: dispatch
});
}
var DECAY = 0.996;

@@ -91,3 +61,3 @@ /**

Object.values(o).forEach(function (value) {
if (value !== null && (typeof value === 'object' || typeof value === 'function') && !Object.isFrozen(value)) {
if (value !== null && typeof value === 'object' && !Object.isFrozen(value)) {
deepFreeze(value);

@@ -99,2 +69,32 @@ }

function EventBus() {
var listeners = {};
function on(type, listener) {
listeners[type] = (listeners[type] || []).concat(listener);
return function () {
return off(type, listener);
};
}
function off(type, listener) {
listeners[type] = (listeners[type] || []).filter(function (l) {
return l !== listener;
});
}
function dispatch(type, data) {
if (!(type in listeners)) return;
listeners[type].forEach(function (l) {
return l(data);
});
}
return deepFreeze({
on: on,
off: off,
dispatch: dispatch
});
}
function WheelTargetObserver(eventListener) {

@@ -101,0 +101,0 @@ var targets = []; // add event listener to target element

{
"name": "wheel-gestures",
"version": "2.2.0",
"version": "2.2.1",
"description": "wheel gestures and momentum detection",

@@ -16,3 +16,3 @@ "main": "dist/index.js",

"scripts": {
"start": "tsdx watch",
"start": "tsdx watch --noClean",
"build": "tsdx build",

@@ -54,3 +54,3 @@ "test": "tsdx test",

"@testing-library/react": "^10.0.2",
"@types/jest": "^25.2.1",
"@types/jest": "^26.0.4",
"bundlewatch": "^0.2.6",

@@ -57,0 +57,0 @@ "eslint-plugin-import": "^2.19.1",

# ![wheel gestures](./WheelGestures.svg)
<p align="center">
wheel gestures and momentum detection in the browser
</p>
🚧 `IN DEVELOPMENT` still working heavily on docs & demos
<p align="center">
<a href="https://www.npmjs.com/package/wheel-gestures" rel="nofollow"><img src="https://camo.githubusercontent.com/da238eaad5556c489501f93369cd209a2e7e4351/68747470733a2f2f696d672e736869656c64732e696f2f6e706d2f762f776865656c2d67657374757265732f6c61746573742e737667" alt="npm (tag)" data-canonical-src="https://img.shields.io/npm/v/wheel-gestures/latest.svg" style="max-width:100%;"></a>
<a href="https://bundlephobia.com/result?p=wheel-gestures@2.1.1" rel="nofollow"><img src="https://camo.githubusercontent.com/7d96deb09bd6d0a2f58a54d94eeaf2dcf0891b42/68747470733a2f2f62616467656e2e6e65742f62756e646c6570686f6269612f6d696e7a69702f776865656c2d6765737475726573" alt="only about 2kb minified and gzipped" data-canonical-src="https://badgen.net/bundlephobia/minzip/wheel-gestures" style="max-width:100%;"></a>
</p>
[![npm (tag)](https://img.shields.io/npm/v/wheel-gestures/latest.svg)](https://www.npmjs.com/package/wheel-gestures)
![GitHub top language](https://img.shields.io/github/languages/top/xiel/wheel-gestures.svg)
<hr/>
**OS & Browsers**

@@ -23,3 +26,1 @@

- https://github.com/d4nyll/lethargy

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

import { deepFreeze } from '../utils'
export type EventMapEmpty = Record<string, unknown>

@@ -22,3 +24,3 @@ export type EventListener<D = unknown> = (data: D) => void

return Object.freeze({
return deepFreeze({
on,

@@ -25,0 +27,0 @@ off,

@@ -27,3 +27,3 @@ export * from './projection'

Object.values(o).forEach((value) => {
if (value !== null && (typeof value === 'object' || typeof value === 'function') && !Object.isFrozen(value)) {
if (value !== null && typeof value === 'object' && !Object.isFrozen(value)) {
deepFreeze(value)

@@ -30,0 +30,0 @@ }

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