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,3 +1,5 @@
1
+ import { createCheckDestroyed } from './utils.mjs';
2
+ const checkDestroy = createCheckDestroyed('TinyDayNightCycle');
1
3
  /**
2
4
  * Represents a mapping of weather type names to their selected values.
3
5
  * Each key is the name of a weather type, and the value is either:
@@ -215,6 +217,7 @@ class TinyDayNightCycle {
215
217
  * @returns {number}
216
218
  */
217
219
  get daySize() {
220
+ checkDestroy(this.#isDestroyed);
218
221
  return this.#daySize;
219
222
  }
220
223
  /**
@@ -222,6 +225,7 @@ class TinyDayNightCycle {
222
225
  * @returns {boolean}
223
226
  */
224
227
  get autoSizeAdjuste() {
228
+ checkDestroy(this.#isDestroyed);
225
229
  return this.#autoSizeAdjuste;
226
230
  }
227
231
  /**
@@ -230,6 +234,7 @@ class TinyDayNightCycle {
230
234
  * @throws {TypeError} If `value` is not a boolean.
231
235
  */
232
236
  set autoSizeAdjuste(value) {
237
+ checkDestroy(this.#isDestroyed);
233
238
  if (typeof value !== 'boolean')
234
239
  throw new TypeError('autoSizeAdjuste must be a boolean.');
235
240
  this.#autoSizeAdjuste = value;
@@ -241,6 +246,7 @@ class TinyDayNightCycle {
241
246
  * @throws {Error} If `value` is not a positive finite number.
242
247
  */
243
248
  set daySize(value) {
249
+ checkDestroy(this.#isDestroyed);
244
250
  if (typeof value !== 'number' || !Number.isFinite(value) || value <= 0)
245
251
  throw new Error('daySize must be a positive finite number.');
246
252
  const hourRatio = this.#hourSize / this.#daySize;
@@ -256,6 +262,7 @@ class TinyDayNightCycle {
256
262
  * @returns {number}
257
263
  */
258
264
  get hourSize() {
265
+ checkDestroy(this.#isDestroyed);
259
266
  return this.#hourSize;
260
267
  }
261
268
  /**
@@ -265,6 +272,7 @@ class TinyDayNightCycle {
265
272
  * @throws {Error} If `value` is not a positive finite number.
266
273
  */
267
274
  set hourSize(value) {
275
+ checkDestroy(this.#isDestroyed);
268
276
  if (typeof value !== 'number' || !Number.isFinite(value) || value <= 0)
269
277
  throw new Error('hourSize must be a positive finite number.');
270
278
  const dayRatio = this.#daySize / this.#hourSize;
@@ -280,6 +288,7 @@ class TinyDayNightCycle {
280
288
  * @returns {number}
281
289
  */
282
290
  get minuteSize() {
291
+ checkDestroy(this.#isDestroyed);
283
292
  return this.#minuteSize;
284
293
  }
285
294
  /**
@@ -289,6 +298,7 @@ class TinyDayNightCycle {
289
298
  * @throws {Error} If `value` is not a positive finite number.
290
299
  */
291
300
  set minuteSize(value) {
301
+ checkDestroy(this.#isDestroyed);
292
302
  if (typeof value !== 'number' || !Number.isFinite(value) || value <= 0)
293
303
  throw new Error('minuteSize must be a positive finite number.');
294
304
  const hourRatio = this.#hourSize / this.#minuteSize;
@@ -311,6 +321,7 @@ class TinyDayNightCycle {
311
321
  * @returns {number} Current seconds (0 to 86399).
312
322
  */
313
323
  get currentSeconds() {
324
+ checkDestroy(this.#isDestroyed);
314
325
  return this.#currentSeconds;
315
326
  }
316
327
  /**
@@ -321,7 +332,7 @@ class TinyDayNightCycle {
321
332
  * @throws {RangeError} If the value is outside the valid range.
322
333
  */
323
334
  set currentSeconds(value) {
324
- this._checkDestroyed();
335
+ checkDestroy(this.#isDestroyed);
325
336
  if (typeof value !== 'number' || !Number.isFinite(value))
326
337
  throw new TypeError(`currentSeconds must be a finite number, received ${typeof value}`);
327
338
  if (value < 0 || value >= this.#daySize)
@@ -335,6 +346,7 @@ class TinyDayNightCycle {
335
346
  * @returns {number} Current minutes (0 to 1439).
336
347
  */
337
348
  get currentMinutes() {
349
+ checkDestroy(this.#isDestroyed);
338
350
  return this.#currentMinutes;
339
351
  }
340
352
  /**
@@ -345,7 +357,7 @@ class TinyDayNightCycle {
345
357
  * @throws {RangeError} If the value is outside the valid range.
346
358
  */
347
359
  set currentMinutes(value) {
348
- this._checkDestroyed();
360
+ checkDestroy(this.#isDestroyed);
349
361
  if (typeof value !== 'number' || !Number.isFinite(value))
350
362
  throw new TypeError(`currentMinutes must be a finite number, received ${typeof value}`);
351
363
  if (value < 0 || value >= 1440)
@@ -360,6 +372,7 @@ class TinyDayNightCycle {
360
372
  * @returns {number} Current hours (0 to less than 24).
361
373
  */
362
374
  get currentHours() {
375
+ checkDestroy(this.#isDestroyed);
363
376
  return this.#currentHours;
364
377
  }
365
378
  /**
@@ -371,7 +384,7 @@ class TinyDayNightCycle {
371
384
  * @throws {RangeError} If the value is outside the valid range.
372
385
  */
373
386
  set currentHours(value) {
374
- this._checkDestroyed();
387
+ checkDestroy(this.#isDestroyed);
375
388
  if (typeof value !== 'number' || !Number.isFinite(value))
376
389
  throw new TypeError(`currentHours must be a finite number, received ${typeof value}`);
377
390
  if (value < 0 || value >= 24)
@@ -385,6 +398,7 @@ class TinyDayNightCycle {
385
398
  * @returns {MoonData[]} Array of moons including their name, current phase index, phase name, and cycle length.
386
399
  */
387
400
  get moons() {
401
+ checkDestroy(this.#isDestroyed);
388
402
  return this.#moons.map((moon) => this.getMoon(moon));
389
403
  }
390
404
  /**
@@ -392,34 +406,42 @@ class TinyDayNightCycle {
392
406
  * @returns {string[]} Array of season names.
393
407
  */
394
408
  get seasons() {
409
+ checkDestroy(this.#isDestroyed);
395
410
  return Array.from(this.#seasons.keys());
396
411
  }
397
412
  /** @returns {number} Hour at which day starts (0-23). */
398
413
  get dayStart() {
414
+ checkDestroy(this.#isDestroyed);
399
415
  return this.#dayStart;
400
416
  }
401
417
  /** @returns {number} Hour at which night starts (0-23). */
402
418
  get nightStart() {
419
+ checkDestroy(this.#isDestroyed);
403
420
  return this.#nightStart;
404
421
  }
405
422
  /** @returns {SelectedWeather} Currently active weather types or nulls if none. */
406
423
  get weather() {
424
+ checkDestroy(this.#isDestroyed);
407
425
  return { ...this.#weather };
408
426
  }
409
427
  /** @returns {string} Currently active season name. */
410
428
  get currentSeason() {
429
+ checkDestroy(this.#isDestroyed);
411
430
  return this.#currentSeason;
412
431
  }
413
432
  /** @returns {number} Current day of the month. */
414
433
  get currentDay() {
434
+ checkDestroy(this.#isDestroyed);
415
435
  return this.#currentDay;
416
436
  }
417
437
  /** @returns {number} Current month number. */
418
438
  get currentMonth() {
439
+ checkDestroy(this.#isDestroyed);
419
440
  return this.#currentMonth;
420
441
  }
421
442
  /** @returns {number} Current year count. */
422
443
  get currentYear() {
444
+ checkDestroy(this.#isDestroyed);
423
445
  return this.#currentYear;
424
446
  }
425
447
  /**
@@ -428,6 +450,7 @@ class TinyDayNightCycle {
428
450
  * @returns {number[]} Object mapping month number to days.
429
451
  */
430
452
  get monthDays() {
453
+ checkDestroy(this.#isDestroyed);
431
454
  return [...this.#monthDays];
432
455
  }
433
456
  /**
@@ -435,10 +458,12 @@ class TinyDayNightCycle {
435
458
  * @returns {{min: number, max: number}} Object with min and max weather duration.
436
459
  */
437
460
  get weatherDuration() {
461
+ checkDestroy(this.#isDestroyed);
438
462
  return { ...this.#weatherDuration };
439
463
  }
440
464
  /** @returns {number} Minutes left until current weather expires. */
441
465
  get weatherTimeLeft() {
466
+ checkDestroy(this.#isDestroyed);
442
467
  return this.#weatherTimeLeft;
443
468
  }
444
469
  /**
@@ -447,7 +472,7 @@ class TinyDayNightCycle {
447
472
  * @throws {TypeError} If value is not a number.
448
473
  */
449
474
  set dayStart(value) {
450
- this._checkDestroyed();
475
+ checkDestroy(this.#isDestroyed);
451
476
  if (typeof value !== 'number' || value < 1)
452
477
  throw new TypeError(`dayStart must be a positive non-zero number, received ${typeof value}`);
453
478
  this.#dayStart = value;
@@ -458,7 +483,7 @@ class TinyDayNightCycle {
458
483
  * @throws {TypeError} If value is not a number.
459
484
  */
460
485
  set nightStart(value) {
461
- this._checkDestroyed();
486
+ checkDestroy(this.#isDestroyed);
462
487
  if (typeof value !== 'number' || value < 1)
463
488
  throw new TypeError(`nightStart must be a positive non-zero number, received ${typeof value}`);
464
489
  this.#nightStart = value;
@@ -469,7 +494,7 @@ class TinyDayNightCycle {
469
494
  * @throws {TypeError} If value is not a string or null.
470
495
  */
471
496
  set weather(value) {
472
- this._checkDestroyed();
497
+ checkDestroy(this.#isDestroyed);
473
498
  if (typeof value !== 'object' ||
474
499
  value === null ||
475
500
  Array.isArray(value) ||
@@ -484,7 +509,7 @@ class TinyDayNightCycle {
484
509
  * @throws {TypeError} If value is not a string or not a configured season.
485
510
  */
486
511
  set currentSeason(value) {
487
- this._checkDestroyed();
512
+ checkDestroy(this.#isDestroyed);
488
513
  if (typeof value !== 'string' || !this.#seasons.has(value)) {
489
514
  throw new TypeError(`currentSeason must be one of ${Array.from(this.#seasons)
490
515
  .map((v) => v[0])
@@ -498,7 +523,7 @@ class TinyDayNightCycle {
498
523
  * @throws {TypeError} If value is not a number.
499
524
  */
500
525
  set currentDay(value) {
501
- this._checkDestroyed();
526
+ checkDestroy(this.#isDestroyed);
502
527
  if (typeof value !== 'number' || value < 1 || value > this.#monthDays[this.#currentMonth - 1])
503
528
  throw new TypeError(`currentDay must be a valid day number, received ${typeof value}`);
504
529
  this.#currentDay = value;
@@ -509,7 +534,7 @@ class TinyDayNightCycle {
509
534
  * @throws {TypeError} If value is not a number.
510
535
  */
511
536
  set currentMonth(value) {
512
- this._checkDestroyed();
537
+ checkDestroy(this.#isDestroyed);
513
538
  if (typeof value !== 'number' || typeof this.#monthDays[value - 1] !== 'number')
514
539
  throw new TypeError(`currentMonth must be a valid month number, received ${typeof value}`);
515
540
  this.#currentMonth = value;
@@ -520,7 +545,7 @@ class TinyDayNightCycle {
520
545
  * @throws {TypeError} If value is not a number.
521
546
  */
522
547
  set currentYear(value) {
523
- this._checkDestroyed();
548
+ checkDestroy(this.#isDestroyed);
524
549
  if (typeof value !== 'number' || value < 1)
525
550
  throw new TypeError(`currentYear must be a positive number non-zero, received ${typeof value}`);
526
551
  this.#currentYear = value;
@@ -531,7 +556,7 @@ class TinyDayNightCycle {
531
556
  * @param {number[]} value - An object where keys are month numbers and values are the number of days.
532
557
  */
533
558
  set monthDays(value) {
534
- this._checkDestroyed();
559
+ checkDestroy(this.#isDestroyed);
535
560
  if (!Array.isArray(value))
536
561
  throw new TypeError(`monthDays must be a array`);
537
562
  if (!value.every((n) => typeof n === 'number'))
@@ -544,7 +569,7 @@ class TinyDayNightCycle {
544
569
  * @throws {TypeError} If value or its min/max are invalid.
545
570
  */
546
571
  set weatherDuration(value) {
547
- this._checkDestroyed();
572
+ checkDestroy(this.#isDestroyed);
548
573
  if (typeof value !== 'object' || value === null)
549
574
  throw new TypeError(`weatherDuration must be a non-null object`);
550
575
  if (typeof value.min !== 'number' || typeof value.max !== 'number')
@@ -557,7 +582,7 @@ class TinyDayNightCycle {
557
582
  * @throws {TypeError} If value is not a number.
558
583
  */
559
584
  set weatherTimeLeft(value) {
560
- this._checkDestroyed();
585
+ checkDestroy(this.#isDestroyed);
561
586
  if (typeof value !== 'number')
562
587
  throw new TypeError(`weatherTimeLeft must be a number, received ${typeof value}`);
563
588
  this.#weatherTimeLeft = value;
@@ -568,6 +593,7 @@ class TinyDayNightCycle {
568
593
  * @returns {WeatherCfgs} Deep copy of the weather configuration.
569
594
  */
570
595
  get weatherConfig() {
596
+ checkDestroy(this.#isDestroyed);
571
597
  /** @type {Record<string, WeatherCfg>} */
572
598
  const hours = {};
573
599
  /** @type {Record<string, WeatherCfg>} */
@@ -591,7 +617,7 @@ class TinyDayNightCycle {
591
617
  * @throws {TypeError} If the provided value is not a valid object or contains invalid data types.
592
618
  */
593
619
  set weatherConfig(config) {
594
- this._checkDestroyed();
620
+ checkDestroy(this.#isDestroyed);
595
621
  if (typeof config !== 'object' || config === null)
596
622
  throw new TypeError(`weatherConfig must be a non-null object, received ${config}`);
597
623
  const requiredKeys = ['default', 'day', 'night', 'hours', 'seasons'];
@@ -658,7 +684,7 @@ class TinyDayNightCycle {
658
684
  * @throws {TypeError} If `name` is not a string or `values` is not an array of numbers.
659
685
  */
660
686
  addSeason(name, values) {
661
- this._checkDestroyed();
687
+ checkDestroy(this.#isDestroyed);
662
688
  if (typeof name !== 'string')
663
689
  throw new TypeError(`Season name must be a string, received ${typeof name}`);
664
690
  if (!Array.isArray(values) || !values.every((v) => typeof v === 'number'))
@@ -672,7 +698,7 @@ class TinyDayNightCycle {
672
698
  * @throws {TypeError} If `name` is not a string.
673
699
  */
674
700
  removeSeason(name) {
675
- this._checkDestroyed();
701
+ checkDestroy(this.#isDestroyed);
676
702
  if (typeof name !== 'string')
677
703
  throw new TypeError(`Season name must be a string, received ${typeof name}`);
678
704
  this.#seasons.delete(name);
@@ -687,6 +713,7 @@ class TinyDayNightCycle {
687
713
  * @throws {TypeError} If `name` is not a string.
688
714
  */
689
715
  hasSeason(name) {
716
+ checkDestroy(this.#isDestroyed);
690
717
  if (typeof name !== 'string')
691
718
  throw new TypeError(`Season name must be a string, received ${typeof name}`);
692
719
  return this.#seasons.has(name);
@@ -700,6 +727,7 @@ class TinyDayNightCycle {
700
727
  * @throws {Error} If the season does not exist.
701
728
  */
702
729
  getSeason(name) {
730
+ checkDestroy(this.#isDestroyed);
703
731
  if (typeof name !== 'string')
704
732
  throw new TypeError(`Season name must be a string, received ${typeof name}`);
705
733
  const result = this.#seasons.get(name);
@@ -716,7 +744,7 @@ class TinyDayNightCycle {
716
744
  * @param {number} [settings.second=0] - 0 to 59
717
745
  */
718
746
  setTime({ hour = 0, minute = 0, second = 0 }) {
719
- this._checkDestroyed();
747
+ checkDestroy(this.#isDestroyed);
720
748
  this.currentSeconds =
721
749
  (hour * this.#hourSize + minute * this.#minuteSize + second) % this.#daySize;
722
750
  }
@@ -728,7 +756,7 @@ class TinyDayNightCycle {
728
756
  * @param {number} [settings.seconds=0]
729
757
  */
730
758
  addTime({ hours = 0, minutes = 0, seconds = 0 }) {
731
- this._checkDestroyed();
759
+ checkDestroy(this.#isDestroyed);
732
760
  let total = this.currentSeconds + hours * this.#hourSize + minutes * this.#minuteSize + seconds;
733
761
  while (total >= this.#daySize) {
734
762
  total -= this.#daySize;
@@ -757,6 +785,7 @@ class TinyDayNightCycle {
757
785
  * }} An object containing the hour, minute, second, and the formatted time string.
758
786
  */
759
787
  getTime({ withSeconds = false, hourSize = this.#hourSize, minuteSize = this.#minuteSize } = {}) {
788
+ checkDestroy(this.#isDestroyed);
760
789
  const hour = Math.floor(this.currentSeconds / hourSize);
761
790
  const minute = Math.floor((this.currentSeconds % hourSize) / minuteSize);
762
791
  const second = this.currentSeconds % minuteSize;
@@ -775,6 +804,7 @@ class TinyDayNightCycle {
775
804
  * @returns {boolean} True if current time is day, false otherwise.
776
805
  */
777
806
  isDay() {
807
+ checkDestroy(this.#isDestroyed);
778
808
  if (this.#dayStart < this.#nightStart) {
779
809
  return (this.#currentMinutes >= this.#dayStart * this.#minuteSize &&
780
810
  this.#currentMinutes < this.#nightStart * this.#minuteSize);
@@ -837,7 +867,7 @@ class TinyDayNightCycle {
837
867
  * @returns {number} Time until target hour, in the specified unit.
838
868
  */
839
869
  timeUntil(targetHour, unit) {
840
- this._checkDestroyed();
870
+ checkDestroy(this.#isDestroyed);
841
871
  const targetSeconds = targetHour * this.#hourSize; // 1 hour = 3600 seconds
842
872
  let diffSeconds = targetSeconds - this.#currentSeconds;
843
873
  if (diffSeconds <= 0)
@@ -857,7 +887,7 @@ class TinyDayNightCycle {
857
887
  * @param {"day"|"night"} phase - The phase to set the time to.
858
888
  */
859
889
  setTo(phase) {
860
- this._checkDestroyed();
890
+ checkDestroy(this.#isDestroyed);
861
891
  if (phase === 'day')
862
892
  this.setTime({ hour: this.#dayStart });
863
893
  else if (phase === 'night')
@@ -871,7 +901,7 @@ class TinyDayNightCycle {
871
901
  * @param {number} [amount=1] - Number of days to move forward.
872
902
  */
873
903
  nextDay(amount = 1) {
874
- this._checkDestroyed();
904
+ checkDestroy(this.#isDestroyed);
875
905
  for (let i = 0; i < amount; i++) {
876
906
  this.#currentDay++;
877
907
  const monthDays = this.#monthDays[this.#currentMonth - 1];
@@ -896,7 +926,7 @@ class TinyDayNightCycle {
896
926
  * @param {number} [amount=1] - Number of days to move backward.
897
927
  */
898
928
  prevDay(amount = 1) {
899
- this._checkDestroyed();
929
+ checkDestroy(this.#isDestroyed);
900
930
  for (let i = 0; i < amount; i++) {
901
931
  this.#currentDay--;
902
932
  if (this.#currentDay < 1) {
@@ -915,7 +945,7 @@ class TinyDayNightCycle {
915
945
  * Updates the current season based on the month.
916
946
  */
917
947
  updateSeason() {
918
- this._checkDestroyed();
948
+ checkDestroy(this.#isDestroyed);
919
949
  this.#seasons.forEach((seasonMonths, name) => {
920
950
  if (seasonMonths.includes(this.#currentMonth))
921
951
  this.#currentSeason = name;
@@ -928,7 +958,7 @@ class TinyDayNightCycle {
928
958
  * An object defining default probabilities, time-based probabilities, day/night differences, and seasonal probabilities.
929
959
  */
930
960
  setWeatherConfig(config) {
931
- this._checkDestroyed();
961
+ checkDestroy(this.#isDestroyed);
932
962
  this.#weatherConfig = { ...this.#weatherConfig, ...config };
933
963
  }
934
964
  /**
@@ -937,7 +967,7 @@ class TinyDayNightCycle {
937
967
  * @param {number} maxMinutes - Maximum duration in minutes.
938
968
  */
939
969
  setWeatherDuration(minMinutes, maxMinutes) {
940
- this._checkDestroyed();
970
+ checkDestroy(this.#isDestroyed);
941
971
  this.#weatherDuration.min = minMinutes;
942
972
  this.#weatherDuration.max = maxMinutes;
943
973
  }
@@ -947,7 +977,7 @@ class TinyDayNightCycle {
947
977
  * @param {number} minutesPassed - Number of in-game minutes passed since last update.
948
978
  */
949
979
  updateWeatherTimer(minutesPassed) {
950
- this._checkDestroyed();
980
+ checkDestroy(this.#isDestroyed);
951
981
  this.#weatherTimeLeft -= minutesPassed;
952
982
  if (this.#weatherTimeLeft <= 0) {
953
983
  this.chooseNewWeather();
@@ -961,7 +991,7 @@ class TinyDayNightCycle {
961
991
  * @param {number|null} [settings.duration=null] - Duration in minutes. If null, a random duration is used.
962
992
  */
963
993
  forceWeather({ where = 'main', type, duration = null }) {
964
- this._checkDestroyed();
994
+ checkDestroy(this.#isDestroyed);
965
995
  const weather = this.#weather;
966
996
  weather[where] = type;
967
997
  this.weather = weather;
@@ -983,7 +1013,7 @@ class TinyDayNightCycle {
983
1013
  * @returns {string|null} - The selected weather type, or null if none selected.
984
1014
  */
985
1015
  chooseNewWeather({ customWeather, where = 'main' } = {}) {
986
- this._checkDestroyed();
1016
+ checkDestroy(this.#isDestroyed);
987
1017
  /** @type {WeatherData} */
988
1018
  let probabilities = {};
989
1019
  /**
@@ -1063,6 +1093,7 @@ class TinyDayNightCycle {
1063
1093
  * @param {number} min - Minimum value.
1064
1094
  * @param {number} max - Maximum value.
1065
1095
  * @returns {number} - A random integer between min and max.
1096
+ * @private
1066
1097
  */
1067
1098
  _randomInRange(min, max) {
1068
1099
  return Math.floor(Math.random() * (max - min + 1)) + min;
@@ -1077,7 +1108,7 @@ class TinyDayNightCycle {
1077
1108
  * @returns {number} - The moon index.
1078
1109
  */
1079
1110
  addMoon(name, cycleLength, phaseNames, startingPhase = 0) {
1080
- this._checkDestroyed();
1111
+ checkDestroy(this.#isDestroyed);
1081
1112
  const length = Math.max(1, cycleLength);
1082
1113
  this.#moons.push({
1083
1114
  name,
@@ -1092,7 +1123,7 @@ class TinyDayNightCycle {
1092
1123
  * @param {string} name
1093
1124
  */
1094
1125
  removeMoon(name) {
1095
- this._checkDestroyed();
1126
+ checkDestroy(this.#isDestroyed);
1096
1127
  this.#moons = this.#moons.filter((m) => m.name !== name);
1097
1128
  }
1098
1129
  /**
@@ -1118,7 +1149,7 @@ class TinyDayNightCycle {
1118
1149
  * @throws {RangeError} If the moonIndex is invalid.
1119
1150
  */
1120
1151
  advanceMoon(moonIndex, days = 1) {
1121
- this._checkDestroyed();
1152
+ checkDestroy(this.#isDestroyed);
1122
1153
  const moon = this.#moons[moonIndex];
1123
1154
  if (!moon)
1124
1155
  throw new RangeError(`No moon found at index ${moonIndex}`);
@@ -1131,7 +1162,7 @@ class TinyDayNightCycle {
1131
1162
  * @throws {RangeError} If the moonIndex is invalid.
1132
1163
  */
1133
1164
  rewindMoon(moonIndex, days = 1) {
1134
- this._checkDestroyed();
1165
+ checkDestroy(this.#isDestroyed);
1135
1166
  const moon = this.#moons[moonIndex];
1136
1167
  if (!moon)
1137
1168
  throw new RangeError(`No moon found at index ${moonIndex}`);
@@ -1144,6 +1175,7 @@ class TinyDayNightCycle {
1144
1175
  * @returns {boolean} `true` if a moon exists at the given index, otherwise `false`.
1145
1176
  */
1146
1177
  moonExists(index) {
1178
+ checkDestroy(this.#isDestroyed);
1147
1179
  if (!this.#moons[index])
1148
1180
  return false;
1149
1181
  return true;
@@ -1158,6 +1190,7 @@ class TinyDayNightCycle {
1158
1190
  * @throws {Error} If `index` is a `MoonRaw` object but required properties are missing or invalid.
1159
1191
  */
1160
1192
  getMoon(index) {
1193
+ checkDestroy(this.#isDestroyed);
1161
1194
  let moon;
1162
1195
  if (typeof index === 'number') {
1163
1196
  moon = this.#moons[index];
@@ -1181,15 +1214,6 @@ class TinyDayNightCycle {
1181
1214
  cycleLength: moon.cycleLength,
1182
1215
  };
1183
1216
  }
1184
- /**
1185
- * Checks if the instance has been destroyed and throws an error if so.
1186
- * @private
1187
- * @throws {Error} If the instance has already been destroyed.
1188
- */
1189
- _checkDestroyed() {
1190
- if (this.#isDestroyed)
1191
- throw new Error('This instance has been destroyed and can no longer be used.');
1192
- }
1193
1217
  /**
1194
1218
  * Destroys all stored data and marks the instance as unusable.
1195
1219
  * Clears all internal maps, arrays, and resets primitive values to defaults.
@@ -1,5 +1,9 @@
1
1
  'use strict';
2
2
 
3
+ var utils = require('./utils.cjs');
4
+
5
+ const checkDestroy = utils.createCheckDestroyed('TinyDragDropDetector');
6
+
3
7
  /**
4
8
  * @typedef {Object} DragAndDropOptions
5
9
  * @property {string} [hoverClass="dnd-hover"] - CSS class applied to the target element while files are being dragged over it.
@@ -39,6 +43,21 @@ class TinyDragDropDetector {
39
43
  /** @type {boolean} */
40
44
  #bound;
41
45
 
46
+ /**
47
+ * Tracks whether the instance has been destroyed.
48
+ * @type {boolean}
49
+ */
50
+ #destroyed = false;
51
+
52
+ /**
53
+ * Gets the current destruction status of the instance.
54
+ *
55
+ * @returns {boolean} True if the instance is destroyed, false otherwise.
56
+ */
57
+ get destroyed() {
58
+ return this.#destroyed;
59
+ }
60
+
42
61
  /**
43
62
  * Creates a new instance of TinyDragDropDetector to handle drag-and-drop file detection.
44
63
  *
@@ -98,6 +117,7 @@ class TinyDragDropDetector {
98
117
  * @returns {HTMLTarget}
99
118
  */
100
119
  getTarget() {
120
+ checkDestroy(this.#destroyed);
101
121
  return this.#target;
102
122
  }
103
123
 
@@ -106,6 +126,7 @@ class TinyDragDropDetector {
106
126
  * @returns {string}
107
127
  */
108
128
  getHoverClass() {
129
+ checkDestroy(this.#destroyed);
109
130
  return this.#hoverClass;
110
131
  }
111
132
 
@@ -114,6 +135,7 @@ class TinyDragDropDetector {
114
135
  * @returns {boolean}
115
136
  */
116
137
  isDragging() {
138
+ checkDestroy(this.#destroyed);
117
139
  return this.#isDragging;
118
140
  }
119
141
 
@@ -122,6 +144,7 @@ class TinyDragDropDetector {
122
144
  * @returns {boolean}
123
145
  */
124
146
  bound() {
147
+ checkDestroy(this.#destroyed);
125
148
  return this.#bound;
126
149
  }
127
150
 
@@ -234,9 +257,11 @@ class TinyDragDropDetector {
234
257
  * @returns {void}
235
258
  */
236
259
  destroy() {
260
+ if (this.#destroyed) return;
237
261
  this.#unbindEvents();
238
262
  const target = this.getTarget();
239
263
  target.classList.remove(this.#hoverClass);
264
+ this.#destroyed = true;
240
265
  }
241
266
  }
242
267
 
@@ -46,6 +46,12 @@ declare class TinyDragDropDetector<HTMLTarget extends HTMLElement> {
46
46
  * @throws {TypeError} If `onLeave` is defined but not a function.
47
47
  */
48
48
  constructor(target: HTMLTarget, options: DragAndDropOptions);
49
+ /**
50
+ * Gets the current destruction status of the instance.
51
+ *
52
+ * @returns {boolean} True if the instance is destroyed, false otherwise.
53
+ */
54
+ get destroyed(): boolean;
49
55
  /**
50
56
  * Handles the `dragenter` event.
51
57
  * Adds the hover CSS class and triggers the `onEnter` callback if provided.
@@ -1,3 +1,5 @@
1
+ import { createCheckDestroyed } from './utils.mjs';
2
+ const checkDestroy = createCheckDestroyed('TinyDragDropDetector');
1
3
  /**
2
4
  * @typedef {Object} DragAndDropOptions
3
5
  * @property {string} [hoverClass="dnd-hover"] - CSS class applied to the target element while files are being dragged over it.
@@ -29,6 +31,19 @@ class TinyDragDropDetector {
29
31
  #isDragging;
30
32
  /** @type {boolean} */
31
33
  #bound;
34
+ /**
35
+ * Tracks whether the instance has been destroyed.
36
+ * @type {boolean}
37
+ */
38
+ #destroyed = false;
39
+ /**
40
+ * Gets the current destruction status of the instance.
41
+ *
42
+ * @returns {boolean} True if the instance is destroyed, false otherwise.
43
+ */
44
+ get destroyed() {
45
+ return this.#destroyed;
46
+ }
32
47
  /**
33
48
  * Creates a new instance of TinyDragDropDetector to handle drag-and-drop file detection.
34
49
  *
@@ -77,6 +92,7 @@ class TinyDragDropDetector {
77
92
  * @returns {HTMLTarget}
78
93
  */
79
94
  getTarget() {
95
+ checkDestroy(this.#destroyed);
80
96
  return this.#target;
81
97
  }
82
98
  /**
@@ -84,6 +100,7 @@ class TinyDragDropDetector {
84
100
  * @returns {string}
85
101
  */
86
102
  getHoverClass() {
103
+ checkDestroy(this.#destroyed);
87
104
  return this.#hoverClass;
88
105
  }
89
106
  /**
@@ -91,6 +108,7 @@ class TinyDragDropDetector {
91
108
  * @returns {boolean}
92
109
  */
93
110
  isDragging() {
111
+ checkDestroy(this.#destroyed);
94
112
  return this.#isDragging;
95
113
  }
96
114
  /**
@@ -98,6 +116,7 @@ class TinyDragDropDetector {
98
116
  * @returns {boolean}
99
117
  */
100
118
  bound() {
119
+ checkDestroy(this.#destroyed);
101
120
  return this.#bound;
102
121
  }
103
122
  /**
@@ -205,9 +224,12 @@ class TinyDragDropDetector {
205
224
  * @returns {void}
206
225
  */
207
226
  destroy() {
227
+ if (this.#destroyed)
228
+ return;
208
229
  this.#unbindEvents();
209
230
  const target = this.getTarget();
210
231
  target.classList.remove(this.#hoverClass);
232
+ this.#destroyed = true;
211
233
  }
212
234
  }
213
235
  export default TinyDragDropDetector;