inpt 0.0.0
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/LICENSE.md +21 -0
- package/README.md +89 -0
- package/dist/index.js +1182 -0
- package/dist/types/core/BoundAction.d.ts +8 -0
- package/dist/types/core/Disposable.d.ts +11 -0
- package/dist/types/core/Input.d.ts +46 -0
- package/dist/types/core/InputManager.d.ts +179 -0
- package/dist/types/core/InputManagerEventMap.d.ts +26 -0
- package/dist/types/core/KeyCode.d.ts +7 -0
- package/dist/types/core/Modifier.d.ts +6 -0
- package/dist/types/core/PointerButton.d.ts +19 -0
- package/dist/types/core/PointerLockBehavior.d.ts +6 -0
- package/dist/types/core/WheelRotation.d.ts +30 -0
- package/dist/types/core/index.d.ts +10 -0
- package/dist/types/events/ActionEvent.d.ts +12 -0
- package/dist/types/events/MovementEvent.d.ts +28 -0
- package/dist/types/events/index.d.ts +2 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/settings/Bindings.d.ts +125 -0
- package/dist/types/settings/InputSettings.d.ts +57 -0
- package/dist/types/settings/PointerSettings.d.ts +89 -0
- package/dist/types/settings/SettingsEventMap.d.ts +9 -0
- package/dist/types/settings/index.d.ts +4 -0
- package/package.json +92 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Raoul van Rüschen
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# Input Controller
|
|
2
|
+
|
|
3
|
+
[](https://github.com/vanruesc/input-controller/actions/workflows/ci.yml)
|
|
4
|
+
[](https://www.npmjs.com/package/input-controller)
|
|
5
|
+
|
|
6
|
+
A fast, event-based input management library for the browser.
|
|
7
|
+
|
|
8
|
+
*[Demo](https://vanruesc.github.io/input-controller/demo) · [Documentation](https://vanruesc.github.io/input-controller/docs)*
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
npm install input-controller
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Features
|
|
17
|
+
|
|
18
|
+
* Emits action events for bound inputs.
|
|
19
|
+
* Emits normalized events for different pointer types and gestures.
|
|
20
|
+
* Supports input bindings with user-defined actions.
|
|
21
|
+
* Supports input combinations with modifiers.
|
|
22
|
+
* Input matching uses fast bitwise operations.
|
|
23
|
+
* Matches are reevaluated immediately when any input changes.
|
|
24
|
+
* Supports different pointer lock behaviors per pointer button: `none`, `lock` and `lock-hold`.
|
|
25
|
+
* Disables the context menu when any action is bound to the secondary button.
|
|
26
|
+
* This does not apply if the action also requires a modifier.
|
|
27
|
+
|
|
28
|
+
## Usage
|
|
29
|
+
|
|
30
|
+
```js
|
|
31
|
+
import { InputManager } from "input-controller";
|
|
32
|
+
|
|
33
|
+
const inputManager = new InputManager(settings.input, domElement);
|
|
34
|
+
inputManager.addEventListener("activate", event => console.log(event));
|
|
35
|
+
inputManager.addEventListener("deactivate", event => console.log(event));
|
|
36
|
+
inputManager.addEventListener("move", event => console.log(event));
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Settings
|
|
40
|
+
|
|
41
|
+
### Configuration
|
|
42
|
+
|
|
43
|
+
```js
|
|
44
|
+
import { KeyCode, Input, PointerButton } from "input-controller";
|
|
45
|
+
|
|
46
|
+
const settings = inputManager.settings;
|
|
47
|
+
settings.pointer.setBehavior(PointerButton.MAIN, "lock");
|
|
48
|
+
|
|
49
|
+
const keyBindings = settings.keyBindings;
|
|
50
|
+
keyBindings.set("Space", "jump");
|
|
51
|
+
keyBindings.set(new Input("KeyS", { modifiers: ["Ctrl"] }), "save");
|
|
52
|
+
|
|
53
|
+
const pointerBindings = settings.pointerBindings;
|
|
54
|
+
pointerBindings.set(PointerButton.MAIN, "drag");
|
|
55
|
+
pointerBindings.set(Gesture.PINCH, "zoom");
|
|
56
|
+
pointerBindings.set(Gesture.ROTATE, "rotate");
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
See the [docs](https://vanruesc.github.io/input-controller/docs/classes/Settings.html) for more information.
|
|
60
|
+
|
|
61
|
+
### Saving and Loading
|
|
62
|
+
|
|
63
|
+
```js
|
|
64
|
+
// JSON round-trip.
|
|
65
|
+
const json = JSON.stringify(settings);
|
|
66
|
+
settings.fromJSON(json);
|
|
67
|
+
|
|
68
|
+
// Via local storage.
|
|
69
|
+
localStorage.setItem("input-controller", JSON.stringify(settings));
|
|
70
|
+
settings.fromJSON(localStorage.getItem("input-controller"));
|
|
71
|
+
|
|
72
|
+
// Save as JSON file.
|
|
73
|
+
const settingsURL = URL.createObjectURL(settings.toBlob());
|
|
74
|
+
const a = document.createElement("a");
|
|
75
|
+
a.setAttribute("href", settingsURL);
|
|
76
|
+
a.setAttribute("download", "input-controller.json");
|
|
77
|
+
a.click();
|
|
78
|
+
URL.revokeObjectURL(settingsURL);
|
|
79
|
+
|
|
80
|
+
// Load from JSON file.
|
|
81
|
+
fetch("./input-controller.json")
|
|
82
|
+
.then(response => response.text())
|
|
83
|
+
.then(data => settings.fromJSON(data))
|
|
84
|
+
.catch(e => console.error(e));
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Contributing
|
|
88
|
+
|
|
89
|
+
Maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code.
|