lethargy-ts
Advanced tools
Comparing version 0.0.6-beta.3 to 0.0.6-beta.4
@@ -7,4 +7,3 @@ export declare enum CHECK_RESULT_CODES { | ||
NON_DECREASING_DELTAS_OF_KNOWN_HUMAN = "NON_DECREASING_DELTAS_OF_KNOWN_HUMAN", | ||
HIGH_VELOCITY_NON_DECREASING_DELTAS = "HIGH_VELOCITY_NON_DECREASING_DELTAS", | ||
DELTA_MODULE_HAS_BEEN_INCREASING = "DELTA_MODULE_HAS_BEEN_INCREASING" | ||
} |
@@ -33,3 +33,2 @@ /** Converts default WheelEvent to our custom IWheelEvent */ | ||
CHECK_RESULT_CODES["NON_DECREASING_DELTAS_OF_KNOWN_HUMAN"] = "NON_DECREASING_DELTAS_OF_KNOWN_HUMAN"; | ||
CHECK_RESULT_CODES["HIGH_VELOCITY_NON_DECREASING_DELTAS"] = "HIGH_VELOCITY_NON_DECREASING_DELTAS"; | ||
CHECK_RESULT_CODES["DELTA_MODULE_HAS_BEEN_INCREASING"] = "DELTA_MODULE_HAS_BEEN_INCREASING"; | ||
@@ -43,4 +42,2 @@ })(CHECK_RESULT_CODES || (CHECK_RESULT_CODES = {})); | ||
delay; | ||
/** Events with high `wheelDelta` usually decay quickly. If `wheelDelta` is above this threshold and doesn't decrease, it's assumed to be user-triggered. */ | ||
highVelocity; | ||
/** If delta has been increasing for this amount of consecutive events, the event is considered to be user-triggered. */ | ||
@@ -50,6 +47,5 @@ increasingDeltasThreshold; | ||
previousEvents; | ||
constructor({ sensitivity = 2, delay = 100, highVelocity = 100, increasingDeltasThreshold = 3, } = {}) { | ||
constructor({ sensitivity = 2, delay = 100, increasingDeltasThreshold = 4, } = {}) { | ||
this.sensitivity = Math.max(1, sensitivity); | ||
this.delay = Math.max(1, delay); | ||
this.highVelocity = Math.max(1, highVelocity); | ||
this.increasingDeltasThreshold = Math.max(2, increasingDeltasThreshold); | ||
@@ -120,11 +116,2 @@ // Reset inner state | ||
} | ||
// High velocity non-decreasing deltas are likely human | ||
const isHighVelocity = biggestDeltaModule >= this.highVelocity; | ||
const isPreviousEventHighVelocity = previousBiggestDeltaModule >= this.highVelocity; | ||
if (isHighVelocity && isPreviousEventHighVelocity) { | ||
return { | ||
isHuman: true, | ||
reason: CHECK_RESULT_CODES.HIGH_VELOCITY_NON_DECREASING_DELTAS, | ||
}; | ||
} | ||
// Delta has been increasing for the last `increasingDeltasThreshold` consecutive events | ||
@@ -131,0 +118,0 @@ const deltaHasBeenIncreasing = this.increasingDeltasThreshold <= 2 || |
@@ -7,4 +7,2 @@ import type { LethargyConfig, WheelEventLike } from "./types.js"; | ||
delay: number; | ||
/** Events with high `wheelDelta` usually decay quickly. If `wheelDelta` is above this threshold and doesn't decrease, it's assumed to be user-triggered. */ | ||
highVelocity: number; | ||
/** If delta has been increasing for this amount of consecutive events, the event is considered to be user-triggered. */ | ||
@@ -14,3 +12,3 @@ increasingDeltasThreshold: number; | ||
private previousEvents; | ||
constructor({ sensitivity, delay, highVelocity, increasingDeltasThreshold, }?: LethargyConfig); | ||
constructor({ sensitivity, delay, increasingDeltasThreshold, }?: LethargyConfig); | ||
/** Checks whether the wheel event is an intent. | ||
@@ -17,0 +15,0 @@ * Remembers a passed event to compare future events with it */ |
@@ -13,6 +13,4 @@ /** [deltaX, deltaY, deltaZ] */ | ||
delay?: number; | ||
/** Events with high `wheelDelta` usually decay quickly. If `wheelDelta` is above this threshold and doesn't decrease, it's assumed to be user-triggered. */ | ||
highVelocity?: number; | ||
/** If `wheelDelta` has been increasing for this amount of consecutive events, the current event is assumed to be user-triggered. */ | ||
increasingDeltasThreshold?: number; | ||
} |
{ | ||
"name": "lethargy-ts", | ||
"version": "0.0.6-beta.3", | ||
"version": "0.0.6-beta.4", | ||
"description": "Distinguish between scroll events initiated by the user, and those by inertial scrolling", | ||
@@ -5,0 +5,0 @@ "repository": "https://github.com/snelsi/lethargy-ts", |
@@ -48,4 +48,3 @@ # ⭐ Lethargy-TS | ||
delay: 100, | ||
highVelocity: 100, | ||
increasingDeltasThreshold: 3, | ||
increasingDeltasThreshold: 4, | ||
}); | ||
@@ -80,4 +79,2 @@ ``` | ||
- `highVelocity` - Events with high `wheelDelta` usually decay quickly. If `wheelDelta` is above this threshold and doesn't decrease, it's assumed to be user-triggered. | ||
- `increasingDeltasThreshold` - If `wheelDelta` has been increasing for this amount of consecutive events, the current event is assumed to be user-triggered. | ||
@@ -97,4 +94,2 @@ | ||
- The delta of the event doesn't decrease and has a high velocity. | ||
- The delta of the event has been increasing for `n` consecutive events. | ||
@@ -101,0 +96,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
26791
199
118