@egjs/axes
Version:
A module used to change the information of user action entered by various input devices such as touch screen or mouse into the logical virtual coordinates. You can easily create a UI that responds to user actions.
112 lines • 4.3 kB
JavaScript
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
import { MOUSE_BUTTON_CODE_MAP } from "../const";
import { EventInput } from "./EventInput";
var TouchMouseEventInput = (function (_super) {
__extends(TouchMouseEventInput, _super);
function TouchMouseEventInput() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.start = ["mousedown", "touchstart"];
_this.move = ["mousemove", "touchmove"];
_this.end = ["mouseup", "touchend", "touchcancel"];
return _this;
}
TouchMouseEventInput.prototype.onEventStart = function (event, inputKey, inputButton) {
var button = this._getButton(event);
if (this._isTouchEvent(event)) {
this._baseTouches = event.touches;
}
if (!this._isValidEvent(event, inputKey, inputButton)) {
return null;
}
this._preventMouseButton(event, button);
return this.extendEvent(event);
};
TouchMouseEventInput.prototype.onEventMove = function (event, inputKey, inputButton) {
if (!this._isValidEvent(event, inputKey, inputButton)) {
return null;
}
return this.extendEvent(event);
};
TouchMouseEventInput.prototype.onEventEnd = function (event) {
if (this._isTouchEvent(event)) {
this._baseTouches = event.touches;
}
return;
};
TouchMouseEventInput.prototype.onRelease = function () {
this.prevEvent = null;
this._baseTouches = null;
return;
};
TouchMouseEventInput.prototype.getTouches = function (event, inputButton) {
if (this._isTouchEvent(event)) {
return event.touches.length;
}
else {
return this._isValidButton(MOUSE_BUTTON_CODE_MAP[event.which], inputButton) &&
this.end.indexOf(event.type) === -1
? 1
: 0;
}
};
TouchMouseEventInput.prototype._getScale = function (event) {
if (this._isTouchEvent(event)) {
if (event.touches.length !== 2 || this._baseTouches.length < 2) {
return 1;
}
return (this._getDistance(event.touches[0], event.touches[1]) /
this._getDistance(this._baseTouches[0], this._baseTouches[1]));
}
return this.prevEvent.scale;
};
TouchMouseEventInput.prototype._getCenter = function (event) {
if (this._isTouchEvent(event)) {
return {
x: event.touches[0].clientX,
y: event.touches[0].clientY,
};
}
return {
x: event.clientX,
y: event.clientY,
};
};
TouchMouseEventInput.prototype._getMovement = function (event) {
var _this = this;
var prev = this.prevEvent.srcEvent;
var _a = [event, prev].map(function (e) {
if (_this._isTouchEvent(e)) {
return {
id: e.touches[0].identifier,
x: e.touches[0].clientX,
y: e.touches[0].clientY,
};
}
return {
id: null,
x: e.clientX,
y: e.clientY,
};
}), nextSpot = _a[0], prevSpot = _a[1];
return nextSpot.id === prevSpot.id
? { x: nextSpot.x - prevSpot.x, y: nextSpot.y - prevSpot.y }
: { x: 0, y: 0 };
};
return TouchMouseEventInput;
}(EventInput));
export { TouchMouseEventInput };
//# sourceMappingURL=TouchMouseEventInput.js.map