tiny-essentials 1.24.3 → 1.24.5

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.
@@ -1,4 +1,103 @@
1
1
  export default TinySimpleDice;
2
+ /**
3
+ * Represents a list of values used in dice modifier operations.
4
+ *
5
+ * Each entry can be either:
6
+ * - A number (representing a fixed numeric value), or
7
+ * - An object describing a dice roll, containing:
8
+ * - `value`: The rolled result.
9
+ * - `sides`: The number of sides of the die (e.g., 6 for a d6).
10
+ *
11
+ * Examples of valid entries:
12
+ * - `5` → a direct numeric value
13
+ * - `{ value: 3, sides: 6 }` → result of rolling a d6
14
+ */
15
+ export type DiceModifiersValues = (number | {
16
+ value: number;
17
+ sides: number;
18
+ })[];
19
+ /**
20
+ * Represents the result after applying all dice modifiers to a roll.
21
+ */
22
+ export type ApplyDiceModifiersResult = {
23
+ /**
24
+ * - The final computed value after all modifiers and dice results are processed.
25
+ */
26
+ final: number;
27
+ /**
28
+ * - A detailed, ordered list of steps describing how the final value was obtained.
29
+ */
30
+ steps: ApplyDiceModifiersStep[];
31
+ };
32
+ /**
33
+ * Represents a single step in the dice-modification process.
34
+ */
35
+ export type ApplyDiceModifiersStep = {
36
+ /**
37
+ * - The parsed tokens used in this step after normalization.
38
+ */
39
+ tokens: string[];
40
+ /**
41
+ * - The raw tokens preserved in their partially processed state.
42
+ */
43
+ rawTokensP: string[];
44
+ /**
45
+ * - The original unprocessed tokens extracted from the expression.
46
+ */
47
+ rawTokens: string[];
48
+ /**
49
+ * - Index references pointing to where each raw dice token appears in the original expression.
50
+ */
51
+ rawDiceTokenSlots: number[];
52
+ /**
53
+ * - Index references for processed/normalized dice tokens within the final evaluation sequence.
54
+ */
55
+ diceTokenSlots: number[];
56
+ /**
57
+ * - The computed subtotal for this step, before aggregation in later steps.
58
+ */
59
+ total: number;
60
+ /**
61
+ * - A list containing the result set of each dice roll.
62
+ * Each entry represents a single dice token and contains an array with the rolled numbers.
63
+ */
64
+ dicesResult: Array<number[]>;
65
+ };
66
+ /**
67
+ * Represents a list of values used in dice modifier operations.
68
+ *
69
+ * Each entry can be either:
70
+ * - A number (representing a fixed numeric value), or
71
+ * - An object describing a dice roll, containing:
72
+ * - `value`: The rolled result.
73
+ * - `sides`: The number of sides of the die (e.g., 6 for a d6).
74
+ *
75
+ * Examples of valid entries:
76
+ * - `5` → a direct numeric value
77
+ * - `{ value: 3, sides: 6 }` → result of rolling a d6
78
+ *
79
+ * @typedef {(number | { value: number; sides: number })[]} DiceModifiersValues
80
+ */
81
+ /**
82
+ * Represents the result after applying all dice modifiers to a roll.
83
+ *
84
+ * @typedef {Object} ApplyDiceModifiersResult
85
+ * @property {number} final - The final computed value after all modifiers and dice results are processed.
86
+ * @property {ApplyDiceModifiersStep[]} steps - A detailed, ordered list of steps describing how the final value was obtained.
87
+ */
88
+ /**
89
+ * Represents a single step in the dice-modification process.
90
+ *
91
+ * @typedef {Object} ApplyDiceModifiersStep
92
+ * @property {string[]} tokens - The parsed tokens used in this step after normalization.
93
+ * @property {string[]} rawTokensP - The raw tokens preserved in their partially processed state.
94
+ * @property {string[]} rawTokens - The original unprocessed tokens extracted from the expression.
95
+ * @property {number[]} rawDiceTokenSlots - Index references pointing to where each raw dice token appears in the original expression.
96
+ * @property {number[]} diceTokenSlots - Index references for processed/normalized dice tokens within the final evaluation sequence.
97
+ * @property {number} total - The computed subtotal for this step, before aggregation in later steps.
98
+ * @property {Array<number[]>} dicesResult - A list containing the result set of each dice roll.
99
+ * Each entry represents a single dice token and contains an array with the rolled numbers.
100
+ */
2
101
  /**
3
102
  * TinySimpleDice
4
103
  *
@@ -7,6 +106,114 @@ export default TinySimpleDice;
7
106
  * values suitable for indexing arrays or Sets.
8
107
  */
