-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoscillation.d.ts
75 lines (73 loc) · 2.2 KB
/
oscillation.d.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
73
74
75
/**
* Starts an animation and calls the callback with updated values on each frame.
* Provided motion defition is a single motion object.
*
* ```js
* motion(spring(0, 100), (value) => {
* // value gets animated from 0 to 100
* });
* ```
*/
export function motion<Value extends Motion<any>>(
defs: Value,
callback: (state: Value extends Motion<infer V> ? V : never) => void,
options?: { signal?: AbortSignal; ignoreReducedMotion?: boolean },
): void;
/**
* Starts an animation and calls the callback with updated values on each frame.
* Provided motion defition is a single motion object.
*
* ```js
* motion({ x: spring(0, 100), y: spring(-50, 50) }, ({ x, y }) => {
* // callback receives an object which shape follows motion definition
* // x and y animated simultaneously
* });
* ```
*/
export function motion<Dict extends { [k: string]: Motion<any> }>(
defs: Dict,
callback: (state: { [k in keyof Dict]: Dict[k] extends Motion<infer V> ? V : never }) => void,
options?: { signal?: AbortSignal; ignoreReducedMotion?: boolean },
): void;
/**
* Starts an animation and calls the callback with updated values on each frame.
* Provided motion defition is a single motion object.
*
* ```js
* motion([
* spring([0, 0, 0], [255, 128, 0]),
* spring(0, 360),
* ], ([color, rotation]) => {
* // callback receives an array which elements follow the motion definition
* });
* ```
*/
export function motion<List extends [Motion<any>, ...Motion<any>[]]>(
defs: List,
callback: (state: { [k in keyof List]: List[k] extends Motion<infer V> ? V : never }) => void,
options?: { signal?: AbortSignal; ignoreReducedMotion?: boolean },
): void;
export type Motion<Value> = {
update(n: number): void;
destination(v: Value): void;
complete(): boolean;
interpolate(t: number): Value;
};
/** Creates a spring-based motion between source and destination values. */
export function spring<
Value =
| number
| Float64Array
| Float32Array
| Uint32Array
| Int32Array
| Uint16Array
| Int16Array
| Uint8Array
| Int8Array
| Array<number>,
>(
source: Value,
destination: Value,
config?: { damping: number; frequency: number; precision: number },
): Motion<Value>;