1import{b as v}from"./index.k2Romlaj.js";const p={a:0,b:1,x:2,y:3,lb:4,rb:5,lt:6,rt:7,back:8,start:9,l3:10,ls:10,r3:11,rs:11,u:12,up:12,d:13,down:13,l:14,left:14,r:15,right:15};class w{constructor(t=1e3){this.sequence=[],this.timeWindow=t,this.lastInputTime=0,this.buttonStates=Array(16).fill(0)}addInput(t,n){const a=Date.now();if(n===1&&this.buttonStates[t]===0){a-this.lastInputTime>this.timeWindow&&(this.sequence=[]);const e=Object.keys(p).find(o=>p[o]===t)||t.toString();this.sequence.push({input:e,timestamp:a}),this.lastInputTime=a,this.sequence=this.sequence.filter(o=>a-o.timestamp<=this.timeWindow)}this.buttonStates[t]=n}checkSequence(t){if(!Array.isArray(t)&&typeof t!="string")return console.error("ButtonSequenceDetector: targetSequence must be an array or string"),0;if(this.sequence.length<t.length)return 0;const n=typeof t=="string"?t.toLowerCase().split(""):t.map(e=>e.toString().toLowerCase());return this.sequence.slice(-t.length).map(e=>e.input).every((e,o)=>{const r=n[o];return e===r||p[e]===p[r]||p[e]===parseInt(r)})?1:0}}class x{constructor(t=0){this._gamepads={},this._activeGamepad=t,this._axes=[0,0,0,0],this._buttons=Array(16).fill(0),this.setupEventListeners()}setupEventListeners(){window.addEventListener("gamepadconnected",t=>{this._gamepads[t.gamepad.index]=t.gamepad,this._activeGamepad||(this._activeGamepad=t.gamepad.index)}),window.addEventListener("gamepaddisconnected",t=>{delete this._gamepads[t.gamepad.index],this._activeGamepad===t.gamepad.index&&(this._activeGamepad=Object.keys(this._gamepads)[0]||null)})}poll(){if(this._activeGamepad!==null){const t=navigator.getGamepads()[this._activeGamepad];t&&(this._axes=t.axes.map(n=>(n+1)/2),this._buttons=t.buttons.map(n=>n.value))}}getAxes(){return this._axes}getButtons(){return this._buttons}}const u=new Map,q=(m=0)=>{const t=new x(m),n=new w(2e3),a=v(s=>{t.poll();const i=t.getAxes(),c=t.getButtons();return c.forEach((g,d)=>{n.addInput(d,g)}),{axes:i,buttons:c,t:s}}),e={x1:a.fmap(s=>s.axes[0]),y1:a.fmap(s=>s.axes[1]),x2:a.fmap(s=>s.axes[2]),y2:a.fmap(s=>s.axes[3])};e.x1_2=e.x1.toBipolar(),e.y1_2=e.y1.toBipolar(),e.x2_2=e.x2.toBipolar(),e.y2_2=e.y2.toBipolar();const o=Array(16).fill(null).map((s,i)=>{const c=`gamepad${m}_btn${i}`;u.has(c)||u.set(c,{lastButtonState:0,toggleState:0});const g=a.fmap(h=>h.buttons[i]),d=a.fmap(h=>{const b=h.buttons[i],l=u.get(c);return b===1&&l.lastButtonState===0&&(l.toggleState=l.toggleState===0?1:0),l.lastButtonState=b,l.toggleState});return{value:g,toggle:d}}),r=s=>a.fmap(()=>n.checkSequence(s)),_=r,f=r,S=f;return{...e,buttons:o,...Object.fromEntries(Object.entries(p).flatMap(([s,i])=>[[s.toLowerCase(),o[i].value],[s.toUpperCase(),o[i].value],[`tgl${s.toLowerCase()}`,o[i].toggle],[`tgl${s.toUpperCase()}`,o[i].toggle]])),checkSequence:_,btnSequence:r,btnSeq:f,btnseq:S,raw:a}},B=()=>Object.fromEntries(u),G=()=>u.clear();export{p as buttonMap,G as clearGamepadStates,q as gamepad,B as getGamepadStates};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.