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
@@ -401,12 +401,12 @@ declare class TinyHtml<TinyHtmlT extends ConstructorElValues | ConstructorElValu
401
401
  * ```
402
402
  *
403
403
  * @param {string} tagName - The HTML tag name (e.g., 'div', 'span', 'button').
404
- * @param {Record<string, string|null>} [attrs] - Optional key-value pairs representing HTML attributes.
404
+ * @param {Record<string, string|number|null>} [attrs] - Optional key-value pairs representing HTML attributes.
405
405
  * If the value is `null`, the attribute will still be set with an empty value.
406
406
  * @returns {TinyHtml<HTMLElement>} - A new instance of TinyHtml representing the created element.
407
407
  * @throws {TypeError} - If `tagName` is not a string, or `attrs` is not a plain object when defined.
408
408
  */
409
- static createFrom(tagName: string, attrs?: Record<string, string | null>): TinyHtml<HTMLElement>;
409
+ static createFrom(tagName: string, attrs?: Record<string, string | number | null>): TinyHtml<HTMLElement>;
410
410
  /**
411
411
  * Creates a new DOM element with the specified tag name and options, then wraps it in a TinyHtml instance.
412
412
  *
@@ -2346,6 +2346,104 @@ declare class TinyHtml<TinyHtmlT extends ConstructorElValues | ConstructorElValu
2346
2346
  * @returns {string} - The corresponding attribute name.
2347
2347
  */
2348
2348
  static getAttrName(name: string): string;
2349
+ /**
2350
+ * Returns the BigInt value of an attribute.
2351
+ * @param {TinyElement} el
2352
+ * @param {string} name
2353
+ * @returns {bigint|null}
2354
+ */
2355
+ static attrBigInt(el: TinyElement, name: string): bigint | null;
2356
+ /**
2357
+ * Set a BigInt attribute.
2358
+ * @template {TinyElement|TinyElement[]} T
2359
+ * @param {T} el
2360
+ * @param {string} name
2361
+ * @param {bigint} value
2362
+ * @returns {T}
2363
+ */
2364
+ static setAttrBigInt<T extends TinyElement | TinyElement[]>(el: T, name: string, value: bigint): T;
2365
+ /**
2366
+ * Returns the Date value of an attribute.
2367
+ * @param {TinyElement} el
2368
+ * @param {string} name
2369
+ * @returns {Date|null}
2370
+ */
2371
+ static attrDate(el: TinyElement, name: string): Date | null;
2372
+ /**
2373
+ * Set a Date attribute.
2374
+ * @template {TinyElement|TinyElement[]} T
2375
+ * @param {T} el
2376
+ * @param {string} name
2377
+ * @param {Date} value
2378
+ * @returns {T}
2379
+ */
2380
+ static setAttrDate<T extends TinyElement | TinyElement[]>(el: T, name: string, value: Date): T;
2381
+ /**
2382
+ * Returns the JSON value of an attribute.
2383
+ * @param {TinyElement} el
2384
+ * @param {string} name
2385
+ * @returns {any|null}
2386
+ */
2387
+ static attrJson(el: TinyElement, name: string): any | null;
2388
+ /**
2389
+ * Set a JSON attribute.
2390
+ * @template {TinyElement|TinyElement[]} T
2391
+ * @param {T} el
2392
+ * @param {string} name
2393
+ * @param {any} value
2394
+ * @param {(this: any, key: string, value: any) => any} [replacer]
2395
+ * @param {number|string} [space]
2396
+ * @returns {T}
2397
+ */
2398
+ static setAttrJson<T extends TinyElement | TinyElement[]>(el: T, name: string, value: any, replacer?: (this: any, key: string, value: any) => any, space?: number | string): T;
2399
+ /**
2400
+ * Returns the number value of an attribute.
2401
+ * @param {TinyElement} el
2402
+ * @param {string} name
2403
+ * @returns {number|null}
2404
+ */
2405
+ static attrNumber(el: TinyElement, name: string): number | null;
2406
+ /**
2407
+ * Set a number attribute.
2408
+ * @template {TinyElement|TinyElement[]} T
2409
+ * @param {T} el
2410
+ * @param {string} name
2411
+ * @param {number} value
2412
+ * @returns {T}
2413
+ */
2414
+ static setAttrNumber<T extends TinyElement | TinyElement[]>(el: T, name: string, value: number): T;
2415
+ /**
2416
+ * Returns the boolean value of an attribute.
2417
+ * @param {TinyElement} el
2418
+ * @param {string} name
2419
+ * @returns {boolean|null}
2420
+ */
2421
+ static attrBoolean(el: TinyElement, name: string): boolean | null;
2422
+ /**
2423
+ * Set a boolean attribute.
2424
+ * @template {TinyElement|TinyElement[]} T
2425
+ * @param {T} el
2426
+ * @param {string} name
2427
+ * @param {boolean} value
2428
+ * @returns {T}
2429
+ */
2430
+ static setAttrBoolean<T extends TinyElement | TinyElement[]>(el: T, name: string, value: boolean): T;
2431
+ /**
2432
+ * Returns the string value of an attribute.
2433
+ * @param {TinyElement} el
2434
+ * @param {string} name
2435
+ * @returns {string|null}
2436
+ */
2437
+ static attrString(el: TinyElement, name: string): string | null;
2438
+ /**
2439
+ * Set a string attribute.
2440
+ * @template {TinyElement|TinyElement[]} T
2441
+ * @param {T} el
2442
+ * @param {string} name
2443
+ * @param {string} value
2444
+ * @returns {T}
2445
+ */
2446
+ static setAttrString<T extends TinyElement | TinyElement[]>(el: T, name: string, value: string): T;
2349
2447
  /**
2350
2448
  * Get an attribute on an element.
2351
2449
  * @param {TinyElement} el
@@ -2357,11 +2455,11 @@ declare class TinyHtml<TinyHtmlT extends ConstructorElValues | ConstructorElValu
2357
2455
  * Set one or multiple attributes on an element.
2358
2456
  * @template {TinyElement|TinyElement[]} T
2359
2457
  * @param {T} el - Target element(s).
2360
- * @param {string|Record<string, string|null>} name - Attribute name or an object of attributes.
2361
- * @param {string|null} [value=null] - Attribute value (ignored if "name" is an object).
2458
+ * @param {string|Record<string, any>} name - Attribute name or an object of attributes.
2459
+ * @param {any} [value=null] - Attribute value (ignored if "name" is an object).
2362
2460
  * @returns {T}
2363
2461
  */
2364
- static setAttr<T extends TinyElement | TinyElement[]>(el: T, name: string | Record<string, string | null>, value?: string | null): T;
2462
+ static setAttr<T extends TinyElement | TinyElement[]>(el: T, name: string | Record<string, any>, value?: any): T;
2365
2463
  /**
2366
2464
  * Remove attribute(s) from an element.
2367
2465
  * @template {TinyElement|TinyElement[]} T
@@ -2417,6 +2515,15 @@ declare class TinyHtml<TinyHtmlT extends ConstructorElValues | ConstructorElValu
2417
2515
  * @returns {any} - Property value if getting, otherwise `undefined`.
2418
2516
  */
2419
2517
  static prop(el: TinyHtmlElement, name: string): any;
2518
+ /**
2519
+ * Set a property on elements.
2520
+ * @template {TinyElement|TinyElement[]} T
2521
+ * @param {T} el - Target element(s).
2522
+ * @param {string} name - Property name.
2523
+ * @param {any} value - Value to set.
2524
+ * @returns {T}
2525
+ */
2526
+ static setProp<T extends TinyElement | TinyElement[]>(el: T, name: string, value: any): T;
2420
2527
  /**
2421
2528
  * Removes an element from the DOM.
2422
2529
  * @template {TinyElement|TinyElement[]} T
@@ -2591,6 +2698,12 @@ declare class TinyHtml<TinyHtmlT extends ConstructorElValues | ConstructorElValu
2591
2698
  * @returns {TinyHtml<HTMLCollectionOf<Element>>} An array of TinyHtml instances wrapping the found elements.
2592
2699
  */
2593
2700
  getElementsByTagNameNS(localName: string, namespaceURI?: string | null): TinyHtml<HTMLCollectionOf<Element>>;
2701
+ /**
2702
+ * Returns the current targets held by this instance.
2703
+ *
2704
+ * @returns {ConstructorElValues[]} - The instance's targets element.
2705
+ */
2706
+ get elements(): ConstructorElValues[];
2594
2707
  /**
2595
2708
  * Iterates over all elements, executing the provided callback on each.
2596
2709
  * @param {(element: TinyHtmlAny, index: number, items: TinyHtmlAny[]) => void} callback - Function invoked for each element.
@@ -2619,6 +2732,7 @@ declare class TinyHtml<TinyHtmlT extends ConstructorElValues | ConstructorElValu
2619
2732
  */
2620
2733
  exists(index: number): boolean;
2621
2734
  /**
2735
+ * @deprecated Use the getter {@link elements} instead.
2622
2736
  * Returns the current targets held by this instance.
2623
2737
  *
2624
2738
  * @returns {ConstructorElValues[]} - The instance's targets element.
@@ -3512,6 +3626,86 @@ declare class TinyHtml<TinyHtmlT extends ConstructorElValues | ConstructorElValu
3512
3626
  * @returns {this}
3513
3627
  */
3514
3628
  trigger(events: string | string[], payload?: Event | CustomEvent | CustomEventInit): this;
3629
+ /**
3630
+ * Returns the BigInt value of an attribute.
3631
+ * @param {string} name
3632
+ * @returns {bigint|null}
3633
+ */
3634
+ attrBigInt(name: string): bigint | null;
3635
+ /**
3636
+ * Set a BigInt attribute.
3637
+ * @param {string} name
3638
+ * @param {bigint} value
3639
+ * @returns {this}
3640
+ */
3641
+ setAttrBigInt(name: string, value: bigint): this;
3642
+ /**
3643
+ * Returns the Date value of an attribute.
3644
+ * @param {string} name
3645
+ * @returns {Date|null}
3646
+ */
3647
+ attrDate(name: string): Date | null;
3648
+ /**
3649
+ * Set a Date attribute.
3650
+ * @param {string} name
3651
+ * @param {Date} value
3652
+ * @returns {this}
3653
+ */
3654
+ setAttrDate(name: string, value: Date): this;
3655
+ /**
3656
+ * Returns the JSON value of an attribute.
3657
+ * @param {string} name
3658
+ * @returns {any|null}
3659
+ */
3660
+ attrJson(name: string): any | null;
3661
+ /**
3662
+ * Set a JSON attribute.
3663
+ * @param {string} name
3664
+ * @param {any} value
3665
+ * @param {(this: any, key: string, value: any) => any} [replacer]
3666
+ * @param {number|string} [space]
3667
+ * @returns {this}
3668
+ */
3669
+ setAttrJson(name: string, value: any, replacer?: (this: any, key: string, value: any) => any, space?: number | string): this;
3670
+ /**
3671
+ * Returns the number value of an attribute.
3672
+ * @param {string} name
3673
+ * @returns {number|null}
3674
+ */
3675
+ attrNumber(name: string): number | null;
3676
+ /**
3677
+ * Set a number attribute.
3678
+ * @param {string} name
3679
+ * @param {number} value
3680
+ * @returns {this}
3681
+ */
3682
+ setAttrNumber(name: string, value: number): this;
3683
+ /**
3684
+ * Returns the boolean value of an attribute.
3685
+ * @param {string} name
3686
+ * @returns {boolean|null}
3687
+ */
3688
+ attrBoolean(name: string): boolean | null;
3689
+ /**
3690
+ * Set a boolean attribute.
3691
+ * @param {string} name
3692
+ * @param {boolean} value
3693
+ * @returns {this}
3694
+ */
3695
+ setAttrBoolean(name: string, value: boolean): this;
3696
+ /**
3697
+ * Returns the string value of an attribute.
3698
+ * @param {string} name
3699
+ * @returns {string|null}
3700
+ */
3701
+ attrString(name: string): string | null;
3702
+ /**
3703
+ * Set a string attribute.
3704
+ * @param {string} name
3705
+ * @param {string} value
3706
+ * @returns {this}
3707
+ */
3708
+ setAttrString(name: string, value: string): this;
3515
3709
  /**
3516
3710
  * Get an attribute on an element.
3517
3711
  * @param {string} name
@@ -3520,11 +3714,11 @@ declare class TinyHtml<TinyHtmlT extends ConstructorElValues | ConstructorElValu
3520
3714
  attr(name: string): string | null;
3521
3715
  /**
3522
3716
  * Set one or multiple attributes on an element.
3523
- * @param {string|Record<string, string|null>} name - Attribute name or an object of attributes.
3524
- * @param {string|null} [value=null] - Attribute value (ignored if "name" is an object).
3717
+ * @param {string|Record<string, any>} name - Attribute name or an object of attributes.
3718
+ * @param {any} [value=null] - Attribute value (ignored if "name" is an object).
3525
3719
  * @returns {this}
3526
3720
  */
3527
- setAttr(name: string | Record<string, string | null>, value?: string | null): this;
3721
+ setAttr(name: string | Record<string, any>, value?: any): this;
3528
3722
  /**
3529
3723
  * Remove attribute(s) from an element.
3530
3724
  * @param {string} name Space-separated list of attributes.
@@ -3569,6 +3763,13 @@ declare class TinyHtml<TinyHtmlT extends ConstructorElValues | ConstructorElValu
3569
3763
  * @returns {any} - Property value if getting, otherwise `undefined`.
3570
3764
  */
3571
3765
  prop(name: string): any;
3766
+ /**
3767
+ * Set a property on this element.
3768
+ * @param {string} name - Property name.
3769
+ * @param {any} value - Value to set.
3770
+ * @returns {this} The same element.
3771
+ */
3772
+ setProp(name: string, value: any): this;
3572
3773
  /**
3573
3774
  * Removes the element from the DOM.
3574
3775
  * @returns {this}
@@ -558,7 +558,7 @@ class TinyHtml {
558
558
  * ```
