@oscarpalmer/timer 0.47.0 → 0.48.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/constants.d.mts +2 -1
- package/dist/constants.mjs +2 -1
- package/dist/global.mjs +3 -2
- package/dist/index.d.mts +8 -8
- package/dist/index.mjs +3 -1
- package/package.json +4 -4
- package/src/constants.ts +2 -0
- package/src/global.ts +11 -6
package/dist/constants.d.mts
CHANGED
|
@@ -5,6 +5,7 @@ import { TimerName, TimerStates, WorkHandlerType } from "./models.mjs";
|
|
|
5
5
|
*/
|
|
6
6
|
declare const BUFFER_INTERVAL = 5;
|
|
7
7
|
declare const DEFAULT_TIMEOUT = 30000;
|
|
8
|
+
declare const GLOBAL_NAME = "_oscarpalmer_timers";
|
|
8
9
|
/**
|
|
9
10
|
* Message to show when a when-timer is started
|
|
10
11
|
*/
|
|
@@ -19,4 +20,4 @@ declare const WORK_RESTART: WorkHandlerType;
|
|
|
19
20
|
declare const WORK_START: WorkHandlerType;
|
|
20
21
|
declare const WORK_STOP: WorkHandlerType;
|
|
21
22
|
//#endregion
|
|
22
|
-
export { BUFFER_INTERVAL, DEFAULT_TIMEOUT, MESSAGE_STARTED, STATES, TYPE_REPEAT, TYPE_WAIT, TYPE_WHEN, WORK_CONTINUE, WORK_PAUSE, WORK_RESTART, WORK_START, WORK_STOP };
|
|
23
|
+
export { BUFFER_INTERVAL, DEFAULT_TIMEOUT, GLOBAL_NAME, MESSAGE_STARTED, STATES, TYPE_REPEAT, TYPE_WAIT, TYPE_WHEN, WORK_CONTINUE, WORK_PAUSE, WORK_RESTART, WORK_START, WORK_STOP };
|
package/dist/constants.mjs
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
const BUFFER_INTERVAL = 5;
|
|
6
6
|
const DEFAULT_TIMEOUT = 3e4;
|
|
7
|
+
const GLOBAL_NAME = "_oscarpalmer_timers";
|
|
7
8
|
/**
|
|
8
9
|
* Message to show when a when-timer is started
|
|
9
10
|
*/
|
|
@@ -21,4 +22,4 @@ const WORK_RESTART = "restart";
|
|
|
21
22
|
const WORK_START = "start";
|
|
22
23
|
const WORK_STOP = "stop";
|
|
23
24
|
//#endregion
|
|
24
|
-
export { BUFFER_INTERVAL, DEFAULT_TIMEOUT, MESSAGE_STARTED, STATES, TYPE_REPEAT, TYPE_WAIT, TYPE_WHEN, WORK_CONTINUE, WORK_PAUSE, WORK_RESTART, WORK_START, WORK_STOP };
|
|
25
|
+
export { BUFFER_INTERVAL, DEFAULT_TIMEOUT, GLOBAL_NAME, MESSAGE_STARTED, STATES, TYPE_REPEAT, TYPE_WAIT, TYPE_WHEN, WORK_CONTINUE, WORK_PAUSE, WORK_RESTART, WORK_START, WORK_STOP };
|
package/dist/global.mjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { STATES } from "./constants.mjs";
|
|
1
|
+
import { GLOBAL_NAME, STATES } from "./constants.mjs";
|
|
2
2
|
import { onVisibilityChange } from "./misc.mjs";
|
|
3
3
|
//#region src/global.ts
|
|
4
|
-
|
|
4
|
+
/* istanbul ignore next */
|
|
5
|
+
if (!("_oscarpalmer_timers" in globalThis)) Object.defineProperty(globalThis, GLOBAL_NAME, { get() {
|
|
5
6
|
return globalThis._oscarpalmer_timer_debug ? [...STATES.active].map((state) => state.timer) : [];
|
|
6
7
|
} });
|
|
7
8
|
document.addEventListener("visibilitychange", onVisibilityChange);
|
package/dist/index.d.mts
CHANGED
|
@@ -156,28 +156,28 @@ declare global {
|
|
|
156
156
|
* @param value Value to check
|
|
157
157
|
* @returns `true` if the value is a repeating timer, otherwise `false`
|
|
158
158
|
*/
|
|
159
|
-
declare function isRepeated(value: unknown): value is Timer;
|
|
159
|
+
export declare function isRepeated(value: unknown): value is Timer;
|
|
160
160
|
/**
|
|
161
161
|
* Is the value a timer?
|
|
162
162
|
*
|
|
163
163
|
* @param value Value to check
|
|
164
164
|
* @returns `true` if the value is a timer, otherwise `false`
|
|
165
165
|
*/
|
|
166
|
-
declare function isTimer(value: unknown): value is Timer;
|
|
166
|
+
export declare function isTimer(value: unknown): value is Timer;
|
|
167
167
|
/**
|
|
168
168
|
* Is the value a waiting timer?
|
|
169
169
|
*
|
|
170
170
|
* @param value Value to check
|
|
171
171
|
* @returns `true` if the value is a waiting timer, otherwise `false`
|
|
172
172
|
*/
|
|
173
|
-
declare function isWaited(value: unknown): value is Timer;
|
|
173
|
+
export declare function isWaited(value: unknown): value is Timer;
|
|
174
174
|
/**
|
|
175
175
|
* Is the value a conditional timer?
|
|
176
176
|
*
|
|
177
177
|
* @param value Value to check
|
|
178
178
|
* @returns `true` if the value is a conditional timer, otherwise `false`
|
|
179
179
|
*/
|
|
180
|
-
declare function isWhen(value: unknown): value is When;
|
|
180
|
+
export declare function isWhen(value: unknown): value is When;
|
|
181
181
|
//#endregion
|
|
182
182
|
//#region src/repeat.d.ts
|
|
183
183
|
/**
|
|
@@ -187,7 +187,7 @@ declare function isWhen(value: unknown): value is When;
|
|
|
187
187
|
* @param options Timer options
|
|
188
188
|
* @returns Repeating timer
|
|
189
189
|
*/
|
|
190
|
-
declare function repeat(callback: (index: number) => void, options?: Partial<RepeatOptions>): Timer;
|
|
190
|
+
export declare function repeat(callback: (index: number) => void, options?: Partial<RepeatOptions>): Timer;
|
|
191
191
|
//#endregion
|
|
192
192
|
//#region src/wait.d.ts
|
|
193
193
|
/**
|
|
@@ -197,7 +197,7 @@ declare function repeat(callback: (index: number) => void, options?: Partial<Rep
|
|
|
197
197
|
* @param time How long to wait for _(in milliseconds; defaults to screen refresh rate)_
|
|
198
198
|
* @returns Waiting timer
|
|
199
199
|
*/
|
|
200
|
-
declare function wait(callback: () => void, time?: number): Timer;
|
|
200
|
+
export declare function wait(callback: () => void, time?: number): Timer;
|
|
201
201
|
//#endregion
|
|
202
202
|
//#region src/when.d.ts
|
|
203
203
|
/**
|
|
@@ -206,6 +206,6 @@ declare function wait(callback: () => void, time?: number): Timer;
|
|
|
206
206
|
* @param options Timer options
|
|
207
207
|
* @returns Timer instance
|
|
208
208
|
*/
|
|
209
|
-
declare function when(condition: () => boolean, options?: Partial<WhenOptions>): When;
|
|
209
|
+
export declare function when(condition: () => boolean, options?: Partial<WhenOptions>): When;
|
|
210
210
|
//#endregion
|
|
211
|
-
export {
|
|
211
|
+
export type { RepeatOptions, Timer, TimerOptions, When, WhenOptions };
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
//#region src/constants.ts
|
|
2
2
|
const DEFAULT_TIMEOUT = 3e4;
|
|
3
|
+
const GLOBAL_NAME = "_oscarpalmer_timers";
|
|
3
4
|
/**
|
|
4
5
|
* Message to show when a when-timer is started
|
|
5
6
|
*/
|
|
@@ -129,7 +130,8 @@ function updateStates(state, hide) {
|
|
|
129
130
|
}
|
|
130
131
|
//#endregion
|
|
131
132
|
//#region src/global.ts
|
|
132
|
-
|
|
133
|
+
/* istanbul ignore next */
|
|
134
|
+
if (!("_oscarpalmer_timers" in globalThis)) Object.defineProperty(globalThis, GLOBAL_NAME, { get() {
|
|
133
135
|
return globalThis._oscarpalmer_timer_debug ? [...STATES.active].map((state) => state.timer) : [];
|
|
134
136
|
} });
|
|
135
137
|
document.addEventListener("visibilitychange", onVisibilityChange);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oscarpalmer/timer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.48.0",
|
|
4
4
|
"description": "A better solution for timeout- and interval-based timers.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"requestAnimationFrame",
|
|
@@ -60,14 +60,14 @@
|
|
|
60
60
|
"watch": "npx vite build --watch"
|
|
61
61
|
},
|
|
62
62
|
"dependencies": {
|
|
63
|
-
"@oscarpalmer/atoms": "^0.
|
|
63
|
+
"@oscarpalmer/atoms": "^0.199"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
|
-
"@oxlint/plugins": "^1.
|
|
66
|
+
"@oxlint/plugins": "^1.81",
|
|
67
67
|
"@types/node": "^26.4",
|
|
68
68
|
"@vitest/coverage-istanbul": "^4.1",
|
|
69
69
|
"jsdom": "^30",
|
|
70
|
-
"tsdown": "^0.
|
|
70
|
+
"tsdown": "^0.23",
|
|
71
71
|
"typescript": "^6",
|
|
72
72
|
"vite": "npm:@voidzero-dev/vite-plus-core@latest",
|
|
73
73
|
"vite-plus": "latest",
|
package/src/constants.ts
CHANGED
package/src/global.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {STATES} from './constants';
|
|
1
|
+
import {GLOBAL_NAME, STATES} from './constants';
|
|
2
2
|
import {onVisibilityChange} from './misc';
|
|
3
3
|
import type {Timer} from './models';
|
|
4
4
|
|
|
@@ -10,10 +10,15 @@ declare global {
|
|
|
10
10
|
var _oscarpalmer_timers: Timer[] | undefined;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
/* istanbul ignore next */
|
|
14
|
+
if (!(GLOBAL_NAME in globalThis)) {
|
|
15
|
+
Object.defineProperty(globalThis, GLOBAL_NAME, {
|
|
16
|
+
get() {
|
|
17
|
+
return globalThis._oscarpalmer_timer_debug
|
|
18
|
+
? [...STATES.active].map(state => state.timer)
|
|
19
|
+
: [];
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
}
|
|
18
23
|
|
|
19
24
|
document.addEventListener('visibilitychange', onVisibilityChange);
|