-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d9208c2
commit 0224bd1
Showing
4 changed files
with
190 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,74 @@ | ||
type Series = | ||
| number | ||
| Float64Array | ||
| Float32Array | ||
| Uint32Array | ||
| Int32Array | ||
| Uint16Array | ||
| Int16Array | ||
| Uint8Array | ||
| Int8Array | ||
| Array<number>; | ||
|
||
/** | ||
* 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 }, | ||
): 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 }, | ||
): void; | ||
export function motion<List extends Array<Motion<any>>>( | ||
/** | ||
* 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: List extends Array<Motion<infer V>> ? Array<V> : never) => void, | ||
callback: (state: { [k in keyof List]: List[k] extends Motion<infer V> ? V : never }) => void, | ||
options?: { signal: AbortSignal }, | ||
): void; | ||
|
||
type Motion<Value> = { | ||
export type Motion<Value> = { | ||
update(): void; | ||
complete(): boolean; | ||
interpolate(t: number): Value; | ||
}; | ||
|
||
type SpringConfig = { damping: number; frequency: number; precision: number }; | ||
|
||
export function spring<Value = Series>( | ||
/** 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?: SpringConfig, | ||
config?: { damping: number; frequency: number; precision: number }, | ||
): Motion<Value>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters