tiny-essentials 1.16.2 → 1.17.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (133) hide show
  1. package/dist/legacy/crypto/decrypt.cjs +1 -0
  2. package/dist/legacy/crypto/decrypt.d.mts +1 -0
  3. package/dist/legacy/crypto/decrypt.mjs +1 -0
  4. package/dist/legacy/crypto/encrypt.cjs +1 -0
  5. package/dist/legacy/crypto/encrypt.d.mts +1 -0
  6. package/dist/legacy/crypto/encrypt.mjs +1 -0
  7. package/dist/legacy/get/decimalColor.cjs +1 -0
  8. package/dist/legacy/get/decimalColor.d.mts +1 -0
  9. package/dist/legacy/get/decimalColor.mjs +1 -0
  10. package/dist/legacy/get/pagination.cjs +1 -0
  11. package/dist/legacy/get/pagination.d.mts +1 -0
  12. package/dist/legacy/get/pagination.mjs +1 -0
  13. package/dist/legacy/get/queryUrlByName.cjs +1 -0
  14. package/dist/legacy/get/queryUrlByName.d.mts +1 -0
  15. package/dist/legacy/get/queryUrlByName.mjs +1 -0
  16. package/dist/legacy/get/queryUrlJSON.cjs +1 -0
  17. package/dist/legacy/get/queryUrlJSON.d.mts +1 -0
  18. package/dist/legacy/get/queryUrlJSON.mjs +1 -0
  19. package/dist/legacy/get/super_string_filter.cjs +1 -0
  20. package/dist/legacy/get/super_string_filter.d.mts +1 -0
  21. package/dist/legacy/get/super_string_filter.mjs +1 -0
  22. package/dist/legacy/get/versionCheck.cjs +1 -0
  23. package/dist/legacy/get/versionCheck.d.mts +1 -0
  24. package/dist/legacy/get/versionCheck.mjs +1 -0
  25. package/dist/legacy/http/HTTP-1.0.cjs +2 -0
  26. package/dist/legacy/http/HTTP-1.0.mjs +2 -0
  27. package/dist/legacy/http/auth.cjs +1 -0
  28. package/dist/legacy/http/auth.d.mts +1 -0
  29. package/dist/legacy/http/auth.mjs +1 -0
  30. package/dist/legacy/http/check_domain.cjs +11 -0
  31. package/dist/legacy/http/check_domain.d.mts +3 -0
  32. package/dist/legacy/http/check_domain.mjs +11 -0
  33. package/dist/legacy/http/csrfTokenAnalyze.cjs +1 -0
  34. package/dist/legacy/http/csrfTokenAnalyze.d.mts +1 -0
  35. package/dist/legacy/http/csrfTokenAnalyze.mjs +1 -0
  36. package/dist/legacy/http/domainValidator.cjs +1 -0
  37. package/dist/legacy/http/domainValidator.d.mts +1 -0
  38. package/dist/legacy/http/domainValidator.mjs +1 -0
  39. package/dist/legacy/http/errorsCallback.cjs +1 -0
  40. package/dist/legacy/http/errorsCallback.d.mts +1 -0
  41. package/dist/legacy/http/errorsCallback.mjs +1 -0
  42. package/dist/legacy/http/fetch/json.cjs +1 -0
  43. package/dist/legacy/http/fetch/json.d.mts +1 -0
  44. package/dist/legacy/http/fetch/json.mjs +1 -0
  45. package/dist/legacy/http/fetch/text.cjs +1 -0
  46. package/dist/legacy/http/fetch/text.d.mts +1 -0
  47. package/dist/legacy/http/fetch/text.mjs +1 -0
  48. package/dist/legacy/http/fileCache.cjs +1 -0
  49. package/dist/legacy/http/fileCache.d.mts +1 -0
  50. package/dist/legacy/http/fileCache.mjs +1 -0
  51. package/dist/legacy/http/getDomainURL.cjs +1 -0
  52. package/dist/legacy/http/getDomainURL.d.mts +1 -0
  53. package/dist/legacy/http/getDomainURL.mjs +1 -0
  54. package/dist/legacy/http/userIP.cjs +1 -0
  55. package/dist/legacy/http/userIP.d.mts +1 -0
  56. package/dist/legacy/http/userIP.mjs +1 -0
  57. package/dist/legacy/libs/capitalize.cjs +1 -0
  58. package/dist/legacy/libs/capitalize.d.mts +1 -0
  59. package/dist/legacy/libs/capitalize.mjs +1 -0
  60. package/dist/legacy/libs/convertBytes.cjs +2 -0
  61. package/dist/legacy/libs/convertBytes.mjs +2 -0
  62. package/dist/legacy/libs/custom_module_loader.cjs +2 -0
  63. package/dist/legacy/libs/custom_module_loader.mjs +2 -0
  64. package/dist/legacy/libs/dice.cjs +2 -0
  65. package/dist/legacy/libs/dice.mjs +2 -0
  66. package/dist/legacy/libs/markdown.cjs +1 -0
  67. package/dist/legacy/libs/markdown.mjs +1 -0
  68. package/dist/legacy/libs/percentage.cjs +1 -0
  69. package/dist/legacy/libs/percentage.mjs +1 -0
  70. package/dist/legacy/libs/regex/getLetter.cjs +2 -0
  71. package/dist/legacy/libs/regex/getLetter.d.mts +2 -0
  72. package/dist/legacy/libs/regex/getLetter.mjs +2 -0
  73. package/dist/legacy/libs/rule3.cjs +1 -0
  74. package/dist/legacy/libs/rule3.mjs +1 -0
  75. package/dist/legacy/momentjs/getAge.cjs +1 -0
  76. package/dist/legacy/momentjs/getAge.d.mts +1 -0
  77. package/dist/legacy/momentjs/getAge.mjs +1 -0
  78. package/dist/legacy/momentjs/timeDuration.cjs +1 -0
  79. package/dist/legacy/momentjs/timeDuration.d.mts +1 -0
  80. package/dist/legacy/momentjs/timeDuration.mjs +1 -0
  81. package/dist/legacy/socket.io/antiFlood/install.cjs +1 -0
  82. package/dist/legacy/socket.io/antiFlood/install.d.mts +1 -0
  83. package/dist/legacy/socket.io/antiFlood/install.mjs +1 -0
  84. package/dist/legacy/socket.io/antiFlood/verify.cjs +1 -0
  85. package/dist/legacy/socket.io/antiFlood/verify.d.mts +1 -0
  86. package/dist/legacy/socket.io/antiFlood/verify.mjs +1 -0
  87. package/dist/legacy/socket.io/cookie-session.cjs +1 -0
  88. package/dist/legacy/socket.io/cookie-session.d.mts +1 -0
  89. package/dist/legacy/socket.io/cookie-session.mjs +1 -0
  90. package/dist/legacy/socket.io/discord.cjs +1 -0
  91. package/dist/legacy/socket.io/discord.d.mts +1 -0
  92. package/dist/legacy/socket.io/discord.mjs +1 -0
  93. package/dist/v1/TinyBasicsEs.js +729 -93
  94. package/dist/v1/TinyBasicsEs.min.js +1 -1
  95. package/dist/v1/TinyDragger.js +656 -69
  96. package/dist/v1/TinyDragger.min.js +1 -1
  97. package/dist/v1/TinyEssentials.js +2688 -116
  98. package/dist/v1/TinyEssentials.min.js +1 -1
  99. package/dist/v1/TinyHtml.js +656 -69
  100. package/dist/v1/TinyHtml.min.js +1 -1
  101. package/dist/v1/TinySmartScroller.js +6378 -0
  102. package/dist/v1/TinySmartScroller.min.js +1 -0
  103. package/dist/v1/TinyUploadClicker.js +1732 -118
  104. package/dist/v1/TinyUploadClicker.min.js +1 -1
  105. package/dist/v1/UltraRandomMsgGen.js +995 -0
  106. package/dist/v1/UltraRandomMsgGen.min.js +1 -0
  107. package/dist/v1/basics/html.cjs +74 -24
  108. package/dist/v1/basics/html.d.mts +38 -15
  109. package/dist/v1/basics/html.mjs +63 -20
  110. package/dist/v1/build/TinySmartScroller.cjs +7 -0
  111. package/dist/v1/build/TinySmartScroller.d.mts +3 -0
  112. package/dist/v1/build/TinySmartScroller.mjs +2 -0
  113. package/dist/v1/build/UltraRandomMsgGen.cjs +7 -0
  114. package/dist/v1/build/UltraRandomMsgGen.d.mts +3 -0
  115. package/dist/v1/build/UltraRandomMsgGen.mjs +2 -0
  116. package/dist/v1/index.cjs +4 -0
  117. package/dist/v1/index.d.mts +3 -1
  118. package/dist/v1/index.mjs +3 -1
  119. package/dist/v1/libs/TinyHtml.cjs +656 -69
  120. package/dist/v1/libs/TinyHtml.d.mts +440 -139
  121. package/dist/v1/libs/TinyHtml.mjs +591 -72
  122. package/dist/v1/libs/TinySmartScroller.cjs +976 -0
  123. package/dist/v1/libs/TinySmartScroller.d.mts +458 -0
  124. package/dist/v1/libs/TinySmartScroller.mjs +856 -0
  125. package/dist/v1/libs/UltraRandomMsgGen.cjs +956 -0
  126. package/dist/v1/libs/UltraRandomMsgGen.d.mts +390 -0
  127. package/dist/v1/libs/UltraRandomMsgGen.mjs +825 -0
  128. package/docs/v1/README.md +2 -0
  129. package/docs/v1/basics/html.md +17 -2
  130. package/docs/v1/libs/TinyHtml.md +296 -8
  131. package/docs/v1/libs/TinySmartScroller.md +523 -0
  132. package/docs/v1/libs/UltraRandomMsgGen.md +289 -0
  133. package/package.json +1 -1
@@ -1,5 +1,16 @@
1
1
  import * as TinyCollision from '../basics/collision.mjs';
2
2
  const { areElsColliding, areElsPerfColliding, areElsCollTop, areElsCollBottom, areElsCollLeft, areElsCollRight, } = TinyCollision;
3
+ /**
4
+ * Callback invoked on each animation frame with the current scroll position,
5
+ * normalized animation time (`0` to `1`), and a completion flag.
6
+ *
7
+ * @typedef {(progress: { x: number, y: number, isComplete: boolean, time: number }) => void} OnScrollAnimation
8
+ */
9
+ /**
10
+ * A list of supported easing function names for smooth animations.
11
+ *
12
+ * @typedef {'linear' | 'easeInQuad' | 'easeOutQuad' | 'easeInOutQuad' | 'easeInCubic' | 'easeOutCubic' | 'easeInOutCubic'} Easings
13
+ */
3
14
  /**
4
15
  * Represents a raw Node element or an instance of TinyHtml.
5
16
  * This type is used to abstract interactions with both plain elements
@@ -48,6 +59,19 @@ const { areElsColliding, areElsPerfColliding, areElsCollTop, areElsCollBottom, a
48
59
  *
49
60
  * @typedef {Element|Window} ElementAndWindow
50
61
  */
