@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.
167 lines • 6.61 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 __());
};
})();
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import Component from "@egjs/component";
import { ReactiveSubscribe, Computed } from "@cfcs/core";
import { EventManager } from "./EventManager";
import { InterruptManager } from "./InterruptManager";
import { AxisManager } from "./AxisManager";
import { InputObserver } from "./InputObserver";
import { TRANSFORM, DIRECTION_NONE, DIRECTION_LEFT, DIRECTION_RIGHT, DIRECTION_UP, DIRECTION_DOWN, DIRECTION_HORIZONTAL, DIRECTION_VERTICAL, DIRECTION_ALL, } from "./const";
import { EasingManager } from "./animation/EasingManager";
var Axes = (function (_super) {
__extends(Axes, _super);
function Axes(axis, options, startPos) {
if (axis === void 0) { axis = {}; }
if (options === void 0) { options = {}; }
if (startPos === void 0) { startPos = {}; }
var _this = _super.call(this) || this;
_this.axis = axis;
_this._inputs = [];
_this.options = __assign({
easing: function (x) {
return 1 - Math.pow(1 - x, 3);
},
interruptable: true,
maximumDuration: Infinity,
minimumDuration: 0,
deceleration: 0.0006,
round: null,
nested: false,
}, options);
Object.keys(startPos).forEach(function (key) {
_this.axis[key].startPos = startPos[key];
});
_this.interruptManager = new InterruptManager(_this.options);
_this.axisManager = new AxisManager(_this.axis);
_this.eventManager = new EventManager(_this);
_this.animationManager = new EasingManager(_this);
_this.inputObserver = new InputObserver(_this);
_this.eventManager.setAnimationManager(_this.animationManager);
_this.eventManager.triggerChange(_this.axisManager.get());
return _this;
}
Object.defineProperty(Axes.prototype, "holding", {
get: function () {
return this.eventManager.holdingCount > 0;
},
enumerable: false,
configurable: true
});
Axes.prototype.connect = function (axes, inputType) {
var mapped;
if (typeof axes === "string") {
mapped = axes.split(" ");
}
else {
mapped = axes.concat();
}
if (~this._inputs.indexOf(inputType)) {
this.disconnect(inputType);
}
inputType.mapAxes(mapped);
inputType.connect(this.inputObserver);
this._inputs.push(inputType);
return this;
};
Axes.prototype.disconnect = function (inputType) {
if (inputType) {
var index = this._inputs.indexOf(inputType);
if (index >= 0) {
this._inputs[index].disconnect();
this._inputs.splice(index, 1);
}
}
else {
this._inputs.forEach(function (v) { return v.disconnect(); });
this._inputs = [];
}
return this;
};
Axes.prototype.get = function (axes) {
return this.axisManager.get(axes);
};
Axes.prototype.setTo = function (pos, duration) {
if (duration === void 0) { duration = 0; }
this.animationManager.setTo(pos, duration);
return this;
};
Axes.prototype.setBy = function (pos, duration) {
if (duration === void 0) { duration = 0; }
this.animationManager.setBy(pos, duration);
return this;
};
Axes.prototype.setOptions = function (options) {
this.options = __assign(__assign({}, this.options), options);
this.animationManager.setOptions(options);
return this;
};
Axes.prototype.setAxis = function (axis) {
this.axisManager.setAxis(axis);
return this;
};
Axes.prototype.stopAnimation = function () {
this.animationManager.stopAnimation();
this.animationManager.finish(false);
return this;
};
Axes.prototype.updateAnimation = function (options) {
this.animationManager.updateAnimation(options);
return this;
};
Axes.prototype.isBounceArea = function (axes) {
return this.axisManager.isOutside(axes);
};
Axes.prototype.destroy = function () {
this.disconnect();
this.eventManager.destroy();
};
Axes.VERSION = "#__VERSION__#";
Axes.TRANSFORM = TRANSFORM;
Axes.DIRECTION_NONE = DIRECTION_NONE;
Axes.DIRECTION_LEFT = DIRECTION_LEFT;
Axes.DIRECTION_RIGHT = DIRECTION_RIGHT;
Axes.DIRECTION_UP = DIRECTION_UP;
Axes.DIRECTION_DOWN = DIRECTION_DOWN;
Axes.DIRECTION_HORIZONTAL = DIRECTION_HORIZONTAL;
Axes.DIRECTION_VERTICAL = DIRECTION_VERTICAL;
Axes.DIRECTION_ALL = DIRECTION_ALL;
__decorate([
Computed
], Axes.prototype, "holding", null);
Axes = __decorate([
ReactiveSubscribe
], Axes);
return Axes;
}(Component));
export default Axes;
//# sourceMappingURL=Axes.js.map