UNPKG

@aurigma/design-atoms

Version:

Design Atoms is a part of Customer's Canvas SDK which allows for manipulating individual design elements through your code.

79 lines 3.43 kB
var PointerInputHelper = /** @class */ (function () { function PointerInputHelper(settings) { var _this = this; this._clicks = []; this.isInDownUpThresholdArea = function (point, isTouch) { var threshold = _this._getThreshold(isTouch, false); return _this._isInThresholdArea(point, _this._lastDownPoint, threshold); }; this._isInClickThresholdArea = function (point, isTouch) { var threshold = _this._getThreshold(isTouch, true); var prevClick = _this._getLastClick(); return _this._isInThresholdArea(point, prevClick === null || prevClick === void 0 ? void 0 : prevClick.point, threshold); }; this._isInClickTimeSpan = function (time0, time1) { return Math.abs(time1 - time0) < _this._settings.doubleTapTime; }; this._isInThresholdArea = function (point0, point1, threshold) { if (point1 == null) return false; var dx = Math.abs(point1.x - point0.x); var dy = Math.abs(point1.y - point0.y); return dx < threshold && dy < threshold; }; this._settings = settings; } Object.defineProperty(PointerInputHelper.prototype, "lastDownPoint", { get: function () { return this._lastDownPoint; }, enumerable: true, configurable: true }); PointerInputHelper.prototype.onButtonDown = function (point) { this._lastDownPoint = point; }; PointerInputHelper.prototype.onButtonUp = function (point, isTouch, button) { if (this._lastDownPoint == null) return this._reset(); if (this.isInDownUpThresholdArea(point, isTouch) == false) return this._reset(); var clickCount = this._addClick(this._lastDownPoint, Date.now(), isTouch); this._reset(false); return clickCount; }; PointerInputHelper.prototype.isButtonDown = function () { return this._lastDownPoint != null; }; PointerInputHelper.prototype._getThreshold = function (isTouch, isClick) { var threshold = isTouch ? (isClick ? this._settings.doubleTapThreshold : this._settings.tapThreshold) : this._settings.clickThreshold; return threshold; }; PointerInputHelper.prototype._addClick = function (point, time, isTouch) { var prevClick = this._getLastClick(); if (this._isInClickThresholdArea(point, isTouch) == false || this._isInClickTimeSpan(prevClick === null || prevClick === void 0 ? void 0 : prevClick.time, time) == false) { this._clicks = []; } var click = { point: point, time: time }; this._clicks.push(click); return this._clicks.length; }; PointerInputHelper.prototype._getLastClick = function () { if (this._clicks.length == 0) return null; return this._clicks[this._clicks.length - 1]; }; PointerInputHelper.prototype._reset = function (resetClicks) { if (resetClicks === void 0) { resetClicks = true; } this._lastDownPoint = null; if (resetClicks) this._clicks = []; return 0; }; return PointerInputHelper; }()); export { PointerInputHelper }; //# sourceMappingURL=PointerInputHelper.js.map