tiny-essentials 1.15.0 β 1.16.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/dist/v1/TinyAfterScrollWatcher.js +196 -0
- package/dist/v1/TinyAfterScrollWatcher.min.js +1 -0
- package/dist/v1/TinyBasicsEs.js +5058 -745
- package/dist/v1/TinyBasicsEs.min.js +1 -1
- package/dist/v1/TinyDragger.js +4874 -546
- package/dist/v1/TinyDragger.min.js +1 -1
- package/dist/v1/TinyEssentials.js +5299 -750
- package/dist/v1/TinyEssentials.min.js +1 -1
- package/dist/v1/TinyHtml.js +4815 -0
- package/dist/v1/TinyHtml.min.js +1 -0
- package/dist/v1/TinyUploadClicker.js +5093 -298
- package/dist/v1/TinyUploadClicker.min.js +1 -1
- package/dist/v1/basics/html.cjs +5 -187
- package/dist/v1/basics/html.d.mts +2 -53
- package/dist/v1/basics/html.mjs +5 -161
- 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 +8 -7
- package/dist/v1/basics/index.d.mts +7 -7
- package/dist/v1/basics/index.mjs +2 -1
- package/dist/v1/build/TinyAfterScrollWatcher.cjs +7 -0
- package/dist/v1/build/TinyAfterScrollWatcher.d.mts +3 -0
- package/dist/v1/build/TinyAfterScrollWatcher.mjs +2 -0
- 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 +12 -7
- package/dist/v1/index.d.mts +10 -8
- package/dist/v1/index.mjs +5 -2
- package/dist/v1/libs/TinyAfterScrollWatcher.cjs +157 -0
- package/dist/v1/libs/TinyAfterScrollWatcher.d.mts +86 -0
- package/dist/v1/libs/TinyAfterScrollWatcher.mjs +138 -0
- 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 +4347 -0
- package/dist/v1/libs/TinyHtml.d.mts +2301 -0
- package/dist/v1/libs/TinyHtml.mjs +3926 -0
- package/dist/v1/libs/TinyUploadClicker.cjs +1 -0
- package/docs/v1/README.md +11 -10
- package/docs/v1/basics/html.md +0 -130
- package/docs/v1/basics/html_deprecated.md +127 -0
- package/docs/v1/libs/TinyAfterScrollWatcher.md +181 -0
- package/docs/v1/libs/TinyDragger.md +45 -15
- package/docs/v1/libs/TinyHtml.md +1658 -0
- package/package.json +4 -1
package/docs/v1/README.md
CHANGED
|
@@ -12,15 +12,15 @@ Here, you can navigate through different sections of the project. Below are the
|
|
|
12
12
|
|
|
13
13
|
This folder contains the core scripts we have worked on so far. Each file is a module focused on specific functionality.
|
|
14
14
|
|
|
15
|
-
- π¦ **[
|
|
16
|
-
- β° **[
|
|
17
|
-
- π§ **[
|
|
18
|
-
- π’ **[
|
|
19
|
-
- βοΈ **[
|
|
20
|
-
- π **[
|
|
21
|
-
- πΌοΈ **[
|
|
22
|
-
- πΊ **[
|
|
23
|
-
- π§± **[
|
|
15
|
+
- π¦ **[Array](./basics/array.md)** β A tiny utility for shuffling arrays using the FisherβYates algorithm.
|
|
16
|
+
- β° **[Clock](./basics/clock.md)** β A versatile time utility module for calculating and formatting time durations.
|
|
17
|
+
- π§ **[ObjFilter](./basics/objFilter.md)** β Type detection, extension, and analysis made easy with simple and extensible type validation.
|
|
18
|
+
- π’ **[SimpleMath](./basics/simpleMath.md)** β A collection of simple math utilities for calculations like the Rule of Three and percentages.
|
|
19
|
+
- βοΈ **[Text](./basics/text.md)** β A utility for transforming text into title case formats, with multiple options for capitalization.
|
|
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
|
+
- π§± **[Collision](./basics/collision.md)** β Full-featured rectangle collision detection system with directional analysis, depth calculation, and center offset metrics.
|
|
24
24
|
|
|
25
25
|
### 2. **`libs/`**
|
|
26
26
|
- ποΈ **[TinyPromiseQueue](./libs/TinyPromiseQueue.md)** β A class that allows sequential execution of asynchronous tasks, supporting task delays, cancellation, and queue management.
|
|
@@ -34,9 +34,10 @@ This folder contains the core scripts we have worked on so far. Each file is a m
|
|
|
34
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.
|
|
35
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.
|
|
36
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.
|
|
37
38
|
|
|
38
39
|
### 3. **`fileManager/`**
|
|
39
|
-
* π **[
|
|
40
|
+
* π **[Main](./fileManager/main.md)** β A Node.js file/directory utility module with support for JSON, backups, renaming, size analysis, and more.
|
|
40
41
|
|
|
41
42
|
---
|
|
42
43
|
|
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.
|
|
@@ -266,84 +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
|
-
### ποΈ `isInViewport(element)`
|
|
283
|
-
|
|
284
|
-
π Checks if an element is **partially visible** in the current viewport.
|
|
285
|
-
|
|
286
|
-
```js
|
|
287
|
-
isInViewport(element: HTMLElement): boolean
|
|
288
|
-
```
|
|
289
|
-
|
|
290
|
-
* `element`: The DOM element to check.
|
|
291
|
-
* **Returns**: `true` if the element is at least partially visible; `false` otherwise.
|
|
292
|
-
|
|
293
|
-
---
|
|
294
|
-
|
|
295
|
-
### β
`isScrolledIntoView(element)`
|
|
296
|
-
|
|
297
|
-
π¦ Checks if an element is **fully visible** (top and bottom) within the viewport.
|
|
298
|
-
|
|
299
|
-
```js
|
|
300
|
-
isScrolledIntoView(element: HTMLElement): boolean
|
|
301
|
-
```
|
|
302
|
-
|
|
303
|
-
* `element`: The DOM element to check.
|
|
304
|
-
* **Returns**: `true` if the entire element is within the viewport; `false` otherwise.
|
|
305
|
-
|
|
306
|
-
---
|
|
307
|
-
|
|
308
|
-
### π³ `getHtmlElBorders(el)`
|
|
309
|
-
|
|
310
|
-
π Returns the total **border size** of an element using `border{Side}` shorthand values from computed styles.
|
|
311
|
-
|
|
312
|
-
```js
|
|
313
|
-
getHtmlElBorders(el: Element): HtmlElBoxSides
|
|
314
|
-
```
|
|
315
|
-
|
|
316
|
-
* `el`: The target DOM element.
|
|
317
|
-
* **Returns**: An object with total horizontal/vertical border sizes and all four sides.
|
|
318
|
-
|
|
319
|
-
---
|
|
320
|
-
|
|
321
|
-
### β `getHtmlElMargin(el)`
|
|
322
|
-
|
|
323
|
-
π Returns the total **margin** of an element using `margin{Side}` from computed styles.
|
|
324
|
-
|
|
325
|
-
```js
|
|
326
|
-
getHtmlElMargin(el: Element): HtmlElBoxSides
|
|
327
|
-
```
|
|
328
|
-
|
|
329
|
-
* `el`: The target DOM element.
|
|
330
|
-
* **Returns**: An object containing margin values for each side and totals for horizontal (`x`) and vertical (`y`).
|
|
331
|
-
|
|
332
|
-
---
|
|
333
|
-
|
|
334
|
-
### β `getHtmlElPadding(el)`
|
|
335
|
-
|
|
336
|
-
π§© Returns the total **padding** of an element using `padding{Side}` from computed styles.
|
|
337
|
-
|
|
338
|
-
```js
|
|
339
|
-
getHtmlElPadding(el: Element): HtmlElBoxSides
|
|
340
|
-
```
|
|
341
|
-
|
|
342
|
-
* `el`: The target DOM element.
|
|
343
|
-
* **Returns**: Padding values for all sides and summed horizontal (`x`) and vertical (`y`) values.
|
|
344
|
-
|
|
345
|
-
---
|
|
346
|
-
|
|
347
217
|
### π `installWindowHiddenScript`
|
|
348
218
|
|
|
349
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.
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
# π TinyAfterScrollWatcher
|
|
2
|
+
|
|
3
|
+
A minimalistic scroll watcher that queues and executes functions **after scrolling has stopped** on a given element or the window.
|
|
4
|
+
Perfect for optimizing logic that should only run **after** the user has finished scrolling.
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## π Features
|
|
9
|
+
|
|
10
|
+
* β
Works on any scrollable element or the window
|
|
11
|
+
* β±οΈ Customizable "inactivity timeout" (default: `100ms`)
|
|
12
|
+
* π§ Executes queued callbacks after scroll ends
|
|
13
|
+
* π§© Add/remove your own scroll listeners easily (`onScroll` / `offScroll`)
|
|
14
|
+
* π§Ή Cleanly destroy the instance when no longer needed
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## π¦ Import
|
|
19
|
+
|
|
20
|
+
```js
|
|
21
|
+
import TinyAfterScrollWatcher from './TinyAfterScrollWatcher.mjs';
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## π§ͺ Example
|
|
27
|
+
|
|
28
|
+
```js
|
|
29
|
+
const watcher = new TinyAfterScrollWatcher(window);
|
|
30
|
+
|
|
31
|
+
// Optional: set a custom delay (in ms)
|
|
32
|
+
watcher.inactivityTime = 300;
|
|
33
|
+
|
|
34
|
+
// Add a function to run after scroll has stopped
|
|
35
|
+
watcher.doAfterScroll(() => {
|
|
36
|
+
console.log('Scroll has stopped for 300ms!');
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
// Add a custom scroll listener
|
|
40
|
+
const myScrollHandler = () => console.log('Scrolling...');
|
|
41
|
+
watcher.onScroll(myScrollHandler);
|
|
42
|
+
|
|
43
|
+
// Remove it later
|
|
44
|
+
watcher.offScroll(myScrollHandler);
|
|
45
|
+
|
|
46
|
+
// Fully destroy the watcher
|
|
47
|
+
watcher.destroy();
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## π§ Class: `TinyAfterScrollWatcher`
|
|
53
|
+
|
|
54
|
+
### π§ Constructor
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
new TinyAfterScrollWatcher(scrollTarget?: Element | Window, inactivityTime?: number)
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
#### Parameters:
|
|
61
|
+
|
|
62
|
+
| Name | Type | Default | Description |
|
|
63
|
+
| ---------------- | ------------------- | -------- | ---------------------------------------------------------------------- |
|
|
64
|
+
| `scrollTarget` | `Element \| Window` | `window` | The scrollable element to watch. Can also be the global `window`. |
|
|
65
|
+
| `inactivityTime` | `number` | `100` | Milliseconds to wait after the last scroll before executing the queue. |
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
### β²οΈ Property: `inactivityTime`
|
|
70
|
+
|
|
71
|
+
* **Type:** `number`
|
|
72
|
+
* **Getter/Setter**
|
|
73
|
+
|
|
74
|
+
Defines how many milliseconds to wait after scroll stops before executing the queue.
|
|
75
|
+
|
|
76
|
+
#### Example:
|
|
77
|
+
|
|
78
|
+
```js
|
|
79
|
+
watcher.inactivityTime = 500;
|
|
80
|
+
console.log(watcher.inactivityTime); // 500
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
#### Throws:
|
|
84
|
+
|
|
85
|
+
* `TypeError` if the value is not a finite positive number.
|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
### π§© Method: `doAfterScroll(fn)`
|
|
90
|
+
|
|
91
|
+
Adds a function to the queue that runs once scroll has stopped for the configured delay.
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
doAfterScroll(fn: FnData): void
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
#### Parameters:
|
|
98
|
+
|
|
99
|
+
| Name | Type | Description |
|
|
100
|
+
| ---- | -------- | ------------------------------------ |
|
|
101
|
+
| `fn` | `FnData` | Function to run after scrolling ends |
|
|
102
|
+
|
|
103
|
+
#### Throws:
|
|
104
|
+
|
|
105
|
+
* `TypeError` if the argument is not a function.
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
### π§· Method: `onScroll(fn)`
|
|
110
|
+
|
|
111
|
+
Registers a custom scroll listener on the tracked element.
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
onScroll(fn: OnScrollFunc): void
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
#### Parameters:
|
|
118
|
+
|
|
119
|
+
| Name | Type | Description |
|
|
120
|
+
| ---- | -------------- | --------------------------------------- |
|
|
121
|
+
| `fn` | `OnScrollFunc` | The listener function for scroll events |
|
|
122
|
+
|
|
123
|
+
#### Throws:
|
|
124
|
+
|
|
125
|
+
* `TypeError` if the argument is not a function.
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
### ποΈ Method: `offScroll(fn)`
|
|
130
|
+
|
|
131
|
+
Removes a previously registered scroll listener.
|
|
132
|
+
|
|
133
|
+
```ts
|
|
134
|
+
offScroll(fn: OnScrollFunc): void
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
#### Parameters:
|
|
138
|
+
|
|
139
|
+
| Name | Type | Description |
|
|
140
|
+
| ---- | -------------- | ----------------------------- |
|
|
141
|
+
| `fn` | `OnScrollFunc` | The scroll listener to remove |
|
|
142
|
+
|
|
143
|
+
#### Throws:
|
|
144
|
+
|
|
145
|
+
* `TypeError` if the argument is not a function.
|
|
146
|
+
|
|
147
|
+
---
|
|
148
|
+
|
|
149
|
+
### π£ Method: `destroy()`
|
|
150
|
+
|
|
151
|
+
Cleans up all internal and external listeners.
|
|
152
|
+
Once destroyed, the instance stops functioning and cannot be reused.
|
|
153
|
+
|
|
154
|
+
```ts
|
|
155
|
+
destroy(): void
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
---
|
|
159
|
+
|
|
160
|
+
## π§Ύ Typedefs
|
|
161
|
+
|
|
162
|
+
```ts
|
|
163
|
+
/**
|
|
164
|
+
* A function with no parameters and no return value.
|
|
165
|
+
*/
|
|
166
|
+
type FnData = () => void;
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* A function that handles a scroll event.
|
|
170
|
+
* It receives a standard `Event` object when a scroll occurs.
|
|
171
|
+
*/
|
|
172
|
+
type OnScrollFunc = (ev: Event) => void;
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
---
|
|
176
|
+
|
|
177
|
+
## π Notes
|
|
178
|
+
|
|
179
|
+
* The scroll queue is **LIFO** (last-in, first-out)
|
|
180
|
+
* The internal check loop uses `requestAnimationFrame`, so it's efficient
|
|
181
|
+
* Setting `inactivityTime` to a lower value makes it more sensitive
|
|
@@ -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:
|