Skip to content

Commit

Permalink
style: 移除对tslib的依赖
Browse files Browse the repository at this point in the history
  • Loading branch information
any86 committed Apr 2, 2022
1 parent f0f939b commit f4fb2b0
Show file tree
Hide file tree
Showing 15 changed files with 86 additions and 104 deletions.
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@
"url": "https://github.com/any86/any-touch/issues"
},
"homepage": "https://github.com/any86/any-touch#readme",
"dependencies": {
"tslib": "^2.3.1"
},
"devDependencies": {
"@rollup/plugin-alias": "^2.2.0",
"@rollup/plugin-json": "^4.0.0",
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/bindElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

import type { SupportElement } from 'any-touch';
import type { NativeEvent } from '@any-touch/shared';
import { TOUCH_START, TOUCH_MOVE, TOUCH_END, TOUCH_CANCEL, MOUSE_DOWN, MOUSE_MOVE, MOUSE_UP } from '@any-touch/shared';
const ELEMENT_TYPES = [TOUCH_START, TOUCH_MOVE, TOUCH_END, TOUCH_CANCEL, MOUSE_DOWN];
const WINDOW_TYPES = [MOUSE_MOVE, MOUSE_UP];
import { TOUCH_START, TOUCH_MOVE, TOUCH_END, TOUCH_CANCEL, MOUSE_DOWN, MOUSE_MOVE, MOUSE_UP } from './const';
const ELEMENT_TYPES = [TOUCH_START, TOUCH_MOVE, TOUCH_END, TOUCH_CANCEL, MOUSE_DOWN] as const;
const WINDOW_TYPES = [MOUSE_MOVE, MOUSE_UP] as const;
/*
* 根据输入设备绑定事件
*/
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/canPreventDefault.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NativeEvent } from '@any-touch/shared';
import { isFunction } from '@any-touch/shared';
import type { NativeEvent } from '@any-touch/shared';
import { isFunction } from './const';
import { Options } from './index';
/**
* 计算是否需要阻止默认事件
Expand Down
26 changes: 26 additions & 0 deletions packages/core/src/const.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
export const TOUCH_START = 'touchstart';
export const TOUCH_MOVE = 'touchmove';
export const TOUCH_END = 'touchend';
export const TOUCH_CANCEL = 'touchcancel';

export const MOUSE_UP = 'mouseup';
export const MOUSE_MOVE = 'mousemove';
export const MOUSE_DOWN = 'mousedown';


export const CLIENT_X = 'clientX';
export const CLIENT_Y = 'clientY';


/**
* 输入阶段
*/
export const TYPE_START = 'start';
export const TYPE_MOVE = 'move';
export const TYPE_CANCEL = 'cancel';
export const TYPE_END = 'end';

