Skip to content

🎥 Make videos programmatically with React

apply prettier

Jonny Burgerdd75f5552f69
diff --git a/packages/core/src/spring.ts b/packages/core/src/spring.ts
index b140b4df25..b2b8a2e10b 100644
--- a/packages/core/src/spring.ts
+++ b/packages/core/src/spring.ts
@@ -3,8 +3,8 @@ type AnimationNode = {
toValue: number;
current: number;
velocity: number;
- isFinished?: boolean;
- prevPosition?: number;
+ isFinished?: boolean;
+ prevPosition?: number;
};
export type SpringConfig = {
@@ -70,27 +70,27 @@ function advance(
criticallyDampedEnvelope *
(v0 * (t * omega0 - 1) + t * x0 * omega0 * omega0);
+ let isOvershooting;
+ if (config.overshootClamping && config.stiffness != 0) {
+ if (animation.prevPosition != null && animation.prevPosition < toValue) {
+ isOvershooting = current > toValue;
+ } else {
+ isOvershooting = current < toValue;
+ }
+ } else {
+ isOvershooting = false;
+ }
- let isOvershooting
- if(config.overshootClamping && config.stiffness != 0){
- if(animation.prevPosition != null && animation.prevPosition < toValue){
- isOvershooting = current > toValue
- }else{
- isOvershooting = current < toValue
- }
- }else{
- isOvershooting = false
- }
-
- const isVelocity = Math.abs(animation.velocity) < 0.001;
+ const isVelocity = Math.abs(animation.velocity) < 0.001;
- const isDisplacement = (config.stiffness == 0) || (Math.abs(toValue - current) < 0.001);
+ const isDisplacement =
+ config.stiffness == 0 || Math.abs(toValue - current) < 0.001;
- if(isOvershooting == true || (isVelocity && isDisplacement)){
- copiedAnimated.isFinished = true
- }
+ if (isOvershooting == true || (isVelocity && isDisplacement)) {
+ copiedAnimated.isFinished = true;
+ }
- copiedAnimated.prevPosition = current
+ copiedAnimated.prevPosition = current;
if (zeta < 1) {
copiedAnimated.current = underDampedPosition;
copiedAnimated.velocity = underDampedVelocity;
@@ -108,22 +108,22 @@ function springCalculation({
frame,
fps,
config = {},
- prevPosition = 0,
+ prevPosition = 0,
}: {
from?: number;
to?: number;
frame: number;
fps: number;
config?: Partial<SpringConfig>;
- prevPosition ?: number;
+ prevPosition?: number;
}): AnimationNode {
let animation: AnimationNode = {
lastTimestamp: 0,
current: from,
toValue: to,
velocity: 0,
- isFinished: false,
- prevPosition
+ isFinished: false,
+ prevPosition,
};
const frameClamped = Math.max(0, frame);
const unevenRest = frameClamped % 1;
@@ -153,7 +153,7 @@ export function spring({
fps: number;
config?: Partial<SpringConfig>;
}): number {
- return springCalculation({fps, frame, config, from, to}).current
+ return springCalculation({fps, frame, config, from, to}).current;
}
export function measureSpring({
@@ -167,11 +167,25 @@ export function measureSpring({
fps: number;
config?: Partial<SpringConfig>;
}): number {
- let iteration = 0;
- let animation = springCalculation({prevPosition: 0, fps, frame: iteration, config, from, to})
- while(!animation.isFinished){
- animation = springCalculation({prevPosition: animation.prevPosition, fps, frame: iteration++, config, from, to})
- }
- //minus 1 because the last calculate animation was finished
- return iteration - 1;
-}
\ No newline at end of file
+ let iteration = 0;
+ let animation = springCalculation({
+ prevPosition: 0,
+ fps,
+ frame: iteration,
+ config,
+ from,
+ to,
+ });
+ while (!animation.isFinished) {
+ animation = springCalculation({
+ prevPosition: animation.prevPosition,
+ fps,
+ frame: iteration++,
+ config,
+ from,
+ to,
+ });
+ }
+ //minus 1 because the last calculate animation was finished
+ return iteration - 1;
+}