timeout-flow 0.0.17 → 0.0.19
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/ADDITIONAL_TERMS.md +122 -0
- package/LICENSE +694 -0
- package/README.md +307 -237
- package/dist/timeout-flow.min.js +1 -6
- package/package.json +68 -58
- package/robots.txt +79 -3
- package/src/AfterTimer.js +82 -21
- package/src/EveryTimer.js +209 -88
- package/src/TimeoutFlow.js +400 -227
- package/src/TimerBase.js +133 -75
- package/src/abort.js +75 -0
- package/src/after.js +32 -83
- package/src/debounce.js +106 -40
- package/src/every.js +34 -120
- package/src/index.js +24 -19
- package/src/now.js +23 -0
- package/src/parseDuration.js +46 -44
- package/src/raf/ReadMe-Raf.md +94 -94
- package/src/raf/afterRaf.js +204 -72
- package/src/raf/debounceRaf.js +127 -45
- package/src/raf/everyRaf.js +317 -106
- package/src/raf/index.js +28 -8
- package/src/raf/throttleRaf.js +182 -38
- package/src/raf/waitForRaf.js +101 -33
- package/src/resolveDelayAndFn.js +90 -28
- package/src/retry.js +164 -24
- package/src/throttle.js +141 -47
- package/src/waitFor.js +77 -33
- package/types/AfterTimer.d.ts +8 -2
- package/types/EveryTimer.d.ts +21 -4
- package/types/TimeoutFlow.d.ts +6 -18
- package/types/TimerBase.d.ts +15 -4
- package/types/abort.d.ts +31 -0
- package/types/after.d.ts +22 -22
- package/types/debounce.d.ts +28 -6
- package/types/every.d.ts +20 -28
- package/types/index.d.ts +1 -1
- package/types/now.d.ts +1 -0
- package/types/raf/afterRaf.d.ts +35 -5
- package/types/raf/debounceRaf.d.ts +27 -6
- package/types/raf/everyRaf.d.ts +39 -9
- package/types/raf/index.d.ts +6 -5
- package/types/raf/throttleRaf.d.ts +33 -10
- package/types/raf/waitForRaf.d.ts +10 -4
- package/types/resolveDelayAndFn.d.ts +27 -0
- package/types/retry.d.ts +25 -8
- package/types/throttle.d.ts +28 -6
- package/types/waitFor.d.ts +11 -6
- package/LICENSE.MD +0 -285
package/src/waitFor.js
CHANGED
|
@@ -1,33 +1,77 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* @param {
|
|
12
|
-
* @
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
1
|
+
// ./src/waitFor.js
|
|
2
|
+
|
|
3
|
+
import { parseDuration } from './parseDuration.js';
|
|
4
|
+
import { attachAbort, createAbortError } from './abort.js';
|
|
5
|
+
import { now } from './now.js'
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Waits for a condition to become true, polling at intervals.
|
|
10
|
+
*
|
|
11
|
+
* @param {Function} condition - returns truthy when satisfied
|
|
12
|
+
* @param {Object} [options] - optional polling control
|
|
13
|
+
* @param {string|number} [options.interval='250ms'] - poll frequency
|
|
14
|
+
* @param {string|number} [options.timeout] - max wait time
|
|
15
|
+
* @param {boolean} [options.immediate=false] - If true, evaluate condition immediately
|
|
16
|
+
* @param {AbortSignal} [options.signal] - Optional AbortSignal to cancel waiting
|
|
17
|
+
* @returns {Promise<void>}
|
|
18
|
+
*/
|
|
19
|
+
export function waitFor(condition, { interval = '250ms', timeout, immediate = false, signal } = {}) {
|
|
20
|
+
return new Promise((resolve, reject) => {
|
|
21
|
+
if (signal?.aborted) {
|
|
22
|
+
reject(createAbortError());
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const start = now();
|
|
27
|
+
|
|
28
|
+
const intervalMs = typeof interval === 'string' ? parseDuration(interval) : interval;
|
|
29
|
+
const timeoutMs = timeout != null ? parseDuration(timeout) : null;
|
|
30
|
+
|
|
31
|
+
let poller = null;
|
|
32
|
+
|
|
33
|
+
const cleanup = () => {
|
|
34
|
+
if (poller != null) {
|
|
35
|
+
clearInterval(poller);
|
|
36
|
+
poller = null;
|
|
37
|
+
}
|
|
38
|
+
cleanupAbort();
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const onAbort = () => {
|
|
42
|
+
cleanup();
|
|
43
|
+
reject(createAbortError());
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const cleanupAbort = attachAbort(signal, onAbort);
|
|
47
|
+
|
|
48
|
+
const check = () => {
|
|
49
|
+
let ok = false;
|
|
50
|
+
|
|
51
|
+
try {
|
|
52
|
+
ok = !!condition();
|
|
53
|
+
} catch (err) {
|
|
54
|
+
cleanup();
|
|
55
|
+
reject(err);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (ok) {
|
|
60
|
+
cleanup();
|
|
61
|
+
resolve();
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (timeoutMs != null && now() - start >= timeoutMs) {
|
|
66
|
+
cleanup();
|
|
67
|
+
reject(new Error('waitFor timed out'));
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
// Only evaluate immediately if explicitly requested
|
|
72
|
+
if (immediate) check();
|
|
73
|
+
|
|
74
|
+
// Schedule exactly once
|
|
75
|
+
poller = setInterval(check, intervalMs);
|
|
76
|
+
});
|
|
77
|
+
}
|
package/types/AfterTimer.d.ts
CHANGED
|
@@ -5,8 +5,14 @@ export class AfterTimer extends TimerBase {
|
|
|
5
5
|
/**
|
|
6
6
|
* @param {string|number} duration - Delay before firing (e.g., '1s', 300)
|
|
7
7
|
* @param {Function} fn - Main function to execute
|
|
8
|
-
* @param {
|
|
8
|
+
* @param {Object} [options]
|
|
9
|
+
* @param {Function} [options.onFinish] - Optional callback when done
|
|
10
|
+
* @param {AbortSignal} [options.signal] - Optional AbortSignal to auto-cancel
|
|
9
11
|
*/
|
|
10
|
-
constructor(duration: string | number, fn: Function, onFinish?:
|
|
12
|
+
constructor(duration: string | number, fn: Function, { onFinish, signal }?: {
|
|
13
|
+
onFinish?: Function | undefined;
|
|
14
|
+
signal?: AbortSignal | undefined;
|
|
15
|
+
});
|
|
16
|
+
#private;
|
|
11
17
|
}
|
|
12
18
|
import { TimerBase } from './TimerBase.js';
|
package/types/EveryTimer.d.ts
CHANGED
|
@@ -5,18 +5,35 @@ export class EveryTimer {
|
|
|
5
5
|
/**
|
|
6
6
|
* @param {string|number} duration - Delay between calls (e.g., '1s', 200)
|
|
7
7
|
* @param {Function} fn - Function to call each tick
|
|
8
|
-
* @param {
|
|
9
|
-
* @param {
|
|
8
|
+
* @param {Object} [options]
|
|
9
|
+
* @param {number} [options.max=Infinity] - Max executions
|
|
10
|
+
* @param {boolean} [options.runImmediately=false] - Run `fn` once before first delay
|
|
11
|
+
* @param {AbortSignal} [options.signal] - Optional AbortSignal to auto-cancel
|
|
10
12
|
*/
|
|
11
|
-
constructor(duration: string | number, fn: Function, max
|
|
13
|
+
constructor(duration: string | number, fn: Function, { max, runImmediately, signal }?: {
|
|
14
|
+
max?: number | undefined;
|
|
15
|
+
runImmediately?: boolean | undefined;
|
|
16
|
+
signal?: AbortSignal | undefined;
|
|
17
|
+
});
|
|
12
18
|
/**
|
|
13
19
|
* Number of times `fn` has been executed.
|
|
14
20
|
*/
|
|
15
21
|
get count(): number;
|
|
16
22
|
/**
|
|
17
|
-
* Whether the timer is actively running.
|
|
23
|
+
* Whether the timer is actively running (waiting for next tick).
|
|
24
|
+
*
|
|
25
|
+
* Note: during the brief moment between a tick firing and the next schedule,
|
|
26
|
+
* this may be false — which reflects "no countdown currently pending".
|
|
18
27
|
*/
|
|
19
28
|
get isRunning(): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Whether the timer is paused (resumable).
|
|
31
|
+
*/
|
|
32
|
+
get isPaused(): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Whether the timer has finished (hit max) or been canceled (terminal).
|
|
35
|
+
*/
|
|
36
|
+
get isFinished(): boolean;
|
|
20
37
|
pause(): void;
|
|
21
38
|
resume(): void;
|
|
22
39
|
cancel(): void;
|
package/types/TimeoutFlow.d.ts
CHANGED
|
@@ -1,22 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Creates a fluent scheduler.
|
|
3
3
|
* Returns a chainable timeline.
|
|
4
|
+
*
|
|
5
|
+
* @param {Object} [options]
|
|
6
|
+
* @param {AbortSignal} [options.signal] - Optional AbortSignal to auto-cancel the flow
|
|
4
7
|
*/
|
|
5
|
-
export function flow(
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
loop(n?: boolean): /*elided*/ any;
|
|
9
|
-
onFinish(cb: any): /*elided*/ any;
|
|
10
|
-
start(): /*elided*/ any;
|
|
11
|
-
pause(): void;
|
|
12
|
-
resume(): void;
|
|
13
|
-
cancel(): void;
|
|
14
|
-
reset(): /*elided*/ any;
|
|
15
|
-
readonly isPaused: boolean;
|
|
16
|
-
label(name: any): /*elided*/ any;
|
|
17
|
-
jumpTo(name: any): /*elided*/ any;
|
|
18
|
-
if(predicate: any): /*elided*/ any;
|
|
19
|
-
unless(predicate: any): /*elided*/ any;
|
|
20
|
-
while(predicate: any): /*elided*/ any;
|
|
21
|
-
doWhile(predicate: any): /*elided*/ any;
|
|
22
|
-
};
|
|
8
|
+
export function flow({ signal }?: {
|
|
9
|
+
signal?: AbortSignal | undefined;
|
|
10
|
+
}): any;
|
package/types/TimerBase.d.ts
CHANGED
|
@@ -8,26 +8,37 @@ export class TimerBase {
|
|
|
8
8
|
*/
|
|
9
9
|
constructor(duration: string | number);
|
|
10
10
|
/**
|
|
11
|
-
* Whether the timer is currently running.
|
|
11
|
+
* Whether the timer is currently running (actively counting down).
|
|
12
12
|
* @returns {boolean}
|
|
13
13
|
*/
|
|
14
14
|
get isRunning(): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Whether the timer is paused (resumable).
|
|
17
|
+
* @returns {boolean}
|
|
18
|
+
*/
|
|
19
|
+
get isPaused(): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Whether the timer has finished or been canceled (terminal state).
|
|
22
|
+
* @returns {boolean}
|
|
23
|
+
*/
|
|
24
|
+
get isFinished(): boolean;
|
|
15
25
|
/**
|
|
16
26
|
* Pause the active timer, storing remaining time.
|
|
17
27
|
*/
|
|
18
28
|
pause(): void;
|
|
19
29
|
/**
|
|
20
|
-
* Resume the timer using the remaining time.
|
|
30
|
+
* Resume the timer using the remaining time (or an override delay).
|
|
21
31
|
* @param {Function} callback - Called when time completes
|
|
22
|
-
* @param {number|null} [overrideDelay] - Optional custom delay in ms
|
|
32
|
+
* @param {number|null} [overrideDelay=null] - Optional custom delay in ms
|
|
23
33
|
*/
|
|
24
34
|
resume(callback: Function, overrideDelay?: number | null): void;
|
|
25
35
|
/**
|
|
26
|
-
* Cancel the timer immediately.
|
|
36
|
+
* Cancel the timer immediately (terminal).
|
|
27
37
|
*/
|
|
28
38
|
cancel(): void;
|
|
29
39
|
/**
|
|
30
40
|
* Reset the timer to its original delay, cancelling if needed.
|
|
41
|
+
* After reset, the timer is not running.
|
|
31
42
|
*/
|
|
32
43
|
reset(): void;
|
|
33
44
|
#private;
|
package/types/abort.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Attach an AbortSignal listener and return a cleanup function.
|
|
3
|
+
* - If `signal` is missing, returns a no-op cleanup.
|
|
4
|
+
* - If already aborted, calls `onAbort()` immediately and returns a no-op cleanup.
|
|
5
|
+
*
|
|
6
|
+
* @param {AbortSignal | null | undefined} signal
|
|
7
|
+
* @param {() => void} onAbort
|
|
8
|
+
* @returns {() => void} cleanup
|
|
9
|
+
*/
|
|
10
|
+
export function attachAbort(signal: AbortSignal | null | undefined, onAbort: () => void): () => void;
|
|
11
|
+
/**
|
|
12
|
+
* Manage AbortSignal listener lifecycle for "pending work" cases.
|
|
13
|
+
* Call `add()` when work becomes pending and `remove()` when it’s resolved/canceled.
|
|
14
|
+
*
|
|
15
|
+
* @param {AbortSignal | null | undefined} signal
|
|
16
|
+
* @param {() => void} onAbort
|
|
17
|
+
* @returns {{ add: () => void, remove: () => void, reset: () => void }}
|
|
18
|
+
*/
|
|
19
|
+
export function pendingAbort(signal: AbortSignal | null | undefined, onAbort: () => void): {
|
|
20
|
+
add: () => void;
|
|
21
|
+
remove: () => void;
|
|
22
|
+
reset: () => void;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Standardized AbortError factory.
|
|
26
|
+
* Works in browsers and Node runtimes that may not have DOMException.
|
|
27
|
+
*
|
|
28
|
+
* We resolve the best implementation once at module load time.
|
|
29
|
+
* This avoids feature detection in the hot path.
|
|
30
|
+
*/
|
|
31
|
+
export let createAbortError: any;
|
package/types/after.d.ts
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Schedules a one-time delayed function.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* }
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
pause(): void;
|
|
16
|
-
resume(): void;
|
|
17
|
-
cancel(): void;
|
|
18
|
-
isRunning: boolean;
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* Schedules a one-time delayed function.
|
|
22
|
-
* @param {string} duration - e.g. "5s", "500ms", "2m"
|
|
23
|
-
* @param {Function} fn - callback to run
|
|
4
|
+
* Preferred:
|
|
5
|
+
* - after(fn, duration, [options])
|
|
6
|
+
*
|
|
7
|
+
* Also supported (legacy/alt):
|
|
8
|
+
* - after(duration, fn, [options])
|
|
9
|
+
*
|
|
10
|
+
* @param {Function|string|number} a - Function or duration (see overloads)
|
|
11
|
+
* @param {Function|string|number|Object} b - Duration, function, or options
|
|
12
|
+
* @param {Object} [c] - Options
|
|
13
|
+
* @param {Function} [c.onFinish] - Optional callback after `fn` runs
|
|
14
|
+
* @param {AbortSignal} [c.signal] - Optional AbortSignal to auto-cancel
|
|
24
15
|
* @returns {{
|
|
25
16
|
* pause(): void,
|
|
26
17
|
* resume(): void,
|
|
27
18
|
* cancel(): void,
|
|
19
|
+
* reset(): void,
|
|
28
20
|
* readonly isRunning: boolean,
|
|
21
|
+
* readonly isPaused: boolean,
|
|
22
|
+
* readonly isFinished: boolean
|
|
29
23
|
* }}
|
|
30
|
-
|
|
31
|
-
export function
|
|
24
|
+
*/
|
|
25
|
+
export function after(a: Function | string | number, b: Function | string | number | Object, c?: {
|
|
26
|
+
onFinish?: Function | undefined;
|
|
27
|
+
signal?: AbortSignal | undefined;
|
|
28
|
+
}): {
|
|
32
29
|
pause(): void;
|
|
33
30
|
resume(): void;
|
|
34
31
|
cancel(): void;
|
|
32
|
+
reset(): void;
|
|
35
33
|
readonly isRunning: boolean;
|
|
34
|
+
readonly isPaused: boolean;
|
|
35
|
+
readonly isFinished: boolean;
|
|
36
36
|
};
|
package/types/debounce.d.ts
CHANGED
|
@@ -1,14 +1,36 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @typedef {((...args: any[]) => void) & {
|
|
2
|
+
* @typedef {((...args: any[]) => void) & {
|
|
3
|
+
* cancel: () => void,
|
|
4
|
+
* flush: () => void
|
|
5
|
+
* }} DebouncedFunction
|
|
3
6
|
*/
|
|
4
7
|
/**
|
|
5
|
-
* Creates a debounced function that delays invoking `fn`
|
|
8
|
+
* Creates a debounced function that delays invoking `fn`
|
|
9
|
+
* until after `delay` ms of inactivity.
|
|
6
10
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
11
|
+
* Preferred:
|
|
12
|
+
* - debounce(fn, [delay], [options]) // delay defaults to 0
|
|
13
|
+
*
|
|
14
|
+
* Also supported:
|
|
15
|
+
* - debounce(delay, fn, [options]) // legacy/alt ordering
|
|
16
|
+
* - debounce(fn, [options])
|
|
17
|
+
*
|
|
18
|
+
* Notes:
|
|
19
|
+
* - Always invokes with the latest arguments/context.
|
|
20
|
+
* - `.cancel()` clears any pending invocation.
|
|
21
|
+
* - `.flush()` immediately invokes if pending.
|
|
22
|
+
* - Optional AbortSignal: abort cancels pending invocation.
|
|
23
|
+
*
|
|
24
|
+
* @param {Function|string|number} a - Function or delay (see overloads)
|
|
25
|
+
* @param {Function|string|number|Object} [b] - Delay, function, or options
|
|
26
|
+
* @param {Object} [c] - Options (3-arg form)
|
|
27
|
+
* @param {AbortSignal} [c.signal] - Optional AbortSignal to cancel pending work
|
|
28
|
+
* @returns {DebouncedFunction}
|
|
10
29
|
*/
|
|
11
|
-
export function debounce(a:
|
|
30
|
+
export function debounce(a: Function | string | number, b?: Function | string | number | Object, c?: {
|
|
31
|
+
signal?: AbortSignal | undefined;
|
|
32
|
+
}): DebouncedFunction;
|
|
12
33
|
export type DebouncedFunction = ((...args: any[]) => void) & {
|
|
13
34
|
cancel: () => void;
|
|
35
|
+
flush: () => void;
|
|
14
36
|
};
|
package/types/every.d.ts
CHANGED
|
@@ -1,48 +1,40 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Runs a function every N ms with optional execution limit.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* pause(): void,
|
|
10
|
-
* resume(): void,
|
|
11
|
-
* cancel(): void,
|
|
12
|
-
* reset(restart?: boolean): void,
|
|
13
|
-
* readonly isRunning: boolean,
|
|
14
|
-
* readonly count: number
|
|
15
|
-
* }}
|
|
16
|
-
*/
|
|
17
|
-
export function every(duration: string | number, fn: Function, max?: number, runImmediately?: boolean): {
|
|
18
|
-
pause(): void;
|
|
19
|
-
resume(): void;
|
|
20
|
-
cancel(): void;
|
|
21
|
-
reset(restart?: boolean): void;
|
|
22
|
-
readonly isRunning: boolean;
|
|
23
|
-
readonly count: number;
|
|
24
|
-
};
|
|
25
|
-
/**
|
|
26
|
-
* Runs a function every N milliseconds with optional execution limit.
|
|
27
|
-
* Returns control methods: pause, resume, cancel, reset, and status flags.
|
|
4
|
+
* Preferred:
|
|
5
|
+
* - every(fn, duration, [options])
|
|
6
|
+
*
|
|
7
|
+
* Also supported (legacy/alt):
|
|
8
|
+
* - every(duration, fn, [options])
|
|
28
9
|
*
|
|
29
|
-
* @param {string|number}
|
|
30
|
-
* @param {Function}
|
|
31
|
-
* @param {
|
|
10
|
+
* @param {Function|string|number} a - Function or duration (see overloads)
|
|
11
|
+
* @param {Function|string|number|Object} b - Duration, function, or options
|
|
12
|
+
* @param {Object} [c] - Options
|
|
13
|
+
* @param {number} [c.max=Infinity] - Max times to run
|
|
14
|
+
* @param {boolean} [c.runImmediately=false] - Run immediately on first tick
|
|
15
|
+
* @param {AbortSignal} [c.signal] - Optional AbortSignal to auto-cancel
|
|
32
16
|
* @returns {{
|
|
33
17
|
* pause(): void,
|
|
34
18
|
* resume(): void,
|
|
35
19
|
* cancel(): void,
|
|
36
20
|
* reset(restart?: boolean): void,
|
|
37
21
|
* readonly isRunning: boolean,
|
|
22
|
+
* readonly isPaused: boolean,
|
|
23
|
+
* readonly isFinished: boolean,
|
|
38
24
|
* readonly count: number
|
|
39
25
|
* }}
|
|
40
26
|
*/
|
|
41
|
-
export function
|
|
27
|
+
export function every(a: Function | string | number, b: Function | string | number | Object, c?: {
|
|
28
|
+
max?: number | undefined;
|
|
29
|
+
runImmediately?: boolean | undefined;
|
|
30
|
+
signal?: AbortSignal | undefined;
|
|
31
|
+
}): {
|
|
42
32
|
pause(): void;
|
|
43
33
|
resume(): void;
|
|
44
34
|
cancel(): void;
|
|
45
35
|
reset(restart?: boolean): void;
|
|
46
36
|
readonly isRunning: boolean;
|
|
37
|
+
readonly isPaused: boolean;
|
|
38
|
+
readonly isFinished: boolean;
|
|
47
39
|
readonly count: number;
|
|
48
40
|
};
|
package/types/index.d.ts
CHANGED
|
@@ -6,4 +6,4 @@ export { after } from "./after.js";
|
|
|
6
6
|
export { every } from "./every.js";
|
|
7
7
|
export { waitFor } from "./waitFor.js";
|
|
8
8
|
export { retry } from "./retry.js";
|
|
9
|
-
export
|
|
9
|
+
export { afterRaf, everyRaf, debounceRaf, throttleRaf, waitForRaf } from "./raf/index.js";
|
package/types/now.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export let now: any;
|
package/types/raf/afterRaf.d.ts
CHANGED
|
@@ -1,8 +1,38 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Schedules a one-time delayed function using requestAnimationFrame.
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
3
|
+
*
|
|
4
|
+
* Preferred:
|
|
5
|
+
* - afterRaf(fn, duration, [options])
|
|
6
|
+
*
|
|
7
|
+
* Also supported (legacy):
|
|
8
|
+
* - afterRaf(duration, fn, [onFinish], [options])
|
|
9
|
+
*
|
|
10
|
+
* Timing model:
|
|
11
|
+
* - Uses frame timestamps for progression.
|
|
12
|
+
* - Paused time does NOT count toward elapsed time (pause freezes remaining).
|
|
13
|
+
*
|
|
14
|
+
* @param {Function|string|number} a
|
|
15
|
+
* @param {Function|string|number|Object} b
|
|
16
|
+
* @param {Function|Object} [c] - legacy onFinish OR options
|
|
17
|
+
* @param {Object} [d] - legacy options (when using 4 args)
|
|
18
|
+
* @param {Function} [c.onFinish] - optional callback after finishing (preferred: in options)
|
|
19
|
+
* @param {AbortSignal} [c.signal] - optional AbortSignal to auto-cancel
|
|
20
|
+
* @returns {{
|
|
21
|
+
* pause(): void,
|
|
22
|
+
* resume(): void,
|
|
23
|
+
* cancel(): void,
|
|
24
|
+
* reset(): void,
|
|
25
|
+
* readonly isRunning: boolean,
|
|
26
|
+
* readonly isPaused: boolean,
|
|
27
|
+
* readonly isFinished: boolean
|
|
28
|
+
* }}
|
|
7
29
|
*/
|
|
8
|
-
export function afterRaf(
|
|
30
|
+
export function afterRaf(a: Function | string | number, b: Function | string | number | Object, c?: Function | Object, d?: Object): {
|
|
31
|
+
pause(): void;
|
|
32
|
+
resume(): void;
|
|
33
|
+
cancel(): void;
|
|
34
|
+
reset(): void;
|
|
35
|
+
readonly isRunning: boolean;
|
|
36
|
+
readonly isPaused: boolean;
|
|
37
|
+
readonly isFinished: boolean;
|
|
38
|
+
};
|
|
@@ -1,10 +1,31 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Debounces a function using requestAnimationFrame.
|
|
3
|
-
* - If no duration is passed, triggers on the next frame.
|
|
4
|
-
* - If duration is passed, waits until N ms of inactivity using frame-based timing.
|
|
5
3
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
4
|
+
* Preferred:
|
|
5
|
+
* - debounceRaf(fn, [duration], [options]) // duration defaults to 0 (next frame)
|
|
6
|
+
*
|
|
7
|
+
* Also supported:
|
|
8
|
+
* - debounceRaf(duration, fn, [options])
|
|
9
|
+
* - debounceRaf(fn, [options])
|
|
10
|
+
*
|
|
11
|
+
* Timing model:
|
|
12
|
+
* - Waits until `ms` of inactivity have passed (measured using frame timestamps).
|
|
13
|
+
* - `ms = 0` means "run on the next animation frame" (still debounced).
|
|
14
|
+
*
|
|
15
|
+
* Supports:
|
|
16
|
+
* - `.cancel()` clears any pending invocation.
|
|
17
|
+
* - `.flush()` immediately invokes if pending.
|
|
18
|
+
* - Optional AbortSignal: abort cancels any pending invocation.
|
|
19
|
+
*
|
|
20
|
+
* @param {Function|string|number} a - function or duration
|
|
21
|
+
* @param {Function|string|number|Object} [b] - duration, fn, or options
|
|
22
|
+
* @param {Object} [c] - options (3-arg form)
|
|
23
|
+
* @param {AbortSignal} [c.signal] - AbortSignal to auto-cancel pending work
|
|
24
|
+
* @returns {((...args: any[]) => void) & { cancel: () => void, flush: () => void }}
|
|
9
25
|
*/
|
|
10
|
-
export function debounceRaf(
|
|
26
|
+
export function debounceRaf(a: Function | string | number, b?: Function | string | number | Object, c?: {
|
|
27
|
+
signal?: AbortSignal | undefined;
|
|
28
|
+
}): ((...args: any[]) => void) & {
|
|
29
|
+
cancel: () => void;
|
|
30
|
+
flush: () => void;
|
|
31
|
+
};
|
package/types/raf/everyRaf.d.ts
CHANGED
|
@@ -1,11 +1,41 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Repeats a function every N milliseconds using requestAnimationFrame
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
2
|
+
* Repeats a function every N milliseconds using requestAnimationFrame.
|
|
3
|
+
*
|
|
4
|
+
* Preferred:
|
|
5
|
+
* - everyRaf(fn, duration, [options])
|
|
6
|
+
*
|
|
7
|
+
* Also supported (legacy):
|
|
8
|
+
* - everyRaf(duration, fn, [maxTimes], [runImmediately], [options])
|
|
9
|
+
*
|
|
10
|
+
* Timing model:
|
|
11
|
+
* - Counts down using frame deltas.
|
|
12
|
+
* - Paused time does NOT count (pause freezes remaining-to-next-tick).
|
|
13
|
+
* - On large frame gaps, may "catch up" by running multiple ticks in one frame,
|
|
14
|
+
* but will never exceed max.
|
|
15
|
+
*
|
|
16
|
+
* @param {Function|string|number} a
|
|
17
|
+
* @param {Function|string|number|Object} b
|
|
18
|
+
* @param {number|boolean|Object} [c] - legacy maxTimes OR legacy runImmediately OR options
|
|
19
|
+
* @param {boolean|Object} [d] - legacy runImmediately OR options
|
|
20
|
+
* @param {Object} [e] - legacy options
|
|
21
|
+
* @returns {{
|
|
22
|
+
* pause(): void,
|
|
23
|
+
* resume(): void,
|
|
24
|
+
* cancel(): void,
|
|
25
|
+
* reset(restart?: boolean): void,
|
|
26
|
+
* readonly isRunning: boolean,
|
|
27
|
+
* readonly isPaused: boolean,
|
|
28
|
+
* readonly isFinished: boolean,
|
|
29
|
+
* readonly count: number
|
|
30
|
+
* }}
|
|
10
31
|
*/
|
|
11
|
-
export function everyRaf(
|
|
32
|
+
export function everyRaf(a: Function | string | number, b: Function | string | number | Object, c?: number | boolean | Object, d?: boolean | Object, e?: Object): {
|
|
33
|
+
pause(): void;
|
|
34
|
+
resume(): void;
|
|
35
|
+
cancel(): void;
|
|
36
|
+
reset(restart?: boolean): void;
|
|
37
|
+
readonly isRunning: boolean;
|
|
38
|
+
readonly isPaused: boolean;
|
|
39
|
+
readonly isFinished: boolean;
|
|
40
|
+
readonly count: number;
|
|
41
|
+
};
|
package/types/raf/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
1
|
+
export function assertRafAvailable(): void;
|
|
2
|
+
export function afterRaf(...args: any[]): any;
|
|
3
|
+
export function everyRaf(...args: any[]): any;
|
|
4
|
+
export function debounceRaf(...args: any[]): any;
|
|
5
|
+
export function throttleRaf(...args: any[]): any;
|
|
6
|
+
export function waitForRaf(...args: any[]): any;
|
|
@@ -1,12 +1,35 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Throttles a function using requestAnimationFrame with optional frame skipping.
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* - frameSkip
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
2
|
+
* Throttles a function using `requestAnimationFrame`, with optional frame skipping.
|
|
3
|
+
*
|
|
4
|
+
* Preferred:
|
|
5
|
+
* - throttleRaf(fn, [frameSkip], [options])
|
|
6
|
+
*
|
|
7
|
+
* Also supported:
|
|
8
|
+
* - throttleRaf(fn, [options]) // frameSkip defaults to 0
|
|
9
|
+
*
|
|
10
|
+
* Executes at most once every `(frameSkip + 1)` frames.
|
|
11
|
+
*
|
|
12
|
+
* Argument behavior while throttled:
|
|
13
|
+
* - trailing=true (default): uses the latest args/this seen while waiting
|
|
14
|
+
* - trailing=false: keeps the first args/this and ignores later calls until it fires
|
|
15
|
+
*
|
|
16
|
+
* AbortSignal:
|
|
17
|
+
* - If `signal` is provided, abort will cancel any pending scheduled execution.
|
|
18
|
+
* - Listener is attached only while a call is pending.
|
|
19
|
+
*
|
|
20
|
+
* @template {(...args: any[]) => any} T
|
|
21
|
+
* @param {T} fn
|
|
22
|
+
* @param {number|{signal?: AbortSignal, trailing?: boolean}} [frameSkipOrOptions=0]
|
|
23
|
+
* @param {{signal?: AbortSignal, trailing?: boolean}} [maybeOptions]
|
|
24
|
+
* @returns {T & { cancel: () => void, flush: () => void }}
|
|
11
25
|
*/
|
|
12
|
-
export function throttleRaf(fn:
|
|
26
|
+
export function throttleRaf<T extends (...args: any[]) => any>(fn: T, frameSkipOrOptions?: number | {
|
|
27
|
+
signal?: AbortSignal;
|
|
28
|
+
trailing?: boolean;
|
|
29
|
+
}, maybeOptions?: {
|
|
30
|
+
signal?: AbortSignal;
|
|
31
|
+
trailing?: boolean;
|
|
32
|
+
}): T & {
|
|
33
|
+
cancel: () => void;
|
|
34
|
+
flush: () => void;
|
|
35
|
+
};
|