tiny-essentials 1.20.3 โ†’ 1.21.1

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 (126) hide show
  1. package/README.md +13 -11
  2. package/dist/_/numbers.cjs +136 -0
  3. package/dist/_/numbers.d.mts +24 -0
  4. package/dist/_/numbers.mjs +102 -0
  5. package/dist/v1/TinyAdvancedRaffle.min.js +1 -0
  6. package/dist/v1/TinyArrayPaginator.min.js +1 -0
  7. package/dist/v1/TinyBasicsEs.min.js +1 -1
  8. package/dist/v1/TinyCookieConsent.min.js +1 -0
  9. package/dist/v1/TinyDayNightCycle.min.js +1 -0
  10. package/dist/v1/TinyEssentials.min.js +1 -1
  11. package/dist/v1/TinyGamepad.min.js +1 -0
  12. package/dist/v1/TinyI18.min.js +1 -0
  13. package/dist/v1/TinyInventory.min.js +1 -0
  14. package/dist/v1/TinyInventoryTrader.min.js +1 -0
  15. package/dist/v1/TinyLocalStorage.min.js +1 -1
  16. package/dist/v1/TinyNeedBar.min.js +1 -0
  17. package/dist/v1/TinyRateLimiter.min.js +1 -1
  18. package/dist/v1/TinySmartScroller.min.js +1 -1
  19. package/dist/v1/TinyToastNotify.min.js +1 -1
  20. package/dist/v1/TinyUploadClicker.min.js +1 -1
  21. package/dist/v1/basics/array.cjs +21 -0
  22. package/dist/v1/basics/array.d.mts +8 -0
  23. package/dist/v1/basics/array.mjs +18 -0
  24. package/dist/v1/basics/clock.cjs +127 -11
  25. package/dist/v1/basics/clock.d.mts +26 -0
  26. package/dist/v1/basics/clock.mjs +96 -1
  27. package/dist/v1/basics/index.cjs +2 -8
  28. package/dist/v1/basics/index.d.mts +3 -8
  29. package/dist/v1/basics/index.mjs +2 -3
  30. package/dist/v1/basics/simpleMath.cjs +46 -0
  31. package/dist/v1/basics/simpleMath.d.mts +27 -0
  32. package/dist/v1/basics/simpleMath.mjs +42 -0
  33. package/dist/v1/build/TinyAdvancedRaffle.cjs +7 -0
  34. package/dist/v1/build/TinyAdvancedRaffle.d.mts +3 -0
  35. package/dist/v1/build/TinyAdvancedRaffle.mjs +2 -0
  36. package/dist/v1/build/TinyArrayPaginator.cjs +7 -0
  37. package/dist/v1/build/TinyArrayPaginator.d.mts +3 -0
  38. package/dist/v1/build/TinyArrayPaginator.mjs +2 -0
  39. package/dist/v1/build/TinyCookieConsent.cjs +7 -0
  40. package/dist/v1/build/TinyCookieConsent.d.mts +3 -0
  41. package/dist/v1/build/TinyCookieConsent.mjs +2 -0
  42. package/dist/v1/build/TinyDayNightCycle.cjs +7 -0
  43. package/dist/v1/build/TinyDayNightCycle.d.mts +3 -0
  44. package/dist/v1/build/TinyDayNightCycle.mjs +2 -0
  45. package/dist/v1/build/TinyGamepad.cjs +7 -0
  46. package/dist/v1/build/TinyGamepad.d.mts +3 -0
  47. package/dist/v1/build/TinyGamepad.mjs +2 -0
  48. package/dist/v1/build/TinyI18.cjs +7 -0
  49. package/dist/v1/build/TinyI18.d.mts +3 -0
  50. package/dist/v1/build/TinyI18.mjs +2 -0
  51. package/dist/v1/build/TinyInventory.cjs +7 -0
  52. package/dist/v1/build/TinyInventory.d.mts +3 -0
  53. package/dist/v1/build/TinyInventory.mjs +2 -0
  54. package/dist/v1/build/TinyInventoryTrader.cjs +7 -0
  55. package/dist/v1/build/TinyInventoryTrader.d.mts +3 -0
  56. package/dist/v1/build/TinyInventoryTrader.mjs +2 -0
  57. package/dist/v1/build/TinyNeedBar.cjs +7 -0
  58. package/dist/v1/build/TinyNeedBar.d.mts +3 -0
  59. package/dist/v1/build/TinyNeedBar.mjs +2 -0
  60. package/dist/v1/css/TinyCookieConsent.min.css +1 -0
  61. package/dist/v1/index.cjs +20 -8
  62. package/dist/v1/index.d.mts +12 -8
  63. package/dist/v1/index.mjs +11 -3
  64. package/dist/v1/libs/TinyAdvancedRaffle.cjs +1654 -0
  65. package/dist/v1/libs/TinyAdvancedRaffle.d.mts +851 -0
  66. package/dist/v1/libs/TinyAdvancedRaffle.mjs +1477 -0
  67. package/dist/v1/libs/TinyArrayPaginator.cjs +132 -0
  68. package/dist/v1/libs/TinyArrayPaginator.d.mts +78 -0
  69. package/dist/v1/libs/TinyArrayPaginator.mjs +119 -0
  70. package/dist/v1/libs/TinyCookieConsent.cjs +278 -0
  71. package/dist/v1/libs/TinyCookieConsent.d.mts +142 -0
  72. package/dist/v1/libs/TinyCookieConsent.mjs +248 -0
  73. package/dist/v1/libs/TinyDayNightCycle.cjs +1389 -0
  74. package/dist/v1/libs/TinyDayNightCycle.d.mts +673 -0
  75. package/dist/v1/libs/TinyDayNightCycle.mjs +1232 -0
  76. package/dist/v1/libs/TinyGamepad.cjs +2690 -0
  77. package/dist/v1/libs/TinyGamepad.d.mts +1286 -0
  78. package/dist/v1/libs/TinyGamepad.mjs +2386 -0
  79. package/dist/v1/libs/TinyHtml.d.mts +2 -2
  80. package/dist/v1/libs/TinyI18.cjs +946 -0
  81. package/dist/v1/libs/TinyI18.d.mts +418 -0
  82. package/dist/v1/libs/TinyI18.mjs +873 -0
  83. package/dist/v1/libs/TinyInventory.cjs +1788 -0
  84. package/dist/v1/libs/TinyInventory.d.mts +871 -0
  85. package/dist/v1/libs/TinyInventory.mjs +1650 -0
  86. package/dist/v1/libs/TinyInventoryTrader.cjs +242 -0
  87. package/dist/v1/libs/TinyInventoryTrader.d.mts +95 -0
  88. package/dist/v1/libs/TinyInventoryTrader.mjs +212 -0
  89. package/dist/v1/libs/TinyLocalStorage.cjs +14 -1
  90. package/dist/v1/libs/TinyLocalStorage.mjs +8 -1
  91. package/dist/v1/libs/TinyNeedBar.cjs +272 -0
  92. package/dist/v1/libs/TinyNeedBar.d.mts +223 -0
  93. package/dist/v1/libs/TinyNeedBar.mjs +241 -0
  94. package/dist/v1/libs/TinyRateLimiter.cjs +0 -13
  95. package/dist/v1/libs/TinyRateLimiter.d.mts +0 -8
  96. package/dist/v1/libs/TinyRateLimiter.mjs +0 -12
  97. package/dist/v1/libs/TinySmartScroller.cjs +0 -51
  98. package/dist/v1/libs/TinySmartScroller.d.mts +0 -36
  99. package/dist/v1/libs/TinySmartScroller.mjs +0 -46
  100. package/dist/v1/libs/TinyToastNotify.cjs +2 -2
  101. package/dist/v1/libs/TinyToastNotify.mjs +2 -2
  102. package/dist/v1/libs/TinyUploadClicker.cjs +1 -1
  103. package/docs/v1/Ai-Tips.md +51 -0
  104. package/docs/v1/Personal-Ai-Prompts(portuguese).md +134 -0
  105. package/docs/v1/Personal-Ai-Prompts.md +113 -0
  106. package/docs/v1/README.md +24 -0
  107. package/docs/v1/basics/array.md +17 -0
  108. package/docs/v1/basics/clock.md +51 -11
  109. package/docs/v1/basics/simpleMath.md +73 -0
  110. package/docs/v1/libs/TinyAdvancedRaffle.md +674 -0
  111. package/docs/v1/libs/TinyArrayPaginator.md +150 -0
  112. package/docs/v1/libs/TinyCookieConsent.md +152 -0
  113. package/docs/v1/libs/TinyDayNightCycle.md +711 -0
  114. package/docs/v1/libs/TinyGamepad.md +980 -0
  115. package/docs/v1/libs/TinyI18.md +515 -0
  116. package/docs/v1/libs/TinyInventory.md +777 -0
  117. package/docs/v1/libs/TinyInventoryTrader.md +114 -0
  118. package/docs/v1/libs/TinyNeedBar.md +226 -0
  119. package/package.json +7 -5
  120. package/dist/v1/basics/html_deprecated.cjs +0 -124
  121. package/dist/v1/basics/html_deprecated.d.mts +0 -40
  122. package/dist/v1/basics/html_deprecated.mjs +0 -97
  123. package/dist/v1/css/TinyDraggerExample.css +0 -21
  124. package/dist/v1/css/TinyNotify.css +0 -350
  125. package/dist/v1/css/aiMarker.css +0 -4
  126. package/docs/v1/basics/html_deprecated.md +0 -127
