tiny-essentials 1.19.3 โ†’ 1.20.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 (57) hide show
  1. package/dist/v1/TinyBasicsEs.min.js +1 -1
  2. package/dist/v1/TinyDragger.min.js +1 -1
  3. package/dist/v1/TinyEssentials.min.js +1 -1
  4. package/dist/v1/TinyHtml.min.js +1 -1
  5. package/dist/v1/TinyIframeEvents.min.js +1 -0
  6. package/dist/v1/TinyNewWinEvents.min.js +1 -0
  7. package/dist/v1/TinySmartScroller.min.js +1 -1
  8. package/dist/v1/TinyUploadClicker.min.js +1 -1
  9. package/dist/v1/build/TinyIframeEvents.cjs +7 -0
  10. package/dist/v1/build/TinyIframeEvents.d.mts +3 -0
  11. package/dist/v1/build/TinyIframeEvents.mjs +2 -0
  12. package/dist/v1/build/TinyNewWinEvents.cjs +7 -0
  13. package/dist/v1/build/TinyNewWinEvents.d.mts +3 -0
  14. package/dist/v1/build/TinyNewWinEvents.mjs +2 -0
  15. package/dist/v1/index.cjs +4 -0
  16. package/dist/v1/index.d.mts +3 -1
  17. package/dist/v1/index.mjs +3 -1
  18. package/dist/v1/libs/TinyDragger.cjs +1 -1
  19. package/dist/v1/libs/TinyDragger.mjs +1 -1
  20. package/dist/v1/libs/TinyHtml.cjs +292 -103
  21. package/dist/v1/libs/TinyHtml.d.mts +142 -39
  22. package/dist/v1/libs/TinyHtml.mjs +266 -94
  23. package/dist/v1/libs/TinyIframeEvents.cjs +410 -0
  24. package/dist/v1/libs/TinyIframeEvents.d.mts +193 -0
  25. package/dist/v1/libs/TinyIframeEvents.mjs +348 -0
  26. package/dist/v1/libs/TinyNewWinEvents.cjs +488 -0
  27. package/dist/v1/libs/TinyNewWinEvents.d.mts +241 -0
  28. package/dist/v1/libs/TinyNewWinEvents.mjs +437 -0
  29. package/docs/v1/README.md +2 -0
  30. package/docs/v1/libs/TinyHtml.md +128 -6
  31. package/docs/v1/libs/TinyIframeEvents.md +149 -0
  32. package/docs/v1/libs/TinyNewWinEvents.md +186 -0
  33. package/docs/v1/libs/TinyNotifyCenter.md +1 -1
  34. package/package.json +1 -1
  35. package/dist/v1/ColorSafeStringify.js +0 -235
  36. package/dist/v1/TinyAfterScrollWatcher.js +0 -219
  37. package/dist/v1/TinyBasicsEs.js +0 -9334
  38. package/dist/v1/TinyClipboard.js +0 -459
  39. package/dist/v1/TinyColorConverter.js +0 -617
  40. package/dist/v1/TinyDomReadyManager.js +0 -213
  41. package/dist/v1/TinyDragDropDetector.js +0 -307
  42. package/dist/v1/TinyDragger.js +0 -6569
  43. package/dist/v1/TinyEssentials.js +0 -19893
  44. package/dist/v1/TinyEvents.js +0 -402
  45. package/dist/v1/TinyHtml.js +0 -5545
  46. package/dist/v1/TinyLevelUp.js +0 -291
  47. package/dist/v1/TinyLocalStorage.js +0 -1440
  48. package/dist/v1/TinyNotifications.js +0 -408
  49. package/dist/v1/TinyNotifyCenter.js +0 -493
  50. package/dist/v1/TinyPromiseQueue.js +0 -299
  51. package/dist/v1/TinyRateLimiter.js +0 -611
  52. package/dist/v1/TinySmartScroller.js +0 -7039
  53. package/dist/v1/TinyTextRangeEditor.js +0 -497
  54. package/dist/v1/TinyTimeout.js +0 -233
  55. package/dist/v1/TinyToastNotify.js +0 -441
  56. package/dist/v1/TinyUploadClicker.js +0 -13456
  57. package/dist/v1/UltraRandomMsgGen.js +0 -995
