|
- {"ast":null,"code":"import { __assign } from \"tslib\";\nimport { getPosition } from './get-position';\n\nvar Tracker =\n/** @class */\nfunction () {\n function Tracker(touch) {\n this.updateTime = Date.now();\n this.delta = {\n x: 0,\n y: 0\n };\n this.velocity = {\n x: 0,\n y: 0\n };\n this.lastPosition = {\n x: 0,\n y: 0\n };\n this.lastPosition = getPosition(touch);\n }\n\n Tracker.prototype.update = function (touch) {\n var _a = this,\n velocity = _a.velocity,\n updateTime = _a.updateTime,\n lastPosition = _a.lastPosition;\n\n var now = Date.now();\n var position = getPosition(touch);\n var delta = {\n x: -(position.x - lastPosition.x),\n y: -(position.y - lastPosition.y)\n };\n var duration = now - updateTime || 16;\n var vx = delta.x / duration * 16;\n var vy = delta.y / duration * 16;\n velocity.x = vx * 0.9 + velocity.x * 0.1;\n velocity.y = vy * 0.9 + velocity.y * 0.1;\n this.delta = delta;\n this.updateTime = now;\n this.lastPosition = position;\n };\n\n return Tracker;\n}();\n\nexport { Tracker };\n\nvar TouchRecord =\n/** @class */\nfunction () {\n function TouchRecord() {\n this._touchList = {};\n }\n\n Object.defineProperty(TouchRecord.prototype, \"_primitiveValue\", {\n get: function get() {\n return {\n x: 0,\n y: 0\n };\n },\n enumerable: true,\n configurable: true\n });\n\n TouchRecord.prototype.isActive = function () {\n return this._activeTouchID !== undefined;\n };\n\n TouchRecord.prototype.getDelta = function () {\n var tracker = this._getActiveTracker();\n\n if (!tracker) {\n return this._primitiveValue;\n }\n\n return __assign({}, tracker.delta);\n };\n\n TouchRecord.prototype.getVelocity = function () {\n var tracker = this._getActiveTracker();\n\n if (!tracker) {\n return this._primitiveValue;\n }\n\n return __assign({}, tracker.velocity);\n };\n\n TouchRecord.prototype.track = function (evt) {\n var _this = this;\n\n var targetTouches = evt.targetTouches;\n Array.from(targetTouches).forEach(function (touch) {\n _this._add(touch);\n });\n return this._touchList;\n };\n\n TouchRecord.prototype.update = function (evt) {\n var _this = this;\n\n var touches = evt.touches,\n changedTouches = evt.changedTouches;\n Array.from(touches).forEach(function (touch) {\n _this._renew(touch);\n });\n\n this._setActiveID(changedTouches);\n\n return this._touchList;\n };\n\n TouchRecord.prototype.release = function (evt) {\n var _this = this;\n\n delete this._activeTouchID;\n Array.from(evt.changedTouches).forEach(function (touch) {\n _this._delete(touch);\n });\n };\n\n TouchRecord.prototype._add = function (touch) {\n if (this._has(touch)) {\n return;\n }\n\n var tracker = new Tracker(touch);\n this._touchList[touch.identifier] = tracker;\n };\n\n TouchRecord.prototype._renew = function (touch) {\n if (!this._has(touch)) {\n return;\n }\n\n var tracker = this._touchList[touch.identifier];\n tracker.update(touch);\n };\n\n TouchRecord.prototype._delete = function (touch) {\n delete this._touchList[touch.identifier];\n };\n\n TouchRecord.prototype._has = function (touch) {\n return this._touchList.hasOwnProperty(touch.identifier);\n };\n\n TouchRecord.prototype._setActiveID = function (touches) {\n this._activeTouchID = touches[touches.length - 1].identifier;\n };\n\n TouchRecord.prototype._getActiveTracker = function () {\n var _a = this,\n _touchList = _a._touchList,\n _activeTouchID = _a._activeTouchID;\n\n return _touchList[_activeTouchID];\n };\n\n return TouchRecord;\n}();\n\nexport { TouchRecord };","map":null,"metadata":{},"sourceType":"module"}
|