@any-touch/shared
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -0,29 +1,58 @@ | ||
export declare const EVENT_PREFIX = "at"; | ||
/** | ||
* 是否微信 | ||
*/ | ||
export declare const NONE = "none"; | ||
export declare const CLIENT_X = "clientX"; | ||
export declare const CLIENT_Y = "clientY"; | ||
/** | ||
* 计算方向/速度的时间间隔 | ||
*/ | ||
export declare const COMPUTE_INTERVAL = 16; | ||
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 DIRECTION_LEFT = "left"; | ||
export declare const DIRECTION_RIGHT = "right"; | ||
export declare const DIRECTION_UP = "up"; | ||
export declare const DIRECTION_DOWN = "down"; | ||
export declare const NONE = "none"; | ||
export declare const TOUCH = "touch"; | ||
export declare const MOUSE = "mouse"; | ||
export declare const TOUCH_START: "touchstart"; | ||
export declare const TOUCH_MOVE: "touchmove"; | ||
export declare const TOUCH_END: "touchend"; | ||
export declare const TOUCH_CANCEL: "touchcancel"; | ||
export declare const MOUSE_UP: "mouseup"; | ||
export declare const MOUSE_MOVE: "mousemove"; | ||
export declare const MOUSE_DOWN: "mousedown"; | ||
export declare const SUPPORT_TOUCH: boolean; | ||
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 STAGE { | ||
START = "start", | ||
MOVE = "move", | ||
END = "end", | ||
CANCEL = "cancel" | ||
} | ||
/** | ||
* 方向 | ||
*/ | ||
export declare const enum DIRECTION { | ||
LEFT = "left", | ||
RIGHT = "right", | ||
UP = "up", | ||
DOWN = "down" | ||
} | ||
/** | ||
* TOUCH事件名称 | ||
*/ | ||
export declare const enum TOUCH { | ||
START = "touchstart", | ||
MOVE = "touchmove", | ||
END = "touchend", | ||
CANCEL = "touchcancel" | ||
} | ||
/** | ||
* 鼠标事件名称 | ||
*/ | ||
export declare const enum MOUSE { | ||
UP = "mouseup", | ||
MOVE = "mousemove", | ||
DOWN = "mousedown" | ||
} | ||
/** | ||
* 识别器状态码 | ||
*/ | ||
export declare const enum RECOGNIZER_STATUS { | ||
POSSIBLE = 0, | ||
START = 1, | ||
MOVE = 2, | ||
END = 3, | ||
RECOGNIZED = 4, | ||
FAILED = 5, | ||
CANCELLED = 6 | ||
} |
@@ -0,0 +0,0 @@ export * from './is'; |
@@ -9,31 +9,44 @@ var ObjectToString = Object.prototype.toString; | ||
var EVENT_PREFIX = 'at'; | ||
var NONE = 'none'; | ||
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 SUPPORT_TOUCH = "on" + TOUCH_START in window; | ||
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; | ||
var STAGE; | ||
(function (STAGE) { | ||
STAGE["START"] = "start"; | ||
STAGE["MOVE"] = "move"; | ||
STAGE["END"] = "end"; | ||
STAGE["CANCEL"] = "cancel"; | ||
})(STAGE || (STAGE = {})); | ||
var DIRECTION; | ||
(function (DIRECTION) { | ||
DIRECTION["LEFT"] = "left"; | ||
DIRECTION["RIGHT"] = "right"; | ||
DIRECTION["UP"] = "up"; | ||
DIRECTION["DOWN"] = "down"; | ||
})(DIRECTION || (DIRECTION = {})); | ||
var TOUCH; | ||
(function (TOUCH) { | ||
TOUCH["START"] = "touchstart"; | ||
TOUCH["MOVE"] = "touchmove"; | ||
TOUCH["END"] = "touchend"; | ||
TOUCH["CANCEL"] = "touchcancel"; | ||
})(TOUCH || (TOUCH = {})); | ||
var MOUSE; | ||
(function (MOUSE) { | ||
MOUSE["UP"] = "mouseup"; | ||
MOUSE["MOVE"] = "mousemove"; | ||
MOUSE["DOWN"] = "mousedown"; | ||
})(MOUSE || (MOUSE = {})); | ||
var RECOGNIZER_STATUS; | ||
(function (RECOGNIZER_STATUS) { | ||
RECOGNIZER_STATUS[RECOGNIZER_STATUS["POSSIBLE"] = 0] = "POSSIBLE"; | ||
RECOGNIZER_STATUS[RECOGNIZER_STATUS["START"] = 1] = "START"; | ||
RECOGNIZER_STATUS[RECOGNIZER_STATUS["MOVE"] = 2] = "MOVE"; | ||
RECOGNIZER_STATUS[RECOGNIZER_STATUS["END"] = 3] = "END"; | ||
RECOGNIZER_STATUS[RECOGNIZER_STATUS["RECOGNIZED"] = 4] = "RECOGNIZED"; | ||
RECOGNIZER_STATUS[RECOGNIZER_STATUS["FAILED"] = 5] = "FAILED"; | ||
RECOGNIZER_STATUS[RECOGNIZER_STATUS["CANCELLED"] = 6] = "CANCELLED"; | ||
})(RECOGNIZER_STATUS || (RECOGNIZER_STATUS = {})); | ||
@@ -44,2 +57,2 @@ function round2(n) { | ||
export { CLIENT_X, CLIENT_Y, COMPUTE_INTERVAL, DIRECTION_DOWN, DIRECTION_LEFT, DIRECTION_RIGHT, DIRECTION_UP, INPUT_CANCEL, INPUT_END, INPUT_MOVE, INPUT_START, MOUSE, MOUSE_DOWN, MOUSE_MOVE, MOUSE_UP, NONE, STATUS_CANCELLED, STATUS_END, STATUS_FAILED, STATUS_MOVE, STATUS_POSSIBLE, STATUS_RECOGNIZED, STATUS_START, SUPPORT_TOUCH, TOUCH, TOUCH_CANCEL, TOUCH_END, TOUCH_MOVE, TOUCH_START, isFunction, isRegExp, round2 }; | ||
export { CLIENT_X, CLIENT_Y, COMPUTE_INTERVAL, DIRECTION, EVENT_PREFIX, MOUSE, NONE, RECOGNIZER_STATUS, STAGE, TOUCH, isFunction, isRegExp, round2 }; |
@@ -1,1 +0,1 @@ | ||
if (process.env.NODE_ENV === 'development') {module.exports = require('./index.dev.js');} else {module.exports = require('./index.prod.js');} | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=Object.prototype.toString;var e,o,E,r,s;(e=exports.STAGE||(exports.STAGE={})).START="start",e.MOVE="move",e.END="end",e.CANCEL="cancel",(o=exports.DIRECTION||(exports.DIRECTION={})).LEFT="left",o.RIGHT="right",o.UP="up",o.DOWN="down",(E=exports.TOUCH||(exports.TOUCH={})).START="touchstart",E.MOVE="touchmove",E.END="touchend",E.CANCEL="touchcancel",(r=exports.MOUSE||(exports.MOUSE={})).UP="mouseup",r.MOVE="mousemove",r.DOWN="mousedown",(s=exports.RECOGNIZER_STATUS||(exports.RECOGNIZER_STATUS={}))[s.POSSIBLE=0]="POSSIBLE",s[s.START=1]="START",s[s.MOVE=2]="MOVE",s[s.END=3]="END",s[s.RECOGNIZED=4]="RECOGNIZED",s[s.FAILED=5]="FAILED",s[s.CANCELLED=6]="CANCELLED",exports.CLIENT_X="clientX",exports.CLIENT_Y="clientY",exports.COMPUTE_INTERVAL=16,exports.EVENT_PREFIX="at",exports.NONE="none",exports.isFunction=function(e){return"[object Function]"===t.call(e)},exports.isRegExp=function(e){return"[object RegExp]"===t.call(e)},exports.round2=function(t){return Math.round(100*t)/100}; |
export declare function isRegExp(input: any): input is RegExp; | ||
export declare function isFunction(input: any): input is Function; |
@@ -1,5 +0,53 @@ | ||
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'; | ||
export declare type Recognizer = Base; | ||
export declare type AnyTouchPlugin = any; | ||
import { DIRECTION, RECOGNIZER_STATUS, STAGE } from './const'; | ||
/** | ||
* 计算函数 | ||
*/ | ||
export interface ComputeFunction { | ||
(input: Input): Partial<Computed> | void; | ||
} | ||
/** | ||
* 计算函数外壳函数 | ||
*/ | ||
export interface ComputeWrapFunction { | ||
(): ComputeFunction; | ||
_id: string; | ||
} | ||
/** | ||
* 仅用来作为识别器和at通知的载体函数 | ||
*/ | ||
export interface EventTrigger { | ||
(type: string): void; | ||
} | ||
/** | ||
* 识别器选项 | ||
*/ | ||
export declare type RecognizerOptions<DEFAULT_OPTIONS = { | ||
[k: string]: string | number; | ||
}> = Partial<DEFAULT_OPTIONS>; | ||
/** | ||
* 识别器上下文 | ||
*/ | ||
export declare type RecognizerContext<DEFAULT_OPTIONS = any> = RecognizerOptions<DEFAULT_OPTIONS> & { | ||
/** | ||
* 识别状态 | ||
*/ | ||
status: RECOGNIZER_STATUS; | ||
/** | ||
* 识别器对应的事件名称 | ||
*/ | ||
name: string; | ||
}; | ||
/** | ||
* 识别器实例 | ||
*/ | ||
export declare type Recognizer = [RecognizerContext, (computed: Computed, emit: EventTrigger) => void, ComputeWrapFunction[]]; | ||
/** | ||
* 识别器构造函数 | ||
*/ | ||
export interface RecognizerFunction { | ||
(options?: RecognizerOptions): Recognizer; | ||
} | ||
/** | ||
* 适配器支持的事件类型 | ||
*/ | ||
export declare type SupportEvent = MouseEvent | TouchEvent; | ||
@@ -11,6 +59,7 @@ export interface PointClientXY { | ||
} | ||
export declare type InputType = 'start' | 'move' | 'end' | 'cancel'; | ||
export interface BaseInput { | ||
readonly id: number; | ||
readonly inputType: InputType; | ||
/** | ||
* 原生事件对象最基础的统一化 | ||
*/ | ||
export interface BasicsInput { | ||
readonly stage: STAGE; | ||
readonly changedPoints: PointClientXY[]; | ||
@@ -22,3 +71,7 @@ readonly points: PointClientXY[]; | ||
} | ||
export interface PureInput extends BaseInput { | ||
/** | ||
* 不包含prevInput/startInput/startMultiInput的Input | ||
*/ | ||
export interface InputOnlyHasCurrent extends BasicsInput { | ||
readonly id: number; | ||
readonly isStart: boolean; | ||
@@ -33,3 +86,3 @@ readonly isEnd: boolean; | ||
readonly y: number; | ||
readonly getOffset: (el: HTMLElement | SVGElement) => { | ||
readonly getOffset: (el: HTMLElement) => { | ||
x: number; | ||
@@ -39,21 +92,13 @@ y: number; | ||
} | ||
export interface Input extends PureInput { | ||
readonly startInput: PureInput; | ||
readonly startMultiInput?: PureInput; | ||
readonly prevInput?: PureInput; | ||
/** | ||
* 统一化event后数据 | ||
*/ | ||
export interface Input extends InputOnlyHasCurrent { | ||
readonly startInput: InputOnlyHasCurrent; | ||
readonly startMultiInput?: InputOnlyHasCurrent; | ||
readonly prevInput?: InputOnlyHasCurrent; | ||
} | ||
export interface StdClass { | ||
new (...args: any[]): any; | ||
} | ||
export interface ComputeConstructor { | ||
_id: string; | ||
new (...args: any[]): { | ||
compute(input: Input): Record<string, any> | void; | ||
}; | ||
} | ||
export interface CommonEmitFunction { | ||
(type: string, ...payload: any[]): void; | ||
} | ||
export declare type directionString = 'up' | 'right' | 'down' | 'left' | 'none'; | ||
export declare type RecognizerStatus = 'possible' | 'recognized' | 'began' | 'changed' | 'ended' | 'failed' | 'cancelled'; | ||
/** | ||
* 点 | ||
*/ | ||
export interface Point { | ||
@@ -64,33 +109,43 @@ x: number; | ||
export declare type Vector = Point; | ||
export declare type InputRecord = { | ||
input: Input; | ||
startInput: Input; | ||
prevInput?: Input; | ||
startMultiInput?: Input; | ||
}; | ||
export interface Computed { | ||
maxPointLength?: number; | ||
velocityX: number; | ||
velocityY: number; | ||
speedX: number; | ||
speedY: number; | ||
scale: number; | ||
deltaScale: number; | ||
angle: number; | ||
deltaAngle: number; | ||
deltaX: number; | ||
deltaY: number; | ||
deltaXYAngle: number; | ||
displacementX: number; | ||
displacementY: number; | ||
distanceX: number; | ||
distanceY: number; | ||
distance: number; | ||
deltaTime: number; | ||
overallDirection?: directionString; | ||
direction?: directionString; | ||
/** | ||
* 仅仅是获取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 direction?: DIRECTION; | ||
} | ||
export interface AnyTouchEvent extends Input, Readonly<Computed> { | ||
readonly name: string; | ||
readonly type: string; | ||
} | ||
export declare type SupportStatus = typeof STATUS_POSSIBLE | typeof STATUS_START | typeof STATUS_MOVE | typeof STATUS_END | typeof STATUS_CANCELLED | typeof STATUS_FAILED | typeof STATUS_RECOGNIZED; | ||
/** | ||
* Input转换器 | ||
*/ | ||
export interface InputCreatorFunction<T> { | ||
(event: T): void | Input; | ||
} |
{ | ||
"name": "@any-touch/shared", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "any-touch内部的公共函数.", | ||
@@ -19,3 +19,3 @@ "main": "dist/index.js", | ||
"sideEffects": false, | ||
"gitHead": "daec688784b1b67c7e427a0b474deae8773f54e6" | ||
"gitHead": "a11a02a110bf20b6163b5b716b60b87de3b967da" | ||
} |
@@ -5,4 +5,2 @@ # @any-touch/share | ||
```javascript | ||
export const SUPPORT_TOUCH = 'ontouchstart' in window; | ||
// input的类型 | ||
@@ -32,13 +30,3 @@ export const INPUT_START = 'start'; | ||
// 识别器状态码 | ||
// 注意: 此处的值会直接被事件名所用, 如panstart/panmove等等 | ||
export const STATUS_POSSIBLE = 'possible'; | ||
export const STATUS_START = 'start'; | ||
export const STATUS_MOVE = 'move'; | ||
export const STATUS_END = 'end'; | ||
export const STATUS_CANCELLED = 'cancel'; | ||
export const STATUS_FAILED = 'failed'; | ||
export const STATUS_RECOGNIZED = 'recognized'; | ||
// 方向 | ||
@@ -49,4 +37,2 @@ export const DIRECTION_LEFT = 'left'; | ||
export const DIRECTION_DOWN = 'down'; | ||
export const NONE = 'none'; | ||
``` | ||
export const NONE = 'none'; |
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
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
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
268
1
10550
9
35
1