@byloth/core 2.1.7 → 2.2.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.
@@ -3,11 +3,12 @@ import { isBrowser } from "../../helpers.js";
3
3
 
4
4
  import Publisher from "../callbacks/publisher.js";
5
5
  import { FatalErrorException, RuntimeException } from "../exceptions/index.js";
6
+ import type { Callback } from "../types.js";
6
7
 
7
8
  interface GameLoopEventsMap
8
9
  {
9
- start: () => void;
10
- stop: () => void;
10
+ "start": () => void;
11
+ "stop": () => void;
11
12
  }
12
13
 
13
14
  /**
@@ -102,7 +103,7 @@ export default class GameLoop
102
103
  * Depending on the current environment, it could use the
103
104
  * {@link requestAnimationFrame} or the {@link setInterval} function.
104
105
  */
105
- protected readonly _start: () => void;
106
+ protected readonly _start: Callback;
106
107
 
107
108
  /**
108
109
  * The internal method actually responsible for stopping the game loop.
@@ -110,7 +111,7 @@ export default class GameLoop
110
111
  * Depending on the current environment, it could use the
111
112
  * {@link cancelAnimationFrame} or the {@link clearInterval} function.
112
113
  */
113
- protected readonly _stop: () => void;
114
+ protected readonly _stop: Callback;
114
115
 
115
116
  /**
116
117
  * Initializes a new instance of the {@link GameLoop} class.
@@ -235,7 +236,7 @@ export default class GameLoop
235
236
  *
236
237
  * @returns A function that can be used to unsubscribe from the event.
237
238
  */
238
- public onStart(callback: () => void): () => void
239
+ public onStart(callback: Callback): Callback
239
240
  {
240
241
  return this._publisher.subscribe("start", callback);
241
242
  }
@@ -256,7 +257,7 @@ export default class GameLoop
256
257
  *
257
258
  * @returns A function that can be used to unsubscribe from the event.
258
259
  */
259
- public onStop(callback: () => void): () => void
260
+ public onStop(callback: Callback): Callback
260
261
  {
261
262
  return this._publisher.subscribe("stop", callback);
262
263
  }
@@ -9,7 +9,7 @@ export type {
9
9
 
10
10
  } from "./aggregators/types.js";
11
11
 
12
- export type { MapViewEventsMap, ReadonlyMapView, SetViewEventsMap, ReadonlySetView } from "./collections/types.js";
12
+ export type { ReadonlyMapView, ReadonlySetView } from "./collections/types.js";
13
13
  export type {
14
14
  GeneratorFunction,
15
15
  AsyncGeneratorFunction,
@@ -1,3 +1,5 @@
1
+ import { SmartPromise } from "../models/index.js";
2
+
1
3
  /**
2
4
  * Returns a promise that resolves after a certain number of milliseconds.
3
5
  * It can be used to pause or delay the execution of an asynchronous function.
@@ -15,11 +17,11 @@
15
17
  *
16
18
  * @param milliseconds The number of milliseconds to wait before resolving the promise.
17
19
  *
18
- * @returns A {@link Promise} that resolves after the specified number of milliseconds.
20
+ * @returns A {@link SmartPromise} that resolves after the specified number of milliseconds.
19
21
  */
20
- export function delay(milliseconds: number): Promise<void>
22
+ export function delay(milliseconds: number): SmartPromise<void>
21
23
  {
22
- return new Promise((resolve) => setTimeout(resolve, milliseconds));
24
+ return new SmartPromise((resolve) => setTimeout(resolve, milliseconds));
23
25
  }
24
26
 
25
27
  /**
@@ -39,11 +41,11 @@ export function delay(milliseconds: number): Promise<void>
39
41
  *
40
42
  * ---
41
43
  *
42
- * @returns A {@link Promise} that resolves on the next animation frame.
44
+ * @returns A {@link SmartPromise} that resolves on the next animation frame.
43
45
  */
44
- export function nextAnimationFrame(): Promise<void>
46
+ export function nextAnimationFrame(): SmartPromise<void>
45
47
  {
46
- return new Promise((resolve) => requestAnimationFrame(() => resolve()));
48
+ return new SmartPromise((resolve) => requestAnimationFrame(() => resolve()));
47
49
  }
48
50
 
49
51
  /**
@@ -64,9 +66,9 @@ export function nextAnimationFrame(): Promise<void>
64
66
  *
65
67
  * ---
66
68
  *
67
- * @returns A {@link Promise} that resolves on the next microtask.
69
+ * @returns A {@link SmartPromise} that resolves on the next microtask.
68
70
  */
69
- export function yieldToEventLoop(): Promise<void>
71
+ export function yieldToEventLoop(): SmartPromise<void>
70
72
  {
71
- return new Promise((resolve) => setTimeout(resolve));
73
+ return new SmartPromise((resolve) => setTimeout(resolve));
72
74
  }
package/src/utils/date.ts CHANGED
@@ -174,8 +174,9 @@ export function dateDifference(start: number | string | Date, end: number | stri
174
174
  *
175
175
  * @returns A {@link SmartIterator} object that generates the dates in the range.
176
176
  */
177
- export function dateRange(start: number | string | Date, end: number | string | Date, step = TimeUnit.Day)
178
- : SmartIterator<Date>
177
+ export function dateRange(
178
+ start: number | string | Date, end: number | string | Date, step = TimeUnit.Day
179
+ ): SmartIterator<Date>
179
180
  {
180
181
  start = new Date(start);
181
182
  end = new Date(end);
@@ -271,3 +272,14 @@ export function getWeek(date: number | string | Date, firstDay = WeekDay.Sunday)
271
272
 
272
273
  return dateRound(new Date(firstDayTime));
273
274
  }
275
+
276
+ export function getMonth(date: number | string | Date): Date
277
+ {
278
+ date = new Date(date);
279
+ return new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth()));
280
+ }
281
+ export function getYear(date: number | string | Date): Date
282
+ {
283
+ date = new Date(date);
284
+ return new Date(Date.UTC(date.getUTCFullYear()));
285
+ }
package/src/utils/dom.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { SmartPromise } from "../models/index.js";
2
+
1
3
  /**
2
4
  * Appends a script element to the document body.
3
5
  * It can be used to load external scripts dynamically.
@@ -15,11 +17,11 @@
15
17
  * @param scriptType The type of the script to load. Default is `"text/javascript"`.
16
18
  *
17
19
  * @returns
18
- * A {@link Promise} that resolves when the script has been loaded successfully or rejects if an error occurs.
20
+ * A {@link SmartPromise} that resolves when the script has been loaded successfully or rejects if an error occurs.
19
21
  */
20
- export function loadScript(scriptUrl: string, scriptType = "text/javascript"): Promise<void>
22
+ export function loadScript(scriptUrl: string, scriptType = "text/javascript"): SmartPromise<void>
21
23
  {
22
- return new Promise<void>((resolve, reject) =>
24
+ return new SmartPromise<void>((resolve, reject) =>
23
25
  {
24
26
  const script = document.createElement("script");
25
27