Skip to content

Commit

Permalink
expose spring's destination override
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeyraspopov committed Oct 21, 2024
1 parent d3b48db commit b88328a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 10 deletions.
9 changes: 0 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,6 @@ Parameters:
Supports various numeric types: `number`, `Float64Array`, `Float32Array`, `Uint32Array`,
`Int32Array`, `Uint16Array`, `Int16Array`, `Uint8Array`, `Int8Array`, `Array<number>`.

## Types

Extra types provided for TypeScript:

- `Motion<Value>`: Represents an animatable value with methods:
- `update()`: Updates the motion state.
- `complete()`: Checks if the motion is complete.
- `interpolate(t: number)`: Interpolates the motion value at a given time t.

## Cancelling Animations

You can cancel ongoing animations using an `AbortSignal`:
Expand Down
6 changes: 6 additions & 0 deletions modules/spring.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ function singlespring(current, destination, damping, stiffness, precision) {
velocity = tuple[1];
}
},
destination(v) {
destination = v;
},
complete() {
if (velocity !== 0 || current !== destination) return false;
return true;
Expand Down Expand Up @@ -68,6 +71,9 @@ function multispring(current, destination, damping, stiffness, precision) {
}
}
},
destination(v) {
destination = v;
},
complete() {
for (let i = 0; i < current.length; i++) {
if (velocity[i] !== 0 || current[i] !== destination[i]) return false;
Expand Down
1 change: 1 addition & 0 deletions oscillation.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export function motion<List extends [Motion<any>, ...Motion<any>[]]>(

export type Motion<Value> = {
update(n: number): void;
destination(v: Value): void;
complete(): boolean;
interpolate(t: number): Value;
};
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "oscillation",
"description": "An animation library",
"version": "0.4.0",
"version": "0.4.1",
"license": "ISC",
"author": "Oleksii Raspopov",
"repository": "UnknownPrinciple/oscillation",
Expand Down

0 comments on commit b88328a

Please sign in to comment.