@remotion/lottie 3.2.0
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/LICENSE.md +41 -0
- package/README.md +3 -0
- package/dist/Lottie.d.ts +25 -0
- package/dist/Lottie.js +65 -0
- package/dist/get-lottie-metadata.d.ts +10 -0
- package/dist/get-lottie-metadata.js +20 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +7 -0
- package/dist/test/get-lottie-metadata.test.d.ts +1 -0
- package/dist/test/get-lottie-metadata.test.js +24 -0
- package/dist/test/utils.test.d.ts +1 -0
- package/dist/test/utils.test.js +22 -0
- package/dist/types.d.ts +6 -0
- package/dist/types.js +2 -0
- package/dist/utils.d.ts +1 -0
- package/dist/utils.js +9 -0
- package/dist/validate-loop.d.ts +1 -0
- package/dist/validate-loop.js +12 -0
- package/dist/validate-playbackrate.d.ts +1 -0
- package/dist/validate-playbackrate.js +18 -0
- package/package.json +62 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Remotion License
|
|
2
|
+
|
|
3
|
+
Depending on the type of your legal entity, you are granted permission to use Remotion for your project. Individuals and small companies are allowed to use Remotion create videos for free (even commercial), while a company license is required for for-profit organisations of a certain size. This two-tier system was designed to ensure funding for this project while still allowing the source code to be available and the program to be free for most. Read below for the exact terms of use.
|
|
4
|
+
|
|
5
|
+
- [Free license](#free-license)
|
|
6
|
+
- [Company license](#company-license)
|
|
7
|
+
|
|
8
|
+
## Free license
|
|
9
|
+
|
|
10
|
+
Copyright © 2022 [Jonny Burger](https://jonny.io)
|
|
11
|
+
|
|
12
|
+
### Eligibility
|
|
13
|
+
|
|
14
|
+
You are eligible to use Remotion for free if you are:
|
|
15
|
+
|
|
16
|
+
- an individual
|
|
17
|
+
- a for-profit organisation with up to 3 employees
|
|
18
|
+
- a non-profit or not-for-profit organisation
|
|
19
|
+
- evaluating whether Remotion is a good fit, and are not yet using it in a commercial way
|
|
20
|
+
|
|
21
|
+
### Allowed use cases
|
|
22
|
+
|
|
23
|
+
Permission is hereby granted, free of charge, to any person eligible for the "Free license", to use the software non-commercially or commercially for the purpose of creating videos and images and to modify and the software to their own liking, for the purpose of fulfilling their custom use case or to contribute bug fixes or improvements back to Remotion.
|
|
24
|
+
|
|
25
|
+
### Disallowed use cases
|
|
26
|
+
|
|
27
|
+
It is not allowed to copy or modify Remotion code for the purpose of selling, renting, licensing, relicensing, sublicensing your own derivate of Remotion.
|
|
28
|
+
|
|
29
|
+
### Warranty notice
|
|
30
|
+
|
|
31
|
+
The software is provided "as is", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. In no event shall the author or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the software.
|
|
32
|
+
|
|
33
|
+
### Support
|
|
34
|
+
|
|
35
|
+
Support is provided on a best-we-can-do basis via GitHub Issues and Discord.
|
|
36
|
+
|
|
37
|
+
## Company license
|
|
38
|
+
|
|
39
|
+
You are required to obtain a company license to use Remotion if you are not within the group of entities eligible for a free license. This license will enable you to use Remotion for the allowed use cases specified in the free license, and give you access to prioritized support.
|
|
40
|
+
|
|
41
|
+
Visit [companies.remotion.dev](https://companies.remotion.dev) for pricing and to buy a license.
|
package/README.md
ADDED
package/dist/Lottie.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { CSSProperties } from 'react';
|
|
2
|
+
import type { LottieAnimationData } from './types';
|
|
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;
|
package/dist/Lottie.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Lottie = void 0;
|
|
7
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
|
+
const lottie_web_1 = __importDefault(require("lottie-web"));
|
|
9
|
+
const react_1 = require("react");
|
|
10
|
+
const remotion_1 = require("remotion");
|
|
11
|
+
const utils_1 = require("./utils");
|
|
12
|
+
const validate_loop_1 = require("./validate-loop");
|
|
13
|
+
const validate_playbackrate_1 = require("./validate-playbackrate");
|
|
14
|
+
const Lottie = ({ animationData, className, loop, playbackRate, style, }) => {
|
|
15
|
+
if (typeof animationData !== 'object') {
|
|
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
|
+
}
|
|
18
|
+
(0, validate_playbackrate_1.validatePlaybackRate)(playbackRate);
|
|
19
|
+
(0, validate_loop_1.validateLoop)(loop);
|
|
20
|
+
const animationRef = (0, react_1.useRef)();
|
|
21
|
+
const lastFrameRef = (0, react_1.useRef)(null);
|
|
22
|
+
const containerRef = (0, react_1.useRef)(null);
|
|
23
|
+
const [handle] = (0, react_1.useState)(() => (0, remotion_1.delayRender)('Waiting for Lottie animation to load'));
|
|
24
|
+
const frame = (0, remotion_1.useCurrentFrame)();
|
|
25
|
+
(0, react_1.useEffect)(() => {
|
|
26
|
+
if (!containerRef.current) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
animationRef.current = lottie_web_1.default.loadAnimation({
|
|
30
|
+
container: containerRef.current,
|
|
31
|
+
autoplay: false,
|
|
32
|
+
animationData,
|
|
33
|
+
});
|
|
34
|
+
if (lastFrameRef.current) {
|
|
35
|
+
animationRef.current.goToAndStop(lastFrameRef.current, true);
|
|
36
|
+
}
|
|
37
|
+
const { current: animation } = animationRef;
|
|
38
|
+
const onComplete = () => {
|
|
39
|
+
(0, remotion_1.continueRender)(handle);
|
|
40
|
+
};
|
|
41
|
+
animation.addEventListener('DOMLoaded', onComplete);
|
|
42
|
+
return () => {
|
|
43
|
+
lastFrameRef.current = animation.currentFrame;
|
|
44
|
+
animation.removeEventListener('DOMLoaded', onComplete);
|
|
45
|
+
animation.destroy();
|
|
46
|
+
};
|
|
47
|
+
}, [animationData, handle]);
|
|
48
|
+
(0, react_1.useEffect)(() => {
|
|
49
|
+
if (!animationRef.current) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
animationRef.current.setSpeed(playbackRate !== null && playbackRate !== void 0 ? playbackRate : 1);
|
|
53
|
+
}, [playbackRate]);
|
|
54
|
+
(0, react_1.useEffect)(() => {
|
|
55
|
+
if (!animationRef.current) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const { totalFrames } = animationRef.current;
|
|
59
|
+
const expectedFrame = frame * (playbackRate !== null && playbackRate !== void 0 ? playbackRate : 1);
|
|
60
|
+
const nextFrame = (0, utils_1.getNextFrame)(expectedFrame, totalFrames, loop);
|
|
61
|
+
animationRef.current.goToAndStop(nextFrame, true);
|
|
62
|
+
}, [frame, loop, playbackRate]);
|
|
63
|
+
return (0, jsx_runtime_1.jsx)("div", { ref: containerRef, className: className, style: style });
|
|
64
|
+
};
|
|
65
|
+
exports.Lottie = Lottie;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { LottieAnimationData } from './types';
|
|
2
|
+
declare type LottieMetadata = {
|
|
3
|
+
fps: number;
|
|
4
|
+
durationInSeconds: number;
|
|
5
|
+
durationInFrames: number;
|
|
6
|
+
width: number;
|
|
7
|
+
height: number;
|
|
8
|
+
};
|
|
9
|
+
export declare const getLottieMetadata: (animationData: LottieAnimationData) => LottieMetadata | null;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getLottieMetadata = void 0;
|
|
4
|
+
const getLottieMetadata = (animationData) => {
|
|
5
|
+
const width = animationData.w;
|
|
6
|
+
const height = animationData.h;
|
|
7
|
+
const framerate = animationData.fr;
|
|
8
|
+
const durationInFrames = animationData.op;
|
|
9
|
+
if (![width, height, framerate, durationInFrames].every(Boolean)) {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
return {
|
|
13
|
+
durationInFrames: Math.floor(durationInFrames),
|
|
14
|
+
durationInSeconds: durationInFrames / framerate,
|
|
15
|
+
fps: framerate,
|
|
16
|
+
height,
|
|
17
|
+
width,
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
exports.getLottieMetadata = getLottieMetadata;
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Lottie = exports.getLottieMetadata = void 0;
|
|
4
|
+
var get_lottie_metadata_1 = require("./get-lottie-metadata");
|
|
5
|
+
Object.defineProperty(exports, "getLottieMetadata", { enumerable: true, get: function () { return get_lottie_metadata_1.getLottieMetadata; } });
|
|
6
|
+
var Lottie_1 = require("./Lottie");
|
|
7
|
+
Object.defineProperty(exports, "Lottie", { enumerable: true, get: function () { return Lottie_1.Lottie; } });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const fs_1 = __importDefault(require("fs"));
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const vitest_1 = require("vitest");
|
|
9
|
+
const get_lottie_metadata_1 = require("../get-lottie-metadata");
|
|
10
|
+
(0, vitest_1.test)('Should be able to get Lottie metadata', () => {
|
|
11
|
+
const file = fs_1.default.readFileSync(path_1.default.join(__dirname, 'example.json'), 'utf-8');
|
|
12
|
+
const parsed = JSON.parse(file);
|
|
13
|
+
(0, vitest_1.expect)((0, get_lottie_metadata_1.getLottieMetadata)(parsed)).toEqual({
|
|
14
|
+
durationInFrames: 90,
|
|
15
|
+
durationInSeconds: 3.0030030030030037,
|
|
16
|
+
fps: 29.9700012207031,
|
|
17
|
+
height: 1080,
|
|
18
|
+
width: 1920,
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
(0, vitest_1.test)('Should return null if invalid Lottie file', () => {
|
|
22
|
+
// @ts-expect-error
|
|
23
|
+
(0, vitest_1.expect)((0, get_lottie_metadata_1.getLottieMetadata)({})).toEqual(null);
|
|
24
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const vitest_1 = require("vitest");
|
|
4
|
+
const utils_1 = require("../utils");
|
|
5
|
+
(0, vitest_1.describe)('getNextFrame', () => {
|
|
6
|
+
(0, vitest_1.describe)('when loop is falsy', () => {
|
|
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);
|
|
9
|
+
});
|
|
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);
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
(0, vitest_1.describe)('when loop is truthy', () => {
|
|
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);
|
|
17
|
+
});
|
|
18
|
+
(0, vitest_1.it)('returns the last frame if current frame is bigger than total frames', () => {
|
|
19
|
+
(0, vitest_1.expect)((0, utils_1.getNextFrame)(23, 20, true)).toBe(3);
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
});
|
package/dist/types.d.ts
ADDED
package/dist/types.js
ADDED
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getNextFrame: (currentFrame: number, totalFrames: number, loop?: boolean) => number;
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getNextFrame = void 0;
|
|
4
|
+
const getNextFrame = (currentFrame, totalFrames, loop) => {
|
|
5
|
+
return loop
|
|
6
|
+
? currentFrame % totalFrames
|
|
7
|
+
: Math.min(currentFrame, totalFrames);
|
|
8
|
+
};
|
|
9
|
+
exports.getNextFrame = getNextFrame;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const validateLoop: (loop: unknown) => void;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateLoop = void 0;
|
|
4
|
+
const validateLoop = (loop) => {
|
|
5
|
+
if (typeof loop === 'undefined') {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
if (typeof loop !== 'boolean') {
|
|
9
|
+
throw new TypeError(`The "loop" prop must be a boolean or undefined, but is "${JSON.stringify(loop)}"`);
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
exports.validateLoop = validateLoop;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const validatePlaybackRate: (playbackRate: unknown) => void;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validatePlaybackRate = void 0;
|
|
4
|
+
const validatePlaybackRate = (playbackRate) => {
|
|
5
|
+
if (typeof playbackRate === 'undefined') {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
if (typeof playbackRate !== 'number') {
|
|
9
|
+
throw new TypeError(`The "playbackRate" prop must be a number or undefined, but is ${JSON.stringify(playbackRate)}`);
|
|
10
|
+
}
|
|
11
|
+
if (Number.isNaN(playbackRate) || !Number.isFinite(playbackRate)) {
|
|
12
|
+
throw new TypeError(`The "playbackRate" props must be a real number, but is ${playbackRate}`);
|
|
13
|
+
}
|
|
14
|
+
if (playbackRate <= 0) {
|
|
15
|
+
throw new TypeError(`The "playbackRate" props must be positive, but is ${playbackRate}`);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
exports.validatePlaybackRate = validatePlaybackRate;
|
package/package.json
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@remotion/lottie",
|
|
3
|
+
"version": "3.2.0",
|
|
4
|
+
"description": "Remotion Lottie",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"scripts": {
|
|
8
|
+
"lint": "eslint src --ext ts,tsx",
|
|
9
|
+
"test": "vitest --run",
|
|
10
|
+
"build": "tsc -d",
|
|
11
|
+
"watch": "tsc -w"
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"url": "https://github.com/remotion-dev/remotion"
|
|
15
|
+
},
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/remotion-dev/remotion/issues"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist",
|
|
21
|
+
"README.md"
|
|
22
|
+
],
|
|
23
|
+
"author": "Arthur Denner <arthurdenner7@gmail.com>",
|
|
24
|
+
"maintainers": [
|
|
25
|
+
"Jonny Burger <jonny@remotion.dev>",
|
|
26
|
+
"Arthur Denner <arthurdenner7@gmail.com>"
|
|
27
|
+
],
|
|
28
|
+
"license": "SEE LICENSE IN LICENSE.md",
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"remotion": "3.2.0"
|
|
31
|
+
},
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"lottie-web": "^5",
|
|
34
|
+
"react": ">=16.8.0",
|
|
35
|
+
"react-dom": ">=16.8.0"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@jonny/eslint-config": "3.0.266",
|
|
39
|
+
"@types/node": "^16.7.5",
|
|
40
|
+
"@types/react": "18.0.1",
|
|
41
|
+
"@types/react-dom": "18.0.0",
|
|
42
|
+
"eslint": "8.13.0",
|
|
43
|
+
"prettier": "^2.0.5",
|
|
44
|
+
"prettier-plugin-organize-imports": "^2.3.4",
|
|
45
|
+
"react": "^18.0.0",
|
|
46
|
+
"react-dom": "^18.0.0",
|
|
47
|
+
"typescript": "^4.7.0",
|
|
48
|
+
"vitest": "^0.18.0"
|
|
49
|
+
},
|
|
50
|
+
"keywords": [
|
|
51
|
+
"remotion",
|
|
52
|
+
"ffmpeg",
|
|
53
|
+
"video",
|
|
54
|
+
"react",
|
|
55
|
+
"puppeteer",
|
|
56
|
+
"player"
|
|
57
|
+
],
|
|
58
|
+
"publishConfig": {
|
|
59
|
+
"access": "public"
|
|
60
|
+
},
|
|
61
|
+
"gitHead": "47b188161a9e922a247eaa998e72d37af9137707"
|
|
62
|
+
}
|