tiny-essentials 1.27.1 → 1.28.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 (188) hide show
  1. package/README.md +1 -0
  2. package/changelog/1/28/0.md +16 -0
  3. package/changelog/1/28/1.md +23 -0
  4. package/dist/v1/TinyAdvancedRaffle.min.js +1 -1
  5. package/dist/v1/TinyAfterScrollWatcher.min.js +1 -1
  6. package/dist/v1/TinyAnalogClock.min.js +1 -1
  7. package/dist/v1/TinyBasicsEs.min.js +1 -2
  8. package/dist/v1/TinyDayNightCycle.min.js +1 -1
  9. package/dist/v1/TinyDragDropDetector.min.js +1 -1
  10. package/dist/v1/TinyDragger.min.js +1 -1
  11. package/dist/v1/TinyElementObserver.min.js +1 -1
  12. package/dist/v1/TinyEssentials.min.js +1 -2
  13. package/dist/v1/TinyGamepad.min.js +1 -1
  14. package/dist/v1/TinyHtml.min.js +1 -1
  15. package/dist/v1/TinyI18.min.js +1 -1
  16. package/dist/v1/TinyIframeEvents.min.js +1 -1
  17. package/dist/v1/TinyLocalStorage.min.js +1 -1
  18. package/dist/v1/TinyMediaPlayer.min.js +1 -1
  19. package/dist/v1/TinyNewWinEvents.min.js +1 -1
  20. package/dist/v1/TinyNotifyCenter.min.js +1 -1
  21. package/dist/v1/TinyRadioFm.min.js +1 -1
  22. package/dist/v1/TinyRateLimiter.min.js +1 -1
  23. package/dist/v1/TinySmartScroller.min.js +1 -1
  24. package/dist/v1/TinyTextDiffer.min.js +1 -1
  25. package/dist/v1/TinyTextarea.min.js +1 -1
  26. package/dist/v1/TinyTimeout.min.js +1 -1
  27. package/dist/v1/TinyToastNotify.min.js +1 -1
  28. package/dist/v1/TinyUploadClicker.min.js +1 -2
  29. package/dist/v1/UltraRandomMsgGen.min.js +1 -1
  30. package/dist/v1/basics/array.cjs +57 -9
  31. package/dist/v1/basics/array.d.mts +27 -11
  32. package/dist/v1/basics/array.mjs +51 -9
  33. package/dist/v1/basics/clock.cjs +94 -42
  34. package/dist/v1/basics/clock.d.mts +10 -10
  35. package/dist/v1/basics/clock.mjs +91 -54
  36. package/dist/v1/basics/deprecated/html.cjs +246 -0
  37. package/dist/v1/basics/deprecated/html.d.mts +63 -0
  38. package/dist/v1/basics/deprecated/html.mjs +190 -0
  39. package/dist/v1/basics/extendObjType/Buffer.cjs +13 -0
  40. package/dist/v1/basics/extendObjType/Buffer.d.mts +4 -0
  41. package/dist/v1/basics/extendObjType/Buffer.mjs +8 -0
  42. package/dist/v1/basics/html.cjs +149 -130
  43. package/dist/v1/basics/html.d.mts +26 -61
  44. package/dist/v1/basics/html.mjs +113 -105
  45. package/dist/v1/basics/index.cjs +2 -0
  46. package/dist/v1/basics/index.d.mts +3 -1
  47. package/dist/v1/basics/index.mjs +3 -3
  48. package/dist/v1/basics/mediaContent.cjs +51 -9
  49. package/dist/v1/basics/mediaContent.d.mts +0 -87
  50. package/dist/v1/basics/mediaContent.mjs +40 -10
  51. package/dist/v1/basics/objChecker.cjs +7 -5
  52. package/dist/v1/basics/objChecker.d.mts +3 -2
  53. package/dist/v1/basics/objChecker.mjs +6 -6
  54. package/dist/v1/basics/objFilter.cjs +40 -18
  55. package/dist/v1/basics/objFilter.d.mts +6 -6
  56. package/dist/v1/basics/objFilter.mjs +32 -17
  57. package/dist/v1/basics/simpleMath.cjs +81 -25
  58. package/dist/v1/basics/simpleMath.d.mts +2 -2
  59. package/dist/v1/basics/simpleMath.mjs +70 -27
  60. package/dist/v1/basics/text.cjs +76 -31
  61. package/dist/v1/basics/text.d.mts +69 -7
  62. package/dist/v1/basics/text.mjs +62 -31
  63. package/dist/v1/index.cjs +4 -2
  64. package/dist/v1/index.d.mts +4 -2
  65. package/dist/v1/index.mjs +4 -4
  66. package/dist/v1/libs/TinyAdvancedRaffle.cjs +71 -255
  67. package/dist/v1/libs/TinyAdvancedRaffle.d.mts +6 -134
  68. package/dist/v1/libs/TinyAdvancedRaffle.mjs +69 -228
  69. package/dist/v1/libs/TinyAfterScrollWatcher.cjs +17 -1
  70. package/dist/v1/libs/TinyAfterScrollWatcher.d.mts +4 -1
  71. package/dist/v1/libs/TinyAfterScrollWatcher.mjs +15 -1
  72. package/dist/v1/libs/TinyAnalogClock.cjs +60 -0
  73. package/dist/v1/libs/TinyAnalogClock.d.mts +6 -0
  74. package/dist/v1/libs/TinyAnalogClock.mjs +57 -0
  75. package/dist/v1/libs/TinyClipboard.cjs +2 -0
  76. package/dist/v1/libs/TinyClipboard.d.mts +4 -2
  77. package/dist/v1/libs/TinyClipboard.mjs +2 -0
  78. package/dist/v1/libs/TinyColorConverter.cjs +1 -0
  79. package/dist/v1/libs/TinyColorConverter.d.mts +2 -1
  80. package/dist/v1/libs/TinyColorConverter.mjs +1 -0
  81. package/dist/v1/libs/TinyDayNightCycle.cjs +67 -42
  82. package/dist/v1/libs/TinyDayNightCycle.d.mts +2 -7
  83. package/dist/v1/libs/TinyDayNightCycle.mjs +65 -41
  84. package/dist/v1/libs/TinyDragDropDetector.cjs +25 -0
  85. package/dist/v1/libs/TinyDragDropDetector.d.mts +6 -0
  86. package/dist/v1/libs/TinyDragDropDetector.mjs +22 -0
  87. package/dist/v1/libs/TinyDragger.cjs +46 -19
  88. package/dist/v1/libs/TinyDragger.mjs +45 -18
  89. package/dist/v1/libs/TinyElementObserver.cjs +39 -0
  90. package/dist/v1/libs/TinyElementObserver.d.mts +6 -0
  91. package/dist/v1/libs/TinyElementObserver.mjs +36 -0
  92. package/dist/v1/libs/TinyGamepad.cjs +131 -1
  93. package/dist/v1/libs/TinyGamepad.mjs +129 -1
  94. package/dist/v1/libs/TinyHtml.cjs +1 -1
  95. package/dist/v1/libs/TinyHtml.mjs +2 -2
  96. package/dist/v1/libs/TinyI18.cjs +61 -0
  97. package/dist/v1/libs/TinyI18.d.mts +14 -0
  98. package/dist/v1/libs/TinyI18.mjs +55 -0
  99. package/dist/v1/libs/TinyIframeEvents.cjs +26 -196
  100. package/dist/v1/libs/TinyIframeEvents.d.mts +3 -122
  101. package/dist/v1/libs/TinyIframeEvents.mjs +26 -171
  102. package/dist/v1/libs/TinyLocalStorage.cjs +53 -205
  103. package/dist/v1/libs/TinyLocalStorage.d.mts +6 -127
  104. package/dist/v1/libs/TinyLocalStorage.mjs +50 -178
  105. package/dist/v1/libs/TinyMediaPlayer.cjs +74 -2
  106. package/dist/v1/libs/TinyMediaPlayer.d.mts +12 -2
  107. package/dist/v1/libs/TinyMediaPlayer.mjs +68 -2
  108. package/dist/v1/libs/TinyNewWinEvents.cjs +39 -197
  109. package/dist/v1/libs/TinyNewWinEvents.d.mts +6 -119
  110. package/dist/v1/libs/TinyNewWinEvents.mjs +36 -172
  111. package/dist/v1/libs/TinyNotifyCenter.cjs +36 -0
  112. package/dist/v1/libs/TinyNotifyCenter.d.mts +6 -0
  113. package/dist/v1/libs/TinyNotifyCenter.mjs +32 -0
  114. package/dist/v1/libs/TinyRadioFm.cjs +40 -3
  115. package/dist/v1/libs/TinyRadioFm.d.mts +3 -3
  116. package/dist/v1/libs/TinyRadioFm.mjs +37 -3
  117. package/dist/v1/libs/TinyRateLimiter.cjs +52 -0
  118. package/dist/v1/libs/TinyRateLimiter.d.mts +6 -0
  119. package/dist/v1/libs/TinyRateLimiter.mjs +48 -0
  120. package/dist/v1/libs/TinySmartScroller.cjs +56 -205
  121. package/dist/v1/libs/TinySmartScroller.d.mts +19 -152
  122. package/dist/v1/libs/TinySmartScroller.mjs +55 -181
  123. package/dist/v1/libs/TinyTextDiffer.cjs +19 -18
  124. package/dist/v1/libs/TinyTextDiffer.d.mts +1 -0
  125. package/dist/v1/libs/TinyTextDiffer.mjs +16 -17
  126. package/dist/v1/libs/TinyTextarea.cjs +19 -0
  127. package/dist/v1/libs/TinyTextarea.d.mts +6 -0
  128. package/dist/v1/libs/TinyTextarea.mjs +17 -0
  129. package/dist/v1/libs/TinyTimeout.cjs +11 -1
  130. package/dist/v1/libs/TinyTimeout.mjs +9 -1
  131. package/dist/v1/libs/TinyToastNotify.cjs +35 -0
  132. package/dist/v1/libs/TinyToastNotify.d.mts +6 -0
  133. package/dist/v1/libs/TinyToastNotify.mjs +31 -0
  134. package/dist/v1/libs/TinyUploadClicker.cjs +20 -0
  135. package/dist/v1/libs/TinyUploadClicker.d.mts +6 -0
  136. package/dist/v1/libs/TinyUploadClicker.mjs +17 -0
  137. package/dist/v1/libs/UltraRandomMsgGen.cjs +148 -35
  138. package/dist/v1/libs/UltraRandomMsgGen.d.mts +17 -3
  139. package/dist/v1/libs/UltraRandomMsgGen.mjs +133 -34
  140. package/dist/v1/libs/utils.cjs +21 -0
  141. package/dist/v1/libs/utils.d.mts +2 -0
  142. package/dist/v1/libs/utils.mjs +16 -0
  143. package/docs/v1/Exports.md +0 -1
  144. package/docs/v1/README.md +1 -1
  145. package/docs/v1/basics/array.md +2 -2
  146. package/docs/v1/basics/deprecated/html.md +17 -0
  147. package/docs/v1/basics/fullScreen.md +1 -1
  148. package/docs/v1/basics/html.md +12 -26
  149. package/docs/v1/basics/mediaContent.md +1 -1
  150. package/docs/v1/basics/objChecker.md +1 -1
  151. package/docs/v1/basics/objFilter.md +1 -1
  152. package/docs/v1/basics/text.md +2 -2
  153. package/docs/v1/fileManager/main.md +1 -1
  154. package/docs/v1/libs/ColorSafeStringify.md +1 -1
  155. package/docs/v1/libs/TinyAfterScrollWatcher.md +1 -1
  156. package/docs/v1/libs/TinyAnalogClock.md +1 -1
  157. package/docs/v1/libs/TinyArrayComparator.md +1 -1
  158. package/docs/v1/libs/TinyArrayPaginator.md +1 -1
  159. package/docs/v1/libs/TinyClassManager/TinyPluginInliner.md +2 -2
  160. package/docs/v1/libs/TinyClassManager.md +1 -1
  161. package/docs/v1/libs/TinyClipboard.md +1 -1
  162. package/docs/v1/libs/TinyCookieConsent.md +1 -1
  163. package/docs/v1/libs/TinyDomReadyManager.md +1 -1
  164. package/docs/v1/libs/TinyDragDropDetector.md +1 -1
  165. package/docs/v1/libs/TinyDragger.md +1 -1
  166. package/docs/v1/libs/TinyElementObserver.md +1 -1
  167. package/docs/v1/libs/TinyHtml.md +1 -1
  168. package/docs/v1/libs/TinyIframeEvents.md +10 -10
  169. package/docs/v1/libs/TinyLevelUp.md +1 -1
  170. package/docs/v1/libs/TinyLoadingScreen.md +1 -1
  171. package/docs/v1/libs/TinyLocalStorage.md +3 -3
  172. package/docs/v1/libs/TinyNewWinEvents.md +10 -11
  173. package/docs/v1/libs/TinyNotifications.md +1 -1
  174. package/docs/v1/libs/TinyPromiseQueue.md +2 -2
  175. package/docs/v1/libs/TinyTextDiffer.md +1 -1
  176. package/docs/v1/libs/TinyTextarea.md +1 -1
  177. package/package.json +15 -5
  178. package/dist/v1/TinyBasicsEs.min.js.LICENSE.txt +0 -8
  179. package/dist/v1/TinyEssentials.min.js.LICENSE.txt +0 -8
  180. package/dist/v1/TinyEvents.min.js +0 -1
  181. package/dist/v1/TinyUploadClicker.min.js.LICENSE.txt +0 -8
  182. package/dist/v1/build/TinyEvents.cjs +0 -7
  183. package/dist/v1/build/TinyEvents.d.mts +0 -3
  184. package/dist/v1/build/TinyEvents.mjs +0 -2
  185. package/dist/v1/libs/TinyEvents.cjs +0 -395
  186. package/dist/v1/libs/TinyEvents.d.mts +0 -164
  187. package/dist/v1/libs/TinyEvents.mjs +0 -360
  188. package/docs/v1/libs/TinyEvents.md +0 -187
