@oscarpalmer/timer 0.37.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 +4 -4
- package/dist/index.js +4 -4
- 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 +5 -5
- package/package.json +16 -19
- package/src/constants.ts +20 -14
- package/src/delay.ts +6 -7
- package/src/get.ts +3 -5
- package/src/global.ts +4 -9
- package/src/is.ts +8 -0
- 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/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 -17
- package/dist/global.cjs +0 -15
- 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 -68
- package/dist/timer.full.js +0 -532
- package/dist/wait.cjs +0 -18
- package/dist/when.cjs +0 -96
- package/dist/work.cjs +0 -82
package/src/work.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
TIMERS_ACTIVE,
|
|
3
|
+
BUFFER_INTERVAL,
|
|
4
|
+
MILLISECONDS,
|
|
5
5
|
TYPE_WAIT,
|
|
6
6
|
WORK_CONTINUE,
|
|
7
7
|
WORK_PAUSE,
|
|
@@ -9,12 +9,7 @@ import {
|
|
|
9
9
|
WORK_START,
|
|
10
10
|
WORK_STOP,
|
|
11
11
|
} from './constants';
|
|
12
|
-
import type {
|
|
13
|
-
TimerOptions,
|
|
14
|
-
TimerState,
|
|
15
|
-
WorkHandlerTimer,
|
|
16
|
-
WorkHandlerType,
|
|
17
|
-
} from './models';
|
|
12
|
+
import type {TimerOptions, TimerState, WorkHandlerTimer, WorkHandlerType} from './models';
|
|
18
13
|
import type {Timer} from './timer';
|
|
19
14
|
|
|
20
15
|
function finish(
|
|
@@ -25,7 +20,7 @@ function finish(
|
|
|
25
20
|
): void {
|
|
26
21
|
cancelAnimationFrame(state.frame as never);
|
|
27
22
|
|
|
28
|
-
|
|
23
|
+
TIMERS_ACTIVE.delete(timer.instance);
|
|
29
24
|
|
|
30
25
|
state.active = false;
|
|
31
26
|
state.elapsed = 0;
|
|
@@ -89,10 +84,7 @@ function run(
|
|
|
89
84
|
return;
|
|
90
85
|
}
|
|
91
86
|
|
|
92
|
-
if (
|
|
93
|
-
options.interval === milliseconds ||
|
|
94
|
-
state.elapsed >= options.interval - intervalBuffer
|
|
95
|
-
) {
|
|
87
|
+
if (options.interval === MILLISECONDS || state.elapsed >= options.interval - BUFFER_INTERVAL) {
|
|
96
88
|
if (options.count > -1) {
|
|
97
89
|
(state.callback as (index: number) => void)(state.index);
|
|
98
90
|
}
|
|
@@ -102,10 +94,7 @@ function run(
|
|
|
102
94
|
state.elapsed = 0;
|
|
103
95
|
state.index += 1;
|
|
104
96
|
|
|
105
|
-
if (
|
|
106
|
-
options.count === -1 ||
|
|
107
|
-
(options.count > 0 && state.index >= options.count)
|
|
108
|
-
) {
|
|
97
|
+
if (options.count === -1 || (options.count > 0 && state.index >= options.count)) {
|
|
109
98
|
finish(timer, state, options, true);
|
|
110
99
|
|
|
111
100
|
return;
|
|
@@ -124,23 +113,19 @@ function setState(type: WorkHandlerType, state: TimerState): void {
|
|
|
124
113
|
state.total = pausable ? state.total : 0;
|
|
125
114
|
}
|
|
126
115
|
|
|
127
|
-
export function stop(
|
|
128
|
-
|
|
129
|
-
state: TimerState,
|
|
130
|
-
options: TimerOptions,
|
|
131
|
-
): Timer {
|
|
132
|
-
cancelAnimationFrame(state.frame as never);
|
|
116
|
+
export function stop(timer: WorkHandlerTimer, state: TimerState, options: TimerOptions): Timer {
|
|
117
|
+
cancelAnimationFrame(state.frame as never);
|
|
133
118
|
|
|
134
|
-
|
|
119
|
+
TIMERS_ACTIVE.delete(timer.instance);
|
|
135
120
|
|
|
136
|
-
|
|
121
|
+
options.onAfter?.(false);
|
|
137
122
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
123
|
+
state.active = !stop;
|
|
124
|
+
state.frame = undefined;
|
|
125
|
+
state.paused = false;
|
|
141
126
|
|
|
142
|
-
|
|
143
|
-
|
|
127
|
+
return timer.instance;
|
|
128
|
+
}
|
|
144
129
|
|
|
145
130
|
export function work(
|
|
146
131
|
type: WorkHandlerType,
|
|
@@ -171,7 +156,7 @@ export function work(
|
|
|
171
156
|
return pause(timer, state);
|
|
172
157
|
}
|
|
173
158
|
|
|
174
|
-
|
|
159
|
+
TIMERS_ACTIVE.add(timer.instance);
|
|
175
160
|
|
|
176
161
|
const runner = run(timer, state, options);
|
|
177
162
|
|
package/types/constants.d.ts
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
import type { TimerType, WorkHandlerType } from './models';
|
|
2
2
|
import type { Timer } from './timer';
|
|
3
|
-
export declare const defaultTimeout = 30000;
|
|
4
|
-
/**
|
|
5
|
-
* A set of all active timers
|
|
6
|
-
*/
|
|
7
|
-
export declare const activeTimers: Set<Timer>;
|
|
8
3
|
/**
|
|
9
4
|
* Buffer value to use when evaluating if a specific time is within a certain range
|
|
10
5
|
*/
|
|
11
|
-
export declare const
|
|
6
|
+
export declare const BUFFER_INTERVAL = 5;
|
|
7
|
+
export declare const DEFAULT_TIMEOUT = 30000;
|
|
12
8
|
/**
|
|
13
9
|
* Message to show when a when-timer is destroyed
|
|
14
10
|
*/
|
|
15
|
-
export declare const
|
|
11
|
+
export declare const MESSAGE_DESTROYED = "Timer has already been destroyed";
|
|
16
12
|
/**
|
|
17
|
-
*
|
|
13
|
+
* Message to show when a when-timer is started
|
|
18
14
|
*/
|
|
19
|
-
export declare const
|
|
15
|
+
export declare const MESSAGE_STARTED = "Timer has already been started";
|
|
20
16
|
/**
|
|
21
|
-
*
|
|
17
|
+
* A set of all active timers
|
|
18
|
+
*/
|
|
19
|
+
export declare const TIMERS_ACTIVE: Set<Timer>;
|
|
20
|
+
/**
|
|
21
|
+
* A set of timers that were paused due to the document being hidden
|
|
22
22
|
*/
|
|
23
|
-
export declare const
|
|
23
|
+
export declare const TIMERS_HIDDEN: Set<Timer>;
|
|
24
24
|
export declare const TYPE_REPEAT: TimerType;
|
|
25
25
|
export declare const TYPE_WAIT: TimerType;
|
|
26
26
|
export declare const TYPE_WHEN: TimerType;
|
|
@@ -32,4 +32,4 @@ export declare const WORK_STOP: WorkHandlerType;
|
|
|
32
32
|
/**
|
|
33
33
|
* A calculated average of the refresh rate of the display _(in milliseconds)_
|
|
34
34
|
*/
|
|
35
|
-
export declare let
|
|
35
|
+
export declare let MILLISECONDS: number;
|
package/types/delay.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Create a delayed promise that resolves after a certain amount of time
|
|
2
|
+
* Create a delayed promise that resolves after a certain amount of time
|
|
3
|
+
* @param time How long to wait for _(in milliseconds; defaults to screen refresh rate)_
|
|
4
|
+
* @returns A promise that resolves after the delay
|
|
3
5
|
*/
|
|
4
6
|
export declare function delay(time?: number): Promise<void>;
|
package/types/is.d.ts
CHANGED
|
@@ -2,17 +2,25 @@ import type { Timer } from './timer';
|
|
|
2
2
|
import type { When } from './when';
|
|
3
3
|
/**
|
|
4
4
|
* Is the value a repeating timer?
|
|
5
|
+
* @param value Value to check
|
|
6
|
+
* @returns `true` if the value is a repeating timer
|
|
5
7
|
*/
|
|
6
8
|
export declare function isRepeated(value: unknown): value is Timer;
|
|
7
9
|
/**
|
|
8
10
|
* Is the value a timer?
|
|
11
|
+
* @param value Value to check
|
|
12
|
+
* @returns `true` if the value is a timer
|
|
9
13
|
*/
|
|
10
14
|
export declare function isTimer(value: unknown): value is Timer;
|
|
11
15
|
/**
|
|
12
16
|
* Is the value a waiting timer?
|
|
17
|
+
* @param value Value to check
|
|
18
|
+
* @returns `true` if the value is a waiting timer
|
|
13
19
|
*/
|
|
14
20
|
export declare function isWaited(value: unknown): value is Timer;
|
|
15
21
|
/**
|
|
16
22
|
* Is the value a conditional timer?
|
|
23
|
+
* @param value Value to check
|
|
24
|
+
* @returns `true` if the value is a conditional timer
|
|
17
25
|
*/
|
|
18
26
|
export declare function isWhen(value: unknown): value is When;
|
package/types/repeat.d.ts
CHANGED
|
@@ -3,6 +3,9 @@ import { type RepeatOptions } from './models';
|
|
|
3
3
|
import { Timer } from './timer';
|
|
4
4
|
/**
|
|
5
5
|
* Create a repeating timer
|
|
6
|
+
* @param callback Callback to run on each interval
|
|
7
|
+
* @param options Timer options
|
|
8
|
+
* @returns Timer instance
|
|
6
9
|
*/
|
|
7
10
|
export declare function repeat(callback: (index: number) => void, options?: Partial<RepeatOptions>): Timer;
|
|
8
11
|
export type { RepeatOptions, Timer };
|
package/types/when.d.ts
CHANGED
|
@@ -32,17 +32,31 @@ declare class When {
|
|
|
32
32
|
* Pauses the timer _(if it was running)_
|
|
33
33
|
*/
|
|
34
34
|
pause(): When;
|
|
35
|
+
/**
|
|
36
|
+
* Start the timer
|
|
37
|
+
* @param resolve Optional resolve callback
|
|
38
|
+
* @param reject Optional reject callback
|
|
39
|
+
* @returns Promise that resolves when the condition is met
|
|
40
|
+
*/
|
|
41
|
+
start(resolve?: (() => void) | null, reject?: (() => void) | null): Promise<void>;
|
|
35
42
|
/**
|
|
36
43
|
* Stops the timer _(if it was running)_
|
|
37
44
|
*/
|
|
38
45
|
stop(): When;
|
|
39
46
|
/**
|
|
40
|
-
*
|
|
47
|
+
* Start the timer
|
|
48
|
+
* @deprecated Use `start()` instead
|
|
49
|
+
* @param resolve Optional resolve callback
|
|
50
|
+
* @param reject Optional reject callback
|
|
51
|
+
* @returns Promise that resolves when the condition is met
|
|
41
52
|
*/
|
|
42
53
|
then(resolve?: (() => void) | null, reject?: (() => void) | null): Promise<void>;
|
|
43
54
|
}
|
|
44
55
|
/**
|
|
45
56
|
* Create a conditional timer
|
|
57
|
+
* @param condition Condition to check
|
|
58
|
+
* @param options Timer options
|
|
59
|
+
* @returns Timer instance
|
|
46
60
|
*/
|
|
47
61
|
export declare function when(condition: () => boolean, options?: Partial<WhenOptions>): When;
|
|
48
62
|
export type { When };
|
package/dist/constants.cjs
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
function calculate() {
|
|
2
|
-
return new Promise((resolve) => {
|
|
3
|
-
const values = [];
|
|
4
|
-
let last;
|
|
5
|
-
function step(now) {
|
|
6
|
-
if (last != null) values.push(now - last);
|
|
7
|
-
last = now;
|
|
8
|
-
if (values.length >= 10) {
|
|
9
|
-
const median = values.sort().slice(2, -2).reduce((first, second) => first + second, 0) / (values.length - 4);
|
|
10
|
-
resolve(median);
|
|
11
|
-
} else requestAnimationFrame(step);
|
|
12
|
-
}
|
|
13
|
-
requestAnimationFrame(step);
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
const defaultTimeout = 3e4;
|
|
17
|
-
const activeTimers = /* @__PURE__ */ new Set();
|
|
18
|
-
const intervalBuffer = 5;
|
|
19
|
-
const destroyedMessage = "Timer has already been destroyed";
|
|
20
|
-
const hiddenTimers = /* @__PURE__ */ new Set();
|
|
21
|
-
const startedMessage = "Timer has already been started";
|
|
22
|
-
const TYPE_REPEAT = "repeat";
|
|
23
|
-
const TYPE_WAIT = "wait";
|
|
24
|
-
const TYPE_WHEN = "when";
|
|
25
|
-
const WORK_CONTINUE = "continue";
|
|
26
|
-
const WORK_PAUSE = "pause";
|
|
27
|
-
const WORK_RESTART = "restart";
|
|
28
|
-
const WORK_START = "start";
|
|
29
|
-
const WORK_STOP = "stop";
|
|
30
|
-
let milliseconds = 1e3 / 60;
|
|
31
|
-
calculate().then((value) => {
|
|
32
|
-
milliseconds = value;
|
|
33
|
-
});
|
|
34
|
-
exports.TYPE_REPEAT = TYPE_REPEAT;
|
|
35
|
-
exports.TYPE_WAIT = TYPE_WAIT;
|
|
36
|
-
exports.TYPE_WHEN = TYPE_WHEN;
|
|
37
|
-
exports.WORK_CONTINUE = WORK_CONTINUE;
|
|
38
|
-
exports.WORK_PAUSE = WORK_PAUSE;
|
|
39
|
-
exports.WORK_RESTART = WORK_RESTART;
|
|
40
|
-
exports.WORK_START = WORK_START;
|
|
41
|
-
exports.WORK_STOP = WORK_STOP;
|
|
42
|
-
exports.activeTimers = activeTimers;
|
|
43
|
-
exports.defaultTimeout = defaultTimeout;
|
|
44
|
-
exports.destroyedMessage = destroyedMessage;
|
|
45
|
-
exports.hiddenTimers = hiddenTimers;
|
|
46
|
-
exports.intervalBuffer = intervalBuffer;
|
|
47
|
-
Object.defineProperty(exports, "milliseconds", {
|
|
48
|
-
enumerable: true,
|
|
49
|
-
get: function() {
|
|
50
|
-
return milliseconds;
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
exports.startedMessage = startedMessage;
|
package/dist/delay.cjs
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
const require_constants = require("./constants.cjs");
|
|
2
|
-
const require_get = require("./get.cjs");
|
|
3
|
-
function delay(time) {
|
|
4
|
-
return new Promise((resolve) => {
|
|
5
|
-
const interval = require_get.getValidNumber(time, require_constants.milliseconds);
|
|
6
|
-
let start;
|
|
7
|
-
function step(now) {
|
|
8
|
-
start ??= now;
|
|
9
|
-
if (interval === require_constants.milliseconds || now - start >= interval - 5) resolve();
|
|
10
|
-
else requestAnimationFrame(step);
|
|
11
|
-
}
|
|
12
|
-
requestAnimationFrame(step);
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
exports.delay = delay;
|
package/dist/get.cjs
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
const require_rolldown_runtime = require("./rolldown_runtime.cjs");
|
|
2
|
-
const require_constants = require("./constants.cjs");
|
|
3
|
-
let __oscarpalmer_atoms_function = require("@oscarpalmer/atoms/function");
|
|
4
|
-
__oscarpalmer_atoms_function = require_rolldown_runtime.__toESM(__oscarpalmer_atoms_function);
|
|
5
|
-
function getCallback(value) {
|
|
6
|
-
return typeof value === "function" ? value : __oscarpalmer_atoms_function.noop;
|
|
7
|
-
}
|
|
8
|
-
function getValidTimeout(value) {
|
|
9
|
-
return typeof value === "number" && value > 0 ? value : require_constants.defaultTimeout;
|
|
10
|
-
}
|
|
11
|
-
function getValidNumber(value, defaultValue) {
|
|
12
|
-
const actualDefault = defaultValue ?? 0;
|
|
13
|
-
return typeof value === "number" && value > actualDefault ? value : actualDefault;
|
|
14
|
-
}
|
|
15
|
-
exports.getCallback = getCallback;
|
|
16
|
-
exports.getValidNumber = getValidNumber;
|
|
17
|
-
exports.getValidTimeout = getValidTimeout;
|
package/dist/global.cjs
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
const require_constants = require("./constants.cjs");
|
|
2
|
-
if (globalThis._oscarpalmer_timers == null) Object.defineProperty(globalThis, "_oscarpalmer_timers", { get() {
|
|
3
|
-
return globalThis._oscarpalmer_timer_debug ? [...require_constants.activeTimers] : [];
|
|
4
|
-
} });
|
|
5
|
-
/* istanbul ignore next */
|
|
6
|
-
document.addEventListener("visibilitychange", () => {
|
|
7
|
-
const from = document.hidden ? require_constants.activeTimers : require_constants.hiddenTimers;
|
|
8
|
-
const method = document.hidden ? require_constants.WORK_PAUSE : require_constants.WORK_CONTINUE;
|
|
9
|
-
const to = document.hidden ? require_constants.hiddenTimers : require_constants.activeTimers;
|
|
10
|
-
for (const timer of from) {
|
|
11
|
-
timer[method]();
|
|
12
|
-
to.add(timer);
|
|
13
|
-
}
|
|
14
|
-
from.clear();
|
|
15
|
-
});
|
package/dist/index.cjs
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
require("./global.cjs");
|
|
2
|
-
const require_when = require("./when.cjs");
|
|
3
|
-
const require_wait = require("./wait.cjs");
|
|
4
|
-
const require_repeat = require("./repeat.cjs");
|
|
5
|
-
const require_is = require("./is.cjs");
|
|
6
|
-
const require_delay = require("./delay.cjs");
|
|
7
|
-
exports.delay = require_delay.delay;
|
|
8
|
-
exports.isRepeated = require_is.isRepeated;
|
|
9
|
-
exports.isTimer = require_is.isTimer;
|
|
10
|
-
exports.isWaited = require_is.isWaited;
|
|
11
|
-
exports.isWhen = require_is.isWhen;
|
|
12
|
-
exports.repeat = require_repeat.repeat;
|
|
13
|
-
exports.wait = require_wait.wait;
|
|
14
|
-
exports.when = require_when.when;
|
package/dist/is.cjs
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
const require_constants = require("./constants.cjs");
|
|
2
|
-
function is(names, value) {
|
|
3
|
-
return names.includes(value?.$timer);
|
|
4
|
-
}
|
|
5
|
-
function isRepeated(value) {
|
|
6
|
-
return is([require_constants.TYPE_REPEAT], value);
|
|
7
|
-
}
|
|
8
|
-
function isTimer(value) {
|
|
9
|
-
return is([require_constants.TYPE_REPEAT, require_constants.TYPE_WAIT], value);
|
|
10
|
-
}
|
|
11
|
-
function isWaited(value) {
|
|
12
|
-
return is([require_constants.TYPE_WAIT], value);
|
|
13
|
-
}
|
|
14
|
-
function isWhen(value) {
|
|
15
|
-
return is(["when"], value) && typeof value.then === "function";
|
|
16
|
-
}
|
|
17
|
-
exports.isRepeated = isRepeated;
|
|
18
|
-
exports.isTimer = isTimer;
|
|
19
|
-
exports.isWaited = isWaited;
|
|
20
|
-
exports.isWhen = isWhen;
|
package/dist/models.cjs
DELETED
package/dist/repeat.cjs
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
const require_constants = require("./constants.cjs");
|
|
2
|
-
const require_get = require("./get.cjs");
|
|
3
|
-
require("./global.cjs");
|
|
4
|
-
const require_models = require("./models.cjs");
|
|
5
|
-
const require_timer = require("./timer.cjs");
|
|
6
|
-
function repeat(callback, options) {
|
|
7
|
-
return new require_timer.Timer(require_constants.TYPE_REPEAT, {
|
|
8
|
-
callback: require_get.getCallback(callback),
|
|
9
|
-
trace: new require_models.TimerTrace().stack
|
|
10
|
-
}, {
|
|
11
|
-
onAfter: require_get.getCallback(options?.onAfter),
|
|
12
|
-
onError: require_get.getCallback(options?.onTimeout),
|
|
13
|
-
count: require_get.getValidNumber(options?.count),
|
|
14
|
-
interval: require_get.getValidNumber(options?.interval, require_constants.milliseconds),
|
|
15
|
-
timeout: require_get.getValidNumber(options?.timeout)
|
|
16
|
-
}, true);
|
|
17
|
-
}
|
|
18
|
-
exports.repeat = repeat;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __copyProps = (to, from, except, desc) => {
|
|
8
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
9
|
-
key = keys[i];
|
|
10
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
11
|
-
get: ((k) => from[k]).bind(null, key),
|
|
12
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
18
|
-
value: mod,
|
|
19
|
-
enumerable: true
|
|
20
|
-
}) : target, mod));
|
|
21
|
-
exports.__toESM = __toESM;
|
package/dist/timer.cjs
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
const require_rolldown_runtime = require("./rolldown_runtime.cjs");
|
|
2
|
-
const require_constants = require("./constants.cjs");
|
|
3
|
-
const require_work = require("./work.cjs");
|
|
4
|
-
let __oscarpalmer_atoms_function = require("@oscarpalmer/atoms/function");
|
|
5
|
-
__oscarpalmer_atoms_function = require_rolldown_runtime.__toESM(__oscarpalmer_atoms_function);
|
|
6
|
-
var Timer = class {
|
|
7
|
-
state;
|
|
8
|
-
get active() {
|
|
9
|
-
return this.state.active;
|
|
10
|
-
}
|
|
11
|
-
get destroyed() {
|
|
12
|
-
return this.state.destroyed;
|
|
13
|
-
}
|
|
14
|
-
get paused() {
|
|
15
|
-
return this.state.paused;
|
|
16
|
-
}
|
|
17
|
-
get trace() {
|
|
18
|
-
return globalThis._oscarpalmer_timer_debug ?? false ? this.state.trace : void 0;
|
|
19
|
-
}
|
|
20
|
-
constructor(type, state, options, start) {
|
|
21
|
-
this.options = options;
|
|
22
|
-
this.$timer = type;
|
|
23
|
-
this.state = {
|
|
24
|
-
...state,
|
|
25
|
-
active: false,
|
|
26
|
-
destroyed: false,
|
|
27
|
-
elapsed: 0,
|
|
28
|
-
frame: void 0,
|
|
29
|
-
index: 0,
|
|
30
|
-
paused: false,
|
|
31
|
-
total: 0
|
|
32
|
-
};
|
|
33
|
-
if (start) this.start();
|
|
34
|
-
}
|
|
35
|
-
continue() {
|
|
36
|
-
return this.#work(require_constants.WORK_CONTINUE);
|
|
37
|
-
}
|
|
38
|
-
destroy() {
|
|
39
|
-
this.state.destroyed = true;
|
|
40
|
-
this.options.onAfter = __oscarpalmer_atoms_function.noop;
|
|
41
|
-
this.options.onError = __oscarpalmer_atoms_function.noop;
|
|
42
|
-
this.state.callback = __oscarpalmer_atoms_function.noop;
|
|
43
|
-
if (!globalThis._oscarpalmer_timer_debug) this.state.trace = void 0;
|
|
44
|
-
require_work.stop({
|
|
45
|
-
instance: this,
|
|
46
|
-
type: this.$timer
|
|
47
|
-
}, this.state, this.options);
|
|
48
|
-
}
|
|
49
|
-
pause() {
|
|
50
|
-
return this.#work(require_constants.WORK_PAUSE);
|
|
51
|
-
}
|
|
52
|
-
restart() {
|
|
53
|
-
return this.#work(require_constants.WORK_RESTART);
|
|
54
|
-
}
|
|
55
|
-
start() {
|
|
56
|
-
return this.#work(require_constants.WORK_START);
|
|
57
|
-
}
|
|
58
|
-
stop() {
|
|
59
|
-
return this.#work(require_constants.WORK_STOP);
|
|
60
|
-
}
|
|
61
|
-
#work(type) {
|
|
62
|
-
return require_work.work(type, {
|
|
63
|
-
instance: this,
|
|
64
|
-
type: this.$timer
|
|
65
|
-
}, this.state, this.options);
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
exports.Timer = Timer;
|