Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@hscmap/inertial-wheel

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hscmap/inertial-wheel - npm Package Compare versions

Comparing version 0.5.5 to 0.6.0

lib/inertial_wheel.d.ts

45

lib/index.d.ts

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

export interface Callbacks {
wheel?: (e: InertialWheelEvent) => void;
wheelstart?: (e: InertialWheelStartEvent) => void;
wheelend?: (e: InertialWheelEndEvent) => void;
}
export declare class InertialWheel {
readonly target: HTMLElement;
private cb;
static defaults: {
accDuration: number;
t1: number;
t2: number;
};
private a;
private v;
private lastT;
private lastA;
private clientRect;
accDuration: number;
t1: number;
t2: number;
baseInterval: number;
constructor(target: HTMLElement, cb: Callbacks);
teardown(): void;
stop(): void;
private lastNativeEvent;
private magicTrackpadDetector;
private rafId?;
wheel: (e: WheelEvent) => void;
private finishAnimation();
private tick();
private moving(now);
private nextTick();
}
export declare class InertialWheelEvent {
readonly v: number;
readonly originalEvent: WheelEvent;
constructor(v: number, originalEvent: WheelEvent);
}
export declare class InertialWheelStartEvent {
}
export declare class InertialWheelEndEvent {
}
export { InertialWheel } from "./inertial_wheel";
export { Physics } from "./physics";
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var magic_trackpad_detector_1 = require("@hscmap/magic-trackpad-detector");
var defaults = {
accDuration: 100,
t1: 100,
t2: 200,
};
var InertialWheel = /** @class */ (function () {
function InertialWheel(target, cb) {
var _this = this;
this.target = target;
this.cb = cb;
this.v = 0;
this.accDuration = defaults.accDuration;
this.t1 = defaults.t1;
this.t2 = defaults.t2;
this.baseInterval = 1000 / 60;
this.magicTrackpadDetector = new magic_trackpad_detector_1.MagicTrackpadDetector();
this.wheel = function (e) {
e.preventDefault();
var now = performance.now();
if (_this.rafId == undefined) {
_this.lastT = now;
_this.lastA = now;
_this.nextTick();
_this.cb.wheelstart && _this.cb.wheelstart(new InertialWheelStartEvent());
}
if (!_this.magicTrackpadDetector.inertial(e)) {
_this.lastNativeEvent = e;
_this.lastA = now;
_this.a = e.deltaY > 0 ? 1 : (e.deltaY < 0 ? -1 : 0);
}
};
target.addEventListener('wheel', this.wheel);
this.clientRect = target.getBoundingClientRect();
}
InertialWheel.prototype.teardown = function () {
this.target.removeEventListener('wheel', this.wheel);
};
InertialWheel.prototype.stop = function () {
if (this.rafId) {
cancelAnimationFrame(this.rafId);
this.finishAnimation();
}
};
InertialWheel.prototype.finishAnimation = function () {
this.rafId = undefined;
this.cb.wheelend && this.cb.wheelend(new InertialWheelEndEvent());
this.v = 0;
};
InertialWheel.prototype.tick = function () {
var now = performance.now();
if (this.moving(now))
this.nextTick();
else {
this.finishAnimation();
return;
}
if (now - this.lastA > this.accDuration)
this.a = 0;
var dt = now - this.lastT;
this.v += dt * (this.a == 0 ?
-1. / this.t2 * this.v :
this.a / this.t1);
this.v = clamp(this.v, -1, 1);
this.cb.wheel && this.cb.wheel(new InertialWheelEvent(dt / this.baseInterval * this.v, this.lastNativeEvent));
this.lastT = now;
};
InertialWheel.prototype.moving = function (now) {
return now - this.lastA <= this.accDuration || Math.abs(this.v) >= 0.005;
};
InertialWheel.prototype.nextTick = function () {
var _this = this;
this.rafId = requestAnimationFrame(function () { return _this.tick(); });
};
InertialWheel.defaults = defaults;
return InertialWheel;
}());
exports.InertialWheel = InertialWheel;
var InertialWheelEvent = /** @class */ (function () {
function InertialWheelEvent(v, originalEvent) {
this.v = v;
this.originalEvent = originalEvent;
}
return InertialWheelEvent;
}());
exports.InertialWheelEvent = InertialWheelEvent;
var InertialWheelStartEvent = /** @class */ (function () {
function InertialWheelStartEvent() {
}
return InertialWheelStartEvent;
}());
exports.InertialWheelStartEvent = InertialWheelStartEvent;
var InertialWheelEndEvent = /** @class */ (function () {
function InertialWheelEndEvent() {
}
return InertialWheelEndEvent;
}());
exports.InertialWheelEndEvent = InertialWheelEndEvent;
function clamp(x, min, max) {
return x < min ? min : (x > max ? max : x);
}
var inertial_wheel_1 = require("./inertial_wheel");
exports.InertialWheel = inertial_wheel_1.InertialWheel;
var physics_1 = require("./physics");
exports.Physics = physics_1.Physics;
{
"name": "@hscmap/inertial-wheel",
"version": "0.5.5",
"version": "0.6.0",
"main": "./lib/index.js",

@@ -5,0 +5,0 @@ "types": "./lib/index.d.ts",

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