Add .gitignore to exclude all node packages and lock files

This commit is contained in:
Adolfo Reyna
2026-02-23 21:56:04 -05:00
parent faae96c9ed
commit dcc5c6c044
9747 changed files with 1555105 additions and 2 deletions
@@ -0,0 +1,14 @@
import type { SpringConfig } from './spring-utils';
export declare function spring({ frame: passedFrame, fps, config, from, to, durationInFrames: passedDurationInFrames, durationRestThreshold, delay, reverse, }: {
frame: number;
fps: number;
config?: Partial<SpringConfig>;
from?: number;
to?: number;
durationInFrames?: number;
durationRestThreshold?: number;
delay?: number;
reverse?: boolean;
}): number;
export { measureSpring } from './measure-spring.js';
export type { SpringConfig } from './spring-utils';
@@ -0,0 +1,64 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.measureSpring = void 0;
exports.spring = spring;
const interpolate_js_1 = require("../interpolate.js");
const validate_frame_js_1 = require("../validate-frame.js");
const validate_fps_js_1 = require("../validation/validate-fps.js");
const validation_spring_duration_js_1 = require("../validation/validation-spring-duration.js");
const measure_spring_js_1 = require("./measure-spring.js");
const spring_utils_js_1 = require("./spring-utils.js");
/*
* @description Calculates a position based on physical parameters, start and end value, and time.
* @see [Documentation](https://www.remotion.dev/docs/spring)
*/
function spring({ frame: passedFrame, fps, config = {}, from = 0, to = 1, durationInFrames: passedDurationInFrames, durationRestThreshold, delay = 0, reverse = false, }) {
(0, validation_spring_duration_js_1.validateSpringDuration)(passedDurationInFrames);
(0, validate_frame_js_1.validateFrame)({
frame: passedFrame,
durationInFrames: Infinity,
allowFloats: true,
});
(0, validate_fps_js_1.validateFps)(fps, 'to spring()', false);
const needsToCalculateNaturalDuration = reverse || typeof passedDurationInFrames !== 'undefined';
const naturalDuration = needsToCalculateNaturalDuration
? (0, measure_spring_js_1.measureSpring)({
fps,
config,
threshold: durationRestThreshold,
})
: undefined;
const naturalDurationGetter = needsToCalculateNaturalDuration
? {
get: () => naturalDuration,
}
: {
get: () => {
throw new Error('did not calculate natural duration, this is an error with Remotion. Please report');
},
};
const reverseProcessed = reverse
? (passedDurationInFrames !== null && passedDurationInFrames !== void 0 ? passedDurationInFrames : naturalDurationGetter.get()) - passedFrame
: passedFrame;
const delayProcessed = reverseProcessed + (reverse ? delay : -delay);
const durationProcessed = passedDurationInFrames === undefined
? delayProcessed
: delayProcessed / (passedDurationInFrames / naturalDurationGetter.get());
if (passedDurationInFrames && delayProcessed > passedDurationInFrames) {
return to;
}
const spr = (0, spring_utils_js_1.springCalculation)({
fps,
frame: durationProcessed,
config,
});
const inner = config.overshootClamping
? to >= from
? Math.min(spr.current, to)
: Math.max(spr.current, to)
: spr.current;
const interpolated = from === 0 && to === 1 ? inner : (0, interpolate_js_1.interpolate)(inner, [0, 1], [from, to]);
return interpolated;
}
var measure_spring_js_2 = require("./measure-spring.js");
Object.defineProperty(exports, "measureSpring", { enumerable: true, get: function () { return measure_spring_js_2.measureSpring; } });
@@ -0,0 +1,13 @@
import type { ENABLE_V5_BREAKING_CHANGES } from '../v5-flag.js';
import type { SpringConfig } from './spring-utils';
type V4Props = {
from?: number;
to?: number;
};
type MeasureSpringProps = {
fps: number;
config?: Partial<SpringConfig>;
threshold?: number;
} & (false extends typeof ENABLE_V5_BREAKING_CHANGES ? V4Props : {});
export declare function measureSpring({ fps, config, threshold, }: MeasureSpringProps): number;
export {};
@@ -0,0 +1,76 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.measureSpring = measureSpring;
const validate_fps_js_1 = require("../validation/validate-fps.js");
const spring_utils_js_1 = require("./spring-utils.js");
const cache = new Map();
/*
* @description Based on a spring() configuration and the frame rate, return how long it takes for a spring animation to settle.
* @see [Documentation](https://remotion.dev/docs/measure-spring)
*/
function measureSpring({ fps, config = {}, threshold = 0.005, }) {
if (typeof threshold !== 'number') {
throw new TypeError(`threshold must be a number, got ${threshold} of type ${typeof threshold}`);
}
if (threshold === 0) {
return Infinity;
}
if (threshold === 1) {
return 0;
}
if (isNaN(threshold)) {
throw new TypeError('Threshold is NaN');
}
if (!Number.isFinite(threshold)) {
throw new TypeError('Threshold is not finite');
}
if (threshold < 0) {
throw new TypeError('Threshold is below 0');
}
const cacheKey = [
fps,
config.damping,
config.mass,
config.overshootClamping,
config.stiffness,
threshold,
].join('-');
if (cache.has(cacheKey)) {
return cache.get(cacheKey);
}
(0, validate_fps_js_1.validateFps)(fps, 'to the measureSpring() function', false);
let frame = 0;
let finishedFrame = 0;
const calc = () => {
return (0, spring_utils_js_1.springCalculation)({
fps,
frame,
config,
});
};
let animation = calc();
const calcDifference = () => {
return Math.abs(animation.current - animation.toValue);
};
let difference = calcDifference();
while (difference >= threshold) {
frame++;
animation = calc();
difference = calcDifference();
}
// Since spring is bouncy, just because it's under the threshold we
// cannot be sure it's done. We need to animate further until it stays in the
// threshold for, say, 20 frames.
finishedFrame = frame;
for (let i = 0; i < 20; i++) {
frame++;
animation = calc();
difference = calcDifference();
if (difference >= threshold) {
i = 0;
finishedFrame = frame + 1;
}
}
cache.set(cacheKey, finishedFrame);
return finishedFrame;
}
@@ -0,0 +1,19 @@
type AnimationNode = {
lastTimestamp: number;
toValue: number;
current: number;
velocity: number;
prevPosition?: number;
};
export type SpringConfig = {
damping: number;
mass: number;
stiffness: number;
overshootClamping: boolean;
};
export declare function springCalculation({ frame, fps, config, }: {
frame: number;
fps: number;
config?: Partial<SpringConfig>;
}): AnimationNode;
export {};
@@ -0,0 +1,105 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.springCalculation = springCalculation;
const defaultSpringConfig = {
damping: 10,
mass: 1,
stiffness: 100,
overshootClamping: false,
};
const advanceCache = {};
function advance({ animation, now, config, }) {
const { toValue, lastTimestamp, current, velocity } = animation;
const deltaTime = Math.min(now - lastTimestamp, 64);
if (config.damping <= 0) {
throw new Error('Spring damping must be greater than 0, otherwise the spring() animation will never end, causing an infinite loop.');
}
const c = config.damping;
const m = config.mass;
const k = config.stiffness;
const cacheKey = [
toValue,
lastTimestamp,
current,
velocity,
c,
m,
k,
now,
].join('-');
if (advanceCache[cacheKey]) {
return advanceCache[cacheKey];
}
const v0 = -velocity;
const x0 = toValue - current;
const zeta = c / (2 * Math.sqrt(k * m)); // damping ratio
const omega0 = Math.sqrt(k / m); // undamped angular frequency of the oscillator (rad/ms)
const omega1 = omega0 * Math.sqrt(1 - zeta ** 2); // exponential decay
const t = deltaTime / 1000;
const sin1 = Math.sin(omega1 * t);
const cos1 = Math.cos(omega1 * t);
// under damped
const underDampedEnvelope = Math.exp(-zeta * omega0 * t);
const underDampedFrag1 = underDampedEnvelope *
(sin1 * ((v0 + zeta * omega0 * x0) / omega1) + x0 * cos1);
const underDampedPosition = toValue - underDampedFrag1;
// This looks crazy -- it's actually just the derivative of the oscillation function
const underDampedVelocity = zeta * omega0 * underDampedFrag1 -
underDampedEnvelope *
(cos1 * (v0 + zeta * omega0 * x0) - omega1 * x0 * sin1);
// critically damped
const criticallyDampedEnvelope = Math.exp(-omega0 * t);
const criticallyDampedPosition = toValue - criticallyDampedEnvelope * (x0 + (v0 + omega0 * x0) * t);
const criticallyDampedVelocity = criticallyDampedEnvelope *
(v0 * (t * omega0 - 1) + t * x0 * omega0 * omega0);
const animationNode = {
toValue,
prevPosition: current,
lastTimestamp: now,
current: zeta < 1 ? underDampedPosition : criticallyDampedPosition,
velocity: zeta < 1 ? underDampedVelocity : criticallyDampedVelocity,
};
advanceCache[cacheKey] = animationNode;
return animationNode;
}
const calculationCache = {};
function springCalculation({ frame, fps, config = {}, }) {
const from = 0;
const to = 1;
const cacheKey = [
frame,
fps,
config.damping,
config.mass,
config.overshootClamping,
config.stiffness,
].join('-');
if (calculationCache[cacheKey]) {
return calculationCache[cacheKey];
}
let animation = {
lastTimestamp: 0,
current: from,
toValue: to,
velocity: 0,
prevPosition: 0,
};
const frameClamped = Math.max(0, frame);
const unevenRest = frameClamped % 1;
for (let f = 0; f <= Math.floor(frameClamped); f++) {
if (f === Math.floor(frameClamped)) {
f += unevenRest;
}
const time = (f / fps) * 1000;
animation = advance({
animation,
now: time,
config: {
...defaultSpringConfig,
...config,
},
});
}
calculationCache[cacheKey] = animation;
return animation;
}