@remotion/lottie 3.2.2 → 3.2.3
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/Lottie.d.ts +2 -25
- package/dist/Lottie.js +15 -7
- package/dist/index.d.ts +1 -2
- package/dist/test/utils.test.js +31 -5
- package/dist/types.d.ts +27 -0
- package/dist/utils.d.ts +7 -1
- package/dist/utils.js +6 -2
- package/package.json +3 -3
package/dist/Lottie.d.ts
CHANGED
|
@@ -1,25 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
export interface LottieProps {
|
|
4
|
-
/**
|
|
5
|
-
* JSON object with the animation data.
|
|
6
|
-
* */
|
|
7
|
-
animationData: LottieAnimationData;
|
|
8
|
-
/**
|
|
9
|
-
* If the animation should loop after its end.
|
|
10
|
-
*/
|
|
11
|
-
loop?: boolean;
|
|
12
|
-
/**
|
|
13
|
-
* The speed of the animation. Defaults to 1.
|
|
14
|
-
*/
|
|
15
|
-
playbackRate?: number;
|
|
16
|
-
/**
|
|
17
|
-
* CSS classes to apply on the container of the animation.
|
|
18
|
-
*/
|
|
19
|
-
className?: string;
|
|
20
|
-
/**
|
|
21
|
-
* CSS properties to apply on the container of the animation.
|
|
22
|
-
*/
|
|
23
|
-
style?: CSSProperties;
|
|
24
|
-
}
|
|
25
|
-
export declare const Lottie: ({ animationData, className, loop, playbackRate, style, }: LottieProps) => JSX.Element;
|
|
1
|
+
import type { LottieProps } from './types';
|
|
2
|
+
export declare const Lottie: ({ animationData, className, direction, loop, playbackRate, style, }: LottieProps) => JSX.Element;
|
package/dist/Lottie.js
CHANGED
|
@@ -11,7 +11,7 @@ const remotion_1 = require("remotion");
|
|
|
11
11
|
const utils_1 = require("./utils");
|
|
12
12
|
const validate_loop_1 = require("./validate-loop");
|
|
13
13
|
const validate_playbackrate_1 = require("./validate-playbackrate");
|
|
14
|
-
const Lottie = ({ animationData, className, loop, playbackRate, style, }) => {
|
|
14
|
+
const Lottie = ({ animationData, className, direction, loop, playbackRate, style, }) => {
|
|
15
15
|
if (typeof animationData !== 'object') {
|
|
16
16
|
throw new Error('animationData should be provided as an object. If you only have the path to the JSON file, load it and pass it as animationData. See https://remotion.dev/docs/lottie/lottie#example for more information.');
|
|
17
17
|
}
|
|
@@ -46,20 +46,28 @@ const Lottie = ({ animationData, className, loop, playbackRate, style, }) => {
|
|
|
46
46
|
};
|
|
47
47
|
}, [animationData, handle]);
|
|
48
48
|
(0, react_1.useEffect)(() => {
|
|
49
|
-
if (
|
|
50
|
-
|
|
49
|
+
if (animationRef.current && direction) {
|
|
50
|
+
animationRef.current.setDirection(direction === 'backward' ? -1 : 1);
|
|
51
|
+
}
|
|
52
|
+
}, [direction]);
|
|
53
|
+
(0, react_1.useEffect)(() => {
|
|
54
|
+
if (animationRef.current && playbackRate) {
|
|
55
|
+
animationRef.current.setSpeed(playbackRate);
|
|
51
56
|
}
|
|
52
|
-
animationRef.current.setSpeed(playbackRate !== null && playbackRate !== void 0 ? playbackRate : 1);
|
|
53
57
|
}, [playbackRate]);
|
|
54
58
|
(0, react_1.useEffect)(() => {
|
|
55
59
|
if (!animationRef.current) {
|
|
56
60
|
return;
|
|
57
61
|
}
|
|
58
62
|
const { totalFrames } = animationRef.current;
|
|
59
|
-
const
|
|
60
|
-
|
|
63
|
+
const nextFrame = (0, utils_1.getNextFrame)({
|
|
64
|
+
currentFrame: frame * (playbackRate !== null && playbackRate !== void 0 ? playbackRate : 1),
|
|
65
|
+
direction,
|
|
66
|
+
loop,
|
|
67
|
+
totalFrames,
|
|
68
|
+
});
|
|
61
69
|
animationRef.current.goToAndStop(nextFrame, true);
|
|
62
|
-
}, [frame, loop, playbackRate]);
|
|
70
|
+
}, [direction, frame, loop, playbackRate]);
|
|
63
71
|
return (0, jsx_runtime_1.jsx)("div", { ref: containerRef, className: className, style: style });
|
|
64
72
|
};
|
|
65
73
|
exports.Lottie = Lottie;
|
package/dist/index.d.ts
CHANGED
package/dist/test/utils.test.js
CHANGED
|
@@ -5,18 +5,44 @@ const utils_1 = require("../utils");
|
|
|
5
5
|
(0, vitest_1.describe)('getNextFrame', () => {
|
|
6
6
|
(0, vitest_1.describe)('when loop is falsy', () => {
|
|
7
7
|
(0, vitest_1.it)('returns the current frame if smaller than total frames', () => {
|
|
8
|
-
(0, vitest_1.expect)((0, utils_1.getNextFrame)(23, 56)).toBe(23);
|
|
8
|
+
(0, vitest_1.expect)((0, utils_1.getNextFrame)({ currentFrame: 23, totalFrames: 56 })).toBe(23);
|
|
9
9
|
});
|
|
10
10
|
(0, vitest_1.it)('returns the last frame if current frame is bigger than total frames', () => {
|
|
11
|
-
(0, vitest_1.expect)((0, utils_1.getNextFrame)(23, 20)).toBe(20);
|
|
11
|
+
(0, vitest_1.expect)((0, utils_1.getNextFrame)({ currentFrame: 23, totalFrames: 20 })).toBe(20);
|
|
12
12
|
});
|
|
13
13
|
});
|
|
14
14
|
(0, vitest_1.describe)('when loop is truthy', () => {
|
|
15
15
|
(0, vitest_1.it)('returns the current frame if smaller than total frames', () => {
|
|
16
|
-
(0, vitest_1.expect)((0, utils_1.getNextFrame)(23, 56, true)).toBe(23);
|
|
16
|
+
(0, vitest_1.expect)((0, utils_1.getNextFrame)({ currentFrame: 23, totalFrames: 56, loop: true })).toBe(23);
|
|
17
17
|
});
|
|
18
|
-
(0, vitest_1.it)('returns the
|
|
19
|
-
(0, vitest_1.expect)((0, utils_1.getNextFrame)(23, 20, true)).toBe(3);
|
|
18
|
+
(0, vitest_1.it)('returns the modulo if current frame is bigger than total frames', () => {
|
|
19
|
+
(0, vitest_1.expect)((0, utils_1.getNextFrame)({ currentFrame: 23, totalFrames: 20, loop: true })).toBe(3);
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
(0, vitest_1.describe)('when direction is reverse and loop is falsy', () => {
|
|
23
|
+
(0, vitest_1.it)('returns the correct frame if current frame is smaller than total frames', () => {
|
|
24
|
+
(0, vitest_1.expect)((0, utils_1.getNextFrame)({ currentFrame: 15, totalFrames: 20, direction: 'backward' })).toBe(5);
|
|
25
|
+
});
|
|
26
|
+
(0, vitest_1.it)('returns frame zero if current frame is bigger than total frames', () => {
|
|
27
|
+
(0, vitest_1.expect)((0, utils_1.getNextFrame)({ currentFrame: 23, totalFrames: 20, direction: 'backward' })).toBe(0);
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
(0, vitest_1.describe)('when direction is reverse and loop is truthy', () => {
|
|
31
|
+
(0, vitest_1.it)('returns the correct frame if current frame is smaller than total frames', () => {
|
|
32
|
+
(0, vitest_1.expect)((0, utils_1.getNextFrame)({
|
|
33
|
+
currentFrame: 15,
|
|
34
|
+
totalFrames: 20,
|
|
35
|
+
direction: 'backward',
|
|
36
|
+
loop: true,
|
|
37
|
+
})).toBe(5);
|
|
38
|
+
});
|
|
39
|
+
(0, vitest_1.it)('returns (total-overflow) if current frame is bigger than total frames', () => {
|
|
40
|
+
(0, vitest_1.expect)((0, utils_1.getNextFrame)({
|
|
41
|
+
currentFrame: 23,
|
|
42
|
+
totalFrames: 20,
|
|
43
|
+
direction: 'backward',
|
|
44
|
+
loop: true,
|
|
45
|
+
})).toBe(17);
|
|
20
46
|
});
|
|
21
47
|
});
|
|
22
48
|
});
|
package/dist/types.d.ts
CHANGED
|
@@ -1,6 +1,33 @@
|
|
|
1
|
+
import type { CSSProperties } from 'react';
|
|
1
2
|
export declare type LottieAnimationData = {
|
|
2
3
|
fr: number;
|
|
3
4
|
w: number;
|
|
4
5
|
h: number;
|
|
5
6
|
op: number;
|
|
6
7
|
} & Record<string | number | symbol, unknown>;
|
|
8
|
+
export declare type LottieProps = {
|
|
9
|
+
/**
|
|
10
|
+
* JSON object with the animation data.
|
|
11
|
+
* */
|
|
12
|
+
animationData: LottieAnimationData;
|
|
13
|
+
/**
|
|
14
|
+
* CSS classes to apply on the container of the animation.
|
|
15
|
+
*/
|
|
16
|
+
className?: string;
|
|
17
|
+
/**
|
|
18
|
+
* The direction of the animation. Defaults to forward.
|
|
19
|
+
*/
|
|
20
|
+
direction?: 'forward' | 'backward';
|
|
21
|
+
/**
|
|
22
|
+
* If the animation should loop after its end.
|
|
23
|
+
*/
|
|
24
|
+
loop?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* The speed of the animation. Defaults to 1.
|
|
27
|
+
*/
|
|
28
|
+
playbackRate?: number;
|
|
29
|
+
/**
|
|
30
|
+
* CSS properties to apply to the container of the animation.
|
|
31
|
+
*/
|
|
32
|
+
style?: CSSProperties;
|
|
33
|
+
};
|
package/dist/utils.d.ts
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import type { LottieProps } from './types';
|
|
2
|
+
declare type Params = Pick<LottieProps, 'direction' | 'loop'> & {
|
|
3
|
+
currentFrame: number;
|
|
4
|
+
totalFrames: number;
|
|
5
|
+
};
|
|
6
|
+
export declare const getNextFrame: ({ currentFrame, direction, loop, totalFrames, }: Params) => number;
|
|
7
|
+
export {};
|
package/dist/utils.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getNextFrame = void 0;
|
|
4
|
-
const getNextFrame = (currentFrame, totalFrames,
|
|
5
|
-
|
|
4
|
+
const getNextFrame = ({ currentFrame, direction, loop, totalFrames, }) => {
|
|
5
|
+
const nextFrame = loop
|
|
6
6
|
? currentFrame % totalFrames
|
|
7
7
|
: Math.min(currentFrame, totalFrames);
|
|
8
|
+
if (direction === 'backward') {
|
|
9
|
+
return totalFrames - nextFrame;
|
|
10
|
+
}
|
|
11
|
+
return nextFrame;
|
|
8
12
|
};
|
|
9
13
|
exports.getNextFrame = getNextFrame;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@remotion/lottie",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.3",
|
|
4
4
|
"description": "Remotion Lottie",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
],
|
|
28
28
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"remotion": "3.2.
|
|
30
|
+
"remotion": "3.2.3"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
33
|
"lottie-web": "^5",
|
|
@@ -58,5 +58,5 @@
|
|
|
58
58
|
"publishConfig": {
|
|
59
59
|
"access": "public"
|
|
60
60
|
},
|
|
61
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "15773a2e48ee8a9dbcfd898520cb914396c21eb1"
|
|
62
62
|
}
|