tiny-essentials 1.26.4 → 1.27.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.
Files changed (120) hide show
  1. package/.github/workflows/node.js.yml +1 -1
  2. package/README.md +0 -1
  3. package/changelog/1/27/0.md +24 -0
  4. package/dist/v1/ColorSafeStringify.min.js +1 -1
  5. package/dist/v1/TinyAdvancedRaffle.min.js +1 -1
  6. package/dist/v1/TinyAfterScrollWatcher.min.js +1 -1
  7. package/dist/v1/TinyAnalogClock.min.js +1 -1
  8. package/dist/v1/TinyArrayComparator.min.js +1 -1
  9. package/dist/v1/TinyArrayPaginator.min.js +1 -1
  10. package/dist/v1/TinyBasicsEs.min.js +1 -1
  11. package/dist/v1/TinyClassManager.min.js +1 -1
  12. package/dist/v1/TinyClipboard.min.js +1 -1
  13. package/dist/v1/TinyColorConverter.min.js +1 -1
  14. package/dist/v1/TinyColorValidator.min.js +1 -1
  15. package/dist/v1/TinyCookieConsent.min.js +1 -1
  16. package/dist/v1/TinyDayNightCycle.min.js +1 -1
  17. package/dist/v1/TinyDomReadyManager.min.js +1 -1
  18. package/dist/v1/TinyDragDropDetector.min.js +1 -1
  19. package/dist/v1/TinyDragger.min.js +1 -1
  20. package/dist/v1/TinyElementObserver.min.js +1 -1
  21. package/dist/v1/TinyEssentials.min.js +1 -1
  22. package/dist/v1/TinyEvents.min.js +1 -1
  23. package/dist/v1/TinyGamepad.min.js +1 -1
  24. package/dist/v1/TinyHtml.min.js +1 -1
  25. package/dist/v1/TinyI18.min.js +1 -1
  26. package/dist/v1/TinyIframeEvents.min.js +1 -1
  27. package/dist/v1/TinyInventory.min.js +1 -1
  28. package/dist/v1/TinyInventoryTrader.min.js +1 -1
  29. package/dist/v1/TinyLevelUp.min.js +1 -1
  30. package/dist/v1/TinyLoadingScreen.min.js +1 -1
  31. package/dist/v1/TinyLocalStorage.min.js +1 -1
  32. package/dist/v1/TinyMaInSys.min.js +1 -1
  33. package/dist/v1/TinyMediaPlayer.min.js +1 -0
  34. package/dist/v1/TinyNeedBar.min.js +1 -1
  35. package/dist/v1/TinyNewWinEvents.min.js +1 -1
  36. package/dist/v1/TinyNotifications.min.js +1 -1
  37. package/dist/v1/TinyNotifyCenter.min.js +1 -1
  38. package/dist/v1/TinyPromiseQueue.min.js +1 -1
  39. package/dist/v1/TinyRadioFm.min.js +1 -0
  40. package/dist/v1/TinyRateLimiter.min.js +1 -1
  41. package/dist/v1/TinySimpleDice.min.js +1 -1
  42. package/dist/v1/TinySmartScroller.min.js +1 -1
  43. package/dist/v1/TinyTextDiffer.min.js +1 -1
  44. package/dist/v1/TinyTextRangeEditor.min.js +1 -1
  45. package/dist/v1/TinyTextarea.min.js +1 -1
  46. package/dist/v1/TinyTimeout.min.js +1 -1
  47. package/dist/v1/TinyToastNotify.min.js +1 -1
  48. package/dist/v1/TinyUploadClicker.min.js +1 -1
  49. package/dist/v1/UltraRandomMsgGen.min.js +1 -1
  50. package/dist/v1/basics/index.cjs +5 -0
  51. package/dist/v1/basics/index.d.mts +5 -1
  52. package/dist/v1/basics/index.mjs +2 -1
  53. package/dist/v1/basics/mediaContent.cjs +644 -0
  54. package/dist/v1/basics/mediaContent.d.mts +296 -0
  55. package/dist/v1/basics/mediaContent.mjs +557 -0
  56. package/dist/v1/build/TinyMediaPlayer.cjs +7 -0
  57. package/dist/v1/build/TinyMediaPlayer.d.mts +3 -0
  58. package/dist/v1/build/TinyMediaPlayer.mjs +2 -0
  59. package/dist/v1/build/TinyRadioFm.cjs +7 -0
  60. package/dist/v1/build/TinyRadioFm.d.mts +3 -0
  61. package/dist/v1/build/TinyRadioFm.mjs +2 -0
  62. package/dist/v1/index.cjs +9 -0
  63. package/dist/v1/index.d.mts +7 -1
  64. package/dist/v1/index.mjs +5 -2
  65. package/dist/v1/libs/ColorSafeStringify.d.mts +1 -1
  66. package/dist/v1/libs/TinyAfterScrollWatcher.cjs +16 -3
  67. package/dist/v1/libs/TinyAfterScrollWatcher.d.mts +7 -3
  68. package/dist/v1/libs/TinyAfterScrollWatcher.mjs +13 -3
  69. package/dist/v1/libs/TinyArrayComparator.cjs +14 -11
  70. package/dist/v1/libs/TinyArrayComparator.d.mts +22 -19
  71. package/dist/v1/libs/TinyArrayComparator.mjs +14 -11
  72. package/dist/v1/libs/TinyArrayPaginator.cjs +23 -16
  73. package/dist/v1/libs/TinyArrayPaginator.d.mts +57 -30
  74. package/dist/v1/libs/TinyArrayPaginator.mjs +22 -16
  75. package/dist/v1/libs/TinyClassManager/TinyPluginInliner.cjs +265 -0
  76. package/dist/v1/libs/TinyClassManager/TinyPluginInliner.d.mts +92 -0
  77. package/dist/v1/libs/TinyClassManager/TinyPluginInliner.mjs +223 -0
  78. package/dist/v1/libs/TinyClassManager.cjs +52 -22
  79. package/dist/v1/libs/TinyClassManager.d.mts +26 -16
  80. package/dist/v1/libs/TinyClassManager.mjs +50 -21
  81. package/dist/v1/libs/TinyColorValidator.d.mts +16 -16
  82. package/dist/v1/libs/TinyDragDropDetector.cjs +9 -34
  83. package/dist/v1/libs/TinyDragDropDetector.d.mts +7 -21
  84. package/dist/v1/libs/TinyDragDropDetector.mjs +9 -24
  85. package/dist/v1/libs/TinyDragger.cjs +5 -5
  86. package/dist/v1/libs/TinyDragger.d.mts +4 -3
  87. package/dist/v1/libs/TinyDragger.mjs +5 -5
  88. package/dist/v1/libs/TinyElementObserver.cjs +6 -21
  89. package/dist/v1/libs/TinyElementObserver.d.mts +6 -15
  90. package/dist/v1/libs/TinyElementObserver.mjs +6 -20
  91. package/dist/v1/libs/TinyGamepad.cjs +4 -6
  92. package/dist/v1/libs/TinyGamepad.d.mts +1 -1
  93. package/dist/v1/libs/TinyHtml/TinyHtmlIcon.d.mts +1 -1
  94. package/dist/v1/libs/TinyHtml/TinyHtmlTemplate.d.mts +1 -1
  95. package/dist/v1/libs/TinyHtml/TinyHtmlTextarea.d.mts +1 -1
  96. package/dist/v1/libs/TinyHtml/index.d.mts +1 -1
  97. package/dist/v1/libs/TinyHtml.cjs +72 -98
  98. package/dist/v1/libs/TinyHtml.d.mts +15 -32
  99. package/dist/v1/libs/TinyHtml.mjs +53 -77
  100. package/dist/v1/libs/TinyInventory.d.mts +1 -1
  101. package/dist/v1/libs/TinyMediaPlayer.cjs +844 -0
  102. package/dist/v1/libs/TinyMediaPlayer.d.mts +306 -0
  103. package/dist/v1/libs/TinyMediaPlayer.mjs +755 -0
  104. package/dist/v1/libs/TinyRadioFm.cjs +1378 -0
  105. package/dist/v1/libs/TinyRadioFm.d.mts +554 -0
  106. package/dist/v1/libs/TinyRadioFm.mjs +1137 -0
  107. package/dist/v1/libs/TinySmartScroller.cjs +39 -26
  108. package/dist/v1/libs/TinySmartScroller.d.mts +16 -62
  109. package/dist/v1/libs/TinySmartScroller.mjs +35 -26
  110. package/dist/v1/libs/UltraRandomMsgGen.d.mts +7 -7
  111. package/docs/v1/README.md +6 -0
  112. package/docs/v1/basics/mediaContent.md +131 -0
  113. package/docs/v1/libs/TinyClassManager/TinyPluginInliner.md +107 -0
  114. package/docs/v1/libs/TinyDragDropDetector.md +5 -9
  115. package/docs/v1/libs/TinyElementObserver.md +3 -6
  116. package/docs/v1/libs/TinyHtml.md +0 -29
  117. package/docs/v1/libs/TinyMediaPlayer.md +100 -0
  118. package/docs/v1/libs/TinyRadioFm.md +141 -0
  119. package/docs/v1/libs/TinySmartScroller.md +3 -3
  120. package/package.json +40 -22
