@oscarpalmer/timer 0.36.0 → 0.38.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 +13 -13
- package/dist/constants.js +11 -13
- package/dist/delay.js +3 -3
- package/dist/get.js +2 -2
- package/dist/global.js +5 -4
- package/dist/index.js +4 -4
- package/dist/is.js +1 -1
- package/dist/repeat.js +2 -2
- package/dist/toretto.full.js +515 -0
- package/dist/wait.js +2 -2
- package/dist/when.js +11 -8
- package/dist/work.js +11 -11
- package/package.json +36 -61
- package/src/constants.ts +20 -14
- package/src/delay.ts +6 -7
- package/src/get.ts +4 -6
- package/src/global.ts +5 -9
- package/src/is.ts +9 -1
- package/src/models.ts +35 -40
- package/src/repeat.ts +6 -6
- package/src/timer.ts +4 -17
- package/src/wait.ts +2 -2
- package/src/when.ts +35 -31
- package/src/work.ts +17 -32
- package/types/constants.d.ts +12 -12
- package/types/delay.d.ts +3 -1
- package/types/get.d.ts +1 -1
- package/types/is.d.ts +8 -0
- package/types/repeat.d.ts +3 -0
- package/types/when.d.ts +15 -1
- package/dist/constants.cjs +0 -53
- package/dist/delay.cjs +0 -15
- package/dist/get.cjs +0 -16
- package/dist/global.cjs +0 -14
- package/dist/index.cjs +0 -14
- package/dist/is.cjs +0 -20
- package/dist/models.cjs +0 -7
- package/dist/repeat.cjs +0 -18
- package/dist/rolldown_runtime.cjs +0 -21
- package/dist/timer.cjs +0 -67
- package/dist/timer.full.js +0 -530
- package/dist/wait.cjs +0 -18
- package/dist/when.cjs +0 -95
- package/dist/work.cjs +0 -82
- package/types/constants.d.cts +0 -104
- package/types/delay.d.cts +0 -8
- package/types/get.d.cts +0 -11
- package/types/global.d.cts +0 -3
- package/types/index.d.cts +0 -187
- package/types/is.d.cts +0 -144
- package/types/models.d.cts +0 -128
- package/types/repeat.d.cts +0 -99
- package/types/timer.d.cts +0 -70
- package/types/wait.d.cts +0 -76
- package/types/when.d.cts +0 -66
- package/types/work.d.cts +0 -81
package/dist/work.cjs
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
const require_constants = require("./constants.cjs");
|
|
2
|
-
function finish(timer, state, options, success) {
|
|
3
|
-
cancelAnimationFrame(state.frame);
|
|
4
|
-
require_constants.activeTimers.delete(timer.instance);
|
|
5
|
-
state.active = false;
|
|
6
|
-
state.elapsed = 0;
|
|
7
|
-
state.frame = void 0;
|
|
8
|
-
if (timer.type === require_constants.TYPE_WAIT) state.callback();
|
|
9
|
-
else options.onAfter?.(success);
|
|
10
|
-
}
|
|
11
|
-
function ignore(type, state) {
|
|
12
|
-
if (state.destroyed) return type !== require_constants.WORK_STOP;
|
|
13
|
-
if (state.paused) return type === require_constants.WORK_PAUSE || type === require_constants.WORK_START;
|
|
14
|
-
return state.active && type === require_constants.WORK_START;
|
|
15
|
-
}
|
|
16
|
-
function pause(timer, state) {
|
|
17
|
-
cancelAnimationFrame(state.frame);
|
|
18
|
-
state.frame = void 0;
|
|
19
|
-
return timer.instance;
|
|
20
|
-
}
|
|
21
|
-
function run(timer, state, options) {
|
|
22
|
-
let last;
|
|
23
|
-
let start;
|
|
24
|
-
return function step(now) {
|
|
25
|
-
if (!state.active) return;
|
|
26
|
-
last ??= now;
|
|
27
|
-
start ??= now;
|
|
28
|
-
const difference = now - last;
|
|
29
|
-
state.elapsed += difference;
|
|
30
|
-
state.total += difference;
|
|
31
|
-
last = now;
|
|
32
|
-
if (options.timeout > 0 && state.total >= options.timeout) {
|
|
33
|
-
options.onError?.();
|
|
34
|
-
finish(timer, state, options, false);
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
if (options.interval === require_constants.milliseconds || state.elapsed >= options.interval - require_constants.intervalBuffer) {
|
|
38
|
-
if (options.count > -1) state.callback(state.index);
|
|
39
|
-
start = now;
|
|
40
|
-
state.elapsed = 0;
|
|
41
|
-
state.index += 1;
|
|
42
|
-
if (options.count === -1 || options.count > 0 && state.index >= options.count) {
|
|
43
|
-
finish(timer, state, options, true);
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
state.frame = requestAnimationFrame(step);
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
function setState(type, state) {
|
|
51
|
-
const pausable = type === require_constants.WORK_CONTINUE || type === require_constants.WORK_PAUSE;
|
|
52
|
-
state.elapsed = pausable ? state.elapsed : 0;
|
|
53
|
-
state.index = pausable ? state.index : 0;
|
|
54
|
-
state.total = pausable ? state.total : 0;
|
|
55
|
-
}
|
|
56
|
-
function stop(timer, state, options) {
|
|
57
|
-
cancelAnimationFrame(state.frame);
|
|
58
|
-
require_constants.activeTimers.delete(timer.instance);
|
|
59
|
-
options.onAfter?.(false);
|
|
60
|
-
state.active = !stop;
|
|
61
|
-
state.frame = void 0;
|
|
62
|
-
state.paused = false;
|
|
63
|
-
return timer.instance;
|
|
64
|
-
}
|
|
65
|
-
function work(type, timer, state, options) {
|
|
66
|
-
if (ignore(type, state)) return timer.instance;
|
|
67
|
-
setState(type, state);
|
|
68
|
-
if (type === require_constants.WORK_STOP) return stop(timer, state, options);
|
|
69
|
-
if (type === require_constants.WORK_PAUSE || type === require_constants.WORK_RESTART) {
|
|
70
|
-
cancelAnimationFrame(state.frame);
|
|
71
|
-
state.frame = void 0;
|
|
72
|
-
}
|
|
73
|
-
state.active = true;
|
|
74
|
-
state.paused = type === require_constants.WORK_PAUSE;
|
|
75
|
-
if (state.paused) return pause(timer, state);
|
|
76
|
-
require_constants.activeTimers.add(timer.instance);
|
|
77
|
-
const runner = run(timer, state, options);
|
|
78
|
-
state.frame = requestAnimationFrame(runner);
|
|
79
|
-
return timer.instance;
|
|
80
|
-
}
|
|
81
|
-
exports.stop = stop;
|
|
82
|
-
exports.work = work;
|
package/types/constants.d.cts
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
// Generated by dts-bundle-generator v9.5.1
|
|
2
|
-
|
|
3
|
-
declare class Timer {
|
|
4
|
-
#private;
|
|
5
|
-
protected readonly options: TimerOptions;
|
|
6
|
-
private readonly $timer;
|
|
7
|
-
protected readonly state: TimerState;
|
|
8
|
-
/**
|
|
9
|
-
* Is the timer active?
|
|
10
|
-
*/
|
|
11
|
-
get active(): boolean;
|
|
12
|
-
/**
|
|
13
|
-
* Is the timer destroyed?
|
|
14
|
-
*/
|
|
15
|
-
get destroyed(): boolean;
|
|
16
|
-
/**
|
|
17
|
-
* Is the timer paused?
|
|
18
|
-
*/
|
|
19
|
-
get paused(): boolean;
|
|
20
|
-
/**
|
|
21
|
-
* Get the timer's origin _(if debugging is enabled)_
|
|
22
|
-
*/
|
|
23
|
-
get trace(): string | undefined;
|
|
24
|
-
constructor(type: TimerType, state: Pick<TimerState, "callback" | "trace">, options: TimerOptions, start: boolean);
|
|
25
|
-
/**
|
|
26
|
-
* Continue running the timer _(if it's paused)_
|
|
27
|
-
*/
|
|
28
|
-
continue(): Timer;
|
|
29
|
-
/**
|
|
30
|
-
* Destroy the timer
|
|
31
|
-
*/
|
|
32
|
-
destroy(): void;
|
|
33
|
-
/**
|
|
34
|
-
* Pause the timer _(if it's running)_
|
|
35
|
-
*/
|
|
36
|
-
pause(): Timer;
|
|
37
|
-
/**
|
|
38
|
-
* Restart the timer _(or start it, if it's not running)_
|
|
39
|
-
*/
|
|
40
|
-
restart(): Timer;
|
|
41
|
-
/**
|
|
42
|
-
* Start the timer _(if it's not running)_
|
|
43
|
-
*/
|
|
44
|
-
start(): Timer;
|
|
45
|
-
/**
|
|
46
|
-
* Stop the timer _(if it's running)_
|
|
47
|
-
*/
|
|
48
|
-
stop(): Timer;
|
|
49
|
-
}
|
|
50
|
-
export type TimerOptions = {
|
|
51
|
-
onAfter: ((finished: boolean) => void) | undefined;
|
|
52
|
-
onError: (() => void) | undefined;
|
|
53
|
-
count: number;
|
|
54
|
-
interval: number;
|
|
55
|
-
timeout: number;
|
|
56
|
-
};
|
|
57
|
-
export type TimerState = {
|
|
58
|
-
active: boolean;
|
|
59
|
-
callback: () => void;
|
|
60
|
-
destroyed: boolean;
|
|
61
|
-
elapsed: number;
|
|
62
|
-
frame: number | undefined;
|
|
63
|
-
index: number;
|
|
64
|
-
paused: boolean;
|
|
65
|
-
total: number;
|
|
66
|
-
trace: string | undefined;
|
|
67
|
-
};
|
|
68
|
-
export type TimerType = "repeat" | "wait" | "when";
|
|
69
|
-
export type WorkHandlerType = "continue" | "pause" | "restart" | "start" | "stop";
|
|
70
|
-
export declare const defaultTimeout = 30000;
|
|
71
|
-
/**
|
|
72
|
-
* A set of all active timers
|
|
73
|
-
*/
|
|
74
|
-
export declare const activeTimers: Set<Timer>;
|
|
75
|
-
/**
|
|
76
|
-
* Buffer value to use when evaluating if a specific time is within a certain range
|
|
77
|
-
*/
|
|
78
|
-
export declare const intervalBuffer = 5;
|
|
79
|
-
/**
|
|
80
|
-
* Message to show when a when-timer is destroyed
|
|
81
|
-
*/
|
|
82
|
-
export declare const destroyedMessage = "Timer has already been destroyed";
|
|
83
|
-
/**
|
|
84
|
-
* A set of timers that were paused due to the document being hidden
|
|
85
|
-
*/
|
|
86
|
-
export declare const hiddenTimers: Set<Timer>;
|
|
87
|
-
/**
|
|
88
|
-
* Message to show when a when-timer is started
|
|
89
|
-
*/
|
|
90
|
-
export declare const startedMessage = "Timer has already been started";
|
|
91
|
-
export declare const TYPE_REPEAT: TimerType;
|
|
92
|
-
export declare const TYPE_WAIT: TimerType;
|
|
93
|
-
export declare const TYPE_WHEN: TimerType;
|
|
94
|
-
export declare const WORK_CONTINUE: WorkHandlerType;
|
|
95
|
-
export declare const WORK_PAUSE: WorkHandlerType;
|
|
96
|
-
export declare const WORK_RESTART: WorkHandlerType;
|
|
97
|
-
export declare const WORK_START: WorkHandlerType;
|
|
98
|
-
export declare const WORK_STOP: WorkHandlerType;
|
|
99
|
-
/**
|
|
100
|
-
* A calculated average of the refresh rate of the display _(in milliseconds)_
|
|
101
|
-
*/
|
|
102
|
-
export declare let milliseconds: number;
|
|
103
|
-
|
|
104
|
-
export {};
|
package/types/delay.d.cts
DELETED
package/types/get.d.cts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
// Generated by dts-bundle-generator v9.5.1
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* A generic callback function
|
|
5
|
-
*/
|
|
6
|
-
export type GenericCallback = (...args: any[]) => any;
|
|
7
|
-
export declare function getCallback(value: unknown): GenericCallback;
|
|
8
|
-
export declare function getValidTimeout(value: unknown): number;
|
|
9
|
-
export declare function getValidNumber(value: unknown, defaultValue?: number): number;
|
|
10
|
-
|
|
11
|
-
export {};
|
package/types/global.d.cts
DELETED
package/types/index.d.cts
DELETED
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
// Generated by dts-bundle-generator v9.5.1
|
|
2
|
-
|
|
3
|
-
export declare class Timer {
|
|
4
|
-
#private;
|
|
5
|
-
protected readonly options: TimerOptions;
|
|
6
|
-
private readonly $timer;
|
|
7
|
-
protected readonly state: TimerState;
|
|
8
|
-
/**
|
|
9
|
-
* Is the timer active?
|
|
10
|
-
*/
|
|
11
|
-
get active(): boolean;
|
|
12
|
-
/**
|
|
13
|
-
* Is the timer destroyed?
|
|
14
|
-
*/
|
|
15
|
-
get destroyed(): boolean;
|
|
16
|
-
/**
|
|
17
|
-
* Is the timer paused?
|
|
18
|
-
*/
|
|
19
|
-
get paused(): boolean;
|
|
20
|
-
/**
|
|
21
|
-
* Get the timer's origin _(if debugging is enabled)_
|
|
22
|
-
*/
|
|
23
|
-
get trace(): string | undefined;
|
|
24
|
-
constructor(type: TimerType, state: Pick<TimerState, "callback" | "trace">, options: TimerOptions, start: boolean);
|
|
25
|
-
/**
|
|
26
|
-
* Continue running the timer _(if it's paused)_
|
|
27
|
-
*/
|
|
28
|
-
continue(): Timer;
|
|
29
|
-
/**
|
|
30
|
-
* Destroy the timer
|
|
31
|
-
*/
|
|
32
|
-
destroy(): void;
|
|
33
|
-
/**
|
|
34
|
-
* Pause the timer _(if it's running)_
|
|
35
|
-
*/
|
|
36
|
-
pause(): Timer;
|
|
37
|
-
/**
|
|
38
|
-
* Restart the timer _(or start it, if it's not running)_
|
|
39
|
-
*/
|
|
40
|
-
restart(): Timer;
|
|
41
|
-
/**
|
|
42
|
-
* Start the timer _(if it's not running)_
|
|
43
|
-
*/
|
|
44
|
-
start(): Timer;
|
|
45
|
-
/**
|
|
46
|
-
* Stop the timer _(if it's running)_
|
|
47
|
-
*/
|
|
48
|
-
stop(): Timer;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Options for a repeating timer
|
|
52
|
-
*/
|
|
53
|
-
export type RepeatOptions = {
|
|
54
|
-
/**
|
|
55
|
-
* Callback to be called when the timer has stopped, either manually or by completing its work
|
|
56
|
-
*/
|
|
57
|
-
onAfter: (finished: boolean) => void;
|
|
58
|
-
/**
|
|
59
|
-
* Callback to be called after the timer has timed out
|
|
60
|
-
*/
|
|
61
|
-
onTimeout: () => void;
|
|
62
|
-
/**
|
|
63
|
-
* How many times the timer should repeat
|
|
64
|
-
*/
|
|
65
|
-
count: number;
|
|
66
|
-
/**
|
|
67
|
-
* The interval between each repeat
|
|
68
|
-
*/
|
|
69
|
-
interval: number;
|
|
70
|
-
/**
|
|
71
|
-
* The timeout for the timer _(any value above `0` will enable the timeout)_
|
|
72
|
-
*/
|
|
73
|
-
timeout: number;
|
|
74
|
-
};
|
|
75
|
-
export type TimerOptions = {
|
|
76
|
-
onAfter: ((finished: boolean) => void) | undefined;
|
|
77
|
-
onError: (() => void) | undefined;
|
|
78
|
-
count: number;
|
|
79
|
-
interval: number;
|
|
80
|
-
timeout: number;
|
|
81
|
-
};
|
|
82
|
-
export type TimerState = {
|
|
83
|
-
active: boolean;
|
|
84
|
-
callback: () => void;
|
|
85
|
-
destroyed: boolean;
|
|
86
|
-
elapsed: number;
|
|
87
|
-
frame: number | undefined;
|
|
88
|
-
index: number;
|
|
89
|
-
paused: boolean;
|
|
90
|
-
total: number;
|
|
91
|
-
trace: string | undefined;
|
|
92
|
-
};
|
|
93
|
-
export type TimerType = "repeat" | "wait" | "when";
|
|
94
|
-
/**
|
|
95
|
-
* Options for a conditional timer
|
|
96
|
-
*/
|
|
97
|
-
export type WhenOptions = {
|
|
98
|
-
/**
|
|
99
|
-
* How many times the timer should check the condition
|
|
100
|
-
*/
|
|
101
|
-
count: number;
|
|
102
|
-
/**
|
|
103
|
-
* Then interval between each condtional check
|
|
104
|
-
*/
|
|
105
|
-
interval: number;
|
|
106
|
-
/**
|
|
107
|
-
* The timeout for the timer _(any value above `0` will enable the timeout)_
|
|
108
|
-
*/
|
|
109
|
-
timeout: number;
|
|
110
|
-
};
|
|
111
|
-
export declare class When {
|
|
112
|
-
private readonly $timer;
|
|
113
|
-
private readonly state;
|
|
114
|
-
/**
|
|
115
|
-
* Is the timer active?
|
|
116
|
-
*/
|
|
117
|
-
get active(): boolean;
|
|
118
|
-
/**
|
|
119
|
-
* Is the timer destroyed?
|
|
120
|
-
*/
|
|
121
|
-
get destroyed(): boolean;
|
|
122
|
-
/**
|
|
123
|
-
* Is the timer paused?
|
|
124
|
-
*/
|
|
125
|
-
get paused(): boolean;
|
|
126
|
-
/**
|
|
127
|
-
* Get the timer's origin _(if debugging is enabled)_
|
|
128
|
-
*/
|
|
129
|
-
get trace(): string | undefined;
|
|
130
|
-
constructor(condition: () => boolean, options?: Partial<WhenOptions>);
|
|
131
|
-
/**
|
|
132
|
-
* Continues the timer _(if it was paused)_
|
|
133
|
-
*/
|
|
134
|
-
continue(): When;
|
|
135
|
-
/**
|
|
136
|
-
* Destroys the timer _(and stops it,if it was running)_
|
|
137
|
-
*/
|
|
138
|
-
destroy(): void;
|
|
139
|
-
/**
|
|
140
|
-
* Pauses the timer _(if it was running)_
|
|
141
|
-
*/
|
|
142
|
-
pause(): When;
|
|
143
|
-
/**
|
|
144
|
-
* Stops the timer _(if it was running)_
|
|
145
|
-
*/
|
|
146
|
-
stop(): When;
|
|
147
|
-
/**
|
|
148
|
-
* Starts the timer and returns a promise that resolves when the condition is met
|
|
149
|
-
*/
|
|
150
|
-
then(resolve?: (() => void) | null, reject?: (() => void) | null): Promise<void>;
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* Create a conditional timer
|
|
154
|
-
*/
|
|
155
|
-
export declare function when(condition: () => boolean, options?: Partial<WhenOptions>): When;
|
|
156
|
-
/**
|
|
157
|
-
* Create a waiting timer
|
|
158
|
-
* @param callback Callback to run when the timer has finished
|
|
159
|
-
* @param time How long to wait for _(in milliseconds; defaults to screen refresh rate)_
|
|
160
|
-
*/
|
|
161
|
-
export declare function wait(callback: () => void, time?: number): Timer;
|
|
162
|
-
/**
|
|
163
|
-
* Create a repeating timer
|
|
164
|
-
*/
|
|
165
|
-
export declare function repeat(callback: (index: number) => void, options?: Partial<RepeatOptions>): Timer;
|
|
166
|
-
/**
|
|
167
|
-
* Is the value a repeating timer?
|
|
168
|
-
*/
|
|
169
|
-
export declare function isRepeated(value: unknown): value is Timer;
|
|
170
|
-
/**
|
|
171
|
-
* Is the value a timer?
|
|
172
|
-
*/
|
|
173
|
-
export declare function isTimer(value: unknown): value is Timer;
|
|
174
|
-
/**
|
|
175
|
-
* Is the value a waiting timer?
|
|
176
|
-
*/
|
|
177
|
-
export declare function isWaited(value: unknown): value is Timer;
|
|
178
|
-
/**
|
|
179
|
-
* Is the value a conditional timer?
|
|
180
|
-
*/
|
|
181
|
-
export declare function isWhen(value: unknown): value is When;
|
|
182
|
-
/**
|
|
183
|
-
* Create a delayed promise that resolves after a certain amount of time _(in milliseconds; defaults to screen refresh rate)_
|
|
184
|
-
*/
|
|
185
|
-
export declare function delay(time?: number): Promise<void>;
|
|
186
|
-
|
|
187
|
-
export {};
|
package/types/is.d.cts
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
// Generated by dts-bundle-generator v9.5.1
|
|
2
|
-
|
|
3
|
-
declare class Timer {
|
|
4
|
-
#private;
|
|
5
|
-
protected readonly options: TimerOptions;
|
|
6
|
-
private readonly $timer;
|
|
7
|
-
protected readonly state: TimerState;
|
|
8
|
-
/**
|
|
9
|
-
* Is the timer active?
|
|
10
|
-
*/
|
|
11
|
-
get active(): boolean;
|
|
12
|
-
/**
|
|
13
|
-
* Is the timer destroyed?
|
|
14
|
-
*/
|
|
15
|
-
get destroyed(): boolean;
|
|
16
|
-
/**
|
|
17
|
-
* Is the timer paused?
|
|
18
|
-
*/
|
|
19
|
-
get paused(): boolean;
|
|
20
|
-
/**
|
|
21
|
-
* Get the timer's origin _(if debugging is enabled)_
|
|
22
|
-
*/
|
|
23
|
-
get trace(): string | undefined;
|
|
24
|
-
constructor(type: TimerType, state: Pick<TimerState, "callback" | "trace">, options: TimerOptions, start: boolean);
|
|
25
|
-
/**
|
|
26
|
-
* Continue running the timer _(if it's paused)_
|
|
27
|
-
*/
|
|
28
|
-
continue(): Timer;
|
|
29
|
-
/**
|
|
30
|
-
* Destroy the timer
|
|
31
|
-
*/
|
|
32
|
-
destroy(): void;
|
|
33
|
-
/**
|
|
34
|
-
* Pause the timer _(if it's running)_
|
|
35
|
-
*/
|
|
36
|
-
pause(): Timer;
|
|
37
|
-
/**
|
|
38
|
-
* Restart the timer _(or start it, if it's not running)_
|
|
39
|
-
*/
|
|
40
|
-
restart(): Timer;
|
|
41
|
-
/**
|
|
42
|
-
* Start the timer _(if it's not running)_
|
|
43
|
-
*/
|
|
44
|
-
start(): Timer;
|
|
45
|
-
/**
|
|
46
|
-
* Stop the timer _(if it's running)_
|
|
47
|
-
*/
|
|
48
|
-
stop(): Timer;
|
|
49
|
-
}
|
|
50
|
-
export type TimerOptions = {
|
|
51
|
-
onAfter: ((finished: boolean) => void) | undefined;
|
|
52
|
-
onError: (() => void) | undefined;
|
|
53
|
-
count: number;
|
|
54
|
-
interval: number;
|
|
55
|
-
timeout: number;
|
|
56
|
-
};
|
|
57
|
-
export type TimerState = {
|
|
58
|
-
active: boolean;
|
|
59
|
-
callback: () => void;
|
|
60
|
-
destroyed: boolean;
|
|
61
|
-
elapsed: number;
|
|
62
|
-
frame: number | undefined;
|
|
63
|
-
index: number;
|
|
64
|
-
paused: boolean;
|
|
65
|
-
total: number;
|
|
66
|
-
trace: string | undefined;
|
|
67
|
-
};
|
|
68
|
-
export type TimerType = "repeat" | "wait" | "when";
|
|
69
|
-
/**
|
|
70
|
-
* Options for a conditional timer
|
|
71
|
-
*/
|
|
72
|
-
export type WhenOptions = {
|
|
73
|
-
/**
|
|
74
|
-
* How many times the timer should check the condition
|
|
75
|
-
*/
|
|
76
|
-
count: number;
|
|
77
|
-
/**
|
|
78
|
-
* Then interval between each condtional check
|
|
79
|
-
*/
|
|
80
|
-
interval: number;
|
|
81
|
-
/**
|
|
82
|
-
* The timeout for the timer _(any value above `0` will enable the timeout)_
|
|
83
|
-
*/
|
|
84
|
-
timeout: number;
|
|
85
|
-
};
|
|
86
|
-
declare class When {
|
|
87
|
-
private readonly $timer;
|
|
88
|
-
private readonly state;
|
|
89
|
-
/**
|
|
90
|
-
* Is the timer active?
|
|
91
|
-
*/
|
|
92
|
-
get active(): boolean;
|
|
93
|
-
/**
|
|
94
|
-
* Is the timer destroyed?
|
|
95
|
-
*/
|
|
96
|
-
get destroyed(): boolean;
|
|
97
|
-
/**
|
|
98
|
-
* Is the timer paused?
|
|
99
|
-
*/
|
|
100
|
-
get paused(): boolean;
|
|
101
|
-
/**
|
|
102
|
-
* Get the timer's origin _(if debugging is enabled)_
|
|
103
|
-
*/
|
|
104
|
-
get trace(): string | undefined;
|
|
105
|
-
constructor(condition: () => boolean, options?: Partial<WhenOptions>);
|
|
106
|
-
/**
|
|
107
|
-
* Continues the timer _(if it was paused)_
|
|
108
|
-
*/
|
|
109
|
-
continue(): When;
|
|
110
|
-
/**
|
|
111
|
-
* Destroys the timer _(and stops it,if it was running)_
|
|
112
|
-
*/
|
|
113
|
-
destroy(): void;
|
|
114
|
-
/**
|
|
115
|
-
* Pauses the timer _(if it was running)_
|
|
116
|
-
*/
|
|
117
|
-
pause(): When;
|
|
118
|
-
/**
|
|
119
|
-
* Stops the timer _(if it was running)_
|
|
120
|
-
*/
|
|
121
|
-
stop(): When;
|
|
122
|
-
/**
|
|
123
|
-
* Starts the timer and returns a promise that resolves when the condition is met
|
|
124
|
-
*/
|
|
125
|
-
then(resolve?: (() => void) | null, reject?: (() => void) | null): Promise<void>;
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Is the value a repeating timer?
|
|
129
|
-
*/
|
|
130
|
-
export declare function isRepeated(value: unknown): value is Timer;
|
|
131
|
-
/**
|
|
132
|
-
* Is the value a timer?
|
|
133
|
-
*/
|
|
134
|
-
export declare function isTimer(value: unknown): value is Timer;
|
|
135
|
-
/**
|
|
136
|
-
* Is the value a waiting timer?
|
|
137
|
-
*/
|
|
138
|
-
export declare function isWaited(value: unknown): value is Timer;
|
|
139
|
-
/**
|
|
140
|
-
* Is the value a conditional timer?
|
|
141
|
-
*/
|
|
142
|
-
export declare function isWhen(value: unknown): value is When;
|
|
143
|
-
|
|
144
|
-
export {};
|
package/types/models.d.cts
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
// Generated by dts-bundle-generator v9.5.1
|
|
2
|
-
|
|
3
|
-
declare class Timer {
|
|
4
|
-
#private;
|
|
5
|
-
protected readonly options: TimerOptions;
|
|
6
|
-
private readonly $timer;
|
|
7
|
-
protected readonly state: TimerState;
|
|
8
|
-
/**
|
|
9
|
-
* Is the timer active?
|
|
10
|
-
*/
|
|
11
|
-
get active(): boolean;
|
|
12
|
-
/**
|
|
13
|
-
* Is the timer destroyed?
|
|
14
|
-
*/
|
|
15
|
-
get destroyed(): boolean;
|
|
16
|
-
/**
|
|
17
|
-
* Is the timer paused?
|
|
18
|
-
*/
|
|
19
|
-
get paused(): boolean;
|
|
20
|
-
/**
|
|
21
|
-
* Get the timer's origin _(if debugging is enabled)_
|
|
22
|
-
*/
|
|
23
|
-
get trace(): string | undefined;
|
|
24
|
-
constructor(type: TimerType, state: Pick<TimerState, "callback" | "trace">, options: TimerOptions, start: boolean);
|
|
25
|
-
/**
|
|
26
|
-
* Continue running the timer _(if it's paused)_
|
|
27
|
-
*/
|
|
28
|
-
continue(): Timer;
|
|
29
|
-
/**
|
|
30
|
-
* Destroy the timer
|
|
31
|
-
*/
|
|
32
|
-
destroy(): void;
|
|
33
|
-
/**
|
|
34
|
-
* Pause the timer _(if it's running)_
|
|
35
|
-
*/
|
|
36
|
-
pause(): Timer;
|
|
37
|
-
/**
|
|
38
|
-
* Restart the timer _(or start it, if it's not running)_
|
|
39
|
-
*/
|
|
40
|
-
restart(): Timer;
|
|
41
|
-
/**
|
|
42
|
-
* Start the timer _(if it's not running)_
|
|
43
|
-
*/
|
|
44
|
-
start(): Timer;
|
|
45
|
-
/**
|
|
46
|
-
* Stop the timer _(if it's running)_
|
|
47
|
-
*/
|
|
48
|
-
stop(): Timer;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Options for a repeating timer
|
|
52
|
-
*/
|
|
53
|
-
export type RepeatOptions = {
|
|
54
|
-
/**
|
|
55
|
-
* Callback to be called when the timer has stopped, either manually or by completing its work
|
|
56
|
-
*/
|
|
57
|
-
onAfter: (finished: boolean) => void;
|
|
58
|
-
/**
|
|
59
|
-
* Callback to be called after the timer has timed out
|
|
60
|
-
*/
|
|
61
|
-
onTimeout: () => void;
|
|
62
|
-
/**
|
|
63
|
-
* How many times the timer should repeat
|
|
64
|
-
*/
|
|
65
|
-
count: number;
|
|
66
|
-
/**
|
|
67
|
-
* The interval between each repeat
|
|
68
|
-
*/
|
|
69
|
-
interval: number;
|
|
70
|
-
/**
|
|
71
|
-
* The timeout for the timer _(any value above `0` will enable the timeout)_
|
|
72
|
-
*/
|
|
73
|
-
timeout: number;
|
|
74
|
-
};
|
|
75
|
-
export type TimerOptions = {
|
|
76
|
-
onAfter: ((finished: boolean) => void) | undefined;
|
|
77
|
-
onError: (() => void) | undefined;
|
|
78
|
-
count: number;
|
|
79
|
-
interval: number;
|
|
80
|
-
timeout: number;
|
|
81
|
-
};
|
|
82
|
-
export type TimerState = {
|
|
83
|
-
active: boolean;
|
|
84
|
-
callback: () => void;
|
|
85
|
-
destroyed: boolean;
|
|
86
|
-
elapsed: number;
|
|
87
|
-
frame: number | undefined;
|
|
88
|
-
index: number;
|
|
89
|
-
paused: boolean;
|
|
90
|
-
total: number;
|
|
91
|
-
trace: string | undefined;
|
|
92
|
-
};
|
|
93
|
-
export declare class TimerTrace extends Error {
|
|
94
|
-
constructor();
|
|
95
|
-
}
|
|
96
|
-
export type TimerType = "repeat" | "wait" | "when";
|
|
97
|
-
/**
|
|
98
|
-
* Options for a conditional timer
|
|
99
|
-
*/
|
|
100
|
-
export type WhenOptions = {
|
|
101
|
-
/**
|
|
102
|
-
* How many times the timer should check the condition
|
|
103
|
-
*/
|
|
104
|
-
count: number;
|
|
105
|
-
/**
|
|
106
|
-
* Then interval between each condtional check
|
|
107
|
-
*/
|
|
108
|
-
interval: number;
|
|
109
|
-
/**
|
|
110
|
-
* The timeout for the timer _(any value above `0` will enable the timeout)_
|
|
111
|
-
*/
|
|
112
|
-
timeout: number;
|
|
113
|
-
};
|
|
114
|
-
export type WhenState = {
|
|
115
|
-
promise: Promise<void>;
|
|
116
|
-
rejecter?: () => void;
|
|
117
|
-
resolver?: () => void;
|
|
118
|
-
started: boolean;
|
|
119
|
-
timer: Timer;
|
|
120
|
-
};
|
|
121
|
-
export type WorkHandler = (type: WorkHandlerType, timer: WorkHandlerTimer, state: TimerState, options: TimerOptions) => Timer;
|
|
122
|
-
export type WorkHandlerTimer = {
|
|
123
|
-
instance: Timer;
|
|
124
|
-
type: TimerType;
|
|
125
|
-
};
|
|
126
|
-
export type WorkHandlerType = "continue" | "pause" | "restart" | "start" | "stop";
|
|
127
|
-
|
|
128
|
-
export {};
|