westures-core 1.2.1 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # Changelog
2
2
 
3
+ ## Unreleased
4
+
5
+ ## 1.3.1
6
+
7
+ - Add 'contextmenu' to CANCEL_EVENTS
8
+ - Changed docs deployment strategy
9
+
10
+ ## 1.3.0
11
+
12
+ - Introduce "headless" mode, which allows westures to be run in a server environment.
13
+
14
+ ## 1.2.0
15
+
16
+ - Switch to "parcel" from "parcel-bundler"
17
+ - Add a list of the PHASES to constants.js
18
+ - Provide Input.elapsedTime
19
+ - Provide Point2D.anglesTo()
20
+
3
21
  ## 1.1.0
4
22
 
5
23
  - Switch to using pointer events by default, combined with setting touch-action:
@@ -0,0 +1,121 @@
1
+ # Contributing to westures-core
2
+
3
+ Thanks for contributing to westures-core. Contributions to the gesture engine,
4
+ tests, documentation, and examples are welcome.
5
+
6
+ ## Development Setup
7
+
8
+ This project uses npm and is [tested in CI](./.github/workflows/node.js.yml) across a matrix of recent Node versions.
9
+
10
+ Install dependencies with:
11
+
12
+ ```sh
13
+ npm clean-install --ignore-scripts
14
+ ```
15
+
16
+ ## Common commands
17
+
18
+ Run the same checks used by CI before opening a pull request:
19
+
20
+ ```bash
21
+ npm run build
22
+ npm run lint
23
+ npm test
24
+ npm run test:coverage
25
+ ```
26
+
27
+ Additional useful commands:
28
+
29
+ ```bash
30
+ npm run build:debug
31
+ npm run lint:fix
32
+ ```
33
+
34
+ ## Development Workflow
35
+
36
+ - Keep changes focused and update tests when behavior changes.
37
+ - Update `CHANGELOG.md` for notable user-facing, maintenance, or security changes.
38
+ - Open a pull request using the repository's pull request template.
39
+
40
+ The source is in `src/`, tests are in `test/`, and `index.js` is the package
41
+ entry point. The `dist/` directory contains build output; regenerate it with
42
+ `npm run build` rather than editing it directly.
43
+
44
+ Follow the existing JavaScript style. ESLint enforces the project conventions,
45
+ including two-space indentation, single quotes, semicolons, and trailing commas
46
+ in multiline constructs.
47
+
48
+ ## Pull Requests
49
+
50
+ Before opening a pull request, run the build, linter, and relevant tests. Give
51
+ the pull request a clear description, explain any behavioral changes, and use
52
+ the provided pull request template to identify its type. Keep unrelated
53
+ formatting or refactoring changes out of the pull request.
54
+
55
+ For bugs, include a regression test when practical. For user-facing API or
56
+ behavior changes, update the README and JSDoc documentation as appropriate.
57
+
58
+ ## Publishing Documentation
59
+
60
+ Published documentation is generated with `npm run docs` and deployed from the
61
+ generated `docs/` directory by the
62
+ [documentation deployment workflow](./.github/workflows/deploy-documentation.yaml).
63
+
64
+ To publish the current `deploy-docs` branch, push your changes to that branch.
65
+ For a one-off deployment from another branch, run the **Build and Deploy**
66
+ workflow manually in GitHub Actions and select the branch to deploy. The
67
+ workflow installs dependencies, regenerates the documentation, and publishes
68
+ the resulting `docs/` directory, so do not commit generated documentation just
69
+ to deploy it.
70
+
71
+ ## Reporting Issues
72
+
73
+ When reporting a bug, include the Node.js version, browser and version when
74
+ relevant, a minimal reproduction, expected behavior, and actual behavior.
75
+
76
+ ## License
77
+
78
+ By contributing, you agree that your contributions are licensed under the
79
+ [MIT License](LICENSE).
80
+
81
+ ## Release process
82
+
83
+ For a package release, use the following workflow so you publish from the same
84
+ source commit you tag (with build artifacts generated locally), while only
85
+ pushing the tag after `npm publish` succeeds.
86
+
87
+ 1. Create a release preparation branch from `main`.
88
+ 2. Update `package.json`, `package-lock.json`, and `CHANGELOG.md` for the new version.
89
+ 3. Commit the release preparation changes and open a pull request.
90
+ 4. Merge the pull request into `main`.
91
+ 5. Check out the merged `main` commit locally.
92
+ 6. Verify the working tree is clean.
93
+ 7. Create the release tag locally for that commit, but do not push it yet.
94
+ 8. Check what will be published with `npm pack --dry-run`.
95
+ 9. Sanity-check the built bundle in `dist/index.js`.
96
+ 10. Publish the package to npm from the tagged commit.
97
+ 11. Push the tag.
98
+ 12. Create the GitHub release from the pushed tag.
99
+
100
+ Example commands for `1.3.1`:
101
+
102
+ ```bash
103
+ git switch --create release/1.3.1
104
+ git add package.json package-lock.json CHANGELOG.md
105
+ git commit --message "Prepare for 1.3.1 release"
106
+ gh pr create
107
+ # merge the PR, then sync your local main to the merged commit
108
+ git switch main
109
+ git pull --ff-only origin main
110
+ git status --short # must produce no output
111
+ git tag --annotate v1.3.1 --message "Release 1.3.1"
112
+ npm pack --dry-run # also builds, via 'prepare' script
113
+ ls -lh dist/index.js
114
+ npm publish
115
+ git push origin v1.3.1
116
+ gh release create v1.3.1 --title "v1.3.1"
117
+ ```
118
+
119
+ If you want GitHub release notes to match the changelog closely, paste the
120
+ `1.3.1` section of `CHANGELOG.md` into the release notes when creating the
121
+ release.
package/README.md CHANGED
@@ -1,20 +1,12 @@
1
1
  # westures-core
