pixijs-input-devices 0.4.0 → 0.5.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/README.md +133 -106
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +170 -112
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
#
|
|
1
|
+
# 🎮 PixiJS Input Devices [](https://github.com/reececomo/pixijs-input-devices/blob/main/LICENSE) [](https://github.com/reececomo/pixijs-input-devices/actions/workflows/tests.yml) [](https://www.npmjs.com/package/pixijs-input-devices) [](https://www.npmjs.com/package/pixijs-input-devices)
|
|
2
2
|
|
|
3
|
-
⚡
|
|
3
|
+
⚡ Simple keyboard & gamepad management for PixiJS
|
|
4
4
|
|
|
5
5
|
| | |
|
|
6
6
|
| ------ | ------ |
|
|
7
|
-
| 🎮
|
|
8
|
-
|
|
|
9
|
-
|
|
|
10
|
-
|
|
|
7
|
+
| 🎮 Interface [keyboards](#keyboarddevice), [gamepads](#gamepaddevice), and [more](#custom-devices)! | 🚀 Flexible [update](#real-time) and [event-driven](#keyboarddevice-events) APIs |
|
|
8
|
+
| ⚡ Optimized for [INP performance](https://web.dev/articles/inp) | 🪄 Built-in [named binds](#named-binds) |
|
|
9
|
+
| 🔮 Highly configurable | 🌐 Built-in [international keyboard](#keyboard-layout---detection) support |
|
|
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> | 🧭 Built-in [UI navigation](#uinavigation-api) _(optional)_ |
|
|
11
11
|
| 🍃 Zero dependencies & tree-shakeable | ✨ Supports PixiJS v8, v7, v6.3+ |
|
|
12
12
|
|
|
13
13
|
|
|
@@ -16,22 +16,23 @@
|
|
|
16
16
|
*Handle device inputs with ease.*
|
|
17
17
|
|
|
18
18
|
```ts
|
|
19
|
-
import { InputDevice } from "pixijs-input-devices";
|
|
19
|
+
import { InputDevice, GamepadDevice } from "pixijs-input-devices";
|
|
20
20
|
|
|
21
|
-
//
|
|
22
|
-
|
|
21
|
+
// Set named binds
|
|
22
|
+
InputDevice.keyboard.configureBinds({ jump: [ "Space" ] })
|
|
23
|
+
GamepadDevice.configureDefaultBinds({ jump: [ "A", "LeftStickUp" ] })
|
|
23
24
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
// Use binds
|
|
26
|
+
for ( const device of InputDevice.devices ) {
|
|
27
|
+
if ( device.pressedBind("jump") ) doJump()
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
// Event-driven
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
InputDevice.onBind( "jump", ({ device }) =>
|
|
32
|
+
if ( device.type === "gamepad" ) {
|
|
33
|
+
e.device.playVibration({ duration: 100 })
|
|
34
|
+
}
|
|
35
|
+
);
|
|
35
36
|
```
|
|
36
37
|
|
|
37
38
|
## Getting Started with PixiJS Input Devices
|
|
@@ -45,10 +46,10 @@ The core concepts are:
|
|
|
45
46
|
|
|
46
47
|
1. **Devices:** _Any human interface device_
|
|
47
48
|
2. **Binds:** _Custom, named input actions that can be triggered by assigned keys or buttons_
|
|
48
|
-
3. **
|
|
49
|
+
3. **UINavigation:** _A global controller that allows non-pointer devices to navigate UIs_
|
|
49
50
|
|
|
50
51
|
> [!NOTE]
|
|
51
|
-
> _See [
|
|
52
|
+
> _See [UINavigation API](#uinavigation-api) for more information._
|
|
52
53
|
|
|
53
54
|
|
|
54
55
|
## Installation
|
|
@@ -68,32 +69,26 @@ yarn add pixijs-input-devices --dev
|
|
|
68
69
|
**2.** Register the update loop:
|
|
69
70
|
|
|
70
71
|
```ts
|
|
71
|
-
import
|
|
72
|
+
import { Ticker } from 'pixi.js';
|
|
72
73
|
import { InputDevice } from 'pixijs-input-devices';
|
|
73
74
|
|
|
74
|
-
// register `InputDevice.update()` with shared ticker
|
|
75
75
|
Ticker.shared.add(ticker => InputDevice.update());
|
|
76
76
|
```
|
|
77
77
|
|
|
78
78
|
> [!TIP]
|
|
79
|
-
> **Input polling:** In the context of a video game, you may want to put the input update at the start of your game event loop
|
|
80
|
-
|
|
81
|
-
> [!NOTE]
|
|
82
|
-
> _If not using a PixiJS ticker, then just put `Action.tick(elapsedMs)` in the appropriate equivalent place (i.e. your `requestAnimationFrame()` render loop)._
|
|
79
|
+
> **Input polling:** In the context of a video game, you may want to put the input update at the start of your game event loop instead.
|
|
83
80
|
|
|
84
|
-
**3.** (Optional) enable the
|
|
81
|
+
**3.** (Optional) enable the UINavigation API
|
|
85
82
|
|
|
86
83
|
```ts
|
|
87
84
|
import * as PIXI from 'pixi.js';
|
|
88
|
-
import {
|
|
89
|
-
|
|
90
|
-
// register container mixin
|
|
91
|
-
registerPixiJSInputDevicesMixin(PIXI.Container);
|
|
85
|
+
import { UINavigation, registerPixiJSNavigationMixin } from 'pixijs-input-devices';
|
|
92
86
|
|
|
93
87
|
const app = new PIXI.Application(/*…*/)
|
|
94
88
|
|
|
95
|
-
//
|
|
96
|
-
|
|
89
|
+
// enable the navigation API
|
|
90
|
+
UINavigation.configureWithRoot( app.stage )
|
|
91
|
+
registerPixiJSNavigationMixin( PIXI.Container )
|
|
97
92
|
```
|
|
98
93
|
|
|
99
94
|
✨ You are now ready to use inputs!
|
|
@@ -241,31 +236,43 @@ gamepad.playVibration({
|
|
|
241
236
|
|
|
242
237
|
The gamepad buttons reference **Standard Controller Layout**:
|
|
243
238
|
|
|
244
|
-
| Button
|
|
245
|
-
|
|
246
|
-
| `0` | `"A"` | **
|
|
247
|
-
| `1` | `"B"` | **
|
|
248
|
-
| `2` | `"X"` | **
|
|
249
|
-
| `3` | `"Y"` | **
|
|
250
|
-
| `4` | `"LeftShoulder"` | **Left Shoulder** |
|
|
251
|
-
| `5` | `"RightShoulder"` | **Right Shoulder** |
|
|
252
|
-
| `6` | `"LeftTrigger"` | **Left Trigger** |
|
|
253
|
-
| `7` | `"RightTrigger"` | **Right Trigger** |
|
|
254
|
-
| `8` | `"Back"` | **Back** |
|
|
255
|
-
| `9` | `"Start"` | **Start** |
|
|
256
|
-
| `10` | `"
|
|
257
|
-
| `11` | `"
|
|
239
|
+
| Button Index | BindableCode | Description | Xbox | Playstation | Nintendo<sup>[[?]](#gamepad---nintendo-layout-remapping)</sup> |
|
|
240
|
+
|:---:|:---|:---|:---:|:---:|:---:|
|
|
241
|
+
| `0` | `"A"` | **Face Button 0** | A | Cross | A |
|
|
242
|
+
| `1` | `"B"` | **Face Button 1** | B | Circle | X* |
|
|
243
|
+
| `2` | `"X"` | **Face Button 2** | X | Square | B* |
|
|
244
|
+
| `3` | `"Y"` | **Face Button 3** | Y | Triangle | Y |
|
|
245
|
+
| `4` | `"LeftShoulder"` | **Left Shoulder** | LB | L1 | L |
|
|
246
|
+
| `5` | `"RightShoulder"` | **Right Shoulder** | RB | R1 | R |
|
|
247
|
+
| `6` | `"LeftTrigger"` | **Left Trigger** | LT | L2 | ZL |
|
|
248
|
+
| `7` | `"RightTrigger"` | **Right Trigger** | RT | R2 | ZR |
|
|
249
|
+
| `8` | `"Back"` | **Back** | Back | Options | Minus |
|
|
250
|
+
| `9` | `"Start"` | **Start** | Start | Select | Plus |
|
|
251
|
+
| `10` | `"LeftStickClick"` | **Left Stick Click** | LSB | L3 | L3 |
|
|
252
|
+
| `11` | `"RightStickClick"` | **Right Stick Click** | RSB | R3 | R3 |
|
|
258
253
|
| `12` | `"DPadUp"` | **D-Pad Up** | ⬆️ | ⬆️ | ⬆️ |
|
|
259
254
|
| `13` | `"DPadDown"` | **D-Pad Down** | ⬇️ | ⬇️ | ⬇️ |
|
|
260
255
|
| `14` | `"DPadLeft"` | **D-Pad Left** | ⬅️ | ⬅️ | ⬅️ |
|
|
261
256
|
| `15` | `"DPadRight"` | **D-Pad Right** | ➡️ | ➡️ | ➡️ |
|
|
262
257
|
|
|
263
|
-
|
|
258
|
+
#### Gamepad Axis Codes
|
|
259
|
+
|
|
260
|
+
Bindable helpers are available for the joysticks too:
|
|
261
|
+
|
|
262
|
+
| Axis # | BindableCode | Standard | Layout
|
|
263
|
+
|:---:|:---:|:---:|:---:|
|
|
264
|
+
| `0` | `"LeftStickLeft"`<br/>`"LeftStickRight"` | **Left Stick (Left/Right)** | ⬅️➡️ |
|
|
265
|
+
| `1` | `"LeftStickUp"`<br/>`"LeftStickDown"` | **Left Stick (Up/Down)** | ⬆️⬇️ |
|
|
266
|
+
| `2` | `"RightStickLeft"`<br/>`"RightStickRight"` | **Right Stick (Left/Right)** | ⬅️➡️ |
|
|
267
|
+
| `3` | `"RightStickUp"`<br/>`"RightStickDown"` | **Right Stick (Up/Down)** | ⬆️⬇️ |
|
|
268
|
+
|
|
269
|
+
> [!TIP]
|
|
270
|
+
> Set the `joystick.threshold` option in `GamepadDevice.defaultOptions` to control when this is triggered.
|
|
264
271
|
|
|
265
272
|
#### Gamepad Layouts
|
|
266
273
|
|
|
267
274
|
```ts
|
|
268
|
-
gamepad.layout // "nintendo" | "xbox" | "playstation" | "logitech" | "steam" | "
|
|
275
|
+
gamepad.layout // "nintendo" | "xbox" | "playstation" | "logitech" | "steam" | "standard"
|
|
269
276
|
```
|
|
270
277
|
|
|
271
278
|
Layout detection is **highly non-standard** across major browsers, it should generally be used for aesthetic
|
|
@@ -280,10 +287,10 @@ only major brand controller that deviates from the standard.
|
|
|
280
287
|
> ***Nintendo:** Both the labels and physical positions of the A,B,X,Y buttons are different
|
|
281
288
|
> on Nintendo controllers.
|
|
282
289
|
>
|
|
283
|
-
> Set `GamepadDevice.defaultOptions.
|
|
290
|
+
> Set `GamepadDevice.defaultOptions.nintendoRemapMode` to apply the remapping as required.
|
|
284
291
|
>
|
|
285
|
-
> - `"physical"` _**(default)**_ – The A,B,X,Y button codes will refer the
|
|
286
|
-
> - `"accurate"` – The A,B,X,Y button codes will
|
|
292
|
+
> - `"physical"` _**(default)**_ – The A,B,X,Y button codes will refer the standard face button positions (Left=X, Top=Y, Bottom=A, Right=B).
|
|
293
|
+
> - `"accurate"` – The A,B,X,Y button codes will refer to the exact Nintendo labels (Left=Y, Top=X, Bottom=B, Right=A).
|
|
287
294
|
> - `"none"` – The A,B,X,Y button codes mapping stay at the default indices (Left=Y, Top=B, Bottom=X, Right=A).
|
|
288
295
|
>
|
|
289
296
|
> ```
|
|
@@ -303,8 +310,11 @@ only major brand controller that deviates from the standard.
|
|
|
303
310
|
You can manually override this per-gamepad, or for all gamepads:
|
|
304
311
|
|
|
305
312
|
```ts
|
|
306
|
-
|
|
307
|
-
GamepadDevice.defaultOptions.
|
|
313
|
+
// set default
|
|
314
|
+
GamepadDevice.defaultOptions.nintendoRemapMode = "none"
|
|
315
|
+
|
|
316
|
+
// set for a single gamepad
|
|
317
|
+
gamepad.options.nintendoRemapMode = "accurate"
|
|
308
318
|
```
|
|
309
319
|
|
|
310
320
|
#### GamepadDevice Events
|
|
@@ -351,18 +361,18 @@ This allows you to change the keys/buttons later (e.g. allow users to override i
|
|
|
351
361
|
|
|
352
362
|
```ts
|
|
353
363
|
// keyboard:
|
|
354
|
-
InputDevice.keyboard.
|
|
364
|
+
InputDevice.keyboard.configureBinds({
|
|
355
365
|
jump: [ "ArrowUp", "Space", "KeyW" ],
|
|
356
366
|
crouch: [ "ArrowDown", "KeyS" ],
|
|
357
367
|
toggleGraphics: [ "KeyB" ],
|
|
358
|
-
}
|
|
368
|
+
})
|
|
359
369
|
|
|
360
370
|
// all gamepads:
|
|
361
|
-
GamepadDevice.
|
|
362
|
-
jump: [ "A" ],
|
|
371
|
+
GamepadDevice.configureDefaultBinds({
|
|
372
|
+
jump: [ "A", "LeftStickUp" ],
|
|
363
373
|
crouch: [ "B", "X", "RightTrigger" ],
|
|
364
|
-
toggleGraphics: [ "
|
|
365
|
-
}
|
|
374
|
+
toggleGraphics: [ "RightStickUp", "RightStickDown" ],
|
|
375
|
+
})
|
|
366
376
|
```
|
|
367
377
|
|
|
368
378
|
These can then be used with either the real-time and event-based APIs.
|
|
@@ -384,14 +394,14 @@ InputDevice.gamepads[0].onBind( "jump", ( e ) => doJump() )
|
|
|
384
394
|
let jump = false, crouch = false, moveX = 0
|
|
385
395
|
|
|
386
396
|
const keyboard = InputDevice.keyboard
|
|
387
|
-
if ( keyboard.
|
|
388
|
-
if ( keyboard.
|
|
397
|
+
if ( keyboard.pressedBind( "jump" ) ) jump = true
|
|
398
|
+
if ( keyboard.pressedBind( "crouch" ) ) crouch = true
|
|
389
399
|
if ( keyboard.key.ArrowLeft ) moveX = -1
|
|
390
400
|
else if ( keyboard.key.ArrowRight ) moveX = 1
|
|
391
401
|
|
|
392
402
|
for ( const gamepad of InputDevice.gamepads ) {
|
|
393
|
-
if ( gamepad.
|
|
394
|
-
if ( gamepad.
|
|
403
|
+
if ( gamepad.pressedBind( "jump" ) ) jump = true
|
|
404
|
+
if ( gamepad.pressedBind( "crouch" ) ) crouch = true
|
|
395
405
|
|
|
396
406
|
// gamepads have additional analog inputs
|
|
397
407
|
// we're going to apply these only if touched
|
|
@@ -400,42 +410,55 @@ for ( const gamepad of InputDevice.gamepads ) {
|
|
|
400
410
|
}
|
|
401
411
|
```
|
|
402
412
|
|
|
403
|
-
##
|
|
413
|
+
## UINavigation API
|
|
404
414
|
|
|
405
415
|
_Traverse a UI using input devices._
|
|
406
416
|
|
|
407
|
-
|
|
408
|
-
|
|
417
|
+
```ts
|
|
418
|
+
UINavigation.configureWithRoot( app.stage ) // (or any Container)
|
|
419
|
+
```
|
|
409
420
|
|
|
410
|
-
|
|
411
|
-
example, you might add a `NavigationResponder` for a drop-down UI. A normal `Container` can be used as a `NavigationResponder`, and any
|
|
412
|
-
container on the stack will become the **current root container**.
|
|
421
|
+
You can manually take control of navigation using:
|
|
413
422
|
|
|
414
|
-
|
|
415
|
-
|
|
423
|
+
```ts
|
|
424
|
+
// take control
|
|
425
|
+
UINavigation.pushResponder( myModalView )
|
|
426
|
+
|
|
427
|
+
// relinquish control
|
|
428
|
+
UINavigation.popResponder()
|
|
429
|
+
```
|
|
430
|
+
|
|
431
|
+
The Navigation API is centered around the **UINavigation** manager, which
|
|
432
|
+
receives navigation intents from devices and forwards it to the UI context.
|
|
416
433
|
|
|
417
|
-
|
|
418
|
-
|
|
434
|
+
The **UINavigation** manager maintains a stack of responders, which can be a
|
|
435
|
+
`Container`, or any object that implements the `NavigationResponder` interface.
|
|
419
436
|
|
|
420
|
-
|
|
437
|
+
When a device sends a navigation intent, the **UINavigation** manager is
|
|
438
|
+
responsible for asking the **first responder** whether it can handle the intent.
|
|
439
|
+
|
|
440
|
+
If it returns `false`, any other responders are checked (if they exist),
|
|
441
|
+
otherwise the default global navigation behavior kicks in.
|
|
442
|
+
|
|
443
|
+
### Default Global Navigation Behaviors
|
|
421
444
|
|
|
422
445
|
When a navigation intent is **not** handled manually by a responder, it is handled in one of the following ways:
|
|
423
446
|
|
|
424
447
|
| Intent | Behavior |
|
|
425
448
|
|---|---|
|
|
426
|
-
|`"
|
|
427
|
-
|`"
|
|
428
|
-
|`"trigger"`|<ul><li>Checks if we are currently focused on a container, and then issue a `"
|
|
449
|
+
|`"navigate.back"`|<ul><li>No action.</li></ul>|
|
|
450
|
+
|`"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>|
|
|
451
|
+
|`"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>|
|
|
429
452
|
|
|
430
|
-
Container event | Description |
|
|
453
|
+
Container event | Description | Compatibility
|
|
431
454
|
-----------------|--------------------------------------------------------
|
|
432
|
-
`
|
|
433
|
-
`
|
|
434
|
-
`
|
|
455
|
+
`"devicedown"` | Target was triggered. | `"pointerdown"`, `"mousedown"`
|
|
456
|
+
`"deviceover"` | Target became focused. | `"pointerover"`, `"mouseover"`
|
|
457
|
+
`"deviceout"` | Target lost focus. | `"pointerout"`, `"mouseout"`
|
|
435
458
|
|
|
436
|
-
### Container
|
|
459
|
+
### Container Navigatability
|
|
437
460
|
|
|
438
|
-
Containers are extended with a few properties/
|
|
461
|
+
Containers are extended with a few properties/accessors:
|
|
439
462
|
|
|
440
463
|
Container properties | type | default | description
|
|
441
464
|
---------------------|------|---------|--------------
|
|
@@ -447,19 +470,23 @@ Container properties | type | default | description
|
|
|
447
470
|
> **isNavigatable:** By default, any element with `"pointerdown"` or `"mousedown"` handlers is navigatable.
|
|
448
471
|
|
|
449
472
|
> [!WARNING]
|
|
450
|
-
> **Fallback Hover Effect:** If there is no `"pointerover"` or `"mouseover"` handler detected on a container, `
|
|
473
|
+
> **Fallback Hover Effect:** If there is no `"pointerover"` or `"mouseover"` handler detected on a container, `UINavigation`
|
|
451
474
|
> will apply abasic alpha effect to the selected item to indicate which container is currently the navigation target. This
|
|
452
|
-
> can be disabled by setting `
|
|
475
|
+
> can be disabled by setting `UINavigation.options.useFallbackHoverEffect` to `false`.
|
|
453
476
|
|
|
454
477
|
|
|
455
|
-
###
|
|
478
|
+
### Default Binds
|
|
456
479
|
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
```ts
|
|
460
|
-
Navigation.options.enabled = false
|
|
461
|
-
```
|
|
480
|
+
The keyboard and gamepad devices are preconfigured with the following binds, feel free to modify them:
|
|
462
481
|
|
|
482
|
+
Navigation Intent Bind | Keyboard | Gamepad
|
|
483
|
+
---|---|---
|
|
484
|
+
`"navigate.left"` | "ArrowLeft", "KeyA" | "DPadLeft", "LeftStickLeft"
|
|
485
|
+
`"navigate.right"` | "ArrowRight", "KeyD" | "DPadRight", "LeftStickRight"
|
|
486
|
+
`"navigate.up"` | "ArrowUp", "KeyW" | "DPadUp", "LeftStickUp"
|
|
487
|
+
`"navigate.down"` | "ArrowDown", "KeyS" | "DPadDown", "LeftStickDown"
|
|
488
|
+
`"navigate.trigger"` | "Enter", "Space" | "A"
|
|
489
|
+
`"navigate.back"` | "Escape", "Backspace" | "B", "Back"
|
|
463
490
|
|
|
464
491
|
## Advanced usage
|
|
465
492
|
|
|
@@ -517,7 +544,7 @@ InputDevice.remove( onscreen )
|
|
|
517
544
|
You could set up multiple named inputs:
|
|
518
545
|
|
|
519
546
|
```ts
|
|
520
|
-
InputDevice.keyboard.
|
|
547
|
+
InputDevice.keyboard.configureBinds({
|
|
521
548
|
jump: [ "ArrowUp", "KeyW" ],
|
|
522
549
|
defend: [ "ArrowDown", "KeyS" ],
|
|
523
550
|
left: [ "ArrowLeft", "KeyA" ],
|
|
@@ -532,7 +559,7 @@ InputDevice.keyboard.options.binds = {
|
|
|
532
559
|
p2_defend: [ "ArrowDown" ],
|
|
533
560
|
p2_left: [ "ArrowLeft" ],
|
|
534
561
|
p2_right: [ "ArrowRight" ],
|
|
535
|
-
}
|
|
562
|
+
})
|
|
536
563
|
```
|
|
537
564
|
|
|
538
565
|
and then switch groups depending on the mode:
|
|
@@ -540,22 +567,22 @@ and then switch groups depending on the mode:
|
|
|
540
567
|
```ts
|
|
541
568
|
if ( gameMode === "multiplayer" )
|
|
542
569
|
{
|
|
543
|
-
player1.jump = device.
|
|
544
|
-
player1.defend = device.
|
|
545
|
-
player1.moveX += device.
|
|
546
|
-
player1.moveX += device.
|
|
547
|
-
|
|
548
|
-
player2.jump = device.
|
|
549
|
-
player2.defend = device.
|
|
550
|
-
player2.moveX += device.
|
|
551
|
-
player2.moveX += device.
|
|
570
|
+
player1.jump = device.pressedBind( "p1_jump" )
|
|
571
|
+
player1.defend = device.pressedBind( "p1_defend" )
|
|
572
|
+
player1.moveX += device.pressedBind( "p1_left" ) ? -1 : 0
|
|
573
|
+
player1.moveX += device.pressedBind( "p1_right" ) ? 1 : 0
|
|
574
|
+
|
|
575
|
+
player2.jump = device.pressedBind( "p2_jump" )
|
|
576
|
+
player2.defend = device.pressedBind( "p2_defend" )
|
|
577
|
+
player2.moveX += device.pressedBind( "p2_left" ) ? -1 : 0
|
|
578
|
+
player2.moveX += device.pressedBind( "p2_right" ) ? 1 : 0
|
|
552
579
|
}
|
|
553
580
|
else
|
|
554
581
|
{
|
|
555
|
-
player1.jump = device.
|
|
556
|
-
player1.defend = device.
|
|
557
|
-
player1.moveX += device.
|
|
558
|
-
player1.moveX += device.
|
|
582
|
+
player1.jump = device.pressedBind( "jump" )
|
|
583
|
+
player1.defend = device.pressedBind( "defend" )
|
|
584
|
+
player1.moveX += device.pressedBind( "left" ) ? -1 : 0
|
|
585
|
+
player1.moveX += device.pressedBind( "right" ) ? 1 : 0
|
|
559
586
|
|
|
560
587
|
updateComputerPlayerInput( player2 )
|
|
561
588
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";const e=0,t=1,i=2,s=3,o={A:0,B:1,X:2,Y:3,LeftShoulder:4,RightShoulder:5,LeftTrigger:6,RightTrigger:7,Back:8,Start:9,LeftStick:10,RightStick:11,DPadUp:12,DPadDown:13,DPadLeft:14,DPadRight:15},n=["A","B","X","Y","LeftShoulder","RightShoulder","LeftTrigger","RightTrigger","Back","Start","LeftStick","RightStick","DPadUp","DPadDown","DPadLeft","DPadRight"];function getAllNavigatables(e,t=[]){for(const i of e.children)i.isNavigatable?t.push(i):getAllNavigatables(i,t);return t}function getFirstNavigatable(e,t,i,{minimumDistance:s=3}={}){return function chooseFirstNavigatableInDirection(e,t,i,{minimumDistance:s=3}={}){var o,n,a,r,d,c,u,l,h;const g=e.filter((e=>e.isNavigatable&&null!=e.parent&&function isVisible(e){for(;null!=e;){if(!e.visible)return!1;e=e.parent}return!0}(e))),p=g.find((e=>e===t));if(void 0===p)return g.sort(((e,t)=>t.navigationPriority-e.navigationPriority)),g[0];if(void 0===i&&p)return p;const m=null!=p?p:g[Math.floor(Math.random()*g.length)];if(void 0===p)return null!==(o=e[0])&&void 0!==o?o:m;const v=p.getBounds(),y={x:v.left+v.width/2,y:v.top+v.height/2},f=g.filter((e=>e!==p)).map((e=>{const t=e.getBounds(),i={x:t.left+t.width/2,y:t.top+t.height/2};return{element:e,bounds:t,center:i,distSqrd:squaredDist(i,y)}}));switch(i){case"navigateUp":return null!==(a=null===(n=f.filter((e=>e.center.y<y.y-s)).sort(((e,t)=>e.distSqrd-t.distSqrd))[0])||void 0===n?void 0:n.element)&&void 0!==a?a:m;case"navigateLeft":return null!==(d=null===(r=f.filter((e=>e.center.x<y.x-s)).sort(((e,t)=>e.distSqrd-t.distSqrd))[0])||void 0===r?void 0:r.element)&&void 0!==d?d:m;case"navigateRight":return null!==(u=null===(c=f.filter((e=>e.center.x>y.x+s)).sort(((e,t)=>e.distSqrd-t.distSqrd))[0])||void 0===c?void 0:c.element)&&void 0!==u?u:m;case"navigateDown":return null!==(h=null===(l=f.filter((e=>e.center.y>y.y+s)).sort(((e,t)=>e.distSqrd-t.distSqrd))[0])||void 0===l?void 0:l.element)&&void 0!==h?h:m;default:return p}}(getAllNavigatables(e),t,i,{minimumDistance:s})}function isChildOf(e,t){for(;null!=e;){if(e===t)return!0;e=e.parent}return!1}function squaredDist(e,t){const i=t.x-e.x,s=t.y-e.y;return i*i+s*s}class NavigationManager{constructor(){this.options={enabled:!0,useFallbackHoverEffect:!0},this._responderStack=[]}get firstResponder(){return this._responderStack[0]}get responders(){return this._responderStack}commit(e,t){this.options.enabled&&this._propagateIntent(e,t)}popResponder(){var e,t,i,s;const o=this._responderStack.shift();return null===(e=null==o?void 0:o.resignedAsFirstResponder)||void 0===e||e.call(o),this._clearFocusIfNeeded(),this.firstResponder&&(null===(i=(t=this.firstResponder).becameFirstResponder)||void 0===i||i.call(t),(null===(s=this.firstResponder.autoFocus)||void 0===s||s)&&this.autoFocus()),o}pushResponder(e){var t,i,s;if(this._responderStack.includes(e))throw new Error("Responder already in stack.");const o=this.firstResponder;this._responderStack.unshift(e),null===(t=null==o?void 0:o.resignedAsFirstResponder)||void 0===t||t.call(o),this._clearFocusIfNeeded(),null===(i=e.becameFirstResponder)||void 0===i||i.call(e),(null===(s=e.autoFocus)||void 0===s||s)&&this.autoFocus()}autoFocus(){var e;const t=null!==(e=this.responders.find(isContainer))&&void 0!==e?e:this.stage;if(!t)return;const i=getFirstNavigatable(t);void 0!==i?i!==this._focused&&(this._focused&&this._emitBlur(this._focused),this._emitFocus(i),this._focused=i):console.debug("navigation: no navigatable containers found")}_propagateIntent(e,t){var i,s;for(const s of this._responderStack)if(null===(i=s.handledNavigationIntent)||void 0===i?void 0:i.call(s,e,t))return;if(void 0===this.stage)console.warn("navigation: no stage root set");else{const t=null!==(s=this.responders.find(isContainer))&&void 0!==s?s:this.stage;this._handleGlobalIntent(t,e)}}_handleGlobalIntent(e,t){var i,s;if(void 0===this._focused)return void this.autoFocus();if("navigateBack"===t)return this._emitBlur(this._focused),void(this._focused=void 0);if("trigger"===t)return void this._emitTrigger(this._focused);const o=null!==(s=getFirstNavigatable(null!==(i=this.responders.find(isContainer))&&void 0!==i?i:this.stage,this._focused,t))&&void 0!==s?s:this._focused;o!==this._focused&&(this._emitBlur(this._focused),this._emitFocus(o),this._focused=o)}_emitBlur(e){const t=e.eventNames();t.includes("pointerout")?e.emit("pointerout"):t.includes("mouseout")?e.emit("mouseout"):"auto"===e.navigationMode&&this.options.useFallbackHoverEffect&&(e.alpha=1),e.emit("blur")}_emitFocus(e){const t=e.eventNames();t.includes("pointerover")?e.emit("pointerover"):t.includes("mouseover")?e.emit("mouseover"):"auto"===e.navigationMode&&this.options.useFallbackHoverEffect&&(e.alpha=.5),e.emit("focus")}_emitTrigger(e){const t=e.eventNames();t.includes("pointerdown")?e.emit("pointerdown"):t.includes("mousedown")?e.emit("mousedown"):"auto"===e.navigationMode&&this.options.useFallbackHoverEffect&&(e.alpha=.75),e.emit("trigger")}_clearFocusIfNeeded(){var e;const t=null!==(e=this.responders.find(isContainer))&&void 0!==e?e:this.stage;t&&this._focused&&!isChildOf(this._focused,t)&&(this._focused=void 0)}}function isContainer(e){return"children"in e}NavigationManager.global=new NavigationManager;const a=NavigationManager.global;let r=new Map;function throttle(e,t){var i;const s=Date.now();return(null!==(i=r.get(e))&&void 0!==i?i:0)>s||(r.set(e,s+t),!1)}class EventEmitter{constructor(){this._listeners={}}hasListener(e){return void 0!==this._listeners[e]}emit(e,t){var i;null===(i=this._listeners[e])||void 0===i||i.forEach((e=>e(t)))}on(e,t){var i;this._listeners[e]||(this._listeners[e]=[]),null===(i=this._listeners[e])||void 0===i||i.push(t)}off(e,t){var i,s;this._listeners[e]=void 0===t||null===(i=this._listeners[e])||void 0===i?void 0:i.filter((e=>e!==t)),0===(null===(s=this._listeners[e])||void 0===s?void 0:s.length)&&(this._listeners[e]=void 0)}}class GamepadDevice{pressedBind(e){return void 0!==this.options.binds[e]&&this.pressedAny(this.options.binds[e])}pressedAny(e){for(let t=0;t<e.length;t++)if(this.button[e[t]])return!0;return!1}pressedAll(e){for(let t=0;t<e.length;t++)if(!this.button[e[t]])return!1;return!0}on(e,t){const i="number"==typeof e?n[e]:e;return this._emitter.on(i,t),this}off(e,t){const i="number"==typeof e?n[e]:e;return this._emitter.off(i,t),this}onBind(e,t){return this._bindEmitter.on(e,t),this}offBind(e,t){return this._bindEmitter.off(e,t),this}playVibration({duration:e=200,weakMagnitude:t=.5,strongMagnitude:i=.5,vibrationType:s="dual-rumble",rightTrigger:o=0,leftTrigger:n=0,startDelay:a=0}={}){if(!this.options.vibration.enabled)return;if(!this.source.vibrationActuator)return;const r=this.options.vibration.intensity;try{this.source.vibrationActuator.playEffect(s,{duration:e,startDelay:a,weakMagnitude:r*t,strongMagnitude:r*i,leftTrigger:r*n,rightTrigger:r*o})}catch(e){}}update(e,t){this.updatePresses(e,t),this.source=e}clear(){this._axisIntents=this._axisIntents.map((()=>!1)),this._btnPrevState=this._btnPrevState.map((()=>!1))}constructor(e){this.source=e,this.type="gamepad",this.meta={},this.lastInteraction=performance.now(),this.options=JSON.parse(JSON.stringify(GamepadDevice.defaultOptions)),this.leftJoystick={x:0,y:0},this.rightJoystick={x:0,y:0},this.button=Object.keys(o).reduce(((e,t)=>(e[t]=!1,e)),{}),this._btnPrevState=new Array(16),this._axisIntents=new Array(2),this._emitter=new EventEmitter,this._bindEmitter=new EventEmitter,this.leftTrigger=0,this.rightTrigger=0,this.leftShoulder=0,this.rightShoulder=0,this.id="gamepad"+e.index,this.layout=function detectLayout(e){const t=(e.id||"").toLowerCase();return/(steam|28de)/.test(t)?"steam":/(logitech|046d|c216)/.test(t)?"logitech":/(nintendo|switch|joycon|057e)/.test(t)?"nintendo":/(dualshock|dualsense|sony|054c|0ce6|0810)/.test(t)?"playstation":/(xbox|xinput|045e|028e|0291|02a0|02a1|02ea|02ff)/.test(t)?"xbox":"generic"}(e),this._throttleIdLeftStickX=this.id+"-lsx",this._throttleIdLeftStickY=this.id+"-lsy"}updatePresses(r,d){var c,u,l,h,g,p,m;const v=this._btnPrevState.length;for(let e=0;e<v;e++){let t=e;if("nintendo"===this.layout&&"none"!==this.options.remapNintendoMode&&("physical"===this.options.remapNintendoMode?t===o.B?t=o.A:t===o.A?t=o.B:t===o.X?t=o.Y:t===o.Y&&(t=o.X):t===o.B?t=o.X:t===o.X&&(t=o.B)),this._btnPrevState[t]===(null===(c=r.buttons[e])||void 0===c?void 0:c.pressed))continue;this.lastInteraction=d;const i=null!==(l=null===(u=r.buttons[e])||void 0===u?void 0:u.pressed)&&void 0!==l&&l,s=n[t];this._btnPrevState[t]=i,this.button[s]=i,i&&(this._emitter.hasListener(s)&&setTimeout((()=>this._emitter.emit(s,{device:this,button:t,buttonCode:s}))),Object.entries(this.options.binds).forEach((([e,i])=>{i.includes(s)&&setTimeout((()=>{const i={device:this,button:t,buttonCode:s,name:e};this._bindEmitter.emit(e,i),this._emitter.emit("bind",i)}))})),a.options.enabled&&this.options.navigation.enabled&&void 0!==this.options.navigation.binds[t]&&setTimeout((()=>a.commit(this.options.navigation.binds[t],this))))}const y=this.options.triggerDeadzone;this.leftTrigger=_scale(this.source.buttons[o.LeftTrigger].value,y),this.rightTrigger=_scale(this.source.buttons[o.RightTrigger].value,y),this.leftShoulder=_scale(this.source.buttons[o.LeftShoulder].value,y),this.rightShoulder=_scale(this.source.buttons[o.RightShoulder].value,y);const f=this.options.joystickDeadzone;this.leftJoystick.x=_scale(null!==(h=r.axes[e])&&void 0!==h?h:0,f),this.leftJoystick.y=_scale(null!==(g=r.axes[t])&&void 0!==g?g:0,f),this.rightJoystick.x=_scale(null!==(p=r.axes[i])&&void 0!==p?p:0,f),this.rightJoystick.y=_scale(null!==(m=r.axes[s])&&void 0!==m?m:0,f),0===this.leftJoystick.x&&0===this.leftJoystick.y&&0===this.rightJoystick.x&&0===this.rightJoystick.y||(this.lastInteraction=d);const b=this.options.navigation.joystick;if(Math.abs(this.leftJoystick.x)>=b.commitSensitivity){const t=this.leftJoystick.x<0?"navigateLeft":"navigateRight",i=this._axisIntents[e]?b.repeatCooldownMs:b.firstRepeatCooldownMs;this._axisIntents[e]=!0,this.options.navigation.enabled&&!throttle(this._throttleIdLeftStickX,i)&&setTimeout((()=>a.commit(t,this)))}else this._axisIntents[e]=!1;if(Math.abs(this.leftJoystick.y)>=b.commitSensitivity){const e=this.leftJoystick.y<0?"navigateUp":"navigateDown",i=this._axisIntents[t]?b.repeatCooldownMs:b.firstRepeatCooldownMs;this._axisIntents[t]=!0,this.options.navigation.enabled&&!throttle(this._throttleIdLeftStickY,i)&&setTimeout((()=>a.commit(e,this)))}else this._axisIntents[t]=!1}}function _scale(e,t){const i=(Math.abs(e)-t[0])/(t[1]-t[0]);return i>=0&&i<=1?Math.sign(e)*i:i>1?1*Math.sign(e):0}GamepadDevice.defaultOptions={remapNintendoMode:"physical",binds:{},navigation:{enabled:!0,binds:{[o.A]:"trigger",[o.B]:"navigateBack",[o.Back]:"navigateBack",[o.DPadDown]:"navigateDown",[o.DPadLeft]:"navigateLeft",[o.DPadRight]:"navigateRight",[o.DPadUp]:"navigateUp"},joystick:{commitSensitivity:.5,repeatCooldownMs:80,firstRepeatCooldownMs:400}},joystickDeadzone:[0,1],triggerDeadzone:[0,1],vibration:{enabled:!0,intensity:1}};const d={AltLeft:"AltLeft",AltRight:"AltRight",ArrowDown:"ArrowDown",ArrowLeft:"ArrowLeft",ArrowRight:"ArrowRight",ArrowUp:"ArrowUp",Backquote:"Backquote",Backslash:"Backslash",Backspace:"Backspace",BracketLeft:"BracketLeft",BracketRight:"BracketRight",CapsLock:"CapsLock",Comma:"Comma",ContextMenu:"ContextMenu",ControlLeft:"ControlLeft",ControlRight:"ControlRight",Delete:"Delete",Digit0:"Digit0",Digit1:"Digit1",Digit2:"Digit2",Digit3:"Digit3",Digit4:"Digit4",Digit5:"Digit5",Digit6:"Digit6",Digit7:"Digit7",Digit8:"Digit8",Digit9:"Digit9",End:"End",Enter:"Enter",Equal:"Equal",Escape:"Escape",F1:"F1",F10:"F10",F11:"F11",F12:"F12",F13:"F13",F14:"F14",F15:"F15",F16:"F16",F17:"F17",F18:"F18",F19:"F19",F2:"F2",F20:"F20",F21:"F21",F22:"F22",F23:"F23",F24:"F24",F25:"F25",F26:"F26",F27:"F27",F28:"F28",F29:"F29",F3:"F3",F30:"F30",F31:"F31",F32:"F32",F4:"F4",F5:"F5",F6:"F6",F7:"F7",F8:"F8",F9:"F9",Home:"Home",IntlBackslash:"IntlBackslash",IntlRo:"IntlRo",IntlYen:"IntlYen",KeyA:"KeyA",KeyB:"KeyB",KeyC:"KeyC",KeyD:"KeyD",KeyE:"KeyE",KeyF:"KeyF",KeyG:"KeyG",KeyH:"KeyH",KeyI:"KeyI",KeyJ:"KeyJ",KeyK:"KeyK",KeyL:"KeyL",KeyM:"KeyM",KeyN:"KeyN",KeyO:"KeyO",KeyP:"KeyP",KeyQ:"KeyQ",KeyR:"KeyR",KeyS:"KeyS",KeyT:"KeyT",KeyU:"KeyU",KeyV:"KeyV",KeyW:"KeyW",KeyX:"KeyX",KeyY:"KeyY",KeyZ:"KeyZ",Lang1:"Lang1",Lang2:"Lang2",MediaTrackNext:"MediaTrackNext",MediaTrackPrevious:"MediaTrackPrevious",MetaLeft:"MetaLeft",MetaRight:"MetaRight",Minus:"Minus",NumLock:"NumLock",Numpad0:"Numpad0",Numpad1:"Numpad1",Numpad2:"Numpad2",Numpad3:"Numpad3",Numpad4:"Numpad4",Numpad5:"Numpad5",Numpad6:"Numpad6",Numpad7:"Numpad7",Numpad8:"Numpad8",Numpad9:"Numpad9",NumpadAdd:"NumpadAdd",NumpadComma:"NumpadComma",NumpadDecimal:"NumpadDecimal",NumpadDivide:"NumpadDivide",NumpadMultiply:"NumpadMultiply",NumpadSubtract:"NumpadSubtract",OSLeft:"OSLeft",Pause:"Pause",Period:"Period",Quote:"Quote",ScrollLock:"ScrollLock",Semicolon:"Semicolon",ShiftLeft:"ShiftLeft",ShiftRight:"ShiftRight",Slash:"Slash",Space:"Space",Tab:"Tab",VolumeDown:"VolumeDown",VolumeMute:"VolumeMute",VolumeUp:"VolumeUp",WakeUp:"WakeUp"};function __awaiter(e,t,i,s){return new(i||(i=Promise))((function(o,n){function fulfilled(e){try{step(s.next(e))}catch(e){n(e)}}function rejected(e){try{step(s.throw(e))}catch(e){n(e)}}function step(e){e.done?o(e.value):function adopt(e){return e instanceof i?e:new i((function(t){t(e)}))}(e.value).then(fulfilled,rejected)}step((s=s.apply(e,t||[])).next())}))}let c,u;"function"==typeof SuppressedError&&SuppressedError;const l=["fr","mg","lu"],h=["ab","ba","be","bg","ch","kk","ky","mk","mn","ru","sr","tg","tt","uk","uz"],g=["de","cs","sk","sl","hu","hr","bs","ro","sq","me","lt","lv","et"],p=/ф|и|с|в|у|а|п|р|ш|о|л|д|ь|т|щ|з|й|к|ы|е|г|м|ц|ч|н|я|ё|х|ъ|б|ю|э|ж|и/i,m=/[a-z]/i;function inferKeyboardLayoutFromLang(e=function getLang(){var e;const t=navigator;return null!=(null===(e=t.languages)||void 0===e?void 0:e.length)?t.languages[0]:t.userLanguage||t.language||t.browserLanguage}()){const t=(e||"").toLowerCase(),i=t.split("-")[0];return l.includes(i)||t.startsWith("nl-be")?"AZERTY":h.includes(i)?"JCUKEN":g.includes(i)||t.startsWith("sr-latn")?"QWERTZ":"QWERTY"}const v=new Set(["AZERTY","JCUKEN","QWERTY","QWERTZ"]);function getLayoutKeyLabel(e,t){var i,s;if(void 0===u){const e={ArrowLeft:"⬅",ArrowRight:"➡",ArrowUp:"⬆",ArrowDown:"⬇",AltLeft:"Left Alt",AltRight:"Right Alt",Backquote:"`",Backslash:"\\",Backspace:"Backspace",BracketLeft:"[",BracketRight:"]",CapsLock:"CapsLock",Comma:",",ContextMenu:"Context Menu",ControlLeft:"Left Ctrl",ControlRight:"Right Ctrl",Delete:"Delete",Digit0:"0",Digit1:"1",Digit2:"2",Digit3:"3",Digit4:"4",Digit5:"5",Digit6:"6",Digit7:"7",Digit8:"8",Digit9:"9",End:"End",Enter:"Enter",Equal:"=",Escape:"Esc",F1:"F1",F2:"F2",F3:"F3",F4:"F4",F5:"F5",F6:"F6",F7:"F7",F8:"F8",F9:"F9",F10:"F10",F11:"F11",F12:"F12",F13:"F13",F14:"F14",F15:"F15",F16:"F16",F17:"F17",F18:"F18",F19:"F19",F20:"F20",F21:"F21",F22:"F22",F23:"F23",F24:"F24",F25:"F25",F26:"F26",F27:"F27",F28:"F28",F29:"F29",F30:"F30",F31:"F31",F32:"F32",Home:"Home",IntlBackslash:"\\",IntlRo:"Ro",IntlYen:"¥",KeyA:"A",KeyB:"B",KeyC:"C",KeyD:"D",KeyE:"E",KeyF:"F",KeyG:"G",KeyH:"H",KeyI:"I",KeyJ:"J",KeyK:"K",KeyL:"L",KeyM:"M",KeyN:"N",KeyO:"O",KeyP:"P",KeyQ:"Q",KeyR:"R",KeyS:"S",KeyT:"T",KeyU:"U",KeyV:"V",KeyW:"W",KeyX:"X",KeyY:"Y",KeyZ:"Z",Lang1:"Language 1",Lang2:"Language 2",MediaTrackNext:"Next Track",MediaTrackPrevious:"Previous Track",MetaLeft:"Left "+getMetaKeyLabel(),MetaRight:"Right "+getMetaKeyLabel(),Minus:"-",NumLock:"Num Lock",Numpad0:"Num0",Numpad1:"Num1",Numpad2:"Num2",Numpad3:"Num3",Numpad4:"Num4",Numpad5:"Num5",Numpad6:"Num6",Numpad7:"Num7",Numpad8:"Num8",Numpad9:"Num9",NumpadAdd:"+",NumpadComma:",",NumpadDecimal:".",NumpadDivide:"/",NumpadMultiply:"*",NumpadSubtract:"-",OSLeft:"OS Left",Pause:"Pause",Period:".",Quote:"'",ScrollLock:"Scroll Lock",Semicolon:";",ShiftLeft:"Left Shift",ShiftRight:"Right Shift",Slash:"/",Space:"Space",Tab:"Tab",VolumeDown:"Volume Down",VolumeMute:"Volume Mute",VolumeUp:"Volume Up",WakeUp:"Wake Up"};u={AZERTY:{KeyA:"Q",KeyQ:"A",KeyW:"Z",KeyZ:"W",Backquote:"²",BracketLeft:"«",BracketRight:"»"},JCUKEN:{KeyA:"Ф",KeyB:"И",KeyC:"С",KeyD:"В",KeyE:"У",KeyF:"А",KeyG:"П",KeyH:"Р",KeyI:"Ш",KeyJ:"О",KeyK:"Л",KeyL:"Д",KeyM:"Ь",KeyN:"Т",KeyO:"Щ",KeyP:"З",KeyQ:"Й",KeyR:"К",KeyS:"Ы",KeyT:"Е",KeyU:"Г",KeyV:"М",KeyW:"Ц",KeyX:"Ч",KeyY:"Н",KeyZ:"Я",Backquote:"Ё",BracketLeft:"х",BracketRight:"ъ",Comma:"Б",Period:"Ю",Quote:"Э",Semicolon:"Ж",Slash:"И"},QWERTY:e,QWERTZ:{KeyY:"Z",KeyZ:"Y",BracketLeft:"ü",BracketRight:"ö",Slash:"-"}}}return null!==(s=null!==(i=u[t][e])&&void 0!==i?i:u.QWERTY[e])&&void 0!==s?s:e}function getMetaKeyLabel(){var e,t,i,s;const o=navigator,n=null!==(t=null===(e=o.platform)||void 0===e?void 0:e.toLowerCase())&&void 0!==t?t:"",a=null!==(s=null===(i=o.userAgent)||void 0===i?void 0:i.toLowerCase())&&void 0!==s?s:"";return n.includes("mac")?"⌘":n.includes("win")||n.includes("linux")?"⊞":a.includes("android")?"Search":a.includes("iphone")||a.includes("ipad")?"⌘":"⊞"}const y=["navigateLeft","navigateRight","navigateUp","navigateDown"];class KeyboardDevice{constructor(){this.type="keyboard",this.id="keyboard",this.meta={},this.lastInteraction=performance.now(),this.detectLayoutOnKeypress=!0,this.detected=!1,this.options={binds:{},navigation:{enabled:!0,binds:{Space:"trigger",Enter:"trigger",Escape:"navigateBack",Backspace:"navigateBack",ArrowDown:"navigateDown",ArrowLeft:"navigateLeft",ArrowRight:"navigateRight",ArrowUp:"navigateUp",KeyA:"navigateLeft",KeyD:"navigateRight",KeyS:"navigateDown",KeyW:"navigateUp"}}},this.key=Object.keys(d).reduce(((e,t)=>(e[t]=!1,e)),{}),this._emitter=new EventEmitter,this._bindEmitter=new EventEmitter,this._deferredKeydown=[],this._layout=inferKeyboardLayoutFromLang(),this._layoutSource="lang",function requestKeyboardLayout(){return __awaiter(this,void 0,void 0,(function*(){const e=navigator;if(e.keyboard&&e.keyboard.getLayoutMap)try{const t=yield e.keyboard.getLayoutMap();c=t;const i=t.get("KeyQ"),s=t.get("KeyA"),o=t.get("KeyZ");if("a"===i&&"w"===o&&"q"===s)return"AZERTY";if("q"===i&&"y"===o&&"a"===s)return"QWERTZ";if("q"===i&&"z"===o&&"a"===s)return"QWERTY";if("й"===i&&"я"===o&&"ф"===s)return"JCUKEN"}catch(e){}}))}().then((e=>{void 0!==e&&(this._layoutSource="browser",this._layout=e,this.detectLayoutOnKeypress=!1,this._emitter.emit("layoutdetected",{layoutSource:"browser",layout:e,device:this}))})),this._configureEventListeners()}get layout(){return this._layout}set layout(e){this._layoutSource="manual",this._layout=e,this.detectLayoutOnKeypress=!1}get layoutSource(){return this._layoutSource}pressedBind(e){return void 0!==this.options.binds[e]&&this.pressedAny(this.options.binds[e])}pressedAny(e){for(let t=0;t<e.length;t++)if(this.key[e[t]])return!0;return!1}pressedAll(e){for(let t=0;t<e.length;t++)if(!this.key[e[t]])return!1;return!0}on(e,t){return this._emitter.on(e,t),this}off(e,t){return this._emitter.off(e,t),this}onBind(e,t){return this._bindEmitter.on(e,t),this}offBind(e,t){return this._bindEmitter.off(e,t),this}getKeyLabel(e,t){var i;return t?getLayoutKeyLabel(e,t):null!==(i=function getNavigatorKeyLabel(e){const t=null==c?void 0:c.get(e);return void 0===t?void 0:function _toLocaleTitleCase(e){return e.split(/\s+/).map((e=>e.charAt(0).toLocaleUpperCase()+e.slice(1))).join(" ")}(t)}(e))&&void 0!==i?i:getLayoutKeyLabel(e,null!=t?t:this._layout)}update(e){this._deferredKeydown.length>0&&(this._deferredKeydown.forEach((e=>this._processDeferredKeydownEvent(e))),this._deferredKeydown.length=0)}clear(){for(const e of Object.keys(d))this.key[e]=!1}_configureEventListeners(){const e=this.key,t=this._deferredKeydown;window.addEventListener("keydown",(i=>{e[i.code]=!0,t.push(i),this.lastInteraction=performance.now()}),{passive:!0,capture:!0}),window.addEventListener("keyup",(t=>{e[t.code]=!1,this.lastInteraction=performance.now()}),{passive:!0,capture:!0})}_processDeferredKeydownEvent(e){const t=e.code;if(!e.repeat){if(this.detectLayoutOnKeypress&&"lang"===this._layoutSource){const t=function detectKeyboardLayoutFromKeydown(e){const t=e.key.toLowerCase(),i=e.code;return p.test(t)?(v.delete("AZERTY"),v.delete("QWERTY"),v.delete("QWERTZ")):"Backquote"===i&&"²"===t||"BracketLeft"===i&&"«"===t||"BracketRight"===i&&"»"===t||"KeyA"===i&&"q"===t||"KeyQ"===i&&"a"===t||"KeyW"===i&&"z"===t||"KeyZ"===i&&"w"===t?(v.delete("JCUKEN"),v.delete("QWERTY"),v.delete("QWERTZ")):"BracketLeft"===i&&"ü"===t||"BracketRight"===i&&"ö"===t||"KeyY"===i&&"z"===t||"KeyZ"===i&&"y"===t||"Slash"===i&&"-"===t?(v.delete("AZERTY"),v.delete("JCUKEN"),v.delete("QWERTY")):"BracketLeft"===i&&"["===t||"BracketRight"===i&&"]"===t||"KeyZ"===i&&"z"===t?(v.delete("AZERTY"),v.delete("JCUKEN"),v.delete("QWERTZ")):"KeyQ"===i&&"q"===t||"KeyW"===i&&"w"===t?(v.delete("AZERTY"),v.delete("JCUKEN")):"KeyY"===i&&"Y"===t?(v.delete("QWERTZ"),v.delete("JCUKEN")):m.test(t)&&v.delete("JCUKEN"),1===v.size?[...v][0]:void 0}(e);void 0!==t&&(this._layout=t,this._layoutSource="keypress",this.detectLayoutOnKeypress=!1,this._emitter.emit("layoutdetected",{layout:t,layoutSource:"keypress",device:this}))}this._emitter.hasListener(t)&&setTimeout((()=>this._emitter.emit(t,{device:this,keyCode:t,keyLabel:this.getKeyLabel(t),event:e}))),Object.entries(this.options.binds).forEach((([i,s])=>{s.includes(t)&&setTimeout((()=>{const s={device:this,keyCode:t,keyLabel:this.getKeyLabel(t),event:e,name:i};this._bindEmitter.emit(i,s),this._emitter.emit("bind",s)}))}))}if(a.options.enabled&&this.options.navigation.enabled&&void 0!==this.options.navigation.binds[t]){const i=this.options.navigation.binds[t];e.repeat&&!y.includes(i)||setTimeout((()=>a.commit(this.options.navigation.binds[t],this)))}}}KeyboardDevice.global=new KeyboardDevice;class InputDeviceManager{constructor(){this.isMobile=(()=>{let e=!1;var t;return t=navigator.userAgent||navigator.vendor,(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(t)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(t.substr(0,4)))&&(e=!0),e})(),this.isTouchCapable=function isTouchCapable(){return"ontouchstart"in window||navigator.maxTouchPoints>0}(),this.options={requireFocus:!0,clearInputInBackground:!0},this._devices=[],this._gamepadDevices=[],this._gamepadDeviceMap=new Map,this._customDevices=[],this._emitter=new EventEmitter,this._bindEmitter=new EventEmitter,this._hasFocus=!1,this.keyboard=KeyboardDevice.global,this.isTouchCapable||this.isMobile?window.addEventListener("keydown",(()=>this.add(this.keyboard)),{once:!0}):this.add(this.keyboard),window.addEventListener("gamepadconnected",(()=>this._pollGamepads(performance.now()))),window.addEventListener("gamepaddisconnected",(e=>this._removeGamepad(e.gamepad.index)))}get devices(){return this._devices}get gamepads(){return this._gamepadDevices}get custom(){return this._customDevices}get lastInteractedDevice(){return this._lastInteractedDevice}on(e,t){return this._emitter.on(e,t),this}off(e,t){return this._emitter.off(e,t),this}onBind(e,t){return this._bindEmitter.on(e,t),this}offBind(e,t){return this._bindEmitter.off(e,t),this}emitBind(e){this._bindEmitter.emit(e.name,e)}add(e){-1===this._devices.indexOf(e)&&(this._devices.push(e),e instanceof KeyboardDevice?(e.detected=!0,e.on("bind",(e=>this.emitBind(e)))):e instanceof GamepadDevice?(this._gamepadDeviceMap.set(e.source.index,e),this._gamepadDevices.push(e),e.on("bind",(e=>this.emitBind(e)))):this._customDevices.push(e),this._emitter.emit("deviceadded",{device:e}))}remove(e){if(!(e instanceof KeyboardDevice||e instanceof GamepadDevice)){const t=this._customDevices.indexOf(e);-1!==t&&this._devices.splice(t,1)}const t=this._devices.indexOf(e);-1!==t&&(this._devices.splice(t,1),this._emitter.emit("deviceremoved",{device:e}))}update(){if(this.options.requireFocus&&!document.hasFocus())return this._hasFocus&&this.options.clearInputInBackground&&this.devices.forEach((e=>{var t;return null===(t=e.clear)||void 0===t?void 0:t.call(e)})),this._hasFocus=!1,this._devices;this._hasFocus=!0;const e=performance.now();return this.keyboard.detected&&this.keyboard.update(e),this._gamepadDevices.length>0&&this._pollGamepads(e),this._customDevices.length>0&&this._customDevices.forEach((t=>t.update(e))),this._updateLastInteracted(),this._devices}_updateLastInteracted(){if(0===this._devices.length)return;let e;if(1===this._devices.length)e=this._devices[0];else for(const t of this._devices)(void 0===e||t.lastInteraction>e.lastInteraction)&&(e=t);this._lastInteractedDevice=e}_pollGamepads(e){if(!document.hasFocus())return this._gamepadDevices;if(void 0===navigator.getGamepads)return this._gamepadDevices;for(const t of navigator.getGamepads())if(null!=t)if(this._gamepadDeviceMap.has(t.index)){this._gamepadDeviceMap.get(t.index).update(t,e)}else{const i=new GamepadDevice(t);this.add(i),i.update(t,e)}return this._gamepadDevices}_removeGamepad(e){const t=this._gamepadDeviceMap.get(e);if(!t)return;const i=this._gamepadDevices.indexOf(t);-1!==i&&this._gamepadDevices.splice(i,1),this.remove(t),this._gamepadDeviceMap.delete(e)}}InputDeviceManager.global=new InputDeviceManager;const f=InputDeviceManager.global;exports.Button=o,exports.GamepadDevice=GamepadDevice,exports.InputDevice=f,exports.KeyCode=d,exports.KeyboardDevice=KeyboardDevice,exports.Navigation=a,exports.REPEATABLE_NAV_INTENTS=y,exports.getAllNavigatables=getAllNavigatables,exports.getFirstNavigatable=getFirstNavigatable,exports.isChildOf=isChildOf,exports.registerPixiJSInputDeviceMixin=function registerPixiJSInputDeviceMixin(e){const t=e.prototype;t.navigationPriority=0,t.navigationMode="auto",Object.defineProperty(t,"isNavigatable",{get:function(){if("auto"===this.navigationMode){if(!this.isInteractive)return!1;const e=this.eventNames();return e.includes("pointerdown")||e.includes("mousedown")}return"target"===this.navigationMode},configurable:!0,enumerable:!1})};
|
|
1
|
+
"use strict";const e=0,t=1,i=2,s=3,o=["LeftStickLeft","LeftStickRight","LeftStickUp","LeftStickDown","RightStickLeft","RightStickRight","RightStickUp","RightStickDown"],n={A:0,B:1,X:2,Y:3,LeftShoulder:4,RightShoulder:5,LeftTrigger:6,RightTrigger:7,Back:8,Start:9,LeftStickClick:10,RightStickClick:11,DPadUp:12,DPadDown:13,DPadLeft:14,DPadRight:15},a=["A","B","X","Y","LeftShoulder","RightShoulder","LeftTrigger","RightTrigger","Back","Start","LeftStickClick","RightStickClick","DPadUp","DPadDown","DPadLeft","DPadRight"];let r=new Map;function throttle(e,t){var i;const s=Date.now();return(null!==(i=r.get(e))&&void 0!==i?i:0)>s||(r.set(e,s+t),!1)}class EventEmitter{constructor(){this._listeners={}}hasListener(e){return void 0!==this._listeners[e]}emit(e,t){var i;null===(i=this._listeners[e])||void 0===i||i.forEach((e=>e(t)))}on(e,t){var i;this._listeners[e]||(this._listeners[e]=[]),null===(i=this._listeners[e])||void 0===i||i.push(t)}off(e,t){var i,s;this._listeners[e]=void 0===t||null===(i=this._listeners[e])||void 0===i?void 0:i.filter((e=>e!==t)),0===(null===(s=this._listeners[e])||void 0===s?void 0:s.length)&&(this._listeners[e]=void 0)}}class GamepadDevice{static configureDefaultBinds(e){this.defaultOptions.binds=Object.assign(Object.assign({},this.defaultOptions.binds),e)}pressedBind(e){return void 0!==this.options.binds[e]&&this.pressedAny(this.options.binds[e])}pressedAny(e){for(let t=0;t<e.length;t++)if(this.button[e[t]])return!0;return!1}pressedAll(e){for(let t=0;t<e.length;t++)if(!this.button[e[t]])return!1;return!0}configureBinds(e){this.options.binds=Object.assign(Object.assign({},this.options.binds),e)}on(e,t){return this._emitter.on(e,t),this}off(e,t){return this._emitter.off(e,t),this}onBind(e,t){return this._bindEmitter.on(e,t),this}offBind(e,t){return this._bindEmitter.off(e,t),this}playVibration({duration:e=200,weakMagnitude:t=.5,strongMagnitude:i=.5,vibrationType:s="dual-rumble",rightTrigger:o=0,leftTrigger:n=0,startDelay:a=0}={}){if(!this.options.vibration.enabled)return;if(!this.source.vibrationActuator)return;const r=this.options.vibration.intensity;try{this.source.vibrationActuator.playEffect(s,{duration:e,startDelay:a,weakMagnitude:r*t,strongMagnitude:r*i,leftTrigger:r*n,rightTrigger:r*o})}catch(e){}}update(e,t){this.updatePresses(e,t),this.source=e}clear(){this.button=[...o,...a].reduce(((e,t)=>(e[t]=!1,e)),{})}constructor(e){this.source=e,this.type="gamepad",this.meta={},this.lastInteraction=performance.now(),this.options=JSON.parse(JSON.stringify(GamepadDevice.defaultOptions)),this.leftJoystick={x:0,y:0},this.rightJoystick={x:0,y:0},this.button=[...a,...o].reduce(((e,t)=>(e[t]=!1,e)),{}),this._emitter=new EventEmitter,this._bindEmitter=new EventEmitter,this.leftTrigger=0,this.rightTrigger=0,this.leftShoulder=0,this.rightShoulder=0,this.id="gamepad"+e.index,this.layout=function detectLayout(e){const t=(e.id||"").toLowerCase();return/(steam|28de)/.test(t)?"steam":/(logitech|046d|c216)/.test(t)?"logitech":/(nintendo|switch|joycon|057e)/.test(t)?"nintendo":/(dualshock|dualsense|sony|054c|0ce6|0810)/.test(t)?"playstation":/(xbox|xinput|045e|028e|0291|02a0|02a1|02ea|02ff)/.test(t)?"xbox":"standard"}(e)}updatePresses(r,d){var c,u,l,h,g,p,m;const v=this.options.joystick;for(let e=0;e<4;e++){const t=_scale(r.axes[e],v.deadzone),i=o[2*e+(t>0?1:0)];if(Math.abs(t)<v.threshold)this.button[i]=!1;else{const t=v.autoRepeatDelayMs[+this.button[i]];this.button[i]=!0,throttle(i,t)||(this.lastInteraction=d,this._emitter.hasListener(i)&&setTimeout((()=>this._emitter.emit(i,{device:this,axis:e,axisCode:i}))),Object.entries(this.options.binds).forEach((([t,s])=>{s.includes(i)&&setTimeout((()=>{const s={device:this,type:"axis",axis:e,axisCode:i,name:t};this._bindEmitter.emit(t,s),this._emitter.emit("bind",s)}))})))}}for(let e=0;e<16;e++){let t=e;"nintendo"===this.layout&&"none"!==this.options.nintendoRemapMode&&("physical"===this.options.nintendoRemapMode?t===n.B?t=n.A:t===n.A?t=n.B:t===n.X?t=n.Y:t===n.Y&&(t=n.X):t===n.B?t=n.X:t===n.X&&(t=n.B));const i=a[t];if(this.button[i]===(null===(c=r.buttons[e])||void 0===c?void 0:c.pressed))continue;this.lastInteraction=d;const s=null!==(l=null===(u=r.buttons[e])||void 0===u?void 0:u.pressed)&&void 0!==l&&l;this.button[i]=s,s&&(this._emitter.hasListener(i)&&setTimeout((()=>this._emitter.emit(i,{device:this,button:t,buttonCode:i}))),Object.entries(this.options.binds).forEach((([e,s])=>{s.includes(i)&&setTimeout((()=>{const s={device:this,type:"button",button:t,buttonCode:i,name:e};this._bindEmitter.emit(e,s),this._emitter.emit("bind",s)}))})))}const f=this.options.trigger.deadzone;this.leftTrigger=_scale(r.buttons[n.LeftTrigger].value,f),this.rightTrigger=_scale(r.buttons[n.RightTrigger].value,f),this.leftShoulder=_scale(r.buttons[n.LeftShoulder].value,f),this.rightShoulder=_scale(r.buttons[n.RightShoulder].value,f);const y=v.deadzone;this.leftJoystick.x=_scale(null!==(h=r.axes[e])&&void 0!==h?h:0,y),this.leftJoystick.y=_scale(null!==(g=r.axes[t])&&void 0!==g?g:0,y),this.rightJoystick.x=_scale(null!==(p=r.axes[i])&&void 0!==p?p:0,y),this.rightJoystick.y=_scale(null!==(m=r.axes[s])&&void 0!==m?m:0,y)}}function _scale(e,t){const i=(Math.abs(e)-t[0])/(t[1]-t[0]);return i>=0&&i<=1?Math.sign(e)*i:i>1?1*Math.sign(e):0}GamepadDevice.defaultOptions={nintendoRemapMode:"physical",binds:{"navigate.back":["B","Back"],"navigate.down":["DPadDown","LeftStickDown"],"navigate.left":["DPadLeft","LeftStickLeft"],"navigate.right":["DPadRight","LeftStickRight"],"navigate.trigger":["A"],"navigate.up":["DPadUp","LeftStickUp"]},joystick:{deadzone:[0,1],threshold:.25,autoRepeatDelayMs:[400,80]},trigger:{deadzone:[0,1]},vibration:{enabled:!0,intensity:1}};const d={AltLeft:"AltLeft",AltRight:"AltRight",ArrowDown:"ArrowDown",ArrowLeft:"ArrowLeft",ArrowRight:"ArrowRight",ArrowUp:"ArrowUp",Backquote:"Backquote",Backslash:"Backslash",Backspace:"Backspace",BracketLeft:"BracketLeft",BracketRight:"BracketRight",CapsLock:"CapsLock",Comma:"Comma",ContextMenu:"ContextMenu",ControlLeft:"ControlLeft",ControlRight:"ControlRight",Delete:"Delete",Digit0:"Digit0",Digit1:"Digit1",Digit2:"Digit2",Digit3:"Digit3",Digit4:"Digit4",Digit5:"Digit5",Digit6:"Digit6",Digit7:"Digit7",Digit8:"Digit8",Digit9:"Digit9",End:"End",Enter:"Enter",Equal:"Equal",Escape:"Escape",F1:"F1",F10:"F10",F11:"F11",F12:"F12",F13:"F13",F14:"F14",F15:"F15",F16:"F16",F17:"F17",F18:"F18",F19:"F19",F2:"F2",F20:"F20",F21:"F21",F22:"F22",F23:"F23",F24:"F24",F25:"F25",F26:"F26",F27:"F27",F28:"F28",F29:"F29",F3:"F3",F30:"F30",F31:"F31",F32:"F32",F4:"F4",F5:"F5",F6:"F6",F7:"F7",F8:"F8",F9:"F9",Home:"Home",IntlBackslash:"IntlBackslash",IntlRo:"IntlRo",IntlYen:"IntlYen",KeyA:"KeyA",KeyB:"KeyB",KeyC:"KeyC",KeyD:"KeyD",KeyE:"KeyE",KeyF:"KeyF",KeyG:"KeyG",KeyH:"KeyH",KeyI:"KeyI",KeyJ:"KeyJ",KeyK:"KeyK",KeyL:"KeyL",KeyM:"KeyM",KeyN:"KeyN",KeyO:"KeyO",KeyP:"KeyP",KeyQ:"KeyQ",KeyR:"KeyR",KeyS:"KeyS",KeyT:"KeyT",KeyU:"KeyU",KeyV:"KeyV",KeyW:"KeyW",KeyX:"KeyX",KeyY:"KeyY",KeyZ:"KeyZ",Lang1:"Lang1",Lang2:"Lang2",MediaTrackNext:"MediaTrackNext",MediaTrackPrevious:"MediaTrackPrevious",MetaLeft:"MetaLeft",MetaRight:"MetaRight",Minus:"Minus",NumLock:"NumLock",Numpad0:"Numpad0",Numpad1:"Numpad1",Numpad2:"Numpad2",Numpad3:"Numpad3",Numpad4:"Numpad4",Numpad5:"Numpad5",Numpad6:"Numpad6",Numpad7:"Numpad7",Numpad8:"Numpad8",Numpad9:"Numpad9",NumpadAdd:"NumpadAdd",NumpadComma:"NumpadComma",NumpadDecimal:"NumpadDecimal",NumpadDivide:"NumpadDivide",NumpadMultiply:"NumpadMultiply",NumpadSubtract:"NumpadSubtract",OSLeft:"OSLeft",Pause:"Pause",Period:"Period",Quote:"Quote",ScrollLock:"ScrollLock",Semicolon:"Semicolon",ShiftLeft:"ShiftLeft",ShiftRight:"ShiftRight",Slash:"Slash",Space:"Space",Tab:"Tab",VolumeDown:"VolumeDown",VolumeMute:"VolumeMute",VolumeUp:"VolumeUp",WakeUp:"WakeUp"};function __awaiter(e,t,i,s){return new(i||(i=Promise))((function(o,n){function fulfilled(e){try{step(s.next(e))}catch(e){n(e)}}function rejected(e){try{step(s.throw(e))}catch(e){n(e)}}function step(e){e.done?o(e.value):function adopt(e){return e instanceof i?e:new i((function(t){t(e)}))}(e.value).then(fulfilled,rejected)}step((s=s.apply(e,t||[])).next())}))}let c,u;"function"==typeof SuppressedError&&SuppressedError;const l=["fr","mg","lu"],h=["ab","ba","be","bg","ch","kk","ky","mk","mn","ru","sr","tg","tt","uk","uz"],g=["de","cs","sk","sl","hu","hr","bs","ro","sq","me","lt","lv","et"],p=/ф|и|с|в|у|а|п|р|ш|о|л|д|ь|т|щ|з|й|к|ы|е|г|м|ц|ч|н|я|ё|х|ъ|б|ю|э|ж|и/i,m=/[a-z]/i;function inferKeyboardLayoutFromLang(e=function getLang(){var e;const t=navigator;return null!=(null===(e=t.languages)||void 0===e?void 0:e.length)?t.languages[0]:t.userLanguage||t.language||t.browserLanguage}()){const t=(e||"").toLowerCase(),i=t.split("-")[0];return l.includes(i)||t.startsWith("nl-be")?"AZERTY":h.includes(i)?"JCUKEN":g.includes(i)||t.startsWith("sr-latn")?"QWERTZ":"QWERTY"}const v=new Set(["AZERTY","JCUKEN","QWERTY","QWERTZ"]);function getLayoutKeyLabel(e,t){var i,s;if(void 0===u){const e={ArrowLeft:"⬅",ArrowRight:"➡",ArrowUp:"⬆",ArrowDown:"⬇",AltLeft:"Left Alt",AltRight:"Right Alt",Backquote:"`",Backslash:"\\",Backspace:"Backspace",BracketLeft:"[",BracketRight:"]",CapsLock:"CapsLock",Comma:",",ContextMenu:"Context Menu",ControlLeft:"Left Ctrl",ControlRight:"Right Ctrl",Delete:"Delete",Digit0:"0",Digit1:"1",Digit2:"2",Digit3:"3",Digit4:"4",Digit5:"5",Digit6:"6",Digit7:"7",Digit8:"8",Digit9:"9",End:"End",Enter:"Enter",Equal:"=",Escape:"Esc",F1:"F1",F2:"F2",F3:"F3",F4:"F4",F5:"F5",F6:"F6",F7:"F7",F8:"F8",F9:"F9",F10:"F10",F11:"F11",F12:"F12",F13:"F13",F14:"F14",F15:"F15",F16:"F16",F17:"F17",F18:"F18",F19:"F19",F20:"F20",F21:"F21",F22:"F22",F23:"F23",F24:"F24",F25:"F25",F26:"F26",F27:"F27",F28:"F28",F29:"F29",F30:"F30",F31:"F31",F32:"F32",Home:"Home",IntlBackslash:"\\",IntlRo:"Ro",IntlYen:"¥",KeyA:"A",KeyB:"B",KeyC:"C",KeyD:"D",KeyE:"E",KeyF:"F",KeyG:"G",KeyH:"H",KeyI:"I",KeyJ:"J",KeyK:"K",KeyL:"L",KeyM:"M",KeyN:"N",KeyO:"O",KeyP:"P",KeyQ:"Q",KeyR:"R",KeyS:"S",KeyT:"T",KeyU:"U",KeyV:"V",KeyW:"W",KeyX:"X",KeyY:"Y",KeyZ:"Z",Lang1:"Language 1",Lang2:"Language 2",MediaTrackNext:"Next Track",MediaTrackPrevious:"Previous Track",MetaLeft:"Left "+getMetaKeyLabel(),MetaRight:"Right "+getMetaKeyLabel(),Minus:"-",NumLock:"Num Lock",Numpad0:"Num0",Numpad1:"Num1",Numpad2:"Num2",Numpad3:"Num3",Numpad4:"Num4",Numpad5:"Num5",Numpad6:"Num6",Numpad7:"Num7",Numpad8:"Num8",Numpad9:"Num9",NumpadAdd:"+",NumpadComma:",",NumpadDecimal:".",NumpadDivide:"/",NumpadMultiply:"*",NumpadSubtract:"-",OSLeft:"OS Left",Pause:"Pause",Period:".",Quote:"'",ScrollLock:"Scroll Lock",Semicolon:";",ShiftLeft:"Left Shift",ShiftRight:"Right Shift",Slash:"/",Space:"Space",Tab:"Tab",VolumeDown:"Volume Down",VolumeMute:"Volume Mute",VolumeUp:"Volume Up",WakeUp:"Wake Up"};u={AZERTY:{KeyA:"Q",KeyQ:"A",KeyW:"Z",KeyZ:"W",Backquote:"²",BracketLeft:"«",BracketRight:"»"},JCUKEN:{KeyA:"Ф",KeyB:"И",KeyC:"С",KeyD:"В",KeyE:"У",KeyF:"А",KeyG:"П",KeyH:"Р",KeyI:"Ш",KeyJ:"О",KeyK:"Л",KeyL:"Д",KeyM:"Ь",KeyN:"Т",KeyO:"Щ",KeyP:"З",KeyQ:"Й",KeyR:"К",KeyS:"Ы",KeyT:"Е",KeyU:"Г",KeyV:"М",KeyW:"Ц",KeyX:"Ч",KeyY:"Н",KeyZ:"Я",Backquote:"Ё",BracketLeft:"х",BracketRight:"ъ",Comma:"Б",Period:"Ю",Quote:"Э",Semicolon:"Ж",Slash:"И"},QWERTY:e,QWERTZ:{KeyY:"Z",KeyZ:"Y",BracketLeft:"ü",BracketRight:"ö",Slash:"-"}}}return null!==(s=null!==(i=u[t][e])&&void 0!==i?i:u.QWERTY[e])&&void 0!==s?s:e}function getMetaKeyLabel(){var e,t,i,s;const o=navigator,n=null!==(t=null===(e=o.platform)||void 0===e?void 0:e.toLowerCase())&&void 0!==t?t:"",a=null!==(s=null===(i=o.userAgent)||void 0===i?void 0:i.toLowerCase())&&void 0!==s?s:"";return n.includes("mac")?"⌘":n.includes("win")||n.includes("linux")?"⊞":a.includes("android")?"Search":a.includes("iphone")||a.includes("ipad")?"⌘":"⊞"}class KeyboardDevice{constructor(){this.type="keyboard",this.id="keyboard",this.meta={},this.lastInteraction=performance.now(),this.detectLayoutOnKeypress=!0,this.detected=!1,this.options={binds:{"navigate.back":["Escape","Backspace"],"navigate.down":["ArrowDown","KeyS"],"navigate.left":["ArrowLeft","KeyA"],"navigate.right":["ArrowRight","KeyD"],"navigate.trigger":["Enter","Space"],"navigate.up":["ArrowUp","KeyW"]},repeatableBinds:["navigate.down","navigate.left","navigate.right","navigate.up"]},this.key=Object.keys(d).reduce(((e,t)=>(e[t]=!1,e)),{}),this._emitter=new EventEmitter,this._bindEmitter=new EventEmitter,this._deferredKeydown=[],this._layout=inferKeyboardLayoutFromLang(),this._layoutSource="lang",function requestKeyboardLayout(){return __awaiter(this,void 0,void 0,(function*(){const e=navigator;if(e.keyboard&&e.keyboard.getLayoutMap)try{const t=yield e.keyboard.getLayoutMap();c=t;const i=t.get("KeyQ"),s=t.get("KeyA"),o=t.get("KeyZ");if("a"===i&&"w"===o&&"q"===s)return"AZERTY";if("q"===i&&"y"===o&&"a"===s)return"QWERTZ";if("q"===i&&"z"===o&&"a"===s)return"QWERTY";if("й"===i&&"я"===o&&"ф"===s)return"JCUKEN"}catch(e){}}))}().then((e=>{void 0!==e&&(this._layoutSource="browser",this._layout=e,this.detectLayoutOnKeypress=!1,this._emitter.emit("layoutdetected",{layoutSource:"browser",layout:e,device:this}))})),this._configureEventListeners()}get layout(){return this._layout}set layout(e){this._layoutSource="manual",this._layout=e,this.detectLayoutOnKeypress=!1}get layoutSource(){return this._layoutSource}pressedBind(e){return void 0!==this.options.binds[e]&&this.pressedAny(this.options.binds[e])}pressedAny(e){for(let t=0;t<e.length;t++)if(this.key[e[t]])return!0;return!1}pressedAll(e){for(let t=0;t<e.length;t++)if(!this.key[e[t]])return!1;return!0}configureBinds(e){this.options.binds=Object.assign(Object.assign({},this.options.binds),e)}on(e,t){return this._emitter.on(e,t),this}off(e,t){return this._emitter.off(e,t),this}onBind(e,t){return this._bindEmitter.on(e,t),this}offBind(e,t){return this._bindEmitter.off(e,t),this}getKeyLabel(e,t){var i;return t?getLayoutKeyLabel(e,t):null!==(i=function getNavigatorKeyLabel(e){const t=null==c?void 0:c.get(e);return void 0===t?void 0:function _toLocaleTitleCase(e){return e.split(/\s+/).map((e=>e.charAt(0).toLocaleUpperCase()+e.slice(1))).join(" ")}(t)}(e))&&void 0!==i?i:getLayoutKeyLabel(e,null!=t?t:this._layout)}update(e){this._deferredKeydown.length>0&&(this._deferredKeydown.forEach((e=>this._processDeferredKeydownEvent(e))),this._deferredKeydown.length=0)}clear(){for(const e of Object.keys(d))this.key[e]=!1}_configureEventListeners(){const e=this.key,t=this._deferredKeydown;window.addEventListener("keydown",(i=>{e[i.code]=!0,t.push(i),this.lastInteraction=performance.now()}),{passive:!0,capture:!0}),window.addEventListener("keyup",(t=>{e[t.code]=!1,this.lastInteraction=performance.now()}),{passive:!0,capture:!0})}_processDeferredKeydownEvent(e){const t=e.code;if(!e.repeat){if(this.detectLayoutOnKeypress&&"lang"===this._layoutSource){const t=function detectKeyboardLayoutFromKeydown(e){const t=e.key.toLowerCase(),i=e.code;return p.test(t)?(v.delete("AZERTY"),v.delete("QWERTY"),v.delete("QWERTZ")):"Backquote"===i&&"²"===t||"BracketLeft"===i&&"«"===t||"BracketRight"===i&&"»"===t||"KeyA"===i&&"q"===t||"KeyQ"===i&&"a"===t||"KeyW"===i&&"z"===t||"KeyZ"===i&&"w"===t?(v.delete("JCUKEN"),v.delete("QWERTY"),v.delete("QWERTZ")):"BracketLeft"===i&&"ü"===t||"BracketRight"===i&&"ö"===t||"KeyY"===i&&"z"===t||"KeyZ"===i&&"y"===t||"Slash"===i&&"-"===t?(v.delete("AZERTY"),v.delete("JCUKEN"),v.delete("QWERTY")):"BracketLeft"===i&&"["===t||"BracketRight"===i&&"]"===t||"KeyZ"===i&&"z"===t?(v.delete("AZERTY"),v.delete("JCUKEN"),v.delete("QWERTZ")):"KeyQ"===i&&"q"===t||"KeyW"===i&&"w"===t?(v.delete("AZERTY"),v.delete("JCUKEN")):"KeyY"===i&&"y"===t?(v.delete("QWERTZ"),v.delete("JCUKEN")):m.test(t)&&v.delete("JCUKEN"),1===v.size?[...v][0]:void 0}(e);void 0!==t&&(this._layout=t,this._layoutSource="keypress",this.detectLayoutOnKeypress=!1,this._emitter.emit("layoutdetected",{layout:t,layoutSource:"keypress",device:this}))}this._emitter.hasListener(t)&&setTimeout((()=>this._emitter.emit(t,{device:this,keyCode:t,keyLabel:this.getKeyLabel(t),event:e})))}Object.entries(this.options.binds).forEach((([i,s])=>{s.includes(t)&&(e.repeat&&!this.options.repeatableBinds.includes(i)||setTimeout((()=>{const s={device:this,keyCode:t,keyLabel:this.getKeyLabel(t),event:e,name:i,repeat:e.repeat};this._bindEmitter.emit(i,s),this._emitter.emit("bind",s)})))}))}}KeyboardDevice.global=new KeyboardDevice;class InputDeviceManager{constructor(){this.isMobile=(()=>{let e=!1;var t;return t=navigator.userAgent||navigator.vendor,(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(t)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(t.substr(0,4)))&&(e=!0),e})(),this.isTouchCapable=function isTouchCapable(){return"ontouchstart"in window||navigator.maxTouchPoints>0}(),this.options={requireFocus:!0,clearInputInBackground:!0},this._devices=[],this._gamepadDevices=[],this._gamepadDeviceMap=new Map,this._customDevices=[],this._emitter=new EventEmitter,this._bindEmitter=new EventEmitter,this._hasFocus=!1,this.keyboard=KeyboardDevice.global,this.isTouchCapable||this.isMobile?window.addEventListener("keydown",(()=>this.add(this.keyboard)),{once:!0}):this.add(this.keyboard),window.addEventListener("gamepadconnected",(()=>this._pollGamepads(performance.now()))),window.addEventListener("gamepaddisconnected",(e=>this._removeGamepad(e.gamepad.index)))}get devices(){return this._devices}get gamepads(){return this._gamepadDevices}get custom(){return this._customDevices}get lastInteractedDevice(){return this._lastInteractedDevice}on(e,t){return this._emitter.on(e,t),this}off(e,t){return this._emitter.off(e,t),this}onBind(e,t){return(e=Array.isArray(e)?e:[e]).forEach((e=>this._bindEmitter.on(e,t))),this}offBind(e,t){return(e=Array.isArray(e)?e:[e]).forEach((e=>this._bindEmitter.off(e,t))),this}emitBind(e){this._bindEmitter.emit(e.name,e)}add(e){-1===this._devices.indexOf(e)&&(this._devices.push(e),e instanceof KeyboardDevice?(e.detected=!0,e.on("bind",(e=>this.emitBind(e)))):e instanceof GamepadDevice?(this._gamepadDeviceMap.set(e.source.index,e),this._gamepadDevices.push(e),e.on("bind",(e=>this.emitBind(e)))):this._customDevices.push(e),this._emitter.emit("deviceadded",{device:e}))}remove(e){if(!(e instanceof KeyboardDevice||e instanceof GamepadDevice)){const t=this._customDevices.indexOf(e);-1!==t&&this._devices.splice(t,1)}const t=this._devices.indexOf(e);-1!==t&&(this._devices.splice(t,1),this._emitter.emit("deviceremoved",{device:e}))}update(){if(this.options.requireFocus&&!document.hasFocus())return this._hasFocus&&this.options.clearInputInBackground&&this.devices.forEach((e=>{var t;return null===(t=e.clear)||void 0===t?void 0:t.call(e)})),this._hasFocus=!1,this._devices;this._hasFocus=!0;const e=performance.now();return this.keyboard.detected&&this.keyboard.update(e),this._gamepadDevices.length>0&&this._pollGamepads(e),this._customDevices.length>0&&this._customDevices.forEach((t=>t.update(e))),this._updateLastInteracted(),this._devices}_updateLastInteracted(){if(0===this._devices.length)return;let e;if(1===this._devices.length)e=this._devices[0];else for(const t of this._devices)(void 0===e||t.lastInteraction>e.lastInteraction)&&(e=t);this._lastInteractedDevice=e}_pollGamepads(e){if(!document.hasFocus())return this._gamepadDevices;if(void 0===navigator.getGamepads)return this._gamepadDevices;for(const t of navigator.getGamepads())if(null!=t)if(this._gamepadDeviceMap.has(t.index)){this._gamepadDeviceMap.get(t.index).update(t,e)}else{const i=new GamepadDevice(t);this.add(i),i.update(t,e)}return this._gamepadDevices}_removeGamepad(e){const t=this._gamepadDeviceMap.get(e);if(!t)return;const i=this._gamepadDevices.indexOf(t);-1!==i&&this._gamepadDevices.splice(i,1),this.remove(t),this._gamepadDeviceMap.delete(e)}}InputDeviceManager.global=new InputDeviceManager;const f=InputDeviceManager.global;function getAllNavigatables(e,t=[]){var i;for(const s of null!==(i=e.children)&&void 0!==i?i:[])s.isNavigatable?t.push(s):getAllNavigatables(s,t);return t}function getFirstNavigatable(e,t,i,{minimumDistance:s=0}={}){return function chooseFirstNavigatableInDirection(e,t,i,s=0){var o,n,a,r,d,c,u,l,h;const g=e.filter((e=>e.isNavigatable&&null!=e.parent&&isVisible(e))),p=g.find((e=>e===t));if(void 0===p)return g.sort(((e,t)=>t.navigationPriority-e.navigationPriority)),g[0];if(void 0===i&&p)return p;const m=null!=p?p:g[Math.floor(Math.random()*g.length)];if(void 0===p)return null!==(o=e[0])&&void 0!==o?o:m;const v=p.getGlobalPosition(),f=p.getBounds(),y={x:v.x+f.left+f.width/2,y:v.y+f.top+f.height/2},b=g.filter((e=>e!==p)).map((e=>{const t=e.getGlobalPosition(),i=e.getBounds(),s={x:t.x+i.left+i.width/2,y:t.y+i.top+i.height/2};return{element:e,bounds:i,center:s,xDistSqrd:weightedDistSquared(s,y,1,3),yDistSqrd:weightedDistSquared(s,y,3,1)}}));switch(i){case"navigate.up":return null!==(a=null===(n=b.filter((e=>e.center.y<y.y-s)).sort(((e,t)=>e.yDistSqrd-t.yDistSqrd))[0])||void 0===n?void 0:n.element)&&void 0!==a?a:m;case"navigate.left":return null!==(d=null===(r=b.filter((e=>e.center.x<y.x-s)).sort(((e,t)=>e.xDistSqrd-t.xDistSqrd))[0])||void 0===r?void 0:r.element)&&void 0!==d?d:m;case"navigate.right":return null!==(u=null===(c=b.filter((e=>e.center.x>y.x+s)).sort(((e,t)=>e.xDistSqrd-t.xDistSqrd))[0])||void 0===c?void 0:c.element)&&void 0!==u?u:m;case"navigate.down":return null!==(h=null===(l=b.filter((e=>e.center.y>y.y+s)).sort(((e,t)=>e.yDistSqrd-t.yDistSqrd))[0])||void 0===l?void 0:l.element)&&void 0!==h?h:m;default:return p}}(getAllNavigatables(e),t,i,s)}function isChildOf(e,t){for(;null!=e;){if(e===t)return!0;e=e.parent}return!1}function weightedDistSquared(e,t,i,s){const o=t.x-e.x,n=t.y-e.y;return o*o*i+n*n*s}function isVisible(e){for(;null!=e;){if(!e.visible)return!1;e=e.parent}return!0}const y=["navigate.left","navigate.right","navigate.up","navigate.down","navigate.back","navigate.trigger"];class NavigationManager{constructor(){this.options={useFallbackHoverEffect:!0,minimumDirectionDistance:10},this.enabled=!1,this._responders=[]}get focusTarget(){var e,t;return null!==(t=null===(e=this.responders.find((e=>null!=e.focusTarget&&isVisible(e.focusTarget))))||void 0===e?void 0:e.focusTarget)&&void 0!==t?t:this._rootFocused}set focusTarget(e){const t=this.focusTarget;if(t===e)return;const i=this.getResponderStage();i&&(!e||e.isNavigatable&&isChildOf(e,i))&&(t&&this._emitBlur(t),e&&this._emitFocus(e),this.firstResponder?this.firstResponder.focusTarget=e:this._rootFocused=e)}get firstResponder(){return this._responders[0]}get responders(){return this._responders}configureWithRoot(e){null==this._root&&f.onBind(y,(e=>this._propagate(e))),this._root=e,this.enabled=!0}popResponder(){var e,t,i,s,o;const n=this.focusTarget,a=this._responders.shift();a.focusTarget=void 0;const r=this.focusTarget;return null===(e=null==a?void 0:a.resignedAsFirstResponder)||void 0===e||e.call(a),this._invalidateFocusedIfNeeded(),this.firstResponder&&(null===(i=(t=this.firstResponder).becameFirstResponder)||void 0===i||i.call(t)),n!==r&&(null!==(o=null===(s=this.firstResponder)||void 0===s?void 0:s.autoFocus)&&void 0!==o?o:void 0===r)&&this.autoFocus(),a}pushResponder(e){var t,i,s;const o=e;if(this._responders.includes(o))throw new Error("Responder already in stack.");const n=this.firstResponder;this._responders.unshift(o),null===(t=null==n?void 0:n.resignedAsFirstResponder)||void 0===t||t.call(n),this._invalidateFocusedIfNeeded(),null===(i=o.becameFirstResponder)||void 0===i||i.call(o),(null===(s=o.autoFocus)||void 0===s||s)&&this.autoFocus()}autoFocus(){if(!b.enabled)return;const e=this.getResponderStage();if(!e)return;const t=getFirstNavigatable(e);void 0!==t?t!==this.focusTarget&&(this.focusTarget=t):console.debug("navigation: no navigatable containers found")}getResponderStage(){var e;return null!==(e=this.responders.find(isContainer))&&void 0!==e?e:this._root}_propagate({device:e,name:t}){var i;if(this.enabled){for(const s of this._responders)if(null===(i=s.handledNavigationIntent)||void 0===i?void 0:i.call(s,t,e))return;if(null==this._root)throw this.enabled=!1,new Error("Navigation requires root responder to be configured");{const e=this.getResponderStage();this._handleGlobalIntent(e,t)}}}_handleGlobalIntent(e,t){var i;this._invalidateFocusedIfNeeded(e);const s=this.focusTarget;if(void 0===s)return void this.autoFocus();if("navigate.back"===t)return this._emitBlur(s),void(this.focusTarget=void 0);if("navigate.trigger"===t)return void this._emitTrigger(s);const o=null!==(i=getFirstNavigatable(e,s,t,{minimumDistance:this.options.minimumDirectionDistance}))&&void 0!==i?i:s;o!==s&&(this.focusTarget=o)}_emitBlur(e){const t=e.eventNames();t.includes("pointerout")?e.emit("pointerout"):t.includes("mouseout")?e.emit("mouseout"):this.options.useFallbackHoverEffect&&(e.alpha=1),e.emit("deviceout")}_emitFocus(e){const t=e.eventNames();t.includes("pointerover")?e.emit("pointerover"):t.includes("mouseover")?e.emit("mouseover"):this.options.useFallbackHoverEffect&&(e.alpha=.5),e.emit("deviceover")}_emitTrigger(e){const t=e.eventNames();t.includes("pointerdown")?e.emit("pointerdown"):t.includes("mousedown")?e.emit("mousedown"):this.options.useFallbackHoverEffect&&(e.alpha=.75),e.emit("devicedown")}_invalidateFocusedIfNeeded(e=this.getResponderStage()){if(!e)return;const t=this.focusTarget;t&&!isChildOf(t,e)&&(this._emitBlur(t),this.focusTarget=void 0)}}function isContainer(e){return"children"in e}NavigationManager.global=new NavigationManager;const b=NavigationManager.global;let K=!1;exports.Button=n,exports.GamepadDevice=GamepadDevice,exports.InputDevice=f,exports.KeyCode=d,exports.KeyboardDevice=KeyboardDevice,exports.UINavigation=b,exports.getAllNavigatables=getAllNavigatables,exports.getFirstNavigatable=getFirstNavigatable,exports.isChildOf=isChildOf,exports.isVisible=isVisible,exports.navigationIntents=y,exports.registerPixiJSNavigationMixin=function registerPixiJSNavigationMixin(e){if(K)return;K=!0;const t=e.prototype;t.navigationPriority=0,t.navigationMode="auto",Object.defineProperty(t,"isNavigatable",{get:function(){if("target"===this.navigationMode)return!0;if("none"===this.navigationMode)return!1;const e=this.eventNames();return e.includes("pointerdown")||e.includes("mousedown")},configurable:!0,enumerable:!1})};
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|