@oscarpalmer/timer 0.36.0 → 0.37.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/dist/delay.cjs +1 -1
- package/dist/delay.js +1 -1
- package/dist/get.cjs +2 -1
- package/dist/global.cjs +1 -0
- package/dist/global.js +1 -0
- package/dist/is.cjs +1 -1
- package/dist/is.js +1 -1
- package/dist/timer.cjs +2 -1
- package/dist/timer.full.js +3 -1
- package/dist/when.cjs +2 -1
- package/dist/work.cjs +7 -7
- package/dist/work.js +7 -7
- package/package.json +32 -54
- package/src/get.ts +1 -1
- package/src/global.ts +1 -0
- package/src/is.ts +1 -1
- package/types/get.d.ts +1 -1
- 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/delay.cjs
CHANGED
|
@@ -6,7 +6,7 @@ function delay(time) {
|
|
|
6
6
|
let start;
|
|
7
7
|
function step(now) {
|
|
8
8
|
start ??= now;
|
|
9
|
-
if (interval === require_constants.milliseconds || now - start >= interval -
|
|
9
|
+
if (interval === require_constants.milliseconds || now - start >= interval - 5) resolve();
|
|
10
10
|
else requestAnimationFrame(step);
|
|
11
11
|
}
|
|
12
12
|
requestAnimationFrame(step);
|
package/dist/delay.js
CHANGED
|
@@ -6,7 +6,7 @@ function delay(time) {
|
|
|
6
6
|
let start;
|
|
7
7
|
function step(now) {
|
|
8
8
|
start ??= now;
|
|
9
|
-
if (interval === milliseconds || now - start >= interval -
|
|
9
|
+
if (interval === milliseconds || now - start >= interval - 5) resolve();
|
|
10
10
|
else requestAnimationFrame(step);
|
|
11
11
|
}
|
|
12
12
|
requestAnimationFrame(step);
|
package/dist/get.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const require_rolldown_runtime = require("./rolldown_runtime.cjs");
|
|
2
2
|
const require_constants = require("./constants.cjs");
|
|
3
|
-
|
|
3
|
+
let __oscarpalmer_atoms_function = require("@oscarpalmer/atoms/function");
|
|
4
|
+
__oscarpalmer_atoms_function = require_rolldown_runtime.__toESM(__oscarpalmer_atoms_function);
|
|
4
5
|
function getCallback(value) {
|
|
5
6
|
return typeof value === "function" ? value : __oscarpalmer_atoms_function.noop;
|
|
6
7
|
}
|
package/dist/global.cjs
CHANGED
|
@@ -2,6 +2,7 @@ const require_constants = require("./constants.cjs");
|
|
|
2
2
|
if (globalThis._oscarpalmer_timers == null) Object.defineProperty(globalThis, "_oscarpalmer_timers", { get() {
|
|
3
3
|
return globalThis._oscarpalmer_timer_debug ? [...require_constants.activeTimers] : [];
|
|
4
4
|
} });
|
|
5
|
+
/* istanbul ignore next */
|
|
5
6
|
document.addEventListener("visibilitychange", () => {
|
|
6
7
|
const from = document.hidden ? require_constants.activeTimers : require_constants.hiddenTimers;
|
|
7
8
|
const method = document.hidden ? require_constants.WORK_PAUSE : require_constants.WORK_CONTINUE;
|
package/dist/global.js
CHANGED
|
@@ -2,6 +2,7 @@ import { WORK_CONTINUE, WORK_PAUSE, activeTimers, hiddenTimers } from "./constan
|
|
|
2
2
|
if (globalThis._oscarpalmer_timers == null) Object.defineProperty(globalThis, "_oscarpalmer_timers", { get() {
|
|
3
3
|
return globalThis._oscarpalmer_timer_debug ? [...activeTimers] : [];
|
|
4
4
|
} });
|
|
5
|
+
/* istanbul ignore next */
|
|
5
6
|
document.addEventListener("visibilitychange", () => {
|
|
6
7
|
const from = document.hidden ? activeTimers : hiddenTimers;
|
|
7
8
|
const method = document.hidden ? WORK_PAUSE : WORK_CONTINUE;
|
package/dist/is.cjs
CHANGED
|
@@ -12,7 +12,7 @@ function isWaited(value) {
|
|
|
12
12
|
return is([require_constants.TYPE_WAIT], value);
|
|
13
13
|
}
|
|
14
14
|
function isWhen(value) {
|
|
15
|
-
return is([
|
|
15
|
+
return is(["when"], value) && typeof value.then === "function";
|
|
16
16
|
}
|
|
17
17
|
exports.isRepeated = isRepeated;
|
|
18
18
|
exports.isTimer = isTimer;
|
package/dist/is.js
CHANGED
|
@@ -12,6 +12,6 @@ function isWaited(value) {
|
|
|
12
12
|
return is([TYPE_WAIT], value);
|
|
13
13
|
}
|
|
14
14
|
function isWhen(value) {
|
|
15
|
-
return is([
|
|
15
|
+
return is(["when"], value) && typeof value.then === "function";
|
|
16
16
|
}
|
|
17
17
|
export { isRepeated, isTimer, isWaited, isWhen };
|
package/dist/timer.cjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
const require_rolldown_runtime = require("./rolldown_runtime.cjs");
|
|
2
2
|
const require_constants = require("./constants.cjs");
|
|
3
3
|
const require_work = require("./work.cjs");
|
|
4
|
-
|
|
4
|
+
let __oscarpalmer_atoms_function = require("@oscarpalmer/atoms/function");
|
|
5
|
+
__oscarpalmer_atoms_function = require_rolldown_runtime.__toESM(__oscarpalmer_atoms_function);
|
|
5
6
|
var Timer = class {
|
|
6
7
|
state;
|
|
7
8
|
get active() {
|
package/dist/timer.full.js
CHANGED
|
@@ -68,6 +68,7 @@ if (globalThis._oscarpalmer_timers == null) {
|
|
|
68
68
|
},
|
|
69
69
|
});
|
|
70
70
|
}
|
|
71
|
+
/* istanbul ignore next */
|
|
71
72
|
document.addEventListener('visibilitychange', () => {
|
|
72
73
|
const from = document.hidden ? activeTimers : hiddenTimers;
|
|
73
74
|
const method = document.hidden ? WORK_PAUSE : WORK_CONTINUE;
|
|
@@ -85,7 +86,8 @@ function calculate() {
|
|
|
85
86
|
let last;
|
|
86
87
|
function step(now) {
|
|
87
88
|
if (last != null) values.push(now - last);
|
|
88
|
-
|
|
89
|
+
last = now;
|
|
90
|
+
if (values.length >= 10) {
|
|
89
91
|
const median = values.sort().slice(2, -2).reduce((first, second) => first + second, 0) / (values.length - 4);
|
|
90
92
|
resolve(median);
|
|
91
93
|
} else requestAnimationFrame(step);
|
package/dist/when.cjs
CHANGED
|
@@ -4,7 +4,8 @@ const require_get = require("./get.cjs");
|
|
|
4
4
|
require("./global.cjs");
|
|
5
5
|
const require_models = require("./models.cjs");
|
|
6
6
|
const require_timer = require("./timer.cjs");
|
|
7
|
-
|
|
7
|
+
let __oscarpalmer_atoms_function = require("@oscarpalmer/atoms/function");
|
|
8
|
+
__oscarpalmer_atoms_function = require_rolldown_runtime.__toESM(__oscarpalmer_atoms_function);
|
|
8
9
|
var When = class {
|
|
9
10
|
$timer = require_constants.TYPE_WHEN;
|
|
10
11
|
state = {
|
package/dist/work.cjs
CHANGED
|
@@ -5,13 +5,13 @@ function finish(timer, state, options, success) {
|
|
|
5
5
|
state.active = false;
|
|
6
6
|
state.elapsed = 0;
|
|
7
7
|
state.frame = void 0;
|
|
8
|
-
if (timer.type ===
|
|
8
|
+
if (timer.type === "wait") state.callback();
|
|
9
9
|
else options.onAfter?.(success);
|
|
10
10
|
}
|
|
11
11
|
function ignore(type, state) {
|
|
12
12
|
if (state.destroyed) return type !== require_constants.WORK_STOP;
|
|
13
|
-
if (state.paused) return type ===
|
|
14
|
-
return state.active && type ===
|
|
13
|
+
if (state.paused) return type === "pause" || type === "start";
|
|
14
|
+
return state.active && type === "start";
|
|
15
15
|
}
|
|
16
16
|
function pause(timer, state) {
|
|
17
17
|
cancelAnimationFrame(state.frame);
|
|
@@ -34,7 +34,7 @@ function run(timer, state, options) {
|
|
|
34
34
|
finish(timer, state, options, false);
|
|
35
35
|
return;
|
|
36
36
|
}
|
|
37
|
-
if (options.interval === require_constants.milliseconds || state.elapsed >= options.interval -
|
|
37
|
+
if (options.interval === require_constants.milliseconds || state.elapsed >= options.interval - 5) {
|
|
38
38
|
if (options.count > -1) state.callback(state.index);
|
|
39
39
|
start = now;
|
|
40
40
|
state.elapsed = 0;
|
|
@@ -48,7 +48,7 @@ function run(timer, state, options) {
|
|
|
48
48
|
};
|
|
49
49
|
}
|
|
50
50
|
function setState(type, state) {
|
|
51
|
-
const pausable = type ===
|
|
51
|
+
const pausable = type === "continue" || type === "pause";
|
|
52
52
|
state.elapsed = pausable ? state.elapsed : 0;
|
|
53
53
|
state.index = pausable ? state.index : 0;
|
|
54
54
|
state.total = pausable ? state.total : 0;
|
|
@@ -65,8 +65,8 @@ function stop(timer, state, options) {
|
|
|
65
65
|
function work(type, timer, state, options) {
|
|
66
66
|
if (ignore(type, state)) return timer.instance;
|
|
67
67
|
setState(type, state);
|
|
68
|
-
if (type ===
|
|
69
|
-
if (type ===
|
|
68
|
+
if (type === "stop") return stop(timer, state, options);
|
|
69
|
+
if (type === "pause" || type === "restart") {
|
|
70
70
|
cancelAnimationFrame(state.frame);
|
|
71
71
|
state.frame = void 0;
|
|
72
72
|
}
|
package/dist/work.js
CHANGED
|
@@ -5,13 +5,13 @@ function finish(timer, state, options, success) {
|
|
|
5
5
|
state.active = false;
|
|
6
6
|
state.elapsed = 0;
|
|
7
7
|
state.frame = void 0;
|
|
8
|
-
if (timer.type ===
|
|
8
|
+
if (timer.type === "wait") state.callback();
|
|
9
9
|
else options.onAfter?.(success);
|
|
10
10
|
}
|
|
11
11
|
function ignore(type, state) {
|
|
12
12
|
if (state.destroyed) return type !== WORK_STOP;
|
|
13
|
-
if (state.paused) return type ===
|
|
14
|
-
return state.active && type ===
|
|
13
|
+
if (state.paused) return type === "pause" || type === "start";
|
|
14
|
+
return state.active && type === "start";
|
|
15
15
|
}
|
|
16
16
|
function pause(timer, state) {
|
|
17
17
|
cancelAnimationFrame(state.frame);
|
|
@@ -34,7 +34,7 @@ function run(timer, state, options) {
|
|
|
34
34
|
finish(timer, state, options, false);
|
|
35
35
|
return;
|
|
36
36
|
}
|
|
37
|
-
if (options.interval === milliseconds || state.elapsed >= options.interval -
|
|
37
|
+
if (options.interval === milliseconds || state.elapsed >= options.interval - 5) {
|
|
38
38
|
if (options.count > -1) state.callback(state.index);
|
|
39
39
|
start = now;
|
|
40
40
|
state.elapsed = 0;
|
|
@@ -48,7 +48,7 @@ function run(timer, state, options) {
|
|
|
48
48
|
};
|
|
49
49
|
}
|
|
50
50
|
function setState(type, state) {
|
|
51
|
-
const pausable = type ===
|
|
51
|
+
const pausable = type === "continue" || type === "pause";
|
|
52
52
|
state.elapsed = pausable ? state.elapsed : 0;
|
|
53
53
|
state.index = pausable ? state.index : 0;
|
|
54
54
|
state.total = pausable ? state.total : 0;
|
|
@@ -65,8 +65,8 @@ function stop(timer, state, options) {
|
|
|
65
65
|
function work(type, timer, state, options) {
|
|
66
66
|
if (ignore(type, state)) return timer.instance;
|
|
67
67
|
setState(type, state);
|
|
68
|
-
if (type ===
|
|
69
|
-
if (type ===
|
|
68
|
+
if (type === "stop") return stop(timer, state, options);
|
|
69
|
+
if (type === "pause" || type === "restart") {
|
|
70
70
|
cancelAnimationFrame(state.frame);
|
|
71
71
|
state.frame = void 0;
|
|
72
72
|
}
|
package/package.json
CHANGED
|
@@ -4,80 +4,57 @@
|
|
|
4
4
|
"url": "https://oscarpalmer.se"
|
|
5
5
|
},
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@oscarpalmer/atoms": "^0.
|
|
7
|
+
"@oscarpalmer/atoms": "^0.109"
|
|
8
8
|
},
|
|
9
9
|
"description": "A better solution for timeout- and interval-based timers.",
|
|
10
10
|
"devDependencies": {
|
|
11
11
|
"@biomejs/biome": "^2.2",
|
|
12
12
|
"@rollup/plugin-node-resolve": "^16",
|
|
13
13
|
"@rollup/plugin-typescript": "^12.1",
|
|
14
|
-
"@types/node": "^24.
|
|
14
|
+
"@types/node": "^24.5",
|
|
15
15
|
"@vitest/coverage-istanbul": "^3.2",
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"jsdom": "^26.1",
|
|
19
|
-
"rollup": "^4.49",
|
|
16
|
+
"jsdom": "^27",
|
|
17
|
+
"rollup": "^4.50",
|
|
20
18
|
"tslib": "^2.8",
|
|
21
19
|
"typescript": "^5.9",
|
|
22
20
|
"vite": "npm:rolldown-vite@latest",
|
|
23
21
|
"vitest": "^3.2"
|
|
24
22
|
},
|
|
25
23
|
"exports": {
|
|
24
|
+
"./package.json": "./package.json",
|
|
26
25
|
".": {
|
|
27
|
-
"
|
|
28
|
-
|
|
29
|
-
"default": "./dist/index.js"
|
|
30
|
-
},
|
|
31
|
-
"require": {
|
|
32
|
-
"types": "./types/index.d.cts",
|
|
33
|
-
"default": "./dist/index.cjs"
|
|
34
|
-
}
|
|
26
|
+
"types": "./types/index.d.ts",
|
|
27
|
+
"default": "./dist/index.js"
|
|
35
28
|
},
|
|
36
29
|
"./delay": {
|
|
37
|
-
"
|
|
38
|
-
|
|
39
|
-
"default": "./dist/delay.js"
|
|
40
|
-
},
|
|
41
|
-
"require": {
|
|
42
|
-
"types": "./types/delay.d.cts",
|
|
43
|
-
"default": "./dist/delay.cjs"
|
|
44
|
-
}
|
|
30
|
+
"types": "./types/delay.d.ts",
|
|
31
|
+
"default": "./dist/delay.js"
|
|
45
32
|
},
|
|
46
33
|
"./repeat": {
|
|
47
|
-
"
|
|
48
|
-
|
|
49
|
-
"default": "./dist/repeat.js"
|
|
50
|
-
},
|
|
51
|
-
"require": {
|
|
52
|
-
"types": "./types/repeat.d.cts",
|
|
53
|
-
"default": "./dist/repeat.cjs"
|
|
54
|
-
}
|
|
34
|
+
"types": "./types/repeat.d.ts",
|
|
35
|
+
"default": "./dist/repeat.js"
|
|
55
36
|
},
|
|
56
37
|
"./wait": {
|
|
57
|
-
"
|
|
58
|
-
|
|
59
|
-
"default": "./dist/wait.js"
|
|
60
|
-
},
|
|
61
|
-
"require": {
|
|
62
|
-
"types": "./types/wait.d.cts",
|
|
63
|
-
"default": "./dist/wait.cjs"
|
|
64
|
-
}
|
|
38
|
+
"types": "./types/wait.d.ts",
|
|
39
|
+
"default": "./dist/wait.js"
|
|
65
40
|
},
|
|
66
41
|
"./when": {
|
|
67
|
-
"
|
|
68
|
-
|
|
69
|
-
"default": "./dist/when.js"
|
|
70
|
-
},
|
|
71
|
-
"require": {
|
|
72
|
-
"types": "./types/when.d.cts",
|
|
73
|
-
"default": "./dist/when.cjs"
|
|
74
|
-
}
|
|
42
|
+
"types": "./types/when.d.ts",
|
|
43
|
+
"default": "./dist/when.js"
|
|
75
44
|
}
|
|
76
45
|
},
|
|
77
|
-
"files": [
|
|
78
|
-
|
|
46
|
+
"files": [
|
|
47
|
+
"dist",
|
|
48
|
+
"src",
|
|
49
|
+
"types"
|
|
50
|
+
],
|
|
51
|
+
"keywords": [
|
|
52
|
+
"timer",
|
|
53
|
+
"setTimeout",
|
|
54
|
+
"setInterval",
|
|
55
|
+
"requestAnimationFrame"
|
|
56
|
+
],
|
|
79
57
|
"license": "MIT",
|
|
80
|
-
"main": "dist/index.cjs",
|
|
81
58
|
"module": "dist/index.js",
|
|
82
59
|
"name": "@oscarpalmer/timer",
|
|
83
60
|
"repository": {
|
|
@@ -85,15 +62,16 @@
|
|
|
85
62
|
"url": "git+https://github.com/oscarpalmer/timer.git"
|
|
86
63
|
},
|
|
87
64
|
"scripts": {
|
|
88
|
-
"build": "npm run clean && npm run build:js && npm run rollup &&
|
|
65
|
+
"build": "npm run clean && npm run build:js && npm run rollup:build && npx tsc",
|
|
89
66
|
"build:js": "npx vite build",
|
|
90
67
|
"clean": "rm -rf ./dist && rm -rf ./types && rm -f ./tsconfig.tsbuildinfo",
|
|
91
|
-
"rollup": "npx rollup -c",
|
|
68
|
+
"rollup:build": "npx rollup -c",
|
|
69
|
+
"rollup:watch": "npx rollup -c --watch",
|
|
92
70
|
"test": "npx vitest --coverage",
|
|
93
71
|
"types": "npx tsc && npx dts-bundle-generator --config ./dts.config.cts --silent",
|
|
94
72
|
"watch": "npx vite build --watch"
|
|
95
73
|
},
|
|
96
74
|
"type": "module",
|
|
97
|
-
"types": "types/index.d.
|
|
98
|
-
"version": "0.
|
|
99
|
-
}
|
|
75
|
+
"types": "types/index.d.ts",
|
|
76
|
+
"version": "0.37.0"
|
|
77
|
+
}
|
package/src/get.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import type {GenericCallback} from '@oscarpalmer/atoms';
|
|
1
2
|
import {noop} from '@oscarpalmer/atoms/function';
|
|
2
|
-
import type {GenericCallback} from '@oscarpalmer/atoms/models';
|
|
3
3
|
import {defaultTimeout} from './constants';
|
|
4
4
|
|
|
5
5
|
export function getCallback(value: unknown): GenericCallback {
|
package/src/global.ts
CHANGED
|
@@ -19,6 +19,7 @@ if (globalThis._oscarpalmer_timers == null) {
|
|
|
19
19
|
});
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
/* istanbul ignore next */
|
|
22
23
|
document.addEventListener('visibilitychange', () => {
|
|
23
24
|
const from = document.hidden ? activeTimers : hiddenTimers;
|
|
24
25
|
const method = document.hidden ? WORK_PAUSE : WORK_CONTINUE;
|
package/src/is.ts
CHANGED
package/types/get.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { GenericCallback } from '@oscarpalmer/atoms
|
|
1
|
+
import type { GenericCallback } from '@oscarpalmer/atoms';
|
|
2
2
|
export declare function getCallback(value: unknown): GenericCallback;
|
|
3
3
|
export declare function getValidTimeout(value: unknown): number;
|
|
4
4
|
export declare function getValidNumber(value: unknown, defaultValue?: number): number;
|
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 {};
|
package/types/repeat.d.cts
DELETED
|
@@ -1,99 +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
|
-
* Create a repeating timer
|
|
96
|
-
*/
|
|
97
|
-
export declare function repeat(callback: (index: number) => void, options?: Partial<RepeatOptions>): Timer;
|
|
98
|
-
|
|
99
|
-
export {};
|
package/types/timer.d.cts
DELETED
|
@@ -1,70 +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
|
-
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
|
-
export {};
|
package/types/wait.d.cts
DELETED
|
@@ -1,76 +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
|
-
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
|
-
* Create a waiting timer
|
|
71
|
-
* @param callback Callback to run when the timer has finished
|
|
72
|
-
* @param time How long to wait for _(in milliseconds; defaults to screen refresh rate)_
|
|
73
|
-
*/
|
|
74
|
-
export declare function wait(callback: () => void, time?: number): Timer;
|
|
75
|
-
|
|
76
|
-
export {};
|
package/types/when.d.cts
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
// Generated by dts-bundle-generator v9.5.1
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Options for a conditional timer
|
|
5
|
-
*/
|
|
6
|
-
export type WhenOptions = {
|
|
7
|
-
/**
|
|
8
|
-
* How many times the timer should check the condition
|
|
9
|
-
*/
|
|
10
|
-
count: number;
|
|
11
|
-
/**
|
|
12
|
-
* Then interval between each condtional check
|
|
13
|
-
*/
|
|
14
|
-
interval: number;
|
|
15
|
-
/**
|
|
16
|
-
* The timeout for the timer _(any value above `0` will enable the timeout)_
|
|
17
|
-
*/
|
|
18
|
-
timeout: number;
|
|
19
|
-
};
|
|
20
|
-
export declare class When {
|
|
21
|
-
private readonly $timer;
|
|
22
|
-
private readonly state;
|
|
23
|
-
/**
|
|
24
|
-
* Is the timer active?
|
|
25
|
-
*/
|
|
26
|
-
get active(): boolean;
|
|
27
|
-
/**
|
|
28
|
-
* Is the timer destroyed?
|
|
29
|
-
*/
|
|
30
|
-
get destroyed(): boolean;
|
|
31
|
-
/**
|
|
32
|
-
* Is the timer paused?
|
|
33
|
-
*/
|
|
34
|
-
get paused(): boolean;
|
|
35
|
-
/**
|
|
36
|
-
* Get the timer's origin _(if debugging is enabled)_
|
|
37
|
-
*/
|
|
38
|
-
get trace(): string | undefined;
|
|
39
|
-
constructor(condition: () => boolean, options?: Partial<WhenOptions>);
|
|
40
|
-
/**
|
|
41
|
-
* Continues the timer _(if it was paused)_
|
|
42
|
-
*/
|
|
43
|
-
continue(): When;
|
|
44
|
-
/**
|
|
45
|
-
* Destroys the timer _(and stops it,if it was running)_
|
|
46
|
-
*/
|
|
47
|
-
destroy(): void;
|
|
48
|
-
/**
|
|
49
|
-
* Pauses the timer _(if it was running)_
|
|
50
|
-
*/
|
|
51
|
-
pause(): When;
|
|
52
|
-
/**
|
|
53
|
-
* Stops the timer _(if it was running)_
|
|
54
|
-
*/
|
|
55
|
-
stop(): When;
|
|
56
|
-
/**
|
|
57
|
-
* Starts the timer and returns a promise that resolves when the condition is met
|
|
58
|
-
*/
|
|
59
|
-
then(resolve?: (() => void) | null, reject?: (() => void) | null): Promise<void>;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Create a conditional timer
|
|
63
|
-
*/
|
|
64
|
-
export declare function when(condition: () => boolean, options?: Partial<WhenOptions>): When;
|
|
65
|
-
|
|
66
|
-
export {};
|
package/types/work.d.cts
DELETED
|
@@ -1,81 +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 WorkHandlerTimer = {
|
|
70
|
-
instance: Timer;
|
|
71
|
-
type: TimerType;
|
|
72
|
-
};
|
|
73
|
-
export type WorkHandlerType = "continue" | "pause" | "restart" | "start" | "stop";
|
|
74
|
-
declare function stop$1(timer: WorkHandlerTimer, state: TimerState, options: TimerOptions): Timer;
|
|
75
|
-
export declare function work(type: WorkHandlerType, timer: WorkHandlerTimer, state: TimerState, options: TimerOptions): Timer;
|
|
76
|
-
|
|
77
|
-
export {
|
|
78
|
-
stop$1 as stop,
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
export {};
|