@@ -310,6 +310,40 @@ HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement | HTMLOptionElement
310
310
 
311
311
  ---
312
312
 
313
+ ## ๐Ÿ”จ Element Creation
314
+
315
+ ### `TinyHtml.createFrom(tagName, attrs?)`
316
+
317
+ Creates a new `TinyHtml` element from a given tag name and optional attributes.
318
+
319
+ * **Parameters**:
320
+
321
+ * `tagName` *(string)* โ€” The HTML tag name (e.g., `'div'`, `'span'`, `'button'`).
322
+ * `attrs` *(object)* โ€” *(optional)* Key-value pairs representing HTML attributes.
323
+
324
+ * **Returns**: `TinyHtml` โ€” A new `TinyHtml` instance representing the created element.
325
+
326
+ * **Throws**:
327
+
328
+ * `TypeError` โ€” If `tagName` is not a string.
329
+ * `TypeError` โ€” If `attrs` is defined but not a plain object.
330
+
331
+ ### ๐Ÿ’ก Example
332
+
333
+ ```js
334
+ const div = TinyHtml.createFrom('div', { class: 'container' });
335
+ const span = TinyHtml.createFrom('span', { id: 'my-span', title: null });
336
+ ```
337
+
338
+ The method can also be aliased for convenience:
339
+
340
+ ```js
341
+ const createElement = TinyHtml.createFrom;
342
+ const button = createElement('button', { type: 'submit', class: 'btn' });
343
+ ```
344
+
345
+ ---
346
+
313
347
  ## ๐Ÿ”Ž Static DOM Selectors
314
348
 
315
349
  These methods wrap native DOM query methods and return results as `TinyHtml` instances for consistency.
@@ -377,7 +411,7 @@ Finds the first element by CSS selector.
377
411
  ### `TinyHtml.queryAll(selector)`
378
412
  Finds all elements by CSS selector.
379
413
 
380
- - **Returns**: `TinyHtml[]`
414
+ - **Returns**: `TinyHtml`
381
415
 
382
416
  ---
383
417
 
@@ -393,38 +427,64 @@ Selects an element by ID.
393
427
  ### `TinyHtml.getByClassName(selector)`
394
428
  Finds elements by class name.
395
429
 
396
- - **Returns**: `TinyHtml[]`
430
+ - **Returns**: `TinyHtml`
397
431
 
398
432
  ---
399
433
 
400
434
  ### `TinyHtml.getByName(selector)`
401
435
  Finds elements by `name` attribute.
402
436
 
403
- - **Returns**: `TinyHtml[]`
437
+ - **Returns**: `TinyHtml`
404
438
 
405
439
  ---
406
440
 
407
441
  ### `TinyHtml.getByTagNameNS(localName, namespaceURI?)`
408
442
  Finds elements by tag name in a namespace (defaults to XHTML).
409
443
 
410
- - **Returns**: `TinyHtml[]`
444
+ - **Returns**: `TinyHtml`
411
445
 
412
446
  ---
413
447
 
414
448
  ## ๐Ÿงฉ Internal Element Access
415
449
 
416
- ### `get()`
450
+ ### `exists(index)`
451
+ Checks whether the element exists at the given index.
452
+
453
+ - **Returns**: `boolean`
454
+
455
+ ---
456
+
457
+ ### `get(index)`
417
458
  Returns the raw DOM element associated with this instance.
418
459
 
419
460
  - **Returns**: `ConstructorElValues`
420
461
 
421
462
  ---
422
463
 