2
2
 
3
- [![Build Status](
4
- https://travis-ci.org/mvanderkamp/westures-core.svg?branch=master)
5
- ](https://travis-ci.org/mvanderkamp/westures-core)
6
- [![Coverage Status](
7
- https://coveralls.io/repos/github/mvanderkamp/westures-core/badge.svg?branch=master)
8
- ](https://coveralls.io/github/mvanderkamp/westures-core?branch=master)
9
- [![Maintainability](
10
- https://api.codeclimate.com/v1/badges/a5f4a4745352d6e2520c/maintainability)
11
- ](https://codeclimate.com/github/mvanderkamp/westures-core/maintainability)
12
-
13
- Westures is a robust n-pointer multitouch gesture detection library for
14
- JavaScript. This means that each gesture is be capable of working seamlessly as
15
- input points are added and removed, with no limit on the number of input points,
16
- and with each input point contributing to the gesture. It is also capable of
17
- working across a wide range of devices.
3
+ [![Node.js CI](https://github.com/mvanderkamp/westures-core/actions/workflows/node.js.yml/badge.svg)](https://github.com/mvanderkamp/westures-core/actions/workflows/node.js.yml)
4
+ [![Coverage Status](https://coveralls.io/repos/github/mvanderkamp/westures-core/badge.svg?branch=main)](https://coveralls.io/github/mvanderkamp/westures-core?branch=main)
5
+ [![Maintainability](https://api.codeclimate.com/v1/badges/a5f4a4745352d6e2520c/maintainability)](https://codeclimate.com/github/mvanderkamp/westures-core/maintainability)
6
+
7
+ Westures is an n-pointer gesture detection library for JavaScript. Gestures can
8
+ continue as input points are added and removed, with each active input point
9
+ available to the gesture.
18
10
 
19
11
  This module contains the core functionality of the Westures gesture library for
20
12
  JavaScript. It is intended for use as a lighter-weight module to use if you do
@@ -24,13 +16,10 @@ https://mvanderkamp.github.io/westures/) module.
24
16
  Visit this page for an example of the system in action: [Westures Example](
25
17
  https://mvanderkamp.github.io/westures-example/).
26
18
 
27
- Westures aims to achieve its goals without using any dependencies, yet maintain
28
- usability across the main modern browsers. Transpilation may be necessary for
29
- this last point to be achieved, as the library is written using many of the
30
- newer features of the JavaScript language. A transpiled bundle is provided, but
31
- the browser target list is arbitrary and likely includes some bloat. In most
32
- cases you will be better off performing bundling, transpilation, and
33
- minification yourself.
19
+ Westures has no runtime dependencies. It uses Pointer Events when available and
20
+ otherwise listens to mouse and touch events. The package's CommonJS entry point
21
+ is a bundled build; applications that target older browsers may need to
22
+ transpile it as part of their own build pipeline.
34
23
 
35
24
  Westures is a fork of [ZingTouch](https://github.com/zingchart/zingtouch).
36
25
 
@@ -46,6 +35,10 @@ const region = new wes.Region();
46
35
 
47
36
  // Define a Gesture subclass
48
37
  class Follow extends wes.Gesture {
38
+ constructor(element, handler, options) {
39
+ super('follow', element, handler, options);
40
+ }
41
+
49
42
  move(state) {
50
43
  return state.centroid; // Reports the {x, y} of the average input position
51
44
  }
@@ -68,11 +61,13 @@ region.addGesture(follow);
68
61
 
69
62
  - [Features](#features)
70
63
  - [Overview](#overview)
64
+ - [Installation](#installation)
71
65
  - [Basic Usage](#basic-usage)
72
66
  - [Implementing Custom Gestures](#implementing-custom-gestures)
73
67
  - [Nomenclature and Origins](#nomenclature-and-origins)
74
68
  - [Changes](#changes)
75
69
  - [Issues](#issues)
70
+ - [Contributing](#contributing)
76
71
  - [Links](#links)
77
72
 
78
73
  ## Features
@@ -104,17 +99,26 @@ Region | Listen for user input events and respond appropriately
104
99
  Smoothable | Datatype which provides inertial smoothing capabilities
105
100
  State | Track inputs within a Region
106
101
 
107
- Additionally, two support files are defined:
102
+ The package also exports its constants and utility functions, including
103
+ `PHASES`, `STATE_KEYS`, `angularDifference`, and `setFilter`.
108
104
 
109
- Name | Description
110
- --------- | -----------
111
- constants | Constant values used throughout the engine
112
- utils | Helpful utility functions
105
+ ## Installation
113
106
 
114
- Here is a graph to help you understand the relationships between these classes:
107
+ ```sh
108
+ npm install westures-core
109
+ ```
115
110
 
116
- ![Graph of westures-core module](
117
- https://raw.githubusercontent.com/mvanderkamp/westures-core/master/arkit.svg?sanitize=true)
111
+ The package uses CommonJS:
112
+
113
+ ```javascript
114
+ const wes = require('westures-core');
115
+ ```
116
+
117
+ `Region` requires a browser environment by default. For server-side or test
118
+ use, create it in headless mode and provide events directly to
119
+ `arbitrate(event)`, `cancel(event)`, and `handleKeyboardEvent(event)`. Events
120
+ passed to a headless region must include a `target` so the region can select
121
+ the gesture to evaluate.
118
122
 
119
123
  ## Basic Usage
120
124
 
@@ -123,12 +127,6 @@ https://raw.githubusercontent.com/mvanderkamp/westures-core/master/arkit.svg?san
123
127
  - [Instantiating a Gesture](#instantiating-a-gesture)
124
128
  - [Adding a Gesture to a Region](#adding-a-gesture-to-a-region)
125
129
 
126
- ### Importing the module
127
-
128
- ```javascript
129
- const wes = require('westures-core');
130
- ```
131
-
132
130
  ### Declaring a Region
133
131
 
134
132
  First, decide what region should listen for events. This could be the
@@ -161,6 +159,10 @@ input points. Note that the returned value must be an Object!
161
159
  ```javascript
162
160
  // Define a Gesture subclass
163
161
  class Follow extends wes.Gesture {
162
+ constructor(element, handler, options) {
163
+ super('follow', element, handler, options);
164
+ }
165
+
164
166
  move(state) {
165
167
  return state.centroid;
166
168
  }
@@ -184,7 +186,7 @@ const element = document.querySelector('#follow');
184
186
  ```
185
187
 
186
188
  And we also need a handler. This function will be called whenever a gesture hook
187
- returns non-null data. For Follow, this is just the move phase, but the handler
189
+ returns an object. For Follow, this is just the move phase, but the handler
188
190
  doesn't need to know that. The data returned by the hook will be available
189
191
  inside the handler.
190
192
 
@@ -238,18 +240,19 @@ const { Gesture } = require('westures-core');
238
240
  const TIMEOUT = 100;
239
241
 
240
242
  class Tap extends Gesture {
241
- constructor() {
242
- super('tap');
243
+ constructor(element, handler, options) {
244
+ super('tap', element, handler, options);
243
245
  this.startTime = null;
244
246
  }
245
247
 
246
- start(state) {
248
+ start() {
247
249
  this.startTime = Date.now();
248
250
  }
249
251
 
250
252
  end(state) {
251
253
  if (Date.now() - this.startTime <= TIMEOUT) {
252
- return state.getInputsInPhase('end')[0].current.point;
254
+ const point = state.getInputsInPhase('end')[0].current.point;
255
+ return { centroid: point, ...point };
253
256
  }
254
257
  return null;
255
258
  }
@@ -260,7 +263,7 @@ There are problems with this example, and it should probably not be used as an
260
263
  actual Tap gesture, it is merely to illustrate the basic idea.
261
264
 
262
265
  The default hooks for all Gestures simply return null. Data will only be
263
- forwarded to bound handlers when a non-null value is returned by a hook.
266
+ forwarded to bound handlers when an object is returned by a hook.
264
267
  Returned values should be packed inside an object. For example, instead of just
265
268
  `return 42;`, a custom hook should do `return { value: 42 };`
266
269
 
@@ -280,7 +283,7 @@ called. Those properties are:
280
283
 
281
284
  Name | Type | Value
282
285
  -------- | -------- | -----
283
- centroid | Point2D | The centroid of the input points.
286
+ centroid | Point2D \| null | The centroid of the active input points.
284
287
  event | Event | The input event which caused the gesture to be recognized
285
288
  phase | String | `'start'`, `'move'`, `'end'`, or `'cancel'`
286
289
  type | String | The name of the gesture as specified by its designer.
@@ -290,9 +293,21 @@ If data properties returned by a hook have a name collision with one of these
290
293
  properties, the value from the hook gets precedent and the default is
291
294
  overwritten.
292
295
 
296
+ ### Ending Inputs
297
+
298
+ `State.active`, `State.activePoints`, and the default `centroid` represent only
299
+ active inputs. During an `end` hook, this means that inputs ending in the
300
+ current event are excluded; when the final input ends, the default `centroid`
301
+ is `null`.
302
+
303
+ Gestures based on released inputs should read them with
304
+ `state.getInputsInPhase('end')`, retain any data they need, and return their
305
+ own result. A tap gesture, for example, can compute its own centroid from the
306
+ ending inputs and return it as `centroid`, as in the example above.
307
+
293
308
  ## Nomenclature and Origins
294
309
 
295
- In my last year of univerisity, I was working on an API for building
310
+ In my last year of university, I was working on an API for building
296
311
  multi-device interfaces called "WAMS" (Workspaces Across Multiple Surfaces),
297
312
  which included the goal of supporting multi-device gestures.
298
313
 
@@ -307,13 +322,18 @@ The name "westures" is a mash-up of "WAMS" and "gestures".
307
322
  ## Changes
308
323
 
309
324
  See the [changelog](
310
- https://github.com/mvanderkamp/westures-core/blob/master/CHANGELOG.md) for the
325
+ https://github.com/mvanderkamp/westures-core/blob/main/CHANGELOG.md) for the
311
326
  most recent updates.
312
327
 
313
328
  ## Issues
314
329
 
315
330
  If you find any issues, please let me know!
316
331
 
332
+ ## Contributing
333
+
334
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for the development workflow and pull
335
+ request guidelines.
336
+
317
337
  ## Links
318
338
 
319
339
  ### westures
@@ -327,4 +347,3 @@ If you find any issues, please let me know!
327
347
  - [npm](https://www.npmjs.com/package/westures-core)
328
348
  - [github](https://github.com/mvanderkamp/westures-core)
329
349
  - [documentation](https://mvanderkamp.github.io/westures-core/)
330
-