tiny-essentials 1.27.1 → 1.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/changelog/1/28/0.md +16 -0
- package/dist/v1/TinyAdvancedRaffle.min.js +1 -1
- package/dist/v1/TinyBasicsEs.min.js +1 -2
- package/dist/v1/TinyEssentials.min.js +1 -2
- 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/TinyRadioFm.min.js +1 -1
- package/dist/v1/TinySmartScroller.min.js +1 -1
- package/dist/v1/TinyUploadClicker.min.js +1 -2
- 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/objFilter.cjs +0 -11
- package/dist/v1/basics/objFilter.mjs +0 -10
- package/dist/v1/index.cjs +0 -2
- package/dist/v1/index.d.mts +1 -2
- package/dist/v1/index.mjs +1 -2
- package/dist/v1/libs/TinyAdvancedRaffle.cjs +7 -205
- package/dist/v1/libs/TinyAdvancedRaffle.d.mts +2 -121
- package/dist/v1/libs/TinyAdvancedRaffle.mjs +7 -179
- package/dist/v1/libs/TinyIframeEvents.cjs +8 -195
- package/dist/v1/libs/TinyIframeEvents.d.mts +3 -122
- package/dist/v1/libs/TinyIframeEvents.mjs +8 -170
- package/dist/v1/libs/TinyLocalStorage.cjs +5 -205
- package/dist/v1/libs/TinyLocalStorage.d.mts +3 -130
- package/dist/v1/libs/TinyLocalStorage.mjs +5 -178
- package/dist/v1/libs/TinyMediaPlayer.cjs +2 -2
- package/dist/v1/libs/TinyMediaPlayer.d.mts +2 -2
- package/dist/v1/libs/TinyMediaPlayer.mjs +2 -2
- package/dist/v1/libs/TinyNewWinEvents.cjs +10 -197
- package/dist/v1/libs/TinyNewWinEvents.d.mts +3 -122
- package/dist/v1/libs/TinyNewWinEvents.mjs +10 -172
- package/dist/v1/libs/TinyRadioFm.cjs +2 -3
- package/dist/v1/libs/TinyRadioFm.d.mts +2 -3
- package/dist/v1/libs/TinyRadioFm.mjs +2 -3
- package/dist/v1/libs/TinySmartScroller.cjs +4 -202
- package/dist/v1/libs/TinySmartScroller.d.mts +8 -143
- package/dist/v1/libs/TinySmartScroller.mjs +4 -176
- package/dist/v1/libs/TinyUploadClicker.cjs +1 -0
- package/docs/v1/Exports.md +0 -1
- package/docs/v1/README.md +0 -1
- package/docs/v1/basics/objFilter.md +1 -1
- package/docs/v1/libs/TinyIframeEvents.md +8 -8
- package/docs/v1/libs/TinyLocalStorage.md +3 -3
- package/docs/v1/libs/TinyNewWinEvents.md +8 -9
- package/package.json +6 -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
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var buffer = require('buffer');
|
|
4
|
+
|
|
5
|
+
var Buffer = [
|
|
6
|
+
[
|
|
7
|
+
'buffer',
|
|
8
|
+
/** @param {*} val @returns {val is Buffer} */
|
|
9
|
+
(val) => typeof buffer.Buffer !== 'undefined' && buffer.Buffer.isBuffer(val),
|
|
10
|
+
],
|
|
11
|
+
];
|
|
12
|
+
|
|
13
|
+
module.exports = Buffer;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var buffer = require('buffer');
|
|
4
3
|
var objChecker = require('./objChecker.cjs');
|
|
5
4
|
|
|
6
5
|
const isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
|
|
@@ -245,16 +244,6 @@ extendObjType([
|
|
|
245
244
|
],
|
|
246
245
|
]);
|
|
247
246
|
|
|
248
|
-
if (!isBrowser) {
|
|
249
|
-
extendObjType([
|
|
250
|
-
[
|
|
251
|
-
'buffer',
|
|
252
|
-
/** @param {*} val @returns {val is Buffer} */
|
|
253
|
-
(val) => typeof buffer.Buffer !== 'undefined' && buffer.Buffer.isBuffer(val),
|
|
254
|
-
],
|
|
255
|
-
]);
|
|
256
|
-
}
|
|
257
|
-
|
|
258
247
|
if (isBrowser) {
|
|
259
248
|
extendObjType([
|
|
260
249
|
[
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Buffer } from 'buffer';
|
|
2
1
|
import { countObj, isJsonObject } from './objChecker.mjs';
|
|
3
2
|
export { countObj, isJsonObject };
|
|
4
3
|
const isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
|
|
@@ -226,15 +225,6 @@ extendObjType([
|
|
|
226
225
|
(val) => Array.isArray(val),
|
|
227
226
|
],
|
|
228
227
|
]);
|
|
229
|
-
if (!isBrowser) {
|
|
230
|
-
extendObjType([
|
|
231
|
-
[
|
|
232
|
-
'buffer',
|
|
233
|
-
/** @param {*} val @returns {val is Buffer} */
|
|
234
|
-
(val) => typeof Buffer !== 'undefined' && Buffer.isBuffer(val),
|
|
235
|
-
],
|
|
236
|
-
]);
|
|
237
|
-
}
|
|
238
228
|
if (isBrowser) {
|
|
239
229
|
extendObjType([
|
|
240
230
|
[
|
package/dist/v1/index.cjs
CHANGED
|
@@ -30,7 +30,6 @@ var TinyTextRangeEditor = require('./libs/TinyTextRangeEditor.cjs');
|
|
|
30
30
|
var TinyClipboard = require('./libs/TinyClipboard.cjs');
|
|
31
31
|
var TinyColorConverter = require('./libs/TinyColorConverter.cjs');
|
|
32
32
|
var TinyTimeout = require('./libs/TinyTimeout.cjs');
|
|
33
|
-
var TinyEvents = require('./libs/TinyEvents.cjs');
|
|
34
33
|
var TinyLocalStorage = require('./libs/TinyLocalStorage.cjs');
|
|
35
34
|
var TinyIframeEvents = require('./libs/TinyIframeEvents.cjs');
|
|
36
35
|
var TinyNewWinEvents = require('./libs/TinyNewWinEvents.cjs');
|
|
@@ -169,7 +168,6 @@ exports.TinyTextRangeEditor = TinyTextRangeEditor;
|
|
|
169
168
|
exports.TinyClipboard = TinyClipboard;
|
|
170
169
|
exports.TinyColorConverter = TinyColorConverter;
|
|
171
170
|
exports.TinyTimeout = TinyTimeout;
|
|
172
|
-
exports.TinyEvents = TinyEvents;
|
|
173
171
|
exports.TinyLocalStorage = TinyLocalStorage;
|
|
174
172
|
exports.TinyIframeEvents = TinyIframeEvents;
|
|
175
173
|
exports.TinyNewWinEvents = TinyNewWinEvents;
|
package/dist/v1/index.d.mts
CHANGED
|
@@ -23,7 +23,6 @@ import TinyTextarea from './libs/TinyTextarea.mjs';
|
|
|
23
23
|
import TinyNewWinEvents from './libs/TinyNewWinEvents.mjs';
|
|
24
24
|
import TinyIframeEvents from './libs/TinyIframeEvents.mjs';
|
|
25
25
|
import TinyLocalStorage from './libs/TinyLocalStorage.mjs';
|
|
26
|
-
import TinyEvents from './libs/TinyEvents.mjs';
|
|
27
26
|
import TinyTimeout from './libs/TinyTimeout.mjs';
|
|
28
27
|
import TinyColorConverter from './libs/TinyColorConverter.mjs';
|
|
29
28
|
import TinyClipboard from './libs/TinyClipboard.mjs';
|
|
@@ -137,5 +136,5 @@ import { getTimeDuration } from './basics/clock.mjs';
|
|
|
137
136
|
import { shuffleArray } from './basics/array.mjs';
|
|
138
137
|
import { toTitleCase } from './basics/text.mjs';
|
|
139
138
|
import { toTitleCaseLowerFirst } from './basics/text.mjs';
|
|
140
|
-
export { TinyMediaPlayer, TinyRadioFm, TinyClassManager, FuzzySet, MamdaniInferenceSystem, TinyArrayComparator, TinyTextDiffer, TinyAnalogClock, TinyColorValidator, TinyLoadingScreen, TinyElementObserver, TinySimpleDice, TinyNeedBar, TinyI18, TinyCookieConsent, TinyInventory, TinyInventoryTrader, TinyArrayPaginator, TinyAdvancedRaffle, TinyDayNightCycle, TinyGamepad, TinyTextarea, TinyNewWinEvents, TinyIframeEvents, TinyLocalStorage,
|
|
139
|
+
export { TinyMediaPlayer, TinyRadioFm, TinyClassManager, FuzzySet, MamdaniInferenceSystem, TinyArrayComparator, TinyTextDiffer, TinyAnalogClock, TinyColorValidator, TinyLoadingScreen, TinyElementObserver, TinySimpleDice, TinyNeedBar, TinyI18, TinyCookieConsent, TinyInventory, TinyInventoryTrader, TinyArrayPaginator, TinyAdvancedRaffle, TinyDayNightCycle, TinyGamepad, TinyTextarea, TinyNewWinEvents, TinyIframeEvents, TinyLocalStorage, TinyTimeout, TinyColorConverter, TinyClipboard, TinyTextRangeEditor, TinySmartScroller, UltraRandomMsgGen, TinyAfterScrollWatcher, TinyHtml, TinyNotifications, TinyDomReadyManager, TinyDragger, TinyDragDropDetector, TinyToastNotify, TinyNotifyCenter, TinyRateLimiter, ColorSafeStringify, TinyPromiseQueue, TinyLevelUp, valMediaContentMetadata, valMediaContentMetadataPartial, parseMediaMetadata, extractMediaId3Tags, defuzzifyCentroid, trapezoid, diffArrayList, diffStrings, breakdownDuration, calculateMarketcap, compareMarketcap, getPercentage, areElsCollTop, areElsCollBottom, areElsCollLeft, areElsCollRight, areElsCollPerfTop, areElsCollPerfBottom, areElsCollPerfLeft, areElsCollPerfRight, areElsColliding, areElsPerfColliding, getElsColliding, getElsPerfColliding, getElsCollOverlap, getElsCollOverlapPos, getRectCenter, getElsRelativeCenterOffset, getElsCollDirDepth, getElsCollDetails, safeTextTrim, installWindowHiddenScript, genFibonacciSeq, isDirEmptyAsync, fileSizeAsync, dirSizeAsync, listFilesAsync, listDirsAsync, getLatestBackupPath, fetchJson, fetchText, readJsonBlob, readFileBlob, readBase64Blob, saveJsonFile, readJsonFile, writeJsonFile, ensureDirectory, clearDirectoryAsync, clearDirectory, fileExists, dirExists, isDirEmpty, ensureCopyFile, tryDeleteFile, writeTextFile, listFiles, listDirs, fileSize, dirSize, backupFile, restoreLatestBackup, renameFileBatch, renameFileRegex, renameFileAddPrefixSuffix, renameFileNormalizeCase, renameFilePadNumbers, documentIsFullScreen, isScreenFilled, requestFullScreen, exitFullScreen, isFullScreenMode, onFullScreenChange, offFullScreenChange, isJsonObject, arraySortPositions, formatBytes, addAiMarkerShortcut, extendObjType, reorderObjTypeOrder, cloneObjTypeOrder, countObj, checkObj, objType, ruleOfThree, getSimplePerc, asyncReplace, getAge, formatCustomTimer, formatDayTimer, formatTimer, getTimeDuration, shuffleArray, toTitleCase, toTitleCaseLowerFirst };
|
|
141
140
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/v1/index.mjs
CHANGED
|
@@ -28,7 +28,6 @@ import TinyTextRangeEditor from './libs/TinyTextRangeEditor.mjs';
|
|
|
28
28
|
import TinyClipboard from './libs/TinyClipboard.mjs';
|
|
29
29
|
import TinyColorConverter from './libs/TinyColorConverter.mjs';
|
|
30
30
|
import TinyTimeout from './libs/TinyTimeout.mjs';
|
|
31
|
-
import TinyEvents from './libs/TinyEvents.mjs';
|
|
32
31
|
import TinyLocalStorage from './libs/TinyLocalStorage.mjs';
|
|
33
32
|
import TinyIframeEvents from './libs/TinyIframeEvents.mjs';
|
|
34
33
|
import TinyNewWinEvents from './libs/TinyNewWinEvents.mjs';
|
|
@@ -56,4 +55,4 @@ import TinyMediaPlayer from './libs/TinyMediaPlayer.mjs';
|
|
|
56
55
|
// import TinyHtmlElems from './libs/TinyHtml/index.mjs';
|
|
57
56
|
export { TinyMediaPlayer, TinyRadioFm, TinyClassManager, FuzzySet, MamdaniInferenceSystem, TinyArrayComparator, TinyTextDiffer, TinyAnalogClock,
|
|
58
57
|
// TinyHtmlElems,
|
|
59
|
-
TinyColorValidator, TinyLoadingScreen, TinyElementObserver, TinySimpleDice, TinyNeedBar, TinyI18, TinyCookieConsent, TinyInventory, TinyInventoryTrader, TinyArrayPaginator, TinyAdvancedRaffle, TinyDayNightCycle, TinyGamepad, TinyTextarea, TinyNewWinEvents, TinyIframeEvents, TinyLocalStorage,
|
|
58
|
+
TinyColorValidator, TinyLoadingScreen, TinyElementObserver, TinySimpleDice, TinyNeedBar, TinyI18, TinyCookieConsent, TinyInventory, TinyInventoryTrader, TinyArrayPaginator, TinyAdvancedRaffle, TinyDayNightCycle, TinyGamepad, TinyTextarea, TinyNewWinEvents, TinyIframeEvents, TinyLocalStorage, TinyTimeout, TinyColorConverter, TinyClipboard, TinyTextRangeEditor, TinySmartScroller, UltraRandomMsgGen, TinyAfterScrollWatcher, TinyHtml, TinyNotifications, TinyDomReadyManager, TinyDragger, TinyDragDropDetector, TinyToastNotify, TinyNotifyCenter, TinyRateLimiter, ColorSafeStringify, TinyPromiseQueue, TinyLevelUp, valMediaContentMetadata, valMediaContentMetadataPartial, parseMediaMetadata, extractMediaId3Tags, defuzzifyCentroid, trapezoid, diffArrayList, diffStrings, breakdownDuration, calculateMarketcap, compareMarketcap, getPercentage, areElsCollTop, areElsCollBottom, areElsCollLeft, areElsCollRight, areElsCollPerfTop, areElsCollPerfBottom, areElsCollPerfLeft, areElsCollPerfRight, areElsColliding, areElsPerfColliding, getElsColliding, getElsPerfColliding, getElsCollOverlap, getElsCollOverlapPos, getRectCenter, getElsRelativeCenterOffset, getElsCollDirDepth, getElsCollDetails, safeTextTrim, installWindowHiddenScript, genFibonacciSeq, isDirEmptyAsync, fileSizeAsync, dirSizeAsync, listFilesAsync, listDirsAsync, getLatestBackupPath, fetchJson, fetchText, readJsonBlob, readFileBlob, readBase64Blob, saveJsonFile, readJsonFile, writeJsonFile, ensureDirectory, clearDirectoryAsync, clearDirectory, fileExists, dirExists, isDirEmpty, ensureCopyFile, tryDeleteFile, writeTextFile, listFiles, listDirs, fileSize, dirSize, backupFile, restoreLatestBackup, renameFileBatch, renameFileRegex, renameFileAddPrefixSuffix, renameFileNormalizeCase, renameFilePadNumbers, documentIsFullScreen, isScreenFilled, requestFullScreen, exitFullScreen, isFullScreenMode, onFullScreenChange, offFullScreenChange, isJsonObject, arraySortPositions, formatBytes, addAiMarkerShortcut, extendObjType, reorderObjTypeOrder, cloneObjTypeOrder, countObj, checkObj, objType, ruleOfThree, getSimplePerc, asyncReplace, getAge, formatCustomTimer, formatDayTimer, formatTimer, getTimeDuration, shuffleArray, toTitleCase, toTitleCaseLowerFirst, };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var events = require('events');
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Defines the available normalization strategies for probability weight calculations.
|
|
@@ -118,206 +118,7 @@ var TinyEvents = require('./TinyEvents.cjs');
|
|
|
118
118
|
*
|
|
119
119
|
* @class
|
|
120
120
|
*/
|
|
121
|
-
class TinyAdvancedRaffle {
|
|
122
|
-
#events = new TinyEvents();
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Emits an event, triggering all registered handlers for that event.
|
|
126
|
-
*
|
|
127
|
-
* @param {string|string[]} event - The event name to emit.
|
|
128
|
-
* @param {...any} payload - Optional data to pass to each handler.
|
|
129
|
-
* @returns {boolean[]} True if any listeners were called, false otherwise.
|
|
130
|
-
*/
|
|
131
|
-
#emit(event, ...payload) {
|
|
132
|
-
return this.#events.emit(event, ...payload);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* Enables or disables throwing an error when the maximum number of listeners is exceeded.
|
|
137
|
-
*
|
|
138
|
-
* @param {boolean} shouldThrow - If true, an error will be thrown when the max is exceeded.
|
|
139
|
-
*/
|
|
140
|
-
setThrowOnMaxListeners(shouldThrow) {
|
|
141
|
-
return this.#events.setThrowOnMaxListeners(shouldThrow);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Checks whether an error will be thrown when the max listener limit is exceeded.
|
|
146
|
-
*
|
|
147
|
-
* @returns {boolean} True if an error will be thrown, false if only a warning is shown.
|
|
148
|
-
*/
|
|
149
|
-
getThrowOnMaxListeners() {
|
|
150
|
-
return this.#events.getThrowOnMaxListeners();
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
/////////////////////////////////////////////////////////////
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* Adds a listener to the beginning of the listeners array for the specified event.
|
|
157
|
-
*
|
|
158
|
-
* @param {string|string[]} event - Event name.
|
|
159
|
-
* @param {handler} handler - The callback function.
|
|
160
|
-
*/
|
|
161
|
-
prependListener(event, handler) {
|
|
162
|
-
return this.#events.prependListener(event, handler);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* Adds a one-time listener to the beginning of the listeners array for the specified event.
|
|
167
|
-
*
|
|
168
|
-
* @param {string|string[]} event - Event name.
|
|
169
|
-
* @param {handler} handler - The callback function.
|
|
170
|
-
* @returns {handler[]} - The wrapped handler used internally.
|
|
171
|
-
*/
|
|
172
|
-
prependListenerOnce(event, handler) {
|
|
173
|
-
return this.#events.prependListenerOnce(event, handler);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
//////////////////////////////////////////////////////////////////////
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* Adds a event listener.
|
|
180
|
-
*
|
|
181
|
-
* @param {string|string[]} event - Event name, such as 'onScrollBoundary' or 'onAutoScroll'.
|
|
182
|
-
* @param {handler} handler - Callback function to be called when event fires.
|
|
183
|
-
*/
|
|
184
|
-
appendListener(event, handler) {
|
|
185
|
-
return this.#events.appendListener(event, handler);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* Registers an event listener that runs only once, then is removed.
|
|
190
|
-
*
|
|
191
|
-
* @param {string|string[]} event - Event name, such as 'onScrollBoundary' or 'onAutoScroll'.
|
|
192
|
-
* @param {handler} handler - The callback function to run on event.
|
|
193
|
-
* @returns {handler[]} - The wrapped version of the handler.
|
|
194
|
-
*/
|
|
195
|
-
appendListenerOnce(event, handler) {
|
|
196
|
-
return this.#events.appendListenerOnce(event, handler);
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* Adds a event listener.
|
|
201
|
-
*
|
|
202
|
-
* @param {string|string[]} event - Event name, such as 'onScrollBoundary' or 'onAutoScroll'.
|
|
203
|
-
* @param {handler} handler - Callback function to be called when event fires.
|
|
204
|
-
*/
|
|
205
|
-
on(event, handler) {
|
|
206
|
-
return this.#events.on(event, handler);
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
/**
|
|
210
|
-
* Registers an event listener that runs only once, then is removed.
|
|
211
|
-
*
|
|
212
|
-
* @param {string|string[]} event - Event name, such as 'onScrollBoundary' or 'onAutoScroll'.
|
|
213
|
-
* @param {handler} handler - The callback function to run on event.
|
|
214
|
-
* @returns {handler[]} - The wrapped version of the handler.
|
|
215
|
-
*/
|
|
216
|
-
once(event, handler) {
|
|
217
|
-
return this.#events.once(event, handler);
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
////////////////////////////////////////////////////////////////////
|
|
221
|
-
|
|
222
|
-
/**
|
|
223
|
-
* Removes a previously registered event listener.
|
|
224
|
-
*
|
|
225
|
-
* @param {string|string[]} event - The name of the event to remove the handler from.
|
|
226
|
-
* @param {handler} handler - The specific callback function to remove.
|
|
227
|
-
*/
|
|
228
|
-
off(event, handler) {
|
|
229
|
-
return this.#events.off(event, handler);
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
/**
|
|
233
|
-
* Removes all event listeners of a specific type from the element.
|
|
234
|
-
*
|
|
235
|
-
* @param {string|string[]} event - The event type to remove (e.g. 'onScrollBoundary').
|
|
236
|
-
*/
|
|
237
|
-
offAll(event) {
|
|
238
|
-
return this.#events.offAll(event);
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
/**
|
|
242
|
-
* Removes all event listeners of all types from the element.
|
|
243
|
-
*/
|
|
244
|
-
offAllTypes() {
|
|
245
|
-
return this.#events.offAllTypes();
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
////////////////////////////////////////////////////////////
|
|
249
|
-
|
|
250
|
-
/**
|
|
251
|
-
* Returns the number of listeners for a given event.
|
|
252
|
-
*
|
|
253
|
-
* @param {string} event - The name of the event.
|
|
254
|
-
* @returns {number} Number of listeners for the event.
|
|
255
|
-
*/
|
|
256
|
-
listenerCount(event) {
|
|
257
|
-
return this.#events.listenerCount(event);
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
/**
|
|
261
|
-
* Returns a copy of the array of listeners for the specified event.
|
|
262
|
-
*
|
|
263
|
-
* @param {string} event - The name of the event.
|
|
264
|
-
* @returns {handler[]} Array of listener functions.
|
|
265
|
-
*/
|
|
266
|
-
listeners(event) {
|
|
267
|
-
return this.#events.listeners(event);
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
/**
|
|
271
|
-
* Returns a copy of the array of listeners for the specified event.
|
|
272
|
-
*
|
|
273
|
-
* @param {string} event - The name of the event.
|
|
274
|
-
* @returns {handler[]} Array of listener functions.
|
|
275
|
-
*/
|
|
276
|
-
onceListeners(event) {
|
|
277
|
-
return this.#events.onceListeners(event);
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
/**
|
|
281
|
-
* Returns a copy of the internal listeners array for the specified event,
|
|
282
|
-
* including wrapper functions like those used by `.once()`.
|
|
283
|
-
* @param {string | symbol} event - The event name.
|
|
284
|
-
* @returns {handler[]} An array of raw listener functions.
|
|
285
|
-
*/
|
|
286
|
-
allListeners(event) {
|
|
287
|
-
return this.#events.allListeners(event);
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
/**
|
|
291
|
-
* Returns an array of event names for which there are registered listeners.
|
|
292
|
-
*
|
|
293
|
-
* @returns {string[]} Array of registered event names.
|
|
294
|
-
*/
|
|
295
|
-
eventNames() {
|
|
296
|
-
return this.#events.eventNames();
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
//////////////////////////////////////////////////////
|
|
300
|
-
|
|
301
|
-
/**
|
|
302
|
-
* Sets the maximum number of listeners per event before a warning is shown.
|
|
303
|
-
*
|
|
304
|
-
* @param {number} n - The maximum number of listeners.
|
|
305
|
-
*/
|
|
306
|
-
setMaxListeners(n) {
|
|
307
|
-
return this.#events.setMaxListeners(n);
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
/**
|
|
311
|
-
* Gets the maximum number of listeners allowed per event.
|
|
312
|
-
*
|
|
313
|
-
* @returns {number} The maximum number of listeners.
|
|
314
|
-
*/
|
|
315
|
-
getMaxListeners() {
|
|
316
|
-
return this.#events.getMaxListeners();
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
///////////////////////////////////////////////////
|
|
320
|
-
|
|
121
|
+
class TinyAdvancedRaffle extends events.EventEmitter {
|
|
321
122
|
/**
|
|
322
123
|
* Whether this instance has been destroyed.
|
|
323
124
|
* @type {boolean}
|
|
@@ -682,6 +483,7 @@ class TinyAdvancedRaffle {
|
|
|
682
483
|
* @param {Normalization} [opts.normalization='relative'] - Probability normalization mode.
|
|
683
484
|
*/
|
|
684
485
|
constructor(opts = {}) {
|
|
486
|
+
super();
|
|
685
487
|
const { rng = null, seed = null, normalization = 'relative' } = opts;
|
|
686
488
|
this.#normalization = normalization;
|
|
687
489
|
this.#seed = seed;
|
|
@@ -758,7 +560,7 @@ class TinyAdvancedRaffle {
|
|
|
758
560
|
this.#items.set(id, entry);
|
|
759
561
|
// Register in groups map
|
|
760
562
|
for (const g of groups) this._ensureGroup(g).add(id);
|
|
761
|
-
this
|
|
563
|
+
this.emit('itemAdded', entry);
|
|
762
564
|
return entry;
|
|
763
565
|
}
|
|
764
566
|
|
|
@@ -778,7 +580,7 @@ class TinyAdvancedRaffle {
|
|
|
778
580
|
if (s) s.delete(id);
|
|
779
581
|
}
|
|
780
582
|
this.#items.delete(id);
|
|
781
|
-
this
|
|
583
|
+
this.emit('itemRemoved', id);
|
|
782
584
|
this.resetFreq(id);
|
|
783
585
|
this.resetPity(id);
|
|
784
586
|
return true;
|
|
@@ -799,7 +601,7 @@ class TinyAdvancedRaffle {
|
|
|
799
601
|
const it = this.#items.get(id);
|
|
800
602
|
if (!it) throw new Error('Item not found');
|
|
801
603
|
it.baseWeight = Math.max(0, Number(weight) || 0);
|
|
802
|
-
this
|
|
604
|
+
this.emit('weightChanged', { id, weight: it.baseWeight });
|
|
803
605
|
}
|
|
804
606
|
|
|
805
607
|
/**
|
|
@@ -1349,7 +1151,7 @@ class TinyAdvancedRaffle {
|
|
|
1349
1151
|
const item = this.#items.get(chosen.id);
|
|
1350
1152
|
if (!item) return null;
|
|
1351
1153
|
const result = { id: item.id, label: item.label, meta: { ...item.meta }, prob: chosen.p };
|
|
1352
|
-
this
|
|
1154
|
+
this.emit('draw', result);
|
|
1353
1155
|
|
|
1354
1156
|
// add frequence
|
|
1355
1157
|
if (result) this.#freq.set(result.id, (this.#freq.get(result.id) || 0) + 1);
|
|
@@ -260,7 +260,7 @@ export type handler = (payload: any, event: any) => any;
|
|
|
260
260
|
*
|
|
261
261
|
* @class
|
|
262
262
|
*/
|
|
263
|
-
declare class TinyAdvancedRaffle {
|
|
263
|
+
declare class TinyAdvancedRaffle extends EventEmitter<any> {
|
|
264
264
|
/**
|
|
265
265
|
* Creates a new AdvancedRaffle instance.
|
|
266
266
|
* @param {Object} [opts] - Optional configuration.
|
|
@@ -273,126 +273,6 @@ declare class TinyAdvancedRaffle {
|
|
|
273
273
|
seed?: number | null | undefined;
|
|
274
274
|
normalization?: Normalization | undefined;
|
|
275
275
|
});
|
|
276
|
-
/**
|
|
277
|
-
* Enables or disables throwing an error when the maximum number of listeners is exceeded.
|
|
278
|
-
*
|
|
279
|
-
* @param {boolean} shouldThrow - If true, an error will be thrown when the max is exceeded.
|
|
280
|
-
*/
|
|
281
|
-
setThrowOnMaxListeners(shouldThrow: boolean): void;
|
|
282
|
-
/**
|
|
283
|
-
* Checks whether an error will be thrown when the max listener limit is exceeded.
|
|
284
|
-
*
|
|
285
|
-
* @returns {boolean} True if an error will be thrown, false if only a warning is shown.
|
|
286
|
-
*/
|
|
287
|
-
getThrowOnMaxListeners(): boolean;
|
|
288
|
-
/**
|
|
289
|
-
* Adds a listener to the beginning of the listeners array for the specified event.
|
|
290
|
-
*
|
|
291
|
-
* @param {string|string[]} event - Event name.
|
|
292
|
-
* @param {handler} handler - The callback function.
|
|
293
|
-
*/
|
|
294
|
-
prependListener(event: string | string[], handler: handler): void;
|
|
295
|
-
/**
|
|
296
|
-
* Adds a one-time listener to the beginning of the listeners array for the specified event.
|
|
297
|
-
*
|
|
298
|
-
* @param {string|string[]} event - Event name.
|
|
299
|
-
* @param {handler} handler - The callback function.
|
|
300
|
-
* @returns {handler[]} - The wrapped handler used internally.
|
|
301
|
-
*/
|
|
302
|
-
prependListenerOnce(event: string | string[], handler: handler): handler[];
|
|
303
|
-
/**
|
|
304
|
-
* Adds a event listener.
|
|
305
|
-
*
|
|
306
|
-
* @param {string|string[]} event - Event name, such as 'onScrollBoundary' or 'onAutoScroll'.
|
|
307
|
-
* @param {handler} handler - Callback function to be called when event fires.
|
|
308
|
-
*/
|
|
309
|
-
appendListener(event: string | string[], handler: handler): void;
|
|
310
|
-
/**
|
|
311
|
-
* Registers an event listener that runs only once, then is removed.
|
|
312
|
-
*
|
|
313
|
-
* @param {string|string[]} event - Event name, such as 'onScrollBoundary' or 'onAutoScroll'.
|
|
314
|
-
* @param {handler} handler - The callback function to run on event.
|
|
315
|
-
* @returns {handler[]} - The wrapped version of the handler.
|
|
316
|
-
*/
|
|
317
|
-
appendListenerOnce(event: string | string[], handler: handler): handler[];
|
|
318
|
-
/**
|
|
319
|
-
* Adds a event listener.
|
|
320
|
-
*
|
|
321
|
-
* @param {string|string[]} event - Event name, such as 'onScrollBoundary' or 'onAutoScroll'.
|
|
322
|
-
* @param {handler} handler - Callback function to be called when event fires.
|
|
323
|
-
*/
|
|
324
|
-
on(event: string | string[], handler: handler): void;
|
|
325
|
-
/**
|
|
326
|
-
* Registers an event listener that runs only once, then is removed.
|
|
327
|
-
*
|
|
328
|
-
* @param {string|string[]} event - Event name, such as 'onScrollBoundary' or 'onAutoScroll'.
|
|
329
|
-
* @param {handler} handler - The callback function to run on event.
|
|
330
|
-
* @returns {handler[]} - The wrapped version of the handler.
|
|
331
|
-
*/
|
|
332
|
-
once(event: string | string[], handler: handler): handler[];
|
|
333
|
-
/**
|
|
334
|
-
* Removes a previously registered event listener.
|
|
335
|
-
*
|
|
336
|
-
* @param {string|string[]} event - The name of the event to remove the handler from.
|
|
337
|
-
* @param {handler} handler - The specific callback function to remove.
|
|
338
|
-
*/
|
|
339
|
-
off(event: string | string[], handler: handler): void;
|
|
340
|
-
/**
|
|
341
|
-
* Removes all event listeners of a specific type from the element.
|
|
342
|
-
*
|
|
343
|
-
* @param {string|string[]} event - The event type to remove (e.g. 'onScrollBoundary').
|
|
344
|
-
*/
|
|
345
|
-
offAll(event: string | string[]): void;
|
|
346
|
-
/**
|
|
347
|
-
* Removes all event listeners of all types from the element.
|
|
348
|
-
*/
|
|
349
|
-
offAllTypes(): void;
|
|
350
|
-
/**
|
|
351
|
-
* Returns the number of listeners for a given event.
|
|
352
|
-
*
|
|
353
|
-
* @param {string} event - The name of the event.
|
|
354
|
-
* @returns {number} Number of listeners for the event.
|
|
355
|
-
*/
|
|
356
|
-
listenerCount(event: string): number;
|
|
357
|
-
/**
|
|
358
|
-
* Returns a copy of the array of listeners for the specified event.
|
|
359
|
-
*
|
|
360
|
-
* @param {string} event - The name of the event.
|
|
361
|
-
* @returns {handler[]} Array of listener functions.
|
|
362
|
-
*/
|
|
363
|
-
listeners(event: string): handler[];
|
|
364
|
-
/**
|
|
365
|
-
* Returns a copy of the array of listeners for the specified event.
|
|
366
|
-
*
|
|
367
|
-
* @param {string} event - The name of the event.
|
|
368
|
-
* @returns {handler[]} Array of listener functions.
|
|
369
|
-
*/
|
|
370
|
-
onceListeners(event: string): handler[];
|
|
371
|
-
/**
|
|
372
|
-
* Returns a copy of the internal listeners array for the specified event,
|
|
373
|
-
* including wrapper functions like those used by `.once()`.
|
|
374
|
-
* @param {string | symbol} event - The event name.
|
|
375
|
-
* @returns {handler[]} An array of raw listener functions.
|
|
376
|
-
*/
|
|
377
|
-
allListeners(event: string | symbol): handler[];
|
|
378
|
-
/**
|
|
379
|
-
* Returns an array of event names for which there are registered listeners.
|
|
380
|
-
*
|
|
381
|
-
* @returns {string[]} Array of registered event names.
|
|
382
|
-
*/
|
|
383
|
-
eventNames(): string[];
|
|
384
|
-
/**
|
|
385
|
-
* Sets the maximum number of listeners per event before a warning is shown.
|
|
386
|
-
*
|
|
387
|
-
* @param {number} n - The maximum number of listeners.
|
|
388
|
-
*/
|
|
389
|
-
setMaxListeners(n: number): void;
|
|
390
|
-
/**
|
|
391
|
-
* Gets the maximum number of listeners allowed per event.
|
|
392
|
-
*
|
|
393
|
-
* @returns {number} The maximum number of listeners.
|
|
394
|
-
*/
|
|
395
|
-
getMaxListeners(): number;
|
|
396
276
|
/**
|
|
397
277
|
* Indicates whether this instance has been destroyed.
|
|
398
278
|
* @type {boolean}
|
|
@@ -848,4 +728,5 @@ declare class TinyAdvancedRaffle {
|
|
|
848
728
|
destroy(): void;
|
|
849
729
|
#private;
|
|
850
730
|
}
|
|
731
|
+
import { EventEmitter } from 'events';
|
|
851
732
|
//# sourceMappingURL=TinyAdvancedRaffle.d.mts.map
|