pixijs-input-devices 0.1.3 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -44,6 +44,94 @@ declare class GamepadJoystick {
44
44
  /** A scalar -1.0 to 1.0 representing the Y-axis position on the stick */
45
45
  get y(): number;
46
46
  }
47
+ declare class InputDeviceManager {
48
+ static global: InputDeviceManager;
49
+ readonly keyboard: KeyboardDevice;
50
+ private readonly _emitter;
51
+ /** Whether we are a mobile device (including tablets) */
52
+ readonly isMobile: boolean;
53
+ /** Whether a touchscreen is available */
54
+ readonly isTouchCapable: boolean;
55
+ /** Add an event listener */
56
+ on<K extends keyof InputDeviceEvent>(event: K, listener: (event: InputDeviceEvent[K]) => void): this;
57
+ /** Remove an event listener (or all if none provided) */
58
+ off<K extends keyof InputDeviceEvent>(event: K, listener: (event: InputDeviceEvent[K]) => void): this;
59
+ private hasFocus;
60
+ /**
61
+ * Connected gamepads accessible by index.
62
+ *
63
+ * Keep in mind these inputs are only up-to-date from the last update().
64
+ */
65
+ get gamepads(): readonly GamepadDevice[];
66
+ /**
67
+ * Connected devices.
68
+ *
69
+ * Keep in mind these inputs may only be up-to-date from the last update().
70
+ */
71
+ get devices(): readonly Device[];
72
+ options: {
73
+ clearInputInBackground: boolean;
74
+ };
75
+ private _devices;
76
+ private _gamepadDevices;
77
+ private _gamepadDeviceMap;
78
+ private constructor();
79
+ /**
80
+ * Performs a poll of latest input from all devices
81
+ */
82
+ update(): ReadonlyArray<Device>;
83
+ /** Add a custom device. */
84
+ add(device: CustomDevice): void;
85
+ /** Remove a custom device. */
86
+ remove(device: Device): void;
87
+ /**
88
+ * @returns updates connected gamepads, performing a poll of latest input
89
+ */
90
+ pollGamepads(now: number): ReadonlyArray<GamepadDevice>;
91
+ private removeGamepad;
92
+ }
93
+ declare class NavigationManager {
94
+ static global: NavigationManager;
95
+ /**
96
+ * Set the stage root to automatically handle global
97
+ * navigation intents.
98
+ */
99
+ stage?: Container;
100
+ /**
101
+ * When enabled, if no pointover/mouseover listeners
102
+ * exist, a default effect will be used instead.
103
+ */
104
+ fallbackEffects: boolean;
105
+ private _focused?;
106
+ private _responderStack;
107
+ private constructor();
108
+ /**
109
+ * Active global interaction target
110
+ */
111
+ get firstResponder(): NavigationResponder | undefined;
112
+ /**
113
+ * Stack of global interaction targets
114
+ */
115
+ get responders(): readonly NavigationResponder[];
116
+ /**
117
+ * Emit interaction intent to the first responder,
118
+ * or the global responder if none.
119
+ */
120
+ commit(intent: NavigationIntent, device: Device): void;
121
+ /**
122
+ * Remove the top-most global interaction target
123
+ */
124
+ popResponder(): NavigationResponder | undefined;
125
+ /**
126
+ * Set the new top-most global interaction target.
127
+ */
128
+ pushResponder(responder: NavigationResponder): void;
129
+ private _propagateIntent;
130
+ private _handleGlobalIntent;
131
+ private _emitBlur;
132
+ private _emitFocus;
133
+ private _emitTrigger;
134
+ }
47
135
  declare const ButtonCode: readonly [
48
136
  "A",
49
137
  "B",
@@ -65,11 +153,23 @@ declare const ButtonCode: readonly [
65
153
  export declare abstract class CustomDevice {
66
154
  readonly id: string;
67
155
  readonly type = "custom";
68
- assignee?: any;
156
+ /**
157
+ * Associate custom meta data with a device.
158
+ */
159
+ readonly meta: Record<string, any>;
69
160
  lastUpdated: number;
70
161
  constructor(id: string);
71
- update(now: number): void;
162
+ /**
163
+ * (Optional) Clear input.
164
+ *
165
+ * This method is triggered when the window is
166
+ * moved to background.
167
+ */
72
168
  clear(): void;
169
+ /**
170
+ * Triggered during the polling function.
171
+ */
172
+ abstract update(now: number): void;
73
173
  }
74
174
  /**
75
175
  * A gamepad (game controller).
@@ -83,7 +183,21 @@ export declare abstract class CustomDevice {
83
183
  export declare class GamepadDevice {
84
184
  source: Gamepad;
85
185
  static defaultOptions: {
86
- navigationalBinds: Partial<Record<Button, NavigationIntent>>;
186
+ /**
187
+ * When set to `"physical"` _(default)_, ABXY refer to the equivalent
188
+ * positions on a standard layout controller.
189
+ *
190
+ * When set to `"accurate"`, ABXY refer to the ABXY buttons on a Nintendo
191
+ * controller.
192
+ *
193
+ * When set to `"none"`, ABXY refer to the unmapped buttons in the 0, 1,
194
+ * 2, and 3 positions respectively.
195
+ */
196
+ remapNintendoMode: RemapNintendoMode;
197
+ navigation: {
198
+ enabled: boolean;
199
+ binds: Partial<Record<Button, NavigationIntent>>;
200
+ };
87
201
  intent: {
88
202
  joystickCommitSensitivity: number;
89
203
  firstCooldownMs: number;
@@ -101,16 +215,16 @@ export declare class GamepadDevice {
101
215
  readonly id: string;
102
216
  readonly type = "gamepad";
103
217
  /**
104
- * Associate custom metadata with a device.
218
+ * Associate custom meta data with a device.
105
219
  */
106
- meta: Record<string, any>;
220
+ readonly meta: Record<string, any>;
107
221
  lastUpdated: number;
108
222
  /**
109
223
  * Platform of this gamepad, useful for configuring standard
110
224
  * button layouts or displaying branded icons.
111
225
  * @example "playstation"
112
226
  */
113
- platform: GamepadPlatform;
227
+ layout: GamepadLayout;
114
228
  options: typeof GamepadDevice.defaultOptions;
115
229
  private _btnPrevState;
116
230
  private _axisIntents;
@@ -129,8 +243,8 @@ export declare class GamepadDevice {
129
243
  get rightShoulder(): number;
130
244
  /** Add an event listener */
131
245
  on<K extends keyof GamepadDeviceEvent>(event: K, listener: (event: GamepadDeviceEvent[K]) => void): this;
132
- /** Remove an event listener */
133
- off<K extends keyof GamepadDeviceEvent>(event: K, listener: (event: GamepadDeviceEvent[K]) => void): this;
246
+ /** Remove an event listener (or all if none provided). */
247
+ off<K extends keyof GamepadDeviceEvent>(event: K, listener?: (event: GamepadDeviceEvent[K]) => void): this;
134
248
  /** Accessors for buttons */
135
249
  button: Record<ButtonCode, boolean>;
136
250
  /**
@@ -145,60 +259,14 @@ export declare class GamepadDevice {
145
259
  constructor(source: Gamepad);
146
260
  private updatePresses;
147
261
  }
148
- export declare class InputDevice {
149
- static readonly shared: InputDevice;
150
- static keyboard: KeyboardDevice;
151
- static gamepads: readonly GamepadDevice[];
152
- static devices: readonly Device[];
153
- static update: () => ReadonlyArray<Device>;
154
- readonly keyboard: KeyboardDevice;
155
- private readonly _emitter;
156
- /** Add an event listener */
157
- on<K extends keyof InputDeviceEvent>(event: K, listener: (event: InputDeviceEvent[K]) => void): this;
158
- /** Remove an event listener */
159
- off<K extends keyof InputDeviceEvent>(event: K, listener: (event: InputDeviceEvent[K]) => void): this;
160
- private hasFocus;
161
- /**
162
- * Connected gamepads accessible by index.
163
- *
164
- * Keep in mind these inputs are only up-to-date from the last update().
165
- */
166
- get gamepads(): readonly GamepadDevice[];
167
- /**
168
- * Connected devices.
169
- *
170
- * Keep in mind these inputs may only be up-to-date from the last update().
171
- */
172
- get devices(): readonly Device[];
173
- options: {
174
- clearInputInBackground: boolean;
175
- };
176
- private _devices;
177
- private _gamepadDevices;
178
- private _gamepadDeviceMap;
179
- private constructor();
180
- /**
181
- * Performs a poll of latest input from all devices
182
- */
183
- update(): ReadonlyArray<Device>;
184
- /** Add a custom device. */
185
- add(device: CustomDevice): void;
186
- /** Remove a custom device. */
187
- remove(device: Device): void;
188
- /**
189
- * @returns updates connected gamepads, performing a poll of latest input
190
- */
191
- pollGamepads(now: number): ReadonlyArray<GamepadDevice>;
192
- private removeGamepad;
193
- }
194
262
  export declare class KeyboardDevice {
195
263
  static global: KeyboardDevice;
196
- readonly type: "keyboard";
197
- readonly id: "keyboard";
264
+ readonly type = "keyboard";
265
+ readonly id = "keyboard";
198
266
  /**
199
- * Associate custom metadata with a device.
267
+ * Associate custom meta data with a device.
200
268
  */
201
- meta: Record<string, any>;
269
+ readonly meta: Record<string, any>;
202
270
  lastUpdated: number;
203
271
  /**
204
272
  * Detect layout from keypresses.
@@ -207,17 +275,26 @@ export declare class KeyboardDevice {
207
275
  * layout can be determined.
208
276
  */
209
277
  detectLayoutOnKeypress: boolean;
278
+ /**
279
+ * Keyboard has been detected.
280
+ */
281
+ detected: boolean;
210
282
  private _layout;
211
283
  private _layoutSource;
212
284
  private _emitter;
285
+ /** Add an event listener. */
213
286
  on<K extends keyof KeyboardDeviceEvent>(event: K, listener: (event: KeyboardDeviceEvent[K]) => void): this;
287
+ /** Remove an event listener (or all if none provided). */
214
288
  off<K extends keyof KeyboardDeviceEvent>(event: K, listener: (event: KeyboardDeviceEvent[K]) => void): this;
215
289
  options: {
216
290
  /**
217
291
  * Keys to prevent default event propagation for.
218
292
  */
219
293
  preventDefaultKeys: Set<KeyCode>;
220
- navigationBinds: Partial<Record<KeyCode, NavigationIntent>>;
294
+ navigation: {
295
+ enabled: boolean;
296
+ binds: Partial<Record<KeyCode, NavigationIntent>>;
297
+ };
221
298
  };
222
299
  private constructor();
223
300
  /**
@@ -261,53 +338,6 @@ export declare class KeyboardDevice {
261
338
  */
262
339
  clear(): void;
263
340
  }
264
- /**
265
- * Responsible for global navigation interactions.
266
- *
267
- * Set stageRoot to enable the global responder behaviors.
268
- */
269
- export declare class Navigation {
270
- static shared: Navigation;
271
- /**
272
- * Set the stage root to automatically handle global
273
- * navigation intents.
274
- */
275
- stageRoot?: Container;
276
- /**
277
- * When enabled, if no pointover/mouseover listeners
278
- * exist, a default effect will be used instead.
279
- */
280
- fallbackEffects: boolean;
281
- private _focused?;
282
- private _responderStack;
283
- private constructor();
284
- /**
285
- * Active global interaction target
286
- */
287
- get firstResponder(): NavigationResponder | undefined;
288
- /**
289
- * Stack of global interaction targets
290
- */
291
- get responders(): readonly NavigationResponder[];
292
- /**
293
- * Emit interaction intent to the first responder,
294
- * or the global responder if none.
295
- */
296
- commit(intent: NavigationIntent, device: Device): void;
297
- /**
298
- * Remove the top-most global interaction target
299
- */
300
- popResponder(): NavigationResponder | undefined;
301
- /**
302
- * Set the new top-most global interaction target.
303
- */
304
- pushResponder(responder: NavigationResponder): void;
305
- private _propagateIntent;
306
- private _handleGlobalIntent;
307
- private _emitBlur;
308
- private _emitFocus;
309
- private _emitTrigger;
310
- }
311
341
  export declare const Button: {
312
342
  /** A Button (Xbox / Nintendo: "A", PlayStation: "Cross") */
313
343
  readonly A: 0;
@@ -325,9 +355,9 @@ export declare const Button: {
325
355
  readonly LeftTrigger: 6;
326
356
  /** Right Trigger (Xbox: "RT", PlayStation: "R2", Nintendo: "ZR") */
327
357
  readonly RightTrigger: 7;
328
- /** Bak Button (Xbox: "Share", PlayStation: "Options", Nintendo: "-") */
358
+ /** Back Button (Xbox: "Back", PlayStation: "Share", Nintendo: "Minus") */
329
359
  readonly Back: 8;
330
- /** Start Button (Xbox: "Start", PlayStation: "Select", Nintendo: "+") */
360
+ /** Start Button (Xbox: "Start", PlayStation: "Options", Nintendo: "Plus") */
331
361
  readonly Start: 9;
332
362
  /** Left Stick Press (Xbox / PlayStation: "LS", Nintendo: "L3") */
333
363
  readonly LeftStick: 10;
@@ -342,6 +372,7 @@ export declare const Button: {
342
372
  /** D-Pad Right */
343
373
  readonly DPadRight: 15;
344
374
  };
375
+ export declare const InputDevice: InputDeviceManager;
345
376
  export declare const KeyCode: {
346
377
  readonly AltLeft: "AltLeft";
347
378
  readonly AltRight: "AltRight";
@@ -476,6 +507,12 @@ export declare const KeyCode: {
476
507
  readonly VolumeUp: "VolumeUp";
477
508
  readonly WakeUp: "WakeUp";
478
509
  };
510
+ /**
511
+ * Responsible for global navigation interactions.
512
+ *
513
+ * Set stage to enable the global responder behaviors.
514
+ */
515
+ export declare const Navigation: NavigationManager;
479
516
  /**
480
517
  * @returns all navigatable containers in some container
481
518
  */
@@ -506,16 +543,16 @@ export interface InputDeviceEvent {
506
543
  };
507
544
  }
508
545
  export interface KeyboardDeviceKeydownEvent {
546
+ event: KeyboardEvent;
509
547
  device: KeyboardDevice;
510
548
  keyCode: KeyCode;
511
549
  /** Layout-specific label for key. @example "Ц" // JCUKEN for "KeyW" */
512
- label: string;
513
- event: KeyboardEvent;
550
+ keyLabel: string;
514
551
  }
515
552
  export interface KeyboardDeviceLayoutUpdatedEvent {
516
553
  device: KeyboardDevice;
517
554
  layout: KeyboardLayout;
518
- source: KeyboardLayoutSource;
555
+ layoutSource: KeyboardLayoutSource;
519
556
  }
520
557
  /**
521
558
  * A target that responds to navigation on the stack.
@@ -555,12 +592,6 @@ export type GamepadDeviceEvent = {} & {
555
592
  export type GamepadDeviceSource = {
556
593
  source: Gamepad;
557
594
  };
558
- /**
559
- * Common gamepad platforms, which may indicate button layout.
560
- *
561
- * Note: Non-comprehensive list, covers the most brands only.
562
- */
563
- export type GamepadPlatform = "logitech" | "nintendo" | "playstation" | "steam" | "xbox" | "other";
564
595
  export type GamepadVibration = GamepadEffectParameters & {
565
596
  vibrationType?: GamepadHapticEffectType;
566
597
  };
@@ -576,5 +607,16 @@ export type NavigatableContainer = Container;
576
607
  export type NavigationDirection = "navigateLeft" | "navigateRight" | "navigateUp" | "navigateDown";
577
608
  export type NavigationIntent = "navigateBack" | "navigateDown" | "navigateLeft" | "navigateRight" | "navigateUp" | "trigger";
578
609
  export type NavigationTargetEvent = "focus" | "blur";
610
+ export type RemapNintendoMode = "none" | "accurate" | "physical";
611
+ /**
612
+ * Common gamepad platform layouts, which may indicate button layout.
613
+ *
614
+ * Note: Non-comprehensive list, covers the most brands only.
615
+ */
616
+ type GamepadLayout = "logitech" | "nintendo" | "playstation" | "steam" | "xbox" | "generic";
617
+
618
+ export {
619
+ GamepadLayout as GamepadPlatform,
620
+ };
579
621
 
580
622
  export {};
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- class CustomDevice{constructor(e){this.id=e,this.type="custom",this.lastUpdated=performance.now()}update(e){}clear(){}}const e=0,t=1,i=2,a=3,s={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},o=["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 s,o,n,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!==(s=e[0])&&void 0!==s?s: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!==(n=null===(o=f.filter((e=>e.center.y<y.y-a)).sort(((e,t)=>e.distSqrd-t.distSqrd))[0])||void 0===o?void 0:o.element)&&void 0!==n?n: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 Navigation{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.stageRoot?console.warn("navigation: no stageRoot set"):this._handleGlobalIntent(this.stageRoot,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.stageRoot,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")}}Navigation.shared=new Navigation;let n=new Map;function throttle(e,t){var i;const a=Date.now();return(null!==(i=n.get(e))&&void 0!==i?i:0)>a||(n.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;this.l[e]=null===(i=this.l[e])||void 0===i?void 0:i.filter((e=>e!==t)),0===this.l[e].length&&(this.l[e]=void 0)}}class GamepadDevice{get leftTrigger(){return this.source.buttons[s.LeftTrigger].value}get rightTrigger(){return this.source.buttons[s.LeftTrigger].value}get leftShoulder(){return this.source.buttons[s.LeftShoulder].value}get rightShoulder(){return this.source.buttons[s.RightShoulder].value}on(e,t){const i="number"==typeof e?o[e]:e;return this._emitter.on(i,t),this}off(e,t){const i="number"==typeof e?o[e]:e;return this._emitter.off(i,t),this}playVibration({duration:e=200,weakMagnitude:t=.5,strongMagnitude:i=.5,vibrationType:a="dual-rumble",rightTrigger:s=0,leftTrigger:o=0,startDelay:n=0}={}){if(this.options.vibration.enabled&&this.source.vibrationActuator)try{this.source.vibrationActuator.playEffect(a,{duration:e,startDelay:n,weakMagnitude:t,strongMagnitude:i,leftTrigger:o,rightTrigger:s})}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(o){this.source=o,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(s).reduce(((e,t)=>(e[t]=!1,e)),{}),this.id="gamepad"+o.index,this.platform=function detectPlatform(e){const t=(e.id||"").toLowerCase();return/(logitech|046d)/.test(t)?"logitech":/(steam|28de)/.test(t)?"steam":/(dualshock|dualsense|sony|054c|0ce6|0810)/.test(t)?"playstation":/(nintendo|switch|joycon|057e)/.test(t)?"nintendo":/(xbox|xinput|045e|028e|0291|02a0|02a1|02ea|02ff)/.test(t)?"xbox":"other"}(o),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,s,n,r,d,u;const c=this._btnPrevState.length;for(let e=0;e<c;e++){if(this._btnPrevState[e]===(null===(a=i.buttons[e])||void 0===a?void 0:a.pressed))continue;const t=null!==(n=null===(s=i.buttons[e])||void 0===s?void 0:s.pressed)&&void 0!==n&&n,d=o[e];if(this._btnPrevState[e]=t,this.button[d]=t,t)if(this._emitter.hasListener(d))this._emitter.emit(d,{device:this,button:e,buttonCode:d});else{const t=null!==(r=this.options.navigationalBinds[e])&&void 0!==r?r:void 0;void 0!==t&&Navigation.shared.commit(t,this)}}const l=null!==(d=i.axes[e])&&void 0!==d?d:0,h=null!==(u=i.axes[t])&&void 0!==u?u:0;if(Math.abs(l)>=this.options.intent.joystickCommitSensitivity){const t=l<0?"navigateLeft":"navigateRight",i=this._axisIntents[e]?this.options.intent.defaultCooldownMs:this.options.intent.firstCooldownMs;this._axisIntents[e]=!0,throttle(this._throttleIdLeftStickX,i)||Navigation.shared.commit(t,this)}else this._axisIntents[e]=!1;if(Math.abs(h)>=this.options.intent.joystickCommitSensitivity){const e=h<0?"navigateUp":"navigateDown",i=this._axisIntents[t]?this.options.intent.defaultCooldownMs:this.options.intent.firstCooldownMs;this._axisIntents[t]=!0,throttle(this._throttleIdLeftStickY,i)||Navigation.shared.commit(e,this)}else this._axisIntents[t]=!1}}GamepadDevice.defaultOptions={navigationalBinds:{[s.A]:"trigger",[s.B]:"navigateBack",[s.Back]:"navigateBack",[s.DPadDown]:"navigateDown",[s.DPadLeft]:"navigateLeft",[s.DPadRight]:"navigateRight",[s.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 r={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(s,o){function fulfilled(e){try{step(a.next(e))}catch(e){o(e)}}function rejected(e){try{step(a.throw(e))}catch(e){o(e)}}function step(e){e.done?s(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 d=["fr","mg","lu"],u=["ab","ba","be","bg","ch","kk","ky","mk","mn","ru","sr","tg","tt","uk","uz"],c=["de","cs","sk","sl","hu","hr","bs","ro","sq","me","lt","lv","et"],l=/ф|и|с|в|у|а|п|р|ш|о|л|д|ь|т|щ|з|й|к|ы|е|г|м|ц|ч|н|я|ё|х|ъ|б|ю|э|ж|и/i,h=/[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 d.includes(i)||t.startsWith("nl-be")?"AZERTY":u.includes(i)?"JCUKEN":c.includes(i)||t.startsWith("sr-latn")?"QWERTZ":"QWERTY"}const g=new Set(["AZERTY","JCUKEN","QWERTY","QWERTZ"]);let p;function getMetaKeyLabel(){var e,t,i,a;const s=navigator,o=null!==(t=null===(e=s.platform)||void 0===e?void 0:e.toLowerCase())&&void 0!==t?t:"",n=null!==(a=null===(i=s.userAgent)||void 0===i?void 0:i.toLowerCase())&&void 0!==a?a:"";return o.includes("mac")?"⌘":o.includes("win")||o.includes("linux")?"⊞":n.includes("android")?"Search":n.includes("iphone")||n.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.meta={},this.lastUpdated=performance.now(),this.detectLayoutOnKeypress=!0,this._emitter=new EventEmitter,this.options={preventDefaultKeys:new Set([]),navigationBinds:{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(r).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"),s=t.get("KeyZ");if("a"===i&&"w"===s&&"q"===a)return"AZERTY";if("q"===i&&"y"===s&&"a"===a)return"QWERTZ";if("q"===i&&"z"===s&&"a"===a)return"QWERTY";if("й"===i&&"я"===s&&"ф"===a)return"JCUKEN"}catch(e){console.error("Error detecting keyboard layout:",e)}}))}().then((e=>{this._layoutSource="browser",this._layout=e,this._emitter.emit("layoutdetected",{source:"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 l.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")):h.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",{source:"keypress",layout:t,device:this}))}this._emitter.hasListener(t)?setTimeout((()=>this._emitter.emit(t,{device:this,keyCode:t,label:this.keyLabel(t),event:e}))):void 0!==this.options.navigationBinds[t]&&(e.preventDefault(),setTimeout((()=>Navigation.shared.commit(this.options.navigationBinds[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===p){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:"-"});p={AZERTY:t,JCUKEN:i,QWERTY:e,QWERTZ:a}}return p[t][e]}(e,t)}clear(){for(const e of Object.keys(r))this.key[e]=!1}}var m;KeyboardDevice.global=new KeyboardDevice;class InputDevice{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.hasFocus=!1,this.options={clearInputInBackground:!0},this._gamepadDevices=[],this._gamepadDeviceMap=new Map,this.keyboard=KeyboardDevice.global,window.addEventListener("gamepadconnected",(()=>this.pollGamepads(performance.now()))),window.addEventListener("gamepaddisconnected",(e=>this.removeGamepad(e.gamepad.index))),this._devices=[this.keyboard]}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)}}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})}m=InputDevice,InputDevice.shared=new InputDevice,InputDevice.keyboard=m.shared.keyboard,InputDevice.gamepads=m.shared.gamepads,InputDevice.devices=m.shared.devices,InputDevice.update=m.shared.update;export{s as Button,CustomDevice,GamepadDevice,InputDevice,r as KeyCode,KeyboardDevice,Navigation,getAllNavigatables,getFirstNavigatable,registerPixiJSInputDeviceMixin};
1
+ class CustomDevice{constructor(e){this.type="custom",this.meta={},this.lastUpdated=performance.now(),this.id=e}clear(){}}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;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})}export{o as Button,CustomDevice,GamepadDevice,v as InputDevice,d as KeyCode,KeyboardDevice,s as Navigation,getAllNavigatables,getFirstNavigatable,registerPixiJSInputDeviceMixin};
2
2
  //# sourceMappingURL=index.mjs.map