9
108
  declare class TinySimpleDice {
109
+ /**
110
+ * Safely evaluates a mathematical expression (supports +, -, *, /, %, **, parentheses, fractions and decimals).
111
+ * This function ensures only valid math characters are processed.
112
+ *
113
+ * @param {string} expression - Mathematical expression to evaluate.
114
+ * @returns {number} The calculated numeric result.
115
+ * @private
116
+ */
117
+ private static _safeEvaluate;
118
+ /**
119
+ * Replaces dice patterns such as `d6`, `d32`, or multi-dice patterns like `3d6`
120
+ * using sequential values from the provided array.
121
+ *
122
+ * - `d6` consumes 1 value from the array.
123
+ * - `3d6` consumes 3 values from the array and replaces the pattern with their sum.
124
+ *
125
+ * If there are not enough values available, missing rolls default to 0.
126
+ *
127
+ * @param {string} input - The input string containing dice patterns.
128
+ * @param {number[]} values - Sequential numeric values used to replace each dice roll.
129
+ * @returns {string} The resulting string where each dice expression is replaced by its computed value.
130
+ *
131
+ * @example
132
+ * replaceValues("You deal d6 damage", [4]);
133
+ * // → "You deal 4 damage"
134
+ *
135
+ * @example
136
+ * replaceValues("Roll 3d6 for strength", [3, 5, 2]);
137
+ * // → "Roll 10 for strength"
138
+ *
139
+ * @example
140
+ * replaceValues("Attack: 2d4 + d8", [1, 3, 7]);
141
+ * // → "Attack: 4 + 7"
142
+ */
143
+ static replaceValues(input: string, values: number[]): string;
144
+ /**
145
+ * Tokenizes an expression string while replacing dice patterns (`d6`, `3d6`, etc.)
146
+ * with numeric values taken sequentially from the provided array.
147
+ *
148
+ * This function performs two operations:
149
+ * 1. Dice replacement:
150
+ * - `d6` consumes 1 value.
151
+ * - `3d6` consumes 3 values and returns their sum.
152
+ * - Missing values default to 0.
153
+ *
154
+ * 2. Tokenization:
155
+ * - Numbers become numeric tokens.
156
+ * - Operators (`+`, `-`, `*`, `/`, `(`, `)`) become string tokens.
157
+ *
158
+ * Example:
159
+ * Input: "2d6 + 4 - d8"
160
+ * Values: [3, 4, 5]
161
+ * Output: [7, "+", 4, "-", 5]
162
+ *
163
+ * @param {string} input - The input string containing dice expressions.
164
+ * @param {number[]} values - Sequential numbers used to replace each dice roll.
165
+ * @returns {{ tokens: (string|number)[], text: string }} A tokenized list where dice expressions become numbers.
166
+ *
167
+ * @example
168
+ * tokenizeValues("You deal d6 + 2", [4]);
169
+ * // → [4, "+", 2]
170
+ *
171
+ * @example
172
+ * tokenizeValues("3d6 + d4", [3, 5, 2, 1]);
173
+ * // → [10, "+", 1]
174
+ *
175
+ * @example
176
+ * tokenizeValues("2d4 - 1d8 + 7", [1, 3, 7]);
177
+ * // → [4, "-", 7, "+", 7]
178
+ */
179
+ static tokenizeValues(input: string, values: number[]): {
180
+ tokens: (string | number)[];
181
+ text: string;
182
+ };
183
+ /**
184
+ * Parses a dice configuration string supporting notations like "6d" (one d6) or "3d6" (three d6).
185
+ * Extracts all valid dice expressions and keeps their full context as modifiers.
186
+ *
187
+ * @param {string} input - Comma-separated dice expressions.
188
+ * @returns {{
189
+ * sides: { count: number, sides: number }[],
190
+ * modifiers: { index: number, original: string, expression: string }[]
191
+ * }}
192
+ */
193
+ static parseString(input: string): {
194
+ sides: {
195
+ count: number;
196
+ sides: number;
197
+ }[];
198
+ modifiers: {
199
+ index: number;
200
+ original: string;
201
+ expression: string;
202
+ }[];
203
+ };
204
+ /**
205
+ * Applies parsed modifiers (expressions) to a base number.
206
+ * Replaces only the first number in the expression with the current result
207
+ * before evaluation. Returns an object containing a step-by-step history.
208
+ *
209
+ * @param {DiceModifiersValues} values - Starting number (e.g., dice base value).
210
+ * @param {{ expression: string, original: string }[]} modifiers - Parsed modifiers from TinySimpleDice.parseString.
211
+ * @returns {ApplyDiceModifiersResult}
212
+ */
213
+ static applyModifiers(values: DiceModifiersValues, modifiers: {
214
+ expression: string;
215
+ original: string;
216
+ }[]): ApplyDiceModifiersResult;
10
217
  /**
11
218
  * Rolls a dice specifically for choosing an array or Set index.
12
219
  * @param {any[]|Set<any>} arr - The array or Set to get a random index from.
@@ -1,3 +1,39 @@
1
+ import { isJsonObject } from '../basics/objChecker.mjs';
2
+ /**
3
+ * Represents a list of values used in dice modifier operations.
4
+ *
5
+ * Each entry can be either:
6
+ * - A number (representing a fixed numeric value), or
7
+ * - An object describing a dice roll, containing:
8
+ * - `value`: The rolled result.
9
+ * - `sides`: The number of sides of the die (e.g., 6 for a d6).
10
+ *
11
+ * Examples of valid entries:
12
+ * - `5` → a direct numeric value
13
+ * - `{ value: 3, sides: 6 }` → result of rolling a d6
14
+ *
15
+ * @typedef {(number | { value: number; sides: number })[]} DiceModifiersValues
16
+ */
17
+ /**
18
+ * Represents the result after applying all dice modifiers to a roll.
19
+ *
20
+ * @typedef {Object} ApplyDiceModifiersResult
21
+ * @property {number} final - The final computed value after all modifiers and dice results are processed.
22
+ * @property {ApplyDiceModifiersStep[]} steps - A detailed, ordered list of steps describing how the final value was obtained.
23
+ */
24
+ /**
25
+ * Represents a single step in the dice-modification process.
26
+ *
27
+ * @typedef {Object} ApplyDiceModifiersStep
28
+ * @property {string[]} tokens - The parsed tokens used in this step after normalization.
29
+ * @property {string[]} rawTokensP - The raw tokens preserved in their partially processed state.
30
+ * @property {string[]} rawTokens - The original unprocessed tokens extracted from the expression.
31
+ * @property {number[]} rawDiceTokenSlots - Index references pointing to where each raw dice token appears in the original expression.
32
+ * @property {number[]} diceTokenSlots - Index references for processed/normalized dice tokens within the final evaluation sequence.
33
+ * @property {number} total - The computed subtotal for this step, before aggregation in later steps.
34
+ * @property {Array<number[]>} dicesResult - A list containing the result set of each dice roll.
35
+ * Each entry represents a single dice token and contains an array with the rolled numbers.
36
+ */
1
37
  /**
2
38
  * TinySimpleDice
3
39
  *
@@ -6,6 +42,339 @@
6
42
  * values suitable for indexing arrays or Sets.
7
43
  */
8
44
  class TinySimpleDice {
45
+ /**
46
+ * Safely evaluates a mathematical expression (supports +, -, *, /, %, **, parentheses, fractions and decimals).
47
+ * This function ensures only valid math characters are processed.
48
+ *
49
+ * @param {string} expression - Mathematical expression to evaluate.
50
+ * @returns {number} The calculated numeric result.
51
+ * @private
52
+ */
53
+ static _safeEvaluate(expression) {
54
+ // Sanitize and validate only allowed math-safe characters
55
+ if (!/^[\d+\-*/%.()\s^]+$/.test(expression)) {
56
+ throw new Error(`Invalid characters in expression: "${expression}"`);
57
+ }
58
+ // Normalize power operator: allow both ** and ^ for exponentiation
59
+ const normalized = expression.replace(/\^/g, '**');
60
+ try {
61
+ // Create isolated, safe Function (no variables, only math ops)
62
+ return Function(`"use strict"; return (${normalized})`)();
63
+ }
64
+ catch (err) {
65
+ if (!(err instanceof Error))
66
+ throw new Error('Unknown Error');
67
+ throw new Error(`Invalid expression "${expression}": ${err.message}`);
68
+ }
69
+ }
70
+ /**
71
+ * Replaces dice patterns such as `d6`, `d32`, or multi-dice patterns like `3d6`
72
+ * using sequential values from the provided array.
73
+ *
74
+ * - `d6` consumes 1 value from the array.
75
+ * - `3d6` consumes 3 values from the array and replaces the pattern with their sum.
76
+ *
77
+ * If there are not enough values available, missing rolls default to 0.
78
+ *
79
+ * @param {string} input - The input string containing dice patterns.
80
+ * @param {number[]} values - Sequential numeric values used to replace each dice roll.
81
+ * @returns {string} The resulting string where each dice expression is replaced by its computed value.
82
+ *
83
+ * @example
84
+ * replaceValues("You deal d6 damage", [4]);
85
+ * // → "You deal 4 damage"
86
+ *
87
+ * @example
88
+ * replaceValues("Roll 3d6 for strength", [3, 5, 2]);
89
+ * // → "Roll 10 for strength"
90
+ *
91
+ * @example
92
+ * replaceValues("Attack: 2d4 + d8", [1, 3, 7]);
93
+ * // → "Attack: 4 + 7"
94
+ */
95
+ static replaceValues(input, values) {
96
+ let index = 0;
97
+ return input.replace(/(\d*)d(\d+)/g, (match, qty) => {
98
+ const count = qty ? Number(qty) : 1; // default is 1dX
99
+ let total = 0;
100
+ for (let i = 0; i < count; i++) {
101
+ const value = values[index++];
102
+ total += value !== undefined ? value : 0;
103
+ }
104
+ return String(total);
105
+ });
106
+ }
107
+ /**
108
+ * Tokenizes an expression string while replacing dice patterns (`d6`, `3d6`, etc.)
109
+ * with numeric values taken sequentially from the provided array.
110
+ *
111
+ * This function performs two operations:
112
+ * 1. Dice replacement:
113
+ * - `d6` consumes 1 value.
114
+ * - `3d6` consumes 3 values and returns their sum.
115
+ * - Missing values default to 0.
116
+ *
117
+ * 2. Tokenization:
118
+ * - Numbers become numeric tokens.
119
+ * - Operators (`+`, `-`, `*`, `/`, `(`, `)`) become string tokens.
120
+ *
121
+ * Example:
122
+ * Input: "2d6 + 4 - d8"
123
+ * Values: [3, 4, 5]
124
+ * Output: [7, "+", 4, "-", 5]
125
+ *
126
+ * @param {string} input - The input string containing dice expressions.
127
+ * @param {number[]} values - Sequential numbers used to replace each dice roll.
128
+ * @returns {{ tokens: (string|number)[], text: string }} A tokenized list where dice expressions become numbers.
129
+ *
130
+ * @example
131
+ * tokenizeValues("You deal d6 + 2", [4]);
132
+ * // → [4, "+", 2]
133
+ *
134
+ * @example
135
+ * tokenizeValues("3d6 + d4", [3, 5, 2, 1]);
136
+ * // → [10, "+", 1]
137
+ *
138
+ * @example
139
+ * tokenizeValues("2d4 - 1d8 + 7", [1, 3, 7]);
140
+ * // → [4, "-", 7, "+", 7]
141
+ */
142
+ static tokenizeValues(input, values) {
143
+ // Tokenizer: numbers become numbers, operators become strings.
144
+ const replaced = TinySimpleDice.replaceValues(input, values);
145
+ const tokens = [];
146
+ const regex = /\d+|[()+\-*/]/g;
147
+ let match;
148
+ while ((match = regex.exec(replaced)) !== null) {
149
+ if (/^\d+$/.test(match[0])) {
150
+ tokens.push(Number(match[0]));
151
+ }
152
+ else {
153
+ tokens.push(match[0]);
154
+ }
155
+ }
156
+ return { tokens, text: replaced };
157
+ }
158
+ /**
159
+ * Parses a dice configuration string supporting notations like "6d" (one d6) or "3d6" (three d6).
160
+ * Extracts all valid dice expressions and keeps their full context as modifiers.
161
+ *
162
+ * @param {string} input - Comma-separated dice expressions.
163
+ * @returns {{
164
+ * sides: { count: number, sides: number }[],
165
+ * modifiers: { index: number, original: string, expression: string }[]
166
+ * }}
167
+ */
168
+ static parseString(input) {
169
+ if (typeof input !== 'string') {
170
+ throw new TypeError('Input must be a string.');
171
+ }
172
+ const parts = input
173
+ .split(',')
174
+ .map((p) => p.trim())
175
+ .filter(Boolean);
176
+ /** @type {{ count: number, sides: number }[]} */
177
+ const sides = [];
178
+ /** @type {{ index: number, original: string, expression: string }[]} */
179
+ const modifiers = [];
180
+ parts.forEach((part, i) => {
181
+ // ✅ Match dice patterns:
182
+ // - 6d → one d6
183
+ // - 3d6 → three d6
184
+ // - 12d100 → twelve d100
185
+ const regex = /\b(?:(\d+)?d(\d+))\b/g;
186
+ let match;
187
+ const foundDice = [];
188
+ // --- 🔸 Resolve random choice groups like (0 | 1 | d1)
189
+ const finalPart = part.replace(/\(([^()]+?\|[^()]+?)\)/g, (match, inner) => {
190
+ const options = typeof inner === 'string'
191
+ ? inner
192
+ .split('|')
193
+ .map((s) => s.trim())
194
+ .filter(Boolean)
195
+ : [];
196
+ if (options.length === 0)
197
+ throw new Error(`Invalid random-choice group: "${match}"`);
198
+ const chosen = options[Math.floor(Math.random() * options.length)];
199
+ return chosen;
200
+ });
201
+ while ((match = regex.exec(finalPart)) !== null) {
202
+ const count = parseInt(match[1] || '1', 10); // Default to 1 if not specified (e.g. "d6" or "6d")
203
+ const sidesCount = parseInt(match[2], 10);
204
+ if (isNaN(sidesCount)) {
205
+ throw new Error(`Invalid dice sides in expression "${match[0]}" at position ${i + 1}.`);
206
+ }
207
+ foundDice.push({ count, sides: sidesCount });
208
+ }
209
+ if (foundDice.length === 0 && Number.isNaN(parseFloat(finalPart))) {
210
+ throw new Error(`Invalid dice expression at position ${i + 1}: "${part}"`);
211
+ }
212
+ // Add all found dice
213
+ sides.push(...foundDice);
214
+ // Store full expression
215
+ modifiers.push({
216
+ index: i,
217
+ original: part,
218
+ expression: finalPart,
219
+ });
220
+ });
221
+ if (sides.length === 0)
222
+ throw new Error(`Invalid dice amount.`);
223
+ return { sides, modifiers };
224
+ }
225
+ /**
226
+ * Applies parsed modifiers (expressions) to a base number.
227
+ * Replaces only the first number in the expression with the current result
228
+ * before evaluation. Returns an object containing a step-by-step history.
229
+ *
230
+ * @param {DiceModifiersValues} values - Starting number (e.g., dice base value).
231
+ * @param {{ expression: string, original: string }[]} modifiers - Parsed modifiers from TinySimpleDice.parseString.
232
+ * @returns {ApplyDiceModifiersResult}
233
+ */
234
+ static applyModifiers(values, modifiers) {
235
+ if (!Array.isArray(values) ||
236
+ !values.every((n) => (typeof n === 'number' && !Number.isNaN(n)) ||
237
+ (isJsonObject(n) &&
238
+ typeof n.value === 'number' &&
239
+ !Number.isNaN(n.value) &&
240
+ typeof n.sides === 'number' &&
241
+ !Number.isNaN(n.sides))))
242
+ throw new TypeError('Bases must be a valid numbers.');
243
+ if (!Array.isArray(modifiers))
244
+ throw new TypeError('Modifiers must be an array of modifier objects.');
245
+ let result = 0;
246
+ /** @type {ApplyDiceModifiersStep[]} */
247
+ const steps = [];
248
+ /** @type {DiceModifiersValues} */
249
+ const iv = [...values];
250
+ for (const index in modifiers) {
251
+ const mod = modifiers[index];
252
+ if (typeof mod.expression !== 'string') {
253
+ throw new Error('Each modifier must include an expression string.');
254
+ }
255
+ const originalExp = mod.original;
256
+ const expression = mod.expression;
257
+ /** @type {Array<number[]>} */
258
+ const dices = [];
259
+ /** @type {number[]} */
260
+ const diceTokenSlots = [];
261
+ /** @type {number[]} */
262
+ const rawDiceTokenSlots = [];
263
+ /**
264
+ * Tokenize expression for manipulation or display.
265
+ * Supports dice, numbers, parentheses, math ops, and choice groups.
266
+ * Ensures (0 | 1 | d1) is treated as ONE token.
267
+ * @param {string} value
268
+ * @returns {string[]}
269
+ */
270
+ const matchTokens = (value) => value.match(/\(\s*[^()]+\|\s*[^()]+\s*\)|\b\d*d\d+\b|[-+]?\d+(?:\.\d+)?|[+\-*/%^()]/g) ||
271
+ [];
272
+ const rawTokens = matchTokens(expression);
273
+ const rawTokensOriginal = matchTokens(originalExp);
274
+ const tokens = [...rawTokens];
275
+ /** @type {string[]} */
276
+ const rawSlotsUsed = [];
277
+ // ✅ Replace the first numeric literal (integer/decimal) that may be inside parentheses
278
+ // @ts-ignore
279
+ const replacedExpr = expression.replace(/\b\d*d\d+\b/g, (m0) => {
280
+ // Parse dice numbers
281
+ const diceParsed = m0.split('d');
282
+ const getRawTokenSlot = () => {
283
+ for (const index in rawTokens) {
284
+ if (rawTokens[index] === m0 && rawSlotsUsed.indexOf(index) < 0) {
285
+ rawSlotsUsed.push(index);
286
+ rawDiceTokenSlots.push(Number(index));
287
+ break;
288
+ }
289
+ }
290
+ };
291
+ /**
292
+ * Validates that the dice value does not exceed the number of sides.
293
+ * @param {{ value: number; sides: number }} r - The dice roll result and the number of sides.
294
+ * @throws {Error} If the value is greater than the number of sides.
295
+ */
296
+ const diceValidator = (r) => {
297
+ if (r.value > r.sides)
298
+ throw new Error(`Invalid dice roll: value (${r.value}) must be between 1 and ${r.sides}.`);
299
+ };
300
+ // 1dn
301
+ if (diceParsed[0].trim().length === 0) {
302
+ const r = iv.shift();
303
+ const rv = typeof r === 'number' ? r : isJsonObject(r) ? r.value : 0;
304
+ if (isJsonObject(r))
305
+ diceValidator(r);
306
+ dices.push([rv]);
307
+ for (const index in tokens) {
308
+ if (tokens[index] === m0) {
309
+ tokens[index] = String(rv);
310
+ diceTokenSlots.push(Number(index));
311
+ break;
312
+ }
313
+ }
314
+ getRawTokenSlot();
315
+ return rv;
316
+ }
317
+ // ndn
318
+ /** @type {number[]} */
319
+ const dices2 = [];
320
+ const diceAmount = Number(diceParsed[0]);
321
+ const newTokensInsert = ['('];
322
+ let total = '(';
323
+ for (let i = 0; i < diceAmount; i++) {
324
+ const r = iv.shift();
325
+ const rv = typeof r === 'number' ? r : isJsonObject(r) ? r.value : 0;
326
+ if (isJsonObject(r))
327
+ diceValidator(r);
328
+ newTokensInsert.push(String(rv));
329
+ const finishSpace = i < diceAmount - 1 ? ' + ' : ')';
330
+ newTokensInsert.push(finishSpace);
331
+ total += `${rv}${finishSpace}`;
332
+ dices2.push(rv);
333
+ }
334
+ for (const index in tokens) {
335
+ const i = Number(index);
336
+ if (tokens[i] === m0) {
337
+ tokens.splice(i, 1, ...newTokensInsert);
338
+ // Each new item a new string is added
339
+ let amount = 1;
340
+ for (let i2 = 0; i2 < diceAmount; i2++) {
341
+ diceTokenSlots.push(i + i2 + amount);
342
+ amount++;
343
+ }
344
+ break;
345
+ }
346
+ }
347
+ dices.push(dices2);
348
+ getRawTokenSlot();
349
+ return total;
350
+ });
351
+ /** @type {number} */
352
+ let evaluated;
353
+ try {
354
+ evaluated = TinySimpleDice._safeEvaluate(replacedExpr);
355
+ }
356
+ catch (err) {
357
+ if (!(err instanceof Error))
358
+ throw new Error('Unknown Error');
359
+ throw new Error(`Error evaluating expression "${replacedExpr}" (from "${expression}"): ${err.message}`);
360
+ }
361
+ steps.push({
362
+ rawTokensP: rawTokens,
363
+ rawTokens: rawTokensOriginal,
364
+ tokens,
365
+ rawDiceTokenSlots,
366
+ diceTokenSlots,
367
+ dicesResult: dices,
368
+ total: evaluated,
369
+ });
370
+ result += evaluated;
371
+ }
372
+ // Complete
373
+ return {
374
+ final: result,
375
+ steps,
376
+ };
377
+ }
9
378
  /**
10
379
  * Rolls a dice specifically for choosing an array or Set index.
11
380
  * @param {any[]|Set<any>} arr - The array or Set to get a random index from.
@@ -114,7 +114,77 @@ Each library can be imported separately:
114
114
  * **HTML Helpers** 🧩
115
115
 
116
116
  * `libs/TinyHtml`
117
- * `libs/TinyHtmlElems`
117
+ * `libs/TinyHtmlElems` (BETA)
118
+
119
+ * **General Elements (BETA)**
120
+
121
+ * `libs/TinyHtmlElems/Anchor`
122
+ * `libs/TinyHtmlElems/Button`
123
+ * `libs/TinyHtmlElems/Canvas`
124
+ * `libs/TinyHtmlElems/Datalist`
125
+ * `libs/TinyHtmlElems/Form`
126
+ * `libs/TinyHtmlElems/Embed`
127
+ * `libs/TinyHtmlElems/Icon`
128
+ * `libs/TinyHtmlElems/Iframe`
129
+ * `libs/TinyHtmlElems/Image`
130
+ * `libs/TinyHtmlElems/Link`
131
+ * `libs/TinyHtmlElems/Script`
132
+ * `libs/TinyHtmlElems/Select`
133
+ * `libs/TinyHtmlElems/Style`
134
+ * `libs/TinyHtmlElems/Template`
135
+ * `libs/TinyHtmlElems/Textarea`
136
+
137
+ * **Media Elements (BETA)** 🎬
138
+
139
+ * `libs/TinyHtmlElems/Media`
140
+ * `libs/TinyHtmlElems/Media/Audio`
141
+ * `libs/TinyHtmlElems/Media/Object`
142
+ * `libs/TinyHtmlElems/Media/Source`
143
+ * `libs/TinyHtmlElems/Media/Video`
144
+
145
+ * **Input Elements (BETA)** ⌨️
146
+
147
+ * `libs/TinyHtmlElems/Input`
148
+
149
+ * **Button Inputs (BETA)**
150
+
151
+ * `libs/TinyHtmlElems/Input/Button`
152
+ * `libs/TinyHtmlElems/Input/Reset`
153
+ * `libs/TinyHtmlElems/Input/Submit`
154
+
155
+ * **Check Inputs (BETA)**
156
+
157
+ * `libs/TinyHtmlElems/Input/Checkbox`
158
+ * `libs/TinyHtmlElems/Input/Radio`
159
+
160
+ * **Color & File Inputs (BETA)**
161
+
162
+ * `libs/TinyHtmlElems/Input/Color`
163
+ * `libs/TinyHtmlElems/Input/File`
164
+ * `libs/TinyHtmlElems/Input/Hidden`
165
+ * `libs/TinyHtmlElems/Input/Image`
166
+
167
+ * **Date & Time Inputs (BETA)** 🕒
168
+
169
+ * `libs/TinyHtmlElems/Input/Date`
170
+ * `libs/TinyHtmlElems/Input/DateTime`
171
+ * `libs/TinyHtmlElems/Input/Month`
172
+ * `libs/TinyHtmlElems/Input/Time`
173
+ * `libs/TinyHtmlElems/Input/Week`
174
+
175
+ * **Number Inputs (BETA)** 🔢
176
+
177
+ * `libs/TinyHtmlElems/Input/Number`
178
+ * `libs/TinyHtmlElems/Input/Range`
179
+
180
+ * **Text Inputs (BETA)** ✏️
181
+
182
+ * `libs/TinyHtmlElems/Input/Email`
183
+ * `libs/TinyHtmlElems/Input/Password`
184
+ * `libs/TinyHtmlElems/Input/Search`
185
+ * `libs/TinyHtmlElems/Input/Tel`
186
+ * `libs/TinyHtmlElems/Input/Text`
187
+ * `libs/TinyHtmlElems/Input/Url`
118
188
 
119
189
  ---
120
190