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.0 to 2.0.1

dist/wheel-gestures/options.d.ts

1

dist/index.d.ts
export { WheelGestures as default } from './wheel-gestures/wheel-gestures';
export * from './wheel-gestures/wheel-gestures';
export * from './wheel-gestures/options';
export * from './wheel-gestures/wheel-gestures-types';

@@ -4,0 +5,0 @@ export * from './wheel-normalizer/wheel-normalizer';

10

dist/test/helper/recordPhases.d.ts

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

import { WheelEventData, WheelEventState } from '../../wheel-gestures/wheel-gestures-types';
import { WheelEventData, WheelEventState } from '../..';
interface SubAndFeedProps {

@@ -9,9 +9,9 @@ beforeFeed?: (e: WheelEventData, i: number) => void;

wheelAnalyzer: Readonly<{
on: <EK extends "wheel">(type: EK, listener: import("../..").EventListener<import("../../wheel-gestures/wheel-gestures-types").WheelGesturesEventMap[EK]>) => import("../..").Off;
off: <EK_1 extends "wheel">(type: EK_1, listener: import("../..").EventListener<import("../../wheel-gestures/wheel-gestures-types").WheelGesturesEventMap[EK_1]>) => void;
observe: (target: EventTarget) => import("../../wheel-gestures/wheel-gestures-types").Unobserve;
on: <EK extends "wheel">(type: EK, listener: import("../..").EventListener<import("../..").WheelGesturesEventMap[EK]>) => import("../..").Off;
off: <EK_1 extends "wheel">(type: EK_1, listener: import("../..").EventListener<import("../..").WheelGesturesEventMap[EK_1]>) => void;
observe: (target: EventTarget) => import("../..").Unobserve;
unobserve: (target: EventTarget) => void;
disconnect: () => void;
feedWheel: (wheelEvents: WheelEventData | WheelEventData[]) => void;
updateOptions: (newOptions?: Partial<import("../../wheel-gestures/wheel-gestures-types").WheelGesturesConfig>) => import("../../wheel-gestures/wheel-gestures-types").WheelGesturesConfig;
updateOptions: (newOptions?: Partial<import("../..").WheelGesturesConfig>) => import("../..").WheelGesturesConfig;
}>;

@@ -18,0 +18,0 @@ allPhaseData: WheelEventState[];

@@ -5,1 +5,2 @@ export declare function lastOf<T>(array: T[]): T;

export declare function absMax(numbers: number[]): number;
export declare function deepFreeze<T extends object>(o: T): Readonly<T>;

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

function _objectWithoutPropertiesLoose(source, excluded) {
if (source == null) return {};
var target = {};
var sourceKeys = Object.keys(source);
var key, i;
for (i = 0; i < sourceKeys.length; i++) {
key = sourceKeys[i];
if (excluded.indexOf(key) >= 0) continue;
target[key] = source[key];
}
return target;
}
function EventBus() {

@@ -89,2 +74,11 @@ var listeners = {};

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

@@ -130,2 +124,7 @@ var LINE_HEIGHT = 16 * 1.125;

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

@@ -156,3 +155,2 @@ * the timeout is automatically adjusted during a gesture

var WHEELEVENTS_TO_ANALAZE = 5;
var reverseSignDefault = [true, true, false];
function WheelGestures(optionsParam) {

@@ -168,3 +166,3 @@ if (optionsParam === void 0) {

var config;
var config = configDefaults;
var state = createWheelAnalyzerState();

@@ -232,15 +230,10 @@ var targets = [];

var _newOptions = newOptions,
_newOptions$preventWh = _newOptions.preventWheelAction,
preventWheelAction = _newOptions$preventWh === void 0 ? 'all' : _newOptions$preventWh,
_newOptions$reverseSi = _newOptions.reverseSign,
reverseSign = _newOptions$reverseSi === void 0 ? reverseSignDefault : _newOptions$reverseSi,
otherOptions = _objectWithoutPropertiesLoose(_newOptions, ["preventWheelAction", "reverseSign"]); // TODO: current config should be preserved!
if (Object.values(newOptions).some(function (option) {
return option === undefined || option === null;
})) {
console.error('updateOptions ignored! undefined & null options not allowed');
return config;
}
config = _extends({
preventWheelAction: preventWheelAction,
reverseSign: reverseSign
}, otherOptions);
return config;
return config = deepFreeze(_extends({}, configDefaults, {}, config, {}, newOptions));
};

@@ -494,2 +487,4 @@

exports.clampAxisDelta = clampAxisDelta;
exports.configDefaults = configDefaults;
exports.deepFreeze = deepFreeze;
exports.default = WheelGestures;

@@ -496,0 +491,0 @@ exports.lastOf = lastOf;

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

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

function _objectWithoutPropertiesLoose(source, excluded) {
if (source == null) return {};
var target = {};
var sourceKeys = Object.keys(source);
var key, i;
for (i = 0; i < sourceKeys.length; i++) {
key = sourceKeys[i];
if (excluded.indexOf(key) >= 0) continue;
target[key] = source[key];
}
return target;
}
function EventBus() {

@@ -85,2 +70,11 @@ var listeners = {};

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

@@ -126,2 +120,7 @@ var LINE_HEIGHT = 16 * 1.125;

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

@@ -153,3 +152,2 @@ * the timeout is automatically adjusted during a gesture

var WHEELEVENTS_TO_ANALAZE = 5;
var reverseSignDefault = [true, true, false];
function WheelGestures(optionsParam) {

@@ -165,3 +163,3 @@ if (optionsParam === void 0) {

var config;
var config = configDefaults;
var state = createWheelAnalyzerState();

@@ -229,15 +227,10 @@ var targets = [];

var _newOptions = newOptions,
_newOptions$preventWh = _newOptions.preventWheelAction,
preventWheelAction = _newOptions$preventWh === void 0 ? 'all' : _newOptions$preventWh,
_newOptions$reverseSi = _newOptions.reverseSign,
reverseSign = _newOptions$reverseSi === void 0 ? reverseSignDefault : _newOptions$reverseSi,
otherOptions = _objectWithoutPropertiesLoose(_newOptions, ["preventWheelAction", "reverseSign"]); // TODO: current config should be preserved!
if (Object.values(newOptions).some(function (option) {
return option === undefined || option === null;
})) {
isDev && console.error('updateOptions ignored! undefined & null options not allowed');
return config;
}
config = _extends({
preventWheelAction: preventWheelAction,
reverseSign: reverseSign
}, otherOptions);
return config;
return config = deepFreeze(_extends({}, configDefaults, {}, config, {}, newOptions));
};

@@ -486,3 +479,3 @@

export default WheelGestures;
export { WheelGestures, absMax, addVectors, average, clamp, clampAxisDelta, lastOf, normalizeWheel, reverseAxisDeltaSign };
export { WheelGestures, absMax, addVectors, average, clamp, clampAxisDelta, configDefaults, deepFreeze, lastOf, normalizeWheel, reverseAxisDeltaSign };
//# sourceMappingURL=wheel-gestures.esm.js.map

@@ -16,7 +16,2 @@ export declare type VectorXYZ = [number, number, number];

}
export interface WheelGesturesConfig {
preventWheelAction: PreventWheelActionType;
reverseSign: ReverseSign;
}
export declare type WheelGesturesOptions = Partial<WheelGesturesConfig>;
export interface ScrollPoint {

@@ -50,3 +45,1 @@ deltaMaxAbs: number;

export declare type Unobserve = () => void;
export declare type PreventWheelActionType = 'all' | 'x' | 'y';
export declare type ReverseSign = BooleanXYZ | boolean;

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

import { Unobserve, WheelEventData, WheelGesturesConfig, WheelGesturesEventMap, WheelGesturesOptions } from './wheel-gestures-types';
import { WheelGesturesConfig, WheelGesturesOptions } from './options';
import { Unobserve, WheelEventData, WheelGesturesEventMap } from './wheel-gestures-types';
export declare function WheelGestures(optionsParam?: WheelGesturesOptions): Readonly<{

@@ -3,0 +4,0 @@ on: <EK extends "wheel">(type: EK, listener: import("../events/EventBus").EventListener<WheelGesturesEventMap[EK]>) => import("../events/EventBus").Off;

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

import { ReverseSign, VectorXYZ, WheelEventData } from '../wheel-gestures/wheel-gestures-types';
import { ReverseSign } from '../wheel-gestures/options';
import { VectorXYZ, WheelEventData } from '../wheel-gestures/wheel-gestures-types';
export interface NormalizedWheel {

@@ -3,0 +4,0 @@ axisDelta: VectorXYZ;

{
"name": "wheel-gestures",
"version": "2.0.0",
"version": "2.0.1",
"description": "wheel gestures and momentum detection",

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

"tslib": "^1.11.1",
"typescript": "^3.8.3"
"typescript": "^3.9.1-rc"
},

@@ -66,0 +66,0 @@ "jest": {

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