tiny-essentials 1.11.0 โ 1.12.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.
- package/README.md +12 -3
- package/dist/node_modules/firebase-functions/lib/common/trace.cjs +82 -0
- package/dist/node_modules/firebase-functions/lib/logger/common.cjs +57 -0
- package/dist/node_modules/firebase-functions/lib/logger/index.cjs +158 -0
- package/dist/v1/TinyBasicsEs.js +1653 -1
- package/dist/v1/TinyBasicsEs.min.js +1 -1
- package/dist/v1/TinyDragDropDetector.js +307 -0
- package/dist/v1/TinyDragDropDetector.min.js +1 -0
- package/dist/v1/TinyDragger.js +3668 -0
- package/dist/v1/TinyDragger.min.js +2 -0
- package/dist/v1/TinyDragger.min.js.LICENSE.txt +8 -0
- package/dist/v1/TinyEssentials.js +2888 -2
- package/dist/v1/TinyEssentials.min.js +1 -1
- package/dist/v1/TinyNotifyCenter.js +32 -0
- package/dist/v1/TinyNotifyCenter.min.js +1 -1
- package/dist/v1/TinyToastNotify.js +24 -0
- package/dist/v1/TinyToastNotify.min.js +1 -1
- package/dist/v1/TinyUploadClicker.js +5340 -0
- package/dist/v1/TinyUploadClicker.min.js +2 -0
- package/dist/v1/TinyUploadClicker.min.js.LICENSE.txt +8 -0
- package/dist/v1/basics/fileManager.cjs +524 -0
- package/dist/v1/basics/fileManager.d.mts +209 -0
- package/dist/v1/basics/fileManager.mjs +443 -0
- package/dist/v1/basics/fullScreen.cjs +134 -0
- package/dist/v1/basics/fullScreen.d.mts +8 -0
- package/dist/v1/basics/fullScreen.mjs +121 -0
- package/dist/v1/basics/html.cjs +262 -0
- package/dist/v1/basics/html.d.mts +63 -0
- package/dist/v1/basics/html.mjs +208 -0
- package/dist/v1/basics/index.cjs +40 -0
- package/dist/v1/basics/index.d.mts +38 -1
- package/dist/v1/basics/index.mjs +4 -1
- package/dist/v1/build/TinyDragDropDetector.cjs +7 -0
- package/dist/v1/build/TinyDragDropDetector.d.mts +3 -0
- package/dist/v1/build/TinyDragDropDetector.mjs +2 -0
- package/dist/v1/build/TinyDragger.cjs +7 -0
- package/dist/v1/build/TinyDragger.d.mts +3 -0
- package/dist/v1/build/TinyDragger.mjs +2 -0
- package/dist/v1/build/TinyUploadClicker.cjs +7 -0
- package/dist/v1/build/TinyUploadClicker.d.mts +3 -0
- package/dist/v1/build/TinyUploadClicker.mjs +2 -0
- package/dist/v1/css/TinyDraggerExample.css +21 -0
- package/dist/v1/css/TinyDraggerExample.min.css +1 -0
- package/dist/v1/index.cjs +44 -0
- package/dist/v1/index.d.mts +40 -1
- package/dist/v1/index.mjs +6 -1
- package/dist/v1/libs/TinyDragDropDetector.cjs +268 -0
- package/dist/v1/libs/TinyDragDropDetector.d.mts +123 -0
- package/dist/v1/libs/TinyDragDropDetector.mjs +228 -0
- package/dist/v1/libs/TinyDragger.cjs +906 -0
- package/dist/v1/libs/TinyDragger.d.mts +316 -0
- package/dist/v1/libs/TinyDragger.mjs +783 -0
- package/dist/v1/libs/TinyNotifyCenter.cjs +32 -0
- package/dist/v1/libs/TinyNotifyCenter.d.mts +9 -0
- package/dist/v1/libs/TinyNotifyCenter.mjs +28 -0
- package/dist/v1/libs/TinyToastNotify.cjs +24 -0
- package/dist/v1/libs/TinyToastNotify.d.mts +8 -0
- package/dist/v1/libs/TinyToastNotify.mjs +20 -0
- package/dist/v1/libs/TinyUploadClicker.cjs +223 -0
- package/dist/v1/libs/TinyUploadClicker.d.mts +80 -0
- package/dist/v1/libs/TinyUploadClicker.mjs +182 -0
- package/docs/v1/README.md +8 -2
- package/docs/v1/basics/fileManager.md +222 -0
- package/docs/v1/basics/fullScreen.md +183 -0
- package/docs/v1/basics/html.md +243 -0
- package/docs/v1/libs/TinyDragDropDetector.md +143 -0
- package/docs/v1/libs/TinyDragger.md +430 -0
- package/docs/v1/libs/TinyLevelUp.md +1 -1
- package/docs/v1/libs/TinyNotifyCenter.md +20 -0
- package/docs/v1/libs/TinyToastNotify.md +19 -0
- package/docs/v1/libs/TinyUploadClicker.md +108 -0
- package/package.json +12 -2
package/docs/v1/README.md
CHANGED
|
@@ -18,14 +18,20 @@ This folder contains the core scripts we have worked on so far. Each file is a m
|
|
|
18
18
|
- ๐ข **[simpleMath](./basics/simpleMath.md)** โ A collection of simple math utilities for calculations like the Rule of Three and percentages.
|
|
19
19
|
- โ๏ธ **[text](./basics/text.md)** โ A utility for transforming text into title case formats, with multiple options for capitalization.
|
|
20
20
|
- ๐ **[asyncReplace](./basics/asyncReplace.md)** โ Asynchronously replaces matches in a string using a regex and an async function.
|
|
21
|
+
- ๐ผ๏ธ **[html](./basics/html.md)** โ Utilities for handling DOM element interactions like collision detection and basic element manipulation.
|
|
22
|
+
- ๐บ **[fullScreen](./basics/fullScreen.md)** โ A complete fullscreen API manager with detection, event handling, and cross-browser compatibility.
|
|
23
|
+
* ๐ **[fileManager](./basics/fileManager.mjs.md)** โ A Node.js file/directory utility module with support for JSON, backups, renaming, size analysis, and more.
|
|
21
24
|
|
|
22
25
|
### 2. **`libs/`**
|
|
23
26
|
- ๐๏ธ **[TinyPromiseQueue](./libs/TinyPromiseQueue.md)** โ A class that allows sequential execution of asynchronous tasks, supporting task delays, cancellation, and queue management.
|
|
24
27
|
- ๐
**[TinyLevelUp](./libs/TinyLevelUp.md)** โ A class to manage user level-up logic based on experience points, providing methods for experience validation, addition, removal, and calculation.
|
|
25
28
|
- ๐จ **[ColorSafeStringify](./libs/ColorSafeStringify.md)** โ A utility for applying customizable ANSI colors to JSON strings in terminal outputs, supporting presets and fine-grained type-based highlighting.
|
|
26
29
|
- ๐ฆ **[TinyRateLimiter](./libs/TinyRateLimiter.md)** โ A flexible per-user rate limiter supporting time windows, hit caps, and automatic cleanup of inactive users.
|
|
27
|
-
|
|
28
|
-
|
|
30
|
+
- ๐ **[TinyNotifyCenter](./libs/TinyNotifyCenter.md)** โ A dynamic notification center class to display, manage, and interact with notifications, supporting avatars, clickable items, HTML/text modes, and clean UI controls.
|
|
31
|
+
- ๐ **[TinyToastNotify](./libs/TinyToastNotify.md)** โ A lightweight toast notification system supporting positioning, timing customization, avatars, click actions, and fade-out animations.
|
|
32
|
+
- ๐ฅ **[TinyDragDropDetector](./libs/TinyDragDropDetector.md)** โ A lightweight drag-and-drop detector for files, handling the full drag lifecycle (`enter`, `over`, `leave`, `drop`) with CSS hover management and safe event handling on any DOM element or the full page.
|
|
33
|
+
* ๐ **[TinyUploadClicker](./libs/TinyUploadClicker.md)** โ A minimal utility to bind any clickable element to a hidden file input, offering full control over styling, behavior, and upload event hooks.
|
|
34
|
+
* ๐งฒ **[TinyDragger](./libs/TinyDragger.md)** โ A flexible drag-and-drop manager with collision detection, jail constraints, vibration feedback, visual proxies, revert-on-drop, and full custom event support.
|
|
29
35
|
|
|
30
36
|
---
|
|
31
37
|
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
# ๐ Node.js File & Directory Utilities
|
|
2
|
+
|
|
3
|
+
A powerful and flexible utility toolkit for managing files and directories in Node.js using `fs` and `path`. Includes support for JSON operations, text handling, backups, renaming strategies, and more!
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## ๐ฆ JSON Operations
|
|
8
|
+
|
|
9
|
+
### `readJsonFile(filePath: string): any`
|
|
10
|
+
|
|
11
|
+
๐ Reads and parses a JSON file.
|
|
12
|
+
|
|
13
|
+
* Throws an error if the file doesn't exist or contains invalid JSON.
|
|
14
|
+
* Async version: `readJsonFileAsync`.
|
|
15
|
+
|
|
16
|
+
### `writeJsonFile(filePath: string, data: any, spaces: number = 2): void`
|
|
17
|
+
|
|
18
|
+
๐พ Saves a JavaScript object as a formatted JSON file.
|
|
19
|
+
|
|
20
|
+
* Automatically creates the directory if it doesn't exist.
|
|
21
|
+
* Async version: `writeJsonFileAsync`.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## ๐ Directory Management
|
|
26
|
+
|
|
27
|
+
### `ensureDirectory(dirPath: string): void`
|
|
28
|
+
|
|
29
|
+
๐ ๏ธ Ensures a directory exists. Creates it recursively if needed.
|
|
30
|
+
|
|
31
|
+
### `clearDirectory(dirPath: string): void`
|
|
32
|
+
|
|
33
|
+
๐งน Deletes all contents inside a directory while keeping the directory itself.
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## ๐งช File Checks
|
|
38
|
+
|
|
39
|
+
### `fileExists(filePath: string): boolean`
|
|
40
|
+
|
|
41
|
+
๐ Checks if a file exists.
|
|
42
|
+
|
|
43
|
+
### `dirExists(dirPath: string): boolean`
|
|
44
|
+
|
|
45
|
+
๐ข Checks if a directory exists.
|
|
46
|
+
|
|
47
|
+
### `isDirEmpty(dirPath: string): boolean`
|
|
48
|
+
|
|
49
|
+
๐ญ Checks if a directory is empty.
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## ๐ File Operations
|
|
54
|
+
|
|
55
|
+
### `ensureCopyFile(src: string, dest: string): void`
|
|
56
|
+
|
|
57
|
+
๐ Copies a file from `src` to `dest`, ensuring the destination directory exists.
|
|
58
|
+
|
|
59
|
+
* Async version: `ensureCopyFileAsync`.
|
|
60
|
+
|
|
61
|
+
### `tryDeleteFile(filePath: string): boolean`
|
|
62
|
+
|
|
63
|
+
๐๏ธ Tries to delete a file if it exists. Returns `true` if deleted.
|
|
64
|
+
|
|
65
|
+
* Async version: `tryDeleteFileAsync`.
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
## ๐ Text Operations
|
|
70
|
+
|
|
71
|
+
### `writeTextFile(filePath: string, content: string, ops?: fs.WriteFileOptions): void`
|
|
72
|
+
|
|
73
|
+
โ๏ธ Writes text content to a file. Ensures the directory exists before writing.
|
|
74
|
+
|
|
75
|
+
* Async version: `writeTextFileAsync`.
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
## ๐งพ Directory Listings
|
|
80
|
+
|
|
81
|
+
### `listFiles(dirPath: string, recursive?: boolean): string[]`
|
|
82
|
+
|
|
83
|
+
๐ Lists all files and dirs in a directory. Can be recursive.
|
|
84
|
+
|
|
85
|
+
### `listDirs(dirPath: string, recursive?: boolean): string[]`
|
|
86
|
+
|
|
87
|
+
๐ Lists all directories in a directory. Can be recursive.
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## ๐ File Info
|
|
92
|
+
|
|
93
|
+
### `fileSize(filePath: string): number`
|
|
94
|
+
|
|
95
|
+
โ๏ธ Gets the size of a single file in bytes.
|
|
96
|
+
|
|
97
|
+
### `dirSize(dirPath: string): number`
|
|
98
|
+
|
|
99
|
+
๐ฆ Gets the total size of all files inside a directory (recursive).
|
|
100
|
+
|
|
101
|
+
---
|
|
102
|
+
|
|
103
|
+
## ๐พ Backup Utilities
|
|
104
|
+
|
|
105
|
+
### `backupFile(filePath: string, ext: string = 'bak'): void`
|
|
106
|
+
|
|
107
|
+
๐ Creates a timestamped `.bak` copy of the file.
|
|
108
|
+
|
|
109
|
+
* Async version: `backupFileAsync`.
|
|
110
|
+
|
|
111
|
+
### `getLatestBackupPath(filePath: string, ext: string = 'bak'): void`
|
|
112
|
+
|
|
113
|
+
๐ฆ Returns the **most recent backup file path** for a given file, without modifying anything. Useful for checking which backup would be restored.
|
|
114
|
+
|
|
115
|
+
### `restoreLatestBackup(filePath: string, ext: string = 'bak'): void`
|
|
116
|
+
|
|
117
|
+
โป๏ธ Restores the most recent backup for the file.
|
|
118
|
+
|
|
119
|
+
Output: `/home/yasmin/notes.txt.bak.20250625T153000`
|
|
120
|
+
|
|
121
|
+
```
|
|
122
|
+
<file name>.<ext>.<timestamp>
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
* Async version: `restoreLatestBackupAsync`.
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
## ๐ Rename Utilities
|
|
130
|
+
|
|
131
|
+
### `renameFileBatch(dirPath, renameFn, extensions?)`
|
|
132
|
+
|
|
133
|
+
๐ง Renames all files using a custom renaming function.
|
|
134
|
+
|
|
135
|
+
* Only affects files with the specified extensions (if any).
|
|
136
|
+
|
|
137
|
+
### `renameFileRegex(dirPath, pattern, replacement, extensions?)`
|
|
138
|
+
|
|
139
|
+
๐ก Renames files using a regex pattern and replacement string.
|
|
140
|
+
|
|
141
|
+
### `renameFileAddPrefixSuffix(dirPath, { prefix, suffix }, extensions?)`
|
|
142
|
+
|
|
143
|
+
๐ Adds a prefix and/or suffix to each filename.
|
|
144
|
+
|
|
145
|
+
### `renameFileNormalizeCase(dirPath, mode, extensions?, normalizeExt: boolean = false)`
|
|
146
|
+
|
|
147
|
+
๐ Converts filenames to lowercase or uppercase.
|
|
148
|
+
|
|
149
|
+
* `mode`: `'lower'` or `'upper'`.
|
|
150
|
+
|
|
151
|
+
### `renameFilePadNumbers(dirPath, totalDigits, extensions?)`
|
|
152
|
+
|
|
153
|
+
๐ข Pads the first numeric sequence in a filename with leading zeros.
|
|
154
|
+
|
|
155
|
+
---
|
|
156
|
+
|
|
157
|
+
## ๐ก `renameFileNormalizeCase(dirPath, mode = 'lower', extensions = [])`
|
|
158
|
+
|
|
159
|
+
Normalizes all filenames in a directory to lowercase or uppercase.
|
|
160
|
+
|
|
161
|
+
### ๐ฅ Parameters:
|
|
162
|
+
|
|
163
|
+
* `dirPath` *(string)*: Path to the target directory.
|
|
164
|
+
* `mode` *(`'lower' | 'upper'`)*: Case conversion mode.
|
|
165
|
+
|
|
166
|
+
* `'lower'`: Converts filenames to lowercase.
|
|
167
|
+
* `'upper'`: Converts filenames to uppercase.
|
|
168
|
+
* `extensions` *(string\[])* *(optional)*: List of file extensions to filter. If provided, only files with these extensions will be renamed.
|
|
169
|
+
|
|
170
|
+
### ๐ฏ Example:
|
|
171
|
+
|
|
172
|
+
```js
|
|
173
|
+
renameFileNormalizeCase('./images', 'lower', ['.jpg', '.png']);
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
๐ **Effect**:
|
|
177
|
+
`Photo01.JPG` โ `photo01.jpg`
|
|
178
|
+
`Logo.PNG` โ `logo.png`
|
|
179
|
+
|
|
180
|
+
---
|
|
181
|
+
|
|
182
|
+
## ๐ข `renameFilePadNumbers(dirPath, totalDigits = 3, extensions = [])`
|
|
183
|
+
|
|
184
|
+
Pads the first numeric sequence found in each filename to a specified number of digits.
|
|
185
|
+
|
|
186
|
+
### ๐ฅ Parameters:
|
|
187
|
+
|
|
188
|
+
* `dirPath` *(string)*: Path to the target directory.
|
|
189
|
+
* `totalDigits` *(number)*: Minimum number of digits. Numbers will be padded with leading zeros.
|
|
190
|
+
* `extensions` *(string\[])* *(optional)*: Only rename files with matching extensions.
|
|
191
|
+
|
|
192
|
+
### ๐ฏ Example:
|
|
193
|
+
|
|
194
|
+
```js
|
|
195
|
+
renameFilePadNumbers('./screenshots', 4, ['.jpg']);
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
๐ **Effect**:
|
|
199
|
+
`screenshot1.jpg` โ `screenshot0001.jpg`
|
|
200
|
+
`photo23.jpg` โ `photo0023.jpg`
|
|
201
|
+
|
|
202
|
+
### ๐ง Notes:
|
|
203
|
+
|
|
204
|
+
* Only the **first** number in the filename is affected.
|
|
205
|
+
* If a filename has no digits, it will not be changed.
|
|
206
|
+
|
|
207
|
+
---
|
|
208
|
+
|
|
209
|
+
## ๐ฆ More Example Use
|
|
210
|
+
|
|
211
|
+
```js
|
|
212
|
+
import { readJsonFile, writeJsonFile, listFiles, backupFile } from './utils/files.js';
|
|
213
|
+
|
|
214
|
+
const data = readJsonFile('./config/settings.json');
|
|
215
|
+
data.debug = false;
|
|
216
|
+
writeJsonFile('./config/settings.json', data);
|
|
217
|
+
|
|
218
|
+
const files = listFiles('./src/assets', true);
|
|
219
|
+
console.log('Found files:', files);
|
|
220
|
+
|
|
221
|
+
backupFile('./config/settings.json');
|
|
222
|
+
```
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
# ๐บ Fullscreen Utility API
|
|
2
|
+
|
|
3
|
+
A lightweight JavaScript utility to manage fullscreen behavior easily with cross-browser support! ๐
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## ๐ง Features
|
|
8
|
+
|
|
9
|
+
* โ
Check if fullscreen is active
|
|
10
|
+
* โ
Check if the screen is completely filled
|
|
11
|
+
* โ
Enter fullscreen mode (with legacy browser support)
|
|
12
|
+
* โ
Exit fullscreen mode (with legacy browser support)
|
|
13
|
+
* โ
Listen to fullscreen change events
|
|
14
|
+
* โ
Remove fullscreen change listeners
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## ๐ Functions
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
### ๐ `documentIsFullScreen()`
|
|
23
|
+
|
|
24
|
+
Checks if the **document** is currently in fullscreen mode.
|
|
25
|
+
|
|
26
|
+
```js
|
|
27
|
+
documentIsFullScreen();
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
#### โ
Returns
|
|
31
|
+
|
|
32
|
+
* `boolean` โ `true` if the document is in fullscreen, `false` otherwise.
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
### ๐ `isScreenFilled()`
|
|
37
|
+
|
|
38
|
+
Checks if the **window is filling the entire screen**, based on window dimensions.
|
|
39
|
+
|
|
40
|
+
```js
|
|
41
|
+
isScreenFilled();
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
#### โ
Returns
|
|
45
|
+
|
|
46
|
+
* `boolean` โ `true` if the window occupies the full screen (matching `screen.width` and `screen.height`), otherwise `false`.
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
### ๐ `isFullScreenMode()`
|
|
51
|
+
|
|
52
|
+
Checks whether fullscreen mode is active **by API** (`documentIsFullScreen`) **or by matching window dimensions** (`isScreenFilled`).
|
|
53
|
+
|
|
54
|
+
```js
|
|
55
|
+
isFullScreenMode();
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
#### โ
Returns
|
|
59
|
+
|
|
60
|
+
* `boolean` โ `true` if fullscreen mode is detected by either method.
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
### ๐ฅ๏ธ `requestFullScreen(ops?)`
|
|
65
|
+
|
|
66
|
+
Requests fullscreen mode for the entire document.
|
|
67
|
+
|
|
68
|
+
```js
|
|
69
|
+
await requestFullScreen();
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
#### ๐ง Parameters
|
|
73
|
+
|
|
74
|
+
| Name | Type | Description |
|
|
75
|
+
| ---- | -------------------- | ------------------ |
|
|
76
|
+
| ops | `FullscreenOptions?` | Optional settings. |
|
|
77
|
+
|
|
78
|
+
#### โ
Returns
|
|
79
|
+
|
|
80
|
+
* `Promise<void>` โ Resolves when fullscreen mode is successfully entered.
|
|
81
|
+
|
|
82
|
+
#### โ ๏ธ Notes
|
|
83
|
+
|
|
84
|
+
* Fully supports modern and legacy browsers (`moz`, `webkit`, `ms` prefixes).
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
### ๐ฅ๏ธ `exitFullScreen()`
|
|
89
|
+
|
|
90
|
+
Exits fullscreen mode.
|
|
91
|
+
|
|
92
|
+
```js
|
|
93
|
+
await exitFullScreen();
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
#### โ
Returns
|
|
97
|
+
|
|
98
|
+
* `Promise<void>` โ Resolves when fullscreen mode is successfully exited.
|
|
99
|
+
|
|
100
|
+
#### โ ๏ธ Notes
|
|
101
|
+
|
|
102
|
+
* Fully supports modern and legacy browsers (`moz`, `webkit`, `ms` prefixes).
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
### ๐ `onFullScreenChange(listener, ops?)`
|
|
107
|
+
|
|
108
|
+
Attaches a listener for fullscreen change events.
|
|
109
|
+
|
|
110
|
+
```js
|
|
111
|
+
onFullScreenChange((event) => {
|
|
112
|
+
console.log('Fullscreen changed!', event);
|
|
113
|
+
});
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
#### ๐ง Parameters
|
|
117
|
+
|
|
118
|
+
| Name | Type | Description |
|
|
119
|
+
| -------- | ------------------------------------------- | ------------------ |
|
|
120
|
+
| listener | `EventListenerOrEventListenerObject` | Callback function. |
|
|
121
|
+
| ops | `boolean \| AddEventListenerOptions` (opt.) | Optional options. |
|
|
122
|
+
|
|
123
|
+
#### โ
Returns
|
|
124
|
+
|
|
125
|
+
* `void`
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
### ๐ `offFullScreenChange(listener, ops?)`
|
|
130
|
+
|
|
131
|
+
Removes a listener from fullscreen change events.
|
|
132
|
+
|
|
133
|
+
```js
|
|
134
|
+
offFullScreenChange(myListener);
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
#### ๐ง Parameters
|
|
138
|
+
|
|
139
|
+
| Name | Type | Description |
|
|
140
|
+
| -------- | ------------------------------------------- | ------------------ |
|
|
141
|
+
| listener | `EventListenerOrEventListenerObject` | Callback function. |
|
|
142
|
+
| ops | `boolean \| AddEventListenerOptions` (opt.) | Optional options. |
|
|
143
|
+
|
|
144
|
+
#### โ
Returns
|
|
145
|
+
|
|
146
|
+
* `void`
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
## ๐ Fullscreen Events Supported
|
|
151
|
+
|
|
152
|
+
The following events are internally used for compatibility:
|
|
153
|
+
|
|
154
|
+
* `'fullscreenchange'`
|
|
155
|
+
* `'webkitfullscreenchange'`
|
|
156
|
+
* `'mozfullscreenchange'`
|
|
157
|
+
* `'MSFullscreenChange'`
|
|
158
|
+
|
|
159
|
+
---
|
|
160
|
+
|
|
161
|
+
## ๐ก Example Usage
|
|
162
|
+
|
|
163
|
+
```js
|
|
164
|
+
import {
|
|
165
|
+
requestFullScreen,
|
|
166
|
+
exitFullScreen,
|
|
167
|
+
isFullScreenMode,
|
|
168
|
+
onFullScreenChange,
|
|
169
|
+
offFullScreenChange,
|
|
170
|
+
} from './fullScreen';
|
|
171
|
+
|
|
172
|
+
async function toggleFullscreen() {
|
|
173
|
+
if (isFullScreenMode()) {
|
|
174
|
+
await exitFullScreen();
|
|
175
|
+
} else {
|
|
176
|
+
await requestFullScreen();
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
onFullScreenChange(() => {
|
|
181
|
+
console.log('Fullscreen mode changed!');
|
|
182
|
+
});
|
|
183
|
+
```
|
|
@@ -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.
|