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
|
@@ -11,6 +11,19 @@ const {
|
|
|
11
11
|
areElsCollRight,
|
|
12
12
|
} = collision;
|
|
13
13
|
|
|
14
|
+
/**
|
|
15
|
+
* Callback invoked on each animation frame with the current scroll position,
|
|
16
|
+
* normalized animation time (`0` to `1`), and a completion flag.
|
|
17
|
+
*
|
|
18
|
+
* @typedef {(progress: { x: number, y: number, isComplete: boolean, time: number }) => void} OnScrollAnimation
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* A list of supported easing function names for smooth animations.
|
|
23
|
+
*
|
|
24
|
+
* @typedef {'linear' | 'easeInQuad' | 'easeOutQuad' | 'easeInOutQuad' | 'easeInCubic' | 'easeOutCubic' | 'easeInOutCubic'} Easings
|
|
25
|
+
*/
|
|
26
|
+
|
|
14
27
|
/**
|
|
15
28
|
* Represents a raw Node element or an instance of TinyHtml.
|
|
16
29
|
* This type is used to abstract interactions with both plain elements
|
|
@@ -66,6 +79,21 @@ const {
|
|
|
66
79
|
* @typedef {Element|Window} ElementAndWindow
|
|
67
80
|
*/
|
|
68
81
|
|
|
82
|
+
/**
|
|
83
|
+
* Represents a raw DOM element/window/document or an instance of TinyHtml.
|
|
84
|
+
* This type is used to abstract interactions with both plain elements
|
|
85
|
+
* and wrapped elements via the TinyHtml class.
|
|
86
|
+
*
|
|
87
|
+
* @typedef {ElementAndWinAndDoc|TinyHtml} TinyElementAndWinAndDoc
|
|
88
|
+
*/
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Represents a value that can be either a DOM Element, or the global Window object, or the document object.
|
|
92
|
+
* Useful for functions that operate generically on scrollable or measurable targets.
|
|
93
|
+
*
|
|
94
|
+
* @typedef {Element|Window|Document} ElementAndWinAndDoc
|
|
95
|
+
*/
|
|
96
|
+
|
|
69
97
|
/**
|
|
70
98
|
* A parameter type used for filtering or matching elements.
|
|
71
99
|
* It can be:
|
|
@@ -82,7 +110,7 @@ const {
|
|
|
82
110
|
* Elements accepted as constructor values for TinyHtml.
|
|
83
111
|
* These include common DOM elements and root containers.
|
|
84
112
|
*
|
|
85
|
-
* @typedef {Window|Element|Document} ConstructorElValues
|
|
113
|
+
* @typedef {Window|Element|Document|Text} ConstructorElValues
|
|
86
114
|
*/
|
|
87
115
|
|
|
88
116
|
/**
|
|
@@ -203,40 +231,114 @@ class TinyHtml {
|
|
|
203
231
|
|
|
204
232
|
static Utils = { ...collision };
|
|
205
233
|
|
|
234
|
+
/**
|
|
235
|
+
* Creates a new DOM element with the specified tag name and options, then wraps it in a TinyHtml instance.
|
|
236
|
+
*
|
|
237
|
+
* @param {string} tagName - The tag name of the element to create (e.g., 'div', 'span').
|
|
238
|
+
* @param {ElementCreationOptions} ops - Optional settings for creating the element.
|
|
239
|
+
* @returns {TinyHtml} A TinyHtml instance wrapping the newly created DOM element.
|
|
240
|
+
* @throws {TypeError} If tagName is not a string or ops is not an object.
|
|
241
|
+
*/
|
|
242
|
+
static createElement(tagName, ops) {
|
|
243
|
+
if (typeof tagName !== 'string')
|
|
244
|
+
throw new TypeError(`[TinyHtml] createElement(): The tagName must be a string.`);
|
|
245
|
+
if (typeof ops !== 'undefined' && typeof ops !== 'object')
|
|
246
|
+
throw new TypeError(`[TinyHtml] createElement(): The ops must be a object.`);
|
|
247
|
+
return new TinyHtml(document.createElement(tagName, ops));
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Creates a new TinyHtml instance that wraps a DOM TextNode.
|
|
252
|
+
*
|
|
253
|
+
* This method is useful when you want to insert raw text content into the DOM
|
|
254
|
+
* without it being interpreted as HTML. The returned instance behaves like any
|
|
255
|
+
* other TinyHtml element and can be appended or manipulated as needed.
|
|
256
|
+
*
|
|
257
|
+
* @param {string} value - The plain text content to be wrapped in a TextNode.
|
|
258
|
+
* @returns {TinyHtml} A TinyHtml instance wrapping the newly created DOM TextNode.
|
|
259
|
+
* @throws {TypeError} If the provided value is not a string.
|
|
260
|
+
*/
|
|
261
|
+
static createTextNode(value) {
|
|
262
|
+
if (typeof value !== 'string')
|
|
263
|
+
throw new TypeError(`[TinyHtml] createTextNode(): The value must be a string.`);
|
|
264
|
+
return new TinyHtml(document.createTextNode(value));
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Creates an HTMLElement or TextNode from an HTML string.
|
|
269
|
+
* Supports both elements and plain text.
|
|
270
|
+
*
|
|
271
|
+
* @param {string} htmlString - The HTML string to convert.
|
|
272
|
+
* @returns {TinyHtml} - A single HTMLElement or TextNode.
|
|
273
|
+
*/
|
|
274
|
+
static createElementFromHTML(htmlString) {
|
|
275
|
+
const template = document.createElement('template');
|
|
276
|
+
htmlString = htmlString.trim();
|
|
277
|
+
|
|
278
|
+
// If it's only text (e.g., no "<" tag), return a TextNode
|
|
279
|
+
if (!htmlString.startsWith('<')) {
|
|
280
|
+
return TinyHtml.createTextNode(htmlString);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
template.innerHTML = htmlString;
|
|
284
|
+
if (!(template.content.firstChild instanceof Element)) throw new Error('');
|
|
285
|
+
return new TinyHtml(template.content.firstChild);
|
|
286
|
+
}
|
|
287
|
+
|
|
206
288
|
/**
|
|
207
289
|
* Queries the document for the first element matching the CSS selector and wraps it in a TinyHtml instance.
|
|
208
290
|
*
|
|
209
291
|
* @param {string} selector - A valid CSS selector string.
|
|
210
|
-
* @
|
|
211
|
-
* @
|
|
292
|
+
* @param {Document|Element} elem - Target element.
|
|
293
|
+
* @returns {TinyHtml|null} A TinyHtml instance wrapping the matched element.
|
|
212
294
|
*/
|
|
213
|
-
static query(selector) {
|
|
214
|
-
const newEl =
|
|
215
|
-
if (!newEl)
|
|
295
|
+
static query(selector, elem = document) {
|
|
296
|
+
const newEl = elem.querySelector(selector);
|
|
297
|
+
if (!newEl) return null;
|
|
216
298
|
return new TinyHtml(newEl);
|
|
217
299
|
}
|
|
218
300
|
|
|
301
|
+
/**
|
|
302
|
+
* Queries the element for the first element matching the CSS selector and wraps it in a TinyHtml instance.
|
|
303
|
+
*
|
|
304
|
+
* @param {string} selector - A valid CSS selector string.
|
|
305
|
+
* @returns {TinyHtml|null} A TinyHtml instance wrapping the matched element.
|
|
306
|
+
*/
|
|
307
|
+
querySelector(selector) {
|
|
308
|
+
return TinyHtml.query(selector, TinyHtml._preElem(this, 'query'));
|
|
309
|
+
}
|
|
310
|
+
|
|
219
311
|
/**
|
|
220
312
|
* Queries the document for all elements matching the CSS selector and wraps them in TinyHtml instances.
|
|
221
313
|
*
|
|
222
314
|
* @param {string} selector - A valid CSS selector string.
|
|
315
|
+
* @param {Document|Element} elem - Target element.
|
|
223
316
|
* @returns {TinyHtml[]} An array of TinyHtml instances wrapping the matched elements.
|
|
224
317
|
*/
|
|
225
|
-
static queryAll(selector) {
|
|
226
|
-
const newEls =
|
|
318
|
+
static queryAll(selector, elem = document) {
|
|
319
|
+
const newEls = elem.querySelectorAll(selector);
|
|
227
320
|
return TinyHtml.toTinyElm([...newEls]);
|
|
228
321
|
}
|
|
229
322
|
|
|
323
|
+
/**
|
|
324
|
+
* Queries the element for all elements matching the CSS selector and wraps them in TinyHtml instances.
|
|
325
|
+
*
|
|
326
|
+
* @param {string} selector - A valid CSS selector string.
|
|
327
|
+
* @returns {TinyHtml[]} An array of TinyHtml instances wrapping the matched elements.
|
|
328
|
+
*/
|
|
329
|
+
querySelectorAll(selector) {
|
|
330
|
+
return TinyHtml.queryAll(selector, TinyHtml._preElem(this, 'queryAll'));
|
|
331
|
+
}
|
|
332
|
+
|
|
230
333
|
/**
|
|
231
334
|
* Retrieves an element by its ID and wraps it in a TinyHtml instance.
|
|
232
335
|
*
|
|
233
336
|
* @param {string} selector - The ID of the element to retrieve.
|
|
234
|
-
* @returns {TinyHtml} A TinyHtml instance wrapping the found element.
|
|
235
|
-
* @throws {Error} If no element is found with the specified ID.
|
|
337
|
+
* @returns {TinyHtml|null} A TinyHtml instance wrapping the found element.
|
|
236
338
|
*/
|
|
237
339
|
static getById(selector) {
|
|
238
340
|
const newEl = document.getElementById(selector);
|
|
239
|
-
if (!newEl)
|
|
341
|
+
if (!newEl) return null;
|
|
240
342
|
return new TinyHtml(newEl);
|
|
241
343
|
}
|
|
242
344
|
|
|
@@ -244,13 +346,24 @@ class TinyHtml {
|
|
|
244
346
|
* Retrieves all elements with the specified class name and wraps them in TinyHtml instances.
|
|
245
347
|
*
|
|
246
348
|
* @param {string} selector - The class name to search for.
|
|
349
|
+
* @param {Document|Element} elem - Target element.
|
|
247
350
|
* @returns {TinyHtml[]} An array of TinyHtml instances wrapping the found elements.
|
|
248
351
|
*/
|
|
249
|
-
static getByClassName(selector) {
|
|
250
|
-
const newEls =
|
|
352
|
+
static getByClassName(selector, elem = document) {
|
|
353
|
+
const newEls = elem.getElementsByClassName(selector);
|
|
251
354
|
return TinyHtml.toTinyElm([...newEls]);
|
|
252
355
|
}
|
|
253
356
|
|
|
357
|
+
/**
|
|
358
|
+
* Retrieves all elements with the specified class name and wraps them in TinyHtml instances.
|
|
359
|
+
*
|
|
360
|
+
* @param {string} selector - The class name to search for.
|
|
361
|
+
* @returns {TinyHtml[]} An array of TinyHtml instances wrapping the found elements.
|
|
362
|
+
*/
|
|
363
|
+
getElementsByClassName(selector) {
|
|
364
|
+
return TinyHtml.getByClassName(selector, TinyHtml._preElem(this, 'getByClassName'));
|
|
365
|
+
}
|
|
366
|
+
|
|
254
367
|
/**
|
|
255
368
|
* Retrieves all elements with the specified name attribute and wraps them in TinyHtml instances.
|
|
256
369
|
*
|
|
@@ -268,13 +381,30 @@ class TinyHtml {
|
|
|
268
381
|
*
|
|
269
382
|
* @param {string} localName - The local name (tag) of the elements to search for.
|
|
270
383
|
* @param {string|null} [namespaceURI='http://www.w3.org/1999/xhtml'] - The namespace URI to search within.
|
|
384
|
+
* @param {Document|Element} elem - Target element.
|
|
271
385
|
* @returns {TinyHtml[]} An array of TinyHtml instances wrapping the found elements.
|
|
272
386
|
*/
|
|
273
|
-
static getByTagNameNS(localName, namespaceURI = 'http://www.w3.org/1999/xhtml') {
|
|
274
|
-
const newEls =
|
|
387
|
+
static getByTagNameNS(localName, namespaceURI = 'http://www.w3.org/1999/xhtml', elem = document) {
|
|
388
|
+
const newEls = elem.getElementsByTagNameNS(namespaceURI, localName);
|
|
275
389
|
return TinyHtml.toTinyElm([...newEls]);
|
|
276
390
|
}
|
|
277
391
|
|
|
392
|
+
/**
|
|
393
|
+
* Retrieves all elements with the specified local tag name within the given namespace URI,
|
|
394
|
+
* and wraps them in TinyHtml instances.
|
|
395
|
+
*
|
|
396
|
+
* @param {string} localName - The local name (tag) of the elements to search for.
|
|
397
|
+
* @param {string|null} [namespaceURI='http://www.w3.org/1999/xhtml'] - The namespace URI to search within.
|
|
398
|
+
* @returns {TinyHtml[]} An array of TinyHtml instances wrapping the found elements.
|
|
399
|
+
*/
|
|
400
|
+
getElementsByTagNameNS(localName, namespaceURI = 'http://www.w3.org/1999/xhtml') {
|
|
401
|
+
return TinyHtml.getByTagNameNS(
|
|
402
|
+
localName,
|
|
403
|
+
namespaceURI,
|
|
404
|
+
TinyHtml._preElem(this, 'getByTagNameNS'),
|
|
405
|
+
);
|
|
406
|
+
}
|
|
407
|
+
|
|
278
408
|
//////////////////////////////////////////////////////////////////
|
|
279
409
|
|
|
280
410
|
/**
|
|
@@ -555,6 +685,45 @@ class TinyHtml {
|
|
|
555
685
|
return TinyHtml._preElemTemplate(elems, where, [Element, Window], ['Element', 'Window']);
|
|
556
686
|
}
|
|
557
687
|
|
|
688
|
+
/**
|
|
689
|
+
* Ensures the input is returned as an array.
|
|
690
|
+
* Useful to normalize operations across multiple or single element/window/document elements.
|
|
691
|
+
*
|
|
692
|
+
* @param {TinyElementAndWinAndDoc|TinyElementAndWinAndDoc[]} elems - A single element/window element or array of html elements.
|
|
693
|
+
* @param {string} where - The method or context name where validation is being called.
|
|
694
|
+
* @returns {ElementAndWindow[]} - Always returns an array of element/window elements.
|
|
695
|
+
* @readonly
|
|
696
|
+
*/
|
|
697
|
+
static _preElemsAndWinAndDoc(elems, where) {
|
|
698
|
+
const result = TinyHtml._preElemsTemplate(
|
|
699
|
+
elems,
|
|
700
|
+
where,
|
|
701
|
+
[Element, Window, Document],
|
|
702
|
+
['Element', 'Window', 'Document'],
|
|
703
|
+
);
|
|
704
|
+
return result.map((elem) => (!(elem instanceof Document) ? elem : elem.documentElement));
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
/**
|
|
708
|
+
* Ensures the input is returned as an single element/window/document element.
|
|
709
|
+
* Useful to normalize operations across multiple or single element/window/document elements.
|
|
710
|
+
*
|
|
711
|
+
* @param {TinyElementAndWinAndDoc|TinyElementAndWinAndDoc[]} elems - A single element/window element or array of html elements.
|
|
712
|
+
* @param {string} where - The method or context name where validation is being called.
|
|
713
|
+
* @returns {ElementAndWindow} - Always returns an single element/window element.
|
|
714
|
+
* @readonly
|
|
715
|
+
*/
|
|
716
|
+
static _preElemAndWinAndDoc(elems, where) {
|
|
717
|
+
const result = TinyHtml._preElemTemplate(
|
|
718
|
+
elems,
|
|
719
|
+
where,
|
|
720
|
+
[Element, Window, Document],
|
|
721
|
+
['Element', 'Window', 'Document'],
|
|
722
|
+
);
|
|
723
|
+
if (result instanceof Document) return result.documentElement;
|
|
724
|
+
return result;
|
|
725
|
+
}
|
|
726
|
+
|
|
558
727
|
/**
|
|
559
728
|
* Normalizes and converts one or more DOM elements (or TinyHtml instances)
|
|
560
729
|
* into an array of `TinyHtml` instances.
|
|
@@ -901,12 +1070,13 @@ class TinyHtml {
|
|
|
901
1070
|
* @param {string} key - The key under which the data will be stored.
|
|
902
1071
|
* @param {any} value - The value to store.
|
|
903
1072
|
* @param {boolean} [isPrivate=false] - Whether to store the data in the private store.
|
|
904
|
-
* @returns {
|
|
1073
|
+
* @returns {TinyElement}
|
|
905
1074
|
*/
|
|
906
1075
|
static setData(el, key, value, isPrivate = false) {
|
|
907
1076
|
const data = TinyHtml._dataSelector[!isPrivate ? 'public' : 'private']('setData', el);
|
|
908
1077
|
if (typeof key !== 'string') throw new TypeError('The key must be a string.');
|
|
909
1078
|
data[key] = value;
|
|
1079
|
+
return el;
|
|
910
1080
|
}
|
|
911
1081
|
|
|
912
1082
|
/**
|
|
@@ -915,7 +1085,7 @@ class TinyHtml {
|
|
|
915
1085
|
* @param {string} key - The key under which the data will be stored.
|
|
916
1086
|
* @param {any} value - The value to store.
|
|
917
1087
|
* @param {boolean} [isPrivate=false] - Whether to store the data in the private store.
|
|
918
|
-
* @returns {
|
|
1088
|
+
* @returns {TinyElement}
|
|
919
1089
|
*/
|
|
920
1090
|
setData(key, value, isPrivate = false) {
|
|
921
1091
|
return TinyHtml.setData(this, key, value, isPrivate);
|
|
@@ -1262,18 +1432,21 @@ class TinyHtml {
|
|
|
1262
1432
|
/**
|
|
1263
1433
|
* Appends child elements or strings to the end of the target element(s).
|
|
1264
1434
|
*
|
|
1265
|
-
* @param {TinyElement
|
|
1435
|
+
* @param {TinyElement} el - The target element(s) to receive children.
|
|
1266
1436
|
* @param {...(TinyNode | TinyNode[] | string)} children - The child elements or text to append.
|
|
1437
|
+
* @returns {TinyElement}
|
|
1267
1438
|
*/
|
|
1268
1439
|
static append(el, ...children) {
|
|
1269
1440
|
const elem = TinyHtml._preElem(el, 'append');
|
|
1270
1441
|
elem.append(...TinyHtml._appendChecker('append', ...children));
|
|
1442
|
+
return el;
|
|
1271
1443
|
}
|
|
1272
1444
|
|
|
1273
1445
|
/**
|
|
1274
1446
|
* Appends child elements or strings to the end of the target element(s).
|
|
1275
1447
|
*
|
|
1276
1448
|
* @param {...(TinyNode | TinyNode[] | string)} children - The child elements or text to append.
|
|
1449
|
+
* @returns {TinyElement}
|
|
1277
1450
|
*/
|
|
1278
1451
|
append(...children) {
|
|
1279
1452
|
return TinyHtml.append(this, ...children);
|
|
@@ -1282,18 +1455,21 @@ class TinyHtml {
|
|
|
1282
1455
|
/**
|
|
1283
1456
|
* Prepends child elements or strings to the beginning of the target element(s).
|
|
1284
1457
|
*
|
|
1285
|
-
* @param {TinyElement
|
|
1458
|
+
* @param {TinyElement} el - The target element(s) to receive children.
|
|
1286
1459
|
* @param {...(TinyNode | TinyNode[] | string)} children - The child elements or text to prepend.
|
|
1460
|
+
* @returns {TinyElement}
|
|
1287
1461
|
*/
|
|
1288
1462
|
static prepend(el, ...children) {
|
|
1289
1463
|
const elem = TinyHtml._preElem(el, 'prepend');
|
|
1290
1464
|
elem.prepend(...TinyHtml._appendChecker('prepend', ...children));
|
|
1465
|
+
return el;
|
|
1291
1466
|
}
|
|
1292
1467
|
|
|
1293
1468
|
/**
|
|
1294
1469
|
* Prepends child elements or strings to the beginning of the target element(s).
|
|
1295
1470
|
*
|
|
1296
1471
|
* @param {...(TinyNode | TinyNode[] | string)} children - The child elements or text to prepend.
|
|
1472
|
+
* @returns {TinyElement}
|
|
1297
1473
|
*/
|
|
1298
1474
|
prepend(...children) {
|
|
1299
1475
|
return TinyHtml.prepend(this, ...children);
|
|
@@ -1302,18 +1478,21 @@ class TinyHtml {
|
|
|
1302
1478
|
/**
|
|
1303
1479
|
* Inserts elements or strings immediately before the target element(s) in the DOM.
|
|
1304
1480
|
*
|
|
1305
|
-
* @param {TinyElement
|
|
1481
|
+
* @param {TinyElement} el - The target element(s) before which new content is inserted.
|
|
1306
1482
|
* @param {...(TinyNode | TinyNode[] | string)} children - Elements or text to insert before the target.
|
|
1483
|
+
* @returns {TinyElement}
|
|
1307
1484
|
*/
|
|
1308
1485
|
static before(el, ...children) {
|
|
1309
1486
|
const elem = TinyHtml._preElem(el, 'before');
|
|
1310
1487
|
elem.before(...TinyHtml._appendChecker('before', ...children));
|
|
1488
|
+
return el;
|
|
1311
1489
|
}
|
|
1312
1490
|
|
|
1313
1491
|
/**
|
|
1314
1492
|
* Inserts elements or strings immediately before the target element(s) in the DOM.
|
|
1315
1493
|
*
|
|
1316
1494
|
* @param {...(TinyNode | TinyNode[] | string)} children - Elements or text to insert before the target.
|
|
1495
|
+
* @returns {TinyElement}
|
|
1317
1496
|
*/
|
|
1318
1497
|
before(...children) {
|
|
1319
1498
|
return TinyHtml.before(this, ...children);
|
|
@@ -1322,18 +1501,21 @@ class TinyHtml {
|
|
|
1322
1501
|
/**
|
|
1323
1502
|
* Inserts elements or strings immediately after the target element(s) in the DOM.
|
|
1324
1503
|
*
|
|
1325
|
-
* @param {TinyElement
|
|
1504
|
+
* @param {TinyElement} el - The target element(s) after which new content is inserted.
|
|
1326
1505
|
* @param {...(TinyNode | TinyNode[] | string)} children - Elements or text to insert after the target.
|
|
1506
|
+
* @returns {TinyElement}
|
|
1327
1507
|
*/
|
|
1328
1508
|
static after(el, ...children) {
|
|
1329
1509
|
const elem = TinyHtml._preElem(el, 'after');
|
|
1330
1510
|
elem.after(...TinyHtml._appendChecker('after', ...children));
|
|
1511
|
+
return el;
|
|
1331
1512
|
}
|
|
1332
1513
|
|
|
1333
1514
|
/**
|
|
1334
1515
|
* Inserts elements or strings immediately after the target element(s) in the DOM.
|
|
1335
1516
|
*
|
|
1336
1517
|
* @param {...(TinyNode | TinyNode[] | string)} children - Elements or text to insert after the target.
|
|
1518
|
+
* @returns {TinyElement}
|
|
1337
1519
|
*/
|
|
1338
1520
|
after(...children) {
|
|
1339
1521
|
return TinyHtml.after(this, ...children);
|
|
@@ -1342,18 +1524,21 @@ class TinyHtml {
|
|
|
1342
1524
|
/**
|
|
1343
1525
|
* Replaces the target element(s) in the DOM with new elements or text.
|
|
1344
1526
|
*
|
|
1345
|
-
* @param {TinyElement
|
|
1527
|
+
* @param {TinyElement} el - The element(s) to be replaced.
|
|
1346
1528
|
* @param {...(TinyNode | TinyNode[] | string)} newNodes - New elements or text to replace the target.
|
|
1529
|
+
* @returns {TinyElement}
|
|
1347
1530
|
*/
|
|
1348
1531
|
static replaceWith(el, ...newNodes) {
|
|
1349
1532
|
const elem = TinyHtml._preElem(el, 'replaceWith');
|
|
1350
1533
|
elem.replaceWith(...TinyHtml._appendChecker('replaceWith', ...newNodes));
|
|
1534
|
+
return el;
|
|
1351
1535
|
}
|
|
1352
1536
|
|
|
1353
1537
|
/**
|
|
1354
1538
|
* Replaces the target element(s) in the DOM with new elements or text.
|
|
1355
1539
|
*
|
|
1356
1540
|
* @param {...(TinyNode | TinyNode[] | string)} newNodes - New elements or text to replace the target.
|
|
1541
|
+
* @returns {TinyElement}
|
|
1357
1542
|
*/
|
|
1358
1543
|
replaceWith(...newNodes) {
|
|
1359
1544
|
return TinyHtml.replaceWith(this, ...newNodes);
|
|
@@ -1364,6 +1549,7 @@ class TinyHtml {
|
|
|
1364
1549
|
*
|
|
1365
1550
|
* @param {TinyNode | TinyNode[]} el - The element(s) to append.
|
|
1366
1551
|
* @param {TinyNode | TinyNode[]} targets - Target element(s) where content will be appended.
|
|
1552
|
+
* @returns {TinyNode|TinyNode[]}
|
|
1367
1553
|
*/
|
|
1368
1554
|
static appendTo(el, targets) {
|
|
1369
1555
|
const elems = TinyHtml._preNodeElems(el, 'appendTo');
|
|
@@ -1373,12 +1559,14 @@ class TinyHtml {
|
|
|
1373
1559
|
target.appendChild(i === tars.length - 1 ? elem : elem.cloneNode(true)),
|
|
1374
1560
|
);
|
|
1375
1561
|
});
|
|
1562
|
+
return el;
|
|
1376
1563
|
}
|
|
1377
1564
|
|
|
1378
1565
|
/**
|
|
1379
1566
|
* Appends the given element(s) to each target element in sequence.
|
|
1380
1567
|
*
|
|
1381
1568
|
* @param {TinyNode | TinyNode[]} targets - Target element(s) where content will be appended.
|
|
1569
|
+
* @returns {TinyNode|TinyNode[]}
|
|
1382
1570
|
*/
|
|
1383
1571
|
appendTo(targets) {
|
|
1384
1572
|
return TinyHtml.appendTo(this, targets);
|
|
@@ -1389,6 +1577,7 @@ class TinyHtml {
|
|
|
1389
1577
|
*
|
|
1390
1578
|
* @param {TinyElement | TinyElement[]} el - The element(s) to prepend.
|
|
1391
1579
|
* @param {TinyElement | TinyElement[]} targets - Target element(s) where content will be prepended.
|
|
1580
|
+
* @returns {TinyElement|TinyElement[]}
|
|
1392
1581
|
*/
|
|
1393
1582
|
static prependTo(el, targets) {
|
|
1394
1583
|
const elems = TinyHtml._preElems(el, 'prependTo');
|
|
@@ -1399,12 +1588,14 @@ class TinyHtml {
|
|
|
1399
1588
|
.reverse()
|
|
1400
1589
|
.forEach((elem) => target.prepend(i === tars.length - 1 ? elem : elem.cloneNode(true)));
|
|
1401
1590
|
});
|
|
1591
|
+
return el;
|
|
1402
1592
|
}
|
|
1403
1593
|
|
|
1404
1594
|
/**
|
|
1405
1595
|
* Prepends the given element(s) to each target element in sequence.
|
|
1406
1596
|
*
|
|
1407
1597
|
* @param {TinyElement | TinyElement[]} targets - Target element(s) where content will be prepended.
|
|
1598
|
+
* @returns {TinyElement|TinyElement[]}
|
|
1408
1599
|
*/
|
|
1409
1600
|
prependTo(targets) {
|
|
1410
1601
|
return TinyHtml.prependTo(this, targets);
|
|
@@ -1416,6 +1607,7 @@ class TinyHtml {
|
|
|
1416
1607
|
* @param {TinyNode | TinyNode[]} el - The element(s) to insert.
|
|
1417
1608
|
* @param {TinyNode | TinyNode[]} target - The reference element where insertion happens.
|
|
1418
1609
|
* @param {TinyNode | TinyNode[] | null} [child=null] - Optional child to insert before, defaults to target.
|
|
1610
|
+
* @returns {TinyNode|TinyNode[]}
|
|
1419
1611
|
*/
|
|
1420
1612
|
static insertBefore(el, target, child = null) {
|
|
1421
1613
|
const elem = TinyHtml._preNodeElem(el, 'insertBefore');
|
|
@@ -1423,6 +1615,7 @@ class TinyHtml {
|
|
|
1423
1615
|
const childNode = TinyHtml._preNodeElemWithNull(child, 'insertBefore');
|
|
1424
1616
|
if (!targ.parentNode) throw new Error('');
|
|
1425
1617
|
targ.parentNode.insertBefore(elem, childNode || targ);
|
|
1618
|
+
return el;
|
|
1426
1619
|
}
|
|
1427
1620
|
|
|
1428
1621
|
/**
|
|
@@ -1430,6 +1623,7 @@ class TinyHtml {
|
|
|
1430
1623
|
*
|
|
1431
1624
|
* @param {TinyNode | TinyNode[]} target - The reference element where insertion happens.
|
|
1432
1625
|
* @param {TinyNode | TinyNode[] | null} [child=null] - Optional child to insert before, defaults to target.
|
|
1626
|
+
* @returns {TinyNode|TinyNode[]}
|
|
1433
1627
|
*/
|
|
1434
1628
|
insertBefore(target, child) {
|
|
1435
1629
|
return TinyHtml.insertBefore(this, target, child);
|
|
@@ -1441,6 +1635,7 @@ class TinyHtml {
|
|
|
1441
1635
|
* @param {TinyNode | TinyNode[]} el - The element(s) to insert.
|
|
1442
1636
|
* @param {TinyNode | TinyNode[]} target - The reference element where insertion happens.
|
|
1443
1637
|
* @param {TinyNode | TinyNode[] | null} [child=null] - Optional child to insert after, defaults to target.
|
|
1638
|
+
* @returns {TinyNode|TinyNode[]}
|
|
1444
1639
|
*/
|
|
1445
1640
|
static insertAfter(el, target, child = null) {
|
|
1446
1641
|
const elem = TinyHtml._preNodeElem(el, 'insertAfter');
|
|
@@ -1448,6 +1643,7 @@ class TinyHtml {
|
|
|
1448
1643
|
const childNode = TinyHtml._preNodeElemWithNull(child, 'insertBefore');
|
|
1449
1644
|
if (!targ.parentNode) throw new Error('');
|
|
1450
1645
|
targ.parentNode.insertBefore(elem, childNode || targ.nextSibling);
|
|
1646
|
+
return el;
|
|
1451
1647
|
}
|
|
1452
1648
|
|
|
1453
1649
|
/**
|
|
@@ -1455,6 +1651,7 @@ class TinyHtml {
|
|
|
1455
1651
|
*
|
|
1456
1652
|
* @param {TinyNode | TinyNode[]} target - The reference element where insertion happens.
|
|
1457
1653
|
* @param {TinyNode | TinyNode[] | null} [child=null] - Optional child to insert after, defaults to target.
|
|
1654
|
+
* @returns {TinyNode|TinyNode[]}
|
|
1458
1655
|
*/
|
|
1459
1656
|
insertAfter(target, child) {
|
|
1460
1657
|
return TinyHtml.insertAfter(this, target, child);
|
|
@@ -1466,6 +1663,7 @@ class TinyHtml {
|
|
|
1466
1663
|
*
|
|
1467
1664
|
* @param {TinyNode | TinyNode[]} el - The new element(s) to insert.
|
|
1468
1665
|
* @param {TinyNode | TinyNode[]} targets - The elements to be replaced.
|
|
1666
|
+
* @returns {TinyNode|TinyNode[]}
|
|
1469
1667
|
*/
|
|
1470
1668
|
static replaceAll(el, targets) {
|
|
1471
1669
|
const elems = TinyHtml._preNodeElems(el, 'replaceAll');
|
|
@@ -1477,6 +1675,7 @@ class TinyHtml {
|
|
|
1477
1675
|
parent.replaceChild(i === tars.length - 1 ? elem : elem.cloneNode(true), target);
|
|
1478
1676
|
});
|
|
1479
1677
|
});
|
|
1678
|
+
return el;
|
|
1480
1679
|
}
|
|
1481
1680
|
|
|
1482
1681
|
/**
|
|
@@ -1484,6 +1683,7 @@ class TinyHtml {
|
|
|
1484
1683
|
* If multiple targets exist, the inserted elements are cloned accordingly.
|
|
1485
1684
|
*
|
|
1486
1685
|
* @param {TinyNode | TinyNode[]} targets - The elements to be replaced.
|
|
1686
|
+
* @returns {TinyNode|TinyNode[]}
|
|
1487
1687
|
*/
|
|
1488
1688
|
replaceAll(targets) {
|
|
1489
1689
|
return TinyHtml.replaceAll(this, targets);
|
|
@@ -1507,7 +1707,12 @@ class TinyHtml {
|
|
|
1507
1707
|
throw new Error(
|
|
1508
1708
|
`[TinyHtml] You are trying to put a TinyHtml inside another TinyHtml in constructor.`,
|
|
1509
1709
|
);
|
|
1510
|
-
if (
|
|
1710
|
+
if (
|
|
1711
|
+
!(el instanceof Element) &&
|
|
1712
|
+
!(el instanceof Window) &&
|
|
1713
|
+
!(el instanceof Document) &&
|
|
1714
|
+
!(el instanceof Text)
|
|
1715
|
+
)
|
|
1511
1716
|
throw new Error(`[TinyHtml] Invalid Target in constructor.`);
|
|
1512
1717
|
this.#el = el;
|
|
1513
1718
|
}
|
|
@@ -1957,6 +2162,7 @@ class TinyHtml {
|
|
|
1957
2162
|
* @param {TinyHtmlElement|TinyHtmlElement[]} el - The element to inspect.
|
|
1958
2163
|
* @param {string|Object} prop - The property name or an object with key-value pairs
|
|
1959
2164
|
* @param {string|null} [value=null] - The value to set (if `prop` is a string)
|
|
2165
|
+
* @returns {TinyHtmlElement|TinyHtmlElement[]}
|
|
1960
2166
|
*/
|
|
1961
2167
|
static setStyle(el, prop, value = null) {
|
|
1962
2168
|
TinyHtml._preHtmlElems(el, 'setStyle').forEach((elem) => {
|
|
@@ -1969,6 +2175,7 @@ class TinyHtml {
|
|
|
1969
2175
|
}
|
|
1970
2176
|
} else elem.style.setProperty(TinyHtml.toStyleKc(prop), value);
|
|
1971
2177
|
});
|
|
2178
|
+
return el;
|
|
1972
2179
|
}
|
|
1973
2180
|
|
|
1974
2181
|
/**
|
|
@@ -1979,6 +2186,7 @@ class TinyHtml {
|
|
|
1979
2186
|
*
|
|
1980
2187
|
* @param {string|Object} prop - The property name or an object with key-value pairs
|
|
1981
2188
|
* @param {string|null} [value=null] - The value to set (if `prop` is a string)
|
|
2189
|
+
* @returns {TinyHtmlElement|TinyHtmlElement[]}
|
|
1982
2190
|
*/
|
|
1983
2191
|
setStyle(prop, value) {
|
|
1984
2192
|
return TinyHtml.setStyle(this, prop, value);
|
|
@@ -2074,6 +2282,7 @@ class TinyHtml {
|
|
|
2074
2282
|
*
|
|
2075
2283
|
* @param {TinyHtmlElement|TinyHtmlElement[]} el - A single element or an array of elements.
|
|
2076
2284
|
* @param {string|string[]} prop - A property name or an array of property names to remove.
|
|
2285
|
+
* @returns {TinyHtmlElement|TinyHtmlElement[]}
|
|
2077
2286
|
*/
|
|
2078
2287
|
static removeStyle(el, prop) {
|
|
2079
2288
|
TinyHtml._preHtmlElems(el, 'removeStyle').forEach((elem) => {
|
|
@@ -2083,12 +2292,14 @@ class TinyHtml {
|
|
|
2083
2292
|
}
|
|
2084
2293
|
} else elem.style.removeProperty(TinyHtml.toStyleKc(prop));
|
|
2085
2294
|
});
|
|
2295
|
+
return el;
|
|
2086
2296
|
}
|
|
2087
2297
|
|
|
2088
2298
|
/**
|
|
2089
2299
|
* Removes one or more inline CSS properties from the given element(s).
|
|
2090
2300
|
*
|
|
2091
2301
|
* @param {string|string[]} prop - A property name or an array of property names to remove.
|
|
2302
|
+
* @returns {TinyHtmlElement|TinyHtmlElement[]}
|
|
2092
2303
|
*/
|
|
2093
2304
|
removeStyle(prop) {
|
|
2094
2305
|
return TinyHtml.removeStyle(this, prop);
|
|
@@ -2103,6 +2314,7 @@ class TinyHtml {
|
|
|
2103
2314
|
* @param {string} prop - The CSS property to toggle.
|
|
2104
2315
|
* @param {string} val1 - The first value (used as "current" check).
|
|
2105
2316
|
* @param {string} val2 - The second value (used as the "alternative").
|
|
2317
|
+
* @returns {TinyHtmlElement|TinyHtmlElement[]}
|
|
2106
2318
|
*/
|
|
2107
2319
|
static toggleStyle(el, prop, val1, val2) {
|
|
2108
2320
|
TinyHtml._preHtmlElems(el, 'toggleStyle').forEach((elem) => {
|
|
@@ -2110,6 +2322,7 @@ class TinyHtml {
|
|
|
2110
2322
|
const newVal = current === TinyHtml.toStyleKc(val1) ? val2 : val1;
|
|
2111
2323
|
TinyHtml.setStyle(elem, prop, newVal);
|
|
2112
2324
|
});
|
|
2325
|
+
return el;
|
|
2113
2326
|
}
|
|
2114
2327
|
|
|
2115
2328
|
/**
|
|
@@ -2120,6 +2333,7 @@ class TinyHtml {
|
|
|
2120
2333
|
* @param {string} prop - The CSS property to toggle.
|
|
2121
2334
|
* @param {string} val1 - The first value (used as "current" check).
|
|
2122
2335
|
* @param {string} val2 - The second value (used as the "alternative").
|
|
2336
|
+
* @returns {TinyHtmlElement|TinyHtmlElement[]}
|
|
2123
2337
|
*/
|
|
2124
2338
|
toggleStyle(prop, val1, val2) {
|
|
2125
2339
|
return TinyHtml.toggleStyle(this, prop, val1, val2);
|
|
@@ -2129,14 +2343,16 @@ class TinyHtml {
|
|
|
2129
2343
|
* Removes all inline styles (`style` attribute) from the given element(s).
|
|
2130
2344
|
*
|
|
2131
2345
|
* @param {TinyElement|TinyElement[]} el - A single element or an array of elements.
|
|
2346
|
+
* @returns {TinyElement|TinyElement[]}
|
|
2132
2347
|
*/
|
|
2133
2348
|
static clearStyle(el) {
|
|
2134
2349
|
TinyHtml._preElems(el, 'clearStyle').forEach((elem) => elem.removeAttribute('style'));
|
|
2350
|
+
return el;
|
|
2135
2351
|
}
|
|
2136
2352
|
|
|
2137
2353
|
/**
|
|
2138
2354
|
* Removes all inline styles (`style` attribute) from the given element(s).
|
|
2139
|
-
*
|
|
2355
|
+
* @returns {TinyElement|TinyElement[]}
|
|
2140
2356
|
*/
|
|
2141
2357
|
clearStyle() {
|
|
2142
2358
|
return TinyHtml.clearStyle(this);
|
|
@@ -2148,14 +2364,17 @@ class TinyHtml {
|
|
|
2148
2364
|
* Focus the element.
|
|
2149
2365
|
*
|
|
2150
2366
|
* @param {TinyHtmlElement} el - The element or a selector string.
|
|
2367
|
+
* @returns {TinyHtmlElement}
|
|
2151
2368
|
*/
|
|
2152
2369
|
static focus(el) {
|
|
2153
2370
|
const elem = TinyHtml._preHtmlElem(el, 'focus');
|
|
2154
2371
|
elem.focus();
|
|
2372
|
+
return el;
|
|
2155
2373
|
}
|
|
2156
2374
|
|
|
2157
2375
|
/**
|
|
2158
2376
|
* Focus the element.
|
|
2377
|
+
* @returns {TinyHtmlElement}
|
|
2159
2378
|
*/
|
|
2160
2379
|
focus() {
|
|
2161
2380
|
return TinyHtml.focus(this);
|
|
@@ -2165,19 +2384,46 @@ class TinyHtml {
|
|
|
2165
2384
|
* Blur the element.
|
|
2166
2385
|
*
|
|
2167
2386
|
* @param {TinyHtmlElement} el - The element or a selector string.
|
|
2387
|
+
* @returns {TinyHtmlElement}
|
|
2168
2388
|
*/
|
|
2169
2389
|
static blur(el) {
|
|
2170
2390
|
const elem = TinyHtml._preHtmlElem(el, 'blur');
|
|
2171
2391
|
elem.blur();
|
|
2392
|
+
return el;
|
|
2172
2393
|
}
|
|
2173
2394
|
|
|
2174
2395
|
/**
|
|
2175
2396
|
* Blur the element.
|
|
2397
|
+
* @returns {TinyHtmlElement}
|
|
2176
2398
|
*/
|
|
2177
2399
|
blur() {
|
|
2178
2400
|
return TinyHtml.blur(this);
|
|
2179
2401
|
}
|
|
2180
2402
|
|
|
2403
|
+
/**
|
|
2404
|
+
* Interprets a value as a boolean `true` if it matches a common truthy representation.
|
|
2405
|
+
*
|
|
2406
|
+
* This method checks if the input is any of the common forms used to represent `true`,
|
|
2407
|
+
* such as the string `'true'`, `'1'`, `'on'`, the boolean `true`, or the number `1`.
|
|
2408
|
+
*
|
|
2409
|
+
* @param {string|boolean|number} [value] - The value to interpret as boolean.
|
|
2410
|
+
* @returns {boolean} `true` if the value represents a truthy state, otherwise `false`.
|
|
2411
|
+
*/
|
|
2412
|
+
static boolCheck(value) {
|
|
2413
|
+
if (
|
|
2414
|
+
typeof value !== 'undefined' &&
|
|
2415
|
+
(value === 'true' ||
|
|
2416
|
+
value === '1' ||
|
|
2417
|
+
value === true ||
|
|
2418
|
+
value === 'on' ||
|
|
2419
|
+
(typeof value === 'number' && value > 0))
|
|
2420
|
+
) {
|
|
2421
|
+
return true;
|
|
2422
|
+
} else {
|
|
2423
|
+
return false;
|
|
2424
|
+
}
|
|
2425
|
+
}
|
|
2426
|
+
|
|
2181
2427
|
//////////////////////////////////////////////////////////////////////
|
|
2182
2428
|
|
|
2183
2429
|
/**
|
|
@@ -2186,7 +2432,7 @@ class TinyHtml {
|
|
|
2186
2432
|
*/
|
|
2187
2433
|
static setWinScrollTop(value) {
|
|
2188
2434
|
if (typeof value !== 'number') throw new TypeError('The value must be a number.');
|
|
2189
|
-
|
|
2435
|
+
TinyHtml.setScrollTop(window, value);
|
|
2190
2436
|
}
|
|
2191
2437
|
|
|
2192
2438
|
/**
|
|
@@ -2195,7 +2441,7 @@ class TinyHtml {
|
|
|
2195
2441
|
*/
|
|
2196
2442
|
static setWinScrollLeft(value) {
|
|
2197
2443
|
if (typeof value !== 'number') throw new TypeError('The value must be a number.');
|
|
2198
|
-
|
|
2444
|
+
TinyHtml.setScrollLeft(window, value);
|
|
2199
2445
|
}
|
|
2200
2446
|
|
|
2201
2447
|
/**
|
|
@@ -2230,16 +2476,40 @@ class TinyHtml {
|
|
|
2230
2476
|
return window.innerWidth || document.documentElement.clientWidth;
|
|
2231
2477
|
}
|
|
2232
2478
|
|
|
2479
|
+
/**
|
|
2480
|
+
* Checks if the page is currently scrolled to the very top.
|
|
2481
|
+
*
|
|
2482
|
+
* This method compares the current vertical scroll position with the total document height.
|
|
2483
|
+
* It's useful for detecting if the user has reached the top of the page.
|
|
2484
|
+
*
|
|
2485
|
+
* @returns {boolean} `true` if the page is scrolled to the top, otherwise `false`.
|
|
2486
|
+
*/
|
|
2487
|
+
static isPageTop() {
|
|
2488
|
+
return window.scrollY === 0;
|
|
2489
|
+
}
|
|
2490
|
+
|
|
2491
|
+
/**
|
|
2492
|
+
* Checks if the page is currently scrolled to the very bottom.
|
|
2493
|
+
*
|
|
2494
|
+
* This method uses the `scrollY` and `innerHeight` properties to determine if the
|
|
2495
|
+
* user has reached the end of the document.
|
|
2496
|
+
*
|
|
2497
|
+
* @returns {boolean} `true` if the page is scrolled to the bottom, otherwise `false`.
|
|
2498
|
+
*/
|
|
2499
|
+
static isPageBottom() {
|
|
2500
|
+
return window.innerHeight + window.scrollY >= document.body.offsetHeight;
|
|
2501
|
+
}
|
|
2502
|
+
|
|
2233
2503
|
/**
|
|
2234
2504
|
* Gets the width or height of an element based on the box model.
|
|
2235
|
-
* @param {
|
|
2505
|
+
* @param {TinyElementAndWinAndDoc} el - The element or window.
|
|
2236
2506
|
* @param {"width"|"height"} type - Dimension type.
|
|
2237
2507
|
* @param {"content"|"padding"|"border"|"margin"} [extra='content'] - Box model context.
|
|
2238
2508
|
* @returns {number} - Computed dimension.
|
|
2239
2509
|
* @throws {TypeError} If `type` or `extra` is not a string.
|
|
2240
2510
|
*/
|
|
2241
2511
|
static getDimension(el, type, extra = 'content') {
|
|
2242
|
-
const elem = TinyHtml.
|
|
2512
|
+
const elem = TinyHtml._preElemAndWinAndDoc(el, 'getDimension');
|
|
2243
2513
|
if (typeof type !== 'string') throw new TypeError('The type must be a string.');
|
|
2244
2514
|
if (typeof extra !== 'string') throw new TypeError('The extra must be a string.');
|
|
2245
2515
|
|
|
@@ -2327,17 +2597,20 @@ class TinyHtml {
|
|
|
2327
2597
|
* @param {TinyHtmlElement} el - Target element.
|
|
2328
2598
|
* @param {string|number} value - Height value.
|
|
2329
2599
|
* @throws {TypeError} If `value` is neither a string nor number.
|
|
2600
|
+
* @returns {TinyHtmlElement}
|
|
2330
2601
|
*/
|
|
2331
2602
|
static setHeight(el, value) {
|
|
2332
2603
|
const elem = TinyHtml._preHtmlElem(el, 'setHeight');
|
|
2333
2604
|
if (typeof value !== 'number' && typeof value !== 'string')
|
|
2334
2605
|
throw new TypeError('The value must be a string or number.');
|
|
2335
2606
|
elem.style.height = typeof value === 'number' ? `${value}px` : value;
|
|
2607
|
+
return el;
|
|
2336
2608
|
}
|
|
2337
2609
|
|
|
2338
2610
|
/**
|
|
2339
2611
|
* Sets the height of the element.
|
|
2340
2612
|
* @param {string|number} value - Height value.
|
|
2613
|
+
* @returns {TinyHtmlElement}
|
|
2341
2614
|
*/
|
|
2342
2615
|
setHeight(value) {
|
|
2343
2616
|
return TinyHtml.setHeight(this, value);
|
|
@@ -2348,17 +2621,20 @@ class TinyHtml {
|
|
|
2348
2621
|
* @param {TinyHtmlElement} el - Target element.
|
|
2349
2622
|
* @param {string|number} value - Width value.
|
|
2350
2623
|
* @throws {TypeError} If `value` is neither a string nor number.
|
|
2624
|
+
* @returns {TinyHtmlElement}
|
|
2351
2625
|
*/
|
|
2352
2626
|
static setWidth(el, value) {
|
|
2353
2627
|
const elem = TinyHtml._preHtmlElem(el, 'setWidth');
|
|
2354
2628
|
if (typeof value !== 'number' && typeof value !== 'string')
|
|
2355
2629
|
throw new TypeError('The value must be a string or number.');
|
|
2356
2630
|
elem.style.width = typeof value === 'number' ? `${value}px` : value;
|
|
2631
|
+
return el;
|
|
2357
2632
|
}
|
|
2358
2633
|
|
|
2359
2634
|
/**
|
|
2360
2635
|
* Sets the width of the element.
|
|
2361
2636
|
* @param {string|number} value - Width value.
|
|
2637
|
+
* @returns {TinyHtmlElement}
|
|
2362
2638
|
*/
|
|
2363
2639
|
setWidth(value) {
|
|
2364
2640
|
return TinyHtml.setWidth(this, value);
|
|
@@ -2366,11 +2642,11 @@ class TinyHtml {
|
|
|
2366
2642
|
|
|
2367
2643
|
/**
|
|
2368
2644
|
* Returns content box height.
|
|
2369
|
-
* @param {
|
|
2645
|
+
* @param {TinyElementAndWinAndDoc} el - Target element.
|
|
2370
2646
|
* @returns {number}
|
|
2371
2647
|
*/
|
|
2372
2648
|
static height(el) {
|
|
2373
|
-
const elem = TinyHtml.
|
|
2649
|
+
const elem = TinyHtml._preElemAndWinAndDoc(el, 'height');
|
|
2374
2650
|
return TinyHtml.getDimension(elem, 'height', 'content');
|
|
2375
2651
|
}
|
|
2376
2652
|
|
|
@@ -2384,11 +2660,11 @@ class TinyHtml {
|
|
|
2384
2660
|
|
|
2385
2661
|
/**
|
|
2386
2662
|
* Returns content box width.
|
|
2387
|
-
* @param {
|
|
2663
|
+
* @param {TinyElementAndWinAndDoc} el - Target element.
|
|
2388
2664
|
* @returns {number}
|
|
2389
2665
|
*/
|
|
2390
2666
|
static width(el) {
|
|
2391
|
-
const elem = TinyHtml.
|
|
2667
|
+
const elem = TinyHtml._preElemAndWinAndDoc(el, 'width');
|
|
2392
2668
|
return TinyHtml.getDimension(elem, 'width', 'content');
|
|
2393
2669
|
}
|
|
2394
2670
|
|
|
@@ -2402,11 +2678,11 @@ class TinyHtml {
|
|
|
2402
2678
|
|
|
2403
2679
|
/**
|
|
2404
2680
|
* Returns padding box height.
|
|
2405
|
-
* @param {
|
|
2681
|
+
* @param {TinyElementAndWinAndDoc} el - Target element.
|
|
2406
2682
|
* @returns {number}
|
|
2407
2683
|
*/
|
|
2408
2684
|
static innerHeight(el) {
|
|
2409
|
-
const elem = TinyHtml.
|
|
2685
|
+
const elem = TinyHtml._preElemAndWinAndDoc(el, 'innerHeight');
|
|
2410
2686
|
return TinyHtml.getDimension(elem, 'height', 'padding');
|
|
2411
2687
|
}
|
|
2412
2688
|
|
|
@@ -2420,11 +2696,11 @@ class TinyHtml {
|
|
|
2420
2696
|
|
|
2421
2697
|
/**
|
|
2422
2698
|
* Returns padding box width.
|
|
2423
|
-
* @param {
|
|
2699
|
+
* @param {TinyElementAndWinAndDoc} el - Target element.
|
|
2424
2700
|
* @returns {number}
|
|
2425
2701
|
*/
|
|
2426
2702
|
static innerWidth(el) {
|
|
2427
|
-
const elem = TinyHtml.
|
|
2703
|
+
const elem = TinyHtml._preElemAndWinAndDoc(el, 'innerWidth');
|
|
2428
2704
|
return TinyHtml.getDimension(elem, 'width', 'padding');
|
|
2429
2705
|
}
|
|
2430
2706
|
|
|
@@ -2438,14 +2714,14 @@ class TinyHtml {
|
|
|
2438
2714
|
|
|
2439
2715
|
/**
|
|
2440
2716
|
* Returns outer height of the element, optionally including margin.
|
|
2441
|
-
* @param {
|
|
2717
|
+
* @param {TinyElementAndWinAndDoc} el - Target element.
|
|
2442
2718
|
* @param {boolean} [includeMargin=false] - Whether to include margin.
|
|
2443
2719
|
* @returns {number}
|
|
2444
2720
|
*/
|
|
2445
2721
|
static outerHeight(el, includeMargin = false) {
|
|
2446
2722
|
if (typeof includeMargin !== 'boolean')
|
|
2447
2723
|
throw new TypeError('The "includeMargin" must be a boolean.');
|
|
2448
|
-
const elem = TinyHtml.
|
|
2724
|
+
const elem = TinyHtml._preElemAndWinAndDoc(el, 'outerHeight');
|
|
2449
2725
|
return TinyHtml.getDimension(elem, 'height', includeMargin ? 'margin' : 'border');
|
|
2450
2726
|
}
|
|
2451
2727
|
|
|
@@ -2460,14 +2736,14 @@ class TinyHtml {
|
|
|
2460
2736
|
|
|
2461
2737
|
/**
|
|
2462
2738
|
* Returns outer width of the element, optionally including margin.
|
|
2463
|
-
* @param {
|
|
2739
|
+
* @param {TinyElementAndWinAndDoc} el - Target element.
|
|
2464
2740
|
* @param {boolean} [includeMargin=false] - Whether to include margin.
|
|
2465
2741
|
* @returns {number}
|
|
2466
2742
|
*/
|
|
2467
2743
|
static outerWidth(el, includeMargin = false) {
|
|
2468
2744
|
if (typeof includeMargin !== 'boolean')
|
|
2469
2745
|
throw new TypeError('The "includeMargin" must be a boolean.');
|
|
2470
|
-
const elem = TinyHtml.
|
|
2746
|
+
const elem = TinyHtml._preElemAndWinAndDoc(el, 'outerWidth');
|
|
2471
2747
|
return TinyHtml.getDimension(elem, 'width', includeMargin ? 'margin' : 'border');
|
|
2472
2748
|
}
|
|
2473
2749
|
|
|
@@ -2482,6 +2758,30 @@ class TinyHtml {
|
|
|
2482
2758
|
|
|
2483
2759
|
//////////////////////////////////////////////////
|
|
2484
2760
|
|
|
2761
|
+
/**
|
|
2762
|
+
* Applies an animation to one or multiple TinyElement instances.
|
|
2763
|
+
*
|
|
2764
|
+
* @param {TinyElement|TinyElement[]} el - A single TinyElement or an array of TinyElements to animate.
|
|
2765
|
+
* @param {Keyframe[] | PropertyIndexedKeyframes | null} keyframes - The keyframes used to define the animation.
|
|
2766
|
+
* @param {number | KeyframeAnimationOptions} [ops] - Timing or configuration options for the animation.
|
|
2767
|
+
* @returns {TinyElement|TinyElement[]}
|
|
2768
|
+
*/
|
|
2769
|
+
static animate(el, keyframes, ops) {
|
|
2770
|
+
TinyHtml._preElems(el, 'animate').forEach((elem) => elem.animate(keyframes, ops));
|
|
2771
|
+
return el;
|
|
2772
|
+
}
|
|
2773
|
+
|
|
2774
|
+
/**
|
|
2775
|
+
* Applies an animation to one or multiple TinyElement instances.
|
|
2776
|
+
*
|
|
2777
|
+
* @param {Keyframe[] | PropertyIndexedKeyframes | null} keyframes - The keyframes used to define the animation.
|
|
2778
|
+
* @param {number | KeyframeAnimationOptions} [ops] - Timing or configuration options for the animation.
|
|
2779
|
+
* @returns {TinyElement|TinyElement[]}
|
|
2780
|
+
*/
|
|
2781
|
+
animate(keyframes, ops) {
|
|
2782
|
+
return TinyHtml.animate(this, keyframes, ops);
|
|
2783
|
+
}
|
|
2784
|
+
|
|
2485
2785
|
/**
|
|
2486
2786
|
* Gets the offset of the element relative to the document.
|
|
2487
2787
|
* @param {TinyElement} el - Target element.
|
|
@@ -2637,27 +2937,151 @@ class TinyHtml {
|
|
|
2637
2937
|
}
|
|
2638
2938
|
|
|
2639
2939
|
/**
|
|
2640
|
-
*
|
|
2641
|
-
*
|
|
2642
|
-
*
|
|
2940
|
+
* Collection of easing functions used for scroll and animation calculations.
|
|
2941
|
+
* Each function receives a normalized time value (`t` from 0 to 1) and returns the eased progress.
|
|
2942
|
+
*
|
|
2943
|
+
* @type {Record<string, (t: number) => number>}
|
|
2643
2944
|
*/
|
|
2644
|
-
static
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
|
|
2945
|
+
static easings = {
|
|
2946
|
+
linear: (t) => t,
|
|
2947
|
+
easeInQuad: (t) => t * t,
|
|
2948
|
+
easeOutQuad: (t) => t * (2 - t),
|
|
2949
|
+
easeInOutQuad: (t) => (t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t),
|
|
2950
|
+
easeInCubic: (t) => t * t * t,
|
|
2951
|
+
easeOutCubic: (t) => --t * t * t + 1,
|
|
2952
|
+
easeInOutCubic: (t) => (t < 0.5 ? 4 * t * t * t : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1),
|
|
2953
|
+
};
|
|
2954
|
+
|
|
2955
|
+
/**
|
|
2956
|
+
* Smoothly scrolls one or more elements (or the window) to the specified X and Y coordinates
|
|
2957
|
+
* using a custom duration and easing function.
|
|
2958
|
+
*
|
|
2959
|
+
* If `duration` or a valid `easing` is not provided, the scroll will be performed immediately.
|
|
2960
|
+
*
|
|
2961
|
+
* @param {TinyElementAndWindow | TinyElementAndWindow[]} el - A single element, array of elements, or the window to scroll.
|
|
2962
|
+
* @param {Object} [settings={}] - Configuration object for the scroll animation.
|
|
2963
|
+
* @param {number} [settings.targetX] - The horizontal scroll target in pixels.
|
|
2964
|
+
* @param {number} [settings.targetY] - The vertical scroll target in pixels.
|
|
2965
|
+
* @param {number} [settings.duration] - The duration of the animation in milliseconds.
|
|
2966
|
+
* @param {Easings} [settings.easing] - The easing function name to use for the scroll animation.
|
|
2967
|
+
* @param {OnScrollAnimation} [settings.onAnimation] - Optional callback invoked on each animation
|
|
2968
|
+
* frame with the current scroll position, normalized animation time (`0` to `1`), and a completion flag.
|
|
2969
|
+
* @returns {TinyElementAndWindow|TinyElementAndWindow[]}
|
|
2970
|
+
* @throws {TypeError} If `el` is not a valid element, array, or window.
|
|
2971
|
+
* @throws {TypeError} If `targetX` or `targetY` is defined but not a number.
|
|
2972
|
+
* @throws {TypeError} If `duration` is defined but not a number.
|
|
2973
|
+
* @throws {TypeError} If `easing` is defined but not a valid easing function name.
|
|
2974
|
+
* @throws {TypeError} If `onAnimation` is defined but not a function.
|
|
2975
|
+
*/
|
|
2976
|
+
static scrollToXY(el, { targetX, targetY, duration, easing, onAnimation } = {}) {
|
|
2977
|
+
if (targetX !== undefined && typeof targetX !== 'number')
|
|
2978
|
+
throw new TypeError('`targetX` must be a number if provided.');
|
|
2979
|
+
if (targetY !== undefined && typeof targetY !== 'number')
|
|
2980
|
+
throw new TypeError('`targetY` must be a number if provided.');
|
|
2981
|
+
if (duration !== undefined && typeof duration !== 'number')
|
|
2982
|
+
throw new TypeError('`duration` must be a number if provided.');
|
|
2983
|
+
if (easing !== undefined && typeof easing !== 'string')
|
|
2984
|
+
throw new TypeError('`easing` must be a string if provided.');
|
|
2985
|
+
if (easing !== undefined && typeof TinyHtml.easings[easing] !== 'function')
|
|
2986
|
+
throw new TypeError(`Unknown easing function: "${easing}".`);
|
|
2987
|
+
if (onAnimation !== undefined && typeof onAnimation !== 'function')
|
|
2988
|
+
throw new TypeError('`onAnimation` must be a function if provided.');
|
|
2989
|
+
|
|
2990
|
+
/**
|
|
2991
|
+
* Performs an instant scroll to the given coordinates.
|
|
2992
|
+
*
|
|
2993
|
+
* @param {ElementAndWindow} elem - The element or window to scroll.
|
|
2994
|
+
* @param {number} newX - The final horizontal scroll position.
|
|
2995
|
+
* @param {number} newY - The final vertical scroll position.
|
|
2996
|
+
* @param {number} time - Normalized progress value.
|
|
2997
|
+
*/
|
|
2998
|
+
const executeScroll = (elem, newX, newY, time) => {
|
|
2999
|
+
if (elem instanceof Window) {
|
|
3000
|
+
window.scrollTo(newX, newY);
|
|
2649
3001
|
} else if (elem.nodeType === 9) {
|
|
2650
3002
|
// @ts-ignore
|
|
2651
|
-
elem.defaultView.scrollTo(
|
|
3003
|
+
elem.defaultView.scrollTo(newX, newY);
|
|
2652
3004
|
} else {
|
|
2653
|
-
elem.
|
|
3005
|
+
const startX = elem instanceof Window ? window.scrollX : elem.scrollLeft;
|
|
3006
|
+
const startY = elem instanceof Window ? window.scrollY : elem.scrollTop;
|
|
3007
|
+
if (startX !== newX) elem.scrollLeft = newX;
|
|
3008
|
+
if (startY !== newY) elem.scrollTop = newY;
|
|
2654
3009
|
}
|
|
3010
|
+
if (typeof onAnimation === 'function')
|
|
3011
|
+
onAnimation({ x: newX, y: newY, isComplete: time >= 1, time });
|
|
3012
|
+
};
|
|
3013
|
+
|
|
3014
|
+
TinyHtml._preElemsAndWindow(el, 'scrollToXY').forEach((elem) => {
|
|
3015
|
+
const startX = elem instanceof Window ? window.scrollX : elem.scrollLeft;
|
|
3016
|
+
const startY = elem instanceof Window ? window.scrollY : elem.scrollTop;
|
|
3017
|
+
const targX = targetX ?? startX;
|
|
3018
|
+
const targY = targetY ?? startY;
|
|
3019
|
+
|
|
3020
|
+
const changeX = targX - startX;
|
|
3021
|
+
const changeY = targY - startY;
|
|
3022
|
+
|
|
3023
|
+
const ease = (typeof easing === 'string' && TinyHtml.easings[easing]) || null;
|
|
3024
|
+
if (typeof duration !== 'number' || typeof ease !== 'function')
|
|
3025
|
+
return executeScroll(elem, targX, targY, 1);
|
|
3026
|
+
const startTime = performance.now();
|
|
3027
|
+
const dur = duration ?? 0;
|
|
3028
|
+
|
|
3029
|
+
/**
|
|
3030
|
+
* Animates the scroll position based on easing and time.
|
|
3031
|
+
*
|
|
3032
|
+
* @param {number} currentTime - Timestamp provided by requestAnimationFrame.
|
|
3033
|
+
*/
|
|
3034
|
+
function animateScroll(currentTime) {
|
|
3035
|
+
if (typeof ease !== 'function') return;
|
|
3036
|
+
const time = Math.min(1, (currentTime - startTime) / dur);
|
|
3037
|
+
const easedTime = ease(time);
|
|
3038
|
+
|
|
3039
|
+
const newX = startX + changeX * easedTime;
|
|
3040
|
+
const newY = startY + changeY * easedTime;
|
|
3041
|
+
executeScroll(elem, newX, newY, time);
|
|
3042
|
+
|
|
3043
|
+
if (time < 1) requestAnimationFrame(animateScroll);
|
|
3044
|
+
}
|
|
3045
|
+
|
|
3046
|
+
requestAnimationFrame(animateScroll);
|
|
2655
3047
|
});
|
|
3048
|
+
return el;
|
|
3049
|
+
}
|
|
3050
|
+
|
|
3051
|
+
/**
|
|
3052
|
+
* Smoothly scrolls one or more elements (or the window) to the specified X and Y coordinates
|
|
3053
|
+
* using a custom duration and easing function.
|
|
3054
|
+
*
|
|
3055
|
+
* If `duration` or a valid `easing` is not provided, the scroll will be performed immediately.
|
|
3056
|
+
*
|
|
3057
|
+
* @param {Object} [settings={}] - Configuration object for the scroll animation.
|
|
3058
|
+
* @param {number} [settings.targetX] - The horizontal scroll target in pixels.
|
|
3059
|
+
* @param {number} [settings.targetY] - The vertical scroll target in pixels.
|
|
3060
|
+
* @param {number} [settings.duration] - The duration of the animation in milliseconds.
|
|
3061
|
+
* @param {Easings} [settings.easing] - The easing function name to use for the scroll animation.
|
|
3062
|
+
* @param {OnScrollAnimation} [settings.onAnimation] - Optional callback invoked on each animation
|
|
3063
|
+
* frame with the current scroll position, normalized animation time (`0` to `1`), and a completion flag.
|
|
3064
|
+
* @returns {TinyElementAndWindow|TinyElementAndWindow[]}
|
|
3065
|
+
*/
|
|
3066
|
+
scrollToXY({ targetX, targetY, duration, easing, onAnimation } = {}) {
|
|
3067
|
+
return TinyHtml.scrollToXY(this, { targetX, targetY, duration, easing, onAnimation });
|
|
3068
|
+
}
|
|
3069
|
+
|
|
3070
|
+
/**
|
|
3071
|
+
* Sets the vertical scroll position.
|
|
3072
|
+
* @param {TinyElementAndWindow|TinyElementAndWindow[]} el - Element or window.
|
|
3073
|
+
* @param {number} value - Scroll top value.
|
|
3074
|
+
* @returns {TinyElementAndWindow|TinyElementAndWindow[]}
|
|
3075
|
+
*/
|
|
3076
|
+
static setScrollTop(el, value) {
|
|
3077
|
+
if (typeof value !== 'number') throw new TypeError('ScrollTop value must be a number.');
|
|
3078
|
+
return TinyHtml.scrollToXY(el, { targetY: value });
|
|
2656
3079
|
}
|
|
2657
3080
|
|
|
2658
3081
|
/**
|
|
2659
3082
|
* Sets the vertical scroll position.
|
|
2660
3083
|
* @param {number} value - Scroll top value.
|
|
3084
|
+
* @returns {TinyElementAndWindow|TinyElementAndWindow[]}
|
|
2661
3085
|
*/
|
|
2662
3086
|
setScrollTop(value) {
|
|
2663
3087
|
return TinyHtml.setScrollTop(this, value);
|
|
@@ -2667,24 +3091,17 @@ class TinyHtml {
|
|
|
2667
3091
|
* Sets the horizontal scroll position.
|
|
2668
3092
|
* @param {TinyElementAndWindow|TinyElementAndWindow[]} el - Element or window.
|
|
2669
3093
|
* @param {number} value - Scroll left value.
|
|
3094
|
+
* @returns {TinyElementAndWindow|TinyElementAndWindow[]}
|
|
2670
3095
|
*/
|
|
2671
3096
|
static setScrollLeft(el, value) {
|
|
2672
3097
|
if (typeof value !== 'number') throw new TypeError('ScrollLeft value must be a number.');
|
|
2673
|
-
TinyHtml.
|
|
2674
|
-
if (TinyHtml.isWindow(elem)) {
|
|
2675
|
-
elem.scrollTo(value, elem.pageYOffset);
|
|
2676
|
-
} else if (elem.nodeType === 9) {
|
|
2677
|
-
// @ts-ignore
|
|
2678
|
-
elem.defaultView.scrollTo(value, elem.defaultView.pageYOffset);
|
|
2679
|
-
} else {
|
|
2680
|
-
elem.scrollLeft = value;
|
|
2681
|
-
}
|
|
2682
|
-
});
|
|
3098
|
+
return TinyHtml.scrollToXY(el, { targetX: value });
|
|
2683
3099
|
}
|
|
2684
3100
|
|
|
2685
3101
|
/**
|
|
2686
3102
|
* Sets the horizontal scroll position.
|
|
2687
3103
|
* @param {number} value - Scroll left value.
|
|
3104
|
+
* @returns {TinyElementAndWindow|TinyElementAndWindow[]}
|
|
2688
3105
|
*/
|
|
2689
3106
|
setScrollLeft(value) {
|
|
2690
3107
|
return TinyHtml.setScrollLeft(this, value);
|
|
@@ -2815,15 +3232,16 @@ class TinyHtml {
|
|
|
2815
3232
|
|
|
2816
3233
|
/**
|
|
2817
3234
|
* Adds one or more CSS class names to the element.
|
|
2818
|
-
* @type {(el: TinyElement|TinyElement[], ...tokens: string[]) =>
|
|
3235
|
+
* @type {(el: TinyElement|TinyElement[], ...tokens: string[]) => (TinyElement|TinyElement[])} - One or more class names to add.
|
|
2819
3236
|
*/
|
|
2820
3237
|
static addClass(el, ...args) {
|
|
2821
3238
|
TinyHtml._preElems(el, 'addClass').forEach((elem) => elem.classList.add(...args));
|
|
3239
|
+
return el;
|
|
2822
3240
|
}
|
|
2823
3241
|
|
|
2824
3242
|
/**
|
|
2825
3243
|
* Adds one or more CSS class names to the element.
|
|
2826
|
-
* @type {(...tokens: string[]) =>
|
|
3244
|
+
* @type {(...tokens: string[]) => (TinyElement|TinyElement[])} - One or more class names to add.
|
|
2827
3245
|
*/
|
|
2828
3246
|
addClass(...args) {
|
|
2829
3247
|
return TinyHtml.addClass(this, ...args);
|
|
@@ -2831,15 +3249,16 @@ class TinyHtml {
|
|
|
2831
3249
|
|
|
2832
3250
|
/**
|
|
2833
3251
|
* Removes one or more CSS class names from the element.
|
|
2834
|
-
* @type {(el: TinyElement|TinyElement[], ...tokens: string[]) =>
|
|
3252
|
+
* @type {(el: TinyElement|TinyElement[], ...tokens: string[]) => (TinyElement|TinyElement[])} - One or more class names to remove.
|
|
2835
3253
|
*/
|
|
2836
3254
|
static removeClass(el, ...args) {
|
|
2837
3255
|
TinyHtml._preElems(el, 'removeClass').forEach((elem) => elem.classList.remove(...args));
|
|
3256
|
+
return el;
|
|
2838
3257
|
}
|
|
2839
3258
|
|
|
2840
3259
|
/**
|
|
2841
3260
|
* Removes one or more CSS class names from the element.
|
|
2842
|
-
* @type {(...tokens: string[]) =>
|
|
3261
|
+
* @type {(...tokens: string[]) => (TinyElement|TinyElement[])} - One or more class names to remove.
|
|
2843
3262
|
*/
|
|
2844
3263
|
removeClass(...args) {
|
|
2845
3264
|
return TinyHtml.removeClass(this, ...args);
|
|
@@ -3049,15 +3468,18 @@ class TinyHtml {
|
|
|
3049
3468
|
* Set text content of elements.
|
|
3050
3469
|
* @param {TinyElement|TinyElement[]} el
|
|
3051
3470
|
* @param {string} value
|
|
3471
|
+
* @returns {TinyElement|TinyElement[]}
|
|
3052
3472
|
*/
|
|
3053
3473
|
static setText(el, value) {
|
|
3054
3474
|
if (typeof value !== 'string') throw new Error('Value is not a valid string.');
|
|
3055
3475
|
TinyHtml._preElems(el, 'setText').forEach((el) => (el.textContent = value));
|
|
3476
|
+
return el;
|
|
3056
3477
|
}
|
|
3057
3478
|
|
|
3058
3479
|
/**
|
|
3059
3480
|
* Set text content of the element.
|
|
3060
3481
|
* @param {string} value
|
|
3482
|
+
* @returns {TinyElement|TinyElement[]}
|
|
3061
3483
|
*/
|
|
3062
3484
|
setText(value) {
|
|
3063
3485
|
return TinyHtml.setText(this, value);
|
|
@@ -3066,13 +3488,16 @@ class TinyHtml {
|
|
|
3066
3488
|
/**
|
|
3067
3489
|
* Remove all child nodes from each element.
|
|
3068
3490
|
* @param {TinyElement|TinyElement[]} el
|
|
3491
|
+
* @returns {TinyElement|TinyElement[]}
|
|
3069
3492
|
*/
|
|
3070
3493
|
static empty(el) {
|
|
3071
3494
|
TinyHtml._preElems(el, 'empty').forEach((el) => (el.textContent = ''));
|
|
3495
|
+
return el;
|
|
3072
3496
|
}
|
|
3073
3497
|
|
|
3074
3498
|
/**
|
|
3075
3499
|
* Remove all child nodes of the element.
|
|
3500
|
+
* @returns {TinyElement|TinyElement[]}
|
|
3076
3501
|
*/
|
|
3077
3502
|
empty() {
|
|
3078
3503
|
return TinyHtml.empty(this);
|
|
@@ -3080,35 +3505,40 @@ class TinyHtml {
|
|
|
3080
3505
|
|
|
3081
3506
|
/**
|
|
3082
3507
|
* Get the innerHTML of the element.
|
|
3083
|
-
* @param {TinyElement
|
|
3508
|
+
* @param {TinyElement} el
|
|
3509
|
+
* @param {GetHTMLOptions} [ops]
|
|
3084
3510
|
* @returns {string}
|
|
3085
3511
|
*/
|
|
3086
|
-
static html(el) {
|
|
3512
|
+
static html(el, ops) {
|
|
3087
3513
|
const elem = TinyHtml._preElem(el, 'html');
|
|
3088
|
-
return elem.
|
|
3514
|
+
return elem.getHTML(ops);
|
|
3089
3515
|
}
|
|
3090
3516
|
|
|
3091
3517
|
/**
|
|
3092
3518
|
* Get the innerHTML of the element.
|
|
3519
|
+
* @param {GetHTMLOptions} [ops]
|
|
3093
3520
|
* @returns {string}
|
|
3094
3521
|
*/
|
|
3095
|
-
html() {
|
|
3096
|
-
return TinyHtml.html(this);
|
|
3522
|
+
html(ops) {
|
|
3523
|
+
return TinyHtml.html(this, ops);
|
|
3097
3524
|
}
|
|
3098
3525
|
|
|
3099
3526
|
/**
|
|
3100
3527
|
* Set the innerHTML of each element.
|
|
3101
3528
|
* @param {TinyElement|TinyElement[]} el
|
|
3102
3529
|
* @param {string} value
|
|
3530
|
+
* @returns {TinyElement|TinyElement[]}
|
|
3103
3531
|
*/
|
|
3104
3532
|
static setHtml(el, value) {
|
|
3105
3533
|
if (typeof value !== 'string') throw new Error('Value is not a valid string.');
|
|
3106
3534
|
TinyHtml._preElems(el, 'setHtml').forEach((el) => (el.innerHTML = value));
|
|
3535
|
+
return el;
|
|
3107
3536
|
}
|
|
3108
3537
|
|
|
3109
3538
|
/**
|
|
3110
3539
|
* Set the innerHTML of the element.
|
|
3111
3540
|
* @param {string} value
|
|
3541
|
+
* @returns {TinyElement|TinyElement[]}
|
|
3112
3542
|
*/
|
|
3113
3543
|
setHtml(value) {
|
|
3114
3544
|
return TinyHtml.setHtml(this, value);
|
|
@@ -3242,6 +3672,7 @@ class TinyHtml {
|
|
|
3242
3672
|
* @param {TinyInputElement|TinyInputElement[]} el - Target element.
|
|
3243
3673
|
* @param {SetValueList|((el: InputElement, val: SetValueList) => SetValueList)} value - The value to assign or a function that returns it.
|
|
3244
3674
|
* @throws {Error} If the computed value is not a valid string or boolean.
|
|
3675
|
+
* @returns {TinyInputElement|TinyInputElement[]}
|
|
3245
3676
|
*/
|
|
3246
3677
|
static setVal(el, value) {
|
|
3247
3678
|
TinyHtml._preInputElems(el, 'setVal').forEach((elem) => {
|
|
@@ -3281,6 +3712,7 @@ class TinyHtml {
|
|
|
3281
3712
|
if (typeof valToSet === 'string') elem.value = valToSet;
|
|
3282
3713
|
}
|
|
3283
3714
|
});
|
|
3715
|
+
return el;
|
|
3284
3716
|
}
|
|
3285
3717
|
|
|
3286
3718
|
/**
|
|
@@ -3288,6 +3720,7 @@ class TinyHtml {
|
|
|
3288
3720
|
* Accepts strings, numbers, booleans or arrays of these values, or a callback function that computes them.
|
|
3289
3721
|
*
|
|
3290
3722
|
* @param {SetValueList|((el: InputElement, val: SetValueList) => SetValueList)} value - The value to assign or a function that returns it.
|
|
3723
|
+
* @returns {TinyInputElement|TinyInputElement[]}
|
|
3291
3724
|
* @throws {Error} If the computed value is not a valid string or boolean.
|
|
3292
3725
|
*/
|
|
3293
3726
|
setVal(value) {
|
|
@@ -3557,6 +3990,7 @@ class TinyHtml {
|
|
|
3557
3990
|
* @param {string} event - The event type (e.g. 'click', 'keydown').
|
|
3558
3991
|
* @param {EventRegistryHandle} handler - The callback function to run on event.
|
|
3559
3992
|
* @param {EventRegistryOptions} [options] - Optional event listener options.
|
|
3993
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
3560
3994
|
*/
|
|
3561
3995
|
static on(el, event, handler, options) {
|
|
3562
3996
|
if (typeof event !== 'string') throw new TypeError('The event name must be a string.');
|
|
@@ -3569,6 +4003,7 @@ class TinyHtml {
|
|
|
3569
4003
|
if (!Array.isArray(events[event])) events[event] = [];
|
|
3570
4004
|
events[event].push({ handler, options });
|
|
3571
4005
|
});
|
|
4006
|
+
return el;
|
|
3572
4007
|
}
|
|
3573
4008
|
|
|
3574
4009
|
/**
|
|
@@ -3577,6 +4012,7 @@ class TinyHtml {
|
|
|
3577
4012
|
* @param {string} event - The event type (e.g. 'click', 'keydown').
|
|
3578
4013
|
* @param {EventRegistryHandle} handler - The callback function to run on event.
|
|
3579
4014
|
* @param {EventRegistryOptions} [options] - Optional event listener options.
|
|
4015
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
3580
4016
|
*/
|
|
3581
4017
|
on(event, handler, options) {
|
|
3582
4018
|
return TinyHtml.on(this, event, handler, options);
|
|
@@ -3589,6 +4025,7 @@ class TinyHtml {
|
|
|
3589
4025
|
* @param {string} event - The event type (e.g. 'click', 'keydown').
|
|
3590
4026
|
* @param {EventRegistryHandle} handler - The callback function to run on event.
|
|
3591
4027
|
* @param {EventRegistryOptions} [options={}] - Optional event listener options.
|
|
4028
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
3592
4029
|
*/
|
|
3593
4030
|
static once(el, event, handler, options = {}) {
|
|
3594
4031
|
if (typeof event !== 'string') throw new TypeError('The event name must be a string.');
|
|
@@ -3606,6 +4043,7 @@ class TinyHtml {
|
|
|
3606
4043
|
typeof options === 'boolean' ? options : { ...options, once: true },
|
|
3607
4044
|
);
|
|
3608
4045
|
});
|
|
4046
|
+
return el;
|
|
3609
4047
|
}
|
|
3610
4048
|
|
|
3611
4049
|
/**
|
|
@@ -3614,6 +4052,7 @@ class TinyHtml {
|
|
|
3614
4052
|
* @param {string} event - The event type (e.g. 'click', 'keydown').
|
|
3615
4053
|
* @param {EventRegistryHandle} handler - The callback function to run on event.
|
|
3616
4054
|
* @param {EventRegistryOptions} [options={}] - Optional event listener options.
|
|
4055
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
3617
4056
|
*/
|
|
3618
4057
|
once(event, handler, options = {}) {
|
|
3619
4058
|
return TinyHtml.once(this, event, handler, options);
|
|
@@ -3626,6 +4065,7 @@ class TinyHtml {
|
|
|
3626
4065
|
* @param {string} event - The event type.
|
|
3627
4066
|
* @param {EventRegistryHandle} handler - The function originally bound to the event.
|
|
3628
4067
|
* @param {boolean|EventListenerOptions} [options] - Optional listener options.
|
|
4068
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
3629
4069
|
*/
|
|
3630
4070
|
static off(el, event, handler, options) {
|
|
3631
4071
|
if (typeof event !== 'string') throw new TypeError('The event name must be a string.');
|
|
@@ -3638,6 +4078,7 @@ class TinyHtml {
|
|
|
3638
4078
|
if (events[event].length === 0) delete events[event];
|
|
3639
4079
|
}
|
|
3640
4080
|
});
|
|
4081
|
+
return el;
|
|
3641
4082
|
}
|
|
3642
4083
|
|
|
3643
4084
|
/**
|
|
@@ -3646,6 +4087,7 @@ class TinyHtml {
|
|
|
3646
4087
|
* @param {string} event - The event type.
|
|
3647
4088
|
* @param {EventRegistryHandle} handler - The function originally bound to the event.
|
|
3648
4089
|
* @param {boolean|EventListenerOptions} [options] - Optional listener options.
|
|
4090
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
3649
4091
|
*/
|
|
3650
4092
|
off(event, handler, options) {
|
|
3651
4093
|
return TinyHtml.off(this, event, handler, options);
|
|
@@ -3656,6 +4098,7 @@ class TinyHtml {
|
|
|
3656
4098
|
*
|
|
3657
4099
|
* @param {TinyEventTarget|TinyEventTarget[]} el - The target element.
|
|
3658
4100
|
* @param {string} event - The event type to remove (e.g. 'click').
|
|
4101
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
3659
4102
|
*/
|
|
3660
4103
|
static offAll(el, event) {
|
|
3661
4104
|
if (typeof event !== 'string') throw new TypeError('The event name must be a string.');
|
|
@@ -3668,12 +4111,14 @@ class TinyHtml {
|
|
|
3668
4111
|
delete events[event];
|
|
3669
4112
|
}
|
|
3670
4113
|
});
|
|
4114
|
+
return el;
|
|
3671
4115
|
}
|
|
3672
4116
|
|
|
3673
4117
|
/**
|
|
3674
4118
|
* Removes all event listeners of a specific type from the element.
|
|
3675
4119
|
*
|
|
3676
4120
|
* @param {string} event - The event type to remove (e.g. 'click').
|
|
4121
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
3677
4122
|
*/
|
|
3678
4123
|
offAll(event) {
|
|
3679
4124
|
return TinyHtml.offAll(this, event);
|
|
@@ -3685,6 +4130,7 @@ class TinyHtml {
|
|
|
3685
4130
|
* @param {TinyEventTarget|TinyEventTarget[]} el - The target element.
|
|
3686
4131
|
* @param {((handler: EventListenerOrEventListenerObject, event: string) => boolean)|null} [filterFn=null] -
|
|
3687
4132
|
* Optional filter function to selectively remove specific handlers.
|
|
4133
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
3688
4134
|
*/
|
|
3689
4135
|
static offAllTypes(el, filterFn = null) {
|
|
3690
4136
|
if (filterFn !== null && typeof filterFn !== 'function')
|
|
@@ -3703,6 +4149,7 @@ class TinyHtml {
|
|
|
3703
4149
|
|
|
3704
4150
|
__eventRegistry.delete(elem);
|
|
3705
4151
|
});
|
|
4152
|
+
return el;
|
|
3706
4153
|
}
|
|
3707
4154
|
|
|
3708
4155
|
/**
|
|
@@ -3710,6 +4157,7 @@ class TinyHtml {
|
|
|
3710
4157
|
*
|
|
3711
4158
|
* @param {((handler: EventListenerOrEventListenerObject, event: string) => boolean)|null} [filterFn=null] -
|
|
3712
4159
|
* Optional filter function to selectively remove specific handlers.
|
|
4160
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
3713
4161
|
*/
|
|
3714
4162
|
offAllTypes(filterFn = null) {
|
|
3715
4163
|
return TinyHtml.offAllTypes(this, filterFn);
|
|
@@ -3721,6 +4169,7 @@ class TinyHtml {
|
|
|
3721
4169
|
* @param {TinyEventTarget|TinyEventTarget[]} el - Target element where the event should be triggered.
|
|
3722
4170
|
* @param {string} event - Name of the event to trigger.
|
|
3723
4171
|
* @param {Event|CustomEvent|CustomEventInit} [payload] - Optional event object or data to pass.
|
|
4172
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
3724
4173
|
*/
|
|
3725
4174
|
static trigger(el, event, payload = {}) {
|
|
3726
4175
|
if (typeof event !== 'string') throw new TypeError('The event name must be a string.');
|
|
@@ -3736,6 +4185,7 @@ class TinyHtml {
|
|
|
3736
4185
|
|
|
3737
4186
|
elem.dispatchEvent(evt);
|
|
3738
4187
|
});
|
|
4188
|
+
return el;
|
|
3739
4189
|
}
|
|
3740
4190
|
|
|
3741
4191
|
/**
|
|
@@ -3743,6 +4193,7 @@ class TinyHtml {
|
|
|
3743
4193
|
*
|
|
3744
4194
|
* @param {string} event - Name of the event to trigger.
|
|
3745
4195
|
* @param {Event|CustomEvent|CustomEventInit} [payload] - Optional event object or data to pass.
|
|
4196
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
3746
4197
|
*/
|
|
3747
4198
|
trigger(event, payload = {}) {
|
|
3748
4199
|
return TinyHtml.trigger(this, event, payload);
|
|
@@ -3785,6 +4236,7 @@ class TinyHtml {
|
|
|
3785
4236
|
* @param {TinyElement|TinyElement[]} el
|
|
3786
4237
|
* @param {string} name
|
|
3787
4238
|
* @param {string|null} [value=null]
|
|
4239
|
+
* @returns {TinyElement|TinyElement[]}
|
|
3788
4240
|
*/
|
|
3789
4241
|
static setAttr(el, name, value = null) {
|
|
3790
4242
|
if (typeof name !== 'string') throw new TypeError('The "name" must be a string.');
|
|
@@ -3794,12 +4246,14 @@ class TinyHtml {
|
|
|
3794
4246
|
if (value === null) elem.removeAttribute(name);
|
|
3795
4247
|
else elem.setAttribute(name, value);
|
|
3796
4248
|
});
|
|
4249
|
+
return el;
|
|
3797
4250
|
}
|
|
3798
4251
|
|
|
3799
4252
|
/**
|
|
3800
4253
|
* Set an attribute on an element.
|
|
3801
4254
|
* @param {string} name
|
|
3802
4255
|
* @param {string|null} [value=null]
|
|
4256
|
+
* @returns {TinyElement|TinyElement[]}
|
|
3803
4257
|
*/
|
|
3804
4258
|
setAttr(name, value) {
|
|
3805
4259
|
return TinyHtml.setAttr(this, name, value);
|
|
@@ -3809,15 +4263,18 @@ class TinyHtml {
|
|
|
3809
4263
|
* Remove attribute(s) from an element.
|
|
3810
4264
|
* @param {TinyElement|TinyElement[]} el
|
|
3811
4265
|
* @param {string} name Space-separated list of attributes.
|
|
4266
|
+
* @returns {TinyElement|TinyElement[]}
|
|
3812
4267
|
*/
|
|
3813
4268
|
static removeAttr(el, name) {
|
|
3814
4269
|
if (typeof name !== 'string') throw new TypeError('The "name" must be a string.');
|
|
3815
4270
|
TinyHtml._preElems(el, 'removeAttr').forEach((elem) => elem.removeAttribute(name));
|
|
4271
|
+
return el;
|
|
3816
4272
|
}
|
|
3817
4273
|
|
|
3818
4274
|
/**
|
|
3819
4275
|
* Remove attribute(s) from an element.
|
|
3820
4276
|
* @param {string} name Space-separated list of attributes.
|
|
4277
|
+
* @returns {TinyElement|TinyElement[]}
|
|
3821
4278
|
*/
|
|
3822
4279
|
removeAttr(name) {
|
|
3823
4280
|
return TinyHtml.removeAttr(this, name);
|
|
@@ -3872,6 +4329,7 @@ class TinyHtml {
|
|
|
3872
4329
|
* Set a property on an element.
|
|
3873
4330
|
* @param {TinyElement|TinyElement[]} el
|
|
3874
4331
|
* @param {string} name
|
|
4332
|
+
* @returns {TinyElement|TinyElement[]}
|
|
3875
4333
|
*/
|
|
3876
4334
|
static addProp(el, name) {
|
|
3877
4335
|
if (typeof name !== 'string') throw new TypeError('The "name" must be a string.');
|
|
@@ -3881,11 +4339,13 @@ class TinyHtml {
|
|
|
3881
4339
|
// @ts-ignore
|
|
3882
4340
|
elem[name] = true;
|
|
3883
4341
|
});
|
|
4342
|
+
return el;
|
|
3884
4343
|
}
|
|
3885
4344
|
|
|
3886
4345
|
/**
|
|
3887
4346
|
* Set a property on an element.
|
|
3888
4347
|
* @param {string} name
|
|
4348
|
+
* @returns {TinyElement|TinyElement[]}
|
|
3889
4349
|
*/
|
|
3890
4350
|
addProp(name) {
|
|
3891
4351
|
return TinyHtml.addProp(this, name);
|
|
@@ -3895,6 +4355,7 @@ class TinyHtml {
|
|
|
3895
4355
|
* Remove a property from an element.
|
|
3896
4356
|
* @param {TinyElement|TinyElement[]} el
|
|
3897
4357
|
* @param {string} name
|
|
4358
|
+
* @returns {TinyElement|TinyElement[]}
|
|
3898
4359
|
*/
|
|
3899
4360
|
static removeProp(el, name) {
|
|
3900
4361
|
if (typeof name !== 'string') throw new TypeError('The "name" must be a string.');
|
|
@@ -3904,11 +4365,13 @@ class TinyHtml {
|
|
|
3904
4365
|
// @ts-ignore
|
|
3905
4366
|
elem[name] = false;
|
|
3906
4367
|
});
|
|
4368
|
+
return el;
|
|
3907
4369
|
}
|
|
3908
4370
|
|
|
3909
4371
|
/**
|
|
3910
4372
|
* Remove a property from an element.
|
|
3911
4373
|
* @param {string} name
|
|
4374
|
+
* @returns {TinyElement|TinyElement[]}
|
|
3912
4375
|
*/
|
|
3913
4376
|
removeProp(name) {
|
|
3914
4377
|
return TinyHtml.removeProp(this, name);
|
|
@@ -3949,13 +4412,16 @@ class TinyHtml {
|
|
|
3949
4412
|
/**
|
|
3950
4413
|
* Removes an element from the DOM.
|
|
3951
4414
|
* @param {TinyElement|TinyElement[]} el - The DOM element or selector to remove.
|
|
4415
|
+
* @returns {TinyElement|TinyElement[]}
|
|
3952
4416
|
*/
|
|
3953
4417
|
static remove(el) {
|
|
3954
4418
|
TinyHtml._preElems(el, 'remove').forEach((elem) => elem.remove());
|
|
4419
|
+
return el;
|
|
3955
4420
|
}
|
|
3956
4421
|
|
|
3957
4422
|
/**
|
|
3958
4423
|
* Removes the element from the DOM.
|
|
4424
|
+
* @returns {TinyElement|TinyElement[]}
|
|
3959
4425
|
*/
|
|
3960
4426
|
remove() {
|
|
3961
4427
|
return TinyHtml.remove(this);
|
|
@@ -4299,6 +4765,14 @@ class TinyHtml {
|
|
|
4299
4765
|
*/
|
|
4300
4766
|
static isInViewport(el) {
|
|
4301
4767
|
const elem = TinyHtml._preElem(el, 'isInViewport');
|
|
4768
|
+
if (
|
|
4769
|
+
!elem.checkVisibility({
|
|
4770
|
+
contentVisibilityAuto: false,
|
|
4771
|
+
opacityProperty: false,
|
|
4772
|
+
visibilityProperty: false,
|
|
4773
|
+
})
|
|
4774
|
+
)
|
|
4775
|
+
return false;
|
|
4302
4776
|
const elementTop = TinyHtml.offset(elem).top;
|
|
4303
4777
|
const elementBottom = elementTop + TinyHtml.outerHeight(elem);
|
|
4304
4778
|
|
|
@@ -4325,6 +4799,14 @@ class TinyHtml {
|
|
|
4325
4799
|
*/
|
|
4326
4800
|
static isScrolledIntoView(el) {
|
|
4327
4801
|
const elem = TinyHtml._preElem(el, 'isScrolledIntoView');
|
|
4802
|
+
if (
|
|
4803
|
+
!elem.checkVisibility({
|
|
4804
|
+
contentVisibilityAuto: false,
|
|
4805
|
+
opacityProperty: false,
|
|
4806
|
+
visibilityProperty: false,
|
|
4807
|
+
})
|
|
4808
|
+
)
|
|
4809
|
+
return false;
|
|
4328
4810
|
const docViewTop = TinyHtml.scrollTop(window);
|
|
4329
4811
|
const docViewBottom = docViewTop + TinyHtml.height(window);
|
|
4330
4812
|
|
|
@@ -4342,6 +4824,111 @@ class TinyHtml {
|
|
|
4342
4824
|
isScrolledIntoView() {
|
|
4343
4825
|
return TinyHtml.isScrolledIntoView(this);
|
|
4344
4826
|
}
|
|
4827
|
+
|
|
4828
|
+
/**
|
|
4829
|
+
* Checks if the given element is at least partially visible within the boundaries of a container.
|
|
4830
|
+
*
|
|
4831
|
+
* @param {TinyElement} el - The DOM element to check.
|
|
4832
|
+
* @param {TinyElement} cont - The container element acting as the viewport.
|
|
4833
|
+
* @returns {boolean} True if the element is partially visible within the container, false otherwise.
|
|
4834
|
+
*/
|
|
4835
|
+
static isInContainer(el, cont) {
|
|
4836
|
+
const elem = TinyHtml._preElem(el, 'isInContainer');
|
|
4837
|
+
const container = TinyHtml._preElem(cont, 'isInContainer');
|
|
4838
|
+
|
|
4839
|
+
if (
|
|
4840
|
+
!elem.checkVisibility({
|
|
4841
|
+
contentVisibilityAuto: false,
|
|
4842
|
+
opacityProperty: false,
|
|
4843
|
+
visibilityProperty: false,
|
|
4844
|
+
})
|
|
4845
|
+
)
|
|
4846
|
+
return false;
|
|
4847
|
+
const elemRect = elem.getBoundingClientRect();
|
|
4848
|
+
const containerRect = container.getBoundingClientRect();
|
|
4849
|
+
|
|
4850
|
+
const verticallyVisible =
|
|
4851
|
+
elemRect.bottom > containerRect.top && elemRect.top < containerRect.bottom;
|
|
4852
|
+
|
|
4853
|
+
const horizontallyVisible =
|
|
4854
|
+
elemRect.right > containerRect.left && elemRect.left < containerRect.right;
|
|
4855
|
+
|
|
4856
|
+
return verticallyVisible && horizontallyVisible;
|
|
4857
|
+
}
|
|
4858
|
+
|
|
4859
|
+
/**
|
|
4860
|
+
* Checks if the given element is at least partially visible within the boundaries of a container.
|
|
4861
|
+
*
|
|
4862
|
+
* @param {TinyElement} cont - The container element acting as the viewport.
|
|
4863
|
+
* @returns {boolean} True if the element is partially visible within the container, false otherwise.
|
|
4864
|
+
*/
|
|
4865
|
+
isInContainer(cont) {
|
|
4866
|
+
return TinyHtml.isInContainer(this, cont);
|
|
4867
|
+
}
|
|
4868
|
+
|
|
4869
|
+
/**
|
|
4870
|
+
* Checks if the given element is fully visible within the boundaries of a container (top and bottom).
|
|
4871
|
+
*
|
|
4872
|
+
* @param {TinyElement} el - The DOM element to check.
|
|
4873
|
+
* @param {TinyElement} cont - The container element acting as the viewport.
|
|
4874
|
+
* @returns {boolean} True if the element is fully visible within the container, false otherwise.
|
|
4875
|
+
*/
|
|
4876
|
+
static isFullyInContainer(el, cont) {
|
|
4877
|
+
const elem = TinyHtml._preElem(el, 'isScrolledIntoView');
|
|
4878
|
+
const container = TinyHtml._preElem(cont, 'isInContainer');
|
|
4879
|
+
|
|
4880
|
+
if (
|
|
4881
|
+
!elem.checkVisibility({
|
|
4882
|
+
contentVisibilityAuto: false,
|
|
4883
|
+
opacityProperty: false,
|
|
4884
|
+
visibilityProperty: false,
|
|
4885
|
+
})
|
|
4886
|
+
)
|
|
4887
|
+
return false;
|
|
4888
|
+
const elemRect = elem.getBoundingClientRect();
|
|
4889
|
+
const containerRect = container.getBoundingClientRect();
|
|
4890
|
+
|
|
4891
|
+
const isFullyVisible =
|
|
4892
|
+
elemRect.top >= containerRect.top &&
|
|
4893
|
+
elemRect.bottom <= containerRect.bottom &&
|
|
4894
|
+
elemRect.left >= containerRect.left &&
|
|
4895
|
+
elemRect.right <= containerRect.right;
|
|
4896
|
+
|
|
4897
|
+
return isFullyVisible;
|
|
4898
|
+
}
|
|
4899
|
+
|
|
4900
|
+
/**
|
|
4901
|
+
* Checks if the given element is fully visible within the boundaries of a container (top and bottom).
|
|
4902
|
+
*
|
|
4903
|
+
* @param {TinyElement} cont - The container element acting as the viewport.
|
|
4904
|
+
* @returns {boolean} True if the element is fully visible within the container, false otherwise.
|
|
4905
|
+
*/
|
|
4906
|
+
isFullyInContainer(cont) {
|
|
4907
|
+
return TinyHtml.isFullyInContainer(this, cont);
|
|
4908
|
+
}
|
|
4909
|
+
|
|
4910
|
+
/**
|
|
4911
|
+
* Checks if an element has scrollable content.
|
|
4912
|
+
*
|
|
4913
|
+
* @param {TinyElement} el - The DOM element to check.
|
|
4914
|
+
* @returns {{ v: boolean, h: boolean }} - True if scroll is needed in that direction.
|
|
4915
|
+
*/
|
|
4916
|
+
static hasScroll(el) {
|
|
4917
|
+
const elem = TinyHtml._preElem(el, 'hasScroll');
|
|
4918
|
+
return {
|
|
4919
|
+
v: elem.scrollHeight > elem.clientHeight,
|
|
4920
|
+
h: elem.scrollWidth > elem.clientWidth,
|
|
4921
|
+
};
|
|
4922
|
+
}
|
|
4923
|
+
|
|
4924
|
+
/**
|
|
4925
|
+
* Checks if an element has scrollable content.
|
|
4926
|
+
*
|
|
4927
|
+
* @returns {{ v: boolean, h: boolean }} - True if scroll is needed in that direction.
|
|
4928
|
+
*/
|
|
4929
|
+
hasScroll() {
|
|
4930
|
+
return TinyHtml.hasScroll(this);
|
|
4931
|
+
}
|
|
4345
4932
|
}
|
|
4346
4933
|
|
|
4347
4934
|
module.exports = TinyHtml;
|