├── .gitignore
├── src
├── index.ts
├── shared.ts
├── tap.ts
└── swipe.ts
├── CHANGELOG.md
├── rollup.config.js
├── scripts
└── move-type-declarations.js
├── tsconfig.json
├── package.json
├── LICENSE
└── README.md
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | node_modules
3 | *.d.ts
4 | dist
--------------------------------------------------------------------------------
/src/index.ts:
--------------------------------------------------------------------------------
1 | export * from './tap';
2 | export * from './swipe';
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # TODO changelog
2 |
3 | ## 1.0.0
4 |
5 | * First release
--------------------------------------------------------------------------------
/src/shared.ts:
--------------------------------------------------------------------------------
1 | export function add(node: EventTarget, event: string, handler: EventListener) {
2 | node.addEventListener(event, handler);
3 | return () => node.removeEventListener(event, handler);
4 | }
--------------------------------------------------------------------------------
/rollup.config.js:
--------------------------------------------------------------------------------
1 | import sucrase from 'rollup-plugin-sucrase';
2 | import pkg from './package.json';
3 |
4 | export default {
5 | input: 'src/index.ts',
6 | output: [
7 | { file: pkg.main, format: 'cjs' },
8 | { file: pkg.module, format: 'esm' }
9 | ],
10 | plugins: [
11 | sucrase({
12 | transforms: ['typescript']
13 | })
14 | ]
15 | };
--------------------------------------------------------------------------------
/scripts/move-type-declarations.js:
--------------------------------------------------------------------------------
1 | const sander = require('sander');
2 | const glob = require('tiny-glob/sync');
3 |
4 | for (const file of glob('src/**/*.js')) {
5 | sander.unlinkSync(file);
6 | }
7 |
8 | sander.rimrafSync('types');
9 | for (const file of glob('src/**/*.d.ts')) {
10 | sander.renameSync(file).to(file.replace(/^src/, 'types'));
11 | }
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "noImplicitAny": true,
4 | "diagnostics": true,
5 | "noImplicitThis": true,
6 | "noEmitOnError": true,
7 | "lib": ["es5", "es6", "dom"]
8 | },
9 | "target": "ES5",
10 | "module": "ES6",
11 | "include": [
12 | "src"
13 | ],
14 | "exclude": [
15 | "node_modules"
16 | ]
17 | }
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@sveltejs/gestures",
3 | "description": "Svelte actions for cross-platform gesture detection",
4 | "version": "0.0.1",
5 | "repository": "sveltejs/gestures",
6 | "main": "dist/gestures.js",
7 | "module": "dist/gestures.mjs",
8 | "types": "types/index.d.ts",
9 | "files": [
10 | "dist",
11 | "types"
12 | ],
13 | "devDependencies": {
14 | "@types/node": "^10.9.4",
15 | "rollup": "^0.65.2",
16 | "rollup-plugin-sucrase": "^2.1.0",
17 | "sander": "^0.6.0",
18 | "tiny-glob": "^0.2.6",
19 | "typescript": "^3.3.3333"
20 | },
21 | "scripts": {
22 | "build-declarations": "tsc -d && node scripts/move-type-declarations.js",
23 | "build": "npm run build-declarations && rollup -c",
24 | "dev": "rollup -cw",
25 | "test": "echo \"no tests. open the demos in a browser instead\"",
26 | "prepublishOnly": "npm run build"
27 | },
28 | "license": "LIL"
29 | }
30 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2019 Rich Harris
2 |
3 | Permission is hereby granted by the authors of this software, to any person, to use the software for any purpose, free of charge, including the rights to run, read, copy, change, distribute and sell it, and including usage rights to any patents the authors may hold on it, subject to the following conditions:
4 |
5 | This license, or a link to its text, must be included with all copies of the software and any derivative works.
6 |
7 | Any modification to the software submitted to the authors may be incorporated into the software under the terms of this license.
8 |
9 | The software is provided "as is", without warranty of any kind, including but not limited to the warranties of title, fitness, merchantability and non-infringement. The authors have no obligation to provide support or updates for the software, and may not be held liable for any damages, claims or other liability arising from its use.
10 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # @sveltejs/gestures
2 |
3 | A (work-in-progress) collection of gesture recognisers for Svelte components.
4 |
5 | Each recogniser is implemented as an action that emits custom events. Pointer events are used where possible, falling back to mouse and touch events.
6 |
7 |
8 | ## tap ([demo](https://v3.svelte.technology/repl?version=3.0.0-beta.10&gist=ffbdb659f2c52c8510bec42af3ffb0d1))
9 |
10 | This action fires a `tap` event when the user taps on an element with either a mouse or a finger (or other pointing device). If the pointer is down for more than 300ms, it doesn't count, unlike with `click` events.
11 |
12 | Pressing the spacebar on a focused button will also fire a `tap` event. Taps on disabled form elements are disregarded.
13 |
14 | The `event.detail` object has `x` and `y` properties corresponding to `clientX` and `clientY`. If the original event was a spacebar keypress, both are `null`.
15 |
16 | ```html
17 |
24 |
25 |
28 | ```
29 |
30 | ## swipe
31 |
32 | This action include three events `swipe`, `swipestart` and `swipeend`. The `swipestart` event
33 | will fire when the pointer is down and the `swipeend` event is fired when the pointer is up, if after 300ms the pointermove event is not fired, the `swipe` and `swipeend` events are canceled.
34 |
35 | The `swipe` event will be fired if a minimal `TRESHOLD` distance is accomplished. This event will include in `event.detail` a `direction` string, which can be one of `left`, `right`, `up` and `down`, and a `distance` number.
36 |
37 | ```html
38 |
47 |
48 |
53 |
54 |
active = true}
58 | on:swipeend={e => active = false}
59 | on:swipe={handler}
60 | >