tiny-essentials 1.22.10 → 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.
@@ -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 {ConstructorElValues|ConstructorElValues[]|NodeListOf<Element>|HTMLCollectionOf<Element>|NodeListOf<HTMLElement>} TinyHtmlT
361
+ * @template {TinyHtmlConstructor} TinyHtmlT
347
362
  * @class
348
363
  */
349
364
  class TinyHtml {
@@ -815,6 +830,8 @@ class TinyHtml {
815
830
  }
816
831
 
817
832
  /**
833
+ * @deprecated Use the {@link createFromHTML} instead.
834
+ *
818
835
  * Creates an HTMLElement or TextNode from an HTML string.
819
836
  * Supports both elements and plain text.
820
837
  *
@@ -836,6 +853,24 @@ class TinyHtml {
836
853
  return new TinyHtml(template.content.firstChild);
837
854
  }
838
855
 
856
+ /**
857
+ * Creates an HTMLElement or TextNode from an HTML string.
858
+ * Supports both elements and plain text.
859
+ *
860
+ * @param {string} htmlString - The HTML string to convert.
861
+ * @returns {TinyHtml<Element>} - A single HTMLElement or TextNode.
862
+ */
863
+ static createFromHTML(htmlString) {
864
+ const template = document.createElement('template');
865
+ htmlString = htmlString.trim();
866
+
867
+ template.innerHTML = htmlString;
868
+ const elems = Array.from(template.content.childNodes);
869
+ if (!elems.every((item) => item instanceof Element || item instanceof Text))
870
+ throw new Error('The HTML string must contain a valid HTML element.');
871
+ return new TinyHtml(elems);
872
+ }
873
+
839
874
  ///////////////////////////////////////////////////
840
875
  // TITLE: Query Script
841
876
 
@@ -1804,7 +1839,8 @@ class TinyHtml {
1804
1839
  static setData(el, key, value, isPrivate = false) {
1805
1840
  const data = TinyHtml._dataSelector[!isPrivate ? 'public' : 'private']('setData', el);
1806
1841
  if (typeof key !== 'string') throw new TypeError('The key must be a string.');
1807
- data[key] = value;
1842
+ if (typeof value !== 'undefined') data[key] = value;
1843
+ else TinyHtml.removeData(el, key);
1808
1844
  return el;
1809
1845
  }
1810
1846
 
@@ -1820,6 +1856,57 @@ class TinyHtml {
1820
1856
  return TinyHtml.setData(this, key, value, isPrivate);
1821
1857
  }
1822
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
+
1823
1910
  //////////////////////////////////////////////////////
1824
1911
 
1825
1912
  // TITLE: DOM Getter 2
@@ -2164,7 +2251,7 @@ class TinyHtml {
2164
2251
  if (typeof item === 'undefined' || item === null || item === false) continue;
2165
2252
  if (typeof item !== 'string' && typeof item !== 'number') {
2166
2253
  if (item instanceof Node || item instanceof TinyHtml)
2167
- results.push(TinyHtml._preNodeElems(item, where)[0]);
2254
+ results.push(...TinyHtml._preNodeElems(item, where));
2168
2255
  else if (Array.isArray(item)) results.push(...TinyHtml._appendChecker(where, ...item));
2169
2256
  else {
2170
2257
  for (const name in item) {
@@ -2468,47 +2555,75 @@ class TinyHtml {
2468
2555
  }
2469
2556
 
2470
2557
  /**
2471
- * Creates an instance of TinyHtml for a specific Element.
2472
- * Useful when you want to operate repeatedly on the same element using instance methods.
2473
- * @param {TinyHtmlT} el - The element to wrap and manipulate.
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.
2474
2562
  */
2475
- constructor(el) {
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) {
2476
2595
  if (el instanceof TinyHtml)
2477
2596
  throw new Error(
2478
2597
  `[TinyHtml] You are trying to put a TinyHtml inside another TinyHtml in constructor.`,
2479
2598
  );
2480
2599
 
2481
- /** @param {any[]} els */
2482
- const elCheck = (els) => {
2483
- if (
2484
- !els.every(
2485
- (el) =>
2486
- el instanceof Element ||
2487
- el instanceof Window ||
2488
- el instanceof Document ||
2489
- el instanceof Text,
2490
- )
2491
- )
2492
- throw new Error(`[TinyHtml] Invalid Target in constructor.`);
2493
- };
2494
-
2495
- if (Array.isArray(el)) {
2496
- elCheck(el);
2497
- this.#el = el;
2498
- } else if (el instanceof NodeList || el instanceof HTMLCollection) {
2499
- /** @type {ConstructorElValues[]} */
2500
- // @ts-ignore
2501
- const els = [...el];
2502
- elCheck(els);
2503
- 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);
2504
2610
  } else {
2505
- const els = [el];
2506
- elCheck(els);
2611
+ const els = [selector];
2612
+ TinyHtml._elCheck(els);
2507
2613
  // @ts-ignore
2508
- this.#el = els;
2614
+ return fixItemList(els);
2509
2615
  }
2510
2616
  }
2511
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
+
2512
2627
  /**
2513
2628
  * Checks whether the given object is a window.
2514
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 {ConstructorElValues|ConstructorElValues[]|NodeListOf<Element>|HTMLCollectionOf<Element>|NodeListOf<HTMLElement>} TinyHtmlT
277
+ * @template {TinyHtmlConstructor} TinyHtmlT
258
278
  * @class
259
279
  */
260
- declare class TinyHtml<TinyHtmlT extends ConstructorElValues | ConstructorElValues[] | NodeListOf<Element> | HTMLCollectionOf<Element> | NodeListOf<HTMLElement>> {
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): {
@@ -473,6 +493,8 @@ declare class TinyHtml<TinyHtmlT extends ConstructorElValues | ConstructorElValu
473
493
  */
474
494
  static createTextNode(value: string): TinyHtml<Text>;
475
495
  /**
496
+ * @deprecated Use the {@link createFromHTML} instead.
497
+ *
476
498
  * Creates an HTMLElement or TextNode from an HTML string.
477
499
  * Supports both elements and plain text.
478
500
  *
@@ -480,6 +502,14 @@ declare class TinyHtml<TinyHtmlT extends ConstructorElValues | ConstructorElValu
480
502
  * @returns {TinyHtml<Element>} - A single HTMLElement or TextNode.
481
503
  */
482
504
  static createElementFromHTML(htmlString: string): TinyHtml<Element>;
505
+ /**
506
+ * Creates an HTMLElement or TextNode from an HTML string.
507
+ * Supports both elements and plain text.
508
+ *
509
+ * @param {string} htmlString - The HTML string to convert.
510
+ * @returns {TinyHtml<Element>} - A single HTMLElement or TextNode.
511
+ */
512
+ static createFromHTML(htmlString: string): TinyHtml<Element>;
483
513
  /**
484
514
  * Queries the document for the first element matching the CSS selector and wraps it in a TinyHtml instance.
485
515
  *
@@ -861,6 +891,25 @@ declare class TinyHtml<TinyHtmlT extends ConstructorElValues | ConstructorElValu
861
891
  * @returns {T}
862
892
  */
863
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;
864
913
  /**
865
914
  * Get the sibling element in a given direction.
866
915
  *
@@ -1071,6 +1120,22 @@ declare class TinyHtml<TinyHtmlT extends ConstructorElValues | ConstructorElValu
1071
1120
  * @returns {T}
1072
1121
  */
1073
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[];
1074
1139
  /**
1075
1140
  * Checks whether the given object is a window.
1076
1141
  * @param {*} obj - The object to test.
@@ -2874,6 +2939,22 @@ declare class TinyHtml<TinyHtmlT extends ConstructorElValues | ConstructorElValu
2874
2939
  * @returns {this}
2875
2940
  */
2876
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;
2877
2958
  /**
2878
2959
  * Returns the direct parent node of the given element, excluding document fragments.
2879
2960
  *
@@ -3028,6 +3109,14 @@ declare class TinyHtml<TinyHtmlT extends ConstructorElValues | ConstructorElValu
3028
3109
  * @returns {number} The total count of elements.
3029
3110
  */
3030
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>;
3031
3120
  /**
3032
3121
  * Returns the full computed CSS styles for the given element.
3033
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 {ConstructorElValues|ConstructorElValues[]|NodeListOf<Element>|HTMLCollectionOf<Element>|NodeListOf<HTMLElement>} TinyHtmlT
307
+ * @template {TinyHtmlConstructor} TinyHtmlT
294
308
  * @class
295
309
  */
296
310
  class TinyHtml {
@@ -702,6 +716,8 @@ class TinyHtml {
702
716
  return new TinyHtml(document.createTextNode(value));
703
717
  }
704
718
  /**
719
+ * @deprecated Use the {@link createFromHTML} instead.
720
+ *
705
721
  * Creates an HTMLElement or TextNode from an HTML string.
706
722
  * Supports both elements and plain text.
707
723
  *
@@ -720,6 +736,22 @@ class TinyHtml {
720
736
  throw new Error('The HTML string must contain a valid HTML element.');
721
737
  return new TinyHtml(template.content.firstChild);
722
738
  }
739
+ /**
740
+ * Creates an HTMLElement or TextNode from an HTML string.
741
+ * Supports both elements and plain text.
742
+ *
743
+ * @param {string} htmlString - The HTML string to convert.
744
+ * @returns {TinyHtml<Element>} - A single HTMLElement or TextNode.
745
+ */
746
+ static createFromHTML(htmlString) {
747
+ const template = document.createElement('template');
748
+ htmlString = htmlString.trim();
749
+ template.innerHTML = htmlString;
750
+ const elems = Array.from(template.content.childNodes);
751
+ if (!elems.every((item) => item instanceof Element || item instanceof Text))
752
+ throw new Error('The HTML string must contain a valid HTML element.');
753
+ return new TinyHtml(elems);
754
+ }
723
755
  ///////////////////////////////////////////////////
724
756
  // TITLE: Query Script
725
757
  /**
@@ -1564,7 +1596,10 @@ class TinyHtml {
1564
1596
  const data = TinyHtml._dataSelector[!isPrivate ? 'public' : 'private']('setData', el);
1565
1597
  if (typeof key !== 'string')
1566
1598
  throw new TypeError('The key must be a string.');
1567
- data[key] = value;
1599
+ if (typeof value !== 'undefined')
1600
+ data[key] = value;
1601
+ else
1602
+ TinyHtml.removeData(el, key);
1568
1603
  return el;
1569
1604
  }
1570
1605
  /**
@@ -1578,6 +1613,55 @@ class TinyHtml {
1578
1613
  setData(key, value, isPrivate = false) {
1579
1614
  return TinyHtml.setData(this, key, value, isPrivate);
1580
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
+ }
1581
1665
  //////////////////////////////////////////////////////
1582
1666
  // TITLE: DOM Getter 2
1583
1667
  /**
@@ -1889,7 +1973,7 @@ class TinyHtml {
1889
1973
  continue;
1890
1974
  if (typeof item !== 'string' && typeof item !== 'number') {
1891
1975
  if (item instanceof Node || item instanceof TinyHtml)
1892
- results.push(TinyHtml._preNodeElems(item, where)[0]);
1976
+ results.push(...TinyHtml._preNodeElems(item, where));
1893
1977
  else if (Array.isArray(item))
1894
1978
  results.push(...TinyHtml._appendChecker(where, ...item));
1895
1979
  else {
@@ -2170,39 +2254,68 @@ class TinyHtml {
2170
2254
  return this.#el.length;
2171
2255
  }
2172
2256
  /**
2173
- * Creates an instance of TinyHtml for a specific Element.
2174
- * Useful when you want to operate repeatedly on the same element using instance methods.
2175
- * @param {TinyHtmlT} el - The element to wrap and manipulate.
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.
2176
2261
  */
2177
- constructor(el) {
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) {
2178
2290
  if (el instanceof TinyHtml)
2179
2291
  throw new Error(`[TinyHtml] You are trying to put a TinyHtml inside another TinyHtml in constructor.`);
2180
- /** @param {any[]} els */
2181
- const elCheck = (els) => {
2182
- if (!els.every((el) => el instanceof Element ||
2183
- el instanceof Window ||
2184
- el instanceof Document ||
2185
- el instanceof Text))
2186
- throw new Error(`[TinyHtml] Invalid Target in constructor.`);
2187
- };
2188
- if (Array.isArray(el)) {
2189
- elCheck(el);
2190
- 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);
2191
2298
  }
2192
- else if (el instanceof NodeList || el instanceof HTMLCollection) {
2193
- /** @type {ConstructorElValues[]} */
2194
- // @ts-ignore
2195
- const els = [...el];
2196
- elCheck(els);
2197
- this.#el = els;
2299
+ else if (selector instanceof NodeList || selector instanceof HTMLCollection) {
2300
+ const els = [...selector];
2301
+ TinyHtml._elCheck(els);
2302
+ return fixItemList(els);
2198
2303
  }
2199
2304
  else {
2200
- const els = [el];
2201
- elCheck(els);
2305
+ const els = [selector];
2306
+ TinyHtml._elCheck(els);
2202
2307
  // @ts-ignore
2203
- this.#el = els;
2308
+ return fixItemList(els);
2204
2309
  }
2205
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
+ }
2206
2319
  /**
2207
2320
  * Checks whether the given object is a window.
2208
2321
  * @param {*} obj - The object to test.