Socket
Socket
Sign inDemoInstall

drag-event-service

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

drag-event-service - npm Package Compare versions

Comparing version 1.1.10 to 2.0.0

dist/index.cjs.js

26

package.json
{
"name": "drag-event-service",
"version": "1.1.10",
"version": "2.0.0",
"description": "",
"main": "dist/drag-event-service.cjs.js",
"module": "dist/drag-event-service.esm.js",
"types": "types/index.d.ts",
"main": "dist/index.cjs.js",
"module": "dist/index.esm.js",
"types": "dist/index.d.ts",
"jsdelivr": "dist/index.iife.js",
"unpkg": "dist/index.iife.js",
"files": [
"dist",
"types"
"src"
],
"scripts": {
"build": "rollup -c scripts/build.js & node scripts/build.js --report",
"watch-lib": "rollup -c scripts/build.js --watch"
"build": "rogo",
"watch": "rogo -w"
},
"author": "phphe <phphe@outlook.com> (https://github.com/phphe)",
"unpkg": "dist/drag-event-service.js",
"bugs": {

@@ -26,9 +27,10 @@ "url": "https://github.com/phphe/drag-event-service/issues"

"devDependencies": {
"@rollup-use/core": "^0"
"rogo": "^3.1.4",
"typescript": "^4"
},
"dependencies": {
"@babel/runtime": "^7.7.7",
"helper-js": "^2.0.0"
"helper-js": "^3.0.0",
"@babel/runtime": "^7.7.7"
},
"license": "MIT"
}
}
# drag-event-service
Listen both mouse and touch event. With Typescript definition files. Support Typescript.
同时监听鼠标和触摸事件. 支持Typescript.
同时监听鼠标和触摸事件. 支持 Typescript.
```js
// mapping
const events = {
start: ['mousedown', 'touchstart'],
move: ['mousemove', 'touchmove'],
end: ['mouseup', 'touchend'],
}
start: ["mousedown", "touchstart"],
move: ["mousemove", "touchmove"],
end: ["mouseup", "touchend"],
};
```
## install
```sh
npm install drag-event-service --save
```
## usage & api
```js
import DragEventService from 'drag-event-service'
DragEventService.on(el, name, handler, {args, mouseArgs, touchArgs})
DragEventService.off(el, name, handler, {args, mouseArgs, touchArgs})
import DragEventService from "drag-event-service";
DragEventService.on(el, name, handler, { args, mouseArgs, touchArgs });
DragEventService.off(el, name, handler, { args, mouseArgs, touchArgs });
```
* args, mouseArgs and touchArgs should be Array
* The args will pass to addEventListener.
* mouseArgs will pass to mouse event.
* touchArgs will pass to touch event.
* handler(event, currentPosition). The second argument of handler is current position({x, y, pageX, pageY, clientX, clientY, screenX, screenY}). x and y is pageX and pageY.
- args, mouseArgs and touchArgs should be Array
- The args will pass to addEventListener.
- mouseArgs will pass to mouse event.
- touchArgs will pass to touch event.
- handler(event, currentPosition). The second argument of handler is current position({x, y, pageX, pageY, clientX, clientY, screenX, screenY}). x and y is pageX and pageY.
## example
```js

@@ -40,32 +48,1 @@ // 1

```
## Track mouse or touch position globally
全局跟踪鼠标或触摸位置
### Usage
```js
import {trackMouseOrTouchPosition} from 'drag-event-service'
const {info, start, stop} = trackMouseOrTouchPosition(options)
start() // call start to start tracking.
```
### Types
```ts
// options
export interface Options_trackMouseOrTouchPosition{
onMove: () => void
onStart: () => void
onEnd: () => void
}
// info
export interface TrackedInfo{
position: EventPosition
event: MouseOrTouchEvent
eventType: EventType
isTouch: boolean
started: boolean
startEvent?: MouseOrTouchEvent
endEvent?: MouseOrTouchEvent
}
//
start: () => void
stop: () => void
```
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