@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.
105 lines • 4.18 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, SUPPORT_POINTER } from "./EventInput";
var PointerEventInput = (function (_super) {
__extends(PointerEventInput, _super);
function PointerEventInput() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.start = SUPPORT_POINTER ? ["pointerdown"] : ["MSPointerDown"];
_this.move = SUPPORT_POINTER ? ["pointermove"] : ["MSPointerMove"];
_this.end = SUPPORT_POINTER
? ["pointerup", "pointercancel"]
: ["MSPointerUp", "MSPointerCancel"];
_this._firstInputs = [];
_this._recentInputs = [];
return _this;
}
PointerEventInput.prototype.onEventStart = function (event, inputKey, inputButton) {
var button = this._getButton(event);
if (!this._isValidEvent(event, inputKey, inputButton)) {
return null;
}
this._preventMouseButton(event, button);
this._updatePointerEvent(event);
return this.extendEvent(event);
};
PointerEventInput.prototype.onEventMove = function (event, inputKey, inputButton) {
if (!this._isValidEvent(event, inputKey, inputButton)) {
return null;
}
this._updatePointerEvent(event);
return this.extendEvent(event);
};
PointerEventInput.prototype.onEventEnd = function (event) {
this._removePointerEvent(event);
};
PointerEventInput.prototype.onRelease = function () {
this.prevEvent = null;
this._firstInputs = [];
this._recentInputs = [];
return;
};
PointerEventInput.prototype.getTouches = function () {
return this._recentInputs.length;
};
PointerEventInput.prototype._getScale = function () {
if (this._recentInputs.length !== 2) {
return null;
}
return (this._getDistance(this._recentInputs[0], this._recentInputs[1]) /
this._getDistance(this._firstInputs[0], this._firstInputs[1]));
};
PointerEventInput.prototype._getCenter = function (event) {
return {
x: event.clientX,
y: event.clientY,
};
};
PointerEventInput.prototype._getMovement = function (event) {
var prev = this.prevEvent.srcEvent;
if (event.pointerId !== prev.pointerId) {
return {
x: 0,
y: 0,
};
}
return {
x: event.clientX - prev.clientX,
y: event.clientY - prev.clientY,
};
};
PointerEventInput.prototype._updatePointerEvent = function (event) {
var _this = this;
var addFlag = false;
this._recentInputs.forEach(function (e, i) {
if (e.pointerId === event.pointerId) {
addFlag = true;
_this._recentInputs[i] = event;
}
});
if (!addFlag) {
this._firstInputs.push(event);
this._recentInputs.push(event);
}
};
PointerEventInput.prototype._removePointerEvent = function (event) {
this._firstInputs = this._firstInputs.filter(function (x) { return x.pointerId !== event.pointerId; });
this._recentInputs = this._recentInputs.filter(function (x) { return x.pointerId !== event.pointerId; });
};
return PointerEventInput;
}(EventInput));
export { PointerEventInput };
//# sourceMappingURL=PointerEventInput.js.map