@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.
80 lines • 3.05 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 { EventInput } from "./EventInput";
var TouchEventInput = (function (_super) {
__extends(TouchEventInput, _super);
function TouchEventInput() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.start = ["touchstart"];
_this.move = ["touchmove"];
_this.end = ["touchend", "touchcancel"];
return _this;
}
TouchEventInput.prototype.onEventStart = function (event, inputKey) {
this._baseTouches = event.touches;
if (!this._isValidEvent(event, inputKey)) {
return null;
}
return this.extendEvent(event);
};
TouchEventInput.prototype.onEventMove = function (event, inputKey) {
if (!this._isValidEvent(event, inputKey)) {
return null;
}
return this.extendEvent(event);
};
TouchEventInput.prototype.onEventEnd = function (event) {
this._baseTouches = event.touches;
return;
};
TouchEventInput.prototype.onRelease = function () {
this.prevEvent = null;
this._baseTouches = null;
return;
};
TouchEventInput.prototype.getTouches = function (event) {
return event.touches.length;
};
TouchEventInput.prototype._getScale = function (event) {
if (event.touches.length !== 2 || this._baseTouches.length < 2) {
return null;
}
return (this._getDistance(event.touches[0], event.touches[1]) /
this._getDistance(this._baseTouches[0], this._baseTouches[1]));
};
TouchEventInput.prototype._getCenter = function (event) {
return {
x: event.touches[0].clientX,
y: event.touches[0].clientY,
};
};
TouchEventInput.prototype._getMovement = function (event) {
var prev = this.prevEvent.srcEvent;
if (event.touches[0].identifier !== prev.touches[0].identifier) {
return {
x: 0,
y: 0,
};
}
return {
x: event.touches[0].clientX - prev.touches[0].clientX,
y: event.touches[0].clientY - prev.touches[0].clientY,
};
};
return TouchEventInput;
}(EventInput));
export { TouchEventInput };
//# sourceMappingURL=TouchEventInput.js.map