@@ -1,6 +1,8 @@
1
+ import { EventEmitter } from 'events';
1
2
  import TinyHtml from './TinyHtml.mjs';
2
3
  import * as TinyCollision from '../basics/collision.mjs';
3
- import TinyEvents from './TinyEvents.mjs';
4
+ import { createCheckDestroyed } from './utils.mjs';
5
+ const checkDestroy = createCheckDestroyed('TinySmartScroller');
4
6
  /**
5
7
  * Represents the dimensions of a DOM element.
6
8
  *
@@ -42,181 +44,8 @@ import TinyEvents from './TinyEvents.mjs';
42
44
  * This class is **not framework-dependent** and works with vanilla DOM elements and the window object.
43
45
  * @template {Element|Window} HTMLTarget
44
46
  */
45
- class TinySmartScroller {
47
+ class TinySmartScroller extends EventEmitter {
46
48
  static Utils = { ...TinyCollision, TinyHtml };
47
- #events = new TinyEvents();
48
- /**
49
- * Enables or disables throwing an error when the maximum number of listeners is exceeded.
50
- *
51
- * @param {boolean} shouldThrow - If true, an error will be thrown when the max is exceeded.
52
- */
53
- setThrowOnMaxListeners(shouldThrow) {
54
- return this.#events.setThrowOnMaxListeners(shouldThrow);
55
- }
56
- /**
57
- * Checks whether an error will be thrown when the max listener limit is exceeded.
58
- *
59
- * @returns {boolean} True if an error will be thrown, false if only a warning is shown.
60
- */
61
- getThrowOnMaxListeners() {
62
- return this.#events.getThrowOnMaxListeners();
63
- }
64
- /////////////////////////////////////////////////////////////
65
- /**
66
- * Adds a listener to the beginning of the listeners array for the specified event.
67
- *
68
- * @param {string|string[]} event - Event name.
69
- * @param {ScrollListenersFunc} handler - The callback function.
70
- */
71
- prependListener(event, handler) {
72
- return this.#events.prependListener(event, handler);
73
- }
74
- /**
75
- * Adds a one-time listener to the beginning of the listeners array for the specified event.
76
- *
77
- * @param {string|string[]} event - Event name.
78
- * @param {ScrollListenersFunc} handler - The callback function.
79
- * @returns {ScrollListenersFunc[]} - The wrapped handler used internally.
80
- */
81
- prependListenerOnce(event, handler) {
82
- return this.#events.prependListenerOnce(event, handler);
83
- }
84
- //////////////////////////////////////////////////////////////////////
85
- /**
86
- * Adds a event listener.
87
- *
88
- * @param {string|string[]} event - Event name, such as 'onScrollBoundary' or 'onAutoScroll'.
89
- * @param {ScrollListenersFunc} handler - Callback function to be called when event fires.
90
- */
91
- appendListener(event, handler) {
92
- return this.#events.appendListener(event, handler);
93
- }
94
- /**
95
- * Registers an event listener that runs only once, then is removed.
96
- *
97
- * @param {string|string[]} event - Event name, such as 'onScrollBoundary' or 'onAutoScroll'.
98
- * @param {ScrollListenersFunc} handler - The callback function to run on event.
99
- * @returns {ScrollListenersFunc[]} - The wrapped version of the handler.
100
- */
101
- appendListenerOnce(event, handler) {
102
- return this.#events.appendListenerOnce(event, handler);
103
- }
104
- /**
105
- * Adds a event listener.
106
- *
107
- * @param {string|string[]} event - Event name, such as 'onScrollBoundary' or 'onAutoScroll'.
108
- * @param {ScrollListenersFunc} handler - Callback function to be called when event fires.
109
- */
110
- on(event, handler) {
111
- return this.#events.on(event, handler);
112
- }
113
- /**
114
- * Registers an event listener that runs only once, then is removed.
115
- *
116
- * @param {string|string[]} event - Event name, such as 'onScrollBoundary' or 'onAutoScroll'.
117
- * @param {ScrollListenersFunc} handler - The callback function to run on event.
118
- * @returns {ScrollListenersFunc[]} - The wrapped version of the handler.
119
- */
120
- once(event, handler) {
121
- return this.#events.once(event, handler);
122
- }
123
- ////////////////////////////////////////////////////////////////////
124
- /**
125
- * Removes a previously registered event listener.
126
- *
127
- * @param {string|string[]} event - The name of the event to remove the handler from.
128
- * @param {ScrollListenersFunc} handler - The specific callback function to remove.
129
- */
130
- off(event, handler) {
131
- return this.#events.off(event, handler);
132
- }
133
- /**
134
- * Removes all event listeners of a specific type from the element.
135
- *
136
- * @param {string|string[]} event - The event type to remove (e.g. 'onScrollBoundary').
137
- */
138
- offAll(event) {
139
- return this.#events.offAll(event);
140
- }
141
- /**
142
- * Removes all event listeners of all types from the element.
143
- */
144
- offAllTypes() {
145
- return this.#events.offAllTypes();
146
- }
147
- ////////////////////////////////////////////////////////////
148
- /**
149
- * Returns the number of listeners for a given event.
150
- *
151
- * @param {string} event - The name of the event.
152
- * @returns {number} Number of listeners for the event.
153
- */
154
- listenerCount(event) {
155
- return this.#events.listenerCount(event);
156
- }
157
- /**
158
- * Returns a copy of the array of listeners for the specified event.
159
- *
160
- * @param {string} event - The name of the event.
161
- * @returns {ScrollListenersFunc[]} Array of listener functions.
162
- */
163
- listeners(event) {
164
- return this.#events.listeners(event);
165
- }
166
- /**
167
- * Returns a copy of the array of listeners for the specified event.
168
- *
169
- * @param {string} event - The name of the event.
170
- * @returns {ScrollListenersFunc[]} Array of listener functions.
171
- */
172
- onceListeners(event) {
173
- return this.#events.onceListeners(event);
174
- }
175
- /**
176
- * Returns a copy of the internal listeners array for the specified event,
177
- * including wrapper functions like those used by `.once()`.
178
- * @param {string | symbol} event - The event name.
179
- * @returns {ScrollListenersFunc[]} An array of raw listener functions.
180
- */
181
- allListeners(event) {
182
- return this.#events.allListeners(event);
183
- }
184
- /**
185
- * Returns an array of event names for which there are registered listeners.
186
- *
187
- * @returns {string[]} Array of registered event names.
188
- */
189
- eventNames() {
190
- return this.#events.eventNames();
191
- }
192
- //////////////////////////////////////////////////////
193
- /**
194
- * Emits an event, triggering all registered handlers for that event.
195
- *
196
- * @param {string} event - The event name to emit.
197
- * @param {...any} payload - Optional data to pass to each handler.
198
- * @returns {boolean[]} True if any listeners were called, false otherwise.
199
- */
200
- emit(event, ...payload) {
201
- return this.#events.emit(event, ...payload);
202
- }
203
- /**
204
- * Sets the maximum number of listeners per event before a warning is shown.
205
- *
206
- * @param {number} n - The maximum number of listeners.
207
- */
208
- setMaxListeners(n) {
209
- return this.#events.setMaxListeners(n);
210
- }
211
- /**
212
- * Gets the maximum number of listeners allowed per event.
213
- *
214
- * @returns {number} The maximum number of listeners.
215
- */
216
- getMaxListeners() {
217
- return this.#events.getMaxListeners();
218
- }
219
- ///////////////////////////////////////////////////
220
49
  /** @type {WeakMap<Element, NodeSizes>} */
221
50
  #oldSizes = new WeakMap();
222
51
  /** @type {WeakMap<Element, NodeSizes>} */
@@ -281,6 +110,7 @@ class TinySmartScroller {
281
110
  * - Which attributes to observe for changes.
282
111
  */
283
112
  constructor(target, { extraScrollBoundary = 0, autoScrollBottom = true, observeMutations = true, preserveScrollOnLayoutShift = true, debounceTime = 100, querySelector = null, attributeFilter = ['class', 'style', 'src', 'data-*', 'height', 'width'], } = {}) {
113
+ super();
284
114
  // === target ===
285
115
  if (!(target instanceof Element ||
286
116
  // @ts-ignore
@@ -344,6 +174,7 @@ class TinySmartScroller {
344
174
  * @returns {NodeSizesEvent} A function that compares previous and current height, returning height delta.
345
175
  */
346
176
  getSimpleOnHeight(filter = []) {
177
+ checkDestroy(this.#destroyed);
347
178
  if (!Array.isArray(filter))
348
179
  throw new TypeError('getSimpleOnHeight(filter): filter must be an array of tag names');
349
180
  return (elem, sizes, amounts) => {
@@ -362,6 +193,7 @@ class TinySmartScroller {
362
193
  * @returns {NodeSizesEvent} The added size difference callback.
363
194
  */
364
195
  addSimpleOnHeight(filter) {
196
+ checkDestroy(this.#destroyed);
365
197
  if (!Array.isArray(filter))
366
198
  throw new TypeError('addSimpleOnHeight(filter): filter must be an array of tag names');
367
199
  const result = this.getSimpleOnHeight(filter);
@@ -374,6 +206,7 @@ class TinySmartScroller {
374
206
  * @returns {string[]} Array of tag names.
375
207
  */
376
208
  getLoadTags() {
209
+ checkDestroy(this.#destroyed);
377
210
  return Array.from(this.#loadTags);
378
211
  }
379
212
  /**
@@ -382,6 +215,7 @@ class TinySmartScroller {
382
215
  * @param {string} tag - The tag name to add (e.g., 'IMG').
383
216
  */
384
217
  addLoadTag(tag) {
218
+ checkDestroy(this.#destroyed);
385
219
  if (typeof tag !== 'string')
386
220
  throw new TypeError('addLoadTag(tag): tag must be a string');
387
221
  this.#loadTags.add(tag.toUpperCase());
@@ -392,6 +226,7 @@ class TinySmartScroller {
392
226
  * @param {string} tag - The tag name to remove.
393
227
  */
394
228
  removeLoadTag(tag) {
229
+ checkDestroy(this.#destroyed);
395
230
  if (typeof tag !== 'string')
396
231
  throw new TypeError('removeLoadTag(tag): tag must be a string');
397
232
  this.#loadTags.delete(tag.toUpperCase());
@@ -403,6 +238,7 @@ class TinySmartScroller {
403
238
  * @returns {boolean} True if the tag is being tracked.
404
239
  */
405
240
  hasLoadTag(tag) {
241
+ checkDestroy(this.#destroyed);
406
242
  if (typeof tag !== 'string')
407
243
  throw new TypeError('hasLoadTag(tag): tag must be a string');
408
244
  return this.#loadTags.has(tag.toUpperCase());
@@ -414,6 +250,7 @@ class TinySmartScroller {
414
250
  * @throws {TypeError} If `addDefault` is not a boolean.
415
251
  */
416
252
  resetLoadTags(addDefault = false) {
253
+ checkDestroy(this.#destroyed);
417
254
  if (typeof addDefault !== 'boolean')
418
255
  throw new TypeError('resetLoadTags(addDefault): addDefault must be a boolean');
419
256
  this.#loadTags.clear();
@@ -429,6 +266,7 @@ class TinySmartScroller {
429
266
  * @returns {string[]} Array of attribute names.
430
267
  */
431
268
  getAttributeFilters() {
269
+ checkDestroy(this.#destroyed);
432
270
  return Array.from(this.#attributeFilter);
433
271
  }
434
272
  /**
@@ -437,6 +275,7 @@ class TinySmartScroller {
437
275
  * @param {string} attr - The attribute name to add.
438
276
  */
439
277
  addAttributeFilter(attr) {
278
+ checkDestroy(this.#destroyed);
440
279
  if (typeof attr !== 'string')
441
280
  throw new TypeError('addAttributeFilter(attr): attr must be a string');
442
281
  this.#attributeFilter.add(attr);
@@ -447,6 +286,7 @@ class TinySmartScroller {
447
286
  * @param {string} attr - The attribute name to remove.
448
287
  */
449
288
  removeAttributeFilter(attr) {
289
+ checkDestroy(this.#destroyed);
450
290
  if (typeof attr !== 'string')
451
291
  throw new TypeError('removeAttributeFilter(attr): attr must be a string');
452
292
  this.#attributeFilter.delete(attr);
@@ -458,6 +298,7 @@ class TinySmartScroller {
458
298
  * @returns {boolean} True if the attribute is being filtered.
459
299
  */
460
300
  hasAttributeFilter(attr) {
301
+ checkDestroy(this.#destroyed);
461
302
  if (typeof attr !== 'string')
462
303
  throw new TypeError('hasAttributeFilter(attr): attr must be a string');
463
304
  return this.#attributeFilter.has(attr);
@@ -470,6 +311,7 @@ class TinySmartScroller {
470
311
  * @throws {TypeError} If `addDefault` is not a boolean.
471
312
  */
472
313
  resetAttributeFilters(addDefault = false) {
314
+ checkDestroy(this.#destroyed);
473
315
  if (typeof addDefault !== 'boolean')
474
316
  throw new TypeError('resetAttributeFilters(addDefault): addDefault must be a boolean');
475
317
  this.#attributeFilter.clear();
@@ -483,8 +325,7 @@ class TinySmartScroller {
483
325
  * @param {NodeSizesEvent} handler - Function that compares old and new sizes.
484
326
  */
485
327
  onSize(handler) {
486
- if (this.#destroyed)
487
- return;
328
+ checkDestroy(this.#destroyed);
488
329
  if (typeof handler !== 'function')
489
330
  throw new TypeError('onSize(handler): handler must be a function');
490
331
  this.#sizeFilter.add(handler);
@@ -495,8 +336,7 @@ class TinySmartScroller {
495
336
  * @param {NodeSizesEvent} handler - The handler function to remove.
496
337
  */
497
338
  offSize(handler) {
498
- if (this.#destroyed)
499
- return;
339
+ checkDestroy(this.#destroyed);
500
340
  if (typeof handler !== 'function')
501
341
  throw new TypeError('offSize(handler): handler must be a function');
502
342
  this.#sizeFilter.delete(handler);
@@ -505,6 +345,7 @@ class TinySmartScroller {
505
345
  * Checks which elements inside the target are currently visible and updates internal maps.
506
346
  *
507
347
  * @returns {Map<Element, { oldIsVisible: boolean; isVisible: boolean }>} Visibility comparison results.
348
+ * @private
508
349
  */
509
350
  _scrollDataUpdater() {
510
351
  const results = new Map();
@@ -519,6 +360,7 @@ class TinySmartScroller {
519
360
  }
520
361
  /**
521
362
  * Handles scroll events, calculates position-related statuses, and emits appropriate events.
363
+ * @private
522
364
  */
523
365
  _onScroll() {
524
366
  if (this.#destroyed)
@@ -574,6 +416,7 @@ class TinySmartScroller {
574
416
  * Attempts to correct the scroll position when layout shifts happen, preserving the user position if needed.
575
417
  *
576
418
  * @param {Element[]} [targets=[]] - List of elements involved in the size change.
419
+ * @private
577
420
  */
578
421
  _fixScroll(targets = []) {
579
422
  if (this.#destroyed)
@@ -650,6 +493,7 @@ class TinySmartScroller {
650
493
  }
651
494
  /**
652
495
  * Sets up a MutationObserver to watch for DOM changes and react accordingly to maintain scroll consistency.
496
+ * @private
653
497
  */
654
498
  _observeMutations() {
655
499
  this.#mutationObserver = new MutationObserver((mutations) => {
@@ -685,6 +529,7 @@ class TinySmartScroller {
685
529
  * Adds a ResizeObserver to monitor elements' size changes and trigger layout adjustments.
686
530
  *
687
531
  * @param {NodeListOf<Element>|Element[]|HTMLCollection} elements - Elements to observe.
532
+ * @private
688
533
  */
689
534
  _observeResizes(elements) {
690
535
  // Add resize observer
@@ -722,6 +567,7 @@ class TinySmartScroller {
722
567
  * Listens for media/content load events (e.g., images, iframes, videos) to trigger scroll updates.
723
568
  *
724
569
  * @param {NodeListOf<Element>|Element} elements - Target element(s) to listen on.
570
+ * @private
725
571
  */
726
572
  _listenLoadEvents(elements) {
727
573
  if (this.#destroyed)
@@ -757,6 +603,7 @@ class TinySmartScroller {
757
603
  * @returns {NodeSizes|null} The old size, or undefined.
758
604
  */
759
605
  getOldSize(el) {
606
+ checkDestroy(this.#destroyed);
760
607
  return this.#oldSizes.get(el) ?? null;
761
608
  }
762
609
  /**
@@ -766,6 +613,7 @@ class TinySmartScroller {
766
613
  * @returns {NodeSizes|null} The new size, or undefined.
767
614
  */
768
615
  getNewSize(el) {
616
+ checkDestroy(this.#destroyed);
769
617
  return this.#newSizes.get(el) ?? null;
770
618
  }
771
619
  /**
@@ -775,6 +623,7 @@ class TinySmartScroller {
775
623
  * @returns {boolean} True if visible, false if not, or undefined if not tracked.
776
624
  */
777
625
  wasVisible(el) {
626
+ checkDestroy(this.#destroyed);
778
627
  return this.#oldVisibles.get(el) ?? false;
779
628
  }
780
629
  /**
@@ -784,6 +633,7 @@ class TinySmartScroller {
784
633
  * @returns {boolean} True if visible, false if not, or undefined if not tracked.
785
634
  */
786
635
  isVisible(el) {
636
+ checkDestroy(this.#destroyed);
787
637
  return this.#newVisibles.get(el) ?? false;
788
638
  }
789
639
  /**
@@ -793,6 +643,7 @@ class TinySmartScroller {
793
643
  * @returns {boolean} Visibility state from the previous timed check.
794
644
  */
795
645
  wasTimedVisible(el) {
646
+ checkDestroy(this.#destroyed);
796
647
  return this.#oldVisiblesByTime.get(el) ?? false;
797
648
  }
798
649
  /**
@@ -802,6 +653,7 @@ class TinySmartScroller {
802
653
  * @returns {boolean} Visibility state from the current timed check.
803
654
  */
804
655
  isTimedVisible(el) {
656
+ checkDestroy(this.#destroyed);
805
657
  return this.#newVisiblesByTime.get(el) ?? false;
806
658
  }
807
659
  /**
@@ -810,6 +662,7 @@ class TinySmartScroller {
810
662
  * @param {number} value - Pixels of additional margin to use.
811
663
  */
812
664
  setExtraScrollBoundary(value) {
665
+ checkDestroy(this.#destroyed);
813
666
  if (typeof value !== 'number' || Number.isNaN(value))
814
667
  throw new TypeError('setExtraScrollBoundary(value): value must be a valid number');
815
668
  this.#extraScrollBoundary = value;
@@ -820,6 +673,7 @@ class TinySmartScroller {
820
673
  * @returns {number}
821
674
  */
822
675
  getExtraScrollBoundary() {
676
+ checkDestroy(this.#destroyed);
823
677
  return this.#extraScrollBoundary;
824
678
  }
825
679
  /**
@@ -828,18 +682,21 @@ class TinySmartScroller {
828
682
  * @returns {number}
829
683
  */
830
684
  getLastKnownScrollBottomOffset() {
685
+ checkDestroy(this.#destroyed);
831
686
  return this.#lastKnownScrollBottomOffset;
832
687
  }
833
688
  /**
834
689
  * Forces the scroll position to move to the very bottom of the target.
835
690
  */
836
691
  scrollToBottom() {
692
+ checkDestroy(this.#destroyed);
837
693
  this.#targetElement.scrollTop = this.#targetElement.scrollHeight;
838
694
  }
839
695
  /**
840
696
  * Forces the scroll position to move to the very top of the target.
841
697
  */
842
698
  scrollToTop() {
699
+ checkDestroy(this.#destroyed);
843
700
  this.#targetElement.scrollTop = 0;
844
701
  }
845
702
  /**
@@ -848,6 +705,7 @@ class TinySmartScroller {
848
705
  * @returns {boolean}
849
706
  */
850
707
  isAtCustomBottom() {
708
+ checkDestroy(this.#destroyed);
851
709
  return this.#isAtCustomBottom;
852
710
  }
853
711
  /**
@@ -856,6 +714,7 @@ class TinySmartScroller {
856
714
  * @returns {boolean}
857
715
  */
858
716
  isAtCustomTop() {
717
+ checkDestroy(this.#destroyed);
859
718
  return this.#isAtCustomTop;
860
719
  }
861
720
  /**
@@ -864,6 +723,7 @@ class TinySmartScroller {
864
723
  * @returns {boolean}
865
724
  */
866
725
  isAtBottom() {
726
+ checkDestroy(this.#destroyed);
867
727
  return this.#isAtBottom;
868
728
  }
869
729
  /**
@@ -872,6 +732,7 @@ class TinySmartScroller {
872
732
  * @returns {boolean}
873
733
  */
874
734
  isAtTop() {
735
+ checkDestroy(this.#destroyed);
875
736
  return this.#isAtTop;
876
737
  }
877
738
  /**
@@ -880,6 +741,7 @@ class TinySmartScroller {
880
741
  * @returns {boolean}
881
742
  */
882
743
  isPastAtBottom() {
744
+ checkDestroy(this.#destroyed);
883
745
  return this.#isPastAtBottom;
884
746
  }
885
747
  /**
@@ -888,6 +750,7 @@ class TinySmartScroller {
888
750
  * @returns {boolean}
889
751
  */
890
752
  isPastAtTop() {
753
+ checkDestroy(this.#destroyed);
891
754
  return this.#isPastAtTop;
892
755
  }
893
756
  /**
@@ -896,6 +759,7 @@ class TinySmartScroller {
896
759
  * @returns {boolean}
897
760
  */
898
761
  isPastAtCustomTop() {
762
+ checkDestroy(this.#destroyed);
899
763
  return this.#isPastAtCustomTop;
900
764
  }
901
765
  /**
@@ -904,6 +768,7 @@ class TinySmartScroller {
904
768
  * @returns {boolean}
905
769
  */
906
770
  isPastAtCustomBottom() {
771
+ checkDestroy(this.#destroyed);
907
772
  return this.#isPastAtCustomBottom;
908
773
  }
909
774
  /**
@@ -912,6 +777,7 @@ class TinySmartScroller {
912
777
  * @returns {boolean}
913
778
  */
914
779
  isScrollPaused() {
780
+ checkDestroy(this.#destroyed);
915
781
  return this.#scrollPaused;
916
782
  }
917
783
  /**
@@ -920,6 +786,7 @@ class TinySmartScroller {
920
786
  * @returns {boolean} True if the scroll target is window, false otherwise.
921
787
  */
922
788
  isWindow() {
789
+ checkDestroy(this.#destroyed);
923
790
  return this.#useWindow;
924
791
  }
925
792
  /**
@@ -936,6 +803,7 @@ class TinySmartScroller {
936
803
  * @returns {boolean} True if auto-scroll is active, false otherwise.
937
804
  */
938
805
  getAutoScrollBottom() {
806
+ checkDestroy(this.#destroyed);
939
807
  return this.#autoScrollBottom;
940
808
  }
941
809
  /**
@@ -944,6 +812,7 @@ class TinySmartScroller {
944
812
  * @returns {boolean} True if mutation observation is active, false otherwise.
945
813
  */
946
814
  getObserveMutations() {
815
+ checkDestroy(this.#destroyed);
947
816
  return this.#observeMutations;
948
817
  }
949
818
  /**
@@ -952,6 +821,7 @@ class TinySmartScroller {
952
821
  * @returns {boolean} True if scroll preservation is active, false otherwise.
953
822
  */
954
823
  getPreserveScrollOnLayoutShift() {
824
+ checkDestroy(this.#destroyed);
955
825
  return this.#preserveScrollOnLayoutShift;
956
826
  }
957
827
  /**
@@ -960,6 +830,7 @@ class TinySmartScroller {
960
830
  * @returns {number} Debounce delay time.
961
831
  */
962
832
  getDebounceTime() {
833
+ checkDestroy(this.#destroyed);
963
834
  return this.#debounceTime;
964
835
  }
965
836
  /**
@@ -968,6 +839,7 @@ class TinySmartScroller {
968
839
  * @returns {number} Current count of matching elements.
969
840
  */
970
841
  getElemAmount() {
842
+ checkDestroy(this.#destroyed);
971
843
  return this.#elemAmount;
972
844
  }
973
845
  /**
@@ -976,6 +848,7 @@ class TinySmartScroller {
976
848
  * @returns {number} Previous count of matching elements.
977
849
  */
978
850
  getPrevElemAmount() {
851
+ checkDestroy(this.#destroyed);
979
852
  return this.#elemOldAmount;
980
853
  }
981
854
  /**
@@ -984,6 +857,7 @@ class TinySmartScroller {
984
857
  * @returns {string} The CSS selector string, or an empty string if none was provided.
985
858
  */
986
859
  getQuerySelector() {
860
+ checkDestroy(this.#destroyed);
987
861
  return this.#querySelector;
988
862
  }
989
863
  /**
@@ -993,7 +867,6 @@ class TinySmartScroller {
993
867
  destroy() {
994
868
  if (this.#destroyed)
995
869
  return;
996
- this.#destroyed = true;
997
870
  // Disconnects MutationObserver
998
871
  if (this.#mutationObserver) {
999
872
  this.#mutationObserver.disconnect();
@@ -1016,9 +889,10 @@ class TinySmartScroller {
1016
889
  this.#newVisiblesByTime = new WeakMap();
1017
890
  this.#oldVisiblesByTime = new WeakMap();
1018
891
  // Cleans listeners and filters
1019
- this.#events.offAllTypes();
892
+ this.removeAllListeners();
1020
893
  this.#sizeFilter.clear();
1021
894
  this.#loadTags.clear();
895
+ this.#destroyed = true;
1022
896
  }
1023
897
  }
1024
898
  export default TinySmartScroller;