tiny-essentials 1.20.2 → 1.21.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 (123) 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/TinyRateLimiter.min.js +1 -1
  17. package/dist/v1/TinySmartScroller.min.js +1 -1
  18. package/dist/v1/TinyTextarea.min.js +1 -0
  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/index.cjs +2 -8
  25. package/dist/v1/basics/index.d.mts +3 -8
  26. package/dist/v1/basics/index.mjs +2 -3
  27. package/dist/v1/basics/simpleMath.cjs +46 -0
  28. package/dist/v1/basics/simpleMath.d.mts +27 -0
  29. package/dist/v1/basics/simpleMath.mjs +42 -0
  30. package/dist/v1/build/TinyAdvancedRaffle.cjs +7 -0
  31. package/dist/v1/build/TinyAdvancedRaffle.d.mts +3 -0
  32. package/dist/v1/build/TinyAdvancedRaffle.mjs +2 -0
  33. package/dist/v1/build/TinyArrayPaginator.cjs +7 -0
  34. package/dist/v1/build/TinyArrayPaginator.d.mts +3 -0
  35. package/dist/v1/build/TinyArrayPaginator.mjs +2 -0
  36. package/dist/v1/build/TinyCookieConsent.cjs +7 -0
  37. package/dist/v1/build/TinyCookieConsent.d.mts +3 -0
  38. package/dist/v1/build/TinyCookieConsent.mjs +2 -0
  39. package/dist/v1/build/TinyDayNightCycle.cjs +7 -0
  40. package/dist/v1/build/TinyDayNightCycle.d.mts +3 -0
  41. package/dist/v1/build/TinyDayNightCycle.mjs +2 -0
  42. package/dist/v1/build/TinyGamepad.cjs +7 -0
  43. package/dist/v1/build/TinyGamepad.d.mts +3 -0
  44. package/dist/v1/build/TinyGamepad.mjs +2 -0
  45. package/dist/v1/build/TinyI18.cjs +7 -0
  46. package/dist/v1/build/TinyI18.d.mts +3 -0
  47. package/dist/v1/build/TinyI18.mjs +2 -0
  48. package/dist/v1/build/TinyInventory.cjs +7 -0
  49. package/dist/v1/build/TinyInventory.d.mts +3 -0
  50. package/dist/v1/build/TinyInventory.mjs +2 -0
  51. package/dist/v1/build/TinyInventoryTrader.cjs +7 -0
  52. package/dist/v1/build/TinyInventoryTrader.d.mts +3 -0
  53. package/dist/v1/build/TinyInventoryTrader.mjs +2 -0
  54. package/dist/v1/build/TinyTextarea.cjs +7 -0
  55. package/dist/v1/build/TinyTextarea.d.mts +3 -0
  56. package/dist/v1/build/TinyTextarea.mjs +2 -0
  57. package/dist/v1/css/TinyCookieConsent.min.css +1 -0
  58. package/dist/v1/index.cjs +20 -8
  59. package/dist/v1/index.d.mts +12 -8
  60. package/dist/v1/index.mjs +11 -3
  61. package/dist/v1/libs/TinyAdvancedRaffle.cjs +1654 -0
  62. package/dist/v1/libs/TinyAdvancedRaffle.d.mts +851 -0
  63. package/dist/v1/libs/TinyAdvancedRaffle.mjs +1477 -0
  64. package/dist/v1/libs/TinyArrayPaginator.cjs +132 -0
  65. package/dist/v1/libs/TinyArrayPaginator.d.mts +78 -0
  66. package/dist/v1/libs/TinyArrayPaginator.mjs +119 -0
  67. package/dist/v1/libs/TinyCookieConsent.cjs +278 -0
  68. package/dist/v1/libs/TinyCookieConsent.d.mts +142 -0
  69. package/dist/v1/libs/TinyCookieConsent.mjs +248 -0
  70. package/dist/v1/libs/TinyDayNightCycle.cjs +1389 -0
  71. package/dist/v1/libs/TinyDayNightCycle.d.mts +673 -0
  72. package/dist/v1/libs/TinyDayNightCycle.mjs +1232 -0
  73. package/dist/v1/libs/TinyGamepad.cjs +2690 -0
  74. package/dist/v1/libs/TinyGamepad.d.mts +1286 -0
  75. package/dist/v1/libs/TinyGamepad.mjs +2386 -0
  76. package/dist/v1/libs/TinyHtml.d.mts +2 -2
  77. package/dist/v1/libs/TinyI18.cjs +946 -0
  78. package/dist/v1/libs/TinyI18.d.mts +418 -0
  79. package/dist/v1/libs/TinyI18.mjs +873 -0
  80. package/dist/v1/libs/TinyInventory.cjs +1788 -0
  81. package/dist/v1/libs/TinyInventory.d.mts +871 -0
  82. package/dist/v1/libs/TinyInventory.mjs +1650 -0
  83. package/dist/v1/libs/TinyInventoryTrader.cjs +242 -0
  84. package/dist/v1/libs/TinyInventoryTrader.d.mts +95 -0
  85. package/dist/v1/libs/TinyInventoryTrader.mjs +212 -0
  86. package/dist/v1/libs/TinyLocalStorage.cjs +14 -1
  87. package/dist/v1/libs/TinyLocalStorage.mjs +8 -1
  88. package/dist/v1/libs/TinyRateLimiter.cjs +0 -13
  89. package/dist/v1/libs/TinyRateLimiter.d.mts +0 -8
  90. package/dist/v1/libs/TinyRateLimiter.mjs +0 -12
  91. package/dist/v1/libs/TinySmartScroller.cjs +51 -15
  92. package/dist/v1/libs/TinySmartScroller.d.mts +28 -12
  93. package/dist/v1/libs/TinySmartScroller.mjs +44 -14
  94. package/dist/v1/libs/TinyTextarea.cjs +230 -0
  95. package/dist/v1/libs/TinyTextarea.d.mts +128 -0
  96. package/dist/v1/libs/TinyTextarea.mjs +198 -0
  97. package/dist/v1/libs/TinyToastNotify.cjs +2 -2
  98. package/dist/v1/libs/TinyToastNotify.mjs +2 -2
  99. package/dist/v1/libs/TinyUploadClicker.cjs +1 -1
  100. package/docs/v1/Ai-Tips.md +51 -0
  101. package/docs/v1/Personal-Ai-Prompts(portuguese).md +134 -0
  102. package/docs/v1/Personal-Ai-Prompts.md +113 -0
  103. package/docs/v1/README.md +24 -0
  104. package/docs/v1/basics/array.md +17 -0
  105. package/docs/v1/basics/simpleMath.md +73 -0
  106. package/docs/v1/libs/TinyAdvancedRaffle.md +674 -0
  107. package/docs/v1/libs/TinyArrayPaginator.md +150 -0
  108. package/docs/v1/libs/TinyCookieConsent.md +152 -0
  109. package/docs/v1/libs/TinyDayNightCycle.md +711 -0
  110. package/docs/v1/libs/TinyGamepad.md +980 -0
  111. package/docs/v1/libs/TinyI18.md +515 -0
  112. package/docs/v1/libs/TinyInventory.md +777 -0
  113. package/docs/v1/libs/TinyInventoryTrader.md +114 -0
  114. package/docs/v1/libs/TinySmartScroller.md +4 -4
  115. package/docs/v1/libs/TinyTextarea.md +156 -0
  116. package/package.json +7 -5
  117. package/dist/v1/basics/html_deprecated.cjs +0 -124
  118. package/dist/v1/basics/html_deprecated.d.mts +0 -40
  119. package/dist/v1/basics/html_deprecated.mjs +0 -97
  120. package/dist/v1/css/TinyDraggerExample.css +0 -21
  121. package/dist/v1/css/TinyNotify.css +0 -350
  122. package/dist/v1/css/aiMarker.css +0 -4
  123. package/docs/v1/basics/html_deprecated.md +0 -127
