tiny-essentials 1.16.1 → 1.17.0
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.
- package/dist/legacy/crypto/decrypt.cjs +1 -0
- package/dist/legacy/crypto/decrypt.d.mts +1 -0
- package/dist/legacy/crypto/decrypt.mjs +1 -0
- package/dist/legacy/crypto/encrypt.cjs +1 -0
- package/dist/legacy/crypto/encrypt.d.mts +1 -0
- package/dist/legacy/crypto/encrypt.mjs +1 -0
- package/dist/legacy/get/decimalColor.cjs +1 -0
- package/dist/legacy/get/decimalColor.d.mts +1 -0
- package/dist/legacy/get/decimalColor.mjs +1 -0
- package/dist/legacy/get/pagination.cjs +1 -0
- package/dist/legacy/get/pagination.d.mts +1 -0
- package/dist/legacy/get/pagination.mjs +1 -0
- package/dist/legacy/get/queryUrlByName.cjs +1 -0
- package/dist/legacy/get/queryUrlByName.d.mts +1 -0
- package/dist/legacy/get/queryUrlByName.mjs +1 -0
- package/dist/legacy/get/queryUrlJSON.cjs +1 -0
- package/dist/legacy/get/queryUrlJSON.d.mts +1 -0
- package/dist/legacy/get/queryUrlJSON.mjs +1 -0
- package/dist/legacy/get/super_string_filter.cjs +1 -0
- package/dist/legacy/get/super_string_filter.d.mts +1 -0
- package/dist/legacy/get/super_string_filter.mjs +1 -0
- package/dist/legacy/get/versionCheck.cjs +1 -0
- package/dist/legacy/get/versionCheck.d.mts +1 -0
- package/dist/legacy/get/versionCheck.mjs +1 -0
- package/dist/legacy/http/HTTP-1.0.cjs +2 -0
- package/dist/legacy/http/HTTP-1.0.mjs +2 -0
- package/dist/legacy/http/auth.cjs +1 -0
- package/dist/legacy/http/auth.d.mts +1 -0
- package/dist/legacy/http/auth.mjs +1 -0
- package/dist/legacy/http/check_domain.cjs +11 -0
- package/dist/legacy/http/check_domain.d.mts +3 -0
- package/dist/legacy/http/check_domain.mjs +11 -0
- package/dist/legacy/http/csrfTokenAnalyze.cjs +1 -0
- package/dist/legacy/http/csrfTokenAnalyze.d.mts +1 -0
- package/dist/legacy/http/csrfTokenAnalyze.mjs +1 -0
- package/dist/legacy/http/domainValidator.cjs +1 -0
- package/dist/legacy/http/domainValidator.d.mts +1 -0
- package/dist/legacy/http/domainValidator.mjs +1 -0
- package/dist/legacy/http/errorsCallback.cjs +1 -0
- package/dist/legacy/http/errorsCallback.d.mts +1 -0
- package/dist/legacy/http/errorsCallback.mjs +1 -0
- package/dist/legacy/http/fetch/json.cjs +1 -0
- package/dist/legacy/http/fetch/json.d.mts +1 -0
- package/dist/legacy/http/fetch/json.mjs +1 -0
- package/dist/legacy/http/fetch/text.cjs +1 -0
- package/dist/legacy/http/fetch/text.d.mts +1 -0
- package/dist/legacy/http/fetch/text.mjs +1 -0
- package/dist/legacy/http/fileCache.cjs +1 -0
- package/dist/legacy/http/fileCache.d.mts +1 -0
- package/dist/legacy/http/fileCache.mjs +1 -0
- package/dist/legacy/http/getDomainURL.cjs +1 -0
- package/dist/legacy/http/getDomainURL.d.mts +1 -0
- package/dist/legacy/http/getDomainURL.mjs +1 -0
- package/dist/legacy/http/userIP.cjs +1 -0
- package/dist/legacy/http/userIP.d.mts +1 -0
- package/dist/legacy/http/userIP.mjs +1 -0
- package/dist/legacy/libs/capitalize.cjs +1 -0
- package/dist/legacy/libs/capitalize.d.mts +1 -0
- package/dist/legacy/libs/capitalize.mjs +1 -0
- package/dist/legacy/libs/convertBytes.cjs +2 -0
- package/dist/legacy/libs/convertBytes.mjs +2 -0
- package/dist/legacy/libs/custom_module_loader.cjs +2 -0
- package/dist/legacy/libs/custom_module_loader.mjs +2 -0
- package/dist/legacy/libs/dice.cjs +2 -0
- package/dist/legacy/libs/dice.mjs +2 -0
- package/dist/legacy/libs/markdown.cjs +1 -0
- package/dist/legacy/libs/markdown.mjs +1 -0
- package/dist/legacy/libs/percentage.cjs +1 -0
- package/dist/legacy/libs/percentage.mjs +1 -0
- package/dist/legacy/libs/regex/getLetter.cjs +2 -0
- package/dist/legacy/libs/regex/getLetter.d.mts +2 -0
- package/dist/legacy/libs/regex/getLetter.mjs +2 -0
- package/dist/legacy/libs/rule3.cjs +1 -0
- package/dist/legacy/libs/rule3.mjs +1 -0
- package/dist/legacy/momentjs/getAge.cjs +1 -0
- package/dist/legacy/momentjs/getAge.d.mts +1 -0
- package/dist/legacy/momentjs/getAge.mjs +1 -0
- package/dist/legacy/momentjs/timeDuration.cjs +1 -0
- package/dist/legacy/momentjs/timeDuration.d.mts +1 -0
- package/dist/legacy/momentjs/timeDuration.mjs +1 -0
- package/dist/legacy/socket.io/antiFlood/install.cjs +1 -0
- package/dist/legacy/socket.io/antiFlood/install.d.mts +1 -0
- package/dist/legacy/socket.io/antiFlood/install.mjs +1 -0
- package/dist/legacy/socket.io/antiFlood/verify.cjs +1 -0
- package/dist/legacy/socket.io/antiFlood/verify.d.mts +1 -0
- package/dist/legacy/socket.io/antiFlood/verify.mjs +1 -0
- package/dist/legacy/socket.io/cookie-session.cjs +1 -0
- package/dist/legacy/socket.io/cookie-session.d.mts +1 -0
- package/dist/legacy/socket.io/cookie-session.mjs +1 -0
- package/dist/legacy/socket.io/discord.cjs +1 -0
- package/dist/legacy/socket.io/discord.d.mts +1 -0
- package/dist/legacy/socket.io/discord.mjs +1 -0
- package/dist/v1/TinyAfterScrollWatcher.js +49 -26
- package/dist/v1/TinyAfterScrollWatcher.min.js +1 -1
- package/dist/v1/TinyBasicsEs.js +559 -71
- package/dist/v1/TinyBasicsEs.min.js +1 -1
- package/dist/v1/TinyDragger.js +486 -47
- package/dist/v1/TinyDragger.min.js +1 -1
- package/dist/v1/TinyEssentials.js +2545 -98
- package/dist/v1/TinyEssentials.min.js +1 -1
- package/dist/v1/TinyHtml.js +486 -47
- package/dist/v1/TinyHtml.min.js +1 -1
- package/dist/v1/TinySmartScroller.js +6230 -0
- package/dist/v1/TinySmartScroller.min.js +1 -0
- package/dist/v1/TinyUploadClicker.js +1538 -72
- package/dist/v1/TinyUploadClicker.min.js +1 -1
- package/dist/v1/UltraRandomMsgGen.js +995 -0
- package/dist/v1/UltraRandomMsgGen.min.js +1 -0
- package/dist/v1/basics/html.cjs +74 -24
- package/dist/v1/basics/html.d.mts +38 -15
- package/dist/v1/basics/html.mjs +63 -20
- package/dist/v1/build/TinySmartScroller.cjs +7 -0
- package/dist/v1/build/TinySmartScroller.d.mts +3 -0
- package/dist/v1/build/TinySmartScroller.mjs +2 -0
- package/dist/v1/build/UltraRandomMsgGen.cjs +7 -0
- package/dist/v1/build/UltraRandomMsgGen.d.mts +3 -0
- package/dist/v1/build/UltraRandomMsgGen.mjs +2 -0
- package/dist/v1/index.cjs +4 -0
- package/dist/v1/index.d.mts +3 -1
- package/dist/v1/index.mjs +3 -1
- package/dist/v1/libs/TinyAfterScrollWatcher.cjs +49 -26
- package/dist/v1/libs/TinyAfterScrollWatcher.d.mts +17 -14
- package/dist/v1/libs/TinyAfterScrollWatcher.mjs +50 -24
- package/dist/v1/libs/TinyHtml.cjs +486 -47
- package/dist/v1/libs/TinyHtml.d.mts +352 -139
- package/dist/v1/libs/TinyHtml.mjs +431 -47
- package/dist/v1/libs/TinySmartScroller.cjs +976 -0
- package/dist/v1/libs/TinySmartScroller.d.mts +458 -0
- package/dist/v1/libs/TinySmartScroller.mjs +856 -0
- package/dist/v1/libs/UltraRandomMsgGen.cjs +956 -0
- package/dist/v1/libs/UltraRandomMsgGen.d.mts +390 -0
- package/dist/v1/libs/UltraRandomMsgGen.mjs +825 -0
- package/docs/v1/README.md +2 -0
- package/docs/v1/basics/html.md +17 -2
- package/docs/v1/libs/TinyAfterScrollWatcher.md +54 -4
- package/docs/v1/libs/TinyHtml.md +197 -8
- package/docs/v1/libs/TinySmartScroller.md +523 -0
- package/docs/v1/libs/UltraRandomMsgGen.md +289 -0
- package/package.json +1 -1
package/dist/v1/TinyDragger.js
CHANGED
|
@@ -2628,6 +2628,21 @@ const {
|
|
|
2628
2628
|
* @typedef {Element|Window} ElementAndWindow
|
|
2629
2629
|
*/
|
|
2630
2630
|
|
|
2631
|
+
/**
|
|
2632
|
+
* Represents a raw DOM element/window/document or an instance of TinyHtml.
|
|
2633
|
+
* This type is used to abstract interactions with both plain elements
|
|
2634
|
+
* and wrapped elements via the TinyHtml class.
|
|
2635
|
+
*
|
|
2636
|
+
* @typedef {ElementAndWinAndDoc|TinyHtml} TinyElementAndWinAndDoc
|
|
2637
|
+
*/
|
|
2638
|
+
|
|
2639
|
+
/**
|
|
2640
|
+
* Represents a value that can be either a DOM Element, or the global Window object, or the document object.
|
|
2641
|
+
* Useful for functions that operate generically on scrollable or measurable targets.
|
|
2642
|
+
*
|
|
2643
|
+
* @typedef {Element|Window|Document} ElementAndWinAndDoc
|
|
2644
|
+
*/
|
|
2645
|
+
|
|
2631
2646
|
/**
|
|
2632
2647
|
* A parameter type used for filtering or matching elements.
|
|
2633
2648
|
* It can be:
|
|
@@ -2644,7 +2659,7 @@ const {
|
|
|
2644
2659
|
* Elements accepted as constructor values for TinyHtml.
|
|
2645
2660
|
* These include common DOM elements and root containers.
|
|
2646
2661
|
*
|
|
2647
|
-
* @typedef {Window|Element|Document} ConstructorElValues
|
|
2662
|
+
* @typedef {Window|Element|Document|Text} ConstructorElValues
|
|
2648
2663
|
*/
|
|
2649
2664
|
|
|
2650
2665
|
/**
|
|
@@ -2765,40 +2780,114 @@ class TinyHtml {
|
|
|
2765
2780
|
|
|
2766
2781
|
static Utils = { ...collision_namespaceObject };
|
|
2767
2782
|
|
|
2783
|
+
/**
|
|
2784
|
+
* Creates a new DOM element with the specified tag name and options, then wraps it in a TinyHtml instance.
|
|
2785
|
+
*
|
|
2786
|
+
* @param {string} tagName - The tag name of the element to create (e.g., 'div', 'span').
|
|
2787
|
+
* @param {ElementCreationOptions} ops - Optional settings for creating the element.
|
|
2788
|
+
* @returns {TinyHtml} A TinyHtml instance wrapping the newly created DOM element.
|
|
2789
|
+
* @throws {TypeError} If tagName is not a string or ops is not an object.
|
|
2790
|
+
*/
|
|
2791
|
+
static createElement(tagName, ops) {
|
|
2792
|
+
if (typeof tagName !== 'string')
|
|
2793
|
+
throw new TypeError(`[TinyHtml] createElement(): The tagName must be a string.`);
|
|
2794
|
+
if (typeof ops !== 'undefined' && typeof ops !== 'object')
|
|
2795
|
+
throw new TypeError(`[TinyHtml] createElement(): The ops must be a object.`);
|
|
2796
|
+
return new TinyHtml(document.createElement(tagName, ops));
|
|
2797
|
+
}
|
|
2798
|
+
|
|
2799
|
+
/**
|
|
2800
|
+
* Creates a new TinyHtml instance that wraps a DOM TextNode.
|
|
2801
|
+
*
|
|
2802
|
+
* This method is useful when you want to insert raw text content into the DOM
|
|
2803
|
+
* without it being interpreted as HTML. The returned instance behaves like any
|
|
2804
|
+
* other TinyHtml element and can be appended or manipulated as needed.
|
|
2805
|
+
*
|
|
2806
|
+
* @param {string} value - The plain text content to be wrapped in a TextNode.
|
|
2807
|
+
* @returns {TinyHtml} A TinyHtml instance wrapping the newly created DOM TextNode.
|
|
2808
|
+
* @throws {TypeError} If the provided value is not a string.
|
|
2809
|
+
*/
|
|
2810
|
+
static createTextNode(value) {
|
|
2811
|
+
if (typeof value !== 'string')
|
|
2812
|
+
throw new TypeError(`[TinyHtml] createTextNode(): The value must be a string.`);
|
|
2813
|
+
return new TinyHtml(document.createTextNode(value));
|
|
2814
|
+
}
|
|
2815
|
+
|
|
2816
|
+
/**
|
|
2817
|
+
* Creates an HTMLElement or TextNode from an HTML string.
|
|
2818
|
+
* Supports both elements and plain text.
|
|
2819
|
+
*
|
|
2820
|
+
* @param {string} htmlString - The HTML string to convert.
|
|
2821
|
+
* @returns {TinyHtml} - A single HTMLElement or TextNode.
|
|
2822
|
+
*/
|
|
2823
|
+
static createElementFromHTML(htmlString) {
|
|
2824
|
+
const template = document.createElement('template');
|
|
2825
|
+
htmlString = htmlString.trim();
|
|
2826
|
+
|
|
2827
|
+
// If it's only text (e.g., no "<" tag), return a TextNode
|
|
2828
|
+
if (!htmlString.startsWith('<')) {
|
|
2829
|
+
return TinyHtml.createTextNode(htmlString);
|
|
2830
|
+
}
|
|
2831
|
+
|
|
2832
|
+
template.innerHTML = htmlString;
|
|
2833
|
+
if (!(template.content.firstChild instanceof Element)) throw new Error('');
|
|
2834
|
+
return new TinyHtml(template.content.firstChild);
|
|
2835
|
+
}
|
|
2836
|
+
|
|
2768
2837
|
/**
|
|
2769
2838
|
* Queries the document for the first element matching the CSS selector and wraps it in a TinyHtml instance.
|
|
2770
2839
|
*
|
|
2771
2840
|
* @param {string} selector - A valid CSS selector string.
|
|
2772
|
-
* @
|
|
2773
|
-
* @
|
|
2841
|
+
* @param {Document|Element} elem - Target element.
|
|
2842
|
+
* @returns {TinyHtml|null} A TinyHtml instance wrapping the matched element.
|
|
2774
2843
|
*/
|
|
2775
|
-
static query(selector) {
|
|
2776
|
-
const newEl =
|
|
2777
|
-
if (!newEl)
|
|
2844
|
+
static query(selector, elem = document) {
|
|
2845
|
+
const newEl = elem.querySelector(selector);
|
|
2846
|
+
if (!newEl) return null;
|
|
2778
2847
|
return new TinyHtml(newEl);
|
|
2779
2848
|
}
|
|
2780
2849
|
|
|
2850
|
+
/**
|
|
2851
|
+
* Queries the element for the first element matching the CSS selector and wraps it in a TinyHtml instance.
|
|
2852
|
+
*
|
|
2853
|
+
* @param {string} selector - A valid CSS selector string.
|
|
2854
|
+
* @returns {TinyHtml|null} A TinyHtml instance wrapping the matched element.
|
|
2855
|
+
*/
|
|
2856
|
+
querySelector(selector) {
|
|
2857
|
+
return TinyHtml.query(selector, TinyHtml._preElem(this, 'query'));
|
|
2858
|
+
}
|
|
2859
|
+
|
|
2781
2860
|
/**
|
|
2782
2861
|
* Queries the document for all elements matching the CSS selector and wraps them in TinyHtml instances.
|
|
2783
2862
|
*
|
|
2784
2863
|
* @param {string} selector - A valid CSS selector string.
|
|
2864
|
+
* @param {Document|Element} elem - Target element.
|
|
2785
2865
|
* @returns {TinyHtml[]} An array of TinyHtml instances wrapping the matched elements.
|
|
2786
2866
|
*/
|
|
2787
|
-
static queryAll(selector) {
|
|
2788
|
-
const newEls =
|
|
2867
|
+
static queryAll(selector, elem = document) {
|
|
2868
|
+
const newEls = elem.querySelectorAll(selector);
|
|
2789
2869
|
return TinyHtml.toTinyElm([...newEls]);
|
|
2790
2870
|
}
|
|
2791
2871
|
|
|
2872
|
+
/**
|
|
2873
|
+
* Queries the element for all elements matching the CSS selector and wraps them in TinyHtml instances.
|
|
2874
|
+
*
|
|
2875
|
+
* @param {string} selector - A valid CSS selector string.
|
|
2876
|
+
* @returns {TinyHtml[]} An array of TinyHtml instances wrapping the matched elements.
|
|
2877
|
+
*/
|
|
2878
|
+
querySelectorAll(selector) {
|
|
2879
|
+
return TinyHtml.queryAll(selector, TinyHtml._preElem(this, 'queryAll'));
|
|
2880
|
+
}
|
|
2881
|
+
|
|
2792
2882
|
/**
|
|
2793
2883
|
* Retrieves an element by its ID and wraps it in a TinyHtml instance.
|
|
2794
2884
|
*
|
|
2795
2885
|
* @param {string} selector - The ID of the element to retrieve.
|
|
2796
|
-
* @returns {TinyHtml} A TinyHtml instance wrapping the found element.
|
|
2797
|
-
* @throws {Error} If no element is found with the specified ID.
|
|
2886
|
+
* @returns {TinyHtml|null} A TinyHtml instance wrapping the found element.
|
|
2798
2887
|
*/
|
|
2799
2888
|
static getById(selector) {
|
|
2800
2889
|
const newEl = document.getElementById(selector);
|
|
2801
|
-
if (!newEl)
|
|
2890
|
+
if (!newEl) return null;
|
|
2802
2891
|
return new TinyHtml(newEl);
|
|
2803
2892
|
}
|
|
2804
2893
|
|
|
@@ -2806,13 +2895,24 @@ class TinyHtml {
|
|
|
2806
2895
|
* Retrieves all elements with the specified class name and wraps them in TinyHtml instances.
|
|
2807
2896
|
*
|
|
2808
2897
|
* @param {string} selector - The class name to search for.
|
|
2898
|
+
* @param {Document|Element} elem - Target element.
|
|
2809
2899
|
* @returns {TinyHtml[]} An array of TinyHtml instances wrapping the found elements.
|
|
2810
2900
|
*/
|
|
2811
|
-
static getByClassName(selector) {
|
|
2812
|
-
const newEls =
|
|
2901
|
+
static getByClassName(selector, elem = document) {
|
|
2902
|
+
const newEls = elem.getElementsByClassName(selector);
|
|
2813
2903
|
return TinyHtml.toTinyElm([...newEls]);
|
|
2814
2904
|
}
|
|
2815
2905
|
|
|
2906
|
+
/**
|
|
2907
|
+
* Retrieves all elements with the specified class name and wraps them in TinyHtml instances.
|
|
2908
|
+
*
|
|
2909
|
+
* @param {string} selector - The class name to search for.
|
|
2910
|
+
* @returns {TinyHtml[]} An array of TinyHtml instances wrapping the found elements.
|
|
2911
|
+
*/
|
|
2912
|
+
getElementsByClassName(selector) {
|
|
2913
|
+
return TinyHtml.getByClassName(selector, TinyHtml._preElem(this, 'getByClassName'));
|
|
2914
|
+
}
|
|
2915
|
+
|
|
2816
2916
|
/**
|
|
2817
2917
|
* Retrieves all elements with the specified name attribute and wraps them in TinyHtml instances.
|
|
2818
2918
|
*
|
|
@@ -2830,13 +2930,30 @@ class TinyHtml {
|
|
|
2830
2930
|
*
|
|
2831
2931
|
* @param {string} localName - The local name (tag) of the elements to search for.
|
|
2832
2932
|
* @param {string|null} [namespaceURI='http://www.w3.org/1999/xhtml'] - The namespace URI to search within.
|
|
2933
|
+
* @param {Document|Element} elem - Target element.
|
|
2833
2934
|
* @returns {TinyHtml[]} An array of TinyHtml instances wrapping the found elements.
|
|
2834
2935
|
*/
|
|
2835
|
-
static getByTagNameNS(localName, namespaceURI = 'http://www.w3.org/1999/xhtml') {
|
|
2836
|
-
const newEls =
|
|
2936
|
+
static getByTagNameNS(localName, namespaceURI = 'http://www.w3.org/1999/xhtml', elem = document) {
|
|
2937
|
+
const newEls = elem.getElementsByTagNameNS(namespaceURI, localName);
|
|
2837
2938
|
return TinyHtml.toTinyElm([...newEls]);
|
|
2838
2939
|
}
|
|
2839
2940
|
|
|
2941
|
+
/**
|
|
2942
|
+
* Retrieves all elements with the specified local tag name within the given namespace URI,
|
|
2943
|
+
* and wraps them in TinyHtml instances.
|
|
2944
|
+
*
|
|
2945
|
+
* @param {string} localName - The local name (tag) of the elements to search for.
|
|
2946
|
+
* @param {string|null} [namespaceURI='http://www.w3.org/1999/xhtml'] - The namespace URI to search within.
|
|
2947
|
+
* @returns {TinyHtml[]} An array of TinyHtml instances wrapping the found elements.
|
|
2948
|
+
*/
|
|
2949
|
+
getElementsByTagNameNS(localName, namespaceURI = 'http://www.w3.org/1999/xhtml') {
|
|
2950
|
+
return TinyHtml.getByTagNameNS(
|
|
2951
|
+
localName,
|
|
2952
|
+
namespaceURI,
|
|
2953
|
+
TinyHtml._preElem(this, 'getByTagNameNS'),
|
|
2954
|
+
);
|
|
2955
|
+
}
|
|
2956
|
+
|
|
2840
2957
|
//////////////////////////////////////////////////////////////////
|
|
2841
2958
|
|
|
2842
2959
|
/**
|
|
@@ -3117,6 +3234,45 @@ class TinyHtml {
|
|
|
3117
3234
|
return TinyHtml._preElemTemplate(elems, where, [Element, Window], ['Element', 'Window']);
|
|
3118
3235
|
}
|
|
3119
3236
|
|
|
3237
|
+
/**
|
|
3238
|
+
* Ensures the input is returned as an array.
|
|
3239
|
+
* Useful to normalize operations across multiple or single element/window/document elements.
|
|
3240
|
+
*
|
|
3241
|
+
* @param {TinyElementAndWinAndDoc|TinyElementAndWinAndDoc[]} elems - A single element/window element or array of html elements.
|
|
3242
|
+
* @param {string} where - The method or context name where validation is being called.
|
|
3243
|
+
* @returns {ElementAndWindow[]} - Always returns an array of element/window elements.
|
|
3244
|
+
* @readonly
|
|
3245
|
+
*/
|
|
3246
|
+
static _preElemsAndWinAndDoc(elems, where) {
|
|
3247
|
+
const result = TinyHtml._preElemsTemplate(
|
|
3248
|
+
elems,
|
|
3249
|
+
where,
|
|
3250
|
+
[Element, Window, Document],
|
|
3251
|
+
['Element', 'Window', 'Document'],
|
|
3252
|
+
);
|
|
3253
|
+
return result.map((elem) => (!(elem instanceof Document) ? elem : elem.documentElement));
|
|
3254
|
+
}
|
|
3255
|
+
|
|
3256
|
+
/**
|
|
3257
|
+
* Ensures the input is returned as an single element/window/document element.
|
|
3258
|
+
* Useful to normalize operations across multiple or single element/window/document elements.
|
|
3259
|
+
*
|
|
3260
|
+
* @param {TinyElementAndWinAndDoc|TinyElementAndWinAndDoc[]} elems - A single element/window element or array of html elements.
|
|
3261
|
+
* @param {string} where - The method or context name where validation is being called.
|
|
3262
|
+
* @returns {ElementAndWindow} - Always returns an single element/window element.
|
|
3263
|
+
* @readonly
|
|
3264
|
+
*/
|
|
3265
|
+
static _preElemAndWinAndDoc(elems, where) {
|
|
3266
|
+
const result = TinyHtml._preElemTemplate(
|
|
3267
|
+
elems,
|
|
3268
|
+
where,
|
|
3269
|
+
[Element, Window, Document],
|
|
3270
|
+
['Element', 'Window', 'Document'],
|
|
3271
|
+
);
|
|
3272
|
+
if (result instanceof Document) return result.documentElement;
|
|
3273
|
+
return result;
|
|
3274
|
+
}
|
|
3275
|
+
|
|
3120
3276
|
/**
|
|
3121
3277
|
* Normalizes and converts one or more DOM elements (or TinyHtml instances)
|
|
3122
3278
|
* into an array of `TinyHtml` instances.
|
|
@@ -3463,12 +3619,13 @@ class TinyHtml {
|
|
|
3463
3619
|
* @param {string} key - The key under which the data will be stored.
|
|
3464
3620
|
* @param {any} value - The value to store.
|
|
3465
3621
|
* @param {boolean} [isPrivate=false] - Whether to store the data in the private store.
|
|
3466
|
-
* @returns {
|
|
3622
|
+
* @returns {TinyElement}
|
|
3467
3623
|
*/
|
|
3468
3624
|
static setData(el, key, value, isPrivate = false) {
|
|
3469
3625
|
const data = TinyHtml._dataSelector[!isPrivate ? 'public' : 'private']('setData', el);
|
|
3470
3626
|
if (typeof key !== 'string') throw new TypeError('The key must be a string.');
|
|
3471
3627
|
data[key] = value;
|
|
3628
|
+
return el;
|
|
3472
3629
|
}
|
|
3473
3630
|
|
|
3474
3631
|
/**
|
|
@@ -3477,7 +3634,7 @@ class TinyHtml {
|
|
|
3477
3634
|
* @param {string} key - The key under which the data will be stored.
|
|
3478
3635
|
* @param {any} value - The value to store.
|
|
3479
3636
|
* @param {boolean} [isPrivate=false] - Whether to store the data in the private store.
|
|
3480
|
-
* @returns {
|
|
3637
|
+
* @returns {TinyElement}
|
|
3481
3638
|
*/
|
|
3482
3639
|
setData(key, value, isPrivate = false) {
|
|
3483
3640
|
return TinyHtml.setData(this, key, value, isPrivate);
|
|
@@ -3824,18 +3981,21 @@ class TinyHtml {
|
|
|
3824
3981
|
/**
|
|
3825
3982
|
* Appends child elements or strings to the end of the target element(s).
|
|
3826
3983
|
*
|
|
3827
|
-
* @param {TinyElement
|
|
3984
|
+
* @param {TinyElement} el - The target element(s) to receive children.
|
|
3828
3985
|
* @param {...(TinyNode | TinyNode[] | string)} children - The child elements or text to append.
|
|
3986
|
+
* @returns {TinyElement}
|
|
3829
3987
|
*/
|
|
3830
3988
|
static append(el, ...children) {
|
|
3831
3989
|
const elem = TinyHtml._preElem(el, 'append');
|
|
3832
3990
|
elem.append(...TinyHtml._appendChecker('append', ...children));
|
|
3991
|
+
return el;
|
|
3833
3992
|
}
|
|
3834
3993
|
|
|
3835
3994
|
/**
|
|
3836
3995
|
* Appends child elements or strings to the end of the target element(s).
|
|
3837
3996
|
*
|
|
3838
3997
|
* @param {...(TinyNode | TinyNode[] | string)} children - The child elements or text to append.
|
|
3998
|
+
* @returns {TinyElement}
|
|
3839
3999
|
*/
|
|
3840
4000
|
append(...children) {
|
|
3841
4001
|
return TinyHtml.append(this, ...children);
|
|
@@ -3844,18 +4004,21 @@ class TinyHtml {
|
|
|
3844
4004
|
/**
|
|
3845
4005
|
* Prepends child elements or strings to the beginning of the target element(s).
|
|
3846
4006
|
*
|
|
3847
|
-
* @param {TinyElement
|
|
4007
|
+
* @param {TinyElement} el - The target element(s) to receive children.
|
|
3848
4008
|
* @param {...(TinyNode | TinyNode[] | string)} children - The child elements or text to prepend.
|
|
4009
|
+
* @returns {TinyElement}
|
|
3849
4010
|
*/
|
|
3850
4011
|
static prepend(el, ...children) {
|
|
3851
4012
|
const elem = TinyHtml._preElem(el, 'prepend');
|
|
3852
4013
|
elem.prepend(...TinyHtml._appendChecker('prepend', ...children));
|
|
4014
|
+
return el;
|
|
3853
4015
|
}
|
|
3854
4016
|
|
|
3855
4017
|
/**
|
|
3856
4018
|
* Prepends child elements or strings to the beginning of the target element(s).
|
|
3857
4019
|
*
|
|
3858
4020
|
* @param {...(TinyNode | TinyNode[] | string)} children - The child elements or text to prepend.
|
|
4021
|
+
* @returns {TinyElement}
|
|
3859
4022
|
*/
|
|
3860
4023
|
prepend(...children) {
|
|
3861
4024
|
return TinyHtml.prepend(this, ...children);
|
|
@@ -3864,18 +4027,21 @@ class TinyHtml {
|
|
|
3864
4027
|
/**
|
|
3865
4028
|
* Inserts elements or strings immediately before the target element(s) in the DOM.
|
|
3866
4029
|
*
|
|
3867
|
-
* @param {TinyElement
|
|
4030
|
+
* @param {TinyElement} el - The target element(s) before which new content is inserted.
|
|
3868
4031
|
* @param {...(TinyNode | TinyNode[] | string)} children - Elements or text to insert before the target.
|
|
4032
|
+
* @returns {TinyElement}
|
|
3869
4033
|
*/
|
|
3870
4034
|
static before(el, ...children) {
|
|
3871
4035
|
const elem = TinyHtml._preElem(el, 'before');
|
|
3872
4036
|
elem.before(...TinyHtml._appendChecker('before', ...children));
|
|
4037
|
+
return el;
|
|
3873
4038
|
}
|
|
3874
4039
|
|
|
3875
4040
|
/**
|
|
3876
4041
|
* Inserts elements or strings immediately before the target element(s) in the DOM.
|
|
3877
4042
|
*
|
|
3878
4043
|
* @param {...(TinyNode | TinyNode[] | string)} children - Elements or text to insert before the target.
|
|
4044
|
+
* @returns {TinyElement}
|
|
3879
4045
|
*/
|
|
3880
4046
|
before(...children) {
|
|
3881
4047
|
return TinyHtml.before(this, ...children);
|
|
@@ -3884,18 +4050,21 @@ class TinyHtml {
|
|
|
3884
4050
|
/**
|
|
3885
4051
|
* Inserts elements or strings immediately after the target element(s) in the DOM.
|
|
3886
4052
|
*
|
|
3887
|
-
* @param {TinyElement
|
|
4053
|
+
* @param {TinyElement} el - The target element(s) after which new content is inserted.
|
|
3888
4054
|
* @param {...(TinyNode | TinyNode[] | string)} children - Elements or text to insert after the target.
|
|
4055
|
+
* @returns {TinyElement}
|
|
3889
4056
|
*/
|
|
3890
4057
|
static after(el, ...children) {
|
|
3891
4058
|
const elem = TinyHtml._preElem(el, 'after');
|
|
3892
4059
|
elem.after(...TinyHtml._appendChecker('after', ...children));
|
|
4060
|
+
return el;
|
|
3893
4061
|
}
|
|
3894
4062
|
|
|
3895
4063
|
/**
|
|
3896
4064
|
* Inserts elements or strings immediately after the target element(s) in the DOM.
|
|
3897
4065
|
*
|
|
3898
4066
|
* @param {...(TinyNode | TinyNode[] | string)} children - Elements or text to insert after the target.
|
|
4067
|
+
* @returns {TinyElement}
|
|
3899
4068
|
*/
|
|
3900
4069
|
after(...children) {
|
|
3901
4070
|
return TinyHtml.after(this, ...children);
|
|
@@ -3904,18 +4073,21 @@ class TinyHtml {
|
|
|
3904
4073
|
/**
|
|
3905
4074
|
* Replaces the target element(s) in the DOM with new elements or text.
|
|
3906
4075
|
*
|
|
3907
|
-
* @param {TinyElement
|
|
4076
|
+
* @param {TinyElement} el - The element(s) to be replaced.
|
|
3908
4077
|
* @param {...(TinyNode | TinyNode[] | string)} newNodes - New elements or text to replace the target.
|
|
4078
|
+
* @returns {TinyElement}
|
|
3909
4079
|
*/
|
|
3910
4080
|
static replaceWith(el, ...newNodes) {
|
|
3911
4081
|
const elem = TinyHtml._preElem(el, 'replaceWith');
|
|
3912
4082
|
elem.replaceWith(...TinyHtml._appendChecker('replaceWith', ...newNodes));
|
|
4083
|
+
return el;
|
|
3913
4084
|
}
|
|
3914
4085
|
|
|
3915
4086
|
/**
|
|
3916
4087
|
* Replaces the target element(s) in the DOM with new elements or text.
|
|
3917
4088
|
*
|
|
3918
4089
|
* @param {...(TinyNode | TinyNode[] | string)} newNodes - New elements or text to replace the target.
|
|
4090
|
+
* @returns {TinyElement}
|
|
3919
4091
|
*/
|
|
3920
4092
|
replaceWith(...newNodes) {
|
|
3921
4093
|
return TinyHtml.replaceWith(this, ...newNodes);
|
|
@@ -3926,6 +4098,7 @@ class TinyHtml {
|
|
|
3926
4098
|
*
|
|
3927
4099
|
* @param {TinyNode | TinyNode[]} el - The element(s) to append.
|
|
3928
4100
|
* @param {TinyNode | TinyNode[]} targets - Target element(s) where content will be appended.
|
|
4101
|
+
* @returns {TinyNode|TinyNode[]}
|
|
3929
4102
|
*/
|
|
3930
4103
|
static appendTo(el, targets) {
|
|
3931
4104
|
const elems = TinyHtml._preNodeElems(el, 'appendTo');
|
|
@@ -3935,12 +4108,14 @@ class TinyHtml {
|
|
|
3935
4108
|
target.appendChild(i === tars.length - 1 ? elem : elem.cloneNode(true)),
|
|
3936
4109
|
);
|
|
3937
4110
|
});
|
|
4111
|
+
return el;
|
|
3938
4112
|
}
|
|
3939
4113
|
|
|
3940
4114
|
/**
|
|
3941
4115
|
* Appends the given element(s) to each target element in sequence.
|
|
3942
4116
|
*
|
|
3943
4117
|
* @param {TinyNode | TinyNode[]} targets - Target element(s) where content will be appended.
|
|
4118
|
+
* @returns {TinyNode|TinyNode[]}
|
|
3944
4119
|
*/
|
|
3945
4120
|
appendTo(targets) {
|
|
3946
4121
|
return TinyHtml.appendTo(this, targets);
|
|
@@ -3951,6 +4126,7 @@ class TinyHtml {
|
|
|
3951
4126
|
*
|
|
3952
4127
|
* @param {TinyElement | TinyElement[]} el - The element(s) to prepend.
|
|
3953
4128
|
* @param {TinyElement | TinyElement[]} targets - Target element(s) where content will be prepended.
|
|
4129
|
+
* @returns {TinyElement|TinyElement[]}
|
|
3954
4130
|
*/
|
|
3955
4131
|
static prependTo(el, targets) {
|
|
3956
4132
|
const elems = TinyHtml._preElems(el, 'prependTo');
|
|
@@ -3961,12 +4137,14 @@ class TinyHtml {
|
|
|
3961
4137
|
.reverse()
|
|
3962
4138
|
.forEach((elem) => target.prepend(i === tars.length - 1 ? elem : elem.cloneNode(true)));
|
|
3963
4139
|
});
|
|
4140
|
+
return el;
|
|
3964
4141
|
}
|
|
3965
4142
|
|
|
3966
4143
|
/**
|
|
3967
4144
|
* Prepends the given element(s) to each target element in sequence.
|
|
3968
4145
|
*
|
|
3969
4146
|
* @param {TinyElement | TinyElement[]} targets - Target element(s) where content will be prepended.
|
|
4147
|
+
* @returns {TinyElement|TinyElement[]}
|
|
3970
4148
|
*/
|
|
3971
4149
|
prependTo(targets) {
|
|
3972
4150
|
return TinyHtml.prependTo(this, targets);
|
|
@@ -3978,6 +4156,7 @@ class TinyHtml {
|
|
|
3978
4156
|
* @param {TinyNode | TinyNode[]} el - The element(s) to insert.
|
|
3979
4157
|
* @param {TinyNode | TinyNode[]} target - The reference element where insertion happens.
|
|
3980
4158
|
* @param {TinyNode | TinyNode[] | null} [child=null] - Optional child to insert before, defaults to target.
|
|
4159
|
+
* @returns {TinyNode|TinyNode[]}
|
|
3981
4160
|
*/
|
|
3982
4161
|
static insertBefore(el, target, child = null) {
|
|
3983
4162
|
const elem = TinyHtml._preNodeElem(el, 'insertBefore');
|
|
@@ -3985,6 +4164,7 @@ class TinyHtml {
|
|
|
3985
4164
|
const childNode = TinyHtml._preNodeElemWithNull(child, 'insertBefore');
|
|
3986
4165
|
if (!targ.parentNode) throw new Error('');
|
|
3987
4166
|
targ.parentNode.insertBefore(elem, childNode || targ);
|
|
4167
|
+
return el;
|
|
3988
4168
|
}
|
|
3989
4169
|
|
|
3990
4170
|
/**
|
|
@@ -3992,6 +4172,7 @@ class TinyHtml {
|
|
|
3992
4172
|
*
|
|
3993
4173
|
* @param {TinyNode | TinyNode[]} target - The reference element where insertion happens.
|
|
3994
4174
|
* @param {TinyNode | TinyNode[] | null} [child=null] - Optional child to insert before, defaults to target.
|
|
4175
|
+
* @returns {TinyNode|TinyNode[]}
|
|
3995
4176
|
*/
|
|
3996
4177
|
insertBefore(target, child) {
|
|
3997
4178
|
return TinyHtml.insertBefore(this, target, child);
|
|
@@ -4003,6 +4184,7 @@ class TinyHtml {
|
|
|
4003
4184
|
* @param {TinyNode | TinyNode[]} el - The element(s) to insert.
|
|
4004
4185
|
* @param {TinyNode | TinyNode[]} target - The reference element where insertion happens.
|
|
4005
4186
|
* @param {TinyNode | TinyNode[] | null} [child=null] - Optional child to insert after, defaults to target.
|
|
4187
|
+
* @returns {TinyNode|TinyNode[]}
|
|
4006
4188
|
*/
|
|
4007
4189
|
static insertAfter(el, target, child = null) {
|
|
4008
4190
|
const elem = TinyHtml._preNodeElem(el, 'insertAfter');
|
|
@@ -4010,6 +4192,7 @@ class TinyHtml {
|
|
|
4010
4192
|
const childNode = TinyHtml._preNodeElemWithNull(child, 'insertBefore');
|
|
4011
4193
|
if (!targ.parentNode) throw new Error('');
|
|
4012
4194
|
targ.parentNode.insertBefore(elem, childNode || targ.nextSibling);
|
|
4195
|
+
return el;
|
|
4013
4196
|
}
|
|
4014
4197
|
|
|
4015
4198
|
/**
|
|
@@ -4017,6 +4200,7 @@ class TinyHtml {
|
|
|
4017
4200
|
*
|
|
4018
4201
|
* @param {TinyNode | TinyNode[]} target - The reference element where insertion happens.
|
|
4019
4202
|
* @param {TinyNode | TinyNode[] | null} [child=null] - Optional child to insert after, defaults to target.
|
|
4203
|
+
* @returns {TinyNode|TinyNode[]}
|
|
4020
4204
|
*/
|
|
4021
4205
|
insertAfter(target, child) {
|
|
4022
4206
|
return TinyHtml.insertAfter(this, target, child);
|
|
@@ -4028,6 +4212,7 @@ class TinyHtml {
|
|
|
4028
4212
|
*
|
|
4029
4213
|
* @param {TinyNode | TinyNode[]} el - The new element(s) to insert.
|
|
4030
4214
|
* @param {TinyNode | TinyNode[]} targets - The elements to be replaced.
|
|
4215
|
+
* @returns {TinyNode|TinyNode[]}
|
|
4031
4216
|
*/
|
|
4032
4217
|
static replaceAll(el, targets) {
|
|
4033
4218
|
const elems = TinyHtml._preNodeElems(el, 'replaceAll');
|
|
@@ -4039,6 +4224,7 @@ class TinyHtml {
|
|
|
4039
4224
|
parent.replaceChild(i === tars.length - 1 ? elem : elem.cloneNode(true), target);
|
|
4040
4225
|
});
|
|
4041
4226
|
});
|
|
4227
|
+
return el;
|
|
4042
4228
|
}
|
|
4043
4229
|
|
|
4044
4230
|
/**
|
|
@@ -4046,6 +4232,7 @@ class TinyHtml {
|
|
|
4046
4232
|
* If multiple targets exist, the inserted elements are cloned accordingly.
|
|
4047
4233
|
*
|
|
4048
4234
|
* @param {TinyNode | TinyNode[]} targets - The elements to be replaced.
|
|
4235
|
+
* @returns {TinyNode|TinyNode[]}
|
|
4049
4236
|
*/
|
|
4050
4237
|
replaceAll(targets) {
|
|
4051
4238
|
return TinyHtml.replaceAll(this, targets);
|
|
@@ -4069,7 +4256,12 @@ class TinyHtml {
|
|
|
4069
4256
|
throw new Error(
|
|
4070
4257
|
`[TinyHtml] You are trying to put a TinyHtml inside another TinyHtml in constructor.`,
|
|
4071
4258
|
);
|
|
4072
|
-
if (
|
|
4259
|
+
if (
|
|
4260
|
+
!(el instanceof Element) &&
|
|
4261
|
+
!(el instanceof Window) &&
|
|
4262
|
+
!(el instanceof Document) &&
|
|
4263
|
+
!(el instanceof Text)
|
|
4264
|
+
)
|
|
4073
4265
|
throw new Error(`[TinyHtml] Invalid Target in constructor.`);
|
|
4074
4266
|
this.#el = el;
|
|
4075
4267
|
}
|
|
@@ -4519,6 +4711,7 @@ class TinyHtml {
|
|
|
4519
4711
|
* @param {TinyHtmlElement|TinyHtmlElement[]} el - The element to inspect.
|
|
4520
4712
|
* @param {string|Object} prop - The property name or an object with key-value pairs
|
|
4521
4713
|
* @param {string|null} [value=null] - The value to set (if `prop` is a string)
|
|
4714
|
+
* @returns {TinyHtmlElement|TinyHtmlElement[]}
|
|
4522
4715
|
*/
|
|
4523
4716
|
static setStyle(el, prop, value = null) {
|
|
4524
4717
|
TinyHtml._preHtmlElems(el, 'setStyle').forEach((elem) => {
|
|
@@ -4531,6 +4724,7 @@ class TinyHtml {
|
|
|
4531
4724
|
}
|
|
4532
4725
|
} else elem.style.setProperty(TinyHtml.toStyleKc(prop), value);
|
|
4533
4726
|
});
|
|
4727
|
+
return el;
|
|
4534
4728
|
}
|
|
4535
4729
|
|
|
4536
4730
|
/**
|
|
@@ -4541,6 +4735,7 @@ class TinyHtml {
|
|
|
4541
4735
|
*
|
|
4542
4736
|
* @param {string|Object} prop - The property name or an object with key-value pairs
|
|
4543
4737
|
* @param {string|null} [value=null] - The value to set (if `prop` is a string)
|
|
4738
|
+
* @returns {TinyHtmlElement|TinyHtmlElement[]}
|
|
4544
4739
|
*/
|
|
4545
4740
|
setStyle(prop, value) {
|
|
4546
4741
|
return TinyHtml.setStyle(this, prop, value);
|
|
@@ -4636,6 +4831,7 @@ class TinyHtml {
|
|
|
4636
4831
|
*
|
|
4637
4832
|
* @param {TinyHtmlElement|TinyHtmlElement[]} el - A single element or an array of elements.
|
|
4638
4833
|
* @param {string|string[]} prop - A property name or an array of property names to remove.
|
|
4834
|
+
* @returns {TinyHtmlElement|TinyHtmlElement[]}
|
|
4639
4835
|
*/
|
|
4640
4836
|
static removeStyle(el, prop) {
|
|
4641
4837
|
TinyHtml._preHtmlElems(el, 'removeStyle').forEach((elem) => {
|
|
@@ -4645,12 +4841,14 @@ class TinyHtml {
|
|
|
4645
4841
|
}
|
|
4646
4842
|
} else elem.style.removeProperty(TinyHtml.toStyleKc(prop));
|
|
4647
4843
|
});
|
|
4844
|
+
return el;
|
|
4648
4845
|
}
|
|
4649
4846
|
|
|
4650
4847
|
/**
|
|
4651
4848
|
* Removes one or more inline CSS properties from the given element(s).
|
|
4652
4849
|
*
|
|
4653
4850
|
* @param {string|string[]} prop - A property name or an array of property names to remove.
|
|
4851
|
+
* @returns {TinyHtmlElement|TinyHtmlElement[]}
|
|
4654
4852
|
*/
|
|
4655
4853
|
removeStyle(prop) {
|
|
4656
4854
|
return TinyHtml.removeStyle(this, prop);
|
|
@@ -4665,6 +4863,7 @@ class TinyHtml {
|
|
|
4665
4863
|
* @param {string} prop - The CSS property to toggle.
|
|
4666
4864
|
* @param {string} val1 - The first value (used as "current" check).
|
|
4667
4865
|
* @param {string} val2 - The second value (used as the "alternative").
|
|
4866
|
+
* @returns {TinyHtmlElement|TinyHtmlElement[]}
|
|
4668
4867
|
*/
|
|
4669
4868
|
static toggleStyle(el, prop, val1, val2) {
|
|
4670
4869
|
TinyHtml._preHtmlElems(el, 'toggleStyle').forEach((elem) => {
|
|
@@ -4672,6 +4871,7 @@ class TinyHtml {
|
|
|
4672
4871
|
const newVal = current === TinyHtml.toStyleKc(val1) ? val2 : val1;
|
|
4673
4872
|
TinyHtml.setStyle(elem, prop, newVal);
|
|
4674
4873
|
});
|
|
4874
|
+
return el;
|
|
4675
4875
|
}
|
|
4676
4876
|
|
|
4677
4877
|
/**
|
|
@@ -4682,6 +4882,7 @@ class TinyHtml {
|
|
|
4682
4882
|
* @param {string} prop - The CSS property to toggle.
|
|
4683
4883
|
* @param {string} val1 - The first value (used as "current" check).
|
|
4684
4884
|
* @param {string} val2 - The second value (used as the "alternative").
|
|
4885
|
+
* @returns {TinyHtmlElement|TinyHtmlElement[]}
|
|
4685
4886
|
*/
|
|
4686
4887
|
toggleStyle(prop, val1, val2) {
|
|
4687
4888
|
return TinyHtml.toggleStyle(this, prop, val1, val2);
|
|
@@ -4691,14 +4892,16 @@ class TinyHtml {
|
|
|
4691
4892
|
* Removes all inline styles (`style` attribute) from the given element(s).
|
|
4692
4893
|
*
|
|
4693
4894
|
* @param {TinyElement|TinyElement[]} el - A single element or an array of elements.
|
|
4895
|
+
* @returns {TinyElement|TinyElement[]}
|
|
4694
4896
|
*/
|
|
4695
4897
|
static clearStyle(el) {
|
|
4696
4898
|
TinyHtml._preElems(el, 'clearStyle').forEach((elem) => elem.removeAttribute('style'));
|
|
4899
|
+
return el;
|
|
4697
4900
|
}
|
|
4698
4901
|
|
|
4699
4902
|
/**
|
|
4700
4903
|
* Removes all inline styles (`style` attribute) from the given element(s).
|
|
4701
|
-
*
|
|
4904
|
+
* @returns {TinyElement|TinyElement[]}
|
|
4702
4905
|
*/
|
|
4703
4906
|
clearStyle() {
|
|
4704
4907
|
return TinyHtml.clearStyle(this);
|
|
@@ -4710,14 +4913,17 @@ class TinyHtml {
|
|
|
4710
4913
|
* Focus the element.
|
|
4711
4914
|
*
|
|
4712
4915
|
* @param {TinyHtmlElement} el - The element or a selector string.
|
|
4916
|
+
* @returns {TinyHtmlElement}
|
|
4713
4917
|
*/
|
|
4714
4918
|
static focus(el) {
|
|
4715
4919
|
const elem = TinyHtml._preHtmlElem(el, 'focus');
|
|
4716
4920
|
elem.focus();
|
|
4921
|
+
return el;
|
|
4717
4922
|
}
|
|
4718
4923
|
|
|
4719
4924
|
/**
|
|
4720
4925
|
* Focus the element.
|
|
4926
|
+
* @returns {TinyHtmlElement}
|
|
4721
4927
|
*/
|
|
4722
4928
|
focus() {
|
|
4723
4929
|
return TinyHtml.focus(this);
|
|
@@ -4727,19 +4933,46 @@ class TinyHtml {
|
|
|
4727
4933
|
* Blur the element.
|
|
4728
4934
|
*
|
|
4729
4935
|
* @param {TinyHtmlElement} el - The element or a selector string.
|
|
4936
|
+
* @returns {TinyHtmlElement}
|
|
4730
4937
|
*/
|
|
4731
4938
|
static blur(el) {
|
|
4732
4939
|
const elem = TinyHtml._preHtmlElem(el, 'blur');
|
|
4733
4940
|
elem.blur();
|
|
4941
|
+
return el;
|
|
4734
4942
|
}
|
|
4735
4943
|
|
|
4736
4944
|
/**
|
|
4737
4945
|
* Blur the element.
|
|
4946
|
+
* @returns {TinyHtmlElement}
|
|
4738
4947
|
*/
|
|
4739
4948
|
blur() {
|
|
4740
4949
|
return TinyHtml.blur(this);
|
|
4741
4950
|
}
|
|
4742
4951
|
|
|
4952
|
+
/**
|
|
4953
|
+
* Interprets a value as a boolean `true` if it matches a common truthy representation.
|
|
4954
|
+
*
|
|
4955
|
+
* This method checks if the input is any of the common forms used to represent `true`,
|
|
4956
|
+
* such as the string `'true'`, `'1'`, `'on'`, the boolean `true`, or the number `1`.
|
|
4957
|
+
*
|
|
4958
|
+
* @param {string|boolean|number} [value] - The value to interpret as boolean.
|
|
4959
|
+
* @returns {boolean} `true` if the value represents a truthy state, otherwise `false`.
|
|
4960
|
+
*/
|
|
4961
|
+
static boolCheck(value) {
|
|
4962
|
+
if (
|
|
4963
|
+
typeof value !== 'undefined' &&
|
|
4964
|
+
(value === 'true' ||
|
|
4965
|
+
value === '1' ||
|
|
4966
|
+
value === true ||
|
|
4967
|
+
value === 'on' ||
|
|
4968
|
+
(typeof value === 'number' && value > 0))
|
|
4969
|
+
) {
|
|
4970
|
+
return true;
|
|
4971
|
+
} else {
|
|
4972
|
+
return false;
|
|
4973
|
+
}
|
|
4974
|
+
}
|
|
4975
|
+
|
|
4743
4976
|
//////////////////////////////////////////////////////////////////////
|
|
4744
4977
|
|
|
4745
4978
|
/**
|
|
@@ -4792,16 +5025,40 @@ class TinyHtml {
|
|
|
4792
5025
|
return window.innerWidth || document.documentElement.clientWidth;
|
|
4793
5026
|
}
|
|
4794
5027
|
|
|
5028
|
+
/**
|
|
5029
|
+
* Checks if the page is currently scrolled to the very top.
|
|
5030
|
+
*
|
|
5031
|
+
* This method compares the current vertical scroll position with the total document height.
|
|
5032
|
+
* It's useful for detecting if the user has reached the top of the page.
|
|
5033
|
+
*
|
|
5034
|
+
* @returns {boolean} `true` if the page is scrolled to the top, otherwise `false`.
|
|
5035
|
+
*/
|
|
5036
|
+
static isPageTop() {
|
|
5037
|
+
return window.scrollY === 0;
|
|
5038
|
+
}
|
|
5039
|
+
|
|
5040
|
+
/**
|
|
5041
|
+
* Checks if the page is currently scrolled to the very bottom.
|
|
5042
|
+
*
|
|
5043
|
+
* This method uses the `scrollY` and `innerHeight` properties to determine if the
|
|
5044
|
+
* user has reached the end of the document.
|
|
5045
|
+
*
|
|
5046
|
+
* @returns {boolean} `true` if the page is scrolled to the bottom, otherwise `false`.
|
|
5047
|
+
*/
|
|
5048
|
+
static isPageBottom() {
|
|
5049
|
+
return window.innerHeight + window.scrollY >= document.body.offsetHeight;
|
|
5050
|
+
}
|
|
5051
|
+
|
|
4795
5052
|
/**
|
|
4796
5053
|
* Gets the width or height of an element based on the box model.
|
|
4797
|
-
* @param {
|
|
5054
|
+
* @param {TinyElementAndWinAndDoc} el - The element or window.
|
|
4798
5055
|
* @param {"width"|"height"} type - Dimension type.
|
|
4799
5056
|
* @param {"content"|"padding"|"border"|"margin"} [extra='content'] - Box model context.
|
|
4800
5057
|
* @returns {number} - Computed dimension.
|
|
4801
5058
|
* @throws {TypeError} If `type` or `extra` is not a string.
|
|
4802
5059
|
*/
|
|
4803
5060
|
static getDimension(el, type, extra = 'content') {
|
|
4804
|
-
const elem = TinyHtml.
|
|
5061
|
+
const elem = TinyHtml._preElemAndWinAndDoc(el, 'getDimension');
|
|
4805
5062
|
if (typeof type !== 'string') throw new TypeError('The type must be a string.');
|
|
4806
5063
|
if (typeof extra !== 'string') throw new TypeError('The extra must be a string.');
|
|
4807
5064
|
|
|
@@ -4889,17 +5146,20 @@ class TinyHtml {
|
|
|
4889
5146
|
* @param {TinyHtmlElement} el - Target element.
|
|
4890
5147
|
* @param {string|number} value - Height value.
|
|
4891
5148
|
* @throws {TypeError} If `value` is neither a string nor number.
|
|
5149
|
+
* @returns {TinyHtmlElement}
|
|
4892
5150
|
*/
|
|
4893
5151
|
static setHeight(el, value) {
|
|
4894
5152
|
const elem = TinyHtml._preHtmlElem(el, 'setHeight');
|
|
4895
5153
|
if (typeof value !== 'number' && typeof value !== 'string')
|
|
4896
5154
|
throw new TypeError('The value must be a string or number.');
|
|
4897
5155
|
elem.style.height = typeof value === 'number' ? `${value}px` : value;
|
|
5156
|
+
return el;
|
|
4898
5157
|
}
|
|
4899
5158
|
|
|
4900
5159
|
/**
|
|
4901
5160
|
* Sets the height of the element.
|
|
4902
5161
|
* @param {string|number} value - Height value.
|
|
5162
|
+
* @returns {TinyHtmlElement}
|
|
4903
5163
|
*/
|
|
4904
5164
|
setHeight(value) {
|
|
4905
5165
|
return TinyHtml.setHeight(this, value);
|
|
@@ -4910,17 +5170,20 @@ class TinyHtml {
|
|
|
4910
5170
|
* @param {TinyHtmlElement} el - Target element.
|
|
4911
5171
|
* @param {string|number} value - Width value.
|
|
4912
5172
|
* @throws {TypeError} If `value` is neither a string nor number.
|
|
5173
|
+
* @returns {TinyHtmlElement}
|
|
4913
5174
|
*/
|
|
4914
5175
|
static setWidth(el, value) {
|
|
4915
5176
|
const elem = TinyHtml._preHtmlElem(el, 'setWidth');
|
|
4916
5177
|
if (typeof value !== 'number' && typeof value !== 'string')
|
|
4917
5178
|
throw new TypeError('The value must be a string or number.');
|
|
4918
5179
|
elem.style.width = typeof value === 'number' ? `${value}px` : value;
|
|
5180
|
+
return el;
|
|
4919
5181
|
}
|
|
4920
5182
|
|
|
4921
5183
|
/**
|
|
4922
5184
|
* Sets the width of the element.
|
|
4923
5185
|
* @param {string|number} value - Width value.
|
|
5186
|
+
* @returns {TinyHtmlElement}
|
|
4924
5187
|
*/
|
|
4925
5188
|
setWidth(value) {
|
|
4926
5189
|
return TinyHtml.setWidth(this, value);
|
|
@@ -4928,11 +5191,11 @@ class TinyHtml {
|
|
|
4928
5191
|
|
|
4929
5192
|
/**
|
|
4930
5193
|
* Returns content box height.
|
|
4931
|
-
* @param {
|
|
5194
|
+
* @param {TinyElementAndWinAndDoc} el - Target element.
|
|
4932
5195
|
* @returns {number}
|
|
4933
5196
|
*/
|
|
4934
5197
|
static height(el) {
|
|
4935
|
-
const elem = TinyHtml.
|
|
5198
|
+
const elem = TinyHtml._preElemAndWinAndDoc(el, 'height');
|
|
4936
5199
|
return TinyHtml.getDimension(elem, 'height', 'content');
|
|
4937
5200
|
}
|
|
4938
5201
|
|
|
@@ -4946,11 +5209,11 @@ class TinyHtml {
|
|
|
4946
5209
|
|
|
4947
5210
|
/**
|
|
4948
5211
|
* Returns content box width.
|
|
4949
|
-
* @param {
|
|
5212
|
+
* @param {TinyElementAndWinAndDoc} el - Target element.
|
|
4950
5213
|
* @returns {number}
|
|
4951
5214
|
*/
|
|
4952
5215
|
static width(el) {
|
|
4953
|
-
const elem = TinyHtml.
|
|
5216
|
+
const elem = TinyHtml._preElemAndWinAndDoc(el, 'width');
|
|
4954
5217
|
return TinyHtml.getDimension(elem, 'width', 'content');
|
|
4955
5218
|
}
|
|
4956
5219
|
|
|
@@ -4964,11 +5227,11 @@ class TinyHtml {
|
|
|
4964
5227
|
|
|
4965
5228
|
/**
|
|
4966
5229
|
* Returns padding box height.
|
|
4967
|
-
* @param {
|
|
5230
|
+
* @param {TinyElementAndWinAndDoc} el - Target element.
|
|
4968
5231
|
* @returns {number}
|
|
4969
5232
|
*/
|
|
4970
5233
|
static innerHeight(el) {
|
|
4971
|
-
const elem = TinyHtml.
|
|
5234
|
+
const elem = TinyHtml._preElemAndWinAndDoc(el, 'innerHeight');
|
|
4972
5235
|
return TinyHtml.getDimension(elem, 'height', 'padding');
|
|
4973
5236
|
}
|
|
4974
5237
|
|
|
@@ -4982,11 +5245,11 @@ class TinyHtml {
|
|
|
4982
5245
|
|
|
4983
5246
|
/**
|
|
4984
5247
|
* Returns padding box width.
|
|
4985
|
-
* @param {
|
|
5248
|
+
* @param {TinyElementAndWinAndDoc} el - Target element.
|
|
4986
5249
|
* @returns {number}
|
|
4987
5250
|
*/
|
|
4988
5251
|
static innerWidth(el) {
|
|
4989
|
-
const elem = TinyHtml.
|
|
5252
|
+
const elem = TinyHtml._preElemAndWinAndDoc(el, 'innerWidth');
|
|
4990
5253
|
return TinyHtml.getDimension(elem, 'width', 'padding');
|
|
4991
5254
|
}
|
|
4992
5255
|
|
|
@@ -5000,14 +5263,14 @@ class TinyHtml {
|
|
|
5000
5263
|
|
|
5001
5264
|
/**
|
|
5002
5265
|
* Returns outer height of the element, optionally including margin.
|
|
5003
|
-
* @param {
|
|
5266
|
+
* @param {TinyElementAndWinAndDoc} el - Target element.
|
|
5004
5267
|
* @param {boolean} [includeMargin=false] - Whether to include margin.
|
|
5005
5268
|
* @returns {number}
|
|
5006
5269
|
*/
|
|
5007
5270
|
static outerHeight(el, includeMargin = false) {
|
|
5008
5271
|
if (typeof includeMargin !== 'boolean')
|
|
5009
5272
|
throw new TypeError('The "includeMargin" must be a boolean.');
|
|
5010
|
-
const elem = TinyHtml.
|
|
5273
|
+
const elem = TinyHtml._preElemAndWinAndDoc(el, 'outerHeight');
|
|
5011
5274
|
return TinyHtml.getDimension(elem, 'height', includeMargin ? 'margin' : 'border');
|
|
5012
5275
|
}
|
|
5013
5276
|
|
|
@@ -5022,14 +5285,14 @@ class TinyHtml {
|
|
|
5022
5285
|
|
|
5023
5286
|
/**
|
|
5024
5287
|
* Returns outer width of the element, optionally including margin.
|
|
5025
|
-
* @param {
|
|
5288
|
+
* @param {TinyElementAndWinAndDoc} el - Target element.
|
|
5026
5289
|
* @param {boolean} [includeMargin=false] - Whether to include margin.
|
|
5027
5290
|
* @returns {number}
|
|
5028
5291
|
*/
|
|
5029
5292
|
static outerWidth(el, includeMargin = false) {
|
|
5030
5293
|
if (typeof includeMargin !== 'boolean')
|
|
5031
5294
|
throw new TypeError('The "includeMargin" must be a boolean.');
|
|
5032
|
-
const elem = TinyHtml.
|
|
5295
|
+
const elem = TinyHtml._preElemAndWinAndDoc(el, 'outerWidth');
|
|
5033
5296
|
return TinyHtml.getDimension(elem, 'width', includeMargin ? 'margin' : 'border');
|
|
5034
5297
|
}
|
|
5035
5298
|
|
|
@@ -5202,6 +5465,7 @@ class TinyHtml {
|
|
|
5202
5465
|
* Sets the vertical scroll position.
|
|
5203
5466
|
* @param {TinyElementAndWindow|TinyElementAndWindow[]} el - Element or window.
|
|
5204
5467
|
* @param {number} value - Scroll top value.
|
|
5468
|
+
* @returns {TinyElementAndWindow|TinyElementAndWindow[]}
|
|
5205
5469
|
*/
|
|
5206
5470
|
static setScrollTop(el, value) {
|
|
5207
5471
|
if (typeof value !== 'number') throw new TypeError('ScrollTop value must be a number.');
|
|
@@ -5215,11 +5479,13 @@ class TinyHtml {
|
|
|
5215
5479
|
elem.scrollTop = value;
|
|
5216
5480
|
}
|
|
5217
5481
|
});
|
|
5482
|
+
return el;
|
|
5218
5483
|
}
|
|
5219
5484
|
|
|
5220
5485
|
/**
|
|
5221
5486
|
* Sets the vertical scroll position.
|
|
5222
5487
|
* @param {number} value - Scroll top value.
|
|
5488
|
+
* @returns {TinyElementAndWindow|TinyElementAndWindow[]}
|
|
5223
5489
|
*/
|
|
5224
5490
|
setScrollTop(value) {
|
|
5225
5491
|
return TinyHtml.setScrollTop(this, value);
|
|
@@ -5229,6 +5495,7 @@ class TinyHtml {
|
|
|
5229
5495
|
* Sets the horizontal scroll position.
|
|
5230
5496
|
* @param {TinyElementAndWindow|TinyElementAndWindow[]} el - Element or window.
|
|
5231
5497
|
* @param {number} value - Scroll left value.
|
|
5498
|
+
* @returns {TinyElementAndWindow|TinyElementAndWindow[]}
|
|
5232
5499
|
*/
|
|
5233
5500
|
static setScrollLeft(el, value) {
|
|
5234
5501
|
if (typeof value !== 'number') throw new TypeError('ScrollLeft value must be a number.');
|
|
@@ -5242,11 +5509,13 @@ class TinyHtml {
|
|
|
5242
5509
|
elem.scrollLeft = value;
|
|
5243
5510
|
}
|
|
5244
5511
|
});
|
|
5512
|
+
return el;
|
|
5245
5513
|
}
|
|
5246
5514
|
|
|
5247
5515
|
/**
|
|
5248
5516
|
* Sets the horizontal scroll position.
|
|
5249
5517
|
* @param {number} value - Scroll left value.
|
|
5518
|
+
* @returns {TinyElementAndWindow|TinyElementAndWindow[]}
|
|
5250
5519
|
*/
|
|
5251
5520
|
setScrollLeft(value) {
|
|
5252
5521
|
return TinyHtml.setScrollLeft(this, value);
|
|
@@ -5377,15 +5646,16 @@ class TinyHtml {
|
|
|
5377
5646
|
|
|
5378
5647
|
/**
|
|
5379
5648
|
* Adds one or more CSS class names to the element.
|
|
5380
|
-
* @type {(el: TinyElement|TinyElement[], ...tokens: string[]) =>
|
|
5649
|
+
* @type {(el: TinyElement|TinyElement[], ...tokens: string[]) => (TinyElement|TinyElement[])} - One or more class names to add.
|
|
5381
5650
|
*/
|
|
5382
5651
|
static addClass(el, ...args) {
|
|
5383
5652
|
TinyHtml._preElems(el, 'addClass').forEach((elem) => elem.classList.add(...args));
|
|
5653
|
+
return el;
|
|
5384
5654
|
}
|
|
5385
5655
|
|
|
5386
5656
|
/**
|
|
5387
5657
|
* Adds one or more CSS class names to the element.
|
|
5388
|
-
* @type {(...tokens: string[]) =>
|
|
5658
|
+
* @type {(...tokens: string[]) => (TinyElement|TinyElement[])} - One or more class names to add.
|
|
5389
5659
|
*/
|
|
5390
5660
|
addClass(...args) {
|
|
5391
5661
|
return TinyHtml.addClass(this, ...args);
|
|
@@ -5393,15 +5663,16 @@ class TinyHtml {
|
|
|
5393
5663
|
|
|
5394
5664
|
/**
|
|
5395
5665
|
* Removes one or more CSS class names from the element.
|
|
5396
|
-
* @type {(el: TinyElement|TinyElement[], ...tokens: string[]) =>
|
|
5666
|
+
* @type {(el: TinyElement|TinyElement[], ...tokens: string[]) => (TinyElement|TinyElement[])} - One or more class names to remove.
|
|
5397
5667
|
*/
|
|
5398
5668
|
static removeClass(el, ...args) {
|
|
5399
5669
|
TinyHtml._preElems(el, 'removeClass').forEach((elem) => elem.classList.remove(...args));
|
|
5670
|
+
return el;
|
|
5400
5671
|
}
|
|
5401
5672
|
|
|
5402
5673
|
/**
|
|
5403
5674
|
* Removes one or more CSS class names from the element.
|
|
5404
|
-
* @type {(...tokens: string[]) =>
|
|
5675
|
+
* @type {(...tokens: string[]) => (TinyElement|TinyElement[])} - One or more class names to remove.
|
|
5405
5676
|
*/
|
|
5406
5677
|
removeClass(...args) {
|
|
5407
5678
|
return TinyHtml.removeClass(this, ...args);
|
|
@@ -5611,15 +5882,18 @@ class TinyHtml {
|
|
|
5611
5882
|
* Set text content of elements.
|
|
5612
5883
|
* @param {TinyElement|TinyElement[]} el
|
|
5613
5884
|
* @param {string} value
|
|
5885
|
+
* @returns {TinyElement|TinyElement[]}
|
|
5614
5886
|
*/
|
|
5615
5887
|
static setText(el, value) {
|
|
5616
5888
|
if (typeof value !== 'string') throw new Error('Value is not a valid string.');
|
|
5617
5889
|
TinyHtml._preElems(el, 'setText').forEach((el) => (el.textContent = value));
|
|
5890
|
+
return el;
|
|
5618
5891
|
}
|
|
5619
5892
|
|
|
5620
5893
|
/**
|
|
5621
5894
|
* Set text content of the element.
|
|
5622
5895
|
* @param {string} value
|
|
5896
|
+
* @returns {TinyElement|TinyElement[]}
|
|
5623
5897
|
*/
|
|
5624
5898
|
setText(value) {
|
|
5625
5899
|
return TinyHtml.setText(this, value);
|
|
@@ -5628,13 +5902,16 @@ class TinyHtml {
|
|
|
5628
5902
|
/**
|
|
5629
5903
|
* Remove all child nodes from each element.
|
|
5630
5904
|
* @param {TinyElement|TinyElement[]} el
|
|
5905
|
+
* @returns {TinyElement|TinyElement[]}
|
|
5631
5906
|
*/
|
|
5632
5907
|
static empty(el) {
|
|
5633
5908
|
TinyHtml._preElems(el, 'empty').forEach((el) => (el.textContent = ''));
|
|
5909
|
+
return el;
|
|
5634
5910
|
}
|
|
5635
5911
|
|
|
5636
5912
|
/**
|
|
5637
5913
|
* Remove all child nodes of the element.
|
|
5914
|
+
* @returns {TinyElement|TinyElement[]}
|
|
5638
5915
|
*/
|
|
5639
5916
|
empty() {
|
|
5640
5917
|
return TinyHtml.empty(this);
|
|
@@ -5642,35 +5919,40 @@ class TinyHtml {
|
|
|
5642
5919
|
|
|
5643
5920
|
/**
|
|
5644
5921
|
* Get the innerHTML of the element.
|
|
5645
|
-
* @param {TinyElement
|
|
5922
|
+
* @param {TinyElement} el
|
|
5923
|
+
* @param {GetHTMLOptions} [ops]
|
|
5646
5924
|
* @returns {string}
|
|
5647
5925
|
*/
|
|
5648
|
-
static html(el) {
|
|
5926
|
+
static html(el, ops) {
|
|
5649
5927
|
const elem = TinyHtml._preElem(el, 'html');
|
|
5650
|
-
return elem.
|
|
5928
|
+
return elem.getHTML(ops);
|
|
5651
5929
|
}
|
|
5652
5930
|
|
|
5653
5931
|
/**
|
|
5654
5932
|
* Get the innerHTML of the element.
|
|
5933
|
+
* @param {GetHTMLOptions} [ops]
|
|
5655
5934
|
* @returns {string}
|
|
5656
5935
|
*/
|
|
5657
|
-
html() {
|
|
5658
|
-
return TinyHtml.html(this);
|
|
5936
|
+
html(ops) {
|
|
5937
|
+
return TinyHtml.html(this, ops);
|
|
5659
5938
|
}
|
|
5660
5939
|
|
|
5661
5940
|
/**
|
|
5662
5941
|
* Set the innerHTML of each element.
|
|
5663
5942
|
* @param {TinyElement|TinyElement[]} el
|
|
5664
5943
|
* @param {string} value
|
|
5944
|
+
* @returns {TinyElement|TinyElement[]}
|
|
5665
5945
|
*/
|
|
5666
5946
|
static setHtml(el, value) {
|
|
5667
5947
|
if (typeof value !== 'string') throw new Error('Value is not a valid string.');
|
|
5668
5948
|
TinyHtml._preElems(el, 'setHtml').forEach((el) => (el.innerHTML = value));
|
|
5949
|
+
return el;
|
|
5669
5950
|
}
|
|
5670
5951
|
|
|
5671
5952
|
/**
|
|
5672
5953
|
* Set the innerHTML of the element.
|
|
5673
5954
|
* @param {string} value
|
|
5955
|
+
* @returns {TinyElement|TinyElement[]}
|
|
5674
5956
|
*/
|
|
5675
5957
|
setHtml(value) {
|
|
5676
5958
|
return TinyHtml.setHtml(this, value);
|
|
@@ -5804,6 +6086,7 @@ class TinyHtml {
|
|
|
5804
6086
|
* @param {TinyInputElement|TinyInputElement[]} el - Target element.
|
|
5805
6087
|
* @param {SetValueList|((el: InputElement, val: SetValueList) => SetValueList)} value - The value to assign or a function that returns it.
|
|
5806
6088
|
* @throws {Error} If the computed value is not a valid string or boolean.
|
|
6089
|
+
* @returns {TinyInputElement|TinyInputElement[]}
|
|
5807
6090
|
*/
|
|
5808
6091
|
static setVal(el, value) {
|
|
5809
6092
|
TinyHtml._preInputElems(el, 'setVal').forEach((elem) => {
|
|
@@ -5843,6 +6126,7 @@ class TinyHtml {
|
|
|
5843
6126
|
if (typeof valToSet === 'string') elem.value = valToSet;
|
|
5844
6127
|
}
|
|
5845
6128
|
});
|
|
6129
|
+
return el;
|
|
5846
6130
|
}
|
|
5847
6131
|
|
|
5848
6132
|
/**
|
|
@@ -5850,6 +6134,7 @@ class TinyHtml {
|
|
|
5850
6134
|
* Accepts strings, numbers, booleans or arrays of these values, or a callback function that computes them.
|
|
5851
6135
|
*
|
|
5852
6136
|
* @param {SetValueList|((el: InputElement, val: SetValueList) => SetValueList)} value - The value to assign or a function that returns it.
|
|
6137
|
+
* @returns {TinyInputElement|TinyInputElement[]}
|
|
5853
6138
|
* @throws {Error} If the computed value is not a valid string or boolean.
|
|
5854
6139
|
*/
|
|
5855
6140
|
setVal(value) {
|
|
@@ -6119,6 +6404,7 @@ class TinyHtml {
|
|
|
6119
6404
|
* @param {string} event - The event type (e.g. 'click', 'keydown').
|
|
6120
6405
|
* @param {EventRegistryHandle} handler - The callback function to run on event.
|
|
6121
6406
|
* @param {EventRegistryOptions} [options] - Optional event listener options.
|
|
6407
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
6122
6408
|
*/
|
|
6123
6409
|
static on(el, event, handler, options) {
|
|
6124
6410
|
if (typeof event !== 'string') throw new TypeError('The event name must be a string.');
|
|
@@ -6131,6 +6417,7 @@ class TinyHtml {
|
|
|
6131
6417
|
if (!Array.isArray(events[event])) events[event] = [];
|
|
6132
6418
|
events[event].push({ handler, options });
|
|
6133
6419
|
});
|
|
6420
|
+
return el;
|
|
6134
6421
|
}
|
|
6135
6422
|
|
|
6136
6423
|
/**
|
|
@@ -6139,6 +6426,7 @@ class TinyHtml {
|
|
|
6139
6426
|
* @param {string} event - The event type (e.g. 'click', 'keydown').
|
|
6140
6427
|
* @param {EventRegistryHandle} handler - The callback function to run on event.
|
|
6141
6428
|
* @param {EventRegistryOptions} [options] - Optional event listener options.
|
|
6429
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
6142
6430
|
*/
|
|
6143
6431
|
on(event, handler, options) {
|
|
6144
6432
|
return TinyHtml.on(this, event, handler, options);
|
|
@@ -6151,6 +6439,7 @@ class TinyHtml {
|
|
|
6151
6439
|
* @param {string} event - The event type (e.g. 'click', 'keydown').
|
|
6152
6440
|
* @param {EventRegistryHandle} handler - The callback function to run on event.
|
|
6153
6441
|
* @param {EventRegistryOptions} [options={}] - Optional event listener options.
|
|
6442
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
6154
6443
|
*/
|
|
6155
6444
|
static once(el, event, handler, options = {}) {
|
|
6156
6445
|
if (typeof event !== 'string') throw new TypeError('The event name must be a string.');
|
|
@@ -6168,6 +6457,7 @@ class TinyHtml {
|
|
|
6168
6457
|
typeof options === 'boolean' ? options : { ...options, once: true },
|
|
6169
6458
|
);
|
|
6170
6459
|
});
|
|
6460
|
+
return el;
|
|
6171
6461
|
}
|
|
6172
6462
|
|
|
6173
6463
|
/**
|
|
@@ -6176,6 +6466,7 @@ class TinyHtml {
|
|
|
6176
6466
|
* @param {string} event - The event type (e.g. 'click', 'keydown').
|
|
6177
6467
|
* @param {EventRegistryHandle} handler - The callback function to run on event.
|
|
6178
6468
|
* @param {EventRegistryOptions} [options={}] - Optional event listener options.
|
|
6469
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
6179
6470
|
*/
|
|
6180
6471
|
once(event, handler, options = {}) {
|
|
6181
6472
|
return TinyHtml.once(this, event, handler, options);
|
|
@@ -6188,6 +6479,7 @@ class TinyHtml {
|
|
|
6188
6479
|
* @param {string} event - The event type.
|
|
6189
6480
|
* @param {EventRegistryHandle} handler - The function originally bound to the event.
|
|
6190
6481
|
* @param {boolean|EventListenerOptions} [options] - Optional listener options.
|
|
6482
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
6191
6483
|
*/
|
|
6192
6484
|
static off(el, event, handler, options) {
|
|
6193
6485
|
if (typeof event !== 'string') throw new TypeError('The event name must be a string.');
|
|
@@ -6200,6 +6492,7 @@ class TinyHtml {
|
|
|
6200
6492
|
if (events[event].length === 0) delete events[event];
|
|
6201
6493
|
}
|
|
6202
6494
|
});
|
|
6495
|
+
return el;
|
|
6203
6496
|
}
|
|
6204
6497
|
|
|
6205
6498
|
/**
|
|
@@ -6208,6 +6501,7 @@ class TinyHtml {
|
|
|
6208
6501
|
* @param {string} event - The event type.
|
|
6209
6502
|
* @param {EventRegistryHandle} handler - The function originally bound to the event.
|
|
6210
6503
|
* @param {boolean|EventListenerOptions} [options] - Optional listener options.
|
|
6504
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
6211
6505
|
*/
|
|
6212
6506
|
off(event, handler, options) {
|
|
6213
6507
|
return TinyHtml.off(this, event, handler, options);
|
|
@@ -6218,6 +6512,7 @@ class TinyHtml {
|
|
|
6218
6512
|
*
|
|
6219
6513
|
* @param {TinyEventTarget|TinyEventTarget[]} el - The target element.
|
|
6220
6514
|
* @param {string} event - The event type to remove (e.g. 'click').
|
|
6515
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
6221
6516
|
*/
|
|
6222
6517
|
static offAll(el, event) {
|
|
6223
6518
|
if (typeof event !== 'string') throw new TypeError('The event name must be a string.');
|
|
@@ -6230,12 +6525,14 @@ class TinyHtml {
|
|
|
6230
6525
|
delete events[event];
|
|
6231
6526
|
}
|
|
6232
6527
|
});
|
|
6528
|
+
return el;
|
|
6233
6529
|
}
|
|
6234
6530
|
|
|
6235
6531
|
/**
|
|
6236
6532
|
* Removes all event listeners of a specific type from the element.
|
|
6237
6533
|
*
|
|
6238
6534
|
* @param {string} event - The event type to remove (e.g. 'click').
|
|
6535
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
6239
6536
|
*/
|
|
6240
6537
|
offAll(event) {
|
|
6241
6538
|
return TinyHtml.offAll(this, event);
|
|
@@ -6247,6 +6544,7 @@ class TinyHtml {
|
|
|
6247
6544
|
* @param {TinyEventTarget|TinyEventTarget[]} el - The target element.
|
|
6248
6545
|
* @param {((handler: EventListenerOrEventListenerObject, event: string) => boolean)|null} [filterFn=null] -
|
|
6249
6546
|
* Optional filter function to selectively remove specific handlers.
|
|
6547
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
6250
6548
|
*/
|
|
6251
6549
|
static offAllTypes(el, filterFn = null) {
|
|
6252
6550
|
if (filterFn !== null && typeof filterFn !== 'function')
|
|
@@ -6265,6 +6563,7 @@ class TinyHtml {
|
|
|
6265
6563
|
|
|
6266
6564
|
__eventRegistry.delete(elem);
|
|
6267
6565
|
});
|
|
6566
|
+
return el;
|
|
6268
6567
|
}
|
|
6269
6568
|
|
|
6270
6569
|
/**
|
|
@@ -6272,6 +6571,7 @@ class TinyHtml {
|
|
|
6272
6571
|
*
|
|
6273
6572
|
* @param {((handler: EventListenerOrEventListenerObject, event: string) => boolean)|null} [filterFn=null] -
|
|
6274
6573
|
* Optional filter function to selectively remove specific handlers.
|
|
6574
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
6275
6575
|
*/
|
|
6276
6576
|
offAllTypes(filterFn = null) {
|
|
6277
6577
|
return TinyHtml.offAllTypes(this, filterFn);
|
|
@@ -6283,6 +6583,7 @@ class TinyHtml {
|
|
|
6283
6583
|
* @param {TinyEventTarget|TinyEventTarget[]} el - Target element where the event should be triggered.
|
|
6284
6584
|
* @param {string} event - Name of the event to trigger.
|
|
6285
6585
|
* @param {Event|CustomEvent|CustomEventInit} [payload] - Optional event object or data to pass.
|
|
6586
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
6286
6587
|
*/
|
|
6287
6588
|
static trigger(el, event, payload = {}) {
|
|
6288
6589
|
if (typeof event !== 'string') throw new TypeError('The event name must be a string.');
|
|
@@ -6298,6 +6599,7 @@ class TinyHtml {
|
|
|
6298
6599
|
|
|
6299
6600
|
elem.dispatchEvent(evt);
|
|
6300
6601
|
});
|
|
6602
|
+
return el;
|
|
6301
6603
|
}
|
|
6302
6604
|
|
|
6303
6605
|
/**
|
|
@@ -6305,6 +6607,7 @@ class TinyHtml {
|
|
|
6305
6607
|
*
|
|
6306
6608
|
* @param {string} event - Name of the event to trigger.
|
|
6307
6609
|
* @param {Event|CustomEvent|CustomEventInit} [payload] - Optional event object or data to pass.
|
|
6610
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
6308
6611
|
*/
|
|
6309
6612
|
trigger(event, payload = {}) {
|
|
6310
6613
|
return TinyHtml.trigger(this, event, payload);
|
|
@@ -6347,6 +6650,7 @@ class TinyHtml {
|
|
|
6347
6650
|
* @param {TinyElement|TinyElement[]} el
|
|
6348
6651
|
* @param {string} name
|
|
6349
6652
|
* @param {string|null} [value=null]
|
|
6653
|
+
* @returns {TinyElement|TinyElement[]}
|
|
6350
6654
|
*/
|
|
6351
6655
|
static setAttr(el, name, value = null) {
|
|
6352
6656
|
if (typeof name !== 'string') throw new TypeError('The "name" must be a string.');
|
|
@@ -6356,12 +6660,14 @@ class TinyHtml {
|
|
|
6356
6660
|
if (value === null) elem.removeAttribute(name);
|
|
6357
6661
|
else elem.setAttribute(name, value);
|
|
6358
6662
|
});
|
|
6663
|
+
return el;
|
|
6359
6664
|
}
|
|
6360
6665
|
|
|
6361
6666
|
/**
|
|
6362
6667
|
* Set an attribute on an element.
|
|
6363
6668
|
* @param {string} name
|
|
6364
6669
|
* @param {string|null} [value=null]
|
|
6670
|
+
* @returns {TinyElement|TinyElement[]}
|
|
6365
6671
|
*/
|
|
6366
6672
|
setAttr(name, value) {
|
|
6367
6673
|
return TinyHtml.setAttr(this, name, value);
|
|
@@ -6371,15 +6677,18 @@ class TinyHtml {
|
|
|
6371
6677
|
* Remove attribute(s) from an element.
|
|
6372
6678
|
* @param {TinyElement|TinyElement[]} el
|
|
6373
6679
|
* @param {string} name Space-separated list of attributes.
|
|
6680
|
+
* @returns {TinyElement|TinyElement[]}
|
|
6374
6681
|
*/
|
|
6375
6682
|
static removeAttr(el, name) {
|
|
6376
6683
|
if (typeof name !== 'string') throw new TypeError('The "name" must be a string.');
|
|
6377
6684
|
TinyHtml._preElems(el, 'removeAttr').forEach((elem) => elem.removeAttribute(name));
|
|
6685
|
+
return el;
|
|
6378
6686
|
}
|
|
6379
6687
|
|
|
6380
6688
|
/**
|
|
6381
6689
|
* Remove attribute(s) from an element.
|
|
6382
6690
|
* @param {string} name Space-separated list of attributes.
|
|
6691
|
+
* @returns {TinyElement|TinyElement[]}
|
|
6383
6692
|
*/
|
|
6384
6693
|
removeAttr(name) {
|
|
6385
6694
|
return TinyHtml.removeAttr(this, name);
|
|
@@ -6434,6 +6743,7 @@ class TinyHtml {
|
|
|
6434
6743
|
* Set a property on an element.
|
|
6435
6744
|
* @param {TinyElement|TinyElement[]} el
|
|
6436
6745
|
* @param {string} name
|
|
6746
|
+
* @returns {TinyElement|TinyElement[]}
|
|
6437
6747
|
*/
|
|
6438
6748
|
static addProp(el, name) {
|
|
6439
6749
|
if (typeof name !== 'string') throw new TypeError('The "name" must be a string.');
|
|
@@ -6443,11 +6753,13 @@ class TinyHtml {
|
|
|
6443
6753
|
// @ts-ignore
|
|
6444
6754
|
elem[name] = true;
|
|
6445
6755
|
});
|
|
6756
|
+
return el;
|
|
6446
6757
|
}
|
|
6447
6758
|
|
|
6448
6759
|
/**
|
|
6449
6760
|
* Set a property on an element.
|
|
6450
6761
|
* @param {string} name
|
|
6762
|
+
* @returns {TinyElement|TinyElement[]}
|
|
6451
6763
|
*/
|
|
6452
6764
|
addProp(name) {
|
|
6453
6765
|
return TinyHtml.addProp(this, name);
|
|
@@ -6457,6 +6769,7 @@ class TinyHtml {
|
|
|
6457
6769
|
* Remove a property from an element.
|
|
6458
6770
|
* @param {TinyElement|TinyElement[]} el
|
|
6459
6771
|
* @param {string} name
|
|
6772
|
+
* @returns {TinyElement|TinyElement[]}
|
|
6460
6773
|
*/
|
|
6461
6774
|
static removeProp(el, name) {
|
|
6462
6775
|
if (typeof name !== 'string') throw new TypeError('The "name" must be a string.');
|
|
@@ -6466,11 +6779,13 @@ class TinyHtml {
|
|
|
6466
6779
|
// @ts-ignore
|
|
6467
6780
|
elem[name] = false;
|
|
6468
6781
|
});
|
|
6782
|
+
return el;
|
|
6469
6783
|
}
|
|
6470
6784
|
|
|
6471
6785
|
/**
|
|
6472
6786
|
* Remove a property from an element.
|
|
6473
6787
|
* @param {string} name
|
|
6788
|
+
* @returns {TinyElement|TinyElement[]}
|
|
6474
6789
|
*/
|
|
6475
6790
|
removeProp(name) {
|
|
6476
6791
|
return TinyHtml.removeProp(this, name);
|
|
@@ -6511,13 +6826,16 @@ class TinyHtml {
|
|
|
6511
6826
|
/**
|
|
6512
6827
|
* Removes an element from the DOM.
|
|
6513
6828
|
* @param {TinyElement|TinyElement[]} el - The DOM element or selector to remove.
|
|
6829
|
+
* @returns {TinyElement|TinyElement[]}
|
|
6514
6830
|
*/
|
|
6515
6831
|
static remove(el) {
|
|
6516
6832
|
TinyHtml._preElems(el, 'remove').forEach((elem) => elem.remove());
|
|
6833
|
+
return el;
|
|
6517
6834
|
}
|
|
6518
6835
|
|
|
6519
6836
|
/**
|
|
6520
6837
|
* Removes the element from the DOM.
|
|
6838
|
+
* @returns {TinyElement|TinyElement[]}
|
|
6521
6839
|
*/
|
|
6522
6840
|
remove() {
|
|
6523
6841
|
return TinyHtml.remove(this);
|
|
@@ -6861,6 +7179,14 @@ class TinyHtml {
|
|
|
6861
7179
|
*/
|
|
6862
7180
|
static isInViewport(el) {
|
|
6863
7181
|
const elem = TinyHtml._preElem(el, 'isInViewport');
|
|
7182
|
+
if (
|
|
7183
|
+
!elem.checkVisibility({
|
|
7184
|
+
contentVisibilityAuto: false,
|
|
7185
|
+
opacityProperty: false,
|
|
7186
|
+
visibilityProperty: false,
|
|
7187
|
+
})
|
|
7188
|
+
)
|
|
7189
|
+
return false;
|
|
6864
7190
|
const elementTop = TinyHtml.offset(elem).top;
|
|
6865
7191
|
const elementBottom = elementTop + TinyHtml.outerHeight(elem);
|
|
6866
7192
|
|
|
@@ -6887,6 +7213,14 @@ class TinyHtml {
|
|
|
6887
7213
|
*/
|
|
6888
7214
|
static isScrolledIntoView(el) {
|
|
6889
7215
|
const elem = TinyHtml._preElem(el, 'isScrolledIntoView');
|
|
7216
|
+
if (
|
|
7217
|
+
!elem.checkVisibility({
|
|
7218
|
+
contentVisibilityAuto: false,
|
|
7219
|
+
opacityProperty: false,
|
|
7220
|
+
visibilityProperty: false,
|
|
7221
|
+
})
|
|
7222
|
+
)
|
|
7223
|
+
return false;
|
|
6890
7224
|
const docViewTop = TinyHtml.scrollTop(window);
|
|
6891
7225
|
const docViewBottom = docViewTop + TinyHtml.height(window);
|
|
6892
7226
|
|
|
@@ -6904,6 +7238,111 @@ class TinyHtml {
|
|
|
6904
7238
|
isScrolledIntoView() {
|
|
6905
7239
|
return TinyHtml.isScrolledIntoView(this);
|
|
6906
7240
|
}
|
|
7241
|
+
|
|
7242
|
+
/**
|
|
7243
|
+
* Checks if the given element is at least partially visible within the boundaries of a container.
|
|
7244
|
+
*
|
|
7245
|
+
* @param {TinyElement} el - The DOM element to check.
|
|
7246
|
+
* @param {TinyElement} cont - The container element acting as the viewport.
|
|
7247
|
+
* @returns {boolean} True if the element is partially visible within the container, false otherwise.
|
|
7248
|
+
*/
|
|
7249
|
+
static isInContainer(el, cont) {
|
|
7250
|
+
const elem = TinyHtml._preElem(el, 'isInContainer');
|
|
7251
|
+
const container = TinyHtml._preElem(cont, 'isInContainer');
|
|
7252
|
+
|
|
7253
|
+
if (
|
|
7254
|
+
!elem.checkVisibility({
|
|
7255
|
+
contentVisibilityAuto: false,
|
|
7256
|
+
opacityProperty: false,
|
|
7257
|
+
visibilityProperty: false,
|
|
7258
|
+
})
|
|
7259
|
+
)
|
|
7260
|
+
return false;
|
|
7261
|
+
const elemRect = elem.getBoundingClientRect();
|
|
7262
|
+
const containerRect = container.getBoundingClientRect();
|
|
7263
|
+
|
|
7264
|
+
const verticallyVisible =
|
|
7265
|
+
elemRect.bottom > containerRect.top && elemRect.top < containerRect.bottom;
|
|
7266
|
+
|
|
7267
|
+
const horizontallyVisible =
|
|
7268
|
+
elemRect.right > containerRect.left && elemRect.left < containerRect.right;
|
|
7269
|
+
|
|
7270
|
+
return verticallyVisible && horizontallyVisible;
|
|
7271
|
+
}
|
|
7272
|
+
|
|
7273
|
+
/**
|
|
7274
|
+
* Checks if the given element is at least partially visible within the boundaries of a container.
|
|
7275
|
+
*
|
|
7276
|
+
* @param {TinyElement} cont - The container element acting as the viewport.
|
|
7277
|
+
* @returns {boolean} True if the element is partially visible within the container, false otherwise.
|
|
7278
|
+
*/
|
|
7279
|
+
isInContainer(cont) {
|
|
7280
|
+
return TinyHtml.isInContainer(this, cont);
|
|
7281
|
+
}
|
|
7282
|
+
|
|
7283
|
+
/**
|
|
7284
|
+
* Checks if the given element is fully visible within the boundaries of a container (top and bottom).
|
|
7285
|
+
*
|
|
7286
|
+
* @param {TinyElement} el - The DOM element to check.
|
|
7287
|
+
* @param {TinyElement} cont - The container element acting as the viewport.
|
|
7288
|
+
* @returns {boolean} True if the element is fully visible within the container, false otherwise.
|
|
7289
|
+
*/
|
|
7290
|
+
static isFullyInContainer(el, cont) {
|
|
7291
|
+
const elem = TinyHtml._preElem(el, 'isScrolledIntoView');
|
|
7292
|
+
const container = TinyHtml._preElem(cont, 'isInContainer');
|
|
7293
|
+
|
|
7294
|
+
if (
|
|
7295
|
+
!elem.checkVisibility({
|
|
7296
|
+
contentVisibilityAuto: false,
|
|
7297
|
+
opacityProperty: false,
|
|
7298
|
+
visibilityProperty: false,
|
|
7299
|
+
})
|
|
7300
|
+
)
|
|
7301
|
+
return false;
|
|
7302
|
+
const elemRect = elem.getBoundingClientRect();
|
|
7303
|
+
const containerRect = container.getBoundingClientRect();
|
|
7304
|
+
|
|
7305
|
+
const isFullyVisible =
|
|
7306
|
+
elemRect.top >= containerRect.top &&
|
|
7307
|
+
elemRect.bottom <= containerRect.bottom &&
|
|
7308
|
+
elemRect.left >= containerRect.left &&
|
|
7309
|
+
elemRect.right <= containerRect.right;
|
|
7310
|
+
|
|
7311
|
+
return isFullyVisible;
|
|
7312
|
+
}
|
|
7313
|
+
|
|
7314
|
+
/**
|
|
7315
|
+
* Checks if the given element is fully visible within the boundaries of a container (top and bottom).
|
|
7316
|
+
*
|
|
7317
|
+
* @param {TinyElement} cont - The container element acting as the viewport.
|
|
7318
|
+
* @returns {boolean} True if the element is fully visible within the container, false otherwise.
|
|
7319
|
+
*/
|
|
7320
|
+
isFullyInContainer(cont) {
|
|
7321
|
+
return TinyHtml.isFullyInContainer(this, cont);
|
|
7322
|
+
}
|
|
7323
|
+
|
|
7324
|
+
/**
|
|
7325
|
+
* Checks if an element has scrollable content.
|
|
7326
|
+
*
|
|
7327
|
+
* @param {TinyElement} el - The DOM element to check.
|
|
7328
|
+
* @returns {{ v: boolean, h: boolean }} - True if scroll is needed in that direction.
|
|
7329
|
+
*/
|
|
7330
|
+
static hasScroll(el) {
|
|
7331
|
+
const elem = TinyHtml._preElem(el, 'hasScroll');
|
|
7332
|
+
return {
|
|
7333
|
+
v: elem.scrollHeight > elem.clientHeight,
|
|
7334
|
+
h: elem.scrollWidth > elem.clientWidth,
|
|
7335
|
+
};
|
|
7336
|
+
}
|
|
7337
|
+
|
|
7338
|
+
/**
|
|
7339
|
+
* Checks if an element has scrollable content.
|
|
7340
|
+
*
|
|
7341
|
+
* @returns {{ v: boolean, h: boolean }} - True if scroll is needed in that direction.
|
|
7342
|
+
*/
|
|
7343
|
+
hasScroll() {
|
|
7344
|
+
return TinyHtml.hasScroll(this);
|
|
7345
|
+
}
|
|
6907
7346
|
}
|
|
6908
7347
|
|
|
6909
7348
|
/* harmony default export */ const libs_TinyHtml = (TinyHtml);
|