423
- ### `_getElement(where)`
464
+ ### `extract(index)`
465
+ Extracts a single DOM element from the internal list at the specified index.
466
+
467
+ - **Returns**: `TinyHtml`
468
+
469
+ ---
470
+
471
+ ### `getAll()`
472
+ Returns the current targets held by this instance.
473
+
474
+ - **Returns**: `ConstructorElValues[]`
475
+
476
+ ---
477
+
478
+ ### `_getElement(where, index)`
424
479
  Safely returns the element with error checking.
425
480
 
426
481
  ---
427
482
 
483
+ ### `_getElements(where)`
484
+ Returns the current Elements held by this instance.
485
+
486
+ ---
487
+
428
488
  ## ๐Ÿ› ๏ธ Static Pre-Validation Utilities
429
489
 
430
490
  These methods normalize, validate, and prepare elements/nodes before operations. They're internal and mainly used inside the class.
@@ -1719,6 +1779,68 @@ TinyHtml.hasScroll(element);
1719
1779
 
1720
1780
  ---
1721
1781
 
1782
+ ## ๐Ÿง  Property Name Normalization
1783
+
1784
+ The object `TinyHtml.propFix` maps HTML attribute names (as strings) to their corresponding JavaScript DOM property names. This works similarly to jQueryโ€™s `propFix`.
1785
+
1786
+ ```js
1787
+ TinyHtml.propFix['for']; // "htmlFor"
1788
+ TinyHtml.propFix['class']; // "className"
1789
+ ```
1790
+
1791
+ โš ๏ธ **Do not modify** the internal `#propFix` object directly. Instead, use `TinyHtml.propFix` (the public proxy) to ensure the reverse mapping in `TinyHtml.attrFix` stays in sync.
1792
+
1793
+ ### โœ๏ธ Adding a New Property Mapping
1794
+
1795
+ To add a new property normalization:
1796
+
1797
+ ```js
1798
+ TinyHtml.propFix['readonly'] = 'readOnly';
1799
+ ```
1800
+
1801
+ This will automatically make this available:
1802
+
1803
+ ```js
1804
+ TinyHtml.attrFix['readOnly']; // "readonly"
1805
+ ```
1806
+
1807
+ ---
1808
+
1809
+ ## ๐Ÿ” Attribute โ†” Property Mapping
1810
+
1811
+ ### ๐Ÿงญ `TinyHtml.getPropName(name)`
1812
+
1813
+ Normalizes an HTML attribute name to its corresponding DOM property name.
1814
+
1815
+ ```js
1816
+ TinyHtml.getPropName('for'); // "htmlFor"
1817
+ TinyHtml.getPropName('class'); // "className"
1818
+ TinyHtml.getPropName('title'); // "title" (not mapped, returns input)
1819
+ ```
1820
+
1821
+ Useful when setting DOM properties programmatically.
1822
+
1823
+ ### ๐Ÿงญ `TinyHtml.getAttrName(name)`
1824
+
1825
+ Converts a DOM property name back to its equivalent HTML attribute name.
1826
+
1827
+ ```js
1828
+ TinyHtml.getAttrName('htmlFor'); // "for"
1829
+ TinyHtml.getAttrName('className'); // "class"
1830
+ TinyHtml.getAttrName('title'); // "title" (not mapped, returns input)
1831
+ ```
1832
+
1833
+ Useful when serializing an element back to HTML or attributes.
1834
+
1835
+ ### ๐Ÿ”„ Behind the Scenes
1836
+
1837
+ * `TinyHtml.propFix` (public) is a proxy of the internal `#propFix` object.
1838
+ * `TinyHtml.attrFix` is auto-generated from `#propFix`, mapping values back in reverse.
1839
+
1840
+ These mappings are kept **in sync automatically** whenever you assign a new property to `TinyHtml.propFix`.
1841
+
1842
+ ---
1843
+
1722
1844
  ## ๐ŸŽจ CSS Property Aliases (`cssPropAliases`)
1723
1845
 
1724
1846
  TinyHtml provides automatic conversion between `camelCase` and `kebab-case` style properties to simplify working with inline styles in HTML elements.
