{"_id":"@3land/vue3-touch-events","name":"@3land/vue3-touch-events","dist-tags":{"latest":"0.0.2"},"versions":{"0.0.2":{"name":"@3land/vue3-touch-events","version":"0.0.2","description":"Simple touch events support for vue.js 3","main":"index.js","types":"index.d.ts","type":"module","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"repository":{"type":"git","url":"git+https://github.com/robinrodricks/vue3-touch-events.git"},"keywords":["vue","touch","tap","swipe","longtap"],"author":{"name":"Robin Rodricks, Xavier Julien, Jerry Bendy"},"license":"MIT","bugs":{"url":"https://github.com/robinrodricks/vue3-touch-events/issues"},"homepage":"https://github.com/robinrodricks/vue3-touch-events#readme","devDependencies":{},"gitHead":"367e7de6ee5c96b75978ad27c2edbc7c3d5d7ca9","_id":"@3land/vue3-touch-events@0.0.2","_nodeVersion":"16.15.0","_npmVersion":"8.5.5","dist":{"integrity":"sha512-J0VYCcXCs4/gC91PAooUCAp2hKkRm4H/yCa7CLYgryyPSbpDATNjaHdWyOLJePOg5eySgKxi4hBgRuGZwd1T3w==","shasum":"4c4aa5ba527bf371b7df08f82244d31da0b983e5","tarball":"https://registry.npmjs.org/@3land/vue3-touch-events/-/vue3-touch-events-0.0.2.tgz","fileCount":6,"unpackedSize":32741,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCr+bJtUO4wjmCrp8iedCpuvMyFD9AXUYdNsnFO5byunQIhAPnetftP8h/OMsZ15kAYR9QQFjj4FCT0gf0ke/jtUOer"}]},"_npmUser":{"name":"3land","email":"dev@3.land"},"directories":{},"maintainers":[{"name":"3land","email":"dev@3.land"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/vue3-touch-events_0.0.2_1725990372612_0.6587739502700345"},"_hasShrinkwrap":false}},"time":{"created":"2024-09-10T17:46:12.498Z","0.0.2":"2024-09-10T17:46:12.827Z","modified":"2024-09-10T17:46:13.094Z"},"maintainers":[{"name":"3land","email":"dev@3.land"}],"description":"Simple touch events support for vue.js 3","homepage":"https://github.com/robinrodricks/vue3-touch-events#readme","keywords":["vue","touch","tap","swipe","longtap"],"repository":{"type":"git","url":"git+https://github.com/robinrodricks/vue3-touch-events.git"},"author":{"name":"Robin Rodricks, Xavier Julien, Jerry Bendy"},"bugs":{"url":"https://github.com/robinrodricks/vue3-touch-events/issues"},"license":"MIT","readme":"# vue3-touch-events [![](https://img.shields.io/npm/v/vue3-touch-events.svg)](https://www.npmjs.com/package/vue3-touch-events) [![](https://img.shields.io/npm/dt/vue3-touch-events)](https://www.npmjs.com/package/vue3-touch-events)\n\n**Enable tap, swipe, touch, hold, mouse down, mouse up events on any HTML DOM Element in vue.js 3.x.**\n\nThe easiest way to make your interactive vue.js content mobile-friendly. When you add `v-touch` events to your elements, it works on desktop and mobile using a fully declarative syntax. Unlike other libraries, you do not need to add any special code to your components to make this work. You simply have to register the library globally and it enables new events throughout your application.\n\n### Note: Press the play button to the right of the image!\n\n![Events](https://github.com/robinrodricks/vue3-touch-events/raw/master/images/animation.gif)\n\nReleased under the permissive MIT License.\n\nFeatures:\n\n- Declarative syntax for common touch events, such as `tap`, `swipe`, `hold`, `drag` and [more](#Events)\n- All events support desktop (mouse) and mobile devices (touch screen) with the same syntax\n- Automatically add styling on hover and tap using `v-touch-class` directive\n- Bind multiple touch events on one DOM element\n- Customizable events with native-like events handler\n- Throttling for `drag` and `rollover` events to prevent crashing your application\n- Global configuration that applies to all events in the application\n- Ability to override global configuration on any element using `v-touch-options` directive\n- Bindings for TypeScript included and also works in pure-JavaScript projects\n\nVersion:\n\n> Note: This library is for **vue.js 3.x** only. For **vue.js 2.x** see the [older library](https://github.com/jerrybendy/vue-touch-events).\n\nCredits:\n\n- All credits go to Jerry Bendy for creating the original project [vue2-touch-events](https://github.com/jerrybendy/vue-touch-events)\n- Special thanks to Xavier Julien for creating the [Vue 3.x port](https://github.com/XjulI1/vue-touch-events/tree/migrate-to-vuejs-3)\n\n\n\n\n## Installation\n\nTo install with npm:\n\n```shell\nnpm install vue3-touch-events\n```\n\nTo install with yarn:\n\n```shell\nyarn add vue3-touch-events\n```\n\n### TypeScript\n\nYou need to register this plugin with vue.js in your main application file:\n\n```js\nimport Vue from \"vue\";\nimport Vue3TouchEvents from \"vue3-touch-events\";\n\nVue.use(Vue3TouchEvents);\n```\n\n### JavaScript\n\nYou need to include the [UMD script](https://raw.githubusercontent.com/robinrodricks/vue3-touch-events/master/index.js) of this plugin and you do not need to register this plugin with vue.js.\n\n```html\n<script src=\"libs/vue.js\"></script>\n<script src=\"libs/vue3-touch-events.js\"></script>\n```\n\n\n\n## Examples\n\nIn your `.vue` component files, use the `v-touch` directive add touch events to elements.\n\nSpecify the event using the first argument, for example `v-touch:tap` or `v-touch:swipe`.\n\n```html\n<!-- bind a tap event -->\n<span v-touch:tap=\"touchHandler\">Tap Me</span>\n\n<!-- tap is the default event, you can omit it -->\n<span v-touch=\"touchHandler\">Tap Me</span>\n\n<!-- bind the swipe event, no matter direction -->\n<span v-touch:swipe=\"swipeHandler\">Swipe Here</span>\n\n<!-- only when swipe left can trigger the callback -->\n<span v-touch:swipe.left=\"swipeHandler\">Swipe Left Here</span>\n\n<!-- bind a long tap event -->\n<span v-touch:longtap=\"longtapHandler\">Long Tap Event</span>\n\n<!-- bind a start and end event -->\n<span v-touch:press=\"startHandler\" v-touch:release=\"endHandler\">Press and Release Events</span>\n\n<!-- bind a move and moving event -->\n<span v-touch:drag.once=\"movedHandler\">Triggered once when starting to move and tapTolerance is exceeded</span>\n<span v-touch:drag=\"movingHandler\">Continuously triggered while dragging</span>\n\n<!-- touch and hold -->\n<span v-touch:hold=\"touchHoldHandler\">Touch and hold on the screen for a while</span>\n\n<!-- you can even mix multiple events -->\n<span v-touch:tap=\"tapHandler\" v-touch:longtap=\"longtapHandler\" v-touch:swipe.left=\"swipeLeftHandler\" v-touch:press=\"startHandler\" v-touch:release=\"endHandler\" v-touch:swipe.right=\"swipeRightHandler\">Mix Multiple Events</span>\n\n<!-- using different options for specified element -->\n<span v-touch:tap=\"tapHandler\" v-touch-options=\"{touchClass: 'active', swipeTolerance: 80, touchHoldTolerance: 300}\">Different options</span>\n\n<!-- customize touch effects by CSS class -->\n<span v-touch:tap=\"tapHandler\" v-touch-class=\"active\">Customize touch class</span>\n<!-- or -->\n<span v-touch:tap=\"tapHandler\" v-touch-options=\"{touchClass: 'active'}\">Customize touch class</span>\n```\n\n\n\n## Usage\n\n### Simple callback\n\nIf you simply want to execute a callback function on a `v-touch` event, use this pattern:\n\n```html\n<div v-touch:tap=\"onTapItem\">Button</div>\n```\n\n```js\nmethods: {\n\tonTapItem(mouseEvent) { // you can remove the `mouseEvent` argument\n\t\tconsole.log(\"Tapped!\");\n\t},\n},\n```\n\n### Passing parameters to the event handler\n\nIf you want to add extra parameters to your `v-touch` event handler, you need to return a delegate in the event handler. You can pass as many attributes as you need.\n\n```html\n<div v-for=\"(item, i) in items\">\n\t<div v-touch:swipe=\"onSwipeItem(item, i)\">Button</div>\n</div>\n```\n\n```js\nmethods: {\n\tonSwipeItem(item, i) {\n\t\treturn function (direction, mouseEvent) {\n\t\t\tconsole.log(\"Swiped item \", i, \": \", item, \" in direction \", direction);\n\t\t};\n\t},\n},\n```\n\n\n\n\n## Events\n\nList of all supported events are given below.\n\n**All events work on Desktop & Mobile devices.**\n\n| <div style=\"width:170px\">Event</div>                      | Behaviour                                                |\n| ---------------------------- | ----------------------------------------------------- |\n|  `v-touch`<br> `v-touch:tap` | **Desktop:** Triggered when the user clicks on the element (press and release). <br> **Mobile:** Triggered when the user taps on the element (tap and release)      |\n| `v-touch:longtap` | **Desktop:** Triggered when the user holds on the element for `longTapTimeInterval` MS and then releases it (press and release). <br> **Mobile:** Triggered when the user taps and holds on the element for `longTapTimeInterval` MS and then releases it (tap and release)      |\n| `v-touch:swipe`              | Triggered when the user drags on the element (swipe). <br> It will detect the direction of the swipe and send it to your callback. <br> First argument of the callback must be `direction` attribute, which can be `left`, `right`, `top` or `bottom`. <br> Example callback: `onSwipe(direction){ ... }` |\n| `v-touch:swipe.left` <br>`v-touch:swipe.right` <br>`v-touch:swipe.top` <br>`v-touch:swipe.bottom` <br> | Triggered when the user drags on the element in a specific direction (directional swipe).\n| `v-touch:hold`              | Triggered when the user holds the mouse button down for `touchHoldTolerance` MS while over the element (press and hold). <br> This will be triggered before your finger is released, similar to what native mobile apps do.    |\n| `v-touch:press`              | **Desktop:** Triggered when the user presses the element (mouse down). <br> **Mobile:** Triggered when the user taps the element without releasing.    |\n| `v-touch:drag.once`              | Triggered when the user presses and drags the element. <br> Only fired once, the moment the user first drags on the element.   |\n| `v-touch:drag`             | Triggered when the user presses and drags the element. <br> Fired every time the mouse moves while dragging the element.  <br> This event is throttled to prevent too many events per second. <br>  This event will fire every `dragFrequency` MS.   |\n| `v-touch:release`                | **Desktop:** Triggered when the user releases the element (mouse up). <br> **Mobile:** Triggered when the user taps and releases the element.  |\n| `v-touch:rollover`                | **Desktop only:** Triggered when the user moves his mouse over the element. <br> This event is throttled to prevent too many events per second. <br> This event will fire every `rollOverFrequency` MS.  |\n\n\n\n### Migration from Vue 2.x\n\nSome events have been renamed from the vue 2.x version of this library, in order to expose a cleaner, more consistant and more descriptive naming scheme.\n\n| Old event name               | New event name      |\n| ---------------------------- | ------------------- |\n| `v-touch:touchhold`          | `v-touch:hold`      |\n| `v-touch:start`              | `v-touch:press`     |\n| `v-touch:end`                | `v-touch:release`   |\n| `v-touch:moved`              | `v-touch:drag.once` |\n| `v-touch:moving`             | `v-touch:drag`      |\n\n\n\n### System events\n\nThese are the default interactivity events supported by vue.js 3.x.\n\n* You do not need to install this library to use them.\n* They are always available for your usage alongside this library.\n* The system default `mousemove` event is similar to `v-touch:rollover`, however the system event is not throttled and it will trigger hundreds of times per second, potentially crashing your application if any logic is performed in the event handler\n\n**[Desktop devices](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent):**\n- `v-on:click` - Triggered when the user presses and releases the element.\n- `v-on:mousedown` - Triggered when the user presses the element.\n- `v-on:mousemove` - Triggered when the user moves the mouse over the element.\n- `v-on:mouseup` - Triggered when the user presses and releases the element.\n- `v-on:mouseenter` - Triggered when the user moves his mouse into the element.\n- `v-on:mouseleave` - Triggered when the user moves his mouse away from the element.\n\n**[Mobile devices](https://developer.mozilla.org/en-US/docs/Web/API/Touch_events):**\n- `v-on:touchstart` - Triggered when the user presses the element.\n- `v-on:touchmove` - Triggered when the user presses and drags over the element.\n- `v-on:touchcancel` - Triggered when the user presses the element, and releases outside the element, thereby cancelling his tap.\n- `v-on:touchend` - Triggered when the user taps the element (press and release).\n\n\n\n## Options\n\nThese additional directives can be added to each element.\n\n### v-touch-options\n\n`v-touch-options` directive allows you set a different configuration for a specified component. It will override global configurations.\n\n### v-touch-class\n\n`v-touch-class` directive allows you automatically add a class when the element is rolled over (desktop) or tapped (mobile). It overrides the class specified in the global config option `touchClass`.\n\n- By default the `touchClass` is added when the element is pressed (`mousedown`), and removed when the element is released (`mouseup`).\n- If desktop events are enabled (`disableClick: false`), then the `touchClass` is added on roll over (`mouseenter`) and roll out (`mouseleave`) as well.\n- You can use this instead of `:active` and `:hover` pseudo classes, as it works on both desktop and mobile\n\nBehaviour:\n\n<table>\n\t<tr>\n\t\t<th>Device</th>\n\t\t<th>Event name</th>\n\t\t<th>Effect</th>\n\t\t<th>Condition</th>\n\t</tr>\n\t<tr>\n\t\t<td rowspan=\"2\">Desktop only</td>\n\t\t<td>Mouse enter (roll over)</td>\n\t\t<td>`touchClass` added</td>\n\t\t<td>desktop events must be enabled</td>\n\t</tr>\n\t<tr>\n\t\t<td>Mouse leave (roll out)</td>\n\t\t<td>`touchClass` removed</td>\n\t\t<td>desktop events must be enabled</td>\n\t</tr>\n\t<tr>\n\t\t<td rowspan=\"2\">Mobile only</td>\n\t\t<td>Mouse down (press)</td>\n\t\t<td>`touchClass` added</td>\n\t\t<td></td>\n\t</tr>\n\t<tr>\n\t\t<td>Mouse up (release)</td>\n\t\t<td>`touchClass` removed</td>\n\t\t<td></td>\n\t</tr>\n</table>\n\nFor example:\n\n```html\n<span v-touch:tap=\"touchHandler\" v-touch-class=\"'active'\">Tap Me</span>\n```\n\nNow, when you press the element, it will add an extra `active` class automatically, and when you release the element the class will be removed.\n\nSo that you can use this feature to instead of `:active` and `:hover` pseudo class, for a better user experience.\n\n```css\n/* before */\nspan:active,\nspan:hover {\n\tbackground: green;\n}\n\n/* now, you can write like this */\nspan.active {\n\tbackground: green;\n}\n```\n\n## Global configuration\n\n```js\nVue.use(Vue3TouchEvents, {\n\tdisableClick: false, ...\n});\n```\n\n- `disableClick` - Whether to disable desktop events. **Default:** `false`.\n\n  Keep the default value or `false` if your application is used on desktop and mobile devices.\n\n  If your application is only for mobile use, set this to `true` to get a better user experience, because it can resolve some touch pass-through issues encountered on mobile devices.\n\n- `touchClass` - Which CSS class to add while an element is rolled over (desktop) or tapped (mobile). **Default:** `''`\n\n  This is a global config, and you can use `v-touch-class` directive to override this setting for a single element.\n\n- `tapTolerance` in pixels - How many pixels the user must drag on the element for it to register as a `tap` event. **Default:** `10` pixels.\n\n- `touchHoldTolerance` in milliseconds - The timeout for a `hold` event. **Default:**  `400` MS\n\n- `swipeTolerance` in pixels - How many pixels the user must drag on the element for it to register as a `swipe` event. **Default:**  `30` pixels.\n\n- `longTapTimeInterval` in milliseconds - The minimum time interval to detect whether long tap event effective or not.  **Default:**  `400` MS.\n\n- `dragFrequency` in milliseconds - How often should `drag` events be fired.  **Default:**  `100` MS (10 times a second).\n\n- `rollOverFrequency` in milliseconds - How often should `rollover` events be fired.  **Default:**  `100` MS (10 times a second).\n\n","readmeFilename":"README.md"}