Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@any-touch/recognizer

Package Overview
Dependencies
Maintainers
1
Versions
58
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@any-touch/recognizer - npm Package Compare versions

Comparing version 0.7.9 to 0.8.0

37

dist/index.d.ts

@@ -1,52 +0,35 @@

import { Input } from '@any-touch/shared';
import type { Input, Computed, ComputeWrapFunction } from '@any-touch/shared';
import { RecognizerStatus } from '@any-touch/shared';
export { default as recognizeForPressMoveLike } from './recognizeForPressMoveLike';
export { default as resetStatusForPressMoveLike } from './resetStatusForPressMoveLike';
declare type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
interface ComputeFunction {
(input: Input): Record<string, any> | void;
}
interface GenComputeFunction {
(): ComputeFunction;
_id: string;
}
export default abstract class {
name: string;
disabled: boolean;
isRecognized: boolean;
status: RecognizerStatus;
isRecognized: boolean;
options: {
[propName: string]: any;
[k: string]: any;
};
recognizerMap: Record<string, this>;
computedGroup: Record<string, any>;
computed: Record<string, any>;
computeFunctionMap: Record<string, any>;
input?: Input;
computeFunctions: ComputeWrapFunction[];
constructor(options: {
name: string;
[k: string]: any;
[k: string]: number | string;
});
/**
* 设置识别器
* @param {Object} 选项
* @param options 选项
*/
set(options?: Record<string, any>): this;
/**
* 验证触点
* @param {Number} 触点数
* 验证触点数量
* @param pointLength 触点数
*/
isValidPointLength(pointLength: number): boolean;
/**
* 缓存计算函数的结果
* @param Cs 计算函数
* @param input 计算函数的参数
*/
protected compute<T extends GenComputeFunction>(Cs: T[], input: Input): UnionToIntersection<Exclude<ReturnType<ReturnType<T>>, void>>;
/**
* 适用于大部分移动类型的手势,
* 如pan/rotate/pinch/swipe
* @param {Input} 输入记录
* @param computed 计算值
*/
abstract recognize(Input: Input, callback: (type: string, ...payload: any[]) => void): void;
abstract recognize(computed: Computed, callback: (type: string, ...payload: any[]) => void): void;
/**

@@ -53,0 +36,0 @@ * 校验输入数据

@@ -1,2 +0,2 @@

import { __assign, __values } from 'tslib';
import { __assign } from 'tslib';
import { STATUS_END, STATUS_CANCELLED, STATUS_RECOGNIZED, STATUS_FAILED, STATUS_POSSIBLE, STATUS_START, STATUS_MOVE, INPUT_MOVE, INPUT_END, INPUT_CANCEL, INPUT_START } from '@any-touch/shared';

@@ -10,3 +10,3 @@

function flow(isVaild, activeStatus, stage) {
function flow(isVaild, lastStatus, stage) {
var _a, _b, _c, _d, _e, _f, _g;

@@ -17,2 +17,4 @@ var STATE_MAP = {

_b[INPUT_MOVE] = STATUS_START,
_b[INPUT_END] = STATUS_FAILED,
_b[INPUT_CANCEL] = STATUS_FAILED,
_b),

@@ -32,4 +34,4 @@ _a[STATUS_START] = (_c = {},

_e[STATUS_START] = (_f = {},
_f[INPUT_MOVE] = STATUS_CANCELLED,
_f[INPUT_END] = STATUS_END,
_f[INPUT_MOVE] = STATUS_FAILED,
_f[INPUT_END] = STATUS_FAILED,
_f[INPUT_CANCEL] = STATUS_CANCELLED,

@@ -39,4 +41,4 @@ _f),

_g[INPUT_START] = STATUS_FAILED,
_g[INPUT_MOVE] = STATUS_CANCELLED,
_g[INPUT_END] = STATUS_END,
_g[INPUT_MOVE] = STATUS_FAILED,
_g[INPUT_END] = STATUS_FAILED,
_g[INPUT_CANCEL] = STATUS_CANCELLED,

@@ -46,22 +48,17 @@ _g),

};
if (void 0 !== STATE_MAP[Number(isVaild)][activeStatus]) {
return STATE_MAP[Number(isVaild)][activeStatus][stage] || activeStatus;
}
else {
return activeStatus;
}
var stageToStatusMap = STATE_MAP[Number(isVaild)][lastStatus];
return void 0 !== stageToStatusMap && stageToStatusMap[stage] || lastStatus;
}
function recognizeForPressMoveLike (recognizer, input, emit) {
var isVaild = recognizer.test(input);
function recognizeForPressMoveLike (recognizer, computed, emit) {
var isVaild = recognizer.test(computed);
resetStatus(recognizer);
var stage = input.stage;
var stage = computed.stage;
recognizer.status = flow(isVaild, recognizer.status, stage);
var computed = recognizer.computed;
recognizer.isRecognized = [STATUS_START, STATUS_MOVE].includes(recognizer.status);
var name = recognizer.name, status = recognizer.status, isRecognized = recognizer.isRecognized;
if (isRecognized) {
emit(name, computed);
emit(name);
}
if (isRecognized || [STATUS_END, STATUS_CANCELLED].includes(recognizer.status)) {
emit(name + status, computed);
emit(name + status);
}

@@ -74,8 +71,6 @@ return isVaild;

this.disabled = false;
this.isRecognized = false;
this.status = STATUS_POSSIBLE;
this.isRecognized = false;
this.recognizerMap = {};
this.computedGroup = {};
this.computed = {};
this.computeFunctionMap = {};
this.computeFunctions = [];
this.options = options;

@@ -91,30 +86,4 @@ this.name = this.options.name;

default_1.prototype.isValidPointLength = function (pointLength) {
return 0 === this.options.pointLength || this.options.pointLength === pointLength;
return this.options.pointLength === pointLength;
};
default_1.prototype.compute = function (Cs, input) {
var e_1, _a;
var computed = Object.create(null);
try {
for (var Cs_1 = __values(Cs), Cs_1_1 = Cs_1.next(); !Cs_1_1.done; Cs_1_1 = Cs_1.next()) {
var C = Cs_1_1.value;
var _id = C._id;
var _b = this, computedGroup = _b.computedGroup, computeFunctionMap = _b.computeFunctionMap;
if (void 0 === computeFunctionMap[_id]) {
computeFunctionMap[_id] = C();
}
computedGroup[_id] = computedGroup[_id] || computeFunctionMap[_id](input);
for (var key in computedGroup[_id]) {
computed[key] = computedGroup[_id][key];
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (Cs_1_1 && !Cs_1_1.done && (_a = Cs_1.return)) _a.call(Cs_1);
}
finally { if (e_1) throw e_1.error; }
}
return computed;
};
return default_1;

@@ -121,0 +90,0 @@ }());

@@ -1,1 +0,1 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("tslib"),T=require("@any-touch/shared");function e(t){-1!==[T.STATUS_END,T.STATUS_CANCELLED,T.STATUS_RECOGNIZED,T.STATUS_FAILED].indexOf(t.status)&&(t.status=T.STATUS_POSSIBLE)}var S=function(){function e(t){this.disabled=!1,this.status=T.STATUS_POSSIBLE,this.isRecognized=!1,this.recognizerMap={},this.computedGroup={},this.computed={},this.computeFunctionMap={},this.options=t,this.name=this.options.name}return e.prototype.set=function(T){return void 0!==T&&(this.options=t.__assign(t.__assign({},this.options),T)),this},e.prototype.isValidPointLength=function(t){return 0===this.options.pointLength||this.options.pointLength===t},e.prototype.compute=function(T,e){var S,s,i=Object.create(null);try{for(var o=t.__values(T),r=o.next();!r.done;r=o.next()){var n=r.value,_=n._id,u=this.computedGroup,A=this.computeFunctionMap;for(var E in void 0===A[_]&&(A[_]=n()),u[_]=u[_]||A[_](e),u[_])i[E]=u[_][E]}}catch(t){S={error:t}}finally{try{r&&!r.done&&(s=o.return)&&s.call(o)}finally{if(S)throw S.error}}return i},e}();exports.default=S,exports.recognizeForPressMoveLike=function(t,S,s){var i=t.test(S);e(t);var o=S.stage;t.status=function(t,e,S){var s,i,o,r,n,_,u,A={1:(s={},s[T.STATUS_POSSIBLE]=(i={},i[T.INPUT_MOVE]=T.STATUS_START,i),s[T.STATUS_START]=(o={},o[T.INPUT_MOVE]=T.STATUS_MOVE,o[T.INPUT_END]=T.STATUS_END,o[T.INPUT_CANCEL]=T.STATUS_CANCELLED,o),s[T.STATUS_MOVE]=(r={},r[T.INPUT_MOVE]=T.STATUS_MOVE,r[T.INPUT_END]=T.STATUS_END,r[T.INPUT_CANCEL]=T.STATUS_CANCELLED,r),s),0:(n={},n[T.STATUS_START]=(_={},_[T.INPUT_MOVE]=T.STATUS_CANCELLED,_[T.INPUT_END]=T.STATUS_END,_[T.INPUT_CANCEL]=T.STATUS_CANCELLED,_),n[T.STATUS_MOVE]=(u={},u[T.INPUT_START]=T.STATUS_FAILED,u[T.INPUT_MOVE]=T.STATUS_CANCELLED,u[T.INPUT_END]=T.STATUS_END,u[T.INPUT_CANCEL]=T.STATUS_CANCELLED,u),n)};return void 0!==A[Number(t)][e]&&A[Number(t)][e][S]||e}(i,t.status,o);var r=t.computed;t.isRecognized=[T.STATUS_START,T.STATUS_MOVE].includes(t.status);var n=t.name,_=t.status,u=t.isRecognized;return u&&s(n,r),(u||[T.STATUS_END,T.STATUS_CANCELLED].includes(t.status))&&s(n+_,r),i},exports.resetStatusForPressMoveLike=e;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var T=require("tslib"),S=require("@any-touch/shared");function t(T){-1!==[S.STATUS_END,S.STATUS_CANCELLED,S.STATUS_RECOGNIZED,S.STATUS_FAILED].indexOf(T.status)&&(T.status=S.STATUS_POSSIBLE)}var s=function(){function t(T){this.disabled=!1,this.isRecognized=!1,this.status=S.STATUS_POSSIBLE,this.recognizerMap={},this.computeFunctions=[],this.options=T,this.name=this.options.name}return t.prototype.set=function(S){return void 0!==S&&(this.options=T.__assign(T.__assign({},this.options),S)),this},t.prototype.isValidPointLength=function(T){return this.options.pointLength===T},t}();exports.default=s,exports.recognizeForPressMoveLike=function(T,s,e){var A=T.test(s);t(T);var _=s.stage;T.status=function(T,t,s){var e,A,_,i,E,U,n,o={1:(e={},e[S.STATUS_POSSIBLE]=(A={},A[S.INPUT_MOVE]=S.STATUS_START,A[S.INPUT_END]=S.STATUS_FAILED,A[S.INPUT_CANCEL]=S.STATUS_FAILED,A),e[S.STATUS_START]=(_={},_[S.INPUT_MOVE]=S.STATUS_MOVE,_[S.INPUT_END]=S.STATUS_END,_[S.INPUT_CANCEL]=S.STATUS_CANCELLED,_),e[S.STATUS_MOVE]=(i={},i[S.INPUT_MOVE]=S.STATUS_MOVE,i[S.INPUT_END]=S.STATUS_END,i[S.INPUT_CANCEL]=S.STATUS_CANCELLED,i),e),0:(E={},E[S.STATUS_START]=(U={},U[S.INPUT_MOVE]=S.STATUS_FAILED,U[S.INPUT_END]=S.STATUS_FAILED,U[S.INPUT_CANCEL]=S.STATUS_CANCELLED,U),E[S.STATUS_MOVE]=(n={},n[S.INPUT_START]=S.STATUS_FAILED,n[S.INPUT_MOVE]=S.STATUS_FAILED,n[S.INPUT_END]=S.STATUS_FAILED,n[S.INPUT_CANCEL]=S.STATUS_CANCELLED,n),E)}[Number(T)][t];return void 0!==o&&o[s]||t}(A,T.status,_),T.isRecognized=[S.STATUS_START,S.STATUS_MOVE].includes(T.status);var i=T.name,E=T.status,U=T.isRecognized;return U&&e(i),(U||[S.STATUS_END,S.STATUS_CANCELLED].includes(T.status))&&e(i+E),A},exports.resetStatusForPressMoveLike=t;

@@ -1,2 +0,2 @@

import { CommonEmitFunction, Input } from '@any-touch/shared';
import { EventTrigger, Computed } from '@any-touch/shared';
import Recognizer from './index';

@@ -6,5 +6,7 @@ /**

* 如pan/rotate/pinch/swipe
* @param {Input} 输入记录
* @returns {Boolean} test是否通过
* @param recognizer 识别器实例
* @param computed 当前输入
* @param emit at实例上的emit函数
* @returns 是否通过test
*/
export default function (recognizer: Recognizer, input: Input, emit: CommonEmitFunction): boolean;
export default function (recognizer: Recognizer, computed: Computed, emit: EventTrigger): boolean;
{
"name": "@any-touch/recognizer",
"version": "0.7.9",
"version": "0.8.0",
"description": "any-touch的识别器的基类.",

@@ -11,3 +11,3 @@ "main": "./dist/index",

"dependencies": {
"@any-touch/shared": "^0.7.9"
"@any-touch/shared": "^0.8.0"
},

@@ -21,3 +21,3 @@ "files": [

"sideEffects": false,
"gitHead": "4d795d9ac1c0cf597db9bc070284f3de7578e5fd"
"gitHead": "2bc02cd25dc78562a2b61c95e2d481ac718e805e"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc