tiny-essentials 1.22.3 → 1.22.5

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 (34) hide show
  1. package/dist/v1/TinyAdvancedRaffle.min.js +1 -1
  2. package/dist/v1/TinyDragger.min.js +1 -1
  3. package/dist/v1/TinyEssentials.min.js +1 -1
  4. package/dist/v1/TinyEvents.min.js +1 -1
  5. package/dist/v1/TinyHtml.min.js +1 -1
  6. package/dist/v1/TinyIframeEvents.min.js +1 -1
  7. package/dist/v1/TinyLocalStorage.min.js +1 -1
  8. package/dist/v1/TinyNewWinEvents.min.js +1 -1
  9. package/dist/v1/TinySmartScroller.min.js +1 -1
  10. package/dist/v1/TinyUploadClicker.min.js +1 -1
  11. package/dist/v1/libs/TinyAdvancedRaffle.cjs +13 -13
  12. package/dist/v1/libs/TinyAdvancedRaffle.d.mts +19 -19
  13. package/dist/v1/libs/TinyAdvancedRaffle.mjs +13 -13
  14. package/dist/v1/libs/TinyEvents.cjs +98 -73
  15. package/dist/v1/libs/TinyEvents.d.mts +22 -22
  16. package/dist/v1/libs/TinyEvents.mjs +103 -77
  17. package/dist/v1/libs/TinyHtml.cjs +335 -17
  18. package/dist/v1/libs/TinyHtml.d.mts +209 -8
  19. package/dist/v1/libs/TinyHtml.mjs +320 -20
  20. package/dist/v1/libs/TinyIframeEvents.cjs +11 -11
  21. package/dist/v1/libs/TinyIframeEvents.d.mts +19 -19
  22. package/dist/v1/libs/TinyIframeEvents.mjs +11 -11
  23. package/dist/v1/libs/TinyLocalStorage.cjs +12 -12
  24. package/dist/v1/libs/TinyLocalStorage.d.mts +21 -21
  25. package/dist/v1/libs/TinyLocalStorage.mjs +12 -12
  26. package/dist/v1/libs/TinyNewWinEvents.cjs +11 -11
  27. package/dist/v1/libs/TinyNewWinEvents.d.mts +19 -19
  28. package/dist/v1/libs/TinyNewWinEvents.mjs +11 -11
  29. package/dist/v1/libs/TinySmartScroller.cjs +12 -12
  30. package/dist/v1/libs/TinySmartScroller.d.mts +53 -30
  31. package/dist/v1/libs/TinySmartScroller.mjs +12 -12
  32. package/docs/v1/libs/TinyEvents.md +93 -105
  33. package/docs/v1/libs/TinyHtml.md +39 -2
  34. package/package.json +1 -1
