@hscmap/inertial-mouse
Advanced tools
Comparing version 3.3.1 to 3.4.0
@@ -0,3 +1,4 @@ | ||
export { SinglePointEvent } from "./SinglePointEvent"; | ||
export { V2 } from "./v2"; | ||
export { Physics } from "./physics"; | ||
export { InertialMouse } from "./inertial_mouse"; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var SinglePointEvent_1 = require("./SinglePointEvent"); | ||
exports.SinglePointEvent = SinglePointEvent_1.SinglePointEvent; | ||
var v2_1 = require("./v2"); | ||
@@ -4,0 +6,0 @@ exports.V2 = v2_1.V2; |
@@ -0,1 +1,2 @@ | ||
import { SinglePointEvent } from "./SinglePointEvent"; | ||
import { V2 } from "./v2"; | ||
@@ -11,25 +12,24 @@ import { Physics } from "./physics"; | ||
} | ||
export declare type EventFitler = (e: MouseEvent) => boolean; | ||
export declare class InertialMouse { | ||
readonly target: HTMLElement; | ||
readonly cb: Partial<Callbacks>; | ||
readonly eventFilter?: EventFitler | undefined; | ||
readonly physics: Physics; | ||
constructor(target: HTMLElement, cb: Partial<Callbacks>, eventFilter?: EventFitler | undefined); | ||
constructor(cb: Partial<Callbacks>); | ||
private dead; | ||
teardown(): void; | ||
stop(): void; | ||
private mousedown; | ||
private mousemove; | ||
private mouseup; | ||
private clearEvents?; | ||
start(e: SinglePointEvent): void; | ||
private pointmove; | ||
private pointend; | ||
protected tick(): void; | ||
private coord; | ||
} | ||
export declare class DownEvent { | ||
readonly r: V2; | ||
constructor(r: V2, originalEvent: MouseEvent); | ||
readonly pointerEvent: SinglePointEvent; | ||
constructor(r: V2, pointerEvent: SinglePointEvent); | ||
} | ||
export declare class UpEvent { | ||
readonly r: V2; | ||
constructor(r: V2, originalEvent: MouseEvent); | ||
readonly pointerEvent: SinglePointEvent; | ||
constructor(r: V2, pointerEvent: SinglePointEvent); | ||
} | ||
@@ -36,0 +36,0 @@ export declare class MoveEvent { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var v2_1 = require("./v2"); | ||
var SinglePointEvent_1 = require("./SinglePointEvent"); | ||
var physics_1 = require("./physics"); | ||
var InertialMouse = /** @class */ (function () { | ||
function InertialMouse(target, cb, eventFilter) { | ||
function InertialMouse(cb) { | ||
var _this = this; | ||
this.target = target; | ||
this.cb = cb; | ||
this.eventFilter = eventFilter; | ||
this.physics = new physics_1.Physics(); | ||
this.dead = false; | ||
this.mousedown = function (e) { | ||
if (_this.eventFilter && _this.eventFilter(e) || _this.eventFilter == undefined) { | ||
var r = _this.coord(e); | ||
_this.physics.put(r); | ||
document.addEventListener('mousemove', _this.mousemove); | ||
document.addEventListener('mouseup', _this.mouseup); | ||
_this.cb.down && _this.cb.down(new DownEvent(r, e)); | ||
} | ||
}; | ||
this.mousemove = function (e) { | ||
this.pointmove = function (e) { | ||
if (_this.dead) | ||
return; | ||
_this.physics.hook(_this.coord(e)); | ||
_this.physics.hook(e.clientCoord); | ||
_this.cb.setNextTick(function () { return _this.tick(); }); | ||
}; | ||
this.mouseup = function (e) { | ||
this.pointend = function (e) { | ||
if (_this.dead) | ||
return; | ||
_this.physics.unhook(); | ||
document.removeEventListener('mousemove', _this.mousemove); | ||
document.removeEventListener('mouseup', _this.mouseup); | ||
_this.cb.up && _this.cb.up(new UpEvent(_this.coord(e), e)); | ||
_this.clearEvents && _this.clearEvents(); | ||
_this.cb.up && _this.cb.up(new UpEvent(e.clientCoord, e)); | ||
}; | ||
if (cb.setNextTick == undefined) | ||
cb.setNextTick = defaultSetNextTick(); | ||
target.addEventListener('mousedown', this.mousedown); | ||
cb.setNextTick = cb.setNextTick || defaultSetNextTick(); | ||
} | ||
InertialMouse.prototype.teardown = function () { | ||
this.dead = true; | ||
this.target.removeEventListener('mousedown', this.mousedown); | ||
document.removeEventListener('mousemove', this.mousemove); | ||
document.removeEventListener('mouseup', this.mouseup); | ||
this.clearEvents && this.clearEvents(); | ||
}; | ||
@@ -49,2 +33,17 @@ InertialMouse.prototype.stop = function () { | ||
}; | ||
InertialMouse.prototype.start = function (e) { | ||
var r = e.clientCoord; | ||
this.physics.put(r); | ||
var clear = [ | ||
SinglePointEvent_1.SinglePointEvent.onMove(document, this.pointmove), | ||
SinglePointEvent_1.SinglePointEvent.onEnd(document, this.pointend) | ||
]; | ||
this.clearEvents = function () { | ||
for (var _i = 0, clear_1 = clear; _i < clear_1.length; _i++) { | ||
var c = clear_1[_i]; | ||
c(); | ||
} | ||
}; | ||
this.cb.down && this.cb.down(new DownEvent(r, e)); | ||
}; | ||
InertialMouse.prototype.tick = function () { | ||
@@ -60,6 +59,2 @@ var _this = this; | ||
}; | ||
InertialMouse.prototype.coord = function (e) { | ||
var rect = this.target.getBoundingClientRect(); | ||
return new v2_1.V2(e.clientX - rect.left, e.clientY - rect.top); | ||
}; | ||
return InertialMouse; | ||
@@ -80,4 +75,5 @@ }()); | ||
var DownEvent = /** @class */ (function () { | ||
function DownEvent(r, originalEvent) { | ||
function DownEvent(r, pointerEvent) { | ||
this.r = r; | ||
this.pointerEvent = pointerEvent; | ||
} | ||
@@ -88,4 +84,5 @@ return DownEvent; | ||
var UpEvent = /** @class */ (function () { | ||
function UpEvent(r, originalEvent) { | ||
function UpEvent(r, pointerEvent) { | ||
this.r = r; | ||
this.pointerEvent = pointerEvent; | ||
} | ||
@@ -92,0 +89,0 @@ return UpEvent; |
{ | ||
"name": "@hscmap/inertial-mouse", | ||
"version": "3.3.1", | ||
"version": "3.4.0", | ||
"main": "./lib/index.js", | ||
@@ -8,3 +8,3 @@ "types": "./lib/index.d.ts", | ||
"prepare": "tsc", | ||
"example-server": "webpack-dev-server --context example --config ./example/webpack.config.js --mode development", | ||
"example-server": "webpack-dev-server --context example --config ./example/webpack.config.js --mode development --host 0.0.0.0", | ||
"example": "webpack --context example --config ./example/webpack.config.js --mode development" | ||
@@ -11,0 +11,0 @@ }, |
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
19341
15
495