pixijs-input-devices 0.7.3 → 0.8.1-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/README.md +49 -65
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +285 -96
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -4,34 +4,13 @@
|
|
|
4
4
|
|
|
5
5
|
| | |
|
|
6
6
|
| ------ | ------ |
|
|
7
|
-
| 🎮
|
|
8
|
-
| ⚡
|
|
9
|
-
| 🔮
|
|
10
|
-
| ✅ Cross-platform & mobile-friendly <sup>[[1]](https://caniuse.com/mdn-api_keyboardlayoutmap) [[2]](https://caniuse.com/mdn-api_gamepad_vibrationactuator) [[3]](https://chromestatus.com/feature/5989275208253440)</sup> | 🌐
|
|
11
|
-
| 🍃 Zero dependencies
|
|
7
|
+
| 🎮 Enable [keyboard](#keyboard), [gamepads](#gamepaddevice), [and more](#custom-devices) | 🪄 Input [binding](#named-binds) |
|
|
8
|
+
| ⚡ Performance [optimized](https://web.dev/articles/inp) | 🚀 Simple APIs ([realtime](#real-time), [events](#keyboarddevice-events)) |
|
|
9
|
+
| 🔮 Configurable (and sensible defaults) | 🧭 Navigate [pointer-based UIs](#uinavigation-api) |
|
|
10
|
+
| ✅ Cross-platform & mobile-friendly <sup>[[1]](https://caniuse.com/mdn-api_keyboardlayoutmap) [[2]](https://caniuse.com/mdn-api_gamepad_vibrationactuator) [[3]](https://chromestatus.com/feature/5989275208253440)</sup> | 🌐 International layout [support](#keyboard-layout---detection) |
|
|
11
|
+
| 🍃 Zero dependencies, tree-shakeable | ✨ Supports PixiJS v8, v7, v6.3+ |
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
## Basic Usage
|
|
15
|
-
|
|
16
|
-
```ts
|
|
17
|
-
import { InputDevice } from "pixijs-input-devices";
|
|
18
|
-
|
|
19
|
-
let moveX = 0.0,
|
|
20
|
-
jump = false;
|
|
21
|
-
|
|
22
|
-
for (const device of InputDevice.devices)
|
|
23
|
-
{
|
|
24
|
-
if (device.bindDown("left")) moveX = -1;
|
|
25
|
-
if (device.bindDown("right")) moveX = 1;
|
|
26
|
-
if (device.bindDown("jump")) jump = true;
|
|
27
|
-
|
|
28
|
-
if (device.type === "gamepad" && device.leftJoystick.x != 0.0)
|
|
29
|
-
{
|
|
30
|
-
moveX = device.leftJoystick.x;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
```
|
|
34
|
-
|
|
35
14
|
#### Configure binds
|
|
36
15
|
|
|
37
16
|
```ts
|
|
@@ -41,27 +20,46 @@ import { InputDevice, GamepadDevice } from "pixijs-input-devices";
|
|
|
41
20
|
InputDevice.keyboard.configureBinds({
|
|
42
21
|
jump: ["Space"],
|
|
43
22
|
left: ["KeyA", "ArrowLeft"],
|
|
44
|
-
right: ["KeyD", "ArrowRight"]
|
|
23
|
+
right: ["KeyD", "ArrowRight"]
|
|
45
24
|
});
|
|
46
25
|
|
|
47
|
-
// 🎮
|
|
48
|
-
|
|
26
|
+
// 🎮 all gamepads
|
|
27
|
+
GamepadDevice.configureDefaultBinds({
|
|
49
28
|
left: ["DpadLeft"],
|
|
50
29
|
right: ["DpadRight"],
|
|
51
|
-
jump: ["Face1"]
|
|
30
|
+
jump: ["Face1"]
|
|
52
31
|
});
|
|
53
32
|
|
|
54
|
-
// 🎮
|
|
55
|
-
|
|
56
|
-
left: ["
|
|
57
|
-
right: ["
|
|
58
|
-
jump: ["Face1"],
|
|
33
|
+
// 🎮 individual gamepad
|
|
34
|
+
InputDevice.gamepads[0].configurBinds({
|
|
35
|
+
left: ["LeftStickLeft"],
|
|
36
|
+
right: ["LeftStickRight"]
|
|
59
37
|
});
|
|
60
38
|
```
|
|
61
39
|
|
|
62
40
|
> [!TIP]
|
|
63
41
|
> See [**Named binds**](#named-binds) for more information on configuring devices.
|
|
64
42
|
|
|
43
|
+
## Basic Usage
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
let jump = false;
|
|
47
|
+
let moveX = 0;
|
|
48
|
+
|
|
49
|
+
for (let device of InputDevice.devices)
|
|
50
|
+
{
|
|
51
|
+
if (device.bindDown("jump")) jump = true;
|
|
52
|
+
if (device.bindDown("left")) moveX = -1;
|
|
53
|
+
if (device.bindDown("right")) moveX = 1;
|
|
54
|
+
|
|
55
|
+
// 🎮 analog
|
|
56
|
+
if (device.type === "gamepad" && device.leftJoystick.x)
|
|
57
|
+
{
|
|
58
|
+
moveX = device.leftJoystick.x;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
65
63
|
#### Events
|
|
66
64
|
|
|
67
65
|
```ts
|
|
@@ -126,7 +124,7 @@ import { UINavigation, registerPixiJSNavigationMixin } from 'pixijs-input-device
|
|
|
126
124
|
const app = new PIXI.Application(/*…*/)
|
|
127
125
|
|
|
128
126
|
// enable the navigation API
|
|
129
|
-
UINavigation.
|
|
127
|
+
UINavigation.enable(app.stage)
|
|
130
128
|
registerPixiJSNavigationMixin(PIXI.Container)
|
|
131
129
|
```
|
|
132
130
|
|
|
@@ -485,14 +483,14 @@ for (const gamepad of InputDevice.gamepads) {
|
|
|
485
483
|
|
|
486
484
|
## UINavigation API
|
|
487
485
|
|
|
488
|
-
|
|
486
|
+
_Traversing a pointer-based UI using input devices._
|
|
489
487
|
|
|
490
488
|
### Quick setup
|
|
491
489
|
|
|
492
490
|
Set up navigation once using:
|
|
493
491
|
|
|
494
492
|
```ts
|
|
495
|
-
UINavigation.
|
|
493
|
+
UINavigation.enable(app.stage) // any root container
|
|
496
494
|
registerPixiJSNavigationMixin(PIXI.Container)
|
|
497
495
|
```
|
|
498
496
|
|
|
@@ -530,19 +528,13 @@ otherwise the default global navigation behavior kicks in.
|
|
|
530
528
|
|
|
531
529
|
### Default Global Navigation Behaviors
|
|
532
530
|
|
|
533
|
-
When a navigation
|
|
531
|
+
When a navigation action is **not** handled manually by a responder, it is handled in one of the following ways:
|
|
534
532
|
|
|
535
|
-
|
|
|
533
|
+
| Action | Behavior |
|
|
536
534
|
|---|---|
|
|
537
|
-
|`"
|
|
538
|
-
|`"
|
|
539
|
-
|`"
|
|
540
|
-
|
|
541
|
-
| Container event | Description | Compatibility
|
|
542
|
-
|-----------------|-------------|------------------------------------------
|
|
543
|
-
| `"devicedown"` | Target was triggered. | `"pointerdown"`, `"mousedown"`
|
|
544
|
-
| `"deviceover"` | Target became focused. | `"pointerover"`, `"mouseover"`
|
|
545
|
-
| `"deviceout"` | Target lost focus. | `"pointerout"`, `"mouseout"`
|
|
535
|
+
|`"NavigateBack"`|<ul><li>No action.</li></ul>|
|
|
536
|
+
|`"NavigateLeft"`, `"NavigateRight"`, `"NavigateUp"`, `"NavigateDown"`|<ul><li>Looks for the nearest `Container` where `container.isNavigatable` in the direction given, and if found, receives a `"pointerover"` event.</li><li>Additionally, if the newly focused container has registered an event handler for either `"pointerover"`, it will fire that too.</li><li>If we were previously focused on a container, that previous container receives a `"pointerout"` event.</li></ul>|
|
|
537
|
+
|`"NavigateActivate"`|<ul><li>Checks if we are currently focused on a container, and then issue a `"pointerdown"` and `"pointerup"` event.</li><li>If the focused container has registered an event handler for either `"pointerdown"`, that event handler will be fired too.</li></ul>|
|
|
546
538
|
|
|
547
539
|
### Container Navigatability
|
|
548
540
|
|
|
@@ -550,30 +542,22 @@ Containers are extended with a few properties/accessors:
|
|
|
550
542
|
|
|
551
543
|
| Container properties | type | default | description
|
|
552
544
|
|---------------------|------|---------|--------------
|
|
553
|
-
| `isNavigatable` | `
|
|
554
|
-
| `navigationMode` | `"auto"` \| `"
|
|
545
|
+
| `isNavigatable` | `readonly boolean` | `false` | returns `true` if `navigationMode` is set to `"pointer"`, |or is `"auto"` and is interactive.
|
|
546
|
+
| `navigationMode` | `"auto"` \| `"pointer"` | `"none"` \| `"auto"` | When set to `"auto"`, a `Container` can be navigated to if it is int
|
|
555
547
|
| `navigationPriority` | `number` | `0` | The priority relative to other navigation items in this group.
|
|
556
548
|
|
|
557
|
-
> [!NOTE]
|
|
558
|
-
> **isNavigatable:** By default, any element with `"pointerdown"` or `"mousedown"` handlers is navigatable.
|
|
559
|
-
|
|
560
|
-
> [!WARNING]
|
|
561
|
-
> **Fallback Hover Effect:** If there is no `"pointerover"` or `"mouseover"` handler detected on a container, `UINavigation`
|
|
562
|
-
> will apply abasic alpha effect to the selected item to indicate which container is currently the navigation target. This
|
|
563
|
-
> can be disabled by setting `UINavigation.options.enableFallbackOverEffect` to `false`.
|
|
564
|
-
|
|
565
549
|
### Default Binds
|
|
566
550
|
|
|
567
551
|
The keyboard and gamepad devices are preconfigured with the following binds, feel free to modify them:
|
|
568
552
|
|
|
569
553
|
Navigation Intent Bind | Keyboard | Gamepad
|
|
570
554
|
---|---|---
|
|
571
|
-
`"
|
|
572
|
-
`"
|
|
573
|
-
`"
|
|
574
|
-
`"
|
|
575
|
-
`"
|
|
576
|
-
`"
|
|
555
|
+
`"NavigateLeft"` | "ArrowLeft", "KeyA" | "DpadLeft", "LeftStickLeft"
|
|
556
|
+
`"NavigateRight"` | "ArrowRight", "KeyD" | "DpadRight", "LeftStickRight"
|
|
557
|
+
`"NavigateUp"` | "ArrowUp", "KeyW" | "DpadUp", "LeftStickUp"
|
|
558
|
+
`"NavigateDown"` | "ArrowDown", "KeyS" | "DpadDown", "LeftStickDown"
|
|
559
|
+
`"NavigateActivate"` | "Enter", "Space" | "Face1"
|
|
560
|
+
`"NavigateBack"` | "Escape", "Backspace" | "Face2", "Back"
|
|
577
561
|
|
|
578
562
|
### Manual control for submenus & modal views
|
|
579
563
|
|