UNPKG

@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.

76 lines 2.84 kB
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 MouseEventInput = (function (_super) { __extends(MouseEventInput, _super); function MouseEventInput() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.start = ["mousedown"]; _this.move = ["mousemove"]; _this.end = ["mouseup"]; return _this; } MouseEventInput.prototype.onEventStart = function (event, inputKey, inputButton) { var button = this._getButton(event); if (!this._isValidEvent(event, inputKey, inputButton)) { return null; } this._preventMouseButton(event, button); return this.extendEvent(event); }; MouseEventInput.prototype.onEventMove = function (event, inputKey, inputButton) { if (!this._isValidEvent(event, inputKey, inputButton)) { return null; } return this.extendEvent(event); }; MouseEventInput.prototype.onEventEnd = function () { return; }; MouseEventInput.prototype.onRelease = function () { this.prevEvent = null; return; }; MouseEventInput.prototype.getTouches = function (event, inputButton) { if (inputButton) { return this._isValidButton(MOUSE_BUTTON_CODE_MAP[event.which], inputButton) && this.end.indexOf(event.type) === -1 ? 1 : 0; } return 0; }; MouseEventInput.prototype._getScale = function () { return 1; }; MouseEventInput.prototype._getCenter = function (event) { return { x: event.clientX, y: event.clientY, }; }; MouseEventInput.prototype._getMovement = function (event) { var prev = this.prevEvent.srcEvent; return { x: event.clientX - prev.clientX, y: event.clientY - prev.clientY, }; }; return MouseEventInput; }(EventInput)); export { MouseEventInput }; //# sourceMappingURL=MouseEventInput.js.map