tiny-essentials 1.16.1 → 1.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/legacy/crypto/decrypt.cjs +1 -0
- package/dist/legacy/crypto/decrypt.d.mts +1 -0
- package/dist/legacy/crypto/decrypt.mjs +1 -0
- package/dist/legacy/crypto/encrypt.cjs +1 -0
- package/dist/legacy/crypto/encrypt.d.mts +1 -0
- package/dist/legacy/crypto/encrypt.mjs +1 -0
- package/dist/legacy/get/decimalColor.cjs +1 -0
- package/dist/legacy/get/decimalColor.d.mts +1 -0
- package/dist/legacy/get/decimalColor.mjs +1 -0
- package/dist/legacy/get/pagination.cjs +1 -0
- package/dist/legacy/get/pagination.d.mts +1 -0
- package/dist/legacy/get/pagination.mjs +1 -0
- package/dist/legacy/get/queryUrlByName.cjs +1 -0
- package/dist/legacy/get/queryUrlByName.d.mts +1 -0
- package/dist/legacy/get/queryUrlByName.mjs +1 -0
- package/dist/legacy/get/queryUrlJSON.cjs +1 -0
- package/dist/legacy/get/queryUrlJSON.d.mts +1 -0
- package/dist/legacy/get/queryUrlJSON.mjs +1 -0
- package/dist/legacy/get/super_string_filter.cjs +1 -0
- package/dist/legacy/get/super_string_filter.d.mts +1 -0
- package/dist/legacy/get/super_string_filter.mjs +1 -0
- package/dist/legacy/get/versionCheck.cjs +1 -0
- package/dist/legacy/get/versionCheck.d.mts +1 -0
- package/dist/legacy/get/versionCheck.mjs +1 -0
- package/dist/legacy/http/HTTP-1.0.cjs +2 -0
- package/dist/legacy/http/HTTP-1.0.mjs +2 -0
- package/dist/legacy/http/auth.cjs +1 -0
- package/dist/legacy/http/auth.d.mts +1 -0
- package/dist/legacy/http/auth.mjs +1 -0
- package/dist/legacy/http/check_domain.cjs +11 -0
- package/dist/legacy/http/check_domain.d.mts +3 -0
- package/dist/legacy/http/check_domain.mjs +11 -0
- package/dist/legacy/http/csrfTokenAnalyze.cjs +1 -0
- package/dist/legacy/http/csrfTokenAnalyze.d.mts +1 -0
- package/dist/legacy/http/csrfTokenAnalyze.mjs +1 -0
- package/dist/legacy/http/domainValidator.cjs +1 -0
- package/dist/legacy/http/domainValidator.d.mts +1 -0
- package/dist/legacy/http/domainValidator.mjs +1 -0
- package/dist/legacy/http/errorsCallback.cjs +1 -0
- package/dist/legacy/http/errorsCallback.d.mts +1 -0
- package/dist/legacy/http/errorsCallback.mjs +1 -0
- package/dist/legacy/http/fetch/json.cjs +1 -0
- package/dist/legacy/http/fetch/json.d.mts +1 -0
- package/dist/legacy/http/fetch/json.mjs +1 -0
- package/dist/legacy/http/fetch/text.cjs +1 -0
- package/dist/legacy/http/fetch/text.d.mts +1 -0
- package/dist/legacy/http/fetch/text.mjs +1 -0
- package/dist/legacy/http/fileCache.cjs +1 -0
- package/dist/legacy/http/fileCache.d.mts +1 -0
- package/dist/legacy/http/fileCache.mjs +1 -0
- package/dist/legacy/http/getDomainURL.cjs +1 -0
- package/dist/legacy/http/getDomainURL.d.mts +1 -0
- package/dist/legacy/http/getDomainURL.mjs +1 -0
- package/dist/legacy/http/userIP.cjs +1 -0
- package/dist/legacy/http/userIP.d.mts +1 -0
- package/dist/legacy/http/userIP.mjs +1 -0
- package/dist/legacy/libs/capitalize.cjs +1 -0
- package/dist/legacy/libs/capitalize.d.mts +1 -0
- package/dist/legacy/libs/capitalize.mjs +1 -0
- package/dist/legacy/libs/convertBytes.cjs +2 -0
- package/dist/legacy/libs/convertBytes.mjs +2 -0
- package/dist/legacy/libs/custom_module_loader.cjs +2 -0
- package/dist/legacy/libs/custom_module_loader.mjs +2 -0
- package/dist/legacy/libs/dice.cjs +2 -0
- package/dist/legacy/libs/dice.mjs +2 -0
- package/dist/legacy/libs/markdown.cjs +1 -0
- package/dist/legacy/libs/markdown.mjs +1 -0
- package/dist/legacy/libs/percentage.cjs +1 -0
- package/dist/legacy/libs/percentage.mjs +1 -0
- package/dist/legacy/libs/regex/getLetter.cjs +2 -0
- package/dist/legacy/libs/regex/getLetter.d.mts +2 -0
- package/dist/legacy/libs/regex/getLetter.mjs +2 -0
- package/dist/legacy/libs/rule3.cjs +1 -0
- package/dist/legacy/libs/rule3.mjs +1 -0
- package/dist/legacy/momentjs/getAge.cjs +1 -0
- package/dist/legacy/momentjs/getAge.d.mts +1 -0
- package/dist/legacy/momentjs/getAge.mjs +1 -0
- package/dist/legacy/momentjs/timeDuration.cjs +1 -0
- package/dist/legacy/momentjs/timeDuration.d.mts +1 -0
- package/dist/legacy/momentjs/timeDuration.mjs +1 -0
- package/dist/legacy/socket.io/antiFlood/install.cjs +1 -0
- package/dist/legacy/socket.io/antiFlood/install.d.mts +1 -0
- package/dist/legacy/socket.io/antiFlood/install.mjs +1 -0
- package/dist/legacy/socket.io/antiFlood/verify.cjs +1 -0
- package/dist/legacy/socket.io/antiFlood/verify.d.mts +1 -0
- package/dist/legacy/socket.io/antiFlood/verify.mjs +1 -0
- package/dist/legacy/socket.io/cookie-session.cjs +1 -0
- package/dist/legacy/socket.io/cookie-session.d.mts +1 -0
- package/dist/legacy/socket.io/cookie-session.mjs +1 -0
- package/dist/legacy/socket.io/discord.cjs +1 -0
- package/dist/legacy/socket.io/discord.d.mts +1 -0
- package/dist/legacy/socket.io/discord.mjs +1 -0
- package/dist/v1/TinyAfterScrollWatcher.js +49 -26
- package/dist/v1/TinyAfterScrollWatcher.min.js +1 -1
- package/dist/v1/TinyBasicsEs.js +559 -71
- package/dist/v1/TinyBasicsEs.min.js +1 -1
- package/dist/v1/TinyDragger.js +486 -47
- package/dist/v1/TinyDragger.min.js +1 -1
- package/dist/v1/TinyEssentials.js +2545 -98
- package/dist/v1/TinyEssentials.min.js +1 -1
- package/dist/v1/TinyHtml.js +486 -47
- package/dist/v1/TinyHtml.min.js +1 -1
- package/dist/v1/TinySmartScroller.js +6230 -0
- package/dist/v1/TinySmartScroller.min.js +1 -0
- package/dist/v1/TinyUploadClicker.js +1538 -72
- package/dist/v1/TinyUploadClicker.min.js +1 -1
- package/dist/v1/UltraRandomMsgGen.js +995 -0
- package/dist/v1/UltraRandomMsgGen.min.js +1 -0
- package/dist/v1/basics/html.cjs +74 -24
- package/dist/v1/basics/html.d.mts +38 -15
- package/dist/v1/basics/html.mjs +63 -20
- package/dist/v1/build/TinySmartScroller.cjs +7 -0
- package/dist/v1/build/TinySmartScroller.d.mts +3 -0
- package/dist/v1/build/TinySmartScroller.mjs +2 -0
- package/dist/v1/build/UltraRandomMsgGen.cjs +7 -0
- package/dist/v1/build/UltraRandomMsgGen.d.mts +3 -0
- package/dist/v1/build/UltraRandomMsgGen.mjs +2 -0
- package/dist/v1/index.cjs +4 -0
- package/dist/v1/index.d.mts +3 -1
- package/dist/v1/index.mjs +3 -1
- package/dist/v1/libs/TinyAfterScrollWatcher.cjs +49 -26
- package/dist/v1/libs/TinyAfterScrollWatcher.d.mts +17 -14
- package/dist/v1/libs/TinyAfterScrollWatcher.mjs +50 -24
- package/dist/v1/libs/TinyHtml.cjs +486 -47
- package/dist/v1/libs/TinyHtml.d.mts +352 -139
- package/dist/v1/libs/TinyHtml.mjs +431 -47
- package/dist/v1/libs/TinySmartScroller.cjs +976 -0
- package/dist/v1/libs/TinySmartScroller.d.mts +458 -0
- package/dist/v1/libs/TinySmartScroller.mjs +856 -0
- package/dist/v1/libs/UltraRandomMsgGen.cjs +956 -0
- package/dist/v1/libs/UltraRandomMsgGen.d.mts +390 -0
- package/dist/v1/libs/UltraRandomMsgGen.mjs +825 -0
- package/docs/v1/README.md +2 -0
- package/docs/v1/basics/html.md +17 -2
- package/docs/v1/libs/TinyAfterScrollWatcher.md +54 -4
- package/docs/v1/libs/TinyHtml.md +197 -8
- package/docs/v1/libs/TinySmartScroller.md +523 -0
- package/docs/v1/libs/UltraRandomMsgGen.md +289 -0
- package/package.json +1 -1
|
@@ -48,6 +48,19 @@ const { areElsColliding, areElsPerfColliding, areElsCollTop, areElsCollBottom, a
|
|
|
48
48
|
*
|
|
49
49
|
* @typedef {Element|Window} ElementAndWindow
|
|
50
50
|
*/
|
|
51
|
+
/**
|
|
52
|
+
* Represents a raw DOM element/window/document or an instance of TinyHtml.
|
|
53
|
+
* This type is used to abstract interactions with both plain elements
|
|
54
|
+
* and wrapped elements via the TinyHtml class.
|
|
55
|
+
*
|
|
56
|
+
* @typedef {ElementAndWinAndDoc|TinyHtml} TinyElementAndWinAndDoc
|
|
57
|
+
*/
|
|
58
|
+
/**
|
|
59
|
+
* Represents a value that can be either a DOM Element, or the global Window object, or the document object.
|
|
60
|
+
* Useful for functions that operate generically on scrollable or measurable targets.
|
|
61
|
+
*
|
|
62
|
+
* @typedef {Element|Window|Document} ElementAndWinAndDoc
|
|
63
|
+
*/
|
|
51
64
|
/**
|
|
52
65
|
* A parameter type used for filtering or matching elements.
|
|
53
66
|
* It can be:
|
|
@@ -63,7 +76,7 @@ const { areElsColliding, areElsPerfColliding, areElsCollTop, areElsCollBottom, a
|
|
|
63
76
|
* Elements accepted as constructor values for TinyHtml.
|
|
64
77
|
* These include common DOM elements and root containers.
|
|
65
78
|
*
|
|
66
|
-
* @typedef {Window|Element|Document} ConstructorElValues
|
|
79
|
+
* @typedef {Window|Element|Document|Text} ConstructorElValues
|
|
67
80
|
*/
|
|
68
81
|
/**
|
|
69
82
|
* The handler function used in event listeners.
|
|
@@ -167,52 +180,130 @@ const __elemCollision = {
|
|
|
167
180
|
class TinyHtml {
|
|
168
181
|
/** @typedef {import('../basics/collision.mjs').ObjRect} ObjRect */
|
|
169
182
|
static Utils = { ...TinyCollision };
|
|
183
|
+
/**
|
|
184
|
+
* Creates a new DOM element with the specified tag name and options, then wraps it in a TinyHtml instance.
|
|
185
|
+
*
|
|
186
|
+
* @param {string} tagName - The tag name of the element to create (e.g., 'div', 'span').
|
|
187
|
+
* @param {ElementCreationOptions} ops - Optional settings for creating the element.
|
|
188
|
+
* @returns {TinyHtml} A TinyHtml instance wrapping the newly created DOM element.
|
|
189
|
+
* @throws {TypeError} If tagName is not a string or ops is not an object.
|
|
190
|
+
*/
|
|
191
|
+
static createElement(tagName, ops) {
|
|
192
|
+
if (typeof tagName !== 'string')
|
|
193
|
+
throw new TypeError(`[TinyHtml] createElement(): The tagName must be a string.`);
|
|
194
|
+
if (typeof ops !== 'undefined' && typeof ops !== 'object')
|
|
195
|
+
throw new TypeError(`[TinyHtml] createElement(): The ops must be a object.`);
|
|
196
|
+
return new TinyHtml(document.createElement(tagName, ops));
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Creates a new TinyHtml instance that wraps a DOM TextNode.
|
|
200
|
+
*
|
|
201
|
+
* This method is useful when you want to insert raw text content into the DOM
|
|
202
|
+
* without it being interpreted as HTML. The returned instance behaves like any
|
|
203
|
+
* other TinyHtml element and can be appended or manipulated as needed.
|
|
204
|
+
*
|
|
205
|
+
* @param {string} value - The plain text content to be wrapped in a TextNode.
|
|
206
|
+
* @returns {TinyHtml} A TinyHtml instance wrapping the newly created DOM TextNode.
|
|
207
|
+
* @throws {TypeError} If the provided value is not a string.
|
|
208
|
+
*/
|
|
209
|
+
static createTextNode(value) {
|
|
210
|
+
if (typeof value !== 'string')
|
|
211
|
+
throw new TypeError(`[TinyHtml] createTextNode(): The value must be a string.`);
|
|
212
|
+
return new TinyHtml(document.createTextNode(value));
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Creates an HTMLElement or TextNode from an HTML string.
|
|
216
|
+
* Supports both elements and plain text.
|
|
217
|
+
*
|
|
218
|
+
* @param {string} htmlString - The HTML string to convert.
|
|
219
|
+
* @returns {TinyHtml} - A single HTMLElement or TextNode.
|
|
220
|
+
*/
|
|
221
|
+
static createElementFromHTML(htmlString) {
|
|
222
|
+
const template = document.createElement('template');
|
|
223
|
+
htmlString = htmlString.trim();
|
|
224
|
+
// If it's only text (e.g., no "<" tag), return a TextNode
|
|
225
|
+
if (!htmlString.startsWith('<')) {
|
|
226
|
+
return TinyHtml.createTextNode(htmlString);
|
|
227
|
+
}
|
|
228
|
+
template.innerHTML = htmlString;
|
|
229
|
+
if (!(template.content.firstChild instanceof Element))
|
|
230
|
+
throw new Error('');
|
|
231
|
+
return new TinyHtml(template.content.firstChild);
|
|
232
|
+
}
|
|
170
233
|
/**
|
|
171
234
|
* Queries the document for the first element matching the CSS selector and wraps it in a TinyHtml instance.
|
|
172
235
|
*
|
|
173
236
|
* @param {string} selector - A valid CSS selector string.
|
|
174
|
-
* @
|
|
175
|
-
* @
|
|
237
|
+
* @param {Document|Element} elem - Target element.
|
|
238
|
+
* @returns {TinyHtml|null} A TinyHtml instance wrapping the matched element.
|
|
176
239
|
*/
|
|
177
|
-
static query(selector) {
|
|
178
|
-
const newEl =
|
|
240
|
+
static query(selector, elem = document) {
|
|
241
|
+
const newEl = elem.querySelector(selector);
|
|
179
242
|
if (!newEl)
|
|
180
|
-
|
|
243
|
+
return null;
|
|
181
244
|
return new TinyHtml(newEl);
|
|
182
245
|
}
|
|
246
|
+
/**
|
|
247
|
+
* Queries the element for the first element matching the CSS selector and wraps it in a TinyHtml instance.
|
|
248
|
+
*
|
|
249
|
+
* @param {string} selector - A valid CSS selector string.
|
|
250
|
+
* @returns {TinyHtml|null} A TinyHtml instance wrapping the matched element.
|
|
251
|
+
*/
|
|
252
|
+
querySelector(selector) {
|
|
253
|
+
return TinyHtml.query(selector, TinyHtml._preElem(this, 'query'));
|
|
254
|
+
}
|
|
183
255
|
/**
|
|
184
256
|
* Queries the document for all elements matching the CSS selector and wraps them in TinyHtml instances.
|
|
185
257
|
*
|
|
186
258
|
* @param {string} selector - A valid CSS selector string.
|
|
259
|
+
* @param {Document|Element} elem - Target element.
|
|
187
260
|
* @returns {TinyHtml[]} An array of TinyHtml instances wrapping the matched elements.
|
|
188
261
|
*/
|
|
189
|
-
static queryAll(selector) {
|
|
190
|
-
const newEls =
|
|
262
|
+
static queryAll(selector, elem = document) {
|
|
263
|
+
const newEls = elem.querySelectorAll(selector);
|
|
191
264
|
return TinyHtml.toTinyElm([...newEls]);
|
|
192
265
|
}
|
|
266
|
+
/**
|
|
267
|
+
* Queries the element for all elements matching the CSS selector and wraps them in TinyHtml instances.
|
|
268
|
+
*
|
|
269
|
+
* @param {string} selector - A valid CSS selector string.
|
|
270
|
+
* @returns {TinyHtml[]} An array of TinyHtml instances wrapping the matched elements.
|
|
271
|
+
*/
|
|
272
|
+
querySelectorAll(selector) {
|
|
273
|
+
return TinyHtml.queryAll(selector, TinyHtml._preElem(this, 'queryAll'));
|
|
274
|
+
}
|
|
193
275
|
/**
|
|
194
276
|
* Retrieves an element by its ID and wraps it in a TinyHtml instance.
|
|
195
277
|
*
|
|
196
278
|
* @param {string} selector - The ID of the element to retrieve.
|
|
197
|
-
* @returns {TinyHtml} A TinyHtml instance wrapping the found element.
|
|
198
|
-
* @throws {Error} If no element is found with the specified ID.
|
|
279
|
+
* @returns {TinyHtml|null} A TinyHtml instance wrapping the found element.
|
|
199
280
|
*/
|
|
200
281
|
static getById(selector) {
|
|
201
282
|
const newEl = document.getElementById(selector);
|
|
202
283
|
if (!newEl)
|
|
203
|
-
|
|
284
|
+
return null;
|
|
204
285
|
return new TinyHtml(newEl);
|
|
205
286
|
}
|
|
206
287
|
/**
|
|
207
288
|
* Retrieves all elements with the specified class name and wraps them in TinyHtml instances.
|
|
208
289
|
*
|
|
209
290
|
* @param {string} selector - The class name to search for.
|
|
291
|
+
* @param {Document|Element} elem - Target element.
|
|
210
292
|
* @returns {TinyHtml[]} An array of TinyHtml instances wrapping the found elements.
|
|
211
293
|
*/
|
|
212
|
-
static getByClassName(selector) {
|
|
213
|
-
const newEls =
|
|
294
|
+
static getByClassName(selector, elem = document) {
|
|
295
|
+
const newEls = elem.getElementsByClassName(selector);
|
|
214
296
|
return TinyHtml.toTinyElm([...newEls]);
|
|
215
297
|
}
|
|
298
|
+
/**
|
|
299
|
+
* Retrieves all elements with the specified class name and wraps them in TinyHtml instances.
|
|
300
|
+
*
|
|
301
|
+
* @param {string} selector - The class name to search for.
|
|
302
|
+
* @returns {TinyHtml[]} An array of TinyHtml instances wrapping the found elements.
|
|
303
|
+
*/
|
|
304
|
+
getElementsByClassName(selector) {
|
|
305
|
+
return TinyHtml.getByClassName(selector, TinyHtml._preElem(this, 'getByClassName'));
|
|
306
|
+
}
|
|
216
307
|
/**
|
|
217
308
|
* Retrieves all elements with the specified name attribute and wraps them in TinyHtml instances.
|
|
218
309
|
*
|
|
@@ -229,12 +320,24 @@ class TinyHtml {
|
|
|
229
320
|
*
|
|
230
321
|
* @param {string} localName - The local name (tag) of the elements to search for.
|
|
231
322
|
* @param {string|null} [namespaceURI='http://www.w3.org/1999/xhtml'] - The namespace URI to search within.
|
|
323
|
+
* @param {Document|Element} elem - Target element.
|
|
232
324
|
* @returns {TinyHtml[]} An array of TinyHtml instances wrapping the found elements.
|
|
233
325
|
*/
|
|
234
|
-
static getByTagNameNS(localName, namespaceURI = 'http://www.w3.org/1999/xhtml') {
|
|
235
|
-
const newEls =
|
|
326
|
+
static getByTagNameNS(localName, namespaceURI = 'http://www.w3.org/1999/xhtml', elem = document) {
|
|
327
|
+
const newEls = elem.getElementsByTagNameNS(namespaceURI, localName);
|
|
236
328
|
return TinyHtml.toTinyElm([...newEls]);
|
|
237
329
|
}
|
|
330
|
+
/**
|
|
331
|
+
* Retrieves all elements with the specified local tag name within the given namespace URI,
|
|
332
|
+
* and wraps them in TinyHtml instances.
|
|
333
|
+
*
|
|
334
|
+
* @param {string} localName - The local name (tag) of the elements to search for.
|
|
335
|
+
* @param {string|null} [namespaceURI='http://www.w3.org/1999/xhtml'] - The namespace URI to search within.
|
|
336
|
+
* @returns {TinyHtml[]} An array of TinyHtml instances wrapping the found elements.
|
|
337
|
+
*/
|
|
338
|
+
getElementsByTagNameNS(localName, namespaceURI = 'http://www.w3.org/1999/xhtml') {
|
|
339
|
+
return TinyHtml.getByTagNameNS(localName, namespaceURI, TinyHtml._preElem(this, 'getByTagNameNS'));
|
|
340
|
+
}
|
|
238
341
|
//////////////////////////////////////////////////////////////////
|
|
239
342
|
/**
|
|
240
343
|
* Returns the current target held by this instance.
|
|
@@ -477,6 +580,34 @@ class TinyHtml {
|
|
|
477
580
|
static _preElemAndWindow(elems, where) {
|
|
478
581
|
return TinyHtml._preElemTemplate(elems, where, [Element, Window], ['Element', 'Window']);
|
|
479
582
|
}
|
|
583
|
+
/**
|
|
584
|
+
* Ensures the input is returned as an array.
|
|
585
|
+
* Useful to normalize operations across multiple or single element/window/document elements.
|
|
586
|
+
*
|
|
587
|
+
* @param {TinyElementAndWinAndDoc|TinyElementAndWinAndDoc[]} elems - A single element/window element or array of html elements.
|
|
588
|
+
* @param {string} where - The method or context name where validation is being called.
|
|
589
|
+
* @returns {ElementAndWindow[]} - Always returns an array of element/window elements.
|
|
590
|
+
* @readonly
|
|
591
|
+
*/
|
|
592
|
+
static _preElemsAndWinAndDoc(elems, where) {
|
|
593
|
+
const result = TinyHtml._preElemsTemplate(elems, where, [Element, Window, Document], ['Element', 'Window', 'Document']);
|
|
594
|
+
return result.map((elem) => (!(elem instanceof Document) ? elem : elem.documentElement));
|
|
595
|
+
}
|
|
596
|
+
/**
|
|
597
|
+
* Ensures the input is returned as an single element/window/document element.
|
|
598
|
+
* Useful to normalize operations across multiple or single element/window/document elements.
|
|
599
|
+
*
|
|
600
|
+
* @param {TinyElementAndWinAndDoc|TinyElementAndWinAndDoc[]} elems - A single element/window element or array of html elements.
|
|
601
|
+
* @param {string} where - The method or context name where validation is being called.
|
|
602
|
+
* @returns {ElementAndWindow} - Always returns an single element/window element.
|
|
603
|
+
* @readonly
|
|
604
|
+
*/
|
|
605
|
+
static _preElemAndWinAndDoc(elems, where) {
|
|
606
|
+
const result = TinyHtml._preElemTemplate(elems, where, [Element, Window, Document], ['Element', 'Window', 'Document']);
|
|
607
|
+
if (result instanceof Document)
|
|
608
|
+
return result.documentElement;
|
|
609
|
+
return result;
|
|
610
|
+
}
|
|
480
611
|
/**
|
|
481
612
|
* Normalizes and converts one or more DOM elements (or TinyHtml instances)
|
|
482
613
|
* into an array of `TinyHtml` instances.
|
|
@@ -779,13 +910,14 @@ class TinyHtml {
|
|
|
779
910
|
* @param {string} key - The key under which the data will be stored.
|
|
780
911
|
* @param {any} value - The value to store.
|
|
781
912
|
* @param {boolean} [isPrivate=false] - Whether to store the data in the private store.
|
|
782
|
-
* @returns {
|
|
913
|
+
* @returns {TinyElement}
|
|
783
914
|
*/
|
|
784
915
|
static setData(el, key, value, isPrivate = false) {
|
|
785
916
|
const data = TinyHtml._dataSelector[!isPrivate ? 'public' : 'private']('setData', el);
|
|
786
917
|
if (typeof key !== 'string')
|
|
787
918
|
throw new TypeError('The key must be a string.');
|
|
788
919
|
data[key] = value;
|
|
920
|
+
return el;
|
|
789
921
|
}
|
|
790
922
|
/**
|
|
791
923
|
* Stores a value associated with a specific key for a DOM element.
|
|
@@ -793,7 +925,7 @@ class TinyHtml {
|
|
|
793
925
|
* @param {string} key - The key under which the data will be stored.
|
|
794
926
|
* @param {any} value - The value to store.
|
|
795
927
|
* @param {boolean} [isPrivate=false] - Whether to store the data in the private store.
|
|
796
|
-
* @returns {
|
|
928
|
+
* @returns {TinyElement}
|
|
797
929
|
*/
|
|
798
930
|
setData(key, value, isPrivate = false) {
|
|
799
931
|
return TinyHtml.setData(this, key, value, isPrivate);
|
|
@@ -1111,17 +1243,20 @@ class TinyHtml {
|
|
|
1111
1243
|
/**
|
|
1112
1244
|
* Appends child elements or strings to the end of the target element(s).
|
|
1113
1245
|
*
|
|
1114
|
-
* @param {TinyElement
|
|
1246
|
+
* @param {TinyElement} el - The target element(s) to receive children.
|
|
1115
1247
|
* @param {...(TinyNode | TinyNode[] | string)} children - The child elements or text to append.
|
|
1248
|
+
* @returns {TinyElement}
|
|
1116
1249
|
*/
|
|
1117
1250
|
static append(el, ...children) {
|
|
1118
1251
|
const elem = TinyHtml._preElem(el, 'append');
|
|
1119
1252
|
elem.append(...TinyHtml._appendChecker('append', ...children));
|
|
1253
|
+
return el;
|
|
1120
1254
|
}
|
|
1121
1255
|
/**
|
|
1122
1256
|
* Appends child elements or strings to the end of the target element(s).
|
|
1123
1257
|
*
|
|
1124
1258
|
* @param {...(TinyNode | TinyNode[] | string)} children - The child elements or text to append.
|
|
1259
|
+
* @returns {TinyElement}
|
|
1125
1260
|
*/
|
|
1126
1261
|
append(...children) {
|
|
1127
1262
|
return TinyHtml.append(this, ...children);
|
|
@@ -1129,17 +1264,20 @@ class TinyHtml {
|
|
|
1129
1264
|
/**
|
|
1130
1265
|
* Prepends child elements or strings to the beginning of the target element(s).
|
|
1131
1266
|
*
|
|
1132
|
-
* @param {TinyElement
|
|
1267
|
+
* @param {TinyElement} el - The target element(s) to receive children.
|
|
1133
1268
|
* @param {...(TinyNode | TinyNode[] | string)} children - The child elements or text to prepend.
|
|
1269
|
+
* @returns {TinyElement}
|
|
1134
1270
|
*/
|
|
1135
1271
|
static prepend(el, ...children) {
|
|
1136
1272
|
const elem = TinyHtml._preElem(el, 'prepend');
|
|
1137
1273
|
elem.prepend(...TinyHtml._appendChecker('prepend', ...children));
|
|
1274
|
+
return el;
|
|
1138
1275
|
}
|
|
1139
1276
|
/**
|
|
1140
1277
|
* Prepends child elements or strings to the beginning of the target element(s).
|
|
1141
1278
|
*
|
|
1142
1279
|
* @param {...(TinyNode | TinyNode[] | string)} children - The child elements or text to prepend.
|
|
1280
|
+
* @returns {TinyElement}
|
|
1143
1281
|
*/
|
|
1144
1282
|
prepend(...children) {
|
|
1145
1283
|
return TinyHtml.prepend(this, ...children);
|
|
@@ -1147,17 +1285,20 @@ class TinyHtml {
|
|
|
1147
1285
|
/**
|
|
1148
1286
|
* Inserts elements or strings immediately before the target element(s) in the DOM.
|
|
1149
1287
|
*
|
|
1150
|
-
* @param {TinyElement
|
|
1288
|
+
* @param {TinyElement} el - The target element(s) before which new content is inserted.
|
|
1151
1289
|
* @param {...(TinyNode | TinyNode[] | string)} children - Elements or text to insert before the target.
|
|
1290
|
+
* @returns {TinyElement}
|
|
1152
1291
|
*/
|
|
1153
1292
|
static before(el, ...children) {
|
|
1154
1293
|
const elem = TinyHtml._preElem(el, 'before');
|
|
1155
1294
|
elem.before(...TinyHtml._appendChecker('before', ...children));
|
|
1295
|
+
return el;
|
|
1156
1296
|
}
|
|
1157
1297
|
/**
|
|
1158
1298
|
* Inserts elements or strings immediately before the target element(s) in the DOM.
|
|
1159
1299
|
*
|
|
1160
1300
|
* @param {...(TinyNode | TinyNode[] | string)} children - Elements or text to insert before the target.
|
|
1301
|
+
* @returns {TinyElement}
|
|
1161
1302
|
*/
|
|
1162
1303
|
before(...children) {
|
|
1163
1304
|
return TinyHtml.before(this, ...children);
|
|
@@ -1165,17 +1306,20 @@ class TinyHtml {
|
|
|
1165
1306
|
/**
|
|
1166
1307
|
* Inserts elements or strings immediately after the target element(s) in the DOM.
|
|
1167
1308
|
*
|
|
1168
|
-
* @param {TinyElement
|
|
1309
|
+
* @param {TinyElement} el - The target element(s) after which new content is inserted.
|
|
1169
1310
|
* @param {...(TinyNode | TinyNode[] | string)} children - Elements or text to insert after the target.
|
|
1311
|
+
* @returns {TinyElement}
|
|
1170
1312
|
*/
|
|
1171
1313
|
static after(el, ...children) {
|
|
1172
1314
|
const elem = TinyHtml._preElem(el, 'after');
|
|
1173
1315
|
elem.after(...TinyHtml._appendChecker('after', ...children));
|
|
1316
|
+
return el;
|
|
1174
1317
|
}
|
|
1175
1318
|
/**
|
|
1176
1319
|
* Inserts elements or strings immediately after the target element(s) in the DOM.
|
|
1177
1320
|
*
|
|
1178
1321
|
* @param {...(TinyNode | TinyNode[] | string)} children - Elements or text to insert after the target.
|
|
1322
|
+
* @returns {TinyElement}
|
|
1179
1323
|
*/
|
|
1180
1324
|
after(...children) {
|
|
1181
1325
|
return TinyHtml.after(this, ...children);
|
|
@@ -1183,17 +1327,20 @@ class TinyHtml {
|
|
|
1183
1327
|
/**
|
|
1184
1328
|
* Replaces the target element(s) in the DOM with new elements or text.
|
|
1185
1329
|
*
|
|
1186
|
-
* @param {TinyElement
|
|
1330
|
+
* @param {TinyElement} el - The element(s) to be replaced.
|
|
1187
1331
|
* @param {...(TinyNode | TinyNode[] | string)} newNodes - New elements or text to replace the target.
|
|
1332
|
+
* @returns {TinyElement}
|
|
1188
1333
|
*/
|
|
1189
1334
|
static replaceWith(el, ...newNodes) {
|
|
1190
1335
|
const elem = TinyHtml._preElem(el, 'replaceWith');
|
|
1191
1336
|
elem.replaceWith(...TinyHtml._appendChecker('replaceWith', ...newNodes));
|
|
1337
|
+
return el;
|
|
1192
1338
|
}
|
|
1193
1339
|
/**
|
|
1194
1340
|
* Replaces the target element(s) in the DOM with new elements or text.
|
|
1195
1341
|
*
|
|
1196
1342
|
* @param {...(TinyNode | TinyNode[] | string)} newNodes - New elements or text to replace the target.
|
|
1343
|
+
* @returns {TinyElement}
|
|
1197
1344
|
*/
|
|
1198
1345
|
replaceWith(...newNodes) {
|
|
1199
1346
|
return TinyHtml.replaceWith(this, ...newNodes);
|
|
@@ -1203,6 +1350,7 @@ class TinyHtml {
|
|
|
1203
1350
|
*
|
|
1204
1351
|
* @param {TinyNode | TinyNode[]} el - The element(s) to append.
|
|
1205
1352
|
* @param {TinyNode | TinyNode[]} targets - Target element(s) where content will be appended.
|
|
1353
|
+
* @returns {TinyNode|TinyNode[]}
|
|
1206
1354
|
*/
|
|
1207
1355
|
static appendTo(el, targets) {
|
|
1208
1356
|
const elems = TinyHtml._preNodeElems(el, 'appendTo');
|
|
@@ -1210,11 +1358,13 @@ class TinyHtml {
|
|
|
1210
1358
|
tars.forEach((target, i) => {
|
|
1211
1359
|
elems.forEach((elem) => target.appendChild(i === tars.length - 1 ? elem : elem.cloneNode(true)));
|
|
1212
1360
|
});
|
|
1361
|
+
return el;
|
|
1213
1362
|
}
|
|
1214
1363
|
/**
|
|
1215
1364
|
* Appends the given element(s) to each target element in sequence.
|
|
1216
1365
|
*
|
|
1217
1366
|
* @param {TinyNode | TinyNode[]} targets - Target element(s) where content will be appended.
|
|
1367
|
+
* @returns {TinyNode|TinyNode[]}
|
|
1218
1368
|
*/
|
|
1219
1369
|
appendTo(targets) {
|
|
1220
1370
|
return TinyHtml.appendTo(this, targets);
|
|
@@ -1224,6 +1374,7 @@ class TinyHtml {
|
|
|
1224
1374
|
*
|
|
1225
1375
|
* @param {TinyElement | TinyElement[]} el - The element(s) to prepend.
|
|
1226
1376
|
* @param {TinyElement | TinyElement[]} targets - Target element(s) where content will be prepended.
|
|
1377
|
+
* @returns {TinyElement|TinyElement[]}
|
|
1227
1378
|
*/
|
|
1228
1379
|
static prependTo(el, targets) {
|
|
1229
1380
|
const elems = TinyHtml._preElems(el, 'prependTo');
|
|
@@ -1234,11 +1385,13 @@ class TinyHtml {
|
|
|
1234
1385
|
.reverse()
|
|
1235
1386
|
.forEach((elem) => target.prepend(i === tars.length - 1 ? elem : elem.cloneNode(true)));
|
|
1236
1387
|
});
|
|
1388
|
+
return el;
|
|
1237
1389
|
}
|
|
1238
1390
|
/**
|
|
1239
1391
|
* Prepends the given element(s) to each target element in sequence.
|
|
1240
1392
|
*
|
|
1241
1393
|
* @param {TinyElement | TinyElement[]} targets - Target element(s) where content will be prepended.
|
|
1394
|
+
* @returns {TinyElement|TinyElement[]}
|
|
1242
1395
|
*/
|
|
1243
1396
|
prependTo(targets) {
|
|
1244
1397
|
return TinyHtml.prependTo(this, targets);
|
|
@@ -1249,6 +1402,7 @@ class TinyHtml {
|
|
|
1249
1402
|
* @param {TinyNode | TinyNode[]} el - The element(s) to insert.
|
|
1250
1403
|
* @param {TinyNode | TinyNode[]} target - The reference element where insertion happens.
|
|
1251
1404
|
* @param {TinyNode | TinyNode[] | null} [child=null] - Optional child to insert before, defaults to target.
|
|
1405
|
+
* @returns {TinyNode|TinyNode[]}
|
|
1252
1406
|
*/
|
|
1253
1407
|
static insertBefore(el, target, child = null) {
|
|
1254
1408
|
const elem = TinyHtml._preNodeElem(el, 'insertBefore');
|
|
@@ -1257,12 +1411,14 @@ class TinyHtml {
|
|
|
1257
1411
|
if (!targ.parentNode)
|
|
1258
1412
|
throw new Error('');
|
|
1259
1413
|
targ.parentNode.insertBefore(elem, childNode || targ);
|
|
1414
|
+
return el;
|
|
1260
1415
|
}
|
|
1261
1416
|
/**
|
|
1262
1417
|
* Inserts the element before a child of a given target, or before the target itself.
|
|
1263
1418
|
*
|
|
1264
1419
|
* @param {TinyNode | TinyNode[]} target - The reference element where insertion happens.
|
|
1265
1420
|
* @param {TinyNode | TinyNode[] | null} [child=null] - Optional child to insert before, defaults to target.
|
|
1421
|
+
* @returns {TinyNode|TinyNode[]}
|
|
1266
1422
|
*/
|
|
1267
1423
|
insertBefore(target, child) {
|
|
1268
1424
|
return TinyHtml.insertBefore(this, target, child);
|
|
@@ -1273,6 +1429,7 @@ class TinyHtml {
|
|
|
1273
1429
|
* @param {TinyNode | TinyNode[]} el - The element(s) to insert.
|
|
1274
1430
|
* @param {TinyNode | TinyNode[]} target - The reference element where insertion happens.
|
|
1275
1431
|
* @param {TinyNode | TinyNode[] | null} [child=null] - Optional child to insert after, defaults to target.
|
|
1432
|
+
* @returns {TinyNode|TinyNode[]}
|
|
1276
1433
|
*/
|
|
1277
1434
|
static insertAfter(el, target, child = null) {
|
|
1278
1435
|
const elem = TinyHtml._preNodeElem(el, 'insertAfter');
|
|
@@ -1281,12 +1438,14 @@ class TinyHtml {
|
|
|
1281
1438
|
if (!targ.parentNode)
|
|
1282
1439
|
throw new Error('');
|
|
1283
1440
|
targ.parentNode.insertBefore(elem, childNode || targ.nextSibling);
|
|
1441
|
+
return el;
|
|
1284
1442
|
}
|
|
1285
1443
|
/**
|
|
1286
1444
|
* Inserts the element after a child of a given target, or after the target itself.
|
|
1287
1445
|
*
|
|
1288
1446
|
* @param {TinyNode | TinyNode[]} target - The reference element where insertion happens.
|
|
1289
1447
|
* @param {TinyNode | TinyNode[] | null} [child=null] - Optional child to insert after, defaults to target.
|
|
1448
|
+
* @returns {TinyNode|TinyNode[]}
|
|
1290
1449
|
*/
|
|
1291
1450
|
insertAfter(target, child) {
|
|
1292
1451
|
return TinyHtml.insertAfter(this, target, child);
|
|
@@ -1297,6 +1456,7 @@ class TinyHtml {
|
|
|
1297
1456
|
*
|
|
1298
1457
|
* @param {TinyNode | TinyNode[]} el - The new element(s) to insert.
|
|
1299
1458
|
* @param {TinyNode | TinyNode[]} targets - The elements to be replaced.
|
|
1459
|
+
* @returns {TinyNode|TinyNode[]}
|
|
1300
1460
|
*/
|
|
1301
1461
|
static replaceAll(el, targets) {
|
|
1302
1462
|
const elems = TinyHtml._preNodeElems(el, 'replaceAll');
|
|
@@ -1308,12 +1468,14 @@ class TinyHtml {
|
|
|
1308
1468
|
parent.replaceChild(i === tars.length - 1 ? elem : elem.cloneNode(true), target);
|
|
1309
1469
|
});
|
|
1310
1470
|
});
|
|
1471
|
+
return el;
|
|
1311
1472
|
}
|
|
1312
1473
|
/**
|
|
1313
1474
|
* Replaces all target elements with the provided element(s).
|
|
1314
1475
|
* If multiple targets exist, the inserted elements are cloned accordingly.
|
|
1315
1476
|
*
|
|
1316
1477
|
* @param {TinyNode | TinyNode[]} targets - The elements to be replaced.
|
|
1478
|
+
* @returns {TinyNode|TinyNode[]}
|
|
1317
1479
|
*/
|
|
1318
1480
|
replaceAll(targets) {
|
|
1319
1481
|
return TinyHtml.replaceAll(this, targets);
|
|
@@ -1332,7 +1494,10 @@ class TinyHtml {
|
|
|
1332
1494
|
constructor(el) {
|
|
1333
1495
|
if (el instanceof TinyHtml)
|
|
1334
1496
|
throw new Error(`[TinyHtml] You are trying to put a TinyHtml inside another TinyHtml in constructor.`);
|
|
1335
|
-
if (!(el instanceof Element) &&
|
|
1497
|
+
if (!(el instanceof Element) &&
|
|
1498
|
+
!(el instanceof Window) &&
|
|
1499
|
+
!(el instanceof Document) &&
|
|
1500
|
+
!(el instanceof Text))
|
|
1336
1501
|
throw new Error(`[TinyHtml] Invalid Target in constructor.`);
|
|
1337
1502
|
this.#el = el;
|
|
1338
1503
|
}
|
|
@@ -1764,6 +1929,7 @@ class TinyHtml {
|
|
|
1764
1929
|
* @param {TinyHtmlElement|TinyHtmlElement[]} el - The element to inspect.
|
|
1765
1930
|
* @param {string|Object} prop - The property name or an object with key-value pairs
|
|
1766
1931
|
* @param {string|null} [value=null] - The value to set (if `prop` is a string)
|
|
1932
|
+
* @returns {TinyHtmlElement|TinyHtmlElement[]}
|
|
1767
1933
|
*/
|
|
1768
1934
|
static setStyle(el, prop, value = null) {
|
|
1769
1935
|
TinyHtml._preHtmlElems(el, 'setStyle').forEach((elem) => {
|
|
@@ -1775,6 +1941,7 @@ class TinyHtml {
|
|
|
1775
1941
|
else
|
|
1776
1942
|
elem.style.setProperty(TinyHtml.toStyleKc(prop), value);
|
|
1777
1943
|
});
|
|
1944
|
+
return el;
|
|
1778
1945
|
}
|
|
1779
1946
|
/**
|
|
1780
1947
|
* Sets one or more CSS inline style properties on the given element(s).
|
|
@@ -1784,6 +1951,7 @@ class TinyHtml {
|
|
|
1784
1951
|
*
|
|
1785
1952
|
* @param {string|Object} prop - The property name or an object with key-value pairs
|
|
1786
1953
|
* @param {string|null} [value=null] - The value to set (if `prop` is a string)
|
|
1954
|
+
* @returns {TinyHtmlElement|TinyHtmlElement[]}
|
|
1787
1955
|
*/
|
|
1788
1956
|
setStyle(prop, value) {
|
|
1789
1957
|
return TinyHtml.setStyle(this, prop, value);
|
|
@@ -1872,6 +2040,7 @@ class TinyHtml {
|
|
|
1872
2040
|
*
|
|
1873
2041
|
* @param {TinyHtmlElement|TinyHtmlElement[]} el - A single element or an array of elements.
|
|
1874
2042
|
* @param {string|string[]} prop - A property name or an array of property names to remove.
|
|
2043
|
+
* @returns {TinyHtmlElement|TinyHtmlElement[]}
|
|
1875
2044
|
*/
|
|
1876
2045
|
static removeStyle(el, prop) {
|
|
1877
2046
|
TinyHtml._preHtmlElems(el, 'removeStyle').forEach((elem) => {
|
|
@@ -1883,11 +2052,13 @@ class TinyHtml {
|
|
|
1883
2052
|
else
|
|
1884
2053
|
elem.style.removeProperty(TinyHtml.toStyleKc(prop));
|
|
1885
2054
|
});
|
|
2055
|
+
return el;
|
|
1886
2056
|
}
|
|
1887
2057
|
/**
|
|
1888
2058
|
* Removes one or more inline CSS properties from the given element(s).
|
|
1889
2059
|
*
|
|
1890
2060
|
* @param {string|string[]} prop - A property name or an array of property names to remove.
|
|
2061
|
+
* @returns {TinyHtmlElement|TinyHtmlElement[]}
|
|
1891
2062
|
*/
|
|
1892
2063
|
removeStyle(prop) {
|
|
1893
2064
|
return TinyHtml.removeStyle(this, prop);
|
|
@@ -1901,6 +2072,7 @@ class TinyHtml {
|
|
|
1901
2072
|
* @param {string} prop - The CSS property to toggle.
|
|
1902
2073
|
* @param {string} val1 - The first value (used as "current" check).
|
|
1903
2074
|
* @param {string} val2 - The second value (used as the "alternative").
|
|
2075
|
+
* @returns {TinyHtmlElement|TinyHtmlElement[]}
|
|
1904
2076
|
*/
|
|
1905
2077
|
static toggleStyle(el, prop, val1, val2) {
|
|
1906
2078
|
TinyHtml._preHtmlElems(el, 'toggleStyle').forEach((elem) => {
|
|
@@ -1908,6 +2080,7 @@ class TinyHtml {
|
|
|
1908
2080
|
const newVal = current === TinyHtml.toStyleKc(val1) ? val2 : val1;
|
|
1909
2081
|
TinyHtml.setStyle(elem, prop, newVal);
|
|
1910
2082
|
});
|
|
2083
|
+
return el;
|
|
1911
2084
|
}
|
|
1912
2085
|
/**
|
|
1913
2086
|
* Toggles a CSS property value between two given values.
|
|
@@ -1917,6 +2090,7 @@ class TinyHtml {
|
|
|
1917
2090
|
* @param {string} prop - The CSS property to toggle.
|
|
1918
2091
|
* @param {string} val1 - The first value (used as "current" check).
|
|
1919
2092
|
* @param {string} val2 - The second value (used as the "alternative").
|
|
2093
|
+
* @returns {TinyHtmlElement|TinyHtmlElement[]}
|
|
1920
2094
|
*/
|
|
1921
2095
|
toggleStyle(prop, val1, val2) {
|
|
1922
2096
|
return TinyHtml.toggleStyle(this, prop, val1, val2);
|
|
@@ -1925,13 +2099,15 @@ class TinyHtml {
|
|
|
1925
2099
|
* Removes all inline styles (`style` attribute) from the given element(s).
|
|
1926
2100
|
*
|
|
1927
2101
|
* @param {TinyElement|TinyElement[]} el - A single element or an array of elements.
|
|
2102
|
+
* @returns {TinyElement|TinyElement[]}
|
|
1928
2103
|
*/
|
|
1929
2104
|
static clearStyle(el) {
|
|
1930
2105
|
TinyHtml._preElems(el, 'clearStyle').forEach((elem) => elem.removeAttribute('style'));
|
|
2106
|
+
return el;
|
|
1931
2107
|
}
|
|
1932
2108
|
/**
|
|
1933
2109
|
* Removes all inline styles (`style` attribute) from the given element(s).
|
|
1934
|
-
*
|
|
2110
|
+
* @returns {TinyElement|TinyElement[]}
|
|
1935
2111
|
*/
|
|
1936
2112
|
clearStyle() {
|
|
1937
2113
|
return TinyHtml.clearStyle(this);
|
|
@@ -1941,13 +2117,16 @@ class TinyHtml {
|
|
|
1941
2117
|
* Focus the element.
|
|
1942
2118
|
*
|
|
1943
2119
|
* @param {TinyHtmlElement} el - The element or a selector string.
|
|
2120
|
+
* @returns {TinyHtmlElement}
|
|
1944
2121
|
*/
|
|
1945
2122
|
static focus(el) {
|
|
1946
2123
|
const elem = TinyHtml._preHtmlElem(el, 'focus');
|
|
1947
2124
|
elem.focus();
|
|
2125
|
+
return el;
|
|
1948
2126
|
}
|
|
1949
2127
|
/**
|
|
1950
2128
|
* Focus the element.
|
|
2129
|
+
* @returns {TinyHtmlElement}
|
|
1951
2130
|
*/
|
|
1952
2131
|
focus() {
|
|
1953
2132
|
return TinyHtml.focus(this);
|
|
@@ -1956,17 +2135,42 @@ class TinyHtml {
|
|
|
1956
2135
|
* Blur the element.
|
|
1957
2136
|
*
|
|
1958
2137
|
* @param {TinyHtmlElement} el - The element or a selector string.
|
|
2138
|
+
* @returns {TinyHtmlElement}
|
|
1959
2139
|
*/
|
|
1960
2140
|
static blur(el) {
|
|
1961
2141
|
const elem = TinyHtml._preHtmlElem(el, 'blur');
|
|
1962
2142
|
elem.blur();
|
|
2143
|
+
return el;
|
|
1963
2144
|
}
|
|
1964
2145
|
/**
|
|
1965
2146
|
* Blur the element.
|
|
2147
|
+
* @returns {TinyHtmlElement}
|
|
1966
2148
|
*/
|
|
1967
2149
|
blur() {
|
|
1968
2150
|
return TinyHtml.blur(this);
|
|
1969
2151
|
}
|
|
2152
|
+
/**
|
|
2153
|
+
* Interprets a value as a boolean `true` if it matches a common truthy representation.
|
|
2154
|
+
*
|
|
2155
|
+
* This method checks if the input is any of the common forms used to represent `true`,
|
|
2156
|
+
* such as the string `'true'`, `'1'`, `'on'`, the boolean `true`, or the number `1`.
|
|
2157
|
+
*
|
|
2158
|
+
* @param {string|boolean|number} [value] - The value to interpret as boolean.
|
|
2159
|
+
* @returns {boolean} `true` if the value represents a truthy state, otherwise `false`.
|
|
2160
|
+
*/
|
|
2161
|
+
static boolCheck(value) {
|
|
2162
|
+
if (typeof value !== 'undefined' &&
|
|
2163
|
+
(value === 'true' ||
|
|
2164
|
+
value === '1' ||
|
|
2165
|
+
value === true ||
|
|
2166
|
+
value === 'on' ||
|
|
2167
|
+
(typeof value === 'number' && value > 0))) {
|
|
2168
|
+
return true;
|
|
2169
|
+
}
|
|
2170
|
+
else {
|
|
2171
|
+
return false;
|
|
2172
|
+
}
|
|
2173
|
+
}
|
|
1970
2174
|
//////////////////////////////////////////////////////////////////////
|
|
1971
2175
|
/**
|
|
1972
2176
|
* Sets the vertical scroll position of the window.
|
|
@@ -2014,16 +2218,38 @@ class TinyHtml {
|
|
|
2014
2218
|
static winInnerWidth() {
|
|
2015
2219
|
return window.innerWidth || document.documentElement.clientWidth;
|
|
2016
2220
|
}
|
|
2221
|
+
/**
|
|
2222
|
+
* Checks if the page is currently scrolled to the very top.
|
|
2223
|
+
*
|
|
2224
|
+
* This method compares the current vertical scroll position with the total document height.
|
|
2225
|
+
* It's useful for detecting if the user has reached the top of the page.
|
|
2226
|
+
*
|
|
2227
|
+
* @returns {boolean} `true` if the page is scrolled to the top, otherwise `false`.
|
|
2228
|
+
*/
|
|
2229
|
+
static isPageTop() {
|
|
2230
|
+
return window.scrollY === 0;
|
|
2231
|
+
}
|
|
2232
|
+
/**
|
|
2233
|
+
* Checks if the page is currently scrolled to the very bottom.
|
|
2234
|
+
*
|
|
2235
|
+
* This method uses the `scrollY` and `innerHeight` properties to determine if the
|
|
2236
|
+
* user has reached the end of the document.
|
|
2237
|
+
*
|
|
2238
|
+
* @returns {boolean} `true` if the page is scrolled to the bottom, otherwise `false`.
|
|
2239
|
+
*/
|
|
2240
|
+
static isPageBottom() {
|
|
2241
|
+
return window.innerHeight + window.scrollY >= document.body.offsetHeight;
|
|
2242
|
+
}
|
|
2017
2243
|
/**
|
|
2018
2244
|
* Gets the width or height of an element based on the box model.
|
|
2019
|
-
* @param {
|
|
2245
|
+
* @param {TinyElementAndWinAndDoc} el - The element or window.
|
|
2020
2246
|
* @param {"width"|"height"} type - Dimension type.
|
|
2021
2247
|
* @param {"content"|"padding"|"border"|"margin"} [extra='content'] - Box model context.
|
|
2022
2248
|
* @returns {number} - Computed dimension.
|
|
2023
2249
|
* @throws {TypeError} If `type` or `extra` is not a string.
|
|
2024
2250
|
*/
|
|
2025
2251
|
static getDimension(el, type, extra = 'content') {
|
|
2026
|
-
const elem = TinyHtml.
|
|
2252
|
+
const elem = TinyHtml._preElemAndWinAndDoc(el, 'getDimension');
|
|
2027
2253
|
if (typeof type !== 'string')
|
|
2028
2254
|
throw new TypeError('The type must be a string.');
|
|
2029
2255
|
if (typeof extra !== 'string')
|
|
@@ -2094,16 +2320,19 @@ class TinyHtml {
|
|
|
2094
2320
|
* @param {TinyHtmlElement} el - Target element.
|
|
2095
2321
|
* @param {string|number} value - Height value.
|
|
2096
2322
|
* @throws {TypeError} If `value` is neither a string nor number.
|
|
2323
|
+
* @returns {TinyHtmlElement}
|
|
2097
2324
|
*/
|
|
2098
2325
|
static setHeight(el, value) {
|
|
2099
2326
|
const elem = TinyHtml._preHtmlElem(el, 'setHeight');
|
|
2100
2327
|
if (typeof value !== 'number' && typeof value !== 'string')
|
|
2101
2328
|
throw new TypeError('The value must be a string or number.');
|
|
2102
2329
|
elem.style.height = typeof value === 'number' ? `${value}px` : value;
|
|
2330
|
+
return el;
|
|
2103
2331
|
}
|
|
2104
2332
|
/**
|
|
2105
2333
|
* Sets the height of the element.
|
|
2106
2334
|
* @param {string|number} value - Height value.
|
|
2335
|
+
* @returns {TinyHtmlElement}
|
|
2107
2336
|
*/
|
|
2108
2337
|
setHeight(value) {
|
|
2109
2338
|
return TinyHtml.setHeight(this, value);
|
|
@@ -2113,27 +2342,30 @@ class TinyHtml {
|
|
|
2113
2342
|
* @param {TinyHtmlElement} el - Target element.
|
|
2114
2343
|
* @param {string|number} value - Width value.
|
|
2115
2344
|
* @throws {TypeError} If `value` is neither a string nor number.
|
|
2345
|
+
* @returns {TinyHtmlElement}
|
|
2116
2346
|
*/
|
|
2117
2347
|
static setWidth(el, value) {
|
|
2118
2348
|
const elem = TinyHtml._preHtmlElem(el, 'setWidth');
|
|
2119
2349
|
if (typeof value !== 'number' && typeof value !== 'string')
|
|
2120
2350
|
throw new TypeError('The value must be a string or number.');
|
|
2121
2351
|
elem.style.width = typeof value === 'number' ? `${value}px` : value;
|
|
2352
|
+
return el;
|
|
2122
2353
|
}
|
|
2123
2354
|
/**
|
|
2124
2355
|
* Sets the width of the element.
|
|
2125
2356
|
* @param {string|number} value - Width value.
|
|
2357
|
+
* @returns {TinyHtmlElement}
|
|
2126
2358
|
*/
|
|
2127
2359
|
setWidth(value) {
|
|
2128
2360
|
return TinyHtml.setWidth(this, value);
|
|
2129
2361
|
}
|
|
2130
2362
|
/**
|
|
2131
2363
|
* Returns content box height.
|
|
2132
|
-
* @param {
|
|
2364
|
+
* @param {TinyElementAndWinAndDoc} el - Target element.
|
|
2133
2365
|
* @returns {number}
|
|
2134
2366
|
*/
|
|
2135
2367
|
static height(el) {
|
|
2136
|
-
const elem = TinyHtml.
|
|
2368
|
+
const elem = TinyHtml._preElemAndWinAndDoc(el, 'height');
|
|
2137
2369
|
return TinyHtml.getDimension(elem, 'height', 'content');
|
|
2138
2370
|
}
|
|
2139
2371
|
/**
|
|
@@ -2145,11 +2377,11 @@ class TinyHtml {
|
|
|
2145
2377
|
}
|
|
2146
2378
|
/**
|
|
2147
2379
|
* Returns content box width.
|
|
2148
|
-
* @param {
|
|
2380
|
+
* @param {TinyElementAndWinAndDoc} el - Target element.
|
|
2149
2381
|
* @returns {number}
|
|
2150
2382
|
*/
|
|
2151
2383
|
static width(el) {
|
|
2152
|
-
const elem = TinyHtml.
|
|
2384
|
+
const elem = TinyHtml._preElemAndWinAndDoc(el, 'width');
|
|
2153
2385
|
return TinyHtml.getDimension(elem, 'width', 'content');
|
|
2154
2386
|
}
|
|
2155
2387
|
/**
|
|
@@ -2161,11 +2393,11 @@ class TinyHtml {
|
|
|
2161
2393
|
}
|
|
2162
2394
|
/**
|
|
2163
2395
|
* Returns padding box height.
|
|
2164
|
-
* @param {
|
|
2396
|
+
* @param {TinyElementAndWinAndDoc} el - Target element.
|
|
2165
2397
|
* @returns {number}
|
|
2166
2398
|
*/
|
|
2167
2399
|
static innerHeight(el) {
|
|
2168
|
-
const elem = TinyHtml.
|
|
2400
|
+
const elem = TinyHtml._preElemAndWinAndDoc(el, 'innerHeight');
|
|
2169
2401
|
return TinyHtml.getDimension(elem, 'height', 'padding');
|
|
2170
2402
|
}
|
|
2171
2403
|
/**
|
|
@@ -2177,11 +2409,11 @@ class TinyHtml {
|
|
|
2177
2409
|
}
|
|
2178
2410
|
/**
|
|
2179
2411
|
* Returns padding box width.
|
|
2180
|
-
* @param {
|
|
2412
|
+
* @param {TinyElementAndWinAndDoc} el - Target element.
|
|
2181
2413
|
* @returns {number}
|
|
2182
2414
|
*/
|
|
2183
2415
|
static innerWidth(el) {
|
|
2184
|
-
const elem = TinyHtml.
|
|
2416
|
+
const elem = TinyHtml._preElemAndWinAndDoc(el, 'innerWidth');
|
|
2185
2417
|
return TinyHtml.getDimension(elem, 'width', 'padding');
|
|
2186
2418
|
}
|
|
2187
2419
|
/**
|
|
@@ -2193,14 +2425,14 @@ class TinyHtml {
|
|
|
2193
2425
|
}
|
|
2194
2426
|
/**
|
|
2195
2427
|
* Returns outer height of the element, optionally including margin.
|
|
2196
|
-
* @param {
|
|
2428
|
+
* @param {TinyElementAndWinAndDoc} el - Target element.
|
|
2197
2429
|
* @param {boolean} [includeMargin=false] - Whether to include margin.
|
|
2198
2430
|
* @returns {number}
|
|
2199
2431
|
*/
|
|
2200
2432
|
static outerHeight(el, includeMargin = false) {
|
|
2201
2433
|
if (typeof includeMargin !== 'boolean')
|
|
2202
2434
|
throw new TypeError('The "includeMargin" must be a boolean.');
|
|
2203
|
-
const elem = TinyHtml.
|
|
2435
|
+
const elem = TinyHtml._preElemAndWinAndDoc(el, 'outerHeight');
|
|
2204
2436
|
return TinyHtml.getDimension(elem, 'height', includeMargin ? 'margin' : 'border');
|
|
2205
2437
|
}
|
|
2206
2438
|
/**
|
|
@@ -2213,14 +2445,14 @@ class TinyHtml {
|
|
|
2213
2445
|
}
|
|
2214
2446
|
/**
|
|
2215
2447
|
* Returns outer width of the element, optionally including margin.
|
|
2216
|
-
* @param {
|
|
2448
|
+
* @param {TinyElementAndWinAndDoc} el - Target element.
|
|
2217
2449
|
* @param {boolean} [includeMargin=false] - Whether to include margin.
|
|
2218
2450
|
* @returns {number}
|
|
2219
2451
|
*/
|
|
2220
2452
|
static outerWidth(el, includeMargin = false) {
|
|
2221
2453
|
if (typeof includeMargin !== 'boolean')
|
|
2222
2454
|
throw new TypeError('The "includeMargin" must be a boolean.');
|
|
2223
|
-
const elem = TinyHtml.
|
|
2455
|
+
const elem = TinyHtml._preElemAndWinAndDoc(el, 'outerWidth');
|
|
2224
2456
|
return TinyHtml.getDimension(elem, 'width', includeMargin ? 'margin' : 'border');
|
|
2225
2457
|
}
|
|
2226
2458
|
/**
|
|
@@ -2369,6 +2601,7 @@ class TinyHtml {
|
|
|
2369
2601
|
* Sets the vertical scroll position.
|
|
2370
2602
|
* @param {TinyElementAndWindow|TinyElementAndWindow[]} el - Element or window.
|
|
2371
2603
|
* @param {number} value - Scroll top value.
|
|
2604
|
+
* @returns {TinyElementAndWindow|TinyElementAndWindow[]}
|
|
2372
2605
|
*/
|
|
2373
2606
|
static setScrollTop(el, value) {
|
|
2374
2607
|
if (typeof value !== 'number')
|
|
@@ -2385,10 +2618,12 @@ class TinyHtml {
|
|
|
2385
2618
|
elem.scrollTop = value;
|
|
2386
2619
|
}
|
|
2387
2620
|
});
|
|
2621
|
+
return el;
|
|
2388
2622
|
}
|
|
2389
2623
|
/**
|
|
2390
2624
|
* Sets the vertical scroll position.
|
|
2391
2625
|
* @param {number} value - Scroll top value.
|
|
2626
|
+
* @returns {TinyElementAndWindow|TinyElementAndWindow[]}
|
|
2392
2627
|
*/
|
|
2393
2628
|
setScrollTop(value) {
|
|
2394
2629
|
return TinyHtml.setScrollTop(this, value);
|
|
@@ -2397,6 +2632,7 @@ class TinyHtml {
|
|
|
2397
2632
|
* Sets the horizontal scroll position.
|
|
2398
2633
|
* @param {TinyElementAndWindow|TinyElementAndWindow[]} el - Element or window.
|
|
2399
2634
|
* @param {number} value - Scroll left value.
|
|
2635
|
+
* @returns {TinyElementAndWindow|TinyElementAndWindow[]}
|
|
2400
2636
|
*/
|
|
2401
2637
|
static setScrollLeft(el, value) {
|
|
2402
2638
|
if (typeof value !== 'number')
|
|
@@ -2413,10 +2649,12 @@ class TinyHtml {
|
|
|
2413
2649
|
elem.scrollLeft = value;
|
|
2414
2650
|
}
|
|
2415
2651
|
});
|
|
2652
|
+
return el;
|
|
2416
2653
|
}
|
|
2417
2654
|
/**
|
|
2418
2655
|
* Sets the horizontal scroll position.
|
|
2419
2656
|
* @param {number} value - Scroll left value.
|
|
2657
|
+
* @returns {TinyElementAndWindow|TinyElementAndWindow[]}
|
|
2420
2658
|
*/
|
|
2421
2659
|
setScrollLeft(value) {
|
|
2422
2660
|
return TinyHtml.setScrollLeft(this, value);
|
|
@@ -2513,28 +2751,30 @@ class TinyHtml {
|
|
|
2513
2751
|
/////////////////////////////////////////////
|
|
2514
2752
|
/**
|
|
2515
2753
|
* Adds one or more CSS class names to the element.
|
|
2516
|
-
* @type {(el: TinyElement|TinyElement[], ...tokens: string[]) =>
|
|
2754
|
+
* @type {(el: TinyElement|TinyElement[], ...tokens: string[]) => (TinyElement|TinyElement[])} - One or more class names to add.
|
|
2517
2755
|
*/
|
|
2518
2756
|
static addClass(el, ...args) {
|
|
2519
2757
|
TinyHtml._preElems(el, 'addClass').forEach((elem) => elem.classList.add(...args));
|
|
2758
|
+
return el;
|
|
2520
2759
|
}
|
|
2521
2760
|
/**
|
|
2522
2761
|
* Adds one or more CSS class names to the element.
|
|
2523
|
-
* @type {(...tokens: string[]) =>
|
|
2762
|
+
* @type {(...tokens: string[]) => (TinyElement|TinyElement[])} - One or more class names to add.
|
|
2524
2763
|
*/
|
|
2525
2764
|
addClass(...args) {
|
|
2526
2765
|
return TinyHtml.addClass(this, ...args);
|
|
2527
2766
|
}
|
|
2528
2767
|
/**
|
|
2529
2768
|
* Removes one or more CSS class names from the element.
|
|
2530
|
-
* @type {(el: TinyElement|TinyElement[], ...tokens: string[]) =>
|
|
2769
|
+
* @type {(el: TinyElement|TinyElement[], ...tokens: string[]) => (TinyElement|TinyElement[])} - One or more class names to remove.
|
|
2531
2770
|
*/
|
|
2532
2771
|
static removeClass(el, ...args) {
|
|
2533
2772
|
TinyHtml._preElems(el, 'removeClass').forEach((elem) => elem.classList.remove(...args));
|
|
2773
|
+
return el;
|
|
2534
2774
|
}
|
|
2535
2775
|
/**
|
|
2536
2776
|
* Removes one or more CSS class names from the element.
|
|
2537
|
-
* @type {(...tokens: string[]) =>
|
|
2777
|
+
* @type {(...tokens: string[]) => (TinyElement|TinyElement[])} - One or more class names to remove.
|
|
2538
2778
|
*/
|
|
2539
2779
|
removeClass(...args) {
|
|
2540
2780
|
return TinyHtml.removeClass(this, ...args);
|
|
@@ -2724,15 +2964,18 @@ class TinyHtml {
|
|
|
2724
2964
|
* Set text content of elements.
|
|
2725
2965
|
* @param {TinyElement|TinyElement[]} el
|
|
2726
2966
|
* @param {string} value
|
|
2967
|
+
* @returns {TinyElement|TinyElement[]}
|
|
2727
2968
|
*/
|
|
2728
2969
|
static setText(el, value) {
|
|
2729
2970
|
if (typeof value !== 'string')
|
|
2730
2971
|
throw new Error('Value is not a valid string.');
|
|
2731
2972
|
TinyHtml._preElems(el, 'setText').forEach((el) => (el.textContent = value));
|
|
2973
|
+
return el;
|
|
2732
2974
|
}
|
|
2733
2975
|
/**
|
|
2734
2976
|
* Set text content of the element.
|
|
2735
2977
|
* @param {string} value
|
|
2978
|
+
* @returns {TinyElement|TinyElement[]}
|
|
2736
2979
|
*/
|
|
2737
2980
|
setText(value) {
|
|
2738
2981
|
return TinyHtml.setText(this, value);
|
|
@@ -2740,45 +2983,53 @@ class TinyHtml {
|
|
|
2740
2983
|
/**
|
|
2741
2984
|
* Remove all child nodes from each element.
|
|
2742
2985
|
* @param {TinyElement|TinyElement[]} el
|
|
2986
|
+
* @returns {TinyElement|TinyElement[]}
|
|
2743
2987
|
*/
|
|
2744
2988
|
static empty(el) {
|
|
2745
2989
|
TinyHtml._preElems(el, 'empty').forEach((el) => (el.textContent = ''));
|
|
2990
|
+
return el;
|
|
2746
2991
|
}
|
|
2747
2992
|
/**
|
|
2748
2993
|
* Remove all child nodes of the element.
|
|
2994
|
+
* @returns {TinyElement|TinyElement[]}
|
|
2749
2995
|
*/
|
|
2750
2996
|
empty() {
|
|
2751
2997
|
return TinyHtml.empty(this);
|
|
2752
2998
|
}
|
|
2753
2999
|
/**
|
|
2754
3000
|
* Get the innerHTML of the element.
|
|
2755
|
-
* @param {TinyElement
|
|
3001
|
+
* @param {TinyElement} el
|
|
3002
|
+
* @param {GetHTMLOptions} [ops]
|
|
2756
3003
|
* @returns {string}
|
|
2757
3004
|
*/
|
|
2758
|
-
static html(el) {
|
|
3005
|
+
static html(el, ops) {
|
|
2759
3006
|
const elem = TinyHtml._preElem(el, 'html');
|
|
2760
|
-
return elem.
|
|
3007
|
+
return elem.getHTML(ops);
|
|
2761
3008
|
}
|
|
2762
3009
|
/**
|
|
2763
3010
|
* Get the innerHTML of the element.
|
|
3011
|
+
* @param {GetHTMLOptions} [ops]
|
|
2764
3012
|
* @returns {string}
|
|
2765
3013
|
*/
|
|
2766
|
-
html() {
|
|
2767
|
-
return TinyHtml.html(this);
|
|
3014
|
+
html(ops) {
|
|
3015
|
+
return TinyHtml.html(this, ops);
|
|
2768
3016
|
}
|
|
2769
3017
|
/**
|
|
2770
3018
|
* Set the innerHTML of each element.
|
|
2771
3019
|
* @param {TinyElement|TinyElement[]} el
|
|
2772
3020
|
* @param {string} value
|
|
3021
|
+
* @returns {TinyElement|TinyElement[]}
|
|
2773
3022
|
*/
|
|
2774
3023
|
static setHtml(el, value) {
|
|
2775
3024
|
if (typeof value !== 'string')
|
|
2776
3025
|
throw new Error('Value is not a valid string.');
|
|
2777
3026
|
TinyHtml._preElems(el, 'setHtml').forEach((el) => (el.innerHTML = value));
|
|
3027
|
+
return el;
|
|
2778
3028
|
}
|
|
2779
3029
|
/**
|
|
2780
3030
|
* Set the innerHTML of the element.
|
|
2781
3031
|
* @param {string} value
|
|
3032
|
+
* @returns {TinyElement|TinyElement[]}
|
|
2782
3033
|
*/
|
|
2783
3034
|
setHtml(value) {
|
|
2784
3035
|
return TinyHtml.setHtml(this, value);
|
|
@@ -2899,6 +3150,7 @@ class TinyHtml {
|
|
|
2899
3150
|
* @param {TinyInputElement|TinyInputElement[]} el - Target element.
|
|
2900
3151
|
* @param {SetValueList|((el: InputElement, val: SetValueList) => SetValueList)} value - The value to assign or a function that returns it.
|
|
2901
3152
|
* @throws {Error} If the computed value is not a valid string or boolean.
|
|
3153
|
+
* @returns {TinyInputElement|TinyInputElement[]}
|
|
2902
3154
|
*/
|
|
2903
3155
|
static setVal(el, value) {
|
|
2904
3156
|
TinyHtml._preInputElems(el, 'setVal').forEach((elem) => {
|
|
@@ -2937,12 +3189,14 @@ class TinyHtml {
|
|
|
2937
3189
|
elem.value = valToSet;
|
|
2938
3190
|
}
|
|
2939
3191
|
});
|
|
3192
|
+
return el;
|
|
2940
3193
|
}
|
|
2941
3194
|
/**
|
|
2942
3195
|
* Sets the value of the current HTML value element (input, select, textarea, etc.).
|
|
2943
3196
|
* Accepts strings, numbers, booleans or arrays of these values, or a callback function that computes them.
|
|
2944
3197
|
*
|
|
2945
3198
|
* @param {SetValueList|((el: InputElement, val: SetValueList) => SetValueList)} value - The value to assign or a function that returns it.
|
|
3199
|
+
* @returns {TinyInputElement|TinyInputElement[]}
|
|
2946
3200
|
* @throws {Error} If the computed value is not a valid string or boolean.
|
|
2947
3201
|
*/
|
|
2948
3202
|
setVal(value) {
|
|
@@ -3199,6 +3453,7 @@ class TinyHtml {
|
|
|
3199
3453
|
* @param {string} event - The event type (e.g. 'click', 'keydown').
|
|
3200
3454
|
* @param {EventRegistryHandle} handler - The callback function to run on event.
|
|
3201
3455
|
* @param {EventRegistryOptions} [options] - Optional event listener options.
|
|
3456
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
3202
3457
|
*/
|
|
3203
3458
|
static on(el, event, handler, options) {
|
|
3204
3459
|
if (typeof event !== 'string')
|
|
@@ -3214,6 +3469,7 @@ class TinyHtml {
|
|
|
3214
3469
|
events[event] = [];
|
|
3215
3470
|
events[event].push({ handler, options });
|
|
3216
3471
|
});
|
|
3472
|
+
return el;
|
|
3217
3473
|
}
|
|
3218
3474
|
/**
|
|
3219
3475
|
* Registers an event listener on the specified element.
|
|
@@ -3221,6 +3477,7 @@ class TinyHtml {
|
|
|
3221
3477
|
* @param {string} event - The event type (e.g. 'click', 'keydown').
|
|
3222
3478
|
* @param {EventRegistryHandle} handler - The callback function to run on event.
|
|
3223
3479
|
* @param {EventRegistryOptions} [options] - Optional event listener options.
|
|
3480
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
3224
3481
|
*/
|
|
3225
3482
|
on(event, handler, options) {
|
|
3226
3483
|
return TinyHtml.on(this, event, handler, options);
|
|
@@ -3232,6 +3489,7 @@ class TinyHtml {
|
|
|
3232
3489
|
* @param {string} event - The event type (e.g. 'click', 'keydown').
|
|
3233
3490
|
* @param {EventRegistryHandle} handler - The callback function to run on event.
|
|
3234
3491
|
* @param {EventRegistryOptions} [options={}] - Optional event listener options.
|
|
3492
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
3235
3493
|
*/
|
|
3236
3494
|
static once(el, event, handler, options = {}) {
|
|
3237
3495
|
if (typeof event !== 'string')
|
|
@@ -3244,6 +3502,7 @@ class TinyHtml {
|
|
|
3244
3502
|
};
|
|
3245
3503
|
TinyHtml.on(elem, event, wrapped, typeof options === 'boolean' ? options : { ...options, once: true });
|
|
3246
3504
|
});
|
|
3505
|
+
return el;
|
|
3247
3506
|
}
|
|
3248
3507
|
/**
|
|
3249
3508
|
* Registers an event listener that runs only once, then is removed.
|
|
@@ -3251,6 +3510,7 @@ class TinyHtml {
|
|
|
3251
3510
|
* @param {string} event - The event type (e.g. 'click', 'keydown').
|
|
3252
3511
|
* @param {EventRegistryHandle} handler - The callback function to run on event.
|
|
3253
3512
|
* @param {EventRegistryOptions} [options={}] - Optional event listener options.
|
|
3513
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
3254
3514
|
*/
|
|
3255
3515
|
once(event, handler, options = {}) {
|
|
3256
3516
|
return TinyHtml.once(this, event, handler, options);
|
|
@@ -3262,6 +3522,7 @@ class TinyHtml {
|
|
|
3262
3522
|
* @param {string} event - The event type.
|
|
3263
3523
|
* @param {EventRegistryHandle} handler - The function originally bound to the event.
|
|
3264
3524
|
* @param {boolean|EventListenerOptions} [options] - Optional listener options.
|
|
3525
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
3265
3526
|
*/
|
|
3266
3527
|
static off(el, event, handler, options) {
|
|
3267
3528
|
if (typeof event !== 'string')
|
|
@@ -3275,6 +3536,7 @@ class TinyHtml {
|
|
|
3275
3536
|
delete events[event];
|
|
3276
3537
|
}
|
|
3277
3538
|
});
|
|
3539
|
+
return el;
|
|
3278
3540
|
}
|
|
3279
3541
|
/**
|
|
3280
3542
|
* Removes a specific event listener from an element.
|
|
@@ -3282,6 +3544,7 @@ class TinyHtml {
|
|
|
3282
3544
|
* @param {string} event - The event type.
|
|
3283
3545
|
* @param {EventRegistryHandle} handler - The function originally bound to the event.
|
|
3284
3546
|
* @param {boolean|EventListenerOptions} [options] - Optional listener options.
|
|
3547
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
3285
3548
|
*/
|
|
3286
3549
|
off(event, handler, options) {
|
|
3287
3550
|
return TinyHtml.off(this, event, handler, options);
|
|
@@ -3291,6 +3554,7 @@ class TinyHtml {
|
|
|
3291
3554
|
*
|
|
3292
3555
|
* @param {TinyEventTarget|TinyEventTarget[]} el - The target element.
|
|
3293
3556
|
* @param {string} event - The event type to remove (e.g. 'click').
|
|
3557
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
3294
3558
|
*/
|
|
3295
3559
|
static offAll(el, event) {
|
|
3296
3560
|
if (typeof event !== 'string')
|
|
@@ -3304,11 +3568,13 @@ class TinyHtml {
|
|
|
3304
3568
|
delete events[event];
|
|
3305
3569
|
}
|
|
3306
3570
|
});
|
|
3571
|
+
return el;
|
|
3307
3572
|
}
|
|
3308
3573
|
/**
|
|
3309
3574
|
* Removes all event listeners of a specific type from the element.
|
|
3310
3575
|
*
|
|
3311
3576
|
* @param {string} event - The event type to remove (e.g. 'click').
|
|
3577
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
3312
3578
|
*/
|
|
3313
3579
|
offAll(event) {
|
|
3314
3580
|
return TinyHtml.offAll(this, event);
|
|
@@ -3319,6 +3585,7 @@ class TinyHtml {
|
|
|
3319
3585
|
* @param {TinyEventTarget|TinyEventTarget[]} el - The target element.
|
|
3320
3586
|
* @param {((handler: EventListenerOrEventListenerObject, event: string) => boolean)|null} [filterFn=null] -
|
|
3321
3587
|
* Optional filter function to selectively remove specific handlers.
|
|
3588
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
3322
3589
|
*/
|
|
3323
3590
|
static offAllTypes(el, filterFn = null) {
|
|
3324
3591
|
if (filterFn !== null && typeof filterFn !== 'function')
|
|
@@ -3336,12 +3603,14 @@ class TinyHtml {
|
|
|
3336
3603
|
}
|
|
3337
3604
|
__eventRegistry.delete(elem);
|
|
3338
3605
|
});
|
|
3606
|
+
return el;
|
|
3339
3607
|
}
|
|
3340
3608
|
/**
|
|
3341
3609
|
* Removes all event listeners of all types from the element.
|
|
3342
3610
|
*
|
|
3343
3611
|
* @param {((handler: EventListenerOrEventListenerObject, event: string) => boolean)|null} [filterFn=null] -
|
|
3344
3612
|
* Optional filter function to selectively remove specific handlers.
|
|
3613
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
3345
3614
|
*/
|
|
3346
3615
|
offAllTypes(filterFn = null) {
|
|
3347
3616
|
return TinyHtml.offAllTypes(this, filterFn);
|
|
@@ -3352,6 +3621,7 @@ class TinyHtml {
|
|
|
3352
3621
|
* @param {TinyEventTarget|TinyEventTarget[]} el - Target element where the event should be triggered.
|
|
3353
3622
|
* @param {string} event - Name of the event to trigger.
|
|
3354
3623
|
* @param {Event|CustomEvent|CustomEventInit} [payload] - Optional event object or data to pass.
|
|
3624
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
3355
3625
|
*/
|
|
3356
3626
|
static trigger(el, event, payload = {}) {
|
|
3357
3627
|
if (typeof event !== 'string')
|
|
@@ -3366,12 +3636,14 @@ class TinyHtml {
|
|
|
3366
3636
|
});
|
|
3367
3637
|
elem.dispatchEvent(evt);
|
|
3368
3638
|
});
|
|
3639
|
+
return el;
|
|
3369
3640
|
}
|
|
3370
3641
|
/**
|
|
3371
3642
|
* Triggers all handlers associated with a specific event on the given element.
|
|
3372
3643
|
*
|
|
3373
3644
|
* @param {string} event - Name of the event to trigger.
|
|
3374
3645
|
* @param {Event|CustomEvent|CustomEventInit} [payload] - Optional event object or data to pass.
|
|
3646
|
+
* @returns {TinyEventTarget|TinyEventTarget[]}
|
|
3375
3647
|
*/
|
|
3376
3648
|
trigger(event, payload = {}) {
|
|
3377
3649
|
return TinyHtml.trigger(this, event, payload);
|
|
@@ -3410,6 +3682,7 @@ class TinyHtml {
|
|
|
3410
3682
|
* @param {TinyElement|TinyElement[]} el
|
|
3411
3683
|
* @param {string} name
|
|
3412
3684
|
* @param {string|null} [value=null]
|
|
3685
|
+
* @returns {TinyElement|TinyElement[]}
|
|
3413
3686
|
*/
|
|
3414
3687
|
static setAttr(el, name, value = null) {
|
|
3415
3688
|
if (typeof name !== 'string')
|
|
@@ -3422,11 +3695,13 @@ class TinyHtml {
|
|
|
3422
3695
|
else
|
|
3423
3696
|
elem.setAttribute(name, value);
|
|
3424
3697
|
});
|
|
3698
|
+
return el;
|
|
3425
3699
|
}
|
|
3426
3700
|
/**
|
|
3427
3701
|
* Set an attribute on an element.
|
|
3428
3702
|
* @param {string} name
|
|
3429
3703
|
* @param {string|null} [value=null]
|
|
3704
|
+
* @returns {TinyElement|TinyElement[]}
|
|
3430
3705
|
*/
|
|
3431
3706
|
setAttr(name, value) {
|
|
3432
3707
|
return TinyHtml.setAttr(this, name, value);
|
|
@@ -3435,15 +3710,18 @@ class TinyHtml {
|
|
|
3435
3710
|
* Remove attribute(s) from an element.
|
|
3436
3711
|
* @param {TinyElement|TinyElement[]} el
|
|
3437
3712
|
* @param {string} name Space-separated list of attributes.
|
|
3713
|
+
* @returns {TinyElement|TinyElement[]}
|
|
3438
3714
|
*/
|
|
3439
3715
|
static removeAttr(el, name) {
|
|
3440
3716
|
if (typeof name !== 'string')
|
|
3441
3717
|
throw new TypeError('The "name" must be a string.');
|
|
3442
3718
|
TinyHtml._preElems(el, 'removeAttr').forEach((elem) => elem.removeAttribute(name));
|
|
3719
|
+
return el;
|
|
3443
3720
|
}
|
|
3444
3721
|
/**
|
|
3445
3722
|
* Remove attribute(s) from an element.
|
|
3446
3723
|
* @param {string} name Space-separated list of attributes.
|
|
3724
|
+
* @returns {TinyElement|TinyElement[]}
|
|
3447
3725
|
*/
|
|
3448
3726
|
removeAttr(name) {
|
|
3449
3727
|
return TinyHtml.removeAttr(this, name);
|
|
@@ -3495,6 +3773,7 @@ class TinyHtml {
|
|
|
3495
3773
|
* Set a property on an element.
|
|
3496
3774
|
* @param {TinyElement|TinyElement[]} el
|
|
3497
3775
|
* @param {string} name
|
|
3776
|
+
* @returns {TinyElement|TinyElement[]}
|
|
3498
3777
|
*/
|
|
3499
3778
|
static addProp(el, name) {
|
|
3500
3779
|
if (typeof name !== 'string')
|
|
@@ -3505,10 +3784,12 @@ class TinyHtml {
|
|
|
3505
3784
|
// @ts-ignore
|
|
3506
3785
|
elem[name] = true;
|
|
3507
3786
|
});
|
|
3787
|
+
return el;
|
|
3508
3788
|
}
|
|
3509
3789
|
/**
|
|
3510
3790
|
* Set a property on an element.
|
|
3511
3791
|
* @param {string} name
|
|
3792
|
+
* @returns {TinyElement|TinyElement[]}
|
|
3512
3793
|
*/
|
|
3513
3794
|
addProp(name) {
|
|
3514
3795
|
return TinyHtml.addProp(this, name);
|
|
@@ -3517,6 +3798,7 @@ class TinyHtml {
|
|
|
3517
3798
|
* Remove a property from an element.
|
|
3518
3799
|
* @param {TinyElement|TinyElement[]} el
|
|
3519
3800
|
* @param {string} name
|
|
3801
|
+
* @returns {TinyElement|TinyElement[]}
|
|
3520
3802
|
*/
|
|
3521
3803
|
static removeProp(el, name) {
|
|
3522
3804
|
if (typeof name !== 'string')
|
|
@@ -3527,10 +3809,12 @@ class TinyHtml {
|
|
|
3527
3809
|
// @ts-ignore
|
|
3528
3810
|
elem[name] = false;
|
|
3529
3811
|
});
|
|
3812
|
+
return el;
|
|
3530
3813
|
}
|
|
3531
3814
|
/**
|
|
3532
3815
|
* Remove a property from an element.
|
|
3533
3816
|
* @param {string} name
|
|
3817
|
+
* @returns {TinyElement|TinyElement[]}
|
|
3534
3818
|
*/
|
|
3535
3819
|
removeProp(name) {
|
|
3536
3820
|
return TinyHtml.removeProp(this, name);
|
|
@@ -3570,12 +3854,15 @@ class TinyHtml {
|
|
|
3570
3854
|
/**
|
|
3571
3855
|
* Removes an element from the DOM.
|
|
3572
3856
|
* @param {TinyElement|TinyElement[]} el - The DOM element or selector to remove.
|
|
3857
|
+
* @returns {TinyElement|TinyElement[]}
|
|
3573
3858
|
*/
|
|
3574
3859
|
static remove(el) {
|
|
3575
3860
|
TinyHtml._preElems(el, 'remove').forEach((elem) => elem.remove());
|
|
3861
|
+
return el;
|
|
3576
3862
|
}
|
|
3577
3863
|
/**
|
|
3578
3864
|
* Removes the element from the DOM.
|
|
3865
|
+
* @returns {TinyElement|TinyElement[]}
|
|
3579
3866
|
*/
|
|
3580
3867
|
remove() {
|
|
3581
3868
|
return TinyHtml.remove(this);
|
|
@@ -3886,6 +4173,12 @@ class TinyHtml {
|
|
|
3886
4173
|
*/
|
|
3887
4174
|
static isInViewport(el) {
|
|
3888
4175
|
const elem = TinyHtml._preElem(el, 'isInViewport');
|
|
4176
|
+
if (!elem.checkVisibility({
|
|
4177
|
+
contentVisibilityAuto: false,
|
|
4178
|
+
opacityProperty: false,
|
|
4179
|
+
visibilityProperty: false,
|
|
4180
|
+
}))
|
|
4181
|
+
return false;
|
|
3889
4182
|
const elementTop = TinyHtml.offset(elem).top;
|
|
3890
4183
|
const elementBottom = elementTop + TinyHtml.outerHeight(elem);
|
|
3891
4184
|
const viewportTop = TinyHtml.scrollTop(window);
|
|
@@ -3908,6 +4201,12 @@ class TinyHtml {
|
|
|
3908
4201
|
*/
|
|
3909
4202
|
static isScrolledIntoView(el) {
|
|
3910
4203
|
const elem = TinyHtml._preElem(el, 'isScrolledIntoView');
|
|
4204
|
+
if (!elem.checkVisibility({
|
|
4205
|
+
contentVisibilityAuto: false,
|
|
4206
|
+
opacityProperty: false,
|
|
4207
|
+
visibilityProperty: false,
|
|
4208
|
+
}))
|
|
4209
|
+
return false;
|
|
3911
4210
|
const docViewTop = TinyHtml.scrollTop(window);
|
|
3912
4211
|
const docViewBottom = docViewTop + TinyHtml.height(window);
|
|
3913
4212
|
const elemTop = TinyHtml.offset(elem).top;
|
|
@@ -3922,5 +4221,90 @@ class TinyHtml {
|
|
|
3922
4221
|
isScrolledIntoView() {
|
|
3923
4222
|
return TinyHtml.isScrolledIntoView(this);
|
|
3924
4223
|
}
|
|
4224
|
+
/**
|
|
4225
|
+
* Checks if the given element is at least partially visible within the boundaries of a container.
|
|
4226
|
+
*
|
|
4227
|
+
* @param {TinyElement} el - The DOM element to check.
|
|
4228
|
+
* @param {TinyElement} cont - The container element acting as the viewport.
|
|
4229
|
+
* @returns {boolean} True if the element is partially visible within the container, false otherwise.
|
|
4230
|
+
*/
|
|
4231
|
+
static isInContainer(el, cont) {
|
|
4232
|
+
const elem = TinyHtml._preElem(el, 'isInContainer');
|
|
4233
|
+
const container = TinyHtml._preElem(cont, 'isInContainer');
|
|
4234
|
+
if (!elem.checkVisibility({
|
|
4235
|
+
contentVisibilityAuto: false,
|
|
4236
|
+
opacityProperty: false,
|
|
4237
|
+
visibilityProperty: false,
|
|
4238
|
+
}))
|
|
4239
|
+
return false;
|
|
4240
|
+
const elemRect = elem.getBoundingClientRect();
|
|
4241
|
+
const containerRect = container.getBoundingClientRect();
|
|
4242
|
+
const verticallyVisible = elemRect.bottom > containerRect.top && elemRect.top < containerRect.bottom;
|
|
4243
|
+
const horizontallyVisible = elemRect.right > containerRect.left && elemRect.left < containerRect.right;
|
|
4244
|
+
return verticallyVisible && horizontallyVisible;
|
|
4245
|
+
}
|
|
4246
|
+
/**
|
|
4247
|
+
* Checks if the given element is at least partially visible within the boundaries of a container.
|
|
4248
|
+
*
|
|
4249
|
+
* @param {TinyElement} cont - The container element acting as the viewport.
|
|
4250
|
+
* @returns {boolean} True if the element is partially visible within the container, false otherwise.
|
|
4251
|
+
*/
|
|
4252
|
+
isInContainer(cont) {
|
|
4253
|
+
return TinyHtml.isInContainer(this, cont);
|
|
4254
|
+
}
|
|
4255
|
+
/**
|
|
4256
|
+
* Checks if the given element is fully visible within the boundaries of a container (top and bottom).
|
|
4257
|
+
*
|
|
4258
|
+
* @param {TinyElement} el - The DOM element to check.
|
|
4259
|
+
* @param {TinyElement} cont - The container element acting as the viewport.
|
|
4260
|
+
* @returns {boolean} True if the element is fully visible within the container, false otherwise.
|
|
4261
|
+
*/
|
|
4262
|
+
static isFullyInContainer(el, cont) {
|
|
4263
|
+
const elem = TinyHtml._preElem(el, 'isScrolledIntoView');
|
|
4264
|
+
const container = TinyHtml._preElem(cont, 'isInContainer');
|
|
4265
|
+
if (!elem.checkVisibility({
|
|
4266
|
+
contentVisibilityAuto: false,
|
|
4267
|
+
opacityProperty: false,
|
|
4268
|
+
visibilityProperty: false,
|
|
4269
|
+
}))
|
|
4270
|
+
return false;
|
|
4271
|
+
const elemRect = elem.getBoundingClientRect();
|
|
4272
|
+
const containerRect = container.getBoundingClientRect();
|
|
4273
|
+
const isFullyVisible = elemRect.top >= containerRect.top &&
|
|
4274
|
+
elemRect.bottom <= containerRect.bottom &&
|
|
4275
|
+
elemRect.left >= containerRect.left &&
|
|
4276
|
+
elemRect.right <= containerRect.right;
|
|
4277
|
+
return isFullyVisible;
|
|
4278
|
+
}
|
|
4279
|
+
/**
|
|
4280
|
+
* Checks if the given element is fully visible within the boundaries of a container (top and bottom).
|
|
4281
|
+
*
|
|
4282
|
+
* @param {TinyElement} cont - The container element acting as the viewport.
|
|
4283
|
+
* @returns {boolean} True if the element is fully visible within the container, false otherwise.
|
|
4284
|
+
*/
|
|
4285
|
+
isFullyInContainer(cont) {
|
|
4286
|
+
return TinyHtml.isFullyInContainer(this, cont);
|
|
4287
|
+
}
|
|
4288
|
+
/**
|
|
4289
|
+
* Checks if an element has scrollable content.
|
|
4290
|
+
*
|
|
4291
|
+
* @param {TinyElement} el - The DOM element to check.
|
|
4292
|
+
* @returns {{ v: boolean, h: boolean }} - True if scroll is needed in that direction.
|
|
4293
|
+
*/
|
|
4294
|
+
static hasScroll(el) {
|
|
4295
|
+
const elem = TinyHtml._preElem(el, 'hasScroll');
|
|
4296
|
+
return {
|
|
4297
|
+
v: elem.scrollHeight > elem.clientHeight,
|
|
4298
|
+
h: elem.scrollWidth > elem.clientWidth,
|
|
4299
|
+
};
|
|
4300
|
+
}
|
|
4301
|
+
/**
|
|
4302
|
+
* Checks if an element has scrollable content.
|
|
4303
|
+
*
|
|
4304
|
+
* @returns {{ v: boolean, h: boolean }} - True if scroll is needed in that direction.
|
|
4305
|
+
*/
|
|
4306
|
+
hasScroll() {
|
|
4307
|
+
return TinyHtml.hasScroll(this);
|
|
4308
|
+
}
|
|
3925
4309
|
}
|
|
3926
4310
|
export default TinyHtml;
|