@@ -0,0 +1,980 @@
1
+ # ๐ŸŽฎ TinyGamepad
2
+
3
+ TinyGamepad is a powerful and flexible JavaScript library designed to manage gamepad, keyboard, and mouse inputs seamlessly.
4
+ It supports advanced features like input mapping, combo detection, haptic feedback, and multiple event callbacks โ€” all in a clean, easy-to-use API.
5
+
6
+ Perfect for game developers and interactive apps who want precise control over input devices without hassle.
7
+
8
+ ---
9
+
10
+ ## ๐ŸŽฎ Type Definitions
11
+
12
+ This section documents the key **types**, **structures**, and **callback signatures** used by **TinyGamepad** for handling gamepad, keyboard, and mouse inputs.
13
+
14
+ ---
15
+
16
+ ### ๐Ÿ”‘ `KeyStatus`
17
+
18
+ Represents the **status** of a key or button.
19
+
20
+ ```ts
21
+ type KeyStatus = {
22
+ pressed: boolean; // Whether the key is currently pressed
23
+ value?: number; // Optional analog value
24
+ value2?: number; // Optional secondary analog value
25
+ };
26
+ ```
27
+
28
+ ---
29
+
30
+ ### ๐ŸŽฏ `InputMode`
31
+
32
+ Defines the available **input modes**:
33
+
34
+ * `'gamepad-only'` โ†’ Only gamepad input
35
+ * `'keyboard-only'` โ†’ Only keyboard input
36
+ * `'both'` โ†’ Accept both gamepad and keyboard
37
+
38
+ ```ts
39
+ type InputMode = 'gamepad-only' | 'keyboard-only' | 'both';
40
+ ```
41
+
42
+ ---
43
+
44
+ ### ๐Ÿ—บ๏ธ `MappedInputCallback`
45
+
46
+ Callback fired when a **mapped logical input** (e.g., `"Jump"`, `"Shoot"`) is activated or deactivated.
47
+
48
+ ```ts
49
+ type MappedInputCallback = (payload: {
50
+ logicalName: string; // Logical input name
51
+ activeTime: number; // Time active in milliseconds
52
+ comboTime: number; // Combo sequence timing
53
+ }) => void;
54
+ ```
55
+
56
+ ---
57
+
58
+ ### โŒจ๏ธ `MappedKeyCallback`
59
+
60
+ Callback fired when a **mapped key** (e.g., `"KeyA"`, `"KeyB"`) is activated or deactivated.
61
+
62
+ ```ts
63
+ type MappedKeyCallback = (payload: {
64
+ key: string; // Physical key name
65
+ activeTime: number; // Time active in milliseconds
66
+ }) => void;
67
+ ```
68
+
69
+ ---
70
+
71
+ ### ๐Ÿ“ฆ `PayloadCallback`
72
+
73
+ Generic callback for handling **input events**:
74
+
75
+ ```ts
76
+ type PayloadCallback = (payload: InputPayload | InputAnalogPayload) => void;
77
+ ```
78
+
79
+ ---
80
+
81
+ ### ๐Ÿ”Œ `ConnectionCallback`
82
+
83
+ Callback for **gamepad connection events**:
84
+
85
+ ```ts
86
+ type ConnectionCallback = (payload: ConnectionPayload) => void;
87
+ ```
88
+
89
+ ---
90
+
91
+ ### ๐Ÿ•น๏ธ `InputSequenceCallback`
92
+
93
+ Fired when a **registered input sequence** is fully activated:
94
+
95
+ ```ts
96
+ type InputSequenceCallback = (timestamp: number) => void;
97
+ ```
98
+
99
+ ---
100
+
101
+ ### โŒจ๏ธ `KeySequenceCallback`
102
+
103
+ Fired when a **registered key sequence** is fully activated:
104
+
105
+ ```ts
106
+ type KeySequenceCallback = (timestamp: number) => void;
107
+ ```
108
+
109
+ ---
110
+
111
+ ### ๐Ÿ“š `CallbackList`
112
+
113
+ Union of all possible **callback types** in the event system:
114
+
115
+ ```ts
116
+ type CallbackList =
117
+ | ConnectionCallback
118
+ | PayloadCallback
119
+ | MappedInputCallback
120
+ | MappedKeyCallback;
121
+ ```
122
+
123
+ ---
124
+
125
+ ### ๐ŸŽฎ `GamepadDeviceSource`
126
+
127
+ Specific gamepad input sources:
128
+
129
+ * `'gamepad-analog'` โ†’ Analog sticks / triggers
130
+ * `'gamepad-button'` โ†’ Digital buttons
131
+
132
+ ```ts
133
+ type GamepadDeviceSource = 'gamepad-analog' | 'gamepad-button';
134
+ ```
135
+
136
+ ---
137
+
138
+ ### ๐Ÿ–ฑ๏ธ `DeviceSource`
139
+
140
+ All possible **physical input sources**:
141
+
142
+ * `'mouse'`
143
+ * `'keyboard'`
144
+ * `'gamepad-analog'`
145
+ * `'gamepad-button'`
146
+
147
+ ```ts
148
+ type DeviceSource = 'mouse' | 'keyboard' | GamepadDeviceSource;
149
+ ```
150
+
151
+ ---
152
+
153
+ ### ๐Ÿ“ `DeviceInputType`
154
+
155
+ Describes **input interaction types**:
156
+
157
+ * `'up'` โ†’ Released
158
+ * `'down'` โ†’ Pressed
159
+ * `'hold'` โ†’ Held
160
+ * `'change'` โ†’ Value changed
161
+ * `'move'` โ†’ Analog motion detected
162
+
163
+ ```ts
164
+ type DeviceInputType = 'up' | 'down' | 'hold' | 'change' | 'move';
165
+ ```
166
+
167
+ ---
168
+
169
+ ### ๐Ÿ†™ `InputPayload`
170
+
171
+ Payload structure for **digital button input events**:
172
+
173
+ ```ts
174
+ type InputPayload = {
175
+ id: string;
176
+ event?: Event;
177
+ type: DeviceInputType;
178
+ source: DeviceSource;
179
+ key: string;
180
+ isPressure: boolean;
181
+ logicalName: string;
182
+ value: number;
183
+ value2: number;
184
+ pressed: boolean;
185
+ prevPressed?: boolean | null;
186
+ timestamp: number;
187
+ gp?: Gamepad;
188
+ };
189
+ ```
190
+
191
+ ---
192
+
193
+ ### ๐Ÿ“ `InputAnalogPayload`
194
+
195
+ Payload structure for **analog input events**:
196
+
197
+ ```ts
198
+ type InputAnalogPayload = {
199
+ id: string;
200
+ event?: Event;
201
+ type: DeviceInputType;
202
+ source: DeviceSource;
203
+ key: string;
204
+ logicalName: string;
205
+ value: number;
206
+ value2: number;
207
+ timestamp: number;
208
+ gp?: Gamepad;
209
+ };
210
+ ```
211
+
212
+ ---
213
+
214
+ ### ๐Ÿ—‚๏ธ `InputEvents`
215
+
216
+ Internal structure for **digital input tracking**:
217
+
218
+ ```ts
219
+ type InputEvents = {
220
+ id: string;
221
+ event?: Event;
222
+ key: string;
223
+ source: DeviceSource;
224
+ value: number;
225
+ value2: number;
226
+ type: DeviceInputType;
227
+ isPressure: boolean;
228
+ pressed: boolean;
229
+ prevPressed?: boolean | null;
230
+ timestamp: number;
231
+ gp?: Gamepad;
232
+ };
233
+ ```
234
+
235
+ ---
236
+
237
+ ### ๐ŸŽš๏ธ `InputAnalogEvents`
238
+
239
+ Internal structure for **analog input tracking**:
240
+
241
+ ```ts
242
+ type InputAnalogEvents = {
243
+ id: string;
244
+ event?: Event;
245
+ key: string;
246
+ source: DeviceSource;
247
+ value: number;
248
+ value2: number;
249
+ type: DeviceInputType;
250
+ timestamp: number;
251
+ gp?: Gamepad;
252
+ };
253
+ ```
254
+
255
+ ---
256
+
257
+ ### ๐Ÿ”Œ `ConnectionPayload`
258
+
259
+ Payload for **gamepad connection events**:
260
+
261
+ ```ts
262
+ type ConnectionPayload = {
263
+ id: string;
264
+ timestamp: number;
265
+ gp: Gamepad;
266
+ };
267
+ ```
268
+
269
+ ---
270
+
271
+ ### โš™๏ธ `ExportedConfig`
272
+
273
+ Structure for **exporting and importing TinyGamepad configurations**:
274
+
275
+ ```ts
276
+ type ExportedConfig = {
277
+ expectedId: string | null; // Expected gamepad ID or null
278
+ ignoreIds: string[]; // IDs to ignore
279
+ deadZone: number; // Analog dead zone threshold
280
+ timeoutComboKeys: number; // Max time between combo inputs
281
+ axisActiveSensitivity: number; // Analog movement sensitivity
282
+ inputMap: [string, string | string[]][]; // Logical-to-physical mappings
283
+ };
284
+ ```
285
+
286
+ ---
287
+
288
+ ## ๐ŸŽฎ Constructor & Input Event Initialization
289
+
290
+ ### โš™๏ธ Constructor
291
+
292
+ ```js
293
+ constructor({
294
+ expectedId = null,
295
+ inputMode = 'both',
296
+ ignoreIds = [],
297
+ deadZone = 0.1,
298
+ axisActiveSensitivity = 0.3,
299
+ timeoutComboKeys = 500,
300
+ allowMouse = false,
301
+ elementBase = window,
302
+ } = {}) { ... }
303
+ ```
304
+
305
+ Initializes a new instance of **TinyGamepad** with customizable input behavior.
306
+
307
+ #### ๐Ÿ”‘ Parameters:
308
+
309
+ | Name | Type | Default | Description | | |
310
+ | ----------------------- | ------------------- | -------------- | ----------------------------------------------------------------------------------- | -------- | ------------------------------------ |
311
+ | `expectedId` | `string \| null` | `null` | Specific controller ID to expect; filters gamepads. | | |
312
+ | `inputMode` | \`'keyboard-only' | 'gamepad-only' | 'both'\` | `'both'` | Selects input sources to listen for. |
313
+ | `ignoreIds` | `string[]` | `[]` | List of device IDs to ignore during detection. | | |
314
+ | `deadZone` | `number` | `0.1` | Threshold under which analog stick inputs are ignored (0 to 1). | | |
315
+ | `axisActiveSensitivity` | `number` | `0.3` | Sensitivity threshold to detect meaningful analog axis movement (0 most sensitive). | | |
316
+ | `timeoutComboKeys` | `number` | `500` | Time (ms) allowed between inputs in a key sequence before reset. | | |
317
+ | `allowMouse` | `boolean` | `false` | Whether mouse input events should be treated as triggers. | | |
318
+ | `elementBase` | `Window \| Element` | `window` | DOM element or window to bind keyboard and mouse event listeners. | | |
319
+
320
+ #### ๐Ÿšจ Validation:
321
+
322
+ * Throws `TypeError` or `RangeError` on invalid types or out-of-range values.
323
+ * Ensures only valid configurations are accepted.
324
+
325
+ #### ๐Ÿ”ฅ Behavior:
326
+
327
+ * Initializes gamepad event listeners if mode includes `'gamepad-only'` or `'both'`.
328
+ * Initializes keyboard and mouse listeners if mode includes `'keyboard-only'` or `'both'`.
329
+
330
+ ---
331
+
332
+ ## ๐ŸŽฎ Input Mapping & Sequence Management
333
+
334
+ ### โณ `awaitInputMapping({ timeout, eventName, canMove })`
335
+
336
+ Waits for a single input event from the user and resolves with detailed input info.
337
+ Useful for input configuration screens where the user chooses a key/button to assign.
338
+
339
+ #### โš™๏ธ Parameters (all optional):
340
+
341
+ | Name | Type | Default | Description |
342
+ | ----------- | ------- | ---------------- | -------------------------------------------------------- |
343
+ | `timeout` | number | `10000` ms | How long to wait before resolving with `null` (no input) |
344
+ | `eventName` | string | `'MappingInput'` | Temporary logical event name used internally |
345
+ | `canMove` | boolean | `false` | Whether to accept movement inputs like mouse move |
346
+
347
+ #### ๐Ÿ”„ Returns:
348
+
349
+ A `Promise` that resolves with an object:
350
+
351
+ ```ts
352
+ {
353
+ key: string | null, // Input identifier ("KeyW", "Button0", "LeftClick")
354
+ source: DeviceSource | null, // Input origin: "keyboard", "mouse", "gamepad-button", "gamepad-analog"
355
+ gp?: Gamepad // Gamepad object if the source is a gamepad
356
+ }
357
+ ```
358
+
359
+ ---
360
+
361
+ ### ๐Ÿ› ๏ธ `mapInput(logicalName, physicalInput)`
362
+
363
+ Maps one or multiple physical inputs to a logical input name.
364
+
365
+ | Parameter | Type | Description |
366
+ | --------------- | ---------------------- | --------------------------------------------------------------- |
367
+ | `logicalName` | `string` | Logical input identifier (e.g. "Jump") |
368
+ | `physicalInput` | `string` or `string[]` | Physical input(s) mapped (e.g. "Button1", \["KeyW", "ArrowUp"]) |
369
+
370
+ ---
371
+
372
+ ### โŒ `unmapInput(logicalName)`
373
+
374
+ Removes the mapping for the specified logical input.
375
+
376
+ | Parameter | Type | Description |
377
+ | ------------- | -------- | ---------------------------------- |
378
+ | `logicalName` | `string` | Logical input identifier to remove |
379
+
380
+ ---
381
+
382
+ ### ๐Ÿ” `hasMappedInput(logicalName): boolean`
383
+
384
+ Checks if a logical input name has any physical inputs mapped.
385
+
386
+ | Parameter | Type | Returns |
387
+ | ------------- | -------- | ------------------------------------------- |
388
+ | `logicalName` | `string` | `true` if mapping exists, otherwise `false` |
389
+
390
+ ---
391
+
392
+ ### ๐Ÿ“‹ `getMappedInput(logicalName): string | string[]`
393
+
394
+ Gets the physical input(s) mapped to a logical input name.
395
+
396
+ | Parameter | Type | Returns |
397
+ | ------------- | -------- | ------------------------ |
398
+ | `logicalName` | `string` | Mapped physical input(s) |
399
+
400
+ ---
401
+
402
+ ### ๐Ÿงน `clearMapInputs()`
403
+
404
+ Clears **all** logical to physical input mappings.
405
+
406
+ ---
407
+
408
+ ## ๐Ÿ”— Input Sequences โ€” Logical & Physical
409
+
410
+ #### โžก๏ธ `registerInputSequence(sequence, callback)`
411
+
412
+ Registers a sequence of logical inputs that triggers a callback when fully held.
413
+
414
+ | Parameter | Type | Description |
415
+ | ---------- | ----------------------- | ----------------------------------------------------------- |
416
+ | `sequence` | `string[]` | Ordered list of logical inputs (e.g., `['Jump', 'Action']`) |
417
+ | `callback` | `InputSequenceCallback` | Function invoked when sequence is triggered |
418
+
419
+ ---
420
+
421
+ #### โŒ `unregisterInputSequence(sequence)`
422
+
423
+ Removes a registered logical input sequence.
424
+
425
+ ---
426
+
427
+ #### ๐Ÿงน `unregisterAllInputSequences()`
428
+
429
+ Removes **all** registered logical input sequences.
430
+
431
+ ---
432
+
433
+ #### ๐Ÿ” `hasInputSequence(sequence): boolean`
434
+
435
+ Checks if a logical input sequence is registered.
436
+
437
+ ---
438
+
439
+ #### โžก๏ธ `registerKeySequence(sequence, callback)`
440
+
441
+ Same as `registerInputSequence` but for **physical key** sequences.
442
+
443
+ ---
444
+
445
+ #### โŒ `unregisterKeySequence(sequence)`
446
+
447
+ Unregisters a physical key sequence.
448
+
449
+ ---
450
+
451
+ #### ๐Ÿงน `unregisterAllKeySequences()`
452
+
453
+ Removes all physical key sequences.
454
+
455
+ ---
456
+
457
+ #### ๐Ÿ” `hasKeySequence(sequence): boolean`
458
+
459
+ Checks if a physical key sequence is registered.
460
+
461
+ ---
462
+
463
+ ## โณ Combo Logical Keys Management
464
+
465
+ #### ๐Ÿ”„ `renewComboMapped()`
466
+
467
+ Refreshes the timer that tracks the currently held combo logical keys.
468
+ Useful to prevent premature combo resets when keys are still being held.
469
+
470
+ ---
471
+
472
+ #### โŒ `resetComboMapped()`
473
+
474
+ Resets and clears all current combo keys and combo inputs, stopping timers and resetting timestamps.
475
+
476
+ ---
477
+
478
+ ## ๐ŸŽฏ Event Listener Methods for Input Events
479
+
480
+ This section covers how to register, unregister, and manage callbacks for various input-related events.
481
+ Each event type has methods for regular (`on`), one-time (`once`), prepend, and removal of callbacks (`off`).
482
+
483
+ ---
484
+
485
+ ### ๐Ÿ”‘ Mapped Key Events
486
+
487
+ #### `onMappedKeyStart(callback)`
488
+
489
+ Register callback for when a mapped key is **pressed down**.
490
+
491
+ #### `onceMappedKeyStart(callback)`
492
+
493
+ Register a one-time callback that triggers once when a mapped key is pressed.
494
+
495
+ #### `prependMappedKeyStart(callback)`
496
+
497
+ Adds a callback at the start of the callback list for mapped key start.
498
+
499
+ #### `offMappedKeyStart(callback)`
500
+
501
+ Removes a specific callback from mapped key start event.
502
+
503
+ #### `offAllMappedKeyStart()`
504
+
505
+ Removes **all** callbacks from mapped key start event.
506
+
507
+ ---
508
+
509
+ #### `onMappedKeyEnd(callback)`
510
+
511
+ Register callback for when a mapped key is **released**.
512
+
513
+ #### `onceMappedKeyEnd(callback)`
514
+
515
+ One-time callback for mapped key release.
516
+
517
+ #### `prependMappedKeyEnd(callback)`
518
+
519
+ Prepends callback for mapped key release event.
520
+
521
+ #### `offMappedKeyEnd(callback)`
522
+
523
+ Removes a callback from mapped key release event.
524
+
525
+ #### `offAllMappedKeyEnd()`
526
+
527
+ Removes all callbacks from mapped key release event.
528
+
529
+ ---
530
+
531
+ ### ๐ŸŽ›๏ธ Mapped Input Events (includes buttons, analogs, sensors, etc.)
532
+
533
+ #### `onMappedInputStart(callback)`
534
+
535
+ Triggered when any mapped input is activated (pressed or engaged).
536
+
537
+ #### `onceMappedInputStart(callback)`
538
+
539
+ One-time callback for mapped input activation.
540
+
541
+ #### `prependMappedInputStart(callback)`
542
+
543
+ Prepends callback for mapped input start.
544
+
545
+ #### `offMappedInputStart(callback)`
546
+
547
+ Removes a callback from mapped input start.
548
+
549
+ #### `offAllMappedInputStart()`
550
+
551
+ Removes all callbacks from mapped input start.
552
+
553
+ ---
554
+
555
+ #### `onMappedInputEnd(callback)`
556
+
557
+ Triggered when a mapped input is deactivated (released or disengaged).
558
+
559
+ #### `onceMappedInputEnd(callback)`
560
+
561
+ One-time callback for mapped input release.
562
+
563
+ #### `prependMappedInputEnd(callback)`
564
+
565
+ Prepends callback for mapped input end.
566
+
567
+ #### `offMappedInputEnd(callback)`
568
+
569
+ Removes a callback from mapped input end.
570
+
571
+ #### `offAllMappedInputEnd()`
572
+
573
+ Removes all callbacks from mapped input end.
574
+
575
+ ---
576
+
577
+ ### ๐Ÿงฉ Logical Input Events by Name
578
+
579
+ These methods use the logical input names to manage callbacks for different stages of input:
580
+
581
+ | Event Type | Description |
582
+ | --------------- | ------------------------------------------------- |
583
+ | `onInput` | Callback on **any** input event |
584
+ | `onInputStart` | Callback when input is **pressed down** |
585
+ | `onInputEnd` | Callback when input is **released** |
586
+ | `onInputHold` | Callback when input is **held down** |
587
+ | `onInputChange` | Callback on **value changes** (e.g. analog move) |
588
+ | `onInputMove` | Callback on **movement inputs** (e.g. mouse move) |
589
+
590
+ ---
591
+
592
+ #### Common method patterns for logical inputs:
593
+
594
+ * `on<EventType>(logicalName, callback)`
595
+ Register a callback for the event.
596
+
597
+ * `once<EventType>(logicalName, callback)`
598
+ Register a one-time callback for the event.
599
+
600
+ * `prepend<EventType>(logicalName, callback)`
601
+ Add a callback to the **start** of the callback list.
602
+
603
+ * `off<EventType>(logicalName, callback)`
604
+ Remove a specific callback.
605
+
606
+ ---
607
+
608
+ #### Example: Logical Input "Jump" pressed down event
609
+
610
+ ```js
611
+ gamepad.onInputStart('Jump', callback);
612
+ gamepad.onceInputStart('Jump', callback);
613
+ gamepad.prependInputStart('Jump', callback);
614
+ gamepad.offInputStart('Jump', callback);
615
+ ```
616
+
617
+ ---
618
+
619
+ #### Detailed List of Methods:
620
+
621
+ | Method | Description |
622
+ | ------------------------------------- | ----------------------------- |
623
+ | `onInput(logicalName, callback)` | On any input event |
624
+ | `onceInput(logicalName, callback)` | One-time on any input |
625
+ | `prependInput(logicalName, callback)` | Prepend callback on any input |
626
+ | `offInput(logicalName, callback)` | Remove callback on any input |
627
+
628
+ | Method | Description |
629
+ | ------------------------------------------ | ------------------------------ |
630
+ | `onInputStart(logicalName, callback)` | On input pressed down |
631
+ | `onceInputStart(logicalName, callback)` | One-time on input pressed down |
632
+ | `prependInputStart(logicalName, callback)` | Prepend on input pressed down |
633
+ | `offInputStart(logicalName, callback)` | Remove on input pressed down |
634
+
635
+ | Method | Description |
636
+ | ---------------------------------------- | -------------------------- |
637
+ | `onInputEnd(logicalName, callback)` | On input released |
638
+ | `onceInputEnd(logicalName, callback)` | One-time on input released |
639
+ | `prependInputEnd(logicalName, callback)` | Prepend on input released |
640
+ | `offInputEnd(logicalName, callback)` | Remove on input released |
641
+
642
+ | Method | Description |
643
+ | ----------------------------------------- | ------------------------ |
644
+ | `onInputHold(logicalName, callback)` | While input is held down |
645
+ | `onceInputHold(logicalName, callback)` | One-time on hold |
646
+ | `prependInputHold(logicalName, callback)` | Prepend on hold |
647
+ | `offInputHold(logicalName, callback)` | Remove on hold |
648
+
649
+ | Method | Description |
650
+ | ------------------------------------------- | ------------------------------------------- |
651
+ | `onInputChange(logicalName, callback)` | On input value change (e.g., analog change) |
652
+ | `onceInputChange(logicalName, callback)` | One-time on input change |
653
+ | `prependInputChange(logicalName, callback)` | Prepend on input change |
654
+ | `offInputChange(logicalName, callback)` | Remove on input change |
655
+
656
+ | Method | Description |
657
+ | ----------------------------------------- | ------------------------------------ |
658
+ | `onInputMove(logicalName, callback)` | On movement input (e.g., mouse move) |
659
+ | `onceInputMove(logicalName, callback)` | One-time on move |
660
+ | `prependInputMove(logicalName, callback)` | Prepend on move |
661
+ | `offInputMove(logicalName, callback)` | Remove on move |
662
+
663
+ ---
664
+
665
+ ## ๐Ÿ“‹ Callback Management for Logical Inputs
666
+
667
+ These methods help you inspect and control the callbacks registered for logical inputs and their event types.
668
+
669
+ ---
670
+
671
+ ### ๐Ÿ” Get Registered Callbacks
672
+
673
+ #### `getCalls(logicalName, type = 'all')`
674
+
675
+ Returns a **shallow clone** of the callback list for a given logical input and event type.
676
+
677
+ * `logicalName`: Logical input name (e.g., "Jump")
678
+ * `type`: Event type filter โ€” `'all' | 'start' | 'end' | 'hold' | 'change' | 'move'` (default: `'all'`)
679
+ * Returns an array of registered callback functions.
680
+
681
+ ---
682
+
683
+ ### โŒ Remove All Callbacks for an Input
684
+
685
+ #### `offAllInputs(logicalName, type = 'all')`
686
+
687
+ Removes **all callbacks** for a specific logical input and event type.
688
+
689
+ * `logicalName`: Logical input name
690
+ * `type`: Event type filter (same as `getCalls`)
691
+
692
+ ---
693
+
694
+ ### ๐Ÿ”ข Count Registered Callbacks
695
+
696
+ #### `getCallSize(logicalName, type = 'all')`
697
+
698
+ Returns the number of callbacks registered for the given logical input and event type.
699
+
700
+ ---
701
+
702
+ ## ๐ŸŽฎ Haptic Feedback (Vibration) Control
703
+
704
+ ---
705
+
706
+ ### โš™๏ธ Default Haptic Effect Settings
707
+
708
+ * Private field storing default effect type and parameters (duration, intensity, etc.)
709
+
710
+ ---
711
+
712
+ ### ๐Ÿ” `get defaultHapticEffect()`
713
+
714
+ Returns the current default haptic feedback effect configuration, including effect type and parameters like duration and intensity.
715
+
716
+ ---
717
+
718
+ ### ๐Ÿ”ง `setDefaultHapticEffect(type, params)`
719
+
720
+ Sets the default haptic feedback effect for gamepad vibration.
721
+
722
+ * `type`: Effect type (e.g., `'dual-rumble'`)
723
+ * `params`: Effect parameters like duration, intensity
724
+
725
+ ---
726
+
727
+ ### ๐ŸŽต `hasHapticEffect()`
728
+
729
+ Checks if the currently connected gamepad supports vibration feedback.
730
+
731
+ * Returns: `true` if supported, `false` otherwise.
732
+
733
+ ---
734
+
735
+ ### ๐Ÿ“ณ `vibrate(params?, type?)`
736
+
737
+ Triggers a vibration on the connected gamepad using either custom or default parameters.
738
+
739
+ * Returns a Promise resolved when vibration completes.
740
+
741
+ ---
742
+
743
+ ## ๐Ÿšซ Ignoring Specific Input IDs
744
+
745
+ ---
746
+
747
+ ### `ignoreId(id)`
748
+
749
+ Adds an input ID to the ignored list (wonโ€™t trigger events).
750
+
751
+ ### `unignoreId(id)`
752
+
753
+ Removes an input ID from the ignored list.
754
+
755
+ ---
756
+
757
+ ## ๐Ÿ”Œ Gamepad Connection Events
758
+
759
+ ---
760
+
761
+ ### Connection Callbacks
762
+
763
+ | Method | Description |
764
+ | ---------------------- | -------------------------------------- |
765
+ | `onConnected(cb)` | Register callback on gamepad connected |
766
+ | `onceConnected(cb)` | One-time callback on connection |
767
+ | `prependConnected(cb)` | Prepend callback for connection |
768
+ | `offConnected(cb)` | Remove callback from connection event |
769
+ | `offAllConnected()` | Remove **all** connection callbacks |
770
+
771
+ ---
772
+
773
+ ### Disconnection Callbacks
774
+
775
+ | Method | Description |
776
+ | ------------------------- | ----------------------------------------- |
777
+ | `onDisconnected(cb)` | Register callback on gamepad disconnected |
778
+ | `onceDisconnected(cb)` | One-time callback on disconnection |
779
+ | `prependDisconnected(cb)` | Prepend callback for disconnection |
780
+ | `offDisconnected(cb)` | Remove callback from disconnection event |
781
+ | `offAllDisconnected()` | Remove **all** disconnection callbacks |
782
+
783
+ ---
784
+
785
+ ## ๐ŸŽฎ Gamepad Info and State
786
+
787
+ ---
788
+
789
+ ### `hasGamepad()`
790
+
791
+ Returns `true` if a gamepad is currently connected, else `false`.
792
+
793
+ ---
794
+
795
+ ### `getGamepad()`
796
+
797
+ Returns the connected `Gamepad` instance. Throws error if none connected.
798
+
799
+ ---
800
+
801
+ ### Button Last State Tracking
802
+
803
+ #### `hasLastButtonState(index)`
804
+
805
+ Checks if there is a recorded last state for button index.
806
+
807
+ #### `getLastButtonState(index)`
808
+
809
+ Returns a copy of the last known state for a button index. Throws if none recorded.
810
+
811
+ ---
812
+
813
+ ## โš™๏ธ Configuration Export & Import
814
+
815
+ ---
816
+
817
+ ### ๐Ÿ’พ `exportConfig()`
818
+
819
+ Exports the current TinyGamepad settings as a plain object, ready for saving or serialization.
820
+ Includes: device filters, ignored IDs, input mappings, sensitivities, and timeouts.
821
+ **Returns:** An object snapshot of the configuration.
822
+
823
+ ---
824
+
825
+ ### ๐Ÿ“ฅ `importConfig(json)`
826
+
827
+ Imports and applies a configuration object or JSON string to update TinyGamepad settings.
828
+
829
+ * Accepts either a JSON string or a config object.
830
+ * Validates types for each property and throws if invalid.
831
+ * Updates internal settings accordingly.
832
+
833
+ ---
834
+
835
+ ## ๐Ÿ”„ Callback Lists Getters
836
+
837
+ ---
838
+
839
+ ### ๐Ÿ”‘ Mapped Key Callbacks
840
+
841
+ * `mappedKeyStartCalls` โ€” Gets cloned list of callbacks for `"mapped-key-start"` event.
842
+ * `mappedKeyEndCalls` โ€” Gets cloned list of callbacks for `"mapped-key-end"` event.
843
+
844
+ ---
845
+
846
+ ### ๐Ÿ”€ Combo Keys and Inputs
847
+
848
+ * `comboMappedKeys` โ€” Clone of currently held **key combo** logical inputs.
849
+ * `comboMappedInputs` โ€” Clone of currently held **combo logical inputs**.
850
+
851
+ ---
852
+
853
+ ## ๐Ÿ“œ Input Sequence Info
854
+
855
+ ---
856
+
857
+ ### ๐Ÿ”ข Key Sequences
858
+
859
+ * `keySequenceSize` โ€” Number of registered input sequences.
860
+ * `keySequences` โ€” Clone array of all input sequence callbacks.
861
+
862
+ ---
863
+
864
+ ### ๐Ÿ”‘ Active Mapped Keys & Inputs
865
+
866
+ * `activeMappedKeys` โ€” Clone of currently held mapped logical keys.
867
+ * `activeMappedInputs` โ€” Clone of currently held mapped logical inputs.
868
+
869
+ ---
870
+
871
+ ## ๐Ÿ”‘ Mapped Input Callbacks
872
+
873
+ * `mappedInputStartCalls` โ€” Cloned callbacks for `"mapped-input-start"`.
874
+ * `mappedInputEndCalls` โ€” Cloned callbacks for `"mapped-input-end"`.
875
+
876
+ ---
877
+
878
+ ## ๐Ÿงฉ Input Sequences (Again)
879
+
880
+ * `inputSequenceSize` โ€” Number of registered input sequences (physical/logical).
881
+ * `inputSequences` โ€” Clone array of all input sequence callbacks.
882
+
883
+ ---
884
+
885
+ ## ๐Ÿ—บ๏ธ Logical-to-Physical Mapping Info
886
+
887
+ * `mappedInputs` โ€” Shallow clone object of all logical โ†’ physical input mappings.
888
+ * `mappedInputSize` โ€” Number of logical inputs currently mapped.
889
+
890
+ ---
891
+
892
+ ## ๐Ÿ”Œ Connection Event Callbacks
893
+
894
+ * `connectedCalls` โ€” Clone of callbacks for `"connected"` event.
895
+ * `disconnectedCalls` โ€” Clone of callbacks for `"disconnected"` event.
896
+
897
+ ---
898
+
899
+ ## ๐Ÿšซ Ignored Devices & Held Keys
900
+
901
+ * `ignoredDeviceIds` โ€” Clone of currently ignored device IDs.
902
+ * `heldKeys` โ€” Clone of currently held raw keys.
903
+
904
+ ---
905
+
906
+ ## ๐Ÿ“Š Event Counts & Sizes
907
+
908
+ * `eventsSize` โ€” Total number of registered callbacks (all events).
909
+ * `callSize` โ€” Number of unique event keys (types).
910
+ * `connectedCallSize` โ€” Number of callbacks registered for `"connected"`.
911
+ * `disconnectedCallSize` โ€” Number of callbacks registered for `"disconnected"`.
912
+ * `mappedKeyStartCallSize` โ€” Callbacks count for `"mapped-key-start"`.
913
+ * `mappedKeyEndCallSize` โ€” Callbacks count for `"mapped-key-end"`.
914
+ * `mappedInputStartCallSize` โ€” Callbacks count for `"mapped-input-start"`.
915
+ * `mappedInputEndCallSize` โ€” Callbacks count for `"mapped-input-end"`.
916
+
917
+ ---
918
+
919
+ ## ๐ŸŽฎ Last Button and Axis States
920
+
921
+ * `lastButtonStates` โ€” Snapshot array of button statuses from last update cycle.
922
+ * `lastAxes` โ€” Snapshot array of axis values (thumbsticks, triggers) from last update.
923
+
924
+ ---
925
+
926
+ ## ๐ŸŽ›๏ธ Input Modes and Event Targets
927
+
928
+ * `inputMode` โ€” Current input mode (e.g., `'keyboard-only'`, `'gamepad-only'`, `'both'`).
929
+ * `elementBase` โ€” DOM element or window used for event bindings.
930
+
931
+ ---
932
+
933
+ ## โฐ Timestamps & Timeouts
934
+
935
+ * `timeComboInputs` โ€” Timestamp of last mapped input combo.
936
+ * `timeComboKeys` โ€” Timestamp of last raw key combo.
937
+ * `timeMappedInputs` โ€” Timestamp of last mapped input activity.
938
+ * `timeoutComboKeys` โ€” Timeout in ms before raw key combos reset (getter/setter).
939
+
940
+ ---
941
+
942
+ ## ๐ŸŽš๏ธ Sensitivity & Dead Zone Settings
943
+
944
+ * `axisActiveSensitivity` โ€” Sensitivity threshold for axis movement to count as "active" input (getter/setter).
945
+ * `deadZone` โ€” Dead zone threshold for analog inputs (getter/setter).
946
+
947
+ ---
948
+
949
+ ## ๐Ÿ†” Device Identification
950
+
951
+ * `expectedId` โ€” Expected device ID filter (getter/setter).
952
+
953
+ ---
954
+
955
+ ## ๐Ÿงน Lifecycle & Cleanup
956
+
957
+ ---
958
+
959
+ ### ๐Ÿ”’ `isDestroyed`
960
+
961
+ **Getter** that returns whether this TinyGamepad instance has been destroyed.
962
+
963
+ * **Returns:** `true` if the instance has been cleaned up and disabled; otherwise `false`.
964
+ * Use this to check if the instance is still active or has been terminated.
965
+
966
+ ---
967
+
968
+ ### ๐Ÿ—‘๏ธ `destroy()`
969
+
970
+ Cleans up and completely stops all internal input monitoring and loops.
971
+
972
+ * Cancels any ongoing animation frames or loops.
973
+ * Removes all event listeners (keyboard, mouse, gamepad) based on current input mode.
974
+ * Resets combos and clears all internal state (maps, callbacks, keys, sequences, etc).
975
+ * Marks the instance as destroyed (`isDestroyed` becomes `true`).
976
+ * After calling this, the instance should no longer be used.
977
+
978
+ ---
979
+
980
+ โœจ **Tip:** Always call `destroy()` when you want to cleanly remove TinyGamepad and free resources, especially before discarding the instance or when switching contexts.