Skip to content

Commit

Permalink
fix(@okikio/animate): 🐛 use -/+ Infinity as initial value for minDela…
Browse files Browse the repository at this point in the history
…y, maxSpeed, totalDuration
  • Loading branch information
okikio committed May 28, 2021
1 parent e268160 commit 9aeec2e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"scss.lint.unknownProperties": "ignore",
"scss.validate": false,
"conventionalCommits.scopes": [
"demo"
"demo",
"@okikio/animate"
],
"npm.packageManager": "pnpm"
}
22 changes: 14 additions & 8 deletions packages/animate/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,17 +255,17 @@ export class Animate {
/**
* The total duration of all Animation's
*/
public totalDuration: number = 0;
public totalDuration: number = -Infinity;

/**
* The smallest delay out of all Animation's
*/
public minDelay: number;
public minDelay: number = Infinity;

/**
* The smallest speed out of all Animation's
*/
public maxSpeed: number;
public maxSpeed: number = Infinity;

/**
* The Element the mainAnimation runs on
Expand Down Expand Up @@ -731,8 +731,8 @@ export class Animate {
iterations,
};

if (!isValid(this.minDelay) || delay < this.minDelay) this.minDelay = delay;
if (!isValid(this.maxSpeed) || speed < this.maxSpeed) this.maxSpeed = speed;
if (this.minDelay > delay) this.minDelay = delay;
if (this.maxSpeed > speed) this.maxSpeed = speed;
});
return result;
}
Expand Down Expand Up @@ -908,9 +908,15 @@ export class Animate {
timeline
}, len);

this.maxSpeed = this.maxSpeed ?? this.options.speed as number;
this.minDelay = this.minDelay ?? this.options.delay as number;
this.totalDuration = this.totalDuration ?? this.options.duration as number;
// If the total number of targets is zero or less, it means there not values in `arrOfComputedOptions`
// So, set the values for `totalDuration`, `minDelay`, and `maxSpeed` to the options directly
// This is for anyone who wants to build a `timeline` in the future
if (len <= 0) {
if (this.maxSpeed == Infinity) this.maxSpeed = Number(this.options.speed);
if (this.minDelay == Infinity)
this.minDelay = Number(this.options.delay) + Number(this.options.timelineOffset);
if (this.totalDuration == -Infinity) this.totalDuration = Number(this.options.duration);
}

if (!this.mainAnimation) {
this.mainkeyframeEffect = new KeyframeEffect(this.mainElement, [
Expand Down

0 comments on commit 9aeec2e

Please sign in to comment.