@@ -1 +1 @@
1
- (()=>{"use strict";var e={d:(t,n)=>{for(var r in n)e.o(n,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:n[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},t={};e.d(t,{TinyEvents:()=>n});const n=class{#e=new Map;#t=10;#n=!1;#r(e,t){if("string"==typeof e)return[e];if(Array.isArray(e)&&e.every(e=>"string"==typeof e))return e;throw new TypeError(`${t}(event): event must be a string or string[]`)}setThrowOnMaxListeners(e){if("boolean"!=typeof e)throw new TypeError("setThrowOnMaxListeners(value): value must be a boolean");this.#n=e}getThrowOnMaxListeners(){return this.#n}#s(e,t,{once:n=!1}={}){let r=this.#e.get(e);Array.isArray(r)||(r=[],this.#e.set(e,r)),r.unshift({handler:t,config:{once:n}});const s=this.#t;if(s>0&&r.length>s){const t=`Possible memory leak detected. ${r.length} "${e}" listeners added. Use setMaxListeners() to increase limit.`;if(this.#n)throw new Error(t);console.warn(t)}}prependListener(e,t){const n=this.#r(e,"prependListener");if("function"!=typeof t)throw new TypeError("prependListener(event, handler): handler must be a function");for(const e of n)this.#s(e,t)}prependListenerOnce(e,t){const n=this.#r(e,"prependListenerOnce");if("function"!=typeof t)throw new TypeError("prependListenerOnce(event, handler): handler must be a function");const r=[];for(const e of n){const n=(...r)=>{this.off(e,n),t(...r)};this.#s(e,n,{once:!0}),r.push(n)}return r}#i(e,t,{once:n=!1}={}){const r=this.#r(e,"on");for(const e of r){let r=this.#e.get(e);Array.isArray(r)||(r=[],this.#e.set(e,r)),r.push({handler:t,config:{once:n}});const s=this.#t;if(s>0&&r.length>s){const t=`Possible memory leak detected. ${r.length} "${e}" listeners added. Use setMaxListeners() to increase limit.`;if(this.#n)throw new Error(t);console.warn(t)}}}on(e,t){if("function"!=typeof t)throw new TypeError("on(event, handler): handler must be a function");return this.#i(e,t)}once(e,t){const n=this.#r(e,"once");if("function"!=typeof t)throw new TypeError("once(event, handler): handler must be a function");const r=[];for(const e of n){const n=(...r)=>{this.off(e,n),t(...r)};this.#i(e,n,{once:!0}),r.push(n)}return r}appendListener(e,t){return this.on(e,t)}appendListenerOnce(e,t){return this.once(e,t)}off(e,t){const n=this.#r(e,"off");if("function"!=typeof t)throw new TypeError("off(event, handler): handler must be a function");for(const e of n){const n=this.#e.get(e);if(!Array.isArray(n))continue;const r=n.findIndex(e=>e.handler===t);-1!==r&&n.splice(r,1),0===n.length&&this.#e.delete(e)}}offAll(e){const t=this.#r(e,"offAll");for(const e of t)this.#e.delete(e)}offAllTypes(){this.#e.clear()}removeAllListeners(){return this.offAllTypes()}listenerCount(e){if("string"!=typeof e)throw new TypeError("listenerCount(event): event name must be a string");const t=this.#e.get(e);return Array.isArray(t)?t.length:0}listeners(e){if("string"!=typeof e)throw new TypeError("listeners(event): event name must be a string");const t=this.#e.get(e);return Array.isArray(t)?[...t].filter(e=>!e.config.once).map(e=>e.handler):[]}onceListeners(e){if("string"!=typeof e)throw new TypeError("onceListeners(event): event name must be a string");const t=this.#e.get(e);return Array.isArray(t)?[...t].filter(e=>e.config.once).map(e=>e.handler):[]}allListeners(e){if("string"!=typeof e)throw new TypeError("allListeners(event): event name must be a string");const t=this.#e.get(e);return Array.isArray(t)?[...t].map(e=>e.handler):[]}eventNames(){return[...this.#e.keys()]}emit(e,...t){const n=this.#r(e,"emit"),r=[];for(const e of n){const n=this.#e.get(e);Array.isArray(n)&&0!==n.length?(n.forEach(e=>e.handler(...t)),r.push(!0)):r.push(!1)}return r}setMaxListeners(e){if(!Number.isInteger(e)||e<0)throw new TypeError("setMaxListeners(n): n must be a non-negative integer");this.#t=e}getMaxListeners(){return this.#t}};window.TinyEvents=t.TinyEvents})();
1
+ (()=>{"use strict";const e={d:(t,n)=>{if(Array.isArray(n))for(var r=0;r<n.length;){var s=n[r++],i=n[r++];e.o(t,s)?0===i&&r++:0===i?Object.defineProperty(t,s,{enumerable:!0,value:n[r++]}):Object.defineProperty(t,s,{enumerable:!0,get:i})}else for(var s in n)e.o(n,s)&&!e.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:n[s]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};let t={};e.d(t,{TinyEvents:()=>n});const n=class{#e=new Map;#t=10;#n=!1;#r(e,t){if("string"==typeof e)return[e];if(Array.isArray(e)&&e.every(e=>"string"==typeof e))return e;throw new TypeError(`${t}(event): event must be a string or string[]`)}setThrowOnMaxListeners(e){if("boolean"!=typeof e)throw new TypeError("setThrowOnMaxListeners(value): value must be a boolean");this.#n=e}getThrowOnMaxListeners(){return this.#n}#s(e,t,{once:n=!1}={}){let r=this.#e.get(e);Array.isArray(r)||(r=[],this.#e.set(e,r)),r.unshift({handler:t,config:{once:n}});const s=this.#t;if(s>0&&r.length>s){const t=`Possible memory leak detected. ${r.length} "${e}" listeners added. Use setMaxListeners() to increase limit.`;if(this.#n)throw new Error(t);console.warn(t)}}prependListener(e,t){const n=this.#r(e,"prependListener");if("function"!=typeof t)throw new TypeError("prependListener(event, handler): handler must be a function");for(const e of n)this.#s(e,t)}prependListenerOnce(e,t){const n=this.#r(e,"prependListenerOnce");if("function"!=typeof t)throw new TypeError("prependListenerOnce(event, handler): handler must be a function");const r=[];for(const e of n){const n=(...r)=>{this.off(e,n),t(...r)};this.#s(e,n,{once:!0}),r.push(n)}return r}#i(e,t,{once:n=!1}={}){const r=this.#r(e,"on");for(const e of r){let r=this.#e.get(e);Array.isArray(r)||(r=[],this.#e.set(e,r)),r.push({handler:t,config:{once:n}});const s=this.#t;if(s>0&&r.length>s){const t=`Possible memory leak detected. ${r.length} "${e}" listeners added. Use setMaxListeners() to increase limit.`;if(this.#n)throw new Error(t);console.warn(t)}}}on(e,t){if("function"!=typeof t)throw new TypeError("on(event, handler): handler must be a function");return this.#i(e,t)}once(e,t){const n=this.#r(e,"once");if("function"!=typeof t)throw new TypeError("once(event, handler): handler must be a function");const r=[];for(const e of n){const n=(...r)=>{this.off(e,n),t(...r)};this.#i(e,n,{once:!0}),r.push(n)}return r}appendListener(e,t){return this.on(e,t)}appendListenerOnce(e,t){return this.once(e,t)}off(e,t){const n=this.#r(e,"off");if("function"!=typeof t)throw new TypeError("off(event, handler): handler must be a function");for(const e of n){const n=this.#e.get(e);if(!Array.isArray(n))continue;const r=n.findIndex(e=>e.handler===t);-1!==r&&n.splice(r,1),0===n.length&&this.#e.delete(e)}}offAll(e){const t=this.#r(e,"offAll");for(const e of t)this.#e.delete(e)}offAllTypes(){this.#e.clear()}removeAllListeners(){return this.offAllTypes()}listenerCount(e){if("string"!=typeof e)throw new TypeError("listenerCount(event): event name must be a string");const t=this.#e.get(e);return Array.isArray(t)?t.length:0}listeners(e){if("string"!=typeof e)throw new TypeError("listeners(event): event name must be a string");const t=this.#e.get(e);return Array.isArray(t)?[...t].filter(e=>!e.config.once).map(e=>e.handler):[]}onceListeners(e){if("string"!=typeof e)throw new TypeError("onceListeners(event): event name must be a string");const t=this.#e.get(e);return Array.isArray(t)?[...t].filter(e=>e.config.once).map(e=>e.handler):[]}allListeners(e){if("string"!=typeof e)throw new TypeError("allListeners(event): event name must be a string");const t=this.#e.get(e);return Array.isArray(t)?[...t].map(e=>e.handler):[]}eventNames(){return[...this.#e.keys()]}emit(e,...t){const n=this.#r(e,"emit"),r=[];for(const e of n){const n=this.#e.get(e);Array.isArray(n)&&0!==n.length?(n.forEach(e=>e.handler(...t)),r.push(!0)):r.push(!1)}return r}setMaxListeners(e){if(!Number.isInteger(e)||e<0)throw new TypeError("setMaxListeners(n): n must be a non-negative integer");this.#t=e}getMaxListeners(){return this.#t}};window.TinyEvents=t.TinyEvents})();
@@ -1 +1 @@
1
- (()=>{"use strict";var e={d:(t,n)=>{for(var i in n)e.o(n,i)&&!e.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:n[i]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},t={};e.d(t,{TinyGamepad:()=>i});class n{#e=!1;#t=new Set;#n=new Map;#i=new Map;#s=null;#a=[];#r={};#o=[];#p=null;#d=null;#c;#u;#l;#m;#h;#y;#f;#g;#v=[];#b=0;#w=0;#I=[];#E=0;#M=null;#S=new Set;#k=new Set;#T=new Map;#K=new Map;#A=new Map;static#C={" ":"Space","\n":"Enter","\r":"Enter","\t":"Tab","-":"Minus",_:"Minus","=":"Equal","+":"Equal","[":"BracketLeft","{":"BracketLeft","]":"BracketRight","}":"BracketRight","\\":"Backslash","|":"Backslash",";":"Semicolon",":":"Semicolon","'":"Quote",'"':"Quote",",":"Comma","<":"Comma",".":"Period",">":"Period","/":"Slash","?":"Slash","`":"Backquote","~":"Backquote"};static addSpecialKey(e,t){if("string"!=typeof e)throw new TypeError("Invalid char type: expected string, got "+typeof e);if(1!==e.length)throw new Error(`Invalid char length: "${e}" (must be exactly one character)`);if("string"!=typeof t)throw new TypeError("Invalid code type: expected string, got "+typeof t);n.#C[e]=t}static removeSpecialKey(e){if("string"!=typeof e)throw new TypeError("Invalid char type: expected string, got "+typeof e);if(1!==e.length)throw new Error(`Invalid char length: "${e}" (must be exactly one character)`);delete n.#C[e]}static getSpecialKey(e){if("string"!=typeof e)throw new TypeError("Invalid char type: expected string, got "+typeof e);if(1!==e.length)throw new Error(`Invalid char length: "${e}" (must be exactly one character)`);return n.#C[e]}static getAllSpecialKeys(){return{...n.#C}}static stringToKeys(e){if("string"!=typeof e)throw new TypeError("Invalid text type: expected string, got "+typeof e);if(!e.length)throw new Error("Invalid text: cannot be empty");return Array.from(e).map(e=>{const t=e.toUpperCase();if(t>="A"&&t<="Z")return`Key${t}`;if(t>="0"&&t<="9")return`Digit${t}`;const i=n.#C[e];if(void 0!==i)return i;throw new Error(`Unsupported character: "${e}"`)})}constructor({expectedId:e=null,inputMode:t="both",ignoreIds:n=[],deadZone:i=.1,axisActiveSensitivity:s=.3,timeoutComboKeys:a=500,allowMouse:r=!1,elementBase:o=window}={}){if(null!==e&&"string"!=typeof e)throw new TypeError('"expectedId" must be a string or null, received: '+typeof e);if(!["keyboard-only","gamepad-only","both"].includes(t))throw new TypeError(`"inputMode" must be 'keyboard-only', 'gamepad-only', or 'both', received: ${t}`);if(!Array.isArray(n)||!n.every(e=>"string"==typeof e))throw new TypeError('"ignoreIds" must be an array of strings');if("number"!=typeof i||i<0||i>1)throw new RangeError(`"deadZone" must be a number between 0 and 1, received: ${i}`);if("number"!=typeof s||s<0||s>1)throw new RangeError(`"axisActiveSensitivity" must be a number between 0 and 1, received: ${s}`);if("number"!=typeof a||a<0)throw new RangeError(`"timeoutComboKeys" must be a positive number, received: ${a}`);if("boolean"!=typeof r)throw new TypeError('"allowMouse" must be a boolean, received: '+typeof r);if(!(o instanceof Window||o instanceof Element))throw new TypeError('"elementBase" must be a Window or Element instance');this.#m=e,this.#c=t,this.#u=new Set(n),this.#l=i,this.#h=r,this.#y=o,this.#f=a,this.#g=s,["gamepad-only","both"].includes(this.#c)&&this.#N(),["keyboard-only","both"].includes(this.#c)&&this.#x()}#$=e=>this.#q(e.gamepad);#B=e=>this.#D(e.gamepad);#N(){window.addEventListener("gamepadconnected",this.#$),window.addEventListener("gamepaddisconnected",this.#B)}#q(e){this.#e||this.#u.has(e.id)||this.#m&&e.id!==this.#m||this.#s||(this.#s=e,this.#m=e.id,this.#G(),this.#H("connected",{id:e.id,gp:e,timestamp:e.timestamp}))}#D(e){this.#e||this.#s&&e.id===this.#s.id&&(this.#s=null,this.#p&&(cancelAnimationFrame(this.#p),this.#p=null),this.#H("disconnected",{id:e.id,gp:e,timestamp:e.timestamp}))}#G(){const e=()=>{this.#e||(this.#L(),this.#p=requestAnimationFrame(e))};e()}#L(){if(this.#e)return;const e=navigator.getGamepads(),t=Array.from(e).find(e=>e&&e.id===this.#m);t&&(this.#s=t,t.buttons.forEach((e,n)=>{const i=`Button${n}`,s=this.#a[n]?.pressed||!1;let a,r,o=!1;e.pressed&&!s?(r=1,a="down"):!e.pressed&&s?(r=0,a="up"):e.pressed&&s&&(r=1,a="hold"),e.pressed&&e.value>0&&e.value<1&&1!==e.value&&(r=e.value,o=!0),"number"==typeof r&&"string"==typeof a&&this.#j({key:i,source:"gamepad-button",value:r,value2:NaN,type:a,gp:t,isPressure:o,pressed:e.pressed,prevPressed:s,timestamp:t.timestamp,id:t.id}),this.#a[n]={pressed:e.pressed,value:"number"==typeof r?r:this.#a[n]?.value,value2:NaN}}),t.axes.forEach((e,n)=>{Math.abs(e)<this.#l&&(e=0);const i=`Axis${n}`;e!==(this.#o[n]??0)&&this.#j({key:i,source:"gamepad-analog",value:e,value2:NaN,type:"change",timestamp:t.timestamp,id:t.id,gp:t}),this.#o[n]=e}))}#z=e=>{if(!this.#e){if(!(e instanceof KeyboardEvent))throw new Error("Expected KeyboardEvent in keydown listener.");this.#t.has(e.code)||(this.#t.add(e.code),this.#j({event:e,key:e.code,source:"keyboard",value:1,value2:NaN,type:"down",pressed:!0,prevPressed:this.#r[e.code]?.pressed??!1,id:"native_keyboard",timestamp:e.timeStamp}),this.#r[e.code]={pressed:!0})}};#Z=e=>{if(!this.#e){if(!(e instanceof KeyboardEvent))throw new Error("Expected KeyboardEvent in keyup listener.");this.#t.has(e.code)&&(this.#t.delete(e.code),this.#j({event:e,key:e.code,source:"keyboard",value:0,value2:NaN,type:"up",pressed:!1,prevPressed:this.#r[e.code]?.pressed??!1,id:"native_keyboard",timestamp:e.timeStamp}),this.#r[e.code]={pressed:!1})}};#P=e=>{if(this.#e)return;if(!(e instanceof MouseEvent))throw new Error("Expected MouseEvent in mousedown listener.");const t=`Mouse${e.button}`;this.#t.add(t),this.#j({event:e,key:t,source:"mouse",value:1,value2:NaN,type:"down",pressed:!0,prevPressed:this.#r[t]?.pressed??!1,id:"native_mouse",timestamp:e.timeStamp}),this.#r[t]={pressed:!0}};#O=e=>{if(this.#e)return;if(!(e instanceof MouseEvent))throw new Error("Expected MouseEvent in mouseup listener.");const t=`Mouse${e.button}`;this.#t.delete(t),this.#j({event:e,key:t,source:"mouse",value:0,value2:NaN,type:"up",pressed:!1,prevPressed:this.#r[t]?.pressed??!1,id:"native_mouse",timestamp:e.timeStamp}),this.#r[t]={pressed:!1}};#F=e=>{if(!this.#e){if(!(e instanceof MouseEvent))throw new Error("Expected MouseEvent in mousemove listener.");if(0!==e.movementX||0!==e.movementY){const t="MouseMove",n=this.#r[t]??{pressed:!1,value:0,value2:0};this.#j({event:e,key:t,source:"mouse",value:e.movementX+(n.value??0),value2:e.movementY+(n.value??0),id:"native_mouse",type:"move",pressed:!0,prevPressed:null,timestamp:e.timeStamp}),this.#r[t]={pressed:!1,value:e.movementX,value2:e.movementY}}}};#x(){this.#y.addEventListener("keydown",this.#z),this.#y.addEventListener("keyup",this.#Z),this.#h&&(this.#y.addEventListener("mousedown",this.#P),this.#y.addEventListener("mouseup",this.#O),this.#y.addEventListener("mousemove",this.#F));const e=()=>{this.#e||(this.#t.forEach(e=>{const t=e.startsWith("Mouse")?"mouse":"keyboard";this.#j({key:e,source:t,id:`native_${t}`,value:1,value2:NaN,type:"hold",pressed:!0,prevPressed:this.#r[e]?.pressed??!1,timestamp:NaN})}),this.#d=requestAnimationFrame(e))};e()}#j(e){if(this.#e)return;const t=this.#i.get("input-*")||[],{pressed:n,key:i}=e,s=i.startsWith("Axis"),a="boolean"==typeof n&&n||s&&(e.value>this.#g||e.value<-Math.abs(this.#g)),r=s?`${i}${e.value>0?"+":e.value<0?"-":""}`:i;let o=null;if("move"!==e.type&&"hold"!==e.type){if(a){if(!s&&!this.#S.has(i)||s&&!this.#S.has(i)&&!this.#S.has(`${i}+`)&&!this.#S.has(`${i}-`)){0===this.#E&&(this.#E=Date.now()),this.#S.add(r),o=!0,this.#I.push(r),this.#v.length<1&&(this.#M&&clearTimeout(this.#M),this.#M=setTimeout(()=>this.resetComboMapped(),this.#f));const e=this.#i.get("mapped-key-start")??[];for(const t of e)t({key:r,activeTime:this.#E})}}else if(!s&&this.#S.has(i)||s&&(this.#S.has(i)||this.#S.has(`${i}+`)||this.#S.has(`${i}-`))){this.#S.delete(i),this.#S.delete(`${i}+`),this.#S.delete(`${i}-`),o=!1;const e=this.#i.get("mapped-key-end")??[];for(const t of e)t({key:r,activeTime:this.#E})}for(const{sequence:e,callback:t,triggered:n}of this.#K.values()){const i=this.#K.get(e.join("+"));if(!i)continue;const s=e.every((e,t)=>this.#I[t]===e);s&&!n?(i.triggered=!0,t(this.#E)):!s&&n&&(i.triggered=!1)}}for(const[n,p]of this.#n.entries()){const d=e=>"string"==typeof p&&e===p||Array.isArray(p)&&p.findIndex((t,n)=>e===p[n])>-1,c=d(r),u=s&&d(`${i}+`),l=s&&d(`${i}-`);if(c||u||l){if(a&&c){if(o||!this.#k.has(n)){0===this.#w&&(this.#w=Date.now()),this.#k.add(n),0===this.#b&&(this.#b=Date.now()),this.#M&&clearTimeout(this.#M),this.#v.push(n),this.#M=setTimeout(()=>this.resetComboMapped(),this.#f);const e=this.#i.get("mapped-input-start")??[];for(const t of e)t({logicalName:n,activeTime:this.#w,comboTime:this.#b})}}else if(!o||this.#k.has(n)){this.#k.delete(n),this.#k.size<1&&(this.#w=0);const e=this.#i.get("mapped-input-end")??[];for(const t of e)t({logicalName:n,activeTime:this.#w,comboTime:this.#b})}for(const{sequence:e,callback:t,triggered:n}of this.#T.values()){const i=this.#T.get(e.join("+"));if(!i)continue;const s=Array.from(this.#k),a=e.every((e,t)=>s[t]===e);a&&!n?(i.triggered=!0,t(this.#w)):!a&&n&&(i.triggered=!1)}}const m=[];if(s&&0===e.value){const{value:t}=this.#A.get(`${i}-`)??{value:0,value2:NaN},{value:n}=this.#A.get(`${i}+`)??{value:0,value2:NaN};e.value!==t&&m.push(`${i}-`),e.value!==n&&m.push(`${i}+`)}else m.push(r);m.forEach(i=>{if(!("*"===p||p===i||Array.isArray(p)&&p.includes(i)))return;const s=this.#i.get(`input-${e.type}-${n}`)||[],a=this.#i.get(`input-${n}`)||[];if(a.length<1&&s.length<1&&t.length<1)return;const r={...e,key:i,logicalName:n};for(const e of t)e(r);for(const e of a)e(r);for(const e of s)e(r);this.#A.set(i,{value:e.value,value2:e.value2})})}}#H(e,t){const n=this.#i.get(e)||[];for(const e of n)e(t)}#J(e,t,n){if("string"!=typeof e)throw new TypeError(`"logicalName" must be a string, received ${e}`);if("function"!=typeof t)throw new TypeError('"callback" must be a function, received '+typeof t);const i=n.replace("{logicalName}",e);let s=this.#i.get(i);Array.isArray(s)||(s=[],this.#i.set(i,s)),s.push(t)}#R(e,t,n){if("string"!=typeof e)throw new TypeError(`"logicalName" must be a string, received ${e}`);if("function"!=typeof t)throw new TypeError('"callback" must be a function, received '+typeof t);const i=s=>{this.#_(e,i,n),t(s)};this.#J(e,i,n)}#V(e,t,n){if("string"!=typeof e)throw new TypeError(`"logicalName" must be a string, received ${e}`);if("function"!=typeof t)throw new TypeError('"callback" must be a function, received '+typeof t);const i=n.replace("{logicalName}",e),s=this.#i.get(i)??[];s.unshift(t),this.#i.set(i,s)}#_(e,t,n){if("string"!=typeof e)throw new TypeError(`"logicalName" must be a string, received ${e}`);if("function"!=typeof t)throw new TypeError('"callback" must be a function, received '+typeof t);const i=n.replace("{logicalName}",e),s=this.#i.get(i);Array.isArray(s)&&this.#i.set(i,s.filter(e=>e!==t))}awaitInputMapping({timeout:e=1e4,eventName:t="MappingInput",canMove:n=!1}={}){return new Promise((i,s)=>{if("number"!=typeof e||Number.isNaN(e)||e<0)return s(new TypeError(`Invalid "timeout": expected a positive number, got ${e}`));if("string"!=typeof t||!t.trim())return s(new TypeError(`Invalid "eventName": expected a non-empty string, got ${t}`));if("boolean"!=typeof n)return s(new TypeError(`Invalid "canMove": expected a boolean, got ${n}`));const a={key:null,source:null},r=({key:e,type:s,source:p,gp:d,value:c})=>{(n||"move"!==s)&&(a.key=e,a.source=p,a.gp=d,clearTimeout(o),this.offInputStart(t,r),this.offInputChange(t,r),n&&this.offInputMove(t,r),i(a))},o=setTimeout(()=>i(a),e);this.mapInput(t,"*"),this.onInputStart(t,r),this.onInputChange(t,r),n&&this.onInputMove(t,r)})}mapInput(e,t){if("string"!=typeof e||!e.trim())throw new TypeError(`Invalid "logicalName": expected a non-empty string, got ${e}`);if(!("string"==typeof t||Array.isArray(t)&&t.every(e=>"string"==typeof e)))throw new TypeError(`Invalid "physicalInput": expected string or array of strings, got ${JSON.stringify(t)}`);this.#n.set(e,t)}unmapInput(e){if("string"!=typeof e||!e.trim())throw new TypeError(`Invalid "logicalName": expected a non-empty string, got ${e}`);this.#n.delete(e)}hasMappedInput(e){if("string"!=typeof e||!e.trim())throw new TypeError(`Invalid "logicalName": expected a non-empty string, got ${e}`);return this.#n.has(e)}getMappedInput(e){if("string"!=typeof e||!e.trim())throw new TypeError(`Invalid "logicalName": expected a non-empty string, got ${e}`);const t=this.#n.get(e);if(!t)throw new Error(`No physical input mapped for logicalName: "${e}"`);return t}clearMapInputs(){this.#n.clear()}registerInputSequence(e,t){if(!Array.isArray(e)||!e.every(e=>"string"==typeof e))throw new TypeError(`'sequence' must be an array of strings, got: ${JSON.stringify(e)}`);if("function"!=typeof t)throw new TypeError("'callback' must be a function, got: "+typeof t);if(0===e.length)throw new Error("'sequence' must contain at least one input name.");const n=e.join("+");this.#T.set(n,{sequence:e,callback:t,triggered:!1})}unregisterInputSequence(e){if(!Array.isArray(e)||!e.every(e=>"string"==typeof e))throw new TypeError(`'sequence' must be an array of strings, got: ${JSON.stringify(e)}`);const t=e.join("+");this.#T.delete(t)}unregisterAllInputSequences(){this.#T.clear()}hasInputSequence(e){if(!Array.isArray(e)||!e.every(e=>"string"==typeof e))throw new TypeError(`'sequence' must be an array of strings, got: ${JSON.stringify(e)}`);const t=e.join("+");return this.#T.has(t)}registerKeySequence(e,t){if(!Array.isArray(e)||!e.every(e=>"string"==typeof e))throw new TypeError(`'sequence' must be an array of strings, got: ${JSON.stringify(e)}`);if("function"!=typeof t)throw new TypeError("'callback' must be a function, got: "+typeof t);if(0===e.length)throw new Error("'sequence' must contain at least one input name.");const n=e.join("+");this.#K.set(n,{sequence:e,callback:t,triggered:!1})}unregisterKeySequence(e){if(!Array.isArray(e)||!e.every(e=>"string"==typeof e))throw new TypeError(`'sequence' must be an array of strings, got: ${JSON.stringify(e)}`);const t=e.join("+");this.#K.delete(t)}unregisterAllKeySequences(){this.#K.clear()}hasKeySequence(e){if(!Array.isArray(e)||!e.every(e=>"string"==typeof e))throw new TypeError(`'sequence' must be an array of strings, got: ${JSON.stringify(e)}`);const t=e.join("+");return this.#K.has(t)}renewComboMapped(){this.#M&&(clearTimeout(this.#M),this.#M=setTimeout(()=>this.resetComboMapped(),this.#f))}resetComboMapped(){this.#M&&clearTimeout(this.#M),this.#I=[],this.#M=null,this.#E=0,this.#v=[],this.#b=0}onMappedKeyStart(e){return this.#J("",e,"mapped-key-start")}onceMappedKeyStart(e){return this.#R("",e,"mapped-key-start")}prependMappedKeyStart(e){return this.#V("",e,"mapped-key-start")}offMappedKeyStart(e){return this.#_("",e,"mapped-key-start")}offAllMappedKeyStart(){this.#i.delete("mapped-key-start")}onMappedKeyEnd(e){return this.#J("",e,"mapped-key-end")}onceMappedKeyEnd(e){return this.#R("",e,"mapped-key-end")}prependMappedKeyEnd(e){return this.#V("",e,"mapped-key-end")}offMappedKeyEnd(e){return this.#_("",e,"mapped-key-end")}offAllMappedKeyEnd(){this.#i.delete("mapped-key-end")}onMappedInputStart(e){return this.#J("",e,"mapped-input-start")}onceMappedInputStart(e){return this.#R("",e,"mapped-input-start")}prependMappedInputStart(e){return this.#V("",e,"mapped-input-start")}offMappedInputStart(e){return this.#_("",e,"mapped-input-start")}offAllMappedInputStart(){this.#i.delete("mapped-input-start")}onMappedInputEnd(e){return this.#J("",e,"mapped-input-end")}onceMappedInputEnd(e){return this.#R("",e,"mapped-input-end")}prependMappedInputEnd(e){return this.#V("",e,"mapped-input-end")}offMappedInputEnd(e){return this.#_("",e,"mapped-input-end")}offAllMappedInputEnd(){this.#i.delete("mapped-input-end")}onInput(e,t){return this.#J(e,t,"input-{logicalName}")}onceInput(e,t){return this.#R(e,t,"input-{logicalName}")}prependInput(e,t){return this.#V(e,t,"input-{logicalName}")}offInput(e,t){return this.#_(e,t,"input-{logicalName}")}onInputStart(e,t){return this.#J(e,t,"input-down-{logicalName}")}onceInputStart(e,t){return this.#R(e,t,"input-down-{logicalName}")}prependInputStart(e,t){return this.#V(e,t,"input-down-{logicalName}")}offInputStart(e,t){return this.#_(e,t,"input-down-{logicalName}")}onInputEnd(e,t){return this.#J(e,t,"input-up-{logicalName}")}onceInputEnd(e,t){return this.#R(e,t,"input-up-{logicalName}")}prependInputEnd(e,t){return this.#V(e,t,"input-up-{logicalName}")}offInputEnd(e,t){return this.#_(e,t,"input-up-{logicalName}")}onInputHold(e,t){return this.#J(e,t,"input-hold-{logicalName}")}onceInputHold(e,t){return this.#R(e,t,"input-hold-{logicalName}")}prependInputHold(e,t){return this.#V(e,t,"input-hold-{logicalName}")}offInputHold(e,t){return this.#_(e,t,"input-hold-{logicalName}")}onInputChange(e,t){return this.#J(e,t,"input-change-{logicalName}")}onceInputChange(e,t){return this.#R(e,t,"input-change-{logicalName}")}prependInputChange(e,t){return this.#V(e,t,"input-change-{logicalName}")}offInputChange(e,t){return this.#_(e,t,"input-change-{logicalName}")}onInputMove(e,t){return this.#J(e,t,"input-move-{logicalName}")}onceInputMove(e,t){return this.#R(e,t,"input-move-{logicalName}")}prependInputMove(e,t){return this.#V(e,t,"input-move-{logicalName}")}offInputMove(e,t){return this.#_(e,t,"input-move-{logicalName}")}getCalls(e,t="all"){if("string"!=typeof e||""===e.trim())throw new TypeError(`"logicalName" must be a non-empty string, received ${e}`);const n=["all","start","end","hold","change","move"];if(!n.includes(t))throw new TypeError(`"type" must be one of ${n.join(", ")}, received ${t}`);const i=`${{all:"input-",start:"input-down-",end:"input-up-",hold:"input-hold-",change:"input-change-",move:"input-move-"}[t]}${e}`,s=this.#i.get(i);return Array.isArray(s)?[...s]:[]}offAllInputs(e,t="all"){if("string"!=typeof e||""===e.trim())throw new TypeError(`"logicalName" must be a non-empty string, received ${e}`);const n=["all","start","end","hold","change","move"];if(!n.includes(t))throw new TypeError(`"type" must be one of ${n.join(", ")}, received ${t}`);const i={all:"input-",start:"input-down-",end:"input-up-",hold:"input-hold-",change:"input-change-",move:"input-move-"}[t];i&&this.#i.delete(`${i}${e}`)}getCallSize(e,t="all"){if("string"!=typeof e||""===e.trim())throw new TypeError(`"logicalName" must be a non-empty string, received ${e}`);const n=["all","start","end","hold","change","move"];if(!n.includes(t))throw new TypeError(`"type" must be one of ${n.join(", ")}, received ${t}`);const i={all:"input-",start:"input-down-",end:"input-up-",hold:"input-hold-",change:"input-change-",move:"input-move-"}[t],s=this.#i.get(`${i}${e}`);return Array.isArray(s)?s.length:0}#W={type:"dual-rumble",params:{startDelay:0,duration:200,weakMagnitude:.5,strongMagnitude:1}};get defaultHapticEffect(){return{type:this.#W.type,params:{...this.#W.params}}}setDefaultHapticEffect(e,t){if("string"!=typeof e)throw new TypeError(`"type" must be a valid GamepadHapticEffectType string, received ${e}`);if("object"!=typeof t||null===t)throw new TypeError(`"params" must be a non-null object, received ${t}`);this.#W.type=e,this.#W.params=t}hasHapticEffect(){const e=this.#s;return!!e&&e.vibrationActuator instanceof GamepadHapticActuator}vibrate(e,t){if(void 0!==e&&("object"!=typeof e||null===e))throw new TypeError(`"params" must be an object if provided, received ${e}`);if(void 0!==t&&"string"!=typeof t)throw new TypeError(`"type" must be a valid GamepadHapticEffectType string if provided, received ${t}`);const n=this.#s;if(!n)return new Promise(e=>e("complete"));const i=n.vibrationActuator;return i instanceof GamepadHapticActuator?i.playEffect(t??this.#W.type,{...this.#W.params,...e}):new Promise(e=>e("complete"))}ignoreId(e){if("string"!=typeof e||""===e.trim())throw new TypeError(`"id" must be a non-empty string, received ${e}`);this.#u.add(e)}unignoreId(e){if("string"!=typeof e||""===e.trim())throw new TypeError(`"id" must be a non-empty string, received ${e}`);this.#u.delete(e)}onConnected(e){return this.#J("",e,"connected")}onceConnected(e){return this.#R("",e,"connected")}prependConnected(e){return this.#V("",e,"connected")}offConnected(e){return this.#_("",e,"connected")}offAllConnected(){this.#i.delete("connected")}onDisconnected(e){return this.#J("",e,"disconnected")}onceDisconnected(e){return this.#R("",e,"disconnected")}prependDisconnected(e){return this.#V("",e,"disconnected")}offDisconnected(e){return this.#_("",e,"disconnected")}offAllDisconnected(){this.#i.delete("disconnected")}hasGamepad(){return this.#s instanceof Gamepad}getGamepad(){if(!this.#s)throw new Error("No gamepad is currently connected.");return this.#s}hasLastButtonState(e){return!!this.#a[e]}getLastButtonState(e){if(!this.#a[e])throw new Error(`No last button state found for index ${e}`);return{...this.#a[e]}}exportConfig(){return{expectedId:this.#m,ignoreIds:Array.from(this.#u),deadZone:this.#l,timeoutComboKeys:this.#f,axisActiveSensitivity:this.#g,inputMap:Array.from(this.#n.entries())}}importConfig(e){if("string"!=typeof e&&("object"!=typeof e||null===e))throw new TypeError(`"json" must be a string or a non-null object, received: ${e}`);const t="string"==typeof e?JSON.parse(e):e;if(void 0!==t.expectedId&&"string"!=typeof t.expectedId&&null!==t.expectedId)throw new TypeError('"expectedId" must be a string or null if provided');if(void 0!==t.ignoreIds&&!Array.isArray(t.ignoreIds))throw new TypeError('"ignoreIds" must be an array if provided');if(void 0!==t.deadZone&&"number"!=typeof t.deadZone)throw new TypeError('"deadZone" must be a number if provided');if(void 0!==t.timeoutComboKeys&&"number"!=typeof t.timeoutComboKeys)throw new TypeError('"timeoutComboKeys" must be a number if provided');if(void 0!==t.axisActiveSensitivity&&"number"!=typeof t.axisActiveSensitivity)throw new TypeError('"axisActiveSensitivity" must be a number if provided');if(void 0!==t.inputMap&&!Array.isArray(t.inputMap))throw new TypeError('"inputMap" must be an array if provided');void 0!==t.expectedId&&(this.#m=t.expectedId),Array.isArray(t.ignoreIds)&&(this.#u=new Set(t.ignoreIds)),"number"==typeof t.deadZone&&(this.#l=t.deadZone),"number"==typeof t.timeoutComboKeys&&(this.#f=t.timeoutComboKeys),"number"==typeof t.axisActiveSensitivity&&(this.#g=t.axisActiveSensitivity),Array.isArray(t.inputMap)&&(this.#n=new Map(t.inputMap))}get mappedKeyStartCalls(){const e=this.#i.get("mapped-key-start");return Array.isArray(e)?[...e]:[]}get mappedKeyEndCalls(){const e=this.#i.get("mapped-key-end");return Array.isArray(e)?[...e]:[]}get comboMappedKeys(){return[...this.#I]}get comboMappedInputs(){return[...this.#v]}get keySequenceSize(){return this.#K.size}get keySequences(){const e=[];for(const[,t]of this.#K.entries())e.push(t.callback);return e}get activeMappedKeys(){return[...this.#S]}get mappedInputStartCalls(){const e=this.#i.get("mapped-input-start");return Array.isArray(e)?[...e]:[]}get mappedInputEndCalls(){const e=this.#i.get("mapped-input-end");return Array.isArray(e)?[...e]:[]}get inputSequenceSize(){return this.#T.size}get inputSequences(){const e=[];for(const[,t]of this.#T.entries())e.push(t.callback);return e}get activeMappedInputs(){return[...this.#k]}get mappedInputs(){const e={};for(const[t,n]of this.#n.entries())e[t]=n;return e}get mappedInputSize(){return this.#n.size}get connectedCalls(){const e=this.#i.get("connected");return Array.isArray(e)?[...e]:[]}get disconnectedCalls(){const e=this.#i.get("disconnected");return Array.isArray(e)?[...e]:[]}get ignoredDeviceIds(){return[...this.#u]}get heldKeys(){return[...this.#t]}get eventsSize(){let e=0;return this.#i.forEach(t=>{e+=t.length}),e}get callSize(){return this.#i.size}get connectedCallSize(){const e=this.#i.get("connected");return Array.isArray(e)?e.length:0}get disconnectedCallSize(){const e=this.#i.get("disconnected");return Array.isArray(e)?e.length:0}get mappedKeyStartCallSize(){const e=this.#i.get("mapped-key-start");return Array.isArray(e)?e.length:0}get mappedKeyEndCallSize(){const e=this.#i.get("mapped-key-end");return Array.isArray(e)?e.length:0}get mappedInputStartCallSize(){const e=this.#i.get("mapped-input-start");return Array.isArray(e)?e.length:0}get mappedInputEndCallSize(){const e=this.#i.get("mapped-input-end");return Array.isArray(e)?e.length:0}get lastButtonStates(){const e=[];return this.#a.forEach(t=>{e.push({...t})}),e}get lastAxes(){return[...this.#o]}get inputMode(){return this.#c}get elementBase(){return this.#y}get timeComboInputs(){return this.#b}get timeComboKeys(){return this.#E}get timeMappedInputs(){return this.#w}get timeoutComboKeys(){return this.#f}set timeoutComboKeys(e){if("number"!=typeof e||e<0||!Number.isFinite(e))throw new TypeError("Timeout combo keys must be a non-negative finite number.");this.#f=e}get axisActiveSensitivity(){return this.#g}set axisActiveSensitivity(e){if("number"!=typeof e||e<0||e>1)throw new RangeError("Axis sensitivity must be a number between 0 and 1.");this.#g=e}get deadZone(){return this.#l}set deadZone(e){if("number"!=typeof e||e<0||e>1)throw new RangeError("Dead zone must be a number between 0 and 1.");this.#l=e}get expectedId(){return this.#m}set expectedId(e){if("string"!=typeof e)throw new TypeError("Expected device id be a string.");this.#m=e}get isDestroyed(){return this.#e}destroy(){this.#e||(this.#e=!0,this.#p&&cancelAnimationFrame(this.#p),this.#d&&cancelAnimationFrame(this.#d),this.#p=null,this.#d=null,["keyboard-only","both"].includes(this.#c)&&(this.#y.removeEventListener("keydown",this.#z),this.#y.removeEventListener("keyup",this.#Z),this.#h&&(this.#y.removeEventListener("mousedown",this.#P),this.#y.removeEventListener("mouseup",this.#O),this.#y.removeEventListener("mousemove",this.#F))),["gamepad-only","both"].includes(this.#c)&&(window.removeEventListener("gamepadconnected",this.#$),window.removeEventListener("gamepaddisconnected",this.#B)),this.resetComboMapped(),this.#n.clear(),this.#i.clear(),this.#t.clear(),this.#k.clear(),this.#S.clear(),this.#T.clear(),this.#K.clear(),this.#u.clear(),this.#A.clear(),this.#a=[],this.#o=[],this.#r={},this.#s=null,this.#m=null,this.#h=!1,this.#w=0)}}const i=n;window.TinyGamepad=t.TinyGamepad})();
1
+ (()=>{"use strict";const e={d:(t,n)=>{if(Array.isArray(n))for(var i=0;i<n.length;){var s=n[i++],a=n[i++];e.o(t,s)?0===a&&i++:0===a?Object.defineProperty(t,s,{enumerable:!0,value:n[i++]}):Object.defineProperty(t,s,{enumerable:!0,get:a})}else for(var s in n)e.o(n,s)&&!e.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:n[s]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};let t={};e.d(t,{TinyGamepad:()=>i});class n{#e=!1;#t=new Set;#n=new Map;#i=new Map;#s=null;#a=[];#r={};#o=[];#p=null;#d=null;#c;#u;#l;#m;#h;#y;#f;#g;#v=[];#b=0;#w=0;#I=[];#E=0;#M=null;#S=new Set;#k=new Set;#T=new Map;#K=new Map;#A=new Map;static#C={" ":"Space","\n":"Enter","\r":"Enter","\t":"Tab","-":"Minus",_:"Minus","=":"Equal","+":"Equal","[":"BracketLeft","{":"BracketLeft","]":"BracketRight","}":"BracketRight","\\":"Backslash","|":"Backslash",";":"Semicolon",":":"Semicolon","'":"Quote",'"':"Quote",",":"Comma","<":"Comma",".":"Period",">":"Period","/":"Slash","?":"Slash","`":"Backquote","~":"Backquote"};static addSpecialKey(e,t){if("string"!=typeof e)throw new TypeError("Invalid char type: expected string, got "+typeof e);if(1!==e.length)throw new Error(`Invalid char length: "${e}" (must be exactly one character)`);if("string"!=typeof t)throw new TypeError("Invalid code type: expected string, got "+typeof t);n.#C[e]=t}static removeSpecialKey(e){if("string"!=typeof e)throw new TypeError("Invalid char type: expected string, got "+typeof e);if(1!==e.length)throw new Error(`Invalid char length: "${e}" (must be exactly one character)`);delete n.#C[e]}static getSpecialKey(e){if("string"!=typeof e)throw new TypeError("Invalid char type: expected string, got "+typeof e);if(1!==e.length)throw new Error(`Invalid char length: "${e}" (must be exactly one character)`);return n.#C[e]}static getAllSpecialKeys(){return{...n.#C}}static stringToKeys(e){if("string"!=typeof e)throw new TypeError("Invalid text type: expected string, got "+typeof e);if(!e.length)throw new Error("Invalid text: cannot be empty");return Array.from(e).map(e=>{const t=e.toUpperCase();if(t>="A"&&t<="Z")return`Key${t}`;if(t>="0"&&t<="9")return`Digit${t}`;const i=n.#C[e];if(void 0!==i)return i;throw new Error(`Unsupported character: "${e}"`)})}constructor({expectedId:e=null,inputMode:t="both",ignoreIds:n=[],deadZone:i=.1,axisActiveSensitivity:s=.3,timeoutComboKeys:a=500,allowMouse:r=!1,elementBase:o=window}={}){if(null!==e&&"string"!=typeof e)throw new TypeError('"expectedId" must be a string or null, received: '+typeof e);if(!["keyboard-only","gamepad-only","both"].includes(t))throw new TypeError(`"inputMode" must be 'keyboard-only', 'gamepad-only', or 'both', received: ${t}`);if(!Array.isArray(n)||!n.every(e=>"string"==typeof e))throw new TypeError('"ignoreIds" must be an array of strings');if("number"!=typeof i||i<0||i>1)throw new RangeError(`"deadZone" must be a number between 0 and 1, received: ${i}`);if("number"!=typeof s||s<0||s>1)throw new RangeError(`"axisActiveSensitivity" must be a number between 0 and 1, received: ${s}`);if("number"!=typeof a||a<0)throw new RangeError(`"timeoutComboKeys" must be a positive number, received: ${a}`);if("boolean"!=typeof r)throw new TypeError('"allowMouse" must be a boolean, received: '+typeof r);if(!(o instanceof Window||o instanceof Element))throw new TypeError('"elementBase" must be a Window or Element instance');this.#m=e,this.#c=t,this.#u=new Set(n),this.#l=i,this.#h=r,this.#y=o,this.#f=a,this.#g=s,["gamepad-only","both"].includes(this.#c)&&this.#N(),["keyboard-only","both"].includes(this.#c)&&this.#x()}#$=e=>this.#q(e.gamepad);#B=e=>this.#D(e.gamepad);#N(){window.addEventListener("gamepadconnected",this.#$),window.addEventListener("gamepaddisconnected",this.#B)}#q(e){this.#e||this.#u.has(e.id)||this.#m&&e.id!==this.#m||this.#s||(this.#s=e,this.#m=e.id,this.#G(),this.#H("connected",{id:e.id,gp:e,timestamp:e.timestamp}))}#D(e){this.#e||this.#s&&e.id===this.#s.id&&(this.#s=null,this.#p&&(cancelAnimationFrame(this.#p),this.#p=null),this.#H("disconnected",{id:e.id,gp:e,timestamp:e.timestamp}))}#G(){const e=()=>{this.#e||(this.#L(),this.#p=requestAnimationFrame(e))};e()}#L(){if(this.#e)return;const e=navigator.getGamepads(),t=Array.from(e).find(e=>e&&e.id===this.#m);t&&(this.#s=t,t.buttons.forEach((e,n)=>{const i=`Button${n}`,s=this.#a[n]?.pressed||!1;let a,r,o=!1;e.pressed&&!s?(r=1,a="down"):!e.pressed&&s?(r=0,a="up"):e.pressed&&s&&(r=1,a="hold"),e.pressed&&e.value>0&&e.value<1&&1!==e.value&&(r=e.value,o=!0),"number"==typeof r&&"string"==typeof a&&this.#j({key:i,source:"gamepad-button",value:r,value2:NaN,type:a,gp:t,isPressure:o,pressed:e.pressed,prevPressed:s,timestamp:t.timestamp,id:t.id}),this.#a[n]={pressed:e.pressed,value:"number"==typeof r?r:this.#a[n]?.value,value2:NaN}}),t.axes.forEach((e,n)=>{Math.abs(e)<this.#l&&(e=0);const i=`Axis${n}`;e!==(this.#o[n]??0)&&this.#j({key:i,source:"gamepad-analog",value:e,value2:NaN,type:"change",timestamp:t.timestamp,id:t.id,gp:t}),this.#o[n]=e}))}#P=e=>{if(!this.#e){if(!(e instanceof KeyboardEvent))throw new Error("Expected KeyboardEvent in keydown listener.");this.#t.has(e.code)||(this.#t.add(e.code),this.#j({event:e,key:e.code,source:"keyboard",value:1,value2:NaN,type:"down",pressed:!0,prevPressed:this.#r[e.code]?.pressed??!1,id:"native_keyboard",timestamp:e.timeStamp}),this.#r[e.code]={pressed:!0})}};#z=e=>{if(!this.#e){if(!(e instanceof KeyboardEvent))throw new Error("Expected KeyboardEvent in keyup listener.");this.#t.has(e.code)&&(this.#t.delete(e.code),this.#j({event:e,key:e.code,source:"keyboard",value:0,value2:NaN,type:"up",pressed:!1,prevPressed:this.#r[e.code]?.pressed??!1,id:"native_keyboard",timestamp:e.timeStamp}),this.#r[e.code]={pressed:!1})}};#O=e=>{if(this.#e)return;if(!(e instanceof MouseEvent))throw new Error("Expected MouseEvent in mousedown listener.");const t=`Mouse${e.button}`;this.#t.add(t),this.#j({event:e,key:t,source:"mouse",value:1,value2:NaN,type:"down",pressed:!0,prevPressed:this.#r[t]?.pressed??!1,id:"native_mouse",timestamp:e.timeStamp}),this.#r[t]={pressed:!0}};#Z=e=>{if(this.#e)return;if(!(e instanceof MouseEvent))throw new Error("Expected MouseEvent in mouseup listener.");const t=`Mouse${e.button}`;this.#t.delete(t),this.#j({event:e,key:t,source:"mouse",value:0,value2:NaN,type:"up",pressed:!1,prevPressed:this.#r[t]?.pressed??!1,id:"native_mouse",timestamp:e.timeStamp}),this.#r[t]={pressed:!1}};#F=e=>{if(!this.#e){if(!(e instanceof MouseEvent))throw new Error("Expected MouseEvent in mousemove listener.");if(0!==e.movementX||0!==e.movementY){const t="MouseMove",n=this.#r[t]??{pressed:!1,value:0,value2:0};this.#j({event:e,key:t,source:"mouse",value:e.movementX+(n.value??0),value2:e.movementY+(n.value??0),id:"native_mouse",type:"move",pressed:!0,prevPressed:null,timestamp:e.timeStamp}),this.#r[t]={pressed:!1,value:e.movementX,value2:e.movementY}}}};#x(){this.#y.addEventListener("keydown",this.#P),this.#y.addEventListener("keyup",this.#z),this.#h&&(this.#y.addEventListener("mousedown",this.#O),this.#y.addEventListener("mouseup",this.#Z),this.#y.addEventListener("mousemove",this.#F));const e=()=>{this.#e||(this.#t.forEach(e=>{const t=e.startsWith("Mouse")?"mouse":"keyboard";this.#j({key:e,source:t,id:`native_${t}`,value:1,value2:NaN,type:"hold",pressed:!0,prevPressed:this.#r[e]?.pressed??!1,timestamp:NaN})}),this.#d=requestAnimationFrame(e))};e()}#j(e){if(this.#e)return;const t=this.#i.get("input-*")||[],{pressed:n,key:i}=e,s=i.startsWith("Axis"),a="boolean"==typeof n&&n||s&&(e.value>this.#g||e.value<-Math.abs(this.#g)),r=s?`${i}${e.value>0?"+":e.value<0?"-":""}`:i;let o=null;if("move"!==e.type&&"hold"!==e.type){if(a){if(!s&&!this.#S.has(i)||s&&!this.#S.has(i)&&!this.#S.has(`${i}+`)&&!this.#S.has(`${i}-`)){0===this.#E&&(this.#E=Date.now()),this.#S.add(r),o=!0,this.#I.push(r),this.#v.length<1&&(this.#M&&clearTimeout(this.#M),this.#M=setTimeout(()=>this.resetComboMapped(),this.#f));const e=this.#i.get("mapped-key-start")??[];for(const t of e)t({key:r,activeTime:this.#E})}}else if(!s&&this.#S.has(i)||s&&(this.#S.has(i)||this.#S.has(`${i}+`)||this.#S.has(`${i}-`))){this.#S.delete(i),this.#S.delete(`${i}+`),this.#S.delete(`${i}-`),o=!1;const e=this.#i.get("mapped-key-end")??[];for(const t of e)t({key:r,activeTime:this.#E})}for(const{sequence:e,callback:t,triggered:n}of this.#K.values()){const i=this.#K.get(e.join("+"));if(!i)continue;const s=e.every((e,t)=>this.#I[t]===e);s&&!n?(i.triggered=!0,t(this.#E)):!s&&n&&(i.triggered=!1)}}for(const[n,p]of this.#n.entries()){const d=e=>"string"==typeof p&&e===p||Array.isArray(p)&&p.findIndex((t,n)=>e===p[n])>-1,c=d(r),u=s&&d(`${i}+`),l=s&&d(`${i}-`);if(c||u||l){if(a&&c){if(o||!this.#k.has(n)){0===this.#w&&(this.#w=Date.now()),this.#k.add(n),0===this.#b&&(this.#b=Date.now()),this.#M&&clearTimeout(this.#M),this.#v.push(n),this.#M=setTimeout(()=>this.resetComboMapped(),this.#f);const e=this.#i.get("mapped-input-start")??[];for(const t of e)t({logicalName:n,activeTime:this.#w,comboTime:this.#b})}}else if(!o||this.#k.has(n)){this.#k.delete(n),this.#k.size<1&&(this.#w=0);const e=this.#i.get("mapped-input-end")??[];for(const t of e)t({logicalName:n,activeTime:this.#w,comboTime:this.#b})}for(const{sequence:e,callback:t,triggered:n}of this.#T.values()){const i=this.#T.get(e.join("+"));if(!i)continue;const s=Array.from(this.#k),a=e.every((e,t)=>s[t]===e);a&&!n?(i.triggered=!0,t(this.#w)):!a&&n&&(i.triggered=!1)}}const m=[];if(s&&0===e.value){const{value:t}=this.#A.get(`${i}-`)??{value:0,value2:NaN},{value:n}=this.#A.get(`${i}+`)??{value:0,value2:NaN};e.value!==t&&m.push(`${i}-`),e.value!==n&&m.push(`${i}+`)}else m.push(r);m.forEach(i=>{if(!("*"===p||p===i||Array.isArray(p)&&p.includes(i)))return;const s=this.#i.get(`input-${e.type}-${n}`)||[],a=this.#i.get(`input-${n}`)||[];if(a.length<1&&s.length<1&&t.length<1)return;const r={...e,key:i,logicalName:n};for(const e of t)e(r);for(const e of a)e(r);for(const e of s)e(r);this.#A.set(i,{value:e.value,value2:e.value2})})}}#H(e,t){const n=this.#i.get(e)||[];for(const e of n)e(t)}#J(e,t,n){if("string"!=typeof e)throw new TypeError(`"logicalName" must be a string, received ${e}`);if("function"!=typeof t)throw new TypeError('"callback" must be a function, received '+typeof t);const i=n.replace("{logicalName}",e);let s=this.#i.get(i);Array.isArray(s)||(s=[],this.#i.set(i,s)),s.push(t)}#R(e,t,n){if("string"!=typeof e)throw new TypeError(`"logicalName" must be a string, received ${e}`);if("function"!=typeof t)throw new TypeError('"callback" must be a function, received '+typeof t);const i=s=>{this.#_(e,i,n),t(s)};this.#J(e,i,n)}#V(e,t,n){if("string"!=typeof e)throw new TypeError(`"logicalName" must be a string, received ${e}`);if("function"!=typeof t)throw new TypeError('"callback" must be a function, received '+typeof t);const i=n.replace("{logicalName}",e),s=this.#i.get(i)??[];s.unshift(t),this.#i.set(i,s)}#_(e,t,n){if("string"!=typeof e)throw new TypeError(`"logicalName" must be a string, received ${e}`);if("function"!=typeof t)throw new TypeError('"callback" must be a function, received '+typeof t);const i=n.replace("{logicalName}",e),s=this.#i.get(i);Array.isArray(s)&&this.#i.set(i,s.filter(e=>e!==t))}awaitInputMapping({timeout:e=1e4,eventName:t="MappingInput",canMove:n=!1}={}){return new Promise((i,s)=>{if("number"!=typeof e||Number.isNaN(e)||e<0)return s(new TypeError(`Invalid "timeout": expected a positive number, got ${e}`));if("string"!=typeof t||!t.trim())return s(new TypeError(`Invalid "eventName": expected a non-empty string, got ${t}`));if("boolean"!=typeof n)return s(new TypeError(`Invalid "canMove": expected a boolean, got ${n}`));const a={key:null,source:null},r=({key:e,type:s,source:p,gp:d,value:c})=>{(n||"move"!==s)&&(a.key=e,a.source=p,a.gp=d,clearTimeout(o),this.offInputStart(t,r),this.offInputChange(t,r),n&&this.offInputMove(t,r),i(a))},o=setTimeout(()=>i(a),e);this.mapInput(t,"*"),this.onInputStart(t,r),this.onInputChange(t,r),n&&this.onInputMove(t,r)})}mapInput(e,t){if("string"!=typeof e||!e.trim())throw new TypeError(`Invalid "logicalName": expected a non-empty string, got ${e}`);if(!("string"==typeof t||Array.isArray(t)&&t.every(e=>"string"==typeof e)))throw new TypeError(`Invalid "physicalInput": expected string or array of strings, got ${JSON.stringify(t)}`);this.#n.set(e,t)}unmapInput(e){if("string"!=typeof e||!e.trim())throw new TypeError(`Invalid "logicalName": expected a non-empty string, got ${e}`);this.#n.delete(e)}hasMappedInput(e){if("string"!=typeof e||!e.trim())throw new TypeError(`Invalid "logicalName": expected a non-empty string, got ${e}`);return this.#n.has(e)}getMappedInput(e){if("string"!=typeof e||!e.trim())throw new TypeError(`Invalid "logicalName": expected a non-empty string, got ${e}`);const t=this.#n.get(e);if(!t)throw new Error(`No physical input mapped for logicalName: "${e}"`);return t}clearMapInputs(){this.#n.clear()}registerInputSequence(e,t){if(!Array.isArray(e)||!e.every(e=>"string"==typeof e))throw new TypeError(`'sequence' must be an array of strings, got: ${JSON.stringify(e)}`);if("function"!=typeof t)throw new TypeError("'callback' must be a function, got: "+typeof t);if(0===e.length)throw new Error("'sequence' must contain at least one input name.");const n=e.join("+");this.#T.set(n,{sequence:e,callback:t,triggered:!1})}unregisterInputSequence(e){if(!Array.isArray(e)||!e.every(e=>"string"==typeof e))throw new TypeError(`'sequence' must be an array of strings, got: ${JSON.stringify(e)}`);const t=e.join("+");this.#T.delete(t)}unregisterAllInputSequences(){this.#T.clear()}hasInputSequence(e){if(!Array.isArray(e)||!e.every(e=>"string"==typeof e))throw new TypeError(`'sequence' must be an array of strings, got: ${JSON.stringify(e)}`);const t=e.join("+");return this.#T.has(t)}registerKeySequence(e,t){if(!Array.isArray(e)||!e.every(e=>"string"==typeof e))throw new TypeError(`'sequence' must be an array of strings, got: ${JSON.stringify(e)}`);if("function"!=typeof t)throw new TypeError("'callback' must be a function, got: "+typeof t);if(0===e.length)throw new Error("'sequence' must contain at least one input name.");const n=e.join("+");this.#K.set(n,{sequence:e,callback:t,triggered:!1})}unregisterKeySequence(e){if(!Array.isArray(e)||!e.every(e=>"string"==typeof e))throw new TypeError(`'sequence' must be an array of strings, got: ${JSON.stringify(e)}`);const t=e.join("+");this.#K.delete(t)}unregisterAllKeySequences(){this.#K.clear()}hasKeySequence(e){if(!Array.isArray(e)||!e.every(e=>"string"==typeof e))throw new TypeError(`'sequence' must be an array of strings, got: ${JSON.stringify(e)}`);const t=e.join("+");return this.#K.has(t)}renewComboMapped(){this.#M&&(clearTimeout(this.#M),this.#M=setTimeout(()=>this.resetComboMapped(),this.#f))}resetComboMapped(){this.#M&&clearTimeout(this.#M),this.#I=[],this.#M=null,this.#E=0,this.#v=[],this.#b=0}onMappedKeyStart(e){return this.#J("",e,"mapped-key-start")}onceMappedKeyStart(e){return this.#R("",e,"mapped-key-start")}prependMappedKeyStart(e){return this.#V("",e,"mapped-key-start")}offMappedKeyStart(e){return this.#_("",e,"mapped-key-start")}offAllMappedKeyStart(){this.#i.delete("mapped-key-start")}onMappedKeyEnd(e){return this.#J("",e,"mapped-key-end")}onceMappedKeyEnd(e){return this.#R("",e,"mapped-key-end")}prependMappedKeyEnd(e){return this.#V("",e,"mapped-key-end")}offMappedKeyEnd(e){return this.#_("",e,"mapped-key-end")}offAllMappedKeyEnd(){this.#i.delete("mapped-key-end")}onMappedInputStart(e){return this.#J("",e,"mapped-input-start")}onceMappedInputStart(e){return this.#R("",e,"mapped-input-start")}prependMappedInputStart(e){return this.#V("",e,"mapped-input-start")}offMappedInputStart(e){return this.#_("",e,"mapped-input-start")}offAllMappedInputStart(){this.#i.delete("mapped-input-start")}onMappedInputEnd(e){return this.#J("",e,"mapped-input-end")}onceMappedInputEnd(e){return this.#R("",e,"mapped-input-end")}prependMappedInputEnd(e){return this.#V("",e,"mapped-input-end")}offMappedInputEnd(e){return this.#_("",e,"mapped-input-end")}offAllMappedInputEnd(){this.#i.delete("mapped-input-end")}onInput(e,t){return this.#J(e,t,"input-{logicalName}")}onceInput(e,t){return this.#R(e,t,"input-{logicalName}")}prependInput(e,t){return this.#V(e,t,"input-{logicalName}")}offInput(e,t){return this.#_(e,t,"input-{logicalName}")}onInputStart(e,t){return this.#J(e,t,"input-down-{logicalName}")}onceInputStart(e,t){return this.#R(e,t,"input-down-{logicalName}")}prependInputStart(e,t){return this.#V(e,t,"input-down-{logicalName}")}offInputStart(e,t){return this.#_(e,t,"input-down-{logicalName}")}onInputEnd(e,t){return this.#J(e,t,"input-up-{logicalName}")}onceInputEnd(e,t){return this.#R(e,t,"input-up-{logicalName}")}prependInputEnd(e,t){return this.#V(e,t,"input-up-{logicalName}")}offInputEnd(e,t){return this.#_(e,t,"input-up-{logicalName}")}onInputHold(e,t){return this.#J(e,t,"input-hold-{logicalName}")}onceInputHold(e,t){return this.#R(e,t,"input-hold-{logicalName}")}prependInputHold(e,t){return this.#V(e,t,"input-hold-{logicalName}")}offInputHold(e,t){return this.#_(e,t,"input-hold-{logicalName}")}onInputChange(e,t){return this.#J(e,t,"input-change-{logicalName}")}onceInputChange(e,t){return this.#R(e,t,"input-change-{logicalName}")}prependInputChange(e,t){return this.#V(e,t,"input-change-{logicalName}")}offInputChange(e,t){return this.#_(e,t,"input-change-{logicalName}")}onInputMove(e,t){return this.#J(e,t,"input-move-{logicalName}")}onceInputMove(e,t){return this.#R(e,t,"input-move-{logicalName}")}prependInputMove(e,t){return this.#V(e,t,"input-move-{logicalName}")}offInputMove(e,t){return this.#_(e,t,"input-move-{logicalName}")}getCalls(e,t="all"){if("string"!=typeof e||""===e.trim())throw new TypeError(`"logicalName" must be a non-empty string, received ${e}`);const n=["all","start","end","hold","change","move"];if(!n.includes(t))throw new TypeError(`"type" must be one of ${n.join(", ")}, received ${t}`);const i=`${{all:"input-",start:"input-down-",end:"input-up-",hold:"input-hold-",change:"input-change-",move:"input-move-"}[t]}${e}`,s=this.#i.get(i);return Array.isArray(s)?[...s]:[]}offAllInputs(e,t="all"){if("string"!=typeof e||""===e.trim())throw new TypeError(`"logicalName" must be a non-empty string, received ${e}`);const n=["all","start","end","hold","change","move"];if(!n.includes(t))throw new TypeError(`"type" must be one of ${n.join(", ")}, received ${t}`);const i={all:"input-",start:"input-down-",end:"input-up-",hold:"input-hold-",change:"input-change-",move:"input-move-"}[t];i&&this.#i.delete(`${i}${e}`)}getCallSize(e,t="all"){if("string"!=typeof e||""===e.trim())throw new TypeError(`"logicalName" must be a non-empty string, received ${e}`);const n=["all","start","end","hold","change","move"];if(!n.includes(t))throw new TypeError(`"type" must be one of ${n.join(", ")}, received ${t}`);const i={all:"input-",start:"input-down-",end:"input-up-",hold:"input-hold-",change:"input-change-",move:"input-move-"}[t],s=this.#i.get(`${i}${e}`);return Array.isArray(s)?s.length:0}#W={type:"dual-rumble",params:{startDelay:0,duration:200,weakMagnitude:.5,strongMagnitude:1}};get defaultHapticEffect(){return{type:this.#W.type,params:{...this.#W.params}}}setDefaultHapticEffect(e,t){if("string"!=typeof e)throw new TypeError(`"type" must be a valid GamepadHapticEffectType string, received ${e}`);if("object"!=typeof t||null===t)throw new TypeError(`"params" must be a non-null object, received ${t}`);this.#W.type=e,this.#W.params=t}hasHapticEffect(){const e=this.#s;return!!e&&e.vibrationActuator instanceof GamepadHapticActuator}vibrate(e,t){if(void 0!==e&&("object"!=typeof e||null===e))throw new TypeError(`"params" must be an object if provided, received ${e}`);if(void 0!==t&&"string"!=typeof t)throw new TypeError(`"type" must be a valid GamepadHapticEffectType string if provided, received ${t}`);const n=this.#s;if(!n)return new Promise(e=>e("complete"));const i=n.vibrationActuator;return i instanceof GamepadHapticActuator?i.playEffect(t??this.#W.type,{...this.#W.params,...e}):new Promise(e=>e("complete"))}ignoreId(e){if("string"!=typeof e||""===e.trim())throw new TypeError(`"id" must be a non-empty string, received ${e}`);this.#u.add(e)}unignoreId(e){if("string"!=typeof e||""===e.trim())throw new TypeError(`"id" must be a non-empty string, received ${e}`);this.#u.delete(e)}onConnected(e){return this.#J("",e,"connected")}onceConnected(e){return this.#R("",e,"connected")}prependConnected(e){return this.#V("",e,"connected")}offConnected(e){return this.#_("",e,"connected")}offAllConnected(){this.#i.delete("connected")}onDisconnected(e){return this.#J("",e,"disconnected")}onceDisconnected(e){return this.#R("",e,"disconnected")}prependDisconnected(e){return this.#V("",e,"disconnected")}offDisconnected(e){return this.#_("",e,"disconnected")}offAllDisconnected(){this.#i.delete("disconnected")}hasGamepad(){return this.#s instanceof Gamepad}getGamepad(){if(!this.#s)throw new Error("No gamepad is currently connected.");return this.#s}hasLastButtonState(e){return!!this.#a[e]}getLastButtonState(e){if(!this.#a[e])throw new Error(`No last button state found for index ${e}`);return{...this.#a[e]}}exportConfig(){return{expectedId:this.#m,ignoreIds:Array.from(this.#u),deadZone:this.#l,timeoutComboKeys:this.#f,axisActiveSensitivity:this.#g,inputMap:Array.from(this.#n.entries())}}importConfig(e){if("string"!=typeof e&&("object"!=typeof e||null===e))throw new TypeError(`"json" must be a string or a non-null object, received: ${e}`);const t="string"==typeof e?JSON.parse(e):e;if(void 0!==t.expectedId&&"string"!=typeof t.expectedId&&null!==t.expectedId)throw new TypeError('"expectedId" must be a string or null if provided');if(void 0!==t.ignoreIds&&!Array.isArray(t.ignoreIds))throw new TypeError('"ignoreIds" must be an array if provided');if(void 0!==t.deadZone&&"number"!=typeof t.deadZone)throw new TypeError('"deadZone" must be a number if provided');if(void 0!==t.timeoutComboKeys&&"number"!=typeof t.timeoutComboKeys)throw new TypeError('"timeoutComboKeys" must be a number if provided');if(void 0!==t.axisActiveSensitivity&&"number"!=typeof t.axisActiveSensitivity)throw new TypeError('"axisActiveSensitivity" must be a number if provided');if(void 0!==t.inputMap&&!Array.isArray(t.inputMap))throw new TypeError('"inputMap" must be an array if provided');void 0!==t.expectedId&&(this.#m=t.expectedId),Array.isArray(t.ignoreIds)&&(this.#u=new Set(t.ignoreIds)),"number"==typeof t.deadZone&&(this.#l=t.deadZone),"number"==typeof t.timeoutComboKeys&&(this.#f=t.timeoutComboKeys),"number"==typeof t.axisActiveSensitivity&&(this.#g=t.axisActiveSensitivity),Array.isArray(t.inputMap)&&(this.#n=new Map(t.inputMap))}get mappedKeyStartCalls(){const e=this.#i.get("mapped-key-start");return Array.isArray(e)?[...e]:[]}get mappedKeyEndCalls(){const e=this.#i.get("mapped-key-end");return Array.isArray(e)?[...e]:[]}get comboMappedKeys(){return[...this.#I]}get comboMappedInputs(){return[...this.#v]}get keySequenceSize(){return this.#K.size}get keySequences(){const e=[];for(const[,t]of this.#K.entries())e.push(t.callback);return e}get activeMappedKeys(){return[...this.#S]}get mappedInputStartCalls(){const e=this.#i.get("mapped-input-start");return Array.isArray(e)?[...e]:[]}get mappedInputEndCalls(){const e=this.#i.get("mapped-input-end");return Array.isArray(e)?[...e]:[]}get inputSequenceSize(){return this.#T.size}get inputSequences(){const e=[];for(const[,t]of this.#T.entries())e.push(t.callback);return e}get activeMappedInputs(){return[...this.#k]}get mappedInputs(){const e={};for(const[t,n]of this.#n.entries())e[t]=n;return e}get mappedInputSize(){return this.#n.size}get connectedCalls(){const e=this.#i.get("connected");return Array.isArray(e)?[...e]:[]}get disconnectedCalls(){const e=this.#i.get("disconnected");return Array.isArray(e)?[...e]:[]}get ignoredDeviceIds(){return[...this.#u]}get heldKeys(){return[...this.#t]}get eventsSize(){let e=0;return this.#i.forEach(t=>{e+=t.length}),e}get callSize(){return this.#i.size}get connectedCallSize(){const e=this.#i.get("connected");return Array.isArray(e)?e.length:0}get disconnectedCallSize(){const e=this.#i.get("disconnected");return Array.isArray(e)?e.length:0}get mappedKeyStartCallSize(){const e=this.#i.get("mapped-key-start");return Array.isArray(e)?e.length:0}get mappedKeyEndCallSize(){const e=this.#i.get("mapped-key-end");return Array.isArray(e)?e.length:0}get mappedInputStartCallSize(){const e=this.#i.get("mapped-input-start");return Array.isArray(e)?e.length:0}get mappedInputEndCallSize(){const e=this.#i.get("mapped-input-end");return Array.isArray(e)?e.length:0}get lastButtonStates(){const e=[];return this.#a.forEach(t=>{e.push({...t})}),e}get lastAxes(){return[...this.#o]}get inputMode(){return this.#c}get elementBase(){return this.#y}get timeComboInputs(){return this.#b}get timeComboKeys(){return this.#E}get timeMappedInputs(){return this.#w}get timeoutComboKeys(){return this.#f}set timeoutComboKeys(e){if("number"!=typeof e||e<0||!Number.isFinite(e))throw new TypeError("Timeout combo keys must be a non-negative finite number.");this.#f=e}get axisActiveSensitivity(){return this.#g}set axisActiveSensitivity(e){if("number"!=typeof e||e<0||e>1)throw new RangeError("Axis sensitivity must be a number between 0 and 1.");this.#g=e}get deadZone(){return this.#l}set deadZone(e){if("number"!=typeof e||e<0||e>1)throw new RangeError("Dead zone must be a number between 0 and 1.");this.#l=e}get expectedId(){return this.#m}set expectedId(e){if("string"!=typeof e)throw new TypeError("Expected device id be a string.");this.#m=e}get isDestroyed(){return this.#e}destroy(){this.#e||(this.#e=!0,this.#p&&cancelAnimationFrame(this.#p),this.#d&&cancelAnimationFrame(this.#d),this.#p=null,this.#d=null,["keyboard-only","both"].includes(this.#c)&&(this.#y.removeEventListener("keydown",this.#P),this.#y.removeEventListener("keyup",this.#z),this.#h&&(this.#y.removeEventListener("mousedown",this.#O),this.#y.removeEventListener("mouseup",this.#Z),this.#y.removeEventListener("mousemove",this.#F))),["gamepad-only","both"].includes(this.#c)&&(window.removeEventListener("gamepadconnected",this.#$),window.removeEventListener("gamepaddisconnected",this.#B)),this.resetComboMapped(),this.#n.clear(),this.#i.clear(),this.#t.clear(),this.#k.clear(),this.#S.clear(),this.#T.clear(),this.#K.clear(),this.#u.clear(),this.#A.clear(),this.#a=[],this.#o=[],this.#r={},this.#s=null,this.#m=null,this.#h=!1,this.#w=0)}}const i=n;window.TinyGamepad=t.TinyGamepad})();