Skip to content

🎥 Make videos programmatically with React

fix(lottie): add missing dotfiles

Arthur Denner5740c42f3c24
diff --git a/packages/lottie/.eslintrc b/packages/lottie/.eslintrc
new file mode 100644
index 0000000000..e1a11da2b5
--- /dev/null
+++ b/packages/lottie/.eslintrc
@@ -0,0 +1,6 @@
+{
+ "extends": "@jonny",
+ "rules": {
+ "@typescript-eslint/no-explicit-any": "off"
+ }
+}
diff --git a/packages/lottie/.npmignore b/packages/lottie/.npmignore
new file mode 100644
index 0000000000..6fdeec6a7f
--- /dev/null
+++ b/packages/lottie/.npmignore
@@ -0,0 +1,8 @@
+dist/test/**
+src
+.eslintrc
+tsconfig.tsbuildinfo
+.prettierrc
+jest.config.js
+*.tgz
+.turbo
diff --git a/packages/lottie/.prettierrc.js b/packages/lottie/.prettierrc.js
new file mode 100644
index 0000000000..32eb24f3bf
--- /dev/null
+++ b/packages/lottie/.prettierrc.js
@@ -0,0 +1,14 @@
+module.exports = {
+ singleQuote: true,
+ bracketSpacing: false,
+ useTabs: true,
+ overrides: [
+ {
+ files: ['*.yml'],
+ options: {
+ singleQuote: false,
+ },
+ },
+ ],
+ plugins: [require.resolve('prettier-plugin-organize-imports')],
+};
diff --git a/packages/lottie/jest.config.js b/packages/lottie/jest.config.js
new file mode 100644
index 0000000000..91ce155181
--- /dev/null
+++ b/packages/lottie/jest.config.js
@@ -0,0 +1,5 @@
+module.exports = {
+ preset: 'ts-jest',
+ testEnvironment: 'jsdom',
+ testPathIgnorePatterns: ['dist'],
+};
diff --git a/packages/lottie/src/Lottie.tsx b/packages/lottie/src/Lottie.tsx
index a16f291b96..506fbe08da 100644
--- a/packages/lottie/src/Lottie.tsx
+++ b/packages/lottie/src/Lottie.tsx
@@ -1,108 +1,109 @@
-import { CSSProperties, useEffect, useRef, useState } from 'react';
-import lottie, { AnimationItem } from 'lottie-web';
-import { continueRender, delayRender, useCurrentFrame } from 'remotion';
+import type {AnimationItem} from 'lottie-web';
+import lottie from 'lottie-web';
+import type {CSSProperties} from 'react';
+import {useEffect, useRef, useState} from 'react';
+import {continueRender, delayRender, useCurrentFrame} from 'remotion';
const getNextFrame = (
- currentFrame: number,
- totalFrames: number,
- loop?: boolean
+ currentFrame: number,
+ totalFrames: number,
+ loop?: boolean
) => {
- return loop
- ? currentFrame % totalFrames
- : Math.min(currentFrame, totalFrames);
+ return loop
+ ? currentFrame % totalFrames
+ : Math.min(currentFrame, totalFrames);
};
interface LottieProps {
- /**
- * JSON object with the animation data.
- * */
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
- animationData?: Record<any, any>;
- /**
- * CSS classes to apply on the container of the animation.
- */
- className?: string;
- /**
- * If the animation should loop after its end.
- */
- loop?: boolean;
- /**
- * The speed of the animation. Defaults to 1.
- */
- speed?: number;
- /**
- * CSS properties to apply on the container of the animation.
- */
- style?: CSSProperties;
+ /**
+ * JSON object with the animation data.
+ * */
+ animationData?: Record<any, any>;
+ /**
+ * CSS classes to apply on the container of the animation.
+ */
+ className?: string;
+ /**
+ * If the animation should loop after its end.
+ */
+ loop?: boolean;
+ /**
+ * The speed of the animation. Defaults to 1.
+ */
+ speed?: number;
+ /**
+ * CSS properties to apply on the container of the animation.
+ */
+ style?: CSSProperties;
}
export const Lottie = ({
- animationData,
- className,
- loop,
- speed = 1,
- style,
+ animationData,
+ className,
+ loop,
+ speed = 1,
+ style,
}: LottieProps) => {
- if (typeof animationData !== 'object') {
- 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/link-tbd for more information.'
- );
- }
-
- const animationRef = useRef<AnimationItem>();
- const lastFrameRef = useRef<number | null>(null);
- const containerRef = useRef<HTMLDivElement>(null);
- const [handle] = useState(delayRender);
- const frame = useCurrentFrame();
-
- useEffect(() => {
- if (!containerRef.current) {
- return;
- }
-
- animationRef.current = lottie.loadAnimation({
- container: containerRef.current,
- autoplay: false,
- animationData,
- });
-
- if (lastFrameRef.current) {
- animationRef.current.goToAndStop(lastFrameRef.current, true);
- }
-
- const { current: animation } = animationRef;
- const onComplete = () => {
- continueRender(handle);
- };
-
- animation.addEventListener('DOMLoaded', onComplete);
-
- return () => {
- lastFrameRef.current = animation.currentFrame;
- animation.removeEventListener('DOMLoaded', onComplete);
- animation.destroy();
- };
- }, [animationData, handle]);
-
- useEffect(() => {
- if (!animationRef.current) {
- return;
- }
-
- animationRef.current.setSpeed(speed);
- }, [speed]);
-
- useEffect(() => {
- if (!animationRef.current) {
- return;
- }
-
- const { totalFrames } = animationRef.current;
- const expectedFrame = frame * speed;
- const nextFrame = getNextFrame(expectedFrame, totalFrames, loop);
-
- animationRef.current.goToAndStop(nextFrame, true);
- }, [frame, loop, speed]);
-
- return <div ref={containerRef} className={className} style={style} />;
+ if (typeof animationData !== 'object') {
+ 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/link-tbd for more information.'
+ );
+ }
+
+ const animationRef = useRef<AnimationItem>();
+ const lastFrameRef = useRef<number | null>(null);
+ const containerRef = useRef<HTMLDivElement>(null);
+ const [handle] = useState(delayRender);
+ const frame = useCurrentFrame();
+
+ useEffect(() => {
+ if (!containerRef.current) {
+ return;
+ }
+
+ animationRef.current = lottie.loadAnimation({
+ container: containerRef.current,
+ autoplay: false,
+ animationData,
+ });
+
+ if (lastFrameRef.current) {
+ animationRef.current.goToAndStop(lastFrameRef.current, true);
+ }
+
+ const {current: animation} = animationRef;
+ const onComplete = () => {
+ continueRender(handle);
+ };
+
+ animation.addEventListener('DOMLoaded', onComplete);
+
+ return () => {
+ lastFrameRef.current = animation.currentFrame;
+ animation.removeEventListener('DOMLoaded', onComplete);
+ animation.destroy();
+ };
+ }, [animationData, handle]);
+
+ useEffect(() => {
+ if (!animationRef.current) {
+ return;
+ }
+
+ animationRef.current.setSpeed(speed);
+ }, [speed]);
+
+ useEffect(() => {
+ if (!animationRef.current) {
+ return;
+ }
+
+ const {totalFrames} = animationRef.current;
+ const expectedFrame = frame * speed;
+ const nextFrame = getNextFrame(expectedFrame, totalFrames, loop);
+
+ animationRef.current.goToAndStop(nextFrame, true);
+ }, [frame, loop, speed]);
+
+ return <div ref={containerRef} className={className} style={style} />;
};