tiny-essentials 1.21.10 → 1.22.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 (40) hide show
  1. package/.vscode/extensions.json +30 -0
  2. package/.vscode/settings.json +53 -0
  3. package/LICENSE +160 -669
  4. package/dist/v1/TinyBasicsEs.min.js +1 -1
  5. package/dist/v1/TinyDragger.min.js +1 -1
  6. package/dist/v1/TinyElementObserver.min.js +1 -0
  7. package/dist/v1/TinyEssentials.min.js +1 -1
  8. package/dist/v1/TinyHtml.min.js +1 -1
  9. package/dist/v1/TinySmartScroller.min.js +1 -1
  10. package/dist/v1/TinyUploadClicker.min.js +1 -1
  11. package/dist/v1/basics/array.cjs +12 -0
  12. package/dist/v1/basics/array.d.mts +9 -0
  13. package/dist/v1/basics/array.mjs +10 -0
  14. package/dist/v1/basics/index.cjs +2 -0
  15. package/dist/v1/basics/index.d.mts +3 -1
  16. package/dist/v1/basics/index.mjs +3 -3
  17. package/dist/v1/basics/text.cjs +44 -9
  18. package/dist/v1/basics/text.d.mts +14 -2
  19. package/dist/v1/basics/text.mjs +38 -9
  20. package/dist/v1/build/TinyElementObserver.cjs +7 -0
  21. package/dist/v1/build/TinyElementObserver.d.mts +3 -0
  22. package/dist/v1/build/TinyElementObserver.mjs +2 -0
  23. package/dist/v1/index.cjs +4 -0
  24. package/dist/v1/index.d.mts +4 -1
  25. package/dist/v1/index.mjs +4 -3
  26. package/dist/v1/libs/TinyElementObserver.cjs +292 -0
  27. package/dist/v1/libs/TinyElementObserver.d.mts +154 -0
  28. package/dist/v1/libs/TinyElementObserver.mjs +266 -0
  29. package/dist/v1/libs/TinyGamepad.d.mts +1 -1
  30. package/dist/v1/libs/TinyHtml.cjs +1418 -131
  31. package/dist/v1/libs/TinyHtml.d.mts +513 -12
  32. package/dist/v1/libs/TinyHtml.mjs +1129 -14
  33. package/dist/v1/libs/TinyInventory.d.mts +1 -1
  34. package/dist/v1/libs/UltraRandomMsgGen.d.mts +7 -7
  35. package/docs/v1/README.md +1 -0
  36. package/docs/v1/basics/array.md +20 -0
  37. package/docs/v1/basics/text.md +38 -7
  38. package/docs/v1/libs/TinyElementObserver.md +107 -0
  39. package/docs/v1/libs/TinyHtml.md +797 -3
  40. package/package.json +2 -2