@@ -663,7 +663,7 @@ class TinyHtml {
663
663
  * ```
664
664
  *
665
665
  * @param {string} tagName - The HTML tag name (e.g., 'div', 'span', 'button').
666
- * @param {Record<string, string|null>} [attrs] - Optional key-value pairs representing HTML attributes.
666
+ * @param {Record<string, string|number|null>} [attrs] - Optional key-value pairs representing HTML attributes.
667
667
  * If the value is `null`, the attribute will still be set with an empty value.
668
668
  * @returns {TinyHtml<HTMLElement>} - A new instance of TinyHtml representing the created element.
669
669
  * @throws {TypeError} - If `tagName` is not a string, or `attrs` is not a plain object when defined.
@@ -859,13 +859,22 @@ class TinyHtml {
859
859
 
860
860
  // TITLE: Element getter
861
861
 
862
+ /**
863
+ * Returns the current targets held by this instance.
864
+ *
865
+ * @returns {ConstructorElValues[]} - The instance's targets element.
866
+ */
867
+ get elements() {
868
+ return [...this.#el];
869
+ }
870
+
862
871
  /**
863
872
  * Iterates over all elements, executing the provided callback on each.
864
873
  * @param {(element: TinyHtmlAny, index: number, items: TinyHtmlAny[]) => void} callback - Function invoked for each element.
865
874
  * @returns {this} The current instance for chaining.
866
875
  */
867
876
  forEach(callback) {
868
- const elems = this.getAll().map((el, index) => this.extract(index));
877
+ const elems = this.elements.map((el, index) => this.extract(index));
869
878
  for (const index in elems) callback(elems[index], Number(index), elems);
870
879
  return this;
871
880
  }
@@ -907,6 +916,7 @@ class TinyHtml {
907
916
  }
908
917
 
909
918
  /**
919
+ * @deprecated Use the getter {@link elements} instead.
910
920
  * Returns the current targets held by this instance.
911
921
  *
912
922
  * @returns {ConstructorElValues[]} - The instance's targets element.
@@ -6508,6 +6518,291 @@ class TinyHtml {
6508
6518
  return propName;
6509
6519
  }
6510
6520
 
6521
+ ////////////////////////////////////////////////////////////////////
6522
+
6523
+ /**
6524
+ * Returns the BigInt value of an attribute.
6525
+ * @param {TinyElement} el
6526
+ * @param {string} name
6527
+ * @returns {bigint|null}
6528
+ */
6529
+ static attrBigInt(el, name) {
6530
+ const elem = TinyHtml._preElem(el, 'attrBigInt');
6531
+ const val = elem.getAttribute(TinyHtml.getAttrName(name));
6532
+ if (val == null) return null;
6533
+ try {
6534
+ return BigInt(val);
6535
+ } catch {
6536
+ return null;
6537
+ }
6538
+ }
6539
+
6540
+ /**
6541
+ * Returns the BigInt value of an attribute.
6542
+ * @param {string} name
6543
+ * @returns {bigint|null}
6544
+ */
6545
+ attrBigInt(name) {
6546
+ return TinyHtml.attrBigInt(this, name);
6547
+ }
6548
+
6549
+ /**
6550
+ * Set a BigInt attribute.
6551
+ * @template {TinyElement|TinyElement[]} T
6552
+ * @param {T} el
6553
+ * @param {string} name
6554
+ * @param {bigint} value
6555
+ * @returns {T}
6556
+ */
6557
+ static setAttrBigInt(el, name, value) {
6558
+ if (typeof value !== 'bigint') throw new Error('Value is not a valid BigInt.');
6559
+ return TinyHtml.setAttr(el, name, value.toString());
6560
+ }
6561
+
6562
+ /**
6563
+ * Set a BigInt attribute.
6564
+ * @param {string} name
6565
+ * @param {bigint} value
6566
+ * @returns {this}
6567
+ */
6568
+ setAttrBigInt(name, value) {
6569
+ return TinyHtml.setAttrBigInt(this, name, value);
6570
+ }
6571
+
6572
+ /**
6573
+ * Returns the Date value of an attribute.
6574
+ * @param {TinyElement} el
6575
+ * @param {string} name
6576
+ * @returns {Date|null}
6577
+ */
6578
+ static attrDate(el, name) {
6579
+ const elem = TinyHtml._preElem(el, 'attrDate');
6580
+ const val = elem.getAttribute(TinyHtml.getAttrName(name));
6581
+ if (!val) return null;
6582
+ const d = new Date(val);
6583
+ return Number.isNaN(d.getTime()) ? null : d;
6584
+ }
6585
+
6586
+ /**
6587
+ * Returns the Date value of an attribute.
6588
+ * @param {string} name
6589
+ * @returns {Date|null}
6590
+ */
6591
+ attrDate(name) {
6592
+ return TinyHtml.attrDate(this, name);
6593
+ }
6594
+
6595
+ /**
6596
+ * Set a Date attribute.
6597
+ * @template {TinyElement|TinyElement[]} T
6598
+ * @param {T} el
6599
+ * @param {string} name
6600
+ * @param {Date} value
6601
+ * @returns {T}
6602
+ */
6603
+ static setAttrDate(el, name, value) {
6604
+ if (!(value instanceof Date) || Number.isNaN(value.getTime()))
6605
+ throw new Error('Value is not a valid Date.');
6606
+ return TinyHtml.setAttr(el, name, value.toISOString());
6607
+ }
6608
+
6609
+ /**
6610
+ * Set a Date attribute.
6611
+ * @param {string} name
6612
+ * @param {Date} value
6613
+ * @returns {this}
6614
+ */
6615
+ setAttrDate(name, value) {
6616
+ return TinyHtml.setAttrDate(this, name, value);
6617
+ }
6618
+
6619
+ /**
6620
+ * Returns the JSON value of an attribute.
6621
+ * @param {TinyElement} el
6622
+ * @param {string} name
6623
+ * @returns {any|null}
6624
+ */
6625
+ static attrJson(el, name) {
6626
+ const elem = TinyHtml._preElem(el, 'attrJson');
6627
+ const val = elem.getAttribute(TinyHtml.getAttrName(name));
6628
+ if (!val) return null;
6629
+ try {
6630
+ return JSON.parse(val);
6631
+ } catch {
6632
+ return null;
6633
+ }
6634
+ }
6635
+
6636
+ /**
6637
+ * Returns the JSON value of an attribute.
6638
+ * @param {string} name
6639
+ * @returns {any|null}
6640
+ */
6641
+ attrJson(name) {
6642
+ return TinyHtml.attrJson(this, name);
6643
+ }
6644
+
6645
+ /**
6646
+ * Set a JSON attribute.
6647
+ * @template {TinyElement|TinyElement[]} T
6648
+ * @param {T} el
6649
+ * @param {string} name
6650
+ * @param {any} value
6651
+ * @param {(this: any, key: string, value: any) => any} [replacer]
6652
+ * @param {number|string} [space]
6653
+ * @returns {T}
6654
+ */
6655
+ static setAttrJson(el, name, value, replacer, space) {
6656
+ const data = JSON.stringify(value, replacer, space);
6657
+ return TinyHtml.setAttr(el, name, data);
6658
+ }
6659
+
6660
+ /**
6661
+ * Set a JSON attribute.
6662
+ * @param {string} name
6663
+ * @param {any} value
6664
+ * @param {(this: any, key: string, value: any) => any} [replacer]
6665
+ * @param {number|string} [space]
6666
+ * @returns {this}
6667
+ */
6668
+ setAttrJson(name, value, replacer, space) {
6669
+ return TinyHtml.setAttrJson(this, name, value, replacer, space);
6670
+ }
6671
+
6672
+ /**
6673
+ * Returns the number value of an attribute.
6674
+ * @param {TinyElement} el
6675
+ * @param {string} name
6676
+ * @returns {number|null}
6677
+ */
6678
+ static attrNumber(el, name) {
6679
+ const elem = TinyHtml._preElem(el, 'attrNumber');
6680
+ const val = elem.getAttribute(TinyHtml.getAttrName(name));
6681
+ return val != null ? parseFloat(val) : null;
6682
+ }
6683
+
6684
+ /**
6685
+ * Returns the number value of an attribute.
6686
+ * @param {string} name
6687
+ * @returns {number|null}
6688
+ */
6689
+ attrNumber(name) {
6690
+ return TinyHtml.attrNumber(this, name);
6691
+ }
6692
+
6693
+ /**
6694
+ * Set a number attribute.
6695
+ * @template {TinyElement|TinyElement[]} T
6696
+ * @param {T} el
6697
+ * @param {string} name
6698
+ * @param {number} value
6699
+ * @returns {T}
6700
+ */
6701
+ static setAttrNumber(el, name, value) {
6702
+ if (typeof value !== 'number') throw new Error('Value is not a valid number.');
6703
+ return TinyHtml.setAttr(el, name, value.toString());
6704
+ }
6705
+
6706
+ /**
6707
+ * Set a number attribute.
6708
+ * @param {string} name
6709
+ * @param {number} value
6710
+ * @returns {this}
6711
+ */
6712
+ setAttrNumber(name, value) {
6713
+ return TinyHtml.setAttrNumber(this, name, value);
6714
+ }
6715
+
6716
+ /**
6717
+ * Returns the boolean value of an attribute.
6718
+ * @param {TinyElement} el
6719
+ * @param {string} name
6720
+ * @returns {boolean|null}
6721
+ */
6722
+ static attrBoolean(el, name) {
6723
+ const elem = TinyHtml._preElem(el, 'attrBoolean');
6724
+ const val = elem.getAttribute(TinyHtml.getAttrName(name));
6725
+ if (val === null) return null;
6726
+ if (val !== 'true' && val !== 'false') return null;
6727
+ return /^true$/i.test(val);
6728
+ }
6729
+
6730
+ /**
6731
+ * Returns the boolean value of an attribute.
6732
+ * @param {string} name
6733
+ * @returns {boolean|null}
6734
+ */
6735
+ attrBoolean(name) {
6736
+ return TinyHtml.attrBoolean(this, name);
6737
+ }
6738
+
6739
+ /**
6740
+ * Set a boolean attribute.
6741
+ * @template {TinyElement|TinyElement[]} T
6742
+ * @param {T} el
6743
+ * @param {string} name
6744
+ * @param {boolean} value
6745
+ * @returns {T}
6746
+ */
6747
+ static setAttrBoolean(el, name, value) {
6748
+ if (typeof value !== 'boolean') throw new Error('Value is not a valid boolean.');
6749
+ return TinyHtml.setAttr(el, name, value.toString());
6750
+ }
6751
+
6752
+ /**
6753
+ * Set a boolean attribute.
6754
+ * @param {string} name
6755
+ * @param {boolean} value
6756
+ * @returns {this}
6757
+ */
6758
+ setAttrBoolean(name, value) {
6759
+ return TinyHtml.setAttrBoolean(this, name, value);
6760
+ }
6761
+
6762
+ /**
6763
+ * Returns the string value of an attribute.
6764
+ * @param {TinyElement} el
6765
+ * @param {string} name
6766
+ * @returns {string|null}
6767
+ */
6768
+ static attrString(el, name) {
6769
+ const elem = TinyHtml._preElem(el, 'attrString');
6770
+ const value = elem.getAttribute(TinyHtml.getAttrName(name));
6771
+ return typeof value === 'string' ? value : null;
6772
+ }
6773
+
6774
+ /**
6775
+ * Returns the string value of an attribute.
6776
+ * @param {string} name
6777
+ * @returns {string|null}
6778
+ */
6779
+ attrString(name) {
6780
+ return TinyHtml.attrString(this, name);
6781
+ }
6782
+
6783
+ /**
6784
+ * Set a string attribute.
6785
+ * @template {TinyElement|TinyElement[]} T
6786
+ * @param {T} el
6787
+ * @param {string} name
6788
+ * @param {string} value
6789
+ * @returns {T}
6790
+ */
6791
+ static setAttrString(el, name, value) {
6792
+ if (typeof value !== 'string') throw new Error('Value is not a valid string.');
6793
+ return TinyHtml.setAttr(el, name, value);
6794
+ }
6795
+
6796
+ /**
6797
+ * Set a string attribute.
6798
+ * @param {string} name
6799
+ * @param {string} value
6800
+ * @returns {this}
6801
+ */
6802
+ setAttrString(name, value) {
6803
+ return TinyHtml.setAttrString(this, name, value);
6804
+ }
6805
+
6511
6806
  /**
6512
6807
  * Get an attribute on an element.
6513
6808
  * @param {TinyElement} el
@@ -6533,8 +6828,8 @@ class TinyHtml {
6533
6828
  * Set one or multiple attributes on an element.
6534
6829
  * @template {TinyElement|TinyElement[]} T
6535
6830
  * @param {T} el - Target element(s).
6536
- * @param {string|Record<string, string|null>} name - Attribute name or an object of attributes.
6537
- * @param {string|null} [value=null] - Attribute value (ignored if "name" is an object).
6831
+ * @param {string|Record<string, any>} name - Attribute name or an object of attributes.
6832
+ * @param {any} [value=null] - Attribute value (ignored if "name" is an object).
6538
6833
  * @returns {T}
6539
6834
  */
6540
6835
  static setAttr(el, name, value = null) {
@@ -6542,25 +6837,20 @@ class TinyHtml {
6542
6837
 
6543
6838
  // Multiple attributes at once
6544
6839
  if (typeof name === 'object' && name !== null) {
6545
- Object.entries(name).forEach(([attr, val]) => {
6546
- if (val !== null && typeof val !== 'string')
6547
- throw new TypeError(`The value for "${attr}" must be a string or null.`);
6840
+ Object.entries(name).forEach(([attr, val]) =>
6548
6841
  elems.forEach((elem) => {
6549
6842
  if (val === null) elem.removeAttribute(TinyHtml.getAttrName(attr));
6550
- else elem.setAttribute(TinyHtml.getAttrName(attr), val);
6551
- });
6552
- });
6843
+ else elem.setAttribute(TinyHtml.getAttrName(attr), String(val));
6844
+ }),
6845
+ );
6553
6846
  return el;
6554
6847
  }
6555
6848
 
6556
6849
  // Single attribute
6557
6850
  if (typeof name !== 'string') throw new TypeError('The "name" must be a string.');
6558
- if (value !== null && typeof value !== 'string')
6559
- throw new TypeError('The "value" must be a string.');
6560
-
6561
6851
  elems.forEach((elem) => {
6562
6852
  if (value === null) elem.removeAttribute(TinyHtml.getAttrName(name));
6563
- else elem.setAttribute(TinyHtml.getAttrName(name), value);
6853
+ else elem.setAttribute(TinyHtml.getAttrName(name), String(value));
6564
6854
  });
6565
6855
 
6566
6856
  return el;
@@ -6568,8 +6858,8 @@ class TinyHtml {
6568
6858
 
6569
6859
  /**
6570
6860
  * Set one or multiple attributes on an element.
6571
- * @param {string|Record<string, string|null>} name - Attribute name or an object of attributes.
6572
- * @param {string|null} [value=null] - Attribute value (ignored if "name" is an object).
6861
+ * @param {string|Record<string, any>} name - Attribute name or an object of attributes.
6862
+ * @param {any} [value=null] - Attribute value (ignored if "name" is an object).
6573
6863
  * @returns {this}
6574
6864
  */
6575
6865
  setAttr(name, value) {
@@ -6746,7 +7036,7 @@ class TinyHtml {
6746
7036
  static prop(el, name) {
6747
7037
  if (typeof name !== 'string')
6748
7038
  throw new TypeError('Invalid arguments passed to prop(). Expected string for "name".');
6749
- const elem = TinyHtml._preElem(el, 'attr');
7039
+ const elem = TinyHtml._preElem(el, 'prop');
6750
7040
  // @ts-ignore
6751
7041
  return elem[name];
6752
7042
  }
@@ -6761,6 +7051,34 @@ class TinyHtml {
6761
7051
  return TinyHtml.prop(this, name);
6762
7052
  }
6763
7053
 
7054
+ /**
7055
+ * Set a property on elements.
7056
+ * @template {TinyElement|TinyElement[]} T
7057
+ * @param {T} el - Target element(s).
7058
+ * @param {string} name - Property name.
7059
+ * @param {any} value - Value to set.
7060
+ * @returns {T}
7061
+ */
7062
+ static setProp(el, name, value) {
7063
+ if (typeof name !== 'string' || name.trim() === '')
7064
+ throw new Error('Property name must be a non-empty string.');
7065
+ TinyHtml._preElems(el, 'setProp').forEach((elem) => {
7066
+ // @ts-ignore
7067
+ elem[name] = value;
7068
+ });
7069
+ return el;
7070
+ }
7071
+
7072
+ /**
7073
+ * Set a property on this element.
7074
+ * @param {string} name - Property name.
7075
+ * @param {any} value - Value to set.
7076
+ * @returns {this} The same element.
7077
+ */
7078
+ setProp(name, value) {
7079
+ return TinyHtml.setProp(this, name, value);
7080
+ }
7081
+
6764
7082
  /////////////////////////////////////////////////////
6765
7083
 
6766
7084
  // TITLE: Remove Element