@@ -0,0 +1,149 @@
1
+ # ๐Ÿงฉ TinyIframeEvents
2
+
3
+ A flexible event routing system for structured communication between a **parent window** and its **iframe** using postMessage.
4
+
5
+ This module abstracts the complexity of origin validation, window detection, and message direction. It allows **modular, bidirectional, and secure communication** across frames.
6
+
7
+ ---
8
+
9
+ ## โœจ Features
10
+
11
+ - ๐Ÿ” Bidirectional communication (`iframe` โ‡„ `parent`)
12
+ - ๐ŸŽฏ Named event routes with custom payloads
13
+ - ๐Ÿ” Target window and origin validation
14
+ - ๐Ÿง  Smart context detection (no config required inside iframe)
15
+ - ๐Ÿงน Clean-up support with `.destroy()`
16
+
17
+ ---
18
+
19
+ ## ๐Ÿš€ Usage
20
+
21
+ ### In the parent:
22
+
23
+ ```js
24
+ import TinyIframeEvents from './TinyIframeEvents.mjs';
25
+
26
+ const iframe = document.querySelector('iframe');
27
+
28
+ const parentEvents = new TinyIframeEvents({
29
+ targetIframe: iframe, // Will use iframe.contentWindow
30
+ targetOrigin: window.location.origin
31
+ });
32
+
33
+ parentEvents.emit('hello:iframe', { text: '๐Ÿ‘‹ From parent!' });
34
+
35
+ parentEvents.on('reply:fromIframe', (data, event) => {
36
+ console.log('๐Ÿ“จ Received from iframe:', data, event);
37
+ });
38
+ ```
39
+
40
+ ---
41
+
42
+ ### In the iframe:
43
+
44
+ ```js
45
+ import TinyIframeEvents from './TinyIframeEvents.mjs';
46
+
47
+ const iframeEvents = new TinyIframeEvents();
48
+
49
+ iframeEvents.on('hello:iframe', (data, event) => {
50
+ console.log('๐Ÿ“ฅ Message from parent:', event);
51
+ });
52
+
53
+ iframeEvents.emit('reply:fromIframe', { text: '๐Ÿ™‹โ€โ™€๏ธ Hi parent!' });
54
+ ```
55
+
56
+ ---
57
+
58
+ ## ๐Ÿง  API Reference
59
+
60
+ ### `new TinyIframeEvents(config?)`
61
+
62
+ Creates a new instance for communication.
63
+
64
+ #### Parameters:
65
+
66
+ | Name | Type | Description |
67
+ | -------------- | -------------------- | --------------------------------------------------------------------- |
68
+ | `targetIframe` | `HTMLIFrameElement?` | The iframe element to communicate with (used in the parent only). |
69
+ | `targetOrigin` | `string?` | Expected origin (for security). Defaults to `window.location.origin`. |
70
+
71
+ ---
72
+
73
+ ### `emit(eventName, payload)`
74
+
75
+ Sends a message to the target frame.
76
+
77
+ | Param | Type | Description |
78
+ | ----------- | -------- | ------------------------------------------ |
79
+ | `eventName` | `string` | Unique identifier of the event. |
80
+ | `payload` | `any` | The data to send (any serializable value). |
81
+
82
+ #### Throws:
83
+
84
+ * `TypeError` if `eventName` is not a string.
85
+
86
+ ---
87
+
88
+ ### `on(eventName, handler)`
89
+
90
+ Registers a listener for a specific event.
91
+
92
+ ```js
93
+ iframeEvents.on('my:event', (payload, event) => {
94
+ // event = { origin, source }
95
+ });
96
+ ```
97
+
98
+ ---
99
+
100
+ ### `destroy()`
101
+
102
+ Removes all listeners and message event binding.
103
+ Call this when the instance is no longer needed.
104
+
105
+ ```js
106
+ iframeEvents.destroy();
107
+ ```
108
+
109
+ ---
110
+
111
+ ### `isDestroyed()`
112
+
113
+ Returns `true` if the instance has been destroyed via `.destroy()`.
114
+
115
+ ```js
116
+ if (events.isDestroyed()) {
117
+ console.warn('Event system is no longer active.');
118
+ }
119
+ ```
120
+
121
+ ---
122
+
123
+ ## ๐Ÿ”’ Security Notes
124
+
125
+ * Only messages with the flag `__tinyEvent: true` are accepted.
126
+ * The source window is checked strictly (`source === targetWindow`).
127
+ * Messages are ignored unless their `direction` matches the current side (`iframe` or `parent`).
128
+
129
+ ---
130
+
131
+ ## ๐Ÿ“š Internals (for advanced users)
132
+
133
+ This class internally wraps:
134
+
135
+ * postMessage
136
+ * A minimal event router: `TinyEvents`
137
+
138
+ ---
139
+
140
+ ## ๐Ÿ“„ Type Definitions
141
+
142
+ ### `@callback handler`
143
+
144
+ ```ts
145
+ type handler = (
146
+ payload: any,
147
+ event: MessageEvent<any>
148
+ ) => void;
149
+ ```
@@ -0,0 +1,186 @@
1
+ # ๐ŸชŸ TinyNewWinEvents
2
+
3
+ Structured and reliable `postMessage`-based communication between a **main window** and a **popup window** (created using `window.open`).
4
+ Ideal for secure, bidirectional messaging with route-based logic.
5
+
6
+ ---
7
+
8
+ ## โœจ Features
9
+
10
+ * ๐Ÿ” Bidirectional communication (`main window` โ‡„ `popup`)
11
+ * ๐Ÿ“ฌ Named message routes with flexible payloads
12
+ * ๐Ÿ•“ Queues messages before handshake is ready
13
+ * ๐Ÿง  Connection and lifecycle status tracking
14
+ * ๐Ÿ”’ Origin and window reference validation
15
+ * ๐Ÿงน Full cleanup support with `.destroy()`
16
+
17
+ ---
18
+
19
+ ## ๐Ÿš€ Usage
20
+
21
+ ### In the main window:
22
+
23
+ ```js
24
+ import TinyNewWinEvents from './TinyNewWinEvents.mjs';
25
+
26
+ const events = new TinyNewWinEvents({
27
+ url: '/popup.html',
28
+ name: 'MyPopupWindow',
29
+ features: 'width=400,height=400',
30
+ targetOrigin: window.location.origin
31
+ });
32
+
33
+ events.on('user:reply', (payload) => {
34
+ console.log('๐Ÿ“ฉ From popup:', payload);
35
+ });
36
+
37
+ events.emit('init:data', { id: 123 });
38
+ ```
39
+
40
+ ---
41
+
42
+ ### In the popup window:
43
+
44
+ ```js
45
+ import TinyNewWinEvents from './TinyNewWinEvents.mjs';
46
+
47
+ const events = new TinyNewWinEvents();
48
+
49
+ events.on('init:data', (payload) => {
50
+ console.log('๐Ÿ“ฆ Init payload from main window:', payload);
51
+ });
52
+
53
+ events.emit('user:reply', { msg: '๐Ÿ‘‹ Hello from popup!' });
54
+ ```
55
+
56
+ ---
57
+
58
+ ## ๐Ÿง  API Reference
59
+
60
+ ### `new TinyNewWinEvents(config?)`
61
+
62
+ Creates a new communication instance.
63
+
64
+ #### Parameters:
65
+
66
+ | Name | Type | Description |
67
+ | -------------- | ------------------------ | -------------------------------------------------- |
68
+ | `url` | `string?` | URL to open in popup. |
69
+ | `name` | `string?` | Name of the popup window . |
70
+ | `features` | `string?` | `window.open` features string. |
71
+ | `targetOrigin` | `string?` | Expected origin (defaults to current origin) |
72
+
73
+ โ— `name: '_blank'` is **not allowed** for popup tracking.
74
+
75
+ ---
76
+
77
+ ### `emit(route, payload)`
78
+
79
+ Sends a message on a specific route.
80
+
81
+ | Param | Type | Description |
82
+ | --------- | -------- | ------------------------------- |
83
+ | `route` | `string` | Event route name |
84
+ | `payload` | `any` | Data to send (any serializable) |
85
+
86
+ ๐Ÿ“ If the handshake hasn't completed yet, the message is **queued**.
87
+
88
+ ---
89
+
90
+ ### `on(route, handler)`
91
+
92
+ Registers a callback for a specific route.
93
+
94
+ ```js
95
+ events.on('data:sync', (payload, event) => {
96
+ console.log(payload, event.origin);
97
+ });
98
+ ```
99
+
100
+ ---
101
+
102
+ ### `off(route, handler)`
103
+
104
+ Removes a previously registered route listener.
105
+
106
+ ---
107
+
108
+ ### `onClose(callback)`
109
+
110
+ Runs when the **popup window** is closed.
111
+
112
+ ---
113
+
114
+ ### `offClose(callback)`
115
+
116
+ Removes a previously registered close callback.
117
+
118
+ ---
119
+
120
+ ### `close()`
121
+
122
+ Closes the popup window (can only be called from the host).
123
+
124
+ ---
125
+
126
+ ### `getWin()`
127
+
128
+ Returns the current window reference (host or popup).
129
+
130
+ ---
131
+
132
+ ### `isConnected()`
133
+
134
+ Returns `true` if both:
135
+
136
+ * Handshake is complete
137
+ * Window is still open
138
+
139
+ ---
140
+
141
+ ### `isDestroyed()`
142
+
143
+ Returns `true` if the instance has been destroyed.
144
+
145
+ ---
146
+
147
+ ### `destroy()`
148
+
149
+ Destroys the instance, cleans up all resources:
150
+
151
+ * Stops polling
152
+ * Removes all listeners
153
+ * Clears queue
154
+
155
+ ---
156
+
157
+ ## ๐Ÿ“ฆ Internals (for advanced use)
158
+
159
+ | Concept | Purpose |
160
+ | --------------- | ------------------------------------------- |
161
+ | `postMessage` | Core transport for messaging |
162
+ | `TinyEvents` | Internal event emitter and listener manager |
163
+ | `__TNE_READY__` | Handshake trigger message type |
164
+ | `__TNE_ROUTE__` | Route-based message delivery type |
165
+
166
+ ---
167
+
168
+ ## ๐Ÿ“„ Type Definitions
169
+
170
+ ### `@callback handler`
171
+
172
+ ```ts
173
+ type handler = (
174
+ payload: any,
175
+ event: MessageEvent<any>
176
+ ) => void;
177
+ ```
178
+
179
+ ---
180
+
181
+ ## ๐Ÿ›ก๏ธ Safety and Validation
182
+
183
+ * ๐Ÿ’ฅ Throws if `emit()` is called after `.destroy()`
184
+ * ๐Ÿ’ฃ Throws if the popup was opened with `_blank` name
185
+ * โœ… Only communicates with expected `targetOrigin`
186
+ * ๐Ÿงผ Automatically detects closed windows and emits `WINDOW_REF_CLOSED`
@@ -80,7 +80,7 @@ TinyNotifyCenter.insertTemplate();
80
80
 
81
81
  // Or insert at the end of <body>
82
82
  TinyNotifyCenter.insertTemplate('beforeend');
83
- ````
83
+ ```
84
84
 
85
85
  ---
86
86
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tiny-essentials",
3
- "version": "1.19.3",
3
+ "version": "1.20.1",
4
4
  "description": "Collection of small, essential scripts designed to be used across various projects. These simple utilities are crafted for speed, ease of use, and versatility.",
5
5
  "scripts": {
6
6
  "test": "npm run test:mjs && npm run test:cjs && npm run test:js",