tiny-essentials 1.14.0 → 1.16.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.
- package/dist/v1/TinyBasicsEs.js +4585 -270
- package/dist/v1/TinyBasicsEs.min.js +1 -1
- package/dist/v1/TinyDragger.js +4386 -471
- package/dist/v1/TinyDragger.min.js +1 -1
- package/dist/v1/TinyEssentials.js +4634 -242
- package/dist/v1/TinyEssentials.min.js +1 -1
- package/dist/v1/TinyHtml.js +4327 -0
- package/dist/v1/TinyHtml.min.js +1 -0
- package/dist/v1/TinyUploadClicker.js +4628 -246
- package/dist/v1/TinyUploadClicker.min.js +1 -1
- package/dist/v1/basics/collision.cjs +413 -0
- package/dist/v1/basics/collision.d.mts +187 -0
- package/dist/v1/basics/collision.mjs +350 -0
- package/dist/v1/basics/html.cjs +5 -109
- package/dist/v1/basics/html.d.mts +2 -28
- package/dist/v1/basics/html.mjs +5 -91
- package/dist/v1/basics/html_deprecated.cjs +124 -0
- package/dist/v1/basics/html_deprecated.d.mts +40 -0
- package/dist/v1/basics/html_deprecated.mjs +97 -0
- package/dist/v1/basics/index.cjs +27 -5
- package/dist/v1/basics/index.d.mts +26 -6
- package/dist/v1/basics/index.mjs +4 -2
- package/dist/v1/build/TinyHtml.cjs +7 -0
- package/dist/v1/build/TinyHtml.d.mts +3 -0
- package/dist/v1/build/TinyHtml.mjs +2 -0
- package/dist/v1/index.cjs +29 -5
- package/dist/v1/index.d.mts +27 -6
- package/dist/v1/index.mjs +5 -2
- package/dist/v1/libs/TinyDragger.cjs +91 -16
- package/dist/v1/libs/TinyDragger.d.mts +78 -2
- package/dist/v1/libs/TinyDragger.mjs +93 -17
- package/dist/v1/libs/TinyHtml.cjs +3859 -0
- package/dist/v1/libs/TinyHtml.d.mts +2151 -0
- package/dist/v1/libs/TinyHtml.mjs +3457 -0
- package/docs/v1/README.md +2 -0
- package/docs/v1/basics/collision.md +237 -0
- package/docs/v1/basics/html.md +1 -105
- package/docs/v1/basics/html_deprecated.md +127 -0
- package/docs/v1/libs/TinyDragger.md +45 -15
- package/docs/v1/libs/TinyHtml.md +1333 -0
- package/package.json +8 -2
package/docs/v1/README.md
CHANGED
|
@@ -20,6 +20,7 @@ This folder contains the core scripts we have worked on so far. Each file is a m
|
|
|
20
20
|
- 🔄 **[asyncReplace](./basics/asyncReplace.md)** — Asynchronously replaces matches in a string using a regex and an async function.
|
|
21
21
|
- 🖼️ **[html](./basics/html.md)** — Utilities for handling DOM element interactions like collision detection and basic element manipulation.
|
|
22
22
|
- 📺 **[fullScreen](./basics/fullScreen.md)** — A complete fullscreen API manager with detection, event handling, and cross-browser compatibility.
|
|
23
|
+
- 🧱 **[collision](./basics/collision.md)** — Full-featured rectangle collision detection system with directional analysis, depth calculation, and center offset metrics.
|
|
23
24
|
|
|
24
25
|
### 2. **`libs/`**
|
|
25
26
|
- 🗂️ **[TinyPromiseQueue](./libs/TinyPromiseQueue.md)** — A class that allows sequential execution of asynchronous tasks, supporting task delays, cancellation, and queue management.
|
|
@@ -33,6 +34,7 @@ This folder contains the core scripts we have worked on so far. Each file is a m
|
|
|
33
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.
|
|
34
35
|
- 🕒 **[TinyDomReadyManager](./libs/TinyDomReadyManager.md)** — A readiness manager for DOM and async conditions, supporting prioritized callbacks, custom filters, and event-based or promise-based bootstrapping.
|
|
35
36
|
- 📣 **[TinyNotifications](./libs/TinyNotifications.md)** — A browser notification utility with sound support, permission management, truncation logic, default icons, and enforced validation to ensure safe and predictable usage.
|
|
37
|
+
- 🧱 **[TinyHtml](./libs/TinyHtml.md)** — A minimalist DOM utility class that offers jQuery-like methods in pure JavaScript for querying, styling, traversing, event handling, collision detection, and visibility logic — all in a lightweight and chainable interface.
|
|
36
38
|
|
|
37
39
|
### 3. **`fileManager/`**
|
|
38
40
|
* 📁 **[main](./fileManager/main.md)** — A Node.js file/directory utility module with support for JSON, backups, renaming, size analysis, and more.
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
# 📦 Collision Detection Module
|
|
2
|
+
|
|
3
|
+
This module provides a complete and flexible system for detecting collisions between rectangles (like DOM elements), extracting direction, depth, and center alignment data.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 📐 Type Definitions
|
|
8
|
+
|
|
9
|
+
### `Dirs`
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
'top' | 'bottom' | 'left' | 'right'
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
🔁 A direction relative to a rectangle. Represents one of the four cardinal sides.
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
### `CollDirs`
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
{
|
|
23
|
+
in: Dirs | 'center' | null;
|
|
24
|
+
x: Dirs | null;
|
|
25
|
+
y: Dirs | null;
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
🚦 Represents all directional aspects of a collision:
|
|
30
|
+
|
|
31
|
+
* `in`: Dominant entry direction (`null` if no collision, `'center'` if perfectly aligned).
|
|
32
|
+
* `x`: Collision bias on X axis.
|
|
33
|
+
* `y`: Collision bias on Y axis.
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
### `NegCollDirs`
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
{
|
|
41
|
+
x: Dirs | null;
|
|
42
|
+
y: Dirs | null;
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
❌ Negative collision flags indicating **gap** instead of overlap.
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
### `CollData`
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
{
|
|
54
|
+
top: number;
|
|
55
|
+
bottom: number;
|
|
56
|
+
left: number;
|
|
57
|
+
right: number;
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
📏 Collision depth (in pixels) from each side of `rect2` into `rect1`.
|
|
62
|
+
|
|
63
|
+
* Positive values = overlap
|
|
64
|
+
* Negative values = no collision (gap)
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
### `CollCenter`
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
{
|
|
72
|
+
x: number;
|
|
73
|
+
y: number;
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
🎯 Offset from the center of `rect1` to the center of `rect2`.
|
|
78
|
+
|
|
79
|
+
---
|
|
80
|
+
|
|
81
|
+
### `ObjRect`
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
{
|
|
85
|
+
height: number;
|
|
86
|
+
width: number;
|
|
87
|
+
top: number;
|
|
88
|
+
bottom: number;
|
|
89
|
+
left: number;
|
|
90
|
+
right: number;
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
📦 Generic rectangle object, similar to `DOMRect`.
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
## 🔍 Collision Checks
|
|
99
|
+
|
|
100
|
+
### Loose Collision (Partial Overlap Only)
|
|
101
|
+
|
|
102
|
+
| Function | Description |
|
|
103
|
+
| -------------------------------- | --------------------------------------- |
|
|
104
|
+
| `areElsCollTop(rect1, rect2)` | `rect1` is **above** `rect2` |
|
|
105
|
+
| `areElsCollBottom(rect1, rect2)` | `rect1` is **below** `rect2` |
|
|
106
|
+
| `areElsCollLeft(rect1, rect2)` | `rect1` is **left of** `rect2` |
|
|
107
|
+
| `areElsCollRight(rect1, rect2)` | `rect1` is **right of** `rect2` |
|
|
108
|
+
| `areElsColliding(rect1, rect2)` | Returns `true` if **any side overlaps** |
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
### Perfect Collision (Touch or Overlap)
|
|
113
|
+
|
|
114
|
+
| Function | Description |
|
|
115
|
+
| ------------------------------------ | -------------------------------------------------- |
|
|
116
|
+
| `areElsCollPerfTop(rect1, rect2)` | `rect1` is **fully above** or touching `rect2` |
|
|
117
|
+
| `areElsCollPerfBottom(rect1, rect2)` | `rect1` is **fully below** or touching `rect2` |
|
|
118
|
+
| `areElsCollPerfLeft(rect1, rect2)` | `rect1` is **fully left** or touching `rect2` |
|
|
119
|
+
| `areElsCollPerfRight(rect1, rect2)` | `rect1` is **fully right** or touching `rect2` |
|
|
120
|
+
| `areElsPerfColliding(rect1, rect2)` | Returns `true` if there's **any overlap or touch** |
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
### Collision Direction (Single Side Detection)
|
|
125
|
+
|
|
126
|
+
| Function | Returns |
|
|
127
|
+
| ----------------------------------- | -------------------------------------------------- |
|
|
128
|
+
| `getElsColliding(rect1, rect2)` | `'left'`, `'right'`, `'top'`, `'bottom'` or `null` |
|
|
129
|
+
| `getElsPerfColliding(rect1, rect2)` | Same as above, but includes **touch detection** |
|
|
130
|
+
|
|
131
|
+
---
|
|
132
|
+
|
|
133
|
+
## 🔬 Overlap & Direction
|
|
134
|
+
|
|
135
|
+
### `getElsCollOverlap(rect1, rect2)`
|
|
136
|
+
|
|
137
|
+
📏 Returns the depth of overlap between two rectangles:
|
|
138
|
+
|
|
139
|
+
```js
|
|
140
|
+
{
|
|
141
|
+
overlapLeft,
|
|
142
|
+
overlapRight,
|
|
143
|
+
overlapTop,
|
|
144
|
+
overlapBottom
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
### `getElsCollOverlapPos({ overlapLeft, overlapRight, overlapTop, overlapBottom })`
|
|
151
|
+
|
|
152
|
+
📍 Determines which axis and direction has the strongest collision.
|
|
153
|
+
|
|
154
|
+
```js
|
|
155
|
+
{
|
|
156
|
+
dirX: 'left' | 'right',
|
|
157
|
+
dirY: 'top' | 'bottom'
|
|
158
|
+
}
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
---
|
|
162
|
+
|
|
163
|
+
## 🎯 Center Detection
|
|
164
|
+
|
|
165
|
+
### `getRectCenter(rect)`
|
|
166
|
+
|
|
167
|
+
Returns the **center X and Y coordinates** of a rectangle.
|
|
168
|
+
|
|
169
|
+
---
|
|
170
|
+
|
|
171
|
+
### `getElsRelativeCenterOffset(rect1, rect2)`
|
|
172
|
+
|
|
173
|
+
Returns the distance from `rect1`'s center to `rect2`'s center:
|
|
174
|
+
|
|
175
|
+
```js
|
|
176
|
+
{
|
|
177
|
+
x: number,
|
|
178
|
+
y: number
|
|
179
|
+
}
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
✅ Values are `0` when centers are aligned.
|
|
183
|
+
|
|
184
|
+
---
|
|
185
|
+
|
|
186
|
+
## 🧠 Direction & Depth
|
|
187
|
+
|
|
188
|
+
### `getElsCollDirDepth(rect1, rect2)`
|
|
189
|
+
|
|
190
|
+
Detects:
|
|
191
|
+
|
|
192
|
+
* Which axis has the dominant collision
|
|
193
|
+
* Overlap depths
|
|
194
|
+
|
|
195
|
+
```js
|
|
196
|
+
{
|
|
197
|
+
inDir: 'left' | 'right' | 'top' | 'bottom' | null,
|
|
198
|
+
dirX: 'left' | 'right' | null,
|
|
199
|
+
dirY: 'top' | 'bottom' | null,
|
|
200
|
+
depthX: number,
|
|
201
|
+
depthY: number
|
|
202
|
+
}
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
---
|
|
206
|
+
|
|
207
|
+
### `getElsCollDetails(rect1, rect2)`
|
|
208
|
+
|
|
209
|
+
🔍 Full analysis of the collision:
|
|
210
|
+
|
|
211
|
+
* Depth of overlap
|
|
212
|
+
* Direction of entry
|
|
213
|
+
* Negative axis gaps
|
|
214
|
+
* Center hit detection
|
|
215
|
+
|
|
216
|
+
```js
|
|
217
|
+
{
|
|
218
|
+
depth: CollData,
|
|
219
|
+
dirs: CollDirs,
|
|
220
|
+
isNeg: NegCollDirs
|
|
221
|
+
}
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
---
|
|
225
|
+
|
|
226
|
+
## 🧪 Example Use
|
|
227
|
+
|
|
228
|
+
```js
|
|
229
|
+
const box = element1.getBoundingClientRect();
|
|
230
|
+
const wall = element2.getBoundingClientRect();
|
|
231
|
+
|
|
232
|
+
const result = getElsCollDetails(box, wall);
|
|
233
|
+
|
|
234
|
+
console.log(result.depth); // { top, bottom, left, right }
|
|
235
|
+
console.log(result.dirs.in); // e.g. 'left'
|
|
236
|
+
console.log(result.isNeg); // e.g. { x: 'left', y: null }
|
|
237
|
+
```
|
package/docs/v1/basics/html.md
CHANGED
|
@@ -1,55 +1,3 @@
|
|
|
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
|
-
#### 🧠 Syntax
|
|
15
|
-
|
|
16
|
-
```javascript
|
|
17
|
-
areHtmlElsColliding(elem1, elem2);
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
#### 🎯 Parameters
|
|
21
|
-
|
|
22
|
-
| Parameter | Type | Description |
|
|
23
|
-
| --------- | --------- | ----------------------- |
|
|
24
|
-
| `elem1` | `Element` | The first DOM element. |
|
|
25
|
-
| `elem2` | `Element` | The second DOM element. |
|
|
26
|
-
|
|
27
|
-
#### 🔁 Return
|
|
28
|
-
|
|
29
|
-
| Type | Description |
|
|
30
|
-
| --------- | ------------------------------------------------------------------ |
|
|
31
|
-
| `boolean` | ✅ `true` if elements are colliding. <br>❌ `false` if they are not. |
|
|
32
|
-
|
|
33
|
-
#### 📦 Example
|
|
34
|
-
|
|
35
|
-
```javascript
|
|
36
|
-
const box1 = document.getElementById('box1');
|
|
37
|
-
const box2 = document.getElementById('box2');
|
|
38
|
-
|
|
39
|
-
if (areHtmlElsColliding(box1, box2)) {
|
|
40
|
-
console.log('🎯 Collision detected!');
|
|
41
|
-
} else {
|
|
42
|
-
console.log('❌ No collision.');
|
|
43
|
-
}
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
#### 🚧 Limitations
|
|
47
|
-
|
|
48
|
-
* Only works with **axis-aligned elements** (rectangular shapes).
|
|
49
|
-
* Does not handle rotated elements or complex shapes.
|
|
50
|
-
|
|
51
|
-
---
|
|
52
|
-
|
|
53
1
|
### 📖 `readBase64Blob(file: File, isDataUrl?: boolean | string): Promise<string>`
|
|
54
2
|
|
|
55
3
|
Reads a file and returns its Base64 content using the FileReader API, with optional formatting as a full Data URL.
|
|
@@ -136,7 +84,7 @@ input.addEventListener('change', async () => {
|
|
|
136
84
|
|
|
137
85
|
### 📖 `readJsonBlob(file: File): Promise<any>`
|
|
138
86
|
|
|
139
|
-
Reads and parses a JSON file using the
|
|
87
|
+
Reads and parses a JSON file using the FileReader API.
|
|
140
88
|
|
|
141
89
|
#### 📥 Parameters
|
|
142
90
|
|
|
@@ -266,58 +214,6 @@ A common return format used to describe the box model dimensions (borders, paddi
|
|
|
266
214
|
|
|
267
215
|
---
|
|
268
216
|
|
|
269
|
-
### 🔲 `getHtmlElBordersWidth(el)`
|
|
270
|
-
|
|
271
|
-
📏 Returns the total **border width** of an element using `border{Side}Width` values from computed styles.
|
|
272
|
-
|
|
273
|
-
```js
|
|
274
|
-
getHtmlElBordersWidth(el: Element): HtmlElBoxSides
|
|
275
|
-
```
|
|
276
|
-
|
|
277
|
-
* `el`: The target DOM element.
|
|
278
|
-
* **Returns**: An object containing total horizontal/vertical border widths, and each side individually.
|
|
279
|
-
|
|
280
|
-
---
|
|
281
|
-
|
|
282
|
-
### 🔳 `getHtmlElBorders(el)`
|
|
283
|
-
|
|
284
|
-
📐 Returns the total **border size** of an element using `border{Side}` shorthand values from computed styles.
|
|
285
|
-
|
|
286
|
-
```js
|
|
287
|
-
getHtmlElBorders(el: Element): HtmlElBoxSides
|
|
288
|
-
```
|
|
289
|
-
|
|
290
|
-
* `el`: The target DOM element.
|
|
291
|
-
* **Returns**: An object with total horizontal/vertical border sizes and all four sides.
|
|
292
|
-
|
|
293
|
-
---
|
|
294
|
-
|
|
295
|
-
### ➖ `getHtmlElMargin(el)`
|
|
296
|
-
|
|
297
|
-
📏 Returns the total **margin** of an element using `margin{Side}` from computed styles.
|
|
298
|
-
|
|
299
|
-
```js
|
|
300
|
-
getHtmlElMargin(el: Element): HtmlElBoxSides
|
|
301
|
-
```
|
|
302
|
-
|
|
303
|
-
* `el`: The target DOM element.
|
|
304
|
-
* **Returns**: An object containing margin values for each side and totals for horizontal (`x`) and vertical (`y`).
|
|
305
|
-
|
|
306
|
-
---
|
|
307
|
-
|
|
308
|
-
### ➕ `getHtmlElPadding(el)`
|
|
309
|
-
|
|
310
|
-
🧩 Returns the total **padding** of an element using `padding{Side}` from computed styles.
|
|
311
|
-
|
|
312
|
-
```js
|
|
313
|
-
getHtmlElPadding(el: Element): HtmlElBoxSides
|
|
314
|
-
```
|
|
315
|
-
|
|
316
|
-
* `el`: The target DOM element.
|
|
317
|
-
* **Returns**: Padding values for all sides and summed horizontal (`x`) and vertical (`y`) values.
|
|
318
|
-
|
|
319
|
-
---
|
|
320
|
-
|
|
321
217
|
### 📄 `installWindowHiddenScript`
|
|
322
218
|
|
|
323
219
|
Automatically toggles CSS classes on a given element based on the browser window or tab **visibility** and **focus** state.
|
|
@@ -0,0 +1,127 @@
|
|
|
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
|
+
#### 🧠 Syntax
|
|
15
|
+
|
|
16
|
+
```javascript
|
|
17
|
+
areHtmlElsColliding(elem1, elem2);
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
#### 🎯 Parameters
|
|
21
|
+
|
|
22
|
+
| Parameter | Type | Description |
|
|
23
|
+
| --------- | --------- | ----------------------- |
|
|
24
|
+
| `elem1` | `Element` | The first DOM element. |
|
|
25
|
+
| `elem2` | `Element` | The second DOM element. |
|
|
26
|
+
|
|
27
|
+
#### 🔁 Return
|
|
28
|
+
|
|
29
|
+
| Type | Description |
|
|
30
|
+
| --------- | ------------------------------------------------------------------ |
|
|
31
|
+
| `boolean` | ✅ `true` if elements are colliding. <br>❌ `false` if they are not. |
|
|
32
|
+
|
|
33
|
+
#### 📦 Example
|
|
34
|
+
|
|
35
|
+
```javascript
|
|
36
|
+
const box1 = document.getElementById('box1');
|
|
37
|
+
const box2 = document.getElementById('box2');
|
|
38
|
+
|
|
39
|
+
if (areHtmlElsColliding(box1, box2)) {
|
|
40
|
+
console.log('🎯 Collision detected!');
|
|
41
|
+
} else {
|
|
42
|
+
console.log('❌ No collision.');
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
#### 🚧 Limitations
|
|
47
|
+
|
|
48
|
+
* Only works with **axis-aligned elements** (rectangular shapes).
|
|
49
|
+
* Does not handle rotated elements or complex shapes.
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
### 🔲 `getHtmlElBordersWidth(el)`
|
|
54
|
+
|
|
55
|
+
📏 Returns the total **border width** of an element using `border{Side}Width` values from computed styles.
|
|
56
|
+
|
|
57
|
+
```js
|
|
58
|
+
getHtmlElBordersWidth(el: Element): HtmlElBoxSides
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
* `el`: The target DOM element.
|
|
62
|
+
* **Returns**: An object containing total horizontal/vertical border widths, and each side individually.
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
### 🔳 `getHtmlElBorders(el)`
|
|
67
|
+
|
|
68
|
+
📐 Returns the total **border size** of an element using `border{Side}` shorthand values from computed styles.
|
|
69
|
+
|
|
70
|
+
```js
|
|
71
|
+
getHtmlElBorders(el: Element): HtmlElBoxSides
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
* `el`: The target DOM element.
|
|
75
|
+
* **Returns**: An object with total horizontal/vertical border sizes and all four sides.
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
### ➖ `getHtmlElMargin(el)`
|
|
80
|
+
|
|
81
|
+
📏 Returns the total **margin** of an element using `margin{Side}` from computed styles.
|
|
82
|
+
|
|
83
|
+
```js
|
|
84
|
+
getHtmlElMargin(el: Element): HtmlElBoxSides
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
* `el`: The target DOM element.
|
|
88
|
+
* **Returns**: An object containing margin values for each side and totals for horizontal (`x`) and vertical (`y`).
|
|
89
|
+
|
|
90
|
+
---
|
|
91
|
+
|
|
92
|
+
### ➕ `getHtmlElPadding(el)`
|
|
93
|
+
|
|
94
|
+
🧩 Returns the total **padding** of an element using `padding{Side}` from computed styles.
|
|
95
|
+
|
|
96
|
+
```js
|
|
97
|
+
getHtmlElPadding(el: Element): HtmlElBoxSides
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
* `el`: The target DOM element.
|
|
101
|
+
* **Returns**: Padding values for all sides and summed horizontal (`x`) and vertical (`y`) values.
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
### 👁️ `isInViewport(element)`
|
|
106
|
+
|
|
107
|
+
🔍 Checks if an element is **partially visible** in the current viewport.
|
|
108
|
+
|
|
109
|
+
```js
|
|
110
|
+
isInViewport(element: HTMLElement): boolean
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
* `element`: The DOM element to check.
|
|
114
|
+
* **Returns**: `true` if the element is at least partially visible; `false` otherwise.
|
|
115
|
+
|
|
116
|
+
---
|
|
117
|
+
|
|
118
|
+
### ✅ `isScrolledIntoView(element)`
|
|
119
|
+
|
|
120
|
+
📦 Checks if an element is **fully visible** (top and bottom) within the viewport.
|
|
121
|
+
|
|
122
|
+
```js
|
|
123
|
+
isScrolledIntoView(element: HTMLElement): boolean
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
* `element`: The DOM element to check.
|
|
127
|
+
* **Returns**: `true` if the entire element is within the viewport; `false` otherwise.
|
|
@@ -42,21 +42,23 @@ new TinyDragger(targetElement, options?)
|
|
|
42
42
|
|
|
43
43
|
### Options:
|
|
44
44
|
|
|
45
|
-
| Option | Type | Default | Description
|
|
46
|
-
| ----------------------- | ------------------------------ | ---------------------- |
|
|
47
|
-
| `jail` | `HTMLElement` | `null` | Optional container that restricts movement
|
|
48
|
-
| `collisionByMouse` | `boolean` | `false` | Use mouse position instead of bounding box for collision
|
|
49
|
-
| `classDragging` | `string` | `'dragging'` | Class applied to the clone element
|
|
50
|
-
| `classBodyDragging` | `string` | `'drag-active'` | Class applied to the `<body>` during dragging
|
|
51
|
-
| `classJailDragging` | `string` | `'jail-drag-active'` | Class applied to jail while dragging
|
|
52
|
-
| `classJailDragDisabled` | `string` | `'jail-drag-disabled'` | Class applied to jail when dragging is disabled
|
|
53
|
-
| `classDragCollision` | `string` | `'dragging-collision'` | Class applied to elements when collision is detected
|
|
54
|
-
| `classHidden` | `string` | `'drag-hidden'` | Class used to hide the original element while dragging
|
|
55
|
-
| `lockInsideJail` | `boolean` | `false` | Prevent drag from exceeding jail bounds
|
|
56
|
-
| `dropInJailOnly` | `boolean` | `false` | Prevent drop outside the jail area
|
|
57
|
-
| `multiCollision` | `boolean` | `false` | Enables returning multiple collided elements
|
|
58
|
-
| `vibration` | `VibrationPatterns` or `false` | `false` | Vibration feedback configuration
|
|
59
|
-
| `revertOnDrop` | `boolean` | `false` | Return to original position after dropping
|
|
45
|
+
| Option | Type | Default | Description |
|
|
46
|
+
| ----------------------- | ------------------------------ | ---------------------- | ----------------------------------------------------------- |
|
|
47
|
+
| `jail` | `HTMLElement` | `null` | Optional container that restricts movement |
|
|
48
|
+
| `collisionByMouse` | `boolean` | `false` | Use mouse position instead of bounding box for collision |
|
|
49
|
+
| `classDragging` | `string` | `'dragging'` | Class applied to the clone element |
|
|
50
|
+
| `classBodyDragging` | `string` | `'drag-active'` | Class applied to the `<body>` during dragging |
|
|
51
|
+
| `classJailDragging` | `string` | `'jail-drag-active'` | Class applied to jail while dragging |
|
|
52
|
+
| `classJailDragDisabled` | `string` | `'jail-drag-disabled'` | Class applied to jail when dragging is disabled |
|
|
53
|
+
| `classDragCollision` | `string` | `'dragging-collision'` | Class applied to elements when collision is detected |
|
|
54
|
+
| `classHidden` | `string` | `'drag-hidden'` | Class used to hide the original element while dragging |
|
|
55
|
+
| `lockInsideJail` | `boolean` | `false` | Prevent drag from exceeding jail bounds |
|
|
56
|
+
| `dropInJailOnly` | `boolean` | `false` | Prevent drop outside the jail area |
|
|
57
|
+
| `multiCollision` | `boolean` | `false` | Enables returning multiple collided elements |
|
|
58
|
+
| `vibration` | `VibrationPatterns` or `false` | `false` | Vibration feedback configuration |
|
|
59
|
+
| `revertOnDrop` | `boolean` | `false` | Return to original position after dropping |
|
|
60
|
+
| `mirrorElem` | `boolean` | `true` | Use a visual clone instead of dragging the original element |
|
|
61
|
+
| `defaultZIndex` | `number` | `9999` | Sets the z-index value applied when dragging starts |
|
|
60
62
|
|
|
61
63
|
---
|
|
62
64
|
|
|
@@ -334,6 +336,34 @@ Returns `null` if no proxy is active.
|
|
|
334
336
|
|
|
335
337
|
---
|
|
336
338
|
|
|
339
|
+
### `getDefaultZIndex(): number`
|
|
340
|
+
|
|
341
|
+
🎯 Returns the current default `z-index` used when a draggable item is picked up.
|
|
342
|
+
|
|
343
|
+
---
|
|
344
|
+
|
|
345
|
+
### `setDefaultZIndex(newZIndex: number): void`
|
|
346
|
+
|
|
347
|
+
🛠️ Sets a new default `z-index` to be used during drag operations.
|
|
348
|
+
|
|
349
|
+
> Throws `TypeError` if `newZIndex` is not a finite number.
|
|
350
|
+
|
|
351
|
+
---
|
|
352
|
+
|
|
353
|
+
### `isMirrorEnabled(): boolean`
|
|
354
|
+
|
|
355
|
+
🎯 Returns whether the draggable element uses a **mirror** (`true`) or the **original element** (`false`) during dragging.
|
|
356
|
+
|
|
357
|
+
---
|
|
358
|
+
|
|
359
|
+
### `setMirrorEnabled(useMirror: boolean): void`
|
|
360
|
+
|
|
361
|
+
🛠️ Defines whether the draggable element should use a **mirror clone** or move the **original element**.
|
|
362
|
+
|
|
363
|
+
> Throws `TypeError` if `useMirror` is not a boolean.
|
|
364
|
+
|
|
365
|
+
---
|
|
366
|
+
|
|
337
367
|
## 🔁 Events
|
|
338
368
|
|
|
339
369
|
The target element will emit these events:
|