// const ObjectToString = Object.prototype.toString;
export function isFunction(input: any): input is Function {
return '[object Function]' === Object.prototype.toString.call(input);
}
2 changes: 1 addition & 1 deletion packages/core/src/createInput/mouse.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { phase, PointClientXY } from '@any-touch/shared';
import { MOUSE_DOWN, MOUSE_MOVE, MOUSE_UP, TYPE_START, TYPE_MOVE, TYPE_END } from '@any-touch/shared';
import { MOUSE_DOWN, MOUSE_MOVE, MOUSE_UP, TYPE_START, TYPE_MOVE, TYPE_END } from '../const';
import inputCreator from './inputCreator';
export default function () {
let prevPoints: PointClientXY[];
Expand Down
8 changes: 7 additions & 1 deletion packages/core/src/dispatchDomEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ import type { SupportElement } from 'any-touch';
*/
export default function (typeName: string, el: EventTarget, payload: Partial<AnyTouchEvent>, eventInit?: EventInit): boolean | void {
// 过滤掉Event上保留的字段(target, currentTarget,type)
let { target, currentTarget, type, ...data } = payload;
const data: Omit<Partial<AnyTouchEvent>, 'target' | 'currentTarget' | 'type'> = {};
for (const key in payload) {
if (!['target', 'currentTarget', 'type'].includes(key)) {
data[key] = payload[key];
}
}

let event: Event;
if (document.createEvent) {
event = document.createEvent('HTMLEvents');
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,14 @@ import type {
} from '@any-touch/shared';

import {
TYPE_COMPUTED,
TOUCH_START,
TOUCH_MOVE,
TOUCH_END,
TOUCH_CANCEL,
MOUSE_DOWN,
MOUSE_MOVE,
MOUSE_UP,
} from '@any-touch/shared';
} from './const';

import { mouse, touch } from './createInput';
import dispatchDomEvent from './dispatchDomEvent';
Expand All @@ -48,6 +47,7 @@ export interface Options {
preventDefault?: boolean | ((e: NativeEvent) => boolean);
}

const TYPE_COMPUTED = 'computed';

/**
* 默认设置
Expand Down
40 changes: 3 additions & 37 deletions packages/shared/README.md
Original file line number Diff line number Diff line change
@@ -1,47 +1,13 @@
# @any-touch/share
一些公用方法和常量.
# @any-touch/shared
在这里可以找到状态马

```javascript
// input的类型
export const TYPE_START = 'start';
export const TYPE_MOVE = 'move';
export const TYPE_CANCEL = 'cancel';
export const TYPE_END = 'end';

export const TOUCH = 'touch';
export const MOUSE = 'mouse';

export const TOUCH_START = 'touchstart';
export const TOUCH_MOVE = 'touchmove';
export const TOUCH_END = 'touchend';
export const TOUCH_CANCEL = 'touchcancel';

export const MOUSE_UP = 'mouseup';
export const MOUSE_MOVE = 'mousemove';
export const MOUSE_DOWN = 'mousedown';

// 计算时候取touchs.clientX | clientY
export const CLIENT_X = 'clientX';
export const CLIENT_Y = 'clientY';

export const COMPUTE_INTERVAL = 16;

// 识别器状态码
// 注意: 此处的值会直接被事件名所用, 如panstart/panmove等等
// shared内部代码
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';


// 方向
export const DIRECTION_LEFT = 'left';
export const DIRECTION_RIGHT = 'right';
export const DIRECTION_UP = 'up';
export const DIRECTION_DOWN = 'down';
export const NONE = 'none';

```
11 changes: 0 additions & 11 deletions packages/shared/src/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export const TYPE_MOVE = 'move';
export const TYPE_CANCEL = 'cancel';
export const TYPE_END = 'end';

export const TYPE_COMPUTED = 'computed';

/**
* 方向
Expand All @@ -31,16 +30,6 @@ export const DIRECTION_DOWN = 'down';
export const TOUCH = 'touch';
export const MOUSE = 'mouse';

export const TOUCH_START = TOUCH + TYPE_START as 'touchstart';
export const TOUCH_MOVE = TOUCH + TYPE_MOVE as 'touchmove';
export const TOUCH_END = TOUCH + TYPE_END as 'touchend';
export const TOUCH_CANCEL = TOUCH + TYPE_CANCEL as 'touchcancel';

export const MOUSE_UP = MOUSE + DIRECTION_UP as 'mouseup';
export const MOUSE_MOVE = MOUSE + TYPE_MOVE as 'mousemove';
export const MOUSE_DOWN = MOUSE + DIRECTION_DOWN as 'mousedown';


// 识别器状态码
export const enum STATE {
POSSIBLE,
Expand Down
1 change: 0 additions & 1 deletion packages/shared/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from './is';
export * from './const';
export * from './types'
export * from './pressMoveFlow'
Expand Down
5 changes: 0 additions & 5 deletions packages/shared/src/is.ts

This file was deleted.

1 change: 1 addition & 0 deletions packages/vue3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"author": "any86",
"license": "MIT",
"dependencies": {
"any-touch":"^2.0.3",
"vue": "^3.2.31"
},
"files": [
Expand Down
2 changes: 1 addition & 1 deletion packages/vue3/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { App, DirectiveBinding } from 'vue';
import type { App, DirectiveBinding } from 'vue';
import type { Options, SupportElement } from 'any-touch';
import ATouch from 'any-touch';
const elAndAtMap = new WeakMap();
Expand Down
Loading

0 comments on commit f4fb2b0

Please sign in to comment.