@@ -328,7 +328,7 @@ declare class TinyInventory {
328
328
  * Keys are item IDs, values are configuration objects created with {@link TinyInventory.defineItem}.
329
329
  * @type {Map<string, ItemDef>}
330
330
  */
331
- static "__#27@#ItemRegistry": Map<string, ItemDef>;
331
+ static "__#28@#ItemRegistry": Map<string, ItemDef>;
332
332
  /**
333
333
  * Returns a deep-cloned snapshot of all registered items.
334
334
  * Ensures the caller cannot mutate the internal registry.
@@ -160,23 +160,23 @@ export type MsgGenConfig = {
160
160
  */
161
161
  declare class UltraRandomMsgGen {
162
162
  /** @type {string[]} */
163
- static "__#12@#defaultWords": string[];
163
+ static "__#13@#defaultWords": string[];
164
164
  /** @type {string[]} */
165
- static "__#12@#defaultEmojis": string[];
165
+ static "__#13@#defaultEmojis": string[];
166
166
  /** @type {string[]} */
167
- static "__#12@#defaultNouns": string[];
167
+ static "__#13@#defaultNouns": string[];
168
168
  /** @type {string[]} */
169
- static "__#12@#defaultVerbs": string[];
169
+ static "__#13@#defaultVerbs": string[];
170
170
  /** @type {string[]} */
171
- static "__#12@#defaultAdjectives": string[];
171
+ static "__#13@#defaultAdjectives": string[];
172
172
  /** @type {string[]} */
173
- static "__#12@#defaultTemplates": string[];
173
+ static "__#13@#defaultTemplates": string[];
174
174
  /**
175
175
  * Utility to validate arrays before setting.
176
176
  * @param {any} value
177
177
  * @param {string} field
178
178
  */
179
- static "__#12@#validateArray"(value: any, field: string): void;
179
+ static "__#13@#validateArray"(value: any, field: string): void;
180
180
  /** @param {string[]} value */
181
181
  static set defaultWords(value: string[]);
182
182
  /** @returns {string[]} */
package/docs/v1/README.md CHANGED
@@ -57,6 +57,7 @@ This folder contains the core scripts we have worked on so far. Each file is a m
57
57
  - 🌐 **[TinyI18](./libs/TinyI18.md)** — A flexible i18n manager supporting local and file modes, regex-based keys, function-based entries, string interpolation, and safe helper functions for advanced rendering.
58
58
  - 🎮 **[TinyNeedBar](./libs/TinyNeedBar.md)** — A versatile "need bar" system for simulating decay over time with multiple configurable factors, serialization, cloning, and full control over clamped and infinite values.
59
59
  - 🎲 **[TinySimpleDice](./libs/TinySimpleDice.md)** — A lightweight and flexible dice rolling utility with configurable maximum values, zero allowance, and array/Set index rolling support.
60
+ - 👀 **[TinyElementObserver](./libs/TinyElementObserver.md)** — A DOM mutation tracking utility built on MutationObserver, with customizable detectors for handling changes, event dispatching, and lifecycle management.
60
61
 
61
62
  ### 3. **`fileManager/`**
62
63
  * 📁 **[Main](./fileManager/main.md)** — A Node.js file/directory utility module with support for JSON, backups, renaming, size analysis, and more.
@@ -95,3 +95,23 @@ Generates a flattened array with phases repeated according to the specified coun
95
95
  multiplyArrayBlocks(['Full', 'Half1', 'Half2', 'New'], [4, 5, 5, 4]);
96
96
  // ➡ ['Full','Full','Full','Full','Half1','Half1','Half1','Half1','Half1', ...]
97
97
  ```
98
+
99
+ ---
100
+
101
+ ## 🔀 `diffArrayList(oldItems, newItems)`
102
+
103
+ Compares two arrays and determines which items were **added** and which were **removed**.
104
+
105
+ * **`oldItems`** 📜 — Array of original class names.
106
+ * **`newItems`** 📜 — Array of updated class names.
107
+ * **Returns** 📦 — An object with two arrays:
108
+
109
+ * `added` → classes that exist in `newItems` but not in `oldItems`.
110
+ * `removed` → classes that exist in `oldItems` but not in `newItems`.
111
+
112
+ **Example:**
113
+
114
+ ```js
115
+ diffArrayList(['btn', 'active'], ['btn', 'disabled']);
116
+ // ➡ { added: ['disabled'], removed: ['active'] }
117
+ ```
@@ -39,21 +39,23 @@ toTitleCaseLowerFirst('hello world'); // → "hello World"
39
39
 
40
40
  ---
41
41
 
42
- ## 🎯 `addAiMarkerShortcut(key = 'a')`
42
+ ## 🎯 `addAiMarkerShortcut({ key = 'a', className = 'detect-made-by-ai' })`
43
43
 
44
- Enables a keyboard shortcut (`Ctrl + Alt + [key]`) that toggles a CSS class on the `<body>` element. Useful for marking or highlighting AI-generated content dynamically.
44
+ Enables a keyboard shortcut (`Ctrl + Alt + [key]`) that toggles a CSS class on the `<body>` element.
45
+ Useful for marking or highlighting AI-generated content dynamically.
45
46
 
46
47
  ### 🔤 Syntax
47
48
 
48
- ```js
49
- addAiMarkerShortcut(key)
49
+ ```ts
50
+ addAiMarkerShortcut({ key, className }) : function
50
51
  ```
51
52
 
52
53
  ### 🧾 Parameters
53
54
 
54
- | Name | Type | Default | Description |
55
- | ----- | -------- | ------- | ---------------------------------------------------------------------------- |
56
- | `key` | `string` | `'a'` | The character key to use in combination with `Ctrl + Alt`. Case-insensitive. |
55
+ | Name | Type | Default | Description |
56
+ | ----------- | -------- | --------------------- | ---------------------------------------------------------------------------- |
57
+ | `key` | `string` | `'a'` | The character key to use in combination with `Ctrl + Alt`. Case-insensitive. |
58
+ | `className` | `string` | `'detect-made-by-ai'` | The CSS class name to toggle on the `<body>` element. |
57
59
 
58
60
  ### ⚙️ Behavior
59
61
 
@@ -157,3 +159,32 @@ const longText = "This is a sample sentence that will be trimmed properly.";
157
159
  console.log(safeTextTrim(longText, 30));
158
160
  // Output: "This is a sample sentence that..."
159
161
  ```
162
+
163
+ ---
164
+
165
+ ## 🔎 `diffStrings(oldStrings, newStrings)`
166
+
167
+ Compares two **style objects** and identifies which properties were **added**, **removed**, or **modified**.
168
+
169
+ * **`oldStrings`** 🎨 — Record of string values (original state).
170
+ * **`newStrings`** 🎨 — Record of string values (new state).
171
+ * **Returns** 📦 — An object with three sub-objects:
172
+
173
+ * `added` → new properties not present before.
174
+ * `removed` → properties that no longer exist.
175
+ * `modified` → properties whose values have changed (with `old` and `new`).
176
+
177
+ **Example:**
178
+
179
+ ```js
180
+ diffStrings(
181
+ { color: 'red', display: 'block' },
182
+ { color: 'blue', visibility: 'hidden' }
183
+ );
184
+
185
+ // ➡ {
186
+ // added: { visibility: 'hidden' },
187
+ // removed: { display: 'block' },
188
+ // modified: { color: { old: 'red', new: 'blue' } }
189
+ // }
190
+ ```
@@ -0,0 +1,107 @@
1
+ # 📌 TinyElementObserver
2
+
3
+ A utility class for tracking **DOM element mutations** 🧬.
4
+ It leverages the native `MutationObserver` API, providing a higher-level abstraction with a configurable **detector system** ⚙️ that can dispatch custom events or run custom logic.
5
+
6
+ ---
7
+
8
+ ## 🔹 Callback Type
9
+
10
+ ### `ElementDetectorsFn`
11
+
12
+ ```ts
13
+ type ElementDetectorsFn = (
14
+ mutation: MutationRecord, // Single mutation being processed
15
+ index: number, // Index of the mutation in the batch
16
+ mutations: MutationRecord[] // Full list of mutation records
17
+ ) => void;
18
+ ```
19
+
20
+ ---
21
+
22
+ ## 🔹 Constructor
23
+
24
+ ```ts
25
+ new TinyElementObserver({
26
+ el?: Element,
27
+ initDetectors?: Array<[string, ElementDetectorsFn]>,
28
+ initCfg?: MutationObserverInit
29
+ })
30
+ ```
31
+
32
+ * **`el`** *(optional)* → Initial element to observe 🏷️
33
+ * **`initDetectors`** *(optional)* → Array of detectors to register on creation 🎛️
34
+ * **`initCfg`** *(optional)* → Initial `MutationObserverInit` configuration ⚙️
35
+
36
+ ---
37
+
38
+ ## 🔹 Properties
39
+
40
+ | Property | Type | Description |
41
+ | ----------- | ------------------------------------- | --------------------------------------------------------- |
42
+ | `el` | `Element \| undefined` | The DOM element being observed. Can only be set once. 🏗️ |
43
+ | `settings` | `MutationObserverInit` | Observer configuration object. 🔧 |
44
+ | `observer` | `MutationObserver \| null` | Internal observer instance. |
45
+ | `detectors` | `Array<[string, ElementDetectorsFn]>` | List of registered detectors. |
46
+ | `isActive` | `boolean` | `true` if the observer is running. 🚦 |
47
+ | `size` | `number` | Total number of registered detectors. 📊 |
48
+
49
+ ---
50
+
51
+ ## 🔹 Methods
52
+
53
+ ### 🎛️ Detector Management
54
+
55
+ * **`add(name, handler)`** → Add detector at the end of the list.
56
+ * **`insertAtStart(name, handler)`** → Add detector at the start of the list.
57
+ * **`insertAt(index, name, handler, position = "after")`** → Insert detector before or after a given index.
58
+ * **`removeAt(index)`** → Remove detector at index.
59
+ * **`removeAround(index, before = 0, after = 0)`** → Remove detectors around an index.
60
+ * **`isIndexUsed(index)`** → Check if an index has a detector.
61
+ * **`hasHandler(handler)`** → Check if a handler already exists.
62
+ * **`clear()`** → Remove all detectors.
63
+
64
+ ---
65
+
66
+ ### 📡 Observation Control
67
+
68
+ * **`start()`** → Begin tracking mutations on the defined element.
69
+ ⚠️ Throws if no element is set.
70
+
71
+ * **`stop()`** → Stop tracking mutations.
72
+
73
+ * **`destroy()`** → Stop observer and clear all detectors. Leaves the instance unusable until reconfigured. 💀
74
+
75
+ ---
76
+
77
+ ## 🔹 Example Usage
78
+
79
+ ```js
80
+ import TinyElementObserver from './TinyElementObserver.js';
81
+
82
+ // Define a detector
83
+ const logDetector = (mutation, index, mutations) => {
84
+ console.log(`🔍 Mutation detected [${index + 1}/${mutations.length}]:`, mutation);
85
+ };
86
+
87
+ // Create instance
88
+ const observer = new TinyElementObserver({
89
+ el: document.querySelector('#target'),
90
+ initDetectors: [['logger', logDetector]],
91
+ initCfg: { childList: true, subtree: true }
92
+ });
93
+
94
+ // Start observing
95
+ observer.start();
96
+
97
+ // Add another detector
98
+ observer.add('attrChange', (mutation) => {
99
+ if (mutation.type === 'attributes') {
100
+ console.log(`⚡ Attribute changed: ${mutation.attributeName}`);
101
+ }
102
+ });
103
+ ```
104
+
105
+ ---
106
+
107
+ ✨ With **TinyElementObserver**, you can easily manage multiple detectors, control observation lifecycle, and create powerful mutation-driven logic with minimal boilerplate.