@hscmap/magic-trackpad-detector
Advanced tools
Sorry, the diff of this file is too big to display
| { | ||
| "extends": "../src/tsconfig", | ||
| "compilerOptions": { | ||
| "noUnusedLocals": true | ||
| "noUnusedLocals": true, | ||
| "declaration": false | ||
| } | ||
| } |
+1
-1
| { | ||
| "name": "@hscmap/magic-trackpad-detector", | ||
| "version": "0.0.5", | ||
| "version": "0.0.6", | ||
| "main": "./lib/index.js", | ||
@@ -5,0 +5,0 @@ "types": "./lib/index.d.ts", |
+2
-8
| export class MagicTrackpadDetector { | ||
| tolerance = 5 // ms | ||
| interval = 1000 / 60 // events per second | ||
| minN1 = 5 | ||
@@ -21,8 +19,7 @@ minN2 = 15 | ||
| const n = h.at(-i + 1) | ||
| // const dt = n[0] - o[0] | ||
| // if (dt < this.interval - this.tolerance) | ||
| // return false | ||
| if (n[1] * o[1] < 0 || n[1] / o[1] > 1) | ||
| return false | ||
| } | ||
| if (h.at(-1)[1] == h.at(-this.minN1 + 1)[1]) | ||
| return false | ||
| } | ||
@@ -40,5 +37,2 @@ else { // |deltaY| == 1 | ||
| const n = h.at(-i + 1) | ||
| // const dt = n[0] - o[0] | ||
| // if (dt < this.interval - this.tolerance) | ||
| // return false | ||
| if (n[1] * o[1] < 0 || n[1] / o[1] > 1) | ||
@@ -45,0 +39,0 @@ return false |
Sorry, the diff of this file is not supported yet
| export declare class MagicTrackpadDetector { | ||
| tolerance: number; | ||
| interval: number; | ||
| minN1: number; | ||
| minN2: number; | ||
| private history; | ||
| inertial(e: WheelEvent): boolean; | ||
| } |
-80
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| var MagicTrackpadDetector = (function () { | ||
| function MagicTrackpadDetector() { | ||
| this.tolerance = 5; // ms | ||
| this.interval = 1000 / 60; // events per second | ||
| this.minN1 = 5; | ||
| this.minN2 = 15; | ||
| this.history = new RingBuffer(Math.max(this.minN1, this.minN2)); | ||
| } | ||
| MagicTrackpadDetector.prototype.inertial = function (e) { | ||
| var h = this.history; | ||
| var t0 = performance.now(); | ||
| var d0 = e.deltaY; | ||
| h.push([t0, d0]); | ||
| if (h.length < this.minN1) | ||
| return false; | ||
| if (Math.abs(e.deltaY) > 1) { | ||
| for (var i = this.minN1 - 1; i > 1; --i) { | ||
| var o = h.at(-i); | ||
| var n = h.at(-i + 1); | ||
| // const dt = n[0] - o[0] | ||
| // if (dt < this.interval - this.tolerance) | ||
| // return false | ||
| if (n[1] * o[1] < 0 || n[1] / o[1] > 1) | ||
| return false; | ||
| } | ||
| } | ||
| else { | ||
| if (h.length < this.minN2) | ||
| return false; | ||
| var _a = h.at(-this.minN2), to = _a[0], vo = _a[1]; | ||
| to; | ||
| if (Math.abs(vo) <= 1) { | ||
| return false; | ||
| } | ||
| for (var i = this.minN2 - 1; i > 1; --i) { | ||
| var o = h.at(-i); | ||
| var n = h.at(-i + 1); | ||
| // const dt = n[0] - o[0] | ||
| // if (dt < this.interval - this.tolerance) | ||
| // return false | ||
| if (n[1] * o[1] < 0 || n[1] / o[1] > 1) | ||
| return false; | ||
| } | ||
| } | ||
| return true; | ||
| }; | ||
| return MagicTrackpadDetector; | ||
| }()); | ||
| exports.MagicTrackpadDetector = MagicTrackpadDetector; | ||
| var RingBuffer = (function () { | ||
| function RingBuffer(n) { | ||
| this.n = n; | ||
| this.clear(); | ||
| } | ||
| RingBuffer.prototype.at = function (i) { | ||
| var j = (this.o + i + this.length) % this.xs.length; | ||
| return this.xs[j]; | ||
| }; | ||
| RingBuffer.prototype.push = function (x) { | ||
| if (this.xs.length < this.n) | ||
| this.xs.push(x); | ||
| else | ||
| this.xs[this.o] = x; | ||
| this.o = (this.o + 1) % this.n; | ||
| }; | ||
| RingBuffer.prototype.clear = function () { | ||
| this.o = 0; | ||
| this.xs = []; | ||
| }; | ||
| Object.defineProperty(RingBuffer.prototype, "length", { | ||
| get: function () { | ||
| return this.xs.length; | ||
| }, | ||
| enumerable: true, | ||
| configurable: true | ||
| }); | ||
| return RingBuffer; | ||
| }()); |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
287331
95.82%4776
1682.09%13
-13.33%1
Infinity%