Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

any-touch

Package Overview
Dependencies
Maintainers
1
Versions
149
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

any-touch - npm Package Compare versions

Comparing version 0.0.12 to 0.0.13

example/index.css

45

dist/anyTouch.common.js

@@ -88,3 +88,2 @@ 'use strict';

var INPUT_END = 'end';
//# sourceMappingURL=const.js.map

@@ -142,3 +141,2 @@ var EventBus = (function () {

}());
//# sourceMappingURL=EventBus.js.map

@@ -202,7 +200,12 @@ var round = Math.round;

};
//# sourceMappingURL=vector.js.map
var touchAdapter = (function (event) {
var pointers = event.touches;
var changedPointers = event.changedTouches;
var pointers = Array.from(event.touches).map(function (_a) {
var clientX = _a.clientX, clientY = _a.clientY;
return ({ clientX: clientX, clientY: clientY });
});
var changedPointers = Array.from(event.changedTouches).map(function (_a) {
var clientX = _a.clientX, clientY = _a.clientY;
return ({ clientX: clientX, clientY: clientY });
});
var inputStatus = event.type.replace('touch', '');

@@ -216,3 +219,2 @@ return {

});
//# sourceMappingURL=touch.js.map

@@ -254,3 +256,2 @@ var prevPointers = undefined;

});
//# sourceMappingURL=mouse.js.map

@@ -305,3 +306,2 @@ var centerX;

});
//# sourceMappingURL=create.js.map

@@ -342,3 +342,2 @@ var startInput;

});
//# sourceMappingURL=inputManage.js.map

@@ -358,4 +357,4 @@ var _prevInput;

if (COMPUTE_INTERVAL < deltaTime) {
velocityX = Math.abs(deltaX / deltaTime);
velocityY = Math.abs(deltaY / deltaTime);
velocityX = Math.round(Math.abs(deltaX / deltaTime) * 100) / 100;
velocityY = Math.round(Math.abs(deltaY / deltaTime) * 100) / 100;
direction = getDirection(deltaX, deltaY);

@@ -375,3 +374,2 @@ _prevVelocityX = velocityX;

});
//# sourceMappingURL=computeLast.js.map

@@ -406,3 +404,2 @@ var prevDisplacementX = 0;

}
//# sourceMappingURL=computeDistance.js.map

@@ -423,3 +420,2 @@ function computeDeltaXY (_a) {

}
//# sourceMappingURL=computeDeltaXY.js.map

@@ -430,3 +426,2 @@ var computeVector = (function (input) { return ({

}); });
//# sourceMappingURL=computeVector.js.map

@@ -439,3 +434,2 @@ function computeScale (_a) {

}
//# sourceMappingURL=computeScale.js.map

@@ -448,3 +442,2 @@ function computeAngle (_a) {

}
//# sourceMappingURL=computeAngle.js.map

@@ -462,3 +455,2 @@ var maxLength = 0;

});
//# sourceMappingURL=computeMaxLength.js.map

