tiny-essentials 1.20.0 → 1.20.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/TinyBasicsEs.min.js +1 -1
- package/dist/v1/TinyDragger.min.js +1 -1
- package/dist/v1/TinyEssentials.min.js +1 -1
- package/dist/v1/TinyHtml.min.js +1 -1
- package/dist/v1/TinySmartScroller.min.js +1 -1
- package/dist/v1/TinyUploadClicker.min.js +1 -1
- package/dist/v1/libs/TinyDragger.cjs +1 -1
- package/dist/v1/libs/TinyDragger.mjs +1 -1
- package/dist/v1/libs/TinyHtml.cjs +292 -103
- package/dist/v1/libs/TinyHtml.d.mts +142 -39
- package/dist/v1/libs/TinyHtml.mjs +266 -94
- package/dist/v1/libs/TinyIframeEvents.cjs +2 -1
- package/dist/v1/libs/TinyNewWinEvents.cjs +4 -2
- package/docs/v1/libs/TinyHtml.md +128 -6
- package/package.json +1 -1
- package/dist/v1/ColorSafeStringify.js +0 -235
- package/dist/v1/TinyAfterScrollWatcher.js +0 -219
- package/dist/v1/TinyBasicsEs.js +0 -9334
- package/dist/v1/TinyClipboard.js +0 -459
- package/dist/v1/TinyColorConverter.js +0 -617
- package/dist/v1/TinyDomReadyManager.js +0 -213
- package/dist/v1/TinyDragDropDetector.js +0 -307
- package/dist/v1/TinyDragger.js +0 -6569
- package/dist/v1/TinyEssentials.js +0 -20792
- package/dist/v1/TinyEvents.js +0 -402
- package/dist/v1/TinyHtml.js +0 -5545
- package/dist/v1/TinyIframeEvents.js +0 -854
- package/dist/v1/TinyLevelUp.js +0 -291
- package/dist/v1/TinyLocalStorage.js +0 -1440
- package/dist/v1/TinyNewWinEvents.js +0 -888
- package/dist/v1/TinyNotifications.js +0 -408
- package/dist/v1/TinyNotifyCenter.js +0 -493
- package/dist/v1/TinyPromiseQueue.js +0 -299
- package/dist/v1/TinyRateLimiter.js +0 -611
- package/dist/v1/TinySmartScroller.js +0 -7039
- package/dist/v1/TinyTextRangeEditor.js +0 -497
- package/dist/v1/TinyTimeout.js +0 -233
- package/dist/v1/TinyToastNotify.js +0 -441
- package/dist/v1/TinyUploadClicker.js +0 -14353
- package/dist/v1/UltraRandomMsgGen.js +0 -995
package/docs/v1/libs/TinyHtml.md
CHANGED
|
@@ -310,6 +310,40 @@ HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement | HTMLOptionElement
|
|
|
310
310
|
|
|
311
311
|
---
|
|
312
312
|
|
|
313
|
+
## 🔨 Element Creation
|
|
314
|
+
|
|
315
|
+
### `TinyHtml.createFrom(tagName, attrs?)`
|
|
316
|
+
|
|
317
|
+
Creates a new `TinyHtml` element from a given tag name and optional attributes.
|
|
318
|
+
|
|
319
|
+
* **Parameters**:
|
|
320
|
+
|
|
321
|
+
* `tagName` *(string)* — The HTML tag name (e.g., `'div'`, `'span'`, `'button'`).
|
|
322
|
+
* `attrs` *(object)* — *(optional)* Key-value pairs representing HTML attributes.
|
|
323
|
+
|
|
324
|
+
* **Returns**: `TinyHtml` — A new `TinyHtml` instance representing the created element.
|
|
325
|
+
|
|
326
|
+
* **Throws**:
|
|
327
|
+
|
|
328
|
+
* `TypeError` — If `tagName` is not a string.
|
|
329
|
+
* `TypeError` — If `attrs` is defined but not a plain object.
|
|
330
|
+
|
|
331
|
+
### 💡 Example
|
|
332
|
+
|
|
333
|
+
```js
|
|
334
|
+
const div = TinyHtml.createFrom('div', { class: 'container' });
|
|
335
|
+
const span = TinyHtml.createFrom('span', { id: 'my-span', title: null });
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
The method can also be aliased for convenience:
|
|
339
|
+
|
|
340
|
+
```js
|
|
341
|
+
const createElement = TinyHtml.createFrom;
|
|
342
|
+
const button = createElement('button', { type: 'submit', class: 'btn' });
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
---
|
|
346
|
+
|
|
313
347
|
## 🔎 Static DOM Selectors
|
|
314
348
|
|
|
315
349
|
These methods wrap native DOM query methods and return results as `TinyHtml` instances for consistency.
|
|
@@ -377,7 +411,7 @@ Finds the first element by CSS selector.
|
|
|
377
411
|
### `TinyHtml.queryAll(selector)`
|
|
378
412
|
Finds all elements by CSS selector.
|
|
379
413
|
|
|
380
|
-
- **Returns**: `TinyHtml
|
|
414
|
+
- **Returns**: `TinyHtml`
|
|
381
415
|
|
|
382
416
|
---
|
|
383
417
|
|
|
@@ -393,38 +427,64 @@ Selects an element by ID.
|
|
|
393
427
|
### `TinyHtml.getByClassName(selector)`
|
|
394
428
|
Finds elements by class name.
|
|
395
429
|
|
|
396
|
-
- **Returns**: `TinyHtml
|
|
430
|
+
- **Returns**: `TinyHtml`
|
|
397
431
|
|
|
398
432
|
---
|
|
399
433
|
|
|
400
434
|
### `TinyHtml.getByName(selector)`
|
|
401
435
|
Finds elements by `name` attribute.
|
|
402
436
|
|
|
403
|
-
- **Returns**: `TinyHtml
|
|
437
|
+
- **Returns**: `TinyHtml`
|
|
404
438
|
|
|
405
439
|
---
|
|
406
440
|
|
|
407
441
|
### `TinyHtml.getByTagNameNS(localName, namespaceURI?)`
|
|
408
442
|
Finds elements by tag name in a namespace (defaults to XHTML).
|
|
409
443
|
|
|
410
|
-
- **Returns**: `TinyHtml
|
|
444
|
+
- **Returns**: `TinyHtml`
|
|
411
445
|
|
|
412
446
|
---
|
|
413
447
|
|
|
414
448
|
## 🧩 Internal Element Access
|
|
415
449
|
|
|
416
|
-
### `
|
|
450
|
+
### `exists(index)`
|
|
451
|
+
Checks whether the element exists at the given index.
|
|
452
|
+
|
|
453
|
+
- **Returns**: `boolean`
|
|
454
|
+
|
|
455
|
+
---
|
|
456
|
+
|
|
457
|
+
### `get(index)`
|
|
417
458
|
Returns the raw DOM element associated with this instance.
|
|
418
459
|
|
|
419
460
|
- **Returns**: `ConstructorElValues`
|
|
420
461
|
|
|
421
462
|
---
|
|
422
463
|
|
|
423
|
-
### `
|
|
464
|
+
### `extract(index)`
|
|
465
|
+
Extracts a single DOM element from the internal list at the specified index.
|
|
466
|
+
|
|
467
|
+
- **Returns**: `TinyHtml`
|
|
468
|
+
|
|
469
|
+
---
|
|
470
|
+
|
|
471
|
+
### `getAll()`
|
|
472
|
+
Returns the current targets held by this instance.
|
|
473
|
+
|
|
474
|
+
- **Returns**: `ConstructorElValues[]`
|
|
475
|
+
|
|
476
|
+
---
|
|
477
|
+
|
|
478
|
+
### `_getElement(where, index)`
|
|
424
479
|
Safely returns the element with error checking.
|
|
425
480
|
|
|
426
481
|
---
|
|
427
482
|
|
|
483
|
+
### `_getElements(where)`
|
|
484
|
+
Returns the current Elements held by this instance.
|
|
485
|
+
|
|
486
|
+
---
|
|
487
|
+
|
|
428
488
|
## 🛠️ Static Pre-Validation Utilities
|
|
429
489
|
|
|
430
490
|
These methods normalize, validate, and prepare elements/nodes before operations. They're internal and mainly used inside the class.
|
|
@@ -1719,6 +1779,68 @@ TinyHtml.hasScroll(element);
|
|
|
1719
1779
|
|
|
1720
1780
|
---
|
|
1721
1781
|
|
|
1782
|
+
## 🧠 Property Name Normalization
|
|
1783
|
+
|
|
1784
|
+
The object `TinyHtml.propFix` maps HTML attribute names (as strings) to their corresponding JavaScript DOM property names. This works similarly to jQuery’s `propFix`.
|
|
1785
|
+
|
|
1786
|
+
```js
|
|
1787
|
+
TinyHtml.propFix['for']; // "htmlFor"
|
|
1788
|
+
TinyHtml.propFix['class']; // "className"
|
|
1789
|
+
```
|
|
1790
|
+
|
|
1791
|
+
⚠️ **Do not modify** the internal `#propFix` object directly. Instead, use `TinyHtml.propFix` (the public proxy) to ensure the reverse mapping in `TinyHtml.attrFix` stays in sync.
|
|
1792
|
+
|
|
1793
|
+
### ✍️ Adding a New Property Mapping
|
|
1794
|
+
|
|
1795
|
+
To add a new property normalization:
|
|
1796
|
+
|
|
1797
|
+
```js
|
|
1798
|
+
TinyHtml.propFix['readonly'] = 'readOnly';
|
|
1799
|
+
```
|
|
1800
|
+
|
|
1801
|
+
This will automatically make this available:
|
|
1802
|
+
|
|
1803
|
+
```js
|
|
1804
|
+
TinyHtml.attrFix['readOnly']; // "readonly"
|
|
1805
|
+
```
|
|
1806
|
+
|
|
1807
|
+
---
|
|
1808
|
+
|
|
1809
|
+
## 🔁 Attribute ↔ Property Mapping
|
|
1810
|
+
|
|
1811
|
+
### 🧭 `TinyHtml.getPropName(name)`
|
|
1812
|
+
|
|
1813
|
+
Normalizes an HTML attribute name to its corresponding DOM property name.
|
|
1814
|
+
|
|
1815
|
+
```js
|
|
1816
|
+
TinyHtml.getPropName('for'); // "htmlFor"
|
|
1817
|
+
TinyHtml.getPropName('class'); // "className"
|
|
1818
|
+
TinyHtml.getPropName('title'); // "title" (not mapped, returns input)
|
|
1819
|
+
```
|
|
1820
|
+
|
|
1821
|
+
Useful when setting DOM properties programmatically.
|
|
1822
|
+
|
|
1823
|
+
### 🧭 `TinyHtml.getAttrName(name)`
|
|
1824
|
+
|
|
1825
|
+
Converts a DOM property name back to its equivalent HTML attribute name.
|
|
1826
|
+
|
|
1827
|
+
```js
|
|
1828
|
+
TinyHtml.getAttrName('htmlFor'); // "for"
|
|
1829
|
+
TinyHtml.getAttrName('className'); // "class"
|
|
1830
|
+
TinyHtml.getAttrName('title'); // "title" (not mapped, returns input)
|
|
1831
|
+
```
|
|
1832
|
+
|
|
1833
|
+
Useful when serializing an element back to HTML or attributes.
|
|
1834
|
+
|
|
1835
|
+
### 🔄 Behind the Scenes
|
|
1836
|
+
|
|
1837
|
+
* `TinyHtml.propFix` (public) is a proxy of the internal `#propFix` object.
|
|
1838
|
+
* `TinyHtml.attrFix` is auto-generated from `#propFix`, mapping values back in reverse.
|
|
1839
|
+
|
|
1840
|
+
These mappings are kept **in sync automatically** whenever you assign a new property to `TinyHtml.propFix`.
|
|
1841
|
+
|
|
1842
|
+
---
|
|
1843
|
+
|
|
1722
1844
|
## 🎨 CSS Property Aliases (`cssPropAliases`)
|
|
1723
1845
|
|
|
1724
1846
|
TinyHtml provides automatic conversion between `camelCase` and `kebab-case` style properties to simplify working with inline styles in HTML elements.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tiny-essentials",
|
|
3
|
-
"version": "1.20.
|
|
3
|
+
"version": "1.20.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",
|
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
/******/ (() => { // webpackBootstrap
|
|
2
|
-
/******/ "use strict";
|
|
3
|
-
/******/ // The require scope
|
|
4
|
-
/******/ var __webpack_require__ = {};
|
|
5
|
-
/******/
|
|
6
|
-
/************************************************************************/
|
|
7
|
-
/******/ /* webpack/runtime/define property getters */
|
|
8
|
-
/******/ (() => {
|
|
9
|
-
/******/ // define getter functions for harmony exports
|
|
10
|
-
/******/ __webpack_require__.d = (exports, definition) => {
|
|
11
|
-
/******/ for(var key in definition) {
|
|
12
|
-
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
|
13
|
-
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
|
14
|
-
/******/ }
|
|
15
|
-
/******/ }
|
|
16
|
-
/******/ };
|
|
17
|
-
/******/ })();
|
|
18
|
-
/******/
|
|
19
|
-
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
|
20
|
-
/******/ (() => {
|
|
21
|
-
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
22
|
-
/******/ })();
|
|
23
|
-
/******/
|
|
24
|
-
/************************************************************************/
|
|
25
|
-
var __webpack_exports__ = {};
|
|
26
|
-
|
|
27
|
-
// EXPORTS
|
|
28
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
29
|
-
ColorSafeStringify: () => (/* reexport */ libs_ColorSafeStringify)
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
;// ./src/v1/libs/ColorSafeStringify.mjs
|
|
33
|
-
/**
|
|
34
|
-
* @typedef {Record<string, string>} ColorsList
|
|
35
|
-
* Represents a mapping of color keys to ANSI escape codes.
|
|
36
|
-
*/
|
|
37
|
-
|
|
38
|
-
class ColorSafeStringify {
|
|
39
|
-
/**
|
|
40
|
-
* Currently active color configuration.
|
|
41
|
-
* @type {ColorsList}
|
|
42
|
-
*/
|
|
43
|
-
#colors;
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Preset collections (internal and user-defined).
|
|
47
|
-
* @type {Record<string, ColorsList>}
|
|
48
|
-
* @static
|
|
49
|
-
*/
|
|
50
|
-
static #PRESETS = {
|
|
51
|
-
default: {
|
|
52
|
-
reset: '\x1b[0m',
|
|
53
|
-
key: '\x1b[36m', // Cyan (object keys)
|
|
54
|
-
string: '\x1b[32m', // Green (regular strings)
|
|
55
|
-
string_url: '\x1b[34m', // Blue (URLs)
|
|
56
|
-
string_bool: '\x1b[35m', // Magenta (boolean/null in string form)
|
|
57
|
-
string_number: '\x1b[33m', // Yellow (numbers in string form)
|
|
58
|
-
number: '\x1b[33m', // Yellow (raw numbers)
|
|
59
|
-
boolean: '\x1b[35m', // Magenta (true/false)
|
|
60
|
-
null: '\x1b[1;30m', // Gray (null)
|
|
61
|
-
special: '\x1b[31m', // Red (e.g., [Circular], [undefined])
|
|
62
|
-
func: '\x1b[90m', // Dim (function string representations)
|
|
63
|
-
},
|
|
64
|
-
solarized: {
|
|
65
|
-
reset: '\x1b[0m',
|
|
66
|
-
key: '\x1b[38;5;37m',
|
|
67
|
-
string: '\x1b[38;5;136m',
|
|
68
|
-
string_url: '\x1b[38;5;33m',
|
|
69
|
-
string_bool: '\x1b[38;5;166m',
|
|
70
|
-
string_number: '\x1b[38;5;136m',
|
|
71
|
-
number: '\x1b[38;5;136m',
|
|
72
|
-
boolean: '\x1b[38;5;166m',
|
|
73
|
-
null: '\x1b[38;5;241m',
|
|
74
|
-
special: '\x1b[38;5;160m',
|
|
75
|
-
func: '\x1b[38;5;244m',
|
|
76
|
-
},
|
|
77
|
-
monokai: {
|
|
78
|
-
reset: '\x1b[0m',
|
|
79
|
-
key: '\x1b[38;5;81m',
|
|
80
|
-
string: '\x1b[38;5;114m',
|
|
81
|
-
string_url: '\x1b[38;5;75m',
|
|
82
|
-
string_bool: '\x1b[38;5;204m',
|
|
83
|
-
string_number: '\x1b[38;5;221m',
|
|
84
|
-
number: '\x1b[38;5;221m',
|
|
85
|
-
boolean: '\x1b[38;5;204m',
|
|
86
|
-
null: '\x1b[38;5;241m',
|
|
87
|
-
special: '\x1b[38;5;160m',
|
|
88
|
-
func: '\x1b[38;5;102m',
|
|
89
|
-
},
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Constructs a new instance with an optional base preset or custom override.
|
|
94
|
-
* @param {ColorsList} [defaultColors] - Optional override for the default color scheme.
|
|
95
|
-
*/
|
|
96
|
-
constructor(defaultColors = {}) {
|
|
97
|
-
this.#colors = { ...ColorSafeStringify.#PRESETS.default, ...defaultColors };
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Internal method to apply ANSI color codes to different parts of a JSON string.
|
|
102
|
-
* @param {string} str - Raw JSON string to be colorized.
|
|
103
|
-
* @param {ColorsList} colors - ANSI color mapping to be applied to each JSON element type.
|
|
104
|
-
* @returns {string} Colorized JSON string.
|
|
105
|
-
*/
|
|
106
|
-
#colorizeJSON(str, colors) {
|
|
107
|
-
/** @type {{ marker: string, key: string }[]} */
|
|
108
|
-
const keyMatches = [];
|
|
109
|
-
|
|
110
|
-
// Colorize numeric values
|
|
111
|
-
str = str.replace(
|
|
112
|
-
/(?<!")\b(-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?)\b(?!")/g,
|
|
113
|
-
`${colors.number}$1${colors.reset}`,
|
|
114
|
-
);
|
|
115
|
-
|
|
116
|
-
// Replace keys with temporary markers for later colorization
|
|
117
|
-
str = str.replace(/"([^"]+)":/g, (_, key) => {
|
|
118
|
-
const marker = `___KEY${keyMatches.length}___`;
|
|
119
|
-
keyMatches.push({ marker, key });
|
|
120
|
-
return `${marker}:`; // Keep the colon for valid syntax
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
// Replace strings and apply specific colors based on their content
|
|
124
|
-
str = str.replace(/"(?:\\.|[^"\\])*?"/g, (match) => {
|
|
125
|
-
const val = match.slice(1, -1); // Remove surrounding quotes
|
|
126
|
-
|
|
127
|
-
if (/^(https?|ftp):\/\/[^\s]+$/i.test(val)) {
|
|
128
|
-
return `${colors.string_url}${match}${colors.reset}`;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
if (/^(true|false|null)$/.test(val)) {
|
|
132
|
-
return `${colors.string_bool}${match}${colors.reset}`;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
if (/^-?\d+(\.\d+)?([eE][+-]?\d+)?$/.test(val)) {
|
|
136
|
-
return `${colors.string_number}${match}${colors.reset}`;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
return `${colors.string}${match}${colors.reset}`;
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
// Replace markers with colorized keys
|
|
143
|
-
for (const { marker, key } of keyMatches) {
|
|
144
|
-
const regex = new RegExp(marker, 'g');
|
|
145
|
-
str = str.replace(regex, `${colors.key}"${key}"${colors.reset}`);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// Colorize boolean values
|
|
149
|
-
str = str.replace(/(?<!")\b(true|false)\b(?!")/g, `${colors.boolean}$1${colors.reset}`);
|
|
150
|
-
|
|
151
|
-
// Colorize null values
|
|
152
|
-
str = str.replace(/(?<!")\bnull\b(?!")/g, `${colors.null}null${colors.reset}`);
|
|
153
|
-
|
|
154
|
-
// Highlight special placeholder values
|
|
155
|
-
str = str.replace(/\[Circular\]/g, `${colors.special}[Circular]${colors.reset}`);
|
|
156
|
-
str = str.replace(/\[undefined\]/g, `${colors.special}[undefined]${colors.reset}`);
|
|
157
|
-
|
|
158
|
-
// Colorize function string representations
|
|
159
|
-
str = str.replace(/"function.*?[^\\]"/gs, `${colors.func}$&${colors.reset}`);
|
|
160
|
-
return str;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* Colorizes a JSON string using the active or optionally overridden color set.
|
|
165
|
-
* @param {string} json - The JSON string to format.
|
|
166
|
-
* @param {ColorsList} [customColors] - Optional temporary color override.
|
|
167
|
-
* @returns {string}
|
|
168
|
-
*/
|
|
169
|
-
colorize(json, customColors = {}) {
|
|
170
|
-
const colors = { ...this.#colors, ...customColors };
|
|
171
|
-
return this.#colorizeJSON(json, colors);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* Returns the currently active color scheme.
|
|
176
|
-
* @returns {ColorsList}
|
|
177
|
-
*/
|
|
178
|
-
getColors() {
|
|
179
|
-
return { ...this.#colors };
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* Updates the current color scheme with a partial override.
|
|
184
|
-
* @param {Partial<ColorsList>} newColors
|
|
185
|
-
*/
|
|
186
|
-
updateColors(newColors) {
|
|
187
|
-
Object.assign(this.#colors, newColors);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
* Resets the current color scheme to the default preset.
|
|
192
|
-
*/
|
|
193
|
-
resetColors() {
|
|
194
|
-
this.#colors = { ...ColorSafeStringify.#PRESETS.default };
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* Loads a color preset by name.
|
|
199
|
-
* @param {string} presetName - Name of the preset to load.
|
|
200
|
-
* @throws Will throw if the preset doesn't exist.
|
|
201
|
-
*/
|
|
202
|
-
loadColorPreset(presetName) {
|
|
203
|
-
const preset = ColorSafeStringify.#PRESETS[presetName];
|
|
204
|
-
if (!preset) throw new Error(`Preset "${presetName}" not found.`);
|
|
205
|
-
this.#colors = { ...preset };
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
/**
|
|
209
|
-
* Saves a new custom color preset.
|
|
210
|
-
* @param {string} name - Name of the new preset.
|
|
211
|
-
* @param {ColorsList} colors - ANSI color map to save.
|
|
212
|
-
*/
|
|
213
|
-
saveColorPreset(name, colors) {
|
|
214
|
-
ColorSafeStringify.#PRESETS[name] = { ...colors };
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
* Returns a list of all available color preset names.
|
|
219
|
-
* @returns {string[]}
|
|
220
|
-
*/
|
|
221
|
-
getAvailablePresets() {
|
|
222
|
-
return Object.keys(ColorSafeStringify.#PRESETS);
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
/* harmony default export */ const libs_ColorSafeStringify = (ColorSafeStringify);
|
|
227
|
-
|
|
228
|
-
;// ./src/v1/build/ColorSafeStringify.mjs
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
window.ColorSafeStringify = __webpack_exports__.ColorSafeStringify;
|
|
234
|
-
/******/ })()
|
|
235
|
-
;
|
|
@@ -1,219 +0,0 @@
|
|
|
1
|
-
/******/ (() => { // webpackBootstrap
|
|
2
|
-
/******/ "use strict";
|
|
3
|
-
/******/ // The require scope
|
|
4
|
-
/******/ var __webpack_require__ = {};
|
|
5
|
-
/******/
|
|
6
|
-
/************************************************************************/
|
|
7
|
-
/******/ /* webpack/runtime/define property getters */
|
|
8
|
-
/******/ (() => {
|
|
9
|
-
/******/ // define getter functions for harmony exports
|
|
10
|
-
/******/ __webpack_require__.d = (exports, definition) => {
|
|
11
|
-
/******/ for(var key in definition) {
|
|
12
|
-
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
|
13
|
-
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
|
14
|
-
/******/ }
|
|
15
|
-
/******/ }
|
|
16
|
-
/******/ };
|
|
17
|
-
/******/ })();
|
|
18
|
-
/******/
|
|
19
|
-
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
|
20
|
-
/******/ (() => {
|
|
21
|
-
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
22
|
-
/******/ })();
|
|
23
|
-
/******/
|
|
24
|
-
/************************************************************************/
|
|
25
|
-
var __webpack_exports__ = {};
|
|
26
|
-
|
|
27
|
-
// EXPORTS
|
|
28
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
29
|
-
TinyAfterScrollWatcher: () => (/* reexport */ libs_TinyAfterScrollWatcher)
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
;// ./src/v1/libs/TinyAfterScrollWatcher.mjs
|
|
33
|
-
/**
|
|
34
|
-
* @typedef {(() => void)} FnData - Function with no arguments and no return value
|
|
35
|
-
*/
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* A function that handles a scroll event.
|
|
39
|
-
* It receives a standard `Event` object when a scroll occurs.
|
|
40
|
-
*
|
|
41
|
-
* @typedef {(ev: Event) => void} OnScrollFunc
|
|
42
|
-
*/
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* A scroll tracker that queues functions to be executed
|
|
46
|
-
* after the user stops scrolling a specific element or the window.
|
|
47
|
-
*/
|
|
48
|
-
class TinyAfterScrollWatcher {
|
|
49
|
-
/** @type {Element|Window} */
|
|
50
|
-
#scrollTarget;
|
|
51
|
-
|
|
52
|
-
/** @type {null|NodeJS.Timeout} */
|
|
53
|
-
#lastScrollTime = null;
|
|
54
|
-
|
|
55
|
-
/** @type {FnData[]} */
|
|
56
|
-
#afterScrollQueue = [];
|
|
57
|
-
|
|
58
|
-
/** @type {number} */
|
|
59
|
-
#inactivityTime = 100;
|
|
60
|
-
|
|
61
|
-
/** @type {Set<OnScrollFunc>} */
|
|
62
|
-
#externalScrollListeners = new Set();
|
|
63
|
-
|
|
64
|
-
/** @type {Set<FnData>} */
|
|
65
|
-
#onStopListeners = new Set();
|
|
66
|
-
|
|
67
|
-
/** @type {boolean} */
|
|
68
|
-
#destroyed = false;
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* @param {Element|Window} scrollTarget - The element or window to track scrolling on
|
|
72
|
-
* @param {number} [inactivityTime=100] - Time in milliseconds to wait after scroll ends before executing the queue
|
|
73
|
-
* @throws {TypeError} If scrollTarget is not a valid Element or Window
|
|
74
|
-
* @throws {TypeError} If inactivityTime is not a positive number
|
|
75
|
-
*/
|
|
76
|
-
constructor(scrollTarget = window, inactivityTime = 100) {
|
|
77
|
-
if (!(scrollTarget instanceof Element) && !(scrollTarget instanceof Window))
|
|
78
|
-
throw new TypeError('scrollTarget must be an Element or the Window object.');
|
|
79
|
-
this.#scrollTarget = scrollTarget;
|
|
80
|
-
this._checkTimer = this._checkTimer.bind(this);
|
|
81
|
-
|
|
82
|
-
this.#scrollTarget.addEventListener('scroll', this._checkTimer);
|
|
83
|
-
this.#inactivityTime = inactivityTime;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
_checkTimer = () => {
|
|
87
|
-
if (this.#lastScrollTime) clearTimeout(this.#lastScrollTime);
|
|
88
|
-
this.#lastScrollTime = setTimeout(() => {
|
|
89
|
-
this.#lastScrollTime = null;
|
|
90
|
-
this.#checkQueue();
|
|
91
|
-
}, this.#inactivityTime);
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Gets the current inactivity time in milliseconds.
|
|
96
|
-
* @returns {number}
|
|
97
|
-
*/
|
|
98
|
-
get inactivityTime() {
|
|
99
|
-
return this.#inactivityTime;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Sets a new inactivity time.
|
|
104
|
-
* Must be a positive number (in milliseconds).
|
|
105
|
-
* @param {number} value
|
|
106
|
-
* @throws {Error} If value is not a positive number
|
|
107
|
-
*/
|
|
108
|
-
set inactivityTime(value) {
|
|
109
|
-
if (typeof value !== 'number' || value <= 0 || !Number.isFinite(value))
|
|
110
|
-
throw new Error('inactivityTime must be a positive number in milliseconds.');
|
|
111
|
-
this.#inactivityTime = value;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Continuously checks whether the user has stopped scrolling,
|
|
116
|
-
* and if so, runs all queued functions.
|
|
117
|
-
*/
|
|
118
|
-
#checkQueue() {
|
|
119
|
-
if (this.#destroyed) return;
|
|
120
|
-
// Runs all onStop first listeners
|
|
121
|
-
for (const fn of this.#onStopListeners) {
|
|
122
|
-
if (typeof fn === 'function') fn();
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
// Then execute the queue afterScrollQueue
|
|
126
|
-
while (this.#afterScrollQueue.length) {
|
|
127
|
-
const fn = this.#afterScrollQueue.pop();
|
|
128
|
-
if (typeof fn === 'function') fn();
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Adds a function to be executed after scroll has stopped.
|
|
134
|
-
* The scroll is considered "stopped" after the configured inactivity time.
|
|
135
|
-
*
|
|
136
|
-
* @param {() => void} fn - A function to execute once scrolling has stopped.
|
|
137
|
-
* @throws {TypeError} If the argument is not a function.
|
|
138
|
-
*/
|
|
139
|
-
doAfterScroll(fn) {
|
|
140
|
-
if (typeof fn !== 'function') throw new TypeError('Argument must be a function.');
|
|
141
|
-
this.lastScrollTime = Date.now();
|
|
142
|
-
this.#afterScrollQueue.push(fn);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* Registers a function to run once after scrolling has stopped,
|
|
147
|
-
* before any afterScrollQueue functions.
|
|
148
|
-
*
|
|
149
|
-
* @param {FnData} fn - A function to execute after scroll stop.
|
|
150
|
-
* @throws {TypeError} If the argument is not a function.
|
|
151
|
-
*/
|
|
152
|
-
onStop(fn) {
|
|
153
|
-
if (typeof fn !== 'function') throw new TypeError('Argument must be a function.');
|
|
154
|
-
this.#onStopListeners.add(fn);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Removes a previously registered onStop function.
|
|
159
|
-
*
|
|
160
|
-
* @param {FnData} fn - The function to remove.
|
|
161
|
-
* @throws {TypeError} If the argument is not a function.
|
|
162
|
-
*/
|
|
163
|
-
offStop(fn) {
|
|
164
|
-
if (typeof fn !== 'function') throw new TypeError('Argument must be a function.');
|
|
165
|
-
this.#onStopListeners.delete(fn);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* Registers an external scroll listener on the tracked element.
|
|
170
|
-
*
|
|
171
|
-
* @param {OnScrollFunc} fn - The scroll listener to add
|
|
172
|
-
* @throws {TypeError} If the argument is not a function.
|
|
173
|
-
*/
|
|
174
|
-
onScroll(fn) {
|
|
175
|
-
if (typeof fn !== 'function') throw new TypeError('Argument must be a function.');
|
|
176
|
-
this.#scrollTarget.addEventListener('scroll', fn);
|
|
177
|
-
this.#externalScrollListeners.add(fn);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
/**
|
|
181
|
-
* Removes a previously registered scroll listener from the tracked element.
|
|
182
|
-
*
|
|
183
|
-
* @param {OnScrollFunc} fn - The scroll listener to remove
|
|
184
|
-
* @throws {TypeError} If the argument is not a function.
|
|
185
|
-
*/
|
|
186
|
-
offScroll(fn) {
|
|
187
|
-
if (typeof fn !== 'function') throw new TypeError('Argument must be a function.');
|
|
188
|
-
if (this.#externalScrollListeners.has(fn)) {
|
|
189
|
-
this.#scrollTarget.removeEventListener('scroll', fn);
|
|
190
|
-
this.#externalScrollListeners.delete(fn);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
/**
|
|
195
|
-
* Destroys the watcher by removing internal listeners and clearing data.
|
|
196
|
-
*/
|
|
197
|
-
destroy() {
|
|
198
|
-
if (this.#destroyed) return;
|
|
199
|
-
this.#destroyed = true;
|
|
200
|
-
|
|
201
|
-
this.#scrollTarget.removeEventListener('scroll', this._checkTimer);
|
|
202
|
-
for (const fn of this.#externalScrollListeners)
|
|
203
|
-
this.#scrollTarget.removeEventListener('scroll', fn);
|
|
204
|
-
|
|
205
|
-
this.#externalScrollListeners.clear();
|
|
206
|
-
this.#onStopListeners.clear();
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
/* harmony default export */ const libs_TinyAfterScrollWatcher = (TinyAfterScrollWatcher);
|
|
211
|
-
|
|
212
|
-
;// ./src/v1/build/TinyAfterScrollWatcher.mjs
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
window.TinyAfterScrollWatcher = __webpack_exports__.TinyAfterScrollWatcher;
|
|
218
|
-
/******/ })()
|
|
219
|
-
;
|