tiny-essentials 1.16.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.
@@ -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
@@ -1331,3 +1331,328 @@ Checks if the element is **fully inside** the viewport โ€” meaning:
1331
1331
  ```js
1332
1332
  TinyHtml.isScrolledIntoView(element);
1333
1333
  ```
1334
+
1335
+ ---
1336
+
1337
+ ## ๐ŸŽจ CSS Property Aliases (`cssPropAliases`)
1338
+
1339
+ TinyHtml provides automatic conversion between `camelCase` and `kebab-case` style properties to simplify working with inline styles in HTML elements.
1340
+
1341
+ This is useful for working with both JavaScript style names and the raw `style=""` attribute.
1342
+
1343
+ ### ๐Ÿ” Alias Mapping
1344
+
1345
+ The object `cssPropAliases` maps JavaScript-style property names (`camelCase`) to their CSS equivalents (`kebab-case`), for example:
1346
+
1347
+ ```js
1348
+ TinyHtml.cssPropAliases.backgroundColor; // "background-color"
1349
+ ```
1350
+
1351
+ โš ๏ธ Do not modify the internal `#cssPropAliases` object directly. Instead, use the `TinyHtml.cssPropAliases` proxy.
1352
+
1353
+ ### โœ๏ธ Adding a New Alias
1354
+
1355
+ To add a new alias and automatically generate the reverse mapping:
1356
+
1357
+ ```js
1358
+ TinyHtml.cssPropAliases.tinyPudding = 'tiny-pudding';
1359
+ ```
1360
+
1361
+ This will automatically make this available:
1362
+
1363
+ ```js
1364
+ TinyHtml.cssPropRevAliases['tiny-pudding']; // "tinyPudding"
1365
+ ```
1366
+
1367
+ ---
1368
+
1369
+ ## โœ‚๏ธ Utility Functions
1370
+
1371
+ ### ๐Ÿ”ก `TinyHtml.toStyleKc(str)`
1372
+
1373
+ Converts a camelCase property to kebab-case if it exists in the alias list.
1374
+
1375
+ ```js
1376
+ TinyHtml.toStyleKc('marginLeft'); // "margin-left"
1377
+ ```
1378
+
1379
+ ### ๐Ÿ”ก `TinyHtml.toStyleCc(str)`
1380
+
1381
+ Converts a kebab-case property to camelCase if it exists in the reverse alias list.
1382
+
1383
+ ```js
1384
+ TinyHtml.toStyleCc('font-weight'); // "fontWeight"
1385
+ ```
1386
+
1387
+ ---
1388
+
1389
+ ## ๐Ÿงฉ Style Methods
1390
+
1391
+ ### ๐ŸŽฏ `TinyHtml.setStyle(el, prop, value)`
1392
+
1393
+ Sets one or more inline CSS properties on an element or a list of elements.
1394
+
1395
+ ```js
1396
+ TinyHtml.setStyle(element, 'backgroundColor', 'blue');
1397
+
1398
+ TinyHtml.setStyle(element, {
1399
+ fontSize: '14px',
1400
+ color: 'white',
1401
+ });
1402
+ ```
1403
+
1404
+ ---
1405
+
1406
+ ### ๐Ÿ” `TinyHtml.getStyle(el, prop)`
1407
+
1408
+ Returns the value of an inline style property (not computed).
1409
+
1410
+ ```js
1411
+ TinyHtml.getStyle(element, 'backgroundColor'); // "blue"
1412
+ ```
1413
+
1414
+ ---
1415
+
1416
+ ### ๐Ÿงพ `TinyHtml.style(el, settings = {})`
1417
+
1418
+ Returns all inline styles defined directly on the element (`style` attribute), as an object.
1419
+
1420
+ You can customize the output by passing an optional settings object:
1421
+
1422
+ * `camelCase` (`boolean`, default `false`) โ€“ If `true`, property names will be returned in camelCase format.
1423
+ * `rawAttr` (`boolean`, default `false`) โ€“ If `true`, the raw `style` attribute string will be parsed manually instead of using the element's `style` object.
1424
+
1425
+ #### โœ… Examples
1426
+
1427
+ ```js
1428
+ TinyHtml.style(element, { rawAttr: true, camelCase: false });
1429
+ // {
1430
+ // "background-color": "tomato",
1431
+ // "border-radius": "10px"
1432
+ // }
1433
+
1434
+ TinyHtml.style(element, { rawAttr: true, camelCase: true });
1435
+ // {
1436
+ // backgroundColor: "tomato",
1437
+ // borderRadius: "10px"
1438
+ // }
1439
+
1440
+ TinyHtml.style(element, { rawAttr: false, camelCase: true });
1441
+ // {
1442
+ // "backgroundColor":"tomato",
1443
+ // "borderTopLeftRadius":"10px",
1444
+ // "borderTopRightRadius":"10px",
1445
+ // "borderBottomRightRadius":"10px",
1446
+ // "borderBottomLeftRadius":"10px",
1447
+ // "borderTopStyle":"dashed",
1448
+ // "borderRightStyle":"dashed",
1449
+ // "borderBottomStyle":"dashed",
1450
+ // "borderLeftStyle":"dashed"
1451
+ // }
1452
+ ```
1453
+
1454
+ ---
1455
+
1456
+ ### โŒ `TinyHtml.removeStyle(el, prop)`
1457
+
1458
+ Removes one or more properties from an elementโ€™s inline styles.
1459
+
1460
+ ```js
1461
+ TinyHtml.removeStyle(element, 'color');
1462
+
1463
+ TinyHtml.removeStyle(element, ['fontSize', 'padding']);
1464
+ ```
1465
+
1466
+ ---
1467
+
1468
+ ### ๐Ÿ” `TinyHtml.toggleStyle(el, prop, val1, val2)`
1469
+
1470
+ Toggles a CSS inline property between two values.
1471
+
1472
+ ```js
1473
+ TinyHtml.toggleStyle(element, 'backgroundColor', 'blue', 'red');
1474
+ ```
1475
+
1476
+ ---
1477
+
1478
+ ### ๐Ÿงผ `TinyHtml.clearStyle(el)`
1479
+
1480
+ Removes all inline styles (`style=""`) from the element(s).
1481
+
1482
+ ```js
1483
+ TinyHtml.clearStyle(element);
1484
+ ```
1485
+
1486
+ ---
1487
+
1488
+ ## ๐Ÿงช Reading Computed Styles
1489
+
1490
+ TinyHtml provides multiple utilities for reading CSS styles from elements, both individually and in groups, using computed values (via `window.getComputedStyle`).
1491
+
1492
+ ---
1493
+
1494
+ ### ๐Ÿงฌ `TinyHtml.css(el)` / `el.css()`
1495
+
1496
+ Returns the full computed style object for a given element.
1497
+
1498
+ ```js
1499
+ const style = TinyHtml.css(element);
1500
+
1501
+ // or using instance:
1502
+ const style = myTinyElem.css();
1503
+ ```
1504
+
1505
+ **Returns:**
1506
+ `CSSStyleDeclaration` โ€“ all computed styles from the browser.
1507
+
1508
+ ---
1509
+
1510
+ ### ๐Ÿ” `TinyHtml.cssString(el, prop)` / `el.cssString(prop)`
1511
+
1512
+ Returns a specific **computed CSS value as a string**.
1513
+
1514
+ ```js
1515
+ myTinyElem.cssString('marginTop'); // "10px"
1516
+ ```
1517
+
1518
+ **Returns:**
1519
+ `string | null` โ€“ The computed value of the property, or `null` if invalid.
1520
+
1521
+ ---
1522
+
1523
+ ### ๐Ÿ“‘ `TinyHtml.cssList(el, props[])` / `el.cssList(props[])`
1524
+
1525
+ Returns a **subset of computed styles** based on a list of property names.
1526
+
1527
+ ```js
1528
+ TinyHtml.cssList(element, ['width', 'height']);
1529
+ // { width: "120px", height: "40px" }
1530
+ ```
1531
+
1532
+ **Returns:**
1533
+ `Partial<CSSStyleDeclaration>` โ€“ only the requested properties.
1534
+
1535
+ ---
1536
+
1537
+ ### ๐Ÿ”ข `TinyHtml.cssFloat(el, prop)` / `el.cssFloat(prop)`
1538
+
1539
+ Returns the **computed value parsed as a float number**.
1540
+
1541
+ ```js
1542
+ myTinyElem.cssFloat('width'); // 120
1543
+ ```
1544
+
1545
+ This is useful when working with dimensions or numeric spacing.
1546
+
1547
+ **Returns:**
1548
+ `number` โ€“ A parsed float, or `0` if invalid.
1549
+
1550
+ ---
1551
+
1552
+ ### ๐Ÿ”ข๐Ÿ”ข `TinyHtml.cssFloats(el, props[])` / `el.cssFloats(props[])`
1553
+
1554
+ Gets multiple computed CSS float values at once.
1555
+
1556
+ ```js
1557
+ myTinyElem.cssFloats(['paddingTop', 'paddingBottom']);
1558
+ // { paddingTop: 10, paddingBottom: 5 }
1559
+ ```
1560
+
1561
+ **Returns:**
1562
+ `Record<string, number>` โ€“ A mapping of property names to their float values.
1563
+
1564
+ ---
1565
+
1566
+ ## ๐Ÿ–ฑ๏ธ Focus & Blur
1567
+
1568
+ TinyHtml provides utility methods to programmatically focus or blur HTML elements.
1569
+
1570
+ ### โœจ `TinyHtml.focus(el)` / `el.focus()`
1571
+
1572
+ Focuses the specified element.
1573
+
1574
+ ```js
1575
+ TinyHtml.focus(element);
1576
+ // or
1577
+ tinyElem.focus();
1578
+ ```
1579
+
1580
+ ---
1581
+
1582
+ ### ๐ŸŒซ๏ธ `TinyHtml.blur(el)` / `el.blur()`
1583
+
1584
+ Removes focus from the specified element.
1585
+
1586
+ ```js
1587
+ TinyHtml.blur(element);
1588
+ // or
1589
+ tinyElem.blur();
1590
+ ```
1591
+
1592
+ ---
1593
+
1594
+ ## ๐ŸŒ Window Scroll & Viewport Helpers
1595
+
1596
+ These methods let you control and query scroll positions and viewport size with simple, readable functions.
1597
+
1598
+ ---
1599
+
1600
+ ### ๐Ÿ”ฝ `TinyHtml.setWinScrollTop(value)`
1601
+
1602
+ Scrolls the window vertically to the given pixel value.
1603
+
1604
+ ```js
1605
+ TinyHtml.setWinScrollTop(500);
1606
+ ```
1607
+
1608
+ ---
1609
+
1610
+ ### โฌ…๏ธ `TinyHtml.setWinScrollLeft(value)`
1611
+
1612
+ Scrolls the window horizontally to the given pixel value.
1613
+
1614
+ ```js
1615
+ TinyHtml.setWinScrollLeft(200);
1616
+ ```
1617
+
1618
+ ---
1619
+
1620
+ ### ๐Ÿ“ `TinyHtml.winScrollTop()`
1621
+
1622
+ Returns the current vertical scroll position.
1623
+
1624
+ ```js
1625
+ const y = TinyHtml.winScrollTop(); // e.g., 512
1626
+ ```
1627
+
1628
+ ---
1629
+
1630
+ ### ๐Ÿ“ `TinyHtml.winScrollLeft()`
1631
+
1632
+ Returns the current horizontal scroll position.
1633
+
1634
+ ```js
1635
+ const x = TinyHtml.winScrollLeft(); // e.g., 100
1636
+ ```
1637
+
1638
+ ---
1639
+
1640
+ ### ๐ŸชŸ `TinyHtml.winInnerHeight()`
1641
+
1642
+ Returns the height of the visible viewport in pixels.
1643
+
1644
+ ```js
1645
+ const height = TinyHtml.winInnerHeight(); // e.g., 1080
1646
+ ```
1647
+
1648
+ ---
1649
+
1650
+ ### ๐ŸชŸ `TinyHtml.winInnerWidth()`
1651
+
1652
+ Returns the width of the visible viewport in pixels.
1653
+
1654
+ ```js
1655
+ const width = TinyHtml.winInnerWidth(); // e.g., 2560
1656
+ ```
1657
+
1658
+ ---
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tiny-essentials",
3
- "version": "1.16.0",
3
+ "version": "1.16.1",
4
4
  "description": "Collection of small, essential scripts designed to be used across various projects. These simple utilities are crafted for speed, ease of use, and versatility.",
5
5
  "scripts": {
6
6
  "test": "npm run test:mjs && npm run test:cjs && npm run test:js",