pixijs-input-devices 0.3.0 → 0.4.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
@@ -58,7 +58,7 @@ declare class InputDeviceManager {
58
58
  private readonly _gamepadDeviceMap;
59
59
  private readonly _customDevices;
60
60
  private readonly _emitter;
61
- private readonly _groupEmitter;
61
+ private readonly _bindEmitter;
62
62
  private _hasFocus;
63
63
  private _lastInteractedDevice?;
64
64
  private constructor();
@@ -88,12 +88,12 @@ declare class InputDeviceManager {
88
88
  on<K extends keyof InputDeviceEvent>(event: K, listener: (event: InputDeviceEvent[K]) => void): this;
89
89
  /** Remove an event listener (or all if none provided) */
90
90
  off<K extends keyof InputDeviceEvent>(event: K, listener: (event: InputDeviceEvent[K]) => void): this;
91
- /** Add a named group event listener (or all if none provided). */
92
- onGroup(name: string, listener: (event: NamedGroupEvent) => void): this;
93
- /** Remove a named group event listener (or all if none provided). */
94
- offGroup(name: string, listener?: (event: NamedGroupEvent) => void): this;
95
- /** Report a named group event (from a CustomDevice). */
96
- emitGroup(e: NamedGroupEvent): void;
91
+ /** Add a named bind event listener (or all if none provided). */
92
+ onBind(name: string, listener: (event: NamedBindEvent) => void): this;
93
+ /** Remove a named bind event listener (or all if none provided). */
94
+ offBind(name: string, listener?: (event: NamedBindEvent) => void): this;
95
+ /** Report a named bind event (from a CustomDevice). */
96
+ emitBind(e: NamedBindEvent): void;
97
97
  /** Add a custom device. */
98
98
  add(device: Device): void;
99
99
  /** Remove a custom device. */
@@ -204,24 +204,24 @@ export declare class GamepadDevice {
204
204
  */
205
205
  remapNintendoMode: RemapNintendoMode;
206
206
  /**
207
- * Create named groups of buttons.
207
+ * Create named binds of buttons.
208
208
  *
209
- * This can be used with `groupPressed( name )`.
209
+ * This can be used with `pressedBind( name )`.
210
210
  *
211
211
  * @example
212
212
  * // set by names
213
- * Gamepad.defaultOptions.namedGroups = {
213
+ * Gamepad.defaultOptions.binds = {
214
214
  * jump: [ "A" ],
215
215
  * crouch: [ "X" ],
216
216
  * }
217
217
  *
218
218
  * // check by named presses
219
- * if ( gamepad.groupPressed( "jump" ) )
219
+ * if ( gamepad.pressedBind( "jump" ) )
220
220
  * {
221
221
  * // ...
222
222
  * }
223
223
  */
224
- namedGroups: Partial<Record<string, ButtonCode[]>>;
224
+ binds: Partial<Record<string, ButtonCode[]>>;
225
225
  navigation: {
226
226
  enabled: boolean;
227
227
  binds: Partial<Record<Button, NavigationIntent>>;
@@ -290,7 +290,7 @@ export declare class GamepadDevice {
290
290
  private readonly _throttleIdLeftStickX;
291
291
  private readonly _throttleIdLeftStickY;
292
292
  private readonly _emitter;
293
- private readonly _groupEmitter;
293
+ private readonly _bindEmitter;
294
294
  /** A scalar 0.0 to 1.0 representing the left trigger value */
295
295
  leftTrigger: number;
296
296
  /** A scalar 0.0 to 1.0 representing the right trigger value */
@@ -299,20 +299,20 @@ export declare class GamepadDevice {
299
299
  leftShoulder: number;
300
300
  /** A scalar 0.0 to 1.0 representing the right shoulder value */
301
301
  rightShoulder: number;
302
- /** @returns true if any button from the named group is pressed. */
303
- groupPressed(name: string): boolean;
302
+ /** @returns true if any button from the named bind is pressed. */
303
+ pressedBind(name: string): boolean;
304
304
  /** @returns true if any of the given buttons are pressed. */
305
- anyPressed(btns: ButtonCode[]): boolean;
305
+ pressedAny(btns: ButtonCode[]): boolean;
306
306
  /** @returns true if all of the given buttons are pressed. */
307
- allPressed(btns: ButtonCode[]): boolean;
307
+ pressedAll(btns: ButtonCode[]): boolean;
308
308
  /** Add an event listener */
309
309
  on<K extends keyof GamepadDeviceEvent>(event: K, listener: (event: GamepadDeviceEvent[K]) => void): this;
310
310
  /** Remove an event listener (or all if none provided). */
311
311
  off<K extends keyof GamepadDeviceEvent>(event: K, listener?: (event: GamepadDeviceEvent[K]) => void): this;
312
- /** Add a named group event listener (or all if none provided). */
313
- onGroup(name: string, listener: (event: GamepadNamedGroupButtonPressEvent) => void): this;
314
- /** Remove a named group event listener (or all if none provided). */
315
- offGroup(name: string, listener?: (event: GamepadNamedGroupButtonPressEvent) => void): this;
312
+ /** Add a named bind event listener (or all if none provided). */
313
+ onBind(name: string, listener: (event: GamepadNamedBindButtonPressEvent) => void): this;
314
+ /** Remove a named bind event listener (or all if none provided). */
315
+ offBind(name: string, listener?: (event: GamepadNamedBindButtonPressEvent) => void): this;
316
316
  /**
317
317
  * Play a vibration effect (if supported).
318
318
  *
@@ -348,13 +348,13 @@ export declare class KeyboardDevice {
348
348
  detected: boolean;
349
349
  options: {
350
350
  /**
351
- * Create named groups of buttons.
351
+ * Create named binds of buttons.
352
352
  *
353
- * This can be used with `groupPressed( name )`.
353
+ * This can be used with `pressedBind( name )`.
354
354
  *
355
355
  * @example
356
356
  * // set by names
357
- * Keyboard.options.namedGroups = {
357
+ * Keyboard.options.binds = {
358
358
  * jump: [ "ArrowUp", "KeyW" ],
359
359
  * left: [ "ArrowLeft", "KeyA" ],
360
360
  * crouch: [ "ArrowDown", "KeyS" ],
@@ -362,12 +362,12 @@ export declare class KeyboardDevice {
362
362
  * }
363
363
  *
364
364
  * // check by named presses
365
- * if ( keyboard.groupPressed( "jump" ) )
365
+ * if ( keyboard.pressedBind( "jump" ) )
366
366
  * {
367
367
  * // ...
368
368
  * }
369
369
  */
370
- namedGroups: Partial<Record<string, KeyCode[]>>;
370
+ binds: Partial<Record<string, KeyCode[]>>;
371
371
  navigation: {
372
372
  enabled: boolean;
373
373
  binds: NavigationBinds;
@@ -376,7 +376,7 @@ export declare class KeyboardDevice {
376
376
  /** Accessors for keys */
377
377
  key: Record<KeyCode, boolean>;
378
378
  private readonly _emitter;
379
- private readonly _groupEmitter;
379
+ private readonly _bindEmitter;
380
380
  private _layout;
381
381
  private _layoutSource;
382
382
  private _deferredKeydown;
@@ -403,20 +403,20 @@ export declare class KeyboardDevice {
403
403
  set layout(value: KeyboardLayout);
404
404
  /** How the keyboard layout was determined. */
405
405
  get layoutSource(): KeyboardLayoutSource;
406
- /** @returns true if any key from the named group is pressed. */
407
- groupPressed(name: string): boolean;
406
+ /** @returns true if any key from the named bind is pressed. */
407
+ pressedBind(name: string): boolean;
408
408
  /** @returns true if any of the given keys are pressed. */
409
- anyPressed(keys: KeyCode[]): boolean;
409
+ pressedAny(keys: KeyCode[]): boolean;
410
410
  /** @returns true if all of the given keys are pressed. */
411
- allPressed(keys: KeyCode[]): boolean;
411
+ pressedAll(keys: KeyCode[]): boolean;
412
412
  /** Add an event listener. */
413
413
  on<K extends keyof KeyboardDeviceEvent>(event: K, listener: (event: KeyboardDeviceEvent[K]) => void): this;
414
414
  /** Remove an event listener (or all if none provided). */
415
415
  off<K extends keyof KeyboardDeviceEvent>(event: K, listener: (event: KeyboardDeviceEvent[K]) => void): this;
416
- /** Add a named group event listener (or all if none provided). */
417
- onGroup(name: string, listener: (event: KeyboardDeviceNamedGroupKeydownEvent) => void): this;
418
- /** Remove a named group event listener (or all if none provided). */
419
- offGroup(name: string, listener?: (event: KeyboardDeviceNamedGroupKeydownEvent) => void): this;
416
+ /** Add a named bind event listener (or all if none provided). */
417
+ onBind(name: string, listener: (event: KeyboardDeviceNamedBindKeydownEvent) => void): this;
418
+ /** Remove a named bind event listener (or all if none provided). */
419
+ offBind(name: string, listener?: (event: KeyboardDeviceNamedBindKeydownEvent) => void): this;
420
420
  /**
421
421
  * Get the label for the given key code in the current keyboard
422
422
  * layout. Attempts to use the Navigator KeyboardLayoutMap API
@@ -432,9 +432,7 @@ export declare class KeyboardDevice {
432
432
  */
433
433
  getKeyLabel(key: KeyCode, layout?: KeyboardLayout): string;
434
434
  /**
435
- * Process pending keyboard events.
436
- *
437
- * @returns any group events to trigger
435
+ * Process deferred keyboard events.
438
436
  */
439
437
  update(now: number): void;
440
438
  /**
@@ -658,8 +656,8 @@ export interface GamepadButtonPressEvent {
658
656
  button: Button;
659
657
  buttonCode: ButtonCode;
660
658
  }
661
- export interface GamepadNamedGroupButtonPressEvent extends GamepadButtonPressEvent {
662
- groupName: string;
659
+ export interface GamepadNamedBindButtonPressEvent extends GamepadButtonPressEvent {
660
+ name: string;
663
661
  }
664
662
  export interface InputDeviceEvent {
665
663
  deviceadded: {
@@ -681,8 +679,8 @@ export interface KeyboardDeviceLayoutUpdatedEvent {
681
679
  layout: KeyboardLayout;
682
680
  layoutSource: KeyboardLayoutSource;
683
681
  }
684
- export interface KeyboardDeviceNamedGroupKeydownEvent extends KeyboardDeviceKeydownEvent {
685
- groupName: string;
682
+ export interface KeyboardDeviceNamedBindKeydownEvent extends KeyboardDeviceKeydownEvent {
683
+ name: string;
686
684
  }
687
685
  /**
688
686
  * A target that responds to navigation on the stack.
@@ -722,7 +720,7 @@ export type ButtonCode = typeof ButtonCode[number];
722
720
  export type Device = GamepadDevice | KeyboardDevice | CustomDevice;
723
721
  export type GamepadButtonDownEvent = (gamepad: GamepadDevice, button: Button) => void;
724
722
  export type GamepadDeviceEvent = {
725
- group: GamepadNamedGroupButtonPressEvent;
723
+ bind: GamepadNamedBindButtonPressEvent;
726
724
  } & {
727
725
  [button in ButtonCode]: GamepadButtonPressEvent;
728
726
  } & {
@@ -734,15 +732,15 @@ export type GamepadVibration = GamepadEffectParameters & {
734
732
  export type KeyCode = (typeof KeyCode)[keyof typeof KeyCode];
735
733
  export type KeyboardDeviceEvent = {
736
734
  layoutdetected: KeyboardDeviceLayoutUpdatedEvent;
737
- group: KeyboardDeviceNamedGroupKeydownEvent;
735
+ bind: KeyboardDeviceNamedBindKeydownEvent;
738
736
  } & {
739
737
  [key in KeyCode]: KeyboardDeviceKeydownEvent;
740
738
  };
741
739
  export type KeyboardLayout = "QWERTY" | "AZERTY" | "JCUKEN" | "QWERTZ";
742
740
  export type KeyboardLayoutSource = "browser" | "lang" | "keypress" | "manual";
743
- export type NamedGroupEvent = {
741
+ export type NamedBindEvent = {
744
742
  device: Device;
745
- groupName: string;
743
+ name: string;
746
744
  };
747
745
  export type NavigatableContainer = Container;
748
746
  export type NavigationBinds = Partial<Record<KeyCode, NavigationIntent>>;
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- const e=0,t=1,i=2,s=3,o={A:0,B:1,X:2,Y:3,LeftShoulder:4,RightShoulder:5,LeftTrigger:6,RightTrigger:7,Back:8,Start:9,LeftStick:10,RightStick:11,DPadUp:12,DPadDown:13,DPadLeft:14,DPadRight:15},a=["A","B","X","Y","LeftShoulder","RightShoulder","LeftTrigger","RightTrigger","Back","Start","LeftStick","RightStick","DPadUp","DPadDown","DPadLeft","DPadRight"];function getAllNavigatables(e,t=[]){for(const i of e.children)i.isNavigatable?t.push(i):getAllNavigatables(i,t);return t}function getFirstNavigatable(e,t,i,{minimumDistance:s=3}={}){return function chooseFirstNavigatableInDirection(e,t,i,{minimumDistance:s=3}={}){var o,a,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)=>t.navigationPriority-e.navigationPriority)),g[0];if(void 0===i&&p)return p;const m=null!=p?p:g[Math.floor(Math.random()*g.length)];if(void 0===p)return null!==(o=e[0])&&void 0!==o?o:m;const v=p.getBounds(),y={x:v.left+v.width/2,y:v.top+v.height/2},f=g.filter((e=>e!==p)).map((e=>{const t=e.getBounds(),i={x:t.left+t.width/2,y:t.top+t.height/2};return{element:e,bounds:t,center:i,distSqrd:squaredDist(i,y)}}));switch(i){case"navigateUp":return null!==(n=null===(a=f.filter((e=>e.center.y<y.y-s)).sort(((e,t)=>e.distSqrd-t.distSqrd))[0])||void 0===a?void 0:a.element)&&void 0!==n?n:m;case"navigateLeft":return null!==(d=null===(r=f.filter((e=>e.center.x<y.x-s)).sort(((e,t)=>e.distSqrd-t.distSqrd))[0])||void 0===r?void 0:r.element)&&void 0!==d?d:m;case"navigateRight":return null!==(c=null===(u=f.filter((e=>e.center.x>y.x+s)).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+s)).sort(((e,t)=>e.distSqrd-t.distSqrd))[0])||void 0===l?void 0:l.element)&&void 0!==h?h:m;default:return p}}(getAllNavigatables(e),t,i,{minimumDistance:s})}function isChildOf(e,t){for(;null!=e;){if(e===t)return!0;e=e.parent}return!1}function squaredDist(e,t){const i=t.x-e.x,s=t.y-e.y;return i*i+s*s}class NavigationManager{constructor(){this.options={enabled:!0,useFallbackHoverEffect:!0},this._responderStack=[]}get firstResponder(){return this._responderStack[0]}get responders(){return this._responderStack}commit(e,t){this.options.enabled&&this._propagateIntent(e,t)}popResponder(){var e,t,i,s;const o=this._responderStack.shift();return null===(e=null==o?void 0:o.resignedAsFirstResponder)||void 0===e||e.call(o),this._clearFocusIfNeeded(),this.firstResponder&&(null===(i=(t=this.firstResponder).becameFirstResponder)||void 0===i||i.call(t),(null===(s=this.firstResponder.autoFocus)||void 0===s||s)&&this.autoFocus()),o}pushResponder(e){var t,i,s;if(this._responderStack.includes(e))throw new Error("Responder already in stack.");const o=this.firstResponder;this._responderStack.unshift(e),null===(t=null==o?void 0:o.resignedAsFirstResponder)||void 0===t||t.call(o),this._clearFocusIfNeeded(),null===(i=e.becameFirstResponder)||void 0===i||i.call(e),(null===(s=e.autoFocus)||void 0===s||s)&&this.autoFocus()}autoFocus(){var e;const t=null!==(e=this.responders.find(isContainer))&&void 0!==e?e:this.stage;if(!t)return;const i=getFirstNavigatable(t);void 0!==i?i!==this._focused&&(this._focused&&this._emitBlur(this._focused),this._emitFocus(i),this._focused=i):console.debug("navigation: no navigatable containers found")}_propagateIntent(e,t){var i,s;for(const s of this._responderStack)if(null===(i=s.handledNavigationIntent)||void 0===i?void 0:i.call(s,e,t))return;if(void 0===this.stage)console.warn("navigation: no stage root set");else{const t=null!==(s=this.responders.find(isContainer))&&void 0!==s?s:this.stage;this._handleGlobalIntent(t,e)}}_handleGlobalIntent(e,t){var i,s;if(void 0===this._focused)return void this.autoFocus();if("navigateBack"===t)return this._emitBlur(this._focused),void(this._focused=void 0);if("trigger"===t)return void this._emitTrigger(this._focused);const o=null!==(s=getFirstNavigatable(null!==(i=this.responders.find(isContainer))&&void 0!==i?i:this.stage,this._focused,t))&&void 0!==s?s:this._focused;o!==this._focused&&(this._emitBlur(this._focused),this._emitFocus(o),this._focused=o)}_emitBlur(e){const t=e.eventNames();t.includes("pointerout")?e.emit("pointerout"):t.includes("mouseout")?e.emit("mouseout"):"auto"===e.navigationMode&&this.options.useFallbackHoverEffect&&(e.alpha=1),e.emit("blur")}_emitFocus(e){const t=e.eventNames();t.includes("pointerover")?e.emit("pointerover"):t.includes("mouseover")?e.emit("mouseover"):"auto"===e.navigationMode&&this.options.useFallbackHoverEffect&&(e.alpha=.5),e.emit("focus")}_emitTrigger(e){const t=e.eventNames();t.includes("pointerdown")?e.emit("pointerdown"):t.includes("mousedown")?e.emit("mousedown"):"auto"===e.navigationMode&&this.options.useFallbackHoverEffect&&(e.alpha=.75),e.emit("trigger")}_clearFocusIfNeeded(){var e;const t=null!==(e=this.responders.find(isContainer))&&void 0!==e?e:this.stage;t&&this._focused&&!isChildOf(this._focused,t)&&(this._focused=void 0)}}function isContainer(e){return"children"in e}NavigationManager.global=new NavigationManager;const n=NavigationManager.global;let r=new Map;function throttle(e,t){var i;const s=Date.now();return(null!==(i=r.get(e))&&void 0!==i?i:0)>s||(r.set(e,s+t),!1)}class EventEmitter{constructor(){this._listeners={}}hasListener(e){return void 0!==this._listeners[e]}emit(e,t){var i;null===(i=this._listeners[e])||void 0===i||i.forEach((e=>e(t)))}on(e,t){var i;this._listeners[e]||(this._listeners[e]=[]),null===(i=this._listeners[e])||void 0===i||i.push(t)}off(e,t){var i,s;this._listeners[e]=void 0===t||null===(i=this._listeners[e])||void 0===i?void 0:i.filter((e=>e!==t)),0===(null===(s=this._listeners[e])||void 0===s?void 0:s.length)&&(this._listeners[e]=void 0)}}class GamepadDevice{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?a[e]:e;return this._emitter.on(i,t),this}off(e,t){const i="number"==typeof e?a[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:s="dual-rumble",rightTrigger:o=0,leftTrigger:a=0,startDelay:n=0}={}){if(!this.options.vibration.enabled)return;if(!this.source.vibrationActuator)return;const r=this.options.vibration.intensity;try{this.source.vibrationActuator.playEffect(s,{duration:e,startDelay:n,weakMagnitude:r*t,strongMagnitude:r*i,leftTrigger:r*a,rightTrigger:r*o})}catch(e){}}update(e,t){this.updatePresses(e,t),this.source=e}clear(){this._axisIntents=this._axisIntents.map((()=>!1)),this._btnPrevState=this._btnPrevState.map((()=>!1))}constructor(e){this.source=e,this.type="gamepad",this.meta={},this.lastInteraction=performance.now(),this.options=JSON.parse(JSON.stringify(GamepadDevice.defaultOptions)),this.leftJoystick={x:0,y:0},this.rightJoystick={x:0,y:0},this.button=Object.keys(o).reduce(((e,t)=>(e[t]=!1,e)),{}),this._btnPrevState=new Array(16),this._axisIntents=new Array(2),this._emitter=new EventEmitter,this._groupEmitter=new EventEmitter,this.leftTrigger=0,this.rightTrigger=0,this.leftShoulder=0,this.rightShoulder=0,this.id="gamepad"+e.index,this.layout=function detectLayout(e){const t=(e.id||"").toLowerCase();return/(steam|28de)/.test(t)?"steam":/(logitech|046d|c216)/.test(t)?"logitech":/(nintendo|switch|joycon|057e)/.test(t)?"nintendo":/(dualshock|dualsense|sony|054c|0ce6|0810)/.test(t)?"playstation":/(xbox|xinput|045e|028e|0291|02a0|02a1|02ea|02ff)/.test(t)?"xbox":"generic"}(e),this._throttleIdLeftStickX=this.id+"-lsx",this._throttleIdLeftStickY=this.id+"-lsy"}updatePresses(r,d){var u,c,l,h,g,p,m;const v=this._btnPrevState.length;for(let e=0;e<v;e++){let t=e;if("nintendo"===this.layout&&"none"!==this.options.remapNintendoMode&&("physical"===this.options.remapNintendoMode?t===o.B?t=o.A:t===o.A?t=o.B:t===o.X?t=o.Y:t===o.Y&&(t=o.X):t===o.B?t=o.X:t===o.X&&(t=o.B)),this._btnPrevState[t]===(null===(u=r.buttons[e])||void 0===u?void 0:u.pressed))continue;this.lastInteraction=d;const i=null!==(l=null===(c=r.buttons[e])||void 0===c?void 0:c.pressed)&&void 0!==l&&l,s=a[t];this._btnPrevState[t]=i,this.button[s]=i,i&&(this._emitter.hasListener(s)&&setTimeout((()=>this._emitter.emit(s,{device:this,button:t,buttonCode:s}))),Object.entries(this.options.namedGroups).forEach((([e,i])=>{i.includes(s)&&setTimeout((()=>{const i={device:this,button:t,buttonCode:s,groupName:e};this._groupEmitter.emit(e,i),this._emitter.emit("group",i)}))})),n.options.enabled&&this.options.navigation.enabled&&void 0!==this.options.navigation.binds[t]&&setTimeout((()=>n.commit(this.options.navigation.binds[t],this))))}const y=this.options.triggerDeadzone;this.leftTrigger=_scale(this.source.buttons[o.LeftTrigger].value,y),this.rightTrigger=_scale(this.source.buttons[o.RightTrigger].value,y),this.leftShoulder=_scale(this.source.buttons[o.LeftShoulder].value,y),this.rightShoulder=_scale(this.source.buttons[o.RightShoulder].value,y);const f=this.options.joystickDeadzone;this.leftJoystick.x=_scale(null!==(h=r.axes[e])&&void 0!==h?h:0,f),this.leftJoystick.y=_scale(null!==(g=r.axes[t])&&void 0!==g?g:0,f),this.rightJoystick.x=_scale(null!==(p=r.axes[i])&&void 0!==p?p:0,f),this.rightJoystick.y=_scale(null!==(m=r.axes[s])&&void 0!==m?m:0,f),0===this.leftJoystick.x&&0===this.leftJoystick.y&&0===this.rightJoystick.x&&0===this.rightJoystick.y||(this.lastInteraction=d);const b=this.options.navigation.joystick;if(Math.abs(this.leftJoystick.x)>=b.commitSensitivity){const t=this.leftJoystick.x<0?"navigateLeft":"navigateRight",i=this._axisIntents[e]?b.repeatCooldownMs:b.firstRepeatCooldownMs;this._axisIntents[e]=!0,this.options.navigation.enabled&&!throttle(this._throttleIdLeftStickX,i)&&setTimeout((()=>n.commit(t,this)))}else this._axisIntents[e]=!1;if(Math.abs(this.leftJoystick.y)>=b.commitSensitivity){const e=this.leftJoystick.y<0?"navigateUp":"navigateDown",i=this._axisIntents[t]?b.repeatCooldownMs:b.firstRepeatCooldownMs;this._axisIntents[t]=!0,this.options.navigation.enabled&&!throttle(this._throttleIdLeftStickY,i)&&setTimeout((()=>n.commit(e,this)))}else this._axisIntents[t]=!1}}function _scale(e,t){const i=(Math.abs(e)-t[0])/(t[1]-t[0]);return i>=0&&i<=1?Math.sign(e)*i:i>1?1*Math.sign(e):0}GamepadDevice.defaultOptions={remapNintendoMode:"physical",namedGroups:{},navigation:{enabled:!0,binds:{[o.A]:"trigger",[o.B]:"navigateBack",[o.Back]:"navigateBack",[o.DPadDown]:"navigateDown",[o.DPadLeft]:"navigateLeft",[o.DPadRight]:"navigateRight",[o.DPadUp]:"navigateUp"},joystick:{commitSensitivity:.5,repeatCooldownMs:80,firstRepeatCooldownMs:400}},joystickDeadzone:[0,1],triggerDeadzone:[0,1],vibration:{enabled:!0,intensity:1}};const d={AltLeft:"AltLeft",AltRight:"AltRight",ArrowDown:"ArrowDown",ArrowLeft:"ArrowLeft",ArrowRight:"ArrowRight",ArrowUp:"ArrowUp",Backquote:"Backquote",Backslash:"Backslash",Backspace:"Backspace",BracketLeft:"BracketLeft",BracketRight:"BracketRight",CapsLock:"CapsLock",Comma:"Comma",ContextMenu:"ContextMenu",ControlLeft:"ControlLeft",ControlRight:"ControlRight",Delete:"Delete",Digit0:"Digit0",Digit1:"Digit1",Digit2:"Digit2",Digit3:"Digit3",Digit4:"Digit4",Digit5:"Digit5",Digit6:"Digit6",Digit7:"Digit7",Digit8:"Digit8",Digit9:"Digit9",End:"End",Enter:"Enter",Equal:"Equal",Escape:"Escape",F1:"F1",F10:"F10",F11:"F11",F12:"F12",F13:"F13",F14:"F14",F15:"F15",F16:"F16",F17:"F17",F18:"F18",F19:"F19",F2:"F2",F20:"F20",F21:"F21",F22:"F22",F23:"F23",F24:"F24",F25:"F25",F26:"F26",F27:"F27",F28:"F28",F29:"F29",F3:"F3",F30:"F30",F31:"F31",F32:"F32",F4:"F4",F5:"F5",F6:"F6",F7:"F7",F8:"F8",F9:"F9",Home:"Home",IntlBackslash:"IntlBackslash",IntlRo:"IntlRo",IntlYen:"IntlYen",KeyA:"KeyA",KeyB:"KeyB",KeyC:"KeyC",KeyD:"KeyD",KeyE:"KeyE",KeyF:"KeyF",KeyG:"KeyG",KeyH:"KeyH",KeyI:"KeyI",KeyJ:"KeyJ",KeyK:"KeyK",KeyL:"KeyL",KeyM:"KeyM",KeyN:"KeyN",KeyO:"KeyO",KeyP:"KeyP",KeyQ:"KeyQ",KeyR:"KeyR",KeyS:"KeyS",KeyT:"KeyT",KeyU:"KeyU",KeyV:"KeyV",KeyW:"KeyW",KeyX:"KeyX",KeyY:"KeyY",KeyZ:"KeyZ",Lang1:"Lang1",Lang2:"Lang2",MediaTrackNext:"MediaTrackNext",MediaTrackPrevious:"MediaTrackPrevious",MetaLeft:"MetaLeft",MetaRight:"MetaRight",Minus:"Minus",NumLock:"NumLock",Numpad0:"Numpad0",Numpad1:"Numpad1",Numpad2:"Numpad2",Numpad3:"Numpad3",Numpad4:"Numpad4",Numpad5:"Numpad5",Numpad6:"Numpad6",Numpad7:"Numpad7",Numpad8:"Numpad8",Numpad9:"Numpad9",NumpadAdd:"NumpadAdd",NumpadComma:"NumpadComma",NumpadDecimal:"NumpadDecimal",NumpadDivide:"NumpadDivide",NumpadMultiply:"NumpadMultiply",NumpadSubtract:"NumpadSubtract",OSLeft:"OSLeft",Pause:"Pause",Period:"Period",Quote:"Quote",ScrollLock:"ScrollLock",Semicolon:"Semicolon",ShiftLeft:"ShiftLeft",ShiftRight:"ShiftRight",Slash:"Slash",Space:"Space",Tab:"Tab",VolumeDown:"VolumeDown",VolumeMute:"VolumeMute",VolumeUp:"VolumeUp",WakeUp:"WakeUp"};function __awaiter(e,t,i,s){return new(i||(i=Promise))((function(o,a){function fulfilled(e){try{step(s.next(e))}catch(e){a(e)}}function rejected(e){try{step(s.throw(e))}catch(e){a(e)}}function step(e){e.done?o(e.value):function adopt(e){return e instanceof i?e:new i((function(t){t(e)}))}(e.value).then(fulfilled,rejected)}step((s=s.apply(e,t||[])).next())}))}let u,c;"function"==typeof SuppressedError&&SuppressedError;const l=["fr","mg","lu"],h=["ab","ba","be","bg","ch","kk","ky","mk","mn","ru","sr","tg","tt","uk","uz"],g=["de","cs","sk","sl","hu","hr","bs","ro","sq","me","lt","lv","et"],p=/ф|и|с|в|у|а|п|р|ш|о|л|д|ь|т|щ|з|й|к|ы|е|г|м|ц|ч|н|я|ё|х|ъ|б|ю|э|ж|и/i,m=/[a-z]/i;function inferKeyboardLayoutFromLang(e=function getLang(){var e;const t=navigator;return null!=(null===(e=t.languages)||void 0===e?void 0:e.length)?t.languages[0]:t.userLanguage||t.language||t.browserLanguage}()){const t=(e||"").toLowerCase(),i=t.split("-")[0];return l.includes(i)||t.startsWith("nl-be")?"AZERTY":h.includes(i)?"JCUKEN":g.includes(i)||t.startsWith("sr-latn")?"QWERTZ":"QWERTY"}const v=new Set(["AZERTY","JCUKEN","QWERTY","QWERTZ"]);function getLayoutKeyLabel(e,t){var i,s;if(void 0===c){const e={ArrowLeft:"⬅",ArrowRight:"➡",ArrowUp:"⬆",ArrowDown:"⬇",AltLeft:"Left Alt",AltRight:"Right Alt",Backquote:"`",Backslash:"\\",Backspace:"Backspace",BracketLeft:"[",BracketRight:"]",CapsLock:"CapsLock",Comma:",",ContextMenu:"Context Menu",ControlLeft:"Left Ctrl",ControlRight:"Right Ctrl",Delete:"Delete",Digit0:"0",Digit1:"1",Digit2:"2",Digit3:"3",Digit4:"4",Digit5:"5",Digit6:"6",Digit7:"7",Digit8:"8",Digit9:"9",End:"End",Enter:"Enter",Equal:"=",Escape:"Esc",F1:"F1",F2:"F2",F3:"F3",F4:"F4",F5:"F5",F6:"F6",F7:"F7",F8:"F8",F9:"F9",F10:"F10",F11:"F11",F12:"F12",F13:"F13",F14:"F14",F15:"F15",F16:"F16",F17:"F17",F18:"F18",F19:"F19",F20:"F20",F21:"F21",F22:"F22",F23:"F23",F24:"F24",F25:"F25",F26:"F26",F27:"F27",F28:"F28",F29:"F29",F30:"F30",F31:"F31",F32:"F32",Home:"Home",IntlBackslash:"\\",IntlRo:"Ro",IntlYen:"¥",KeyA:"A",KeyB:"B",KeyC:"C",KeyD:"D",KeyE:"E",KeyF:"F",KeyG:"G",KeyH:"H",KeyI:"I",KeyJ:"J",KeyK:"K",KeyL:"L",KeyM:"M",KeyN:"N",KeyO:"O",KeyP:"P",KeyQ:"Q",KeyR:"R",KeyS:"S",KeyT:"T",KeyU:"U",KeyV:"V",KeyW:"W",KeyX:"X",KeyY:"Y",KeyZ:"Z",Lang1:"Language 1",Lang2:"Language 2",MediaTrackNext:"Next Track",MediaTrackPrevious:"Previous Track",MetaLeft:"Left "+getMetaKeyLabel(),MetaRight:"Right "+getMetaKeyLabel(),Minus:"-",NumLock:"Num Lock",Numpad0:"Num0",Numpad1:"Num1",Numpad2:"Num2",Numpad3:"Num3",Numpad4:"Num4",Numpad5:"Num5",Numpad6:"Num6",Numpad7:"Num7",Numpad8:"Num8",Numpad9:"Num9",NumpadAdd:"+",NumpadComma:",",NumpadDecimal:".",NumpadDivide:"/",NumpadMultiply:"*",NumpadSubtract:"-",OSLeft:"OS Left",Pause:"Pause",Period:".",Quote:"'",ScrollLock:"Scroll Lock",Semicolon:";",ShiftLeft:"Left Shift",ShiftRight:"Right Shift",Slash:"/",Space:"Space",Tab:"Tab",VolumeDown:"Volume Down",VolumeMute:"Volume Mute",VolumeUp:"Volume Up",WakeUp:"Wake Up"};c={AZERTY:{KeyA:"Q",KeyQ:"A",KeyW:"Z",KeyZ:"W",Backquote:"²",BracketLeft:"«",BracketRight:"»"},JCUKEN:{KeyA:"Ф",KeyB:"И",KeyC:"С",KeyD:"В",KeyE:"У",KeyF:"А",KeyG:"П",KeyH:"Р",KeyI:"Ш",KeyJ:"О",KeyK:"Л",KeyL:"Д",KeyM:"Ь",KeyN:"Т",KeyO:"Щ",KeyP:"З",KeyQ:"Й",KeyR:"К",KeyS:"Ы",KeyT:"Е",KeyU:"Г",KeyV:"М",KeyW:"Ц",KeyX:"Ч",KeyY:"Н",KeyZ:"Я",Backquote:"Ё",BracketLeft:"х",BracketRight:"ъ",Comma:"Б",Period:"Ю",Quote:"Э",Semicolon:"Ж",Slash:"И"},QWERTY:e,QWERTZ:{KeyY:"Z",KeyZ:"Y",BracketLeft:"ü",BracketRight:"ö",Slash:"-"}}}return null!==(s=null!==(i=c[t][e])&&void 0!==i?i:c.QWERTY[e])&&void 0!==s?s:e}function getMetaKeyLabel(){var e,t,i,s;const o=navigator,a=null!==(t=null===(e=o.platform)||void 0===e?void 0:e.toLowerCase())&&void 0!==t?t:"",n=null!==(s=null===(i=o.userAgent)||void 0===i?void 0:i.toLowerCase())&&void 0!==s?s:"";return a.includes("mac")?"⌘":a.includes("win")||a.includes("linux")?"⊞":n.includes("android")?"Search":n.includes("iphone")||n.includes("ipad")?"⌘":"⊞"}const y=["navigateLeft","navigateRight","navigateUp","navigateDown"];class KeyboardDevice{constructor(){this.type="keyboard",this.id="keyboard",this.meta={},this.lastInteraction=performance.now(),this.detectLayoutOnKeypress=!0,this.detected=!1,this.options={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();u=t;const i=t.get("KeyQ"),s=t.get("KeyA"),o=t.get("KeyZ");if("a"===i&&"w"===o&&"q"===s)return"AZERTY";if("q"===i&&"y"===o&&"a"===s)return"QWERTZ";if("q"===i&&"z"===o&&"a"===s)return"QWERTY";if("й"===i&&"я"===o&&"ф"===s)return"JCUKEN"}catch(e){}}))}().then((e=>{void 0!==e&&(this._layoutSource="browser",this._layout=e,this.detectLayoutOnKeypress=!1,this._emitter.emit("layoutdetected",{layoutSource:"browser",layout:e,device:this}))})),this._configureEventListeners()}get layout(){return this._layout}set layout(e){this._layoutSource="manual",this._layout=e,this.detectLayoutOnKeypress=!1}get layoutSource(){return this._layoutSource}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}getKeyLabel(e,t){var i;return t?getLayoutKeyLabel(e,t):null!==(i=function getNavigatorKeyLabel(e){const t=null==u?void 0:u.get(e);return void 0===t?void 0:function _toLocaleTitleCase(e){return e.split(/\s+/).map((e=>e.charAt(0).toLocaleUpperCase()+e.slice(1))).join(" ")}(t)}(e))&&void 0!==i?i:getLayoutKeyLabel(e,null!=t?t:this._layout)}update(e){this._deferredKeydown.length>0&&(this._deferredKeydown.forEach((e=>this._processDeferredKeydownEvent(e))),this._deferredKeydown.length=0)}clear(){for(const e of Object.keys(d))this.key[e]=!1}_configureEventListeners(){const e=this.key,t=this._deferredKeydown;window.addEventListener("keydown",(i=>{e[i.code]=!0,t.push(i),this.lastInteraction=performance.now()}),{passive:!0,capture:!0}),window.addEventListener("keyup",(t=>{e[t.code]=!1,this.lastInteraction=performance.now()}),{passive:!0,capture:!0})}_processDeferredKeydownEvent(e){const t=e.code;if(!e.repeat){if(this.detectLayoutOnKeypress&&"lang"===this._layoutSource){const t=function detectKeyboardLayoutFromKeydown(e){const t=e.key.toLowerCase(),i=e.code;return p.test(t)?(v.delete("AZERTY"),v.delete("QWERTY"),v.delete("QWERTZ")):"Backquote"===i&&"²"===t||"BracketLeft"===i&&"«"===t||"BracketRight"===i&&"»"===t||"KeyA"===i&&"q"===t||"KeyQ"===i&&"a"===t||"KeyW"===i&&"z"===t||"KeyZ"===i&&"w"===t?(v.delete("JCUKEN"),v.delete("QWERTY"),v.delete("QWERTZ")):"BracketLeft"===i&&"ü"===t||"BracketRight"===i&&"ö"===t||"KeyY"===i&&"z"===t||"KeyZ"===i&&"y"===t||"Slash"===i&&"-"===t?(v.delete("AZERTY"),v.delete("JCUKEN"),v.delete("QWERTY")):"BracketLeft"===i&&"["===t||"BracketRight"===i&&"]"===t||"KeyZ"===i&&"z"===t?(v.delete("AZERTY"),v.delete("JCUKEN"),v.delete("QWERTZ")):"KeyQ"===i&&"q"===t||"KeyW"===i&&"w"===t?(v.delete("AZERTY"),v.delete("JCUKEN")):"KeyY"===i&&"Y"===t?(v.delete("QWERTZ"),v.delete("JCUKEN")):m.test(t)&&v.delete("JCUKEN"),1===v.size?[...v][0]:void 0}(e);void 0!==t&&(this._layout=t,this._layoutSource="keypress",this.detectLayoutOnKeypress=!1,this._emitter.emit("layoutdetected",{layout:t,layoutSource:"keypress",device:this}))}this._emitter.hasListener(t)&&setTimeout((()=>this._emitter.emit(t,{device:this,keyCode:t,keyLabel:this.getKeyLabel(t),event:e}))),Object.entries(this.options.namedGroups).forEach((([i,s])=>{s.includes(t)&&setTimeout((()=>{const s={device:this,keyCode:t,keyLabel:this.getKeyLabel(t),event:e,groupName:i};this._groupEmitter.emit(i,s),this._emitter.emit("group",s)}))}))}if(n.options.enabled&&this.options.navigation.enabled&&void 0!==this.options.navigation.binds[t]){const i=this.options.navigation.binds[t];e.repeat&&!y.includes(i)||setTimeout((()=>n.commit(this.options.navigation.binds[t],this)))}}}KeyboardDevice.global=new KeyboardDevice;class InputDeviceManager{constructor(){this.isMobile=(()=>{let e=!1;var t;return t=navigator.userAgent||navigator.vendor,(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(t)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(t.substr(0,4)))&&(e=!0),e})(),this.isTouchCapable=function isTouchCapable(){return"ontouchstart"in window||navigator.maxTouchPoints>0}(),this.options={requireFocus:!0,clearInputInBackground:!0},this._devices=[],this._gamepadDevices=[],this._gamepadDeviceMap=new Map,this._customDevices=[],this._emitter=new EventEmitter,this._groupEmitter=new EventEmitter,this._hasFocus=!1,this.keyboard=KeyboardDevice.global,this.isTouchCapable||this.isMobile?window.addEventListener("keydown",(()=>this.add(this.keyboard)),{once:!0}):this.add(this.keyboard),window.addEventListener("gamepadconnected",(()=>this._pollGamepads(performance.now()))),window.addEventListener("gamepaddisconnected",(e=>this._removeGamepad(e.gamepad.index)))}get devices(){return this._devices}get gamepads(){return this._gamepadDevices}get custom(){return this._customDevices}get lastInteractedDevice(){return this._lastInteractedDevice}on(e,t){return this._emitter.on(e,t),this}off(e,t){return this._emitter.off(e,t),this}onGroup(e,t){return this._groupEmitter.on(e,t),this}offGroup(e,t){return this._groupEmitter.off(e,t),this}emitGroup(e){this._groupEmitter.emit(e.groupName,e)}add(e){-1===this._devices.indexOf(e)&&(this._devices.push(e),e instanceof KeyboardDevice?(e.detected=!0,e.on("group",(e=>this.emitGroup(e)))):e instanceof GamepadDevice?(this._gamepadDeviceMap.set(e.source.index,e),this._gamepadDevices.push(e),e.on("group",(e=>this.emitGroup(e)))):this._customDevices.push(e),this._emitter.emit("deviceadded",{device:e}))}remove(e){if(!(e instanceof KeyboardDevice||e instanceof GamepadDevice)){const t=this._customDevices.indexOf(e);-1!==t&&this._devices.splice(t,1)}const t=this._devices.indexOf(e);-1!==t&&(this._devices.splice(t,1),this._emitter.emit("deviceremoved",{device:e}))}update(){if(this.options.requireFocus&&!document.hasFocus())return this._hasFocus&&this.options.clearInputInBackground&&this.devices.forEach((e=>{var t;return null===(t=e.clear)||void 0===t?void 0:t.call(e)})),this._hasFocus=!1,this._devices;this._hasFocus=!0;const e=performance.now();return this.keyboard.detected&&this.keyboard.update(e),this._pollGamepads(e),this._customDevices.length>0&&this._customDevices.forEach((t=>t.update(e))),this._updateLastInteracted(),this._devices}_updateLastInteracted(){if(0===this._devices.length)return;let e;if(1===this._devices.length)e=this._devices[0];else for(const t of this._devices)(void 0===e||t.lastInteraction>e.lastInteraction)&&(e=t);this._lastInteractedDevice=e}_pollGamepads(e){if(!document.hasFocus())return this._gamepadDevices;if(void 0===navigator.getGamepads)return this._gamepadDevices;for(const t of navigator.getGamepads())if(null!=t)if(this._gamepadDeviceMap.has(t.index)){this._gamepadDeviceMap.get(t.index).update(t,e)}else{const i=new GamepadDevice(t);this.add(i),i.update(t,e)}return this._gamepadDevices}_removeGamepad(e){const t=this._gamepadDeviceMap.get(e);if(!t)return;const i=this._gamepadDevices.indexOf(t);-1!==i&&this._gamepadDevices.splice(i,1),this.remove(t),this._gamepadDeviceMap.delete(e)}}InputDeviceManager.global=new InputDeviceManager;const f=InputDeviceManager.global;function 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,GamepadDevice,f as InputDevice,d as KeyCode,KeyboardDevice,n as Navigation,y as REPEATABLE_NAV_INTENTS,getAllNavigatables,getFirstNavigatable,isChildOf,registerPixiJSInputDeviceMixin};
1
+ const e=0,t=1,i=2,s=3,n={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:s=3}={}){return function chooseFirstNavigatableInDirection(e,t,i,{minimumDistance:s=3}={}){var n,o,a,r,d,c,u,l,h;const g=e.filter((e=>e.isNavigatable&&null!=e.parent&&function isVisible(e){for(;null!=e;){if(!e.visible)return!1;e=e.parent}return!0}(e))),p=g.find((e=>e===t));if(void 0===p)return g.sort(((e,t)=>t.navigationPriority-e.navigationPriority)),g[0];if(void 0===i&&p)return p;const m=null!=p?p:g[Math.floor(Math.random()*g.length)];if(void 0===p)return null!==(n=e[0])&&void 0!==n?n:m;const v=p.getBounds(),y={x:v.left+v.width/2,y:v.top+v.height/2},f=g.filter((e=>e!==p)).map((e=>{const t=e.getBounds(),i={x:t.left+t.width/2,y:t.top+t.height/2};return{element:e,bounds:t,center:i,distSqrd:squaredDist(i,y)}}));switch(i){case"navigateUp":return null!==(a=null===(o=f.filter((e=>e.center.y<y.y-s)).sort(((e,t)=>e.distSqrd-t.distSqrd))[0])||void 0===o?void 0:o.element)&&void 0!==a?a:m;case"navigateLeft":return null!==(d=null===(r=f.filter((e=>e.center.x<y.x-s)).sort(((e,t)=>e.distSqrd-t.distSqrd))[0])||void 0===r?void 0:r.element)&&void 0!==d?d:m;case"navigateRight":return null!==(u=null===(c=f.filter((e=>e.center.x>y.x+s)).sort(((e,t)=>e.distSqrd-t.distSqrd))[0])||void 0===c?void 0:c.element)&&void 0!==u?u:m;case"navigateDown":return null!==(h=null===(l=f.filter((e=>e.center.y>y.y+s)).sort(((e,t)=>e.distSqrd-t.distSqrd))[0])||void 0===l?void 0:l.element)&&void 0!==h?h:m;default:return p}}(getAllNavigatables(e),t,i,{minimumDistance:s})}function isChildOf(e,t){for(;null!=e;){if(e===t)return!0;e=e.parent}return!1}function squaredDist(e,t){const i=t.x-e.x,s=t.y-e.y;return i*i+s*s}class NavigationManager{constructor(){this.options={enabled:!0,useFallbackHoverEffect:!0},this._responderStack=[]}get firstResponder(){return this._responderStack[0]}get responders(){return this._responderStack}commit(e,t){this.options.enabled&&this._propagateIntent(e,t)}popResponder(){var e,t,i,s;const n=this._responderStack.shift();return null===(e=null==n?void 0:n.resignedAsFirstResponder)||void 0===e||e.call(n),this._clearFocusIfNeeded(),this.firstResponder&&(null===(i=(t=this.firstResponder).becameFirstResponder)||void 0===i||i.call(t),(null===(s=this.firstResponder.autoFocus)||void 0===s||s)&&this.autoFocus()),n}pushResponder(e){var t,i,s;if(this._responderStack.includes(e))throw new Error("Responder already in stack.");const n=this.firstResponder;this._responderStack.unshift(e),null===(t=null==n?void 0:n.resignedAsFirstResponder)||void 0===t||t.call(n),this._clearFocusIfNeeded(),null===(i=e.becameFirstResponder)||void 0===i||i.call(e),(null===(s=e.autoFocus)||void 0===s||s)&&this.autoFocus()}autoFocus(){var e;const t=null!==(e=this.responders.find(isContainer))&&void 0!==e?e:this.stage;if(!t)return;const i=getFirstNavigatable(t);void 0!==i?i!==this._focused&&(this._focused&&this._emitBlur(this._focused),this._emitFocus(i),this._focused=i):console.debug("navigation: no navigatable containers found")}_propagateIntent(e,t){var i,s;for(const s of this._responderStack)if(null===(i=s.handledNavigationIntent)||void 0===i?void 0:i.call(s,e,t))return;if(void 0===this.stage)console.warn("navigation: no stage root set");else{const t=null!==(s=this.responders.find(isContainer))&&void 0!==s?s:this.stage;this._handleGlobalIntent(t,e)}}_handleGlobalIntent(e,t){var i,s;if(void 0===this._focused)return void this.autoFocus();if("navigateBack"===t)return this._emitBlur(this._focused),void(this._focused=void 0);if("trigger"===t)return void this._emitTrigger(this._focused);const n=null!==(s=getFirstNavigatable(null!==(i=this.responders.find(isContainer))&&void 0!==i?i:this.stage,this._focused,t))&&void 0!==s?s:this._focused;n!==this._focused&&(this._emitBlur(this._focused),this._emitFocus(n),this._focused=n)}_emitBlur(e){const t=e.eventNames();t.includes("pointerout")?e.emit("pointerout"):t.includes("mouseout")?e.emit("mouseout"):"auto"===e.navigationMode&&this.options.useFallbackHoverEffect&&(e.alpha=1),e.emit("blur")}_emitFocus(e){const t=e.eventNames();t.includes("pointerover")?e.emit("pointerover"):t.includes("mouseover")?e.emit("mouseover"):"auto"===e.navigationMode&&this.options.useFallbackHoverEffect&&(e.alpha=.5),e.emit("focus")}_emitTrigger(e){const t=e.eventNames();t.includes("pointerdown")?e.emit("pointerdown"):t.includes("mousedown")?e.emit("mousedown"):"auto"===e.navigationMode&&this.options.useFallbackHoverEffect&&(e.alpha=.75),e.emit("trigger")}_clearFocusIfNeeded(){var e;const t=null!==(e=this.responders.find(isContainer))&&void 0!==e?e:this.stage;t&&this._focused&&!isChildOf(this._focused,t)&&(this._focused=void 0)}}function isContainer(e){return"children"in e}NavigationManager.global=new NavigationManager;const a=NavigationManager.global;let r=new Map;function throttle(e,t){var i;const s=Date.now();return(null!==(i=r.get(e))&&void 0!==i?i:0)>s||(r.set(e,s+t),!1)}class EventEmitter{constructor(){this._listeners={}}hasListener(e){return void 0!==this._listeners[e]}emit(e,t){var i;null===(i=this._listeners[e])||void 0===i||i.forEach((e=>e(t)))}on(e,t){var i;this._listeners[e]||(this._listeners[e]=[]),null===(i=this._listeners[e])||void 0===i||i.push(t)}off(e,t){var i,s;this._listeners[e]=void 0===t||null===(i=this._listeners[e])||void 0===i?void 0:i.filter((e=>e!==t)),0===(null===(s=this._listeners[e])||void 0===s?void 0:s.length)&&(this._listeners[e]=void 0)}}class GamepadDevice{pressedBind(e){return void 0!==this.options.binds[e]&&this.pressedAny(this.options.binds[e])}pressedAny(e){for(let t=0;t<e.length;t++)if(this.button[e[t]])return!0;return!1}pressedAll(e){for(let t=0;t<e.length;t++)if(!this.button[e[t]])return!1;return!0}on(e,t){const i="number"==typeof e?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}onBind(e,t){return this._bindEmitter.on(e,t),this}offBind(e,t){return this._bindEmitter.off(e,t),this}playVibration({duration:e=200,weakMagnitude:t=.5,strongMagnitude:i=.5,vibrationType:s="dual-rumble",rightTrigger:n=0,leftTrigger:o=0,startDelay:a=0}={}){if(!this.options.vibration.enabled)return;if(!this.source.vibrationActuator)return;const r=this.options.vibration.intensity;try{this.source.vibrationActuator.playEffect(s,{duration:e,startDelay:a,weakMagnitude:r*t,strongMagnitude:r*i,leftTrigger:r*o,rightTrigger:r*n})}catch(e){}}update(e,t){this.updatePresses(e,t),this.source=e}clear(){this._axisIntents=this._axisIntents.map((()=>!1)),this._btnPrevState=this._btnPrevState.map((()=>!1))}constructor(e){this.source=e,this.type="gamepad",this.meta={},this.lastInteraction=performance.now(),this.options=JSON.parse(JSON.stringify(GamepadDevice.defaultOptions)),this.leftJoystick={x:0,y:0},this.rightJoystick={x:0,y:0},this.button=Object.keys(n).reduce(((e,t)=>(e[t]=!1,e)),{}),this._btnPrevState=new Array(16),this._axisIntents=new Array(2),this._emitter=new EventEmitter,this._bindEmitter=new EventEmitter,this.leftTrigger=0,this.rightTrigger=0,this.leftShoulder=0,this.rightShoulder=0,this.id="gamepad"+e.index,this.layout=function detectLayout(e){const t=(e.id||"").toLowerCase();return/(steam|28de)/.test(t)?"steam":/(logitech|046d|c216)/.test(t)?"logitech":/(nintendo|switch|joycon|057e)/.test(t)?"nintendo":/(dualshock|dualsense|sony|054c|0ce6|0810)/.test(t)?"playstation":/(xbox|xinput|045e|028e|0291|02a0|02a1|02ea|02ff)/.test(t)?"xbox":"generic"}(e),this._throttleIdLeftStickX=this.id+"-lsx",this._throttleIdLeftStickY=this.id+"-lsy"}updatePresses(r,d){var c,u,l,h,g,p,m;const v=this._btnPrevState.length;for(let e=0;e<v;e++){let t=e;if("nintendo"===this.layout&&"none"!==this.options.remapNintendoMode&&("physical"===this.options.remapNintendoMode?t===n.B?t=n.A:t===n.A?t=n.B:t===n.X?t=n.Y:t===n.Y&&(t=n.X):t===n.B?t=n.X:t===n.X&&(t=n.B)),this._btnPrevState[t]===(null===(c=r.buttons[e])||void 0===c?void 0:c.pressed))continue;this.lastInteraction=d;const i=null!==(l=null===(u=r.buttons[e])||void 0===u?void 0:u.pressed)&&void 0!==l&&l,s=o[t];this._btnPrevState[t]=i,this.button[s]=i,i&&(this._emitter.hasListener(s)&&setTimeout((()=>this._emitter.emit(s,{device:this,button:t,buttonCode:s}))),Object.entries(this.options.binds).forEach((([e,i])=>{i.includes(s)&&setTimeout((()=>{const i={device:this,button:t,buttonCode:s,name:e};this._bindEmitter.emit(e,i),this._emitter.emit("bind",i)}))})),a.options.enabled&&this.options.navigation.enabled&&void 0!==this.options.navigation.binds[t]&&setTimeout((()=>a.commit(this.options.navigation.binds[t],this))))}const y=this.options.triggerDeadzone;this.leftTrigger=_scale(this.source.buttons[n.LeftTrigger].value,y),this.rightTrigger=_scale(this.source.buttons[n.RightTrigger].value,y),this.leftShoulder=_scale(this.source.buttons[n.LeftShoulder].value,y),this.rightShoulder=_scale(this.source.buttons[n.RightShoulder].value,y);const f=this.options.joystickDeadzone;this.leftJoystick.x=_scale(null!==(h=r.axes[e])&&void 0!==h?h:0,f),this.leftJoystick.y=_scale(null!==(g=r.axes[t])&&void 0!==g?g:0,f),this.rightJoystick.x=_scale(null!==(p=r.axes[i])&&void 0!==p?p:0,f),this.rightJoystick.y=_scale(null!==(m=r.axes[s])&&void 0!==m?m:0,f),0===this.leftJoystick.x&&0===this.leftJoystick.y&&0===this.rightJoystick.x&&0===this.rightJoystick.y||(this.lastInteraction=d);const b=this.options.navigation.joystick;if(Math.abs(this.leftJoystick.x)>=b.commitSensitivity){const t=this.leftJoystick.x<0?"navigateLeft":"navigateRight",i=this._axisIntents[e]?b.repeatCooldownMs:b.firstRepeatCooldownMs;this._axisIntents[e]=!0,this.options.navigation.enabled&&!throttle(this._throttleIdLeftStickX,i)&&setTimeout((()=>a.commit(t,this)))}else this._axisIntents[e]=!1;if(Math.abs(this.leftJoystick.y)>=b.commitSensitivity){const e=this.leftJoystick.y<0?"navigateUp":"navigateDown",i=this._axisIntents[t]?b.repeatCooldownMs:b.firstRepeatCooldownMs;this._axisIntents[t]=!0,this.options.navigation.enabled&&!throttle(this._throttleIdLeftStickY,i)&&setTimeout((()=>a.commit(e,this)))}else this._axisIntents[t]=!1}}function _scale(e,t){const i=(Math.abs(e)-t[0])/(t[1]-t[0]);return i>=0&&i<=1?Math.sign(e)*i:i>1?1*Math.sign(e):0}GamepadDevice.defaultOptions={remapNintendoMode:"physical",binds:{},navigation:{enabled:!0,binds:{[n.A]:"trigger",[n.B]:"navigateBack",[n.Back]:"navigateBack",[n.DPadDown]:"navigateDown",[n.DPadLeft]:"navigateLeft",[n.DPadRight]:"navigateRight",[n.DPadUp]:"navigateUp"},joystick:{commitSensitivity:.5,repeatCooldownMs:80,firstRepeatCooldownMs:400}},joystickDeadzone:[0,1],triggerDeadzone:[0,1],vibration:{enabled:!0,intensity:1}};const d={AltLeft:"AltLeft",AltRight:"AltRight",ArrowDown:"ArrowDown",ArrowLeft:"ArrowLeft",ArrowRight:"ArrowRight",ArrowUp:"ArrowUp",Backquote:"Backquote",Backslash:"Backslash",Backspace:"Backspace",BracketLeft:"BracketLeft",BracketRight:"BracketRight",CapsLock:"CapsLock",Comma:"Comma",ContextMenu:"ContextMenu",ControlLeft:"ControlLeft",ControlRight:"ControlRight",Delete:"Delete",Digit0:"Digit0",Digit1:"Digit1",Digit2:"Digit2",Digit3:"Digit3",Digit4:"Digit4",Digit5:"Digit5",Digit6:"Digit6",Digit7:"Digit7",Digit8:"Digit8",Digit9:"Digit9",End:"End",Enter:"Enter",Equal:"Equal",Escape:"Escape",F1:"F1",F10:"F10",F11:"F11",F12:"F12",F13:"F13",F14:"F14",F15:"F15",F16:"F16",F17:"F17",F18:"F18",F19:"F19",F2:"F2",F20:"F20",F21:"F21",F22:"F22",F23:"F23",F24:"F24",F25:"F25",F26:"F26",F27:"F27",F28:"F28",F29:"F29",F3:"F3",F30:"F30",F31:"F31",F32:"F32",F4:"F4",F5:"F5",F6:"F6",F7:"F7",F8:"F8",F9:"F9",Home:"Home",IntlBackslash:"IntlBackslash",IntlRo:"IntlRo",IntlYen:"IntlYen",KeyA:"KeyA",KeyB:"KeyB",KeyC:"KeyC",KeyD:"KeyD",KeyE:"KeyE",KeyF:"KeyF",KeyG:"KeyG",KeyH:"KeyH",KeyI:"KeyI",KeyJ:"KeyJ",KeyK:"KeyK",KeyL:"KeyL",KeyM:"KeyM",KeyN:"KeyN",KeyO:"KeyO",KeyP:"KeyP",KeyQ:"KeyQ",KeyR:"KeyR",KeyS:"KeyS",KeyT:"KeyT",KeyU:"KeyU",KeyV:"KeyV",KeyW:"KeyW",KeyX:"KeyX",KeyY:"KeyY",KeyZ:"KeyZ",Lang1:"Lang1",Lang2:"Lang2",MediaTrackNext:"MediaTrackNext",MediaTrackPrevious:"MediaTrackPrevious",MetaLeft:"MetaLeft",MetaRight:"MetaRight",Minus:"Minus",NumLock:"NumLock",Numpad0:"Numpad0",Numpad1:"Numpad1",Numpad2:"Numpad2",Numpad3:"Numpad3",Numpad4:"Numpad4",Numpad5:"Numpad5",Numpad6:"Numpad6",Numpad7:"Numpad7",Numpad8:"Numpad8",Numpad9:"Numpad9",NumpadAdd:"NumpadAdd",NumpadComma:"NumpadComma",NumpadDecimal:"NumpadDecimal",NumpadDivide:"NumpadDivide",NumpadMultiply:"NumpadMultiply",NumpadSubtract:"NumpadSubtract",OSLeft:"OSLeft",Pause:"Pause",Period:"Period",Quote:"Quote",ScrollLock:"ScrollLock",Semicolon:"Semicolon",ShiftLeft:"ShiftLeft",ShiftRight:"ShiftRight",Slash:"Slash",Space:"Space",Tab:"Tab",VolumeDown:"VolumeDown",VolumeMute:"VolumeMute",VolumeUp:"VolumeUp",WakeUp:"WakeUp"};function __awaiter(e,t,i,s){return new(i||(i=Promise))((function(n,o){function fulfilled(e){try{step(s.next(e))}catch(e){o(e)}}function rejected(e){try{step(s.throw(e))}catch(e){o(e)}}function step(e){e.done?n(e.value):function adopt(e){return e instanceof i?e:new i((function(t){t(e)}))}(e.value).then(fulfilled,rejected)}step((s=s.apply(e,t||[])).next())}))}let c,u;"function"==typeof SuppressedError&&SuppressedError;const l=["fr","mg","lu"],h=["ab","ba","be","bg","ch","kk","ky","mk","mn","ru","sr","tg","tt","uk","uz"],g=["de","cs","sk","sl","hu","hr","bs","ro","sq","me","lt","lv","et"],p=/ф|и|с|в|у|а|п|р|ш|о|л|д|ь|т|щ|з|й|к|ы|е|г|м|ц|ч|н|я|ё|х|ъ|б|ю|э|ж|и/i,m=/[a-z]/i;function inferKeyboardLayoutFromLang(e=function getLang(){var e;const t=navigator;return null!=(null===(e=t.languages)||void 0===e?void 0:e.length)?t.languages[0]:t.userLanguage||t.language||t.browserLanguage}()){const t=(e||"").toLowerCase(),i=t.split("-")[0];return l.includes(i)||t.startsWith("nl-be")?"AZERTY":h.includes(i)?"JCUKEN":g.includes(i)||t.startsWith("sr-latn")?"QWERTZ":"QWERTY"}const v=new Set(["AZERTY","JCUKEN","QWERTY","QWERTZ"]);function getLayoutKeyLabel(e,t){var i,s;if(void 0===u){const e={ArrowLeft:"⬅",ArrowRight:"➡",ArrowUp:"⬆",ArrowDown:"⬇",AltLeft:"Left Alt",AltRight:"Right Alt",Backquote:"`",Backslash:"\\",Backspace:"Backspace",BracketLeft:"[",BracketRight:"]",CapsLock:"CapsLock",Comma:",",ContextMenu:"Context Menu",ControlLeft:"Left Ctrl",ControlRight:"Right Ctrl",Delete:"Delete",Digit0:"0",Digit1:"1",Digit2:"2",Digit3:"3",Digit4:"4",Digit5:"5",Digit6:"6",Digit7:"7",Digit8:"8",Digit9:"9",End:"End",Enter:"Enter",Equal:"=",Escape:"Esc",F1:"F1",F2:"F2",F3:"F3",F4:"F4",F5:"F5",F6:"F6",F7:"F7",F8:"F8",F9:"F9",F10:"F10",F11:"F11",F12:"F12",F13:"F13",F14:"F14",F15:"F15",F16:"F16",F17:"F17",F18:"F18",F19:"F19",F20:"F20",F21:"F21",F22:"F22",F23:"F23",F24:"F24",F25:"F25",F26:"F26",F27:"F27",F28:"F28",F29:"F29",F30:"F30",F31:"F31",F32:"F32",Home:"Home",IntlBackslash:"\\",IntlRo:"Ro",IntlYen:"¥",KeyA:"A",KeyB:"B",KeyC:"C",KeyD:"D",KeyE:"E",KeyF:"F",KeyG:"G",KeyH:"H",KeyI:"I",KeyJ:"J",KeyK:"K",KeyL:"L",KeyM:"M",KeyN:"N",KeyO:"O",KeyP:"P",KeyQ:"Q",KeyR:"R",KeyS:"S",KeyT:"T",KeyU:"U",KeyV:"V",KeyW:"W",KeyX:"X",KeyY:"Y",KeyZ:"Z",Lang1:"Language 1",Lang2:"Language 2",MediaTrackNext:"Next Track",MediaTrackPrevious:"Previous Track",MetaLeft:"Left "+getMetaKeyLabel(),MetaRight:"Right "+getMetaKeyLabel(),Minus:"-",NumLock:"Num Lock",Numpad0:"Num0",Numpad1:"Num1",Numpad2:"Num2",Numpad3:"Num3",Numpad4:"Num4",Numpad5:"Num5",Numpad6:"Num6",Numpad7:"Num7",Numpad8:"Num8",Numpad9:"Num9",NumpadAdd:"+",NumpadComma:",",NumpadDecimal:".",NumpadDivide:"/",NumpadMultiply:"*",NumpadSubtract:"-",OSLeft:"OS Left",Pause:"Pause",Period:".",Quote:"'",ScrollLock:"Scroll Lock",Semicolon:";",ShiftLeft:"Left Shift",ShiftRight:"Right Shift",Slash:"/",Space:"Space",Tab:"Tab",VolumeDown:"Volume Down",VolumeMute:"Volume Mute",VolumeUp:"Volume Up",WakeUp:"Wake Up"};u={AZERTY:{KeyA:"Q",KeyQ:"A",KeyW:"Z",KeyZ:"W",Backquote:"²",BracketLeft:"«",BracketRight:"»"},JCUKEN:{KeyA:"Ф",KeyB:"И",KeyC:"С",KeyD:"В",KeyE:"У",KeyF:"А",KeyG:"П",KeyH:"Р",KeyI:"Ш",KeyJ:"О",KeyK:"Л",KeyL:"Д",KeyM:"Ь",KeyN:"Т",KeyO:"Щ",KeyP:"З",KeyQ:"Й",KeyR:"К",KeyS:"Ы",KeyT:"Е",KeyU:"Г",KeyV:"М",KeyW:"Ц",KeyX:"Ч",KeyY:"Н",KeyZ:"Я",Backquote:"Ё",BracketLeft:"х",BracketRight:"ъ",Comma:"Б",Period:"Ю",Quote:"Э",Semicolon:"Ж",Slash:"И"},QWERTY:e,QWERTZ:{KeyY:"Z",KeyZ:"Y",BracketLeft:"ü",BracketRight:"ö",Slash:"-"}}}return null!==(s=null!==(i=u[t][e])&&void 0!==i?i:u.QWERTY[e])&&void 0!==s?s:e}function getMetaKeyLabel(){var e,t,i,s;const n=navigator,o=null!==(t=null===(e=n.platform)||void 0===e?void 0:e.toLowerCase())&&void 0!==t?t:"",a=null!==(s=null===(i=n.userAgent)||void 0===i?void 0:i.toLowerCase())&&void 0!==s?s:"";return o.includes("mac")?"⌘":o.includes("win")||o.includes("linux")?"⊞":a.includes("android")?"Search":a.includes("iphone")||a.includes("ipad")?"⌘":"⊞"}const y=["navigateLeft","navigateRight","navigateUp","navigateDown"];class KeyboardDevice{constructor(){this.type="keyboard",this.id="keyboard",this.meta={},this.lastInteraction=performance.now(),this.detectLayoutOnKeypress=!0,this.detected=!1,this.options={binds:{},navigation:{enabled:!0,binds:{Space:"trigger",Enter:"trigger",Escape:"navigateBack",Backspace:"navigateBack",ArrowDown:"navigateDown",ArrowLeft:"navigateLeft",ArrowRight:"navigateRight",ArrowUp:"navigateUp",KeyA:"navigateLeft",KeyD:"navigateRight",KeyS:"navigateDown",KeyW:"navigateUp"}}},this.key=Object.keys(d).reduce(((e,t)=>(e[t]=!1,e)),{}),this._emitter=new EventEmitter,this._bindEmitter=new EventEmitter,this._deferredKeydown=[],this._layout=inferKeyboardLayoutFromLang(),this._layoutSource="lang",function requestKeyboardLayout(){return __awaiter(this,void 0,void 0,(function*(){const e=navigator;if(e.keyboard&&e.keyboard.getLayoutMap)try{const t=yield e.keyboard.getLayoutMap();c=t;const i=t.get("KeyQ"),s=t.get("KeyA"),n=t.get("KeyZ");if("a"===i&&"w"===n&&"q"===s)return"AZERTY";if("q"===i&&"y"===n&&"a"===s)return"QWERTZ";if("q"===i&&"z"===n&&"a"===s)return"QWERTY";if("й"===i&&"я"===n&&"ф"===s)return"JCUKEN"}catch(e){}}))}().then((e=>{void 0!==e&&(this._layoutSource="browser",this._layout=e,this.detectLayoutOnKeypress=!1,this._emitter.emit("layoutdetected",{layoutSource:"browser",layout:e,device:this}))})),this._configureEventListeners()}get layout(){return this._layout}set layout(e){this._layoutSource="manual",this._layout=e,this.detectLayoutOnKeypress=!1}get layoutSource(){return this._layoutSource}pressedBind(e){return void 0!==this.options.binds[e]&&this.pressedAny(this.options.binds[e])}pressedAny(e){for(let t=0;t<e.length;t++)if(this.key[e[t]])return!0;return!1}pressedAll(e){for(let t=0;t<e.length;t++)if(!this.key[e[t]])return!1;return!0}on(e,t){return this._emitter.on(e,t),this}off(e,t){return this._emitter.off(e,t),this}onBind(e,t){return this._bindEmitter.on(e,t),this}offBind(e,t){return this._bindEmitter.off(e,t),this}getKeyLabel(e,t){var i;return t?getLayoutKeyLabel(e,t):null!==(i=function getNavigatorKeyLabel(e){const t=null==c?void 0:c.get(e);return void 0===t?void 0:function _toLocaleTitleCase(e){return e.split(/\s+/).map((e=>e.charAt(0).toLocaleUpperCase()+e.slice(1))).join(" ")}(t)}(e))&&void 0!==i?i:getLayoutKeyLabel(e,null!=t?t:this._layout)}update(e){this._deferredKeydown.length>0&&(this._deferredKeydown.forEach((e=>this._processDeferredKeydownEvent(e))),this._deferredKeydown.length=0)}clear(){for(const e of Object.keys(d))this.key[e]=!1}_configureEventListeners(){const e=this.key,t=this._deferredKeydown;window.addEventListener("keydown",(i=>{e[i.code]=!0,t.push(i),this.lastInteraction=performance.now()}),{passive:!0,capture:!0}),window.addEventListener("keyup",(t=>{e[t.code]=!1,this.lastInteraction=performance.now()}),{passive:!0,capture:!0})}_processDeferredKeydownEvent(e){const t=e.code;if(!e.repeat){if(this.detectLayoutOnKeypress&&"lang"===this._layoutSource){const t=function detectKeyboardLayoutFromKeydown(e){const t=e.key.toLowerCase(),i=e.code;return p.test(t)?(v.delete("AZERTY"),v.delete("QWERTY"),v.delete("QWERTZ")):"Backquote"===i&&"²"===t||"BracketLeft"===i&&"«"===t||"BracketRight"===i&&"»"===t||"KeyA"===i&&"q"===t||"KeyQ"===i&&"a"===t||"KeyW"===i&&"z"===t||"KeyZ"===i&&"w"===t?(v.delete("JCUKEN"),v.delete("QWERTY"),v.delete("QWERTZ")):"BracketLeft"===i&&"ü"===t||"BracketRight"===i&&"ö"===t||"KeyY"===i&&"z"===t||"KeyZ"===i&&"y"===t||"Slash"===i&&"-"===t?(v.delete("AZERTY"),v.delete("JCUKEN"),v.delete("QWERTY")):"BracketLeft"===i&&"["===t||"BracketRight"===i&&"]"===t||"KeyZ"===i&&"z"===t?(v.delete("AZERTY"),v.delete("JCUKEN"),v.delete("QWERTZ")):"KeyQ"===i&&"q"===t||"KeyW"===i&&"w"===t?(v.delete("AZERTY"),v.delete("JCUKEN")):"KeyY"===i&&"Y"===t?(v.delete("QWERTZ"),v.delete("JCUKEN")):m.test(t)&&v.delete("JCUKEN"),1===v.size?[...v][0]:void 0}(e);void 0!==t&&(this._layout=t,this._layoutSource="keypress",this.detectLayoutOnKeypress=!1,this._emitter.emit("layoutdetected",{layout:t,layoutSource:"keypress",device:this}))}this._emitter.hasListener(t)&&setTimeout((()=>this._emitter.emit(t,{device:this,keyCode:t,keyLabel:this.getKeyLabel(t),event:e}))),Object.entries(this.options.binds).forEach((([i,s])=>{s.includes(t)&&setTimeout((()=>{const s={device:this,keyCode:t,keyLabel:this.getKeyLabel(t),event:e,name:i};this._bindEmitter.emit(i,s),this._emitter.emit("bind",s)}))}))}if(a.options.enabled&&this.options.navigation.enabled&&void 0!==this.options.navigation.binds[t]){const i=this.options.navigation.binds[t];e.repeat&&!y.includes(i)||setTimeout((()=>a.commit(this.options.navigation.binds[t],this)))}}}KeyboardDevice.global=new KeyboardDevice;class InputDeviceManager{constructor(){this.isMobile=(()=>{let e=!1;var t;return t=navigator.userAgent||navigator.vendor,(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(t)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(t.substr(0,4)))&&(e=!0),e})(),this.isTouchCapable=function isTouchCapable(){return"ontouchstart"in window||navigator.maxTouchPoints>0}(),this.options={requireFocus:!0,clearInputInBackground:!0},this._devices=[],this._gamepadDevices=[],this._gamepadDeviceMap=new Map,this._customDevices=[],this._emitter=new EventEmitter,this._bindEmitter=new EventEmitter,this._hasFocus=!1,this.keyboard=KeyboardDevice.global,this.isTouchCapable||this.isMobile?window.addEventListener("keydown",(()=>this.add(this.keyboard)),{once:!0}):this.add(this.keyboard),window.addEventListener("gamepadconnected",(()=>this._pollGamepads(performance.now()))),window.addEventListener("gamepaddisconnected",(e=>this._removeGamepad(e.gamepad.index)))}get devices(){return this._devices}get gamepads(){return this._gamepadDevices}get custom(){return this._customDevices}get lastInteractedDevice(){return this._lastInteractedDevice}on(e,t){return this._emitter.on(e,t),this}off(e,t){return this._emitter.off(e,t),this}onBind(e,t){return this._bindEmitter.on(e,t),this}offBind(e,t){return this._bindEmitter.off(e,t),this}emitBind(e){this._bindEmitter.emit(e.name,e)}add(e){-1===this._devices.indexOf(e)&&(this._devices.push(e),e instanceof KeyboardDevice?(e.detected=!0,e.on("bind",(e=>this.emitBind(e)))):e instanceof GamepadDevice?(this._gamepadDeviceMap.set(e.source.index,e),this._gamepadDevices.push(e),e.on("bind",(e=>this.emitBind(e)))):this._customDevices.push(e),this._emitter.emit("deviceadded",{device:e}))}remove(e){if(!(e instanceof KeyboardDevice||e instanceof GamepadDevice)){const t=this._customDevices.indexOf(e);-1!==t&&this._devices.splice(t,1)}const t=this._devices.indexOf(e);-1!==t&&(this._devices.splice(t,1),this._emitter.emit("deviceremoved",{device:e}))}update(){if(this.options.requireFocus&&!document.hasFocus())return this._hasFocus&&this.options.clearInputInBackground&&this.devices.forEach((e=>{var t;return null===(t=e.clear)||void 0===t?void 0:t.call(e)})),this._hasFocus=!1,this._devices;this._hasFocus=!0;const e=performance.now();return this.keyboard.detected&&this.keyboard.update(e),this._gamepadDevices.length>0&&this._pollGamepads(e),this._customDevices.length>0&&this._customDevices.forEach((t=>t.update(e))),this._updateLastInteracted(),this._devices}_updateLastInteracted(){if(0===this._devices.length)return;let e;if(1===this._devices.length)e=this._devices[0];else for(const t of this._devices)(void 0===e||t.lastInteraction>e.lastInteraction)&&(e=t);this._lastInteractedDevice=e}_pollGamepads(e){if(!document.hasFocus())return this._gamepadDevices;if(void 0===navigator.getGamepads)return this._gamepadDevices;for(const t of navigator.getGamepads())if(null!=t)if(this._gamepadDeviceMap.has(t.index)){this._gamepadDeviceMap.get(t.index).update(t,e)}else{const i=new GamepadDevice(t);this.add(i),i.update(t,e)}return this._gamepadDevices}_removeGamepad(e){const t=this._gamepadDeviceMap.get(e);if(!t)return;const i=this._gamepadDevices.indexOf(t);-1!==i&&this._gamepadDevices.splice(i,1),this.remove(t),this._gamepadDeviceMap.delete(e)}}InputDeviceManager.global=new InputDeviceManager;const f=InputDeviceManager.global;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{n as Button,GamepadDevice,f as InputDevice,d as KeyCode,KeyboardDevice,a as Navigation,y as REPEATABLE_NAV_INTENTS,getAllNavigatables,getFirstNavigatable,isChildOf,registerPixiJSInputDeviceMixin};
2
2
  //# sourceMappingURL=index.mjs.map