Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New @remotion/animated-emoji package #4112

Merged
merged 9 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Prettier for docs is temporarily disabled:
# https://github.com/prettier/prettier/issues/12209
packages/docs/docs
packages/docs/docs/**.mdx
3 changes: 3 additions & 0 deletions packages/animated-emoji/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["@jonny/eslint-config/react"],
}
18 changes: 18 additions & 0 deletions packages/animated-emoji/bundle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {build} from 'bun';

if (process.env.NODE_ENV !== 'production') {
throw new Error('This script must be run using NODE_ENV=production');
}

const output = await build({
entrypoints: ['src/index.ts'],
naming: '[name].mjs',
external: ['remotion', 'remotion/no-react', 'react'],
});

const [file] = output.outputs;
const text = await file.text();

await Bun.write('dist/esm/index.mjs', text);

export {};
39 changes: 39 additions & 0 deletions packages/animated-emoji/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "@remotion/animated-emoji",
"version": "4.0.186",
"main": "dist/cjs/index.js",
"types": "dist/cjs/index.d.ts",
"module": "dist/esm/index.mjs",
"sideEffects": false,
"scripts": {
"formatting": "prettier src --check",
"lint": "eslint src --ext ts,tsx",
"build": "bun --env-file=../.env.bundle bundle.ts",
"test": "bun test src"
},
"exports": {
"./package.json": "./package.json",
".": {
"types": "./dist/cjs/index.d.ts",
"module": "./dist/esm/index.mjs",
"import": "./dist/esm/index.mjs",
"require": "./dist/cjs/index.js"
}
},
"author": "Yehor Misiats (https://github.com/satelllte)",
"maintainers": [
"Jonny Burger <[email protected]>"
],
"contributors": [],
"license": "MIT",
"bugs": {
"url": "https://github.com/remotion-dev/remotion/issues"
},
"dependencies": {
"remotion": "workspace:*"
},
"keywords": [],
"publishConfig": {
"access": "public"
}
}
38 changes: 38 additions & 0 deletions packages/animated-emoji/src/AnimatedEmoji.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import type {RemotionOffthreadVideoProps} from 'remotion';
import {Loop, OffthreadVideo, useVideoConfig} from 'remotion';
import type {CalculateEmojiSrc, Scale} from './calculate-emoji-src';
import {defaultCalculateEmojiSrc} from './calculate-emoji-src';
import {emojis} from './emoji-data';
import type {EmojiName} from './get-available-emoji';
import {isWebkit} from './is-webkit';

export type AnimatedEmojiProps = Omit<RemotionOffthreadVideoProps, 'src'> & {
readonly emoji: EmojiName;
readonly scale?: Scale;
readonly calculateSrc?: CalculateEmojiSrc;
};

export const AnimatedEmoji = ({
emoji,
scale = '1',
calculateSrc = defaultCalculateEmojiSrc,
...props
}: AnimatedEmojiProps) => {
const {fps} = useVideoConfig();

const emojiData = emojis.find((e) => e.name === emoji);
if (!emojiData) {
throw new Error(
`Emoji ${emoji} not found. Available emojis: ${emojis.map((e) => e.name).join(', ')}`,
);
}

return (
<Loop durationInFrames={Math.floor(emojiData.durationInSeconds * fps)}>
<OffthreadVideo
{...props}
src={calculateSrc({emoji, scale, format: isWebkit() ? 'hevc' : 'webm'})}
/>
</Loop>
);
};
21 changes: 21 additions & 0 deletions packages/animated-emoji/src/calculate-emoji-src.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {staticFile} from 'remotion';
import type {EmojiName} from './get-available-emoji';

export type Format = 'hevc' | 'webm';
export type Scale = '0.5' | '1' | '2';

export type CalculateEmojiSrc = (options: {
emoji: EmojiName;
scale: Scale;
format: Format;
}) => string;

export const defaultCalculateEmojiSrc: CalculateEmojiSrc = ({
emoji,
scale,
format,
}) => {
const extension = format === 'hevc' ? 'mp4' : 'webm';

return staticFile(`${emoji}-${scale}x.${extension}`);
};
Loading
Loading