tiny-essentials 1.28.0 → 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.
- package/changelog/1/28/1.md +23 -0
- package/dist/v1/TinyAdvancedRaffle.min.js +1 -1
- package/dist/v1/TinyAfterScrollWatcher.min.js +1 -1
- package/dist/v1/TinyAnalogClock.min.js +1 -1
- package/dist/v1/TinyBasicsEs.min.js +1 -1
- package/dist/v1/TinyDayNightCycle.min.js +1 -1
- package/dist/v1/TinyDragDropDetector.min.js +1 -1
- package/dist/v1/TinyDragger.min.js +1 -1
- package/dist/v1/TinyElementObserver.min.js +1 -1
- package/dist/v1/TinyEssentials.min.js +1 -1
- package/dist/v1/TinyGamepad.min.js +1 -1
- package/dist/v1/TinyHtml.min.js +1 -1
- package/dist/v1/TinyI18.min.js +1 -1
- package/dist/v1/TinyIframeEvents.min.js +1 -1
- package/dist/v1/TinyLocalStorage.min.js +1 -1
- package/dist/v1/TinyMediaPlayer.min.js +1 -1
- package/dist/v1/TinyNewWinEvents.min.js +1 -1
- package/dist/v1/TinyNotifyCenter.min.js +1 -1
- package/dist/v1/TinyRadioFm.min.js +1 -1
- package/dist/v1/TinyRateLimiter.min.js +1 -1
- package/dist/v1/TinySmartScroller.min.js +1 -1
- package/dist/v1/TinyTextDiffer.min.js +1 -1
- package/dist/v1/TinyTextarea.min.js +1 -1
- package/dist/v1/TinyTimeout.min.js +1 -1
- package/dist/v1/TinyToastNotify.min.js +1 -1
- package/dist/v1/TinyUploadClicker.min.js +1 -1
- package/dist/v1/UltraRandomMsgGen.min.js +1 -1
- package/dist/v1/basics/array.cjs +57 -9
- package/dist/v1/basics/array.d.mts +27 -11
- package/dist/v1/basics/array.mjs +51 -9
- package/dist/v1/basics/clock.cjs +94 -42
- package/dist/v1/basics/clock.d.mts +10 -10
- package/dist/v1/basics/clock.mjs +91 -54
- package/dist/v1/basics/deprecated/html.cjs +246 -0
- package/dist/v1/basics/deprecated/html.d.mts +63 -0
- package/dist/v1/basics/deprecated/html.mjs +190 -0
- package/dist/v1/basics/html.cjs +149 -130
- package/dist/v1/basics/html.d.mts +26 -61
- package/dist/v1/basics/html.mjs +113 -105
- package/dist/v1/basics/index.cjs +2 -0
- package/dist/v1/basics/index.d.mts +3 -1
- package/dist/v1/basics/index.mjs +3 -3
- package/dist/v1/basics/mediaContent.cjs +51 -9
- package/dist/v1/basics/mediaContent.d.mts +0 -87
- package/dist/v1/basics/mediaContent.mjs +40 -10
- package/dist/v1/basics/objChecker.cjs +7 -5
- package/dist/v1/basics/objChecker.d.mts +3 -2
- package/dist/v1/basics/objChecker.mjs +6 -6
- package/dist/v1/basics/objFilter.cjs +40 -7
- package/dist/v1/basics/objFilter.d.mts +6 -6
- package/dist/v1/basics/objFilter.mjs +32 -7
- package/dist/v1/basics/simpleMath.cjs +81 -25
- package/dist/v1/basics/simpleMath.d.mts +2 -2
- package/dist/v1/basics/simpleMath.mjs +70 -27
- package/dist/v1/basics/text.cjs +76 -31
- package/dist/v1/basics/text.d.mts +69 -7
- package/dist/v1/basics/text.mjs +62 -31
- package/dist/v1/index.cjs +4 -0
- package/dist/v1/index.d.mts +4 -1
- package/dist/v1/index.mjs +4 -3
- package/dist/v1/libs/TinyAdvancedRaffle.cjs +64 -50
- package/dist/v1/libs/TinyAdvancedRaffle.d.mts +4 -13
- package/dist/v1/libs/TinyAdvancedRaffle.mjs +62 -49
- package/dist/v1/libs/TinyAfterScrollWatcher.cjs +17 -1
- package/dist/v1/libs/TinyAfterScrollWatcher.d.mts +4 -1
- package/dist/v1/libs/TinyAfterScrollWatcher.mjs +15 -1
- package/dist/v1/libs/TinyAnalogClock.cjs +60 -0
- package/dist/v1/libs/TinyAnalogClock.d.mts +6 -0
- package/dist/v1/libs/TinyAnalogClock.mjs +57 -0
- package/dist/v1/libs/TinyClipboard.cjs +2 -0
- package/dist/v1/libs/TinyClipboard.d.mts +4 -2
- package/dist/v1/libs/TinyClipboard.mjs +2 -0
- package/dist/v1/libs/TinyColorConverter.cjs +1 -0
- package/dist/v1/libs/TinyColorConverter.d.mts +2 -1
- package/dist/v1/libs/TinyColorConverter.mjs +1 -0
- package/dist/v1/libs/TinyDayNightCycle.cjs +67 -42
- package/dist/v1/libs/TinyDayNightCycle.d.mts +2 -7
- package/dist/v1/libs/TinyDayNightCycle.mjs +65 -41
- package/dist/v1/libs/TinyDragDropDetector.cjs +25 -0
- package/dist/v1/libs/TinyDragDropDetector.d.mts +6 -0
- package/dist/v1/libs/TinyDragDropDetector.mjs +22 -0
- package/dist/v1/libs/TinyDragger.cjs +46 -19
- package/dist/v1/libs/TinyDragger.mjs +45 -18
- package/dist/v1/libs/TinyElementObserver.cjs +39 -0
- package/dist/v1/libs/TinyElementObserver.d.mts +6 -0
- package/dist/v1/libs/TinyElementObserver.mjs +36 -0
- package/dist/v1/libs/TinyGamepad.cjs +131 -1
- package/dist/v1/libs/TinyGamepad.mjs +129 -1
- package/dist/v1/libs/TinyHtml.cjs +1 -1
- package/dist/v1/libs/TinyHtml.mjs +2 -2
- package/dist/v1/libs/TinyI18.cjs +61 -0
- package/dist/v1/libs/TinyI18.d.mts +14 -0
- package/dist/v1/libs/TinyI18.mjs +55 -0
- package/dist/v1/libs/TinyIframeEvents.cjs +18 -1
- package/dist/v1/libs/TinyIframeEvents.mjs +18 -1
- package/dist/v1/libs/TinyLocalStorage.cjs +48 -0
- package/dist/v1/libs/TinyLocalStorage.d.mts +6 -0
- package/dist/v1/libs/TinyLocalStorage.mjs +45 -0
- package/dist/v1/libs/TinyMediaPlayer.cjs +72 -0
- package/dist/v1/libs/TinyMediaPlayer.d.mts +10 -0
- package/dist/v1/libs/TinyMediaPlayer.mjs +66 -0
- package/dist/v1/libs/TinyNewWinEvents.cjs +29 -0
- package/dist/v1/libs/TinyNewWinEvents.d.mts +6 -0
- package/dist/v1/libs/TinyNewWinEvents.mjs +26 -0
- package/dist/v1/libs/TinyNotifyCenter.cjs +36 -0
- package/dist/v1/libs/TinyNotifyCenter.d.mts +6 -0
- package/dist/v1/libs/TinyNotifyCenter.mjs +32 -0
- package/dist/v1/libs/TinyRadioFm.cjs +38 -0
- package/dist/v1/libs/TinyRadioFm.d.mts +1 -0
- package/dist/v1/libs/TinyRadioFm.mjs +35 -0
- package/dist/v1/libs/TinyRateLimiter.cjs +52 -0
- package/dist/v1/libs/TinyRateLimiter.d.mts +6 -0
- package/dist/v1/libs/TinyRateLimiter.mjs +48 -0
- package/dist/v1/libs/TinySmartScroller.cjs +52 -3
- package/dist/v1/libs/TinySmartScroller.d.mts +17 -15
- package/dist/v1/libs/TinySmartScroller.mjs +51 -5
- package/dist/v1/libs/TinyTextDiffer.cjs +19 -18
- package/dist/v1/libs/TinyTextDiffer.d.mts +1 -0
- package/dist/v1/libs/TinyTextDiffer.mjs +16 -17
- package/dist/v1/libs/TinyTextarea.cjs +19 -0
- package/dist/v1/libs/TinyTextarea.d.mts +6 -0
- package/dist/v1/libs/TinyTextarea.mjs +17 -0
- package/dist/v1/libs/TinyTimeout.cjs +11 -1
- package/dist/v1/libs/TinyTimeout.mjs +9 -1
- package/dist/v1/libs/TinyToastNotify.cjs +35 -0
- package/dist/v1/libs/TinyToastNotify.d.mts +6 -0
- package/dist/v1/libs/TinyToastNotify.mjs +31 -0
- package/dist/v1/libs/TinyUploadClicker.cjs +19 -0
- package/dist/v1/libs/TinyUploadClicker.d.mts +6 -0
- package/dist/v1/libs/TinyUploadClicker.mjs +17 -0
- package/dist/v1/libs/UltraRandomMsgGen.cjs +148 -35
- package/dist/v1/libs/UltraRandomMsgGen.d.mts +17 -3
- package/dist/v1/libs/UltraRandomMsgGen.mjs +133 -34
- package/dist/v1/libs/utils.cjs +21 -0
- package/dist/v1/libs/utils.d.mts +2 -0
- package/dist/v1/libs/utils.mjs +16 -0
- package/docs/v1/README.md +1 -0
- package/docs/v1/basics/array.md +2 -2
- package/docs/v1/basics/deprecated/html.md +17 -0
- package/docs/v1/basics/fullScreen.md +1 -1
- package/docs/v1/basics/html.md +12 -26
- package/docs/v1/basics/mediaContent.md +1 -1
- package/docs/v1/basics/objChecker.md +1 -1
- package/docs/v1/basics/text.md +2 -2
- package/docs/v1/fileManager/main.md +1 -1
- package/docs/v1/libs/ColorSafeStringify.md +1 -1
- package/docs/v1/libs/TinyAfterScrollWatcher.md +1 -1
- package/docs/v1/libs/TinyAnalogClock.md +1 -1
- package/docs/v1/libs/TinyArrayComparator.md +1 -1
- package/docs/v1/libs/TinyArrayPaginator.md +1 -1
- package/docs/v1/libs/TinyClassManager/TinyPluginInliner.md +2 -2
- package/docs/v1/libs/TinyClassManager.md +1 -1
- package/docs/v1/libs/TinyClipboard.md +1 -1
- package/docs/v1/libs/TinyCookieConsent.md +1 -1
- package/docs/v1/libs/TinyDomReadyManager.md +1 -1
- package/docs/v1/libs/TinyDragDropDetector.md +1 -1
- package/docs/v1/libs/TinyDragger.md +1 -1
- package/docs/v1/libs/TinyElementObserver.md +1 -1
- package/docs/v1/libs/TinyHtml.md +1 -1
- package/docs/v1/libs/TinyIframeEvents.md +2 -2
- package/docs/v1/libs/TinyLevelUp.md +1 -1
- package/docs/v1/libs/TinyLoadingScreen.md +1 -1
- package/docs/v1/libs/TinyNewWinEvents.md +2 -2
- package/docs/v1/libs/TinyNotifications.md +1 -1
- package/docs/v1/libs/TinyPromiseQueue.md +2 -2
- package/docs/v1/libs/TinyTextDiffer.md +1 -1
- package/docs/v1/libs/TinyTextarea.md +1 -1
- package/package.json +10 -1
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var utils = require('./utils.cjs');
|
|
4
|
+
|
|
5
|
+
const checkDestroy = utils.createCheckDestroyed('TinyElementObserver');
|
|
6
|
+
|
|
3
7
|
/**
|
|
4
8
|
* Callback type used for element mutation detectors.
|
|
5
9
|
*
|
|
@@ -19,6 +23,21 @@
|
|
|
19
23
|
* @template {Element} HTMLElement
|
|
20
24
|
*/
|
|
21
25
|
class TinyElementObserver {
|
|
26
|
+
/**
|
|
27
|
+
* Tracks whether the instance has been destroyed.
|
|
28
|
+
* @type {boolean}
|
|
29
|
+
*/
|
|
30
|
+
#destroyed = false;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Gets the current destruction status of the instance.
|
|
34
|
+
*
|
|
35
|
+
* @returns {boolean} True if the instance is destroyed, false otherwise.
|
|
36
|
+
*/
|
|
37
|
+
get destroyed() {
|
|
38
|
+
return this.#destroyed;
|
|
39
|
+
}
|
|
40
|
+
|
|
22
41
|
/** @type {HTMLElement} */
|
|
23
42
|
#el;
|
|
24
43
|
|
|
@@ -27,6 +46,7 @@ class TinyElementObserver {
|
|
|
27
46
|
* @returns {HTMLElement} The DOM element being tracked, or `undefined` if none is set.
|
|
28
47
|
*/
|
|
29
48
|
get el() {
|
|
49
|
+
checkDestroy(this.#destroyed);
|
|
30
50
|
return this.#el;
|
|
31
51
|
}
|
|
32
52
|
|
|
@@ -42,6 +62,7 @@ class TinyElementObserver {
|
|
|
42
62
|
* @returns {MutationObserverInit}
|
|
43
63
|
*/
|
|
44
64
|
get settings() {
|
|
65
|
+
checkDestroy(this.#destroyed);
|
|
45
66
|
return this.#settings;
|
|
46
67
|
}
|
|
47
68
|
|
|
@@ -50,6 +71,7 @@ class TinyElementObserver {
|
|
|
50
71
|
* @param {MutationObserverInit} settings
|
|
51
72
|
*/
|
|
52
73
|
set settings(settings) {
|
|
74
|
+
checkDestroy(this.#destroyed);
|
|
53
75
|
if (typeof settings !== 'object' || settings === null)
|
|
54
76
|
throw new TypeError('settings must be a non-null object.');
|
|
55
77
|
this.#settings = settings;
|
|
@@ -66,6 +88,7 @@ class TinyElementObserver {
|
|
|
66
88
|
* @returns {MutationObserver|null}
|
|
67
89
|
*/
|
|
68
90
|
get observer() {
|
|
91
|
+
checkDestroy(this.#destroyed);
|
|
69
92
|
return this.#observer;
|
|
70
93
|
}
|
|
71
94
|
|
|
@@ -84,6 +107,7 @@ class TinyElementObserver {
|
|
|
84
107
|
* @returns {Array<[string, ElementDetectorsFn]>}
|
|
85
108
|
*/
|
|
86
109
|
get detectors() {
|
|
110
|
+
checkDestroy(this.#destroyed);
|
|
87
111
|
return this.#detectors.map((item) => [item[0], item[1]]);
|
|
88
112
|
}
|
|
89
113
|
|
|
@@ -92,6 +116,7 @@ class TinyElementObserver {
|
|
|
92
116
|
* @param {Array<[string, ElementDetectorsFn]>} detectors
|
|
93
117
|
*/
|
|
94
118
|
set detectors(detectors) {
|
|
119
|
+
checkDestroy(this.#destroyed);
|
|
95
120
|
if (!Array.isArray(detectors)) throw new TypeError('detectors must be an array.');
|
|
96
121
|
|
|
97
122
|
/** @type {Array<[string, ElementDetectorsFn]>} */
|
|
@@ -110,6 +135,7 @@ class TinyElementObserver {
|
|
|
110
135
|
* @returns {boolean}
|
|
111
136
|
*/
|
|
112
137
|
get isActive() {
|
|
138
|
+
checkDestroy(this.#destroyed);
|
|
113
139
|
return !!this.#observer;
|
|
114
140
|
}
|
|
115
141
|
|
|
@@ -119,6 +145,7 @@ class TinyElementObserver {
|
|
|
119
145
|
* @returns {number} Total count of detectors.
|
|
120
146
|
*/
|
|
121
147
|
get size() {
|
|
148
|
+
checkDestroy(this.#destroyed);
|
|
122
149
|
return this.#detectors.length;
|
|
123
150
|
}
|
|
124
151
|
|
|
@@ -142,6 +169,7 @@ class TinyElementObserver {
|
|
|
142
169
|
* until new detectors are added again.
|
|
143
170
|
*/
|
|
144
171
|
clear() {
|
|
172
|
+
checkDestroy(this.#destroyed);
|
|
145
173
|
this.#detectors = [];
|
|
146
174
|
}
|
|
147
175
|
|
|
@@ -151,6 +179,7 @@ class TinyElementObserver {
|
|
|
151
179
|
* @throws {Error} If no element has been set to observe.
|
|
152
180
|
*/
|
|
153
181
|
start() {
|
|
182
|
+
checkDestroy(this.#destroyed);
|
|
154
183
|
if (!this.#el) throw new Error('Cannot start observation: no target element has been set.');
|
|
155
184
|
if (this.#observer) return;
|
|
156
185
|
this.#observer = new MutationObserver((mutations) => {
|
|
@@ -166,6 +195,7 @@ class TinyElementObserver {
|
|
|
166
195
|
* Stop tracking changes.
|
|
167
196
|
*/
|
|
168
197
|
stop() {
|
|
198
|
+
checkDestroy(this.#destroyed);
|
|
169
199
|
if (!this.#observer) return;
|
|
170
200
|
this.#observer.disconnect();
|
|
171
201
|
this.#observer = null;
|
|
@@ -179,6 +209,7 @@ class TinyElementObserver {
|
|
|
179
209
|
* @param {ElementDetectorsFn} handler
|
|
180
210
|
*/
|
|
181
211
|
add(name, handler) {
|
|
212
|
+
checkDestroy(this.#destroyed);
|
|
182
213
|
this.#validateDetector(name, handler);
|
|
183
214
|
this.#detectors.push([name, handler]);
|
|
184
215
|
}
|
|
@@ -189,6 +220,7 @@ class TinyElementObserver {
|
|
|
189
220
|
* @param {ElementDetectorsFn} handler
|
|
190
221
|
*/
|
|
191
222
|
insertAtStart(name, handler) {
|
|
223
|
+
checkDestroy(this.#destroyed);
|
|
192
224
|
this.#validateDetector(name, handler);
|
|
193
225
|
this.#detectors.unshift([name, handler]);
|
|
194
226
|
}
|
|
@@ -201,6 +233,7 @@ class TinyElementObserver {
|
|
|
201
233
|
* @param {'before'|'after'} position - Position relative to the index
|
|
202
234
|
*/
|
|
203
235
|
insertAt(index, name, handler, position = 'after') {
|
|
236
|
+
checkDestroy(this.#destroyed);
|
|
204
237
|
this.#validateDetector(name, handler);
|
|
205
238
|
if (typeof index !== 'number' || index < 0 || index >= this.#detectors.length)
|
|
206
239
|
throw new RangeError('Invalid index for insertDetectorAt.');
|
|
@@ -213,6 +246,7 @@ class TinyElementObserver {
|
|
|
213
246
|
* @param {number} index
|
|
214
247
|
*/
|
|
215
248
|
removeAt(index) {
|
|
249
|
+
checkDestroy(this.#destroyed);
|
|
216
250
|
if (typeof index !== 'number' || index < 0 || index >= this.#detectors.length)
|
|
217
251
|
throw new RangeError('Invalid index for removeDetectorAt.');
|
|
218
252
|
this.#detectors.splice(index, 1);
|
|
@@ -225,6 +259,7 @@ class TinyElementObserver {
|
|
|
225
259
|
* @param {number} after - Number of items after the index to remove
|
|
226
260
|
*/
|
|
227
261
|
removeAround(index, before = 0, after = 0) {
|
|
262
|
+
checkDestroy(this.#destroyed);
|
|
228
263
|
if (typeof index !== 'number' || index < 0 || index >= this.#detectors.length)
|
|
229
264
|
throw new RangeError('Invalid index for removeDetectorsAround.');
|
|
230
265
|
const start = Math.max(0, index - before);
|
|
@@ -238,6 +273,7 @@ class TinyElementObserver {
|
|
|
238
273
|
* @returns {boolean}
|
|
239
274
|
*/
|
|
240
275
|
isIndexUsed(index) {
|
|
276
|
+
checkDestroy(this.#destroyed);
|
|
241
277
|
return index >= 0 && index < this.#detectors.length;
|
|
242
278
|
}
|
|
243
279
|
|
|
@@ -247,6 +283,7 @@ class TinyElementObserver {
|
|
|
247
283
|
* @returns {boolean}
|
|
248
284
|
*/
|
|
249
285
|
hasHandler(handler) {
|
|
286
|
+
checkDestroy(this.#destroyed);
|
|
250
287
|
if (typeof handler !== 'function') throw new TypeError('Handler must be a function.');
|
|
251
288
|
return this.#detectors.some(([_, fn]) => fn === handler);
|
|
252
289
|
}
|
|
@@ -269,8 +306,10 @@ class TinyElementObserver {
|
|
|
269
306
|
* leaving the instance unusable until reconfigured.
|
|
270
307
|
*/
|
|
271
308
|
destroy() {
|
|
309
|
+
if (this.#destroyed) return;
|
|
272
310
|
this.stop();
|
|
273
311
|
this.clear();
|
|
312
|
+
this.#destroyed = true;
|
|
274
313
|
}
|
|
275
314
|
}
|
|
276
315
|
|
|
@@ -33,6 +33,12 @@ declare class TinyElementObserver<HTMLElement extends Element> {
|
|
|
33
33
|
initDetectors?: [string, ElementDetectorsFn][] | undefined;
|
|
34
34
|
initCfg?: MutationObserverInit | undefined;
|
|
35
35
|
});
|
|
36
|
+
/**
|
|
37
|
+
* Gets the current destruction status of the instance.
|
|
38
|
+
*
|
|
39
|
+
* @returns {boolean} True if the instance is destroyed, false otherwise.
|
|
40
|
+
*/
|
|
41
|
+
get destroyed(): boolean;
|
|
36
42
|
/**
|
|
37
43
|
* Get the current element being observed.
|
|
38
44
|
* @returns {HTMLElement} The DOM element being tracked, or `undefined` if none is set.
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { createCheckDestroyed } from './utils.mjs';
|
|
2
|
+
const checkDestroy = createCheckDestroyed('TinyElementObserver');
|
|
1
3
|
/**
|
|
2
4
|
* Callback type used for element mutation detectors.
|
|
3
5
|
*
|
|
@@ -16,6 +18,19 @@
|
|
|
16
18
|
* @template {Element} HTMLElement
|
|
17
19
|
*/
|
|
18
20
|
class TinyElementObserver {
|
|
21
|
+
/**
|
|
22
|
+
* Tracks whether the instance has been destroyed.
|
|
23
|
+
* @type {boolean}
|
|
24
|
+
*/
|
|
25
|
+
#destroyed = false;
|
|
26
|
+
/**
|
|
27
|
+
* Gets the current destruction status of the instance.
|
|
28
|
+
*
|
|
29
|
+
* @returns {boolean} True if the instance is destroyed, false otherwise.
|
|
30
|
+
*/
|
|
31
|
+
get destroyed() {
|
|
32
|
+
return this.#destroyed;
|
|
33
|
+
}
|
|
19
34
|
/** @type {HTMLElement} */
|
|
20
35
|
#el;
|
|
21
36
|
/**
|
|
@@ -23,6 +38,7 @@ class TinyElementObserver {
|
|
|
23
38
|
* @returns {HTMLElement} The DOM element being tracked, or `undefined` if none is set.
|
|
24
39
|
*/
|
|
25
40
|
get el() {
|
|
41
|
+
checkDestroy(this.#destroyed);
|
|
26
42
|
return this.#el;
|
|
27
43
|
}
|
|
28
44
|
/**
|
|
@@ -36,6 +52,7 @@ class TinyElementObserver {
|
|
|
36
52
|
* @returns {MutationObserverInit}
|
|
37
53
|
*/
|
|
38
54
|
get settings() {
|
|
55
|
+
checkDestroy(this.#destroyed);
|
|
39
56
|
return this.#settings;
|
|
40
57
|
}
|
|
41
58
|
/**
|
|
@@ -43,6 +60,7 @@ class TinyElementObserver {
|
|
|
43
60
|
* @param {MutationObserverInit} settings
|
|
44
61
|
*/
|
|
45
62
|
set settings(settings) {
|
|
63
|
+
checkDestroy(this.#destroyed);
|
|
46
64
|
if (typeof settings !== 'object' || settings === null)
|
|
47
65
|
throw new TypeError('settings must be a non-null object.');
|
|
48
66
|
this.#settings = settings;
|
|
@@ -57,6 +75,7 @@ class TinyElementObserver {
|
|
|
57
75
|
* @returns {MutationObserver|null}
|
|
58
76
|
*/
|
|
59
77
|
get observer() {
|
|
78
|
+
checkDestroy(this.#destroyed);
|
|
60
79
|
return this.#observer;
|
|
61
80
|
}
|
|
62
81
|
/**
|
|
@@ -73,6 +92,7 @@ class TinyElementObserver {
|
|
|
73
92
|
* @returns {Array<[string, ElementDetectorsFn]>}
|
|
74
93
|
*/
|
|
75
94
|
get detectors() {
|
|
95
|
+
checkDestroy(this.#destroyed);
|
|
76
96
|
return this.#detectors.map((item) => [item[0], item[1]]);
|
|
77
97
|
}
|
|
78
98
|
/**
|
|
@@ -80,6 +100,7 @@ class TinyElementObserver {
|
|
|
80
100
|
* @param {Array<[string, ElementDetectorsFn]>} detectors
|
|
81
101
|
*/
|
|
82
102
|
set detectors(detectors) {
|
|
103
|
+
checkDestroy(this.#destroyed);
|
|
83
104
|
if (!Array.isArray(detectors))
|
|
84
105
|
throw new TypeError('detectors must be an array.');
|
|
85
106
|
/** @type {Array<[string, ElementDetectorsFn]>} */
|
|
@@ -98,6 +119,7 @@ class TinyElementObserver {
|
|
|
98
119
|
* @returns {boolean}
|
|
99
120
|
*/
|
|
100
121
|
get isActive() {
|
|
122
|
+
checkDestroy(this.#destroyed);
|
|
101
123
|
return !!this.#observer;
|
|
102
124
|
}
|
|
103
125
|
/**
|
|
@@ -106,6 +128,7 @@ class TinyElementObserver {
|
|
|
106
128
|
* @returns {number} Total count of detectors.
|
|
107
129
|
*/
|
|
108
130
|
get size() {
|
|
131
|
+
checkDestroy(this.#destroyed);
|
|
109
132
|
return this.#detectors.length;
|
|
110
133
|
}
|
|
111
134
|
/**
|
|
@@ -129,6 +152,7 @@ class TinyElementObserver {
|
|
|
129
152
|
* until new detectors are added again.
|
|
130
153
|
*/
|
|
131
154
|
clear() {
|
|
155
|
+
checkDestroy(this.#destroyed);
|
|
132
156
|
this.#detectors = [];
|
|
133
157
|
}
|
|
134
158
|
/**
|
|
@@ -137,6 +161,7 @@ class TinyElementObserver {
|
|
|
137
161
|
* @throws {Error} If no element has been set to observe.
|
|
138
162
|
*/
|
|
139
163
|
start() {
|
|
164
|
+
checkDestroy(this.#destroyed);
|
|
140
165
|
if (!this.#el)
|
|
141
166
|
throw new Error('Cannot start observation: no target element has been set.');
|
|
142
167
|
if (this.#observer)
|
|
@@ -150,6 +175,7 @@ class TinyElementObserver {
|
|
|
150
175
|
* Stop tracking changes.
|
|
151
176
|
*/
|
|
152
177
|
stop() {
|
|
178
|
+
checkDestroy(this.#destroyed);
|
|
153
179
|
if (!this.#observer)
|
|
154
180
|
return;
|
|
155
181
|
this.#observer.disconnect();
|
|
@@ -162,6 +188,7 @@ class TinyElementObserver {
|
|
|
162
188
|
* @param {ElementDetectorsFn} handler
|
|
163
189
|
*/
|
|
164
190
|
add(name, handler) {
|
|
191
|
+
checkDestroy(this.#destroyed);
|
|
165
192
|
this.#validateDetector(name, handler);
|
|
166
193
|
this.#detectors.push([name, handler]);
|
|
167
194
|
}
|
|
@@ -171,6 +198,7 @@ class TinyElementObserver {
|
|
|
171
198
|
* @param {ElementDetectorsFn} handler
|
|
172
199
|
*/
|
|
173
200
|
insertAtStart(name, handler) {
|
|
201
|
+
checkDestroy(this.#destroyed);
|
|
174
202
|
this.#validateDetector(name, handler);
|
|
175
203
|
this.#detectors.unshift([name, handler]);
|
|
176
204
|
}
|
|
@@ -182,6 +210,7 @@ class TinyElementObserver {
|
|
|
182
210
|
* @param {'before'|'after'} position - Position relative to the index
|
|
183
211
|
*/
|
|
184
212
|
insertAt(index, name, handler, position = 'after') {
|
|
213
|
+
checkDestroy(this.#destroyed);
|
|
185
214
|
this.#validateDetector(name, handler);
|
|
186
215
|
if (typeof index !== 'number' || index < 0 || index >= this.#detectors.length)
|
|
187
216
|
throw new RangeError('Invalid index for insertDetectorAt.');
|
|
@@ -193,6 +222,7 @@ class TinyElementObserver {
|
|
|
193
222
|
* @param {number} index
|
|
194
223
|
*/
|
|
195
224
|
removeAt(index) {
|
|
225
|
+
checkDestroy(this.#destroyed);
|
|
196
226
|
if (typeof index !== 'number' || index < 0 || index >= this.#detectors.length)
|
|
197
227
|
throw new RangeError('Invalid index for removeDetectorAt.');
|
|
198
228
|
this.#detectors.splice(index, 1);
|
|
@@ -204,6 +234,7 @@ class TinyElementObserver {
|
|
|
204
234
|
* @param {number} after - Number of items after the index to remove
|
|
205
235
|
*/
|
|
206
236
|
removeAround(index, before = 0, after = 0) {
|
|
237
|
+
checkDestroy(this.#destroyed);
|
|
207
238
|
if (typeof index !== 'number' || index < 0 || index >= this.#detectors.length)
|
|
208
239
|
throw new RangeError('Invalid index for removeDetectorsAround.');
|
|
209
240
|
const start = Math.max(0, index - before);
|
|
@@ -216,6 +247,7 @@ class TinyElementObserver {
|
|
|
216
247
|
* @returns {boolean}
|
|
217
248
|
*/
|
|
218
249
|
isIndexUsed(index) {
|
|
250
|
+
checkDestroy(this.#destroyed);
|
|
219
251
|
return index >= 0 && index < this.#detectors.length;
|
|
220
252
|
}
|
|
221
253
|
/**
|
|
@@ -224,6 +256,7 @@ class TinyElementObserver {
|
|
|
224
256
|
* @returns {boolean}
|
|
225
257
|
*/
|
|
226
258
|
hasHandler(handler) {
|
|
259
|
+
checkDestroy(this.#destroyed);
|
|
227
260
|
if (typeof handler !== 'function')
|
|
228
261
|
throw new TypeError('Handler must be a function.');
|
|
229
262
|
return this.#detectors.some(([_, fn]) => fn === handler);
|
|
@@ -245,8 +278,11 @@ class TinyElementObserver {
|
|
|
245
278
|
* leaving the instance unusable until reconfigured.
|
|
246
279
|
*/
|
|
247
280
|
destroy() {
|
|
281
|
+
if (this.#destroyed)
|
|
282
|
+
return;
|
|
248
283
|
this.stop();
|
|
249
284
|
this.clear();
|
|
285
|
+
this.#destroyed = true;
|
|
250
286
|
}
|
|
251
287
|
}
|
|
252
288
|
export default TinyElementObserver;
|