Skip to content

Commit 34c7b86

Browse files
committed
style: 移除对tslib的依赖
1 parent f0f939b commit 34c7b86

File tree

14 files changed

+211
-95
lines changed

14 files changed

+211
-95
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"tslib": "^2.3.1"
4545
},
4646
"devDependencies": {
47+
"rollup-plugin-typescript2":"^0.31.2",
4748
"@rollup/plugin-alias": "^2.2.0",
4849
"@rollup/plugin-json": "^4.0.0",
4950
"@rollup/plugin-replace": "^3.0.0",

packages/core/src/bindElement.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313

1414
import type { SupportElement } from 'any-touch';
1515
import type { NativeEvent } from '@any-touch/shared';
16-
import { TOUCH_START, TOUCH_MOVE, TOUCH_END, TOUCH_CANCEL, MOUSE_DOWN, MOUSE_MOVE, MOUSE_UP } from '@any-touch/shared';
17-
const ELEMENT_TYPES = [TOUCH_START, TOUCH_MOVE, TOUCH_END, TOUCH_CANCEL, MOUSE_DOWN];
18-
const WINDOW_TYPES = [MOUSE_MOVE, MOUSE_UP];
16+
import { TOUCH_START, TOUCH_MOVE, TOUCH_END, TOUCH_CANCEL, MOUSE_DOWN, MOUSE_MOVE, MOUSE_UP } from './const';
17+
const ELEMENT_TYPES = [TOUCH_START, TOUCH_MOVE, TOUCH_END, TOUCH_CANCEL, MOUSE_DOWN] as const;
18+
const WINDOW_TYPES = [MOUSE_MOVE, MOUSE_UP] as const;
1919
/*
2020
* 根据输入设备绑定事件
2121
*/

packages/core/src/canPreventDefault.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { NativeEvent } from '@any-touch/shared';
2-
import { isFunction } from '@any-touch/shared';
1+
import type { NativeEvent } from '@any-touch/shared';
2+
import { isFunction } from './const';
33
import { Options } from './index';
44
/**
55
* 计算是否需要阻止默认事件

packages/core/src/const.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
export const TOUCH_START = 'touchstart';
2+
export const TOUCH_MOVE = 'touchmove';
3+
export const TOUCH_END = 'touchend';
4+
export const TOUCH_CANCEL = 'touchcancel';
5+
6+
export const MOUSE_UP = 'mouseup';
7+
export const MOUSE_MOVE = 'mousemove';
8+
export const MOUSE_DOWN = 'mousedown';
9+
10+
11+
export const CLIENT_X = 'clientX';
12+
export const CLIENT_Y = 'clientY';
13+
14+
15+
/**
16+
* 输入阶段
17+
*/
18+
export const TYPE_START = 'start';
19+
export const TYPE_MOVE = 'move';
20+
export const TYPE_CANCEL = 'cancel';
21+
export const TYPE_END = 'end';
22+
23+
// const ObjectToString = Object.prototype.toString;
24+
export function isFunction(input: any): input is Function {
25+
return '[object Function]' === Object.prototype.toString.call(input);
26+
}

packages/core/src/createInput/mouse.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { phase, PointClientXY } from '@any-touch/shared';
2-
import { MOUSE_DOWN, MOUSE_MOVE, MOUSE_UP, TYPE_START, TYPE_MOVE, TYPE_END } from '@any-touch/shared';
2+
import { MOUSE_DOWN, MOUSE_MOVE, MOUSE_UP, TYPE_START, TYPE_MOVE, TYPE_END } from '../const';
33
import inputCreator from './inputCreator';
44
export default function () {
55
let prevPoints: PointClientXY[];

packages/core/src/dispatchDomEvent.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@ import type { SupportElement } from 'any-touch';
66
*/
77
export default function (typeName: string, el: EventTarget, payload: Partial<AnyTouchEvent>, eventInit?: EventInit): boolean | void {
88
// 过滤掉Event上保留的字段(target, currentTarget,type)
9-
let { target, currentTarget, type, ...data } = payload;
9+
const data: Omit<Partial<AnyTouchEvent>, 'target' | 'currentTarget' | 'type'> = {};
10+
for (const key in payload) {
11+
if (!['target', 'currentTarget', 'type'].includes(key)) {
12+
data[key] = payload[key];
13+
}
14+
}
15+
1016
let event: Event;
1117
if (document.createEvent) {
1218
event = document.createEvent('HTMLEvents');

packages/core/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,14 @@ import type {
2626
} from '@any-touch/shared';
2727

2828
import {
29-
TYPE_COMPUTED,
3029
TOUCH_START,
3130
TOUCH_MOVE,
3231
TOUCH_END,
3332
TOUCH_CANCEL,
3433
MOUSE_DOWN,
3534
MOUSE_MOVE,
3635
MOUSE_UP,
37-
} from '@any-touch/shared';
36+
} from './const';
3837

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

50+
const TYPE_COMPUTED = 'computed';
5151

5252
/**
5353
* 默认设置

packages/shared/README.md

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,13 @@
1-
# @any-touch/share
2-
一些公用方法和常量.
1+
# @any-touch/shared
2+
在这里可以找到状态马
33

44
```javascript
5-
// input的类型
6-
export const TYPE_START = 'start';
7-
export const TYPE_MOVE = 'move';
8-
export const TYPE_CANCEL = 'cancel';
9-
export const TYPE_END = 'end';
10-
11-
export const TOUCH = 'touch';
12-
export const MOUSE = 'mouse';
13-
14-
export const TOUCH_START = 'touchstart';
15-
export const TOUCH_MOVE = 'touchmove';
16-
export const TOUCH_END = 'touchend';
17-
export const TOUCH_CANCEL = 'touchcancel';
18-
19-
export const MOUSE_UP = 'mouseup';
20-
export const MOUSE_MOVE = 'mousemove';
21-
export const MOUSE_DOWN = 'mousedown';
22-
23-
// 计算时候取touchs.clientX | clientY
24-
export const CLIENT_X = 'clientX';
25-
export const CLIENT_Y = 'clientY';
26-
27-
export const COMPUTE_INTERVAL = 16;
28-
29-
// 识别器状态码
30-
// 注意: 此处的值会直接被事件名所用, 如panstart/panmove等等
5+
// shared内部代码
316
export const STATUS_POSSIBLE = 'possible';
327
export const STATUS_START = 'start';
338
export const STATUS_MOVE = 'move';
349
export const STATUS_END = 'end';
3510
export const STATUS_CANCELLED = 'cancel';
3611
export const STATUS_FAILED = 'failed';
3712
export const STATUS_RECOGNIZED = 'recognized';
38-
39-
40-
// 方向
41-
export const DIRECTION_LEFT = 'left';
42-
export const DIRECTION_RIGHT = 'right';
43-
export const DIRECTION_UP = 'up';
44-
export const DIRECTION_DOWN = 'down';
45-
export const NONE = 'none';
46-
4713
```

packages/shared/src/const.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ export const TYPE_MOVE = 'move';
1818
export const TYPE_CANCEL = 'cancel';
1919
export const TYPE_END = 'end';
2020

21-
export const TYPE_COMPUTED = 'computed';
2221

2322
/**
2423
* 方向
@@ -31,16 +30,6 @@ export const DIRECTION_DOWN = 'down';
3130
export const TOUCH = 'touch';
3231
export const MOUSE = 'mouse';
3332

34-
export const TOUCH_START = TOUCH + TYPE_START as 'touchstart';
35-
export const TOUCH_MOVE = TOUCH + TYPE_MOVE as 'touchmove';
36-
export const TOUCH_END = TOUCH + TYPE_END as 'touchend';
37-
export const TOUCH_CANCEL = TOUCH + TYPE_CANCEL as 'touchcancel';
38-
39-
export const MOUSE_UP = MOUSE + DIRECTION_UP as 'mouseup';
40-
export const MOUSE_MOVE = MOUSE + TYPE_MOVE as 'mousemove';
41-
export const MOUSE_DOWN = MOUSE + DIRECTION_DOWN as 'mousedown';
42-
43-
4433
// 识别器状态码
4534
export const enum STATE {
4635
POSSIBLE,

packages/shared/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
export * from './is';
21
export * from './const';
32
export * from './types'
43
export * from './pressMoveFlow'

0 commit comments

Comments
 (0)