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 CHANGED
@@ -4,34 +4,13 @@
4
4
 
5
5
  | | |
6
6
  | ------ | ------ |
7
- | 🎮 Instant [keyboard](#keyboarddevice), [gamepads](#gamepaddevice), and [custom device](#custom-devices) support | 🚀 [Real-time](#real-time) & [event-driven](#keyboarddevice-events) APIs |
8
- | ⚡ Optimized for [performance](https://web.dev/articles/inp) | 🧭 Built-in [UI navigation](#uinavigation-api) |
9
- | 🔮 Highly configurable (with sensible defaults) | 🪄 Supports [input binding](#named-binds) |
10
- | ✅ Cross-platform &amp; 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> | 🌐 Automatic [Intl layouts](#keyboard-layout---detection) detection |
11
- | 🍃 Zero dependencies & tree-shakeable | ✨ Supports PixiJS v8, v7, v6.3+ |
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 &amp; 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
- // 🎮 gamepad
48
- InputDevice.gamepads[0].configurBinds({
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
- // 🎮 gamepads (all)
55
- GamepadDevice.configureDefaultBinds({
56
- left: ["DpadLeft"],
57
- right: ["DpadRight"],
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.configureWithRoot(app.stage)
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
- _Traverse a UI using input devices._
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.configureWithRoot(app.stage) // any root container
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 intent is **not** handled manually by a responder, it is handled in one of the following ways:
531
+ When a navigation action is **not** handled manually by a responder, it is handled in one of the following ways:
534
532
 
535
- | Intent | Behavior |
533
+ | Action | Behavior |
536
534
  |---|---|
537
- |`"navigate.back"`|<ul><li>No action.</li></ul>|
538
- |`"navigate.left"`, `"navigate.right"`, `"navigate.up"`, `"navigate.down"`|<ul><li>Looks for the nearest `Container` where `container.isNavigatable` in the direction given, and if found, receives a `"deviceover"` event.</li><li>Additionally, if the newly focused container has registered an event handler for either `"pointerover"` or `"mouseover"` (in that order), it will fire that too.</li><li>If we were previously focused on a container, that previous container receives a `"deviceout"` event.</li><li>If the blurred container has register an event handler for either `"pointerout"` or `"mouseout"` (in that order), that event handler will be fired too.</li></ul>|
539
- |`"navigate.trigger"`|<ul><li>Checks if we are currently focused on a container, and then issue a `"devicedown"` event.</li><li>If the focused container has registered an event handler for either `"pointerdown"` or `"mousedown"` (in that order), that event handler will be fired too.</li></ul>|
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` | `get(): boolean` | `false` | returns `true` if `navigationMode` is set to `"target"`, |or is `"auto"` and a `"pointerdown"` or `"mousedown"` event handler is registered.
554
- | `navigationMode` | `"auto"` \| `"disabled"` \| `"target"` | `"auto"` | When set to `"auto"`, a `Container` can be navigated to if it has a `"pointerdown"` or `"mousedown"` event handler registered.
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
- `"navigate.left"` | "ArrowLeft", "KeyA" | "DpadLeft", "LeftStickLeft"
572
- `"navigate.right"` | "ArrowRight", "KeyD" | "DpadRight", "LeftStickRight"
573
- `"navigate.up"` | "ArrowUp", "KeyW" | "DpadUp", "LeftStickUp"
574
- `"navigate.down"` | "ArrowDown", "KeyS" | "DpadDown", "LeftStickDown"
575
- `"navigate.trigger"` | "Enter", "Space" | "Face1"
576
- `"navigate.back"` | "Escape", "Backspace" | "Face2", "Back"
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