@@ -471,4 +463,2 @@ function compute (_a) {

var computed = {
pointers: [],
changedPointers: [],
pointerLength: input.pointerLength,

@@ -538,3 +528,2 @@ changedPointerLength: input.changedPointerLength,

}
//# sourceMappingURL=index.js.map

@@ -580,3 +569,2 @@ var computeTouchAction = (function (touchActions) {

});
//# sourceMappingURL=computeTouchAction.js.map

@@ -590,3 +578,2 @@ var STATUS_POSSIBLE = 'possible';

var STATUS_RECOGNIZED = 'recognized';
//# sourceMappingURL=recognizerStatus.js.map

@@ -714,3 +701,2 @@ var Recognizer = (function () {

};
//# sourceMappingURL=Base.js.map

@@ -781,3 +767,2 @@ var setTimeout = window.setTimeout, clearTimeout$1 = window.clearTimeout;

};
//# sourceMappingURL=Tap.js.map

@@ -835,3 +820,2 @@ var PressRecognizer = (function (_super) {

};
//# sourceMappingURL=Press.js.map

@@ -869,3 +853,2 @@ var getHV = (function (directions) {

});
//# sourceMappingURL=getHV.js.map

@@ -910,3 +893,2 @@ var PanRecognizer = (function (_super) {

};
//# sourceMappingURL=Pan.js.map

@@ -952,3 +934,2 @@ var SwipeRecognizer = (function (_super) {

};
//# sourceMappingURL=Swipe.js.map

@@ -976,3 +957,3 @@ var PinchRecognizer = (function (_super) {

var pointerLength = _a.pointerLength, scale = _a.scale;
return this.isValidPointerLength(pointerLength) && (this.options.threshold < Math.abs(scale - 1) || this.isRecognized);
return this.isValidPointerLength(pointerLength) && (this.options.threshold < Math.abs(scale) || this.isRecognized);
};

@@ -986,3 +967,2 @@ return PinchRecognizer;

};
//# sourceMappingURL=Pinch.js.map

@@ -1010,3 +990,2 @@ var RotateRecognizer = (function (_super) {

};
//# sourceMappingURL=Rotate.js.map

@@ -1131,2 +1110,3 @@ var DEFAULT_OPTIONS = {

var _this = this;
event.preventDefault();
var inputs = inputManage(event);

@@ -1160,4 +1140,3 @@ if (undefined !== inputs) {

}());
//# sourceMappingURL=main.js.map
module.exports = AnyTouch;

@@ -86,3 +86,2 @@ /*! *****************************************************************************

var INPUT_END = 'end';
//# sourceMappingURL=const.js.map

@@ -140,3 +139,2 @@ var EventBus = (function () {

}());
//# sourceMappingURL=EventBus.js.map

@@ -200,7 +198,12 @@ var round = Math.round;

};
//# sourceMappingURL=vector.js.map
var touchAdapter = (function (event) {
var pointers = event.touches;
var changedPointers = event.changedTouches;
var pointers = Array.from(event.touches).map(function (_a) {
var clientX = _a.clientX, clientY = _a.clientY;
return ({ clientX: clientX, clientY: clientY });
});
var changedPointers = Array.from(event.changedTouches).map(function (_a) {
var clientX = _a.clientX, clientY = _a.clientY;
return ({ clientX: clientX, clientY: clientY });
});
var inputStatus = event.type.replace('touch', '');

@@ -214,3 +217,2 @@ return {

});
//# sourceMappingURL=touch.js.map

@@ -252,3 +254,2 @@ var prevPointers = undefined;

});
//# sourceMappingURL=mouse.js.map

@@ -303,3 +304,2 @@ var centerX;

});
//# sourceMappingURL=create.js.map

@@ -340,3 +340,2 @@ var startInput;

});
//# sourceMappingURL=inputManage.js.map

@@ -356,4 +355,4 @@ var _prevInput;

if (COMPUTE_INTERVAL < deltaTime) {
velocityX = Math.abs(deltaX / deltaTime);
velocityY = Math.abs(deltaY / deltaTime);
velocityX = Math.round(Math.abs(deltaX / deltaTime) * 100) / 100;
velocityY = Math.round(Math.abs(deltaY / deltaTime) * 100) / 100;
direction = getDirection(deltaX, deltaY);

@@ -373,3 +372,2 @@ _prevVelocityX = velocityX;

});
//# sourceMappingURL=computeLast.js.map

@@ -404,3 +402,2 @@ var prevDisplacementX = 0;

}
//# sourceMappingURL=computeDistance.js.map

@@ -421,3 +418,2 @@ function computeDeltaXY (_a) {

}
//# sourceMappingURL=computeDeltaXY.js.map

@@ -428,3 +424,2 @@ var computeVector = (function (input) { return ({

}); });
//# sourceMappingURL=computeVector.js.map

@@ -437,3 +432,2 @@ function computeScale (_a) {

}
//# sourceMappingURL=computeScale.js.map

@@ -446,3 +440,2 @@ function computeAngle (_a) {

}
//# sourceMappingURL=computeAngle.js.map

@@ -460,3 +453,2 @@ var maxLength = 0;

});
//# sourceMappingURL=computeMaxLength.js.map

@@ -469,4 +461,2 @@ function compute (_a) {

var computed = {
pointers: [],
changedPointers: [],
pointerLength: input.pointerLength,

@@ -536,3 +526,2 @@ changedPointerLength: input.changedPointerLength,

}
//# sourceMappingURL=index.js.map

@@ -578,3 +567,2 @@ var computeTouchAction = (function (touchActions) {

});
//# sourceMappingURL=computeTouchAction.js.map

@@ -588,3 +576,2 @@ var STATUS_POSSIBLE = 'possible';

var STATUS_RECOGNIZED = 'recognized';
//# sourceMappingURL=recognizerStatus.js.map

@@ -712,3 +699,2 @@ var Recognizer = (function () {

};
//# sourceMappingURL=Base.js.map

@@ -779,3 +765,2 @@ var setTimeout = window.setTimeout, clearTimeout$1 = window.clearTimeout;

};
//# sourceMappingURL=Tap.js.map

@@ -833,3 +818,2 @@ var PressRecognizer = (function (_super) {

};
//# sourceMappingURL=Press.js.map

@@ -867,3 +851,2 @@ var getHV = (function (directions) {

});
//# sourceMappingURL=getHV.js.map

@@ -908,3 +891,2 @@ var PanRecognizer = (function (_super) {

};
//# sourceMappingURL=Pan.js.map

@@ -950,3 +932,2 @@ var SwipeRecognizer = (function (_super) {

};
//# sourceMappingURL=Swipe.js.map

@@ -974,3 +955,3 @@ var PinchRecognizer = (function (_super) {

var pointerLength = _a.pointerLength, scale = _a.scale;
return this.isValidPointerLength(pointerLength) && (this.options.threshold < Math.abs(scale - 1) || this.isRecognized);
return this.isValidPointerLength(pointerLength) && (this.options.threshold < Math.abs(scale) || this.isRecognized);
};

@@ -984,3 +965,2 @@ return PinchRecognizer;

};
//# sourceMappingURL=Pinch.js.map

@@ -1008,3 +988,2 @@ var RotateRecognizer = (function (_super) {

};
//# sourceMappingURL=Rotate.js.map

@@ -1129,2 +1108,3 @@ var DEFAULT_OPTIONS = {

var _this = this;
event.preventDefault();
var inputs = inputManage(event);

@@ -1158,4 +1138,3 @@ if (undefined !== inputs) {

}());
//# sourceMappingURL=main.js.map
export default AnyTouch;

@@ -92,3 +92,2 @@ (function (global, factory) {

var INPUT_END = 'end';
//# sourceMappingURL=const.js.map

@@ -146,3 +145,2 @@ var EventBus = (function () {

}());
//# sourceMappingURL=EventBus.js.map

@@ -206,7 +204,12 @@ var round = Math.round;

};
//# sourceMappingURL=vector.js.map
var touchAdapter = (function (event) {
var pointers = event.touches;
var changedPointers = event.changedTouches;
var pointers = Array.from(event.touches).map(function (_a) {
var clientX = _a.clientX, clientY = _a.clientY;
return ({ clientX: clientX, clientY: clientY });
});
var changedPointers = Array.from(event.changedTouches).map(function (_a) {
var clientX = _a.clientX, clientY = _a.clientY;
return ({ clientX: clientX, clientY: clientY });
});
var inputStatus = event.type.replace('touch', '');

@@ -220,3 +223,2 @@ return {

});
//# sourceMappingURL=touch.js.map

@@ -258,3 +260,2 @@ var prevPointers = undefined;

});
//# sourceMappingURL=mouse.js.map

@@ -309,3 +310,2 @@ var centerX;

});
//# sourceMappingURL=create.js.map

@@ -346,3 +346,2 @@ var startInput;

});
//# sourceMappingURL=inputManage.js.map

@@ -362,4 +361,4 @@ var _prevInput;

if (COMPUTE_INTERVAL < deltaTime) {
velocityX = Math.abs(deltaX / deltaTime);
velocityY = Math.abs(deltaY / deltaTime);
velocityX = Math.round(Math.abs(deltaX / deltaTime) * 100) / 100;
velocityY = Math.round(Math.abs(deltaY / deltaTime) * 100) / 100;
direction = getDirection(deltaX, deltaY);

@@ -379,3 +378,2 @@ _prevVelocityX = velocityX;

});
//# sourceMappingURL=computeLast.js.map

@@ -410,3 +408,2 @@ var prevDisplacementX = 0;

}
//# sourceMappingURL=computeDistance.js.map

@@ -427,3 +424,2 @@ function computeDeltaXY (_a) {

}
//# sourceMappingURL=computeDeltaXY.js.map

@@ -434,3 +430,2 @@ var computeVector = (function (input) { return ({

}); });
//# sourceMappingURL=computeVector.js.map

@@ -443,3 +438,2 @@ function computeScale (_a) {

}
//# sourceMappingURL=computeScale.js.map

@@ -452,3 +446,2 @@ function computeAngle (_a) {

}
//# sourceMappingURL=computeAngle.js.map

@@ -466,3 +459,2 @@ var maxLength = 0;

});
//# sourceMappingURL=computeMaxLength.js.map

@@ -475,4 +467,2 @@ function compute (_a) {

var computed = {
pointers: [],
changedPointers: [],
pointerLength: input.pointerLength,

@@ -542,3 +532,2 @@ changedPointerLength: input.changedPointerLength,

}
//# sourceMappingURL=index.js.map

@@ -584,3 +573,2 @@ var computeTouchAction = (function (touchActions) {

});
//# sourceMappingURL=computeTouchAction.js.map

@@ -594,3 +582,2 @@ var STATUS_POSSIBLE = 'possible';

var STATUS_RECOGNIZED = 'recognized';
//# sourceMappingURL=recognizerStatus.js.map

@@ -718,3 +705,2 @@ var Recognizer = (function () {

};
//# sourceMappingURL=Base.js.map

@@ -785,3 +771,2 @@ var setTimeout = window.setTimeout, clearTimeout$1 = window.clearTimeout;

};
//# sourceMappingURL=Tap.js.map

@@ -839,3 +824,2 @@ var PressRecognizer = (function (_super) {

};
//# sourceMappingURL=Press.js.map

@@ -873,3 +857,2 @@ var getHV = (function (directions) {

});
//# sourceMappingURL=getHV.js.map

@@ -914,3 +897,2 @@ var PanRecognizer = (function (_super) {

};
//# sourceMappingURL=Pan.js.map

@@ -956,3 +938,2 @@ var SwipeRecognizer = (function (_super) {

};
//# sourceMappingURL=Swipe.js.map

@@ -980,3 +961,3 @@ var PinchRecognizer = (function (_super) {

var pointerLength = _a.pointerLength, scale = _a.scale;
return this.isValidPointerLength(pointerLength) && (this.options.threshold < Math.abs(scale - 1) || this.isRecognized);
return this.isValidPointerLength(pointerLength) && (this.options.threshold < Math.abs(scale) || this.isRecognized);
};

@@ -990,3 +971,2 @@ return PinchRecognizer;

};
//# sourceMappingURL=Pinch.js.map

@@ -1014,3 +994,2 @@ var RotateRecognizer = (function (_super) {

};
//# sourceMappingURL=Rotate.js.map

@@ -1135,2 +1114,3 @@ var DEFAULT_OPTIONS = {

var _this = this;
event.preventDefault();
var inputs = inputManage(event);

@@ -1164,3 +1144,2 @@ if (undefined !== inputs) {

}());
//# sourceMappingURL=main.js.map

@@ -1167,0 +1146,0 @@ return AnyTouch;

@@ -10,4 +10,4 @@ let log = console.log;

scale: 1,
x: 0,
y: 0,
x: window.innerWidth/2,
y: window.innerHeight/2,
centerX: 0,

@@ -29,5 +29,8 @@ centerY: 0,

})
const anyTouch = new AnyTouch(this.$refs.circle);
const pan = anyTouch.get('pan');
pan.set({ threshold: 0 });
const pinch = anyTouch.get('pinch');
pinch.set({ threshold: 1.4 });
anyTouch.add(tap2);

@@ -39,2 +42,7 @@ anyTouch.add(tap3);

tap2.requireFailure(tap3);
// this.$refs.circle.addEventListener('touchstart', ev=>{ev.preventDefault()})
// this.$refs.circle.addEventListener('touchmove', ev=>{ev.preventDefault()})
// this.$refs.circle.addEventListener('touchend', ev=>{ev.preventDefault()})
/**

@@ -44,6 +52,6 @@ * =========================== pan ===========================

anyTouch.on('input', e => {
this.message = e;
log(e, e.type);
});
// anyTouch.on('input', e => {
// this.message = e;
// log(e, e.type);
// });

@@ -66,3 +74,5 @@ anyTouch.on('panstart', e => {

anyTouch.on('pan', e => {
console.log(e.centerX, e.centerY);
this.centerX = e.centerX;
this.centerY = e.centerY;
// console.log(e)
log(e.direction);

@@ -72,3 +82,3 @@ if (e.nativeEvent.cancelable && 'down' === e.direction) {

}
// e.preventDefault();
e.preventDefault();
log(`%c ${e.type} `, 'background-color:#69c;color:#fff;');

@@ -75,0 +85,0 @@ this.message = e;

{
"name": "any-touch",
"version": "0.0.12",
"version": "0.0.13",
"description": "一个手势库",

@@ -12,4 +12,4 @@ "main": "dist/anyTouch.common.js",

"dev": "rimraf dist && rollup -c --watch",
"test": "jest"
"test": "jest",
"demo": "node ./script/demo.js"
},

@@ -28,2 +28,3 @@ "repository": {

"@types/jest": "^23.3.5",
"gh-pages": "^2.0.1",
"jest": "^23.6.0",

@@ -35,2 +36,3 @@ "rimraf": "^2.6.2",

"rollup-plugin-typescript": "^1.0.0",
"shelljs": "^0.8.3",
"ts-jest": "^23.10.4",

@@ -37,0 +39,0 @@ "tslib": "^1.9.3",

@@ -5,3 +5,4 @@ # any-touch [![NPM Version][npm-image]][npm-url] [![NPM Downloads][downloads-image]][downloads-url] [![codecov](https://codecov.io/gh/383514580/any-touch/branch/develop/graph/badge.svg)](https://codecov.io/gh/383514580/any-touch) [![CircleCI](https://circleci.com/gh/383514580/any-touch.svg?style=svg)](https://circleci.com/gh/383514580/any-touch)

[size-image]: https://img.shields.io/bundlephobia/minzip/any-touch.svg
[size-url]: https://bundlephobia.com/result?p=any-touch
[npm-image]: https://img.shields.io/npm/v/any-touch.svg

@@ -13,2 +14,5 @@ [npm-url]: https://npmjs.org/package/any-touch

## 演示
[查看](https://383514580.github.io/any-touch/example/)
## 安装

@@ -46,8 +50,1 @@

- [x] 手势互斥(requireFailure)
## 计划支持
- [ ] 识别input数据变形(transform)
- [ ] 自定义识别器(recgnizer)
- [ ] 停止继续识别(stop)
- [ ] 自定义任意触点,让鼠标支持rotate和pinch(addPointer)

@@ -30,4 +30,4 @@ // 返回最近一个时间段的计算结果

if (COMPUTE_INTERVAL < deltaTime) {
velocityX = Math.abs(deltaX / deltaTime);
velocityY = Math.abs(deltaY / deltaTime);
velocityX = Math.round(Math.abs(deltaX / deltaTime)*100)/100;
velocityY = Math.round(Math.abs(deltaY / deltaTime)*100)/100;
direction = getDirection(deltaX, deltaY);

@@ -34,0 +34,0 @@ // 存储状态

@@ -25,4 +25,4 @@

let computed = <Computed>{
pointers: [],
changedPointers: [],
// pointers: [],
// changedPointers: [],
pointerLength: input.pointerLength,

@@ -29,0 +29,0 @@ changedPointerLength: input.changedPointerLength,

@@ -32,3 +32,6 @@ // 简单判断是否手机设备

export const propY = 'clientY';
export const CLIENT_X = 'clientX';
export const CLIENT_Y = 'clientY';
// 识别器状态码

@@ -35,0 +38,0 @@ export const RECOGNIZER_STATUS_POSSIBLE = 1;

export default (event: TouchEvent): any => {
// const pointers = event.targetTouches;
const pointers = event.touches;
const changedPointers = event.changedTouches;
const pointers = Array.from(event.touches).map(({clientX,clientY})=>({clientX,clientY}));
const changedPointers = Array.from(event.changedTouches).map(({clientX,clientY})=>({clientX,clientY}));
const inputStatus = event.type.replace('touch', '');

@@ -6,0 +6,0 @@ return {

@@ -69,2 +69,3 @@ /**

options: Options;
/**

@@ -203,3 +204,3 @@ * @param {Element} el

handler(event: TouchEvent | MouseEvent): void {
// event.preventDefault();
event.preventDefault();
// 记录各个阶段的input

@@ -211,10 +212,2 @@ let inputs = inputManage(event);

this.recognizers.forEach(recognizer => {
// // 构造原生event
// recognizer.afterEmit((type: string, payload: { [propName: string]: any }) => {
// if (this.options.domEvents) {
// let event: any = new Event(type, {});
// event.computed = payload;
// this.el.dispatchEvent(event);
// }
// });
recognizer.recognize(computed);

@@ -221,0 +214,0 @@ this.eventBus.emit('input', { ...computed, type: 'input' });

@@ -53,3 +53,3 @@ /*

* 对emit进行封装
* @param type
* @param type
* @param payload

@@ -56,0 +56,0 @@ */

@@ -32,3 +32,4 @@ import { Computed } from '../interface';

// 如果缩放超过阈值, 或者已识别
return this.isValidPointerLength(pointerLength) && (this.options.threshold < Math.abs(scale - 1) || this.isRecognized);
// console.log({scale})
return this.isValidPointerLength(pointerLength) && (this.options.threshold < Math.abs(scale) || this.isRecognized);
};

@@ -35,0 +36,0 @@ };

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc