pixijs-input-devices 0.2.0 → 0.2.2

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
@@ -1,6 +1,6 @@
1
- # 🕹️ pixijs-input-devices &nbsp[![NPM version](https://img.shields.io/npm/v/pixijs-input-devices.svg)](https://www.npmjs.com/package/pixijs-input-devices) [![Minzipped](https://badgen.net/bundlephobia/minzip/pixijs-input-devices@latest)](https://bundlephobia.com/package/pixijs-input-devices) [![Downloads per month](https://img.shields.io/npm/dm/pixijs-input-devices.svg)](https://www.npmjs.com/package/pixijs-input-devices) [![Tests](https://github.com/reececomo/pixijs-input-devices/actions/workflows/tests.yml/badge.svg)](https://github.com/reececomo/pixijs-input-devices/actions/workflows/tests.yml) [![License](https://badgen.net/npm/license/pixijs-input-devices)](https://github.com/reececomo/pixijs-input-devices/blob/main/LICENSE)
1
+ # 🕹️ pixijs-input-devices  [![NPM version](https://img.shields.io/npm/v/pixijs-input-devices.svg)](https://www.npmjs.com/package/pixijs-input-devices) [![Minzipped](https://badgen.net/bundlephobia/minzip/pixijs-input-devices@latest)](https://bundlephobia.com/package/pixijs-input-devices) [![Downloads per month](https://img.shields.io/npm/dm/pixijs-input-devices.svg)](https://www.npmjs.com/package/pixijs-input-devices) [![Tests](https://github.com/reececomo/pixijs-input-devices/actions/workflows/tests.yml/badge.svg)](https://github.com/reececomo/pixijs-input-devices/actions/workflows/tests.yml) [![License](https://badgen.net/npm/license/pixijs-input-devices)](https://github.com/reececomo/pixijs-input-devices/blob/main/LICENSE)
2
2
 
3
- WIP
3
+ 🚧 WIP - This API is a work in progress, and is subject to change.
4
4
 
5
5
  - Adds support for ⌨️ **Keyboard**, 🎮 **Gamepads**, and other human-interface devices
6
6
  - A simple `Navigation` API which hooks devices into existing pointer/mouse events
@@ -26,74 +26,130 @@ registerPixiJSInputDeviceMixin( Container )
26
26
  // add update loop
27
27
  Ticker.shared.add( () => InputDevice.update() )
28
28
 
29
- // enable nav
29
+ // enable navigation
30
30
  Navigation.stage = app.stage
31
31
  ```
32
32
 
33
+ ### ✨ Binding Groups
34
+
35
+ Use named "groups" to create referenceable groups of inputs.
36
+
37
+ ```ts
38
+ InputDevice.keyboard.options.namedGroups = {
39
+ jump: [ "ArrowUp", "Space", "KeyW" ],
40
+ crouch: [ "ArrowDown","KeyS" ],
41
+ moveSlow: [ "ShiftLeft", "ShiftRight" ],
42
+ left: [ "ArrowLeft", "KeyA" ],
43
+ right: [ "ArrowRight", "KeyD" ],
44
+
45
+ toggleGraphics: [ "KeyB" ],
46
+ // other...
47
+ };
48
+
49
+ GamepadDevice.defaultOptions.namedGroups = {
50
+ jump: [ "A" ],
51
+ crouch: [ "B", "X", "RightTrigger" ],
52
+
53
+ toggleGraphics: [ "RightStick" ],
54
+ // other...
55
+ };
56
+ ```
57
+
58
+ These can then be used with the real-time and event-based APIs.
59
+
60
+ ```ts
61
+ // real-time:
62
+ if ( gamepad.groupPressed("jump") ) doJump();
63
+
64
+ // events:
65
+ InputDevice.gamepads[0].onGroup( "jump", ( event ) => doJump() );
66
+
67
+ // ...or listen to ANY device:
68
+ InputDevice.onGroup( "toggleGraphics", ( event ) => toggleGraphics() );
69
+ ```
70
+
71
+ You definitely do not have to use named inputs:
72
+
73
+ ```ts
74
+ // real-time:
75
+ if ( keyboard.key.Space || keyboard.key.KeyW ) jump = true;
76
+ if ( gamepad.button.A || gamepad.button.LeftTrigger ) jump = true;
77
+
78
+ // events:
79
+ InputDevice.gamepads[0].on( "A", ( event ) => doJump() );
80
+ ```
81
+
33
82
  ### Realtime API
34
83
 
35
- Simple example:
84
+ Iterate through `InputDevice.devices`, or access devices directly:
36
85
 
37
86
  ```ts
38
- let jump = false,
39
- hide = false,
40
- moveX = 0.0;
41
-
42
- // keyboard:
43
- const kb = InputDevice.keyboard;
44
- if ( kb.key.ArrowUp ) jump = true
45
- if ( kb.key.ArrowDown ) hide = true
46
- if ( kb.key.ArrowLeft ) moveX = -1.0
47
- else if ( kb.key.ArrowRight ) moveX = 1.0
48
-
49
- // gamepads:
50
- for ( const gamepad of InputDevice.gamepads )
51
- {
52
- if ( gamepad.button.A ) jump = true
53
- if ( gamepad.rightTrigger > 0.25 ) hide = true
54
- if ( gamepad.leftJoystick.x !== 0.0 ) moveX = gamepad.leftJoystick.x
87
+ let jump = false, crouch = false, moveX = 0
88
+
89
+ const keyboard = InputDevice.keyboard
90
+ if ( keyboard.groupPressed( "jump" ) ) jump = true
91
+ if ( keyboard.groupPressed( "crouch" ) ) crouch = true
92
+ if ( keyboard.groupPressed( "left" ) ) moveX -= 1
93
+ if ( keyboard.groupPressed( "right" ) ) moveX += 1
94
+ if ( keyboard.groupPressed( "moveSlow" ) ) moveX *= 0.5
95
+
96
+ for ( const gamepad of InputDevice.gamepads ) {
97
+ if ( gamepad.groupPressed( "jump" ) ) jump = true
98
+ if ( gamepad.groupPressed( "crouch" ) ) crouch = true
99
+
100
+ // gamepads have additional analog inputs
101
+ // we're going to apply these only if touched
102
+ if ( gamepad.leftJoystick.x != 0 ) moveX = gamepad.leftJoystick.x
103
+ if ( gamepad.leftTrigger > 0 ) moveX *= ( 1 - gamepad.leftTrigger )
55
104
  }
56
105
  ```
57
106
 
58
107
  ### Event API
59
108
 
109
+ Use `on( ... )` to subscribe to built-in events. Use `onGroup( ... )` to subscribe to custom named input group events.
110
+
60
111
  ```ts
61
- // listen to device events
62
- InputDevice.on( "deviceconnected", ({ device }) => {
63
- console.debug( "A new " + device.type + " device connected!" ) // "keyboard" | "gamepad" | "custom"
64
- })
112
+ // global events
113
+ InputDevice.on( "deviceconnected", ({ device }) =>
114
+ console.debug( "A new " + device.type + " device connected!" )
115
+ )
65
116
 
66
- // keyboard events
67
- InputDevice.keyboard.on( "layoutdetected", ({ layout }) => {
68
- console.debug( "layout detected as " + layout ); // "JCUKEN" | "AZERTY" | "QWERTZ" | "QWERTY"
69
- })
70
- InputDevice.keyboard.on( "Escape", () => showMenu() )
117
+ // device events
118
+ InputDevice.keyboard.on( "layoutdetected", ({ layout }) =>
119
+ console.debug( "layout detected as " + layout );
120
+ )
71
121
 
72
- // gamepad events
73
- InputDevice.gamepads[0].on( Button.Back, () => showMenu() )
122
+ // bind keys/buttons
123
+ InputDevice.keyboard.on( "Escape", () => showMenu() )
74
124
  InputDevice.gamepads[0].on( "Back", () => showMenu() )
75
125
 
126
+ // use "onGroup()" to add custom events too:
127
+ InputDevice.onGroup( "pause_menu", ( event ) => {
128
+ // menu was triggered!
129
+ })
76
130
  ```
77
131
 
78
- #### InputAction Events
132
+ #### Global Events
79
133
 
80
134
  | Event | Description | Payload |
81
135
  |---|---|---|
82
136
  | `"deviceconnected"` | `{device}` | A device has become available. |
83
137
  | `"devicedisconnected"` | `{device}` | A device has been removed. |
84
138
 
85
- #### Keyboard Events
139
+ #### Keyboard Device Events
86
140
 
87
141
  | Event | Description | Payload |
88
142
  |---|---|---|
89
143
  | `"layoutdetected"` | `{layout,layoutSource,device}` | The keyboard layout (`"QWERTY"`, `"QWERTZ"`, `"AZERTY"`, or `"JCUKEN"`) has been detected, either from the native API or from keypresses. |
144
+ | `"group"` | `{groupName,event,keyCode,keyLabel,device}` | A named input group key was pressed. |
90
145
  | **Key presses:** | | |
91
146
  | `"KeyA"` \| `"KeyB"` \| ... 103 more ... | `{event,keyCode,keyLabel,device}` | `"KeyA"` was pressed. |
92
147
 
93
- #### Gamepad Events
148
+ #### Gamepad Device Events
94
149
 
95
150
  | Event | Description | Payload |
96
151
  |---|---|---|
152
+ | `"group"` | `{groupName,button,buttonCode,device}` | A named input group button was pressed. |
97
153
  | **Button presses:** | | |
98
154
  | `"A"` \| `"B"` \| `"X"` \| ... 13 more ... | `{button,buttonCode,device}` | Button `"A"` was pressed. Equivalent to `0`. |
99
155
  | ... | ... | ... |
@@ -104,7 +160,41 @@ InputDevice.gamepads[0].on( "Back", () => showMenu() )
104
160
  > [!TIP]
105
161
  > **Multiplayer:** For multiple players, consider assigning devices
106
162
  > using `device.meta` (e.g. `device.meta.player = 1`) and use
107
- > `InputDevice.devices` to iterate through devices instead.
163
+ > `InputDevice.devices` to iterate through devices.
164
+
165
+ ### Navigation API
166
+
167
+ By default, any element with `"mousedown"` or `"pointerdown"` handlers is navigatable.
168
+
169
+ Container properties | type | default | description
170
+ ---------------------|------|---------|--------------
171
+ `isNavigatable` | `boolean` | `false` | returns `true` if `navigationMode` is set to `"target"`, or is `"auto"` and a `"pointerdown"` or `"mousedown"` event handler is registered.
172
+ `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.
173
+ `navigationPriority` | `number` | `0` | The priority relative to other navigation items in this group.
174
+
175
+ Navigation intent | Keyboard | Gamepads
176
+ ------------------|------------------------|-----------------------------------
177
+ `"navigateLeft"` | `ArrowLeft`, `KeyA` | Left Joystick (Left), `DPadLeft`
178
+ `"navigateRight"` | `ArrowRight`, `KeyD` | Left Joystick (Right), `DPadRight`
179
+ `"navigateUp"` | `ArrowUp`, `KeyW` | Left Joystick (Up), `DPadDown`
180
+ `"navigateDown"` | `ArrowDown`, `KeyS` | Left Joystick (Down), `DPadUp`
181
+ `"navigateBack"` | `Escape`, `Backspace` | `B`, `Back`
182
+ `"trigger"` | `Enter,` `Space` | `A`
183
+
184
+ Container events | description
185
+ ------------------|--------------------------------------------------------
186
+ `focus` | Target became focused.
187
+ `blur` | Target lost focus.
188
+
189
+ > [!TIP]
190
+ > Modify `device.options.navigation.binds` to override which keys/buttons are used for navigation.
191
+ >
192
+ > Or set `device.options.navigation.enabled = false` to disable navigation.
193
+
194
+
195
+ ### Devices
196
+
197
+ #### Gamepads
108
198
 
109
199
  ##### Gamepad Layouts
110
200
 
@@ -136,9 +226,9 @@ InputDevice.gamepads[0].on( "Back", () => showMenu() )
136
226
  >
137
227
  > Set `GamepadDevice.defaultOptions.remapNintendoMode` to apply the remapping as required.
138
228
  >
139
- > - `"physical"` _(default)_ &ndash A,B,X,Y refer the physical layout of a standard controller (Left=X,Top=Y,Bottom=A,Right=B).
140
- > - `"accurate"` &ndash A,B,X,Y refer to the exact Nintendo labels (Left=Y,Top=X,Bottom=B,Right=A).
141
- > - `"none"` &ndash A,B,X,Y refer to the button indices 0,1,2,3 (Left=Y,Top=B,Bottom=X,Right=A).
229
+ > - `"physical"` _(default)_ – A,B,X,Y refer the physical layout of a standard controller (Left=X,Top=Y,Bottom=A,Right=B).
230
+ > - `"accurate"` – A,B,X,Y refer to the exact Nintendo labels (Left=Y,Top=X,Bottom=B,Right=A).
231
+ > - `"none"` – A,B,X,Y refer to the button indices 0,1,2,3 (Left=Y,Top=B,Bottom=X,Right=A).
142
232
  >
143
233
  > ```
144
234
  > standard nintendo nintendo nintendo
@@ -154,19 +244,22 @@ InputDevice.gamepads[0].on( "Back", () => showMenu() )
154
244
  > 0 0 1 2
155
245
  > ```
156
246
 
157
- #### Assigning devices
247
+ #### Device assignment
248
+
249
+ You can assign IDs and other meta data using the `device.meta` dictionary.
158
250
 
159
251
  ```ts
160
- InputDevice.on("deviceconnected", ({ device }) => {
161
- device.meta.localPlayerId = 123
162
- })
252
+ InputDevice.on("deviceconnected", ({ device }) =>
253
+ // assign!
254
+ device.meta.localPlayerId = 123
255
+ )
163
256
 
164
257
  for ( const device of InputDevice.devices )
165
258
  {
166
- if ( device.meta.localPlayerId === 123 )
167
- {
168
- // do something
169
- }
259
+ if ( device.meta.localPlayerId === 123 )
260
+ {
261
+ // use assigned input device!
262
+ }
170
263
  }
171
264
  ```
172
265
 
@@ -178,41 +271,12 @@ You can add custom devices to the device manager:
178
271
  // 1. subclass CustomDevice
179
272
  class MySpecialDevice extends CustomDevice
180
273
  {
181
- constructor() {
182
- super( "special-device" )
183
- }
274
+ constructor() {
275
+ super( "special-device" )
276
+ }
184
277
  }
185
278
 
186
279
  // 2. add the device
187
- InputDevice.add( new MySpecialDevice() )
280
+ const device = new MySpecialDevice();
281
+ InputDevice.add( device )
188
282
  ```
189
-
190
- ### Navigation API
191
-
192
- By default, any element with `"mousedown"` or `"pointerdown"` handlers will be navigatable.
193
-
194
- Container properties | type | default | description
195
- ---------------------|------|---------|--------------
196
- `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.
197
- `isNavigatable` | `get () => boolean` | `false` | returns `true` if `navigationMode` is `"target"`, or `"auto"` and a `"pointerdown"` or `"mousedown"` event handler is registered.
198
- `navigationPriority` | `number` | `0` | The priority relative to other navigation items in this group.
199
-
200
- Navigation intent | Keyboard | Gamepads
201
- ------------------|------------------------|-----------------------------------
202
- `"navigateLeft"` | `ArrowLeft`, `KeyA` | Left Joystick (Left), `DPadLeft`
203
- `"navigateRight"` | `ArrowRight`, `KeyD` | Left Joystick (Right), `DPadRight`
204
- `"navigateUp"` | `ArrowUp`, `KeyW` | Left Joystick (Up), `DPadDown`
205
- `"navigateDown"` | `ArrowDown`, `KeyS` | Left Joystick (Down), `DPadUp`
206
- `"navigateBack"` | `Escape`, `Backspace` | `B`, `Back`
207
- `"trigger"` | `Enter,` `Space` | `A`
208
-
209
- Container events | description
210
- ------------------|--------------------------------------------------------
211
- `focus` | Target became focused.
212
- `blur` | Target lost focus.
213
-
214
-
215
- > [!TIP]
216
- > Modify `device.options.navigation.binds` to override which keys/buttons are used for navigation.
217
- >
218
- > Or set `device.options.navigation.enabled = false` to disable navigation.
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";const e=0,t=1,i=2,a=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:a=3}={}){return function chooseFirstNavigatableInDirection(e,t,i,{minimumDistance:a=3}={}){var o,n,s,r,d,u,c,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)=>e.navigationPriority-t.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!==(s=null===(n=f.filter((e=>e.center.y<y.y-a)).sort(((e,t)=>e.distSqrd-t.distSqrd))[0])||void 0===n?void 0:n.element)&&void 0!==s?s:m;case"navigateLeft":return null!==(d=null===(r=f.filter((e=>e.center.x<y.x-a)).sort(((e,t)=>e.distSqrd-t.distSqrd))[0])||void 0===r?void 0:r.element)&&void 0!==d?d:m;case"navigateRight":return null!==(c=null===(u=f.filter((e=>e.center.x>y.x+a)).sort(((e,t)=>e.distSqrd-t.distSqrd))[0])||void 0===u?void 0:u.element)&&void 0!==c?c:m;case"navigateDown":return null!==(h=null===(l=f.filter((e=>e.center.y>y.y+a)).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:a})}function squaredDist(e,t){const i=t.x-e.x,a=t.y-e.y;return i*i+a*a}class NavigationManager{constructor(){this.fallbackEffects=!0,this._responderStack=[]}get firstResponder(){return this._responderStack[0]}get responders(){return this._responderStack}commit(e,t){this._propagateIntent(e,t)}popResponder(){var e,t,i;const a=this._responderStack.shift();return null===(t=null===(e=this.firstResponder)||void 0===e?void 0:e.becameFirstResponder)||void 0===t||t.call(e),null===(i=null==a?void 0:a.resignedAsFirstResponder)||void 0===i||i.call(a),a}pushResponder(e){var t,i;if(this._responderStack.includes(e))throw new Error("Responder already in stack.");const a=this.firstResponder;this._responderStack.unshift(e),null===(t=e.becameFirstResponder)||void 0===t||t.call(e),null===(i=null==a?void 0:a.resignedAsFirstResponder)||void 0===i||i.call(a)}_propagateIntent(e,t){var i;for(const a of this._responderStack)if(null===(i=a.handledNavigationIntent)||void 0===i?void 0:i.call(a,e,t))return;void 0===this.stage?console.warn("navigation: no stage root set"):this._handleGlobalIntent(this.stage,e)}_handleGlobalIntent(e,t){var i;if(void 0===this._focused){const i=getFirstNavigatable(e);return void 0===i?void console.debug("navigation: no navigatable views found",t):(this._emitFocus(i),void(this._focused=i))}if("navigateBack"===t)return this._emitBlur(this._focused),void(this._focused=void 0);if("trigger"===t)return void this._emitTrigger(this._focused);const a=null!==(i=getFirstNavigatable(this.stage,this._focused,t))&&void 0!==i?i:this._focused;a!==this._focused&&(this._emitBlur(this._focused),this._emitFocus(a),this._focused=a)}_emitBlur(e){const t=e.eventNames();t.includes("pointerout")?e.emit("pointerout"):t.includes("mouseout")?e.emit("mouseout"):"auto"===e.navigationMode&&this.fallbackEffects&&(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.fallbackEffects&&(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.fallbackEffects&&(e.alpha=.75),e.emit("trigger")}}NavigationManager.global=new NavigationManager;const s=NavigationManager.global;let r=new Map;function throttle(e,t){var i;const a=Date.now();return(null!==(i=r.get(e))&&void 0!==i?i:0)>a||(r.set(e,a+t),!1)}class EventEmitter{constructor(){this.l={}}hasListener(e){return void 0!==this.l[e]}emit(e,t){var i;null===(i=this.l[e])||void 0===i||i.forEach((e=>e(t)))}on(e,t){var i;this.l[e]||(this.l[e]=[]),null===(i=this.l[e])||void 0===i||i.push(t)}off(e,t){var i,a;this.l[e]=void 0===t||null===(i=this.l[e])||void 0===i?void 0:i.filter((e=>e!==t)),0===(null===(a=this.l[e])||void 0===a?void 0:a.length)&&(this.l[e]=void 0)}}class GamepadDevice{get leftTrigger(){return this.source.buttons[o.LeftTrigger].value}get rightTrigger(){return this.source.buttons[o.RightTrigger].value}get leftShoulder(){return this.source.buttons[o.LeftShoulder].value}get rightShoulder(){return this.source.buttons[o.RightShoulder].value}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}playVibration({duration:e=200,weakMagnitude:t=.5,strongMagnitude:i=.5,vibrationType:a="dual-rumble",rightTrigger:o=0,leftTrigger:n=0,startDelay:s=0}={}){if(this.options.vibration.enabled&&this.source.vibrationActuator)try{this.source.vibrationActuator.playEffect(a,{duration:e,startDelay:s,weakMagnitude:t,strongMagnitude:i,leftTrigger:n,rightTrigger:o})}catch(e){console.warn("gamepad vibrationActuator failed with error:",e)}}update(e,t){this.lastUpdated=t,this.updatePresses(e),this.source=e}clear(){this._axisIntents=this._axisIntents.map((()=>!1)),this._btnPrevState=this._btnPrevState.map((()=>!1))}constructor(n){this.source=n,this.type="gamepad",this.meta={},this.lastUpdated=performance.now(),this.options=structuredClone(GamepadDevice.defaultOptions),this._btnPrevState=new Array(16),this._axisIntents=new Array(2),this._emitter=new EventEmitter,this.button=Object.keys(o).reduce(((e,t)=>(e[t]=!1,e)),{}),this.id="gamepad"+n.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"}(n),this.leftJoystick=new GamepadJoystick(this,e,t),this.rightJoystick=new GamepadJoystick(this,i,a),this._throttleIdLeftStickX=this.id+"-lsx",this._throttleIdLeftStickY=this.id+"-lsy"}updatePresses(i){var a,r,d,u,c;const l=this._btnPrevState.length;for(let e=0;e<l;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===(a=i.buttons[e])||void 0===a?void 0:a.pressed))continue;const u=null!==(d=null===(r=i.buttons[e])||void 0===r?void 0:r.pressed)&&void 0!==d&&d,c=n[t];this._btnPrevState[t]=u,this.button[c]=u,u&&(this._emitter.hasListener(c)?this._emitter.emit(c,{device:this,button:t,buttonCode:c}):this.options.navigation.enabled&&void 0!==this.options.navigation.binds[t]&&s.commit(this.options.navigation.binds[t],this))}const h=null!==(u=i.axes[e])&&void 0!==u?u:0,g=null!==(c=i.axes[t])&&void 0!==c?c:0;if(Math.abs(h)>=this.options.intent.joystickCommitSensitivity){const t=h<0?"navigateLeft":"navigateRight",i=this._axisIntents[e]?this.options.intent.defaultCooldownMs:this.options.intent.firstCooldownMs;this._axisIntents[e]=!0,this.options.navigation.enabled&&!throttle(this._throttleIdLeftStickX,i)&&s.commit(t,this)}else this._axisIntents[e]=!1;if(Math.abs(g)>=this.options.intent.joystickCommitSensitivity){const e=g<0?"navigateUp":"navigateDown",i=this._axisIntents[t]?this.options.intent.defaultCooldownMs:this.options.intent.firstCooldownMs;this._axisIntents[t]=!0,this.options.navigation.enabled&&!throttle(this._throttleIdLeftStickY,i)&&s.commit(e,this)}else this._axisIntents[t]=!1}}GamepadDevice.defaultOptions={remapNintendoMode:"physical",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"}},intent:{joystickCommitSensitivity:.5,firstCooldownMs:400,defaultCooldownMs:80},vibration:{enabled:!0,intensity:1}};class GamepadJoystick{constructor(e,t,i){this._owner=e,this.ix=t,this.iy=i}get x(){return this._owner.source.axes[this.ix]}get y(){return this._owner.source.axes[this.iy]}}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,a){return new(i||(i=Promise))((function(o,n){function fulfilled(e){try{step(a.next(e))}catch(e){n(e)}}function rejected(e){try{step(a.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((a=a.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const u=["fr","mg","lu"],c=["ab","ba","be","bg","ch","kk","ky","mk","mn","ru","sr","tg","tt","uk","uz"],l=["de","cs","sk","sl","hu","hr","bs","ro","sq","me","lt","lv","et"],h=/ф|и|с|в|у|а|п|р|ш|о|л|д|ь|т|щ|з|й|к|ы|е|г|м|ц|ч|н|я|ё|х|ъ|б|ю|э|ж|и/i,g=/[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 u.includes(i)||t.startsWith("nl-be")?"AZERTY":c.includes(i)?"JCUKEN":l.includes(i)||t.startsWith("sr-latn")?"QWERTZ":"QWERTY"}const p=new Set(["AZERTY","JCUKEN","QWERTY","QWERTZ"]);let m;function getMetaKeyLabel(){var e,t,i,a;const o=navigator,n=null!==(t=null===(e=o.platform)||void 0===e?void 0:e.toLowerCase())&&void 0!==t?t:"",s=null!==(a=null===(i=o.userAgent)||void 0===i?void 0:i.toLowerCase())&&void 0!==a?a:"";return n.includes("mac")?"⌘":n.includes("win")||n.includes("linux")?"⊞":s.includes("android")?"Search":s.includes("iphone")||s.includes("ipad")?"⌘":"⊞"}class KeyboardDevice{on(e,t){return this._emitter.on(e,t),this}off(e,t){return this._emitter.off(e,t),this}constructor(){this.type="keyboard",this.id="keyboard",this.meta={},this.lastUpdated=performance.now(),this.detectLayoutOnKeypress=!0,this.detected=!1,this._emitter=new EventEmitter,this.options={preventDefaultKeys:new Set([]),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._layoutSource="lang",this._layout=inferKeyboardLayoutFromLang(),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(),i=t.get("KeyQ"),a=t.get("KeyA"),o=t.get("KeyZ");if("a"===i&&"w"===o&&"q"===a)return"AZERTY";if("q"===i&&"y"===o&&"a"===a)return"QWERTZ";if("q"===i&&"z"===o&&"a"===a)return"QWERTY";if("й"===i&&"я"===o&&"ф"===a)return"JCUKEN"}catch(e){console.error("Error detecting keyboard layout:",e)}}))}().then((e=>{this._layoutSource="browser",this._layout=e,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}get layoutSource(){return this._layoutSource}configureEventListeners(){document.addEventListener("keydown",(e=>{const t=e.code;if(this.key[t]=!0,this.options.preventDefaultKeys.has(t)&&e.preventDefault(),this.detectLayoutOnKeypress&&"lang"===this._layoutSource){const t=function detectKeyboardLayoutFromKeydown(e){const t=e.key.toLowerCase(),i=e.code;return h.test(t)?(p.delete("AZERTY"),p.delete("QWERTY"),p.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?(p.delete("JCUKEN"),p.delete("QWERTY"),p.delete("QWERTZ")):"BracketLeft"===i&&"ü"===t||"BracketRight"===i&&"ö"===t||"KeyY"===i&&"z"===t||"KeyZ"===i&&"y"===t||"Slash"===i&&"-"===t?(p.delete("AZERTY"),p.delete("JCUKEN"),p.delete("QWERTY")):"BracketLeft"===i&&"["===t||"BracketRight"===i&&"]"===t||"KeyZ"===i&&"z"===t?(p.delete("AZERTY"),p.delete("JCUKEN"),p.delete("QWERTZ")):"KeyQ"===i&&"q"===t||"KeyW"===i&&"w"===t?(p.delete("AZERTY"),p.delete("JCUKEN")):"KeyY"===i&&"Y"===t?(p.delete("QWERTZ"),p.delete("JCUKEN")):g.test(t)&&p.delete("JCUKEN"),1===p.size?[...p][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.keyLabel(t),event:e}))):this.options.navigation.enabled&&void 0!==this.options.navigation.binds[t]&&(e.preventDefault(),setTimeout((()=>s.commit(this.options.navigation.binds[t],this))))})),document.addEventListener("keyup",(e=>{this.key[e.code]=!1,this.options.preventDefaultKeys.has(e.code)&&e.preventDefault()}))}keyLabel(e,t=this._layout){return function getLayoutLabel(e,t){if(void 0===m){const e={ArrowLeft:"←",ArrowRight:"→",ArrowUp:"↑",ArrowDown:"↓",AltLeft:"Left Alt",AltRight:"Right Alt",Backquote:"`",Backslash:"\\",Backspace:"Backspace",BracketLeft:"[",BracketRight:"]",CapsLock:"Caps Lock",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:"Mute",VolumeUp:"Volume Up",WakeUp:"Wake Up"},t=Object.assign(Object.assign({},e),{KeyA:"Q",KeyQ:"A",KeyW:"Z",KeyZ:"W",Backquote:"²",BracketLeft:"«",BracketRight:"»"}),i=Object.assign(Object.assign({},e),{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:"И"}),a=Object.assign(Object.assign({},e),{KeyY:"Z",KeyZ:"Y",BracketLeft:"ü",BracketRight:"ö",Slash:"-"});m={AZERTY:t,JCUKEN:i,QWERTY:e,QWERTZ:a}}return m[t][e]}(e,t)}clear(){for(const e of Object.keys(d))this.key[e]=!1}}KeyboardDevice.global=new KeyboardDevice;class InputDeviceManager{on(e,t){return this._emitter.on(e,t),this}off(e,t){return this._emitter.off(e,t),this}get gamepads(){return this._gamepadDevices}get devices(){return this._devices}constructor(){this._emitter=new EventEmitter,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.hasFocus=!1,this.options={clearInputInBackground:!0},this._gamepadDevices=[],this._gamepadDeviceMap=new Map,this._devices=[];const registerKeyboard=()=>{window.removeEventListener("keydown",registerKeyboard),this._devices.push(this.keyboard),this._emitter.emit("deviceadded",{device:this.keyboard}),this.keyboard.detected=!0};this.keyboard=KeyboardDevice.global,this.isTouchCapable||this.isMobile?window.addEventListener("keydown",registerKeyboard):registerKeyboard(),window.addEventListener("gamepadconnected",(()=>this.pollGamepads(performance.now()))),window.addEventListener("gamepaddisconnected",(e=>this.removeGamepad(e.gamepad.index)))}update(){if(!document.hasFocus())return this.hasFocus&&this.options.clearInputInBackground&&this.devices.forEach((e=>e.clear())),this.hasFocus=!1,this._devices;this.hasFocus=!0;const e=performance.now();return this.keyboard.lastUpdated=e,this.pollGamepads(e),this._devices}add(e){this._devices.push(e)}remove(e){const t=this._devices.indexOf(e);-1!==t&&(this._devices.splice(t,1),this._emitter.emit("deviceremoved",{device: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 e=new GamepadDevice(t);this._gamepadDeviceMap.set(t.index,e),this._gamepadDevices.push(e),this._devices.push(e),this._emitter.emit("deviceadded",{device: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 v=InputDeviceManager.global;exports.Button=o,exports.CustomDevice=class CustomDevice{constructor(e){this.type="custom",this.meta={},this.lastUpdated=performance.now(),this.id=e}clear(){}},exports.GamepadDevice=GamepadDevice,exports.InputDevice=v,exports.KeyCode=d,exports.KeyboardDevice=KeyboardDevice,exports.Navigation=s,exports.getAllNavigatables=getAllNavigatables,exports.getFirstNavigatable=getFirstNavigatable,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";class CustomDevice{constructor(e){this.type="custom",this.meta={},this.lastUpdated=performance.now(),this.id=e}clear(){}}const e=0,t=1,i=2,o=3,a={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},s=["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:o=3}={}){return function chooseFirstNavigatableInDirection(e,t,i,{minimumDistance:o=3}={}){var a,s,n,r,d,u,c,l,h;const p=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))),g=p.find((e=>e===t));if(void 0===g)return p.sort(((e,t)=>e.navigationPriority-t.navigationPriority)),p[0];if(void 0===i&&g)return g;const m=null!=g?g:p[Math.floor(Math.random()*p.length)];if(void 0===g)return null!==(a=e[0])&&void 0!==a?a:m;const v=g.getBounds(),y={x:v.left+v.width/2,y:v.top+v.height/2},f=p.filter((e=>e!==g)).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!==(n=null===(s=f.filter((e=>e.center.y<y.y-o)).sort(((e,t)=>e.distSqrd-t.distSqrd))[0])||void 0===s?void 0:s.element)&&void 0!==n?n:m;case"navigateLeft":return null!==(d=null===(r=f.filter((e=>e.center.x<y.x-o)).sort(((e,t)=>e.distSqrd-t.distSqrd))[0])||void 0===r?void 0:r.element)&&void 0!==d?d:m;case"navigateRight":return null!==(c=null===(u=f.filter((e=>e.center.x>y.x+o)).sort(((e,t)=>e.distSqrd-t.distSqrd))[0])||void 0===u?void 0:u.element)&&void 0!==c?c:m;case"navigateDown":return null!==(h=null===(l=f.filter((e=>e.center.y>y.y+o)).sort(((e,t)=>e.distSqrd-t.distSqrd))[0])||void 0===l?void 0:l.element)&&void 0!==h?h:m;default:return g}}(getAllNavigatables(e),t,i,{minimumDistance:o})}function squaredDist(e,t){const i=t.x-e.x,o=t.y-e.y;return i*i+o*o}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;const o=this._responderStack.shift();return null===(t=null===(e=this.firstResponder)||void 0===e?void 0:e.becameFirstResponder)||void 0===t||t.call(e),null===(i=null==o?void 0:o.resignedAsFirstResponder)||void 0===i||i.call(o),o}pushResponder(e){var t,i;if(this._responderStack.includes(e))throw new Error("Responder already in stack.");const o=this.firstResponder;this._responderStack.unshift(e),null===(t=e.becameFirstResponder)||void 0===t||t.call(e),null===(i=null==o?void 0:o.resignedAsFirstResponder)||void 0===i||i.call(o)}_propagateIntent(e,t){var i;for(const o of this._responderStack)if(null===(i=o.handledNavigationIntent)||void 0===i?void 0:i.call(o,e,t))return;void 0===this.stage?console.warn("navigation: no stage root set"):this._handleGlobalIntent(this.stage,e)}_handleGlobalIntent(e,t){var i;if(void 0===this._focused){const i=getFirstNavigatable(e);return void 0===i?void console.debug("navigation: no navigatable views found",t):(this._emitFocus(i),void(this._focused=i))}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!==(i=getFirstNavigatable(this.stage,this._focused,t))&&void 0!==i?i: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")}}NavigationManager.global=new NavigationManager;const n=NavigationManager.global;let r=new Map;function throttle(e,t){var i;const o=Date.now();return(null!==(i=r.get(e))&&void 0!==i?i:0)>o||(r.set(e,o+t),!1)}class EventEmitter{constructor(){this.l={}}hasListener(e){return void 0!==this.l[e]}emit(e,t){var i;null===(i=this.l[e])||void 0===i||i.forEach((e=>e(t)))}on(e,t){var i;this.l[e]||(this.l[e]=[]),null===(i=this.l[e])||void 0===i||i.push(t)}off(e,t){var i,o;this.l[e]=void 0===t||null===(i=this.l[e])||void 0===i?void 0:i.filter((e=>e!==t)),0===(null===(o=this.l[e])||void 0===o?void 0:o.length)&&(this.l[e]=void 0)}}class GamepadDevice{get leftTrigger(){return this.source.buttons[a.LeftTrigger].value}get rightTrigger(){return this.source.buttons[a.RightTrigger].value}get leftShoulder(){return this.source.buttons[a.LeftShoulder].value}get rightShoulder(){return this.source.buttons[a.RightShoulder].value}groupPressed(e){return void 0!==this.options.namedGroups[e]&&this.anyPressed(this.options.namedGroups[e])}anyPressed(e){for(let t=0;t<e.length;t++)if(this.button[e[t]])return!0;return!1}allPressed(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?s[e]:e;return this._emitter.on(i,t),this}off(e,t){const i="number"==typeof e?s[e]:e;return this._emitter.off(i,t),this}onGroup(e,t){return this._groupEmitter.on(e,t),this}offGroup(e,t){return this._groupEmitter.off(e,t),this}playVibration({duration:e=200,weakMagnitude:t=.5,strongMagnitude:i=.5,vibrationType:o="dual-rumble",rightTrigger:a=0,leftTrigger:s=0,startDelay:n=0}={}){if(this.options.vibration.enabled&&this.source.vibrationActuator)try{this.source.vibrationActuator.playEffect(o,{duration:e,startDelay:n,weakMagnitude:t,strongMagnitude:i,leftTrigger:s,rightTrigger:a})}catch(e){console.warn("gamepad vibrationActuator failed with error:",e)}}update(e,t){this.updatePresses(e,t),this.source=e,this.lastUpdated=t}clear(){this._axisIntents=this._axisIntents.map((()=>!1)),this._btnPrevState=this._btnPrevState.map((()=>!1))}constructor(s){this.source=s,this.type="gamepad",this.meta={},this.lastUpdated=performance.now(),this.lastActive=performance.now(),this.options=JSON.parse(JSON.stringify(GamepadDevice.defaultOptions)),this.button=Object.keys(a).reduce(((e,t)=>(e[t]=!1,e)),{}),this._btnPrevState=new Array(16),this._axisIntents=new Array(2),this._emitter=new EventEmitter,this._groupEmitter=new EventEmitter,this.id="gamepad"+s.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"}(s),this.leftJoystick=new GamepadJoystick(this,e,t),this.rightJoystick=new GamepadJoystick(this,i,o),this._throttleIdLeftStickX=this.id+"-lsx",this._throttleIdLeftStickY=this.id+"-lsy"}updatePresses(i,o){var r,d,u,c,l;const h=this._btnPrevState.length;for(let e=0;e<h;e++){let t=e;if("nintendo"===this.layout&&"none"!==this.options.remapNintendoMode&&("physical"===this.options.remapNintendoMode?t===a.B?t=a.A:t===a.A?t=a.B:t===a.X?t=a.Y:t===a.Y&&(t=a.X):t===a.B?t=a.X:t===a.X&&(t=a.B)),this._btnPrevState[t]===(null===(r=i.buttons[e])||void 0===r?void 0:r.pressed))continue;this.lastActive=o;const c=null!==(u=null===(d=i.buttons[e])||void 0===d?void 0:d.pressed)&&void 0!==u&&u,l=s[t];this._btnPrevState[t]=c,this.button[l]=c,c&&(this._emitter.hasListener(l)&&setTimeout((()=>this._emitter.emit(l,{device:this,button:t,buttonCode:l}))),n.options.enabled&&this.options.navigation.enabled&&void 0!==this.options.navigation.binds[t]&&setTimeout((()=>n.commit(this.options.navigation.binds[t],this))),Object.entries(this.options.namedGroups).forEach((([e,i])=>{i.includes(l)&&setTimeout((()=>{const i={device:this,button:t,buttonCode:l,groupName:e};this._groupEmitter.emit(e,i),this._emitter.emit("group",i)}))})))}const p=null!==(c=i.axes[e])&&void 0!==c?c:0,g=null!==(l=i.axes[t])&&void 0!==l?l:0;if(Math.abs(p)>=this.options.intent.joystickCommitSensitivity){const t=p<0?"navigateLeft":"navigateRight",i=this._axisIntents[e]?this.options.intent.defaultCooldownMs:this.options.intent.firstCooldownMs;this._axisIntents[e]=!0,this.options.navigation.enabled&&!throttle(this._throttleIdLeftStickX,i)&&setTimeout((()=>n.commit(t,this)))}else this._axisIntents[e]=!1;if(Math.abs(g)>=this.options.intent.joystickCommitSensitivity){const e=g<0?"navigateUp":"navigateDown",i=this._axisIntents[t]?this.options.intent.defaultCooldownMs:this.options.intent.firstCooldownMs;this._axisIntents[t]=!0,this.options.navigation.enabled&&!throttle(this._throttleIdLeftStickY,i)&&setTimeout((()=>n.commit(e,this)))}else this._axisIntents[t]=!1}}GamepadDevice.defaultOptions={remapNintendoMode:"physical",namedGroups:{},navigation:{enabled:!0,binds:{[a.A]:"trigger",[a.B]:"navigateBack",[a.Back]:"navigateBack",[a.DPadDown]:"navigateDown",[a.DPadLeft]:"navigateLeft",[a.DPadRight]:"navigateRight",[a.DPadUp]:"navigateUp"}},intent:{joystickCommitSensitivity:.5,firstCooldownMs:400,defaultCooldownMs:80},vibration:{enabled:!0,intensity:1}};class GamepadJoystick{constructor(e,t,i){this._owner=e,this.ix=t,this.iy=i}get x(){return this._owner.source.axes[this.ix]}get y(){return this._owner.source.axes[this.iy]}}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,o){return new(i||(i=Promise))((function(a,s){function fulfilled(e){try{step(o.next(e))}catch(e){s(e)}}function rejected(e){try{step(o.throw(e))}catch(e){s(e)}}function step(e){e.done?a(e.value):function adopt(e){return e instanceof i?e:new i((function(t){t(e)}))}(e.value).then(fulfilled,rejected)}step((o=o.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const u=["fr","mg","lu"],c=["ab","ba","be","bg","ch","kk","ky","mk","mn","ru","sr","tg","tt","uk","uz"],l=["de","cs","sk","sl","hu","hr","bs","ro","sq","me","lt","lv","et"],h=/ф|и|с|в|у|а|п|р|ш|о|л|д|ь|т|щ|з|й|к|ы|е|г|м|ц|ч|н|я|ё|х|ъ|б|ю|э|ж|и/i,p=/[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 u.includes(i)||t.startsWith("nl-be")?"AZERTY":c.includes(i)?"JCUKEN":l.includes(i)||t.startsWith("sr-latn")?"QWERTZ":"QWERTY"}const g=new Set(["AZERTY","JCUKEN","QWERTY","QWERTZ"]);let m;function getMetaKeyLabel(){var e,t,i,o;const a=navigator,s=null!==(t=null===(e=a.platform)||void 0===e?void 0:e.toLowerCase())&&void 0!==t?t:"",n=null!==(o=null===(i=a.userAgent)||void 0===i?void 0:i.toLowerCase())&&void 0!==o?o:"";return s.includes("mac")?"⌘":s.includes("win")||s.includes("linux")?"⊞":n.includes("android")?"Search":n.includes("iphone")||n.includes("ipad")?"⌘":"⊞"}class KeyboardDevice{constructor(){this.type="keyboard",this.id="keyboard",this.meta={},this.lastUpdated=performance.now(),this.detectLayoutOnKeypress=!0,this.detected=!1,this.options={namedGroups:{},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._groupEmitter=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(),i=t.get("KeyQ"),o=t.get("KeyA"),a=t.get("KeyZ");if("a"===i&&"w"===a&&"q"===o)return"AZERTY";if("q"===i&&"y"===a&&"a"===o)return"QWERTZ";if("q"===i&&"z"===a&&"a"===o)return"QWERTY";if("й"===i&&"я"===a&&"ф"===o)return"JCUKEN"}catch(e){console.error("Error detecting keyboard layout:",e)}}))}().then((e=>{void 0!==e&&(this._layoutSource="browser",this._layout=e,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}get layoutSource(){return this._layoutSource}groupPressed(e){return void 0!==this.options.namedGroups[e]&&this.anyPressed(this.options.namedGroups[e])}anyPressed(e){for(let t=0;t<e.length;t++)if(this.key[e[t]])return!0;return!1}allPressed(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}onGroup(e,t){return this._groupEmitter.on(e,t),this}offGroup(e,t){return this._groupEmitter.off(e,t),this}keyLabel(e,t=this._layout){return function getLayoutLabel(e,t){if(void 0===m){const e={ArrowLeft:"←",ArrowRight:"→",ArrowUp:"↑",ArrowDown:"↓",AltLeft:"Left Alt",AltRight:"Right Alt",Backquote:"`",Backslash:"\\",Backspace:"Backspace",BracketLeft:"[",BracketRight:"]",CapsLock:"Caps Lock",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:"Mute",VolumeUp:"Volume Up",WakeUp:"Wake Up"},t=Object.assign(Object.assign({},e),{KeyA:"Q",KeyQ:"A",KeyW:"Z",KeyZ:"W",Backquote:"²",BracketLeft:"«",BracketRight:"»"}),i=Object.assign(Object.assign({},e),{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:"И"}),o=Object.assign(Object.assign({},e),{KeyY:"Z",KeyZ:"Y",BracketLeft:"ü",BracketRight:"ö",Slash:"-"});m={AZERTY:t,JCUKEN:i,QWERTY:e,QWERTZ:o}}return m[t][e]}(e,t)}update(e){this._deferredKeydown.length>0&&(this._deferredKeydown.forEach((e=>this._processDeferredKeydownEvent(e))),this._deferredKeydown.length=0),this.lastUpdated=e}clear(){for(const e of Object.keys(d))this.key[e]=!1}_configureEventListeners(){const e=this.key,t=this._deferredKeydown;window.addEventListener("keydown",(e=>t.push(e)),{passive:!0,capture:!0}),window.addEventListener("keyup",(t=>e[t.code]=!1),{passive:!0,capture:!0})}_processDeferredKeydownEvent(e){const t=e.code;if(this.key[t]=!0,this.detectLayoutOnKeypress&&"lang"===this._layoutSource){const t=function detectKeyboardLayoutFromKeydown(e){const t=e.key.toLowerCase(),i=e.code;return h.test(t)?(g.delete("AZERTY"),g.delete("QWERTY"),g.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?(g.delete("JCUKEN"),g.delete("QWERTY"),g.delete("QWERTZ")):"BracketLeft"===i&&"ü"===t||"BracketRight"===i&&"ö"===t||"KeyY"===i&&"z"===t||"KeyZ"===i&&"y"===t||"Slash"===i&&"-"===t?(g.delete("AZERTY"),g.delete("JCUKEN"),g.delete("QWERTY")):"BracketLeft"===i&&"["===t||"BracketRight"===i&&"]"===t||"KeyZ"===i&&"z"===t?(g.delete("AZERTY"),g.delete("JCUKEN"),g.delete("QWERTZ")):"KeyQ"===i&&"q"===t||"KeyW"===i&&"w"===t?(g.delete("AZERTY"),g.delete("JCUKEN")):"KeyY"===i&&"Y"===t?(g.delete("QWERTZ"),g.delete("JCUKEN")):p.test(t)&&g.delete("JCUKEN"),1===g.size?[...g][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.keyLabel(t),event:e}))),n.options.enabled&&this.options.navigation.enabled&&void 0!==this.options.navigation.binds[t]&&setTimeout((()=>n.commit(this.options.navigation.binds[t],this))),Object.entries(this.options.namedGroups).forEach((([i,o])=>{o.includes(t)&&setTimeout((()=>{const o={device:this,keyCode:t,keyLabel:this.keyLabel(t),event:e,groupName:i};this._groupEmitter.emit(i,o),this._emitter.emit("group",o)}))}))}}KeyboardDevice.global=new KeyboardDevice;class InputDeviceManager{constructor(){this._emitter=new EventEmitter,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.hasFocus=!1,this.options={clearInputInBackground:!0},this._gamepadDevices=[],this._gamepadDeviceMap=new Map,this._customDevices=[],this._groupEmitter=new EventEmitter,this._devices=[];const registerKeyboard=()=>{this.add(this.keyboard)};this.keyboard=KeyboardDevice.global,this.isTouchCapable||this.isMobile?window.addEventListener("keydown",registerKeyboard,{once:!0}):registerKeyboard(),window.addEventListener("gamepadconnected",(()=>this.pollGamepads(performance.now()))),window.addEventListener("gamepaddisconnected",(e=>this.removeGamepad(e.gamepad.index)))}get gamepads(){return this._gamepadDevices}get devices(){return this._devices}on(e,t){return this._emitter.on(e,t),this}off(e,t){return this._emitter.off(e,t),this}onGroup(e,t){return this._groupEmitter.on(e,t),this}offGroup(e,t){return this._groupEmitter.off(e,t),this}add(e){this._devices.push(e),e instanceof KeyboardDevice?(e.detected=!0,e.on("group",(e=>this._groupEmitter.emit(e.groupName,e)))):e instanceof GamepadDevice?(this._gamepadDeviceMap.set(e.source.index,e),this._gamepadDevices.push(e),e.on("group",(e=>this._groupEmitter.emit(e.groupName,e)))):e instanceof CustomDevice&&this._customDevices.push(e),this._emitter.emit("deviceadded",{device:e})}remove(e){if(e instanceof CustomDevice){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(!document.hasFocus())return this.hasFocus&&this.options.clearInputInBackground&&this.devices.forEach((e=>e.clear())),this.hasFocus=!1,this._devices;this.hasFocus=!0;const e=performance.now();return this.keyboard.update(e),this.pollGamepads(e),this._customDevices.length>0&&this._customDevices.forEach((t=>t.update(e))),this._devices}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 v=InputDeviceManager.global;exports.Button=a,exports.CustomDevice=CustomDevice,exports.GamepadDevice=GamepadDevice,exports.InputDevice=v,exports.KeyCode=d,exports.KeyboardDevice=KeyboardDevice,exports.Navigation=n,exports.getAllNavigatables=getAllNavigatables,exports.getFirstNavigatable=getFirstNavigatable,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})};
2
2
  //# sourceMappingURL=index.cjs.map