tiny-essentials 1.22.5 → 1.22.7

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.
Files changed (72) hide show
  1. package/changelog/1/1/0.md +1 -0
  2. package/changelog/1/10/0.md +19 -0
  3. package/changelog/1/10/2.md +23 -0
  4. package/changelog/1/11/0.md +66 -0
  5. package/changelog/1/12/0.md +54 -0
  6. package/changelog/1/12/1.md +37 -0
  7. package/changelog/1/12/2.md +29 -0
  8. package/changelog/1/13/0.md +41 -0
  9. package/changelog/1/13/1.md +7 -0
  10. package/changelog/1/13/2.md +13 -0
  11. package/changelog/1/14/0.md +33 -0
  12. package/changelog/1/15/0.md +39 -0
  13. package/changelog/1/16/0.md +42 -0
  14. package/changelog/1/16/1.md +43 -0
  15. package/changelog/1/16/2.md +29 -0
  16. package/changelog/1/17/0.md +28 -0
  17. package/changelog/1/17/1.md +40 -0
  18. package/changelog/1/18/0.md +43 -0
  19. package/changelog/1/18/1.md +12 -0
  20. package/changelog/1/19/1.md +21 -0
  21. package/changelog/1/19/2.md +23 -0
  22. package/changelog/1/19/3.md +15 -0
  23. package/changelog/1/2/0.md +5 -0
  24. package/changelog/1/2/1.md +5 -0
  25. package/changelog/1/20/0.md +9 -0
  26. package/changelog/1/20/1.md +40 -0
  27. package/changelog/1/20/2.md +22 -0
  28. package/changelog/1/20/3.md +39 -0
  29. package/changelog/1/21/0.md +23 -0
  30. package/changelog/1/21/1.md +12 -0
  31. package/changelog/1/21/10.md +23 -0
  32. package/changelog/1/21/2.md +9 -0
  33. package/changelog/1/21/3.md +9 -0
  34. package/changelog/1/21/4.md +9 -0
  35. package/changelog/1/21/6.md +23 -0
  36. package/changelog/1/21/7.md +16 -0
  37. package/changelog/1/21/8.md +5 -0
  38. package/changelog/1/21/9.md +17 -0
  39. package/changelog/1/22/1.md +28 -0
  40. package/changelog/1/22/2.md +17 -0
  41. package/changelog/1/22/3.md +11 -0
  42. package/changelog/1/22/4.md +35 -0
  43. package/changelog/1/22/5.md +23 -0
  44. package/changelog/1/22/6.md +27 -0
  45. package/changelog/1/22/7.md +5 -0
  46. package/changelog/1/3/1.md +4 -0
  47. package/changelog/1/3/2.md +2 -0
  48. package/changelog/1/4/0.md +5 -0
  49. package/changelog/1/5/0.md +4 -0
  50. package/changelog/1/5/1.md +2 -0
  51. package/changelog/1/6/0.md +6 -0
  52. package/changelog/1/7/0.md +3 -0
  53. package/changelog/1/7/1.md +3 -0
  54. package/changelog/1/8/0.md +3 -0
  55. package/changelog/1/8/1.md +2 -0
  56. package/changelog/1/8/2.md +2 -0
  57. package/changelog/1/8/3.md +3 -0
  58. package/changelog/1/8/4.md +2 -0
  59. package/changelog/1/8/5.md +6 -0
  60. package/changelog/1/9/0.md +27 -0
  61. package/changelog/1/9/1.md +5 -0
  62. package/changelog/1/9/2.md +14 -0
  63. package/dist/v1/TinyDragger.min.js +1 -1
  64. package/dist/v1/TinyEssentials.min.js +1 -1
  65. package/dist/v1/TinyHtml.min.js +1 -1
  66. package/dist/v1/TinySmartScroller.min.js +1 -1
  67. package/dist/v1/TinyUploadClicker.min.js +1 -1
  68. package/dist/v1/libs/TinyHtml.cjs +129 -17
  69. package/dist/v1/libs/TinyHtml.d.mts +110 -22
  70. package/dist/v1/libs/TinyHtml.mjs +122 -17
  71. package/docs/v1/libs/TinyHtml.md +105 -0
  72. package/package.json +1 -1
