Skip to content

Commit

Permalink
Add blur to animations
Browse files Browse the repository at this point in the history
  • Loading branch information
pskd73 committed Apr 9, 2024
1 parent 52fe0da commit 068a53a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
3 changes: 3 additions & 0 deletions packages/example/src/Example.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const inputSchema = z.object({
y: z.array(z.number().step(0.1)).optional(),
scale: z.array(z.number().step(0.1).min(0).max(1)).optional(),
rotate: z.array(z.number().step(0.1)).optional(),
blur: z.array(z.number().step(0.2)).optional(),
windowSize: z.number().min(0).max(100),
});

Expand All @@ -21,6 +22,7 @@ export default function Example({
y,
scale,
rotate,
blur,
windowSize,
}: z.infer<typeof inputSchema>) {
return (
Expand All @@ -42,6 +44,7 @@ export default function Example({
y,
scale,
rotate,
blur,
windowSize,
}}
>
Expand Down
1 change: 1 addition & 0 deletions packages/example/src/Root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const Root = () => {
rotate: [0, 0],
windowSize: 20,
word: false,
blur: [0, 0],
}}
schema={inputSchema}
/>
Expand Down
2 changes: 1 addition & 1 deletion packages/library/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "remotion-animate-text",
"version": "1.0.5",
"version": "1.1.0",
"description": "A remotion package to animate text",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
Expand Down
11 changes: 11 additions & 0 deletions packages/library/src/animate-text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export type TextAnimation = {
showOverflow?: boolean;
refRange?: number[];
durations?: number[];
blur?: number[];
};

type Part = {
Expand Down Expand Up @@ -149,6 +150,9 @@ export const applyTextAnimation = ({
toStyle: ({ pct }) => {
const transforms: string[] = [];
const refRange = animation?.refRange || [0, 100];

let blur = 0;

if (animation?.scale) {
const scale = interpolate(pct, refRange, animation.scale, {
extrapolateRight: "clamp",
Expand All @@ -173,6 +177,12 @@ export const applyTextAnimation = ({
});
transforms.push(`rotate(${rotate}deg)`);
}
if (animation?.blur) {
blur = interpolate(pct, refRange, animation.blur, {
extrapolateRight: "clamp",
});
}

return {
opacity:
animation?.opacity &&
Expand All @@ -181,6 +191,7 @@ export const applyTextAnimation = ({
}),
transform: transforms.length > 0 ? transforms.join(" ") : undefined,
display: animation?.hideLoading && pct === 0 ? "none" : "inline-block",
filter: `blur(${blur}px)`,
};
},
});
Expand Down

0 comments on commit 068a53a

Please sign in to comment.