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.
- package/README.md +1 -0
- package/changelog/1/28/0.md +16 -0
- 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 -2
- 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 -2
- 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 -2
- 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/extendObjType/Buffer.cjs +13 -0
- package/dist/v1/basics/extendObjType/Buffer.d.mts +4 -0
- package/dist/v1/basics/extendObjType/Buffer.mjs +8 -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 -18
- package/dist/v1/basics/objFilter.d.mts +6 -6
- package/dist/v1/basics/objFilter.mjs +32 -17
- 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 -2
- package/dist/v1/index.d.mts +4 -2
- package/dist/v1/index.mjs +4 -4
- package/dist/v1/libs/TinyAdvancedRaffle.cjs +71 -255
- package/dist/v1/libs/TinyAdvancedRaffle.d.mts +6 -134
- package/dist/v1/libs/TinyAdvancedRaffle.mjs +69 -228
- 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 +26 -196
- package/dist/v1/libs/TinyIframeEvents.d.mts +3 -122
- package/dist/v1/libs/TinyIframeEvents.mjs +26 -171
- package/dist/v1/libs/TinyLocalStorage.cjs +53 -205
- package/dist/v1/libs/TinyLocalStorage.d.mts +6 -127
- package/dist/v1/libs/TinyLocalStorage.mjs +50 -178
- package/dist/v1/libs/TinyMediaPlayer.cjs +74 -2
- package/dist/v1/libs/TinyMediaPlayer.d.mts +12 -2
- package/dist/v1/libs/TinyMediaPlayer.mjs +68 -2
- package/dist/v1/libs/TinyNewWinEvents.cjs +39 -197
- package/dist/v1/libs/TinyNewWinEvents.d.mts +6 -119
- package/dist/v1/libs/TinyNewWinEvents.mjs +36 -172
- 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 +40 -3
- package/dist/v1/libs/TinyRadioFm.d.mts +3 -3
- package/dist/v1/libs/TinyRadioFm.mjs +37 -3
- 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 +56 -205
- package/dist/v1/libs/TinySmartScroller.d.mts +19 -152
- package/dist/v1/libs/TinySmartScroller.mjs +55 -181
- 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 +20 -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/Exports.md +0 -1
- package/docs/v1/README.md +1 -1
- 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/objFilter.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 +10 -10
- package/docs/v1/libs/TinyLevelUp.md +1 -1
- package/docs/v1/libs/TinyLoadingScreen.md +1 -1
- package/docs/v1/libs/TinyLocalStorage.md +3 -3
- package/docs/v1/libs/TinyNewWinEvents.md +10 -11
- 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 +15 -5
- package/dist/v1/TinyBasicsEs.min.js.LICENSE.txt +0 -8
- package/dist/v1/TinyEssentials.min.js.LICENSE.txt +0 -8
- package/dist/v1/TinyEvents.min.js +0 -1
- package/dist/v1/TinyUploadClicker.min.js.LICENSE.txt +0 -8
- package/dist/v1/build/TinyEvents.cjs +0 -7
- package/dist/v1/build/TinyEvents.d.mts +0 -3
- package/dist/v1/build/TinyEvents.mjs +0 -2
- package/dist/v1/libs/TinyEvents.cjs +0 -395
- package/dist/v1/libs/TinyEvents.d.mts +0 -164
- package/dist/v1/libs/TinyEvents.mjs +0 -360
- package/docs/v1/libs/TinyEvents.md +0 -187
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
1
2
|
import { isJsonObject } from '../basics/objChecker.mjs';
|
|
2
|
-
import
|
|
3
|
+
import { createCheckDestroyed } from './utils.mjs';
|
|
4
|
+
const checkDestroy = createCheckDestroyed('TinyIframeEvents');
|
|
3
5
|
/** @type {WeakMap<Window, TinyIframeEvents>} */
|
|
4
6
|
const instances = new WeakMap();
|
|
5
7
|
/**
|
|
@@ -39,188 +41,29 @@ const instances = new WeakMap();
|
|
|
39
41
|
* - Queue management for messages sent before the connection is established.
|
|
40
42
|
* - Auto-reconnects and resets ports if the target iframe is reloaded.
|
|
41
43
|
*/
|
|
42
|
-
class TinyIframeEvents {
|
|
43
|
-
#events = new TinyEvents();
|
|
44
|
-
/**
|
|
45
|
-
* Enables or disables throwing an error when the maximum number of listeners is exceeded.
|
|
46
|
-
*
|
|
47
|
-
* @param {boolean} shouldThrow - If true, an error will be thrown when the max is exceeded.
|
|
48
|
-
*/
|
|
49
|
-
setThrowOnMaxListeners(shouldThrow) {
|
|
50
|
-
return this.#events.setThrowOnMaxListeners(shouldThrow);
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Checks whether an error will be thrown when the max listener limit is exceeded.
|
|
54
|
-
*
|
|
55
|
-
* @returns {boolean} True if an error will be thrown, false if only a warning is shown.
|
|
56
|
-
*/
|
|
57
|
-
getThrowOnMaxListeners() {
|
|
58
|
-
return this.#events.getThrowOnMaxListeners();
|
|
59
|
-
}
|
|
60
|
-
/////////////////////////////////////////////////////////////
|
|
61
|
-
/**
|
|
62
|
-
* Adds a listener to the beginning of the listeners array for the specified event.
|
|
63
|
-
*
|
|
64
|
-
* @param {string|string[]} event - Event name.
|
|
65
|
-
* @param {handler} handler - The callback function.
|
|
66
|
-
*/
|
|
67
|
-
prependListener(event, handler) {
|
|
68
|
-
return this.#events.prependListener(event, handler);
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Adds a one-time listener to the beginning of the listeners array for the specified event.
|
|
72
|
-
*
|
|
73
|
-
* @param {string|string[]} event - Event name.
|
|
74
|
-
* @param {handler} handler - The callback function.
|
|
75
|
-
* @returns {handler[]} - The wrapped handler used internally.
|
|
76
|
-
*/
|
|
77
|
-
prependListenerOnce(event, handler) {
|
|
78
|
-
return this.#events.prependListenerOnce(event, handler);
|
|
79
|
-
}
|
|
80
|
-
//////////////////////////////////////////////////////////////////////
|
|
81
|
-
/**
|
|
82
|
-
* Adds a event listener.
|
|
83
|
-
*
|
|
84
|
-
* @param {string|string[]} event - Event name, such as 'onScrollBoundary' or 'onAutoScroll'.
|
|
85
|
-
* @param {handler} handler - Callback function to be called when event fires.
|
|
86
|
-
*/
|
|
87
|
-
appendListener(event, handler) {
|
|
88
|
-
return this.#events.appendListener(event, handler);
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Registers an event listener that runs only once, then is removed.
|
|
92
|
-
*
|
|
93
|
-
* @param {string|string[]} event - Event name, such as 'onScrollBoundary' or 'onAutoScroll'.
|
|
94
|
-
* @param {handler} handler - The callback function to run on event.
|
|
95
|
-
* @returns {handler[]} - The wrapped version of the handler.
|
|
96
|
-
*/
|
|
97
|
-
appendListenerOnce(event, handler) {
|
|
98
|
-
return this.#events.appendListenerOnce(event, handler);
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Adds a event listener.
|
|
102
|
-
*
|
|
103
|
-
* @param {string|string[]} event - Event name, such as 'onScrollBoundary' or 'onAutoScroll'.
|
|
104
|
-
* @param {handler} handler - Callback function to be called when event fires.
|
|
105
|
-
*/
|
|
106
|
-
on(event, handler) {
|
|
107
|
-
return this.#events.on(event, handler);
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Registers an event listener that runs only once, then is removed.
|
|
111
|
-
*
|
|
112
|
-
* @param {string|string[]} event - Event name, such as 'onScrollBoundary' or 'onAutoScroll'.
|
|
113
|
-
* @param {handler} handler - The callback function to run on event.
|
|
114
|
-
* @returns {handler[]} - The wrapped version of the handler.
|
|
115
|
-
*/
|
|
116
|
-
once(event, handler) {
|
|
117
|
-
return this.#events.once(event, handler);
|
|
118
|
-
}
|
|
119
|
-
////////////////////////////////////////////////////////////////////
|
|
120
|
-
/**
|
|
121
|
-
* Removes a previously registered event listener.
|
|
122
|
-
*
|
|
123
|
-
* @param {string|string[]} event - The name of the event to remove the handler from.
|
|
124
|
-
* @param {handler} handler - The specific callback function to remove.
|
|
125
|
-
*/
|
|
126
|
-
off(event, handler) {
|
|
127
|
-
return this.#events.off(event, handler);
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Removes all event listeners of a specific type from the element.
|
|
131
|
-
*
|
|
132
|
-
* @param {string|string[]} event - The event type to remove (e.g. 'onScrollBoundary').
|
|
133
|
-
*/
|
|
134
|
-
offAll(event) {
|
|
135
|
-
return this.#events.offAll(event);
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Removes all event listeners of all types from the element.
|
|
139
|
-
*/
|
|
140
|
-
offAllTypes() {
|
|
141
|
-
return this.#events.offAllTypes();
|
|
142
|
-
}
|
|
143
|
-
////////////////////////////////////////////////////////////
|
|
144
|
-
/**
|
|
145
|
-
* Returns the number of listeners for a given event.
|
|
146
|
-
*
|
|
147
|
-
* @param {string} event - The name of the event.
|
|
148
|
-
* @returns {number} Number of listeners for the event.
|
|
149
|
-
*/
|
|
150
|
-
listenerCount(event) {
|
|
151
|
-
return this.#events.listenerCount(event);
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* Returns a copy of the array of listeners for the specified event.
|
|
155
|
-
*
|
|
156
|
-
* @param {string} event - The name of the event.
|
|
157
|
-
* @returns {handler[]} Array of listener functions.
|
|
158
|
-
*/
|
|
159
|
-
listeners(event) {
|
|
160
|
-
return this.#events.listeners(event);
|
|
161
|
-
}
|
|
162
|
-
/**
|
|
163
|
-
* Returns a copy of the array of listeners for the specified event.
|
|
164
|
-
*
|
|
165
|
-
* @param {string} event - The name of the event.
|
|
166
|
-
* @returns {handler[]} Array of listener functions.
|
|
167
|
-
*/
|
|
168
|
-
onceListeners(event) {
|
|
169
|
-
return this.#events.onceListeners(event);
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* Returns a copy of the internal listeners array for the specified event,
|
|
173
|
-
* including wrapper functions like those used by `.once()`.
|
|
174
|
-
* @param {string | symbol} event - The event name.
|
|
175
|
-
* @returns {handler[]} An array of raw listener functions.
|
|
176
|
-
*/
|
|
177
|
-
allListeners(event) {
|
|
178
|
-
return this.#events.allListeners(event);
|
|
179
|
-
}
|
|
180
|
-
/**
|
|
181
|
-
* Returns an array of event names for which there are registered listeners.
|
|
182
|
-
*
|
|
183
|
-
* @returns {string[]} Array of registered event names.
|
|
184
|
-
*/
|
|
185
|
-
eventNames() {
|
|
186
|
-
return this.#events.eventNames();
|
|
187
|
-
}
|
|
188
|
-
//////////////////////////////////////////////////////
|
|
189
|
-
/**
|
|
190
|
-
* Sets the maximum number of listeners per event before a warning is shown.
|
|
191
|
-
*
|
|
192
|
-
* @param {number} n - The maximum number of listeners.
|
|
193
|
-
*/
|
|
194
|
-
setMaxListeners(n) {
|
|
195
|
-
return this.#events.setMaxListeners(n);
|
|
196
|
-
}
|
|
197
|
-
/**
|
|
198
|
-
* Gets the maximum number of listeners allowed per event.
|
|
199
|
-
*
|
|
200
|
-
* @returns {number} The maximum number of listeners.
|
|
201
|
-
*/
|
|
202
|
-
getMaxListeners() {
|
|
203
|
-
return this.#events.getMaxListeners();
|
|
204
|
-
}
|
|
205
|
-
///////////////////////////////////////////////////
|
|
44
|
+
class TinyIframeEvents extends EventEmitter {
|
|
206
45
|
/** @type {Window} */
|
|
207
46
|
#targetWindow;
|
|
208
47
|
get targetWindow() {
|
|
48
|
+
checkDestroy(this.#isDestroyed);
|
|
209
49
|
return this.#targetWindow;
|
|
210
50
|
}
|
|
211
51
|
/** @type {HTMLIFrameElement | undefined} */
|
|
212
52
|
#targetIframeElement;
|
|
213
53
|
get targetIframeElement() {
|
|
54
|
+
checkDestroy(this.#isDestroyed);
|
|
214
55
|
return this.#targetIframeElement;
|
|
215
56
|
}
|
|
216
57
|
/** @type {string} */
|
|
217
58
|
#targetOrigin;
|
|
218
59
|
get targetOrigin() {
|
|
60
|
+
checkDestroy(this.#isDestroyed);
|
|
219
61
|
return this.#targetOrigin;
|
|
220
62
|
}
|
|
221
63
|
/** @type {'iframe' | 'parent'} */
|
|
222
64
|
#selfType;
|
|
223
65
|
get selfType() {
|
|
66
|
+
checkDestroy(this.#isDestroyed);
|
|
224
67
|
return this.#selfType;
|
|
225
68
|
}
|
|
226
69
|
/** @type {boolean} */
|
|
@@ -228,6 +71,7 @@ class TinyIframeEvents {
|
|
|
228
71
|
/** @type {boolean} */
|
|
229
72
|
#ready = false;
|
|
230
73
|
get ready() {
|
|
74
|
+
checkDestroy(this.#isDestroyed);
|
|
231
75
|
return this.#ready;
|
|
232
76
|
}
|
|
233
77
|
/**
|
|
@@ -237,11 +81,12 @@ class TinyIframeEvents {
|
|
|
237
81
|
* @param {function(): void} handler - The callback function to execute.
|
|
238
82
|
*/
|
|
239
83
|
onReady(handler) {
|
|
84
|
+
checkDestroy(this.#isDestroyed);
|
|
240
85
|
if (this.#ready) {
|
|
241
86
|
handler();
|
|
242
87
|
}
|
|
243
88
|
else {
|
|
244
|
-
this
|
|
89
|
+
this.once(this.#readyEventName, handler);
|
|
245
90
|
}
|
|
246
91
|
}
|
|
247
92
|
/** @type {MessagePort | null} */
|
|
@@ -263,6 +108,7 @@ class TinyIframeEvents {
|
|
|
263
108
|
* @param {TinyIframeEventsConfig} config - Configuration object.
|
|
264
109
|
*/
|
|
265
110
|
constructor({ targetIframe, targetOrigin = window.location.origin, secretEventName = '__tinyIframeEvent__', handshakeEventName = '__tinyIframeHandshake__', readyEventName = '__tinyIframeReady__', } = {}) {
|
|
111
|
+
super();
|
|
266
112
|
if (targetIframe !== undefined &&
|
|
267
113
|
(!(targetIframe instanceof HTMLIFrameElement) || !targetIframe.contentWindow)) {
|
|
268
114
|
throw new TypeError(`[TinyIframeEvents] Invalid "targetIframe": expected HTMLIFrameElement, received ${typeof targetIframe}`);
|
|
@@ -289,6 +135,7 @@ class TinyIframeEvents {
|
|
|
289
135
|
* @returns {string}
|
|
290
136
|
*/
|
|
291
137
|
get secretEventName() {
|
|
138
|
+
checkDestroy(this.#isDestroyed);
|
|
292
139
|
return this.#secretEventName;
|
|
293
140
|
}
|
|
294
141
|
/**
|
|
@@ -297,6 +144,7 @@ class TinyIframeEvents {
|
|
|
297
144
|
* @throws {TypeError} If the value is not a string.
|
|
298
145
|
*/
|
|
299
146
|
set secretEventName(name) {
|
|
147
|
+
checkDestroy(this.#isDestroyed);
|
|
300
148
|
if (typeof name !== 'string')
|
|
301
149
|
throw new TypeError('TinyIframeEvents: secretEventName must be a string.');
|
|
302
150
|
this.#secretEventName = name;
|
|
@@ -306,6 +154,7 @@ class TinyIframeEvents {
|
|
|
306
154
|
* @returns {string}
|
|
307
155
|
*/
|
|
308
156
|
get handshakeEventName() {
|
|
157
|
+
checkDestroy(this.#isDestroyed);
|
|
309
158
|
return this.#handshakeEventName;
|
|
310
159
|
}
|
|
311
160
|
/**
|
|
@@ -314,6 +163,7 @@ class TinyIframeEvents {
|
|
|
314
163
|
* @throws {TypeError} If the value is not a string.
|
|
315
164
|
*/
|
|
316
165
|
set handshakeEventName(name) {
|
|
166
|
+
checkDestroy(this.#isDestroyed);
|
|
317
167
|
if (typeof name !== 'string')
|
|
318
168
|
throw new TypeError('TinyIframeEvents: handshakeEventName must be a string.');
|
|
319
169
|
this.#handshakeEventName = name;
|
|
@@ -323,6 +173,7 @@ class TinyIframeEvents {
|
|
|
323
173
|
* @returns {string}
|
|
324
174
|
*/
|
|
325
175
|
get readyEventName() {
|
|
176
|
+
checkDestroy(this.#isDestroyed);
|
|
326
177
|
return this.#readyEventName;
|
|
327
178
|
}
|
|
328
179
|
/**
|
|
@@ -331,6 +182,7 @@ class TinyIframeEvents {
|
|
|
331
182
|
* @throws {TypeError} If the value is not a string.
|
|
332
183
|
*/
|
|
333
184
|
set readyEventName(name) {
|
|
185
|
+
checkDestroy(this.#isDestroyed);
|
|
334
186
|
if (typeof name !== 'string')
|
|
335
187
|
throw new TypeError('TinyIframeEvents: readyEventName must be a string.');
|
|
336
188
|
this.#readyEventName = name;
|
|
@@ -404,7 +256,7 @@ class TinyIframeEvents {
|
|
|
404
256
|
(this.#selfType === 'parent' && direction !== 'parent')) {
|
|
405
257
|
return;
|
|
406
258
|
}
|
|
407
|
-
this
|
|
259
|
+
this.emit(`win:${eventName}`, payload, event);
|
|
408
260
|
}
|
|
409
261
|
/**
|
|
410
262
|
* Marks the communication as ready, flushes any queued messages,
|
|
@@ -415,7 +267,7 @@ class TinyIframeEvents {
|
|
|
415
267
|
return;
|
|
416
268
|
this.#ready = true;
|
|
417
269
|
this.#flushQueue();
|
|
418
|
-
this
|
|
270
|
+
this.emit(this.#readyEventName);
|
|
419
271
|
}
|
|
420
272
|
/**
|
|
421
273
|
* Sends all pending messages queued before the secure port was established.
|
|
@@ -437,7 +289,8 @@ class TinyIframeEvents {
|
|
|
437
289
|
* @throws {TypeError} If `eventName` is not a string.
|
|
438
290
|
* @throws {Error} If instance has been destroyed.
|
|
439
291
|
*/
|
|
440
|
-
|
|
292
|
+
winEmit(eventName, payload) {
|
|
293
|
+
checkDestroy(this.#isDestroyed);
|
|
441
294
|
if (typeof eventName !== 'string')
|
|
442
295
|
throw new TypeError('Event name must be a string.');
|
|
443
296
|
if (this.#isDestroyed)
|
|
@@ -468,7 +321,8 @@ class TinyIframeEvents {
|
|
|
468
321
|
* Call this when the instance is no longer needed to prevent memory leaks.
|
|
469
322
|
*/
|
|
470
323
|
destroy() {
|
|
471
|
-
this.#isDestroyed
|
|
324
|
+
if (this.#isDestroyed)
|
|
325
|
+
return;
|
|
472
326
|
this.#ready = false;
|
|
473
327
|
window.removeEventListener('message', this._boundWindowMessage);
|
|
474
328
|
if (this.#targetIframeElement && this.#boundSendPort) {
|
|
@@ -478,9 +332,10 @@ class TinyIframeEvents {
|
|
|
478
332
|
this.#port.close();
|
|
479
333
|
this.#port = null;
|
|
480
334
|
}
|
|
481
|
-
this
|
|
335
|
+
this.removeAllListeners();
|
|
482
336
|
this.#pendingQueue = [];
|
|
483
337
|
instances.delete(this.#targetWindow);
|
|
338
|
+
this.#isDestroyed = true;
|
|
484
339
|
}
|
|
485
340
|
}
|
|
486
341
|
export default TinyIframeEvents;
|