tiny-essentials 1.22.4 → 1.22.6

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 (71) 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 +25 -0
  45. package/changelog/1/3/1.md +4 -0
  46. package/changelog/1/3/2.md +2 -0
  47. package/changelog/1/4/0.md +5 -0
  48. package/changelog/1/5/0.md +4 -0
  49. package/changelog/1/5/1.md +2 -0
  50. package/changelog/1/6/0.md +6 -0
  51. package/changelog/1/7/0.md +3 -0
  52. package/changelog/1/7/1.md +3 -0
  53. package/changelog/1/8/0.md +3 -0
  54. package/changelog/1/8/1.md +2 -0
  55. package/changelog/1/8/2.md +2 -0
  56. package/changelog/1/8/3.md +3 -0
  57. package/changelog/1/8/4.md +2 -0
  58. package/changelog/1/8/5.md +6 -0
  59. package/changelog/1/9/0.md +27 -0
  60. package/changelog/1/9/1.md +5 -0
  61. package/changelog/1/9/2.md +14 -0
  62. package/dist/v1/TinyDragger.min.js +1 -1
  63. package/dist/v1/TinyEssentials.min.js +1 -1
  64. package/dist/v1/TinyHtml.min.js +1 -1
  65. package/dist/v1/TinySmartScroller.min.js +1 -1
  66. package/dist/v1/TinyUploadClicker.min.js +1 -1
  67. package/dist/v1/libs/TinyHtml.cjs +400 -20
  68. package/dist/v1/libs/TinyHtml.d.mts +220 -6
  69. package/dist/v1/libs/TinyHtml.mjs +384 -23
  70. package/docs/v1/libs/TinyHtml.md +36 -0
  71. package/package.json +1 -1
@@ -339,6 +339,94 @@ class TinyHtml {
339
339
 
340
340
  static Utils = { ...collision };
341
341
 
342
+ /**
343
+ * Controls whether TinyHtml emits detailed debug output to the console.
344
+ * When enabled, helper methods print structured diagnostics for easier troubleshooting.
345
+ * @type {boolean}
346
+ */
347
+ static #elemDebug = false;
348
+
349
+ /**
350
+ * Gets whether debug output is enabled.
351
+ * @returns {boolean} True if debug output is enabled; otherwise, false.
352
+ */
353
+ static get elemDebug() {
354
+ return TinyHtml.#elemDebug;
355
+ }
356
+
357
+ /**
358
+ * Enables or disables debug output.
359
+ * @param {boolean} value True to enable debug output; false to disable.
360
+ * @throws {TypeError} Thrown if the provided value is not a boolean.
361
+ * @returns {void}
362
+ */
363
+ static set elemDebug(value) {
364
+ if (typeof value !== 'boolean') throw new TypeError('Expected a boolean value for elemDebug');
365
+ TinyHtml.#elemDebug = value;
366
+ }
367
+
368
+ /**
369
+ * Logs a standardized debug error for element validation, including a console.table
370
+ * with the involved elements. Use this when an element argument is invalid, unexpected,
371
+ * or fails a guard/validation.
372
+ *
373
+ * The output includes:
374
+ * - A concise error header
375
+ * - A stack trace (when supported)
376
+ * - A table of elements (index, typeof, constructor, summary, value)
377
+ * - The specific problematic element, if provided
378
+ *
379
+ * @param {(ConstructorElValues | EventTarget | TinyElement | null)[]} elems
380
+ * A list of elements participating in the operation (may include nulls).
381
+ * @param {ConstructorElValues | EventTarget | TinyElement | null} [elem]
382
+ * The specific element that triggered the error, if available.
383
+ * @returns {void}
384
+ */
385
+ static _debugElemError(elems, elem) {
386
+ if (!TinyHtml.#elemDebug) return;
387
+ const header = '[TinyHtml Debug] Element validation error';
388
+
389
+ console.groupCollapsed(`${header}${elem ? ' — details below' : ''}`);
390
+ console.error(header);
391
+
392
+ // Stack trace for call-site visibility
393
+ if (typeof Error !== 'undefined' && typeof Error.captureStackTrace === 'function') {
394
+ const err = new Error(header);
395
+ Error.captureStackTrace(err, TinyHtml._debugElemError);
396
+ console.error(err.stack);
397
+ } else {
398
+ console.trace(header);
399
+ }
400
+
401
+ // Tabular overview of provided elements
402
+ if (Array.isArray(elems)) {
403
+ const rows = elems.map((el, index) => {
404
+ const typeOf = el === null ? 'null' : typeof el;
405
+ const ctor = el?.constructor?.name ?? (el === null ? 'null' : 'primitive');
406
+ const isDomEl = typeof Element !== 'undefined' && el instanceof Element;
407
+ const summary = isDomEl
408
+ ? `${el.tagName?.toLowerCase?.() ?? 'element'}#${el.id || ''}.${String(el.className || '')
409
+ .trim()
410
+ .replace(/\s+/g, '.')}`
411
+ : el && typeof el === 'object' && 'nodeType' in el
412
+ ? `nodeType:${/** @type {any} */ (el).nodeType}`
413
+ : '';
414
+ return { index, typeOf, constructor: ctor, summary, value: el };
415
+ });
416
+ console.table(rows);
417
+ } else {
418
+ console.warn('[TinyHtml Debug] "elems" is not an array:', elems);
419
+ }
420
+
421
+ // Highlight the specific problematic element, if any
422
+ if (arguments.length > 1) {
423
+ console.error('[TinyHtml Debug] Problematic element:', elem);
424
+ if (elem && typeof elem === 'object') console.dir(elem);
425
+ }
426
+
427
+ console.groupEnd();
428
+ }
429
+
342
430
  /**
343
431
  * Parse inline styles into an object.
344
432
  * @param {string} styleText
@@ -943,8 +1031,10 @@ class TinyHtml {
943
1031
  !(this.#el[index] instanceof Window) &&
944
1032
  !(this.#el[index] instanceof Document) &&
945
1033
  !(this.#el[index] instanceof Text)
946
- )
1034
+ ) {
1035
+ TinyHtml._debugElemError([...this.#el], this.#el[index]);
947
1036
  throw new Error(`[TinyHtml] Invalid Element in ${where}().`);
1037
+ }
948
1038
  return this.#el[index];
949
1039
  }
950
1040
 
@@ -964,8 +1054,10 @@ class TinyHtml {
964
1054
  el instanceof Document ||
965
1055
  el instanceof Text,
966
1056
  )
967
- )
1057
+ ) {
1058
+ TinyHtml._debugElemError([...this.#el]);
968
1059
  throw new Error(`[TinyHtml] Invalid Element in ${where}().`);
1060
+ }
969
1061
  return [...this.#el];
970
1062
  }
971
1063
 
@@ -998,10 +1090,12 @@ class TinyHtml {
998
1090
  break;
999
1091
  }
1000
1092
  }
1001
- if (!allowed)
1093
+ if (!allowed) {
1094
+ TinyHtml._debugElemError([...item], result);
1002
1095
  throw new Error(
1003
1096
  `[TinyHtml] Invalid element of the list "${elemName.join(',')}" in ${where}().`,
1004
1097
  );
1098
+ }
1005
1099
  results.push(result);
1006
1100
  return result;
1007
1101
  }),
@@ -1029,10 +1123,12 @@ class TinyHtml {
1029
1123
  const checkElement = (item) => {
1030
1124
  const elem = item[0];
1031
1125
  const result = elem instanceof TinyHtml ? elem._getElements(where) : [elem];
1032
- if (result.length > 1)
1126
+ if (result.length > 1) {
1127
+ TinyHtml._debugElemError([...item]);
1033
1128
  throw new Error(
1034
1129
  `[TinyHtml] Invalid element amount in ${where}() (Received ${result.length}/1).`,
1035
1130
  );
1131
+ }
1036
1132
 
1037
1133
  let allowed = false;
1038
1134
  for (const TheTinyElement of TheTinyElements) {
@@ -1047,17 +1143,21 @@ class TinyHtml {
1047
1143
  allowed = true;
1048
1144
  }
1049
1145
 
1050
- if (!allowed)
1146
+ if (!allowed) {
1147
+ TinyHtml._debugElemError([...item], result[0]);
1051
1148
  throw new Error(
1052
1149
  `[TinyHtml] Invalid element of the list "${elemName.join(',')}" in ${where}().`,
1053
1150
  );
1151
+ }
1054
1152
  return result[0];
1055
1153
  };
1056
1154
  if (!Array.isArray(elems)) return checkElement([elems]);
1057
- if (elems.length > 1)
1155
+ if (elems.length > 1) {
1156
+ TinyHtml._debugElemError([...elems]);
1058
1157
  throw new Error(
1059
1158
  `[TinyHtml] Invalid element amount in ${where}() (Received ${elems.length}/1).`,
1060
1159
  );
1160
+ }
1061
1161
  return checkElement(elems);
1062
1162
  }
1063
1163
 
@@ -6518,6 +6618,291 @@ class TinyHtml {
6518
6618
  return propName;
6519
6619
  }
6520
6620
 
6621
+ ////////////////////////////////////////////////////////////////////
6622
+
6623
+ /**
6624
+ * Returns the BigInt value of an attribute.
6625
+ * @param {TinyElement} el
6626
+ * @param {string} name
6627
+ * @returns {bigint|null}
6628
+ */
6629
+ static attrBigInt(el, name) {
6630
+ const elem = TinyHtml._preElem(el, 'attrBigInt');
6631
+ const val = elem.getAttribute(TinyHtml.getAttrName(name));
6632
+ if (val == null) return null;
6633
+ try {
6634
+ return BigInt(val);
6635
+ } catch {
6636
+ return null;
6637
+ }
6638
+ }
6639
+
6640
+ /**
6641
+ * Returns the BigInt value of an attribute.
6642
+ * @param {string} name
6643
+ * @returns {bigint|null}
6644
+ */
6645
+ attrBigInt(name) {
6646
+ return TinyHtml.attrBigInt(this, name);
6647
+ }
6648
+
6649
+ /**
6650
+ * Set a BigInt attribute.
6651
+ * @template {TinyElement|TinyElement[]} T
6652
+ * @param {T} el
6653
+ * @param {string} name
6654
+ * @param {bigint} value
6655
+ * @returns {T}
6656
+ */
6657
+ static setAttrBigInt(el, name, value) {
6658
+ if (typeof value !== 'bigint') throw new Error('Value is not a valid BigInt.');
6659
+ return TinyHtml.setAttr(el, name, value.toString());
6660
+ }
6661
+
6662
+ /**
6663
+ * Set a BigInt attribute.
6664
+ * @param {string} name
6665
+ * @param {bigint} value
6666
+ * @returns {this}
6667
+ */
6668
+ setAttrBigInt(name, value) {
6669
+ return TinyHtml.setAttrBigInt(this, name, value);
6670
+ }
6671
+
6672
+ /**
6673
+ * Returns the Date value of an attribute.
6674
+ * @param {TinyElement} el
6675
+ * @param {string} name
6676
+ * @returns {Date|null}
6677
+ */
6678
+ static attrDate(el, name) {
6679
+ const elem = TinyHtml._preElem(el, 'attrDate');
6680
+ const val = elem.getAttribute(TinyHtml.getAttrName(name));
6681
+ if (!val) return null;
6682
+ const d = new Date(val);
6683
+ return Number.isNaN(d.getTime()) ? null : d;
6684
+ }
6685
+
6686
+ /**
6687
+ * Returns the Date value of an attribute.
6688
+ * @param {string} name
6689
+ * @returns {Date|null}
6690
+ */
6691
+ attrDate(name) {
6692
+ return TinyHtml.attrDate(this, name);
6693
+ }
6694
+
6695
+ /**
6696
+ * Set a Date attribute.
6697
+ * @template {TinyElement|TinyElement[]} T
6698
+ * @param {T} el
6699
+ * @param {string} name
6700
+ * @param {Date} value
6701
+ * @returns {T}
6702
+ */
6703
+ static setAttrDate(el, name, value) {
6704
+ if (!(value instanceof Date) || Number.isNaN(value.getTime()))
6705
+ throw new Error('Value is not a valid Date.');
6706
+ return TinyHtml.setAttr(el, name, value.toISOString());
6707
+ }
6708
+
6709
+ /**
6710
+ * Set a Date attribute.
6711
+ * @param {string} name
6712
+ * @param {Date} value
6713
+ * @returns {this}
6714
+ */
6715
+ setAttrDate(name, value) {
6716
+ return TinyHtml.setAttrDate(this, name, value);
6717
+ }
6718
+
6719
+ /**
6720
+ * Returns the JSON value of an attribute.
6721
+ * @param {TinyElement} el
6722
+ * @param {string} name
6723
+ * @returns {any|null}
6724
+ */
6725
+ static attrJson(el, name) {
6726
+ const elem = TinyHtml._preElem(el, 'attrJson');
6727
+ const val = elem.getAttribute(TinyHtml.getAttrName(name));
6728
+ if (!val) return null;
6729
+ try {
6730
+ return JSON.parse(val);
6731
+ } catch {
6732
+ return null;
6733
+ }
6734
+ }
6735
+
6736
+ /**
6737
+ * Returns the JSON value of an attribute.
6738
+ * @param {string} name
6739
+ * @returns {any|null}
6740
+ */
6741
+ attrJson(name) {
6742
+ return TinyHtml.attrJson(this, name);
6743
+ }
6744
+
6745
+ /**
6746
+ * Set a JSON attribute.
6747
+ * @template {TinyElement|TinyElement[]} T
6748
+ * @param {T} el
6749
+ * @param {string} name
6750
+ * @param {any} value
6751
+ * @param {(this: any, key: string, value: any) => any} [replacer]
6752
+ * @param {number|string} [space]
6753
+ * @returns {T}
6754
+ */
6755
+ static setAttrJson(el, name, value, replacer, space) {
6756
+ const data = JSON.stringify(value, replacer, space);
6757
+ return TinyHtml.setAttr(el, name, data);
6758
+ }
6759
+
6760
+ /**
6761
+ * Set a JSON attribute.
6762
+ * @param {string} name
6763
+ * @param {any} value
6764
+ * @param {(this: any, key: string, value: any) => any} [replacer]
6765
+ * @param {number|string} [space]
6766
+ * @returns {this}
6767
+ */
6768
+ setAttrJson(name, value, replacer, space) {
6769
+ return TinyHtml.setAttrJson(this, name, value, replacer, space);
6770
+ }
6771
+
6772
+ /**
6773
+ * Returns the number value of an attribute.
6774
+ * @param {TinyElement} el
6775
+ * @param {string} name
6776
+ * @returns {number|null}
6777
+ */
6778
+ static attrNumber(el, name) {
6779
+ const elem = TinyHtml._preElem(el, 'attrNumber');
6780
+ const val = elem.getAttribute(TinyHtml.getAttrName(name));
6781
+ return val != null ? parseFloat(val) : null;
6782
+ }
6783
+
6784
+ /**
6785
+ * Returns the number value of an attribute.
6786
+ * @param {string} name
6787
+ * @returns {number|null}
6788
+ */
6789
+ attrNumber(name) {
6790
+ return TinyHtml.attrNumber(this, name);
6791
+ }
6792
+
6793
+ /**
6794
+ * Set a number attribute.
6795
+ * @template {TinyElement|TinyElement[]} T
6796
+ * @param {T} el
6797
+ * @param {string} name
6798
+ * @param {number} value
6799
+ * @returns {T}
6800
+ */
6801
+ static setAttrNumber(el, name, value) {
6802
+ if (typeof value !== 'number') throw new Error('Value is not a valid number.');
6803
+ return TinyHtml.setAttr(el, name, value.toString());
6804
+ }
6805
+
6806
+ /**
6807
+ * Set a number attribute.
6808
+ * @param {string} name
6809
+ * @param {number} value
6810
+ * @returns {this}
6811
+ */
6812
+ setAttrNumber(name, value) {
6813
+ return TinyHtml.setAttrNumber(this, name, value);
6814
+ }
6815
+
6816
+ /**
6817
+ * Returns the boolean value of an attribute.
6818
+ * @param {TinyElement} el
6819
+ * @param {string} name
6820
+ * @returns {boolean|null}
6821
+ */
6822
+ static attrBoolean(el, name) {
6823
+ const elem = TinyHtml._preElem(el, 'attrBoolean');
6824
+ const val = elem.getAttribute(TinyHtml.getAttrName(name));
6825
+ if (val === null) return null;
6826
+ if (val !== 'true' && val !== 'false') return null;
6827
+ return /^true$/i.test(val);
6828
+ }
6829
+
6830
+ /**
6831
+ * Returns the boolean value of an attribute.
6832
+ * @param {string} name
6833
+ * @returns {boolean|null}
6834
+ */
6835
+ attrBoolean(name) {
6836
+ return TinyHtml.attrBoolean(this, name);
6837
+ }
6838
+
6839
+ /**
6840
+ * Set a boolean attribute.
6841
+ * @template {TinyElement|TinyElement[]} T
6842
+ * @param {T} el
6843
+ * @param {string} name
6844
+ * @param {boolean} value
6845
+ * @returns {T}
6846
+ */
6847
+ static setAttrBoolean(el, name, value) {
6848
+ if (typeof value !== 'boolean') throw new Error('Value is not a valid boolean.');
6849
+ return TinyHtml.setAttr(el, name, value.toString());
6850
+ }
6851
+
6852
+ /**
6853
+ * Set a boolean attribute.
6854
+ * @param {string} name
6855
+ * @param {boolean} value
6856
+ * @returns {this}
6857
+ */
6858
+ setAttrBoolean(name, value) {
6859
+ return TinyHtml.setAttrBoolean(this, name, value);
6860
+ }
6861
+
6862
+ /**
6863
+ * Returns the string value of an attribute.
6864
+ * @param {TinyElement} el
6865
+ * @param {string} name
6866
+ * @returns {string|null}
6867
+ */
6868
+ static attrString(el, name) {
6869
+ const elem = TinyHtml._preElem(el, 'attrString');
6870
+ const value = elem.getAttribute(TinyHtml.getAttrName(name));
6871
+ return typeof value === 'string' ? value : null;
6872
+ }
6873
+
6874
+ /**
6875
+ * Returns the string value of an attribute.
6876
+ * @param {string} name
6877
+ * @returns {string|null}
6878
+ */
6879
+ attrString(name) {
6880
+ return TinyHtml.attrString(this, name);
6881
+ }
6882
+
6883
+ /**
6884
+ * Set a string attribute.
6885
+ * @template {TinyElement|TinyElement[]} T
6886
+ * @param {T} el
6887
+ * @param {string} name
6888
+ * @param {string} value
6889
+ * @returns {T}
6890
+ */
6891
+ static setAttrString(el, name, value) {
6892
+ if (typeof value !== 'string') throw new Error('Value is not a valid string.');
6893
+ return TinyHtml.setAttr(el, name, value);
6894
+ }
6895
+
6896
+ /**
6897
+ * Set a string attribute.
6898
+ * @param {string} name
6899
+ * @param {string} value
6900
+ * @returns {this}
6901
+ */
6902
+ setAttrString(name, value) {
6903
+ return TinyHtml.setAttrString(this, name, value);
6904
+ }
6905
+
6521
6906
  /**
6522
6907
  * Get an attribute on an element.
6523
6908
  * @param {TinyElement} el
@@ -6543,8 +6928,8 @@ class TinyHtml {
6543
6928
  * Set one or multiple attributes on an element.
6544
6929
  * @template {TinyElement|TinyElement[]} T
6545
6930
  * @param {T} el - Target element(s).
6546
- * @param {string|Record<string, string|null>} name - Attribute name or an object of attributes.
6547
- * @param {string|number|null} [value=null] - Attribute value (ignored if "name" is an object).
6931
+ * @param {string|Record<string, any>} name - Attribute name or an object of attributes.
6932
+ * @param {any} [value=null] - Attribute value (ignored if "name" is an object).
6548
6933
  * @returns {T}
6549
6934
  */
6550
6935
  static setAttr(el, name, value = null) {
@@ -6552,25 +6937,20 @@ class TinyHtml {
6552
6937
 
6553
6938
  // Multiple attributes at once
6554
6939
  if (typeof name === 'object' && name !== null) {
6555
- Object.entries(name).forEach(([attr, val]) => {
6556
- if (val !== null && typeof val !== 'string' && typeof val !== 'number')
6557
- throw new TypeError(`The value for "${attr}" must be a string/number or null.`);
6940
+ Object.entries(name).forEach(([attr, val]) =>
6558
6941
  elems.forEach((elem) => {
6559
6942
  if (val === null) elem.removeAttribute(TinyHtml.getAttrName(attr));
6560
- else elem.setAttribute(TinyHtml.getAttrName(attr), val);
6561
- });
6562
- });
6943
+ else elem.setAttribute(TinyHtml.getAttrName(attr), String(val));
6944
+ }),
6945
+ );
6563
6946
  return el;
6564
6947
  }
6565
6948
 
6566
6949
  // Single attribute
6567
6950
  if (typeof name !== 'string') throw new TypeError('The "name" must be a string.');
6568
- if (value !== null && typeof value !== 'string')
6569
- throw new TypeError('The "value" must be a string.');
6570
-
6571
6951
  elems.forEach((elem) => {
6572
6952
  if (value === null) elem.removeAttribute(TinyHtml.getAttrName(name));
6573
- else elem.setAttribute(TinyHtml.getAttrName(name), value);
6953
+ else elem.setAttribute(TinyHtml.getAttrName(name), String(value));
6574
6954
  });
6575
6955
 
6576
6956
  return el;
@@ -6578,8 +6958,8 @@ class TinyHtml {
6578
6958
 
6579
6959
  /**
6580
6960
  * Set one or multiple attributes on an element.
6581
- * @param {string|Record<string, string|null>} name - Attribute name or an object of attributes.
6582
- * @param {string|number|null} [value=null] - Attribute value (ignored if "name" is an object).
6961
+ * @param {string|Record<string, any>} name - Attribute name or an object of attributes.
6962
+ * @param {any} [value=null] - Attribute value (ignored if "name" is an object).
6583
6963
  * @returns {this}
6584
6964
  */
6585
6965
  setAttr(name, value) {