Skip to content

Commit c93b739

Browse files
committed
Merge branch 'refactor/build'
2 parents 2fae502 + a70e6ac commit c93b739

File tree

15 files changed

+7474
-7310
lines changed

15 files changed

+7474
-7310
lines changed

jest.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ module.exports = {
1111
collectCoverageFrom: [
1212
'packages/*/src/**/*.ts'],
1313
verbose: false,
14-
testPathIgnorePatterns: ["<rootDir>/node_modules/","<rootDir>/packages/simulator/"],
15-
coveragePathIgnorePatterns: ["<rootDir>/node_modules/","<rootDir>/packages/simulator/"],
14+
testPathIgnorePatterns: ["<rootDir>/node_modules/","<rootDir>/packages/simulator/","<rootDir>/packages/vue3/"],
15+
coveragePathIgnorePatterns: ["<rootDir>/node_modules/","<rootDir>/packages/simulator/","<rootDir>/packages/vue3/"],
1616
globals: {
1717
__TEST__: true,
1818
__VERSION__: require('./package.json').version,

package.json

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,26 +47,25 @@
4747
"@rollup/plugin-alias": "^2.2.0",
4848
"@rollup/plugin-json": "^4.0.0",
4949
"@rollup/plugin-replace": "^3.0.0",
50-
"@rollup/plugin-typescript": "^8.3.00",
51-
"@types/jest": "^24.0.11",
50+
"@rollup/plugin-typescript": "^8.3.1",
51+
"@types/jest": "^26.0.0",
52+
"jest": "^26.0.0",
53+
"ts-jest": "^26.0.0",
5254
"@types/lodash": "^4.14.149",
5355
"brotli": "^1.3.2",
5456
"chalk": "^2.4.2",
5557
"gh-pages": "^2.0.1",
56-
"jest": "^24.7.1",
57-
"lerna": "^3.19.0",
58+
"lerna": "^4.0.0",
5859
"lodash": "^4.17.15",
5960
"minimist": "^1.2.0",
6061
"npm-run-all": "^4.1.5",
6162
"rimraf": "^2.6.2",
6263
"rollup": "^2.60.2",
6364
"rollup-plugin-terser": "^7.0.2",
64-
"rollup-plugin-typescript2": "^0.31.1",
6565
"shelljs": "^0.8.3",
6666
"standard-version": "^4.4.0",
67-
"terser": "^4.6.3",
68-
"ts-jest": "^24.0.2",
69-
"typescript": "^3.8.3",
67+
"terser": "^5.0.0",
68+
"typescript": "^4.6.0",
7069
"zlib": "^1.0.5"
7170
},
7271
"sideEffects": false,

packages/any-touch/src/index.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,17 @@ import press from '@any-touch/press';
1616
import pinch from '@any-touch/pinch';
1717
import rotate from '@any-touch/rotate';
1818
import doubletap from '@any-touch/doubletap';
19-
20-
2119
import {
2220
STATE
2321
} from '@any-touch/shared';
24-
2522
// 类型, 为了兼容
26-
import { Options } from '@any-touch/core';
23+
import { Options as O } from '@any-touch/core';
24+
25+
export type Options = O;
26+
export { AnyTouchEvent } from '@any-touch/shared';
27+
export type SupportElement = HTMLElement | SVGElement;
2728

28-
export default class extends Core {
29+
export default class extends Core {
2930
// 状态码
3031
static STATE_POSSIBLE = STATE.POSSIBLE;
3132
static STATE_START = STATE.START;
@@ -42,7 +43,7 @@ export default class extends Core {
4243
static pinch = pinch;
4344
static doubletap = doubletap;
4445

45-
constructor(el?: HTMLElement, options?: Options) {
46+
constructor(el?: SupportElement, options?: O) {
4647
super(el, options);
4748
this.use(tap);
4849
this.use(pan);

packages/core/src/bindElement.ts

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,41 +11,33 @@
1111
// target.addEventListener(type,listener,options);
1212
// }
1313

14+
import type { SupportElement } from 'any-touch';
1415
import type { NativeEvent } from '@any-touch/shared';
15-
1616
import { TOUCH_START, TOUCH_MOVE, TOUCH_END, TOUCH_CANCEL, MOUSE_DOWN, MOUSE_MOVE, MOUSE_UP } from '@any-touch/shared';
17-
18-
type WType = typeof MOUSE_MOVE | typeof MOUSE_UP;
19-
type EType = typeof TOUCH_START | typeof TOUCH_MOVE | typeof TOUCH_END | typeof TOUCH_CANCEL;
20-
21-
22-
23-
24-
25-
const eTypes = [TOUCH_START, TOUCH_MOVE, TOUCH_END, TOUCH_CANCEL, MOUSE_DOWN];
26-
const wTypes = [MOUSE_MOVE, MOUSE_UP];
17+
const ELEMENT_TYPES = [TOUCH_START, TOUCH_MOVE, TOUCH_END, TOUCH_CANCEL, MOUSE_DOWN];
18+
const WINDOW_TYPES = [MOUSE_MOVE, MOUSE_UP];
2719
/*
2820
* 根据输入设备绑定事件
2921
*/
3022
export default function (
31-
el: HTMLElement,
23+
el: SupportElement,
3224
catchEvent: (e: NativeEvent) => void,
3325
options?: boolean | AddEventListenerOptions
3426
): () => void {
35-
eTypes.forEach((type) => {
36-
el.addEventListener(type, catchEvent, options);
27+
ELEMENT_TYPES.forEach((type) => {
28+
el.addEventListener(type, catchEvent as any, options);
3729
});
3830

39-
wTypes.forEach((type) => {
31+
WINDOW_TYPES.forEach((type) => {
4032
window.addEventListener(type, catchEvent, options);
4133
});
4234

4335
return () => {
44-
eTypes.forEach((types) => {
45-
el.removeEventListener(types, catchEvent);
36+
ELEMENT_TYPES.forEach((types) => {
37+
el.removeEventListener(types, catchEvent as any);
4638
});
4739

48-
wTypes.forEach((type) => {
40+
WINDOW_TYPES.forEach((type) => {
4941
window.removeEventListener(type, catchEvent);
5042
});
5143
};

packages/core/src/createInput/inputCreator.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
*/
55
import type { PubicEvent, InputOnlyHasCurrent, Input, Point } from '@any-touch/shared';
66
import { CLIENT_X, CLIENT_Y, TYPE_START, TYPE_CANCEL, TYPE_END } from '@any-touch/shared';
7+
import type { SupportElement } from 'any-touch';
8+
79
export default function () {
810
let id = 0;
911
let prevInput: InputOnlyHasCurrent | undefined;
@@ -90,7 +92,7 @@ function extendInput(basicsInput: PubicEvent, id: number): Omit<Input, 'prevInpu
9092
pointLength,
9193
currentTarget,
9294
// 触点距离指定元素左上角的偏移
93-
getOffset(el: HTMLElement = currentTarget as HTMLElement): { x: number, y: number } {
95+
getOffset(el: SupportElement = currentTarget as SupportElement): { x: number, y: number } {
9496
const rect = el.getBoundingClientRect();
9597
return { x: x - Math.round(rect.left), y: y - Math.round(rect.top) };
9698
}

packages/core/src/createInput/touch.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import inputCreator from './inputCreator';
33
/**
44
* 格式化Touch事件对象
55
*/
6-
export default function (el?: HTMLElement) {
6+
export default function (el?: Element) {
77
const createInput = inputCreator();
88

99
return function (event: TouchEvent) {
@@ -12,7 +12,7 @@ export default function (el?: HTMLElement) {
1212
const points: { clientX: number, clientY: number, target: EventTarget }[] = [];
1313
Array.from(event.touches).forEach(({ clientX, clientY, target }) => {
1414
// 过滤不在根元素上的触点
15-
if (el?.contains(target as HTMLElement)) {
15+
if (el?.contains(target as Element)) {
1616
targets.push(target);
1717
points.push({ clientX, clientY, target });
1818
}

packages/core/src/dispatchDomEvent.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { AnyTouchEvent } from '@any-touch/shared';
2+
import type { SupportElement } from 'any-touch';
23

34
/**
45
* 触发dom事件
@@ -16,7 +17,7 @@ export default function (typeName: string, el: EventTarget, payload: Partial<Any
1617

1718
Object.assign(event, data, {
1819
match: () =>
19-
payload.targets && 0 < payload.targets.length && payload.targets.every((target) => (event.currentTarget as HTMLElement).contains(target as HTMLElement)),
20+
payload.targets && 0 < payload.targets.length && payload.targets.every((target) => (event.currentTarget as SupportElement).contains(target as SupportElement)),
2021
});
2122
return el.dispatchEvent(event);
2223
}

packages/core/src/index.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
* Event(Mouse|Touch) => BaseInput => Input => Computed => AnyTouchEvent
1010
*/
1111
import AnyEvent from 'any-event';
12+
import type { SupportElement } from 'any-touch';
13+
1214
import type {
1315
UnionToIntersection,
1416
Computed,
@@ -39,22 +41,21 @@ import dispatchDomEvent from './dispatchDomEvent';
3941
import canPreventDefault from './canPreventDefault';
4042
import bindElement from './bindElement';
4143
// type TouchAction = 'auto' | 'none' | 'pan-x' | 'pan-left' | 'pan-right' | 'pan-y' | 'pan-up' | 'pan-down' | 'pinch-zoom' | 'manipulation';
42-
43-
/**
44-
* 默认设置
45-
*/
44+
export { AnyTouchEvent } from '@any-touch/shared';
4645
export interface Options {
4746
// 是否触发DOM事件
4847
domEvents?: false | EventInit;
4948
preventDefault?: boolean | ((e: NativeEvent) => boolean);
5049
}
5150

51+
5252
/**
5353
* 默认设置
5454
*/
5555
const DEFAULT_OPTIONS: Options = {
5656
domEvents: { bubbles: true, cancelable: true },
5757
preventDefault: (event) => {
58+
// console.log((event.target as any).tagName);
5859
if (event.target && 'tagName' in event.target) {
5960
const { tagName } = event.target;
6061
return !/^(?:INPUT|TEXTAREA|BUTTON|SELECT)$/.test(tagName);
@@ -109,7 +110,7 @@ export default class extends AnyEvent<EventMap> {
109110
/**
110111
* 当前绑定元素
111112
*/
112-
el?: HTMLElement;
113+
el?: SupportElement;
113114
/**
114115
* 当前插件(仅供插件开发者使用)
115116
*/
@@ -129,7 +130,7 @@ export default class extends AnyEvent<EventMap> {
129130
* @param el 目标元素, 微信下没有el
130131
* @param options 选项
131132
*/
132-
constructor(el?: HTMLElement, options?: Options) {
133+
constructor(el?: SupportElement, options?: Options) {
133134
super();
134135
this.el = el;
135136
this.c = {} as PluginContext;

packages/shared/src/index.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ export * from './const';
33
export * from './types'
44
export * from './pressMoveFlow'
55
export * from './createPluginContext'
6-
export function addEventListener(target:HTMLElement|Window,){
7-
8-
}
9-
106
export function round2(n: number): number {
117
return Math.round(n * 100) / 100;
128
}

packages/simulator/src/sleep.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export default (time=100) => new Promise((resolve, reject) => {
1+
export default (time=100) => new Promise<void>((resolve, reject) => {
22
try {
33
setTimeout(() => {
44
resolve();

0 commit comments

Comments
 (0)