// All material copyright Esri, All Rights Reserved, unless otherwise specified. // See https://js.arcgis.com/4.30/esri/copyright.txt for details. //>>built define(["exports","../../../core/scheduling","./GamepadInputDevice","./GamepadState"],function(h,m,n,g){function k(b){const d=window.navigator.getGamepads();for(let c=0;c{this._connectGamepad(a.gamepad)};this._onDisconnectGamepad=a=>{a=a.gamepad; const c=a.index,e=this._inputDevices[c];e&&(this._emitGamepadEvent(a,g.extractState(e),!1),this._inputDevices.splice(c,1),this._latestUpdate.splice(c,1),this._input.gamepad.devices.remove(e),this.ensurePollingState())};this._frameTask=null;this._latestUpdate=[];this._inputDevices=[];this._callback=null;b=window.isSecureContext;if(this.supported="getGamepads"in window.navigator&&b)k(a=>this._connectGamepad(a)),window.addEventListener("gamepadconnected",this._onConnectGamepad),window.addEventListener("gamepaddisconnected", this._onDisconnectGamepad),this.ensurePollingState()}destroy(){this.hasEventListeners=!1;this.supported&&(window.removeEventListener("gamepadconnected",this._onConnectGamepad),window.removeEventListener("gamepaddisconnected",this._onDisconnectGamepad))}set hasEventListeners(b){this._hasEventListeners!==b&&(this._hasEventListeners=b,this.ensurePollingState())}get _eventsEnabled(){return this.supported&&0this._readGamepadState()}))}_stopPolling(){null!=this._frameTask&&(this._frameTask.remove(),this._frameTask=null,this._latestUpdate=[])}_readGamepadState(){const b=document.hasFocus(),d=this._element.contains(document.activeElement), a="document"===this._input.gamepad.enabledFocusMode&&!b||"view"===this._input.gamepad.enabledFocusMode&&!d;k(c=>{var e=this._inputDevices[c.index];if(e){var f=this._latestUpdate[c.index];e=g.extractState(e);var l=a||g.stateIdle(e);f&&(f.timestamp===c.timestamp||!f.active&&l||g.stateEqual(f.state,e))||this._emitGamepadEvent(c,e,!l)}})}_emitGamepadEvent(b,d,a){var c=this._latestUpdate[b.index];if((c=c&&c.active)||a)this._latestUpdate[b.index]={timestamp:b.timestamp,state:d,active:a},this._callback&& this._callback({device:this._inputDevices[b.index],state:d,action:!c&&a?"start":c&&a?"update":"end"})}}h.GamepadSource=p;Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});