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/TinyBasicsEs.js
CHANGED
|
@@ -3023,20 +3023,22 @@ function saveJsonFile(filename, data, spaces = 2) {
|
|
|
3023
3023
|
}
|
|
3024
3024
|
|
|
3025
3025
|
/**
|
|
3026
|
-
*
|
|
3027
|
-
*
|
|
3028
|
-
* @
|
|
3029
|
-
* @
|
|
3030
|
-
* @
|
|
3031
|
-
* @
|
|
3032
|
-
* @
|
|
3033
|
-
* @param {number} [options.retries=0] - Number of retry attempts (ignored if signal is provided).
|
|
3034
|
-
* @param {Headers|Record<string, *>} [options.headers={}] - Additional headers.
|
|
3035
|
-
* @param {AbortSignal|null} [options.signal] - External AbortSignal; disables timeout and retries.
|
|
3036
|
-
* @returns {Promise<*>} Parsed JSON object.
|
|
3037
|
-
* @throws {Error} Throws if fetch fails, times out, or returns invalid JSON.
|
|
3026
|
+
* @typedef {Object} FetchTemplateOptions
|
|
3027
|
+
* @property {string} [method="GET"] - HTTP method to use (GET, POST, etc.).
|
|
3028
|
+
* @property {any} [body] - Request body (only for methods like POST, PUT).
|
|
3029
|
+
* @property {number} [timeout=0] - Timeout in milliseconds (ignored if signal is provided).
|
|
3030
|
+
* @property {number} [retries=0] - Number of retry attempts (ignored if signal is provided).
|
|
3031
|
+
* @property {Headers|Record<string, *>} [headers={}] - Additional headers.
|
|
3032
|
+
* @property {AbortSignal|null} [signal] - External AbortSignal; disables timeout and retries.
|
|
3038
3033
|
*/
|
|
3039
|
-
|
|
3034
|
+
|
|
3035
|
+
/**
|
|
3036
|
+
* @param {string} url - The full URL to fetch data from.
|
|
3037
|
+
* @param {FetchTemplateOptions} [options] - Optional settings.
|
|
3038
|
+
* @returns {Promise<Response>} Result data.
|
|
3039
|
+
* @throws {Error} Throws if fetch fails, times out.
|
|
3040
|
+
*/
|
|
3041
|
+
async function fetchTemplate(
|
|
3040
3042
|
url,
|
|
3041
3043
|
{ method = 'GET', body, timeout = 0, retries = 0, headers = {}, signal = null } = {},
|
|
3042
3044
|
) {
|
|
@@ -3095,17 +3097,7 @@ async function fetchJson(
|
|
|
3095
3097
|
if (timer) clearTimeout(timer);
|
|
3096
3098
|
|
|
3097
3099
|
if (!response.ok) throw new Error(`HTTP error: ${response.status} ${response.statusText}`);
|
|
3098
|
-
|
|
3099
|
-
const contentType = response.headers.get('content-type') || '';
|
|
3100
|
-
if (!contentType.includes('application/json'))
|
|
3101
|
-
throw new Error(`Unexpected content-type: ${contentType}`);
|
|
3102
|
-
|
|
3103
|
-
const data = await response.json();
|
|
3104
|
-
|
|
3105
|
-
if (!Array.isArray(data) && !isJsonObject(data))
|
|
3106
|
-
throw new Error('Received invalid data instead of valid JSON.');
|
|
3107
|
-
|
|
3108
|
-
return data;
|
|
3100
|
+
return response;
|
|
3109
3101
|
} catch (err) {
|
|
3110
3102
|
lastError = /** @type {Error} */ (err);
|
|
3111
3103
|
if (signal) break; // if an external signal came, it does not retry
|
|
@@ -3119,6 +3111,63 @@ async function fetchJson(
|
|
|
3119
3111
|
);
|
|
3120
3112
|
}
|
|
3121
3113
|
|
|
3114
|
+
/**
|
|
3115
|
+
* Loads and parses a JSON from a remote URL using Fetch API.
|
|
3116
|
+
*
|
|
3117
|
+
* @param {string} url - The full URL to fetch JSON from.
|
|
3118
|
+
* @param {Object} [options] - Optional settings.
|
|
3119
|
+
* @returns {Promise<any[] | Record<string | number | symbol, unknown>>} Parsed JSON object.
|
|
3120
|
+
* @throws {Error} Throws if fetch fails, times out, or returns invalid JSON.
|
|
3121
|
+
*/
|
|
3122
|
+
async function fetchJson(url, options) {
|
|
3123
|
+
return new Promise((resolve, reject) => {
|
|
3124
|
+
fetchTemplate(url, options)
|
|
3125
|
+
.then(async (res) => {
|
|
3126
|
+
const contentType = res.headers.get('content-type') || '';
|
|
3127
|
+
if (!contentType.includes('application/json'))
|
|
3128
|
+
throw new Error(`Unexpected content-type: ${contentType}`);
|
|
3129
|
+
|
|
3130
|
+
const data = await res.json();
|
|
3131
|
+
|
|
3132
|
+
if (!Array.isArray(data) && !isJsonObject(data))
|
|
3133
|
+
throw new Error('Received invalid data instead of valid JSON.');
|
|
3134
|
+
|
|
3135
|
+
return resolve(data);
|
|
3136
|
+
})
|
|
3137
|
+
.catch(reject);
|
|
3138
|
+
});
|
|
3139
|
+
}
|
|
3140
|
+
|
|
3141
|
+
/**
|
|
3142
|
+
* Loads a remote file as a Blob using Fetch API.
|
|
3143
|
+
*
|
|
3144
|
+
* @param {string} url - The full URL to fetch the file from.
|
|
3145
|
+
* @param {Object} [options] - Optional fetch options.
|
|
3146
|
+
* @param {string[]} [allowedMimeTypes] - Optional list of accepted MIME types (e.g., ['image/jpeg']).
|
|
3147
|
+
* @returns {Promise<Blob>} - The fetched file as a Blob.
|
|
3148
|
+
* @throws {Error} Throws if fetch fails, response is not ok, or MIME type is not allowed.
|
|
3149
|
+
*/
|
|
3150
|
+
async function fetchBlob(url, allowedMimeTypes, options) {
|
|
3151
|
+
return new Promise((resolve, reject) => {
|
|
3152
|
+
fetchTemplate(url, options)
|
|
3153
|
+
.then(async (res) => {
|
|
3154
|
+
const contentType = res.headers.get('content-type') || '';
|
|
3155
|
+
|
|
3156
|
+
if (
|
|
3157
|
+
Array.isArray(allowedMimeTypes) &&
|
|
3158
|
+
allowedMimeTypes.length > 0 &&
|
|
3159
|
+
!allowedMimeTypes.some((type) => contentType.includes(type))
|
|
3160
|
+
) {
|
|
3161
|
+
throw new Error(`Blocked MIME type: ${contentType}`);
|
|
3162
|
+
}
|
|
3163
|
+
|
|
3164
|
+
const data = await res.blob();
|
|
3165
|
+
return resolve(data);
|
|
3166
|
+
})
|
|
3167
|
+
.catch(reject);
|
|
3168
|
+
});
|
|
3169
|
+
}
|
|
3170
|
+
|
|
3122
3171
|
///////////////////////////////////////////////////////////////////////////////
|
|
3123
3172
|
|
|
3124
3173
|
/**
|
|
@@ -3650,6 +3699,19 @@ const {
|
|
|
3650
3699
|
areElsCollRight: TinyHtml_areElsCollRight,
|
|
3651
3700
|
} = collision_namespaceObject;
|
|
3652
3701
|
|
|
3702
|
+
/**
|
|
3703
|
+
* Callback invoked on each animation frame with the current scroll position,
|
|
3704
|
+
* normalized animation time (`0` to `1`), and a completion flag.
|
|
3705
|
+
*
|
|
3706
|
+
* @typedef {(progress: { x: number, y: number, isComplete: boolean, time: number }) => void} OnScrollAnimation
|
|
3707
|
+
*/
|
|
3708
|
+
|
|
3709
|
+
/**
|
|
3710
|
+
* A list of supported easing function names for smooth animations.
|
|
3711
|
+
*
|
|
3712
|
+
* @typedef {'linear' | 'easeInQuad' | 'easeOutQuad' | 'easeInOutQuad' | 'easeInCubic' | 'easeOutCubic' | 'easeInOutCubic'} Easings
|
|
3713
|
+
*/
|
|
3714
|
+
|
|
3653
3715
|
/**
|
|
3654
3716
|
* Represents a raw Node element or an instance of TinyHtml.
|
|
3655
3717
|
* This type is used to abstract interactions with both plain elements
|
|
@@ -3705,6 +3767,21 @@ const {
|
|
|
3705
3767
|
* @typedef {Element|Window} ElementAndWindow
|
|
3706
3768
|
*/
|
|
3707
3769
|
|
|
3770
|
+
/**
|
|
3771
|
+
* Represents a raw DOM element/window/document or an instance of TinyHtml.
|
|
3772
|
+
* This type is used to abstract interactions with both plain elements
|
|
3773
|
+
* and wrapped elements via the TinyHtml class.
|
|
3774
|
+
*
|
|
3775
|
+
* @typedef {ElementAndWinAndDoc|TinyHtml} TinyElementAndWinAndDoc
|
|
3776
|
+
*/
|
|
3777
|
+
|
|
3778
|
+
/**
|
|
3779
|
+
* Represents a value that can be either a DOM Element, or the global Window object, or the document object.
|
|
3780
|
+
* Useful for functions that operate generically on scrollable or measurable targets.
|
|
3781
|
+
*
|
|
3782
|
+
* @typedef {Element|Window|Document} ElementAndWinAndDoc
|
|
3783
|
+
*/
|
|
3784
|
+
|
|
3708
3785
|
/**
|
|
3709
3786
|
* A parameter type used for filtering or matching elements.
|
|
3710
3787
|
* It can be:
|
|
@@ -3721,7 +3798,7 @@ const {
|
|
|
3721
3798
|
* Elements accepted as constructor values for TinyHtml.
|
|
3722
3799
|
* These include common DOM elements and root containers.
|
|
3723
3800
|
*
|
|
3724
|
-
* @typedef {Window|Element|Document} ConstructorElValues
|
|
3801
|
+
* @typedef {Window|Element|Document|Text} ConstructorElValues
|
|
3725
3802
|
*/
|
|
3726
3803
|
|
|
3727
3804
|
/**
|
|
@@ -3842,40 +3919,114 @@ class TinyHtml_TinyHtml {
|
|
|
3842
3919
|
|
|
3843
3920
|
static Utils = { ...collision_namespaceObject };
|
|
3844
3921
|
|
|
3922
|
+
/**
|
|
3923
|
+
* Creates a new DOM element with the specified tag name and options, then wraps it in a TinyHtml instance.
|
|
3924
|
+
*
|
|
3925
|
+
* @param {string} tagName - The tag name of the element to create (e.g., 'div', 'span').
|
|
3926
|
+
* @param {ElementCreationOptions} ops - Optional settings for creating the element.
|
|
3927
|
+
* @returns {TinyHtml} A TinyHtml instance wrapping the newly created DOM element.
|
|
3928
|
+
* @throws {TypeError} If tagName is not a string or ops is not an object.
|
|
3929
|
+
*/
|
|
3930
|
+
static createElement(tagName, ops) {
|
|
3931
|
+
if (typeof tagName !== 'string')
|
|
3932
|
+
throw new TypeError(`[TinyHtml] createElement(): The tagName must be a string.`);
|
|
3933
|
+
if (typeof ops !== 'undefined' && typeof ops !== 'object')
|
|
3934
|
+
throw new TypeError(`[TinyHtml] createElement(): The ops must be a object.`);
|
|
3935
|
+
return new TinyHtml_TinyHtml(document.createElement(tagName, ops));
|
|
3936
|
+
}
|
|
3937
|
+
|
|
3938
|
+
/**
|
|
3939
|
+
* Creates a new TinyHtml instance that wraps a DOM TextNode.
|
|
3940
|
+
*
|
|
3941
|
+
* This method is useful when you want to insert raw text content into the DOM
|
|
3942
|
+
* without it being interpreted as HTML. The returned instance behaves like any
|
|
3943
|
+
* other TinyHtml element and can be appended or manipulated as needed.
|
|
3944
|
+
*
|
|
3945
|
+
* @param {string} value - The plain text content to be wrapped in a TextNode.
|
|
3946
|
+
* @returns {TinyHtml} A TinyHtml instance wrapping the newly created DOM TextNode.
|
|
3947
|
+
* @throws {TypeError} If the provided value is not a string.
|
|
3948
|
+
*/
|
|
3949
|
+
static createTextNode(value) {
|
|
3950
|
+
if (typeof value !== 'string')
|
|
3951
|
+
throw new TypeError(`[TinyHtml] createTextNode(): The value must be a string.`);
|
|
3952
|
+
return new TinyHtml_TinyHtml(document.createTextNode(value));
|
|
3953
|
+
}
|
|
3954
|
+
|
|
3955
|
+
/**
|
|
3956
|
+
* Creates an HTMLElement or TextNode from an HTML string.
|
|
3957
|
+
* Supports both elements and plain text.
|
|
3958
|
+
*
|
|
3959
|
+
* @param {string} htmlString - The HTML string to convert.
|
|
3960
|
+
* @returns {TinyHtml} - A single HTMLElement or TextNode.
|
|
3961
|
+
*/
|
|
3962
|
+
static createElementFromHTML(htmlString) {
|
|
3963
|
+
const template = document.createElement('template');
|
|
3964
|
+
htmlString = htmlString.trim();
|
|
3965
|
+
|
|
3966
|
+
// If it's only text (e.g., no "<" tag), return a TextNode
|
|
3967
|
+
if (!htmlString.startsWith('<')) {
|
|
3968
|
+
return TinyHtml_TinyHtml.createTextNode(htmlString);
|
|
3969
|
+
}
|
|
3970
|
+
|
|
3971
|
+
template.innerHTML = htmlString;
|
|
3972
|
+
if (!(template.content.firstChild instanceof Element)) throw new Error('');
|
|
3973
|
+
return new TinyHtml_TinyHtml(template.content.firstChild);
|
|
3974
|
+
}
|
|
3975
|
+
|
|
3845
3976
|
/**
|
|
3846
3977
|
* Queries the document for the first element matching the CSS selector and wraps it in a TinyHtml instance.
|
|
3847
3978
|
*
|
|
3848
3979
|
* @param {string} selector - A valid CSS selector string.
|
|
3849
|
-
* @
|
|
3850
|
-
* @
|
|
3980
|
+
* @param {Document|Element} elem - Target element.
|
|
3981
|
+
* @returns {TinyHtml|null} A TinyHtml instance wrapping the matched element.
|
|
3851
3982
|
*/
|
|
3852
|
-
static query(selector) {
|
|
3853
|
-
const newEl =
|
|
3854
|
-
if (!newEl)
|
|
3983
|
+
static query(selector, elem = document) {
|
|
3984
|
+
const newEl = elem.querySelector(selector);
|
|
3985
|
+
if (!newEl) return null;
|
|
3855
3986
|
return new TinyHtml_TinyHtml(newEl);
|
|
3856
3987
|
}
|
|
3857
3988
|
|
|
3989
|
+
/**
|
|
3990
|
+
* Queries the element for the first element matching the CSS selector and wraps it in a TinyHtml instance.
|
|
3991
|
+
*
|
|
3992
|
+
* @param {string} selector - A valid CSS selector string.
|
|
3993
|
+
* @returns {TinyHtml|null} A TinyHtml instance wrapping the matched element.
|
|
3994
|
+
*/
|
|
3995
|
+
querySelector(selector) {
|
|
3996
|
+
return TinyHtml_TinyHtml.query(selector, TinyHtml_TinyHtml._preElem(this, 'query'));
|
|
3997
|
+
}
|
|
3998
|
+
|
|
3858
3999
|
/**
|
|
3859
4000
|
* Queries the document for all elements matching the CSS selector and wraps them in TinyHtml instances.
|
|
3860
4001
|
*
|
|
3861
4002
|
* @param {string} selector - A valid CSS selector string.
|
|
4003
|
+
* @param {Document|Element} elem - Target element.
|
|
3862
4004
|
* @returns {TinyHtml[]} An array of TinyHtml instances wrapping the matched elements.
|
|
3863
4005
|
*/
|
|
3864
|
-
static queryAll(selector) {
|
|
3865
|
-
const newEls =
|
|
4006
|
+
static queryAll(selector, elem = document) {
|
|
4007
|
+
const newEls = elem.querySelectorAll(selector);
|
|
3866
4008
|
return TinyHtml_TinyHtml.toTinyElm([...newEls]);
|
|
3867
4009
|
}
|
|
3868
4010
|
|
|
4011
|
+
/**
|
|
4012
|
+
* Queries the element for all elements matching the CSS selector and wraps them in TinyHtml instances.
|
|
4013
|
+
*
|
|
4014
|
+
* @param {string} selector - A valid CSS selector string.
|
|
4015
|
+
* @returns {TinyHtml[]} An array of TinyHtml instances wrapping the matched elements.
|
|
4016
|
+
*/
|
|
4017
|
+
querySelectorAll(selector) {
|
|
4018
|
+
return TinyHtml_TinyHtml.queryAll(selector, TinyHtml_TinyHtml._preElem(this, 'queryAll'));
|
|
4019
|
+
}
|
|
4020
|
+
|
|
3869
4021
|
/**
|
|
3870
4022
|
* Retrieves an element by its ID and wraps it in a TinyHtml instance.
|
|
3871
4023
|
*
|
|
3872
4024
|
* @param {string} selector - The ID of the element to retrieve.
|
|
3873
|
-
* @returns {TinyHtml} A TinyHtml instance wrapping the found element.
|
|
3874
|
-
* @throws {Error} If no element is found with the specified ID.
|
|
4025
|
+
* @returns {TinyHtml|null} A TinyHtml instance wrapping the found element.
|
|
3875
4026
|
*/
|
|
3876
4027
|
static getById(selector) {
|
|
3877
4028
|
const newEl = document.getElementById(selector);
|
|
3878
|
-
if (!newEl)
|
|
4029
|
+
if (!newEl) return null;
|
|
3879
4030
|
return new TinyHtml_TinyHtml(newEl);
|
|
3880
4031
|
}
|
|
3881
4032
|
|
|
@@ -3883,13 +4034,24 @@ class TinyHtml_TinyHtml {
|
|
|
3883
4034
|
* Retrieves all elements with the specified class name and wraps them in TinyHtml instances.
|
|
3884
4035
|
*
|
|
3885
4036
|
* @param {string} selector - The class name to search for.
|
|
4037
|
+
* @param {Document|Element} elem - Target element.
|
|
3886
4038
|
* @returns {TinyHtml[]} An array of TinyHtml instances wrapping the found elements.
|
|
3887
4039
|
*/
|
|
3888
|
-
static getByClassName(selector) {
|
|
3889
|
-
const newEls =
|
|
4040
|
+
static getByClassName(selector, elem = document) {
|
|
4041
|
+
const newEls = elem.getElementsByClassName(selector);
|
|
3890
4042
|
return TinyHtml_TinyHtml.toTinyElm([...newEls]);
|
|
3891
4043
|
}
|
|
3892
4044
|
|
|
4045
|
+
/**
|
|
4046
|
+
* Retrieves all elements with the specified class name and wraps them in TinyHtml instances.
|
|
4047
|
+
*
|
|
4048
|
+
* @param {string} selector - The class name to search for.
|
|
4049
|
+
* @returns {TinyHtml[]} An array of TinyHtml instances wrapping the found elements.
|
|
4050
|
+
*/
|
|
4051
|
+
getElementsByClassName(selector) {
|
|
4052
|
+
return TinyHtml_TinyHtml.getByClassName(selector, TinyHtml_TinyHtml._preElem(this, 'getByClassName'));
|
|
4053
|
+
}
|
|
4054
|
+
|
|
3893
4055
|
/**
|
|
3894
4056
|
* Retrieves all elements with the specified name attribute and wraps them in TinyHtml instances.
|
|
3895
4057
|
*
|
|
@@ -3907,13 +4069,30 @@ class TinyHtml_TinyHtml {
|
|
|
3907
4069
|
*
|
|
3908
4070
|
* @param {string} localName - The local name (tag) of the elements to search for.
|
|
3909
4071
|
* @param {string|null} [namespaceURI='http://www.w3.org/1999/xhtml'] - The namespace URI to search within.
|
|
4072
|
+
* @param {Document|Element} elem - Target element.
|
|
3910
4073
|
* @returns {TinyHtml[]} An array of TinyHtml instances wrapping the found elements.
|
|
3911
4074
|
*/
|
|
3912
|
-
static getByTagNameNS(localName, namespaceURI = 'http://www.w3.org/1999/xhtml') {
|
|
3913
|
-
const newEls =
|
|
4075
|
+
static getByTagNameNS(localName, namespaceURI = 'http://www.w3.org/1999/xhtml', elem = document) {
|
|
4076
|
+
const newEls = elem.getElementsByTagNameNS(namespaceURI, localName);
|
|
3914
4077
|
return TinyHtml_TinyHtml.toTinyElm([...newEls]);
|
|
3915
4078
|
}
|
|
3916
4079
|
|
|
4080
|
+
/**
|
|
4081
|
+
* Retrieves all elements with the specified local tag name within the given namespace URI,
|
|
4082
|
+
* and wraps them in TinyHtml instances.
|
|
4083
|
+
*
|
|
4084
|
+
* @param {string} localName - The local name (tag) of the elements to search for.
|
|
4085
|
+
* @param {string|null} [namespaceURI='http://www.w3.org/1999/xhtml'] - The namespace URI to search within.
|
|
4086
|
+
* @returns {TinyHtml[]} An array of TinyHtml instances wrapping the found elements.
|
|
4087
|
+
*/
|
|
4088
|
+
getElementsByTagNameNS(localName, namespaceURI = 'http://www.w3.org/1999/xhtml') {
|
|
4089
|
+
return TinyHtml_TinyHtml.getByTagNameNS(
|
|
4090
|
+
localName,
|
|
4091
|
+
namespaceURI,
|
|
4092
|
+
TinyHtml_TinyHtml._preElem(this, 'getByTagNameNS'),
|
|
4093
|
+
);
|
|
4094
|
+
}
|
|
4095
|
+
|
|
3917
4096
|
//////////////////////////////////////////////////////////////////
|
|
3918
4097
|
|
|
3919
4098
|
/**
|
|
@@ -4194,6 +4373,45 @@ class TinyHtml_TinyHtml {
|
|
|
4194
4373
|
return TinyHtml_TinyHtml._preElemTemplate(elems, where, [Element, Window], ['Element', 'Window']);
|
|
4195
4374
|
}
|
|
4196
4375
|
|
|
4376
|
+
/**
|
|
4377
|
+
* Ensures the input is returned as an array.
|
|
4378
|
+
* Useful to normalize operations across multiple or single element/window/document elements.
|
|
4379
|
+
*
|
|
4380
|
+
* @param {TinyElementAndWinAndDoc|TinyElementAndWinAndDoc[]} elems - A single element/window element or array of html elements.
|
|
4381
|
+
* @param {string} where - The method or context name where validation is being called.
|
|
4382
|
+
* @returns {ElementAndWindow[]} - Always returns an array of element/window elements.
|
|
4383
|
+
* @readonly
|
|
4384
|
+
*/
|
|
4385
|
+
static _preElemsAndWinAndDoc(elems, where) {
|
|
4386
|
+
const result = TinyHtml_TinyHtml._preElemsTemplate(
|
|
4387
|
+
elems,
|
|
4388
|
+
where,
|
|
4389
|
+
[Element, Window, Document],
|
|
4390
|
+
['Element', 'Window', 'Document'],
|
|
4391
|
+
);
|
|
4392
|
+
return result.map((elem) => (!(elem instanceof Document) ? elem : elem.documentElement));
|
|
4393
|
+
}
|
|
4394
|
+
|
|
4395
|
+
/**
|
|
4396
|
+
* Ensures the input is returned as an single element/window/document element.
|
|
4397
|
+
* Useful to normalize operations across multiple or single element/window/document elements.
|
|
4398
|
+
*
|
|
4399
|
+
* @param {TinyElementAndWinAndDoc|TinyElementAndWinAndDoc[]} elems - A single element/window element or array of html elements.
|
|
4400
|
+
* @param {string} where - The method or context name where validation is being called.
|
|
4401
|
+
* @returns {ElementAndWindow} - Always returns an single element/window element.
|
|
4402
|
+
* @readonly
|
|
4403
|
+
*/
|
|
4404
|
+
static _preElemAndWinAndDoc(elems, where) {
|
|
4405
|
+
const result = TinyHtml_TinyHtml._preElemTemplate(
|
|
4406
|
+
elems,
|
|
4407
|
+
where,
|
|
4408
|
+
[Element, Window, Document],
|
|
4409
|
+
['Element', 'Window', 'Document'],
|
|
4410
|
+
);
|
|
4411
|
+
if (result instanceof Document) return result.documentElement;
|
|
4412
|
+
return result;
|
|
4413
|
+
}
|
|
4414
|
+
|
|
4197
4415
|
/**
|
|
4198
4416
|
* Normalizes and converts one or more DOM elements (or TinyHtml instances)
|
|
4199
4417
|
* into an array of `TinyHtml` instances.
|
|
@@ -4540,12 +4758,13 @@ class TinyHtml_TinyHtml {
|
|
|
4540
4758
|
* @param {string} key - The key under which the data will be stored.
|
|
4541
4759
|
* @param {any} value - The value to store.
|
|
4542
4760
|
* @param {boolean} [isPrivate=false] - Whether to store the data in the private store.
|
|
4543
|
-
* @returns {
|
|
4761
|
+
* @returns {TinyElement}
|
|
4544
4762
|
*/
|
|
4545
4763
|
static setData(el, key, value, isPrivate = false) {
|
|
4546
4764
|
const data = TinyHtml_TinyHtml._dataSelector[!isPrivate ? 'public' : 'private']('setData', el);
|
|
4547
4765
|
if (typeof key !== 'string') throw new TypeError('The key must be a string.');
|
|
4548
4766
|
data[key] = value;
|
|
4767
|
+
return el;
|
|
4549
4768
|
}
|
|
4550
4769
|
|
|
4551
4770
|
/**
|
|
@@ -4554,7 +4773,7 @@ class TinyHtml_TinyHtml {
|
|
|
4554
4773
|
* @param {string} key - The key under which the data will be stored.
|
|
4555
4774
|
* @param {any} value - The value to store.
|
|
4556
4775
|
* @param {boolean} [isPrivate=false] - Whether to store the data in the private store.
|
|
4557
|
-
* @returns {
|
|
4776
|
+
* @returns {TinyElement}
|
|
4558
4777
|
*/
|
|
4559
4778
|
setData(key, value, isPrivate = false) {
|
|
4560
4779
|
return TinyHtml_TinyHtml.setData(this, key, value, isPrivate);
|
|
@@ -4901,18 +5120,21 @@ class TinyHtml_TinyHtml {
|
|
|
4901
5120
|
/**
|
|
4902
5121
|
* Appends child elements or strings to the end of the target element(s).
|
|
4903
5122
|
*
|
|
4904
|
-
* @param {TinyElement
|
|
5123
|
+
* @param {TinyElement} el - The target element(s) to receive children.
|
|
4905
5124
|
* @param {...(TinyNode | TinyNode[] | string)} children - The child elements or text to append.
|
|
5125
|
+
* @returns {TinyElement}
|
|
4906
5126
|
*/
|
|
4907
5127
|
static append(el, ...children) {
|
|
4908
5128
|
const elem = TinyHtml_TinyHtml._preElem(el, 'append');
|
|
4909
5129
|
elem.append(...TinyHtml_TinyHtml._appendChecker('append', ...children));
|
|
5130
|
+
return el;
|
|
4910
5131
|
}
|
|
4911
5132
|
|
|
4912
5133
|
/**
|
|
4913
5134
|
* Appends child elements or strings to the end of the target element(s).
|
|
4914
5135
|
*
|
|
4915
5136
|
* @param {...(TinyNode | TinyNode[] | string)} children - The child elements or text to append.
|
|
5137
|
+
* @returns {TinyElement}
|
|
4916
5138
|
*/
|
|
4917
5139
|
append(...children) {
|
|
4918
5140
|
return TinyHtml_TinyHtml.append(this, ...children);
|
|
@@ -4921,18 +5143,21 @@ class TinyHtml_TinyHtml {
|
|
|
4921
5143
|
/**
|
|
4922
5144
|
* Prepends child elements or strings to the beginning of the target element(s).
|
|
4923
5145
|
*
|
|
4924
|
-
* @param {TinyElement
|
|
5146
|
+
* @param {TinyElement} el - The target element(s) to receive children.
|
|
4925
5147
|
* @param {...(TinyNode | TinyNode[] | string)} children - The child elements or text to prepend.
|
|
5148
|
+
* @returns {TinyElement}
|
|
4926
5149
|
*/
|
|
4927
5150
|
static prepend(el, ...children) {
|
|
4928
5151
|
const elem = TinyHtml_TinyHtml._preElem(el, 'prepend');
|
|
4929
5152
|
elem.prepend(...TinyHtml_TinyHtml._appendChecker('prepend', ...children));
|
|
5153
|
+
return el;
|
|
4930
5154
|
}
|
|
4931
5155
|
|
|
4932
5156
|
/**
|
|
4933
5157
|
* Prepends child elements or strings to the beginning of the target element(s).
|
|
4934
5158
|
*
|
|
4935
5159
|
* @param {...(TinyNode | TinyNode[] | string)} children - The child elements or text to prepend.
|
|
5160
|
+
* @returns {TinyElement}
|
|
4936
5161
|
*/
|
|
4937
5162
|
prepend(...children) {
|
|
4938
5163
|
return TinyHtml_TinyHtml.prepend(this, ...children);
|
|
@@ -4941,18 +5166,21 @@ class TinyHtml_TinyHtml {
|
|
|
4941
5166
|
/**
|
|
4942
5167
|
* Inserts elements or strings immediately before the target element(s) in the DOM.
|
|
4943
5168
|
*
|
|
4944
|
-
* @param {TinyElement
|
|
5169
|
+
* @param {TinyElement} el - The target element(s) before which new content is inserted.
|
|
4945
5170
|
* @param {...(TinyNode | TinyNode[] | string)} children - Elements or text to insert before the target.
|
|
5171
|
+
* @returns {TinyElement}
|
|
4946
5172
|
*/
|
|
4947
5173
|
static before(el, ...children) {
|
|
4948
5174
|
const elem = TinyHtml_TinyHtml._preElem(el, 'before');
|
|
4949
5175
|
elem.before(...TinyHtml_TinyHtml._appendChecker('before', ...children));
|
|
5176
|
+
return el;
|
|
4950
5177
|
}
|
|
4951
5178
|
|
|
4952
5179
|
/**
|
|
4953
5180
|
* Inserts elements or strings immediately before the target element(s) in the DOM.
|
|
4954
5181
|
*
|
|
4955
5182
|
* @param {...(TinyNode | TinyNode[] | string)} children - Elements or text to insert before the target.
|
|
5183
|
+
* @returns {TinyElement}
|
|
4956
5184
|
*/
|
|
4957
5185
|
before(...children) {
|
|
4958
5186
|
return TinyHtml_TinyHtml.before(this, ...children);
|
|
@@ -4961,18 +5189,21 @@ class TinyHtml_TinyHtml {
|
|
|
4961
5189
|
/**
|
|
4962
5190
|
* Inserts elements or strings immediately after the target element(s) in the DOM.
|
|
4963
5191
|
*
|
|
4964
|
-
* @param {TinyElement
|
|
5192
|
+
* @param {TinyElement} el - The target element(s) after which new content is inserted.
|
|
4965
5193
|
* @param {...(TinyNode | TinyNode[] | string)} children - Elements or text to insert after the target.
|
|
5194
|
+
* @returns {TinyElement}
|
|
4966
5195
|
*/
|
|
4967
5196
|
static after(el, ...children) {
|
|
4968
5197
|
const elem = TinyHtml_TinyHtml._preElem(el, 'after');
|
|
4969
5198
|
elem.after(...TinyHtml_TinyHtml._appendChecker('after', ...children));
|
|
5199
|
+
return el;
|
|
4970
5200
|
}
|
|
4971
5201
|
|
|
4972
5202
|
/**
|
|
4973
5203
|
* Inserts elements or strings immediately after the target element(s) in the DOM.
|
|
4974
5204
|
*
|
|
4975
5205
|
* @param {...(TinyNode | TinyNode[] | string)} children - Elements or text to insert after the target.
|
|
5206
|
+
* @returns {TinyElement}
|
|
4976
5207
|
*/
|
|
4977
5208
|
after(...children) {
|
|
4978
5209
|
return TinyHtml_TinyHtml.after(this, ...children);
|
|
@@ -4981,18 +5212,21 @@ class TinyHtml_TinyHtml {
|
|
|
4981
5212
|
/**
|
|
4982
5213
|
* Replaces the target element(s) in the DOM with new elements or text.
|
|
4983
5214
|
*
|
|
4984
|
-
* @param {TinyElement
|
|
5215
|
+
* @param {TinyElement} el - The element(s) to be replaced.
|
|
4985
5216
|
* @param {...(TinyNode | TinyNode[] | string)} newNodes - New elements or text to replace the target.
|
|
5217
|
+
* @returns {TinyElement}
|
|
4986
5218
|
*/
|
|
4987
5219
|
static replaceWith(el, ...newNodes) {
|
|
4988
5220
|
const elem = TinyHtml_TinyHtml._preElem(el, 'replaceWith');
|
|
4989
5221
|
elem.replaceWith(...TinyHtml_TinyHtml._appendChecker('replaceWith', ...newNodes));
|
|
5222
|
+
return el;
|
|
4990
5223
|
}
|
|
4991
5224
|
|
|
4992
5225
|
/**
|
|
4993
5226
|
* Replaces the target element(s) in the DOM with new elements or text.
|
|
4994
5227
|
*
|
|
4995
5228
|
* @param {...(TinyNode | TinyNode[] | string)} newNodes - New elements or text to replace the target.
|
|
5229
|
+
* @returns {TinyElement}
|
|
4996
5230
|
*/
|
|
4997
5231
|
replaceWith(...newNodes) {
|
|
4998
5232
|
return TinyHtml_TinyHtml.replaceWith(this, ...newNodes);
|
|
@@ -5003,6 +5237,7 @@ class TinyHtml_TinyHtml {
|
|
|
5003
5237
|
*
|
|
5004
5238
|
* @param {TinyNode | TinyNode[]} el - The element(s) to append.
|
|
5005
5239
|
* @param {TinyNode | TinyNode[]} targets - Target element(s) where content will be appended.
|
|
5240
|
+
* @returns {TinyNode|TinyNode[]}
|
|
5006
5241
|
*/
|
|
5007
5242
|
static appendTo(el, targets) {
|
|
5008
5243
|
const elems = TinyHtml_TinyHtml._preNodeElems(el, 'appendTo');
|
|
@@ -5012,12 +5247,14 @@ class TinyHtml_TinyHtml {
|
|
|
5012
5247
|
target.appendChild(i === tars.length - 1 ? elem : elem.cloneNode(true)),
|
|
5013
5248
|
);
|
|
5014
5249
|
});
|
|
5250
|
+
return el;
|
|
5015
5251
|
}
|
|
5016
5252
|
|
|
5017
5253
|
/**
|
|
5018
5254
|
* Appends the given element(s) to each target element in sequence.
|
|
5019
5255
|
*
|
|
5020
5256
|
* @param {TinyNode | TinyNode[]} targets - Target element(s) where content will be appended.
|
|
5257
|
+
* @returns {TinyNode|TinyNode[]}
|
|
5021
5258
|
*/
|
|
5022
5259
|
appendTo(targets) {
|
|
5023
5260
|
return TinyHtml_TinyHtml.appendTo(this, targets);
|
|
@@ -5028,6 +5265,7 @@ class TinyHtml_TinyHtml {
|
|
|
5028
5265
|
*
|
|
5029
5266
|
* @param {TinyElement | TinyElement[]} el - The element(s) to prepend.
|
|
5030
5267
|
* @param {TinyElement | TinyElement[]} targets - Target element(s) where content will be prepended.
|
|
5268
|
+
* @returns {TinyElement|TinyElement[]}
|
|
5031
5269
|
*/
|
|
5032
5270
|
static prependTo(el, targets) {
|
|
5033
5271
|
const elems = TinyHtml_TinyHtml._preElems(el, 'prependTo');
|
|
@@ -5038,12 +5276,14 @@ class TinyHtml_TinyHtml {
|
|
|
5038
5276
|
.reverse()
|
|
5039
5277
|
.forEach((elem) => target.prepend(i === tars.length - 1 ? elem : elem.cloneNode(true)));
|
|
5040
5278
|
});
|
|
5279
|
+
return el;
|
|
5041
5280
|
}
|
|
5042
5281
|
|
|
5043
5282
|
/**
|
|
5044
5283
|
* Prepends the given element(s) to each target element in sequence.
|
|
5045
5284
|
*
|
|
5046
5285
|
* @param {TinyElement | TinyElement[]} targets - Target element(s) where content will be prepended.
|
|
5286
|
+
* @returns {TinyElement|TinyElement[]}
|
|
5047
5287
|
*/
|
|
5048
5288
|
prependTo(targets) {
|
|
5049
5289
|
return TinyHtml_TinyHtml.prependTo(this, targets);
|
|
@@ -5055,6 +5295,7 @@ class TinyHtml_TinyHtml {
|
|
|
5055
5295
|
* @param {TinyNode | TinyNode[]} el - The element(s) to insert.
|
|
5056
5296
|
* @param {TinyNode | TinyNode[]} target - The reference element where insertion happens.
|
|
5057
5297
|
* @param {TinyNode | TinyNode[] | null} [child=null] - Optional child to insert before, defaults to target.
|
|
5298
|
+
* @returns {TinyNode|TinyNode[]}
|
|
5058
5299
|
*/
|
|
5059
5300
|
static insertBefore(el, target, child = null) {
|
|
5060
5301
|
const elem = TinyHtml_TinyHtml._preNodeElem(el, 'insertBefore');
|
|
@@ -5062,6 +5303,7 @@ class TinyHtml_TinyHtml {
|
|
|
5062
5303
|
const childNode = TinyHtml_TinyHtml._preNodeElemWithNull(child, 'insertBefore');
|
|
5063
5304
|
if (!targ.parentNode) throw new Error('');
|
|
5064
5305
|
targ.parentNode.insertBefore(elem, childNode || targ);
|
|
5306
|
+
return el;
|
|
5065
5307
|
}
|
|
5066
5308
|
|
|
5067
5309
|
/**
|
|
@@ -5069,6 +5311,7 @@ class TinyHtml_TinyHtml {
|
|
|
5069
5311
|
*
|
|
5070
5312
|
* @param {TinyNode | TinyNode[]} target - The reference element where insertion happens.
|
|
5071
5313
|
* @param {TinyNode | TinyNode[] | null} [child=null] - Optional child to insert before, defaults to target.
|
|
5314
|
+
* @returns {TinyNode|TinyNode[]}
|
|
5072
5315
|
*/
|
|
5073
5316
|
insertBefore(target, child) {
|
|
5074
5317
|
return TinyHtml_TinyHtml.insertBefore(this, target, child);
|
|
@@ -5080,6 +5323,7 @@ class TinyHtml_TinyHtml {
|
|
|
5080
5323
|
* @param {TinyNode | TinyNode[]} el - The element(s) to insert.
|
|
5081
5324
|
* @param {TinyNode | TinyNode[]} target - The reference element where insertion happens.
|
|
5082
5325
|
* @param {TinyNode | TinyNode[] | null} [child=null] - Optional child to insert after, defaults to target.
|
|
5326
|
+
* @returns {TinyNode|TinyNode[]}
|
|
5083
5327
|
*/
|
|
5084
5328
|
static insertAfter(el, target, child = null) {
|
|
5085
5329
|
const elem = TinyHtml_TinyHtml._preNodeElem(el, 'insertAfter');
|
|
@@ -5087,6 +5331,7 @@ class TinyHtml_TinyHtml {
|
|
|
5087
5331
|
const childNode = TinyHtml_TinyHtml._preNodeElemWithNull(child, 'insertBefore');
|
|
5088
5332
|
if (!targ.parentNode) throw new Error('');
|
|
5089
5333
|
targ.parentNode.insertBefore(elem, childNode || targ.nextSibling);
|
|
5334
|
+
return el;
|
|
5090
5335
|
}
|
|
5091
5336
|
|
|
5092
5337
|
/**
|
|
@@ -5094,6 +5339,7 @@ class TinyHtml_TinyHtml {
|
|
|
5094
5339
|
*
|
|
5095
5340
|
* @param {TinyNode | TinyNode[]} target - The reference element where insertion happens.
|
|
5096
5341
|
* @param {TinyNode | TinyNode[] | null} [child=null] - Optional child to insert after, defaults to target.
|
|
5342
|
+
* @returns {TinyNode|TinyNode[]}
|
|
5097
5343
|
*/
|
|
5098
5344
|
insertAfter(target, child) {
|
|
5099
5345
|
return TinyHtml_TinyHtml.insertAfter(this, target, child);
|
|
@@ -5105,6 +5351,7 @@ class TinyHtml_TinyHtml {
|
|
|
5105
5351
|
*
|
|
5106
5352
|
* @param {TinyNode | TinyNode[]} el - The new element(s) to insert.
|
|
5107
5353
|
* @param {TinyNode | TinyNode[]} targets - The elements to be replaced.
|
|
5354
|
+
* @returns {TinyNode|TinyNode[]}
|
|
5108
5355
|
*/
|
|
5109
5356
|
static replaceAll(el, targets) {
|
|
5110
5357
|
const elems = TinyHtml_TinyHtml._preNodeElems(el, 'replaceAll');
|
|
@@ -5116,6 +5363,7 @@ class TinyHtml_TinyHtml {
|
|
|
5116
5363
|
parent.replaceChild(i === tars.length - 1 ? elem : elem.cloneNode(true), target);
|
|
5117
5364
|
});
|
|
5118
5365
|
});
|
|
5366
|
+
return el;
|
|
5119
5367
|
}
|
|
5120
5368
|
|
|
5121
5369
|
/**
|
|
@@ -5123,6 +5371,7 @@ class TinyHtml_TinyHtml {
|
|
|
5123
5371
|
* If multiple targets exist, the inserted elements are cloned accordingly.
|
|
5124
5372
|
*
|
|
5125
5373
|
* @param {TinyNode | TinyNode[]} targets - The elements to be replaced.
|
|
5374
|
+
* @returns {TinyNode|TinyNode[]}
|
|
5126
5375
|
*/
|
|
5127
5376
|
replaceAll(targets) {
|
|
5128
5377
|
return TinyHtml_TinyHtml.replaceAll(this, targets);
|
|
@@ -5146,7 +5395,12 @@ class TinyHtml_TinyHtml {
|
|
|
5146
5395
|
throw new Error(
|
|
5147
5396
|
`[TinyHtml] You are trying to put a TinyHtml inside another TinyHtml in constructor.`,
|
|
5148
5397
|
);
|
|
5149
|
-
if (
|
|
5398
|
+
if (
|
|
5399
|
+
!(el instanceof Element) &&
|
|
5400
|
+
!(el instanceof Window) &&
|
|
5401
|
+
!(el instanceof Document) &&
|
|
5402
|
+
!(el instanceof Text)
|
|
5403
|
+
)
|
|
5150
5404
|
throw new Error(`[TinyHtml] Invalid Target in constructor.`);
|
|
5151
5405
|
this.#el = el;
|
|
5152
5406
|
}
|
|
@@ -5596,6 +5850,7 @@ class TinyHtml_TinyHtml {
|
|
|
5596
5850
|
* @param {TinyHtmlElement|TinyHtmlElement[]} el - The element to inspect.
|
|
5597
5851
|
* @param {string|Object} prop - The property name or an object with key-value pairs
|
|
5598
5852
|
* @param {string|null} [value=null] - The value to set (if `prop` is a string)
|
|
5853
|
+
* @returns {TinyHtmlElement|TinyHtmlElement[]}
|
|
5599
5854
|
*/
|
|
5600
5855
|
static setStyle(el, prop, value = null) {
|
|
5601
5856
|
TinyHtml_TinyHtml._preHtmlElems(el, 'setStyle').forEach((elem) => {
|
|
@@ -5608,6 +5863,7 @@ class TinyHtml_TinyHtml {
|
|
|
5608
5863
|
}
|
|
5609
5864
|
} else elem.style.setProperty(TinyHtml_TinyHtml.toStyleKc(prop), value);
|
|
5610
5865
|
});
|
|
5866
|
+
return el;
|
|
5611
5867
|
}
|
|
5612
5868
|
|
|
5613
5869
|
/**
|
|
@@ -5618,6 +5874,7 @@ class TinyHtml_TinyHtml {
|
|
|
5618
5874
|
*
|
|
5619
5875
|
* @param {string|Object} prop - The property name or an object with key-value pairs
|
|
5620
5876
|
* @param {string|null} [value=null] - The value to set (if `prop` is a string)
|
|
5877
|
+
* @returns {TinyHtmlElement|TinyHtmlElement[]}
|
|
5621
5878
|
*/
|
|
5622
5879
|
setStyle(prop, value) {
|
|
5623
5880
|
return TinyHtml_TinyHtml.setStyle(this, prop, value);
|
|
@@ -5713,6 +5970,7 @@ class TinyHtml_TinyHtml {
|
|
|
5713
5970
|
*
|
|
5714
5971
|
* @param {TinyHtmlElement|TinyHtmlElement[]} el - A single element or an array of elements.
|
|
5715
5972
|
* @param {string|string[]} prop - A property name or an array of property names to remove.
|
|
5973
|
+
* @returns {TinyHtmlElement|TinyHtmlElement[]}
|
|
5716
5974
|
*/
|
|
5717
5975
|
static removeStyle(el, prop) {
|
|
5718
5976
|
TinyHtml_TinyHtml._preHtmlElems(el, 'removeStyle').forEach((elem) => {
|
|
@@ -5722,12 +5980,14 @@ class TinyHtml_TinyHtml {
|
|
|
5722
5980
|
}
|
|
5723
5981
|
} else elem.style.removeProperty(TinyHtml_TinyHtml.toStyleKc(prop));
|
|
5724
5982
|
});
|
|
5983
|
+
return el;
|
|
5725
5984
|
}
|
|
5726
5985
|
|
|
5727
5986
|
/**
|
|
5728
5987
|
* Removes one or more inline CSS properties from the given element(s).
|
|
5729
5988
|
*
|
|
5730
5989
|
* @param {string|string[]} prop - A property name or an array of property names to remove.
|
|
5990
|
+
* @returns {TinyHtmlElement|TinyHtmlElement[]}
|
|
5731
5991
|
*/
|
|
5732
5992
|
removeStyle(prop) {
|
|
5733
5993
|
return TinyHtml_TinyHtml.removeStyle(this, prop);
|
|
@@ -5742,6 +6002,7 @@ class TinyHtml_TinyHtml {
|
|
|
5742
6002
|
* @param {string} prop - The CSS property to toggle.
|
|
5743
6003
|
* @param {string} val1 - The first value (used as "current" check).
|
|
5744
6004
|
* @param {string} val2 - The second value (used as the "alternative").
|
|
6005
|
+
* @returns {TinyHtmlElement|TinyHtmlElement[]}
|
|
5745
6006
|
*/
|
|
5746
6007
|
static toggleStyle(el, prop, val1, val2) {
|
|
5747
6008
|
TinyHtml_TinyHtml._preHtmlElems(el, 'toggleStyle').forEach((elem) => {
|
|
@@ -5749,6 +6010,7 @@ class TinyHtml_TinyHtml {
|
|
|
5749
6010
|
const newVal = current === TinyHtml_TinyHtml.toStyleKc(val1) ? val2 : val1;
|
|
5750
6011
|
TinyHtml_TinyHtml.setStyle(elem, prop, newVal);
|
|
5751
6012
|
});
|
|
6013
|
+
return el;
|
|
5752
6014
|
}
|
|
5753
6015
|
|
|
5754
6016
|
/**
|
|
@@ -5759,6 +6021,7 @@ class TinyHtml_TinyHtml {
|
|
|
5759
6021
|
* @param {string} prop - The CSS property to toggle.
|
|
5760
6022
|
* @param {string} val1 - The first value (used as "current" check).
|
|
5761
6023
|
* @param {string} val2 - The second value (used as the "alternative").
|
|
6024
|
+
* @returns {TinyHtmlElement|TinyHtmlElement[]}
|
|
5762
6025
|
*/
|
|
5763
6026
|
toggleStyle(prop, val1, val2) {
|
|
5764
6027
|
return TinyHtml_TinyHtml.toggleStyle(this, prop, val1, val2);
|
|
@@ -5768,14 +6031,16 @@ class TinyHtml_TinyHtml {
|
|
|
5768
6031
|
* Removes all inline styles (`style` attribute) from the given element(s).
|
|
5769
6032
|
*
|
|
5770
6033
|
* @param {TinyElement|TinyElement[]} el - A single element or an array of elements.
|
|
6034
|
+
* @returns {TinyElement|TinyElement[]}
|
|
5771
6035
|
*/
|
|
5772
6036
|
static clearStyle(el) {
|
|
5773
6037
|
TinyHtml_TinyHtml._preElems(el, 'clearStyle').forEach((elem) => elem.removeAttribute('style'));
|
|
6038
|
+
return el;
|
|
5774
6039
|
}
|
|
5775
6040
|
|
|
5776
6041
|
/**
|
|
5777
6042
|
* Removes all inline styles (`style` attribute) from the given element(s).
|
|
5778
|
-
*
|
|
6043
|
+
* @returns {TinyElement|TinyElement[]}
|
|
5779
6044
|
*/
|
|
5780
6045
|
clearStyle() {
|
|
5781
6046
|
return TinyHtml_TinyHtml.clearStyle(this);
|
|
@@ -5787,14 +6052,17 @@ class TinyHtml_TinyHtml {
|
|
|
5787
6052
|
* Focus the element.
|
|
5788
6053
|
*
|
|
5789
6054
|
* @param {TinyHtmlElement} el - The element or a selector string.
|
|
6055
|
+
* @returns {TinyHtmlElement}
|
|
5790
6056
|
*/
|
|
5791
6057
|
static focus(el) {
|
|
5792
6058
|
const elem = TinyHtml_TinyHtml._preHtmlElem(el, 'focus');
|
|
5793
6059
|
elem.focus();
|
|
6060
|
+
return el;
|
|
5794
6061
|
}
|
|
5795
6062
|
|
|
5796
6063
|
/**
|
|
5797
6064
|
* Focus the element.
|
|
6065
|
+
* @returns {TinyHtmlElement}
|
|
5798
6066
|
*/
|
|
5799
6067
|
focus() {
|
|
5800
6068
|
return TinyHtml_TinyHtml.focus(this);
|
|
@@ -5804,19 +6072,46 @@ class TinyHtml_TinyHtml {
|
|
|
5804
6072
|
* Blur the element.
|
|
5805
6073
|
*
|
|
5806
6074
|
* @param {TinyHtmlElement} el - The element or a selector string.
|
|
6075
|
+
* @returns {TinyHtmlElement}
|
|
5807
6076
|
*/
|
|
5808
6077
|
static blur(el) {
|
|
5809
6078
|
const elem = TinyHtml_TinyHtml._preHtmlElem(el, 'blur');
|
|
5810
6079
|
elem.blur();
|
|
6080
|
+
return el;
|
|
5811
6081
|
}
|
|
5812
6082
|
|
|
5813
6083
|
/**
|
|
5814
6084
|
* Blur the element.
|
|
6085
|
+
* @returns {TinyHtmlElement}
|
|
5815
6086
|
*/
|
|
5816
6087
|
blur() {
|
|
5817
6088
|
return TinyHtml_TinyHtml.blur(this);
|
|
5818
6089
|
}
|
|
5819
6090
|
|
|
6091
|
+
/**
|
|
6092
|
+
* Interprets a value as a boolean `true` if it matches a common truthy representation.
|
|
6093
|
+
*
|
|
6094
|
+
* This method checks if the input is any of the common forms used to represent `true`,
|
|
6095
|
+
* such as the string `'true'`, `'1'`, `'on'`, the boolean `true`, or the number `1`.
|
|
6096
|
+
*
|
|
6097
|
+
* @param {string|boolean|number} [value] - The value to interpret as boolean.
|
|
6098
|
+
* @returns {boolean} `true` if the value represents a truthy state, otherwise `false`.
|
|
6099
|
+
*/
|
|
6100
|
+
static boolCheck(value) {
|
|
6101
|
+
if (
|
|
6102
|
+
typeof value !== 'undefined' &&
|
|
6103
|
+
(value === 'true' ||
|
|
6104
|
+
value === '1' ||
|
|
6105
|
+
value === true ||
|
|
6106
|
+
value === 'on' ||
|
|
6107
|
+
(typeof value === 'number' && value > 0))
|
|
6108
|
+
) {
|
|
6109
|
+
return true;
|
|
6110
|
+
} else {
|
|
6111
|
+
return false;
|
|
6112
|
+
}
|
|
6113
|
+
}
|
|
6114
|
+
|
|
5820
6115
|
//////////////////////////////////////////////////////////////////////
|
|
5821
6116
|
|
|
5822
6117
|
/**
|
|
@@ -5825,7 +6120,7 @@ class TinyHtml_TinyHtml {
|
|
|
5825
6120
|
*/
|
|
5826
6121
|
static setWinScrollTop(value) {
|
|
5827
6122
|
if (typeof value !== 'number') throw new TypeError('The value must be a number.');
|
|
5828
|
-
|
|
6123
|
+
TinyHtml_TinyHtml.setScrollTop(window, value);
|
|
5829
6124
|
}
|
|
5830
6125
|
|
|
5831
6126
|
/**
|
|
@@ -5834,7 +6129,7 @@ class TinyHtml_TinyHtml {
|
|
|
5834
6129
|
*/
|
|
5835
6130
|
static setWinScrollLeft(value) {
|
|
5836
6131
|
if (typeof value !== 'number') throw new TypeError('The value must be a number.');
|
|
5837
|
-
|
|
6132
|
+
TinyHtml_TinyHtml.setScrollLeft(window, value);
|
|
5838
6133
|
}
|
|
5839
6134
|
|
|
5840
6135
|
/**
|
|
@@ -5869,16 +6164,40 @@ class TinyHtml_TinyHtml {
|
|
|
5869
6164
|
return window.innerWidth || document.documentElement.clientWidth;
|
|
5870
6165
|
}
|
|
5871
6166
|
|
|
6167
|
+
/**
|
|
6168
|
+
* Checks if the page is currently scrolled to the very top.
|
|
6169
|
+
*
|
|
6170
|
+
* This method compares the current vertical scroll position with the total document height.
|
|
6171
|
+
* It's useful for detecting if the user has reached the top of the page.
|
|
6172
|
+
*
|
|
6173
|
+
* @returns {boolean} `true` if the page is scrolled to the top, otherwise `false`.
|
|
6174
|
+
*/
|
|
6175
|
+
static isPageTop() {
|
|
6176
|
+
return window.scrollY === 0;
|
|
6177
|
+
}
|
|
6178
|
+
|
|
6179
|
+
/**
|
|
6180
|
+
* Checks if the page is currently scrolled to the very bottom.
|
|
6181
|
+
*
|
|
6182
|
+
* This method uses the `scrollY` and `innerHeight` properties to determine if the
|
|
6183
|
+
* user has reached the end of the document.
|
|
6184
|
+
*
|
|
6185
|
+
* @returns {boolean} `true` if the page is scrolled to the bottom, otherwise `false`.
|
|
6186
|
+
*/
|
|
6187
|
+
static isPageBottom() {
|
|
6188
|
+
return window.innerHeight + window.scrollY >= document.body.offsetHeight;
|
|
6189
|
+
}
|
|
6190
|
+
|
|
5872
6191
|
/**
|
|
5873
6192
|
* Gets the width or height of an element based on the box model.
|
|
5874
|
-
* @param {
|
|
6193
|
+
* @param {TinyElementAndWinAndDoc} el - The element or window.
|
|
5875
6194
|
* @param {"width"|"height"} type - Dimension type.
|
|
5876
6195
|
* @param {"content"|"padding"|"border"|"margin"} [extra='content'] - Box model context.
|
|
5877
6196
|
* @returns {number} - Computed dimension.
|
|
5878
6197
|
* @throws {TypeError} If `type` or `extra` is not a string.
|
|
5879
6198
|
*/
|
|
5880
6199
|
static getDimension(el, type, extra = 'content') {
|
|
5881
|
-
const elem = TinyHtml_TinyHtml.
|
|
6200
|
+
const elem = TinyHtml_TinyHtml._preElemAndWinAndDoc(el, 'getDimension');
|
|
5882
6201
|
if (typeof type !== 'string') throw new TypeError('The type must be a string.');
|
|
5883
6202
|
if (typeof extra !== 'string') throw new TypeError('The extra must be a string.');
|
|
5884
6203
|
|
|
@@ -5966,17 +6285,20 @@ class TinyHtml_TinyHtml {
|
|
|
5966
6285
|
* @param {TinyHtmlElement} el - Target element.
|
|
5967
6286
|
* @param {string|number} value - Height value.
|
|
5968
6287
|
* @throws {TypeError} If `value` is neither a string nor number.
|
|
6288
|
+
* @returns {TinyHtmlElement}
|
|
5969
6289
|
*/
|
|
5970
6290
|
static setHeight(el, value) {
|
|
5971
6291
|
const elem = TinyHtml_TinyHtml._preHtmlElem(el, 'setHeight');
|
|
5972
6292
|
if (typeof value !== 'number' && typeof value !== 'string')
|
|
5973
6293
|
throw new TypeError('The value must be a string or number.');
|
|
5974
6294
|
elem.style.height = typeof value === 'number' ? `${value}px` : value;
|
|
6295
|
+
return el;
|
|
5975
6296
|
}
|
|
5976
6297
|
|
|
5977
6298
|
/**
|
|
5978
6299
|
* Sets the height of the element.
|
|
5979
6300
|
* @param {string|number} value - Height value.
|
|
6301
|
+
* @returns {TinyHtmlElement}
|
|
5980
6302
|
*/
|
|
5981
6303
|
setHeight(value) {
|
|
5982
6304
|
return TinyHtml_TinyHtml.setHeight(this, value);
|
|
@@ -5987,17 +6309,20 @@ class TinyHtml_TinyHtml {
|
|
|
5987
6309
|
* @param {TinyHtmlElement} el - Target element.
|
|
5988
6310
|
* @param {string|number} value - Width value.
|
|
5989
6311
|
* @throws {TypeError} If `value` is neither a string nor number.
|
|
6312
|
+
* @returns {TinyHtmlElement}
|
|
5990
6313
|
*/
|
|
5991
6314
|
static setWidth(el, value) {
|
|
5992
6315
|
const elem = TinyHtml_TinyHtml._preHtmlElem(el, 'setWidth');
|
|
5993
6316
|
if (typeof value !== 'number' && typeof value !== 'string')
|
|
5994
6317
|
throw new TypeError('The value must be a string or number.');
|
|
5995
6318
|
elem.style.width = typeof value === 'number' ? `${value}px` : value;
|
|
6319
|
+
return el;
|
|
5996
6320
|
}
|
|
5997
6321
|
|
|
5998
6322
|
/**
|
|
5999
6323
|
* Sets the width of the element.
|
|
6000
6324
|
* @param {string|number} value - Width value.
|
|
6325
|
+
* @returns {TinyHtmlElement}
|
|
6001
6326
|
*/
|
|
6002
6327
|
setWidth(value) {
|
|
6003
6328
|
return TinyHtml_TinyHtml.setWidth(this, value);
|
|
@@ -6005,11 +6330,11 @@ class TinyHtml_TinyHtml {
|
|
|
6005
6330
|
|
|
6006
6331
|
/**
|
|
6007
6332
|
* Returns content box height.
|
|
6008
|
-
* @param {
|
|
6333
|
+
* @param {TinyElementAndWinAndDoc} el - Target element.
|
|
6009
6334
|
* @returns {number}
|
|
6010
6335
|
*/
|
|
6011
6336
|
static height(el) {
|
|
6012
|
-
const elem = TinyHtml_TinyHtml.
|
|
6337
|
+
const elem = TinyHtml_TinyHtml._preElemAndWinAndDoc(el, 'height');
|
|
6013
6338
|
return TinyHtml_TinyHtml.getDimension(elem, 'height', 'content');
|
|
6014
6339
|
}
|
|
6015
6340
|
|
|
@@ -6023,11 +6348,11 @@ class TinyHtml_TinyHtml {
|
|
|
6023
6348
|
|
|
6024
6349
|
/**
|
|
6025
6350
|
* Returns content box width.
|
|
6026
|
-
* @param {
|
|
6351
|
+
* @param {TinyElementAndWinAndDoc} el - Target element.
|
|
6027
6352
|
* @returns {number}
|
|
6028
6353
|
*/
|
|
6029
6354
|
static width(el) {
|
|
6030
|
-
const elem = TinyHtml_TinyHtml.
|
|
6355
|
+
const elem = TinyHtml_TinyHtml._preElemAndWinAndDoc(el, 'width');
|
|
6031
6356
|
return TinyHtml_TinyHtml.getDimension(elem, 'width', 'content');
|
|
6032
6357
|
}
|
|
6033
6358
|
|
|
@@ -6041,11 +6366,11 @@ class TinyHtml_TinyHtml {
|
|
|
6041
6366
|
|
|
6042
6367
|
/**
|
|
6043
6368
|
* Returns padding box height.
|
|
6044
|
-
* @param {
|
|
6369
|
+
* @param {TinyElementAndWinAndDoc} el - Target element.
|
|
6045
6370
|
* @returns {number}
|
|
6046
6371
|
*/
|
|
6047
6372
|
static innerHeight(el) {
|
|
6048
|
-
const elem = TinyHtml_TinyHtml.
|
|
6373
|
+
const elem = TinyHtml_TinyHtml._preElemAndWinAndDoc(el, 'innerHeight');
|
|
6049
6374
|
return TinyHtml_TinyHtml.getDimension(elem, 'height', 'padding');
|
|
6050
6375
|
}
|
|
6051
6376
|
|
|
@@ -6059,11 +6384,11 @@ class TinyHtml_TinyHtml {
|
|
|
6059
6384
|
|
|
6060
6385
|
/**
|
|
6061
6386
|
* Returns padding box width.
|
|
6062
|
-
* @param {
|
|
6387
|
+
* @param {TinyElementAndWinAndDoc} el - Target element.
|
|
6063
6388
|
* @returns {number}
|
|
6064
6389
|
*/
|
|
6065
6390
|
static innerWidth(el) {
|
|
6066
|
-
const elem = TinyHtml_TinyHtml.
|
|
6391
|
+
const elem = TinyHtml_TinyHtml._preElemAndWinAndDoc(el, 'innerWidth');
|
|
6067
6392
|
return TinyHtml_TinyHtml.getDimension(elem, 'width', 'padding');
|
|
6068
6393
|
}
|
|
6069
6394
|
|
|
@@ -6077,14 +6402,14 @@ class TinyHtml_TinyHtml {
|
|
|
6077
6402
|
|
|
6078
6403
|
/**
|
|
6079
6404
|
* Returns outer height of the element, optionally including margin.
|
|
6080
|
-
* @param {
|
|
6405
|
+
* @param {TinyElementAndWinAndDoc} el - Target element.
|
|
6081
6406
|
* @param {boolean} [includeMargin=false] - Whether to include margin.
|
|
6082
6407
|
* @returns {number}
|
|
6083
6408
|
*/
|
|
6084
6409
|
static outerHeight(el, includeMargin = false) {
|
|
6085
6410
|
if (typeof includeMargin !== 'boolean')
|
|
6086
6411
|
throw new TypeError('The "includeMargin" must be a boolean.');
|
|
6087
|
-
const elem = TinyHtml_TinyHtml.
|
|
6412
|
+
const elem = TinyHtml_TinyHtml._preElemAndWinAndDoc(el, 'outerHeight');
|
|
6088
6413
|
return TinyHtml_TinyHtml.getDimension(elem, 'height', includeMargin ? 'margin' : 'border');
|
|
6089
6414
|
}
|
|
6090
6415
|
|
|
@@ -6099,14 +6424,14 @@ class TinyHtml_TinyHtml {
|
|
|
6099
6424
|
|
|
6100
6425
|
/**
|
|
6101
6426
|
* Returns outer width of the element, optionally including margin.
|
|
6102
|
-
* @param {
|
|
6427
|
+
* @param {TinyElementAndWinAndDoc} el - Target element.
|
|
6103
6428
|
* @param {boolean} [includeMargin=false] - Whether to include margin.
|
|
6104
6429
|
* @returns {number}
|
|
6105
6430
|
*/
|
|
6106
6431
|
static outerWidth(el, includeMargin = false) {
|
|
6107
6432
|
if (typeof includeMargin !== 'boolean')
|
|
6108
6433
|
throw new TypeError('The "includeMargin" must be a boolean.');
|
|
6109
|
-
const elem = TinyHtml_TinyHtml.
|
|
6434
|
+
const elem = TinyHtml_TinyHtml._preElemAndWinAndDoc(el, 'outerWidth');
|
|
6110
6435
|
return TinyHtml_TinyHtml.getDimension(elem, 'width', includeMargin ? 'margin' : 'border');
|
|
6111
6436
|
}
|
|
6112
6437
|
|
|
@@ -6121,6 +6446,30 @@ class TinyHtml_TinyHtml {
|
|
|
6121
6446
|
|
|
6122
6447
|
//////////////////////////////////////////////////
|
|
6123
6448
|
|
|
6449
|
+
/**
|
|
6450
|
+
* Applies an animation to one or multiple TinyElement instances.
|
|
6451
|
+
*
|
|
6452
|
+
* @param {TinyElement|TinyElement[]} el - A single TinyElement or an array of TinyElements to animate.
|
|
6453
|
+
* @param {Keyframe[] | PropertyIndexedKeyframes | null} keyframes - The keyframes used to define the animation.
|
|
6454
|
+
* @param {number | KeyframeAnimationOptions} [ops] - Timing or configuration options for the animation.
|
|
6455
|
+
* @returns {TinyElement|TinyElement[]}
|
|
6456
|
+
*/
|
|
6457
|
+
static animate(el, keyframes, ops) {
|
|
6458
|
+
TinyHtml_TinyHtml._preElems(el, 'animate').forEach((elem) => elem.animate(keyframes, ops));
|
|
6459
|
+
return el;
|
|
6460
|
+
}
|
|
6461
|
+
|
|
6462
|
+
/**
|
|
6463
|
+
* Applies an animation to one or multiple TinyElement instances.
|
|
6464
|
+
*
|
|
6465
|
+
* @param {Keyframe[] | PropertyIndexedKeyframes | null} keyframes - The keyframes used to define the animation.
|
|
6466
|
+
* @param {number | KeyframeAnimationOptions} [ops] - Timing or configuration options for the animation.
|
|
6467
|
+
* @returns {TinyElement|TinyElement[]}
|
|
6468
|
+
*/
|
|
6469
|
+
animate(keyframes, ops) {
|
|
6470
|
+
return TinyHtml_TinyHtml.animate(this, keyframes, ops);
|
|
6471
|
+
}
|
|
6472
|
+
|
|
6124
6473
|
/**
|
|
6125
6474
|
* Gets the offset of the element relative to the document.
|
|
6126
6475
|
* @param {TinyElement} el - Target element.
|
|
@@ -6276,27 +6625,151 @@ class TinyHtml_TinyHtml {
|
|
|
6276
6625
|
}
|
|
6277
6626
|
|
|
6278
6627
|
/**
|
|
6279
|
-
*
|
|
6280
|
-
*
|
|
6281
|
-
*
|
|
6628
|
+
* Collection of easing functions used for scroll and animation calculations.
|
|
6629
|
+
* Each function receives a normalized time value (`t` from 0 to 1) and returns the eased progress.
|
|
6630
|
+
*
|
|
6631
|
+
* @type {Record<string, (t: number) => number>}
|
|
6282
6632
|
*/
|
|
6283
|
-
static
|
|
6284
|
-
|
|
6285
|
-
|
|
6286
|
-
|
|
6287
|
-
|
|
6633
|
+
static easings = {
|
|
6634
|
+
linear: (t) => t,
|
|
6635
|
+
easeInQuad: (t) => t * t,
|
|
6636
|
+
easeOutQuad: (t) => t * (2 - t),
|
|
6637
|
+
easeInOutQuad: (t) => (t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t),
|
|
6638
|
+
easeInCubic: (t) => t * t * t,
|
|
6639
|
+
easeOutCubic: (t) => --t * t * t + 1,
|
|
6640
|
+
easeInOutCubic: (t) => (t < 0.5 ? 4 * t * t * t : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1),
|
|
6641
|
+
};
|
|
6642
|
+
|
|
6643
|
+
/**
|
|
6644
|
+
* Smoothly scrolls one or more elements (or the window) to the specified X and Y coordinates
|
|
6645
|
+
* using a custom duration and easing function.
|
|
6646
|
+
*
|
|
6647
|
+
* If `duration` or a valid `easing` is not provided, the scroll will be performed immediately.
|
|
6648
|
+
*
|
|
6649
|
+
* @param {TinyElementAndWindow | TinyElementAndWindow[]} el - A single element, array of elements, or the window to scroll.
|
|
6650
|
+
* @param {Object} [settings={}] - Configuration object for the scroll animation.
|
|
6651
|
+
* @param {number} [settings.targetX] - The horizontal scroll target in pixels.
|
|
6652
|
+
* @param {number} [settings.targetY] - The vertical scroll target in pixels.
|
|
6653
|
+
* @param {number} [settings.duration] - The duration of the animation in milliseconds.
|
|
6654
|
+
* @param {Easings} [settings.easing] - The easing function name to use for the scroll animation.
|
|
6655
|
+
* @param {OnScrollAnimation} [settings.onAnimation] - Optional callback invoked on each animation
|
|
6656
|
+
* frame with the current scroll position, normalized animation time (`0` to `1`), and a completion flag.
|
|
6657
|
+
* @returns {TinyElementAndWindow|TinyElementAndWindow[]}
|
|
6658
|
+
* @throws {TypeError} If `el` is not a valid element, array, or window.
|
|
6659
|
+
* @throws {TypeError} If `targetX` or `targetY` is defined but not a number.
|
|
6660
|
+
* @throws {TypeError} If `duration` is defined but not a number.
|
|
6661
|
+
* @throws {TypeError} If `easing` is defined but not a valid easing function name.
|
|
6662
|
+
* @throws {TypeError} If `onAnimation` is defined but not a function.
|
|
6663
|
+
*/
|
|
6664
|
+
static scrollToXY(el, { targetX, targetY, duration, easing, onAnimation } = {}) {
|
|
6665
|
+
if (targetX !== undefined && typeof targetX !== 'number')
|
|
6666
|
+
throw new TypeError('`targetX` must be a number if provided.');
|
|
6667
|
+
if (targetY !== undefined && typeof targetY !== 'number')
|
|
6668
|
+
throw new TypeError('`targetY` must be a number if provided.');
|
|
6669
|
+
if (duration !== undefined && typeof duration !== 'number')
|
|
6670
|
+
throw new TypeError('`duration` must be a number if provided.');
|
|
6671
|
+
if (easing !== undefined && typeof easing !== 'string')
|
|
6672
|
+
throw new TypeError('`easing` must be a string if provided.');
|
|
6673
|
+
if (easing !== undefined && typeof TinyHtml_TinyHtml.easings[easing] !== 'function')
|
|
6674
|
+
throw new TypeError(`Unknown easing function: "${easing}".`);
|
|
6675
|
+
if (onAnimation !== undefined && typeof onAnimation !== 'function')
|
|
6676
|
+
throw new TypeError('`onAnimation` must be a function if provided.');
|
|
6677
|
+
|
|
6678
|
+
/**
|
|
6679
|
+
* Performs an instant scroll to the given coordinates.
|
|
6680
|
+
*
|
|
6681
|
+
* @param {ElementAndWindow} elem - The element or window to scroll.
|
|
6682
|
+
* @param {number} newX - The final horizontal scroll position.
|
|
6683
|
+
* @param {number} newY - The final vertical scroll position.
|
|
6684
|
+
* @param {number} time - Normalized progress value.
|
|
6685
|
+
*/
|
|
6686
|
+
const executeScroll = (elem, newX, newY, time) => {
|
|
6687
|
+
if (elem instanceof Window) {
|
|
6688
|
+
window.scrollTo(newX, newY);
|
|
6288
6689
|
} else if (elem.nodeType === 9) {
|
|
6289
6690
|
// @ts-ignore
|
|
6290
|
-
elem.defaultView.scrollTo(
|
|
6691
|
+
elem.defaultView.scrollTo(newX, newY);
|
|
6291
6692
|
} else {
|
|
6292
|
-
elem.
|
|
6693
|
+
const startX = elem instanceof Window ? window.scrollX : elem.scrollLeft;
|
|
6694
|
+
const startY = elem instanceof Window ? window.scrollY : elem.scrollTop;
|
|
6695
|
+
if (startX !== newX) elem.scrollLeft = newX;
|
|
6696
|
+
if (startY !== newY) elem.scrollTop = newY;
|
|
6697
|
+
}
|
|
6698
|
+
if (typeof onAnimation === 'function')
|
|
6699
|
+
onAnimation({ x: newX, y: newY, isComplete: time >= 1, time });
|
|
6700
|
+
};
|
|
6701
|
+
|
|
6702
|
+
TinyHtml_TinyHtml._preElemsAndWindow(el, 'scrollToXY').forEach((elem) => {
|
|
6703
|
+
const startX = elem instanceof Window ? window.scrollX : elem.scrollLeft;
|
|
6704
|
+
const startY = elem instanceof Window ? window.scrollY : elem.scrollTop;
|
|
6705
|
+
const targX = targetX ?? startX;
|
|
6706
|
+
const targY = targetY ?? startY;
|
|
6707
|
+
|
|
6708
|
+
const changeX = targX - startX;
|
|
6709
|
+
const changeY = targY - startY;
|
|
6710
|
+
|
|
6711
|
+
const ease = (typeof easing === 'string' && TinyHtml_TinyHtml.easings[easing]) || null;
|
|
6712
|
+
if (typeof duration !== 'number' || typeof ease !== 'function')
|
|
6713
|
+
return executeScroll(elem, targX, targY, 1);
|
|
6714
|
+
const startTime = performance.now();
|
|
6715
|
+
const dur = duration ?? 0;
|
|
6716
|
+
|
|
6717
|
+
/**
|
|
6718
|
+
* Animates the scroll position based on easing and time.
|
|
6719
|
+
*
|
|
6720
|
+
* @param {number} currentTime - Timestamp provided by requestAnimationFrame.
|
|
6721
|
+
*/
|
|
6722
|
+
function animateScroll(currentTime) {
|
|
6723
|
+
if (typeof ease !== 'function') return;
|
|
6724
|
+
const time = Math.min(1, (currentTime - startTime) / dur);
|
|
6725
|
+
const easedTime = ease(time);
|
|
6726
|
+
|
|
6727
|
+
const newX = startX + changeX * easedTime;
|
|
6728
|
+
const newY = startY + changeY * easedTime;
|
|
6729
|
+
executeScroll(elem, newX, newY, time);
|
|
6730
|
+
|
|
6731
|
+
if (time < 1) requestAnimationFrame(animateScroll);
|
|
6293
6732
|
}
|
|
6733
|
+
|
|
6734
|
+
requestAnimationFrame(animateScroll);
|
|
6294
6735
|
});
|
|
6736
|
+
return el;
|
|
6737
|
+
}
|
|
6738
|
+
|
|
6739
|
+
/**
|
|
6740
|
+
* Smoothly scrolls one or more elements (or the window) to the specified X and Y coordinates
|
|
6741
|
+
* using a custom duration and easing function.
|
|
6742
|
+
*
|
|
6743
|
+
* If `duration` or a valid `easing` is not provided, the scroll will be performed immediately.
|
|
6744
|
+
*
|
|
6745
|
+
* @param {Object} [settings={}] - Configuration object for the scroll animation.
|
|
6746
|
+
* @param {number} [settings.targetX] - The horizontal scroll target in pixels.
|
|
6747
|
+
* @param {number} [settings.targetY] - The vertical scroll target in pixels.
|
|
6748
|
+
* @param {number} [settings.duration] - The duration of the animation in milliseconds.
|
|
6749
|
+
* @param {Easings} [settings.easing] - The easing function name to use for the scroll animation.
|
|
6750
|
+
* @param {OnScrollAnimation} [settings.onAnimation] - Optional callback invoked on each animation
|
|
6751
|
+
* frame with the current scroll position, normalized animation time (`0` to `1`), and a completion flag.
|
|
6752
|
+
* @returns {TinyElementAndWindow|TinyElementAndWindow[]}
|
|
6753
|
+
*/
|
|
6754
|
+
scrollToXY({ targetX, targetY, duration, easing, onAnimation } = {}) {
|
|
6755
|
+
return TinyHtml_TinyHtml.scrollToXY(this, { targetX, targetY, duration, easing, onAnimation });
|
|
6756
|
+
}
|
|
6757
|
+
|
|
6758
|
+
/**
|
|
6759
|
+
* Sets the vertical scroll position.
|
|
6760
|
+
* @param {TinyElementAndWindow|TinyElementAndWindow[]} el - Element or window.
|
|
6761
|
+
* @param {number} value - Scroll top value.
|
|
6762
|
+
* @returns {TinyElementAndWindow|TinyElementAndWindow[]}
|
|
6763
|
+
*/
|
|
6764
|
+
static setScrollTop(el, value) {
|
|
6765
|
+
if (typeof value !== 'number') throw new TypeError('ScrollTop value must be a number.');
|
|
6766
|
+
return TinyHtml_TinyHtml.scrollToXY(el, { targetY: value });
|
|
6295
6767
|
}
|
|
6296
6768
|
|
|
6297
6769
|
/**
|
|
6298
6770
|
* Sets the vertical scroll position.
|
|
6299
6771
|
* @param {number} value - Scroll top value.
|
|
6772
|
+
* @returns {TinyElementAndWindow|TinyElementAndWindow[]}
|
|
6300
6773
|
*/
|
|
6301
6774
|
setScrollTop(value) {
|
|
6302
6775
|
return TinyHtml_TinyHtml.setScrollTop(this, value);
|
|
@@ -6306,24 +6779,17 @@ class TinyHtml_TinyHtml {
|
|
|
6306
6779
|
* Sets the horizontal scroll position.
|
|
6307
6780
|
* @param {TinyElementAndWindow|TinyElementAndWindow[]} el - Element or window.
|
|
6308
6781
|
* @param {number} value - Scroll left value.
|
|
6782
|
+
* @returns {TinyElementAndWindow|TinyElementAndWindow[]}
|
|
6309
6783
|
*/
|
|
6310
6784
|
static setScrollLeft(el, value) {
|
|
6311
6785
|
if (typeof value !== 'number') throw new TypeError('ScrollLeft value must be a number.');
|
|
6312
|
-
TinyHtml_TinyHtml.
|
|
6313
|
-
if (TinyHtml_TinyHtml.isWindow(elem)) {
|
|
6314
|
-
elem.scrollTo(value, elem.pageYOffset);
|
|
6315
|
-
} else if (elem.nodeType === 9) {
|
|
6316
|
-
// @ts-ignore
|
|
6317
|
-
elem.defaultView.scrollTo(value, elem.defaultView.pageYOffset);
|
|
6318
|
-
} else {
|
|
6319
|
-
elem.scrollLeft = value;
|
|
6320
|
-
}
|
|
6321
|
-
});
|
|
6786
|
+
return TinyHtml_TinyHtml.scrollToXY(el, { targetX: value });
|
|
6322
6787
|
}
|
|
6323
6788
|
|
|
6324
6789
|
/**
|
|
6325
6790
|
* Sets the horizontal scroll position.
|
|
6326
6791
|
* @param {number} value - Scroll left value.
|
|
6792
|
+
* @returns {TinyElementAndWindow|TinyElementAndWindow[]}
|
|
6327
6793
|
*/
|
|
6328
6794
|
setScrollLeft(value) {
|
|
6329
6795
|
return TinyHtml_TinyHtml.setScrollLeft(this, value);
|
|
@@ -6454,15 +6920,16 @@ class TinyHtml_TinyHtml {
|
|
|
6454
6920
|
|
|
6455
6921
|
/**
|
|
6456
6922
|
* Adds one or more CSS class names to the element.
|
|
6457
|
-
* @type {(el: TinyElement|TinyElement[], ...tokens: string[]) =>
|
|
6923
|
+
* @type {(el: TinyElement|TinyElement[], ...tokens: string[]) => (TinyElement|TinyElement[])} - One or more class names to add.
|
|
6458
6924
|
*/
|
|
6459
6925
|
static addClass(el, ...args) {
|
|
6460
6926
|
TinyHtml_TinyHtml._preElems(el, 'addClass').forEach((elem) => elem.classList.add(...args));
|
|
6927
|
+
return el;
|
|
6461
6928
|
}
|
|
6462
6929
|
|
|
6463
6930
|
/**
|
|
6464
6931
|
* Adds one or more CSS class names to the element.
|
|
6465
|
-
* @type {(...tokens: string[]) =>
|
|
6932
|
+
* @type {(...tokens: string[]) => (TinyElement|TinyElement[])} - One or more class names to add.
|
|
6466
6933
|
*/
|
|
6467
6934
|
addClass(...args) {
|
|
6468
6935
|
return TinyHtml_TinyHtml.addClass(this, ...args);
|
|
@@ -6470,15 +6937,16 @@ class TinyHtml_TinyHtml {
|
|
|
6470
6937
|
|
|
6471
6938
|
/**
|
|
6472
6939
|
* Removes one or more CSS class names from the element.
|
|
6473
|
-
* @type {(el: TinyElement|TinyElement[], ...tokens: string[]) =>
|
|
6940
|
+
* @type {(el: TinyElement|TinyElement[], ...tokens: string[]) => (TinyElement|TinyElement[])} - One or more class names to remove.
|
|
6474
6941
|
*/
|
|
6475
6942
|
static removeClass(el, ...args) {
|
|
6476
6943
|
TinyHtml_TinyHtml._preElems(el, 'removeClass').forEach((elem) => elem.classList.remove(...args));
|
|
6944
|
+
return el;
|
|
6477
6945
|
}
|
|
6478
6946
|
|
|
6479
6947
|
/**
|
|
6480
6948
|
* Removes one or more CSS class names from the element.
|
|
6481
|
-
* @type {(...tokens: string[]) =>
|
|
6949
|
+
* @type {(...tokens: string[]) => (TinyElement|TinyElement[])} - One or more class names to remove.
|
|
6482
6950
|
*/
|
|
6483
6951
|
removeClass(...args) {
|
|
6484
6952
|
return TinyHtml_TinyHtml.removeClass(this, ...args);
|
|
@@ -6688,15 +7156,18 @@ class TinyHtml_TinyHtml {
|
|
|
6688
7156
|
* Set text content of elements.
|
|
6689
7157
|
* @param {TinyElement|TinyElement[]} el
|
|
6690
7158
|
* @param {string} value
|
|
7159
|
+
* @returns {TinyElement|TinyElement[]}
|
|
6691
7160
|
*/
|
|
6692
7161
|
static setText(el, value) {
|
|
6693
7162
|
if (typeof value !== 'string') throw new Error('Value is not a valid string.');
|
|
6694
7163
|
TinyHtml_TinyHtml._preElems(el, 'setText').forEach((el) => (el.textContent = value));
|
|
7164
|
+
return el;
|
|
6695
7165
|
}
|
|
6696
7166
|
|
|
6697
7167
|
/**
|
|
6698
7168
|
* Set text content of the element.
|
|
6699
7169
|
* @param {string} value
|
|
7170
|
+
* @returns {TinyElement|TinyElement[]}
|
|
6700
7171
|
*/
|
|
6701
7172
|
setText(value) {
|
|
6702
7173
|
return TinyHtml_TinyHtml.setText(this, value);
|
|
@@ -6705,13 +7176,16 @@ class TinyHtml_TinyHtml {
|
|
|
6705
7176
|
/**
|
|
6706
7177
|
* Remove all child nodes from each element.
|
|
6707
7178
|
* @param {TinyElement|TinyElement[]} el
|
|
7179
|
+
* @returns {TinyElement|TinyElement[]}
|
|
6708
7180
|
*/
|
|
6709
7181
|
static empty(el) {
|
|
6710
7182
|
TinyHtml_TinyHtml._preElems(el, 'empty').forEach((el) => (el.textContent = ''));
|
|
7183
|
+
return el;
|
|
6711
7184
|
}
|
|
6712
7185
|
|
|
6713
7186
|
/**
|
|
6714
7187
|
* Remove all child nodes of the element.
|
|
7188
|
+
* @returns {TinyElement|TinyElement[]}
|
|
6715
7189
|
*/
|
|
6716
7190
|
empty() {
|
|
6717
7191
|
return TinyHtml_TinyHtml.empty(this);
|
|
@@ -6719,35 +7193,40 @@ class TinyHtml_TinyHtml {
|
|
|
6719
7193
|
|
|
6720
7194
|
/**
|
|
6721
7195
|
* Get the innerHTML of the element.
|
|
6722
|
-
* @param {TinyElement
|
|
7196
|
+
* @param {TinyElement} el
|
|
7197
|
+
* @param {GetHTMLOptions} [ops]
|
|
6723
7198
|
* @returns {string}
|
|
6724
7199
|
*/
|
|
6725
|
-
static html(el) {
|
|
7200
|
+
static html(el, ops) {
|
|
6726
7201
|
const elem = TinyHtml_TinyHtml._preElem(el, 'html');
|
|
6727
|
-
return elem.
|
|
7202
|
+
return elem.getHTML(ops);
|
|
6728
7203
|
}
|
|
6729
7204
|
|
|
6730
7205
|
/**
|
|
6731
7206
|
* Get the innerHTML of the element.
|
|
7207
|
+
* @param {GetHTMLOptions} [ops]
|
|
6732
7208
|
* @returns {string}
|
|
6733
7209
|
*/
|
|
6734
|
-
html() {
|
|
6735
|
-
return TinyHtml_TinyHtml.html(this);
|
|
7210
|
+
html(ops) {
|
|
7211
|
+
return TinyHtml_TinyHtml.html(this, ops);
|
|
6736
7212
|
}
|
|
6737
7213
|
|
|
6738
7214
|
/**
|
|
6739
7215
|
* Set the innerHTML of each element.
|
|
6740
7216
|
* @param {TinyElement|TinyElement[]} el
|
|
6741
7217
|
* @param {string} value
|
|
7218
|
+
* @returns {TinyElement|TinyElement[]}
|
|
6742
7219
|
*/
|
|
6743
7220
|
static setHtml(el, value) {
|
|
6744
7221
|
if (typeof value !== 'string') throw new Error('Value is not a valid string.');
|
|
6745
7222
|
TinyHtml_TinyHtml._preElems(el, 'setHtml').forEach((el) => (el.innerHTML = value));
|
|
7223
|
+
return el;
|
|
6746
7224
|
}
|
|
6747
7225
|
|
|
6748
7226
|
/**
|
|
6749
7227
|
* Set the innerHTML of the element.
|
|
6750
7228
|
* @param {string} value
|
|
7229
|
+
* @returns {TinyElement|TinyElement[]}
|
|
6751
7230
|
*/
|
|
6752
7231
|
setHtml(value) {
|
|
6753
7232
|
return TinyHtml_TinyHtml.setHtml(this, value);
|
|
@@ -6881,6 +7360,7 @@ class TinyHtml_TinyHtml {
|
|
|
6881
7360
|
* @param {TinyInputElement|TinyInputElement[]} el - Target element.
|
|
6882
7361
|
* @param {SetValueList|((el: InputElement, val: SetValueList) => SetValueList)} value - The value to assign or a function that returns it.
|
|
6883
7362
|
* @throws {Error} If the computed value is not a valid string or boolean.
|
|
7363
|
+
* @returns {TinyInputElement|TinyInputElement[]}
|
|
6884
7364
|
*/
|
|
6885
7365
|
static setVal(el, value) {
|
|
6886
7366
|
TinyHtml_TinyHtml._preInputElems(el, 'setVal').forEach((elem) => {
|
|
@@ -6920,6 +7400,7 @@ class TinyHtml_TinyHtml {
|
|
|
6920
7400
|
if (typeof valToSet === 'string') elem.value = valToSet;
|
|
6921
7401
|
}
|
|
6922
7402
|
});
|
|
7403
|
+
return el;
|
|
6923
7404
|
}
|
|
6924
7405
|
|
|
6925
7406
|
/**
|
|
@@ -6927,6 +7408,7 @@ class TinyHtml_TinyHtml {
|
|
|
6927
7408
|
* Accepts strings, numbers, booleans or arrays of these values, or a callback function that computes them.
|
|
6928
7409
|
*
|
|
6929
7410
|
* @param {SetValueList|((el: InputElement, val: SetValueList) => SetValueList)} value - The value to assign or a function that returns it.
|
|
7411
|
+
* @returns {TinyInputElement|TinyInputElement[]}
|
|
6930
7412
|
* @throws {Error} If the computed value is not a valid string or boolean.
|
|
6931
7413
|
*/
|
|
6932
7414
|
setVal(value) {
|
|
@@ -7196,6 +7678,7 @@ class TinyHtml_TinyHtml {
|
|
|
7196
7678
|
* @param {string} event - The event type (e.g. 'click', 'keydown').
|
|
7197
7679
|
* @param {EventRegistryHandle} handler - The callback function to run on event.
|
|
7198
7680
|
* @param {EventRegistryOptions} [options] - Optional event listener options.
|
|
7681
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
7199
7682
|
*/
|
|
7200
7683
|
static on(el, event, handler, options) {
|
|
7201
7684
|
if (typeof event !== 'string') throw new TypeError('The event name must be a string.');
|
|
@@ -7208,6 +7691,7 @@ class TinyHtml_TinyHtml {
|
|
|
7208
7691
|
if (!Array.isArray(events[event])) events[event] = [];
|
|
7209
7692
|
events[event].push({ handler, options });
|
|
7210
7693
|
});
|
|
7694
|
+
return el;
|
|
7211
7695
|
}
|
|
7212
7696
|
|
|
7213
7697
|
/**
|
|
@@ -7216,6 +7700,7 @@ class TinyHtml_TinyHtml {
|
|
|
7216
7700
|
* @param {string} event - The event type (e.g. 'click', 'keydown').
|
|
7217
7701
|
* @param {EventRegistryHandle} handler - The callback function to run on event.
|
|
7218
7702
|
* @param {EventRegistryOptions} [options] - Optional event listener options.
|
|
7703
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
7219
7704
|
*/
|
|
7220
7705
|
on(event, handler, options) {
|
|
7221
7706
|
return TinyHtml_TinyHtml.on(this, event, handler, options);
|
|
@@ -7228,6 +7713,7 @@ class TinyHtml_TinyHtml {
|
|
|
7228
7713
|
* @param {string} event - The event type (e.g. 'click', 'keydown').
|
|
7229
7714
|
* @param {EventRegistryHandle} handler - The callback function to run on event.
|
|
7230
7715
|
* @param {EventRegistryOptions} [options={}] - Optional event listener options.
|
|
7716
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
7231
7717
|
*/
|
|
7232
7718
|
static once(el, event, handler, options = {}) {
|
|
7233
7719
|
if (typeof event !== 'string') throw new TypeError('The event name must be a string.');
|
|
@@ -7245,6 +7731,7 @@ class TinyHtml_TinyHtml {
|
|
|
7245
7731
|
typeof options === 'boolean' ? options : { ...options, once: true },
|
|
7246
7732
|
);
|
|
7247
7733
|
});
|
|
7734
|
+
return el;
|
|
7248
7735
|
}
|
|
7249
7736
|
|
|
7250
7737
|
/**
|
|
@@ -7253,6 +7740,7 @@ class TinyHtml_TinyHtml {
|
|
|
7253
7740
|
* @param {string} event - The event type (e.g. 'click', 'keydown').
|
|
7254
7741
|
* @param {EventRegistryHandle} handler - The callback function to run on event.
|
|
7255
7742
|
* @param {EventRegistryOptions} [options={}] - Optional event listener options.
|
|
7743
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
7256
7744
|
*/
|
|
7257
7745
|
once(event, handler, options = {}) {
|
|
7258
7746
|
return TinyHtml_TinyHtml.once(this, event, handler, options);
|
|
@@ -7265,6 +7753,7 @@ class TinyHtml_TinyHtml {
|
|
|
7265
7753
|
* @param {string} event - The event type.
|
|
7266
7754
|
* @param {EventRegistryHandle} handler - The function originally bound to the event.
|
|
7267
7755
|
* @param {boolean|EventListenerOptions} [options] - Optional listener options.
|
|
7756
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
7268
7757
|
*/
|
|
7269
7758
|
static off(el, event, handler, options) {
|
|
7270
7759
|
if (typeof event !== 'string') throw new TypeError('The event name must be a string.');
|
|
@@ -7277,6 +7766,7 @@ class TinyHtml_TinyHtml {
|
|
|
7277
7766
|
if (events[event].length === 0) delete events[event];
|
|
7278
7767
|
}
|
|
7279
7768
|
});
|
|
7769
|
+
return el;
|
|
7280
7770
|
}
|
|
7281
7771
|
|
|
7282
7772
|
/**
|
|
@@ -7285,6 +7775,7 @@ class TinyHtml_TinyHtml {
|
|
|
7285
7775
|
* @param {string} event - The event type.
|
|
7286
7776
|
* @param {EventRegistryHandle} handler - The function originally bound to the event.
|
|
7287
7777
|
* @param {boolean|EventListenerOptions} [options] - Optional listener options.
|
|
7778
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
7288
7779
|
*/
|
|
7289
7780
|
off(event, handler, options) {
|
|
7290
7781
|
return TinyHtml_TinyHtml.off(this, event, handler, options);
|
|
@@ -7295,6 +7786,7 @@ class TinyHtml_TinyHtml {
|
|
|
7295
7786
|
*
|
|
7296
7787
|
* @param {TinyEventTarget|TinyEventTarget[]} el - The target element.
|
|
7297
7788
|
* @param {string} event - The event type to remove (e.g. 'click').
|
|
7789
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
7298
7790
|
*/
|
|
7299
7791
|
static offAll(el, event) {
|
|
7300
7792
|
if (typeof event !== 'string') throw new TypeError('The event name must be a string.');
|
|
@@ -7307,12 +7799,14 @@ class TinyHtml_TinyHtml {
|
|
|
7307
7799
|
delete events[event];
|
|
7308
7800
|
}
|
|
7309
7801
|
});
|
|
7802
|
+
return el;
|
|
7310
7803
|
}
|
|
7311
7804
|
|
|
7312
7805
|
/**
|
|
7313
7806
|
* Removes all event listeners of a specific type from the element.
|
|
7314
7807
|
*
|
|
7315
7808
|
* @param {string} event - The event type to remove (e.g. 'click').
|
|
7809
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
7316
7810
|
*/
|
|
7317
7811
|
offAll(event) {
|
|
7318
7812
|
return TinyHtml_TinyHtml.offAll(this, event);
|
|
@@ -7324,6 +7818,7 @@ class TinyHtml_TinyHtml {
|
|
|
7324
7818
|
* @param {TinyEventTarget|TinyEventTarget[]} el - The target element.
|
|
7325
7819
|
* @param {((handler: EventListenerOrEventListenerObject, event: string) => boolean)|null} [filterFn=null] -
|
|
7326
7820
|
* Optional filter function to selectively remove specific handlers.
|
|
7821
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
7327
7822
|
*/
|
|
7328
7823
|
static offAllTypes(el, filterFn = null) {
|
|
7329
7824
|
if (filterFn !== null && typeof filterFn !== 'function')
|
|
@@ -7342,6 +7837,7 @@ class TinyHtml_TinyHtml {
|
|
|
7342
7837
|
|
|
7343
7838
|
__eventRegistry.delete(elem);
|
|
7344
7839
|
});
|
|
7840
|
+
return el;
|
|
7345
7841
|
}
|
|
7346
7842
|
|
|
7347
7843
|
/**
|
|
@@ -7349,6 +7845,7 @@ class TinyHtml_TinyHtml {
|
|
|
7349
7845
|
*
|
|
7350
7846
|
* @param {((handler: EventListenerOrEventListenerObject, event: string) => boolean)|null} [filterFn=null] -
|
|
7351
7847
|
* Optional filter function to selectively remove specific handlers.
|
|
7848
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
7352
7849
|
*/
|
|
7353
7850
|
offAllTypes(filterFn = null) {
|
|
7354
7851
|
return TinyHtml_TinyHtml.offAllTypes(this, filterFn);
|
|
@@ -7360,6 +7857,7 @@ class TinyHtml_TinyHtml {
|
|
|
7360
7857
|
* @param {TinyEventTarget|TinyEventTarget[]} el - Target element where the event should be triggered.
|
|
7361
7858
|
* @param {string} event - Name of the event to trigger.
|
|
7362
7859
|
* @param {Event|CustomEvent|CustomEventInit} [payload] - Optional event object or data to pass.
|
|
7860
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
7363
7861
|
*/
|
|
7364
7862
|
static trigger(el, event, payload = {}) {
|
|
7365
7863
|
if (typeof event !== 'string') throw new TypeError('The event name must be a string.');
|
|
@@ -7375,6 +7873,7 @@ class TinyHtml_TinyHtml {
|
|
|
7375
7873
|
|
|
7376
7874
|
elem.dispatchEvent(evt);
|
|
7377
7875
|
});
|
|
7876
|
+
return el;
|
|
7378
7877
|
}
|
|
7379
7878
|
|
|
7380
7879
|
/**
|
|
@@ -7382,6 +7881,7 @@ class TinyHtml_TinyHtml {
|
|
|
7382
7881
|
*
|
|
7383
7882
|
* @param {string} event - Name of the event to trigger.
|
|
7384
7883
|
* @param {Event|CustomEvent|CustomEventInit} [payload] - Optional event object or data to pass.
|
|
7884
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
7385
7885
|
*/
|
|
7386
7886
|
trigger(event, payload = {}) {
|
|
7387
7887
|
return TinyHtml_TinyHtml.trigger(this, event, payload);
|
|
@@ -7424,6 +7924,7 @@ class TinyHtml_TinyHtml {
|
|
|
7424
7924
|
* @param {TinyElement|TinyElement[]} el
|
|
7425
7925
|
* @param {string} name
|
|
7426
7926
|
* @param {string|null} [value=null]
|
|
7927
|
+
* @returns {TinyElement|TinyElement[]}
|
|
7427
7928
|
*/
|
|
7428
7929
|
static setAttr(el, name, value = null) {
|
|
7429
7930
|
if (typeof name !== 'string') throw new TypeError('The "name" must be a string.');
|
|
@@ -7433,12 +7934,14 @@ class TinyHtml_TinyHtml {
|
|
|
7433
7934
|
if (value === null) elem.removeAttribute(name);
|
|
7434
7935
|
else elem.setAttribute(name, value);
|
|
7435
7936
|
});
|
|
7937
|
+
return el;
|
|
7436
7938
|
}
|
|
7437
7939
|
|
|
7438
7940
|
/**
|
|
7439
7941
|
* Set an attribute on an element.
|
|
7440
7942
|
* @param {string} name
|
|
7441
7943
|
* @param {string|null} [value=null]
|
|
7944
|
+
* @returns {TinyElement|TinyElement[]}
|
|
7442
7945
|
*/
|
|
7443
7946
|
setAttr(name, value) {
|
|
7444
7947
|
return TinyHtml_TinyHtml.setAttr(this, name, value);
|
|
@@ -7448,15 +7951,18 @@ class TinyHtml_TinyHtml {
|
|
|
7448
7951
|
* Remove attribute(s) from an element.
|
|
7449
7952
|
* @param {TinyElement|TinyElement[]} el
|
|
7450
7953
|
* @param {string} name Space-separated list of attributes.
|
|
7954
|
+
* @returns {TinyElement|TinyElement[]}
|
|
7451
7955
|
*/
|
|
7452
7956
|
static removeAttr(el, name) {
|
|
7453
7957
|
if (typeof name !== 'string') throw new TypeError('The "name" must be a string.');
|
|
7454
7958
|
TinyHtml_TinyHtml._preElems(el, 'removeAttr').forEach((elem) => elem.removeAttribute(name));
|
|
7959
|
+
return el;
|
|
7455
7960
|
}
|
|
7456
7961
|
|
|
7457
7962
|
/**
|
|
7458
7963
|
* Remove attribute(s) from an element.
|
|
7459
7964
|
* @param {string} name Space-separated list of attributes.
|
|
7965
|
+
* @returns {TinyElement|TinyElement[]}
|
|
7460
7966
|
*/
|
|
7461
7967
|
removeAttr(name) {
|
|
7462
7968
|
return TinyHtml_TinyHtml.removeAttr(this, name);
|
|
@@ -7511,6 +8017,7 @@ class TinyHtml_TinyHtml {
|
|
|
7511
8017
|
* Set a property on an element.
|
|
7512
8018
|
* @param {TinyElement|TinyElement[]} el
|
|
7513
8019
|
* @param {string} name
|
|
8020
|
+
* @returns {TinyElement|TinyElement[]}
|
|
7514
8021
|
*/
|
|
7515
8022
|
static addProp(el, name) {
|
|
7516
8023
|
if (typeof name !== 'string') throw new TypeError('The "name" must be a string.');
|
|
@@ -7520,11 +8027,13 @@ class TinyHtml_TinyHtml {
|
|
|
7520
8027
|
// @ts-ignore
|
|
7521
8028
|
elem[name] = true;
|
|
7522
8029
|
});
|
|
8030
|
+
return el;
|
|
7523
8031
|
}
|
|
7524
8032
|
|
|
7525
8033
|
/**
|
|
7526
8034
|
* Set a property on an element.
|
|
7527
8035
|
* @param {string} name
|
|
8036
|
+
* @returns {TinyElement|TinyElement[]}
|
|
7528
8037
|
*/
|
|
7529
8038
|
addProp(name) {
|
|
7530
8039
|
return TinyHtml_TinyHtml.addProp(this, name);
|
|
@@ -7534,6 +8043,7 @@ class TinyHtml_TinyHtml {
|
|
|
7534
8043
|
* Remove a property from an element.
|
|
7535
8044
|
* @param {TinyElement|TinyElement[]} el
|
|
7536
8045
|
* @param {string} name
|
|
8046
|
+
* @returns {TinyElement|TinyElement[]}
|
|
7537
8047
|
*/
|
|
7538
8048
|
static removeProp(el, name) {
|
|
7539
8049
|
if (typeof name !== 'string') throw new TypeError('The "name" must be a string.');
|
|
@@ -7543,11 +8053,13 @@ class TinyHtml_TinyHtml {
|
|
|
7543
8053
|
// @ts-ignore
|
|
7544
8054
|
elem[name] = false;
|
|
7545
8055
|
});
|
|
8056
|
+
return el;
|
|
7546
8057
|
}
|
|
7547
8058
|
|
|
7548
8059
|
/**
|
|
7549
8060
|
* Remove a property from an element.
|
|
7550
8061
|
* @param {string} name
|
|
8062
|
+
* @returns {TinyElement|TinyElement[]}
|
|
7551
8063
|
*/
|
|
7552
8064
|
removeProp(name) {
|
|
7553
8065
|
return TinyHtml_TinyHtml.removeProp(this, name);
|
|
@@ -7588,13 +8100,16 @@ class TinyHtml_TinyHtml {
|
|
|
7588
8100
|
/**
|
|
7589
8101
|
* Removes an element from the DOM.
|
|
7590
8102
|
* @param {TinyElement|TinyElement[]} el - The DOM element or selector to remove.
|
|
8103
|
+
* @returns {TinyElement|TinyElement[]}
|
|
7591
8104
|
*/
|
|
7592
8105
|
static remove(el) {
|
|
7593
8106
|
TinyHtml_TinyHtml._preElems(el, 'remove').forEach((elem) => elem.remove());
|
|
8107
|
+
return el;
|
|
7594
8108
|
}
|
|
7595
8109
|
|
|
7596
8110
|
/**
|
|
7597
8111
|
* Removes the element from the DOM.
|
|
8112
|
+
* @returns {TinyElement|TinyElement[]}
|
|
7598
8113
|
*/
|
|
7599
8114
|
remove() {
|
|
7600
8115
|
return TinyHtml_TinyHtml.remove(this);
|
|
@@ -7938,6 +8453,14 @@ class TinyHtml_TinyHtml {
|
|
|
7938
8453
|
*/
|
|
7939
8454
|
static isInViewport(el) {
|
|
7940
8455
|
const elem = TinyHtml_TinyHtml._preElem(el, 'isInViewport');
|
|
8456
|
+
if (
|
|
8457
|
+
!elem.checkVisibility({
|
|
8458
|
+
contentVisibilityAuto: false,
|
|
8459
|
+
opacityProperty: false,
|
|
8460
|
+
visibilityProperty: false,
|
|
8461
|
+
})
|
|
8462
|
+
)
|
|
8463
|
+
return false;
|
|
7941
8464
|
const elementTop = TinyHtml_TinyHtml.offset(elem).top;
|
|
7942
8465
|
const elementBottom = elementTop + TinyHtml_TinyHtml.outerHeight(elem);
|
|
7943
8466
|
|
|
@@ -7964,6 +8487,14 @@ class TinyHtml_TinyHtml {
|
|
|
7964
8487
|
*/
|
|
7965
8488
|
static isScrolledIntoView(el) {
|
|
7966
8489
|
const elem = TinyHtml_TinyHtml._preElem(el, 'isScrolledIntoView');
|
|
8490
|
+
if (
|
|
8491
|
+
!elem.checkVisibility({
|
|
8492
|
+
contentVisibilityAuto: false,
|
|
8493
|
+
opacityProperty: false,
|
|
8494
|
+
visibilityProperty: false,
|
|
8495
|
+
})
|
|
8496
|
+
)
|
|
8497
|
+
return false;
|
|
7967
8498
|
const docViewTop = TinyHtml_TinyHtml.scrollTop(window);
|
|
7968
8499
|
const docViewBottom = docViewTop + TinyHtml_TinyHtml.height(window);
|
|
7969
8500
|
|
|
@@ -7981,6 +8512,111 @@ class TinyHtml_TinyHtml {
|
|
|
7981
8512
|
isScrolledIntoView() {
|
|
7982
8513
|
return TinyHtml_TinyHtml.isScrolledIntoView(this);
|
|
7983
8514
|
}
|
|
8515
|
+
|
|
8516
|
+
/**
|
|
8517
|
+
* Checks if the given element is at least partially visible within the boundaries of a container.
|
|
8518
|
+
*
|
|
8519
|
+
* @param {TinyElement} el - The DOM element to check.
|
|
8520
|
+
* @param {TinyElement} cont - The container element acting as the viewport.
|
|
8521
|
+
* @returns {boolean} True if the element is partially visible within the container, false otherwise.
|
|
8522
|
+
*/
|
|
8523
|
+
static isInContainer(el, cont) {
|
|
8524
|
+
const elem = TinyHtml_TinyHtml._preElem(el, 'isInContainer');
|
|
8525
|
+
const container = TinyHtml_TinyHtml._preElem(cont, 'isInContainer');
|
|
8526
|
+
|
|
8527
|
+
if (
|
|
8528
|
+
!elem.checkVisibility({
|
|
8529
|
+
contentVisibilityAuto: false,
|
|
8530
|
+
opacityProperty: false,
|
|
8531
|
+
visibilityProperty: false,
|
|
8532
|
+
})
|
|
8533
|
+
)
|
|
8534
|
+
return false;
|
|
8535
|
+
const elemRect = elem.getBoundingClientRect();
|
|
8536
|
+
const containerRect = container.getBoundingClientRect();
|
|
8537
|
+
|
|
8538
|
+
const verticallyVisible =
|
|
8539
|
+
elemRect.bottom > containerRect.top && elemRect.top < containerRect.bottom;
|
|
8540
|
+
|
|
8541
|
+
const horizontallyVisible =
|
|
8542
|
+
elemRect.right > containerRect.left && elemRect.left < containerRect.right;
|
|
8543
|
+
|
|
8544
|
+
return verticallyVisible && horizontallyVisible;
|
|
8545
|
+
}
|
|
8546
|
+
|
|
8547
|
+
/**
|
|
8548
|
+
* Checks if the given element is at least partially visible within the boundaries of a container.
|
|
8549
|
+
*
|
|
8550
|
+
* @param {TinyElement} cont - The container element acting as the viewport.
|
|
8551
|
+
* @returns {boolean} True if the element is partially visible within the container, false otherwise.
|
|
8552
|
+
*/
|
|
8553
|
+
isInContainer(cont) {
|
|
8554
|
+
return TinyHtml_TinyHtml.isInContainer(this, cont);
|
|
8555
|
+
}
|
|
8556
|
+
|
|
8557
|
+
/**
|
|
8558
|
+
* Checks if the given element is fully visible within the boundaries of a container (top and bottom).
|
|
8559
|
+
*
|
|
8560
|
+
* @param {TinyElement} el - The DOM element to check.
|
|
8561
|
+
* @param {TinyElement} cont - The container element acting as the viewport.
|
|
8562
|
+
* @returns {boolean} True if the element is fully visible within the container, false otherwise.
|
|
8563
|
+
*/
|
|
8564
|
+
static isFullyInContainer(el, cont) {
|
|
8565
|
+
const elem = TinyHtml_TinyHtml._preElem(el, 'isScrolledIntoView');
|
|
8566
|
+
const container = TinyHtml_TinyHtml._preElem(cont, 'isInContainer');
|
|
8567
|
+
|
|
8568
|
+
if (
|
|
8569
|
+
!elem.checkVisibility({
|
|
8570
|
+
contentVisibilityAuto: false,
|
|
8571
|
+
opacityProperty: false,
|
|
8572
|
+
visibilityProperty: false,
|
|
8573
|
+
})
|
|
8574
|
+
)
|
|
8575
|
+
return false;
|
|
8576
|
+
const elemRect = elem.getBoundingClientRect();
|
|
8577
|
+
const containerRect = container.getBoundingClientRect();
|
|
8578
|
+
|
|
8579
|
+
const isFullyVisible =
|
|
8580
|
+
elemRect.top >= containerRect.top &&
|
|
8581
|
+
elemRect.bottom <= containerRect.bottom &&
|
|
8582
|
+
elemRect.left >= containerRect.left &&
|
|
8583
|
+
elemRect.right <= containerRect.right;
|
|
8584
|
+
|
|
8585
|
+
return isFullyVisible;
|
|
8586
|
+
}
|
|
8587
|
+
|
|
8588
|
+
/**
|
|
8589
|
+
* Checks if the given element is fully visible within the boundaries of a container (top and bottom).
|
|
8590
|
+
*
|
|
8591
|
+
* @param {TinyElement} cont - The container element acting as the viewport.
|
|
8592
|
+
* @returns {boolean} True if the element is fully visible within the container, false otherwise.
|
|
8593
|
+
*/
|
|
8594
|
+
isFullyInContainer(cont) {
|
|
8595
|
+
return TinyHtml_TinyHtml.isFullyInContainer(this, cont);
|
|
8596
|
+
}
|
|
8597
|
+
|
|
8598
|
+
/**
|
|
8599
|
+
* Checks if an element has scrollable content.
|
|
8600
|
+
*
|
|
8601
|
+
* @param {TinyElement} el - The DOM element to check.
|
|
8602
|
+
* @returns {{ v: boolean, h: boolean }} - True if scroll is needed in that direction.
|
|
8603
|
+
*/
|
|
8604
|
+
static hasScroll(el) {
|
|
8605
|
+
const elem = TinyHtml_TinyHtml._preElem(el, 'hasScroll');
|
|
8606
|
+
return {
|
|
8607
|
+
v: elem.scrollHeight > elem.clientHeight,
|
|
8608
|
+
h: elem.scrollWidth > elem.clientWidth,
|
|
8609
|
+
};
|
|
8610
|
+
}
|
|
8611
|
+
|
|
8612
|
+
/**
|
|
8613
|
+
* Checks if an element has scrollable content.
|
|
8614
|
+
*
|
|
8615
|
+
* @returns {{ v: boolean, h: boolean }} - True if scroll is needed in that direction.
|
|
8616
|
+
*/
|
|
8617
|
+
hasScroll() {
|
|
8618
|
+
return TinyHtml_TinyHtml.hasScroll(this);
|
|
8619
|
+
}
|
|
7984
8620
|
}
|
|
7985
8621
|
|
|
7986
8622
|
/* harmony default export */ const libs_TinyHtml = (TinyHtml_TinyHtml);
|