tiny-essentials 1.22.11 → 1.22.12
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/changelog/1/22/12.md +15 -0
- 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/TinyHtml.cjs +127 -32
- package/dist/v1/libs/TinyHtml.d.mts +81 -2
- package/dist/v1/libs/TinyHtml.mjs +121 -26
- package/docs/v1/libs/TinyHtml.md +41 -0
- package/package.json +1 -1
|
@@ -335,6 +335,21 @@ const __elemCollision = {
|
|
|
335
335
|
|
|
336
336
|
// TITLE: Class Intro
|
|
337
337
|
|
|
338
|
+
/**
|
|
339
|
+
* Represents all possible inputs accepted by the TinyHtml constructor.
|
|
340
|
+
* Can be a single element, an array of elements, array-like DOM collections,
|
|
341
|
+
* or a CSS selector string.
|
|
342
|
+
*
|
|
343
|
+
* @typedef {(
|
|
344
|
+
* ConstructorElValues |
|
|
345
|
+
* ConstructorElValues[] |
|
|
346
|
+
* NodeListOf<Element> |
|
|
347
|
+
* HTMLCollectionOf<Element> |
|
|
348
|
+
* NodeListOf<HTMLElement> |
|
|
349
|
+
* string
|
|
350
|
+
* )} TinyHtmlConstructor
|
|
351
|
+
*/
|
|
352
|
+
|
|
338
353
|
/**
|
|
339
354
|
* TinyHtml is a utility class that provides static and instance-level methods
|
|
340
355
|
* for precise dimension and position computations on HTML elements.
|
|
@@ -343,7 +358,7 @@ const __elemCollision = {
|
|
|
343
358
|
* Inspired by the jQuery project's open source implementations of element dimension
|
|
344
359
|
* and offset utilities. This class serves as a lightweight alternative using modern DOM APIs.
|
|
345
360
|
*
|
|
346
|
-
* @template {
|
|
361
|
+
* @template {TinyHtmlConstructor} TinyHtmlT
|
|
347
362
|
* @class
|
|
348
363
|
*/
|
|
349
364
|
class TinyHtml {
|
|
@@ -1824,7 +1839,8 @@ class TinyHtml {
|
|
|
1824
1839
|
static setData(el, key, value, isPrivate = false) {
|
|
1825
1840
|
const data = TinyHtml._dataSelector[!isPrivate ? 'public' : 'private']('setData', el);
|
|
1826
1841
|
if (typeof key !== 'string') throw new TypeError('The key must be a string.');
|
|
1827
|
-
data[key] = value;
|
|
1842
|
+
if (typeof value !== 'undefined') data[key] = value;
|
|
1843
|
+
else TinyHtml.removeData(el, key);
|
|
1828
1844
|
return el;
|
|
1829
1845
|
}
|
|
1830
1846
|
|
|
@@ -1840,6 +1856,57 @@ class TinyHtml {
|
|
|
1840
1856
|
return TinyHtml.setData(this, key, value, isPrivate);
|
|
1841
1857
|
}
|
|
1842
1858
|
|
|
1859
|
+
/**
|
|
1860
|
+
* Checks if a specific key exists in the data store of a DOM element.
|
|
1861
|
+
*
|
|
1862
|
+
* @template {TinyElement} T
|
|
1863
|
+
* @param {T} el - The DOM element.
|
|
1864
|
+
* @param {string} key - The key to check.
|
|
1865
|
+
* @param {boolean} [isPrivate=false] - Whether to check the private store.
|
|
1866
|
+
* @returns {boolean}
|
|
1867
|
+
*/
|
|
1868
|
+
static hasData(el, key, isPrivate = false) {
|
|
1869
|
+
if (typeof key !== 'string') throw new TypeError('The key must be a string.');
|
|
1870
|
+
const data = TinyHtml._dataSelector[!isPrivate ? 'public' : 'private']('hasData', el);
|
|
1871
|
+
return Object.prototype.hasOwnProperty.call(data, key);
|
|
1872
|
+
}
|
|
1873
|
+
|
|
1874
|
+
/**
|
|
1875
|
+
* Checks if a specific key exists in the data store of this element.
|
|
1876
|
+
*
|
|
1877
|
+
* @param {string} key - The key to check.
|
|
1878
|
+
* @param {boolean} [isPrivate=false] - Whether to check the private store.
|
|
1879
|
+
* @returns {boolean}
|
|
1880
|
+
*/
|
|
1881
|
+
hasData(key, isPrivate = false) {
|
|
1882
|
+
return TinyHtml.hasData(this, key, isPrivate);
|
|
1883
|
+
}
|
|
1884
|
+
|
|
1885
|
+
/**
|
|
1886
|
+
* Removes a value associated with a specific key from the data store of a DOM element.
|
|
1887
|
+
*
|
|
1888
|
+
* @param {TinyElement} el - The DOM element.
|
|
1889
|
+
* @param {string} key - The key to remove.
|
|
1890
|
+
* @param {boolean} [isPrivate=false] - Whether to remove from the private store.
|
|
1891
|
+
* @returns {boolean}
|
|
1892
|
+
*/
|
|
1893
|
+
static removeData(el, key, isPrivate = false) {
|
|
1894
|
+
if (typeof key !== 'string') throw new TypeError('The key must be a string.');
|
|
1895
|
+
const data = TinyHtml._dataSelector[!isPrivate ? 'public' : 'private']('removeData', el);
|
|
1896
|
+
return delete data[key];
|
|
1897
|
+
}
|
|
1898
|
+
|
|
1899
|
+
/**
|
|
1900
|
+
* Removes a value associated with a specific key from the data store of this element.
|
|
1901
|
+
*
|
|
1902
|
+
* @param {string} key - The key to remove.
|
|
1903
|
+
* @param {boolean} [isPrivate=false] - Whether to remove from the private store.
|
|
1904
|
+
* @returns {boolean}
|
|
1905
|
+
*/
|
|
1906
|
+
removeData(key, isPrivate = false) {
|
|
1907
|
+
return TinyHtml.removeData(this, key, isPrivate);
|
|
1908
|
+
}
|
|
1909
|
+
|
|
1843
1910
|
//////////////////////////////////////////////////////
|
|
1844
1911
|
|
|
1845
1912
|
// TITLE: DOM Getter 2
|
|
@@ -2488,47 +2555,75 @@ class TinyHtml {
|
|
|
2488
2555
|
}
|
|
2489
2556
|
|
|
2490
2557
|
/**
|
|
2491
|
-
*
|
|
2492
|
-
*
|
|
2493
|
-
* @param {
|
|
2558
|
+
* Validates if all provided items are acceptable constructor values.
|
|
2559
|
+
*
|
|
2560
|
+
* @param {any[]|NodeListOf<Element>|HTMLCollectionOf<Element>|NodeListOf<HTMLElement>} els - The elements to validate.
|
|
2561
|
+
* @throws {Error} If any element is not a valid target.
|
|
2494
2562
|
*/
|
|
2495
|
-
|
|
2563
|
+
static _elCheck(els) {
|
|
2564
|
+
for (const item of els) {
|
|
2565
|
+
if (
|
|
2566
|
+
!(item instanceof Element) &&
|
|
2567
|
+
!(item instanceof Window) &&
|
|
2568
|
+
!(item instanceof Document) &&
|
|
2569
|
+
!(item instanceof Text)
|
|
2570
|
+
)
|
|
2571
|
+
throw new Error(`[TinyHtml] Invalid Target in constructor.`);
|
|
2572
|
+
}
|
|
2573
|
+
}
|
|
2574
|
+
|
|
2575
|
+
/**
|
|
2576
|
+
* A new TinyHtml object containing the combined elements.
|
|
2577
|
+
*
|
|
2578
|
+
* @template {TinyHtmlConstructor} T
|
|
2579
|
+
* @param {T} el - The elements to add.
|
|
2580
|
+
* @returns {TinyHtml<T>} The new length of the internal collection.
|
|
2581
|
+
*/
|
|
2582
|
+
add(el) {
|
|
2583
|
+
return new TinyHtml([...this.#el, ...TinyHtml._selector(el)]);
|
|
2584
|
+
}
|
|
2585
|
+
|
|
2586
|
+
/**
|
|
2587
|
+
* Resolves the given constructor input into a normalized array of elements.
|
|
2588
|
+
*
|
|
2589
|
+
* @param {TinyHtmlConstructor} el - A selector string, element, array-like collection, or array of constructor values.
|
|
2590
|
+
* @returns {ConstructorElValues[]} A normalized array of DOM elements/values.
|
|
2591
|
+
* @throws {Error} If a TinyHtml instance is passed (nesting TinyHtml inside TinyHtml is not allowed).
|
|
2592
|
+
* @throws {Error} If the resolved elements are not valid constructor values.
|
|
2593
|
+
*/
|
|
2594
|
+
static _selector(el) {
|
|
2496
2595
|
if (el instanceof TinyHtml)
|
|
2497
2596
|
throw new Error(
|
|
2498
2597
|
`[TinyHtml] You are trying to put a TinyHtml inside another TinyHtml in constructor.`,
|
|
2499
2598
|
);
|
|
2500
2599
|
|
|
2501
|
-
/** @
|
|
2502
|
-
const
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
)
|
|
2512
|
-
throw new Error(`[TinyHtml] Invalid Target in constructor.`);
|
|
2513
|
-
};
|
|
2514
|
-
|
|
2515
|
-
if (Array.isArray(el)) {
|
|
2516
|
-
elCheck(el);
|
|
2517
|
-
this.#el = el;
|
|
2518
|
-
} else if (el instanceof NodeList || el instanceof HTMLCollection) {
|
|
2519
|
-
/** @type {ConstructorElValues[]} */
|
|
2520
|
-
// @ts-ignore
|
|
2521
|
-
const els = [...el];
|
|
2522
|
-
elCheck(els);
|
|
2523
|
-
this.#el = els;
|
|
2600
|
+
/** @type {(list: any[]) => any[]} */
|
|
2601
|
+
const fixItemList = (list) => Array.from(new Set(list));
|
|
2602
|
+
const selector = typeof el !== 'string' ? el : document.querySelectorAll(el);
|
|
2603
|
+
if (Array.isArray(selector)) {
|
|
2604
|
+
TinyHtml._elCheck(selector);
|
|
2605
|
+
return fixItemList(selector);
|
|
2606
|
+
} else if (selector instanceof NodeList || selector instanceof HTMLCollection) {
|
|
2607
|
+
const els = [...selector];
|
|
2608
|
+
TinyHtml._elCheck(els);
|
|
2609
|
+
return fixItemList(els);
|
|
2524
2610
|
} else {
|
|
2525
|
-
const els = [
|
|
2526
|
-
|
|
2611
|
+
const els = [selector];
|
|
2612
|
+
TinyHtml._elCheck(els);
|
|
2527
2613
|
// @ts-ignore
|
|
2528
|
-
|
|
2614
|
+
return fixItemList(els);
|
|
2529
2615
|
}
|
|
2530
2616
|
}
|
|
2531
2617
|
|
|
2618
|
+
/**
|
|
2619
|
+
* Creates an instance of TinyHtml for a specific Element.
|
|
2620
|
+
* Useful when you want to operate repeatedly on the same element using instance methods.
|
|
2621
|
+
* @param {TinyHtmlT} el - The element to wrap and manipulate.
|
|
2622
|
+
*/
|
|
2623
|
+
constructor(el) {
|
|
2624
|
+
this.#el = TinyHtml._selector(el);
|
|
2625
|
+
}
|
|
2626
|
+
|
|
2532
2627
|
/**
|
|
2533
2628
|
* Checks whether the given object is a window.
|
|
2534
2629
|
* @param {*} obj - The object to test.
|
|
@@ -207,6 +207,12 @@ export type InputElement = HTMLInputElement | HTMLSelectElement | HTMLTextAreaEl
|
|
|
207
207
|
export type HtmlParsed = [tagName: string, // The tag name of the element (e.g., 'div', 'img')
|
|
208
208
|
attributes: Record<string, string>, // All element attributes as key-value pairs
|
|
209
209
|
...children: (string | HtmlParsed)[]];
|
|
210
|
+
/**
|
|
211
|
+
* Represents all possible inputs accepted by the TinyHtml constructor.
|
|
212
|
+
* Can be a single element, an array of elements, array-like DOM collections,
|
|
213
|
+
* or a CSS selector string.
|
|
214
|
+
*/
|
|
215
|
+
export type TinyHtmlConstructor = (ConstructorElValues | ConstructorElValues[] | NodeListOf<Element> | HTMLCollectionOf<Element> | NodeListOf<HTMLElement> | string);
|
|
210
216
|
/**
|
|
211
217
|
* Possible directions from which a collision was detected and locked.
|
|
212
218
|
*
|
|
@@ -246,6 +252,20 @@ attributes: Record<string, string>, // All element attributes as key-value pairs
|
|
|
246
252
|
* ...children: (string | HtmlParsed)[] // Text or nested elements
|
|
247
253
|
* ]} HtmlParsed
|
|
248
254
|
*/
|
|
255
|
+
/**
|
|
256
|
+
* Represents all possible inputs accepted by the TinyHtml constructor.
|
|
257
|
+
* Can be a single element, an array of elements, array-like DOM collections,
|
|
258
|
+
* or a CSS selector string.
|
|
259
|
+
*
|
|
260
|
+
* @typedef {(
|
|
261
|
+
* ConstructorElValues |
|
|
262
|
+
* ConstructorElValues[] |
|
|
263
|
+
* NodeListOf<Element> |
|
|
264
|
+
* HTMLCollectionOf<Element> |
|
|
265
|
+
* NodeListOf<HTMLElement> |
|
|
266
|
+
* string
|
|
267
|
+
* )} TinyHtmlConstructor
|
|
268
|
+
*/
|
|
249
269
|
/**
|
|
250
270
|
* TinyHtml is a utility class that provides static and instance-level methods
|
|
251
271
|
* for precise dimension and position computations on HTML elements.
|
|
@@ -254,10 +274,10 @@ attributes: Record<string, string>, // All element attributes as key-value pairs
|
|
|
254
274
|
* Inspired by the jQuery project's open source implementations of element dimension
|
|
255
275
|
* and offset utilities. This class serves as a lightweight alternative using modern DOM APIs.
|
|
256
276
|
*
|
|
257
|
-
* @template {
|
|
277
|
+
* @template {TinyHtmlConstructor} TinyHtmlT
|
|
258
278
|
* @class
|
|
259
279
|
*/
|
|
260
|
-
declare class TinyHtml<TinyHtmlT extends
|
|
280
|
+
declare class TinyHtml<TinyHtmlT extends TinyHtmlConstructor> {
|
|
261
281
|
/** @typedef {import('../basics/collision.mjs').ObjRect} ObjRect */
|
|
262
282
|
static Utils: {
|
|
263
283
|
getElsRelativeCenterOffset(rect1: TinyCollision.ObjRect, rect2: TinyCollision.ObjRect): {
|
|
@@ -871,6 +891,25 @@ declare class TinyHtml<TinyHtmlT extends ConstructorElValues | ConstructorElValu
|
|
|
871
891
|
* @returns {T}
|
|
872
892
|
*/
|
|
873
893
|
static setData<T extends TinyElement>(el: T, key: string, value: any, isPrivate?: boolean): T;
|
|
894
|
+
/**
|
|
895
|
+
* Checks if a specific key exists in the data store of a DOM element.
|
|
896
|
+
*
|
|
897
|
+
* @template {TinyElement} T
|
|
898
|
+
* @param {T} el - The DOM element.
|
|
899
|
+
* @param {string} key - The key to check.
|
|
900
|
+
* @param {boolean} [isPrivate=false] - Whether to check the private store.
|
|
901
|
+
* @returns {boolean}
|
|
902
|
+
*/
|
|
903
|
+
static hasData<T extends TinyElement>(el: T, key: string, isPrivate?: boolean): boolean;
|
|
904
|
+
/**
|
|
905
|
+
* Removes a value associated with a specific key from the data store of a DOM element.
|
|
906
|
+
*
|
|
907
|
+
* @param {TinyElement} el - The DOM element.
|
|
908
|
+
* @param {string} key - The key to remove.
|
|
909
|
+
* @param {boolean} [isPrivate=false] - Whether to remove from the private store.
|
|
910
|
+
* @returns {boolean}
|
|
911
|
+
*/
|
|
912
|
+
static removeData(el: TinyElement, key: string, isPrivate?: boolean): boolean;
|
|
874
913
|
/**
|
|
875
914
|
* Get the sibling element in a given direction.
|
|
876
915
|
*
|
|
@@ -1081,6 +1120,22 @@ declare class TinyHtml<TinyHtmlT extends ConstructorElValues | ConstructorElValu
|
|
|
1081
1120
|
* @returns {T}
|
|
1082
1121
|
*/
|
|
1083
1122
|
static replaceAll<T extends TinyNode | TinyNode[]>(el: T, targets: TinyNode | TinyNode[]): T;
|
|
1123
|
+
/**
|
|
1124
|
+
* Validates if all provided items are acceptable constructor values.
|
|
1125
|
+
*
|
|
1126
|
+
* @param {any[]|NodeListOf<Element>|HTMLCollectionOf<Element>|NodeListOf<HTMLElement>} els - The elements to validate.
|
|
1127
|
+
* @throws {Error} If any element is not a valid target.
|
|
1128
|
+
*/
|
|
1129
|
+
static _elCheck(els: any[] | NodeListOf<Element> | HTMLCollectionOf<Element> | NodeListOf<HTMLElement>): void;
|
|
1130
|
+
/**
|
|
1131
|
+
* Resolves the given constructor input into a normalized array of elements.
|
|
1132
|
+
*
|
|
1133
|
+
* @param {TinyHtmlConstructor} el - A selector string, element, array-like collection, or array of constructor values.
|
|
1134
|
+
* @returns {ConstructorElValues[]} A normalized array of DOM elements/values.
|
|
1135
|
+
* @throws {Error} If a TinyHtml instance is passed (nesting TinyHtml inside TinyHtml is not allowed).
|
|
1136
|
+
* @throws {Error} If the resolved elements are not valid constructor values.
|
|
1137
|
+
*/
|
|
1138
|
+
static _selector(el: TinyHtmlConstructor): ConstructorElValues[];
|
|
1084
1139
|
/**
|
|
1085
1140
|
* Checks whether the given object is a window.
|
|
1086
1141
|
* @param {*} obj - The object to test.
|
|
@@ -2884,6 +2939,22 @@ declare class TinyHtml<TinyHtmlT extends ConstructorElValues | ConstructorElValu
|
|
|
2884
2939
|
* @returns {this}
|
|
2885
2940
|
*/
|
|
2886
2941
|
setData(key: string, value: any, isPrivate?: boolean): this;
|
|
2942
|
+
/**
|
|
2943
|
+
* Checks if a specific key exists in the data store of this element.
|
|
2944
|
+
*
|
|
2945
|
+
* @param {string} key - The key to check.
|
|
2946
|
+
* @param {boolean} [isPrivate=false] - Whether to check the private store.
|
|
2947
|
+
* @returns {boolean}
|
|
2948
|
+
*/
|
|
2949
|
+
hasData(key: string, isPrivate?: boolean): boolean;
|
|
2950
|
+
/**
|
|
2951
|
+
* Removes a value associated with a specific key from the data store of this element.
|
|
2952
|
+
*
|
|
2953
|
+
* @param {string} key - The key to remove.
|
|
2954
|
+
* @param {boolean} [isPrivate=false] - Whether to remove from the private store.
|
|
2955
|
+
* @returns {boolean}
|
|
2956
|
+
*/
|
|
2957
|
+
removeData(key: string, isPrivate?: boolean): boolean;
|
|
2887
2958
|
/**
|
|
2888
2959
|
* Returns the direct parent node of the given element, excluding document fragments.
|
|
2889
2960
|
*
|
|
@@ -3038,6 +3109,14 @@ declare class TinyHtml<TinyHtmlT extends ConstructorElValues | ConstructorElValu
|
|
|
3038
3109
|
* @returns {number} The total count of elements.
|
|
3039
3110
|
*/
|
|
3040
3111
|
get size(): number;
|
|
3112
|
+
/**
|
|
3113
|
+
* A new TinyHtml object containing the combined elements.
|
|
3114
|
+
*
|
|
3115
|
+
* @template {TinyHtmlConstructor} T
|
|
3116
|
+
* @param {T} el - The elements to add.
|
|
3117
|
+
* @returns {TinyHtml<T>} The new length of the internal collection.
|
|
3118
|
+
*/
|
|
3119
|
+
add<T extends TinyHtmlConstructor>(el: T): TinyHtml<T>;
|
|
3041
3120
|
/**
|
|
3042
3121
|
* Returns the full computed CSS styles for the given element.
|
|
3043
3122
|
*
|
|
@@ -282,6 +282,20 @@ const __elemCollision = {
|
|
|
282
282
|
* ]} HtmlParsed
|
|
283
283
|
*/
|
|
284
284
|
// TITLE: Class Intro
|
|
285
|
+
/**
|
|
286
|
+
* Represents all possible inputs accepted by the TinyHtml constructor.
|
|
287
|
+
* Can be a single element, an array of elements, array-like DOM collections,
|
|
288
|
+
* or a CSS selector string.
|
|
289
|
+
*
|
|
290
|
+
* @typedef {(
|
|
291
|
+
* ConstructorElValues |
|
|
292
|
+
* ConstructorElValues[] |
|
|
293
|
+
* NodeListOf<Element> |
|
|
294
|
+
* HTMLCollectionOf<Element> |
|
|
295
|
+
* NodeListOf<HTMLElement> |
|
|
296
|
+
* string
|
|
297
|
+
* )} TinyHtmlConstructor
|
|
298
|
+
*/
|
|
285
299
|
/**
|
|
286
300
|
* TinyHtml is a utility class that provides static and instance-level methods
|
|
287
301
|
* for precise dimension and position computations on HTML elements.
|
|
@@ -290,7 +304,7 @@ const __elemCollision = {
|
|
|
290
304
|
* Inspired by the jQuery project's open source implementations of element dimension
|
|
291
305
|
* and offset utilities. This class serves as a lightweight alternative using modern DOM APIs.
|
|
292
306
|
*
|
|
293
|
-
* @template {
|
|
307
|
+
* @template {TinyHtmlConstructor} TinyHtmlT
|
|
294
308
|
* @class
|
|
295
309
|
*/
|
|
296
310
|
class TinyHtml {
|
|
@@ -1582,7 +1596,10 @@ class TinyHtml {
|
|
|
1582
1596
|
const data = TinyHtml._dataSelector[!isPrivate ? 'public' : 'private']('setData', el);
|
|
1583
1597
|
if (typeof key !== 'string')
|
|
1584
1598
|
throw new TypeError('The key must be a string.');
|
|
1585
|
-
|
|
1599
|
+
if (typeof value !== 'undefined')
|
|
1600
|
+
data[key] = value;
|
|
1601
|
+
else
|
|
1602
|
+
TinyHtml.removeData(el, key);
|
|
1586
1603
|
return el;
|
|
1587
1604
|
}
|
|
1588
1605
|
/**
|
|
@@ -1596,6 +1613,55 @@ class TinyHtml {
|
|
|
1596
1613
|
setData(key, value, isPrivate = false) {
|
|
1597
1614
|
return TinyHtml.setData(this, key, value, isPrivate);
|
|
1598
1615
|
}
|
|
1616
|
+
/**
|
|
1617
|
+
* Checks if a specific key exists in the data store of a DOM element.
|
|
1618
|
+
*
|
|
1619
|
+
* @template {TinyElement} T
|
|
1620
|
+
* @param {T} el - The DOM element.
|
|
1621
|
+
* @param {string} key - The key to check.
|
|
1622
|
+
* @param {boolean} [isPrivate=false] - Whether to check the private store.
|
|
1623
|
+
* @returns {boolean}
|
|
1624
|
+
*/
|
|
1625
|
+
static hasData(el, key, isPrivate = false) {
|
|
1626
|
+
if (typeof key !== 'string')
|
|
1627
|
+
throw new TypeError('The key must be a string.');
|
|
1628
|
+
const data = TinyHtml._dataSelector[!isPrivate ? 'public' : 'private']('hasData', el);
|
|
1629
|
+
return Object.prototype.hasOwnProperty.call(data, key);
|
|
1630
|
+
}
|
|
1631
|
+
/**
|
|
1632
|
+
* Checks if a specific key exists in the data store of this element.
|
|
1633
|
+
*
|
|
1634
|
+
* @param {string} key - The key to check.
|
|
1635
|
+
* @param {boolean} [isPrivate=false] - Whether to check the private store.
|
|
1636
|
+
* @returns {boolean}
|
|
1637
|
+
*/
|
|
1638
|
+
hasData(key, isPrivate = false) {
|
|
1639
|
+
return TinyHtml.hasData(this, key, isPrivate);
|
|
1640
|
+
}
|
|
1641
|
+
/**
|
|
1642
|
+
* Removes a value associated with a specific key from the data store of a DOM element.
|
|
1643
|
+
*
|
|
1644
|
+
* @param {TinyElement} el - The DOM element.
|
|
1645
|
+
* @param {string} key - The key to remove.
|
|
1646
|
+
* @param {boolean} [isPrivate=false] - Whether to remove from the private store.
|
|
1647
|
+
* @returns {boolean}
|
|
1648
|
+
*/
|
|
1649
|
+
static removeData(el, key, isPrivate = false) {
|
|
1650
|
+
if (typeof key !== 'string')
|
|
1651
|
+
throw new TypeError('The key must be a string.');
|
|
1652
|
+
const data = TinyHtml._dataSelector[!isPrivate ? 'public' : 'private']('removeData', el);
|
|
1653
|
+
return delete data[key];
|
|
1654
|
+
}
|
|
1655
|
+
/**
|
|
1656
|
+
* Removes a value associated with a specific key from the data store of this element.
|
|
1657
|
+
*
|
|
1658
|
+
* @param {string} key - The key to remove.
|
|
1659
|
+
* @param {boolean} [isPrivate=false] - Whether to remove from the private store.
|
|
1660
|
+
* @returns {boolean}
|
|
1661
|
+
*/
|
|
1662
|
+
removeData(key, isPrivate = false) {
|
|
1663
|
+
return TinyHtml.removeData(this, key, isPrivate);
|
|
1664
|
+
}
|
|
1599
1665
|
//////////////////////////////////////////////////////
|
|
1600
1666
|
// TITLE: DOM Getter 2
|
|
1601
1667
|
/**
|
|
@@ -2188,39 +2254,68 @@ class TinyHtml {
|
|
|
2188
2254
|
return this.#el.length;
|
|
2189
2255
|
}
|
|
2190
2256
|
/**
|
|
2191
|
-
*
|
|
2192
|
-
*
|
|
2193
|
-
* @param {
|
|
2257
|
+
* Validates if all provided items are acceptable constructor values.
|
|
2258
|
+
*
|
|
2259
|
+
* @param {any[]|NodeListOf<Element>|HTMLCollectionOf<Element>|NodeListOf<HTMLElement>} els - The elements to validate.
|
|
2260
|
+
* @throws {Error} If any element is not a valid target.
|
|
2194
2261
|
*/
|
|
2195
|
-
|
|
2262
|
+
static _elCheck(els) {
|
|
2263
|
+
for (const item of els) {
|
|
2264
|
+
if (!(item instanceof Element) &&
|
|
2265
|
+
!(item instanceof Window) &&
|
|
2266
|
+
!(item instanceof Document) &&
|
|
2267
|
+
!(item instanceof Text))
|
|
2268
|
+
throw new Error(`[TinyHtml] Invalid Target in constructor.`);
|
|
2269
|
+
}
|
|
2270
|
+
}
|
|
2271
|
+
/**
|
|
2272
|
+
* A new TinyHtml object containing the combined elements.
|
|
2273
|
+
*
|
|
2274
|
+
* @template {TinyHtmlConstructor} T
|
|
2275
|
+
* @param {T} el - The elements to add.
|
|
2276
|
+
* @returns {TinyHtml<T>} The new length of the internal collection.
|
|
2277
|
+
*/
|
|
2278
|
+
add(el) {
|
|
2279
|
+
return new TinyHtml([...this.#el, ...TinyHtml._selector(el)]);
|
|
2280
|
+
}
|
|
2281
|
+
/**
|
|
2282
|
+
* Resolves the given constructor input into a normalized array of elements.
|
|
2283
|
+
*
|
|
2284
|
+
* @param {TinyHtmlConstructor} el - A selector string, element, array-like collection, or array of constructor values.
|
|
2285
|
+
* @returns {ConstructorElValues[]} A normalized array of DOM elements/values.
|
|
2286
|
+
* @throws {Error} If a TinyHtml instance is passed (nesting TinyHtml inside TinyHtml is not allowed).
|
|
2287
|
+
* @throws {Error} If the resolved elements are not valid constructor values.
|
|
2288
|
+
*/
|
|
2289
|
+
static _selector(el) {
|
|
2196
2290
|
if (el instanceof TinyHtml)
|
|
2197
2291
|
throw new Error(`[TinyHtml] You are trying to put a TinyHtml inside another TinyHtml in constructor.`);
|
|
2198
|
-
/** @
|
|
2199
|
-
const
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
throw new Error(`[TinyHtml] Invalid Target in constructor.`);
|
|
2205
|
-
};
|
|
2206
|
-
if (Array.isArray(el)) {
|
|
2207
|
-
elCheck(el);
|
|
2208
|
-
this.#el = el;
|
|
2292
|
+
/** @type {(list: any[]) => any[]} */
|
|
2293
|
+
const fixItemList = (list) => Array.from(new Set(list));
|
|
2294
|
+
const selector = typeof el !== 'string' ? el : document.querySelectorAll(el);
|
|
2295
|
+
if (Array.isArray(selector)) {
|
|
2296
|
+
TinyHtml._elCheck(selector);
|
|
2297
|
+
return fixItemList(selector);
|
|
2209
2298
|
}
|
|
2210
|
-
else if (
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
elCheck(els);
|
|
2215
|
-
this.#el = els;
|
|
2299
|
+
else if (selector instanceof NodeList || selector instanceof HTMLCollection) {
|
|
2300
|
+
const els = [...selector];
|
|
2301
|
+
TinyHtml._elCheck(els);
|
|
2302
|
+
return fixItemList(els);
|
|
2216
2303
|
}
|
|
2217
2304
|
else {
|
|
2218
|
-
const els = [
|
|
2219
|
-
|
|
2305
|
+
const els = [selector];
|
|
2306
|
+
TinyHtml._elCheck(els);
|
|
2220
2307
|
// @ts-ignore
|
|
2221
|
-
|
|
2308
|
+
return fixItemList(els);
|
|
2222
2309
|
}
|
|
2223
2310
|
}
|
|
2311
|
+
/**
|
|
2312
|
+
* Creates an instance of TinyHtml for a specific Element.
|
|
2313
|
+
* Useful when you want to operate repeatedly on the same element using instance methods.
|
|
2314
|
+
* @param {TinyHtmlT} el - The element to wrap and manipulate.
|
|
2315
|
+
*/
|
|
2316
|
+
constructor(el) {
|
|
2317
|
+
this.#el = TinyHtml._selector(el);
|
|
2318
|
+
}
|
|
2224
2319
|
/**
|
|
2225
2320
|
* Checks whether the given object is a window.
|
|
2226
2321
|
* @param {*} obj - The object to test.
|
package/docs/v1/libs/TinyHtml.md
CHANGED
|
@@ -1001,6 +1001,31 @@ static jsonToTinyElems(jsonArray: HtmlParsed[]): TinyHtml[]
|
|
|
1001
1001
|
|
|
1002
1002
|
## 🧩 Internal Element Access
|
|
1003
1003
|
|
|
1004
|
+
### `_elCheck(els)`
|
|
1005
|
+
|
|
1006
|
+
Validates if all provided items are acceptable constructor values.
|
|
1007
|
+
|
|
1008
|
+
* **Parameters**:
|
|
1009
|
+
|
|
1010
|
+
* `els` (`ConstructorElValues[]`) — The elements to validate.
|
|
1011
|
+
* **Throws**:
|
|
1012
|
+
|
|
1013
|
+
* `Error` — If any element is not a valid target.
|
|
1014
|
+
* **Returns**: `void`
|
|
1015
|
+
|
|
1016
|
+
---
|
|
1017
|
+
|
|
1018
|
+
### `add(...el)`
|
|
1019
|
+
|
|
1020
|
+
Adds elements to the end of the internal collection.
|
|
1021
|
+
|
|
1022
|
+
* **Parameters**:
|
|
1023
|
+
|
|
1024
|
+
* `...el` (`ConstructorElValues`) — The elements to add.
|
|
1025
|
+
* **Returns**: `TinyHtml` — A new TinyHtml object containing the combined elements.
|
|
1026
|
+
|
|
1027
|
+
---
|
|
1028
|
+
|
|
1004
1029
|
### `exists(index)`
|
|
1005
1030
|
Checks whether the element exists at the given index.
|
|
1006
1031
|
|
|
@@ -1214,6 +1239,14 @@ Gets data from the element.
|
|
|
1214
1239
|
|
|
1215
1240
|
Sets a value on the element’s data store.
|
|
1216
1241
|
|
|
1242
|
+
#### `TinyHtml.hasData(el, key, isPrivate?)`
|
|
1243
|
+
|
|
1244
|
+
Checks if a specific key exists in the data store of a DOM element.
|
|
1245
|
+
|
|
1246
|
+
#### `TinyHtml.removeData(el, key, isPrivate?)`
|
|
1247
|
+
|
|
1248
|
+
Removes a value associated with a specific key from the data store of a DOM element.
|
|
1249
|
+
|
|
1217
1250
|
---
|
|
1218
1251
|
|
|
1219
1252
|
### 📌 Instance Methods
|
|
@@ -1226,6 +1259,14 @@ Shortcut for getting data from the current instance’s element.
|
|
|
1226
1259
|
|
|
1227
1260
|
Shortcut for setting data on the current element.
|
|
1228
1261
|
|
|
1262
|
+
#### `.hasData(key, isPrivate?)`
|
|
1263
|
+
|
|
1264
|
+
Checks if a specific key exists in the data store of this element.
|
|
1265
|
+
|
|
1266
|
+
#### `.removeData(key, isPrivate?)`
|
|
1267
|
+
|
|
1268
|
+
Removes a value associated with a specific key from the data store of this element.
|
|
1269
|
+
|
|
1229
1270
|
---
|
|
1230
1271
|
|
|
1231
1272
|
## 🔄 DOM Traversal Methods
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tiny-essentials",
|
|
3
|
-
"version": "1.22.
|
|
3
|
+
"version": "1.22.12",
|
|
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",
|