diff --git a/package.json b/package.json index 4e2fde49..8ea8ad90 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/packages/core/src/bindElement.ts b/packages/core/src/bindElement.ts index 19622387..3896bbb7 100644 --- a/packages/core/src/bindElement.ts +++ b/packages/core/src/bindElement.ts @@ -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; /* * 根据输入设备绑定事件 */ diff --git a/packages/core/src/canPreventDefault.ts b/packages/core/src/canPreventDefault.ts index 33a92bf4..bacc45cb 100644 --- a/packages/core/src/canPreventDefault.ts +++ b/packages/core/src/canPreventDefault.ts @@ -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'; /** * 计算是否需要阻止默认事件 diff --git a/packages/core/src/const.ts b/packages/core/src/const.ts new file mode 100644 index 00000000..958c52bd --- /dev/null +++ b/packages/core/src/const.ts @@ -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); +} \ No newline at end of file diff --git a/packages/core/src/createInput/mouse.ts b/packages/core/src/createInput/mouse.ts index 4bbfd1bd..c99e94ba 100644 --- a/packages/core/src/createInput/mouse.ts +++ b/packages/core/src/createInput/mouse.ts @@ -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[]; diff --git a/packages/core/src/dispatchDomEvent.ts b/packages/core/src/dispatchDomEvent.ts index aa88c855..84dbac8c 100644 --- a/packages/core/src/dispatchDomEvent.ts +++ b/packages/core/src/dispatchDomEvent.ts @@ -6,7 +6,13 @@ import type { SupportElement } from 'any-touch'; */ export default function (typeName: string, el: EventTarget, payload: Partial, eventInit?: EventInit): boolean | void { // 过滤掉Event上保留的字段(target, currentTarget,type) - let { target, currentTarget, type, ...data } = payload; + const data: Omit, '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'); diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 30acadcd..de06ed7d 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -26,7 +26,6 @@ import type { } from '@any-touch/shared'; import { - TYPE_COMPUTED, TOUCH_START, TOUCH_MOVE, TOUCH_END, @@ -34,7 +33,7 @@ import { MOUSE_DOWN, MOUSE_MOVE, MOUSE_UP, -} from '@any-touch/shared'; +} from './const'; import { mouse, touch } from './createInput'; import dispatchDomEvent from './dispatchDomEvent'; @@ -48,6 +47,7 @@ export interface Options { preventDefault?: boolean | ((e: NativeEvent) => boolean); } +const TYPE_COMPUTED = 'computed'; /** * 默认设置 diff --git a/packages/shared/README.md b/packages/shared/README.md index 82f1532f..a16c3f11 100644 --- a/packages/shared/README.md +++ b/packages/shared/README.md @@ -1,33 +1,8 @@ -# @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'; @@ -35,13 +10,4 @@ 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'; - ``` \ No newline at end of file diff --git a/packages/shared/src/const.ts b/packages/shared/src/const.ts index 769da198..7fe44da3 100644 --- a/packages/shared/src/const.ts +++ b/packages/shared/src/const.ts @@ -18,7 +18,6 @@ export const TYPE_MOVE = 'move'; export const TYPE_CANCEL = 'cancel'; export const TYPE_END = 'end'; -export const TYPE_COMPUTED = 'computed'; /** * 方向 @@ -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, diff --git a/packages/shared/src/index.ts b/packages/shared/src/index.ts index cbfae6bb..eda4b693 100644 --- a/packages/shared/src/index.ts +++ b/packages/shared/src/index.ts @@ -1,4 +1,3 @@ -export * from './is'; export * from './const'; export * from './types' export * from './pressMoveFlow' diff --git a/packages/shared/src/is.ts b/packages/shared/src/is.ts deleted file mode 100644 index 128fe7a2..00000000 --- a/packages/shared/src/is.ts +++ /dev/null @@ -1,5 +0,0 @@ -const ObjectToString = Object.prototype.toString; - -export function isFunction(input: any): input is Function { - return '[object Function]' === ObjectToString.call(input); -} \ No newline at end of file diff --git a/packages/vue3/package.json b/packages/vue3/package.json index 625f2a59..94fdb44b 100644 --- a/packages/vue3/package.json +++ b/packages/vue3/package.json @@ -8,6 +8,7 @@ "author": "any86", "license": "MIT", "dependencies": { + "any-touch":"^2.0.3", "vue": "^3.2.31" }, "files": [ diff --git a/packages/vue3/src/index.ts b/packages/vue3/src/index.ts index 66816d32..64d4747c 100644 --- a/packages/vue3/src/index.ts +++ b/packages/vue3/src/index.ts @@ -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(); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 08c59c3a..4fafc6aa 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -25,16 +25,13 @@ importers: standard-version: ^4.4.0 terser: ^5.0.0 ts-jest: ^26.0.0 - tslib: ^2.3.1 typescript: ^4.6.0 zlib: ^1.0.5 - dependencies: - tslib: registry.npmmirror.com/tslib/2.3.1 devDependencies: '@rollup/plugin-alias': registry.npmmirror.com/@rollup/plugin-alias/2.2.0_rollup@2.64.0 '@rollup/plugin-json': registry.npmmirror.com/@rollup/plugin-json/4.1.0_rollup@2.64.0 '@rollup/plugin-replace': registry.npmmirror.com/@rollup/plugin-replace/3.0.1_rollup@2.64.0 - '@rollup/plugin-typescript': 8.3.1_d7b4467172c319d6620c719344e1beb5 + '@rollup/plugin-typescript': 8.3.1_rollup@2.64.0+typescript@4.6.3 '@types/jest': 26.0.24 '@types/lodash': registry.npmmirror.com/@types/lodash/4.14.178 brotli: registry.npmmirror.com/brotli/1.3.2 @@ -63,15 +60,15 @@ importers: packages/any-touch: specifiers: - '@any-touch/core': ^2.0.2 - '@any-touch/doubletap': ^2.0.2 - '@any-touch/pan': ^2.0.2 - '@any-touch/pinch': ^2.0.2 - '@any-touch/press': ^2.0.2 - '@any-touch/rotate': ^2.0.2 - '@any-touch/swipe': ^2.0.2 - '@any-touch/tap': ^2.0.2 - any-event: ^2.0.2 + '@any-touch/core': ^2.0.3 + '@any-touch/doubletap': ^2.0.3 + '@any-touch/pan': ^2.0.3 + '@any-touch/pinch': ^2.0.3 + '@any-touch/press': ^2.0.3 + '@any-touch/rotate': ^2.0.3 + '@any-touch/swipe': ^2.0.3 + '@any-touch/tap': ^2.0.3 + any-event: ^2.0.3 tslib: ^2.3.1 dependencies: '@any-touch/core': link:../core @@ -87,8 +84,8 @@ importers: packages/compute: specifiers: - '@any-touch/shared': ^2.0.2 - '@any-touch/vector': ^2.0.2 + '@any-touch/shared': ^2.0.3 + '@any-touch/vector': ^2.0.3 tslib: ^2.3.1 dependencies: '@any-touch/shared': link:../shared @@ -97,17 +94,17 @@ importers: packages/core: specifiers: - '@any-touch/shared': ^2.0.2 - any-event: ^2.0.2 + '@any-touch/shared': ^2.0.3 + any-event: ^2.0.3 dependencies: '@any-touch/shared': link:../shared any-event: link:../any-event packages/doubletap: specifiers: - '@any-touch/compute': ^2.0.2 - '@any-touch/shared': ^2.0.2 - '@any-touch/vector': ^2.0.2 + '@any-touch/compute': ^2.0.3 + '@any-touch/shared': ^2.0.3 + '@any-touch/vector': ^2.0.3 dependencies: '@any-touch/compute': link:../compute '@any-touch/shared': link:../shared @@ -115,29 +112,29 @@ importers: packages/pan: specifiers: - '@any-touch/compute': ^2.0.2 - '@any-touch/shared': ^2.0.2 + '@any-touch/compute': ^2.0.3 + '@any-touch/shared': ^2.0.3 dependencies: '@any-touch/compute': link:../compute '@any-touch/shared': link:../shared packages/pinch: specifiers: - '@any-touch/compute': ^2.0.2 + '@any-touch/compute': ^2.0.3 dependencies: '@any-touch/compute': link:../compute packages/press: specifiers: - '@any-touch/compute': ^2.0.2 - '@any-touch/shared': ^2.0.2 + '@any-touch/compute': ^2.0.3 + '@any-touch/shared': ^2.0.3 dependencies: '@any-touch/compute': link:../compute '@any-touch/shared': link:../shared packages/rotate: specifiers: - '@any-touch/compute': ^2.0.2 + '@any-touch/compute': ^2.0.3 dependencies: '@any-touch/compute': link:../compute @@ -152,17 +149,17 @@ importers: packages/swipe: specifiers: - '@any-touch/compute': ^2.0.2 - '@any-touch/shared': ^2.0.2 + '@any-touch/compute': ^2.0.3 + '@any-touch/shared': ^2.0.3 dependencies: '@any-touch/compute': link:../compute '@any-touch/shared': link:../shared packages/tap: specifiers: - '@any-touch/compute': ^2.0.2 - '@any-touch/shared': ^2.0.2 - '@any-touch/vector': ^2.0.2 + '@any-touch/compute': ^2.0.3 + '@any-touch/shared': ^2.0.3 + '@any-touch/vector': ^2.0.3 dependencies: '@any-touch/compute': link:../compute '@any-touch/shared': link:../shared @@ -170,14 +167,16 @@ importers: packages/vector: specifiers: - '@any-touch/shared': ^2.0.2 + '@any-touch/shared': ^2.0.3 dependencies: '@any-touch/shared': link:../shared packages/vue3: specifiers: + any-touch: ^2.0.3 vue: ^3.2.31 dependencies: + any-touch: link:../any-touch vue: registry.npmmirror.com/vue/3.2.31 packages: @@ -1594,7 +1593,7 @@ packages: '@octokit/openapi-types': 11.2.0 dev: true - /@rollup/plugin-typescript/8.3.1_d7b4467172c319d6620c719344e1beb5: + /@rollup/plugin-typescript/8.3.1_rollup@2.64.0+typescript@4.6.3: resolution: {integrity: sha512-84rExe3ICUBXzqNX48WZV2Jp3OddjTMX97O2Py6D1KJaGSwWp0mDHXj+bCGNJqWHIEKDIT2U0sDjhP4czKi6cA==} engines: {node: '>=8.0.0'} peerDependencies: @@ -1605,7 +1604,6 @@ packages: '@rollup/pluginutils': 3.1.0_rollup@2.64.0 resolve: 1.21.0 rollup: registry.npmmirror.com/rollup/2.64.0 - tslib: registry.npmmirror.com/tslib/2.3.1 typescript: 4.6.3 dev: true @@ -8016,7 +8014,7 @@ packages: version: 1.1.0 engines: {node: '>=0.10.0'} dependencies: - graceful-fs: registry.npmmirror.com/graceful-fs/4.2.9 + graceful-fs: 4.2.9 parse-json: registry.npmmirror.com/parse-json/2.2.0 pify: registry.nlark.com/pify/2.3.0 pinkie-promise: registry.nlark.com/pinkie-promise/2.0.1 @@ -8029,7 +8027,7 @@ packages: version: 2.0.0 engines: {node: '>=4'} dependencies: - graceful-fs: registry.npmmirror.com/graceful-fs/4.2.9 + graceful-fs: 4.2.9 parse-json: registry.npmmirror.com/parse-json/2.2.0 pify: registry.nlark.com/pify/2.3.0 strip-bom: registry.nlark.com/strip-bom/3.0.0 @@ -8312,7 +8310,7 @@ packages: version: 1.1.0 engines: {node: '>=0.10.0'} dependencies: - graceful-fs: registry.npmmirror.com/graceful-fs/4.2.9 + graceful-fs: 4.2.9 pify: registry.nlark.com/pify/2.3.0 pinkie-promise: registry.nlark.com/pinkie-promise/2.0.1 dev: true diff --git a/scripts/build.es.js b/scripts/build.es.js index 224f0471..b2dff7df 100644 --- a/scripts/build.es.js +++ b/scripts/build.es.js @@ -18,6 +18,11 @@ walkPackageDirs((dirName) => { target: 'ES6', module: "ESNEXT", }, terser: terser({ + // mangle: { + // properties: { + // regex: /^__/ + // } + // }, output: { comments: false }