any-touch
Advanced tools
Comparing version 0.0.21 to 0.0.22
@@ -147,11 +147,11 @@ 'use strict'; | ||
}; | ||
var getDirection = function (displacementX, displacementY) { | ||
if (displacementX === displacementY) { | ||
var getDirection = function (x, y) { | ||
if (x === y) { | ||
return undefined; | ||
} | ||
else if (Math.abs(displacementX) > Math.abs(displacementY)) { | ||
return 0 < displacementX ? 'right' : 'left'; | ||
else if (Math.abs(x) > Math.abs(y)) { | ||
return 0 < x ? 'right' : 'left'; | ||
} | ||
else { | ||
return 0 < displacementY ? 'down' : 'up'; | ||
return 0 < y ? 'down' : 'up'; | ||
} | ||
@@ -308,6 +308,6 @@ }; | ||
var deltaY = (0 < input.centerY) ? input.centerY - _prevInput.centerY : 0; | ||
if (COMPUTE_INTERVAL < deltaTime) { | ||
if (INPUT_CANCEL !== input.inputStatus && COMPUTE_INTERVAL < deltaTime || undefined === _prevDirection) { | ||
velocityX = Math.round(Math.abs(deltaX / deltaTime) * 100) / 100; | ||
velocityY = Math.round(Math.abs(deltaY / deltaTime) * 100) / 100; | ||
direction = getDirection(deltaX, deltaY); | ||
direction = getDirection(deltaX, deltaY) || _prevDirection; | ||
_prevVelocityX = velocityX; | ||
@@ -321,3 +321,3 @@ _prevVelocityY = velocityY; | ||
velocityY = _prevVelocityY || 0; | ||
direction = getDirection(deltaX, deltaY) || _prevDirection; | ||
direction = _prevDirection; | ||
} | ||
@@ -862,3 +862,2 @@ var maxVelocity = Math.max(velocityX, velocityY); | ||
_this._timeoutId = null; | ||
_this._isPressing = false; | ||
return _this; | ||
@@ -872,6 +871,11 @@ } | ||
var inputStatus = computed.inputStatus; | ||
if (INPUT_START === inputStatus) { | ||
this.status = STATUS_POSSIBLE; | ||
} | ||
if (STATUS_FAILED === this.status) | ||
return; | ||
if (STATUS_RECOGNIZED !== this.status) { | ||
var IS_VALID = this.test(computed); | ||
if (!this._isPressing && IS_VALID) { | ||
this._isPressing = true; | ||
if (IS_VALID) { | ||
this.cancel(); | ||
this._timeoutId = window.setTimeout(function () { | ||
@@ -883,6 +887,8 @@ _this.status = STATUS_RECOGNIZED; | ||
else { | ||
if (!IS_VALID) { | ||
this.cancel(); | ||
} | ||
this.cancel(); | ||
this.status = STATUS_FAILED; | ||
} | ||
if (INPUT_END === inputStatus) { | ||
this.status = STATUS_FAILED; | ||
} | ||
} | ||
@@ -892,4 +898,2 @@ else { | ||
this.emit(this.options.name + "up", computed); | ||
this.status = STATUS_POSSIBLE; | ||
this._isPressing = false; | ||
} | ||
@@ -900,10 +904,7 @@ } | ||
var pointerLength = _a.pointerLength, inputStatus = _a.inputStatus, distance = _a.distance; | ||
var IS_VALID_INPUT = 'start' === inputStatus || 'move' === inputStatus; | ||
var IS_VLIAD_DISTANCE = this.options.threshold > distance; | ||
return this.isValidPointerLength(pointerLength) && IS_VALID_INPUT && IS_VLIAD_DISTANCE; | ||
return this.isValidPointerLength(pointerLength) && IS_VLIAD_DISTANCE; | ||
}; | ||
PressRecognizer.prototype.cancel = function () { | ||
clearTimeout(this._timeoutId); | ||
this.status = STATUS_FAILED; | ||
this._isPressing = false; | ||
}; | ||
@@ -910,0 +911,0 @@ PressRecognizer.prototype.afterEmit = function () { }; |
@@ -145,11 +145,11 @@ /*! ***************************************************************************** | ||
}; | ||
var getDirection = function (displacementX, displacementY) { | ||
if (displacementX === displacementY) { | ||
var getDirection = function (x, y) { | ||
if (x === y) { | ||
return undefined; | ||
} | ||
else if (Math.abs(displacementX) > Math.abs(displacementY)) { | ||
return 0 < displacementX ? 'right' : 'left'; | ||
else if (Math.abs(x) > Math.abs(y)) { | ||
return 0 < x ? 'right' : 'left'; | ||
} | ||
else { | ||
return 0 < displacementY ? 'down' : 'up'; | ||
return 0 < y ? 'down' : 'up'; | ||
} | ||
@@ -306,6 +306,6 @@ }; | ||
var deltaY = (0 < input.centerY) ? input.centerY - _prevInput.centerY : 0; | ||
if (COMPUTE_INTERVAL < deltaTime) { | ||
if (INPUT_CANCEL !== input.inputStatus && COMPUTE_INTERVAL < deltaTime || undefined === _prevDirection) { | ||
velocityX = Math.round(Math.abs(deltaX / deltaTime) * 100) / 100; | ||
velocityY = Math.round(Math.abs(deltaY / deltaTime) * 100) / 100; | ||
direction = getDirection(deltaX, deltaY); | ||
direction = getDirection(deltaX, deltaY) || _prevDirection; | ||
_prevVelocityX = velocityX; | ||
@@ -319,3 +319,3 @@ _prevVelocityY = velocityY; | ||
velocityY = _prevVelocityY || 0; | ||
direction = getDirection(deltaX, deltaY) || _prevDirection; | ||
direction = _prevDirection; | ||
} | ||
@@ -860,3 +860,2 @@ var maxVelocity = Math.max(velocityX, velocityY); | ||
_this._timeoutId = null; | ||
_this._isPressing = false; | ||
return _this; | ||
@@ -870,6 +869,11 @@ } | ||
var inputStatus = computed.inputStatus; | ||
if (INPUT_START === inputStatus) { | ||
this.status = STATUS_POSSIBLE; | ||
} | ||
if (STATUS_FAILED === this.status) | ||
return; | ||
if (STATUS_RECOGNIZED !== this.status) { | ||
var IS_VALID = this.test(computed); | ||
if (!this._isPressing && IS_VALID) { | ||
this._isPressing = true; | ||
if (IS_VALID) { | ||
this.cancel(); | ||
this._timeoutId = window.setTimeout(function () { | ||
@@ -881,6 +885,8 @@ _this.status = STATUS_RECOGNIZED; | ||
else { | ||
if (!IS_VALID) { | ||
this.cancel(); | ||
} | ||
this.cancel(); | ||
this.status = STATUS_FAILED; | ||
} | ||
if (INPUT_END === inputStatus) { | ||
this.status = STATUS_FAILED; | ||
} | ||
} | ||
@@ -890,4 +896,2 @@ else { | ||
this.emit(this.options.name + "up", computed); | ||
this.status = STATUS_POSSIBLE; | ||
this._isPressing = false; | ||
} | ||
@@ -898,10 +902,7 @@ } | ||
var pointerLength = _a.pointerLength, inputStatus = _a.inputStatus, distance = _a.distance; | ||
var IS_VALID_INPUT = 'start' === inputStatus || 'move' === inputStatus; | ||
var IS_VLIAD_DISTANCE = this.options.threshold > distance; | ||
return this.isValidPointerLength(pointerLength) && IS_VALID_INPUT && IS_VLIAD_DISTANCE; | ||
return this.isValidPointerLength(pointerLength) && IS_VLIAD_DISTANCE; | ||
}; | ||
PressRecognizer.prototype.cancel = function () { | ||
clearTimeout(this._timeoutId); | ||
this.status = STATUS_FAILED; | ||
this._isPressing = false; | ||
}; | ||
@@ -908,0 +909,0 @@ PressRecognizer.prototype.afterEmit = function () { }; |
@@ -151,11 +151,11 @@ (function (global, factory) { | ||
}; | ||
var getDirection = function (displacementX, displacementY) { | ||
if (displacementX === displacementY) { | ||
var getDirection = function (x, y) { | ||
if (x === y) { | ||
return undefined; | ||
} | ||
else if (Math.abs(displacementX) > Math.abs(displacementY)) { | ||
return 0 < displacementX ? 'right' : 'left'; | ||
else if (Math.abs(x) > Math.abs(y)) { | ||
return 0 < x ? 'right' : 'left'; | ||
} | ||
else { | ||
return 0 < displacementY ? 'down' : 'up'; | ||
return 0 < y ? 'down' : 'up'; | ||
} | ||
@@ -312,6 +312,6 @@ }; | ||
var deltaY = (0 < input.centerY) ? input.centerY - _prevInput.centerY : 0; | ||
if (COMPUTE_INTERVAL < deltaTime) { | ||
if (INPUT_CANCEL !== input.inputStatus && COMPUTE_INTERVAL < deltaTime || undefined === _prevDirection) { | ||
velocityX = Math.round(Math.abs(deltaX / deltaTime) * 100) / 100; | ||
velocityY = Math.round(Math.abs(deltaY / deltaTime) * 100) / 100; | ||
direction = getDirection(deltaX, deltaY); | ||
direction = getDirection(deltaX, deltaY) || _prevDirection; | ||
_prevVelocityX = velocityX; | ||
@@ -325,3 +325,3 @@ _prevVelocityY = velocityY; | ||
velocityY = _prevVelocityY || 0; | ||
direction = getDirection(deltaX, deltaY) || _prevDirection; | ||
direction = _prevDirection; | ||
} | ||
@@ -866,3 +866,2 @@ var maxVelocity = Math.max(velocityX, velocityY); | ||
_this._timeoutId = null; | ||
_this._isPressing = false; | ||
return _this; | ||
@@ -876,6 +875,11 @@ } | ||
var inputStatus = computed.inputStatus; | ||
if (INPUT_START === inputStatus) { | ||
this.status = STATUS_POSSIBLE; | ||
} | ||
if (STATUS_FAILED === this.status) | ||
return; | ||
if (STATUS_RECOGNIZED !== this.status) { | ||
var IS_VALID = this.test(computed); | ||
if (!this._isPressing && IS_VALID) { | ||
this._isPressing = true; | ||
if (IS_VALID) { | ||
this.cancel(); | ||
this._timeoutId = window.setTimeout(function () { | ||
@@ -887,6 +891,8 @@ _this.status = STATUS_RECOGNIZED; | ||
else { | ||
if (!IS_VALID) { | ||
this.cancel(); | ||
} | ||
this.cancel(); | ||
this.status = STATUS_FAILED; | ||
} | ||
if (INPUT_END === inputStatus) { | ||
this.status = STATUS_FAILED; | ||
} | ||
} | ||
@@ -896,4 +902,2 @@ else { | ||
this.emit(this.options.name + "up", computed); | ||
this.status = STATUS_POSSIBLE; | ||
this._isPressing = false; | ||
} | ||
@@ -904,10 +908,7 @@ } | ||
var pointerLength = _a.pointerLength, inputStatus = _a.inputStatus, distance = _a.distance; | ||
var IS_VALID_INPUT = 'start' === inputStatus || 'move' === inputStatus; | ||
var IS_VLIAD_DISTANCE = this.options.threshold > distance; | ||
return this.isValidPointerLength(pointerLength) && IS_VALID_INPUT && IS_VLIAD_DISTANCE; | ||
return this.isValidPointerLength(pointerLength) && IS_VLIAD_DISTANCE; | ||
}; | ||
PressRecognizer.prototype.cancel = function () { | ||
clearTimeout(this._timeoutId); | ||
this.status = STATUS_FAILED; | ||
this._isPressing = false; | ||
}; | ||
@@ -914,0 +915,0 @@ PressRecognizer.prototype.afterEmit = function () { }; |
@@ -1,2 +0,2 @@ | ||
import { COMPUTE_INTERVAL } from '../const'; | ||
import { COMPUTE_INTERVAL, INPUT_CANCEL } from '../const'; | ||
import { getDirection } from '../vector'; | ||
@@ -15,6 +15,6 @@ var _prevInput; | ||
var deltaY = (0 < input.centerY) ? input.centerY - _prevInput.centerY : 0; | ||
if (COMPUTE_INTERVAL < deltaTime) { | ||
if (INPUT_CANCEL !== input.inputStatus && COMPUTE_INTERVAL < deltaTime || undefined === _prevDirection) { | ||
velocityX = Math.round(Math.abs(deltaX / deltaTime) * 100) / 100; | ||
velocityY = Math.round(Math.abs(deltaY / deltaTime) * 100) / 100; | ||
direction = getDirection(deltaX, deltaY); | ||
direction = getDirection(deltaX, deltaY) || _prevDirection; | ||
_prevVelocityX = velocityX; | ||
@@ -28,3 +28,3 @@ _prevVelocityY = velocityY; | ||
velocityY = _prevVelocityY || 0; | ||
direction = getDirection(deltaX, deltaY) || _prevDirection; | ||
direction = _prevDirection; | ||
} | ||
@@ -31,0 +31,0 @@ var maxVelocity = Math.max(velocityX, velocityY); |
@@ -6,3 +6,2 @@ import { Computed } from '../interface'; | ||
protected _timeoutId: number; | ||
private _isPressing; | ||
constructor(options?: Options); | ||
@@ -12,4 +11,4 @@ getTouchAction(): string[]; | ||
test({ pointerLength, inputStatus, distance }: Computed): boolean; | ||
protected cancel(): void; | ||
cancel(): void; | ||
afterEmit(): void; | ||
} |
@@ -15,3 +15,3 @@ var __extends = (this && this.__extends) || (function () { | ||
import { STATUS_POSSIBLE, STATUS_FAILED, STATUS_RECOGNIZED } from '../const/recognizerStatus'; | ||
import { INPUT_END } from '../const'; | ||
import { INPUT_END, INPUT_START } from '../const'; | ||
import Recognizer from './Base'; | ||
@@ -24,3 +24,2 @@ var PressRecognizer = (function (_super) { | ||
_this._timeoutId = null; | ||
_this._isPressing = false; | ||
return _this; | ||
@@ -36,6 +35,11 @@ } | ||
var inputStatus = computed.inputStatus; | ||
if (INPUT_START === inputStatus) { | ||
this.status = STATUS_POSSIBLE; | ||
} | ||
if (STATUS_FAILED === this.status) | ||
return; | ||
if (STATUS_RECOGNIZED !== this.status) { | ||
var IS_VALID = this.test(computed); | ||
if (!this._isPressing && IS_VALID) { | ||
this._isPressing = true; | ||
if (IS_VALID) { | ||
this.cancel(); | ||
this._timeoutId = window.setTimeout(function () { | ||
@@ -47,6 +51,8 @@ _this.status = STATUS_RECOGNIZED; | ||
else { | ||
if (!IS_VALID) { | ||
this.cancel(); | ||
} | ||
this.cancel(); | ||
this.status = STATUS_FAILED; | ||
} | ||
if (INPUT_END === inputStatus) { | ||
this.status = STATUS_FAILED; | ||
} | ||
} | ||
@@ -56,4 +62,2 @@ else { | ||
this.emit(this.options.name + "up", computed); | ||
this.status = STATUS_POSSIBLE; | ||
this._isPressing = false; | ||
} | ||
@@ -65,5 +69,4 @@ } | ||
var pointerLength = _a.pointerLength, inputStatus = _a.inputStatus, distance = _a.distance; | ||
var IS_VALID_INPUT = 'start' === inputStatus || 'move' === inputStatus; | ||
var IS_VLIAD_DISTANCE = this.options.threshold > distance; | ||
return this.isValidPointerLength(pointerLength) && IS_VALID_INPUT && IS_VLIAD_DISTANCE; | ||
return this.isValidPointerLength(pointerLength) && IS_VLIAD_DISTANCE; | ||
}; | ||
@@ -73,4 +76,2 @@ ; | ||
clearTimeout(this._timeoutId); | ||
this.status = STATUS_FAILED; | ||
this._isPressing = false; | ||
}; | ||
@@ -77,0 +78,0 @@ PressRecognizer.prototype.afterEmit = function () { }; |
@@ -13,2 +13,2 @@ import { Vector } from './interface'; | ||
}; | ||
export declare const getDirection: (displacementX: number, displacementY: number) => string; | ||
export declare const getDirection: (x: number, y: number) => string; |
@@ -50,13 +50,13 @@ import { propX, propY } from './const'; | ||
}; | ||
export var getDirection = function (displacementX, displacementY) { | ||
if (displacementX === displacementY) { | ||
export var getDirection = function (x, y) { | ||
if (x === y) { | ||
return undefined; | ||
} | ||
else if (Math.abs(displacementX) > Math.abs(displacementY)) { | ||
return 0 < displacementX ? 'right' : 'left'; | ||
else if (Math.abs(x) > Math.abs(y)) { | ||
return 0 < x ? 'right' : 'left'; | ||
} | ||
else { | ||
return 0 < displacementY ? 'down' : 'up'; | ||
return 0 < y ? 'down' : 'up'; | ||
} | ||
}; | ||
//# sourceMappingURL=vector.js.map |
{ | ||
"name": "any-touch", | ||
"version": "0.0.21", | ||
"version": "0.0.22", | ||
"description": "一个手势库", | ||
"unpkg": "dist/anyTouch.umd.js", | ||
"jsdelivr": "dist/anyTouch.umd.js", | ||
"main": "dist/anyTouch.common.js", | ||
"module": "dist/anyTouch.es.js", | ||
"unpkg": "dist/AnyTouch.umd.js", | ||
"jsdelivr": "dist/AnyTouch.umd.js", | ||
"main": "dist/AnyTouch.common.js", | ||
"module": "dist/AnyTouch.es.js", | ||
"types": "lib/main.d.ts", | ||
@@ -10,0 +10,0 @@ "files": [ |
@@ -6,3 +6,3 @@ // 返回最近一个时间段的计算结果 | ||
import { Input } from '../interface'; | ||
import { COMPUTE_INTERVAL } from '../const'; | ||
import { COMPUTE_INTERVAL, INPUT_CANCEL } from '../const'; | ||
import { getDirection } from '../vector'; | ||
@@ -30,6 +30,6 @@ // 上次采集的input | ||
// 每25ms刷新速度数据 | ||
if (COMPUTE_INTERVAL < deltaTime) { | ||
if (INPUT_CANCEL !== input.inputStatus && COMPUTE_INTERVAL < deltaTime || undefined === _prevDirection) { | ||
velocityX = Math.round(Math.abs(deltaX / deltaTime)*100)/100; | ||
velocityY = Math.round(Math.abs(deltaY / deltaTime)*100)/100; | ||
direction = getDirection(deltaX, deltaY); | ||
direction = getDirection(deltaX, deltaY) || _prevDirection; | ||
// 存储状态 | ||
@@ -43,4 +43,6 @@ _prevVelocityX = velocityX; | ||
velocityY = _prevVelocityY || 0; | ||
// console.log({_prevDirection,deltaX, deltaY}); | ||
// direction = getDirection(deltaX, deltaY) || _prevDirection || 'none'; | ||
direction = getDirection(deltaX, deltaY) || _prevDirection; | ||
direction = _prevDirection; | ||
// console.log({direction}) | ||
} | ||
@@ -50,5 +52,4 @@ | ||
const maxVelocity = Math.max(velocityX, velocityY); | ||
// console.log({deltaX,deltaY,direction,time:Date.now()}); | ||
return { velocity: maxVelocity, velocityX, velocityY, direction }; | ||
}; |
@@ -79,3 +79,2 @@ | ||
computed.lastDirection = <directionString>lastComputed.direction; | ||
// 中心点位移增量 | ||
@@ -82,0 +81,0 @@ let { deltaX, deltaY,deltaXYAngle } = computeDeltaXY({ input, prevInput }); |
@@ -48,7 +48,7 @@ import { Computed, directionString } from '../interface'; | ||
/** | ||
* 识别后发布panleft等事件 | ||
* 识别后发布panleft等事件g | ||
* @param {Computed} 计算数据 | ||
*/ | ||
afterEmit(computed: Computed) { | ||
// console.log({deltaX, deltaY}); | ||
// console.log(computed.lastDirection, computed); | ||
this.emit(this.options.name + computed.lastDirection, computed); | ||
@@ -55,0 +55,0 @@ }; |
@@ -12,7 +12,5 @@ import { Computed } from '../interface'; | ||
protected _timeoutId: number; | ||
private _isPressing: boolean; | ||
constructor(options: Options = {}) { | ||
super(options); | ||
this._timeoutId = null; | ||
this._isPressing = false; | ||
}; | ||
@@ -26,27 +24,39 @@ | ||
const { inputStatus } = computed; | ||
// 手指一直按住屏幕 | ||
if (INPUT_START === inputStatus) { | ||
this.status = STATUS_POSSIBLE; | ||
} | ||
if(STATUS_FAILED === this.status) return; | ||
// 开始识别 | ||
if (STATUS_RECOGNIZED !== this.status) { | ||
// console.log(this.status, computed.distance); | ||
// 如果未开始按住屏幕 && 限制条件已经通过 | ||
// 那么延迟触发press | ||
const IS_VALID = this.test(computed); | ||
if (!this._isPressing && IS_VALID) { | ||
this._isPressing = true; | ||
this._timeoutId = window.setTimeout(() => { | ||
this.status = STATUS_RECOGNIZED; | ||
this.emit(this.options.name, computed); | ||
}, this.options.minPressTime); | ||
} else { | ||
if(!IS_VALID) { | ||
const IS_VALID = this.test(computed) | ||
// console.log({IS_VALID}); | ||
if (IS_VALID) { | ||
// 延迟触发 | ||
this.cancel(); | ||
this._timeoutId = window.setTimeout(() => { | ||
this.status = STATUS_RECOGNIZED; | ||
this.emit(this.options.name, computed); | ||
}, this.options.minPressTime); | ||
// console.log('_timeoutId', this._timeoutId); | ||
} else { | ||
this.cancel(); | ||
this.status = STATUS_FAILED; | ||
} | ||
if(INPUT_END === inputStatus) { | ||
this.status = STATUS_FAILED; | ||
// console.log(this.status); | ||
} | ||
} | ||
// 已识别 | ||
else { | ||
else{ | ||
// end阶段触发pressup | ||
if (INPUT_END === inputStatus) { | ||
this.emit(`${this.options.name}up`, computed); | ||
// 复位状态 | ||
this.status = STATUS_POSSIBLE; | ||
this._isPressing = false; | ||
} | ||
@@ -57,11 +67,12 @@ } | ||
public test({ pointerLength, inputStatus, distance }: Computed): boolean { | ||
const IS_VALID_INPUT = 'start' === inputStatus || 'move' === inputStatus; | ||
// const IS_VALID_INPUT = 'start' === inputStatus || 'move' === inputStatus; | ||
const IS_VLIAD_DISTANCE = this.options.threshold > distance; | ||
return this.isValidPointerLength(pointerLength) && IS_VALID_INPUT && IS_VLIAD_DISTANCE; | ||
return this.isValidPointerLength(pointerLength) && IS_VLIAD_DISTANCE; | ||
// return this.isValidPointerLength(pointerLength) && IS_VALID_INPUT && IS_VLIAD_DISTANCE; | ||
}; | ||
protected cancel() { | ||
public cancel() { | ||
clearTimeout(this._timeoutId); | ||
this.status = STATUS_FAILED; | ||
this._isPressing = false; | ||
// console.warn('cancel',this._timeoutId); | ||
} | ||
@@ -68,0 +79,0 @@ |
@@ -95,12 +95,12 @@ import { Vector } from './interface'; | ||
* @param {Number} 事件开始到结束的X位移 | ||
* @param {Number} 事件开始到结束的Y位移 | ||
* @param {Number} 事件开始到结束的Y位移 | ||
*/ | ||
export const getDirection = (displacementX: number, displacementY: number): string => { | ||
if (displacementX === displacementY) { | ||
export const getDirection = (x: number, y: number): string => { | ||
if (x === y) { | ||
return undefined; | ||
} else if (Math.abs(displacementX) > Math.abs(displacementY)) { | ||
return 0 < displacementX ? 'right' : 'left'; | ||
} else if (Math.abs(x) > Math.abs(y)) { | ||
return 0 < x ? 'right' : 'left'; | ||
} else { | ||
return 0 < displacementY ? 'down' : 'up'; | ||
return 0 < y ? 'down' : 'up'; | ||
} | ||
}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6890
306224