@any-touch/shared
Advanced tools
Comparing version 1.0.15 to 2.0.0-alpha.0
/** | ||
* 是否微信 | ||
*/ | ||
export declare const IS_WX: boolean; | ||
export declare const CLIENT_X = "clientX"; | ||
@@ -14,6 +13,7 @@ export declare const CLIENT_Y = "clientY"; | ||
*/ | ||
export declare const INPUT_START = "start"; | ||
export declare const INPUT_MOVE = "move"; | ||
export declare const INPUT_CANCEL = "cancel"; | ||
export declare const INPUT_END = "end"; | ||
export declare const TYPE_START = "start"; | ||
export declare const TYPE_MOVE = "move"; | ||
export declare const TYPE_CANCEL = "cancel"; | ||
export declare const TYPE_END = "end"; | ||
export declare const TYPE_COMPUTED = "computed"; | ||
/** | ||
@@ -26,3 +26,2 @@ * 方向 | ||
export declare const DIRECTION_DOWN = "down"; | ||
export declare const NONE = "none"; | ||
export declare const TOUCH = "touch"; | ||
@@ -37,8 +36,10 @@ export declare const MOUSE = "mouse"; | ||
export declare const MOUSE_DOWN: "mousedown"; | ||
export declare const STATUS_POSSIBLE = "p"; | ||
export declare const STATUS_START = "start"; | ||
export declare const STATUS_MOVE = "move"; | ||
export declare const STATUS_END = "end"; | ||
export declare const STATUS_RECOGNIZED = "r"; | ||
export declare const STATUS_FAILED = "f"; | ||
export declare const STATUS_CANCELLED = "cancel"; | ||
export declare const enum STATE { | ||
POSSIBLE = 0, | ||
RECOGNIZED = 1, | ||
FAILED = 2, | ||
CANCELLED = 3, | ||
START = 4, | ||
MOVE = 5, | ||
END = 1 | ||
} |
export * from './is'; | ||
export * from './const'; | ||
export * from './types'; | ||
export * from './pressMoveFlow'; | ||
export * from './createPluginContext'; | ||
export declare function round2(n: number): number; |
@@ -1,43 +0,1 @@ | ||
var ObjectToString = Object.prototype.toString; | ||
function isRegExp(input) { | ||
return '[object RegExp]' === ObjectToString.call(input); | ||
} | ||
function isFunction(input) { | ||
return '[object Function]' === ObjectToString.call(input); | ||
} | ||
var IS_WX = !!window.wx; | ||
var CLIENT_X = 'clientX'; | ||
var CLIENT_Y = 'clientY'; | ||
var COMPUTE_INTERVAL = 16; | ||
var INPUT_START = 'start'; | ||
var INPUT_MOVE = 'move'; | ||
var INPUT_CANCEL = 'cancel'; | ||
var INPUT_END = 'end'; | ||
var DIRECTION_LEFT = 'left'; | ||
var DIRECTION_RIGHT = 'right'; | ||
var DIRECTION_UP = 'up'; | ||
var DIRECTION_DOWN = 'down'; | ||
var NONE = 'none'; | ||
var TOUCH = 'touch'; | ||
var MOUSE = 'mouse'; | ||
var TOUCH_START = TOUCH + INPUT_START; | ||
var TOUCH_MOVE = TOUCH + INPUT_MOVE; | ||
var TOUCH_END = TOUCH + INPUT_END; | ||
var TOUCH_CANCEL = TOUCH + INPUT_CANCEL; | ||
var MOUSE_UP = MOUSE + DIRECTION_UP; | ||
var MOUSE_MOVE = MOUSE + INPUT_MOVE; | ||
var MOUSE_DOWN = MOUSE + DIRECTION_DOWN; | ||
var STATUS_POSSIBLE = 'p'; | ||
var STATUS_START = INPUT_START; | ||
var STATUS_MOVE = INPUT_MOVE; | ||
var STATUS_END = INPUT_END; | ||
var STATUS_RECOGNIZED = 'r'; | ||
var STATUS_FAILED = 'f'; | ||
var STATUS_CANCELLED = INPUT_CANCEL; | ||
function round2(n) { | ||
return Math.round(n * 100) / 100; | ||
} | ||
export { CLIENT_X, CLIENT_Y, COMPUTE_INTERVAL, DIRECTION_DOWN, DIRECTION_LEFT, DIRECTION_RIGHT, DIRECTION_UP, INPUT_CANCEL, INPUT_END, INPUT_MOVE, INPUT_START, IS_WX, MOUSE, MOUSE_DOWN, MOUSE_MOVE, MOUSE_UP, NONE, STATUS_CANCELLED, STATUS_END, STATUS_FAILED, STATUS_MOVE, STATUS_POSSIBLE, STATUS_RECOGNIZED, STATUS_START, TOUCH, TOUCH_CANCEL, TOUCH_END, TOUCH_MOVE, TOUCH_START, isFunction, isRegExp, round2 }; | ||
import{__assign as t}from"tslib";var e=Object.prototype.toString;function E(t){return"[object Function]"===e.call(t)}var n,o,c="clientX",u="clientY",r=16,L="start",D="move",a="cancel",i="end",S="computed",A="left",C="right",N="up",O="down",d="touch",l="mouse",m="touchstart",s="touchmove",I="touchend",v="touchcancel",T="mouseup",f="mousemove",R="mousedown";!function(t){t[t.POSSIBLE=0]="POSSIBLE",t[t.RECOGNIZED=1]="RECOGNIZED",t[t.FAILED=2]="FAILED",t[t.CANCELLED=3]="CANCELLED",t[t.START=4]="START",t[t.MOVE=5]="MOVE",t[t.END=1]="END"}(n||(n={}));var M=((o={})[n.START]="start",o[n.MOVE]="move",o[n.END]="end",o[n.CANCELLED]="cancel",o);function V(t){return M[t]}function h(t,e,E){var o,c,u,r,L,D,a,i={1:(o={},o[n.POSSIBLE]=(c={},c.move=n.START,c),o[n.START]=(u={},u.move=n.MOVE,u.end=n.END,u.cancel=n.CANCELLED,u),o[n.MOVE]=(r={},r.move=n.MOVE,r.end=n.END,r.cancel=n.CANCELLED,r),o),0:(L={},L[n.START]=(D={},D.move=n.FAILED,D.end=n.END,D.cancel=n.CANCELLED,D),L[n.MOVE]=(a={},a.start=n.FAILED,a.move=n.FAILED,a.end=n.END,a.cancel=n.CANCELLED,a),L)}[Number(t)][e];return void 0!==i&&i[E]||n.POSSIBLE}function p(t){[n.RECOGNIZED,n.CANCELLED,n.FAILED].includes(t.state)&&(t.state=n.POSSIBLE)}function B(t){return[n.START,n.MOVE].includes(t)}function F(t){if(t.disabled)return t.state=n.POSSIBLE,!0}function P(e,E){return t(t(t({},e),E),{state:n.POSSIBLE,disabled:!1})}function b(t){return Math.round(100*t)/100}export{c as CLIENT_X,u as CLIENT_Y,r as COMPUTE_INTERVAL,O as DIRECTION_DOWN,A as DIRECTION_LEFT,C as DIRECTION_RIGHT,N as DIRECTION_UP,l as MOUSE,R as MOUSE_DOWN,f as MOUSE_MOVE,T as MOUSE_UP,n as STATE,d as TOUCH,v as TOUCH_CANCEL,I as TOUCH_END,s as TOUCH_MOVE,m as TOUCH_START,a as TYPE_CANCEL,S as TYPE_COMPUTED,i as TYPE_END,D as TYPE_MOVE,L as TYPE_START,P as createPluginContext,h as flow,V as getStatusName,F as isDisabled,E as isFunction,B as isRecognized,p as resetState,b as round2}; |
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=Object.prototype.toString;var t=!!window.wx;exports.CLIENT_X="clientX",exports.CLIENT_Y="clientY",exports.COMPUTE_INTERVAL=16,exports.DIRECTION_DOWN="down",exports.DIRECTION_LEFT="left",exports.DIRECTION_RIGHT="right",exports.DIRECTION_UP="up",exports.INPUT_CANCEL="cancel",exports.INPUT_END="end",exports.INPUT_MOVE="move",exports.INPUT_START="start",exports.IS_WX=t,exports.MOUSE="mouse",exports.MOUSE_DOWN="mousedown",exports.MOUSE_MOVE="mousemove",exports.MOUSE_UP="mouseup",exports.NONE="none",exports.STATUS_CANCELLED="cancel",exports.STATUS_END="end",exports.STATUS_FAILED="f",exports.STATUS_MOVE="move",exports.STATUS_POSSIBLE="p",exports.STATUS_RECOGNIZED="r",exports.STATUS_START="start",exports.TOUCH="touch",exports.TOUCH_CANCEL="touchcancel",exports.TOUCH_END="touchend",exports.TOUCH_MOVE="touchmove",exports.TOUCH_START="touchstart",exports.isFunction=function(t){return"[object Function]"===e.call(t)},exports.isRegExp=function(t){return"[object RegExp]"===e.call(t)},exports.round2=function(e){return Math.round(100*e)/100}; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("tslib"),t=Object.prototype.toString;var E,o;(E=exports.STATE||(exports.STATE={}))[E.POSSIBLE=0]="POSSIBLE",E[E.RECOGNIZED=1]="RECOGNIZED",E[E.FAILED=2]="FAILED",E[E.CANCELLED=3]="CANCELLED",E[E.START=4]="START",E[E.MOVE=5]="MOVE",E[E.END=1]="END";var T=((o={})[exports.STATE.START]="start",o[exports.STATE.MOVE]="move",o[exports.STATE.END]="end",o[exports.STATE.CANCELLED]="cancel",o);exports.CLIENT_X="clientX",exports.CLIENT_Y="clientY",exports.COMPUTE_INTERVAL=16,exports.DIRECTION_DOWN="down",exports.DIRECTION_LEFT="left",exports.DIRECTION_RIGHT="right",exports.DIRECTION_UP="up",exports.MOUSE="mouse",exports.MOUSE_DOWN="mousedown",exports.MOUSE_MOVE="mousemove",exports.MOUSE_UP="mouseup",exports.TOUCH="touch",exports.TOUCH_CANCEL="touchcancel",exports.TOUCH_END="touchend",exports.TOUCH_MOVE="touchmove",exports.TOUCH_START="touchstart",exports.TYPE_CANCEL="cancel",exports.TYPE_COMPUTED="computed",exports.TYPE_END="end",exports.TYPE_MOVE="move",exports.TYPE_START="start",exports.createPluginContext=function(t,E){return e.__assign(e.__assign(e.__assign({},t),E),{state:exports.STATE.POSSIBLE,disabled:!1})},exports.flow=function(e,t,E){var o,T,r,s,p,x,S,A={1:(o={},o[exports.STATE.POSSIBLE]=(T={},T.move=exports.STATE.START,T),o[exports.STATE.START]=(r={},r.move=exports.STATE.MOVE,r.end=exports.STATE.END,r.cancel=exports.STATE.CANCELLED,r),o[exports.STATE.MOVE]=(s={},s.move=exports.STATE.MOVE,s.end=exports.STATE.END,s.cancel=exports.STATE.CANCELLED,s),o),0:(p={},p[exports.STATE.START]=(x={},x.move=exports.STATE.FAILED,x.end=exports.STATE.END,x.cancel=exports.STATE.CANCELLED,x),p[exports.STATE.MOVE]=(S={},S.start=exports.STATE.FAILED,S.move=exports.STATE.FAILED,S.end=exports.STATE.END,S.cancel=exports.STATE.CANCELLED,S),p)}[Number(e)][t];return void 0!==A&&A[E]||exports.STATE.POSSIBLE},exports.getStatusName=function(e){return T[e]},exports.isDisabled=function(e){if(e.disabled)return e.state=exports.STATE.POSSIBLE,!0},exports.isFunction=function(e){return"[object Function]"===t.call(e)},exports.isRecognized=function(e){return[exports.STATE.START,exports.STATE.MOVE].includes(e)},exports.resetState=function(e){[exports.STATE.RECOGNIZED,exports.STATE.CANCELLED,exports.STATE.FAILED].includes(e.state)&&(e.state=exports.STATE.POSSIBLE)},exports.round2=function(e){return Math.round(100*e)/100}; |
@@ -1,2 +0,1 @@ | ||
export declare function isRegExp(input: any): input is RegExp; | ||
export declare function isFunction(input: any): input is Function; |
@@ -1,13 +0,8 @@ | ||
import { STATUS_POSSIBLE, STATUS_START, STATUS_MOVE, STATUS_END, STATUS_CANCELLED, STATUS_FAILED, STATUS_RECOGNIZED } from '@any-touch/shared'; | ||
import Base from '@any-touch/recognizer'; | ||
import Core from '@any-touch/core'; | ||
import { STATE } from './const'; | ||
export declare type KV = Record<string, any>; | ||
/** | ||
* 基础识别器类型 | ||
*/ | ||
export declare type Recognizer = Base; | ||
export declare type AnyTouchPlugin = any; | ||
export declare type RecognizerConstruct = typeof Base; | ||
/** | ||
* 适配器支持的事件类型 | ||
*/ | ||
export declare type SupportEvent = MouseEvent | TouchEvent; | ||
export declare type NativeEvent = MouseEvent | TouchEvent; | ||
export interface PointClientXY { | ||
@@ -21,8 +16,8 @@ target: EventTarget | null; | ||
*/ | ||
export declare type stage = 'start' | 'move' | 'end' | 'cancel'; | ||
export declare type phase = 'start' | 'move' | 'end' | 'cancel'; | ||
/** | ||
* 原生事件对象最基础的统一化 | ||
* 原生事件上选取的共有字段 | ||
*/ | ||
export interface BasicsInput { | ||
readonly stage: stage; | ||
export interface PubicEvent { | ||
readonly phase: phase; | ||
readonly changedPoints: PointClientXY[]; | ||
@@ -37,3 +32,3 @@ readonly points: PointClientXY[]; | ||
*/ | ||
export interface InputOnlyHasCurrent extends BasicsInput { | ||
export interface InputOnlyHasCurrent extends PubicEvent { | ||
readonly id: number; | ||
@@ -55,3 +50,3 @@ readonly isStart: boolean; | ||
/** | ||
* 统一化event后数据 | ||
* 提供给插件(compute函数)之前的统一化数据 | ||
*/ | ||
@@ -64,21 +59,2 @@ export interface Input extends InputOnlyHasCurrent { | ||
/** | ||
* 计算函数 | ||
*/ | ||
export interface ComputeFunction { | ||
(input: Input): Partial<Computed> | void; | ||
} | ||
/** | ||
* 计算函数外壳函数 | ||
*/ | ||
export interface ComputeWrapFunction { | ||
(): ComputeFunction; | ||
_id: string; | ||
} | ||
/** | ||
* 仅用来作为识别器和at通知的载体函数 | ||
*/ | ||
export interface EventTrigger { | ||
(type: string): void; | ||
} | ||
/** | ||
* 方向 | ||
@@ -96,35 +72,30 @@ */ | ||
/** | ||
* 仅仅是获取scale/angle的前置计算值 | ||
*/ | ||
export interface VS { | ||
prevV: Point; | ||
startV: Point; | ||
activeV: Point; | ||
} | ||
/** | ||
* Input执行计算后的数据格式 | ||
*/ | ||
export interface Computed extends Input { | ||
readonly maxPointLength: number; | ||
readonly velocityX: number; | ||
readonly velocityY: number; | ||
readonly speedX: number; | ||
readonly speedY: number; | ||
readonly scale: number; | ||
readonly deltaScale: number; | ||
readonly angle: number; | ||
readonly deltaAngle: number; | ||
readonly deltaX: number; | ||
readonly deltaY: number; | ||
readonly deltaXYAngle: number; | ||
readonly displacementX: number; | ||
readonly displacementY: number; | ||
readonly distanceX: number; | ||
readonly distanceY: number; | ||
readonly distance: number; | ||
readonly deltaTime: number; | ||
readonly overallDirection: directionString; | ||
readonly direction: directionString; | ||
export interface Computed extends KV { | ||
readonly maxPointLength?: number; | ||
readonly velocityX?: number; | ||
readonly velocityY?: number; | ||
readonly speedX?: number; | ||
readonly speedY?: number; | ||
readonly scale?: number; | ||
readonly deltaScale?: number; | ||
readonly angle?: number; | ||
readonly deltaAngle?: number; | ||
readonly deltaX?: number; | ||
readonly deltaY?: number; | ||
readonly deltaXYAngle?: number; | ||
readonly displacementX?: number; | ||
readonly displacementY?: number; | ||
readonly distanceX?: number; | ||
readonly distanceY?: number; | ||
readonly distance?: number; | ||
readonly deltaTime?: number; | ||
readonly overallDirection?: directionString; | ||
readonly direction?: directionString; | ||
readonly startVecotr?: Vector; | ||
readonly prevVecotr?: Vector; | ||
readonly activeVecotr?: Vector; | ||
} | ||
export interface AnyTouchEvent extends Input, Readonly<Computed> { | ||
export interface AnyTouchEvent extends Input, Required<Computed> { | ||
readonly type: string; | ||
@@ -138,3 +109,3 @@ readonly stopPropagation: () => void; | ||
*/ | ||
export declare type _$recognizerstatus = typeof STATUS_POSSIBLE | typeof STATUS_START | typeof STATUS_MOVE | typeof STATUS_END | typeof STATUS_CANCELLED | typeof STATUS_FAILED | typeof STATUS_RECOGNIZED; | ||
export declare type RECOGNIZER_STATE = STATE; | ||
/** | ||
@@ -146,6 +117,2 @@ * Input转换器 | ||
} | ||
export interface InputCreatorWrapFunction { | ||
(el?: HTMLElement): InputCreatorFunction<TouchEvent>; | ||
(): InputCreatorFunction<MouseEvent>; | ||
} | ||
/** | ||
@@ -155,3 +122,32 @@ * Input转换器外壳函数映射 | ||
export interface InputCreatorFunctionMap { | ||
[k: string]: InputCreatorFunction<SupportEvent>; | ||
[k: string]: InputCreatorFunction<NativeEvent>; | ||
} | ||
export declare type PluginOptions = { | ||
name?: string; | ||
} & KV; | ||
/** | ||
* 插件上下文内容 | ||
*/ | ||
export declare type PluginContext<D extends Required<PluginOptions> = Required<PluginOptions>> = { | ||
state: RECOGNIZER_STATE; | ||
disabled: boolean; | ||
} & D; | ||
/** | ||
* 插件 | ||
*/ | ||
export declare type Plugin = (context: Core, pluginOptions?: PluginOptions) => PluginContext; | ||
/** | ||
* 计算函数 | ||
*/ | ||
export declare type ComputeFunction = (input: Input, computed: Partial<Computed>) => Computed | void; | ||
/** | ||
* 计算函数生成器 | ||
*/ | ||
export declare type ComputeFunctionCreator = () => ComputeFunction; | ||
/** | ||
* 仅用来作为识别器和at通知的载体函数 | ||
*/ | ||
export interface EventTrigger { | ||
(type: string): void; | ||
} | ||
export declare type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never; |
{ | ||
"name": "@any-touch/shared", | ||
"version": "1.0.15", | ||
"version": "2.0.0-alpha.0", | ||
"description": "any-touch内部的公共函数.", | ||
@@ -16,3 +16,3 @@ "main": "dist/index.js", | ||
"sideEffects": false, | ||
"gitHead": "20d54f8303eda39f4ef4efdd1f5e2aadde0c713e" | ||
"gitHead": "3fb899bb8ad845ab52fa4a932cc895637e173723" | ||
} |
@@ -6,6 +6,6 @@ # @any-touch/share | ||
// input的类型 | ||
export const INPUT_START = 'start'; | ||
export const INPUT_MOVE = 'move'; | ||
export const INPUT_CANCEL = 'cancel'; | ||
export const INPUT_END = 'end'; | ||
export const TYPE_START = 'start'; | ||
export const TYPE_MOVE = 'move'; | ||
export const TYPE_CANCEL = 'cancel'; | ||
export const TYPE_END = 'end'; | ||
@@ -12,0 +12,0 @@ export const TOUCH = 'touch'; |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
14143
11
249
3
1