62
+ /**
63
+ * Represents a raw DOM element/window/document or an instance of TinyHtml.
64
+ * This type is used to abstract interactions with both plain elements
65
+ * and wrapped elements via the TinyHtml class.
66
+ *
67
+ * @typedef {ElementAndWinAndDoc|TinyHtml} TinyElementAndWinAndDoc
68
+ */
69
+ /**
70
+ * Represents a value that can be either a DOM Element, or the global Window object, or the document object.
71
+ * Useful for functions that operate generically on scrollable or measurable targets.
72
+ *
73
+ * @typedef {Element|Window|Document} ElementAndWinAndDoc
74
+ */
51
75
  /**
52
76
  * A parameter type used for filtering or matching elements.
53
77
  * It can be:
@@ -63,7 +87,7 @@ const { areElsColliding, areElsPerfColliding, areElsCollTop, areElsCollBottom, a
63
87
  * Elements accepted as constructor values for TinyHtml.
64
88
  * These include common DOM elements and root containers.
65
89
  *
66
- * @typedef {Window|Element|Document} ConstructorElValues
90
+ * @typedef {Window|Element|Document|Text} ConstructorElValues
67
91
  */
68
92
  /**
69
93
  * The handler function used in event listeners.
@@ -167,52 +191,130 @@ const __elemCollision = {
167
191
  class TinyHtml {
168
192
  /** @typedef {import('../basics/collision.mjs').ObjRect} ObjRect */
169
193
  static Utils = { ...TinyCollision };
194
+ /**
195
+ * Creates a new DOM element with the specified tag name and options, then wraps it in a TinyHtml instance.
196
+ *
197
+ * @param {string} tagName - The tag name of the element to create (e.g., 'div', 'span').
198
+ * @param {ElementCreationOptions} ops - Optional settings for creating the element.
199
+ * @returns {TinyHtml} A TinyHtml instance wrapping the newly created DOM element.
200
+ * @throws {TypeError} If tagName is not a string or ops is not an object.
201
+ */
202
+ static createElement(tagName, ops) {
203
+ if (typeof tagName !== 'string')
204
+ throw new TypeError(`[TinyHtml] createElement(): The tagName must be a string.`);
205
+ if (typeof ops !== 'undefined' && typeof ops !== 'object')
206
+ throw new TypeError(`[TinyHtml] createElement(): The ops must be a object.`);
207
+ return new TinyHtml(document.createElement(tagName, ops));
208
+ }
209
+ /**
210
+ * Creates a new TinyHtml instance that wraps a DOM TextNode.
211
+ *
212
+ * This method is useful when you want to insert raw text content into the DOM
213
+ * without it being interpreted as HTML. The returned instance behaves like any
214
+ * other TinyHtml element and can be appended or manipulated as needed.
215
+ *
216
+ * @param {string} value - The plain text content to be wrapped in a TextNode.
217
+ * @returns {TinyHtml} A TinyHtml instance wrapping the newly created DOM TextNode.
218
+ * @throws {TypeError} If the provided value is not a string.
219
+ */
220
+ static createTextNode(value) {
221
+ if (typeof value !== 'string')
222
+ throw new TypeError(`[TinyHtml] createTextNode(): The value must be a string.`);
223
+ return new TinyHtml(document.createTextNode(value));
224
+ }
225
+ /**
226
+ * Creates an HTMLElement or TextNode from an HTML string.
227
+ * Supports both elements and plain text.
228
+ *
229
+ * @param {string} htmlString - The HTML string to convert.
230
+ * @returns {TinyHtml} - A single HTMLElement or TextNode.
231
+ */
232
+ static createElementFromHTML(htmlString) {
233
+ const template = document.createElement('template');
234
+ htmlString = htmlString.trim();
235
+ // If it's only text (e.g., no "<" tag), return a TextNode
236
+ if (!htmlString.startsWith('<')) {
237
+ return TinyHtml.createTextNode(htmlString);
238
+ }
239
+ template.innerHTML = htmlString;
240
+ if (!(template.content.firstChild instanceof Element))
241
+ throw new Error('');
242
+ return new TinyHtml(template.content.firstChild);
243
+ }
170
244
  /**
171
245
  * Queries the document for the first element matching the CSS selector and wraps it in a TinyHtml instance.
172
246
  *
173
247
  * @param {string} selector - A valid CSS selector string.
174
- * @returns {TinyHtml} A TinyHtml instance wrapping the matched element.
175
- * @throws {Error} If no element matches the selector.
248
+ * @param {Document|Element} elem - Target element.
249
+ * @returns {TinyHtml|null} A TinyHtml instance wrapping the matched element.
176
250
  */
