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.0.1 to 2.1.0

2

dist/test/helper/recordPhases.d.ts

@@ -8,3 +8,3 @@ import { WheelEventData, WheelEventState } from '../..';

export declare function subscribeAndFeedWheelEvents({ beforeFeed, callback, wheelEvents }?: SubAndFeedProps): {
wheelAnalyzer: Readonly<{
wheelGestures: Readonly<{
on: <EK extends "wheel">(type: EK, listener: import("../..").EventListener<import("../..").WheelGesturesEventMap[EK]>) => import("../..").Off;

@@ -11,0 +11,0 @@ off: <EK_1 extends "wheel">(type: EK_1, listener: import("../..").EventListener<import("../..").WheelGesturesEventMap[EK_1]>) => void;

@@ -123,3 +123,3 @@ 'use strict';

var configDefaults = /*#__PURE__*/deepFreeze({
preventWheelAction: 'all',
preventWheelAction: true,
reverseSign: [true, true, false]

@@ -133,3 +133,3 @@ });

var WILL_END_TIMEOUT_DEFAULT = 400;
function createWheelAnalyzerState() {
function createWheelGesturesState() {
return {

@@ -165,3 +165,3 @@ isStarted: false,

var config = configDefaults;
var state = createWheelAnalyzerState();
var state = createWheelGesturesState();
var targets = [];

@@ -236,22 +236,27 @@ var currentEvent;

return config = deepFreeze(_extends({}, configDefaults, {}, config, {}, newOptions));
};
}; // should prevent when there is mainly movement on the desired axis
var shouldPreventDefault = function shouldPreventDefault(e) {
var shouldPreventDefault = function shouldPreventDefault(deltaMaxAbs, axisDelta) {
var _config = config,
preventWheelAction = _config.preventWheelAction;
var deltaX = e.deltaX,
deltaY = e.deltaY;
var deltaX = axisDelta[0],
deltaY = axisDelta[1],
deltaZ = axisDelta[2];
if (typeof preventWheelAction === 'boolean') return preventWheelAction;
switch (preventWheelAction) {
case 'all':
return true;
case 'x':
return Math.abs(deltaX) >= Math.abs(deltaY);
return Math.abs(deltaX) >= deltaMaxAbs;
case 'y':
return Math.abs(deltaY) >= Math.abs(deltaX);
return Math.abs(deltaY) >= deltaMaxAbs;
case 'z':
return Math.abs(deltaZ) >= deltaMaxAbs;
default:
console.warn('unsupported preventWheelAction value: ' + preventWheelAction, 'warn');
return false;
}
console.warn('unsupported preventWheelAction value: ' + preventWheelAction, 'warn');
};

@@ -266,3 +271,3 @@

if (wheelEvent.preventDefault && shouldPreventDefault(wheelEvent)) {
if (wheelEvent.preventDefault && shouldPreventDefault(deltaMaxAbs, axisDelta)) {
wheelEvent.preventDefault();

@@ -431,3 +436,3 @@ }

var start = function start() {
state = createWheelAnalyzerState();
state = createWheelGesturesState();
state.isStarted = true;

@@ -434,0 +439,0 @@ state.startTime = Date.now();

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

@@ -119,3 +119,3 @@ function _extends() {

var configDefaults = /*#__PURE__*/deepFreeze({
preventWheelAction: 'all',
preventWheelAction: true,
reverseSign: [true, true, false]

@@ -129,3 +129,3 @@ });

var WILL_END_TIMEOUT_DEFAULT = 400;
function createWheelAnalyzerState() {
function createWheelGesturesState() {
return {

@@ -162,3 +162,3 @@ isStarted: false,

var config = configDefaults;
var state = createWheelAnalyzerState();
var state = createWheelGesturesState();
var targets = [];

@@ -233,22 +233,27 @@ var currentEvent;

return config = deepFreeze(_extends({}, configDefaults, {}, config, {}, newOptions));
};
}; // should prevent when there is mainly movement on the desired axis
var shouldPreventDefault = function shouldPreventDefault(e) {
var shouldPreventDefault = function shouldPreventDefault(deltaMaxAbs, axisDelta) {
var _config = config,
preventWheelAction = _config.preventWheelAction;
var deltaX = e.deltaX,
deltaY = e.deltaY;
var deltaX = axisDelta[0],
deltaY = axisDelta[1],
deltaZ = axisDelta[2];
if (typeof preventWheelAction === 'boolean') return preventWheelAction;
switch (preventWheelAction) {
case 'all':
return true;
case 'x':
return Math.abs(deltaX) >= Math.abs(deltaY);
return Math.abs(deltaX) >= deltaMaxAbs;
case 'y':
return Math.abs(deltaY) >= Math.abs(deltaX);
return Math.abs(deltaY) >= deltaMaxAbs;
case 'z':
return Math.abs(deltaZ) >= deltaMaxAbs;
default:
isDev && console.warn('unsupported preventWheelAction value: ' + preventWheelAction, 'warn');
return false;
}
isDev && console.warn('unsupported preventWheelAction value: ' + preventWheelAction, 'warn');
};

@@ -263,3 +268,3 @@

if (wheelEvent.preventDefault && shouldPreventDefault(wheelEvent)) {
if (wheelEvent.preventDefault && shouldPreventDefault(deltaMaxAbs, axisDelta)) {
wheelEvent.preventDefault();

@@ -428,3 +433,3 @@ }

var start = function start() {
state = createWheelAnalyzerState();
state = createWheelGesturesState();
state.isStarted = true;

@@ -431,0 +436,0 @@ state.startTime = Date.now();

import { BooleanXYZ } from './wheel-gestures-types';
export declare type PreventWheelActionType = 'all' | 'x' | 'y';
export declare type PreventWheelActionType = true | 'x' | 'y' | 'z' | false;
export declare type ReverseSign = BooleanXYZ | boolean;

@@ -4,0 +4,0 @@ export interface WheelGesturesConfig {

import { WheelGesturesInternalState } from './wheel-gestures-types';
export declare function createWheelAnalyzerState(): WheelGesturesInternalState;
export declare function createWheelGesturesState(): WheelGesturesInternalState;
{
"name": "wheel-gestures",
"version": "2.0.1",
"version": "2.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