559
559
  *
560
560
  * @param {string} tagName - The HTML tag name (e.g., 'div', 'span', 'button').
561
- * @param {Record<string, string|null>} [attrs] - Optional key-value pairs representing HTML attributes.
561
+ * @param {Record<string, string|number|null>} [attrs] - Optional key-value pairs representing HTML attributes.
562
562
  * If the value is `null`, the attribute will still be set with an empty value.
563
563
  * @returns {TinyHtml<HTMLElement>} - A new instance of TinyHtml representing the created element.
564
564
  * @throws {TypeError} - If `tagName` is not a string, or `attrs` is not a plain object when defined.
@@ -734,13 +734,21 @@ class TinyHtml {
734
734
  }
735
735
  //////////////////////////////////////////////////////////////////
736
736
  // TITLE: Element getter
737
+ /**
738
+ * Returns the current targets held by this instance.
739
+ *
740
+ * @returns {ConstructorElValues[]} - The instance's targets element.
741
+ */
742
+ get elements() {
743
+ return [...this.#el];
744
+ }
737
745
  /**
738
746
  * Iterates over all elements, executing the provided callback on each.
739
747
  * @param {(element: TinyHtmlAny, index: number, items: TinyHtmlAny[]) => void} callback - Function invoked for each element.
740
748
  * @returns {this} The current instance for chaining.
741
749
  */
742
750
  forEach(callback) {
743
- const elems = this.getAll().map((el, index) => this.extract(index));
751
+ const elems = this.elements.map((el, index) => this.extract(index));
744
752
  for (const index in elems)
745
753
  callback(elems[index], Number(index), elems);
746
754
  return this;
@@ -785,6 +793,7 @@ class TinyHtml {
785
793
  return true;
786
794
  }
787
795
  /**
796
+ * @deprecated Use the getter {@link elements} instead.
788
797
  * Returns the current targets held by this instance.
789
798
  *
790
799
  * @returns {ConstructorElValues[]} - The instance's targets element.
@@ -5834,6 +5843,277 @@ class TinyHtml {
5834
5843
  const propName = typeof TinyHtml.attrFix[name] === 'string' ? TinyHtml.attrFix[name] : name;
5835
5844
  return propName;
5836
5845
  }
5846
+ ////////////////////////////////////////////////////////////////////
5847
+ /**
5848
+ * Returns the BigInt value of an attribute.
5849
+ * @param {TinyElement} el
5850
+ * @param {string} name
5851
+ * @returns {bigint|null}
5852
+ */
5853
+ static attrBigInt(el, name) {
5854
+ const elem = TinyHtml._preElem(el, 'attrBigInt');
5855
+ const val = elem.getAttribute(TinyHtml.getAttrName(name));
5856
+ if (val == null)
5857
+ return null;
5858
+ try {
5859
+ return BigInt(val);
5860
+ }
5861
+ catch {
5862
+ return null;
5863
+ }
5864
+ }
5865
+ /**
5866
+ * Returns the BigInt value of an attribute.
5867
+ * @param {string} name
5868
+ * @returns {bigint|null}
5869
+ */
5870
+ attrBigInt(name) {
5871
+ return TinyHtml.attrBigInt(this, name);
5872
+ }
5873
+ /**
5874
+ * Set a BigInt attribute.
5875
+ * @template {TinyElement|TinyElement[]} T
5876
+ * @param {T} el
5877
+ * @param {string} name
5878
+ * @param {bigint} value
5879
+ * @returns {T}
5880
+ */
5881
+ static setAttrBigInt(el, name, value) {
5882
+ if (typeof value !== 'bigint')
5883
+ throw new Error('Value is not a valid BigInt.');
5884
+ return TinyHtml.setAttr(el, name, value.toString());
5885
+ }
5886
+ /**
5887
+ * Set a BigInt attribute.
5888
+ * @param {string} name
5889
+ * @param {bigint} value
5890
+ * @returns {this}
5891
+ */
5892
+ setAttrBigInt(name, value) {
5893
+ return TinyHtml.setAttrBigInt(this, name, value);
5894
+ }
5895
+ /**
5896
+ * Returns the Date value of an attribute.
5897
+ * @param {TinyElement} el
5898
+ * @param {string} name
5899
+ * @returns {Date|null}
5900
+ */
5901
+ static attrDate(el, name) {
5902
+ const elem = TinyHtml._preElem(el, 'attrDate');
5903
+ const val = elem.getAttribute(TinyHtml.getAttrName(name));
5904
+ if (!val)
5905
+ return null;
5906
+ const d = new Date(val);
5907
+ return Number.isNaN(d.getTime()) ? null : d;
5908
+ }
5909
+ /**
5910
+ * Returns the Date value of an attribute.
5911
+ * @param {string} name
5912
+ * @returns {Date|null}
5913
+ */
5914
+ attrDate(name) {
5915
+ return TinyHtml.attrDate(this, name);
5916
+ }
5917
+ /**
5918
+ * Set a Date attribute.
5919
+ * @template {TinyElement|TinyElement[]} T
5920
+ * @param {T} el
5921
+ * @param {string} name
5922
+ * @param {Date} value
5923
+ * @returns {T}
5924
+ */
5925
+ static setAttrDate(el, name, value) {
5926
+ if (!(value instanceof Date) || Number.isNaN(value.getTime()))
5927
+ throw new Error('Value is not a valid Date.');
5928
+ return TinyHtml.setAttr(el, name, value.toISOString());
5929
+ }
5930
+ /**
5931
+ * Set a Date attribute.
5932
+ * @param {string} name
5933
+ * @param {Date} value
5934
+ * @returns {this}
5935
+ */
5936
+ setAttrDate(name, value) {
5937
+ return TinyHtml.setAttrDate(this, name, value);
5938
+ }
5939
+ /**
5940
+ * Returns the JSON value of an attribute.
5941
+ * @param {TinyElement} el
5942
+ * @param {string} name
5943
+ * @returns {any|null}
5944
+ */
5945
+ static attrJson(el, name) {
5946
+ const elem = TinyHtml._preElem(el, 'attrJson');
5947
+ const val = elem.getAttribute(TinyHtml.getAttrName(name));
5948
+ if (!val)
5949
+ return null;
5950
+ try {
5951
+ return JSON.parse(val);
5952
+ }
5953
+ catch {
5954
+ return null;
5955
+ }
5956
+ }
5957
+ /**
5958
+ * Returns the JSON value of an attribute.
5959
+ * @param {string} name
5960
+ * @returns {any|null}
5961
+ */
5962
+ attrJson(name) {
5963
+ return TinyHtml.attrJson(this, name);
5964
+ }
5965
+ /**
5966
+ * Set a JSON attribute.
5967
+ * @template {TinyElement|TinyElement[]} T
5968
+ * @param {T} el
5969
+ * @param {string} name
5970
+ * @param {any} value
5971
+ * @param {(this: any, key: string, value: any) => any} [replacer]
5972
+ * @param {number|string} [space]
5973
+ * @returns {T}
5974
+ */
5975
+ static setAttrJson(el, name, value, replacer, space) {
5976
+ const data = JSON.stringify(value, replacer, space);
5977
+ return TinyHtml.setAttr(el, name, data);
5978
+ }
5979
+ /**
5980
+ * Set a JSON attribute.
5981
+ * @param {string} name
5982
+ * @param {any} value
5983
+ * @param {(this: any, key: string, value: any) => any} [replacer]
5984
+ * @param {number|string} [space]
5985
+ * @returns {this}
5986
+ */
5987
+ setAttrJson(name, value, replacer, space) {
5988
+ return TinyHtml.setAttrJson(this, name, value, replacer, space);
5989
+ }
5990
+ /**
5991
+ * Returns the number value of an attribute.
5992
+ * @param {TinyElement} el
5993
+ * @param {string} name
5994
+ * @returns {number|null}
5995
+ */
5996
+ static attrNumber(el, name) {
5997
+ const elem = TinyHtml._preElem(el, 'attrNumber');
5998
+ const val = elem.getAttribute(TinyHtml.getAttrName(name));
5999
+ return val != null ? parseFloat(val) : null;
6000
+ }
6001
+ /**
6002
+ * Returns the number value of an attribute.
6003
+ * @param {string} name
6004
+ * @returns {number|null}
6005
+ */
6006
+ attrNumber(name) {
6007
+ return TinyHtml.attrNumber(this, name);
6008
+ }
6009
+ /**
6010
+ * Set a number attribute.
6011
+ * @template {TinyElement|TinyElement[]} T
6012
+ * @param {T} el
6013
+ * @param {string} name
6014
+ * @param {number} value
6015
+ * @returns {T}
6016
+ */
6017
+ static setAttrNumber(el, name, value) {
6018
+ if (typeof value !== 'number')
6019
+ throw new Error('Value is not a valid number.');
6020
+ return TinyHtml.setAttr(el, name, value.toString());
6021
+ }
6022
+ /**
6023
+ * Set a number attribute.
6024
+ * @param {string} name
6025
+ * @param {number} value
6026
+ * @returns {this}
6027
+ */
6028
+ setAttrNumber(name, value) {
6029
+ return TinyHtml.setAttrNumber(this, name, value);
6030
+ }
6031
+ /**
6032
+ * Returns the boolean value of an attribute.
6033
+ * @param {TinyElement} el
6034
+ * @param {string} name
6035
+ * @returns {boolean|null}
6036
+ */
6037
+ static attrBoolean(el, name) {
6038
+ const elem = TinyHtml._preElem(el, 'attrBoolean');
6039
+ const val = elem.getAttribute(TinyHtml.getAttrName(name));
6040
+ if (val === null)
6041
+ return null;
6042
+ if (val !== 'true' && val !== 'false')
6043
+ return null;
6044
+ return /^true$/i.test(val);
6045
+ }
6046
+ /**
6047
+ * Returns the boolean value of an attribute.
6048
+ * @param {string} name
6049
+ * @returns {boolean|null}
6050
+ */
6051
+ attrBoolean(name) {
6052
+ return TinyHtml.attrBoolean(this, name);
6053
+ }
6054
+ /**
6055
+ * Set a boolean attribute.
6056
+ * @template {TinyElement|TinyElement[]} T
6057
+ * @param {T} el
6058
+ * @param {string} name
6059
+ * @param {boolean} value
6060
+ * @returns {T}
6061
+ */
6062
+ static setAttrBoolean(el, name, value) {
6063
+ if (typeof value !== 'boolean')
6064
+ throw new Error('Value is not a valid boolean.');
6065
+ return TinyHtml.setAttr(el, name, value.toString());
6066
+ }
6067
+ /**
6068
+ * Set a boolean attribute.
6069
+ * @param {string} name
6070
+ * @param {boolean} value
6071
+ * @returns {this}
6072
+ */
6073
+ setAttrBoolean(name, value) {
6074
+ return TinyHtml.setAttrBoolean(this, name, value);
6075
+ }
6076
+ /**
6077
+ * Returns the string value of an attribute.
6078
+ * @param {TinyElement} el
6079
+ * @param {string} name
6080
+ * @returns {string|null}
6081
+ */
6082
+ static attrString(el, name) {
6083
+ const elem = TinyHtml._preElem(el, 'attrString');
6084
+ const value = elem.getAttribute(TinyHtml.getAttrName(name));
6085
+ return typeof value === 'string' ? value : null;
6086
+ }
6087
+ /**
6088
+ * Returns the string value of an attribute.
6089
+ * @param {string} name
6090
+ * @returns {string|null}
6091
+ */
6092
+ attrString(name) {
6093
+ return TinyHtml.attrString(this, name);
6094
+ }
6095
+ /**
6096
+ * Set a string attribute.
6097
+ * @template {TinyElement|TinyElement[]} T
6098
+ * @param {T} el
6099
+ * @param {string} name
6100
+ * @param {string} value
6101
+ * @returns {T}
6102
+ */
6103
+ static setAttrString(el, name, value) {
6104
+ if (typeof value !== 'string')
6105
+ throw new Error('Value is not a valid string.');
6106
+ return TinyHtml.setAttr(el, name, value);
6107
+ }
6108
+ /**
6109
+ * Set a string attribute.
6110
+ * @param {string} name
6111
+ * @param {string} value
6112
+ * @returns {this}
6113
+ */
6114
+ setAttrString(name, value) {
6115
+ return TinyHtml.setAttrString(this, name, value);
6116
+ }
5837
6117
  /**
5838
6118
  * Get an attribute on an element.
5839
6119
  * @param {TinyElement} el
@@ -5858,43 +6138,37 @@ class TinyHtml {
5858
6138
  * Set one or multiple attributes on an element.
5859
6139
  * @template {TinyElement|TinyElement[]} T
5860
6140
  * @param {T} el - Target element(s).
5861
- * @param {string|Record<string, string|null>} name - Attribute name or an object of attributes.
5862
- * @param {string|null} [value=null] - Attribute value (ignored if "name" is an object).
6141
+ * @param {string|Record<string, any>} name - Attribute name or an object of attributes.
6142
+ * @param {any} [value=null] - Attribute value (ignored if "name" is an object).
5863
6143
  * @returns {T}
5864
6144
  */
5865
6145
  static setAttr(el, name, value = null) {
5866
6146
  const elems = TinyHtml._preElems(el, 'setAttr');
5867
6147
  // Multiple attributes at once
5868
6148
  if (typeof name === 'object' && name !== null) {
5869
- Object.entries(name).forEach(([attr, val]) => {
5870
- if (val !== null && typeof val !== 'string')
5871
- throw new TypeError(`The value for "${attr}" must be a string or null.`);
5872
- elems.forEach((elem) => {
5873
- if (val === null)
5874
- elem.removeAttribute(TinyHtml.getAttrName(attr));
5875
- else
5876
- elem.setAttribute(TinyHtml.getAttrName(attr), val);
5877
- });
5878
- });
6149
+ Object.entries(name).forEach(([attr, val]) => elems.forEach((elem) => {
6150
+ if (val === null)
6151
+ elem.removeAttribute(TinyHtml.getAttrName(attr));
6152
+ else
6153
+ elem.setAttribute(TinyHtml.getAttrName(attr), String(val));
6154
+ }));
5879
6155
  return el;
5880
6156
  }
5881
6157
  // Single attribute
5882
6158
  if (typeof name !== 'string')
5883
6159
  throw new TypeError('The "name" must be a string.');
5884
- if (value !== null && typeof value !== 'string')
5885
- throw new TypeError('The "value" must be a string.');
5886
6160
  elems.forEach((elem) => {
5887
6161
  if (value === null)
5888
6162
  elem.removeAttribute(TinyHtml.getAttrName(name));
5889
6163
  else
5890
- elem.setAttribute(TinyHtml.getAttrName(name), value);
6164
+ elem.setAttribute(TinyHtml.getAttrName(name), String(value));
5891
6165
  });
5892
6166
  return el;
5893
6167
  }
5894
6168
  /**
5895
6169
  * Set one or multiple attributes on an element.
5896
- * @param {string|Record<string, string|null>} name - Attribute name or an object of attributes.
5897
- * @param {string|null} [value=null] - Attribute value (ignored if "name" is an object).
6170
+ * @param {string|Record<string, any>} name - Attribute name or an object of attributes.
6171
+ * @param {any} [value=null] - Attribute value (ignored if "name" is an object).
5898
6172
  * @returns {this}
5899
6173
  */
5900
6174
  setAttr(name, value) {
@@ -6061,7 +6335,7 @@ class TinyHtml {
6061
6335
  static prop(el, name) {
6062
6336
  if (typeof name !== 'string')
6063
6337
  throw new TypeError('Invalid arguments passed to prop(). Expected string for "name".');
6064
- const elem = TinyHtml._preElem(el, 'attr');
6338
+ const elem = TinyHtml._preElem(el, 'prop');
6065
6339
  // @ts-ignore
6066
6340
  return elem[name];
6067
6341
  }
@@ -6074,6 +6348,32 @@ class TinyHtml {
6074
6348
  prop(name) {
6075
6349
  return TinyHtml.prop(this, name);
6076
6350
  }
6351
+ /**
6352
+ * Set a property on elements.
6353
+ * @template {TinyElement|TinyElement[]} T
6354
+ * @param {T} el - Target element(s).
6355
+ * @param {string} name - Property name.
6356
+ * @param {any} value - Value to set.
6357
+ * @returns {T}
6358
+ */
6359
+ static setProp(el, name, value) {
6360
+ if (typeof name !== 'string' || name.trim() === '')
6361
+ throw new Error('Property name must be a non-empty string.');
6362
+ TinyHtml._preElems(el, 'setProp').forEach((elem) => {
6363
+ // @ts-ignore
6364
+ elem[name] = value;
6365
+ });
6366
+ return el;
6367
+ }
6368
+ /**
6369
+ * Set a property on this element.
6370
+ * @param {string} name - Property name.
6371
+ * @param {any} value - Value to set.
6372
+ * @returns {this} The same element.
6373
+ */
6374
+ setProp(name, value) {
6375
+ return TinyHtml.setProp(this, name, value);
6376
+ }
6077
6377
  /////////////////////////////////////////////////////
6078
6378
  // TITLE: Remove Element
6079
6379
  /**