tiny-essentials 1.16.2 → 1.17.1
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/TinyBasicsEs.js +729 -93
- package/dist/v1/TinyBasicsEs.min.js +1 -1
- package/dist/v1/TinyDragger.js +656 -69
- package/dist/v1/TinyDragger.min.js +1 -1
- package/dist/v1/TinyEssentials.js +2688 -116
- package/dist/v1/TinyEssentials.min.js +1 -1
- package/dist/v1/TinyHtml.js +656 -69
- package/dist/v1/TinyHtml.min.js +1 -1
- package/dist/v1/TinySmartScroller.js +6378 -0
- package/dist/v1/TinySmartScroller.min.js +1 -0
- package/dist/v1/TinyUploadClicker.js +1732 -118
- 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/TinyHtml.cjs +656 -69
- package/dist/v1/libs/TinyHtml.d.mts +440 -139
- package/dist/v1/libs/TinyHtml.mjs +591 -72
- 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/TinyHtml.md +296 -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
|
@@ -2573,6 +2573,19 @@ const {
|
|
|
2573
2573
|
areElsCollRight: TinyHtml_areElsCollRight,
|
|
2574
2574
|
} = collision_namespaceObject;
|
|
2575
2575
|
|
|
2576
|
+
/**
|
|
2577
|
+
* Callback invoked on each animation frame with the current scroll position,
|
|
2578
|
+
* normalized animation time (`0` to `1`), and a completion flag.
|
|
2579
|
+
*
|
|
2580
|
+
* @typedef {(progress: { x: number, y: number, isComplete: boolean, time: number }) => void} OnScrollAnimation
|
|
2581
|
+
*/
|
|
2582
|
+
|
|
2583
|
+
/**
|
|
2584
|
+
* A list of supported easing function names for smooth animations.
|
|
2585
|
+
*
|
|
2586
|
+
* @typedef {'linear' | 'easeInQuad' | 'easeOutQuad' | 'easeInOutQuad' | 'easeInCubic' | 'easeOutCubic' | 'easeInOutCubic'} Easings
|
|
2587
|
+
*/
|
|
2588
|
+
|
|
2576
2589
|
/**
|
|
2577
2590
|
* Represents a raw Node element or an instance of TinyHtml.
|
|
2578
2591
|
* This type is used to abstract interactions with both plain elements
|
|
@@ -2628,6 +2641,21 @@ const {
|
|
|
2628
2641
|
* @typedef {Element|Window} ElementAndWindow
|
|
2629
2642
|
*/
|
|
2630
2643
|
|
|
2644
|
+
/**
|
|
2645
|
+
* Represents a raw DOM element/window/document or an instance of TinyHtml.
|
|
2646
|
+
* This type is used to abstract interactions with both plain elements
|
|
2647
|
+
* and wrapped elements via the TinyHtml class.
|
|
2648
|
+
*
|
|
2649
|
+
* @typedef {ElementAndWinAndDoc|TinyHtml} TinyElementAndWinAndDoc
|
|
2650
|
+
*/
|
|
2651
|
+
|
|
2652
|
+
/**
|
|
2653
|
+
* Represents a value that can be either a DOM Element, or the global Window object, or the document object.
|
|
2654
|
+
* Useful for functions that operate generically on scrollable or measurable targets.
|
|
2655
|
+
*
|
|
2656
|
+
* @typedef {Element|Window|Document} ElementAndWinAndDoc
|
|
2657
|
+
*/
|
|
2658
|
+
|
|
2631
2659
|
/**
|
|
2632
2660
|
* A parameter type used for filtering or matching elements.
|
|
2633
2661
|
* It can be:
|
|
@@ -2644,7 +2672,7 @@ const {
|
|
|
2644
2672
|
* Elements accepted as constructor values for TinyHtml.
|
|
2645
2673
|
* These include common DOM elements and root containers.
|
|
2646
2674
|
*
|
|
2647
|
-
* @typedef {Window|Element|Document} ConstructorElValues
|
|
2675
|
+
* @typedef {Window|Element|Document|Text} ConstructorElValues
|
|
2648
2676
|
*/
|
|
2649
2677
|
|
|
2650
2678
|
/**
|
|
@@ -2765,40 +2793,114 @@ class TinyHtml {
|
|
|
2765
2793
|
|
|
2766
2794
|
static Utils = { ...collision_namespaceObject };
|
|
2767
2795
|
|
|
2796
|
+
/**
|
|
2797
|
+
* Creates a new DOM element with the specified tag name and options, then wraps it in a TinyHtml instance.
|
|
2798
|
+
*
|
|
2799
|
+
* @param {string} tagName - The tag name of the element to create (e.g., 'div', 'span').
|
|
2800
|
+
* @param {ElementCreationOptions} ops - Optional settings for creating the element.
|
|
2801
|
+
* @returns {TinyHtml} A TinyHtml instance wrapping the newly created DOM element.
|
|
2802
|
+
* @throws {TypeError} If tagName is not a string or ops is not an object.
|
|
2803
|
+
*/
|
|
2804
|
+
static createElement(tagName, ops) {
|
|
2805
|
+
if (typeof tagName !== 'string')
|
|
2806
|
+
throw new TypeError(`[TinyHtml] createElement(): The tagName must be a string.`);
|
|
2807
|
+
if (typeof ops !== 'undefined' && typeof ops !== 'object')
|
|
2808
|
+
throw new TypeError(`[TinyHtml] createElement(): The ops must be a object.`);
|
|
2809
|
+
return new TinyHtml(document.createElement(tagName, ops));
|
|
2810
|
+
}
|
|
2811
|
+
|
|
2812
|
+
/**
|
|
2813
|
+
* Creates a new TinyHtml instance that wraps a DOM TextNode.
|
|
2814
|
+
*
|
|
2815
|
+
* This method is useful when you want to insert raw text content into the DOM
|
|
2816
|
+
* without it being interpreted as HTML. The returned instance behaves like any
|
|
2817
|
+
* other TinyHtml element and can be appended or manipulated as needed.
|
|
2818
|
+
*
|
|
2819
|
+
* @param {string} value - The plain text content to be wrapped in a TextNode.
|
|
2820
|
+
* @returns {TinyHtml} A TinyHtml instance wrapping the newly created DOM TextNode.
|
|
2821
|
+
* @throws {TypeError} If the provided value is not a string.
|
|
2822
|
+
*/
|
|
2823
|
+
static createTextNode(value) {
|
|
2824
|
+
if (typeof value !== 'string')
|
|
2825
|
+
throw new TypeError(`[TinyHtml] createTextNode(): The value must be a string.`);
|
|
2826
|
+
return new TinyHtml(document.createTextNode(value));
|
|
2827
|
+
}
|
|
2828
|
+
|
|
2829
|
+
/**
|
|
2830
|
+
* Creates an HTMLElement or TextNode from an HTML string.
|
|
2831
|
+
* Supports both elements and plain text.
|
|
2832
|
+
*
|
|
2833
|
+
* @param {string} htmlString - The HTML string to convert.
|
|
2834
|
+
* @returns {TinyHtml} - A single HTMLElement or TextNode.
|
|
2835
|
+
*/
|
|
2836
|
+
static createElementFromHTML(htmlString) {
|
|
2837
|
+
const template = document.createElement('template');
|
|
2838
|
+
htmlString = htmlString.trim();
|
|
2839
|
+
|
|
2840
|
+
// If it's only text (e.g., no "<" tag), return a TextNode
|
|
2841
|
+
if (!htmlString.startsWith('<')) {
|
|
2842
|
+
return TinyHtml.createTextNode(htmlString);
|
|
2843
|
+
}
|
|
2844
|
+
|
|
2845
|
+
template.innerHTML = htmlString;
|
|
2846
|
+
if (!(template.content.firstChild instanceof Element)) throw new Error('');
|
|
2847
|
+
return new TinyHtml(template.content.firstChild);
|
|
2848
|
+
}
|
|
2849
|
+
|
|
2768
2850
|
/**
|
|
2769
2851
|
* Queries the document for the first element matching the CSS selector and wraps it in a TinyHtml instance.
|
|
2770
2852
|
*
|
|
2771
2853
|
* @param {string} selector - A valid CSS selector string.
|
|
2772
|
-
* @
|
|
2773
|
-
* @
|
|
2854
|
+
* @param {Document|Element} elem - Target element.
|
|
2855
|
+
* @returns {TinyHtml|null} A TinyHtml instance wrapping the matched element.
|
|
2774
2856
|
*/
|
|
2775
|
-
static query(selector) {
|
|
2776
|
-
const newEl =
|
|
2777
|
-
if (!newEl)
|
|
2857
|
+
static query(selector, elem = document) {
|
|
2858
|
+
const newEl = elem.querySelector(selector);
|
|
2859
|
+
if (!newEl) return null;
|
|
2778
2860
|
return new TinyHtml(newEl);
|
|
2779
2861
|
}
|
|
2780
2862
|
|
|
2863
|
+
/**
|
|
2864
|
+
* Queries the element for the first element matching the CSS selector and wraps it in a TinyHtml instance.
|
|
2865
|
+
*
|
|
2866
|
+
* @param {string} selector - A valid CSS selector string.
|
|
2867
|
+
* @returns {TinyHtml|null} A TinyHtml instance wrapping the matched element.
|
|
2868
|
+
*/
|
|
2869
|
+
querySelector(selector) {
|
|
2870
|
+
return TinyHtml.query(selector, TinyHtml._preElem(this, 'query'));
|
|
2871
|
+
}
|
|
2872
|
+
|
|
2781
2873
|
/**
|
|
2782
2874
|
* Queries the document for all elements matching the CSS selector and wraps them in TinyHtml instances.
|
|
2783
2875
|
*
|
|
2784
2876
|
* @param {string} selector - A valid CSS selector string.
|
|
2877
|
+
* @param {Document|Element} elem - Target element.
|
|
2785
2878
|
* @returns {TinyHtml[]} An array of TinyHtml instances wrapping the matched elements.
|
|
2786
2879
|
*/
|
|
2787
|
-
static queryAll(selector) {
|
|
2788
|
-
const newEls =
|
|
2880
|
+
static queryAll(selector, elem = document) {
|
|
2881
|
+
const newEls = elem.querySelectorAll(selector);
|
|
2789
2882
|
return TinyHtml.toTinyElm([...newEls]);
|
|
2790
2883
|
}
|
|
2791
2884
|
|
|
2885
|
+
/**
|
|
2886
|
+
* Queries the element for all elements matching the CSS selector and wraps them in TinyHtml instances.
|
|
2887
|
+
*
|
|
2888
|
+
* @param {string} selector - A valid CSS selector string.
|
|
2889
|
+
* @returns {TinyHtml[]} An array of TinyHtml instances wrapping the matched elements.
|
|
2890
|
+
*/
|
|
2891
|
+
querySelectorAll(selector) {
|
|
2892
|
+
return TinyHtml.queryAll(selector, TinyHtml._preElem(this, 'queryAll'));
|
|
2893
|
+
}
|
|
2894
|
+
|
|
2792
2895
|
/**
|
|
2793
2896
|
* Retrieves an element by its ID and wraps it in a TinyHtml instance.
|
|
2794
2897
|
*
|
|
2795
2898
|
* @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.
|
|
2899
|
+
* @returns {TinyHtml|null} A TinyHtml instance wrapping the found element.
|
|
2798
2900
|
*/
|
|
2799
2901
|
static getById(selector) {
|
|
2800
2902
|
const newEl = document.getElementById(selector);
|
|
2801
|
-
if (!newEl)
|
|
2903
|
+
if (!newEl) return null;
|
|
2802
2904
|
return new TinyHtml(newEl);
|
|
2803
2905
|
}
|
|
2804
2906
|
|
|
@@ -2806,13 +2908,24 @@ class TinyHtml {
|
|
|
2806
2908
|
* Retrieves all elements with the specified class name and wraps them in TinyHtml instances.
|
|
2807
2909
|
*
|
|
2808
2910
|
* @param {string} selector - The class name to search for.
|
|
2911
|
+
* @param {Document|Element} elem - Target element.
|
|
2809
2912
|
* @returns {TinyHtml[]} An array of TinyHtml instances wrapping the found elements.
|
|
2810
2913
|
*/
|
|
2811
|
-
static getByClassName(selector) {
|
|
2812
|
-
const newEls =
|
|
2914
|
+
static getByClassName(selector, elem = document) {
|
|
2915
|
+
const newEls = elem.getElementsByClassName(selector);
|
|
2813
2916
|
return TinyHtml.toTinyElm([...newEls]);
|
|
2814
2917
|
}
|
|
2815
2918
|
|
|
2919
|
+
/**
|
|
2920
|
+
* Retrieves all elements with the specified class name and wraps them in TinyHtml instances.
|
|
2921
|
+
*
|
|
2922
|
+
* @param {string} selector - The class name to search for.
|
|
2923
|
+
* @returns {TinyHtml[]} An array of TinyHtml instances wrapping the found elements.
|
|
2924
|
+
*/
|
|
2925
|
+
getElementsByClassName(selector) {
|
|
2926
|
+
return TinyHtml.getByClassName(selector, TinyHtml._preElem(this, 'getByClassName'));
|
|
2927
|
+
}
|
|
2928
|
+
|
|
2816
2929
|
/**
|
|
2817
2930
|
* Retrieves all elements with the specified name attribute and wraps them in TinyHtml instances.
|
|
2818
2931
|
*
|
|
@@ -2830,13 +2943,30 @@ class TinyHtml {
|
|
|
2830
2943
|
*
|
|
2831
2944
|
* @param {string} localName - The local name (tag) of the elements to search for.
|
|
2832
2945
|
* @param {string|null} [namespaceURI='http://www.w3.org/1999/xhtml'] - The namespace URI to search within.
|
|
2946
|
+
* @param {Document|Element} elem - Target element.
|
|
2833
2947
|
* @returns {TinyHtml[]} An array of TinyHtml instances wrapping the found elements.
|
|
2834
2948
|
*/
|
|
2835
|
-
static getByTagNameNS(localName, namespaceURI = 'http://www.w3.org/1999/xhtml') {
|
|
2836
|
-
const newEls =
|
|
2949
|
+
static getByTagNameNS(localName, namespaceURI = 'http://www.w3.org/1999/xhtml', elem = document) {
|
|
2950
|
+
const newEls = elem.getElementsByTagNameNS(namespaceURI, localName);
|
|
2837
2951
|
return TinyHtml.toTinyElm([...newEls]);
|
|
2838
2952
|
}
|
|
2839
2953
|
|
|
2954
|
+
/**
|
|
2955
|
+
* Retrieves all elements with the specified local tag name within the given namespace URI,
|
|
2956
|
+
* and wraps them in TinyHtml instances.
|
|
2957
|
+
*
|
|
2958
|
+
* @param {string} localName - The local name (tag) of the elements to search for.
|
|
2959
|
+
* @param {string|null} [namespaceURI='http://www.w3.org/1999/xhtml'] - The namespace URI to search within.
|
|
2960
|
+
* @returns {TinyHtml[]} An array of TinyHtml instances wrapping the found elements.
|
|
2961
|
+
*/
|
|
2962
|
+
getElementsByTagNameNS(localName, namespaceURI = 'http://www.w3.org/1999/xhtml') {
|
|
2963
|
+
return TinyHtml.getByTagNameNS(
|
|
2964
|
+
localName,
|
|
2965
|
+
namespaceURI,
|
|
2966
|
+
TinyHtml._preElem(this, 'getByTagNameNS'),
|
|
2967
|
+
);
|
|
2968
|
+
}
|
|
2969
|
+
|
|
2840
2970
|
//////////////////////////////////////////////////////////////////
|
|
2841
2971
|
|
|
2842
2972
|
/**
|
|
@@ -3117,6 +3247,45 @@ class TinyHtml {
|
|
|
3117
3247
|
return TinyHtml._preElemTemplate(elems, where, [Element, Window], ['Element', 'Window']);
|
|
3118
3248
|
}
|
|
3119
3249
|
|
|
3250
|
+
/**
|
|
3251
|
+
* Ensures the input is returned as an array.
|
|
3252
|
+
* Useful to normalize operations across multiple or single element/window/document elements.
|
|
3253
|
+
*
|
|
3254
|
+
* @param {TinyElementAndWinAndDoc|TinyElementAndWinAndDoc[]} elems - A single element/window element or array of html elements.
|
|
3255
|
+
* @param {string} where - The method or context name where validation is being called.
|
|
3256
|
+
* @returns {ElementAndWindow[]} - Always returns an array of element/window elements.
|
|
3257
|
+
* @readonly
|
|
3258
|
+
*/
|
|
3259
|
+
static _preElemsAndWinAndDoc(elems, where) {
|
|
3260
|
+
const result = TinyHtml._preElemsTemplate(
|
|
3261
|
+
elems,
|
|
3262
|
+
where,
|
|
3263
|
+
[Element, Window, Document],
|
|
3264
|
+
['Element', 'Window', 'Document'],
|
|
3265
|
+
);
|
|
3266
|
+
return result.map((elem) => (!(elem instanceof Document) ? elem : elem.documentElement));
|
|
3267
|
+
}
|
|
3268
|
+
|
|
3269
|
+
/**
|
|
3270
|
+
* Ensures the input is returned as an single element/window/document element.
|
|
3271
|
+
* Useful to normalize operations across multiple or single element/window/document elements.
|
|
3272
|
+
*
|
|
3273
|
+
* @param {TinyElementAndWinAndDoc|TinyElementAndWinAndDoc[]} elems - A single element/window element or array of html elements.
|
|
3274
|
+
* @param {string} where - The method or context name where validation is being called.
|
|
3275
|
+
* @returns {ElementAndWindow} - Always returns an single element/window element.
|
|
3276
|
+
* @readonly
|
|
3277
|
+
*/
|
|
3278
|
+
static _preElemAndWinAndDoc(elems, where) {
|
|
3279
|
+
const result = TinyHtml._preElemTemplate(
|
|
3280
|
+
elems,
|
|
3281
|
+
where,
|
|
3282
|
+
[Element, Window, Document],
|
|
3283
|
+
['Element', 'Window', 'Document'],
|
|
3284
|
+
);
|
|
3285
|
+
if (result instanceof Document) return result.documentElement;
|
|
3286
|
+
return result;
|
|
3287
|
+
}
|
|
3288
|
+
|
|
3120
3289
|
/**
|
|
3121
3290
|
* Normalizes and converts one or more DOM elements (or TinyHtml instances)
|
|
3122
3291
|
* into an array of `TinyHtml` instances.
|
|
@@ -3463,12 +3632,13 @@ class TinyHtml {
|
|
|
3463
3632
|
* @param {string} key - The key under which the data will be stored.
|
|
3464
3633
|
* @param {any} value - The value to store.
|
|
3465
3634
|
* @param {boolean} [isPrivate=false] - Whether to store the data in the private store.
|
|
3466
|
-
* @returns {
|
|
3635
|
+
* @returns {TinyElement}
|
|
3467
3636
|
*/
|
|
3468
3637
|
static setData(el, key, value, isPrivate = false) {
|
|
3469
3638
|
const data = TinyHtml._dataSelector[!isPrivate ? 'public' : 'private']('setData', el);
|
|
3470
3639
|
if (typeof key !== 'string') throw new TypeError('The key must be a string.');
|
|
3471
3640
|
data[key] = value;
|
|
3641
|
+
return el;
|
|
3472
3642
|
}
|
|
3473
3643
|
|
|
3474
3644
|
/**
|
|
@@ -3477,7 +3647,7 @@ class TinyHtml {
|
|
|
3477
3647
|
* @param {string} key - The key under which the data will be stored.
|
|
3478
3648
|
* @param {any} value - The value to store.
|
|
3479
3649
|
* @param {boolean} [isPrivate=false] - Whether to store the data in the private store.
|
|
3480
|
-
* @returns {
|
|
3650
|
+
* @returns {TinyElement}
|
|
3481
3651
|
*/
|
|
3482
3652
|
setData(key, value, isPrivate = false) {
|
|
3483
3653
|
return TinyHtml.setData(this, key, value, isPrivate);
|
|
@@ -3824,18 +3994,21 @@ class TinyHtml {
|
|
|
3824
3994
|
/**
|
|
3825
3995
|
* Appends child elements or strings to the end of the target element(s).
|
|
3826
3996
|
*
|
|
3827
|
-
* @param {TinyElement
|
|
3997
|
+
* @param {TinyElement} el - The target element(s) to receive children.
|
|
3828
3998
|
* @param {...(TinyNode | TinyNode[] | string)} children - The child elements or text to append.
|
|
3999
|
+
* @returns {TinyElement}
|
|
3829
4000
|
*/
|
|
3830
4001
|
static append(el, ...children) {
|
|
3831
4002
|
const elem = TinyHtml._preElem(el, 'append');
|
|
3832
4003
|
elem.append(...TinyHtml._appendChecker('append', ...children));
|
|
4004
|
+
return el;
|
|
3833
4005
|
}
|
|
3834
4006
|
|
|
3835
4007
|
/**
|
|
3836
4008
|
* Appends child elements or strings to the end of the target element(s).
|
|
3837
4009
|
*
|
|
3838
4010
|
* @param {...(TinyNode | TinyNode[] | string)} children - The child elements or text to append.
|
|
4011
|
+
* @returns {TinyElement}
|
|
3839
4012
|
*/
|
|
3840
4013
|
append(...children) {
|
|
3841
4014
|
return TinyHtml.append(this, ...children);
|
|
@@ -3844,18 +4017,21 @@ class TinyHtml {
|
|
|
3844
4017
|
/**
|
|
3845
4018
|
* Prepends child elements or strings to the beginning of the target element(s).
|
|
3846
4019
|
*
|
|
3847
|
-
* @param {TinyElement
|
|
4020
|
+
* @param {TinyElement} el - The target element(s) to receive children.
|
|
3848
4021
|
* @param {...(TinyNode | TinyNode[] | string)} children - The child elements or text to prepend.
|
|
4022
|
+
* @returns {TinyElement}
|
|
3849
4023
|
*/
|
|
3850
4024
|
static prepend(el, ...children) {
|
|
3851
4025
|
const elem = TinyHtml._preElem(el, 'prepend');
|
|
3852
4026
|
elem.prepend(...TinyHtml._appendChecker('prepend', ...children));
|
|
4027
|
+
return el;
|
|
3853
4028
|
}
|
|
3854
4029
|
|
|
3855
4030
|
/**
|
|
3856
4031
|
* Prepends child elements or strings to the beginning of the target element(s).
|
|
3857
4032
|
*
|
|
3858
4033
|
* @param {...(TinyNode | TinyNode[] | string)} children - The child elements or text to prepend.
|
|
4034
|
+
* @returns {TinyElement}
|
|
3859
4035
|
*/
|
|
3860
4036
|
prepend(...children) {
|
|
3861
4037
|
return TinyHtml.prepend(this, ...children);
|
|
@@ -3864,18 +4040,21 @@ class TinyHtml {
|
|
|
3864
4040
|
/**
|
|
3865
4041
|
* Inserts elements or strings immediately before the target element(s) in the DOM.
|
|
3866
4042
|
*
|
|
3867
|
-
* @param {TinyElement
|
|
4043
|
+
* @param {TinyElement} el - The target element(s) before which new content is inserted.
|
|
3868
4044
|
* @param {...(TinyNode | TinyNode[] | string)} children - Elements or text to insert before the target.
|
|
4045
|
+
* @returns {TinyElement}
|
|
3869
4046
|
*/
|
|
3870
4047
|
static before(el, ...children) {
|
|
3871
4048
|
const elem = TinyHtml._preElem(el, 'before');
|
|
3872
4049
|
elem.before(...TinyHtml._appendChecker('before', ...children));
|
|
4050
|
+
return el;
|
|
3873
4051
|
}
|
|
3874
4052
|
|
|
3875
4053
|
/**
|
|
3876
4054
|
* Inserts elements or strings immediately before the target element(s) in the DOM.
|
|
3877
4055
|
*
|
|
3878
4056
|
* @param {...(TinyNode | TinyNode[] | string)} children - Elements or text to insert before the target.
|
|
4057
|
+
* @returns {TinyElement}
|
|
3879
4058
|
*/
|
|
3880
4059
|
before(...children) {
|
|
3881
4060
|
return TinyHtml.before(this, ...children);
|
|
@@ -3884,18 +4063,21 @@ class TinyHtml {
|
|
|
3884
4063
|
/**
|
|
3885
4064
|
* Inserts elements or strings immediately after the target element(s) in the DOM.
|
|
3886
4065
|
*
|
|
3887
|
-
* @param {TinyElement
|
|
4066
|
+
* @param {TinyElement} el - The target element(s) after which new content is inserted.
|
|
3888
4067
|
* @param {...(TinyNode | TinyNode[] | string)} children - Elements or text to insert after the target.
|
|
4068
|
+
* @returns {TinyElement}
|
|
3889
4069
|
*/
|
|
3890
4070
|
static after(el, ...children) {
|
|
3891
4071
|
const elem = TinyHtml._preElem(el, 'after');
|
|
3892
4072
|
elem.after(...TinyHtml._appendChecker('after', ...children));
|
|
4073
|
+
return el;
|
|
3893
4074
|
}
|
|
3894
4075
|
|
|
3895
4076
|
/**
|
|
3896
4077
|
* Inserts elements or strings immediately after the target element(s) in the DOM.
|
|
3897
4078
|
*
|
|
3898
4079
|
* @param {...(TinyNode | TinyNode[] | string)} children - Elements or text to insert after the target.
|
|
4080
|
+
* @returns {TinyElement}
|
|
3899
4081
|
*/
|
|
3900
4082
|
after(...children) {
|
|
3901
4083
|
return TinyHtml.after(this, ...children);
|
|
@@ -3904,18 +4086,21 @@ class TinyHtml {
|
|
|
3904
4086
|
/**
|
|
3905
4087
|
* Replaces the target element(s) in the DOM with new elements or text.
|
|
3906
4088
|
*
|
|
3907
|
-
* @param {TinyElement
|
|
4089
|
+
* @param {TinyElement} el - The element(s) to be replaced.
|
|
3908
4090
|
* @param {...(TinyNode | TinyNode[] | string)} newNodes - New elements or text to replace the target.
|
|
4091
|
+
* @returns {TinyElement}
|
|
3909
4092
|
*/
|
|
3910
4093
|
static replaceWith(el, ...newNodes) {
|
|
3911
4094
|
const elem = TinyHtml._preElem(el, 'replaceWith');
|
|
3912
4095
|
elem.replaceWith(...TinyHtml._appendChecker('replaceWith', ...newNodes));
|
|
4096
|
+
return el;
|
|
3913
4097
|
}
|
|
3914
4098
|
|
|
3915
4099
|
/**
|
|
3916
4100
|
* Replaces the target element(s) in the DOM with new elements or text.
|
|
3917
4101
|
*
|
|
3918
4102
|
* @param {...(TinyNode | TinyNode[] | string)} newNodes - New elements or text to replace the target.
|
|
4103
|
+
* @returns {TinyElement}
|
|
3919
4104
|
*/
|
|
3920
4105
|
replaceWith(...newNodes) {
|
|
3921
4106
|
return TinyHtml.replaceWith(this, ...newNodes);
|
|
@@ -3926,6 +4111,7 @@ class TinyHtml {
|
|
|
3926
4111
|
*
|
|
3927
4112
|
* @param {TinyNode | TinyNode[]} el - The element(s) to append.
|
|
3928
4113
|
* @param {TinyNode | TinyNode[]} targets - Target element(s) where content will be appended.
|
|
4114
|
+
* @returns {TinyNode|TinyNode[]}
|
|
3929
4115
|
*/
|
|
3930
4116
|
static appendTo(el, targets) {
|
|
3931
4117
|
const elems = TinyHtml._preNodeElems(el, 'appendTo');
|
|
@@ -3935,12 +4121,14 @@ class TinyHtml {
|
|
|
3935
4121
|
target.appendChild(i === tars.length - 1 ? elem : elem.cloneNode(true)),
|
|
3936
4122
|
);
|
|
3937
4123
|
});
|
|
4124
|
+
return el;
|
|
3938
4125
|
}
|
|
3939
4126
|
|
|
3940
4127
|
/**
|
|
3941
4128
|
* Appends the given element(s) to each target element in sequence.
|
|
3942
4129
|
*
|
|
3943
4130
|
* @param {TinyNode | TinyNode[]} targets - Target element(s) where content will be appended.
|
|
4131
|
+
* @returns {TinyNode|TinyNode[]}
|
|
3944
4132
|
*/
|
|
3945
4133
|
appendTo(targets) {
|
|
3946
4134
|
return TinyHtml.appendTo(this, targets);
|
|
@@ -3951,6 +4139,7 @@ class TinyHtml {
|
|
|
3951
4139
|
*
|
|
3952
4140
|
* @param {TinyElement | TinyElement[]} el - The element(s) to prepend.
|
|
3953
4141
|
* @param {TinyElement | TinyElement[]} targets - Target element(s) where content will be prepended.
|
|
4142
|
+
* @returns {TinyElement|TinyElement[]}
|
|
3954
4143
|
*/
|
|
3955
4144
|
static prependTo(el, targets) {
|
|
3956
4145
|
const elems = TinyHtml._preElems(el, 'prependTo');
|
|
@@ -3961,12 +4150,14 @@ class TinyHtml {
|
|
|
3961
4150
|
.reverse()
|
|
3962
4151
|
.forEach((elem) => target.prepend(i === tars.length - 1 ? elem : elem.cloneNode(true)));
|
|
3963
4152
|
});
|
|
4153
|
+
return el;
|
|
3964
4154
|
}
|
|
3965
4155
|
|
|
3966
4156
|
/**
|
|
3967
4157
|
* Prepends the given element(s) to each target element in sequence.
|
|
3968
4158
|
*
|
|
3969
4159
|
* @param {TinyElement | TinyElement[]} targets - Target element(s) where content will be prepended.
|
|
4160
|
+
* @returns {TinyElement|TinyElement[]}
|
|
3970
4161
|
*/
|
|
3971
4162
|
prependTo(targets) {
|
|
3972
4163
|
return TinyHtml.prependTo(this, targets);
|
|
@@ -3978,6 +4169,7 @@ class TinyHtml {
|
|
|
3978
4169
|
* @param {TinyNode | TinyNode[]} el - The element(s) to insert.
|
|
3979
4170
|
* @param {TinyNode | TinyNode[]} target - The reference element where insertion happens.
|
|
3980
4171
|
* @param {TinyNode | TinyNode[] | null} [child=null] - Optional child to insert before, defaults to target.
|
|
4172
|
+
* @returns {TinyNode|TinyNode[]}
|
|
3981
4173
|
*/
|
|
3982
4174
|
static insertBefore(el, target, child = null) {
|
|
3983
4175
|
const elem = TinyHtml._preNodeElem(el, 'insertBefore');
|
|
@@ -3985,6 +4177,7 @@ class TinyHtml {
|
|
|
3985
4177
|
const childNode = TinyHtml._preNodeElemWithNull(child, 'insertBefore');
|
|
3986
4178
|
if (!targ.parentNode) throw new Error('');
|
|
3987
4179
|
targ.parentNode.insertBefore(elem, childNode || targ);
|
|
4180
|
+
return el;
|
|
3988
4181
|
}
|
|
3989
4182
|
|
|
3990
4183
|
/**
|
|
@@ -3992,6 +4185,7 @@ class TinyHtml {
|
|
|
3992
4185
|
*
|
|
3993
4186
|
* @param {TinyNode | TinyNode[]} target - The reference element where insertion happens.
|
|
3994
4187
|
* @param {TinyNode | TinyNode[] | null} [child=null] - Optional child to insert before, defaults to target.
|
|
4188
|
+
* @returns {TinyNode|TinyNode[]}
|
|
3995
4189
|
*/
|
|
3996
4190
|
insertBefore(target, child) {
|
|
3997
4191
|
return TinyHtml.insertBefore(this, target, child);
|
|
@@ -4003,6 +4197,7 @@ class TinyHtml {
|
|
|
4003
4197
|
* @param {TinyNode | TinyNode[]} el - The element(s) to insert.
|
|
4004
4198
|
* @param {TinyNode | TinyNode[]} target - The reference element where insertion happens.
|
|
4005
4199
|
* @param {TinyNode | TinyNode[] | null} [child=null] - Optional child to insert after, defaults to target.
|
|
4200
|
+
* @returns {TinyNode|TinyNode[]}
|
|
4006
4201
|
*/
|
|
4007
4202
|
static insertAfter(el, target, child = null) {
|
|
4008
4203
|
const elem = TinyHtml._preNodeElem(el, 'insertAfter');
|
|
@@ -4010,6 +4205,7 @@ class TinyHtml {
|
|
|
4010
4205
|
const childNode = TinyHtml._preNodeElemWithNull(child, 'insertBefore');
|
|
4011
4206
|
if (!targ.parentNode) throw new Error('');
|
|
4012
4207
|
targ.parentNode.insertBefore(elem, childNode || targ.nextSibling);
|
|
4208
|
+
return el;
|
|
4013
4209
|
}
|
|
4014
4210
|
|
|
4015
4211
|
/**
|
|
@@ -4017,6 +4213,7 @@ class TinyHtml {
|
|
|
4017
4213
|
*
|
|
4018
4214
|
* @param {TinyNode | TinyNode[]} target - The reference element where insertion happens.
|
|
4019
4215
|
* @param {TinyNode | TinyNode[] | null} [child=null] - Optional child to insert after, defaults to target.
|
|
4216
|
+
* @returns {TinyNode|TinyNode[]}
|
|
4020
4217
|
*/
|
|
4021
4218
|
insertAfter(target, child) {
|
|
4022
4219
|
return TinyHtml.insertAfter(this, target, child);
|
|
@@ -4028,6 +4225,7 @@ class TinyHtml {
|
|
|
4028
4225
|
*
|
|
4029
4226
|
* @param {TinyNode | TinyNode[]} el - The new element(s) to insert.
|
|
4030
4227
|
* @param {TinyNode | TinyNode[]} targets - The elements to be replaced.
|
|
4228
|
+
* @returns {TinyNode|TinyNode[]}
|
|
4031
4229
|
*/
|
|
4032
4230
|
static replaceAll(el, targets) {
|
|
4033
4231
|
const elems = TinyHtml._preNodeElems(el, 'replaceAll');
|
|
@@ -4039,6 +4237,7 @@ class TinyHtml {
|
|
|
4039
4237
|
parent.replaceChild(i === tars.length - 1 ? elem : elem.cloneNode(true), target);
|
|
4040
4238
|
});
|
|
4041
4239
|
});
|
|
4240
|
+
return el;
|
|
4042
4241
|
}
|
|
4043
4242
|
|
|
4044
4243
|
/**
|
|
@@ -4046,6 +4245,7 @@ class TinyHtml {
|
|
|
4046
4245
|
* If multiple targets exist, the inserted elements are cloned accordingly.
|
|
4047
4246
|
*
|
|
4048
4247
|
* @param {TinyNode | TinyNode[]} targets - The elements to be replaced.
|
|
4248
|
+
* @returns {TinyNode|TinyNode[]}
|
|
4049
4249
|
*/
|
|
4050
4250
|
replaceAll(targets) {
|
|
4051
4251
|
return TinyHtml.replaceAll(this, targets);
|
|
@@ -4069,7 +4269,12 @@ class TinyHtml {
|
|
|
4069
4269
|
throw new Error(
|
|
4070
4270
|
`[TinyHtml] You are trying to put a TinyHtml inside another TinyHtml in constructor.`,
|
|
4071
4271
|
);
|
|
4072
|
-
if (
|
|
4272
|
+
if (
|
|
4273
|
+
!(el instanceof Element) &&
|
|
4274
|
+
!(el instanceof Window) &&
|
|
4275
|
+
!(el instanceof Document) &&
|
|
4276
|
+
!(el instanceof Text)
|
|
4277
|
+
)
|
|
4073
4278
|
throw new Error(`[TinyHtml] Invalid Target in constructor.`);
|
|
4074
4279
|
this.#el = el;
|
|
4075
4280
|
}
|
|
@@ -4519,6 +4724,7 @@ class TinyHtml {
|
|
|
4519
4724
|
* @param {TinyHtmlElement|TinyHtmlElement[]} el - The element to inspect.
|
|
4520
4725
|
* @param {string|Object} prop - The property name or an object with key-value pairs
|
|
4521
4726
|
* @param {string|null} [value=null] - The value to set (if `prop` is a string)
|
|
4727
|
+
* @returns {TinyHtmlElement|TinyHtmlElement[]}
|
|
4522
4728
|
*/
|
|
4523
4729
|
static setStyle(el, prop, value = null) {
|
|
4524
4730
|
TinyHtml._preHtmlElems(el, 'setStyle').forEach((elem) => {
|
|
@@ -4531,6 +4737,7 @@ class TinyHtml {
|
|
|
4531
4737
|
}
|
|
4532
4738
|
} else elem.style.setProperty(TinyHtml.toStyleKc(prop), value);
|
|
4533
4739
|
});
|
|
4740
|
+
return el;
|
|
4534
4741
|
}
|
|
4535
4742
|
|
|
4536
4743
|
/**
|
|
@@ -4541,6 +4748,7 @@ class TinyHtml {
|
|
|
4541
4748
|
*
|
|
4542
4749
|
* @param {string|Object} prop - The property name or an object with key-value pairs
|
|
4543
4750
|
* @param {string|null} [value=null] - The value to set (if `prop` is a string)
|
|
4751
|
+
* @returns {TinyHtmlElement|TinyHtmlElement[]}
|
|
4544
4752
|
*/
|
|
4545
4753
|
setStyle(prop, value) {
|
|
4546
4754
|
return TinyHtml.setStyle(this, prop, value);
|
|
@@ -4636,6 +4844,7 @@ class TinyHtml {
|
|
|
4636
4844
|
*
|
|
4637
4845
|
* @param {TinyHtmlElement|TinyHtmlElement[]} el - A single element or an array of elements.
|
|
4638
4846
|
* @param {string|string[]} prop - A property name or an array of property names to remove.
|
|
4847
|
+
* @returns {TinyHtmlElement|TinyHtmlElement[]}
|
|
4639
4848
|
*/
|
|
4640
4849
|
static removeStyle(el, prop) {
|
|
4641
4850
|
TinyHtml._preHtmlElems(el, 'removeStyle').forEach((elem) => {
|
|
@@ -4645,12 +4854,14 @@ class TinyHtml {
|
|
|
4645
4854
|
}
|
|
4646
4855
|
} else elem.style.removeProperty(TinyHtml.toStyleKc(prop));
|
|
4647
4856
|
});
|
|
4857
|
+
return el;
|
|
4648
4858
|
}
|
|
4649
4859
|
|
|
4650
4860
|
/**
|
|
4651
4861
|
* Removes one or more inline CSS properties from the given element(s).
|
|
4652
4862
|
*
|
|
4653
4863
|
* @param {string|string[]} prop - A property name or an array of property names to remove.
|
|
4864
|
+
* @returns {TinyHtmlElement|TinyHtmlElement[]}
|
|
4654
4865
|
*/
|
|
4655
4866
|
removeStyle(prop) {
|
|
4656
4867
|
return TinyHtml.removeStyle(this, prop);
|
|
@@ -4665,6 +4876,7 @@ class TinyHtml {
|
|
|
4665
4876
|
* @param {string} prop - The CSS property to toggle.
|
|
4666
4877
|
* @param {string} val1 - The first value (used as "current" check).
|
|
4667
4878
|
* @param {string} val2 - The second value (used as the "alternative").
|
|
4879
|
+
* @returns {TinyHtmlElement|TinyHtmlElement[]}
|
|
4668
4880
|
*/
|
|
4669
4881
|
static toggleStyle(el, prop, val1, val2) {
|
|
4670
4882
|
TinyHtml._preHtmlElems(el, 'toggleStyle').forEach((elem) => {
|
|
@@ -4672,6 +4884,7 @@ class TinyHtml {
|
|
|
4672
4884
|
const newVal = current === TinyHtml.toStyleKc(val1) ? val2 : val1;
|
|
4673
4885
|
TinyHtml.setStyle(elem, prop, newVal);
|
|
4674
4886
|
});
|
|
4887
|
+
return el;
|
|
4675
4888
|
}
|
|
4676
4889
|
|
|
4677
4890
|
/**
|
|
@@ -4682,6 +4895,7 @@ class TinyHtml {
|
|
|
4682
4895
|
* @param {string} prop - The CSS property to toggle.
|
|
4683
4896
|
* @param {string} val1 - The first value (used as "current" check).
|
|
4684
4897
|
* @param {string} val2 - The second value (used as the "alternative").
|
|
4898
|
+
* @returns {TinyHtmlElement|TinyHtmlElement[]}
|
|
4685
4899
|
*/
|
|
4686
4900
|
toggleStyle(prop, val1, val2) {
|
|
4687
4901
|
return TinyHtml.toggleStyle(this, prop, val1, val2);
|
|
@@ -4691,14 +4905,16 @@ class TinyHtml {
|
|
|
4691
4905
|
* Removes all inline styles (`style` attribute) from the given element(s).
|
|
4692
4906
|
*
|
|
4693
4907
|
* @param {TinyElement|TinyElement[]} el - A single element or an array of elements.
|
|
4908
|
+
* @returns {TinyElement|TinyElement[]}
|
|
4694
4909
|
*/
|
|
4695
4910
|
static clearStyle(el) {
|
|
4696
4911
|
TinyHtml._preElems(el, 'clearStyle').forEach((elem) => elem.removeAttribute('style'));
|
|
4912
|
+
return el;
|
|
4697
4913
|
}
|
|
4698
4914
|
|
|
4699
4915
|
/**
|
|
4700
4916
|
* Removes all inline styles (`style` attribute) from the given element(s).
|
|
4701
|
-
*
|
|
4917
|
+
* @returns {TinyElement|TinyElement[]}
|
|
4702
4918
|
*/
|
|
4703
4919
|
clearStyle() {
|
|
4704
4920
|
return TinyHtml.clearStyle(this);
|
|
@@ -4710,14 +4926,17 @@ class TinyHtml {
|
|
|
4710
4926
|
* Focus the element.
|
|
4711
4927
|
*
|
|
4712
4928
|
* @param {TinyHtmlElement} el - The element or a selector string.
|
|
4929
|
+
* @returns {TinyHtmlElement}
|
|
4713
4930
|
*/
|
|
4714
4931
|
static focus(el) {
|
|
4715
4932
|
const elem = TinyHtml._preHtmlElem(el, 'focus');
|
|
4716
4933
|
elem.focus();
|
|
4934
|
+
return el;
|
|
4717
4935
|
}
|
|
4718
4936
|
|
|
4719
4937
|
/**
|
|
4720
4938
|
* Focus the element.
|
|
4939
|
+
* @returns {TinyHtmlElement}
|
|
4721
4940
|
*/
|
|
4722
4941
|
focus() {
|
|
4723
4942
|
return TinyHtml.focus(this);
|
|
@@ -4727,19 +4946,46 @@ class TinyHtml {
|
|
|
4727
4946
|
* Blur the element.
|
|
4728
4947
|
*
|
|
4729
4948
|
* @param {TinyHtmlElement} el - The element or a selector string.
|
|
4949
|
+
* @returns {TinyHtmlElement}
|
|
4730
4950
|
*/
|
|
4731
4951
|
static blur(el) {
|
|
4732
4952
|
const elem = TinyHtml._preHtmlElem(el, 'blur');
|
|
4733
4953
|
elem.blur();
|
|
4954
|
+
return el;
|
|
4734
4955
|
}
|
|
4735
4956
|
|
|
4736
4957
|
/**
|
|
4737
4958
|
* Blur the element.
|
|
4959
|
+
* @returns {TinyHtmlElement}
|
|
4738
4960
|
*/
|
|
4739
4961
|
blur() {
|
|
4740
4962
|
return TinyHtml.blur(this);
|
|
4741
4963
|
}
|
|
4742
4964
|
|
|
4965
|
+
/**
|
|
4966
|
+
* Interprets a value as a boolean `true` if it matches a common truthy representation.
|
|
4967
|
+
*
|
|
4968
|
+
* This method checks if the input is any of the common forms used to represent `true`,
|
|
4969
|
+
* such as the string `'true'`, `'1'`, `'on'`, the boolean `true`, or the number `1`.
|
|
4970
|
+
*
|
|
4971
|
+
* @param {string|boolean|number} [value] - The value to interpret as boolean.
|
|
4972
|
+
* @returns {boolean} `true` if the value represents a truthy state, otherwise `false`.
|
|
4973
|
+
*/
|
|
4974
|
+
static boolCheck(value) {
|
|
4975
|
+
if (
|
|
4976
|
+
typeof value !== 'undefined' &&
|
|
4977
|
+
(value === 'true' ||
|
|
4978
|
+
value === '1' ||
|
|
4979
|
+
value === true ||
|
|
4980
|
+
value === 'on' ||
|
|
4981
|
+
(typeof value === 'number' && value > 0))
|
|
4982
|
+
) {
|
|
4983
|
+
return true;
|
|
4984
|
+
} else {
|
|
4985
|
+
return false;
|
|
4986
|
+
}
|
|
4987
|
+
}
|
|
4988
|
+
|
|
4743
4989
|
//////////////////////////////////////////////////////////////////////
|
|
4744
4990
|
|
|
4745
4991
|
/**
|
|
@@ -4748,7 +4994,7 @@ class TinyHtml {
|
|
|
4748
4994
|
*/
|
|
4749
4995
|
static setWinScrollTop(value) {
|
|
4750
4996
|
if (typeof value !== 'number') throw new TypeError('The value must be a number.');
|
|
4751
|
-
|
|
4997
|
+
TinyHtml.setScrollTop(window, value);
|
|
4752
4998
|
}
|
|
4753
4999
|
|
|
4754
5000
|
/**
|
|
@@ -4757,7 +5003,7 @@ class TinyHtml {
|
|
|
4757
5003
|
*/
|
|
4758
5004
|
static setWinScrollLeft(value) {
|
|
4759
5005
|
if (typeof value !== 'number') throw new TypeError('The value must be a number.');
|
|
4760
|
-
|
|
5006
|
+
TinyHtml.setScrollLeft(window, value);
|
|
4761
5007
|
}
|
|
4762
5008
|
|
|
4763
5009
|
/**
|
|
@@ -4792,16 +5038,40 @@ class TinyHtml {
|
|
|
4792
5038
|
return window.innerWidth || document.documentElement.clientWidth;
|
|
4793
5039
|
}
|
|
4794
5040
|
|
|
5041
|
+
/**
|
|
5042
|
+
* Checks if the page is currently scrolled to the very top.
|
|
5043
|
+
*
|
|
5044
|
+
* This method compares the current vertical scroll position with the total document height.
|
|
5045
|
+
* It's useful for detecting if the user has reached the top of the page.
|
|
5046
|
+
*
|
|
5047
|
+
* @returns {boolean} `true` if the page is scrolled to the top, otherwise `false`.
|
|
5048
|
+
*/
|
|
5049
|
+
static isPageTop() {
|
|
5050
|
+
return window.scrollY === 0;
|
|
5051
|
+
}
|
|
5052
|
+
|
|
5053
|
+
/**
|
|
5054
|
+
* Checks if the page is currently scrolled to the very bottom.
|
|
5055
|
+
*
|
|
5056
|
+
* This method uses the `scrollY` and `innerHeight` properties to determine if the
|
|
5057
|
+
* user has reached the end of the document.
|
|
5058
|
+
*
|
|
5059
|
+
* @returns {boolean} `true` if the page is scrolled to the bottom, otherwise `false`.
|
|
5060
|
+
*/
|
|
5061
|
+
static isPageBottom() {
|
|
5062
|
+
return window.innerHeight + window.scrollY >= document.body.offsetHeight;
|
|
5063
|
+
}
|
|
5064
|
+
|
|
4795
5065
|
/**
|
|
4796
5066
|
* Gets the width or height of an element based on the box model.
|
|
4797
|
-
* @param {
|
|
5067
|
+
* @param {TinyElementAndWinAndDoc} el - The element or window.
|
|
4798
5068
|
* @param {"width"|"height"} type - Dimension type.
|
|
4799
5069
|
* @param {"content"|"padding"|"border"|"margin"} [extra='content'] - Box model context.
|
|
4800
5070
|
* @returns {number} - Computed dimension.
|
|
4801
5071
|
* @throws {TypeError} If `type` or `extra` is not a string.
|
|
4802
5072
|
*/
|
|
4803
5073
|
static getDimension(el, type, extra = 'content') {
|
|
4804
|
-
const elem = TinyHtml.
|
|
5074
|
+
const elem = TinyHtml._preElemAndWinAndDoc(el, 'getDimension');
|
|
4805
5075
|
if (typeof type !== 'string') throw new TypeError('The type must be a string.');
|
|
4806
5076
|
if (typeof extra !== 'string') throw new TypeError('The extra must be a string.');
|
|
4807
5077
|
|
|
@@ -4889,17 +5159,20 @@ class TinyHtml {
|
|
|
4889
5159
|
* @param {TinyHtmlElement} el - Target element.
|
|
4890
5160
|
* @param {string|number} value - Height value.
|
|
4891
5161
|
* @throws {TypeError} If `value` is neither a string nor number.
|
|
5162
|
+
* @returns {TinyHtmlElement}
|
|
4892
5163
|
*/
|
|
4893
5164
|
static setHeight(el, value) {
|
|
4894
5165
|
const elem = TinyHtml._preHtmlElem(el, 'setHeight');
|
|
4895
5166
|
if (typeof value !== 'number' && typeof value !== 'string')
|
|
4896
5167
|
throw new TypeError('The value must be a string or number.');
|
|
4897
5168
|
elem.style.height = typeof value === 'number' ? `${value}px` : value;
|
|
5169
|
+
return el;
|
|
4898
5170
|
}
|
|
4899
5171
|
|
|
4900
5172
|
/**
|
|
4901
5173
|
* Sets the height of the element.
|
|
4902
5174
|
* @param {string|number} value - Height value.
|
|
5175
|
+
* @returns {TinyHtmlElement}
|
|
4903
5176
|
*/
|
|
4904
5177
|
setHeight(value) {
|
|
4905
5178
|
return TinyHtml.setHeight(this, value);
|
|
@@ -4910,17 +5183,20 @@ class TinyHtml {
|
|
|
4910
5183
|
* @param {TinyHtmlElement} el - Target element.
|
|
4911
5184
|
* @param {string|number} value - Width value.
|
|
4912
5185
|
* @throws {TypeError} If `value` is neither a string nor number.
|
|
5186
|
+
* @returns {TinyHtmlElement}
|
|
4913
5187
|
*/
|
|
4914
5188
|
static setWidth(el, value) {
|
|
4915
5189
|
const elem = TinyHtml._preHtmlElem(el, 'setWidth');
|
|
4916
5190
|
if (typeof value !== 'number' && typeof value !== 'string')
|
|
4917
5191
|
throw new TypeError('The value must be a string or number.');
|
|
4918
5192
|
elem.style.width = typeof value === 'number' ? `${value}px` : value;
|
|
5193
|
+
return el;
|
|
4919
5194
|
}
|
|
4920
5195
|
|
|
4921
5196
|
/**
|
|
4922
5197
|
* Sets the width of the element.
|
|
4923
5198
|
* @param {string|number} value - Width value.
|
|
5199
|
+
* @returns {TinyHtmlElement}
|
|
4924
5200
|
*/
|
|
4925
5201
|
setWidth(value) {
|
|
4926
5202
|
return TinyHtml.setWidth(this, value);
|
|
@@ -4928,11 +5204,11 @@ class TinyHtml {
|
|
|
4928
5204
|
|
|
4929
5205
|
/**
|
|
4930
5206
|
* Returns content box height.
|
|
4931
|
-
* @param {
|
|
5207
|
+
* @param {TinyElementAndWinAndDoc} el - Target element.
|
|
4932
5208
|
* @returns {number}
|
|
4933
5209
|
*/
|
|
4934
5210
|
static height(el) {
|
|
4935
|
-
const elem = TinyHtml.
|
|
5211
|
+
const elem = TinyHtml._preElemAndWinAndDoc(el, 'height');
|
|
4936
5212
|
return TinyHtml.getDimension(elem, 'height', 'content');
|
|
4937
5213
|
}
|
|
4938
5214
|
|
|
@@ -4946,11 +5222,11 @@ class TinyHtml {
|
|
|
4946
5222
|
|
|
4947
5223
|
/**
|
|
4948
5224
|
* Returns content box width.
|
|
4949
|
-
* @param {
|
|
5225
|
+
* @param {TinyElementAndWinAndDoc} el - Target element.
|
|
4950
5226
|
* @returns {number}
|
|
4951
5227
|
*/
|
|
4952
5228
|
static width(el) {
|
|
4953
|
-
const elem = TinyHtml.
|
|
5229
|
+
const elem = TinyHtml._preElemAndWinAndDoc(el, 'width');
|
|
4954
5230
|
return TinyHtml.getDimension(elem, 'width', 'content');
|
|
4955
5231
|
}
|
|
4956
5232
|
|
|
@@ -4964,11 +5240,11 @@ class TinyHtml {
|
|
|
4964
5240
|
|
|
4965
5241
|
/**
|
|
4966
5242
|
* Returns padding box height.
|
|
4967
|
-
* @param {
|
|
5243
|
+
* @param {TinyElementAndWinAndDoc} el - Target element.
|
|
4968
5244
|
* @returns {number}
|
|
4969
5245
|
*/
|
|
4970
5246
|
static innerHeight(el) {
|
|
4971
|
-
const elem = TinyHtml.
|
|
5247
|
+
const elem = TinyHtml._preElemAndWinAndDoc(el, 'innerHeight');
|
|
4972
5248
|
return TinyHtml.getDimension(elem, 'height', 'padding');
|
|
4973
5249
|
}
|
|
4974
5250
|
|
|
@@ -4982,11 +5258,11 @@ class TinyHtml {
|
|
|
4982
5258
|
|
|
4983
5259
|
/**
|
|
4984
5260
|
* Returns padding box width.
|
|
4985
|
-
* @param {
|
|
5261
|
+
* @param {TinyElementAndWinAndDoc} el - Target element.
|
|
4986
5262
|
* @returns {number}
|
|
4987
5263
|
*/
|
|
4988
5264
|
static innerWidth(el) {
|
|
4989
|
-
const elem = TinyHtml.
|
|
5265
|
+
const elem = TinyHtml._preElemAndWinAndDoc(el, 'innerWidth');
|
|
4990
5266
|
return TinyHtml.getDimension(elem, 'width', 'padding');
|
|
4991
5267
|
}
|
|
4992
5268
|
|
|
@@ -5000,14 +5276,14 @@ class TinyHtml {
|
|
|
5000
5276
|
|
|
5001
5277
|
/**
|
|
5002
5278
|
* Returns outer height of the element, optionally including margin.
|
|
5003
|
-
* @param {
|
|
5279
|
+
* @param {TinyElementAndWinAndDoc} el - Target element.
|
|
5004
5280
|
* @param {boolean} [includeMargin=false] - Whether to include margin.
|
|
5005
5281
|
* @returns {number}
|
|
5006
5282
|
*/
|
|
5007
5283
|
static outerHeight(el, includeMargin = false) {
|
|
5008
5284
|
if (typeof includeMargin !== 'boolean')
|
|
5009
5285
|
throw new TypeError('The "includeMargin" must be a boolean.');
|
|
5010
|
-
const elem = TinyHtml.
|
|
5286
|
+
const elem = TinyHtml._preElemAndWinAndDoc(el, 'outerHeight');
|
|
5011
5287
|
return TinyHtml.getDimension(elem, 'height', includeMargin ? 'margin' : 'border');
|
|
5012
5288
|
}
|
|
5013
5289
|
|
|
@@ -5022,14 +5298,14 @@ class TinyHtml {
|
|
|
5022
5298
|
|
|
5023
5299
|
/**
|
|
5024
5300
|
* Returns outer width of the element, optionally including margin.
|
|
5025
|
-
* @param {
|
|
5301
|
+
* @param {TinyElementAndWinAndDoc} el - Target element.
|
|
5026
5302
|
* @param {boolean} [includeMargin=false] - Whether to include margin.
|
|
5027
5303
|
* @returns {number}
|
|
5028
5304
|
*/
|
|
5029
5305
|
static outerWidth(el, includeMargin = false) {
|
|
5030
5306
|
if (typeof includeMargin !== 'boolean')
|
|
5031
5307
|
throw new TypeError('The "includeMargin" must be a boolean.');
|
|
5032
|
-
const elem = TinyHtml.
|
|
5308
|
+
const elem = TinyHtml._preElemAndWinAndDoc(el, 'outerWidth');
|
|
5033
5309
|
return TinyHtml.getDimension(elem, 'width', includeMargin ? 'margin' : 'border');
|
|
5034
5310
|
}
|
|
5035
5311
|
|
|
@@ -5044,6 +5320,30 @@ class TinyHtml {
|
|
|
5044
5320
|
|
|
5045
5321
|
//////////////////////////////////////////////////
|
|
5046
5322
|
|
|
5323
|
+
/**
|
|
5324
|
+
* Applies an animation to one or multiple TinyElement instances.
|
|
5325
|
+
*
|
|
5326
|
+
* @param {TinyElement|TinyElement[]} el - A single TinyElement or an array of TinyElements to animate.
|
|
5327
|
+
* @param {Keyframe[] | PropertyIndexedKeyframes | null} keyframes - The keyframes used to define the animation.
|
|
5328
|
+
* @param {number | KeyframeAnimationOptions} [ops] - Timing or configuration options for the animation.
|
|
5329
|
+
* @returns {TinyElement|TinyElement[]}
|
|
5330
|
+
*/
|
|
5331
|
+
static animate(el, keyframes, ops) {
|
|
5332
|
+
TinyHtml._preElems(el, 'animate').forEach((elem) => elem.animate(keyframes, ops));
|
|
5333
|
+
return el;
|
|
5334
|
+
}
|
|
5335
|
+
|
|
5336
|
+
/**
|
|
5337
|
+
* Applies an animation to one or multiple TinyElement instances.
|
|
5338
|
+
*
|
|
5339
|
+
* @param {Keyframe[] | PropertyIndexedKeyframes | null} keyframes - The keyframes used to define the animation.
|
|
5340
|
+
* @param {number | KeyframeAnimationOptions} [ops] - Timing or configuration options for the animation.
|
|
5341
|
+
* @returns {TinyElement|TinyElement[]}
|
|
5342
|
+
*/
|
|
5343
|
+
animate(keyframes, ops) {
|
|
5344
|
+
return TinyHtml.animate(this, keyframes, ops);
|
|
5345
|
+
}
|
|
5346
|
+
|
|
5047
5347
|
/**
|
|
5048
5348
|
* Gets the offset of the element relative to the document.
|
|
5049
5349
|
* @param {TinyElement} el - Target element.
|
|
@@ -5199,27 +5499,151 @@ class TinyHtml {
|
|
|
5199
5499
|
}
|
|
5200
5500
|
|
|
5201
5501
|
/**
|
|
5202
|
-
*
|
|
5203
|
-
*
|
|
5204
|
-
*
|
|
5502
|
+
* Collection of easing functions used for scroll and animation calculations.
|
|
5503
|
+
* Each function receives a normalized time value (`t` from 0 to 1) and returns the eased progress.
|
|
5504
|
+
*
|
|
5505
|
+
* @type {Record<string, (t: number) => number>}
|
|
5205
5506
|
*/
|
|
5206
|
-
static
|
|
5207
|
-
|
|
5208
|
-
|
|
5209
|
-
|
|
5210
|
-
|
|
5507
|
+
static easings = {
|
|
5508
|
+
linear: (t) => t,
|
|
5509
|
+
easeInQuad: (t) => t * t,
|
|
5510
|
+
easeOutQuad: (t) => t * (2 - t),
|
|
5511
|
+
easeInOutQuad: (t) => (t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t),
|
|
5512
|
+
easeInCubic: (t) => t * t * t,
|
|
5513
|
+
easeOutCubic: (t) => --t * t * t + 1,
|
|
5514
|
+
easeInOutCubic: (t) => (t < 0.5 ? 4 * t * t * t : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1),
|
|
5515
|
+
};
|
|
5516
|
+
|
|
5517
|
+
/**
|
|
5518
|
+
* Smoothly scrolls one or more elements (or the window) to the specified X and Y coordinates
|
|
5519
|
+
* using a custom duration and easing function.
|
|
5520
|
+
*
|
|
5521
|
+
* If `duration` or a valid `easing` is not provided, the scroll will be performed immediately.
|
|
5522
|
+
*
|
|
5523
|
+
* @param {TinyElementAndWindow | TinyElementAndWindow[]} el - A single element, array of elements, or the window to scroll.
|
|
5524
|
+
* @param {Object} [settings={}] - Configuration object for the scroll animation.
|
|
5525
|
+
* @param {number} [settings.targetX] - The horizontal scroll target in pixels.
|
|
5526
|
+
* @param {number} [settings.targetY] - The vertical scroll target in pixels.
|
|
5527
|
+
* @param {number} [settings.duration] - The duration of the animation in milliseconds.
|
|
5528
|
+
* @param {Easings} [settings.easing] - The easing function name to use for the scroll animation.
|
|
5529
|
+
* @param {OnScrollAnimation} [settings.onAnimation] - Optional callback invoked on each animation
|
|
5530
|
+
* frame with the current scroll position, normalized animation time (`0` to `1`), and a completion flag.
|
|
5531
|
+
* @returns {TinyElementAndWindow|TinyElementAndWindow[]}
|
|
5532
|
+
* @throws {TypeError} If `el` is not a valid element, array, or window.
|
|
5533
|
+
* @throws {TypeError} If `targetX` or `targetY` is defined but not a number.
|
|
5534
|
+
* @throws {TypeError} If `duration` is defined but not a number.
|
|
5535
|
+
* @throws {TypeError} If `easing` is defined but not a valid easing function name.
|
|
5536
|
+
* @throws {TypeError} If `onAnimation` is defined but not a function.
|
|
5537
|
+
*/
|
|
5538
|
+
static scrollToXY(el, { targetX, targetY, duration, easing, onAnimation } = {}) {
|
|
5539
|
+
if (targetX !== undefined && typeof targetX !== 'number')
|
|
5540
|
+
throw new TypeError('`targetX` must be a number if provided.');
|
|
5541
|
+
if (targetY !== undefined && typeof targetY !== 'number')
|
|
5542
|
+
throw new TypeError('`targetY` must be a number if provided.');
|
|
5543
|
+
if (duration !== undefined && typeof duration !== 'number')
|
|
5544
|
+
throw new TypeError('`duration` must be a number if provided.');
|
|
5545
|
+
if (easing !== undefined && typeof easing !== 'string')
|
|
5546
|
+
throw new TypeError('`easing` must be a string if provided.');
|
|
5547
|
+
if (easing !== undefined && typeof TinyHtml.easings[easing] !== 'function')
|
|
5548
|
+
throw new TypeError(`Unknown easing function: "${easing}".`);
|
|
5549
|
+
if (onAnimation !== undefined && typeof onAnimation !== 'function')
|
|
5550
|
+
throw new TypeError('`onAnimation` must be a function if provided.');
|
|
5551
|
+
|
|
5552
|
+
/**
|
|
5553
|
+
* Performs an instant scroll to the given coordinates.
|
|
5554
|
+
*
|
|
5555
|
+
* @param {ElementAndWindow} elem - The element or window to scroll.
|
|
5556
|
+
* @param {number} newX - The final horizontal scroll position.
|
|
5557
|
+
* @param {number} newY - The final vertical scroll position.
|
|
5558
|
+
* @param {number} time - Normalized progress value.
|
|
5559
|
+
*/
|
|
5560
|
+
const executeScroll = (elem, newX, newY, time) => {
|
|
5561
|
+
if (elem instanceof Window) {
|
|
5562
|
+
window.scrollTo(newX, newY);
|
|
5211
5563
|
} else if (elem.nodeType === 9) {
|
|
5212
5564
|
// @ts-ignore
|
|
5213
|
-
elem.defaultView.scrollTo(
|
|
5565
|
+
elem.defaultView.scrollTo(newX, newY);
|
|
5214
5566
|
} else {
|
|
5215
|
-
elem.
|
|
5567
|
+
const startX = elem instanceof Window ? window.scrollX : elem.scrollLeft;
|
|
5568
|
+
const startY = elem instanceof Window ? window.scrollY : elem.scrollTop;
|
|
5569
|
+
if (startX !== newX) elem.scrollLeft = newX;
|
|
5570
|
+
if (startY !== newY) elem.scrollTop = newY;
|
|
5216
5571
|
}
|
|
5572
|
+
if (typeof onAnimation === 'function')
|
|
5573
|
+
onAnimation({ x: newX, y: newY, isComplete: time >= 1, time });
|
|
5574
|
+
};
|
|
5575
|
+
|
|
5576
|
+
TinyHtml._preElemsAndWindow(el, 'scrollToXY').forEach((elem) => {
|
|
5577
|
+
const startX = elem instanceof Window ? window.scrollX : elem.scrollLeft;
|
|
5578
|
+
const startY = elem instanceof Window ? window.scrollY : elem.scrollTop;
|
|
5579
|
+
const targX = targetX ?? startX;
|
|
5580
|
+
const targY = targetY ?? startY;
|
|
5581
|
+
|
|
5582
|
+
const changeX = targX - startX;
|
|
5583
|
+
const changeY = targY - startY;
|
|
5584
|
+
|
|
5585
|
+
const ease = (typeof easing === 'string' && TinyHtml.easings[easing]) || null;
|
|
5586
|
+
if (typeof duration !== 'number' || typeof ease !== 'function')
|
|
5587
|
+
return executeScroll(elem, targX, targY, 1);
|
|
5588
|
+
const startTime = performance.now();
|
|
5589
|
+
const dur = duration ?? 0;
|
|
5590
|
+
|
|
5591
|
+
/**
|
|
5592
|
+
* Animates the scroll position based on easing and time.
|
|
5593
|
+
*
|
|
5594
|
+
* @param {number} currentTime - Timestamp provided by requestAnimationFrame.
|
|
5595
|
+
*/
|
|
5596
|
+
function animateScroll(currentTime) {
|
|
5597
|
+
if (typeof ease !== 'function') return;
|
|
5598
|
+
const time = Math.min(1, (currentTime - startTime) / dur);
|
|
5599
|
+
const easedTime = ease(time);
|
|
5600
|
+
|
|
5601
|
+
const newX = startX + changeX * easedTime;
|
|
5602
|
+
const newY = startY + changeY * easedTime;
|
|
5603
|
+
executeScroll(elem, newX, newY, time);
|
|
5604
|
+
|
|
5605
|
+
if (time < 1) requestAnimationFrame(animateScroll);
|
|
5606
|
+
}
|
|
5607
|
+
|
|
5608
|
+
requestAnimationFrame(animateScroll);
|
|
5217
5609
|
});
|
|
5610
|
+
return el;
|
|
5611
|
+
}
|
|
5612
|
+
|
|
5613
|
+
/**
|
|
5614
|
+
* Smoothly scrolls one or more elements (or the window) to the specified X and Y coordinates
|
|
5615
|
+
* using a custom duration and easing function.
|
|
5616
|
+
*
|
|
5617
|
+
* If `duration` or a valid `easing` is not provided, the scroll will be performed immediately.
|
|
5618
|
+
*
|
|
5619
|
+
* @param {Object} [settings={}] - Configuration object for the scroll animation.
|
|
5620
|
+
* @param {number} [settings.targetX] - The horizontal scroll target in pixels.
|
|
5621
|
+
* @param {number} [settings.targetY] - The vertical scroll target in pixels.
|
|
5622
|
+
* @param {number} [settings.duration] - The duration of the animation in milliseconds.
|
|
5623
|
+
* @param {Easings} [settings.easing] - The easing function name to use for the scroll animation.
|
|
5624
|
+
* @param {OnScrollAnimation} [settings.onAnimation] - Optional callback invoked on each animation
|
|
5625
|
+
* frame with the current scroll position, normalized animation time (`0` to `1`), and a completion flag.
|
|
5626
|
+
* @returns {TinyElementAndWindow|TinyElementAndWindow[]}
|
|
5627
|
+
*/
|
|
5628
|
+
scrollToXY({ targetX, targetY, duration, easing, onAnimation } = {}) {
|
|
5629
|
+
return TinyHtml.scrollToXY(this, { targetX, targetY, duration, easing, onAnimation });
|
|
5630
|
+
}
|
|
5631
|
+
|
|
5632
|
+
/**
|
|
5633
|
+
* Sets the vertical scroll position.
|
|
5634
|
+
* @param {TinyElementAndWindow|TinyElementAndWindow[]} el - Element or window.
|
|
5635
|
+
* @param {number} value - Scroll top value.
|
|
5636
|
+
* @returns {TinyElementAndWindow|TinyElementAndWindow[]}
|
|
5637
|
+
*/
|
|
5638
|
+
static setScrollTop(el, value) {
|
|
5639
|
+
if (typeof value !== 'number') throw new TypeError('ScrollTop value must be a number.');
|
|
5640
|
+
return TinyHtml.scrollToXY(el, { targetY: value });
|
|
5218
5641
|
}
|
|
5219
5642
|
|
|
5220
5643
|
/**
|
|
5221
5644
|
* Sets the vertical scroll position.
|
|
5222
5645
|
* @param {number} value - Scroll top value.
|
|
5646
|
+
* @returns {TinyElementAndWindow|TinyElementAndWindow[]}
|
|
5223
5647
|
*/
|
|
5224
5648
|
setScrollTop(value) {
|
|
5225
5649
|
return TinyHtml.setScrollTop(this, value);
|
|
@@ -5229,24 +5653,17 @@ class TinyHtml {
|
|
|
5229
5653
|
* Sets the horizontal scroll position.
|
|
5230
5654
|
* @param {TinyElementAndWindow|TinyElementAndWindow[]} el - Element or window.
|
|
5231
5655
|
* @param {number} value - Scroll left value.
|
|
5656
|
+
* @returns {TinyElementAndWindow|TinyElementAndWindow[]}
|
|
5232
5657
|
*/
|
|
5233
5658
|
static setScrollLeft(el, value) {
|
|
5234
5659
|
if (typeof value !== 'number') throw new TypeError('ScrollLeft value must be a number.');
|
|
5235
|
-
TinyHtml.
|
|
5236
|
-
if (TinyHtml.isWindow(elem)) {
|
|
5237
|
-
elem.scrollTo(value, elem.pageYOffset);
|
|
5238
|
-
} else if (elem.nodeType === 9) {
|
|
5239
|
-
// @ts-ignore
|
|
5240
|
-
elem.defaultView.scrollTo(value, elem.defaultView.pageYOffset);
|
|
5241
|
-
} else {
|
|
5242
|
-
elem.scrollLeft = value;
|
|
5243
|
-
}
|
|
5244
|
-
});
|
|
5660
|
+
return TinyHtml.scrollToXY(el, { targetX: value });
|
|
5245
5661
|
}
|
|
5246
5662
|
|
|
5247
5663
|
/**
|
|
5248
5664
|
* Sets the horizontal scroll position.
|
|
5249
5665
|
* @param {number} value - Scroll left value.
|
|
5666
|
+
* @returns {TinyElementAndWindow|TinyElementAndWindow[]}
|
|
5250
5667
|
*/
|
|
5251
5668
|
setScrollLeft(value) {
|
|
5252
5669
|
return TinyHtml.setScrollLeft(this, value);
|
|
@@ -5377,15 +5794,16 @@ class TinyHtml {
|
|
|
5377
5794
|
|
|
5378
5795
|
/**
|
|
5379
5796
|
* Adds one or more CSS class names to the element.
|
|
5380
|
-
* @type {(el: TinyElement|TinyElement[], ...tokens: string[]) =>
|
|
5797
|
+
* @type {(el: TinyElement|TinyElement[], ...tokens: string[]) => (TinyElement|TinyElement[])} - One or more class names to add.
|
|
5381
5798
|
*/
|
|
5382
5799
|
static addClass(el, ...args) {
|
|
5383
5800
|
TinyHtml._preElems(el, 'addClass').forEach((elem) => elem.classList.add(...args));
|
|
5801
|
+
return el;
|
|
5384
5802
|
}
|
|
5385
5803
|
|
|
5386
5804
|
/**
|
|
5387
5805
|
* Adds one or more CSS class names to the element.
|
|
5388
|
-
* @type {(...tokens: string[]) =>
|
|
5806
|
+
* @type {(...tokens: string[]) => (TinyElement|TinyElement[])} - One or more class names to add.
|
|
5389
5807
|
*/
|
|
5390
5808
|
addClass(...args) {
|
|
5391
5809
|
return TinyHtml.addClass(this, ...args);
|
|
@@ -5393,15 +5811,16 @@ class TinyHtml {
|
|
|
5393
5811
|
|
|
5394
5812
|
/**
|
|
5395
5813
|
* Removes one or more CSS class names from the element.
|
|
5396
|
-
* @type {(el: TinyElement|TinyElement[], ...tokens: string[]) =>
|
|
5814
|
+
* @type {(el: TinyElement|TinyElement[], ...tokens: string[]) => (TinyElement|TinyElement[])} - One or more class names to remove.
|
|
5397
5815
|
*/
|
|
5398
5816
|
static removeClass(el, ...args) {
|
|
5399
5817
|
TinyHtml._preElems(el, 'removeClass').forEach((elem) => elem.classList.remove(...args));
|
|
5818
|
+
return el;
|
|
5400
5819
|
}
|
|
5401
5820
|
|
|
5402
5821
|
/**
|
|
5403
5822
|
* Removes one or more CSS class names from the element.
|
|
5404
|
-
* @type {(...tokens: string[]) =>
|
|
5823
|
+
* @type {(...tokens: string[]) => (TinyElement|TinyElement[])} - One or more class names to remove.
|
|
5405
5824
|
*/
|
|
5406
5825
|
removeClass(...args) {
|
|
5407
5826
|
return TinyHtml.removeClass(this, ...args);
|
|
@@ -5611,15 +6030,18 @@ class TinyHtml {
|
|
|
5611
6030
|
* Set text content of elements.
|
|
5612
6031
|
* @param {TinyElement|TinyElement[]} el
|
|
5613
6032
|
* @param {string} value
|
|
6033
|
+
* @returns {TinyElement|TinyElement[]}
|
|
5614
6034
|
*/
|
|
5615
6035
|
static setText(el, value) {
|
|
5616
6036
|
if (typeof value !== 'string') throw new Error('Value is not a valid string.');
|
|
5617
6037
|
TinyHtml._preElems(el, 'setText').forEach((el) => (el.textContent = value));
|
|
6038
|
+
return el;
|
|
5618
6039
|
}
|
|
5619
6040
|
|
|
5620
6041
|
/**
|
|
5621
6042
|
* Set text content of the element.
|
|
5622
6043
|
* @param {string} value
|
|
6044
|
+
* @returns {TinyElement|TinyElement[]}
|
|
5623
6045
|
*/
|
|
5624
6046
|
setText(value) {
|
|
5625
6047
|
return TinyHtml.setText(this, value);
|
|
@@ -5628,13 +6050,16 @@ class TinyHtml {
|
|
|
5628
6050
|
/**
|
|
5629
6051
|
* Remove all child nodes from each element.
|
|
5630
6052
|
* @param {TinyElement|TinyElement[]} el
|
|
6053
|
+
* @returns {TinyElement|TinyElement[]}
|
|
5631
6054
|
*/
|
|
5632
6055
|
static empty(el) {
|
|
5633
6056
|
TinyHtml._preElems(el, 'empty').forEach((el) => (el.textContent = ''));
|
|
6057
|
+
return el;
|
|
5634
6058
|
}
|
|
5635
6059
|
|
|
5636
6060
|
/**
|
|
5637
6061
|
* Remove all child nodes of the element.
|
|
6062
|
+
* @returns {TinyElement|TinyElement[]}
|
|
5638
6063
|
*/
|
|
5639
6064
|
empty() {
|
|
5640
6065
|
return TinyHtml.empty(this);
|
|
@@ -5642,35 +6067,40 @@ class TinyHtml {
|
|
|
5642
6067
|
|
|
5643
6068
|
/**
|
|
5644
6069
|
* Get the innerHTML of the element.
|
|
5645
|
-
* @param {TinyElement
|
|
6070
|
+
* @param {TinyElement} el
|
|
6071
|
+
* @param {GetHTMLOptions} [ops]
|
|
5646
6072
|
* @returns {string}
|
|
5647
6073
|
*/
|
|
5648
|
-
static html(el) {
|
|
6074
|
+
static html(el, ops) {
|
|
5649
6075
|
const elem = TinyHtml._preElem(el, 'html');
|
|
5650
|
-
return elem.
|
|
6076
|
+
return elem.getHTML(ops);
|
|
5651
6077
|
}
|
|
5652
6078
|
|
|
5653
6079
|
/**
|
|
5654
6080
|
* Get the innerHTML of the element.
|
|
6081
|
+
* @param {GetHTMLOptions} [ops]
|
|
5655
6082
|
* @returns {string}
|
|
5656
6083
|
*/
|
|
5657
|
-
html() {
|
|
5658
|
-
return TinyHtml.html(this);
|
|
6084
|
+
html(ops) {
|
|
6085
|
+
return TinyHtml.html(this, ops);
|
|
5659
6086
|
}
|
|
5660
6087
|
|
|
5661
6088
|
/**
|
|
5662
6089
|
* Set the innerHTML of each element.
|
|
5663
6090
|
* @param {TinyElement|TinyElement[]} el
|
|
5664
6091
|
* @param {string} value
|
|
6092
|
+
* @returns {TinyElement|TinyElement[]}
|
|
5665
6093
|
*/
|
|
5666
6094
|
static setHtml(el, value) {
|
|
5667
6095
|
if (typeof value !== 'string') throw new Error('Value is not a valid string.');
|
|
5668
6096
|
TinyHtml._preElems(el, 'setHtml').forEach((el) => (el.innerHTML = value));
|
|
6097
|
+
return el;
|
|
5669
6098
|
}
|
|
5670
6099
|
|
|
5671
6100
|
/**
|
|
5672
6101
|
* Set the innerHTML of the element.
|
|
5673
6102
|
* @param {string} value
|
|
6103
|
+
* @returns {TinyElement|TinyElement[]}
|
|
5674
6104
|
*/
|
|
5675
6105
|
setHtml(value) {
|
|
5676
6106
|
return TinyHtml.setHtml(this, value);
|
|
@@ -5804,6 +6234,7 @@ class TinyHtml {
|
|
|
5804
6234
|
* @param {TinyInputElement|TinyInputElement[]} el - Target element.
|
|
5805
6235
|
* @param {SetValueList|((el: InputElement, val: SetValueList) => SetValueList)} value - The value to assign or a function that returns it.
|
|
5806
6236
|
* @throws {Error} If the computed value is not a valid string or boolean.
|
|
6237
|
+
* @returns {TinyInputElement|TinyInputElement[]}
|
|
5807
6238
|
*/
|
|
5808
6239
|
static setVal(el, value) {
|
|
5809
6240
|
TinyHtml._preInputElems(el, 'setVal').forEach((elem) => {
|
|
@@ -5843,6 +6274,7 @@ class TinyHtml {
|
|
|
5843
6274
|
if (typeof valToSet === 'string') elem.value = valToSet;
|
|
5844
6275
|
}
|
|
5845
6276
|
});
|
|
6277
|
+
return el;
|
|
5846
6278
|
}
|
|
5847
6279
|
|
|
5848
6280
|
/**
|
|
@@ -5850,6 +6282,7 @@ class TinyHtml {
|
|
|
5850
6282
|
* Accepts strings, numbers, booleans or arrays of these values, or a callback function that computes them.
|
|
5851
6283
|
*
|
|
5852
6284
|
* @param {SetValueList|((el: InputElement, val: SetValueList) => SetValueList)} value - The value to assign or a function that returns it.
|
|
6285
|
+
* @returns {TinyInputElement|TinyInputElement[]}
|
|
5853
6286
|
* @throws {Error} If the computed value is not a valid string or boolean.
|
|
5854
6287
|
*/
|
|
5855
6288
|
setVal(value) {
|
|
@@ -6119,6 +6552,7 @@ class TinyHtml {
|
|
|
6119
6552
|
* @param {string} event - The event type (e.g. 'click', 'keydown').
|
|
6120
6553
|
* @param {EventRegistryHandle} handler - The callback function to run on event.
|
|
6121
6554
|
* @param {EventRegistryOptions} [options] - Optional event listener options.
|
|
6555
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
6122
6556
|
*/
|
|
6123
6557
|
static on(el, event, handler, options) {
|
|
6124
6558
|
if (typeof event !== 'string') throw new TypeError('The event name must be a string.');
|
|
@@ -6131,6 +6565,7 @@ class TinyHtml {
|
|
|
6131
6565
|
if (!Array.isArray(events[event])) events[event] = [];
|
|
6132
6566
|
events[event].push({ handler, options });
|
|
6133
6567
|
});
|
|
6568
|
+
return el;
|
|
6134
6569
|
}
|
|
6135
6570
|
|
|
6136
6571
|
/**
|
|
@@ -6139,6 +6574,7 @@ class TinyHtml {
|
|
|
6139
6574
|
* @param {string} event - The event type (e.g. 'click', 'keydown').
|
|
6140
6575
|
* @param {EventRegistryHandle} handler - The callback function to run on event.
|
|
6141
6576
|
* @param {EventRegistryOptions} [options] - Optional event listener options.
|
|
6577
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
6142
6578
|
*/
|
|
6143
6579
|
on(event, handler, options) {
|
|
6144
6580
|
return TinyHtml.on(this, event, handler, options);
|
|
@@ -6151,6 +6587,7 @@ class TinyHtml {
|
|
|
6151
6587
|
* @param {string} event - The event type (e.g. 'click', 'keydown').
|
|
6152
6588
|
* @param {EventRegistryHandle} handler - The callback function to run on event.
|
|
6153
6589
|
* @param {EventRegistryOptions} [options={}] - Optional event listener options.
|
|
6590
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
6154
6591
|
*/
|
|
6155
6592
|
static once(el, event, handler, options = {}) {
|
|
6156
6593
|
if (typeof event !== 'string') throw new TypeError('The event name must be a string.');
|
|
@@ -6168,6 +6605,7 @@ class TinyHtml {
|
|
|
6168
6605
|
typeof options === 'boolean' ? options : { ...options, once: true },
|
|
6169
6606
|
);
|
|
6170
6607
|
});
|
|
6608
|
+
return el;
|
|
6171
6609
|
}
|
|
6172
6610
|
|
|
6173
6611
|
/**
|
|
@@ -6176,6 +6614,7 @@ class TinyHtml {
|
|
|
6176
6614
|
* @param {string} event - The event type (e.g. 'click', 'keydown').
|
|
6177
6615
|
* @param {EventRegistryHandle} handler - The callback function to run on event.
|
|
6178
6616
|
* @param {EventRegistryOptions} [options={}] - Optional event listener options.
|
|
6617
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
6179
6618
|
*/
|
|
6180
6619
|
once(event, handler, options = {}) {
|
|
6181
6620
|
return TinyHtml.once(this, event, handler, options);
|
|
@@ -6188,6 +6627,7 @@ class TinyHtml {
|
|
|
6188
6627
|
* @param {string} event - The event type.
|
|
6189
6628
|
* @param {EventRegistryHandle} handler - The function originally bound to the event.
|
|
6190
6629
|
* @param {boolean|EventListenerOptions} [options] - Optional listener options.
|
|
6630
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
6191
6631
|
*/
|
|
6192
6632
|
static off(el, event, handler, options) {
|
|
6193
6633
|
if (typeof event !== 'string') throw new TypeError('The event name must be a string.');
|
|
@@ -6200,6 +6640,7 @@ class TinyHtml {
|
|
|
6200
6640
|
if (events[event].length === 0) delete events[event];
|
|
6201
6641
|
}
|
|
6202
6642
|
});
|
|
6643
|
+
return el;
|
|
6203
6644
|
}
|
|
6204
6645
|
|
|
6205
6646
|
/**
|
|
@@ -6208,6 +6649,7 @@ class TinyHtml {
|
|
|
6208
6649
|
* @param {string} event - The event type.
|
|
6209
6650
|
* @param {EventRegistryHandle} handler - The function originally bound to the event.
|
|
6210
6651
|
* @param {boolean|EventListenerOptions} [options] - Optional listener options.
|
|
6652
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
6211
6653
|
*/
|
|
6212
6654
|
off(event, handler, options) {
|
|
6213
6655
|
return TinyHtml.off(this, event, handler, options);
|
|
@@ -6218,6 +6660,7 @@ class TinyHtml {
|
|
|
6218
6660
|
*
|
|
6219
6661
|
* @param {TinyEventTarget|TinyEventTarget[]} el - The target element.
|
|
6220
6662
|
* @param {string} event - The event type to remove (e.g. 'click').
|
|
6663
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
6221
6664
|
*/
|
|
6222
6665
|
static offAll(el, event) {
|
|
6223
6666
|
if (typeof event !== 'string') throw new TypeError('The event name must be a string.');
|
|
@@ -6230,12 +6673,14 @@ class TinyHtml {
|
|
|
6230
6673
|
delete events[event];
|
|
6231
6674
|
}
|
|
6232
6675
|
});
|
|
6676
|
+
return el;
|
|
6233
6677
|
}
|
|
6234
6678
|
|
|
6235
6679
|
/**
|
|
6236
6680
|
* Removes all event listeners of a specific type from the element.
|
|
6237
6681
|
*
|
|
6238
6682
|
* @param {string} event - The event type to remove (e.g. 'click').
|
|
6683
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
6239
6684
|
*/
|
|
6240
6685
|
offAll(event) {
|
|
6241
6686
|
return TinyHtml.offAll(this, event);
|
|
@@ -6247,6 +6692,7 @@ class TinyHtml {
|
|
|
6247
6692
|
* @param {TinyEventTarget|TinyEventTarget[]} el - The target element.
|
|
6248
6693
|
* @param {((handler: EventListenerOrEventListenerObject, event: string) => boolean)|null} [filterFn=null] -
|
|
6249
6694
|
* Optional filter function to selectively remove specific handlers.
|
|
6695
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
6250
6696
|
*/
|
|
6251
6697
|
static offAllTypes(el, filterFn = null) {
|
|
6252
6698
|
if (filterFn !== null && typeof filterFn !== 'function')
|
|
@@ -6265,6 +6711,7 @@ class TinyHtml {
|
|
|
6265
6711
|
|
|
6266
6712
|
__eventRegistry.delete(elem);
|
|
6267
6713
|
});
|
|
6714
|
+
return el;
|
|
6268
6715
|
}
|
|
6269
6716
|
|
|
6270
6717
|
/**
|
|
@@ -6272,6 +6719,7 @@ class TinyHtml {
|
|
|
6272
6719
|
*
|
|
6273
6720
|
* @param {((handler: EventListenerOrEventListenerObject, event: string) => boolean)|null} [filterFn=null] -
|
|
6274
6721
|
* Optional filter function to selectively remove specific handlers.
|
|
6722
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
6275
6723
|
*/
|
|
6276
6724
|
offAllTypes(filterFn = null) {
|
|
6277
6725
|
return TinyHtml.offAllTypes(this, filterFn);
|
|
@@ -6283,6 +6731,7 @@ class TinyHtml {
|
|
|
6283
6731
|
* @param {TinyEventTarget|TinyEventTarget[]} el - Target element where the event should be triggered.
|
|
6284
6732
|
* @param {string} event - Name of the event to trigger.
|
|
6285
6733
|
* @param {Event|CustomEvent|CustomEventInit} [payload] - Optional event object or data to pass.
|
|
6734
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
6286
6735
|
*/
|
|
6287
6736
|
static trigger(el, event, payload = {}) {
|
|
6288
6737
|
if (typeof event !== 'string') throw new TypeError('The event name must be a string.');
|
|
@@ -6298,6 +6747,7 @@ class TinyHtml {
|
|
|
6298
6747
|
|
|
6299
6748
|
elem.dispatchEvent(evt);
|
|
6300
6749
|
});
|
|
6750
|
+
return el;
|
|
6301
6751
|
}
|
|
6302
6752
|
|
|
6303
6753
|
/**
|
|
@@ -6305,6 +6755,7 @@ class TinyHtml {
|
|
|
6305
6755
|
*
|
|
6306
6756
|
* @param {string} event - Name of the event to trigger.
|
|
6307
6757
|
* @param {Event|CustomEvent|CustomEventInit} [payload] - Optional event object or data to pass.
|
|
6758
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
6308
6759
|
*/
|
|
6309
6760
|
trigger(event, payload = {}) {
|
|
6310
6761
|
return TinyHtml.trigger(this, event, payload);
|
|
@@ -6347,6 +6798,7 @@ class TinyHtml {
|
|
|
6347
6798
|
* @param {TinyElement|TinyElement[]} el
|
|
6348
6799
|
* @param {string} name
|
|
6349
6800
|
* @param {string|null} [value=null]
|
|
6801
|
+
* @returns {TinyElement|TinyElement[]}
|
|
6350
6802
|
*/
|
|
6351
6803
|
static setAttr(el, name, value = null) {
|
|
6352
6804
|
if (typeof name !== 'string') throw new TypeError('The "name" must be a string.');
|
|
@@ -6356,12 +6808,14 @@ class TinyHtml {
|
|
|
6356
6808
|
if (value === null) elem.removeAttribute(name);
|
|
6357
6809
|
else elem.setAttribute(name, value);
|
|
6358
6810
|
});
|
|
6811
|
+
return el;
|
|
6359
6812
|
}
|
|
6360
6813
|
|
|
6361
6814
|
/**
|
|
6362
6815
|
* Set an attribute on an element.
|
|
6363
6816
|
* @param {string} name
|
|
6364
6817
|
* @param {string|null} [value=null]
|
|
6818
|
+
* @returns {TinyElement|TinyElement[]}
|
|
6365
6819
|
*/
|
|
6366
6820
|
setAttr(name, value) {
|
|
6367
6821
|
return TinyHtml.setAttr(this, name, value);
|
|
@@ -6371,15 +6825,18 @@ class TinyHtml {
|
|
|
6371
6825
|
* Remove attribute(s) from an element.
|
|
6372
6826
|
* @param {TinyElement|TinyElement[]} el
|
|
6373
6827
|
* @param {string} name Space-separated list of attributes.
|
|
6828
|
+
* @returns {TinyElement|TinyElement[]}
|
|
6374
6829
|
*/
|
|
6375
6830
|
static removeAttr(el, name) {
|
|
6376
6831
|
if (typeof name !== 'string') throw new TypeError('The "name" must be a string.');
|
|
6377
6832
|
TinyHtml._preElems(el, 'removeAttr').forEach((elem) => elem.removeAttribute(name));
|
|
6833
|
+
return el;
|
|
6378
6834
|
}
|
|
6379
6835
|
|
|
6380
6836
|
/**
|
|
6381
6837
|
* Remove attribute(s) from an element.
|
|
6382
6838
|
* @param {string} name Space-separated list of attributes.
|
|
6839
|
+
* @returns {TinyElement|TinyElement[]}
|
|
6383
6840
|
*/
|
|
6384
6841
|
removeAttr(name) {
|
|
6385
6842
|
return TinyHtml.removeAttr(this, name);
|
|
@@ -6434,6 +6891,7 @@ class TinyHtml {
|
|
|
6434
6891
|
* Set a property on an element.
|
|
6435
6892
|
* @param {TinyElement|TinyElement[]} el
|
|
6436
6893
|
* @param {string} name
|
|
6894
|
+
* @returns {TinyElement|TinyElement[]}
|
|
6437
6895
|
*/
|
|
6438
6896
|
static addProp(el, name) {
|
|
6439
6897
|
if (typeof name !== 'string') throw new TypeError('The "name" must be a string.');
|
|
@@ -6443,11 +6901,13 @@ class TinyHtml {
|
|
|
6443
6901
|
// @ts-ignore
|
|
6444
6902
|
elem[name] = true;
|
|
6445
6903
|
});
|
|
6904
|
+
return el;
|
|
6446
6905
|
}
|
|
6447
6906
|
|
|
6448
6907
|
/**
|
|
6449
6908
|
* Set a property on an element.
|
|
6450
6909
|
* @param {string} name
|
|
6910
|
+
* @returns {TinyElement|TinyElement[]}
|
|
6451
6911
|
*/
|
|
6452
6912
|
addProp(name) {
|
|
6453
6913
|
return TinyHtml.addProp(this, name);
|
|
@@ -6457,6 +6917,7 @@ class TinyHtml {
|
|
|
6457
6917
|
* Remove a property from an element.
|
|
6458
6918
|
* @param {TinyElement|TinyElement[]} el
|
|
6459
6919
|
* @param {string} name
|
|
6920
|
+
* @returns {TinyElement|TinyElement[]}
|
|
6460
6921
|
*/
|
|
6461
6922
|
static removeProp(el, name) {
|
|
6462
6923
|
if (typeof name !== 'string') throw new TypeError('The "name" must be a string.');
|
|
@@ -6466,11 +6927,13 @@ class TinyHtml {
|
|
|
6466
6927
|
// @ts-ignore
|
|
6467
6928
|
elem[name] = false;
|
|
6468
6929
|
});
|
|
6930
|
+
return el;
|
|
6469
6931
|
}
|
|
6470
6932
|
|
|
6471
6933
|
/**
|
|
6472
6934
|
* Remove a property from an element.
|
|
6473
6935
|
* @param {string} name
|
|
6936
|
+
* @returns {TinyElement|TinyElement[]}
|
|
6474
6937
|
*/
|
|
6475
6938
|
removeProp(name) {
|
|
6476
6939
|
return TinyHtml.removeProp(this, name);
|
|
@@ -6511,13 +6974,16 @@ class TinyHtml {
|
|
|
6511
6974
|
/**
|
|
6512
6975
|
* Removes an element from the DOM.
|
|
6513
6976
|
* @param {TinyElement|TinyElement[]} el - The DOM element or selector to remove.
|
|
6977
|
+
* @returns {TinyElement|TinyElement[]}
|
|
6514
6978
|
*/
|
|
6515
6979
|
static remove(el) {
|
|
6516
6980
|
TinyHtml._preElems(el, 'remove').forEach((elem) => elem.remove());
|
|
6981
|
+
return el;
|
|
6517
6982
|
}
|
|
6518
6983
|
|
|
6519
6984
|
/**
|
|
6520
6985
|
* Removes the element from the DOM.
|
|
6986
|
+
* @returns {TinyElement|TinyElement[]}
|
|
6521
6987
|
*/
|
|
6522
6988
|
remove() {
|
|
6523
6989
|
return TinyHtml.remove(this);
|
|
@@ -6861,6 +7327,14 @@ class TinyHtml {
|
|
|
6861
7327
|
*/
|
|
6862
7328
|
static isInViewport(el) {
|
|
6863
7329
|
const elem = TinyHtml._preElem(el, 'isInViewport');
|
|
7330
|
+
if (
|
|
7331
|
+
!elem.checkVisibility({
|
|
7332
|
+
contentVisibilityAuto: false,
|
|
7333
|
+
opacityProperty: false,
|
|
7334
|
+
visibilityProperty: false,
|
|
7335
|
+
})
|
|
7336
|
+
)
|
|
7337
|
+
return false;
|
|
6864
7338
|
const elementTop = TinyHtml.offset(elem).top;
|
|
6865
7339
|
const elementBottom = elementTop + TinyHtml.outerHeight(elem);
|
|
6866
7340
|
|
|
@@ -6887,6 +7361,14 @@ class TinyHtml {
|
|
|
6887
7361
|
*/
|
|
6888
7362
|
static isScrolledIntoView(el) {
|
|
6889
7363
|
const elem = TinyHtml._preElem(el, 'isScrolledIntoView');
|
|
7364
|
+
if (
|
|
7365
|
+
!elem.checkVisibility({
|
|
7366
|
+
contentVisibilityAuto: false,
|
|
7367
|
+
opacityProperty: false,
|
|
7368
|
+
visibilityProperty: false,
|
|
7369
|
+
})
|
|
7370
|
+
)
|
|
7371
|
+
return false;
|
|
6890
7372
|
const docViewTop = TinyHtml.scrollTop(window);
|
|
6891
7373
|
const docViewBottom = docViewTop + TinyHtml.height(window);
|
|
6892
7374
|
|
|
@@ -6904,6 +7386,111 @@ class TinyHtml {
|
|
|
6904
7386
|
isScrolledIntoView() {
|
|
6905
7387
|
return TinyHtml.isScrolledIntoView(this);
|
|
6906
7388
|
}
|
|
7389
|
+
|
|
7390
|
+
/**
|
|
7391
|
+
* Checks if the given element is at least partially visible within the boundaries of a container.
|
|
7392
|
+
*
|
|
7393
|
+
* @param {TinyElement} el - The DOM element to check.
|
|
7394
|
+
* @param {TinyElement} cont - The container element acting as the viewport.
|
|
7395
|
+
* @returns {boolean} True if the element is partially visible within the container, false otherwise.
|
|
7396
|
+
*/
|
|
7397
|
+
static isInContainer(el, cont) {
|
|
7398
|
+
const elem = TinyHtml._preElem(el, 'isInContainer');
|
|
7399
|
+
const container = TinyHtml._preElem(cont, 'isInContainer');
|
|
7400
|
+
|
|
7401
|
+
if (
|
|
7402
|
+
!elem.checkVisibility({
|
|
7403
|
+
contentVisibilityAuto: false,
|
|
7404
|
+
opacityProperty: false,
|
|
7405
|
+
visibilityProperty: false,
|
|
7406
|
+
})
|
|
7407
|
+
)
|
|
7408
|
+
return false;
|
|
7409
|
+
const elemRect = elem.getBoundingClientRect();
|
|
7410
|
+
const containerRect = container.getBoundingClientRect();
|
|
7411
|
+
|
|
7412
|
+
const verticallyVisible =
|
|
7413
|
+
elemRect.bottom > containerRect.top && elemRect.top < containerRect.bottom;
|
|
7414
|
+
|
|
7415
|
+
const horizontallyVisible =
|
|
7416
|
+
elemRect.right > containerRect.left && elemRect.left < containerRect.right;
|
|
7417
|
+
|
|
7418
|
+
return verticallyVisible && horizontallyVisible;
|
|
7419
|
+
}
|
|
7420
|
+
|
|
7421
|
+
/**
|
|
7422
|
+
* Checks if the given element is at least partially visible within the boundaries of a container.
|
|
7423
|
+
*
|
|
7424
|
+
* @param {TinyElement} cont - The container element acting as the viewport.
|
|
7425
|
+
* @returns {boolean} True if the element is partially visible within the container, false otherwise.
|
|
7426
|
+
*/
|
|
7427
|
+
isInContainer(cont) {
|
|
7428
|
+
return TinyHtml.isInContainer(this, cont);
|
|
7429
|
+
}
|
|
7430
|
+
|
|
7431
|
+
/**
|
|
7432
|
+
* Checks if the given element is fully visible within the boundaries of a container (top and bottom).
|
|
7433
|
+
*
|
|
7434
|
+
* @param {TinyElement} el - The DOM element to check.
|
|
7435
|
+
* @param {TinyElement} cont - The container element acting as the viewport.
|
|
7436
|
+
* @returns {boolean} True if the element is fully visible within the container, false otherwise.
|
|
7437
|
+
*/
|
|
7438
|
+
static isFullyInContainer(el, cont) {
|
|
7439
|
+
const elem = TinyHtml._preElem(el, 'isScrolledIntoView');
|
|
7440
|
+
const container = TinyHtml._preElem(cont, 'isInContainer');
|
|
7441
|
+
|
|
7442
|
+
if (
|
|
7443
|
+
!elem.checkVisibility({
|
|
7444
|
+
contentVisibilityAuto: false,
|
|
7445
|
+
opacityProperty: false,
|
|
7446
|
+
visibilityProperty: false,
|
|
7447
|
+
})
|
|
7448
|
+
)
|
|
7449
|
+
return false;
|
|
7450
|
+
const elemRect = elem.getBoundingClientRect();
|
|
7451
|
+
const containerRect = container.getBoundingClientRect();
|
|
7452
|
+
|
|
7453
|
+
const isFullyVisible =
|
|
7454
|
+
elemRect.top >= containerRect.top &&
|
|
7455
|
+
elemRect.bottom <= containerRect.bottom &&
|
|
7456
|
+
elemRect.left >= containerRect.left &&
|
|
7457
|
+
elemRect.right <= containerRect.right;
|
|
7458
|
+
|
|
7459
|
+
return isFullyVisible;
|
|
7460
|
+
}
|
|
7461
|
+
|
|
7462
|
+
/**
|
|
7463
|
+
* Checks if the given element is fully visible within the boundaries of a container (top and bottom).
|
|
7464
|
+
*
|
|
7465
|
+
* @param {TinyElement} cont - The container element acting as the viewport.
|
|
7466
|
+
* @returns {boolean} True if the element is fully visible within the container, false otherwise.
|
|
7467
|
+
*/
|
|
7468
|
+
isFullyInContainer(cont) {
|
|
7469
|
+
return TinyHtml.isFullyInContainer(this, cont);
|
|
7470
|
+
}
|
|
7471
|
+
|
|
7472
|
+
/**
|
|
7473
|
+
* Checks if an element has scrollable content.
|
|
7474
|
+
*
|
|
7475
|
+
* @param {TinyElement} el - The DOM element to check.
|
|
7476
|
+
* @returns {{ v: boolean, h: boolean }} - True if scroll is needed in that direction.
|
|
7477
|
+
*/
|
|
7478
|
+
static hasScroll(el) {
|
|
7479
|
+
const elem = TinyHtml._preElem(el, 'hasScroll');
|
|
7480
|
+
return {
|
|
7481
|
+
v: elem.scrollHeight > elem.clientHeight,
|
|
7482
|
+
h: elem.scrollWidth > elem.clientWidth,
|
|
7483
|
+
};
|
|
7484
|
+
}
|
|
7485
|
+
|
|
7486
|
+
/**
|
|
7487
|
+
* Checks if an element has scrollable content.
|
|
7488
|
+
*
|
|
7489
|
+
* @returns {{ v: boolean, h: boolean }} - True if scroll is needed in that direction.
|
|
7490
|
+
*/
|
|
7491
|
+
hasScroll() {
|
|
7492
|
+
return TinyHtml.hasScroll(this);
|
|
7493
|
+
}
|
|
6907
7494
|
}
|
|
6908
7495
|
|
|
6909
7496
|
/* harmony default export */ const libs_TinyHtml = (TinyHtml);
|