tiny-essentials 1.16.2 → 1.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/legacy/crypto/decrypt.cjs +1 -0
- package/dist/legacy/crypto/decrypt.d.mts +1 -0
- package/dist/legacy/crypto/decrypt.mjs +1 -0
- package/dist/legacy/crypto/encrypt.cjs +1 -0
- package/dist/legacy/crypto/encrypt.d.mts +1 -0
- package/dist/legacy/crypto/encrypt.mjs +1 -0
- package/dist/legacy/get/decimalColor.cjs +1 -0
- package/dist/legacy/get/decimalColor.d.mts +1 -0
- package/dist/legacy/get/decimalColor.mjs +1 -0
- package/dist/legacy/get/pagination.cjs +1 -0
- package/dist/legacy/get/pagination.d.mts +1 -0
- package/dist/legacy/get/pagination.mjs +1 -0
- package/dist/legacy/get/queryUrlByName.cjs +1 -0
- package/dist/legacy/get/queryUrlByName.d.mts +1 -0
- package/dist/legacy/get/queryUrlByName.mjs +1 -0
- package/dist/legacy/get/queryUrlJSON.cjs +1 -0
- package/dist/legacy/get/queryUrlJSON.d.mts +1 -0
- package/dist/legacy/get/queryUrlJSON.mjs +1 -0
- package/dist/legacy/get/super_string_filter.cjs +1 -0
- package/dist/legacy/get/super_string_filter.d.mts +1 -0
- package/dist/legacy/get/super_string_filter.mjs +1 -0
- package/dist/legacy/get/versionCheck.cjs +1 -0
- package/dist/legacy/get/versionCheck.d.mts +1 -0
- package/dist/legacy/get/versionCheck.mjs +1 -0
- package/dist/legacy/http/HTTP-1.0.cjs +2 -0
- package/dist/legacy/http/HTTP-1.0.mjs +2 -0
- package/dist/legacy/http/auth.cjs +1 -0
- package/dist/legacy/http/auth.d.mts +1 -0
- package/dist/legacy/http/auth.mjs +1 -0
- package/dist/legacy/http/check_domain.cjs +11 -0
- package/dist/legacy/http/check_domain.d.mts +3 -0
- package/dist/legacy/http/check_domain.mjs +11 -0
- package/dist/legacy/http/csrfTokenAnalyze.cjs +1 -0
- package/dist/legacy/http/csrfTokenAnalyze.d.mts +1 -0
- package/dist/legacy/http/csrfTokenAnalyze.mjs +1 -0
- package/dist/legacy/http/domainValidator.cjs +1 -0
- package/dist/legacy/http/domainValidator.d.mts +1 -0
- package/dist/legacy/http/domainValidator.mjs +1 -0
- package/dist/legacy/http/errorsCallback.cjs +1 -0
- package/dist/legacy/http/errorsCallback.d.mts +1 -0
- package/dist/legacy/http/errorsCallback.mjs +1 -0
- package/dist/legacy/http/fetch/json.cjs +1 -0
- package/dist/legacy/http/fetch/json.d.mts +1 -0
- package/dist/legacy/http/fetch/json.mjs +1 -0
- package/dist/legacy/http/fetch/text.cjs +1 -0
- package/dist/legacy/http/fetch/text.d.mts +1 -0
- package/dist/legacy/http/fetch/text.mjs +1 -0
- package/dist/legacy/http/fileCache.cjs +1 -0
- package/dist/legacy/http/fileCache.d.mts +1 -0
- package/dist/legacy/http/fileCache.mjs +1 -0
- package/dist/legacy/http/getDomainURL.cjs +1 -0
- package/dist/legacy/http/getDomainURL.d.mts +1 -0
- package/dist/legacy/http/getDomainURL.mjs +1 -0
- package/dist/legacy/http/userIP.cjs +1 -0
- package/dist/legacy/http/userIP.d.mts +1 -0
- package/dist/legacy/http/userIP.mjs +1 -0
- package/dist/legacy/libs/capitalize.cjs +1 -0
- package/dist/legacy/libs/capitalize.d.mts +1 -0
- package/dist/legacy/libs/capitalize.mjs +1 -0
- package/dist/legacy/libs/convertBytes.cjs +2 -0
- package/dist/legacy/libs/convertBytes.mjs +2 -0
- package/dist/legacy/libs/custom_module_loader.cjs +2 -0
- package/dist/legacy/libs/custom_module_loader.mjs +2 -0
- package/dist/legacy/libs/dice.cjs +2 -0
- package/dist/legacy/libs/dice.mjs +2 -0
- package/dist/legacy/libs/markdown.cjs +1 -0
- package/dist/legacy/libs/markdown.mjs +1 -0
- package/dist/legacy/libs/percentage.cjs +1 -0
- package/dist/legacy/libs/percentage.mjs +1 -0
- package/dist/legacy/libs/regex/getLetter.cjs +2 -0
- package/dist/legacy/libs/regex/getLetter.d.mts +2 -0
- package/dist/legacy/libs/regex/getLetter.mjs +2 -0
- package/dist/legacy/libs/rule3.cjs +1 -0
- package/dist/legacy/libs/rule3.mjs +1 -0
- package/dist/legacy/momentjs/getAge.cjs +1 -0
- package/dist/legacy/momentjs/getAge.d.mts +1 -0
- package/dist/legacy/momentjs/getAge.mjs +1 -0
- package/dist/legacy/momentjs/timeDuration.cjs +1 -0
- package/dist/legacy/momentjs/timeDuration.d.mts +1 -0
- package/dist/legacy/momentjs/timeDuration.mjs +1 -0
- package/dist/legacy/socket.io/antiFlood/install.cjs +1 -0
- package/dist/legacy/socket.io/antiFlood/install.d.mts +1 -0
- package/dist/legacy/socket.io/antiFlood/install.mjs +1 -0
- package/dist/legacy/socket.io/antiFlood/verify.cjs +1 -0
- package/dist/legacy/socket.io/antiFlood/verify.d.mts +1 -0
- package/dist/legacy/socket.io/antiFlood/verify.mjs +1 -0
- package/dist/legacy/socket.io/cookie-session.cjs +1 -0
- package/dist/legacy/socket.io/cookie-session.d.mts +1 -0
- package/dist/legacy/socket.io/cookie-session.mjs +1 -0
- package/dist/legacy/socket.io/discord.cjs +1 -0
- package/dist/legacy/socket.io/discord.d.mts +1 -0
- package/dist/legacy/socket.io/discord.mjs +1 -0
- package/dist/v1/TinyBasicsEs.js +559 -71
- package/dist/v1/TinyBasicsEs.min.js +1 -1
- package/dist/v1/TinyDragger.js +486 -47
- package/dist/v1/TinyDragger.min.js +1 -1
- package/dist/v1/TinyEssentials.js +2496 -72
- package/dist/v1/TinyEssentials.min.js +1 -1
- package/dist/v1/TinyHtml.js +486 -47
- package/dist/v1/TinyHtml.min.js +1 -1
- package/dist/v1/TinySmartScroller.js +6230 -0
- package/dist/v1/TinySmartScroller.min.js +1 -0
- package/dist/v1/TinyUploadClicker.js +1538 -72
- package/dist/v1/TinyUploadClicker.min.js +1 -1
- package/dist/v1/UltraRandomMsgGen.js +995 -0
- package/dist/v1/UltraRandomMsgGen.min.js +1 -0
- package/dist/v1/basics/html.cjs +74 -24
- package/dist/v1/basics/html.d.mts +38 -15
- package/dist/v1/basics/html.mjs +63 -20
- package/dist/v1/build/TinySmartScroller.cjs +7 -0
- package/dist/v1/build/TinySmartScroller.d.mts +3 -0
- package/dist/v1/build/TinySmartScroller.mjs +2 -0
- package/dist/v1/build/UltraRandomMsgGen.cjs +7 -0
- package/dist/v1/build/UltraRandomMsgGen.d.mts +3 -0
- package/dist/v1/build/UltraRandomMsgGen.mjs +2 -0
- package/dist/v1/index.cjs +4 -0
- package/dist/v1/index.d.mts +3 -1
- package/dist/v1/index.mjs +3 -1
- package/dist/v1/libs/TinyHtml.cjs +486 -47
- package/dist/v1/libs/TinyHtml.d.mts +352 -139
- package/dist/v1/libs/TinyHtml.mjs +431 -47
- package/dist/v1/libs/TinySmartScroller.cjs +976 -0
- package/dist/v1/libs/TinySmartScroller.d.mts +458 -0
- package/dist/v1/libs/TinySmartScroller.mjs +856 -0
- package/dist/v1/libs/UltraRandomMsgGen.cjs +956 -0
- package/dist/v1/libs/UltraRandomMsgGen.d.mts +390 -0
- package/dist/v1/libs/UltraRandomMsgGen.mjs +825 -0
- package/docs/v1/README.md +2 -0
- package/docs/v1/basics/html.md +17 -2
- package/docs/v1/libs/TinyHtml.md +197 -8
- package/docs/v1/libs/TinySmartScroller.md +523 -0
- package/docs/v1/libs/UltraRandomMsgGen.md +289 -0
- package/package.json +1 -1
|
@@ -66,6 +66,21 @@ const {
|
|
|
66
66
|
* @typedef {Element|Window} ElementAndWindow
|
|
67
67
|
*/
|
|
68
68
|
|
|
69
|
+
/**
|
|
70
|
+
* Represents a raw DOM element/window/document or an instance of TinyHtml.
|
|
71
|
+
* This type is used to abstract interactions with both plain elements
|
|
72
|
+
* and wrapped elements via the TinyHtml class.
|
|
73
|
+
*
|
|
74
|
+
* @typedef {ElementAndWinAndDoc|TinyHtml} TinyElementAndWinAndDoc
|
|
75
|
+
*/
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Represents a value that can be either a DOM Element, or the global Window object, or the document object.
|
|
79
|
+
* Useful for functions that operate generically on scrollable or measurable targets.
|
|
80
|
+
*
|
|
81
|
+
* @typedef {Element|Window|Document} ElementAndWinAndDoc
|
|
82
|
+
*/
|
|
83
|
+
|
|
69
84
|
/**
|
|
70
85
|
* A parameter type used for filtering or matching elements.
|
|
71
86
|
* It can be:
|
|
@@ -82,7 +97,7 @@ const {
|
|
|
82
97
|
* Elements accepted as constructor values for TinyHtml.
|
|
83
98
|
* These include common DOM elements and root containers.
|
|
84
99
|
*
|
|
85
|
-
* @typedef {Window|Element|Document} ConstructorElValues
|
|
100
|
+
* @typedef {Window|Element|Document|Text} ConstructorElValues
|
|
86
101
|
*/
|
|
87
102
|
|
|
88
103
|
/**
|
|
@@ -203,40 +218,114 @@ class TinyHtml {
|
|
|
203
218
|
|
|
204
219
|
static Utils = { ...collision };
|
|
205
220
|
|
|
221
|
+
/**
|
|
222
|
+
* Creates a new DOM element with the specified tag name and options, then wraps it in a TinyHtml instance.
|
|
223
|
+
*
|
|
224
|
+
* @param {string} tagName - The tag name of the element to create (e.g., 'div', 'span').
|
|
225
|
+
* @param {ElementCreationOptions} ops - Optional settings for creating the element.
|
|
226
|
+
* @returns {TinyHtml} A TinyHtml instance wrapping the newly created DOM element.
|
|
227
|
+
* @throws {TypeError} If tagName is not a string or ops is not an object.
|
|
228
|
+
*/
|
|
229
|
+
static createElement(tagName, ops) {
|
|
230
|
+
if (typeof tagName !== 'string')
|
|
231
|
+
throw new TypeError(`[TinyHtml] createElement(): The tagName must be a string.`);
|
|
232
|
+
if (typeof ops !== 'undefined' && typeof ops !== 'object')
|
|
233
|
+
throw new TypeError(`[TinyHtml] createElement(): The ops must be a object.`);
|
|
234
|
+
return new TinyHtml(document.createElement(tagName, ops));
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Creates a new TinyHtml instance that wraps a DOM TextNode.
|
|
239
|
+
*
|
|
240
|
+
* This method is useful when you want to insert raw text content into the DOM
|
|
241
|
+
* without it being interpreted as HTML. The returned instance behaves like any
|
|
242
|
+
* other TinyHtml element and can be appended or manipulated as needed.
|
|
243
|
+
*
|
|
244
|
+
* @param {string} value - The plain text content to be wrapped in a TextNode.
|
|
245
|
+
* @returns {TinyHtml} A TinyHtml instance wrapping the newly created DOM TextNode.
|
|
246
|
+
* @throws {TypeError} If the provided value is not a string.
|
|
247
|
+
*/
|
|
248
|
+
static createTextNode(value) {
|
|
249
|
+
if (typeof value !== 'string')
|
|
250
|
+
throw new TypeError(`[TinyHtml] createTextNode(): The value must be a string.`);
|
|
251
|
+
return new TinyHtml(document.createTextNode(value));
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Creates an HTMLElement or TextNode from an HTML string.
|
|
256
|
+
* Supports both elements and plain text.
|
|
257
|
+
*
|
|
258
|
+
* @param {string} htmlString - The HTML string to convert.
|
|
259
|
+
* @returns {TinyHtml} - A single HTMLElement or TextNode.
|
|
260
|
+
*/
|
|
261
|
+
static createElementFromHTML(htmlString) {
|
|
262
|
+
const template = document.createElement('template');
|
|
263
|
+
htmlString = htmlString.trim();
|
|
264
|
+
|
|
265
|
+
// If it's only text (e.g., no "<" tag), return a TextNode
|
|
266
|
+
if (!htmlString.startsWith('<')) {
|
|
267
|
+
return TinyHtml.createTextNode(htmlString);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
template.innerHTML = htmlString;
|
|
271
|
+
if (!(template.content.firstChild instanceof Element)) throw new Error('');
|
|
272
|
+
return new TinyHtml(template.content.firstChild);
|
|
273
|
+
}
|
|
274
|
+
|
|
206
275
|
/**
|
|
207
276
|
* Queries the document for the first element matching the CSS selector and wraps it in a TinyHtml instance.
|
|
208
277
|
*
|
|
209
278
|
* @param {string} selector - A valid CSS selector string.
|
|
210
|
-
* @
|
|
211
|
-
* @
|
|
279
|
+
* @param {Document|Element} elem - Target element.
|
|
280
|
+
* @returns {TinyHtml|null} A TinyHtml instance wrapping the matched element.
|
|
212
281
|
*/
|
|
213
|
-
static query(selector) {
|
|
214
|
-
const newEl =
|
|
215
|
-
if (!newEl)
|
|
282
|
+
static query(selector, elem = document) {
|
|
283
|
+
const newEl = elem.querySelector(selector);
|
|
284
|
+
if (!newEl) return null;
|
|
216
285
|
return new TinyHtml(newEl);
|
|
217
286
|
}
|
|
218
287
|
|
|
288
|
+
/**
|
|
289
|
+
* Queries the element for the first element matching the CSS selector and wraps it in a TinyHtml instance.
|
|
290
|
+
*
|
|
291
|
+
* @param {string} selector - A valid CSS selector string.
|
|
292
|
+
* @returns {TinyHtml|null} A TinyHtml instance wrapping the matched element.
|
|
293
|
+
*/
|
|
294
|
+
querySelector(selector) {
|
|
295
|
+
return TinyHtml.query(selector, TinyHtml._preElem(this, 'query'));
|
|
296
|
+
}
|
|
297
|
+
|
|
219
298
|
/**
|
|
220
299
|
* Queries the document for all elements matching the CSS selector and wraps them in TinyHtml instances.
|
|
221
300
|
*
|
|
222
301
|
* @param {string} selector - A valid CSS selector string.
|
|
302
|
+
* @param {Document|Element} elem - Target element.
|
|
223
303
|
* @returns {TinyHtml[]} An array of TinyHtml instances wrapping the matched elements.
|
|
224
304
|
*/
|
|
225
|
-
static queryAll(selector) {
|
|
226
|
-
const newEls =
|
|
305
|
+
static queryAll(selector, elem = document) {
|
|
306
|
+
const newEls = elem.querySelectorAll(selector);
|
|
227
307
|
return TinyHtml.toTinyElm([...newEls]);
|
|
228
308
|
}
|
|
229
309
|
|
|
310
|
+
/**
|
|
311
|
+
* Queries the element for all elements matching the CSS selector and wraps them in TinyHtml instances.
|
|
312
|
+
*
|
|
313
|
+
* @param {string} selector - A valid CSS selector string.
|
|
314
|
+
* @returns {TinyHtml[]} An array of TinyHtml instances wrapping the matched elements.
|
|
315
|
+
*/
|
|
316
|
+
querySelectorAll(selector) {
|
|
317
|
+
return TinyHtml.queryAll(selector, TinyHtml._preElem(this, 'queryAll'));
|
|
318
|
+
}
|
|
319
|
+
|
|
230
320
|
/**
|
|
231
321
|
* Retrieves an element by its ID and wraps it in a TinyHtml instance.
|
|
232
322
|
*
|
|
233
323
|
* @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.
|
|
324
|
+
* @returns {TinyHtml|null} A TinyHtml instance wrapping the found element.
|
|
236
325
|
*/
|
|
237
326
|
static getById(selector) {
|
|
238
327
|
const newEl = document.getElementById(selector);
|
|
239
|
-
if (!newEl)
|
|
328
|
+
if (!newEl) return null;
|
|
240
329
|
return new TinyHtml(newEl);
|
|
241
330
|
}
|
|
242
331
|
|
|
@@ -244,13 +333,24 @@ class TinyHtml {
|
|
|
244
333
|
* Retrieves all elements with the specified class name and wraps them in TinyHtml instances.
|
|
245
334
|
*
|
|
246
335
|
* @param {string} selector - The class name to search for.
|
|
336
|
+
* @param {Document|Element} elem - Target element.
|
|
247
337
|
* @returns {TinyHtml[]} An array of TinyHtml instances wrapping the found elements.
|
|
248
338
|
*/
|
|
249
|
-
static getByClassName(selector) {
|
|
250
|
-
const newEls =
|
|
339
|
+
static getByClassName(selector, elem = document) {
|
|
340
|
+
const newEls = elem.getElementsByClassName(selector);
|
|
251
341
|
return TinyHtml.toTinyElm([...newEls]);
|
|
252
342
|
}
|
|
253
343
|
|
|
344
|
+
/**
|
|
345
|
+
* Retrieves all elements with the specified class name and wraps them in TinyHtml instances.
|
|
346
|
+
*
|
|
347
|
+
* @param {string} selector - The class name to search for.
|
|
348
|
+
* @returns {TinyHtml[]} An array of TinyHtml instances wrapping the found elements.
|
|
349
|
+
*/
|
|
350
|
+
getElementsByClassName(selector) {
|
|
351
|
+
return TinyHtml.getByClassName(selector, TinyHtml._preElem(this, 'getByClassName'));
|
|
352
|
+
}
|
|
353
|
+
|
|
254
354
|
/**
|
|
255
355
|
* Retrieves all elements with the specified name attribute and wraps them in TinyHtml instances.
|
|
256
356
|
*
|
|
@@ -268,13 +368,30 @@ class TinyHtml {
|
|
|
268
368
|
*
|
|
269
369
|
* @param {string} localName - The local name (tag) of the elements to search for.
|
|
270
370
|
* @param {string|null} [namespaceURI='http://www.w3.org/1999/xhtml'] - The namespace URI to search within.
|
|
371
|
+
* @param {Document|Element} elem - Target element.
|
|
271
372
|
* @returns {TinyHtml[]} An array of TinyHtml instances wrapping the found elements.
|
|
272
373
|
*/
|
|
273
|
-
static getByTagNameNS(localName, namespaceURI = 'http://www.w3.org/1999/xhtml') {
|
|
274
|
-
const newEls =
|
|
374
|
+
static getByTagNameNS(localName, namespaceURI = 'http://www.w3.org/1999/xhtml', elem = document) {
|
|
375
|
+
const newEls = elem.getElementsByTagNameNS(namespaceURI, localName);
|
|
275
376
|
return TinyHtml.toTinyElm([...newEls]);
|
|
276
377
|
}
|
|
277
378
|
|
|
379
|
+
/**
|
|
380
|
+
* Retrieves all elements with the specified local tag name within the given namespace URI,
|
|
381
|
+
* and wraps them in TinyHtml instances.
|
|
382
|
+
*
|
|
383
|
+
* @param {string} localName - The local name (tag) of the elements to search for.
|
|
384
|
+
* @param {string|null} [namespaceURI='http://www.w3.org/1999/xhtml'] - The namespace URI to search within.
|
|
385
|
+
* @returns {TinyHtml[]} An array of TinyHtml instances wrapping the found elements.
|
|
386
|
+
*/
|
|
387
|
+
getElementsByTagNameNS(localName, namespaceURI = 'http://www.w3.org/1999/xhtml') {
|
|
388
|
+
return TinyHtml.getByTagNameNS(
|
|
389
|
+
localName,
|
|
390
|
+
namespaceURI,
|
|
391
|
+
TinyHtml._preElem(this, 'getByTagNameNS'),
|
|
392
|
+
);
|
|
393
|
+
}
|
|
394
|
+
|
|
278
395
|
//////////////////////////////////////////////////////////////////
|
|
279
396
|
|
|
280
397
|
/**
|
|
@@ -555,6 +672,45 @@ class TinyHtml {
|
|
|
555
672
|
return TinyHtml._preElemTemplate(elems, where, [Element, Window], ['Element', 'Window']);
|
|
556
673
|
}
|
|
557
674
|
|
|
675
|
+
/**
|
|
676
|
+
* Ensures the input is returned as an array.
|
|
677
|
+
* Useful to normalize operations across multiple or single element/window/document elements.
|
|
678
|
+
*
|
|
679
|
+
* @param {TinyElementAndWinAndDoc|TinyElementAndWinAndDoc[]} elems - A single element/window element or array of html elements.
|
|
680
|
+
* @param {string} where - The method or context name where validation is being called.
|
|
681
|
+
* @returns {ElementAndWindow[]} - Always returns an array of element/window elements.
|
|
682
|
+
* @readonly
|
|
683
|
+
*/
|
|
684
|
+
static _preElemsAndWinAndDoc(elems, where) {
|
|
685
|
+
const result = TinyHtml._preElemsTemplate(
|
|
686
|
+
elems,
|
|
687
|
+
where,
|
|
688
|
+
[Element, Window, Document],
|
|
689
|
+
['Element', 'Window', 'Document'],
|
|
690
|
+
);
|
|
691
|
+
return result.map((elem) => (!(elem instanceof Document) ? elem : elem.documentElement));
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
/**
|
|
695
|
+
* Ensures the input is returned as an single element/window/document element.
|
|
696
|
+
* Useful to normalize operations across multiple or single element/window/document elements.
|
|
697
|
+
*
|
|
698
|
+
* @param {TinyElementAndWinAndDoc|TinyElementAndWinAndDoc[]} elems - A single element/window element or array of html elements.
|
|
699
|
+
* @param {string} where - The method or context name where validation is being called.
|
|
700
|
+
* @returns {ElementAndWindow} - Always returns an single element/window element.
|
|
701
|
+
* @readonly
|
|
702
|
+
*/
|
|
703
|
+
static _preElemAndWinAndDoc(elems, where) {
|
|
704
|
+
const result = TinyHtml._preElemTemplate(
|
|
705
|
+
elems,
|
|
706
|
+
where,
|
|
707
|
+
[Element, Window, Document],
|
|
708
|
+
['Element', 'Window', 'Document'],
|
|
709
|
+
);
|
|
710
|
+
if (result instanceof Document) return result.documentElement;
|
|
711
|
+
return result;
|
|
712
|
+
}
|
|
713
|
+
|
|
558
714
|
/**
|
|
559
715
|
* Normalizes and converts one or more DOM elements (or TinyHtml instances)
|
|
560
716
|
* into an array of `TinyHtml` instances.
|
|
@@ -901,12 +1057,13 @@ class TinyHtml {
|
|
|
901
1057
|
* @param {string} key - The key under which the data will be stored.
|
|
902
1058
|
* @param {any} value - The value to store.
|
|
903
1059
|
* @param {boolean} [isPrivate=false] - Whether to store the data in the private store.
|
|
904
|
-
* @returns {
|
|
1060
|
+
* @returns {TinyElement}
|
|
905
1061
|
*/
|
|
906
1062
|
static setData(el, key, value, isPrivate = false) {
|
|
907
1063
|
const data = TinyHtml._dataSelector[!isPrivate ? 'public' : 'private']('setData', el);
|
|
908
1064
|
if (typeof key !== 'string') throw new TypeError('The key must be a string.');
|
|
909
1065
|
data[key] = value;
|
|
1066
|
+
return el;
|
|
910
1067
|
}
|
|
911
1068
|
|
|
912
1069
|
/**
|
|
@@ -915,7 +1072,7 @@ class TinyHtml {
|
|
|
915
1072
|
* @param {string} key - The key under which the data will be stored.
|
|
916
1073
|
* @param {any} value - The value to store.
|
|
917
1074
|
* @param {boolean} [isPrivate=false] - Whether to store the data in the private store.
|
|
918
|
-
* @returns {
|
|
1075
|
+
* @returns {TinyElement}
|
|
919
1076
|
*/
|
|
920
1077
|
setData(key, value, isPrivate = false) {
|
|
921
1078
|
return TinyHtml.setData(this, key, value, isPrivate);
|
|
@@ -1262,18 +1419,21 @@ class TinyHtml {
|
|
|
1262
1419
|
/**
|
|
1263
1420
|
* Appends child elements or strings to the end of the target element(s).
|
|
1264
1421
|
*
|
|
1265
|
-
* @param {TinyElement
|
|
1422
|
+
* @param {TinyElement} el - The target element(s) to receive children.
|
|
1266
1423
|
* @param {...(TinyNode | TinyNode[] | string)} children - The child elements or text to append.
|
|
1424
|
+
* @returns {TinyElement}
|
|
1267
1425
|
*/
|
|
1268
1426
|
static append(el, ...children) {
|
|
1269
1427
|
const elem = TinyHtml._preElem(el, 'append');
|
|
1270
1428
|
elem.append(...TinyHtml._appendChecker('append', ...children));
|
|
1429
|
+
return el;
|
|
1271
1430
|
}
|
|
1272
1431
|
|
|
1273
1432
|
/**
|
|
1274
1433
|
* Appends child elements or strings to the end of the target element(s).
|
|
1275
1434
|
*
|
|
1276
1435
|
* @param {...(TinyNode | TinyNode[] | string)} children - The child elements or text to append.
|
|
1436
|
+
* @returns {TinyElement}
|
|
1277
1437
|
*/
|
|
1278
1438
|
append(...children) {
|
|
1279
1439
|
return TinyHtml.append(this, ...children);
|
|
@@ -1282,18 +1442,21 @@ class TinyHtml {
|
|
|
1282
1442
|
/**
|
|
1283
1443
|
* Prepends child elements or strings to the beginning of the target element(s).
|
|
1284
1444
|
*
|
|
1285
|
-
* @param {TinyElement
|
|
1445
|
+
* @param {TinyElement} el - The target element(s) to receive children.
|
|
1286
1446
|
* @param {...(TinyNode | TinyNode[] | string)} children - The child elements or text to prepend.
|
|
1447
|
+
* @returns {TinyElement}
|
|
1287
1448
|
*/
|
|
1288
1449
|
static prepend(el, ...children) {
|
|
1289
1450
|
const elem = TinyHtml._preElem(el, 'prepend');
|
|
1290
1451
|
elem.prepend(...TinyHtml._appendChecker('prepend', ...children));
|
|
1452
|
+
return el;
|
|
1291
1453
|
}
|
|
1292
1454
|
|
|
1293
1455
|
/**
|
|
1294
1456
|
* Prepends child elements or strings to the beginning of the target element(s).
|
|
1295
1457
|
*
|
|
1296
1458
|
* @param {...(TinyNode | TinyNode[] | string)} children - The child elements or text to prepend.
|
|
1459
|
+
* @returns {TinyElement}
|
|
1297
1460
|
*/
|
|
1298
1461
|
prepend(...children) {
|
|
1299
1462
|
return TinyHtml.prepend(this, ...children);
|
|
@@ -1302,18 +1465,21 @@ class TinyHtml {
|
|
|
1302
1465
|
/**
|
|
1303
1466
|
* Inserts elements or strings immediately before the target element(s) in the DOM.
|
|
1304
1467
|
*
|
|
1305
|
-
* @param {TinyElement
|
|
1468
|
+
* @param {TinyElement} el - The target element(s) before which new content is inserted.
|
|
1306
1469
|
* @param {...(TinyNode | TinyNode[] | string)} children - Elements or text to insert before the target.
|
|
1470
|
+
* @returns {TinyElement}
|
|
1307
1471
|
*/
|
|
1308
1472
|
static before(el, ...children) {
|
|
1309
1473
|
const elem = TinyHtml._preElem(el, 'before');
|
|
1310
1474
|
elem.before(...TinyHtml._appendChecker('before', ...children));
|
|
1475
|
+
return el;
|
|
1311
1476
|
}
|
|
1312
1477
|
|
|
1313
1478
|
/**
|
|
1314
1479
|
* Inserts elements or strings immediately before the target element(s) in the DOM.
|
|
1315
1480
|
*
|
|
1316
1481
|
* @param {...(TinyNode | TinyNode[] | string)} children - Elements or text to insert before the target.
|
|
1482
|
+
* @returns {TinyElement}
|
|
1317
1483
|
*/
|
|
1318
1484
|
before(...children) {
|
|
1319
1485
|
return TinyHtml.before(this, ...children);
|
|
@@ -1322,18 +1488,21 @@ class TinyHtml {
|
|
|
1322
1488
|
/**
|
|
1323
1489
|
* Inserts elements or strings immediately after the target element(s) in the DOM.
|
|
1324
1490
|
*
|
|
1325
|
-
* @param {TinyElement
|
|
1491
|
+
* @param {TinyElement} el - The target element(s) after which new content is inserted.
|
|
1326
1492
|
* @param {...(TinyNode | TinyNode[] | string)} children - Elements or text to insert after the target.
|
|
1493
|
+
* @returns {TinyElement}
|
|
1327
1494
|
*/
|
|
1328
1495
|
static after(el, ...children) {
|
|
1329
1496
|
const elem = TinyHtml._preElem(el, 'after');
|
|
1330
1497
|
elem.after(...TinyHtml._appendChecker('after', ...children));
|
|
1498
|
+
return el;
|
|
1331
1499
|
}
|
|
1332
1500
|
|
|
1333
1501
|
/**
|
|
1334
1502
|
* Inserts elements or strings immediately after the target element(s) in the DOM.
|
|
1335
1503
|
*
|
|
1336
1504
|
* @param {...(TinyNode | TinyNode[] | string)} children - Elements or text to insert after the target.
|
|
1505
|
+
* @returns {TinyElement}
|
|
1337
1506
|
*/
|
|
1338
1507
|
after(...children) {
|
|
1339
1508
|
return TinyHtml.after(this, ...children);
|
|
@@ -1342,18 +1511,21 @@ class TinyHtml {
|
|
|
1342
1511
|
/**
|
|
1343
1512
|
* Replaces the target element(s) in the DOM with new elements or text.
|
|
1344
1513
|
*
|
|
1345
|
-
* @param {TinyElement
|
|
1514
|
+
* @param {TinyElement} el - The element(s) to be replaced.
|
|
1346
1515
|
* @param {...(TinyNode | TinyNode[] | string)} newNodes - New elements or text to replace the target.
|
|
1516
|
+
* @returns {TinyElement}
|
|
1347
1517
|
*/
|
|
1348
1518
|
static replaceWith(el, ...newNodes) {
|
|
1349
1519
|
const elem = TinyHtml._preElem(el, 'replaceWith');
|
|
1350
1520
|
elem.replaceWith(...TinyHtml._appendChecker('replaceWith', ...newNodes));
|
|
1521
|
+
return el;
|
|
1351
1522
|
}
|
|
1352
1523
|
|
|
1353
1524
|
/**
|
|
1354
1525
|
* Replaces the target element(s) in the DOM with new elements or text.
|
|
1355
1526
|
*
|
|
1356
1527
|
* @param {...(TinyNode | TinyNode[] | string)} newNodes - New elements or text to replace the target.
|
|
1528
|
+
* @returns {TinyElement}
|
|
1357
1529
|
*/
|
|
1358
1530
|
replaceWith(...newNodes) {
|
|
1359
1531
|
return TinyHtml.replaceWith(this, ...newNodes);
|
|
@@ -1364,6 +1536,7 @@ class TinyHtml {
|
|
|
1364
1536
|
*
|
|
1365
1537
|
* @param {TinyNode | TinyNode[]} el - The element(s) to append.
|
|
1366
1538
|
* @param {TinyNode | TinyNode[]} targets - Target element(s) where content will be appended.
|
|
1539
|
+
* @returns {TinyNode|TinyNode[]}
|
|
1367
1540
|
*/
|
|
1368
1541
|
static appendTo(el, targets) {
|
|
1369
1542
|
const elems = TinyHtml._preNodeElems(el, 'appendTo');
|
|
@@ -1373,12 +1546,14 @@ class TinyHtml {
|
|
|
1373
1546
|
target.appendChild(i === tars.length - 1 ? elem : elem.cloneNode(true)),
|
|
1374
1547
|
);
|
|
1375
1548
|
});
|
|
1549
|
+
return el;
|
|
1376
1550
|
}
|
|
1377
1551
|
|
|
1378
1552
|
/**
|
|
1379
1553
|
* Appends the given element(s) to each target element in sequence.
|
|
1380
1554
|
*
|
|
1381
1555
|
* @param {TinyNode | TinyNode[]} targets - Target element(s) where content will be appended.
|
|
1556
|
+
* @returns {TinyNode|TinyNode[]}
|
|
1382
1557
|
*/
|
|
1383
1558
|
appendTo(targets) {
|
|
1384
1559
|
return TinyHtml.appendTo(this, targets);
|
|
@@ -1389,6 +1564,7 @@ class TinyHtml {
|
|
|
1389
1564
|
*
|
|
1390
1565
|
* @param {TinyElement | TinyElement[]} el - The element(s) to prepend.
|
|
1391
1566
|
* @param {TinyElement | TinyElement[]} targets - Target element(s) where content will be prepended.
|
|
1567
|
+
* @returns {TinyElement|TinyElement[]}
|
|
1392
1568
|
*/
|
|
1393
1569
|
static prependTo(el, targets) {
|
|
1394
1570
|
const elems = TinyHtml._preElems(el, 'prependTo');
|
|
@@ -1399,12 +1575,14 @@ class TinyHtml {
|
|
|
1399
1575
|
.reverse()
|
|
1400
1576
|
.forEach((elem) => target.prepend(i === tars.length - 1 ? elem : elem.cloneNode(true)));
|
|
1401
1577
|
});
|
|
1578
|
+
return el;
|
|
1402
1579
|
}
|
|
1403
1580
|
|
|
1404
1581
|
/**
|
|
1405
1582
|
* Prepends the given element(s) to each target element in sequence.
|
|
1406
1583
|
*
|
|
1407
1584
|
* @param {TinyElement | TinyElement[]} targets - Target element(s) where content will be prepended.
|
|
1585
|
+
* @returns {TinyElement|TinyElement[]}
|
|
1408
1586
|
*/
|
|
1409
1587
|
prependTo(targets) {
|
|
1410
1588
|
return TinyHtml.prependTo(this, targets);
|
|
@@ -1416,6 +1594,7 @@ class TinyHtml {
|
|
|
1416
1594
|
* @param {TinyNode | TinyNode[]} el - The element(s) to insert.
|
|
1417
1595
|
* @param {TinyNode | TinyNode[]} target - The reference element where insertion happens.
|
|
1418
1596
|
* @param {TinyNode | TinyNode[] | null} [child=null] - Optional child to insert before, defaults to target.
|
|
1597
|
+
* @returns {TinyNode|TinyNode[]}
|
|
1419
1598
|
*/
|
|
1420
1599
|
static insertBefore(el, target, child = null) {
|
|
1421
1600
|
const elem = TinyHtml._preNodeElem(el, 'insertBefore');
|
|
@@ -1423,6 +1602,7 @@ class TinyHtml {
|
|
|
1423
1602
|
const childNode = TinyHtml._preNodeElemWithNull(child, 'insertBefore');
|
|
1424
1603
|
if (!targ.parentNode) throw new Error('');
|
|
1425
1604
|
targ.parentNode.insertBefore(elem, childNode || targ);
|
|
1605
|
+
return el;
|
|
1426
1606
|
}
|
|
1427
1607
|
|
|
1428
1608
|
/**
|
|
@@ -1430,6 +1610,7 @@ class TinyHtml {
|
|
|
1430
1610
|
*
|
|
1431
1611
|
* @param {TinyNode | TinyNode[]} target - The reference element where insertion happens.
|
|
1432
1612
|
* @param {TinyNode | TinyNode[] | null} [child=null] - Optional child to insert before, defaults to target.
|
|
1613
|
+
* @returns {TinyNode|TinyNode[]}
|
|
1433
1614
|
*/
|
|
1434
1615
|
insertBefore(target, child) {
|
|
1435
1616
|
return TinyHtml.insertBefore(this, target, child);
|
|
@@ -1441,6 +1622,7 @@ class TinyHtml {
|
|
|
1441
1622
|
* @param {TinyNode | TinyNode[]} el - The element(s) to insert.
|
|
1442
1623
|
* @param {TinyNode | TinyNode[]} target - The reference element where insertion happens.
|
|
1443
1624
|
* @param {TinyNode | TinyNode[] | null} [child=null] - Optional child to insert after, defaults to target.
|
|
1625
|
+
* @returns {TinyNode|TinyNode[]}
|
|
1444
1626
|
*/
|
|
1445
1627
|
static insertAfter(el, target, child = null) {
|
|
1446
1628
|
const elem = TinyHtml._preNodeElem(el, 'insertAfter');
|
|
@@ -1448,6 +1630,7 @@ class TinyHtml {
|
|
|
1448
1630
|
const childNode = TinyHtml._preNodeElemWithNull(child, 'insertBefore');
|
|
1449
1631
|
if (!targ.parentNode) throw new Error('');
|
|
1450
1632
|
targ.parentNode.insertBefore(elem, childNode || targ.nextSibling);
|
|
1633
|
+
return el;
|
|
1451
1634
|
}
|
|
1452
1635
|
|
|
1453
1636
|
/**
|
|
@@ -1455,6 +1638,7 @@ class TinyHtml {
|
|
|
1455
1638
|
*
|
|
1456
1639
|
* @param {TinyNode | TinyNode[]} target - The reference element where insertion happens.
|
|
1457
1640
|
* @param {TinyNode | TinyNode[] | null} [child=null] - Optional child to insert after, defaults to target.
|
|
1641
|
+
* @returns {TinyNode|TinyNode[]}
|
|
1458
1642
|
*/
|
|
1459
1643
|
insertAfter(target, child) {
|
|
1460
1644
|
return TinyHtml.insertAfter(this, target, child);
|
|
@@ -1466,6 +1650,7 @@ class TinyHtml {
|
|
|
1466
1650
|
*
|
|
1467
1651
|
* @param {TinyNode | TinyNode[]} el - The new element(s) to insert.
|
|
1468
1652
|
* @param {TinyNode | TinyNode[]} targets - The elements to be replaced.
|
|
1653
|
+
* @returns {TinyNode|TinyNode[]}
|
|
1469
1654
|
*/
|
|
1470
1655
|
static replaceAll(el, targets) {
|
|
1471
1656
|
const elems = TinyHtml._preNodeElems(el, 'replaceAll');
|
|
@@ -1477,6 +1662,7 @@ class TinyHtml {
|
|
|
1477
1662
|
parent.replaceChild(i === tars.length - 1 ? elem : elem.cloneNode(true), target);
|
|
1478
1663
|
});
|
|
1479
1664
|
});
|
|
1665
|
+
return el;
|
|
1480
1666
|
}
|
|
1481
1667
|
|
|
1482
1668
|
/**
|
|
@@ -1484,6 +1670,7 @@ class TinyHtml {
|
|
|
1484
1670
|
* If multiple targets exist, the inserted elements are cloned accordingly.
|
|
1485
1671
|
*
|
|
1486
1672
|
* @param {TinyNode | TinyNode[]} targets - The elements to be replaced.
|
|
1673
|
+
* @returns {TinyNode|TinyNode[]}
|
|
1487
1674
|
*/
|
|
1488
1675
|
replaceAll(targets) {
|
|
1489
1676
|
return TinyHtml.replaceAll(this, targets);
|
|
@@ -1507,7 +1694,12 @@ class TinyHtml {
|
|
|
1507
1694
|
throw new Error(
|
|
1508
1695
|
`[TinyHtml] You are trying to put a TinyHtml inside another TinyHtml in constructor.`,
|
|
1509
1696
|
);
|
|
1510
|
-
if (
|
|
1697
|
+
if (
|
|
1698
|
+
!(el instanceof Element) &&
|
|
1699
|
+
!(el instanceof Window) &&
|
|
1700
|
+
!(el instanceof Document) &&
|
|
1701
|
+
!(el instanceof Text)
|
|
1702
|
+
)
|
|
1511
1703
|
throw new Error(`[TinyHtml] Invalid Target in constructor.`);
|
|
1512
1704
|
this.#el = el;
|
|
1513
1705
|
}
|
|
@@ -1957,6 +2149,7 @@ class TinyHtml {
|
|
|
1957
2149
|
* @param {TinyHtmlElement|TinyHtmlElement[]} el - The element to inspect.
|
|
1958
2150
|
* @param {string|Object} prop - The property name or an object with key-value pairs
|
|
1959
2151
|
* @param {string|null} [value=null] - The value to set (if `prop` is a string)
|
|
2152
|
+
* @returns {TinyHtmlElement|TinyHtmlElement[]}
|
|
1960
2153
|
*/
|
|
1961
2154
|
static setStyle(el, prop, value = null) {
|
|
1962
2155
|
TinyHtml._preHtmlElems(el, 'setStyle').forEach((elem) => {
|
|
@@ -1969,6 +2162,7 @@ class TinyHtml {
|
|
|
1969
2162
|
}
|
|
1970
2163
|
} else elem.style.setProperty(TinyHtml.toStyleKc(prop), value);
|
|
1971
2164
|
});
|
|
2165
|
+
return el;
|
|
1972
2166
|
}
|
|
1973
2167
|
|
|
1974
2168
|
/**
|
|
@@ -1979,6 +2173,7 @@ class TinyHtml {
|
|
|
1979
2173
|
*
|
|
1980
2174
|
* @param {string|Object} prop - The property name or an object with key-value pairs
|
|
1981
2175
|
* @param {string|null} [value=null] - The value to set (if `prop` is a string)
|
|
2176
|
+
* @returns {TinyHtmlElement|TinyHtmlElement[]}
|
|
1982
2177
|
*/
|
|
1983
2178
|
setStyle(prop, value) {
|
|
1984
2179
|
return TinyHtml.setStyle(this, prop, value);
|
|
@@ -2074,6 +2269,7 @@ class TinyHtml {
|
|
|
2074
2269
|
*
|
|
2075
2270
|
* @param {TinyHtmlElement|TinyHtmlElement[]} el - A single element or an array of elements.
|
|
2076
2271
|
* @param {string|string[]} prop - A property name or an array of property names to remove.
|
|
2272
|
+
* @returns {TinyHtmlElement|TinyHtmlElement[]}
|
|
2077
2273
|
*/
|
|
2078
2274
|
static removeStyle(el, prop) {
|
|
2079
2275
|
TinyHtml._preHtmlElems(el, 'removeStyle').forEach((elem) => {
|
|
@@ -2083,12 +2279,14 @@ class TinyHtml {
|
|
|
2083
2279
|
}
|
|
2084
2280
|
} else elem.style.removeProperty(TinyHtml.toStyleKc(prop));
|
|
2085
2281
|
});
|
|
2282
|
+
return el;
|
|
2086
2283
|
}
|
|
2087
2284
|
|
|
2088
2285
|
/**
|
|
2089
2286
|
* Removes one or more inline CSS properties from the given element(s).
|
|
2090
2287
|
*
|
|
2091
2288
|
* @param {string|string[]} prop - A property name or an array of property names to remove.
|
|
2289
|
+
* @returns {TinyHtmlElement|TinyHtmlElement[]}
|
|
2092
2290
|
*/
|
|
2093
2291
|
removeStyle(prop) {
|
|
2094
2292
|
return TinyHtml.removeStyle(this, prop);
|
|
@@ -2103,6 +2301,7 @@ class TinyHtml {
|
|
|
2103
2301
|
* @param {string} prop - The CSS property to toggle.
|
|
2104
2302
|
* @param {string} val1 - The first value (used as "current" check).
|
|
2105
2303
|
* @param {string} val2 - The second value (used as the "alternative").
|
|
2304
|
+
* @returns {TinyHtmlElement|TinyHtmlElement[]}
|
|
2106
2305
|
*/
|
|
2107
2306
|
static toggleStyle(el, prop, val1, val2) {
|
|
2108
2307
|
TinyHtml._preHtmlElems(el, 'toggleStyle').forEach((elem) => {
|
|
@@ -2110,6 +2309,7 @@ class TinyHtml {
|
|
|
2110
2309
|
const newVal = current === TinyHtml.toStyleKc(val1) ? val2 : val1;
|
|
2111
2310
|
TinyHtml.setStyle(elem, prop, newVal);
|
|
2112
2311
|
});
|
|
2312
|
+
return el;
|
|
2113
2313
|
}
|
|
2114
2314
|
|
|
2115
2315
|
/**
|
|
@@ -2120,6 +2320,7 @@ class TinyHtml {
|
|
|
2120
2320
|
* @param {string} prop - The CSS property to toggle.
|
|
2121
2321
|
* @param {string} val1 - The first value (used as "current" check).
|
|
2122
2322
|
* @param {string} val2 - The second value (used as the "alternative").
|
|
2323
|
+
* @returns {TinyHtmlElement|TinyHtmlElement[]}
|
|
2123
2324
|
*/
|
|
2124
2325
|
toggleStyle(prop, val1, val2) {
|
|
2125
2326
|
return TinyHtml.toggleStyle(this, prop, val1, val2);
|
|
@@ -2129,14 +2330,16 @@ class TinyHtml {
|
|
|
2129
2330
|
* Removes all inline styles (`style` attribute) from the given element(s).
|
|
2130
2331
|
*
|
|
2131
2332
|
* @param {TinyElement|TinyElement[]} el - A single element or an array of elements.
|
|
2333
|
+
* @returns {TinyElement|TinyElement[]}
|
|
2132
2334
|
*/
|
|
2133
2335
|
static clearStyle(el) {
|
|
2134
2336
|
TinyHtml._preElems(el, 'clearStyle').forEach((elem) => elem.removeAttribute('style'));
|
|
2337
|
+
return el;
|
|
2135
2338
|
}
|
|
2136
2339
|
|
|
2137
2340
|
/**
|
|
2138
2341
|
* Removes all inline styles (`style` attribute) from the given element(s).
|
|
2139
|
-
*
|
|
2342
|
+
* @returns {TinyElement|TinyElement[]}
|
|
2140
2343
|
*/
|
|
2141
2344
|
clearStyle() {
|
|
2142
2345
|
return TinyHtml.clearStyle(this);
|
|
@@ -2148,14 +2351,17 @@ class TinyHtml {
|
|
|
2148
2351
|
* Focus the element.
|
|
2149
2352
|
*
|
|
2150
2353
|
* @param {TinyHtmlElement} el - The element or a selector string.
|
|
2354
|
+
* @returns {TinyHtmlElement}
|
|
2151
2355
|
*/
|
|
2152
2356
|
static focus(el) {
|
|
2153
2357
|
const elem = TinyHtml._preHtmlElem(el, 'focus');
|
|
2154
2358
|
elem.focus();
|
|
2359
|
+
return el;
|
|
2155
2360
|
}
|
|
2156
2361
|
|
|
2157
2362
|
/**
|
|
2158
2363
|
* Focus the element.
|
|
2364
|
+
* @returns {TinyHtmlElement}
|
|
2159
2365
|
*/
|
|
2160
2366
|
focus() {
|
|
2161
2367
|
return TinyHtml.focus(this);
|
|
@@ -2165,19 +2371,46 @@ class TinyHtml {
|
|
|
2165
2371
|
* Blur the element.
|
|
2166
2372
|
*
|
|
2167
2373
|
* @param {TinyHtmlElement} el - The element or a selector string.
|
|
2374
|
+
* @returns {TinyHtmlElement}
|
|
2168
2375
|
*/
|
|
2169
2376
|
static blur(el) {
|
|
2170
2377
|
const elem = TinyHtml._preHtmlElem(el, 'blur');
|
|
2171
2378
|
elem.blur();
|
|
2379
|
+
return el;
|
|
2172
2380
|
}
|
|
2173
2381
|
|
|
2174
2382
|
/**
|
|
2175
2383
|
* Blur the element.
|
|
2384
|
+
* @returns {TinyHtmlElement}
|
|
2176
2385
|
*/
|
|
2177
2386
|
blur() {
|
|
2178
2387
|
return TinyHtml.blur(this);
|
|
2179
2388
|
}
|
|
2180
2389
|
|
|
2390
|
+
/**
|
|
2391
|
+
* Interprets a value as a boolean `true` if it matches a common truthy representation.
|
|
2392
|
+
*
|
|
2393
|
+
* This method checks if the input is any of the common forms used to represent `true`,
|
|
2394
|
+
* such as the string `'true'`, `'1'`, `'on'`, the boolean `true`, or the number `1`.
|
|
2395
|
+
*
|
|
2396
|
+
* @param {string|boolean|number} [value] - The value to interpret as boolean.
|
|
2397
|
+
* @returns {boolean} `true` if the value represents a truthy state, otherwise `false`.
|
|
2398
|
+
*/
|
|
2399
|
+
static boolCheck(value) {
|
|
2400
|
+
if (
|
|
2401
|
+
typeof value !== 'undefined' &&
|
|
2402
|
+
(value === 'true' ||
|
|
2403
|
+
value === '1' ||
|
|
2404
|
+
value === true ||
|
|
2405
|
+
value === 'on' ||
|
|
2406
|
+
(typeof value === 'number' && value > 0))
|
|
2407
|
+
) {
|
|
2408
|
+
return true;
|
|
2409
|
+
} else {
|
|
2410
|
+
return false;
|
|
2411
|
+
}
|
|
2412
|
+
}
|
|
2413
|
+
|
|
2181
2414
|
//////////////////////////////////////////////////////////////////////
|
|
2182
2415
|
|
|
2183
2416
|
/**
|
|
@@ -2230,16 +2463,40 @@ class TinyHtml {
|
|
|
2230
2463
|
return window.innerWidth || document.documentElement.clientWidth;
|
|
2231
2464
|
}
|
|
2232
2465
|
|
|
2466
|
+
/**
|
|
2467
|
+
* Checks if the page is currently scrolled to the very top.
|
|
2468
|
+
*
|
|
2469
|
+
* This method compares the current vertical scroll position with the total document height.
|
|
2470
|
+
* It's useful for detecting if the user has reached the top of the page.
|
|
2471
|
+
*
|
|
2472
|
+
* @returns {boolean} `true` if the page is scrolled to the top, otherwise `false`.
|
|
2473
|
+
*/
|
|
2474
|
+
static isPageTop() {
|
|
2475
|
+
return window.scrollY === 0;
|
|
2476
|
+
}
|
|
2477
|
+
|
|
2478
|
+
/**
|
|
2479
|
+
* Checks if the page is currently scrolled to the very bottom.
|
|
2480
|
+
*
|
|
2481
|
+
* This method uses the `scrollY` and `innerHeight` properties to determine if the
|
|
2482
|
+
* user has reached the end of the document.
|
|
2483
|
+
*
|
|
2484
|
+
* @returns {boolean} `true` if the page is scrolled to the bottom, otherwise `false`.
|
|
2485
|
+
*/
|
|
2486
|
+
static isPageBottom() {
|
|
2487
|
+
return window.innerHeight + window.scrollY >= document.body.offsetHeight;
|
|
2488
|
+
}
|
|
2489
|
+
|
|
2233
2490
|
/**
|
|
2234
2491
|
* Gets the width or height of an element based on the box model.
|
|
2235
|
-
* @param {
|
|
2492
|
+
* @param {TinyElementAndWinAndDoc} el - The element or window.
|
|
2236
2493
|
* @param {"width"|"height"} type - Dimension type.
|
|
2237
2494
|
* @param {"content"|"padding"|"border"|"margin"} [extra='content'] - Box model context.
|
|
2238
2495
|
* @returns {number} - Computed dimension.
|
|
2239
2496
|
* @throws {TypeError} If `type` or `extra` is not a string.
|
|
2240
2497
|
*/
|
|
2241
2498
|
static getDimension(el, type, extra = 'content') {
|
|
2242
|
-
const elem = TinyHtml.
|
|
2499
|
+
const elem = TinyHtml._preElemAndWinAndDoc(el, 'getDimension');
|
|
2243
2500
|
if (typeof type !== 'string') throw new TypeError('The type must be a string.');
|
|
2244
2501
|
if (typeof extra !== 'string') throw new TypeError('The extra must be a string.');
|
|
2245
2502
|
|
|
@@ -2327,17 +2584,20 @@ class TinyHtml {
|
|
|
2327
2584
|
* @param {TinyHtmlElement} el - Target element.
|
|
2328
2585
|
* @param {string|number} value - Height value.
|
|
2329
2586
|
* @throws {TypeError} If `value` is neither a string nor number.
|
|
2587
|
+
* @returns {TinyHtmlElement}
|
|
2330
2588
|
*/
|
|
2331
2589
|
static setHeight(el, value) {
|
|
2332
2590
|
const elem = TinyHtml._preHtmlElem(el, 'setHeight');
|
|
2333
2591
|
if (typeof value !== 'number' && typeof value !== 'string')
|
|
2334
2592
|
throw new TypeError('The value must be a string or number.');
|
|
2335
2593
|
elem.style.height = typeof value === 'number' ? `${value}px` : value;
|
|
2594
|
+
return el;
|
|
2336
2595
|
}
|
|
2337
2596
|
|
|
2338
2597
|
/**
|
|
2339
2598
|
* Sets the height of the element.
|
|
2340
2599
|
* @param {string|number} value - Height value.
|
|
2600
|
+
* @returns {TinyHtmlElement}
|
|
2341
2601
|
*/
|
|
2342
2602
|
setHeight(value) {
|
|
2343
2603
|
return TinyHtml.setHeight(this, value);
|
|
@@ -2348,17 +2608,20 @@ class TinyHtml {
|
|
|
2348
2608
|
* @param {TinyHtmlElement} el - Target element.
|
|
2349
2609
|
* @param {string|number} value - Width value.
|
|
2350
2610
|
* @throws {TypeError} If `value` is neither a string nor number.
|
|
2611
|
+
* @returns {TinyHtmlElement}
|
|
2351
2612
|
*/
|
|
2352
2613
|
static setWidth(el, value) {
|
|
2353
2614
|
const elem = TinyHtml._preHtmlElem(el, 'setWidth');
|
|
2354
2615
|
if (typeof value !== 'number' && typeof value !== 'string')
|
|
2355
2616
|
throw new TypeError('The value must be a string or number.');
|
|
2356
2617
|
elem.style.width = typeof value === 'number' ? `${value}px` : value;
|
|
2618
|
+
return el;
|
|
2357
2619
|
}
|
|
2358
2620
|
|
|
2359
2621
|
/**
|
|
2360
2622
|
* Sets the width of the element.
|
|
2361
2623
|
* @param {string|number} value - Width value.
|
|
2624
|
+
* @returns {TinyHtmlElement}
|
|
2362
2625
|
*/
|
|
2363
2626
|
setWidth(value) {
|
|
2364
2627
|
return TinyHtml.setWidth(this, value);
|
|
@@ -2366,11 +2629,11 @@ class TinyHtml {
|
|
|
2366
2629
|
|
|
2367
2630
|
/**
|
|
2368
2631
|
* Returns content box height.
|
|
2369
|
-
* @param {
|
|
2632
|
+
* @param {TinyElementAndWinAndDoc} el - Target element.
|
|
2370
2633
|
* @returns {number}
|
|
2371
2634
|
*/
|
|
2372
2635
|
static height(el) {
|
|
2373
|
-
const elem = TinyHtml.
|
|
2636
|
+
const elem = TinyHtml._preElemAndWinAndDoc(el, 'height');
|
|
2374
2637
|
return TinyHtml.getDimension(elem, 'height', 'content');
|
|
2375
2638
|
}
|
|
2376
2639
|
|
|
@@ -2384,11 +2647,11 @@ class TinyHtml {
|
|
|
2384
2647
|
|
|
2385
2648
|
/**
|
|
2386
2649
|
* Returns content box width.
|
|
2387
|
-
* @param {
|
|
2650
|
+
* @param {TinyElementAndWinAndDoc} el - Target element.
|
|
2388
2651
|
* @returns {number}
|
|
2389
2652
|
*/
|
|
2390
2653
|
static width(el) {
|
|
2391
|
-
const elem = TinyHtml.
|
|
2654
|
+
const elem = TinyHtml._preElemAndWinAndDoc(el, 'width');
|
|
2392
2655
|
return TinyHtml.getDimension(elem, 'width', 'content');
|
|
2393
2656
|
}
|
|
2394
2657
|
|
|
@@ -2402,11 +2665,11 @@ class TinyHtml {
|
|
|
2402
2665
|
|
|
2403
2666
|
/**
|
|
2404
2667
|
* Returns padding box height.
|
|
2405
|
-
* @param {
|
|
2668
|
+
* @param {TinyElementAndWinAndDoc} el - Target element.
|
|
2406
2669
|
* @returns {number}
|
|
2407
2670
|
*/
|
|
2408
2671
|
static innerHeight(el) {
|
|
2409
|
-
const elem = TinyHtml.
|
|
2672
|
+
const elem = TinyHtml._preElemAndWinAndDoc(el, 'innerHeight');
|
|
2410
2673
|
return TinyHtml.getDimension(elem, 'height', 'padding');
|
|
2411
2674
|
}
|
|
2412
2675
|
|
|
@@ -2420,11 +2683,11 @@ class TinyHtml {
|
|
|
2420
2683
|
|
|
2421
2684
|
/**
|
|
2422
2685
|
* Returns padding box width.
|
|
2423
|
-
* @param {
|
|
2686
|
+
* @param {TinyElementAndWinAndDoc} el - Target element.
|
|
2424
2687
|
* @returns {number}
|
|
2425
2688
|
*/
|
|
2426
2689
|
static innerWidth(el) {
|
|
2427
|
-
const elem = TinyHtml.
|
|
2690
|
+
const elem = TinyHtml._preElemAndWinAndDoc(el, 'innerWidth');
|
|
2428
2691
|
return TinyHtml.getDimension(elem, 'width', 'padding');
|
|
2429
2692
|
}
|
|
2430
2693
|
|
|
@@ -2438,14 +2701,14 @@ class TinyHtml {
|
|
|
2438
2701
|
|
|
2439
2702
|
/**
|
|
2440
2703
|
* Returns outer height of the element, optionally including margin.
|
|
2441
|
-
* @param {
|
|
2704
|
+
* @param {TinyElementAndWinAndDoc} el - Target element.
|
|
2442
2705
|
* @param {boolean} [includeMargin=false] - Whether to include margin.
|
|
2443
2706
|
* @returns {number}
|
|
2444
2707
|
*/
|
|
2445
2708
|
static outerHeight(el, includeMargin = false) {
|
|
2446
2709
|
if (typeof includeMargin !== 'boolean')
|
|
2447
2710
|
throw new TypeError('The "includeMargin" must be a boolean.');
|
|
2448
|
-
const elem = TinyHtml.
|
|
2711
|
+
const elem = TinyHtml._preElemAndWinAndDoc(el, 'outerHeight');
|
|
2449
2712
|
return TinyHtml.getDimension(elem, 'height', includeMargin ? 'margin' : 'border');
|
|
2450
2713
|
}
|
|
2451
2714
|
|
|
@@ -2460,14 +2723,14 @@ class TinyHtml {
|
|
|
2460
2723
|
|
|
2461
2724
|
/**
|
|
2462
2725
|
* Returns outer width of the element, optionally including margin.
|
|
2463
|
-
* @param {
|
|
2726
|
+
* @param {TinyElementAndWinAndDoc} el - Target element.
|
|
2464
2727
|
* @param {boolean} [includeMargin=false] - Whether to include margin.
|
|
2465
2728
|
* @returns {number}
|
|
2466
2729
|
*/
|
|
2467
2730
|
static outerWidth(el, includeMargin = false) {
|
|
2468
2731
|
if (typeof includeMargin !== 'boolean')
|
|
2469
2732
|
throw new TypeError('The "includeMargin" must be a boolean.');
|
|
2470
|
-
const elem = TinyHtml.
|
|
2733
|
+
const elem = TinyHtml._preElemAndWinAndDoc(el, 'outerWidth');
|
|
2471
2734
|
return TinyHtml.getDimension(elem, 'width', includeMargin ? 'margin' : 'border');
|
|
2472
2735
|
}
|
|
2473
2736
|
|
|
@@ -2640,6 +2903,7 @@ class TinyHtml {
|
|
|
2640
2903
|
* Sets the vertical scroll position.
|
|
2641
2904
|
* @param {TinyElementAndWindow|TinyElementAndWindow[]} el - Element or window.
|
|
2642
2905
|
* @param {number} value - Scroll top value.
|
|
2906
|
+
* @returns {TinyElementAndWindow|TinyElementAndWindow[]}
|
|
2643
2907
|
*/
|
|
2644
2908
|
static setScrollTop(el, value) {
|
|
2645
2909
|
if (typeof value !== 'number') throw new TypeError('ScrollTop value must be a number.');
|
|
@@ -2653,11 +2917,13 @@ class TinyHtml {
|
|
|
2653
2917
|
elem.scrollTop = value;
|
|
2654
2918
|
}
|
|
2655
2919
|
});
|
|
2920
|
+
return el;
|
|
2656
2921
|
}
|
|
2657
2922
|
|
|
2658
2923
|
/**
|
|
2659
2924
|
* Sets the vertical scroll position.
|
|
2660
2925
|
* @param {number} value - Scroll top value.
|
|
2926
|
+
* @returns {TinyElementAndWindow|TinyElementAndWindow[]}
|
|
2661
2927
|
*/
|
|
2662
2928
|
setScrollTop(value) {
|
|
2663
2929
|
return TinyHtml.setScrollTop(this, value);
|
|
@@ -2667,6 +2933,7 @@ class TinyHtml {
|
|
|
2667
2933
|
* Sets the horizontal scroll position.
|
|
2668
2934
|
* @param {TinyElementAndWindow|TinyElementAndWindow[]} el - Element or window.
|
|
2669
2935
|
* @param {number} value - Scroll left value.
|
|
2936
|
+
* @returns {TinyElementAndWindow|TinyElementAndWindow[]}
|
|
2670
2937
|
*/
|
|
2671
2938
|
static setScrollLeft(el, value) {
|
|
2672
2939
|
if (typeof value !== 'number') throw new TypeError('ScrollLeft value must be a number.');
|
|
@@ -2680,11 +2947,13 @@ class TinyHtml {
|
|
|
2680
2947
|
elem.scrollLeft = value;
|
|
2681
2948
|
}
|
|
2682
2949
|
});
|
|
2950
|
+
return el;
|
|
2683
2951
|
}
|
|
2684
2952
|
|
|
2685
2953
|
/**
|
|
2686
2954
|
* Sets the horizontal scroll position.
|
|
2687
2955
|
* @param {number} value - Scroll left value.
|
|
2956
|
+
* @returns {TinyElementAndWindow|TinyElementAndWindow[]}
|
|
2688
2957
|
*/
|
|
2689
2958
|
setScrollLeft(value) {
|
|
2690
2959
|
return TinyHtml.setScrollLeft(this, value);
|
|
@@ -2815,15 +3084,16 @@ class TinyHtml {
|
|
|
2815
3084
|
|
|
2816
3085
|
/**
|
|
2817
3086
|
* Adds one or more CSS class names to the element.
|
|
2818
|
-
* @type {(el: TinyElement|TinyElement[], ...tokens: string[]) =>
|
|
3087
|
+
* @type {(el: TinyElement|TinyElement[], ...tokens: string[]) => (TinyElement|TinyElement[])} - One or more class names to add.
|
|
2819
3088
|
*/
|
|
2820
3089
|
static addClass(el, ...args) {
|
|
2821
3090
|
TinyHtml._preElems(el, 'addClass').forEach((elem) => elem.classList.add(...args));
|
|
3091
|
+
return el;
|
|
2822
3092
|
}
|
|
2823
3093
|
|
|
2824
3094
|
/**
|
|
2825
3095
|
* Adds one or more CSS class names to the element.
|
|
2826
|
-
* @type {(...tokens: string[]) =>
|
|
3096
|
+
* @type {(...tokens: string[]) => (TinyElement|TinyElement[])} - One or more class names to add.
|
|
2827
3097
|
*/
|
|
2828
3098
|
addClass(...args) {
|
|
2829
3099
|
return TinyHtml.addClass(this, ...args);
|
|
@@ -2831,15 +3101,16 @@ class TinyHtml {
|
|
|
2831
3101
|
|
|
2832
3102
|
/**
|
|
2833
3103
|
* Removes one or more CSS class names from the element.
|
|
2834
|
-
* @type {(el: TinyElement|TinyElement[], ...tokens: string[]) =>
|
|
3104
|
+
* @type {(el: TinyElement|TinyElement[], ...tokens: string[]) => (TinyElement|TinyElement[])} - One or more class names to remove.
|
|
2835
3105
|
*/
|
|
2836
3106
|
static removeClass(el, ...args) {
|
|
2837
3107
|
TinyHtml._preElems(el, 'removeClass').forEach((elem) => elem.classList.remove(...args));
|
|
3108
|
+
return el;
|
|
2838
3109
|
}
|
|
2839
3110
|
|
|
2840
3111
|
/**
|
|
2841
3112
|
* Removes one or more CSS class names from the element.
|
|
2842
|
-
* @type {(...tokens: string[]) =>
|
|
3113
|
+
* @type {(...tokens: string[]) => (TinyElement|TinyElement[])} - One or more class names to remove.
|
|
2843
3114
|
*/
|
|
2844
3115
|
removeClass(...args) {
|
|
2845
3116
|
return TinyHtml.removeClass(this, ...args);
|
|
@@ -3049,15 +3320,18 @@ class TinyHtml {
|
|
|
3049
3320
|
* Set text content of elements.
|
|
3050
3321
|
* @param {TinyElement|TinyElement[]} el
|
|
3051
3322
|
* @param {string} value
|
|
3323
|
+
* @returns {TinyElement|TinyElement[]}
|
|
3052
3324
|
*/
|
|
3053
3325
|
static setText(el, value) {
|
|
3054
3326
|
if (typeof value !== 'string') throw new Error('Value is not a valid string.');
|
|
3055
3327
|
TinyHtml._preElems(el, 'setText').forEach((el) => (el.textContent = value));
|
|
3328
|
+
return el;
|
|
3056
3329
|
}
|
|
3057
3330
|
|
|
3058
3331
|
/**
|
|
3059
3332
|
* Set text content of the element.
|
|
3060
3333
|
* @param {string} value
|
|
3334
|
+
* @returns {TinyElement|TinyElement[]}
|
|
3061
3335
|
*/
|
|
3062
3336
|
setText(value) {
|
|
3063
3337
|
return TinyHtml.setText(this, value);
|
|
@@ -3066,13 +3340,16 @@ class TinyHtml {
|
|
|
3066
3340
|
/**
|
|
3067
3341
|
* Remove all child nodes from each element.
|
|
3068
3342
|
* @param {TinyElement|TinyElement[]} el
|
|
3343
|
+
* @returns {TinyElement|TinyElement[]}
|
|
3069
3344
|
*/
|
|
3070
3345
|
static empty(el) {
|
|
3071
3346
|
TinyHtml._preElems(el, 'empty').forEach((el) => (el.textContent = ''));
|
|
3347
|
+
return el;
|
|
3072
3348
|
}
|
|
3073
3349
|
|
|
3074
3350
|
/**
|
|
3075
3351
|
* Remove all child nodes of the element.
|
|
3352
|
+
* @returns {TinyElement|TinyElement[]}
|
|
3076
3353
|
*/
|
|
3077
3354
|
empty() {
|
|
3078
3355
|
return TinyHtml.empty(this);
|
|
@@ -3080,35 +3357,40 @@ class TinyHtml {
|
|
|
3080
3357
|
|
|
3081
3358
|
/**
|
|
3082
3359
|
* Get the innerHTML of the element.
|
|
3083
|
-
* @param {TinyElement
|
|
3360
|
+
* @param {TinyElement} el
|
|
3361
|
+
* @param {GetHTMLOptions} [ops]
|
|
3084
3362
|
* @returns {string}
|
|
3085
3363
|
*/
|
|
3086
|
-
static html(el) {
|
|
3364
|
+
static html(el, ops) {
|
|
3087
3365
|
const elem = TinyHtml._preElem(el, 'html');
|
|
3088
|
-
return elem.
|
|
3366
|
+
return elem.getHTML(ops);
|
|
3089
3367
|
}
|
|
3090
3368
|
|
|
3091
3369
|
/**
|
|
3092
3370
|
* Get the innerHTML of the element.
|
|
3371
|
+
* @param {GetHTMLOptions} [ops]
|
|
3093
3372
|
* @returns {string}
|
|
3094
3373
|
*/
|
|
3095
|
-
html() {
|
|
3096
|
-
return TinyHtml.html(this);
|
|
3374
|
+
html(ops) {
|
|
3375
|
+
return TinyHtml.html(this, ops);
|
|
3097
3376
|
}
|
|
3098
3377
|
|
|
3099
3378
|
/**
|
|
3100
3379
|
* Set the innerHTML of each element.
|
|
3101
3380
|
* @param {TinyElement|TinyElement[]} el
|
|
3102
3381
|
* @param {string} value
|
|
3382
|
+
* @returns {TinyElement|TinyElement[]}
|
|
3103
3383
|
*/
|
|
3104
3384
|
static setHtml(el, value) {
|
|
3105
3385
|
if (typeof value !== 'string') throw new Error('Value is not a valid string.');
|
|
3106
3386
|
TinyHtml._preElems(el, 'setHtml').forEach((el) => (el.innerHTML = value));
|
|
3387
|
+
return el;
|
|
3107
3388
|
}
|
|
3108
3389
|
|
|
3109
3390
|
/**
|
|
3110
3391
|
* Set the innerHTML of the element.
|
|
3111
3392
|
* @param {string} value
|
|
3393
|
+
* @returns {TinyElement|TinyElement[]}
|
|
3112
3394
|
*/
|
|
3113
3395
|
setHtml(value) {
|
|
3114
3396
|
return TinyHtml.setHtml(this, value);
|
|
@@ -3242,6 +3524,7 @@ class TinyHtml {
|
|
|
3242
3524
|
* @param {TinyInputElement|TinyInputElement[]} el - Target element.
|
|
3243
3525
|
* @param {SetValueList|((el: InputElement, val: SetValueList) => SetValueList)} value - The value to assign or a function that returns it.
|
|
3244
3526
|
* @throws {Error} If the computed value is not a valid string or boolean.
|
|
3527
|
+
* @returns {TinyInputElement|TinyInputElement[]}
|
|
3245
3528
|
*/
|
|
3246
3529
|
static setVal(el, value) {
|
|
3247
3530
|
TinyHtml._preInputElems(el, 'setVal').forEach((elem) => {
|
|
@@ -3281,6 +3564,7 @@ class TinyHtml {
|
|
|
3281
3564
|
if (typeof valToSet === 'string') elem.value = valToSet;
|
|
3282
3565
|
}
|
|
3283
3566
|
});
|
|
3567
|
+
return el;
|
|
3284
3568
|
}
|
|
3285
3569
|
|
|
3286
3570
|
/**
|
|
@@ -3288,6 +3572,7 @@ class TinyHtml {
|
|
|
3288
3572
|
* Accepts strings, numbers, booleans or arrays of these values, or a callback function that computes them.
|
|
3289
3573
|
*
|
|
3290
3574
|
* @param {SetValueList|((el: InputElement, val: SetValueList) => SetValueList)} value - The value to assign or a function that returns it.
|
|
3575
|
+
* @returns {TinyInputElement|TinyInputElement[]}
|
|
3291
3576
|
* @throws {Error} If the computed value is not a valid string or boolean.
|
|
3292
3577
|
*/
|
|
3293
3578
|
setVal(value) {
|
|
@@ -3557,6 +3842,7 @@ class TinyHtml {
|
|
|
3557
3842
|
* @param {string} event - The event type (e.g. 'click', 'keydown').
|
|
3558
3843
|
* @param {EventRegistryHandle} handler - The callback function to run on event.
|
|
3559
3844
|
* @param {EventRegistryOptions} [options] - Optional event listener options.
|
|
3845
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
3560
3846
|
*/
|
|
3561
3847
|
static on(el, event, handler, options) {
|
|
3562
3848
|
if (typeof event !== 'string') throw new TypeError('The event name must be a string.');
|
|
@@ -3569,6 +3855,7 @@ class TinyHtml {
|
|
|
3569
3855
|
if (!Array.isArray(events[event])) events[event] = [];
|
|
3570
3856
|
events[event].push({ handler, options });
|
|
3571
3857
|
});
|
|
3858
|
+
return el;
|
|
3572
3859
|
}
|
|
3573
3860
|
|
|
3574
3861
|
/**
|
|
@@ -3577,6 +3864,7 @@ class TinyHtml {
|
|
|
3577
3864
|
* @param {string} event - The event type (e.g. 'click', 'keydown').
|
|
3578
3865
|
* @param {EventRegistryHandle} handler - The callback function to run on event.
|
|
3579
3866
|
* @param {EventRegistryOptions} [options] - Optional event listener options.
|
|
3867
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
3580
3868
|
*/
|
|
3581
3869
|
on(event, handler, options) {
|
|
3582
3870
|
return TinyHtml.on(this, event, handler, options);
|
|
@@ -3589,6 +3877,7 @@ class TinyHtml {
|
|
|
3589
3877
|
* @param {string} event - The event type (e.g. 'click', 'keydown').
|
|
3590
3878
|
* @param {EventRegistryHandle} handler - The callback function to run on event.
|
|
3591
3879
|
* @param {EventRegistryOptions} [options={}] - Optional event listener options.
|
|
3880
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
3592
3881
|
*/
|
|
3593
3882
|
static once(el, event, handler, options = {}) {
|
|
3594
3883
|
if (typeof event !== 'string') throw new TypeError('The event name must be a string.');
|
|
@@ -3606,6 +3895,7 @@ class TinyHtml {
|
|
|
3606
3895
|
typeof options === 'boolean' ? options : { ...options, once: true },
|
|
3607
3896
|
);
|
|
3608
3897
|
});
|
|
3898
|
+
return el;
|
|
3609
3899
|
}
|
|
3610
3900
|
|
|
3611
3901
|
/**
|
|
@@ -3614,6 +3904,7 @@ class TinyHtml {
|
|
|
3614
3904
|
* @param {string} event - The event type (e.g. 'click', 'keydown').
|
|
3615
3905
|
* @param {EventRegistryHandle} handler - The callback function to run on event.
|
|
3616
3906
|
* @param {EventRegistryOptions} [options={}] - Optional event listener options.
|
|
3907
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
3617
3908
|
*/
|
|
3618
3909
|
once(event, handler, options = {}) {
|
|
3619
3910
|
return TinyHtml.once(this, event, handler, options);
|
|
@@ -3626,6 +3917,7 @@ class TinyHtml {
|
|
|
3626
3917
|
* @param {string} event - The event type.
|
|
3627
3918
|
* @param {EventRegistryHandle} handler - The function originally bound to the event.
|
|
3628
3919
|
* @param {boolean|EventListenerOptions} [options] - Optional listener options.
|
|
3920
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
3629
3921
|
*/
|
|
3630
3922
|
static off(el, event, handler, options) {
|
|
3631
3923
|
if (typeof event !== 'string') throw new TypeError('The event name must be a string.');
|
|
@@ -3638,6 +3930,7 @@ class TinyHtml {
|
|
|
3638
3930
|
if (events[event].length === 0) delete events[event];
|
|
3639
3931
|
}
|
|
3640
3932
|
});
|
|
3933
|
+
return el;
|
|
3641
3934
|
}
|
|
3642
3935
|
|
|
3643
3936
|
/**
|
|
@@ -3646,6 +3939,7 @@ class TinyHtml {
|
|
|
3646
3939
|
* @param {string} event - The event type.
|
|
3647
3940
|
* @param {EventRegistryHandle} handler - The function originally bound to the event.
|
|
3648
3941
|
* @param {boolean|EventListenerOptions} [options] - Optional listener options.
|
|
3942
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
3649
3943
|
*/
|
|
3650
3944
|
off(event, handler, options) {
|
|
3651
3945
|
return TinyHtml.off(this, event, handler, options);
|
|
@@ -3656,6 +3950,7 @@ class TinyHtml {
|
|
|
3656
3950
|
*
|
|
3657
3951
|
* @param {TinyEventTarget|TinyEventTarget[]} el - The target element.
|
|
3658
3952
|
* @param {string} event - The event type to remove (e.g. 'click').
|
|
3953
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
3659
3954
|
*/
|
|
3660
3955
|
static offAll(el, event) {
|
|
3661
3956
|
if (typeof event !== 'string') throw new TypeError('The event name must be a string.');
|
|
@@ -3668,12 +3963,14 @@ class TinyHtml {
|
|
|
3668
3963
|
delete events[event];
|
|
3669
3964
|
}
|
|
3670
3965
|
});
|
|
3966
|
+
return el;
|
|
3671
3967
|
}
|
|
3672
3968
|
|
|
3673
3969
|
/**
|
|
3674
3970
|
* Removes all event listeners of a specific type from the element.
|
|
3675
3971
|
*
|
|
3676
3972
|
* @param {string} event - The event type to remove (e.g. 'click').
|
|
3973
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
3677
3974
|
*/
|
|
3678
3975
|
offAll(event) {
|
|
3679
3976
|
return TinyHtml.offAll(this, event);
|
|
@@ -3685,6 +3982,7 @@ class TinyHtml {
|
|
|
3685
3982
|
* @param {TinyEventTarget|TinyEventTarget[]} el - The target element.
|
|
3686
3983
|
* @param {((handler: EventListenerOrEventListenerObject, event: string) => boolean)|null} [filterFn=null] -
|
|
3687
3984
|
* Optional filter function to selectively remove specific handlers.
|
|
3985
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
3688
3986
|
*/
|
|
3689
3987
|
static offAllTypes(el, filterFn = null) {
|
|
3690
3988
|
if (filterFn !== null && typeof filterFn !== 'function')
|
|
@@ -3703,6 +4001,7 @@ class TinyHtml {
|
|
|
3703
4001
|
|
|
3704
4002
|
__eventRegistry.delete(elem);
|
|
3705
4003
|
});
|
|
4004
|
+
return el;
|
|
3706
4005
|
}
|
|
3707
4006
|
|
|
3708
4007
|
/**
|
|
@@ -3710,6 +4009,7 @@ class TinyHtml {
|
|
|
3710
4009
|
*
|
|
3711
4010
|
* @param {((handler: EventListenerOrEventListenerObject, event: string) => boolean)|null} [filterFn=null] -
|
|
3712
4011
|
* Optional filter function to selectively remove specific handlers.
|
|
4012
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
3713
4013
|
*/
|
|
3714
4014
|
offAllTypes(filterFn = null) {
|
|
3715
4015
|
return TinyHtml.offAllTypes(this, filterFn);
|
|
@@ -3721,6 +4021,7 @@ class TinyHtml {
|
|
|
3721
4021
|
* @param {TinyEventTarget|TinyEventTarget[]} el - Target element where the event should be triggered.
|
|
3722
4022
|
* @param {string} event - Name of the event to trigger.
|
|
3723
4023
|
* @param {Event|CustomEvent|CustomEventInit} [payload] - Optional event object or data to pass.
|
|
4024
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
3724
4025
|
*/
|
|
3725
4026
|
static trigger(el, event, payload = {}) {
|
|
3726
4027
|
if (typeof event !== 'string') throw new TypeError('The event name must be a string.');
|
|
@@ -3736,6 +4037,7 @@ class TinyHtml {
|
|
|
3736
4037
|
|
|
3737
4038
|
elem.dispatchEvent(evt);
|
|
3738
4039
|
});
|
|
4040
|
+
return el;
|
|
3739
4041
|
}
|
|
3740
4042
|
|
|
3741
4043
|
/**
|
|
@@ -3743,6 +4045,7 @@ class TinyHtml {
|
|
|
3743
4045
|
*
|
|
3744
4046
|
* @param {string} event - Name of the event to trigger.
|
|
3745
4047
|
* @param {Event|CustomEvent|CustomEventInit} [payload] - Optional event object or data to pass.
|
|
4048
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
3746
4049
|
*/
|
|
3747
4050
|
trigger(event, payload = {}) {
|
|
3748
4051
|
return TinyHtml.trigger(this, event, payload);
|
|
@@ -3785,6 +4088,7 @@ class TinyHtml {
|
|
|
3785
4088
|
* @param {TinyElement|TinyElement[]} el
|
|
3786
4089
|
* @param {string} name
|
|
3787
4090
|
* @param {string|null} [value=null]
|
|
4091
|
+
* @returns {TinyElement|TinyElement[]}
|
|
3788
4092
|
*/
|
|
3789
4093
|
static setAttr(el, name, value = null) {
|
|
3790
4094
|
if (typeof name !== 'string') throw new TypeError('The "name" must be a string.');
|
|
@@ -3794,12 +4098,14 @@ class TinyHtml {
|
|
|
3794
4098
|
if (value === null) elem.removeAttribute(name);
|
|
3795
4099
|
else elem.setAttribute(name, value);
|
|
3796
4100
|
});
|
|
4101
|
+
return el;
|
|
3797
4102
|
}
|
|
3798
4103
|
|
|
3799
4104
|
/**
|
|
3800
4105
|
* Set an attribute on an element.
|
|
3801
4106
|
* @param {string} name
|
|
3802
4107
|
* @param {string|null} [value=null]
|
|
4108
|
+
* @returns {TinyElement|TinyElement[]}
|
|
3803
4109
|
*/
|
|
3804
4110
|
setAttr(name, value) {
|
|
3805
4111
|
return TinyHtml.setAttr(this, name, value);
|
|
@@ -3809,15 +4115,18 @@ class TinyHtml {
|
|
|
3809
4115
|
* Remove attribute(s) from an element.
|
|
3810
4116
|
* @param {TinyElement|TinyElement[]} el
|
|
3811
4117
|
* @param {string} name Space-separated list of attributes.
|
|
4118
|
+
* @returns {TinyElement|TinyElement[]}
|
|
3812
4119
|
*/
|
|
3813
4120
|
static removeAttr(el, name) {
|
|
3814
4121
|
if (typeof name !== 'string') throw new TypeError('The "name" must be a string.');
|
|
3815
4122
|
TinyHtml._preElems(el, 'removeAttr').forEach((elem) => elem.removeAttribute(name));
|
|
4123
|
+
return el;
|
|
3816
4124
|
}
|
|
3817
4125
|
|
|
3818
4126
|
/**
|
|
3819
4127
|
* Remove attribute(s) from an element.
|
|
3820
4128
|
* @param {string} name Space-separated list of attributes.
|
|
4129
|
+
* @returns {TinyElement|TinyElement[]}
|
|
3821
4130
|
*/
|
|
3822
4131
|
removeAttr(name) {
|
|
3823
4132
|
return TinyHtml.removeAttr(this, name);
|
|
@@ -3872,6 +4181,7 @@ class TinyHtml {
|
|
|
3872
4181
|
* Set a property on an element.
|
|
3873
4182
|
* @param {TinyElement|TinyElement[]} el
|
|
3874
4183
|
* @param {string} name
|
|
4184
|
+
* @returns {TinyElement|TinyElement[]}
|
|
3875
4185
|
*/
|
|
3876
4186
|
static addProp(el, name) {
|
|
3877
4187
|
if (typeof name !== 'string') throw new TypeError('The "name" must be a string.');
|
|
@@ -3881,11 +4191,13 @@ class TinyHtml {
|
|
|
3881
4191
|
// @ts-ignore
|
|
3882
4192
|
elem[name] = true;
|
|
3883
4193
|
});
|
|
4194
|
+
return el;
|
|
3884
4195
|
}
|
|
3885
4196
|
|
|
3886
4197
|
/**
|
|
3887
4198
|
* Set a property on an element.
|
|
3888
4199
|
* @param {string} name
|
|
4200
|
+
* @returns {TinyElement|TinyElement[]}
|
|
3889
4201
|
*/
|
|
3890
4202
|
addProp(name) {
|
|
3891
4203
|
return TinyHtml.addProp(this, name);
|
|
@@ -3895,6 +4207,7 @@ class TinyHtml {
|
|
|
3895
4207
|
* Remove a property from an element.
|
|
3896
4208
|
* @param {TinyElement|TinyElement[]} el
|
|
3897
4209
|
* @param {string} name
|
|
4210
|
+
* @returns {TinyElement|TinyElement[]}
|
|
3898
4211
|
*/
|
|
3899
4212
|
static removeProp(el, name) {
|
|
3900
4213
|
if (typeof name !== 'string') throw new TypeError('The "name" must be a string.');
|
|
@@ -3904,11 +4217,13 @@ class TinyHtml {
|
|
|
3904
4217
|
// @ts-ignore
|
|
3905
4218
|
elem[name] = false;
|
|
3906
4219
|
});
|
|
4220
|
+
return el;
|
|
3907
4221
|
}
|
|
3908
4222
|
|
|
3909
4223
|
/**
|
|
3910
4224
|
* Remove a property from an element.
|
|
3911
4225
|
* @param {string} name
|
|
4226
|
+
* @returns {TinyElement|TinyElement[]}
|
|
3912
4227
|
*/
|
|
3913
4228
|
removeProp(name) {
|
|
3914
4229
|
return TinyHtml.removeProp(this, name);
|
|
@@ -3949,13 +4264,16 @@ class TinyHtml {
|
|
|
3949
4264
|
/**
|
|
3950
4265
|
* Removes an element from the DOM.
|
|
3951
4266
|
* @param {TinyElement|TinyElement[]} el - The DOM element or selector to remove.
|
|
4267
|
+
* @returns {TinyElement|TinyElement[]}
|
|
3952
4268
|
*/
|
|
3953
4269
|
static remove(el) {
|
|
3954
4270
|
TinyHtml._preElems(el, 'remove').forEach((elem) => elem.remove());
|
|
4271
|
+
return el;
|
|
3955
4272
|
}
|
|
3956
4273
|
|
|
3957
4274
|
/**
|
|
3958
4275
|
* Removes the element from the DOM.
|
|
4276
|
+
* @returns {TinyElement|TinyElement[]}
|
|
3959
4277
|
*/
|
|
3960
4278
|
remove() {
|
|
3961
4279
|
return TinyHtml.remove(this);
|
|
@@ -4299,6 +4617,14 @@ class TinyHtml {
|
|
|
4299
4617
|
*/
|
|
4300
4618
|
static isInViewport(el) {
|
|
4301
4619
|
const elem = TinyHtml._preElem(el, 'isInViewport');
|
|
4620
|
+
if (
|
|
4621
|
+
!elem.checkVisibility({
|
|
4622
|
+
contentVisibilityAuto: false,
|
|
4623
|
+
opacityProperty: false,
|
|
4624
|
+
visibilityProperty: false,
|
|
4625
|
+
})
|
|
4626
|
+
)
|
|
4627
|
+
return false;
|
|
4302
4628
|
const elementTop = TinyHtml.offset(elem).top;
|
|
4303
4629
|
const elementBottom = elementTop + TinyHtml.outerHeight(elem);
|
|
4304
4630
|
|
|
@@ -4325,6 +4651,14 @@ class TinyHtml {
|
|
|
4325
4651
|
*/
|
|
4326
4652
|
static isScrolledIntoView(el) {
|
|
4327
4653
|
const elem = TinyHtml._preElem(el, 'isScrolledIntoView');
|
|
4654
|
+
if (
|
|
4655
|
+
!elem.checkVisibility({
|
|
4656
|
+
contentVisibilityAuto: false,
|
|
4657
|
+
opacityProperty: false,
|
|
4658
|
+
visibilityProperty: false,
|
|
4659
|
+
})
|
|
4660
|
+
)
|
|
4661
|
+
return false;
|
|
4328
4662
|
const docViewTop = TinyHtml.scrollTop(window);
|
|
4329
4663
|
const docViewBottom = docViewTop + TinyHtml.height(window);
|
|
4330
4664
|
|
|
@@ -4342,6 +4676,111 @@ class TinyHtml {
|
|
|
4342
4676
|
isScrolledIntoView() {
|
|
4343
4677
|
return TinyHtml.isScrolledIntoView(this);
|
|
4344
4678
|
}
|
|
4679
|
+
|
|
4680
|
+
/**
|
|
4681
|
+
* Checks if the given element is at least partially visible within the boundaries of a container.
|
|
4682
|
+
*
|
|
4683
|
+
* @param {TinyElement} el - The DOM element to check.
|
|
4684
|
+
* @param {TinyElement} cont - The container element acting as the viewport.
|
|
4685
|
+
* @returns {boolean} True if the element is partially visible within the container, false otherwise.
|
|
4686
|
+
*/
|
|
4687
|
+
static isInContainer(el, cont) {
|
|
4688
|
+
const elem = TinyHtml._preElem(el, 'isInContainer');
|
|
4689
|
+
const container = TinyHtml._preElem(cont, 'isInContainer');
|
|
4690
|
+
|
|
4691
|
+
if (
|
|
4692
|
+
!elem.checkVisibility({
|
|
4693
|
+
contentVisibilityAuto: false,
|
|
4694
|
+
opacityProperty: false,
|
|
4695
|
+
visibilityProperty: false,
|
|
4696
|
+
})
|
|
4697
|
+
)
|
|
4698
|
+
return false;
|
|
4699
|
+
const elemRect = elem.getBoundingClientRect();
|
|
4700
|
+
const containerRect = container.getBoundingClientRect();
|
|
4701
|
+
|
|
4702
|
+
const verticallyVisible =
|
|
4703
|
+
elemRect.bottom > containerRect.top && elemRect.top < containerRect.bottom;
|
|
4704
|
+
|
|
4705
|
+
const horizontallyVisible =
|
|
4706
|
+
elemRect.right > containerRect.left && elemRect.left < containerRect.right;
|
|
4707
|
+
|
|
4708
|
+
return verticallyVisible && horizontallyVisible;
|
|
4709
|
+
}
|
|
4710
|
+
|
|
4711
|
+
/**
|
|
4712
|
+
* Checks if the given element is at least partially visible within the boundaries of a container.
|
|
4713
|
+
*
|
|
4714
|
+
* @param {TinyElement} cont - The container element acting as the viewport.
|
|
4715
|
+
* @returns {boolean} True if the element is partially visible within the container, false otherwise.
|
|
4716
|
+
*/
|
|
4717
|
+
isInContainer(cont) {
|
|
4718
|
+
return TinyHtml.isInContainer(this, cont);
|
|
4719
|
+
}
|
|
4720
|
+
|
|
4721
|
+
/**
|
|
4722
|
+
* Checks if the given element is fully visible within the boundaries of a container (top and bottom).
|
|
4723
|
+
*
|
|
4724
|
+
* @param {TinyElement} el - The DOM element to check.
|
|
4725
|
+
* @param {TinyElement} cont - The container element acting as the viewport.
|
|
4726
|
+
* @returns {boolean} True if the element is fully visible within the container, false otherwise.
|
|
4727
|
+
*/
|
|
4728
|
+
static isFullyInContainer(el, cont) {
|
|
4729
|
+
const elem = TinyHtml._preElem(el, 'isScrolledIntoView');
|
|
4730
|
+
const container = TinyHtml._preElem(cont, 'isInContainer');
|
|
4731
|
+
|
|
4732
|
+
if (
|
|
4733
|
+
!elem.checkVisibility({
|
|
4734
|
+
contentVisibilityAuto: false,
|
|
4735
|
+
opacityProperty: false,
|
|
4736
|
+
visibilityProperty: false,
|
|
4737
|
+
})
|
|
4738
|
+
)
|
|
4739
|
+
return false;
|
|
4740
|
+
const elemRect = elem.getBoundingClientRect();
|
|
4741
|
+
const containerRect = container.getBoundingClientRect();
|
|
4742
|
+
|
|
4743
|
+
const isFullyVisible =
|
|
4744
|
+
elemRect.top >= containerRect.top &&
|
|
4745
|
+
elemRect.bottom <= containerRect.bottom &&
|
|
4746
|
+
elemRect.left >= containerRect.left &&
|
|
4747
|
+
elemRect.right <= containerRect.right;
|
|
4748
|
+
|
|
4749
|
+
return isFullyVisible;
|
|
4750
|
+
}
|
|
4751
|
+
|
|
4752
|
+
/**
|
|
4753
|
+
* Checks if the given element is fully visible within the boundaries of a container (top and bottom).
|
|
4754
|
+
*
|
|
4755
|
+
* @param {TinyElement} cont - The container element acting as the viewport.
|
|
4756
|
+
* @returns {boolean} True if the element is fully visible within the container, false otherwise.
|
|
4757
|
+
*/
|
|
4758
|
+
isFullyInContainer(cont) {
|
|
4759
|
+
return TinyHtml.isFullyInContainer(this, cont);
|
|
4760
|
+
}
|
|
4761
|
+
|
|
4762
|
+
/**
|
|
4763
|
+
* Checks if an element has scrollable content.
|
|
4764
|
+
*
|
|
4765
|
+
* @param {TinyElement} el - The DOM element to check.
|
|
4766
|
+
* @returns {{ v: boolean, h: boolean }} - True if scroll is needed in that direction.
|
|
4767
|
+
*/
|
|
4768
|
+
static hasScroll(el) {
|
|
4769
|
+
const elem = TinyHtml._preElem(el, 'hasScroll');
|
|
4770
|
+
return {
|
|
4771
|
+
v: elem.scrollHeight > elem.clientHeight,
|
|
4772
|
+
h: elem.scrollWidth > elem.clientWidth,
|
|
4773
|
+
};
|
|
4774
|
+
}
|
|
4775
|
+
|
|
4776
|
+
/**
|
|
4777
|
+
* Checks if an element has scrollable content.
|
|
4778
|
+
*
|
|
4779
|
+
* @returns {{ v: boolean, h: boolean }} - True if scroll is needed in that direction.
|
|
4780
|
+
*/
|
|
4781
|
+
hasScroll() {
|
|
4782
|
+
return TinyHtml.hasScroll(this);
|
|
4783
|
+
}
|
|
4345
4784
|
}
|
|
4346
4785
|
|
|
4347
4786
|
module.exports = TinyHtml;
|