@@ -0,0 +1,674 @@
1
+ # 🎯 TinyAdvancedRaffle
2
+
3
+ **TinyAdvancedRaffle** is an advanced, event-driven raffle system designed for complex probability-based selections.
4
+ It goes beyond simple random draws by offering **weighted probabilities**, **normalization modes**, **pity mechanics**, **temporary modifiers**, and **seedable randomness** for reproducible outcomes.
5
+
6
+ With **import/export in JSON format**, **group-based filtering**, and **exclusion lists**, it’s ideal for games, loot systems, prize distributions, and any scenario requiring **balanced yet configurable randomness**.
7
+
8
+ ✨ **Key Features**
9
+
10
+ * 📊 **Weighted items** — Assign different probabilities to each item.
11
+ * 🧮 **Normalization modes** — Choose between *relative* and *softmax*.
12
+ * 🎯 **Pity system** — Guarantee fairness over multiple draws.
13
+ * 🔄 **Temporary modifiers** — Adjust weights dynamically for limited draws.
14
+ * 🗂️ **Group filtering** — Include or exclude items by groups.
15
+ * 🔐 **Item exclusions** — Prevent specific items from being drawn.
16
+ * 📦 **Import/export in JSON** — Save and restore raffle states easily.
17
+ * ⏳ **Seedable RNG** — Ensure deterministic and repeatable results.
18
+ * 📡 **Event-driven** — Hook into lifecycle events for customization.
19
+
20
+ ---
21
+
22
+ ## 🎯 Type Definitions & Core Concepts
23
+
24
+ This section defines the **core data structures**, **callbacks**, and **types** used by the `TinyAdvancedRaffle` system.
25
+
26
+ ---
27
+
28
+ ### 📊 Normalization Modes
29
+
30
+ ```ts
31
+ type Normalization = 'relative' | 'softmax';
32
+ ```
33
+
34
+ Defines the available normalization strategies for **probability weight calculations**:
35
+
36
+ * **`relative`** – Direct proportion based on item weights.
37
+ * **`softmax`** – Applies a softmax transformation for a probability distribution with exponential scaling.
38
+
39
+ ---
40
+
41
+ ### 🎲 RNG Generator
42
+
43
+ ```ts
44
+ type RngGenerator = () => number;
45
+ ```
46
+
47
+ A callback that generates a pseudo-random number between `0` (inclusive) and `1` (exclusive).
48
+
49
+ ---
50
+
51
+ ### ⏳ Temporary Weight Modifier
52
+
53
+ ```ts
54
+ type TempModifier = {
55
+ fn: WeightsCallback;
56
+ uses: number;
57
+ };
58
+ ```
59
+
60
+ Represents a **temporary weight modifier** that is applied for a **limited number of draws**.
61
+
62
+ * **`fn`** – Function that modifies the item weights.
63
+ * **`uses`** – Number of draws before the modifier is removed.
64
+
65
+ ---
66
+
67
+ ### 📦 Item Data Template
68
+
69
+ ```ts
70
+ type ItemDataTemplate<TGroups extends Set<string> | string[]> = {
71
+ id: string;
72
+ label: string;
73
+ baseWeight: number;
74
+ groups: TGroups;
75
+ locked: boolean;
76
+ meta: ItemMetadata;
77
+ };
78
+ ```
79
+
80
+ Represents the **core data structure** for an item in the raffle system.
81
+
82
+ | Property | Type | Description |
83
+ | ------------ | --------------------------- | ----------------------------------------- |
84
+ | `id` | `string` | Unique identifier for the item. |
85
+ | `label` | `string` | Human-readable name for the item. |
86
+ | `baseWeight` | `number` | Base probability weight before modifiers. |
87
+ | `groups` | `Set<string>` or `string[]` | Groups the item belongs to. |
88
+ | `locked` | `boolean` | Whether the item is excluded from draws. |
89
+ | `meta` | `ItemMetadata` | Arbitrary metadata. |
90
+
91
+ ---
92
+
93
+ ### 💾 Exported Raffle State
94
+
95
+ ```ts
96
+ type ExportedJson = {
97
+ items: ItemDataGetter[];
98
+ pity: [string, Pity][];
99
+ exclusions: string[];
100
+ normalization: Normalization;
101
+ seed: number | null;
102
+ };
103
+ ```
104
+
105
+ Represents the **serialized state** of the raffle system for export or persistence.
106
+
107
+ ---
108
+
109
+ ### 🏷 Specialized Item Types
110
+
111
+ * **`ItemData`** – Item where `groups` is a `Set<string>`.
112
+ * **`ItemDataGetter`** – Item where `groups` is a `string[]`.
113
+
114
+ ---
115
+
116
+ ### 🗃 Metadata Container
117
+
118
+ ```ts
119
+ type ItemMetadata = Record<string | number | symbol, any>;
120
+ ```
121
+
122
+ Arbitrary key-value container for **extra item information**.
123
+
124
+ ---
125
+
126
+ ### 🛠 Weight Calculation Context
127
+
128
+ ```ts
129
+ type ComputeEffectiveWeightsContext = {
130
+ metadata?: ItemMetadata;
131
+ previousDraws?: DrawOne[];
132
+ };
133
+ ```
134
+
135
+ Provides **context** to weight modification functions during a draw.
136
+
137
+ ---
138
+
139
+ ### ⚖ Weight Map
140
+
141
+ ```ts
142
+ type Weights = Map<string, number>;
143
+ ```
144
+
145
+ Maps **item IDs** to their computed **effective weight**.
146
+
147
+ ---
148
+
149
+ ### 🎯 Pity System
150
+
151
+ ```ts
152
+ type Pity = {
153
+ threshold: number;
154
+ increment: number;
155
+ cap: number;
156
+ counter: number;
157
+ currentAdd: number;
158
+ };
159
+ ```
160
+
161
+ Defines **pity mechanics** for guaranteeing item selection after repeated failures.
162
+
163
+ ---
164
+
165
+ ### 🧮 Weight Modifier Callback
166
+
167
+ ```ts
168
+ type WeightsCallback = (
169
+ weights: Weights,
170
+ context: ComputeEffectiveWeightsContext
171
+ ) => Weights | null;
172
+ ```
173
+
174
+ A function that modifies or overrides computed weights **before** a draw.
175
+
176
+ ---
177
+
178
+ ### 🎟 Draw Result
179
+
180
+ ```ts
181
+ type DrawOne = {
182
+ id: string;
183
+ label: string;
184
+ meta: ItemMetadata;
185
+ prob: number;
186
+ };
187
+ ```
188
+
189
+ Represents the **result** of a single draw.
190
+
191
+ ---
192
+
193
+ ### 📡 Event Handler
194
+
195
+ ```ts
196
+ type handler = (payload: any, event: any) => void;
197
+ ```
198
+
199
+ Generic event handler for message or signal reception.
200
+
201
+ ---
202
+
203
+ ## 🎰 Core Properties, Getters & Setters
204
+
205
+ This section covers the **private fields**, **public getters/setters**, and **constructor** of the `TinyAdvancedRaffle` class.
206
+
207
+ ---
208
+
209
+ ### 🔒 Private Fields
210
+
211
+ * **`#normalization`**: *(Normalization)* — Defines the strategy for scaling probabilities before a draw.
212
+
213
+ * Options: `'relative'` or `'softmax'`.
214
+
215
+ * **`#seed`**: *(number | null)* — RNG seed for deterministic results. If `null`, draws are fully random.
216
+
217
+ * **`#globalModifiers`**: *(WeightsCallback\[])* — Persistent weight-modifying functions applied to **every** draw.
218
+
219
+ * **`#temporaryModifiers`**: *(TempModifier\[])* — Temporary weight modifiers that expire after a set number of draws.
220
+
221
+ * **`#conditionalRules`**: *(WeightsCallback\[])* — Dynamic rules adjusting weights based on the raffle state.
222
+
223
+ * **`#pitySystems`**: *(Map\<string, Pity>)* — "Pity" mechanisms to increase chances after repeated failures.
224
+
225
+ * **`#exclusions`**: *(Set\<string>)* — Item IDs that cannot be drawn.
226
+
227
+ * **`#groups`**: *(Map\<string, Set\<string>>)* — Named groups containing sets of item IDs.
228
+
229
+ * **`#rng`**: *(RngGenerator)* — The random number generator used in draws.
230
+
231
+ * **`#items`**: *(Map\<string, ItemData>)* — All raffle items and their associated data.
232
+
233
+ * **`#freq`**: *(Map\<string, number>)* — Tracks how many times each item has been drawn.
234
+
235
+ ---
236
+
237
+ ### 📤 Public Getters
238
+
239
+ | Getter | Returns | Description |
240
+ | -------------------- | -------------------------------- | ------------------------------------------------ |
241
+ | `freq` | `Record<string, number>` | Draw frequency as a plain object. |
242
+ | `size` | `number` | Total number of registered items. |
243
+ | `normalization` | `Normalization` | Current probability scaling method. |
244
+ | `seed` | `number \| null` | RNG seed (if any). |
245
+ | `globalModifiers` | `WeightsCallback[]` | Copy of persistent modifiers. |
246
+ | `temporaryModifiers` | `TempModifier[]` | Copy of temporary modifiers with usage counts. |
247
+ | `conditionalRules` | `WeightsCallback[]` | Copy of conditional rules. |
248
+ | `pitySystems` | `Record<string, Pity>` | Copy of all pity configurations. |
249
+ | `exclusions` | `string[]` | List of excluded item IDs. |
250
+ | `groups` | `Record<string, string[]>` | Copy of group definitions. |
251
+ | `rng` | `RngGenerator` | RNG function used for draws. |
252
+ | `items` | `Record<string, ItemDataGetter>` | Copy of all item definitions (groups as arrays). |
253
+
254
+ ---
255
+
256
+ ### 📝 Public Setters
257
+
258
+ Each setter **validates input types** and throws `TypeError` for invalid data.
259
+
260
+ * **`normalization`** — Must be a non-empty string: `'relative'` or `'softmax'`.
261
+ * **`seed`** — Must be a finite number or `null`; reseeds RNG when changed.
262
+ * **`globalModifiers`** — Must be an array of functions.
263
+ * **`temporaryModifiers`** — Must be an array of `{ fn: function, uses: positive integer }`.
264
+ * **`conditionalRules`** — Must be an array of functions.
265
+ * **`pitySystems`** — Must be a `Map<string, Pity>` with all numeric fields.
266
+ * **`exclusions`** — Must be a `Set<string>`.
267
+ * **`groups`** — Must be a `Map<string, Set<string>>` where all values are strings.
268
+ * **`rng`** — Must be a function returning a number in `[0, 1)`.
269
+ * **`items`** — Must be a `Map<string, ItemData>`; **clears old list before setting**.
270
+
271
+ ---
272
+
273
+ ### 🏗 Constructor
274
+
275
+ This section sets up all **core data structures** and provides strict **input validation** to keep the raffle system’s state consistent. 🎯
276
+
277
+ **Parameters**:
278
+
279
+ * `opts.rng` *(RngGenerator | null)* — Custom RNG function. Defaults to `Math.random` if no seed is provided.
280
+ * `opts.seed` *(number | null)* — RNG seed for reproducible results.
281
+ * `opts.normalization` *(Normalization)* — Probability scaling mode (`'relative'` by default).
282
+
283
+ ---
284
+
285
+ ## 🎯 Item Management & Rules
286
+
287
+ ### 📦 Item Management
288
+
289
+ #### `hasItem(itemId)`
290
+
291
+ Check if an item exists in the system.
292
+
293
+ * **Parameters:**
294
+
295
+ * `itemId` *(string)* — The ID of the item to check.
296
+ * **Returns:** `boolean` — `true` if the item exists, otherwise `false`.
297
+ * **Throws:** `TypeError` if `itemId` is not a string.
298
+
299
+ ---
300
+
301
+ #### `addItem(id, opts = {})`
302
+
303
+ Add or update an item in the raffle.
304
+
305
+ * **Parameters:**
306
+
307
+ * `id` *(string)* — Unique item identifier.
308
+ * `opts` *(object, optional)* — Item configuration:
309
+
310
+ * `weight` *(number, default=1)* — Base relative weight (≥ 0).
311
+ * `label` *(string)* — Human-readable label.
312
+ * `meta` *(object)* — Arbitrary metadata.
313
+ * `groups` *(string\[] | Set<string>)* — Groups this item belongs to.
314
+ * **Returns:** `ItemData` — The created or updated item.
315
+ * **Throws:** `TypeError` for invalid types.
316
+
317
+ ---
318
+
319
+ #### `removeItem(id)`
320
+
321
+ Remove an item from the system.
322
+
323
+ * **Parameters:**
324
+
325
+ * `id` *(string)* — Item ID to remove.
326
+ * **Returns:** `boolean` — `true` if removed, `false` if it didn’t exist.
327
+ * **Throws:** `TypeError` if `id` is not a string.
328
+
329
+ ---
330
+
331
+ #### `setBaseWeight(id, weight)`
332
+
333
+ Update the base weight of an existing item.
334
+
335
+ * **Parameters:**
336
+
337
+ * `id` *(string)* — Item ID.
338
+ * `weight` *(number)* — New base weight (≥ 0).
339
+ * **Throws:**
340
+
341
+ * `Error` if the item is not found.
342
+ * `TypeError` for invalid parameters.
343
+
344
+ ---
345
+
346
+ #### `getItem(id)`
347
+
348
+ Retrieve an item by ID.
349
+
350
+ * **Parameters:**
351
+
352
+ * `id` *(string)* — Item ID.
353
+ * **Returns:** `ItemData | null` — Item data or `null` if not found.
354
+ * **Throws:** `TypeError` if `id` is not a string.
355
+
356
+ ---
357
+
358
+ #### `listItems()`
359
+
360
+ List all items in the system.
361
+
362
+ * **Returns:** `ItemData[]` — Array of cloned item objects.
363
+
364
+ ---
365
+
366
+ #### `clearList()`
367
+
368
+ Remove all items, frequencies, and pity systems.
369
+
370
+ ---
371
+
372
+ ### 🛠 Modifiers & Rules
373
+
374
+ #### Global Modifiers
375
+
376
+ Modifiers applied **persistently** to all draws.
377
+
378
+ * **`hasGlobalModifier(fn)`** — Check if a global modifier exists.
379
+ * **`addGlobalModifier(fn)`** — Add a persistent modifier.
380
+ * **`removeGlobalModifier(fn)`** — Remove a specific global modifier.
381
+
382
+ ---
383
+
384
+ #### Temporary Modifiers
385
+
386
+ Modifiers applied only for a **limited number of draws**.
387
+
388
+ * **`hasTemporaryModifier(fn)`** — Check if it exists.
389
+ * **`addTemporaryModifier(fn, uses = 1)`** — Add a modifier for `uses` draws.
390
+ * **`removeTemporaryModifier(fn)`** — Remove it.
391
+
392
+ ---
393
+
394
+ #### Conditional Rules
395
+
396
+ Rules applied dynamically during each draw.
397
+
398
+ * **`hasConditionalRule(ruleFn)`** — Check if it exists.
399
+ * **`addConditionalRule(ruleFn)`** — Add a conditional rule.
400
+ * **`removeConditionalRule(ruleFn)`** — Remove a conditional rule.
401
+
402
+ ---
403
+
404
+ ### 🍀 Pity System
405
+
406
+ The **pity system** increases the chance of an item appearing if it hasn’t been drawn after a certain number of tries.
407
+
408
+ * **`hasPity(itemId)`** — Check if pity exists for an item.
409
+ * **`configurePity(itemId, cfg)`** — Configure pity with:
410
+
411
+ * `threshold` *(number)* — Number of failed draws before increasing weight.
412
+ * `increment` *(number)* — Weight added each draw after threshold.
413
+ * `cap` *(number, default=Infinity)* — Max extra weight.
414
+ * **`resetPity(itemId)`** — Reset pity counters.
415
+ * **`clearPities()`** — Remove all pity configurations.
416
+
417
+ ---
418
+
419
+ ### 🚫 Exclusions & Groups
420
+
421
+ #### Exclusions
422
+
423
+ * **`hasExclusion(itemId)`** — Check if excluded.
424
+ * **`excludeItem(itemId)`** — Exclude from raffle.
425
+ * **`includeItem(itemId)`** — Re-include in raffle.
426
+
427
+ #### Groups
428
+
429
+ * **`_ensureGroup(name)`** *(private)* — Create or get a group.
430
+ * **`hasInGroup(itemId, groupName)`** — Check group membership.
431
+ * **`addToGroup(itemId, groupName)`** — Add item to a group.
432
+ * **`removeFromGroup(itemId, groupName)`** — Remove item from a group.
433
+
434
+ ---
435
+
436
+ ## 🎲 Draw Core
437
+
438
+ ### 🔄 Frequency Management
439
+
440
+ #### `clearFreqs()`
441
+
442
+ Clear the draw frequency count for **all** items.
443
+ Effectively resets the internal frequency tracking map to an empty state.
444
+
445
+ ---
446
+
447
+ #### `resetFreq(itemId)`
448
+
449
+ Reset the draw frequency for a **specific item**.
450
+
451
+ * **Parameters:**
452
+
453
+ * `itemId` *(string)* — Unique identifier of the item.
454
+ * **Throws:**
455
+
456
+ * `TypeError` if `itemId` is not a string.
457
+
458
+ ---
459
+
460
+ ### ⚖️ Weight Computation
461
+
462
+ #### `computeEffectiveWeights(context = {})`
463
+
464
+ Compute the **effective weights** of all items after applying:
465
+
466
+ 1. Base weights
467
+ 2. Global modifiers
468
+ 3. Temporary modifiers
469
+ 4. Conditional rules
470
+ 5. Pity system adjustments
471
+ 6. Exclusions
472
+ 7. Removal of zero or negative weights
473
+
474
+ * **Parameters:**
475
+
476
+ * `context` *(object, optional)* — Includes:
477
+
478
+ * `previousDraws` *(array)* — List of past draws.
479
+ * `metadata` *(object)* — Arbitrary metadata for rules.
480
+ * **Returns:** `Map<string, number>` — Map of item ID → effective weight.
481
+ * **Throws:**
482
+
483
+ * `TypeError` for invalid `context` format or property types.
484
+
485
+ ---
486
+
487
+ #### `_weightsToDistribution(weights)`
488
+
489
+ Convert a **weights map** into a normalized **probability distribution array**.
490
+
491
+ * **Parameters:**
492
+
493
+ * `weights` *(Map\<string, number>)* — Item IDs and their weights.
494
+ * **Returns:**
495
+ An array of objects:
496
+
497
+ ```ts
498
+ {
499
+ id: string, // item ID
500
+ weight: number, // weight value
501
+ p: number, // normalized probability
502
+ cumulative: number // cumulative probability for sampling
503
+ }
504
+ ```
505
+ * **Throws:**
506
+
507
+ * `TypeError` if `weights` is not a Map.
508
+ * `TypeError` for invalid key or value types.
509
+ * **Notes:**
510
+
511
+ * Supports **`softmax`** or **relative normalization**.
512
+
513
+ ---
514
+
515
+ ### 🎯 Drawing Items
516
+
517
+ #### `drawOne(opts = {})`
518
+
519
+ Draw **one item** from the raffle considering all configurations, rules, and pity effects.
520
+
521
+ * **Parameters:**
522
+
523
+ * `opts` *(object, optional)*:
524
+
525
+ * `previousDraws` *(array)* — Draw history for context.
526
+ * `metadata` *(object)* — Metadata for conditional rules.
527
+ * **Returns:**
528
+ An object:
529
+
530
+ ```ts
531
+ {
532
+ id: string, // item ID
533
+ label: string, // display label
534
+ meta: object, // cloned metadata
535
+ prob: number // probability at time of draw
536
+ }
537
+ ```
538
+
539
+ Or `null` if no items are available.
540
+ * **Throws:** `TypeError` for invalid option types.
541
+ * **Effects:**
542
+
543
+ * Updates **pity counters**.
544
+ * Consumes **temporary modifiers**.
545
+ * Increments **frequency counts**.
546
+ * Emits a **`draw`** event.
547
+
548
+ ---
549
+
550
+ #### `_consumeTemporaryModifiers()` *(private)*
551
+
552
+ Decrements usage counts of **temporary modifiers** and removes them when their uses reach zero.
553
+
554
+ ---
555
+
556
+ #### `drawMany(count = 1, opts = {})`
557
+
558
+ Draw multiple items in one operation.
559
+
560
+ * **Parameters:**
561
+
562
+ * `count` *(integer > 0)* — Number of items to draw.
563
+ * `opts` *(object, optional)*:
564
+
565
+ * `metadata` *(object)* — Metadata for rules.
566
+ * `withReplacement` *(boolean, default = true)* — Allow duplicates.
567
+ * `ensureUnique` *(boolean, default = false)* — Attempt to ensure unique results.
568
+ * `previousDraws` *(array)* — History for context.
569
+ * **Returns:** `DrawOne[]` — List of drawn items.
570
+ * **Throws:**
571
+
572
+ * `TypeError` for invalid `count` or option types.
573
+ * **Behavior Notes:**
574
+
575
+ * **`withReplacement = false` & `ensureUnique = true`** → Items are temporarily excluded during the draw session.
576
+ * **`withReplacement = false`** (without `ensureUnique`) → Items are excluded only for the session, then re-included.
577
+
578
+ ---
579
+
580
+ ### 📦 Save & Load (JSON)
581
+
582
+ #### 📤 `exportToJson()`
583
+
584
+ Exports the current configuration into a **JSON-serializable object**, capturing:
585
+
586
+ * **Items** (ID, label, base weight, metadata, groups)
587
+ * **Pity systems**
588
+ * **Exclusions**
589
+ * **Normalization mode**
590
+ * **Seed value**
591
+
592
+ This method is ideal for saving and restoring the raffle configuration between sessions.
593
+
594
+ **Returns**
595
+
596
+ * `ExportedJson` — An object containing the complete configuration.
597
+
598
+ ---
599
+
600
+ #### 📥 `loadFromJson(data)`
601
+
602
+ Loads configuration data previously generated by [`exportToJson()`](#-exporttojson).
603
+
604
+ **Behavior**
605
+
606
+ * Clears all existing items and state.
607
+ * Validates all input fields for type safety and constraints.
608
+ * Reconstructs items, pity systems, exclusions, and normalization settings.
609
+ * Restores the seed value if provided.
610
+
611
+ **Parameters**
612
+
613
+ * `data` (`ExportedJson`) — The configuration to load.
614
+
615
+ **Throws**
616
+
617
+ * `TypeError` if `data` is missing required properties or contains invalid values.
618
+
619
+ ---
620
+
621
+ ### 🪞 `clone()`
622
+
623
+ Creates a **deep clone** of the current raffle instance.
624
+
625
+ **Features**
626
+
627
+ * Fully duplicates all internal **Maps**, **Sets**, and **Arrays** to prevent shared references.
628
+ * Functions (e.g., callbacks) are **copied by reference** since they are immutable.
629
+ * The clone is entirely **independent** from the original instance.
630
+
631
+ **Returns**
632
+
633
+ * `TinyAdvancedRaffle` — A new cloned instance with identical state.
634
+
635
+ ---
636
+
637
+ ### 🎲 RNG: Seedable (mulberry32)
638
+
639
+ #### 🔢 `_makeSeededRng(seed)`
640
+
641
+ Creates a **deterministic pseudo-random number generator (PRNG)** using the **mulberry32** algorithm.
642
+
643
+ **Parameters**
644
+
645
+ * `seed` (`number`) — An integer used to seed the PRNG.
646
+
647
+ **Returns**
648
+
649
+ * `RngGenerator` — A function that returns a pseudo-random number in the range `[0, 1)`.
650
+
651
+ **Throws**
652
+
653
+ * `TypeError` if `seed` is not a finite number.
654
+
655
+ ---
656
+
657
+ ## 🗑️ `destroy()`
658
+
659
+ Completely **wipes** all internal data, breaks all references, and renders the raffle instance permanently unusable.
660
+ After calling this method, **any further calls** to its functions will throw an error.
661
+
662
+ **Use Cases**
663
+
664
+ * Freeing memory in long-running applications.
665
+ * Preventing accidental reuse after the raffle is no longer needed.
666
+ * Security-sensitive scenarios where sensitive item data must be fully erased.
667
+
668
+ **Example**
669
+
670
+ ```js
671
+ const raffle = new TinyAdvancedRaffle();
672
+ raffle.destroy();
673
+ raffle.clone(); // ❌ Throws an error: instance has been destroyed
674
+ ```