tiny-essentials 1.10.2 → 1.12.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 (106) hide show
  1. package/README.md +13 -4
  2. package/dist/node_modules/firebase-functions/lib/common/trace.cjs +82 -0
  3. package/dist/node_modules/firebase-functions/lib/logger/common.cjs +57 -0
  4. package/dist/node_modules/firebase-functions/lib/logger/index.cjs +158 -0
  5. package/dist/{TinyEssentials.js → v1/TinyBasicsEs.js} +1726 -1362
  6. package/dist/v1/TinyBasicsEs.min.js +2 -0
  7. package/dist/v1/TinyDragDropDetector.js +307 -0
  8. package/dist/v1/TinyDragDropDetector.min.js +1 -0
  9. package/dist/{TinyBasicsEs.js → v1/TinyDragger.js} +1004 -506
  10. package/dist/v1/TinyDragger.min.js +2 -0
  11. package/dist/v1/TinyEssentials.js +7938 -0
  12. package/dist/v1/TinyEssentials.min.js +2 -0
  13. package/dist/v1/TinyEssentials.min.js.LICENSE.txt +8 -0
  14. package/dist/v1/TinyNotifyCenter.js +493 -0
  15. package/dist/v1/TinyNotifyCenter.min.js +1 -0
  16. package/dist/v1/TinyToastNotify.js +441 -0
  17. package/dist/v1/TinyToastNotify.min.js +1 -0
  18. package/dist/v1/TinyUploadClicker.js +5235 -0
  19. package/dist/v1/TinyUploadClicker.min.js +2 -0
  20. package/dist/v1/TinyUploadClicker.min.js.LICENSE.txt +8 -0
  21. package/dist/v1/basics/fileManager.cjs +524 -0
  22. package/dist/v1/basics/fileManager.d.mts +209 -0
  23. package/dist/v1/basics/fileManager.mjs +443 -0
  24. package/dist/v1/basics/fullScreen.cjs +134 -0
  25. package/dist/v1/basics/fullScreen.d.mts +8 -0
  26. package/dist/v1/basics/fullScreen.mjs +121 -0
  27. package/dist/v1/basics/html.cjs +262 -0
  28. package/dist/v1/basics/html.d.mts +63 -0
  29. package/dist/v1/basics/html.mjs +208 -0
  30. package/dist/v1/basics/index.cjs +40 -0
  31. package/dist/v1/basics/index.d.mts +38 -1
  32. package/dist/v1/basics/index.mjs +4 -1
  33. package/dist/v1/build/TinyDragDropDetector.cjs +7 -0
  34. package/dist/v1/build/TinyDragDropDetector.d.mts +3 -0
  35. package/dist/v1/build/TinyDragDropDetector.mjs +2 -0
  36. package/dist/v1/build/TinyDragger.cjs +7 -0
  37. package/dist/v1/build/TinyDragger.d.mts +3 -0
  38. package/dist/v1/build/TinyDragger.mjs +2 -0
  39. package/dist/v1/build/TinyNotifyCenter.cjs +7 -0
  40. package/dist/v1/build/TinyNotifyCenter.d.mts +3 -0
  41. package/dist/v1/build/TinyNotifyCenter.mjs +2 -0
  42. package/dist/v1/build/TinyToastNotify.cjs +7 -0
  43. package/dist/v1/build/TinyToastNotify.d.mts +3 -0
  44. package/dist/v1/build/TinyToastNotify.mjs +2 -0
  45. package/dist/v1/build/TinyUploadClicker.cjs +7 -0
  46. package/dist/v1/build/TinyUploadClicker.d.mts +3 -0
  47. package/dist/v1/build/TinyUploadClicker.mjs +2 -0
  48. package/dist/v1/css/TinyDraggerExample.css +21 -0
  49. package/dist/v1/css/TinyDraggerExample.min.css +1 -0
  50. package/dist/v1/css/TinyNotify.css +350 -0
  51. package/dist/v1/css/TinyNotify.min.css +1 -0
  52. package/dist/v1/index.cjs +48 -0
  53. package/dist/v1/index.d.mts +42 -1
  54. package/dist/v1/index.mjs +8 -1
  55. package/dist/v1/libs/TinyDragDropDetector.cjs +268 -0
  56. package/dist/v1/libs/TinyDragDropDetector.d.mts +123 -0
  57. package/dist/v1/libs/TinyDragDropDetector.mjs +228 -0
  58. package/dist/v1/libs/TinyDragger.cjs +801 -0
  59. package/dist/v1/libs/TinyDragger.d.mts +300 -0
  60. package/dist/v1/libs/TinyDragger.mjs +689 -0
  61. package/dist/v1/libs/TinyNotifyCenter.cjs +454 -0
  62. package/dist/v1/libs/TinyNotifyCenter.d.mts +175 -0
  63. package/dist/v1/libs/TinyNotifyCenter.mjs +413 -0
  64. package/dist/v1/libs/TinyToastNotify.cjs +402 -0
  65. package/dist/v1/libs/TinyToastNotify.d.mts +165 -0
  66. package/dist/v1/libs/TinyToastNotify.mjs +352 -0
  67. package/dist/v1/libs/TinyUploadClicker.cjs +223 -0
  68. package/dist/v1/libs/TinyUploadClicker.d.mts +80 -0
  69. package/dist/v1/libs/TinyUploadClicker.mjs +182 -0
  70. package/docs/{README.md → v1/README.md} +8 -0
  71. package/docs/v1/basics/fileManager.md +222 -0
  72. package/docs/v1/basics/fullScreen.md +183 -0
  73. package/docs/v1/basics/html.md +243 -0
  74. package/docs/{basics → v1/basics}/text.md +2 -2
  75. package/docs/v1/libs/TinyDragDropDetector.md +143 -0
  76. package/docs/v1/libs/TinyDragger.md +415 -0
  77. package/docs/{libs → v1/libs}/TinyLevelUp.md +1 -1
  78. package/docs/v1/libs/TinyNotifyCenter.md +311 -0
  79. package/docs/v1/libs/TinyToastNotify.md +309 -0
  80. package/docs/v1/libs/TinyUploadClicker.md +108 -0
  81. package/package.json +14 -2
  82. package/dist/TinyBasicsEs.min.js +0 -2
  83. package/dist/TinyEssentials.min.js +0 -2
  84. package/dist/v1/libs/TinyRateLimit.cjs +0 -196
  85. package/dist/v1/libs/TinyRateLimit.d.mts +0 -86
  86. package/dist/v1/libs/TinyRateLimit.mjs +0 -171
  87. /package/dist/{ColorSafeStringify.js → v1/ColorSafeStringify.js} +0 -0
  88. /package/dist/{ColorSafeStringify.min.js → v1/ColorSafeStringify.min.js} +0 -0
  89. /package/dist/{TinyBasicsEs.min.js.LICENSE.txt → v1/TinyBasicsEs.min.js.LICENSE.txt} +0 -0
  90. /package/dist/{TinyEssentials.min.js.LICENSE.txt → v1/TinyDragger.min.js.LICENSE.txt} +0 -0
  91. /package/dist/{TinyLevelUp.js → v1/TinyLevelUp.js} +0 -0
  92. /package/dist/{TinyLevelUp.min.js → v1/TinyLevelUp.min.js} +0 -0
  93. /package/dist/{TinyPromiseQueue.js → v1/TinyPromiseQueue.js} +0 -0
  94. /package/dist/{TinyPromiseQueue.min.js → v1/TinyPromiseQueue.min.js} +0 -0
  95. /package/dist/{TinyRateLimiter.js → v1/TinyRateLimiter.js} +0 -0
  96. /package/dist/{TinyRateLimiter.min.js → v1/TinyRateLimiter.min.js} +0 -0
  97. /package/dist/{aiMarker.css → v1/css/aiMarker.css} +0 -0
  98. /package/dist/{aiMarker.min.css → v1/css/aiMarker.min.css} +0 -0
  99. /package/docs/{basics → v1/basics}/array.md +0 -0
  100. /package/docs/{basics → v1/basics}/asyncReplace.md +0 -0
  101. /package/docs/{basics → v1/basics}/clock.md +0 -0
  102. /package/docs/{basics → v1/basics}/objFilter.md +0 -0
  103. /package/docs/{basics → v1/basics}/simpleMath.md +0 -0
  104. /package/docs/{libs → v1/libs}/ColorSafeStringify.md +0 -0
  105. /package/docs/{libs → v1/libs}/TinyPromiseQueue.md +0 -0
  106. /package/docs/{libs → v1/libs}/TinyRateLimiter.md +0 -0