177
- static query(selector) {
178
- const newEl = document.querySelector(selector);
251
+ static query(selector, elem = document) {
252
+ const newEl = elem.querySelector(selector);
179
253
  if (!newEl)
180
- throw new Error(`[TinyHtml] query(): No element found for selector "${selector}".`);
254
+ return null;
181
255
  return new TinyHtml(newEl);
182
256
  }
257
+ /**
258
+ * Queries the element for the first element matching the CSS selector and wraps it in a TinyHtml instance.
259
+ *
260
+ * @param {string} selector - A valid CSS selector string.
261
+ * @returns {TinyHtml|null} A TinyHtml instance wrapping the matched element.
262
+ */
263
+ querySelector(selector) {
264
+ return TinyHtml.query(selector, TinyHtml._preElem(this, 'query'));
265
+ }
183
266
  /**
184
267
  * Queries the document for all elements matching the CSS selector and wraps them in TinyHtml instances.
185
268
  *
186
269
  * @param {string} selector - A valid CSS selector string.
270
+ * @param {Document|Element} elem - Target element.
187
271
  * @returns {TinyHtml[]} An array of TinyHtml instances wrapping the matched elements.
188
272
  */
189
- static queryAll(selector) {
190
- const newEls = document.querySelectorAll(selector);
273
+ static queryAll(selector, elem = document) {
274
+ const newEls = elem.querySelectorAll(selector);
191
275
  return TinyHtml.toTinyElm([...newEls]);
192
276
  }
277
+ /**
278
+ * Queries the element for all elements matching the CSS selector and wraps them in TinyHtml instances.
279
+ *
280
+ * @param {string} selector - A valid CSS selector string.
281
+ * @returns {TinyHtml[]} An array of TinyHtml instances wrapping the matched elements.
282
+ */
283
+ querySelectorAll(selector) {
284
+ return TinyHtml.queryAll(selector, TinyHtml._preElem(this, 'queryAll'));
285
+ }
193
286
  /**
194
287
  * Retrieves an element by its ID and wraps it in a TinyHtml instance.
195
288
  *
196
289
  * @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.
290
+ * @returns {TinyHtml|null} A TinyHtml instance wrapping the found element.
199
291
  */
200
292
  static getById(selector) {
201
293
  const newEl = document.getElementById(selector);
202
294
  if (!newEl)
203
- throw new Error(`[TinyHtml] getById(): No element found with ID "${selector}".`);
295
+ return null;
204
296
  return new TinyHtml(newEl);
205
297
  }
206
298
  /**
207
299
  * Retrieves all elements with the specified class name and wraps them in TinyHtml instances.
208
300
  *
209
301
  * @param {string} selector - The class name to search for.
302
+ * @param {Document|Element} elem - Target element.
210
303
  * @returns {TinyHtml[]} An array of TinyHtml instances wrapping the found elements.
211
304
  */
212
- static getByClassName(selector) {
213
- const newEls = document.getElementsByClassName(selector);
305
+ static getByClassName(selector, elem = document) {
306
+ const newEls = elem.getElementsByClassName(selector);
214
307
  return TinyHtml.toTinyElm([...newEls]);
215
308
  }
309
+ /**
310
+ * Retrieves all elements with the specified class name and wraps them in TinyHtml instances.
311
+ *
312
+ * @param {string} selector - The class name to search for.
313
+ * @returns {TinyHtml[]} An array of TinyHtml instances wrapping the found elements.
314
+ */
315
+ getElementsByClassName(selector) {
316
+ return TinyHtml.getByClassName(selector, TinyHtml._preElem(this, 'getByClassName'));
317
+ }
216
318
  /**
217
319
  * Retrieves all elements with the specified name attribute and wraps them in TinyHtml instances.
218
320
  *
@@ -229,12 +331,24 @@ class TinyHtml {
229
331
  *
230
332
  * @param {string} localName - The local name (tag) of the elements to search for.
231
333
  * @param {string|null} [namespaceURI='http://www.w3.org/1999/xhtml'] - The namespace URI to search within.
334
+ * @param {Document|Element} elem - Target element.
232
335
  * @returns {TinyHtml[]} An array of TinyHtml instances wrapping the found elements.
233
336
  */
234
- static getByTagNameNS(localName, namespaceURI = 'http://www.w3.org/1999/xhtml') {
235
- const newEls = document.getElementsByTagNameNS(namespaceURI, localName);
337
+ static getByTagNameNS(localName, namespaceURI = 'http://www.w3.org/1999/xhtml', elem = document) {
338
+ const newEls = elem.getElementsByTagNameNS(namespaceURI, localName);
236
339
  return TinyHtml.toTinyElm([...newEls]);
237
340
  }
341
+ /**
342
+ * Retrieves all elements with the specified local tag name within the given namespace URI,
343
+ * and wraps them in TinyHtml instances.
344
+ *
345
+ * @param {string} localName - The local name (tag) of the elements to search for.
346
+ * @param {string|null} [namespaceURI='http://www.w3.org/1999/xhtml'] - The namespace URI to search within.
347
+ * @returns {TinyHtml[]} An array of TinyHtml instances wrapping the found elements.
348
+ */
349
+ getElementsByTagNameNS(localName, namespaceURI = 'http://www.w3.org/1999/xhtml') {
350
+ return TinyHtml.getByTagNameNS(localName, namespaceURI, TinyHtml._preElem(this, 'getByTagNameNS'));
351
+ }
238
352
  //////////////////////////////////////////////////////////////////
239
353
  /**
240
354
  * Returns the current target held by this instance.
@@ -477,6 +591,34 @@ class TinyHtml {
477
591
  static _preElemAndWindow(elems, where) {
478
592
  return TinyHtml._preElemTemplate(elems, where, [Element, Window], ['Element', 'Window']);
479
593
  }
594
+ /**
595
+ * Ensures the input is returned as an array.
596
+ * Useful to normalize operations across multiple or single element/window/document elements.
597
+ *
598
+ * @param {TinyElementAndWinAndDoc|TinyElementAndWinAndDoc[]} elems - A single element/window element or array of html elements.
599
+ * @param {string} where - The method or context name where validation is being called.
600
+ * @returns {ElementAndWindow[]} - Always returns an array of element/window elements.
601
+ * @readonly
602
+ */
603
+ static _preElemsAndWinAndDoc(elems, where) {
604
+ const result = TinyHtml._preElemsTemplate(elems, where, [Element, Window, Document], ['Element', 'Window', 'Document']);
605
+ return result.map((elem) => (!(elem instanceof Document) ? elem : elem.documentElement));
606
+ }
607
+ /**
608
+ * Ensures the input is returned as an single element/window/document element.
609
+ * Useful to normalize operations across multiple or single element/window/document elements.
610
+ *
611
+ * @param {TinyElementAndWinAndDoc|TinyElementAndWinAndDoc[]} elems - A single element/window element or array of html elements.
612
+ * @param {string} where - The method or context name where validation is being called.
613
+ * @returns {ElementAndWindow} - Always returns an single element/window element.
614
+ * @readonly
615
+ */
616
+ static _preElemAndWinAndDoc(elems, where) {
617
+ const result = TinyHtml._preElemTemplate(elems, where, [Element, Window, Document], ['Element', 'Window', 'Document']);
618
+ if (result instanceof Document)
619
+ return result.documentElement;
620
+ return result;
621
+ }
480
622
  /**
481
623
  * Normalizes and converts one or more DOM elements (or TinyHtml instances)
482
624
  * into an array of `TinyHtml` instances.
@@ -779,13 +921,14 @@ class TinyHtml {
779
921
  * @param {string} key - The key under which the data will be stored.
780
922
  * @param {any} value - The value to store.
781
923
  * @param {boolean} [isPrivate=false] - Whether to store the data in the private store.
782
- * @returns {void}
924
+ * @returns {TinyElement}
783
925
  */
784
926
  static setData(el, key, value, isPrivate = false) {
785
927
  const data = TinyHtml._dataSelector[!isPrivate ? 'public' : 'private']('setData', el);
786
928
  if (typeof key !== 'string')
787
929
  throw new TypeError('The key must be a string.');
788
930
  data[key] = value;
931
+ return el;
789
932
  }
790
933
  /**
791
934
  * Stores a value associated with a specific key for a DOM element.
@@ -793,7 +936,7 @@ class TinyHtml {
793
936
  * @param {string} key - The key under which the data will be stored.
794
937
  * @param {any} value - The value to store.
795
938
  * @param {boolean} [isPrivate=false] - Whether to store the data in the private store.
796
- * @returns {void}
939
+ * @returns {TinyElement}
797
940
  */
798
941
  setData(key, value, isPrivate = false) {
799
942
  return TinyHtml.setData(this, key, value, isPrivate);
@@ -1111,17 +1254,20 @@ class TinyHtml {
1111
1254
  /**
1112
1255
  * Appends child elements or strings to the end of the target element(s).
1113
1256
  *
1114
- * @param {TinyElement | TinyElement[]} el - The target element(s) to receive children.
1257
+ * @param {TinyElement} el - The target element(s) to receive children.
1115
1258
  * @param {...(TinyNode | TinyNode[] | string)} children - The child elements or text to append.
1259
+ * @returns {TinyElement}
1116
1260
  */
1117
1261
  static append(el, ...children) {
1118
1262
  const elem = TinyHtml._preElem(el, 'append');
1119
1263
  elem.append(...TinyHtml._appendChecker('append', ...children));
1264
+ return el;
1120
1265
  }
1121
1266
  /**
1122
1267
  * Appends child elements or strings to the end of the target element(s).
1123
1268
  *
1124
1269
  * @param {...(TinyNode | TinyNode[] | string)} children - The child elements or text to append.
1270
+ * @returns {TinyElement}
1125
1271
  */
1126
1272
  append(...children) {
1127
1273
  return TinyHtml.append(this, ...children);
@@ -1129,17 +1275,20 @@ class TinyHtml {
1129
1275
  /**
1130
1276
  * Prepends child elements or strings to the beginning of the target element(s).
1131
1277
  *
1132
- * @param {TinyElement | TinyElement[]} el - The target element(s) to receive children.
1278
+ * @param {TinyElement} el - The target element(s) to receive children.
1133
1279
  * @param {...(TinyNode | TinyNode[] | string)} children - The child elements or text to prepend.
1280
+ * @returns {TinyElement}
1134
1281
  */
1135
1282
  static prepend(el, ...children) {
1136
1283
  const elem = TinyHtml._preElem(el, 'prepend');
1137
1284
  elem.prepend(...TinyHtml._appendChecker('prepend', ...children));
1285
+ return el;
1138
1286
  }
1139
1287
  /**
1140
1288
  * Prepends child elements or strings to the beginning of the target element(s).
1141
1289
  *
1142
1290
  * @param {...(TinyNode | TinyNode[] | string)} children - The child elements or text to prepend.
1291
+ * @returns {TinyElement}
1143
1292
  */
1144
1293
  prepend(...children) {
1145
1294
  return TinyHtml.prepend(this, ...children);
@@ -1147,17 +1296,20 @@ class TinyHtml {
1147
1296
  /**
1148
1297
  * Inserts elements or strings immediately before the target element(s) in the DOM.
1149
1298
  *
1150
- * @param {TinyElement | TinyElement[]} el - The target element(s) before which new content is inserted.
1299
+ * @param {TinyElement} el - The target element(s) before which new content is inserted.
1151
1300
  * @param {...(TinyNode | TinyNode[] | string)} children - Elements or text to insert before the target.
1301
+ * @returns {TinyElement}
1152
1302
  */
1153
1303
  static before(el, ...children) {
1154
1304
  const elem = TinyHtml._preElem(el, 'before');
1155
1305
  elem.before(...TinyHtml._appendChecker('before', ...children));
1306
+ return el;
1156
1307
  }
1157
1308
  /**
1158
1309
  * Inserts elements or strings immediately before the target element(s) in the DOM.
1159
1310
  *
1160
1311
  * @param {...(TinyNode | TinyNode[] | string)} children - Elements or text to insert before the target.
1312
+ * @returns {TinyElement}
1161
1313
  */
1162
1314
  before(...children) {
1163
1315
  return TinyHtml.before(this, ...children);
@@ -1165,17 +1317,20 @@ class TinyHtml {
1165
1317
  /**
1166
1318
  * Inserts elements or strings immediately after the target element(s) in the DOM.
1167
1319
  *
1168
- * @param {TinyElement | TinyElement[]} el - The target element(s) after which new content is inserted.
1320
+ * @param {TinyElement} el - The target element(s) after which new content is inserted.
1169
1321
  * @param {...(TinyNode | TinyNode[] | string)} children - Elements or text to insert after the target.
1322
+ * @returns {TinyElement}
1170
1323
  */
1171
1324
  static after(el, ...children) {
1172
1325
  const elem = TinyHtml._preElem(el, 'after');
1173
1326
  elem.after(...TinyHtml._appendChecker('after', ...children));
1327
+ return el;
1174
1328
  }
1175
1329
  /**
1176
1330
  * Inserts elements or strings immediately after the target element(s) in the DOM.
1177
1331
  *
1178
1332
  * @param {...(TinyNode | TinyNode[] | string)} children - Elements or text to insert after the target.
1333
+ * @returns {TinyElement}
1179
1334
  */
1180
1335
  after(...children) {
1181
1336
  return TinyHtml.after(this, ...children);
@@ -1183,17 +1338,20 @@ class TinyHtml {
1183
1338
  /**
1184
1339
  * Replaces the target element(s) in the DOM with new elements or text.
1185
1340
  *
1186
- * @param {TinyElement | TinyElement[]} el - The element(s) to be replaced.
1341
+ * @param {TinyElement} el - The element(s) to be replaced.
1187
1342
  * @param {...(TinyNode | TinyNode[] | string)} newNodes - New elements or text to replace the target.
1343
+ * @returns {TinyElement}
1188
1344
  */
1189
1345
  static replaceWith(el, ...newNodes) {
1190
1346
  const elem = TinyHtml._preElem(el, 'replaceWith');
1191
1347
  elem.replaceWith(...TinyHtml._appendChecker('replaceWith', ...newNodes));
1348
+ return el;
1192
1349
  }
1193
1350
  /**
1194
1351
  * Replaces the target element(s) in the DOM with new elements or text.
1195
1352
  *
1196
1353
  * @param {...(TinyNode | TinyNode[] | string)} newNodes - New elements or text to replace the target.
1354
+ * @returns {TinyElement}
1197
1355
  */
1198
1356
  replaceWith(...newNodes) {
1199
1357
  return TinyHtml.replaceWith(this, ...newNodes);
@@ -1203,6 +1361,7 @@ class TinyHtml {
1203
1361
  *
1204
1362
  * @param {TinyNode | TinyNode[]} el - The element(s) to append.
1205
1363
  * @param {TinyNode | TinyNode[]} targets - Target element(s) where content will be appended.
1364
+ * @returns {TinyNode|TinyNode[]}
1206
1365
  */
1207
1366
  static appendTo(el, targets) {
1208
1367
  const elems = TinyHtml._preNodeElems(el, 'appendTo');
@@ -1210,11 +1369,13 @@ class TinyHtml {
1210
1369
  tars.forEach((target, i) => {
1211
1370
  elems.forEach((elem) => target.appendChild(i === tars.length - 1 ? elem : elem.cloneNode(true)));
1212
1371
  });
1372
+ return el;
1213
1373
  }
1214
1374
  /**
1215
1375
  * Appends the given element(s) to each target element in sequence.
1216
1376
  *
1217
1377
  * @param {TinyNode | TinyNode[]} targets - Target element(s) where content will be appended.
1378
+ * @returns {TinyNode|TinyNode[]}
1218
1379
  */
1219
1380
  appendTo(targets) {
1220
1381
  return TinyHtml.appendTo(this, targets);
@@ -1224,6 +1385,7 @@ class TinyHtml {
1224
1385
  *
1225
1386
  * @param {TinyElement | TinyElement[]} el - The element(s) to prepend.
1226
1387
  * @param {TinyElement | TinyElement[]} targets - Target element(s) where content will be prepended.
1388
+ * @returns {TinyElement|TinyElement[]}
1227
1389
  */
1228
1390
  static prependTo(el, targets) {
1229
1391
  const elems = TinyHtml._preElems(el, 'prependTo');
@@ -1234,11 +1396,13 @@ class TinyHtml {
1234
1396
  .reverse()
1235
1397
  .forEach((elem) => target.prepend(i === tars.length - 1 ? elem : elem.cloneNode(true)));
1236
1398
  });
1399
+ return el;
1237
1400
  }
1238
1401
  /**
1239
1402
  * Prepends the given element(s) to each target element in sequence.
1240
1403
  *
1241
1404
  * @param {TinyElement | TinyElement[]} targets - Target element(s) where content will be prepended.
1405
+ * @returns {TinyElement|TinyElement[]}
1242
1406
  */
1243
1407
  prependTo(targets) {
1244
1408
  return TinyHtml.prependTo(this, targets);
@@ -1249,6 +1413,7 @@ class TinyHtml {
1249
1413
  * @param {TinyNode | TinyNode[]} el - The element(s) to insert.
1250
1414
  * @param {TinyNode | TinyNode[]} target - The reference element where insertion happens.
1251
1415
  * @param {TinyNode | TinyNode[] | null} [child=null] - Optional child to insert before, defaults to target.
1416
+ * @returns {TinyNode|TinyNode[]}
1252
1417
  */
1253
1418
  static insertBefore(el, target, child = null) {
1254
1419
  const elem = TinyHtml._preNodeElem(el, 'insertBefore');
@@ -1257,12 +1422,14 @@ class TinyHtml {
1257
1422
  if (!targ.parentNode)
1258
1423
  throw new Error('');
1259
1424
  targ.parentNode.insertBefore(elem, childNode || targ);
1425
+ return el;
1260
1426
  }
1261
1427
  /**
1262
1428
  * Inserts the element before a child of a given target, or before the target itself.
1263
1429
  *
1264
1430
  * @param {TinyNode | TinyNode[]} target - The reference element where insertion happens.
1265
1431
  * @param {TinyNode | TinyNode[] | null} [child=null] - Optional child to insert before, defaults to target.
1432
+ * @returns {TinyNode|TinyNode[]}
1266
1433
  */
1267
1434
  insertBefore(target, child) {
1268
1435
  return TinyHtml.insertBefore(this, target, child);
@@ -1273,6 +1440,7 @@ class TinyHtml {
1273
1440
  * @param {TinyNode | TinyNode[]} el - The element(s) to insert.
1274
1441
  * @param {TinyNode | TinyNode[]} target - The reference element where insertion happens.
1275
1442
  * @param {TinyNode | TinyNode[] | null} [child=null] - Optional child to insert after, defaults to target.
1443
+ * @returns {TinyNode|TinyNode[]}
1276
1444
  */
1277
1445
  static insertAfter(el, target, child = null) {
1278
1446
  const elem = TinyHtml._preNodeElem(el, 'insertAfter');
@@ -1281,12 +1449,14 @@ class TinyHtml {
1281
1449
  if (!targ.parentNode)
1282
1450
  throw new Error('');
1283
1451
  targ.parentNode.insertBefore(elem, childNode || targ.nextSibling);
1452
+ return el;
1284
1453
  }
1285
1454
  /**
1286
1455
  * Inserts the element after a child of a given target, or after the target itself.
1287
1456
  *
1288
1457
  * @param {TinyNode | TinyNode[]} target - The reference element where insertion happens.
1289
1458
  * @param {TinyNode | TinyNode[] | null} [child=null] - Optional child to insert after, defaults to target.
1459
+ * @returns {TinyNode|TinyNode[]}
1290
1460
  */
1291
1461
  insertAfter(target, child) {
1292
1462
  return TinyHtml.insertAfter(this, target, child);
@@ -1297,6 +1467,7 @@ class TinyHtml {
1297
1467
  *
1298
1468
  * @param {TinyNode | TinyNode[]} el - The new element(s) to insert.
1299
1469
  * @param {TinyNode | TinyNode[]} targets - The elements to be replaced.
1470
+ * @returns {TinyNode|TinyNode[]}
1300
1471
  */
1301
1472
  static replaceAll(el, targets) {
1302
1473
  const elems = TinyHtml._preNodeElems(el, 'replaceAll');
@@ -1308,12 +1479,14 @@ class TinyHtml {
1308
1479
  parent.replaceChild(i === tars.length - 1 ? elem : elem.cloneNode(true), target);
1309
1480
  });
1310
1481
  });
1482
+ return el;
1311
1483
  }
1312
1484
  /**
1313
1485
  * Replaces all target elements with the provided element(s).
1314
1486
  * If multiple targets exist, the inserted elements are cloned accordingly.
1315
1487
  *
1316
1488
  * @param {TinyNode | TinyNode[]} targets - The elements to be replaced.
1489
+ * @returns {TinyNode|TinyNode[]}
1317
1490
  */
1318
1491
  replaceAll(targets) {
1319
1492
  return TinyHtml.replaceAll(this, targets);
@@ -1332,7 +1505,10 @@ class TinyHtml {
1332
1505
  constructor(el) {
1333
1506
  if (el instanceof TinyHtml)
1334
1507
  throw new Error(`[TinyHtml] You are trying to put a TinyHtml inside another TinyHtml in constructor.`);
1335
- if (!(el instanceof Element) && !(el instanceof Window) && !(el instanceof Document))
1508
+ if (!(el instanceof Element) &&
1509
+ !(el instanceof Window) &&
1510
+ !(el instanceof Document) &&
1511
+ !(el instanceof Text))
1336
1512
  throw new Error(`[TinyHtml] Invalid Target in constructor.`);
1337
1513
  this.#el = el;
1338
1514
  }
@@ -1764,6 +1940,7 @@ class TinyHtml {
1764
1940
  * @param {TinyHtmlElement|TinyHtmlElement[]} el - The element to inspect.
1765
1941
  * @param {string|Object} prop - The property name or an object with key-value pairs
1766
1942
  * @param {string|null} [value=null] - The value to set (if `prop` is a string)
1943
+ * @returns {TinyHtmlElement|TinyHtmlElement[]}
1767
1944
  */
1768
1945
  static setStyle(el, prop, value = null) {
1769
1946
  TinyHtml._preHtmlElems(el, 'setStyle').forEach((elem) => {
@@ -1775,6 +1952,7 @@ class TinyHtml {
1775
1952
  else
1776
1953
  elem.style.setProperty(TinyHtml.toStyleKc(prop), value);
1777
1954
  });
1955
+ return el;
1778
1956
  }
1779
1957
  /**
1780
1958
  * Sets one or more CSS inline style properties on the given element(s).
@@ -1784,6 +1962,7 @@ class TinyHtml {
1784
1962
  *
1785
1963
  * @param {string|Object} prop - The property name or an object with key-value pairs
1786
1964
  * @param {string|null} [value=null] - The value to set (if `prop` is a string)
1965
+ * @returns {TinyHtmlElement|TinyHtmlElement[]}
1787
1966
  */
1788
1967
  setStyle(prop, value) {
1789
1968
  return TinyHtml.setStyle(this, prop, value);
@@ -1872,6 +2051,7 @@ class TinyHtml {
1872
2051
  *
1873
2052
  * @param {TinyHtmlElement|TinyHtmlElement[]} el - A single element or an array of elements.
1874
2053
  * @param {string|string[]} prop - A property name or an array of property names to remove.
2054
+ * @returns {TinyHtmlElement|TinyHtmlElement[]}
1875
2055
  */
1876
2056
  static removeStyle(el, prop) {
1877
2057
  TinyHtml._preHtmlElems(el, 'removeStyle').forEach((elem) => {
@@ -1883,11 +2063,13 @@ class TinyHtml {
1883
2063
  else
1884
2064
  elem.style.removeProperty(TinyHtml.toStyleKc(prop));
1885
2065
  });
2066
+ return el;
1886
2067
  }
1887
2068
  /**
1888
2069
  * Removes one or more inline CSS properties from the given element(s).
1889
2070
  *
1890
2071
  * @param {string|string[]} prop - A property name or an array of property names to remove.
2072
+ * @returns {TinyHtmlElement|TinyHtmlElement[]}
1891
2073
  */
1892
2074
  removeStyle(prop) {
1893
2075
  return TinyHtml.removeStyle(this, prop);
@@ -1901,6 +2083,7 @@ class TinyHtml {
1901
2083
  * @param {string} prop - The CSS property to toggle.
1902
2084
  * @param {string} val1 - The first value (used as "current" check).
1903
2085
  * @param {string} val2 - The second value (used as the "alternative").
2086
+ * @returns {TinyHtmlElement|TinyHtmlElement[]}
1904
2087
  */
1905
2088
  static toggleStyle(el, prop, val1, val2) {
1906
2089
  TinyHtml._preHtmlElems(el, 'toggleStyle').forEach((elem) => {
@@ -1908,6 +2091,7 @@ class TinyHtml {
1908
2091
  const newVal = current === TinyHtml.toStyleKc(val1) ? val2 : val1;
1909
2092
  TinyHtml.setStyle(elem, prop, newVal);
1910
2093
  });
2094
+ return el;
1911
2095
  }
1912
2096
  /**
1913
2097
  * Toggles a CSS property value between two given values.
@@ -1917,6 +2101,7 @@ class TinyHtml {
1917
2101
  * @param {string} prop - The CSS property to toggle.
1918
2102
  * @param {string} val1 - The first value (used as "current" check).
1919
2103
  * @param {string} val2 - The second value (used as the "alternative").
2104
+ * @returns {TinyHtmlElement|TinyHtmlElement[]}
1920
2105
  */
1921
2106
  toggleStyle(prop, val1, val2) {
1922
2107
  return TinyHtml.toggleStyle(this, prop, val1, val2);
@@ -1925,13 +2110,15 @@ class TinyHtml {
1925
2110
  * Removes all inline styles (`style` attribute) from the given element(s).
1926
2111
  *
1927
2112
  * @param {TinyElement|TinyElement[]} el - A single element or an array of elements.
2113
+ * @returns {TinyElement|TinyElement[]}
1928
2114
  */
1929
2115
  static clearStyle(el) {
1930
2116
  TinyHtml._preElems(el, 'clearStyle').forEach((elem) => elem.removeAttribute('style'));
2117
+ return el;
1931
2118
  }
1932
2119
  /**
1933
2120
  * Removes all inline styles (`style` attribute) from the given element(s).
1934
- *
2121
+ * @returns {TinyElement|TinyElement[]}
1935
2122
  */
1936
2123
  clearStyle() {
1937
2124
  return TinyHtml.clearStyle(this);
@@ -1941,13 +2128,16 @@ class TinyHtml {
1941
2128
  * Focus the element.
1942
2129
  *
1943
2130
  * @param {TinyHtmlElement} el - The element or a selector string.
2131
+ * @returns {TinyHtmlElement}
1944
2132
  */
1945
2133
  static focus(el) {
1946
2134
  const elem = TinyHtml._preHtmlElem(el, 'focus');
1947
2135
  elem.focus();
2136
+ return el;
1948
2137
  }
1949
2138
  /**
1950
2139
  * Focus the element.
2140
+ * @returns {TinyHtmlElement}
1951
2141
  */
1952
2142
  focus() {
1953
2143
  return TinyHtml.focus(this);
@@ -1956,17 +2146,42 @@ class TinyHtml {
1956
2146
  * Blur the element.
1957
2147
  *
1958
2148
  * @param {TinyHtmlElement} el - The element or a selector string.
2149
+ * @returns {TinyHtmlElement}
1959
2150
  */
1960
2151
  static blur(el) {
1961
2152
  const elem = TinyHtml._preHtmlElem(el, 'blur');
1962
2153
  elem.blur();
2154
+ return el;
1963
2155
  }
1964
2156
  /**
1965
2157
  * Blur the element.
2158
+ * @returns {TinyHtmlElement}
1966
2159
  */
1967
2160
  blur() {
1968
2161
  return TinyHtml.blur(this);
1969
2162
  }
2163
+ /**
2164
+ * Interprets a value as a boolean `true` if it matches a common truthy representation.
2165
+ *
2166
+ * This method checks if the input is any of the common forms used to represent `true`,
2167
+ * such as the string `'true'`, `'1'`, `'on'`, the boolean `true`, or the number `1`.
2168
+ *
2169
+ * @param {string|boolean|number} [value] - The value to interpret as boolean.
2170
+ * @returns {boolean} `true` if the value represents a truthy state, otherwise `false`.
2171
+ */
2172
+ static boolCheck(value) {
2173
+ if (typeof value !== 'undefined' &&
2174
+ (value === 'true' ||
2175
+ value === '1' ||
2176
+ value === true ||
2177
+ value === 'on' ||
2178
+ (typeof value === 'number' && value > 0))) {
2179
+ return true;
2180
+ }
2181
+ else {
2182
+ return false;
2183
+ }
2184
+ }
1970
2185
  //////////////////////////////////////////////////////////////////////
1971
2186
  /**
1972
2187
  * Sets the vertical scroll position of the window.
@@ -1975,7 +2190,7 @@ class TinyHtml {
1975
2190
  static setWinScrollTop(value) {
1976
2191
  if (typeof value !== 'number')
1977
2192
  throw new TypeError('The value must be a number.');
1978
- window.scrollTo({ top: value });
2193
+ TinyHtml.setScrollTop(window, value);
1979
2194
  }
1980
2195
  /**
1981
2196
  * Sets the horizontal scroll position of the window.
@@ -1984,7 +2199,7 @@ class TinyHtml {
1984
2199
  static setWinScrollLeft(value) {
1985
2200
  if (typeof value !== 'number')
1986
2201
  throw new TypeError('The value must be a number.');
1987
- window.scrollTo({ left: value });
2202
+ TinyHtml.setScrollLeft(window, value);
1988
2203
  }
1989
2204
  /**
1990
2205
  * Gets the vertical scroll position of the window.
@@ -2014,16 +2229,38 @@ class TinyHtml {
2014
2229
  static winInnerWidth() {
2015
2230
  return window.innerWidth || document.documentElement.clientWidth;
2016
2231
  }
2232
+ /**
2233
+ * Checks if the page is currently scrolled to the very top.
2234
+ *
2235
+ * This method compares the current vertical scroll position with the total document height.
2236
+ * It's useful for detecting if the user has reached the top of the page.
2237
+ *
2238
+ * @returns {boolean} `true` if the page is scrolled to the top, otherwise `false`.
2239
+ */
2240
+ static isPageTop() {
2241
+ return window.scrollY === 0;
2242
+ }
2243
+ /**
2244
+ * Checks if the page is currently scrolled to the very bottom.
2245
+ *
2246
+ * This method uses the `scrollY` and `innerHeight` properties to determine if the
2247
+ * user has reached the end of the document.
2248
+ *
2249
+ * @returns {boolean} `true` if the page is scrolled to the bottom, otherwise `false`.
2250
+ */
2251
+ static isPageBottom() {
2252
+ return window.innerHeight + window.scrollY >= document.body.offsetHeight;
2253
+ }
2017
2254
  /**
2018
2255
  * Gets the width or height of an element based on the box model.
2019
- * @param {TinyElementAndWindow} el - The element or window.
2256
+ * @param {TinyElementAndWinAndDoc} el - The element or window.
2020
2257
  * @param {"width"|"height"} type - Dimension type.
2021
2258
  * @param {"content"|"padding"|"border"|"margin"} [extra='content'] - Box model context.
2022
2259
  * @returns {number} - Computed dimension.
2023
2260
  * @throws {TypeError} If `type` or `extra` is not a string.
2024
2261
  */
2025
2262
  static getDimension(el, type, extra = 'content') {
2026
- const elem = TinyHtml._preElemAndWindow(el, 'getDimension');
2263
+ const elem = TinyHtml._preElemAndWinAndDoc(el, 'getDimension');
2027
2264
  if (typeof type !== 'string')
2028
2265
  throw new TypeError('The type must be a string.');
2029
2266
  if (typeof extra !== 'string')
@@ -2094,16 +2331,19 @@ class TinyHtml {
2094
2331
  * @param {TinyHtmlElement} el - Target element.
2095
2332
  * @param {string|number} value - Height value.
2096
2333
  * @throws {TypeError} If `value` is neither a string nor number.
2334
+ * @returns {TinyHtmlElement}
2097
2335
  */
2098
2336
  static setHeight(el, value) {
2099
2337
  const elem = TinyHtml._preHtmlElem(el, 'setHeight');
2100
2338
  if (typeof value !== 'number' && typeof value !== 'string')
2101
2339
  throw new TypeError('The value must be a string or number.');
2102
2340
  elem.style.height = typeof value === 'number' ? `${value}px` : value;
2341
+ return el;
2103
2342
  }
2104
2343
  /**
2105
2344
  * Sets the height of the element.
2106
2345
  * @param {string|number} value - Height value.
2346
+ * @returns {TinyHtmlElement}
2107
2347
  */
2108
2348
  setHeight(value) {
2109
2349
  return TinyHtml.setHeight(this, value);
@@ -2113,27 +2353,30 @@ class TinyHtml {
2113
2353
  * @param {TinyHtmlElement} el - Target element.
2114
2354
  * @param {string|number} value - Width value.
2115
2355
  * @throws {TypeError} If `value` is neither a string nor number.
2356
+ * @returns {TinyHtmlElement}
2116
2357
  */
2117
2358
  static setWidth(el, value) {
2118
2359
  const elem = TinyHtml._preHtmlElem(el, 'setWidth');
2119
2360
  if (typeof value !== 'number' && typeof value !== 'string')
2120
2361
  throw new TypeError('The value must be a string or number.');
2121
2362
  elem.style.width = typeof value === 'number' ? `${value}px` : value;
2363
+ return el;
2122
2364
  }
2123
2365
  /**
2124
2366
  * Sets the width of the element.
2125
2367
  * @param {string|number} value - Width value.
2368
+ * @returns {TinyHtmlElement}
2126
2369
  */
2127
2370
  setWidth(value) {
2128
2371
  return TinyHtml.setWidth(this, value);
2129
2372
  }
2130
2373
  /**
2131
2374
  * Returns content box height.
2132
- * @param {TinyElementAndWindow} el - Target element.
2375
+ * @param {TinyElementAndWinAndDoc} el - Target element.
2133
2376
  * @returns {number}
2134
2377
  */
2135
2378
  static height(el) {
2136
- const elem = TinyHtml._preElemAndWindow(el, 'height');
2379
+ const elem = TinyHtml._preElemAndWinAndDoc(el, 'height');
2137
2380
  return TinyHtml.getDimension(elem, 'height', 'content');
2138
2381
  }
2139
2382
  /**
@@ -2145,11 +2388,11 @@ class TinyHtml {
2145
2388
  }
2146
2389
  /**
2147
2390
  * Returns content box width.
2148
- * @param {TinyElementAndWindow} el - Target element.
2391
+ * @param {TinyElementAndWinAndDoc} el - Target element.
2149
2392
  * @returns {number}
2150
2393
  */
2151
2394
  static width(el) {
2152
- const elem = TinyHtml._preElemAndWindow(el, 'width');
2395
+ const elem = TinyHtml._preElemAndWinAndDoc(el, 'width');
2153
2396
  return TinyHtml.getDimension(elem, 'width', 'content');
2154
2397
  }
2155
2398
  /**
@@ -2161,11 +2404,11 @@ class TinyHtml {
2161
2404
  }
2162
2405
  /**
2163
2406
  * Returns padding box height.
2164
- * @param {TinyElementAndWindow} el - Target element.
2407
+ * @param {TinyElementAndWinAndDoc} el - Target element.
2165
2408
  * @returns {number}
2166
2409
  */
2167
2410
  static innerHeight(el) {
2168
- const elem = TinyHtml._preElemAndWindow(el, 'innerHeight');
2411
+ const elem = TinyHtml._preElemAndWinAndDoc(el, 'innerHeight');
2169
2412
  return TinyHtml.getDimension(elem, 'height', 'padding');
2170
2413
  }
2171
2414
  /**
@@ -2177,11 +2420,11 @@ class TinyHtml {
2177
2420
  }
2178
2421
  /**
2179
2422
  * Returns padding box width.
2180
- * @param {TinyElementAndWindow} el - Target element.
2423
+ * @param {TinyElementAndWinAndDoc} el - Target element.
2181
2424
  * @returns {number}
2182
2425
  */
2183
2426
  static innerWidth(el) {
2184
- const elem = TinyHtml._preElemAndWindow(el, 'innerWidth');
2427
+ const elem = TinyHtml._preElemAndWinAndDoc(el, 'innerWidth');
2185
2428
  return TinyHtml.getDimension(elem, 'width', 'padding');
2186
2429
  }
2187
2430
  /**
@@ -2193,14 +2436,14 @@ class TinyHtml {
2193
2436
  }
2194
2437
  /**
2195
2438
  * Returns outer height of the element, optionally including margin.
2196
- * @param {TinyElementAndWindow} el - Target element.
2439
+ * @param {TinyElementAndWinAndDoc} el - Target element.
2197
2440
  * @param {boolean} [includeMargin=false] - Whether to include margin.
2198
2441
  * @returns {number}
2199
2442
  */
2200
2443
  static outerHeight(el, includeMargin = false) {
2201
2444
  if (typeof includeMargin !== 'boolean')
2202
2445
  throw new TypeError('The "includeMargin" must be a boolean.');
2203
- const elem = TinyHtml._preElemAndWindow(el, 'outerHeight');
2446
+ const elem = TinyHtml._preElemAndWinAndDoc(el, 'outerHeight');
2204
2447
  return TinyHtml.getDimension(elem, 'height', includeMargin ? 'margin' : 'border');
2205
2448
  }
2206
2449
  /**
@@ -2213,14 +2456,14 @@ class TinyHtml {
2213
2456
  }
2214
2457
  /**
2215
2458
  * Returns outer width of the element, optionally including margin.
2216
- * @param {TinyElementAndWindow} el - Target element.
2459
+ * @param {TinyElementAndWinAndDoc} el - Target element.
2217
2460
  * @param {boolean} [includeMargin=false] - Whether to include margin.
2218
2461
  * @returns {number}
2219
2462
  */
2220
2463
  static outerWidth(el, includeMargin = false) {
2221
2464
  if (typeof includeMargin !== 'boolean')
2222
2465
  throw new TypeError('The "includeMargin" must be a boolean.');
2223
- const elem = TinyHtml._preElemAndWindow(el, 'outerWidth');
2466
+ const elem = TinyHtml._preElemAndWinAndDoc(el, 'outerWidth');
2224
2467
  return TinyHtml.getDimension(elem, 'width', includeMargin ? 'margin' : 'border');
2225
2468
  }
2226
2469
  /**
@@ -2232,6 +2475,28 @@ class TinyHtml {
2232
2475
  return TinyHtml.outerWidth(this, includeMargin);
2233
2476
  }
2234
2477
  //////////////////////////////////////////////////
2478
+ /**
2479
+ * Applies an animation to one or multiple TinyElement instances.
2480
+ *
2481
+ * @param {TinyElement|TinyElement[]} el - A single TinyElement or an array of TinyElements to animate.
2482
+ * @param {Keyframe[] | PropertyIndexedKeyframes | null} keyframes - The keyframes used to define the animation.
2483
+ * @param {number | KeyframeAnimationOptions} [ops] - Timing or configuration options for the animation.
2484
+ * @returns {TinyElement|TinyElement[]}
2485
+ */
2486
+ static animate(el, keyframes, ops) {
2487
+ TinyHtml._preElems(el, 'animate').forEach((elem) => elem.animate(keyframes, ops));
2488
+ return el;
2489
+ }
2490
+ /**
2491
+ * Applies an animation to one or multiple TinyElement instances.
2492
+ *
2493
+ * @param {Keyframe[] | PropertyIndexedKeyframes | null} keyframes - The keyframes used to define the animation.
2494
+ * @param {number | KeyframeAnimationOptions} [ops] - Timing or configuration options for the animation.
2495
+ * @returns {TinyElement|TinyElement[]}
2496
+ */
2497
+ animate(keyframes, ops) {
2498
+ return TinyHtml.animate(this, keyframes, ops);
2499
+ }
2235
2500
  /**
2236
2501
  * Gets the offset of the element relative to the document.
2237
2502
  * @param {TinyElement} el - Target element.
@@ -2366,29 +2631,146 @@ class TinyHtml {
2366
2631
  return TinyHtml.scrollLeft(this);
2367
2632
  }
2368
2633
  /**
2369
- * Sets the vertical scroll position.
2370
- * @param {TinyElementAndWindow|TinyElementAndWindow[]} el - Element or window.
2371
- * @param {number} value - Scroll top value.
2634
+ * Collection of easing functions used for scroll and animation calculations.
2635
+ * Each function receives a normalized time value (`t` from 0 to 1) and returns the eased progress.
2636
+ *
2637
+ * @type {Record<string, (t: number) => number>}
2372
2638
  */
2373
- static setScrollTop(el, value) {
2374
- if (typeof value !== 'number')
2375
- throw new TypeError('ScrollTop value must be a number.');
2376
- TinyHtml._preElemsAndWindow(el, 'setScrollTop').forEach((elem) => {
2377
- if (TinyHtml.isWindow(elem)) {
2378
- elem.scrollTo(elem.pageXOffset, value);
2639
+ static easings = {
2640
+ linear: (t) => t,
2641
+ easeInQuad: (t) => t * t,
2642
+ easeOutQuad: (t) => t * (2 - t),
2643
+ easeInOutQuad: (t) => (t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t),
2644
+ easeInCubic: (t) => t * t * t,
2645
+ easeOutCubic: (t) => --t * t * t + 1,
2646
+ easeInOutCubic: (t) => (t < 0.5 ? 4 * t * t * t : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1),
2647
+ };
2648
+ /**
2649
+ * Smoothly scrolls one or more elements (or the window) to the specified X and Y coordinates
2650
+ * using a custom duration and easing function.
2651
+ *
2652
+ * If `duration` or a valid `easing` is not provided, the scroll will be performed immediately.
2653
+ *
2654
+ * @param {TinyElementAndWindow | TinyElementAndWindow[]} el - A single element, array of elements, or the window to scroll.
2655
+ * @param {Object} [settings={}] - Configuration object for the scroll animation.
2656
+ * @param {number} [settings.targetX] - The horizontal scroll target in pixels.
2657
+ * @param {number} [settings.targetY] - The vertical scroll target in pixels.
2658
+ * @param {number} [settings.duration] - The duration of the animation in milliseconds.
2659
+ * @param {Easings} [settings.easing] - The easing function name to use for the scroll animation.
2660
+ * @param {OnScrollAnimation} [settings.onAnimation] - Optional callback invoked on each animation
2661
+ * frame with the current scroll position, normalized animation time (`0` to `1`), and a completion flag.
2662
+ * @returns {TinyElementAndWindow|TinyElementAndWindow[]}
2663
+ * @throws {TypeError} If `el` is not a valid element, array, or window.
2664
+ * @throws {TypeError} If `targetX` or `targetY` is defined but not a number.
2665
+ * @throws {TypeError} If `duration` is defined but not a number.
2666
+ * @throws {TypeError} If `easing` is defined but not a valid easing function name.
2667
+ * @throws {TypeError} If `onAnimation` is defined but not a function.
2668
+ */
2669
+ static scrollToXY(el, { targetX, targetY, duration, easing, onAnimation } = {}) {
2670
+ if (targetX !== undefined && typeof targetX !== 'number')
2671
+ throw new TypeError('`targetX` must be a number if provided.');
2672
+ if (targetY !== undefined && typeof targetY !== 'number')
2673
+ throw new TypeError('`targetY` must be a number if provided.');
2674
+ if (duration !== undefined && typeof duration !== 'number')
2675
+ throw new TypeError('`duration` must be a number if provided.');
2676
+ if (easing !== undefined && typeof easing !== 'string')
2677
+ throw new TypeError('`easing` must be a string if provided.');
2678
+ if (easing !== undefined && typeof TinyHtml.easings[easing] !== 'function')
2679
+ throw new TypeError(`Unknown easing function: "${easing}".`);
2680
+ if (onAnimation !== undefined && typeof onAnimation !== 'function')
2681
+ throw new TypeError('`onAnimation` must be a function if provided.');
2682
+ /**
2683
+ * Performs an instant scroll to the given coordinates.
2684
+ *
2685
+ * @param {ElementAndWindow} elem - The element or window to scroll.
2686
+ * @param {number} newX - The final horizontal scroll position.
2687
+ * @param {number} newY - The final vertical scroll position.
2688
+ * @param {number} time - Normalized progress value.
2689
+ */
2690
+ const executeScroll = (elem, newX, newY, time) => {
2691
+ if (elem instanceof Window) {
2692
+ window.scrollTo(newX, newY);
2379
2693
  }
2380
2694
  else if (elem.nodeType === 9) {
2381
2695
  // @ts-ignore
2382
- elem.defaultView.scrollTo(elem.defaultView.pageXOffset, value);
2696
+ elem.defaultView.scrollTo(newX, newY);
2383
2697
  }
2384
2698
  else {
2385
- elem.scrollTop = value;
2699
+ const startX = elem instanceof Window ? window.scrollX : elem.scrollLeft;
2700
+ const startY = elem instanceof Window ? window.scrollY : elem.scrollTop;
2701
+ if (startX !== newX)
2702
+ elem.scrollLeft = newX;
2703
+ if (startY !== newY)
2704
+ elem.scrollTop = newY;
2705
+ }
2706
+ if (typeof onAnimation === 'function')
2707
+ onAnimation({ x: newX, y: newY, isComplete: time >= 1, time });
2708
+ };
2709
+ TinyHtml._preElemsAndWindow(el, 'scrollToXY').forEach((elem) => {
2710
+ const startX = elem instanceof Window ? window.scrollX : elem.scrollLeft;
2711
+ const startY = elem instanceof Window ? window.scrollY : elem.scrollTop;
2712
+ const targX = targetX ?? startX;
2713
+ const targY = targetY ?? startY;
2714
+ const changeX = targX - startX;
2715
+ const changeY = targY - startY;
2716
+ const ease = (typeof easing === 'string' && TinyHtml.easings[easing]) || null;
2717
+ if (typeof duration !== 'number' || typeof ease !== 'function')
2718
+ return executeScroll(elem, targX, targY, 1);
2719
+ const startTime = performance.now();
2720
+ const dur = duration ?? 0;
2721
+ /**
2722
+ * Animates the scroll position based on easing and time.
2723
+ *
2724
+ * @param {number} currentTime - Timestamp provided by requestAnimationFrame.
2725
+ */
2726
+ function animateScroll(currentTime) {
2727
+ if (typeof ease !== 'function')
2728
+ return;
2729
+ const time = Math.min(1, (currentTime - startTime) / dur);
2730
+ const easedTime = ease(time);
2731
+ const newX = startX + changeX * easedTime;
2732
+ const newY = startY + changeY * easedTime;
2733
+ executeScroll(elem, newX, newY, time);
2734
+ if (time < 1)
2735
+ requestAnimationFrame(animateScroll);
2386
2736
  }
2737
+ requestAnimationFrame(animateScroll);
2387
2738
  });
2739
+ return el;
2740
+ }
2741
+ /**
2742
+ * Smoothly scrolls one or more elements (or the window) to the specified X and Y coordinates
2743
+ * using a custom duration and easing function.
2744
+ *
2745
+ * If `duration` or a valid `easing` is not provided, the scroll will be performed immediately.
2746
+ *
2747
+ * @param {Object} [settings={}] - Configuration object for the scroll animation.
2748
+ * @param {number} [settings.targetX] - The horizontal scroll target in pixels.
2749
+ * @param {number} [settings.targetY] - The vertical scroll target in pixels.
2750
+ * @param {number} [settings.duration] - The duration of the animation in milliseconds.
2751
+ * @param {Easings} [settings.easing] - The easing function name to use for the scroll animation.
2752
+ * @param {OnScrollAnimation} [settings.onAnimation] - Optional callback invoked on each animation
2753
+ * frame with the current scroll position, normalized animation time (`0` to `1`), and a completion flag.
2754
+ * @returns {TinyElementAndWindow|TinyElementAndWindow[]}
2755
+ */
2756
+ scrollToXY({ targetX, targetY, duration, easing, onAnimation } = {}) {
2757
+ return TinyHtml.scrollToXY(this, { targetX, targetY, duration, easing, onAnimation });
2758
+ }
2759
+ /**
2760
+ * Sets the vertical scroll position.
2761
+ * @param {TinyElementAndWindow|TinyElementAndWindow[]} el - Element or window.
2762
+ * @param {number} value - Scroll top value.
2763
+ * @returns {TinyElementAndWindow|TinyElementAndWindow[]}
2764
+ */
2765
+ static setScrollTop(el, value) {
2766
+ if (typeof value !== 'number')
2767
+ throw new TypeError('ScrollTop value must be a number.');
2768
+ return TinyHtml.scrollToXY(el, { targetY: value });
2388
2769
  }
2389
2770
  /**
2390
2771
  * Sets the vertical scroll position.
2391
2772
  * @param {number} value - Scroll top value.
2773
+ * @returns {TinyElementAndWindow|TinyElementAndWindow[]}
2392
2774
  */
2393
2775
  setScrollTop(value) {
2394
2776
  return TinyHtml.setScrollTop(this, value);
@@ -2397,26 +2779,17 @@ class TinyHtml {
2397
2779
  * Sets the horizontal scroll position.
2398
2780
  * @param {TinyElementAndWindow|TinyElementAndWindow[]} el - Element or window.
2399
2781
  * @param {number} value - Scroll left value.
2782
+ * @returns {TinyElementAndWindow|TinyElementAndWindow[]}
2400
2783
  */
2401
2784
  static setScrollLeft(el, value) {
2402
2785
  if (typeof value !== 'number')
2403
2786
  throw new TypeError('ScrollLeft value must be a number.');
2404
- TinyHtml._preElemsAndWindow(el, 'setScrollLeft').forEach((elem) => {
2405
- if (TinyHtml.isWindow(elem)) {
2406
- elem.scrollTo(value, elem.pageYOffset);
2407
- }
2408
- else if (elem.nodeType === 9) {
2409
- // @ts-ignore
2410
- elem.defaultView.scrollTo(value, elem.defaultView.pageYOffset);
2411
- }
2412
- else {
2413
- elem.scrollLeft = value;
2414
- }
2415
- });
2787
+ return TinyHtml.scrollToXY(el, { targetX: value });
2416
2788
  }
2417
2789
  /**
2418
2790
  * Sets the horizontal scroll position.
2419
2791
  * @param {number} value - Scroll left value.
2792
+ * @returns {TinyElementAndWindow|TinyElementAndWindow[]}
2420
2793
  */
2421
2794
  setScrollLeft(value) {
2422
2795
  return TinyHtml.setScrollLeft(this, value);
@@ -2513,28 +2886,30 @@ class TinyHtml {
2513
2886
  /////////////////////////////////////////////
2514
2887
  /**
2515
2888
  * Adds one or more CSS class names to the element.
2516
- * @type {(el: TinyElement|TinyElement[], ...tokens: string[]) => void} - One or more class names to add.
2889
+ * @type {(el: TinyElement|TinyElement[], ...tokens: string[]) => (TinyElement|TinyElement[])} - One or more class names to add.
2517
2890
  */
2518
2891
  static addClass(el, ...args) {
2519
2892
  TinyHtml._preElems(el, 'addClass').forEach((elem) => elem.classList.add(...args));
2893
+ return el;
2520
2894
  }
2521
2895
  /**
2522
2896
  * Adds one or more CSS class names to the element.
2523
- * @type {(...tokens: string[]) => void} - One or more class names to add.
2897
+ * @type {(...tokens: string[]) => (TinyElement|TinyElement[])} - One or more class names to add.
2524
2898
  */
2525
2899
  addClass(...args) {
2526
2900
  return TinyHtml.addClass(this, ...args);
2527
2901
  }
2528
2902
  /**
2529
2903
  * Removes one or more CSS class names from the element.
2530
- * @type {(el: TinyElement|TinyElement[], ...tokens: string[]) => void} - One or more class names to remove.
2904
+ * @type {(el: TinyElement|TinyElement[], ...tokens: string[]) => (TinyElement|TinyElement[])} - One or more class names to remove.
2531
2905
  */
2532
2906
  static removeClass(el, ...args) {
2533
2907
  TinyHtml._preElems(el, 'removeClass').forEach((elem) => elem.classList.remove(...args));
2908
+ return el;
2534
2909
  }
2535
2910
  /**
2536
2911
  * Removes one or more CSS class names from the element.
2537
- * @type {(...tokens: string[]) => void} - One or more class names to remove.
2912
+ * @type {(...tokens: string[]) => (TinyElement|TinyElement[])} - One or more class names to remove.
2538
2913
  */
2539
2914
  removeClass(...args) {
2540
2915
  return TinyHtml.removeClass(this, ...args);
@@ -2724,15 +3099,18 @@ class TinyHtml {
2724
3099
  * Set text content of elements.
2725
3100
  * @param {TinyElement|TinyElement[]} el
2726
3101
  * @param {string} value
3102
+ * @returns {TinyElement|TinyElement[]}
2727
3103
  */
2728
3104
  static setText(el, value) {
2729
3105
  if (typeof value !== 'string')
2730
3106
  throw new Error('Value is not a valid string.');
2731
3107
  TinyHtml._preElems(el, 'setText').forEach((el) => (el.textContent = value));
3108
+ return el;
2732
3109
  }
2733
3110
  /**
2734
3111
  * Set text content of the element.
2735
3112
  * @param {string} value
3113
+ * @returns {TinyElement|TinyElement[]}
2736
3114
  */
2737
3115
  setText(value) {
2738
3116
  return TinyHtml.setText(this, value);
@@ -2740,45 +3118,53 @@ class TinyHtml {
2740
3118
  /**
2741
3119
  * Remove all child nodes from each element.
2742
3120
  * @param {TinyElement|TinyElement[]} el
3121
+ * @returns {TinyElement|TinyElement[]}
2743
3122
  */
2744
3123
  static empty(el) {
2745
3124
  TinyHtml._preElems(el, 'empty').forEach((el) => (el.textContent = ''));
3125
+ return el;
2746
3126
  }
2747
3127
  /**
2748
3128
  * Remove all child nodes of the element.
3129
+ * @returns {TinyElement|TinyElement[]}
2749
3130
  */
2750
3131
  empty() {
2751
3132
  return TinyHtml.empty(this);
2752
3133
  }
2753
3134
  /**
2754
3135
  * Get the innerHTML of the element.
2755
- * @param {TinyElement|TinyElement[]} el
3136
+ * @param {TinyElement} el
3137
+ * @param {GetHTMLOptions} [ops]
2756
3138
  * @returns {string}
2757
3139
  */
2758
- static html(el) {
3140
+ static html(el, ops) {
2759
3141
  const elem = TinyHtml._preElem(el, 'html');
2760
- return elem.innerHTML;
3142
+ return elem.getHTML(ops);
2761
3143
  }
2762
3144
  /**
2763
3145
  * Get the innerHTML of the element.
3146
+ * @param {GetHTMLOptions} [ops]
2764
3147
  * @returns {string}
2765
3148
  */
2766
- html() {
2767
- return TinyHtml.html(this);
3149
+ html(ops) {
3150
+ return TinyHtml.html(this, ops);
2768
3151
  }
2769
3152
  /**
2770
3153
  * Set the innerHTML of each element.
2771
3154
  * @param {TinyElement|TinyElement[]} el
2772
3155
  * @param {string} value
3156
+ * @returns {TinyElement|TinyElement[]}
2773
3157
  */
2774
3158
  static setHtml(el, value) {
2775
3159
  if (typeof value !== 'string')
2776
3160
  throw new Error('Value is not a valid string.');
2777
3161
  TinyHtml._preElems(el, 'setHtml').forEach((el) => (el.innerHTML = value));
3162
+ return el;
2778
3163
  }
2779
3164
  /**
2780
3165
  * Set the innerHTML of the element.
2781
3166
  * @param {string} value
3167
+ * @returns {TinyElement|TinyElement[]}
2782
3168
  */
2783
3169
  setHtml(value) {
2784
3170
  return TinyHtml.setHtml(this, value);
@@ -2899,6 +3285,7 @@ class TinyHtml {
2899
3285
  * @param {TinyInputElement|TinyInputElement[]} el - Target element.
2900
3286
  * @param {SetValueList|((el: InputElement, val: SetValueList) => SetValueList)} value - The value to assign or a function that returns it.
2901
3287
  * @throws {Error} If the computed value is not a valid string or boolean.
3288
+ * @returns {TinyInputElement|TinyInputElement[]}
2902
3289
  */
2903
3290
  static setVal(el, value) {
2904
3291
  TinyHtml._preInputElems(el, 'setVal').forEach((elem) => {
@@ -2937,12 +3324,14 @@ class TinyHtml {
2937
3324
  elem.value = valToSet;
2938
3325
  }
2939
3326
  });
3327
+ return el;
2940
3328
  }
2941
3329
  /**
2942
3330
  * Sets the value of the current HTML value element (input, select, textarea, etc.).
2943
3331
  * Accepts strings, numbers, booleans or arrays of these values, or a callback function that computes them.
2944
3332
  *
2945
3333
  * @param {SetValueList|((el: InputElement, val: SetValueList) => SetValueList)} value - The value to assign or a function that returns it.
3334
+ * @returns {TinyInputElement|TinyInputElement[]}
2946
3335
  * @throws {Error} If the computed value is not a valid string or boolean.
2947
3336
  */
2948
3337
  setVal(value) {
@@ -3199,6 +3588,7 @@ class TinyHtml {
3199
3588
  * @param {string} event - The event type (e.g. 'click', 'keydown').
3200
3589
  * @param {EventRegistryHandle} handler - The callback function to run on event.
3201
3590
  * @param {EventRegistryOptions} [options] - Optional event listener options.
3591
+ * @returns {TinyEventTarget|TinyEventTarget[]}
3202
3592
  */
3203
3593
  static on(el, event, handler, options) {
3204
3594
  if (typeof event !== 'string')
@@ -3214,6 +3604,7 @@ class TinyHtml {
3214
3604
  events[event] = [];
3215
3605
  events[event].push({ handler, options });
3216
3606
  });
3607
+ return el;
3217
3608
  }
3218
3609
  /**
3219
3610
  * Registers an event listener on the specified element.
@@ -3221,6 +3612,7 @@ class TinyHtml {
3221
3612
  * @param {string} event - The event type (e.g. 'click', 'keydown').
3222
3613
  * @param {EventRegistryHandle} handler - The callback function to run on event.
3223
3614
  * @param {EventRegistryOptions} [options] - Optional event listener options.
3615
+ * @returns {TinyEventTarget|TinyEventTarget[]}
3224
3616
  */
3225
3617
  on(event, handler, options) {
3226
3618
  return TinyHtml.on(this, event, handler, options);
@@ -3232,6 +3624,7 @@ class TinyHtml {
3232
3624
  * @param {string} event - The event type (e.g. 'click', 'keydown').
3233
3625
  * @param {EventRegistryHandle} handler - The callback function to run on event.
3234
3626
  * @param {EventRegistryOptions} [options={}] - Optional event listener options.
3627
+ * @returns {TinyEventTarget|TinyEventTarget[]}
3235
3628
  */
3236
3629
  static once(el, event, handler, options = {}) {
3237
3630
  if (typeof event !== 'string')
@@ -3244,6 +3637,7 @@ class TinyHtml {
3244
3637
  };
3245
3638
  TinyHtml.on(elem, event, wrapped, typeof options === 'boolean' ? options : { ...options, once: true });
3246
3639
  });
3640
+ return el;
3247
3641
  }
3248
3642
  /**
3249
3643
  * Registers an event listener that runs only once, then is removed.
@@ -3251,6 +3645,7 @@ class TinyHtml {
3251
3645
  * @param {string} event - The event type (e.g. 'click', 'keydown').
3252
3646
  * @param {EventRegistryHandle} handler - The callback function to run on event.
3253
3647
  * @param {EventRegistryOptions} [options={}] - Optional event listener options.
3648
+ * @returns {TinyEventTarget|TinyEventTarget[]}
3254
3649
  */
3255
3650
  once(event, handler, options = {}) {
3256
3651
  return TinyHtml.once(this, event, handler, options);
@@ -3262,6 +3657,7 @@ class TinyHtml {
3262
3657
  * @param {string} event - The event type.
3263
3658
  * @param {EventRegistryHandle} handler - The function originally bound to the event.
3264
3659
  * @param {boolean|EventListenerOptions} [options] - Optional listener options.
3660
+ * @returns {TinyEventTarget|TinyEventTarget[]}
3265
3661
  */
3266
3662
  static off(el, event, handler, options) {
3267
3663
  if (typeof event !== 'string')
@@ -3275,6 +3671,7 @@ class TinyHtml {
3275
3671
  delete events[event];
3276
3672
  }
3277
3673
  });
3674
+ return el;
3278
3675
  }
3279
3676
  /**
3280
3677
  * Removes a specific event listener from an element.
@@ -3282,6 +3679,7 @@ class TinyHtml {
3282
3679
  * @param {string} event - The event type.
3283
3680
  * @param {EventRegistryHandle} handler - The function originally bound to the event.
3284
3681
  * @param {boolean|EventListenerOptions} [options] - Optional listener options.
3682
+ * @returns {TinyEventTarget|TinyEventTarget[]}
3285
3683
  */
3286
3684
  off(event, handler, options) {
3287
3685
  return TinyHtml.off(this, event, handler, options);
@@ -3291,6 +3689,7 @@ class TinyHtml {
3291
3689
  *
3292
3690
  * @param {TinyEventTarget|TinyEventTarget[]} el - The target element.
3293
3691
  * @param {string} event - The event type to remove (e.g. 'click').
3692
+ * @returns {TinyEventTarget|TinyEventTarget[]}
3294
3693
  */
3295
3694
  static offAll(el, event) {
3296
3695
  if (typeof event !== 'string')
@@ -3304,11 +3703,13 @@ class TinyHtml {
3304
3703
  delete events[event];
3305
3704
  }
3306
3705
  });
3706
+ return el;
3307
3707
  }
3308
3708
  /**
3309
3709
  * Removes all event listeners of a specific type from the element.
3310
3710
  *
3311
3711
  * @param {string} event - The event type to remove (e.g. 'click').
3712
+ * @returns {TinyEventTarget|TinyEventTarget[]}
3312
3713
  */
3313
3714
  offAll(event) {
3314
3715
  return TinyHtml.offAll(this, event);
@@ -3319,6 +3720,7 @@ class TinyHtml {
3319
3720
  * @param {TinyEventTarget|TinyEventTarget[]} el - The target element.
3320
3721
  * @param {((handler: EventListenerOrEventListenerObject, event: string) => boolean)|null} [filterFn=null] -
3321
3722
  * Optional filter function to selectively remove specific handlers.
3723
+ * @returns {TinyEventTarget|TinyEventTarget[]}
3322
3724
  */
3323
3725
  static offAllTypes(el, filterFn = null) {
3324
3726
  if (filterFn !== null && typeof filterFn !== 'function')
@@ -3336,12 +3738,14 @@ class TinyHtml {
3336
3738
  }
3337
3739
  __eventRegistry.delete(elem);
3338
3740
  });
3741
+ return el;
3339
3742
  }
3340
3743
  /**
3341
3744
  * Removes all event listeners of all types from the element.
3342
3745
  *
3343
3746
  * @param {((handler: EventListenerOrEventListenerObject, event: string) => boolean)|null} [filterFn=null] -
3344
3747
  * Optional filter function to selectively remove specific handlers.
3748
+ * @returns {TinyEventTarget|TinyEventTarget[]}
3345
3749
  */
3346
3750
  offAllTypes(filterFn = null) {
3347
3751
  return TinyHtml.offAllTypes(this, filterFn);
@@ -3352,6 +3756,7 @@ class TinyHtml {
3352
3756
  * @param {TinyEventTarget|TinyEventTarget[]} el - Target element where the event should be triggered.
3353
3757
  * @param {string} event - Name of the event to trigger.
3354
3758
  * @param {Event|CustomEvent|CustomEventInit} [payload] - Optional event object or data to pass.
3759
+ * @returns {TinyEventTarget|TinyEventTarget[]}
3355
3760
  */
3356
3761
  static trigger(el, event, payload = {}) {
3357
3762
  if (typeof event !== 'string')
@@ -3366,12 +3771,14 @@ class TinyHtml {
3366
3771
  });
3367
3772
  elem.dispatchEvent(evt);
3368
3773
  });
3774
+ return el;
3369
3775
  }
3370
3776
  /**
3371
3777
  * Triggers all handlers associated with a specific event on the given element.
3372
3778
  *
3373
3779
  * @param {string} event - Name of the event to trigger.
3374
3780
  * @param {Event|CustomEvent|CustomEventInit} [payload] - Optional event object or data to pass.
3781
+ * @returns {TinyEventTarget|TinyEventTarget[]}
3375
3782
  */
3376
3783
  trigger(event, payload = {}) {
3377
3784
  return TinyHtml.trigger(this, event, payload);
@@ -3410,6 +3817,7 @@ class TinyHtml {
3410
3817
  * @param {TinyElement|TinyElement[]} el
3411
3818
  * @param {string} name
3412
3819
  * @param {string|null} [value=null]
3820
+ * @returns {TinyElement|TinyElement[]}
3413
3821
  */
3414
3822
  static setAttr(el, name, value = null) {
3415
3823
  if (typeof name !== 'string')
@@ -3422,11 +3830,13 @@ class TinyHtml {
3422
3830
  else
3423
3831
  elem.setAttribute(name, value);
3424
3832
  });
3833
+ return el;
3425
3834
  }
3426
3835
  /**
3427
3836
  * Set an attribute on an element.
3428
3837
  * @param {string} name
3429
3838
  * @param {string|null} [value=null]
3839
+ * @returns {TinyElement|TinyElement[]}
3430
3840
  */
3431
3841
  setAttr(name, value) {
3432
3842
  return TinyHtml.setAttr(this, name, value);
@@ -3435,15 +3845,18 @@ class TinyHtml {
3435
3845
  * Remove attribute(s) from an element.
3436
3846
  * @param {TinyElement|TinyElement[]} el
3437
3847
  * @param {string} name Space-separated list of attributes.
3848
+ * @returns {TinyElement|TinyElement[]}
3438
3849
  */
3439
3850
  static removeAttr(el, name) {
3440
3851
  if (typeof name !== 'string')
3441
3852
  throw new TypeError('The "name" must be a string.');
3442
3853
  TinyHtml._preElems(el, 'removeAttr').forEach((elem) => elem.removeAttribute(name));
3854
+ return el;
3443
3855
  }
3444
3856
  /**
3445
3857
  * Remove attribute(s) from an element.
3446
3858
  * @param {string} name Space-separated list of attributes.
3859
+ * @returns {TinyElement|TinyElement[]}
3447
3860
  */
3448
3861
  removeAttr(name) {
3449
3862
  return TinyHtml.removeAttr(this, name);
@@ -3495,6 +3908,7 @@ class TinyHtml {
3495
3908
  * Set a property on an element.
3496
3909
  * @param {TinyElement|TinyElement[]} el
3497
3910
  * @param {string} name
3911
+ * @returns {TinyElement|TinyElement[]}
3498
3912
  */
3499
3913
  static addProp(el, name) {
3500
3914
  if (typeof name !== 'string')
@@ -3505,10 +3919,12 @@ class TinyHtml {
3505
3919
  // @ts-ignore
3506
3920
  elem[name] = true;
3507
3921
  });
3922
+ return el;
3508
3923
  }
3509
3924
  /**
3510
3925
  * Set a property on an element.
3511
3926
  * @param {string} name
3927
+ * @returns {TinyElement|TinyElement[]}
3512
3928
  */
3513
3929
  addProp(name) {
3514
3930
  return TinyHtml.addProp(this, name);
@@ -3517,6 +3933,7 @@ class TinyHtml {
3517
3933
  * Remove a property from an element.
3518
3934
  * @param {TinyElement|TinyElement[]} el
3519
3935
  * @param {string} name
3936
+ * @returns {TinyElement|TinyElement[]}
3520
3937
  */
3521
3938
  static removeProp(el, name) {
3522
3939
  if (typeof name !== 'string')
@@ -3527,10 +3944,12 @@ class TinyHtml {
3527
3944
  // @ts-ignore
3528
3945
  elem[name] = false;
3529
3946
  });
3947
+ return el;
3530
3948
  }
3531
3949
  /**
3532
3950
  * Remove a property from an element.
3533
3951
  * @param {string} name
3952
+ * @returns {TinyElement|TinyElement[]}
3534
3953
  */
3535
3954
  removeProp(name) {
3536
3955
  return TinyHtml.removeProp(this, name);
@@ -3570,12 +3989,15 @@ class TinyHtml {
3570
3989
  /**
3571
3990
  * Removes an element from the DOM.
3572
3991
  * @param {TinyElement|TinyElement[]} el - The DOM element or selector to remove.
3992
+ * @returns {TinyElement|TinyElement[]}
3573
3993
  */
3574
3994
  static remove(el) {
3575
3995
  TinyHtml._preElems(el, 'remove').forEach((elem) => elem.remove());
3996
+ return el;
3576
3997
  }
3577
3998
  /**
3578
3999
  * Removes the element from the DOM.
4000
+ * @returns {TinyElement|TinyElement[]}
3579
4001
  */
3580
4002
  remove() {
3581
4003
  return TinyHtml.remove(this);
@@ -3886,6 +4308,12 @@ class TinyHtml {
3886
4308
  */
3887
4309
  static isInViewport(el) {
3888
4310
  const elem = TinyHtml._preElem(el, 'isInViewport');
4311
+ if (!elem.checkVisibility({
4312
+ contentVisibilityAuto: false,
4313
+ opacityProperty: false,
4314
+ visibilityProperty: false,
4315
+ }))
4316
+ return false;
3889
4317
  const elementTop = TinyHtml.offset(elem).top;
3890
4318
  const elementBottom = elementTop + TinyHtml.outerHeight(elem);
3891
4319
  const viewportTop = TinyHtml.scrollTop(window);
@@ -3908,6 +4336,12 @@ class TinyHtml {
3908
4336
  */
3909
4337
  static isScrolledIntoView(el) {
3910
4338
  const elem = TinyHtml._preElem(el, 'isScrolledIntoView');
4339
+ if (!elem.checkVisibility({
4340
+ contentVisibilityAuto: false,
4341
+ opacityProperty: false,
4342
+ visibilityProperty: false,
4343
+ }))
4344
+ return false;
3911
4345
  const docViewTop = TinyHtml.scrollTop(window);
3912
4346
  const docViewBottom = docViewTop + TinyHtml.height(window);
3913
4347
  const elemTop = TinyHtml.offset(elem).top;
@@ -3922,5 +4356,90 @@ class TinyHtml {
3922
4356
  isScrolledIntoView() {
3923
4357
  return TinyHtml.isScrolledIntoView(this);
3924
4358
  }
4359
+ /**
4360
+ * Checks if the given element is at least partially visible within the boundaries of a container.
4361
+ *
4362
+ * @param {TinyElement} el - The DOM element to check.
4363
+ * @param {TinyElement} cont - The container element acting as the viewport.
4364
+ * @returns {boolean} True if the element is partially visible within the container, false otherwise.
4365
+ */
4366
+ static isInContainer(el, cont) {
4367
+ const elem = TinyHtml._preElem(el, 'isInContainer');
4368
+ const container = TinyHtml._preElem(cont, 'isInContainer');
4369
+ if (!elem.checkVisibility({
4370
+ contentVisibilityAuto: false,
4371
+ opacityProperty: false,
4372
+ visibilityProperty: false,
4373
+ }))
4374
+ return false;
4375
+ const elemRect = elem.getBoundingClientRect();
4376
+ const containerRect = container.getBoundingClientRect();
4377
+ const verticallyVisible = elemRect.bottom > containerRect.top && elemRect.top < containerRect.bottom;
4378
+ const horizontallyVisible = elemRect.right > containerRect.left && elemRect.left < containerRect.right;
4379
+ return verticallyVisible && horizontallyVisible;
4380
+ }
4381
+ /**
4382
+ * Checks if the given element is at least partially visible within the boundaries of a container.
4383
+ *
4384
+ * @param {TinyElement} cont - The container element acting as the viewport.
4385
+ * @returns {boolean} True if the element is partially visible within the container, false otherwise.
4386
+ */
4387
+ isInContainer(cont) {
4388
+ return TinyHtml.isInContainer(this, cont);
4389
+ }
4390
+ /**
4391
+ * Checks if the given element is fully visible within the boundaries of a container (top and bottom).
4392
+ *
4393
+ * @param {TinyElement} el - The DOM element to check.
4394
+ * @param {TinyElement} cont - The container element acting as the viewport.
4395
+ * @returns {boolean} True if the element is fully visible within the container, false otherwise.
4396
+ */
4397
+ static isFullyInContainer(el, cont) {
4398
+ const elem = TinyHtml._preElem(el, 'isScrolledIntoView');
4399
+ const container = TinyHtml._preElem(cont, 'isInContainer');
4400
+ if (!elem.checkVisibility({
4401
+ contentVisibilityAuto: false,
4402
+ opacityProperty: false,
4403
+ visibilityProperty: false,
4404
+ }))
4405
+ return false;
4406
+ const elemRect = elem.getBoundingClientRect();
4407
+ const containerRect = container.getBoundingClientRect();
4408
+ const isFullyVisible = elemRect.top >= containerRect.top &&
4409
+ elemRect.bottom <= containerRect.bottom &&
4410
+ elemRect.left >= containerRect.left &&
4411
+ elemRect.right <= containerRect.right;
4412
+ return isFullyVisible;
4413
+ }
4414
+ /**
4415
+ * Checks if the given element is fully visible within the boundaries of a container (top and bottom).
4416
+ *
4417
+ * @param {TinyElement} cont - The container element acting as the viewport.
4418
+ * @returns {boolean} True if the element is fully visible within the container, false otherwise.
4419
+ */
4420
+ isFullyInContainer(cont) {
4421
+ return TinyHtml.isFullyInContainer(this, cont);
4422
+ }
4423
+ /**
4424
+ * Checks if an element has scrollable content.
4425
+ *
4426
+ * @param {TinyElement} el - The DOM element to check.
4427
+ * @returns {{ v: boolean, h: boolean }} - True if scroll is needed in that direction.
4428
+ */
4429
+ static hasScroll(el) {
4430
+ const elem = TinyHtml._preElem(el, 'hasScroll');
4431
+ return {
4432
+ v: elem.scrollHeight > elem.clientHeight,
4433
+ h: elem.scrollWidth > elem.clientWidth,
4434
+ };
4435
+ }
4436
+ /**
4437
+ * Checks if an element has scrollable content.
4438
+ *
4439
+ * @returns {{ v: boolean, h: boolean }} - True if scroll is needed in that direction.
4440
+ */
4441
+ hasScroll() {
4442
+ return TinyHtml.hasScroll(this);
4443
+ }
3925
4444
  }
3926
4445
  export default TinyHtml;