@@ -8,6 +8,11 @@ const { areElsColliding, areElsPerfColliding, areElsCollTop, areElsCollBottom, a
8
8
  * Represents a TinyHtml instance with any constructor element values.
9
9
  * @typedef {TinyHtml<ConstructorElValues>} TinyHtmlAny
10
10
  */
11
+ /**
12
+ * Represents the valid values that can be appended to a TinyNode.
13
+ *
14
+ * @typedef {TinyNode | TinyNode[] | string | false | null | undefined} AppendCheckerValues
15
+ */
11
16
  /**
12
17
  * Callback function used for hover events.
13
18
  * @callback HoverEventCallback
@@ -286,6 +291,90 @@ const __elemCollision = {
286
291
  class TinyHtml {
287
292
  /** @typedef {import('../basics/collision.mjs').ObjRect} ObjRect */
288
293
  static Utils = { ...TinyCollision };
294
+ /**
295
+ * Controls whether TinyHtml emits detailed debug output to the console.
296
+ * When enabled, helper methods print structured diagnostics for easier troubleshooting.
297
+ * @type {boolean}
298
+ */
299
+ static #elemDebug = false;
300
+ /**
301
+ * Gets whether debug output is enabled.
302
+ * @returns {boolean} True if debug output is enabled; otherwise, false.
303
+ */
304
+ static get elemDebug() {
305
+ return TinyHtml.#elemDebug;
306
+ }
307
+ /**
308
+ * Enables or disables debug output.
309
+ * @param {boolean} value True to enable debug output; false to disable.
310
+ * @throws {TypeError} Thrown if the provided value is not a boolean.
311
+ * @returns {void}
312
+ */
313
+ static set elemDebug(value) {
314
+ if (typeof value !== 'boolean')
315
+ throw new TypeError('Expected a boolean value for elemDebug');
316
+ TinyHtml.#elemDebug = value;
317
+ }
318
+ /**
319
+ * Logs a standardized debug error for element validation, including a console.table
320
+ * with the involved elements. Use this when an element argument is invalid, unexpected,
321
+ * or fails a guard/validation.
322
+ *
323
+ * The output includes:
324
+ * - A concise error header
325
+ * - A stack trace (when supported)
326
+ * - A table of elements (index, typeof, constructor, summary, value)
327
+ * - The specific problematic element, if provided
328
+ *
329
+ * @param {(ConstructorElValues | EventTarget | TinyElement | null)[]} elems
330
+ * A list of elements participating in the operation (may include nulls).
331
+ * @param {ConstructorElValues | EventTarget | TinyElement | null} [elem]
332
+ * The specific element that triggered the error, if available.
333
+ * @returns {void}
334
+ */
335
+ static _debugElemError(elems, elem) {
336
+ if (!TinyHtml.#elemDebug)
337
+ return;
338
+ const header = '[TinyHtml Debug] Element validation error';
339
+ console.groupCollapsed(`${header}${elem ? ' — details below' : ''}`);
340
+ console.error(header);
341
+ // Stack trace for call-site visibility
342
+ if (typeof Error !== 'undefined' && typeof Error.captureStackTrace === 'function') {
343
+ const err = new Error(header);
344
+ Error.captureStackTrace(err, TinyHtml._debugElemError);
345
+ console.error(err.stack);
346
+ }
347
+ else {
348
+ console.trace(header);
349
+ }
350
+ // Tabular overview of provided elements
351
+ if (Array.isArray(elems)) {
352
+ const rows = elems.map((el, index) => {
353
+ const typeOf = el === null ? 'null' : typeof el;
354
+ const ctor = el?.constructor?.name ?? (el === null ? 'null' : 'primitive');
355
+ const isDomEl = typeof Element !== 'undefined' && el instanceof Element;
356
+ const summary = isDomEl
357
+ ? `${el.tagName?.toLowerCase?.() ?? 'element'}#${el.id || ''}.${String(el.className || '')
358
+ .trim()
359
+ .replace(/\s+/g, '.')}`
360
+ : el && typeof el === 'object' && 'nodeType' in el
361
+ ? `nodeType:${ /** @type {any} */(el).nodeType}`
362
+ : '';
363
+ return { index, typeOf, constructor: ctor, summary, value: el };
364
+ });
365
+ console.table(rows);
366
+ }
367
+ else {
368
+ console.warn('[TinyHtml Debug] "elems" is not an array:', elems);
369
+ }
370
+ // Highlight the specific problematic element, if any
371
+ if (arguments.length > 1) {
372
+ console.error('[TinyHtml Debug] Problematic element:', elem);
373
+ if (elem && typeof elem === 'object')
374
+ console.dir(elem);
375
+ }
376
+ console.groupEnd();
377
+ }
289
378
  /**
290
379
  * Parse inline styles into an object.
291
380
  * @param {string} styleText
@@ -815,8 +904,10 @@ class TinyHtml {
815
904
  if (!(this.#el[index] instanceof Element) &&
816
905
  !(this.#el[index] instanceof Window) &&
817
906
  !(this.#el[index] instanceof Document) &&
818
- !(this.#el[index] instanceof Text))
907
+ !(this.#el[index] instanceof Text)) {
908
+ TinyHtml._debugElemError([...this.#el], this.#el[index]);
819
909
  throw new Error(`[TinyHtml] Invalid Element in ${where}().`);
910
+ }
820
911
  return this.#el[index];
821
912
  }
822
913
  /**
@@ -830,8 +921,10 @@ class TinyHtml {
830
921
  if (!this.#el.every((el) => el instanceof Element ||
831
922
  el instanceof Window ||
832
923
  el instanceof Document ||
833
- el instanceof Text))
924
+ el instanceof Text)) {
925
+ TinyHtml._debugElemError([...this.#el]);
834
926
  throw new Error(`[TinyHtml] Invalid Element in ${where}().`);
927
+ }
835
928
  return [...this.#el];
836
929
  }
837
930
  //////////////////////////////////////////////////////
@@ -860,8 +953,10 @@ class TinyHtml {
860
953
  break;
861
954
  }
862
955
  }
863
- if (!allowed)
956
+ if (!allowed) {
957
+ TinyHtml._debugElemError([...item], result);
864
958
  throw new Error(`[TinyHtml] Invalid element of the list "${elemName.join(',')}" in ${where}().`);
959
+ }
865
960
  results.push(result);
866
961
  return result;
867
962
  }));
@@ -888,8 +983,10 @@ class TinyHtml {
888
983
  const checkElement = (item) => {
889
984
  const elem = item[0];
890
985
  const result = elem instanceof TinyHtml ? elem._getElements(where) : [elem];
891
- if (result.length > 1)
986
+ if (result.length > 1) {
987
+ TinyHtml._debugElemError([...item]);
892
988
  throw new Error(`[TinyHtml] Invalid element amount in ${where}() (Received ${result.length}/1).`);
989
+ }
893
990
  let allowed = false;
894
991
  for (const TheTinyElement of TheTinyElements) {
895
992
  if (result[0] instanceof TheTinyElement) {
@@ -901,14 +998,18 @@ class TinyHtml {
901
998
  result[0] = null;
902
999
  allowed = true;
903
1000
  }
904
- if (!allowed)
1001
+ if (!allowed) {
1002
+ TinyHtml._debugElemError([...item], result[0]);
905
1003
  throw new Error(`[TinyHtml] Invalid element of the list "${elemName.join(',')}" in ${where}().`);
1004
+ }
906
1005
  return result[0];
907
1006
  };
908
1007
  if (!Array.isArray(elems))
909
1008
  return checkElement([elems]);
910
- if (elems.length > 1)
1009
+ if (elems.length > 1) {
1010
+ TinyHtml._debugElemError([...elems]);
911
1011
  throw new Error(`[TinyHtml] Invalid element amount in ${where}() (Received ${elems.length}/1).`);
1012
+ }
912
1013
  return checkElement(elems);
913
1014
  }
914
1015
  /**
@@ -1772,13 +1873,17 @@ class TinyHtml {
1772
1873
  /**
1773
1874
  * Normalize and validate nodes before DOM insertion.
1774
1875
  * Converts TinyNode-like structures or strings into DOM-compatible nodes.
1775
- * @type {(where: string, ...nodes: (TinyNode | TinyNode[] | string)[]) => (Node | string)[]}
1876
+ * @type {(where: string, ...nodes: AppendCheckerValues[]) => (Node | string)[]}
1776
1877
  * @readonly
1777
1878
  */
1778
1879
  static _appendChecker(where, ...nodes) {
1779
1880
  const results = [];
1780
1881
  const nds = [...nodes];
1781
1882
  for (const index in nds) {
1883
+ if (typeof nds[index] === 'undefined' ||
1884
+ nds[index] === null ||
1885
+ nds[index] === false)
1886
+ continue;
1782
1887
  if (typeof nds[index] !== 'string') {
1783
1888
  results.push(TinyHtml._preNodeElem(nds[index], where));
1784
1889
  }
@@ -1792,7 +1897,7 @@ class TinyHtml {
1792
1897
  *
1793
1898
  * @template {TinyElement} T
1794
1899
  * @param {T} el - The target element(s) to receive children.
1795
- * @param {...(TinyNode | TinyNode[] | string)} children - The child elements or text to append.
1900
+ * @param {...AppendCheckerValues} children - The child elements or text to append.
1796
1901
  * @returns {T}
1797
1902
  */
1798
1903
  static append(el, ...children) {
@@ -1803,7 +1908,7 @@ class TinyHtml {
1803
1908
  /**
1804
1909
  * Appends child elements or strings to the end of the target element(s).
1805
1910
  *
1806
- * @param {...(TinyNode | TinyNode[] | string)} children - The child elements or text to append.
1911
+ * @param {...AppendCheckerValues} children - The child elements or text to append.
1807
1912
  * @returns {this}
1808
1913
  */
1809
1914
  append(...children) {
@@ -1814,7 +1919,7 @@ class TinyHtml {
1814
1919
  *
1815
1920
  * @template {TinyElement} T
1816
1921
  * @param {T} el - The target element(s) to receive children.
1817
- * @param {...(TinyNode | TinyNode[] | string)} children - The child elements or text to prepend.
1922
+ * @param {...AppendCheckerValues} children - The child elements or text to prepend.
1818
1923
  * @returns {T}
1819
1924
  */
1820
1925
  static prepend(el, ...children) {
@@ -1825,7 +1930,7 @@ class TinyHtml {
1825
1930
  /**
1826
1931
  * Prepends child elements or strings to the beginning of the target element(s).
1827
1932
  *
1828
- * @param {...(TinyNode | TinyNode[] | string)} children - The child elements or text to prepend.
1933
+ * @param {...AppendCheckerValues} children - The child elements or text to prepend.
1829
1934
  * @returns {this}
1830
1935
  */
1831
1936
  prepend(...children) {
@@ -1836,7 +1941,7 @@ class TinyHtml {
1836
1941
  *
1837
1942
  * @template {TinyElement} T
1838
1943
  * @param {T} el - The target element(s) before which new content is inserted.
1839
- * @param {...(TinyNode | TinyNode[] | string)} children - Elements or text to insert before the target.
1944
+ * @param {...AppendCheckerValues} children - Elements or text to insert before the target.
1840
1945
  * @returns {T}
1841
1946
  */
1842
1947
  static before(el, ...children) {
@@ -1847,7 +1952,7 @@ class TinyHtml {
1847
1952
  /**
1848
1953
  * Inserts elements or strings immediately before the target element(s) in the DOM.
1849
1954
  *
1850
- * @param {...(TinyNode | TinyNode[] | string)} children - Elements or text to insert before the target.
1955
+ * @param {...AppendCheckerValues} children - Elements or text to insert before the target.
1851
1956
  * @returns {this}
1852
1957
  */
1853
1958
  before(...children) {
@@ -1858,7 +1963,7 @@ class TinyHtml {
1858
1963
  *
1859
1964
  * @template {TinyElement} T
1860
1965
  * @param {T} el - The target element(s) after which new content is inserted.
1861
- * @param {...(TinyNode | TinyNode[] | string)} children - Elements or text to insert after the target.
1966
+ * @param {...AppendCheckerValues} children - Elements or text to insert after the target.
1862
1967
  * @returns {T}
1863
1968
  */
1864
1969
  static after(el, ...children) {
@@ -1869,7 +1974,7 @@ class TinyHtml {
1869
1974
  /**
1870
1975
  * Inserts elements or strings immediately after the target element(s) in the DOM.
1871
1976
  *
1872
- * @param {...(TinyNode | TinyNode[] | string)} children - Elements or text to insert after the target.
1977
+ * @param {...AppendCheckerValues} children - Elements or text to insert after the target.
1873
1978
  * @returns {this}
1874
1979
  */
1875
1980
  after(...children) {
@@ -1880,7 +1985,7 @@ class TinyHtml {
1880
1985
  *
1881
1986
  * @template {TinyElement} T
1882
1987
  * @param {T} el - The element(s) to be replaced.
1883
- * @param {...(TinyNode | TinyNode[] | string)} newNodes - New elements or text to replace the target.
1988
+ * @param {...AppendCheckerValues} newNodes - New elements or text to replace the target.
1884
1989
  * @returns {T}
1885
1990
  */
1886
1991
  static replaceWith(el, ...newNodes) {
@@ -1891,7 +1996,7 @@ class TinyHtml {
1891
1996
  /**
1892
1997
  * Replaces the target element(s) in the DOM with new elements or text.
1893
1998
  *
1894
- * @param {...(TinyNode | TinyNode[] | string)} newNodes - New elements or text to replace the target.
1999
+ * @param {...AppendCheckerValues} newNodes - New elements or text to replace the target.
1895
2000
  * @returns {this}
1896
2001
  */
1897
2002
  replaceWith(...newNodes) {
@@ -19,6 +19,7 @@ This design keeps your code concise while maintaining clarity and control over t
19
19
  ## 📑 Table of Contents
20
20
 
21
21
  - [🧩 Type Definitions – Core Building Blocks](#-type-definitions--core-building-blocks)
22
+ - [🔍 Element Debugging System](#-element-debugging-system)
22
23
  - [🔨 Element Creation](#-element-creation)
23
24
  - [🔎 Static DOM Selectors](#-static-dom-selectors)
24
25
  - [🔍 Element Observer](#-element-observer)
@@ -525,6 +526,110 @@ const __elementCurrentAnimation = new WeakMap();
525
526
 
526
527
  ---
527
528
 
529
+ ## 🔍 Element Debugging System
530
+
531
+ TinyHtml includes a built-in **element debugging system** to help developers identify issues with elements during validation, construction, or event handling.
532
+
533
+ This feature is **disabled by default** and can be toggled on or off.
534
+
535
+ ---
536
+
537
+ ### ⚙️ Enabling Debug Mode
538
+
539
+ ```js
540
+ TinyHtml.elemDebug = true; // Enable
541
+ TinyHtml.elemDebug = false; // Disable
542
+ ```
543
+
544
+ #### API
545
+
546
+ * **`TinyHtml.elemDebug` (boolean)**
547
+ Controls whether TinyHtml emits detailed debug output to the console.
548
+
549
+ * **Getter**
550
+
551
+ ```js
552
+ TinyHtml.elemDebug; // Returns true or false
553
+ ```
554
+
555
+ * **Setter**
556
+
557
+ ```js
558
+ TinyHtml.elemDebug = true; // Enable debug logs
559
+ TinyHtml.elemDebug = false; // Disable debug logs
560
+ ```
561
+
562
+ 🚨 Throws `TypeError` if the value is not a boolean.
563
+
564
+ ---
565
+
566
+ ### 🛠 Debugging Invalid Elements
567
+
568
+ When debug mode is enabled, TinyHtml will log structured information whenever an invalid or unexpected element is passed to its internal operations.
569
+
570
+ This is done through the internal method:
571
+
572
+ ```js
573
+ TinyHtml._debugElemError(elems, elem);
574
+ ```
575
+
576
+ #### Parameters
577
+
578
+ * **`elems`** → An array of elements (`ConstructorElValues | EventTarget | TinyElement | null`) involved in the operation.
579
+ * **`elem`** *(optional)* → The specific element that triggered the error.
580
+
581
+ #### Output Includes
582
+
583
+ * ❌ **Error header** in the console
584
+ * 🧭 **Stack trace** (with `console.trace` or captured stack)
585
+ * 📊 **`console.table`** showing:
586
+
587
+ * Index
588
+ * `typeof`
589
+ * Constructor name
590
+ * Summary (DOM tag, ID, class, or nodeType)
591
+ * The raw value
592
+ * 🎯 **Problematic element** highlighted separately via `console.dir`
593
+
594
+ ---
595
+
596
+ ### 📋 Example Output
597
+
598
+ When debug mode is enabled and an invalid element is detected, you may see something like this:
599
+
600
+ ```
601
+ [TinyHtml Debug] Element validation error
602
+ Error: [TinyHtml Debug] Element validation error
603
+ at TinyHtml._debugElemError (...)
604
+ at ...
605
+ ```
606
+
607
+ Followed by a **console.table**:
608
+
609
+ | index | typeOf | constructor | summary | value |
610
+ | ----- | ------ | ----------- | ------------------ | ------------- |
611
+ | 0 | object | TinyElement | div#main.container | TinyElement{} |
612
+ | 1 | string | primitive | | "invalid" |
613
+ | 2 | null | null | | null |
614
+
615
+ And a detailed log of the problematic element:
616
+
617
+ ```
618
+ [TinyHtml Debug] Problematic element:
619
+ <div id="main" class="container">...</div>
620
+ ```
621
+
622
+ ---
623
+
624
+ ### ✅ Summary
625
+
626
+ * 🔧 Enable debug with `TinyHtml.elemDebug = true;`
627
+ * 🐞 Detailed errors are shown only when debug mode is on
628
+ * 📊 Uses `console.table`, `console.error`, and `console.dir` for clarity
629
+ * 🚀 Zero runtime overhead when disabled
630
+
631
+ ---
632
+
528
633
  ## 🔨 Element Creation
529
634
 
530
635
  ### `TinyHtml.createFrom(tagName, attrs?)`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tiny-essentials",
3
- "version": "1.22.5",
3
+ "version": "1.22.7",
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",