@@ -0,0 +1,243 @@
1
+ ## 🚀 `areHtmlElsColliding()`
2
+
3
+ Check if two DOM elements are **colliding on the screen**! Perfect for games, draggable elements, UI interactions, and more.
4
+
5
+ This function checks whether **two HTML elements are overlapping** (colliding) within the viewport. It uses their bounding boxes (`getBoundingClientRect()`) to perform a simple AABB (Axis-Aligned Bounding Box) collision detection.
6
+
7
+ Combine it with `mousemove`, `drag`, or animation listeners for dynamic collision detection in real-time!
8
+
9
+ It compares the bounding rectangles of both elements:
10
+
11
+ * ✅ Checks if **rect1** is NOT entirely to the left, right, above, or below **rect2**.
12
+ * ✅ If none of these are true, then the elements are overlapping.
13
+
14
+ ---
15
+
16
+ ## 🧠 Syntax
17
+
18
+ ```javascript
19
+ areHtmlElsColliding(elem1, elem2);
20
+ ```
21
+
22
+ ---
23
+
24
+ ## 🎯 Parameters
25
+
26
+ | Parameter | Type | Description |
27
+ | --------- | --------- | ----------------------- |
28
+ | `elem1` | `Element` | The first DOM element. |
29
+ | `elem2` | `Element` | The second DOM element. |
30
+
31
+ ---
32
+
33
+ ## 🔁 Return
34
+
35
+ | Type | Description |
36
+ | --------- | ------------------------------------------------------------------ |
37
+ | `boolean` | ✅ `true` if elements are colliding. <br>❌ `false` if they are not. |
38
+
39
+ ---
40
+
41
+ ## 📦 Example
42
+
43
+ ```javascript
44
+ const box1 = document.getElementById('box1');
45
+ const box2 = document.getElementById('box2');
46
+
47
+ if (areHtmlElsColliding(box1, box2)) {
48
+ console.log('🎯 Collision detected!');
49
+ } else {
50
+ console.log('❌ No collision.');
51
+ }
52
+ ```
53
+
54
+ ---
55
+
56
+ ## 🚧 Limitations
57
+
58
+ * Only works with **axis-aligned elements** (rectangular shapes).
59
+ * Does not handle rotated elements or complex shapes.
60
+
61
+ ---
62
+
63
+ ## 📖 `readJsonBlob(file: File): Promise<any>`
64
+
65
+ Reads and parses a JSON file using the [`FileReader`](https://developer.mozilla.org/en-US/docs/Web/API/FileReader) API.
66
+
67
+ ### 📥 Parameters
68
+
69
+ * `file` *(File)*: The file object selected by the user (e.g., from an `<input type="file">` element).
70
+
71
+ ### 📤 Returns
72
+
73
+ * `Promise<any>`: Resolves with the parsed JSON object, or rejects with an error if the content is invalid.
74
+
75
+ ### ⚠️ Throws
76
+
77
+ * An error if the content is not valid JSON.
78
+ * An error if the file can't be read.
79
+
80
+ ### 🧪 Example
81
+
82
+ ```js
83
+ const input = document.querySelector('input[type="file"]');
84
+ input.addEventListener('change', async () => {
85
+ try {
86
+ const result = await readJsonBlob(input.files[0]);
87
+ console.log(result);
88
+ } catch (err) {
89
+ alert(err.message);
90
+ }
91
+ });
92
+ ```
93
+
94
+ ---
95
+
96
+ ## 💾 `saveJsonFile(filename: string, data: any, spaces: number = 2): void`
97
+
98
+ Converts a JavaScript object to JSON and triggers a download in the browser.
99
+
100
+ ### 📥 Parameters
101
+
102
+ * `filename` *(string)*: The name of the file to save (e.g., `"data.json"`).
103
+ * `data` *(any)*: The JavaScript object to convert to JSON.
104
+ * `spaces` *(number)* *(optional)*: Indentation level for formatting the JSON string. Default is `2`.
105
+
106
+ ### 📤 Returns
107
+
108
+ * `void`
109
+
110
+ ### 📂 Behavior
111
+
112
+ Creates a temporary `<a>` element, downloads the file, and cleans up the URL.
113
+
114
+ ### 🧪 Example
115
+
116
+ ```js
117
+ const data = { name: 'Yasmin', type: 'dev' };
118
+ saveJsonFile('yasmin.json', data);
119
+ ```
120
+
121
+ ## 🌐 `fetchJson(url, options?): Promise<any>`
122
+
123
+ Loads and parses a JSON from a remote URL using the Fetch API, with support for custom HTTP methods, retries, timeouts, headers, and even external abort controllers.
124
+
125
+ ### 📥 Parameters
126
+
127
+ * `url` *(string)*: The full URL to fetch JSON from (must start with `http://`, `https://`, `/`, `./`, or `../`).
128
+ * `options` *(object)* *(optional)*:
129
+
130
+ * `signal` *(`AbortSignal` | `null`)*: Custom abort signal.
131
+ * `method` *(string)*: The HTTP method to use (e.g., `GET`, `POST`, `PUT`, `DELETE`, etc.).
132
+ * `timeout` *(number)*: Request timeout in milliseconds. Default is `0` (no timeout).
133
+ * `retries` *(number)*: Number of retry attempts if the request fails. Default is `0`.
134
+ * `headers` *(object)*: Additional headers to include in the request.
135
+ * `body` *(object)*: Request body. If the value is a plain object, it will be automatically stringified as JSON.
136
+
137
+ #### `signal` (`AbortSignal` | `null`) — *optional*
138
+
139
+ Custom abort signal. If set:
140
+
141
+ * The internal timeout mechanism is **disabled**
142
+ * Retry logic is **disabled**
143
+ * Abortion is handled externally
144
+
145
+ ### 📤 Returns
146
+
147
+ * `Promise<any>`: Resolves with the parsed JSON data.
148
+
149
+ ### ⚠️ Throws
150
+
151
+ * `Error` if the fetch fails or exceeds the timeout
152
+ * `Error` if the response is not `application/json`
153
+ * `Error` if the result is not a plain JSON object
154
+
155
+ ## 🧠 Tip
156
+
157
+ If you pass your own `signal`, this disables both `timeout` and `retries`. Use it when you're managing cancellation manually (e.g. in UI components or async workflows).
158
+
159
+ ### 🧪 Example
160
+
161
+ ```js
162
+ const controller = new AbortController();
163
+
164
+ const data = await fetchJson('https://api.example.com/data', {
165
+ method: 'POST',
166
+ body: { name: 'Yasmin' },
167
+ headers: {
168
+ 'Content-Type': 'application/json'
169
+ },
170
+ timeout: 5000,
171
+ retries: 2,
172
+ signal: controller.signal, // optional
173
+ });
174
+ ```
175
+
176
+ ---
177
+
178
+ ### 📦 `HtmlElBoxSides` Type
179
+
180
+ ```ts
181
+ type HtmlElBoxSides = {
182
+ x: number; // Total horizontal size (left + right)
183
+ y: number; // Total vertical size (top + bottom)
184
+ left: number;
185
+ right: number;
186
+ top: number;
187
+ bottom: number;
188
+ }
189
+ ```
190
+
191
+ A common return format used to describe the box model dimensions (borders, padding, margin) of an HTML element.
192
+
193
+ ---
194
+
195
+ ### 🔲 `getHtmlElBordersWidth(el)`
196
+
197
+ 📏 Returns the total **border width** of an element using `border{Side}Width` values from computed styles.
198
+
199
+ ```js
200
+ getHtmlElBordersWidth(el: Element): HtmlElBoxSides
201
+ ```
202
+
203
+ * `el`: The target DOM element.
204
+ * **Returns**: An object containing total horizontal/vertical border widths, and each side individually.
205
+
206
+ ---
207
+
208
+ ### 🔳 `getHtmlElBorders(el)`
209
+
210
+ 📐 Returns the total **border size** of an element using `border{Side}` shorthand values from computed styles.
211
+
212
+ ```js
213
+ getHtmlElBorders(el: Element): HtmlElBoxSides
214
+ ```
215
+
216
+ * `el`: The target DOM element.
217
+ * **Returns**: An object with total horizontal/vertical border sizes and all four sides.
218
+
219
+ ---
220
+
221
+ ### ➖ `getHtmlElMargin(el)`
222
+
223
+ 📏 Returns the total **margin** of an element using `margin{Side}` from computed styles.
224
+
225
+ ```js
226
+ getHtmlElMargin(el: Element): HtmlElBoxSides
227
+ ```
228
+
229
+ * `el`: The target DOM element.
230
+ * **Returns**: An object containing margin values for each side and totals for horizontal (`x`) and vertical (`y`).
231
+
232
+ ---
233
+
234
+ ### ➕ `getHtmlElPadding(el)`
235
+
236
+ 🧩 Returns the total **padding** of an element using `padding{Side}` from computed styles.
237
+
238
+ ```js
239
+ getHtmlElPadding(el: Element): HtmlElBoxSides
240
+ ```
241
+
242
+ * `el`: The target DOM element.
243
+ * **Returns**: Padding values for all sides and summed horizontal (`x`) and vertical (`y`) values.
@@ -123,7 +123,7 @@ document.addEventListener('DOMContentLoaded', () => {
123
123
 
124
124
  You can use a pre-built CSS template for the `detect-made-by-ai` class, available in the following files:
125
125
 
126
- * `/dist/aiMarker.min.css` – A minified version of the CSS for production use.
127
- * `/dist/aiMarker.css` – The non-minified version for easier readability and customization.
126
+ * `/dist/v1/css/aiMarker.min.css` – A minified version of the CSS for production use.
127
+ * `/dist/v1/css/aiMarker.css` – The non-minified version for easier readability and customization.
128
128
 
129
129
  Simply include the appropriate file in your project to style the elements marked with the `detect-made-by-ai` class.
@@ -0,0 +1,143 @@
1
+ # 📥 TinyDragDropDetector
2
+
3
+ A lightweight JavaScript utility for detecting drag-and-drop file operations on a specific DOM element or the entire page. It manages the full drag lifecycle (`enter`, `over`, `leave`, `drop`) and provides hooks for handling UI changes or file uploads.
4
+
5
+ ---
6
+
7
+ ## 📦 Features
8
+
9
+ * Simple and lightweight.
10
+ * Full drag event lifecycle handling.
11
+ * CSS hover class management.
12
+ * Works on any DOM element or the entire page.
13
+ * Fully typed with JSDoc.
14
+ * Safe with robust error handling.
15
+
16
+ ---
17
+
18
+ ## 🔧 Usage Example
19
+
20
+ ```javascript
21
+ import TinyDragDropDetector from './TinyDragDropDetector.js';
22
+
23
+ const dnd = new TinyDragDropDetector({
24
+ fullscreen: false,
25
+ target: document.getElementById('drop-area'),
26
+ hoverClass: 'hover-effect',
27
+ onDrop: (files, event) => {
28
+ console.log('Files dropped:', files);
29
+ },
30
+ onEnter: (event) => {
31
+ console.log('Drag entered');
32
+ },
33
+ onLeave: (event) => {
34
+ console.log('Drag left');
35
+ },
36
+ });
37
+
38
+ // Destroy when not needed
39
+ // dnd.destroy();
40
+ ```
41
+
42
+ ---
43
+
44
+ ## 🔗 API Reference
45
+
46
+ ### Class: `TinyDragDropDetector`
47
+
48
+ A drag-and-drop detector instance.
49
+
50
+ ### Constructor
51
+
52
+ ```javascript
53
+ new TinyDragDropDetector(options)
54
+ ```
55
+
56
+ #### Parameters:
57
+
58
+ | Name | Type | Default | Description |
59
+ | --------- | ------------------------------------------- | ------- | --------------------- |
60
+ | `options` | [`DragAndDropOptions`](#draganddropoptions) | `{}` | Configuration object. |
61
+
62
+ #### Throws:
63
+
64
+ * `TypeError` if `target` is not an `HTMLElement`.
65
+ * `TypeError` if `fullscreen` is not a boolean.
66
+ * `TypeError` if `hoverClass` is not a string.
67
+ * `TypeError` if `onDrop` is not a function.
68
+ * `TypeError` if `onEnter` is defined but not a function.
69
+ * `TypeError` if `onLeave` is defined but not a function.
70
+
71
+ ---
72
+
73
+ ### Instance Methods
74
+
75
+ | Method | Returns | Description |
76
+ | ----------------- | ------------- | ------------------------------------------------------------------------ |
77
+ | `getTarget()` | `HTMLElement` | Returns the DOM element where listeners are attached. |
78
+ | `getHoverClass()` | `string` | Returns the CSS class applied during drag hover. |
79
+ | `isFullScreen()` | `boolean` | Indicates whether the detector is in fullscreen mode (`document.body`). |
80
+ | `isDragging()` | `boolean` | Returns whether a drag operation is currently active over the target. |
81
+ | `bound()` | `boolean` | Returns whether the event listeners are currently bound to the target. |
82
+ | `destroy()` | `void` | Destroys the detector, unbinding all events and cleaning up CSS classes. |
83
+
84
+ ---
85
+
86
+ ## 🏗️ Event Callbacks
87
+
88
+ | Event | Signature | Description |
89
+ | --------- | --------------------------------------------- | ------------------------------------------- |
90
+ | `onDrop` | `(files: FileList, event: DragEvent) => void` | Fired when files are dropped. **Required**. |
91
+ | `onEnter` | `(event: DragEvent) => void` | Fired when dragging enters the target. |
92
+ | `onLeave` | `(event: DragEvent) => void` | Fired when dragging leaves the target. |
93
+
94
+ ---
95
+
96
+ ## 🛠️ DragAndDropOptions
97
+
98
+ ```javascript
99
+ /**
100
+ * @typedef {Object} DragAndDropOptions
101
+ * @property {HTMLElement} [target=document.body] - The DOM element where drag listeners will be attached. Defaults to `document.body` if `fullscreen` is true or no target is provided.
102
+ * @property {boolean} [fullscreen=true] - If true, listeners are attached to the entire page (`document.body`). If false, the `target` must be specified.
103
+ * @property {string} [hoverClass="dnd-hover"] - CSS class applied to the target element while files are being dragged over it.
104
+ * @property {(files: FileList, event: DragEvent) => void} onDrop - Callback function executed when files are dropped onto the target.
105
+ * @property {(event: DragEvent) => void} [onEnter] - Optional callback triggered when dragging enters the target area.
106
+ * @property {(event: DragEvent) => void} [onLeave] - Optional callback triggered when dragging leaves the target area.
107
+ */
108
+ ```
109
+
110
+ ---
111
+
112
+ ## ⚠️ Warnings
113
+
114
+ * If `dataTransfer` is missing in a `dragover` or `drop` event, a console warning will be shown:
115
+
116
+ * `[TinyDragDropDetector] [handleDragOver] DragOver event missing dataTransfer.`
117
+ * `[TinyDragDropDetector] [handleDrop] Drop event missing dataTransfer.`
118
+
119
+ This is a safe check to prevent runtime errors in malformed events.
120
+
121
+ ---
122
+
123
+ ## 🗑️ Cleanup
124
+
125
+ Call `destroy()` when the detector is no longer needed to prevent memory leaks:
126
+
127
+ ```javascript
128
+ dnd.destroy();
129
+ ```
130
+
131
+ This unbinds all event listeners and removes the hover class if applied.
132
+
133
+ ---
134
+
135
+ ## 🎨 CSS Example
136
+
137
+ ```css
138
+ /* Example hover effect */
139
+ .hover-effect {
140
+ outline: 3px dashed #4caf50;
141
+ background-color: rgba(76, 175, 80, 0.1);
142
+ }
143
+ ```