/
types.ts
72 lines (67 loc) · 2.07 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import type {ThreadGenerator} from '../threading';
import type {InterpolationFunction, TimingFunction} from '../tweening';
import {DEFAULT} from './symbols';
export type SignalValue<TValue> = TValue | (() => TValue);
export type SignalGenerator<
TSetterValue,
TValue extends TSetterValue,
> = ThreadGenerator & {
/**
* Tween to the specified value.
*/
to: SignalTween<TSetterValue, TValue>;
/**
* Tween back to the original value.
*
* @param time - The duration of the tween.
* @param timingFunction - The timing function of the tween.
* @param interpolationFunction - The interpolation function of the tween.
*/
back: (
time: number,
timingFunction?: TimingFunction,
interpolationFunction?: InterpolationFunction<TValue>,
) => SignalGenerator<TSetterValue, TValue>;
/**
* Wait for the specified duration.
*
* @param duration - The duration to wait.
*/
wait: (duration: number) => SignalGenerator<TSetterValue, TValue>;
/**
* Run the given task.
*
* @param task - The generator to run.
*/
run: (task: ThreadGenerator) => SignalGenerator<TSetterValue, TValue>;
/**
* Invoke the given callback.
*
* @param callback - The callback to invoke.
*/
do: (callback: () => void) => SignalGenerator<TSetterValue, TValue>;
};
export interface SignalSetter<TValue, TOwner = void> {
(value: SignalValue<TValue> | typeof DEFAULT): TOwner;
}
export interface SignalGetter<TValue> {
(): TValue;
}
export interface SignalTween<TSetterValue, TValue extends TSetterValue> {
(
value: SignalValue<TSetterValue> | typeof DEFAULT,
time: number,
timingFunction?: TimingFunction,
interpolationFunction?: InterpolationFunction<TValue>,
): SignalGenerator<TSetterValue, TValue>;
}
export interface SignalExtensions<TSetterValue, TValue extends TSetterValue> {
getter: SignalGetter<TValue>;
setter: SignalSetter<TSetterValue>;
tweener(
value: SignalValue<TSetterValue>,
time: number,
timingFunction?: TimingFunction,
interpolationFunction?: InterpolationFunction<TValue>,
): ThreadGenerator;
}