remotion 4.0.508 → 4.0.509
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/RemotionRoot.d.ts +1 -0
- package/dist/cjs/RemotionRoot.js +2 -2
- package/dist/cjs/audio/shared-audio-tags.d.ts +2 -0
- package/dist/cjs/audio/shared-audio-tags.js +74 -5
- package/dist/cjs/audio/wait-until-actually-resumed.js +21 -8
- package/dist/cjs/internals.d.ts +5 -1
- package/dist/cjs/interpolate.js +81 -2
- package/dist/cjs/use-schema.d.ts +2 -1
- package/dist/cjs/use-schema.js +3 -3
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/index.mjs +147 -16
- package/dist/esm/no-react.mjs +607 -72
- package/dist/esm/version.mjs +1 -1
- package/package.json +2 -2
package/dist/esm/no-react.mjs
CHANGED
|
@@ -1,3 +1,511 @@
|
|
|
1
|
+
// src/bezier.ts
|
|
2
|
+
var NEWTON_ITERATIONS = 4;
|
|
3
|
+
var NEWTON_MIN_SLOPE = 0.001;
|
|
4
|
+
var SUBDIVISION_PRECISION = 0.0000001;
|
|
5
|
+
var SUBDIVISION_MAX_ITERATIONS = 10;
|
|
6
|
+
var kSplineTableSize = 11;
|
|
7
|
+
var kSampleStepSize = 1 / (kSplineTableSize - 1);
|
|
8
|
+
var float32ArraySupported = typeof Float32Array === "function";
|
|
9
|
+
function a(aA1, aA2) {
|
|
10
|
+
return 1 - 3 * aA2 + 3 * aA1;
|
|
11
|
+
}
|
|
12
|
+
function b(aA1, aA2) {
|
|
13
|
+
return 3 * aA2 - 6 * aA1;
|
|
14
|
+
}
|
|
15
|
+
function c(aA1) {
|
|
16
|
+
return 3 * aA1;
|
|
17
|
+
}
|
|
18
|
+
function calcBezier(aT, aA1, aA2) {
|
|
19
|
+
return ((a(aA1, aA2) * aT + b(aA1, aA2)) * aT + c(aA1)) * aT;
|
|
20
|
+
}
|
|
21
|
+
function getSlope(aT, aA1, aA2) {
|
|
22
|
+
return 3 * a(aA1, aA2) * aT * aT + 2 * b(aA1, aA2) * aT + c(aA1);
|
|
23
|
+
}
|
|
24
|
+
function binarySubdivide({
|
|
25
|
+
aX,
|
|
26
|
+
_aA,
|
|
27
|
+
_aB,
|
|
28
|
+
mX1,
|
|
29
|
+
mX2
|
|
30
|
+
}) {
|
|
31
|
+
let currentX;
|
|
32
|
+
let currentT;
|
|
33
|
+
let i = 0;
|
|
34
|
+
let aA = _aA;
|
|
35
|
+
let aB = _aB;
|
|
36
|
+
do {
|
|
37
|
+
currentT = aA + (aB - aA) / 2;
|
|
38
|
+
currentX = calcBezier(currentT, mX1, mX2) - aX;
|
|
39
|
+
if (currentX > 0) {
|
|
40
|
+
aB = currentT;
|
|
41
|
+
} else {
|
|
42
|
+
aA = currentT;
|
|
43
|
+
}
|
|
44
|
+
} while (Math.abs(currentX) > SUBDIVISION_PRECISION && ++i < SUBDIVISION_MAX_ITERATIONS);
|
|
45
|
+
return currentT;
|
|
46
|
+
}
|
|
47
|
+
function newtonRaphsonIterate(aX, _aGuessT, mX1, mX2) {
|
|
48
|
+
let aGuessT = _aGuessT;
|
|
49
|
+
for (let i = 0;i < NEWTON_ITERATIONS; ++i) {
|
|
50
|
+
const currentSlope = getSlope(aGuessT, mX1, mX2);
|
|
51
|
+
if (currentSlope === 0) {
|
|
52
|
+
return aGuessT;
|
|
53
|
+
}
|
|
54
|
+
const currentX = calcBezier(aGuessT, mX1, mX2) - aX;
|
|
55
|
+
aGuessT -= currentX / currentSlope;
|
|
56
|
+
}
|
|
57
|
+
return aGuessT;
|
|
58
|
+
}
|
|
59
|
+
function bezier(mX1, mY1, mX2, mY2) {
|
|
60
|
+
if (!(mX1 >= 0 && mX1 <= 1 && mX2 >= 0 && mX2 <= 1)) {
|
|
61
|
+
throw new Error("bezier x values must be in [0, 1] range");
|
|
62
|
+
}
|
|
63
|
+
const sampleValues = float32ArraySupported ? new Float32Array(kSplineTableSize) : new Array(kSplineTableSize);
|
|
64
|
+
if (mX1 !== mY1 || mX2 !== mY2) {
|
|
65
|
+
for (let i = 0;i < kSplineTableSize; ++i) {
|
|
66
|
+
sampleValues[i] = calcBezier(i * kSampleStepSize, mX1, mX2);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function getTForX(aX) {
|
|
70
|
+
let intervalStart = 0;
|
|
71
|
+
let currentSample = 1;
|
|
72
|
+
const lastSample = kSplineTableSize - 1;
|
|
73
|
+
for (;currentSample !== lastSample && sampleValues[currentSample] <= aX; ++currentSample) {
|
|
74
|
+
intervalStart += kSampleStepSize;
|
|
75
|
+
}
|
|
76
|
+
--currentSample;
|
|
77
|
+
const dist = (aX - sampleValues[currentSample]) / (sampleValues[currentSample + 1] - sampleValues[currentSample]);
|
|
78
|
+
const guessForT = intervalStart + dist * kSampleStepSize;
|
|
79
|
+
const initialSlope = getSlope(guessForT, mX1, mX2);
|
|
80
|
+
if (initialSlope >= NEWTON_MIN_SLOPE) {
|
|
81
|
+
return newtonRaphsonIterate(aX, guessForT, mX1, mX2);
|
|
82
|
+
}
|
|
83
|
+
if (initialSlope === 0) {
|
|
84
|
+
return guessForT;
|
|
85
|
+
}
|
|
86
|
+
return binarySubdivide({
|
|
87
|
+
aX,
|
|
88
|
+
_aA: intervalStart,
|
|
89
|
+
_aB: intervalStart + kSampleStepSize,
|
|
90
|
+
mX1,
|
|
91
|
+
mX2
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
return function(x) {
|
|
95
|
+
const clampedX = Math.min(1, Math.max(0, x));
|
|
96
|
+
if (mX1 === mY1 && mX2 === mY2) {
|
|
97
|
+
return clampedX;
|
|
98
|
+
}
|
|
99
|
+
if (clampedX === 0) {
|
|
100
|
+
return 0;
|
|
101
|
+
}
|
|
102
|
+
if (clampedX === 1) {
|
|
103
|
+
return 1;
|
|
104
|
+
}
|
|
105
|
+
return calcBezier(getTForX(clampedX), mY1, mY2);
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// src/validate-frame.ts
|
|
110
|
+
var validateFrame = ({
|
|
111
|
+
allowFloats,
|
|
112
|
+
durationInFrames,
|
|
113
|
+
frame
|
|
114
|
+
}) => {
|
|
115
|
+
if (typeof frame === "undefined") {
|
|
116
|
+
throw new TypeError(`Argument missing for parameter "frame"`);
|
|
117
|
+
}
|
|
118
|
+
if (typeof frame !== "number") {
|
|
119
|
+
throw new TypeError(`Argument passed for "frame" is not a number: ${frame}`);
|
|
120
|
+
}
|
|
121
|
+
if (!Number.isFinite(frame)) {
|
|
122
|
+
throw new RangeError(`Frame ${frame} is not finite`);
|
|
123
|
+
}
|
|
124
|
+
if (frame % 1 !== 0 && !allowFloats) {
|
|
125
|
+
throw new RangeError(`Argument for frame must be an integer, but got ${frame}`);
|
|
126
|
+
}
|
|
127
|
+
if (frame < 0 && frame < -durationInFrames) {
|
|
128
|
+
throw new RangeError(`Cannot use frame ${frame}: Duration of composition is ${durationInFrames}, therefore the lowest frame that can be rendered is ${-durationInFrames}`);
|
|
129
|
+
}
|
|
130
|
+
if (frame > durationInFrames - 1) {
|
|
131
|
+
throw new RangeError(`Cannot use frame ${frame}: Duration of composition is ${durationInFrames}, therefore the highest frame that can be rendered is ${durationInFrames - 1}`);
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
// src/validation/validate-fps.ts
|
|
136
|
+
function validateFps(fps, location, isGif) {
|
|
137
|
+
if (typeof fps !== "number") {
|
|
138
|
+
throw new Error(`"fps" must be a number, but you passed a value of type ${typeof fps} ${location}`);
|
|
139
|
+
}
|
|
140
|
+
if (!Number.isFinite(fps)) {
|
|
141
|
+
throw new Error(`"fps" must be a finite, but you passed ${fps} ${location}`);
|
|
142
|
+
}
|
|
143
|
+
if (isNaN(fps)) {
|
|
144
|
+
throw new Error(`"fps" must not be NaN, but got ${fps} ${location}`);
|
|
145
|
+
}
|
|
146
|
+
if (fps <= 0) {
|
|
147
|
+
throw new TypeError(`"fps" must be positive, but got ${fps} ${location}`);
|
|
148
|
+
}
|
|
149
|
+
if (isGif && fps > 50) {
|
|
150
|
+
throw new TypeError(`The FPS for a GIF cannot be higher than 50. Use the --every-nth-frame option to lower the FPS: https://remotion.dev/docs/render-as-gif`);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// src/validation/validation-spring-duration.ts
|
|
155
|
+
var validateSpringDuration = (dur) => {
|
|
156
|
+
if (typeof dur === "undefined") {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
if (typeof dur !== "number") {
|
|
160
|
+
throw new TypeError(`A "duration" of a spring must be a "number" but is "${typeof dur}"`);
|
|
161
|
+
}
|
|
162
|
+
if (Number.isNaN(dur)) {
|
|
163
|
+
throw new TypeError('A "duration" of a spring is NaN, which it must not be');
|
|
164
|
+
}
|
|
165
|
+
if (!Number.isFinite(dur)) {
|
|
166
|
+
throw new TypeError('A "duration" of a spring must be finite, but is ' + dur);
|
|
167
|
+
}
|
|
168
|
+
if (dur <= 0) {
|
|
169
|
+
throw new TypeError('A "duration" of a spring must be positive, but is ' + dur);
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
// src/spring/spring-utils.ts
|
|
174
|
+
var defaultSpringConfig = {
|
|
175
|
+
damping: 10,
|
|
176
|
+
mass: 1,
|
|
177
|
+
stiffness: 100,
|
|
178
|
+
overshootClamping: false
|
|
179
|
+
};
|
|
180
|
+
var advanceCache = {};
|
|
181
|
+
function advance({
|
|
182
|
+
animation,
|
|
183
|
+
now,
|
|
184
|
+
config
|
|
185
|
+
}) {
|
|
186
|
+
const { toValue, lastTimestamp, current, velocity } = animation;
|
|
187
|
+
const deltaTime = Math.min(now - lastTimestamp, 64);
|
|
188
|
+
if (config.damping <= 0) {
|
|
189
|
+
throw new Error("Spring damping must be greater than 0, otherwise the spring() animation will never end, causing an infinite loop.");
|
|
190
|
+
}
|
|
191
|
+
const c2 = config.damping;
|
|
192
|
+
const m = config.mass;
|
|
193
|
+
const k = config.stiffness;
|
|
194
|
+
const cacheKey = [
|
|
195
|
+
toValue,
|
|
196
|
+
lastTimestamp,
|
|
197
|
+
current,
|
|
198
|
+
velocity,
|
|
199
|
+
c2,
|
|
200
|
+
m,
|
|
201
|
+
k,
|
|
202
|
+
now
|
|
203
|
+
].join("-");
|
|
204
|
+
if (advanceCache[cacheKey]) {
|
|
205
|
+
return advanceCache[cacheKey];
|
|
206
|
+
}
|
|
207
|
+
const v0 = -velocity;
|
|
208
|
+
const x0 = toValue - current;
|
|
209
|
+
const zeta = c2 / (2 * Math.sqrt(k * m));
|
|
210
|
+
const omega0 = Math.sqrt(k / m);
|
|
211
|
+
const omega1 = omega0 * Math.sqrt(1 - zeta ** 2);
|
|
212
|
+
const t = deltaTime / 1000;
|
|
213
|
+
const sin1 = Math.sin(omega1 * t);
|
|
214
|
+
const cos1 = Math.cos(omega1 * t);
|
|
215
|
+
const underDampedEnvelope = Math.exp(-zeta * omega0 * t);
|
|
216
|
+
const underDampedFrag1 = underDampedEnvelope * (sin1 * ((v0 + zeta * omega0 * x0) / omega1) + x0 * cos1);
|
|
217
|
+
const underDampedPosition = toValue - underDampedFrag1;
|
|
218
|
+
const underDampedVelocity = zeta * omega0 * underDampedFrag1 - underDampedEnvelope * (cos1 * (v0 + zeta * omega0 * x0) - omega1 * x0 * sin1);
|
|
219
|
+
const criticallyDampedEnvelope = Math.exp(-omega0 * t);
|
|
220
|
+
const criticallyDampedPosition = toValue - criticallyDampedEnvelope * (x0 + (v0 + omega0 * x0) * t);
|
|
221
|
+
const criticallyDampedVelocity = criticallyDampedEnvelope * (v0 * (t * omega0 - 1) + t * x0 * omega0 * omega0);
|
|
222
|
+
const animationNode = {
|
|
223
|
+
toValue,
|
|
224
|
+
prevPosition: current,
|
|
225
|
+
lastTimestamp: now,
|
|
226
|
+
current: zeta < 1 ? underDampedPosition : criticallyDampedPosition,
|
|
227
|
+
velocity: zeta < 1 ? underDampedVelocity : criticallyDampedVelocity
|
|
228
|
+
};
|
|
229
|
+
advanceCache[cacheKey] = animationNode;
|
|
230
|
+
return animationNode;
|
|
231
|
+
}
|
|
232
|
+
var calculationCache = {};
|
|
233
|
+
function springCalculation({
|
|
234
|
+
frame,
|
|
235
|
+
fps,
|
|
236
|
+
config = {}
|
|
237
|
+
}) {
|
|
238
|
+
const from = 0;
|
|
239
|
+
const to = 1;
|
|
240
|
+
const cacheKey = [
|
|
241
|
+
frame,
|
|
242
|
+
fps,
|
|
243
|
+
config.damping,
|
|
244
|
+
config.mass,
|
|
245
|
+
config.overshootClamping,
|
|
246
|
+
config.stiffness
|
|
247
|
+
].join("-");
|
|
248
|
+
if (calculationCache[cacheKey]) {
|
|
249
|
+
return calculationCache[cacheKey];
|
|
250
|
+
}
|
|
251
|
+
let animation = {
|
|
252
|
+
lastTimestamp: 0,
|
|
253
|
+
current: from,
|
|
254
|
+
toValue: to,
|
|
255
|
+
velocity: 0,
|
|
256
|
+
prevPosition: 0
|
|
257
|
+
};
|
|
258
|
+
const frameClamped = Math.max(0, frame);
|
|
259
|
+
const unevenRest = frameClamped % 1;
|
|
260
|
+
for (let f = 0;f <= Math.floor(frameClamped); f++) {
|
|
261
|
+
if (f === Math.floor(frameClamped)) {
|
|
262
|
+
f += unevenRest;
|
|
263
|
+
}
|
|
264
|
+
const time = f / fps * 1000;
|
|
265
|
+
animation = advance({
|
|
266
|
+
animation,
|
|
267
|
+
now: time,
|
|
268
|
+
config: {
|
|
269
|
+
...defaultSpringConfig,
|
|
270
|
+
...config
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
calculationCache[cacheKey] = animation;
|
|
275
|
+
return animation;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// src/spring/measure-spring.ts
|
|
279
|
+
var cache = new Map;
|
|
280
|
+
function measureSpring({
|
|
281
|
+
fps,
|
|
282
|
+
config = {},
|
|
283
|
+
threshold = 0.005
|
|
284
|
+
}) {
|
|
285
|
+
if (typeof threshold !== "number") {
|
|
286
|
+
throw new TypeError(`threshold must be a number, got ${threshold} of type ${typeof threshold}`);
|
|
287
|
+
}
|
|
288
|
+
if (threshold === 0) {
|
|
289
|
+
return Infinity;
|
|
290
|
+
}
|
|
291
|
+
if (threshold === 1) {
|
|
292
|
+
return 0;
|
|
293
|
+
}
|
|
294
|
+
if (isNaN(threshold)) {
|
|
295
|
+
throw new TypeError("Threshold is NaN");
|
|
296
|
+
}
|
|
297
|
+
if (!Number.isFinite(threshold)) {
|
|
298
|
+
throw new TypeError("Threshold is not finite");
|
|
299
|
+
}
|
|
300
|
+
if (threshold < 0) {
|
|
301
|
+
throw new TypeError("Threshold is below 0");
|
|
302
|
+
}
|
|
303
|
+
const cacheKey = [
|
|
304
|
+
fps,
|
|
305
|
+
config.damping,
|
|
306
|
+
config.mass,
|
|
307
|
+
config.overshootClamping,
|
|
308
|
+
config.stiffness,
|
|
309
|
+
threshold
|
|
310
|
+
].join("-");
|
|
311
|
+
if (cache.has(cacheKey)) {
|
|
312
|
+
return cache.get(cacheKey);
|
|
313
|
+
}
|
|
314
|
+
validateFps(fps, "to the measureSpring() function", false);
|
|
315
|
+
let frame = 0;
|
|
316
|
+
let finishedFrame = 0;
|
|
317
|
+
const calc = () => {
|
|
318
|
+
return springCalculation({
|
|
319
|
+
fps,
|
|
320
|
+
frame,
|
|
321
|
+
config
|
|
322
|
+
});
|
|
323
|
+
};
|
|
324
|
+
let animation = calc();
|
|
325
|
+
const calcDifference = () => {
|
|
326
|
+
return Math.abs(animation.current - animation.toValue);
|
|
327
|
+
};
|
|
328
|
+
let difference = calcDifference();
|
|
329
|
+
while (difference >= threshold) {
|
|
330
|
+
frame++;
|
|
331
|
+
animation = calc();
|
|
332
|
+
difference = calcDifference();
|
|
333
|
+
}
|
|
334
|
+
finishedFrame = frame;
|
|
335
|
+
for (let i = 0;i < 20; i++) {
|
|
336
|
+
frame++;
|
|
337
|
+
animation = calc();
|
|
338
|
+
difference = calcDifference();
|
|
339
|
+
if (difference >= threshold) {
|
|
340
|
+
i = 0;
|
|
341
|
+
finishedFrame = frame + 1;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
cache.set(cacheKey, finishedFrame);
|
|
345
|
+
return finishedFrame;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
// src/spring/index.ts
|
|
349
|
+
function spring({
|
|
350
|
+
frame: passedFrame,
|
|
351
|
+
fps,
|
|
352
|
+
config = {},
|
|
353
|
+
from = 0,
|
|
354
|
+
to = 1,
|
|
355
|
+
durationInFrames: passedDurationInFrames,
|
|
356
|
+
durationRestThreshold,
|
|
357
|
+
delay = 0,
|
|
358
|
+
reverse = false
|
|
359
|
+
}) {
|
|
360
|
+
validateSpringDuration(passedDurationInFrames);
|
|
361
|
+
validateFrame({
|
|
362
|
+
frame: passedFrame,
|
|
363
|
+
durationInFrames: Infinity,
|
|
364
|
+
allowFloats: true
|
|
365
|
+
});
|
|
366
|
+
validateFps(fps, "to spring()", false);
|
|
367
|
+
const needsToCalculateNaturalDuration = reverse || typeof passedDurationInFrames !== "undefined";
|
|
368
|
+
const naturalDuration = needsToCalculateNaturalDuration ? measureSpring({
|
|
369
|
+
fps,
|
|
370
|
+
config,
|
|
371
|
+
threshold: durationRestThreshold
|
|
372
|
+
}) : undefined;
|
|
373
|
+
const naturalDurationGetter = needsToCalculateNaturalDuration ? {
|
|
374
|
+
get: () => naturalDuration
|
|
375
|
+
} : {
|
|
376
|
+
get: () => {
|
|
377
|
+
throw new Error("did not calculate natural duration, this is an error with Remotion. Please report");
|
|
378
|
+
}
|
|
379
|
+
};
|
|
380
|
+
const reverseProcessed = reverse ? (passedDurationInFrames ?? naturalDurationGetter.get()) - passedFrame : passedFrame;
|
|
381
|
+
const delayProcessed = reverseProcessed + (reverse ? delay : -delay);
|
|
382
|
+
const durationProcessed = passedDurationInFrames === undefined ? delayProcessed : delayProcessed / (passedDurationInFrames / naturalDurationGetter.get());
|
|
383
|
+
if (passedDurationInFrames && delayProcessed > passedDurationInFrames) {
|
|
384
|
+
return to;
|
|
385
|
+
}
|
|
386
|
+
const spr = springCalculation({
|
|
387
|
+
fps,
|
|
388
|
+
frame: durationProcessed,
|
|
389
|
+
config
|
|
390
|
+
});
|
|
391
|
+
const inner = config.overshootClamping ? to >= from ? Math.min(spr.current, to) : Math.max(spr.current, to) : spr.current;
|
|
392
|
+
const interpolated = from === 0 && to === 1 ? inner : interpolate(inner, [0, 1], [from, to]);
|
|
393
|
+
return interpolated;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
// src/easing.ts
|
|
397
|
+
var clampUnit = (t) => Math.min(1, Math.max(0, t));
|
|
398
|
+
var springEasingDurationInFrames = 30;
|
|
399
|
+
|
|
400
|
+
class Easing {
|
|
401
|
+
static step0(n) {
|
|
402
|
+
return n > 0 ? 1 : 0;
|
|
403
|
+
}
|
|
404
|
+
static step1(n) {
|
|
405
|
+
return n >= 1 ? 1 : 0;
|
|
406
|
+
}
|
|
407
|
+
static linear(t) {
|
|
408
|
+
return t;
|
|
409
|
+
}
|
|
410
|
+
static ease(t) {
|
|
411
|
+
return Easing.bezier(0.42, 0, 1, 1)(t);
|
|
412
|
+
}
|
|
413
|
+
static quad(t) {
|
|
414
|
+
return t * t;
|
|
415
|
+
}
|
|
416
|
+
static cubic(t) {
|
|
417
|
+
return t * t * t;
|
|
418
|
+
}
|
|
419
|
+
static poly(n) {
|
|
420
|
+
return (t) => t ** n;
|
|
421
|
+
}
|
|
422
|
+
static sin(t) {
|
|
423
|
+
return 1 - Math.cos(t * Math.PI / 2);
|
|
424
|
+
}
|
|
425
|
+
static circle(t) {
|
|
426
|
+
const u = clampUnit(t);
|
|
427
|
+
return 1 - Math.sqrt(1 - u * u);
|
|
428
|
+
}
|
|
429
|
+
static exp(t) {
|
|
430
|
+
return 2 ** (10 * (t - 1));
|
|
431
|
+
}
|
|
432
|
+
static elastic(bounciness = 1) {
|
|
433
|
+
const p = bounciness * Math.PI;
|
|
434
|
+
return (t) => 1 - Math.cos(t * Math.PI / 2) ** 3 * Math.cos(t * p);
|
|
435
|
+
}
|
|
436
|
+
static back(s = 1.70158) {
|
|
437
|
+
return (t) => t * t * ((s + 1) * t - s);
|
|
438
|
+
}
|
|
439
|
+
static spring({
|
|
440
|
+
allowTail = false,
|
|
441
|
+
durationRestThreshold,
|
|
442
|
+
...config
|
|
443
|
+
} = {}) {
|
|
444
|
+
const easing = (t) => {
|
|
445
|
+
if (t <= 0) {
|
|
446
|
+
return 0;
|
|
447
|
+
}
|
|
448
|
+
if (!allowTail && t >= 1) {
|
|
449
|
+
return 1;
|
|
450
|
+
}
|
|
451
|
+
if (allowTail) {
|
|
452
|
+
return spring({
|
|
453
|
+
fps: springEasingDurationInFrames,
|
|
454
|
+
frame: t * measureSpring({
|
|
455
|
+
fps: springEasingDurationInFrames,
|
|
456
|
+
config,
|
|
457
|
+
threshold: durationRestThreshold
|
|
458
|
+
}),
|
|
459
|
+
config
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
return spring({
|
|
463
|
+
fps: springEasingDurationInFrames,
|
|
464
|
+
frame: t * springEasingDurationInFrames,
|
|
465
|
+
config,
|
|
466
|
+
durationInFrames: springEasingDurationInFrames,
|
|
467
|
+
durationRestThreshold
|
|
468
|
+
});
|
|
469
|
+
};
|
|
470
|
+
return Object.assign(easing, {
|
|
471
|
+
remotionShouldExtendRight: allowTail
|
|
472
|
+
});
|
|
473
|
+
}
|
|
474
|
+
static bounce(t) {
|
|
475
|
+
const u = clampUnit(t);
|
|
476
|
+
if (u < 1 / 2.75) {
|
|
477
|
+
return 7.5625 * u * u;
|
|
478
|
+
}
|
|
479
|
+
if (u < 2 / 2.75) {
|
|
480
|
+
const t2_ = u - 1.5 / 2.75;
|
|
481
|
+
return 7.5625 * t2_ * t2_ + 0.75;
|
|
482
|
+
}
|
|
483
|
+
if (u < 2.5 / 2.75) {
|
|
484
|
+
const t2_ = u - 2.25 / 2.75;
|
|
485
|
+
return 7.5625 * t2_ * t2_ + 0.9375;
|
|
486
|
+
}
|
|
487
|
+
const t2 = u - 2.625 / 2.75;
|
|
488
|
+
return 7.5625 * t2 * t2 + 0.984375;
|
|
489
|
+
}
|
|
490
|
+
static bezier(x1, y1, x2, y2) {
|
|
491
|
+
return bezier(x1, y1, x2, y2);
|
|
492
|
+
}
|
|
493
|
+
static in(easing) {
|
|
494
|
+
return easing;
|
|
495
|
+
}
|
|
496
|
+
static out(easing) {
|
|
497
|
+
return (t) => 1 - easing(1 - t);
|
|
498
|
+
}
|
|
499
|
+
static inOut(easing) {
|
|
500
|
+
return (t) => {
|
|
501
|
+
if (t < 0.5) {
|
|
502
|
+
return easing(t * 2) / 2;
|
|
503
|
+
}
|
|
504
|
+
return 1 - easing((1 - t) * 2) / 2;
|
|
505
|
+
};
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
|
|
1
509
|
// src/normalize-number.ts
|
|
2
510
|
var normalizeNumber = (value) => {
|
|
3
511
|
return Math.round(value * 1e6) / 1e6;
|
|
@@ -71,10 +579,13 @@ var transformOriginCenter = { value: 50, unit: "%" };
|
|
|
71
579
|
var stringifyNumber = (value) => {
|
|
72
580
|
return String(normalizeNumber(value));
|
|
73
581
|
};
|
|
582
|
+
|
|
583
|
+
class UnsupportedStringInterpolationValueError extends TypeError {
|
|
584
|
+
}
|
|
74
585
|
var parseStringInterpolationComponent = (component, value) => {
|
|
75
586
|
const match = cssNumberRegex.exec(component);
|
|
76
587
|
if (match === null) {
|
|
77
|
-
throw new
|
|
588
|
+
throw new UnsupportedStringInterpolationValueError(`Cannot interpolate "${value}" because "${component}" is not a supported scale, translate, or rotate value`);
|
|
78
589
|
}
|
|
79
590
|
const unit = match[2] ?? null;
|
|
80
591
|
const numberValue = Number(match[1]);
|
|
@@ -541,6 +1052,52 @@ var interpolateString = ({
|
|
|
541
1052
|
axisRotation: hasAxisRotation
|
|
542
1053
|
});
|
|
543
1054
|
};
|
|
1055
|
+
var interpolateDiscreteString = ({
|
|
1056
|
+
input,
|
|
1057
|
+
inputRange,
|
|
1058
|
+
outputRange,
|
|
1059
|
+
options
|
|
1060
|
+
}) => {
|
|
1061
|
+
if (inputRange.length === 1) {
|
|
1062
|
+
return outputRange[0];
|
|
1063
|
+
}
|
|
1064
|
+
for (let segmentIndex = 0;segmentIndex < inputRange.length - 1; segmentIndex++) {
|
|
1065
|
+
if (resolveEasingForSegment({
|
|
1066
|
+
easing: options?.easing,
|
|
1067
|
+
segmentIndex
|
|
1068
|
+
}) !== Easing.step1) {
|
|
1069
|
+
throw new TypeError("Non-numeric strings can only be interpolated using Easing.step1");
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
const posterizedInput = options?.posterize === undefined ? input : Math.floor(input / options.posterize) * options.posterize;
|
|
1073
|
+
const inputMin = inputRange[0];
|
|
1074
|
+
const inputMax = inputRange[inputRange.length - 1];
|
|
1075
|
+
let resolvedInput = posterizedInput;
|
|
1076
|
+
if (resolvedInput < inputMin) {
|
|
1077
|
+
if (options?.extrapolateLeft === "identity") {
|
|
1078
|
+
throw new TypeError('extrapolateLeft: "identity" is not supported for non-numeric strings');
|
|
1079
|
+
}
|
|
1080
|
+
if (options?.extrapolateLeft === "wrap") {
|
|
1081
|
+
const wrapRange = inputMax - inputMin;
|
|
1082
|
+
resolvedInput = ((resolvedInput - inputMin) % wrapRange + wrapRange) % wrapRange + inputMin;
|
|
1083
|
+
} else {
|
|
1084
|
+
return outputRange[0];
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
if (resolvedInput > inputMax) {
|
|
1088
|
+
if (options?.extrapolateRight === "identity") {
|
|
1089
|
+
throw new TypeError('extrapolateRight: "identity" is not supported for non-numeric strings');
|
|
1090
|
+
}
|
|
1091
|
+
if (options?.extrapolateRight === "wrap") {
|
|
1092
|
+
const wrapRange = inputMax - inputMin;
|
|
1093
|
+
resolvedInput = ((resolvedInput - inputMin) % wrapRange + wrapRange) % wrapRange + inputMin;
|
|
1094
|
+
} else {
|
|
1095
|
+
return outputRange[outputRange.length - 1];
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1098
|
+
const range = findRange(resolvedInput, inputRange);
|
|
1099
|
+
return resolvedInput >= inputRange[range + 1] ? outputRange[range + 1] : outputRange[range];
|
|
1100
|
+
};
|
|
544
1101
|
var validateTupleOutputRange = (outputRange) => {
|
|
545
1102
|
const dimensions = outputRange[0]?.length;
|
|
546
1103
|
if (dimensions === undefined) {
|
|
@@ -655,7 +1212,30 @@ function interpolate(input, inputRange, outputRange, options) {
|
|
|
655
1212
|
if (!outputRange.every((output) => typeof output === "string" || typeof output === "number")) {
|
|
656
1213
|
throw new TypeError("outputRange must contain only numbers, or supported scale, translate, and rotate strings");
|
|
657
1214
|
}
|
|
658
|
-
|
|
1215
|
+
try {
|
|
1216
|
+
return interpolateString({ input, inputRange, outputRange, options });
|
|
1217
|
+
} catch (error) {
|
|
1218
|
+
if (!outputRange.every((output) => typeof output === "string")) {
|
|
1219
|
+
throw error;
|
|
1220
|
+
}
|
|
1221
|
+
const hasNonNumericString = outputRange.some((output) => {
|
|
1222
|
+
try {
|
|
1223
|
+
parseStringInterpolationValue(output);
|
|
1224
|
+
return false;
|
|
1225
|
+
} catch (parseError) {
|
|
1226
|
+
return parseError instanceof UnsupportedStringInterpolationValueError;
|
|
1227
|
+
}
|
|
1228
|
+
});
|
|
1229
|
+
if (!hasNonNumericString) {
|
|
1230
|
+
throw error;
|
|
1231
|
+
}
|
|
1232
|
+
return interpolateDiscreteString({
|
|
1233
|
+
input,
|
|
1234
|
+
inputRange,
|
|
1235
|
+
outputRange,
|
|
1236
|
+
options
|
|
1237
|
+
});
|
|
1238
|
+
}
|
|
659
1239
|
}
|
|
660
1240
|
if (outputRange.every((output) => Array.isArray(output))) {
|
|
661
1241
|
return interpolateTuple({ input, inputRange, outputRange, options });
|
|
@@ -667,8 +1247,8 @@ function interpolate(input, inputRange, outputRange, options) {
|
|
|
667
1247
|
return interpolateNumber({ input, inputRange, outputRange, options });
|
|
668
1248
|
}
|
|
669
1249
|
// src/random.ts
|
|
670
|
-
function mulberry32(
|
|
671
|
-
let t =
|
|
1250
|
+
function mulberry32(a2) {
|
|
1251
|
+
let t = a2 + 1831565813;
|
|
672
1252
|
t = Math.imul(t ^ t >>> 15, t | 1);
|
|
673
1253
|
t ^= t + Math.imul(t ^ t >>> 7, t | 61);
|
|
674
1254
|
return ((t ^ t >>> 14) >>> 0) / 4294967296;
|
|
@@ -1168,8 +1748,8 @@ function hslToRgb(h, s, l) {
|
|
|
1168
1748
|
const p = 2 * l - q;
|
|
1169
1749
|
const r = hue2rgb(p, q, h + 1 / 3);
|
|
1170
1750
|
const g = hue2rgb(p, q, h);
|
|
1171
|
-
const
|
|
1172
|
-
return Math.round(r * 255) << 24 | Math.round(g * 255) << 16 | Math.round(
|
|
1751
|
+
const b2 = hue2rgb(p, q, h - 1 / 3);
|
|
1752
|
+
return Math.round(r * 255) << 24 | Math.round(g * 255) << 16 | Math.round(b2 * 255) << 8;
|
|
1173
1753
|
}
|
|
1174
1754
|
function parse255(str) {
|
|
1175
1755
|
const int = Number.parseInt(str, 10);
|
|
@@ -1233,25 +1813,25 @@ function parseModernAlpha(str) {
|
|
|
1233
1813
|
}
|
|
1234
1814
|
return Math.max(0, Math.min(1, Number.parseFloat(str)));
|
|
1235
1815
|
}
|
|
1236
|
-
function linearToSrgb(
|
|
1237
|
-
if (
|
|
1238
|
-
return 12.92 *
|
|
1239
|
-
return 1.055 *
|
|
1816
|
+
function linearToSrgb(c2) {
|
|
1817
|
+
if (c2 <= 0.0031308)
|
|
1818
|
+
return 12.92 * c2;
|
|
1819
|
+
return 1.055 * c2 ** (1 / 2.4) - 0.055;
|
|
1240
1820
|
}
|
|
1241
1821
|
function clamp01(v) {
|
|
1242
1822
|
return Math.max(0, Math.min(1, v));
|
|
1243
1823
|
}
|
|
1244
|
-
function rgbFloatToInt(r, g,
|
|
1824
|
+
function rgbFloatToInt(r, g, b2, alpha) {
|
|
1245
1825
|
const ri = Math.round(clamp01(r) * 255);
|
|
1246
1826
|
const gi = Math.round(clamp01(g) * 255);
|
|
1247
|
-
const bi = Math.round(clamp01(
|
|
1827
|
+
const bi = Math.round(clamp01(b2) * 255);
|
|
1248
1828
|
const ai = Math.round(clamp01(alpha) * 255);
|
|
1249
1829
|
return (ri << 24 | gi << 16 | bi << 8 | ai) >>> 0;
|
|
1250
1830
|
}
|
|
1251
|
-
function oklabToSrgb(L,
|
|
1252
|
-
const l_ = L + 0.3963377774 *
|
|
1253
|
-
const m_ = L - 0.1055613458 *
|
|
1254
|
-
const s_ = L - 0.0894841775 *
|
|
1831
|
+
function oklabToSrgb(L, a2, b2) {
|
|
1832
|
+
const l_ = L + 0.3963377774 * a2 + 0.2158037573 * b2;
|
|
1833
|
+
const m_ = L - 0.1055613458 * a2 - 0.0638541728 * b2;
|
|
1834
|
+
const s_ = L - 0.0894841775 * a2 - 1.291485548 * b2;
|
|
1255
1835
|
const l = l_ * l_ * l_;
|
|
1256
1836
|
const m = m_ * m_ * m_;
|
|
1257
1837
|
const s = s_ * s_ * s_;
|
|
@@ -1260,15 +1840,15 @@ function oklabToSrgb(L, a, b) {
|
|
|
1260
1840
|
const bLin = -0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s;
|
|
1261
1841
|
return [linearToSrgb(rLin), linearToSrgb(gLin), linearToSrgb(bLin)];
|
|
1262
1842
|
}
|
|
1263
|
-
function labToSrgb(L,
|
|
1843
|
+
function labToSrgb(L, a2, b2) {
|
|
1264
1844
|
const epsilon = 216 / 24389;
|
|
1265
1845
|
const kappa = 24389 / 27;
|
|
1266
1846
|
const Xn = 0.95047;
|
|
1267
1847
|
const Yn = 1;
|
|
1268
1848
|
const Zn = 1.08883;
|
|
1269
1849
|
const fy = (L + 16) / 116;
|
|
1270
|
-
const fx =
|
|
1271
|
-
const fz = fy -
|
|
1850
|
+
const fx = a2 / 500 + fy;
|
|
1851
|
+
const fz = fy - b2 / 200;
|
|
1272
1852
|
const fx3 = fx * fx * fx;
|
|
1273
1853
|
const fz3 = fz * fz * fz;
|
|
1274
1854
|
const xr = fx3 > epsilon ? fx3 : (116 * fx - 16) / kappa;
|
|
@@ -1500,27 +2080,27 @@ function normalizeColor(color) {
|
|
|
1500
2080
|
const H = parseHueAngle(match[3]);
|
|
1501
2081
|
const alpha = parseModernAlpha(match[4]);
|
|
1502
2082
|
const hRad = H * Math.PI / 180;
|
|
1503
|
-
const [r, g,
|
|
1504
|
-
return rgbFloatToInt(r, g,
|
|
2083
|
+
const [r, g, b2] = oklabToSrgb(L, C * Math.cos(hRad), C * Math.sin(hRad));
|
|
2084
|
+
return rgbFloatToInt(r, g, b2, alpha);
|
|
1505
2085
|
}
|
|
1506
2086
|
}
|
|
1507
2087
|
if (matchers.oklab) {
|
|
1508
2088
|
if (match = matchers.oklab.exec(color)) {
|
|
1509
2089
|
const L = parseModernComponent(match[1], 1);
|
|
1510
|
-
const
|
|
1511
|
-
const
|
|
2090
|
+
const a2 = parseModernComponent(match[2], 0.4);
|
|
2091
|
+
const b2 = parseModernComponent(match[3], 0.4);
|
|
1512
2092
|
const alpha = parseModernAlpha(match[4]);
|
|
1513
|
-
const [r, g, bl] = oklabToSrgb(L,
|
|
2093
|
+
const [r, g, bl] = oklabToSrgb(L, a2, b2);
|
|
1514
2094
|
return rgbFloatToInt(r, g, bl, alpha);
|
|
1515
2095
|
}
|
|
1516
2096
|
}
|
|
1517
2097
|
if (matchers.lab) {
|
|
1518
2098
|
if (match = matchers.lab.exec(color)) {
|
|
1519
2099
|
const L = parseModernComponent(match[1], 100);
|
|
1520
|
-
const
|
|
1521
|
-
const
|
|
2100
|
+
const a2 = parseModernComponent(match[2], 125);
|
|
2101
|
+
const b2 = parseModernComponent(match[3], 125);
|
|
1522
2102
|
const alpha = parseModernAlpha(match[4]);
|
|
1523
|
-
const [r, g, bl] = labToSrgb(L,
|
|
2103
|
+
const [r, g, bl] = labToSrgb(L, a2, b2);
|
|
1524
2104
|
return rgbFloatToInt(r, g, bl, alpha);
|
|
1525
2105
|
}
|
|
1526
2106
|
}
|
|
@@ -1606,32 +2186,6 @@ var serializeScaleValue = ([x, y, z]) => {
|
|
|
1606
2186
|
// src/v5-flag.ts
|
|
1607
2187
|
var ENABLE_V5_BREAKING_CHANGES = false;
|
|
1608
2188
|
|
|
1609
|
-
// src/validate-frame.ts
|
|
1610
|
-
var validateFrame = ({
|
|
1611
|
-
allowFloats,
|
|
1612
|
-
durationInFrames,
|
|
1613
|
-
frame
|
|
1614
|
-
}) => {
|
|
1615
|
-
if (typeof frame === "undefined") {
|
|
1616
|
-
throw new TypeError(`Argument missing for parameter "frame"`);
|
|
1617
|
-
}
|
|
1618
|
-
if (typeof frame !== "number") {
|
|
1619
|
-
throw new TypeError(`Argument passed for "frame" is not a number: ${frame}`);
|
|
1620
|
-
}
|
|
1621
|
-
if (!Number.isFinite(frame)) {
|
|
1622
|
-
throw new RangeError(`Frame ${frame} is not finite`);
|
|
1623
|
-
}
|
|
1624
|
-
if (frame % 1 !== 0 && !allowFloats) {
|
|
1625
|
-
throw new RangeError(`Argument for frame must be an integer, but got ${frame}`);
|
|
1626
|
-
}
|
|
1627
|
-
if (frame < 0 && frame < -durationInFrames) {
|
|
1628
|
-
throw new RangeError(`Cannot use frame ${frame}: Duration of composition is ${durationInFrames}, therefore the lowest frame that can be rendered is ${-durationInFrames}`);
|
|
1629
|
-
}
|
|
1630
|
-
if (frame > durationInFrames - 1) {
|
|
1631
|
-
throw new RangeError(`Cannot use frame ${frame}: Duration of composition is ${durationInFrames}, therefore the highest frame that can be rendered is ${durationInFrames - 1}`);
|
|
1632
|
-
}
|
|
1633
|
-
};
|
|
1634
|
-
|
|
1635
2189
|
// src/codec.ts
|
|
1636
2190
|
var validCodecs = [
|
|
1637
2191
|
"h264",
|
|
@@ -1713,25 +2267,6 @@ function validateDurationInFrames(durationInFrames, options) {
|
|
|
1713
2267
|
}
|
|
1714
2268
|
}
|
|
1715
2269
|
|
|
1716
|
-
// src/validation/validate-fps.ts
|
|
1717
|
-
function validateFps(fps, location, isGif) {
|
|
1718
|
-
if (typeof fps !== "number") {
|
|
1719
|
-
throw new Error(`"fps" must be a number, but you passed a value of type ${typeof fps} ${location}`);
|
|
1720
|
-
}
|
|
1721
|
-
if (!Number.isFinite(fps)) {
|
|
1722
|
-
throw new Error(`"fps" must be a finite, but you passed ${fps} ${location}`);
|
|
1723
|
-
}
|
|
1724
|
-
if (isNaN(fps)) {
|
|
1725
|
-
throw new Error(`"fps" must not be NaN, but got ${fps} ${location}`);
|
|
1726
|
-
}
|
|
1727
|
-
if (fps <= 0) {
|
|
1728
|
-
throw new TypeError(`"fps" must be positive, but got ${fps} ${location}`);
|
|
1729
|
-
}
|
|
1730
|
-
if (isGif && fps > 50) {
|
|
1731
|
-
throw new TypeError(`The FPS for a GIF cannot be higher than 50. Use the --every-nth-frame option to lower the FPS: https://remotion.dev/docs/render-as-gif`);
|
|
1732
|
-
}
|
|
1733
|
-
}
|
|
1734
|
-
|
|
1735
2270
|
// src/video/get-current-time.ts
|
|
1736
2271
|
var getExpectedMediaFrameUncorrected = ({
|
|
1737
2272
|
frame,
|