Skip to content

πŸŽ₯ Make videos programmatically with React

`@remotion/web-renderer`: Support clip-path with polygon, path, circle, ellipse, inset

Jonny Burger4ae31138cf89
diff --git a/packages/docs/docs/client-side-rendering/limitations.mdx b/packages/docs/docs/client-side-rendering/limitations.mdx
index ef00a16a1b..d70dcad82e 100644
--- a/packages/docs/docs/client-side-rendering/limitations.mdx
+++ b/packages/docs/docs/client-side-rendering/limitations.mdx
@@ -131,12 +131,22 @@ The [`<Audio>`](/docs/media/audio) from `@remotion/media` is <a style={{color: '
[`<AnimatedEmoji>`](/docs/animated-emoji) from [`@remotion/animated-emoji`](/docs/animated-emoji) is <a style={{color: 'red'}}>not supported</a>.
β†’ Use [`<Lottie>`](/docs/lottie) instead.
+## Clip path
+
+The `clip-path` property is <a style={{color: 'green'}}>partially supported</a>:
+
+- `clip-path: polygon()` is <a style={{color: 'green'}}>supported</a>.
+- `clip-path: path()` is <a style={{color: 'green'}}>supported</a>.
+- `clip-path: circle()` is <a style={{color: 'green'}}>supported</a>.
+- `clip-path: ellipse()` is <a style={{color: 'green'}}>supported</a>.
+- `clip-path: inset()` is <a style={{color: 'green'}}>supported</a>.
+- `clip-path: url()` referencing SVG `<clipPath>` elements is <a style={{color: 'red'}}>not supported</a>.
+
## Unsupported styles
All styles not explicitly mentioned are <a style={{color: 'red'}}>not supported</a>.
Here is a selection of unsupported styles:
-- `clip-path`
- `backdrop-filter`
- `mix-blend-mode`
- `background-blend-mode`
diff --git a/packages/transitions/src/presentations/clock-wipe.tsx b/packages/transitions/src/presentations/clock-wipe.tsx
index 60b55ffeaa..93f3e1ded9 100644
--- a/packages/transitions/src/presentations/clock-wipe.tsx
+++ b/packages/transitions/src/presentations/clock-wipe.tsx
@@ -1,7 +1,7 @@
import {translatePath} from '@remotion/paths';
import {makePie} from '@remotion/shapes';
-import React, {useMemo, useState} from 'react';
-import {AbsoluteFill, random} from 'remotion';
+import React, {useMemo} from 'react';
+import {AbsoluteFill} from 'remotion';
import type {
TransitionPresentation,
TransitionPresentationComponentProps,
@@ -16,8 +16,6 @@ export type ClockWipeProps = {
innerExitStyle?: React.CSSProperties;
};
-const svgContainerStyle: React.CSSProperties = {pointerEvents: 'none'};
-
const ClockWipePresentation: React.FC<
TransitionPresentationComponentProps<ClockWipeProps>
> = ({children, presentationDirection, presentationProgress, passedProps}) => {
@@ -35,19 +33,20 @@ const ClockWipePresentation: React.FC<
-(finishedRadius * 2 - passedProps.height) / 2,
);
- const [clipId] = useState(() => String(random(null)));
const style: React.CSSProperties = useMemo(() => {
return {
width: '100%',
height: '100%',
clipPath:
- presentationDirection === 'exiting' ? undefined : `url(#${clipId})`,
+ presentationDirection === 'exiting'
+ ? undefined
+ : `path("${translatedPath}")`,
...(presentationDirection === 'entering'
? passedProps.innerEnterStyle
: passedProps.innerExitStyle),
};
}, [
- clipId,
+ translatedPath,
passedProps.innerEnterStyle,
passedProps.innerExitStyle,
presentationDirection,
@@ -66,17 +65,6 @@ const ClockWipePresentation: React.FC<
return (
<AbsoluteFill style={outerStyle}>
<AbsoluteFill style={style}>{children}</AbsoluteFill>
- {presentationDirection === 'exiting' ? null : (
- <AbsoluteFill style={svgContainerStyle}>
- <svg>
- <defs>
- <clipPath id={clipId}>
- <path d={translatedPath} fill="black" />
- </clipPath>
- </defs>
- </svg>
- </AbsoluteFill>
- )}
</AbsoluteFill>
);
};
diff --git a/packages/transitions/src/presentations/iris.tsx b/packages/transitions/src/presentations/iris.tsx
index b07027dde0..09d3da85c4 100644
--- a/packages/transitions/src/presentations/iris.tsx
+++ b/packages/transitions/src/presentations/iris.tsx
@@ -1,7 +1,7 @@
import {translatePath} from '@remotion/paths';
import {makeCircle} from '@remotion/shapes';
-import React, {useMemo, useState} from 'react';
-import {AbsoluteFill, random} from 'remotion';
+import React, {useMemo} from 'react';
+import {AbsoluteFill} from 'remotion';
import type {
TransitionPresentation,
TransitionPresentationComponentProps,
@@ -16,17 +16,12 @@ export type IrisProps = {
innerExitStyle?: React.CSSProperties;
};
-const svgContainerStyle: React.CSSProperties = {pointerEvents: 'none'};
-
const IrisPresentation: React.FC<
TransitionPresentationComponentProps<IrisProps>
> = ({children, presentationDirection, presentationProgress, passedProps}) => {
- // Calculate the radius needed to cover the entire viewport
const maxRadius =
Math.sqrt(passedProps.width ** 2 + passedProps.height ** 2) / 2;
- // For iris, we want to start small and grow large (entering)
- // or start large and shrink small (exiting)
const minRadius = 0;
const currentRadius =
presentationDirection === 'entering'
@@ -37,27 +32,26 @@ const IrisPresentation: React.FC<
radius: currentRadius,
});
- // Center the circle in the viewport
const translatedPath = translatePath(
path,
passedProps.width / 2 - currentRadius,
passedProps.height / 2 - currentRadius,
);
- const [clipId] = useState(() => String(random(null)));
-
const style: React.CSSProperties = useMemo(() => {
return {
width: '100%',
height: '100%',
clipPath:
- presentationDirection === 'exiting' ? undefined : `url(#${clipId})`,
+ presentationDirection === 'exiting'
+ ? undefined
+ : `path("${translatedPath}")`,
...(presentationDirection === 'entering'
? passedProps.innerEnterStyle
: passedProps.innerExitStyle),
};
}, [
- clipId,
+ translatedPath,
passedProps.innerEnterStyle,
passedProps.innerExitStyle,
presentationDirection,
@@ -76,17 +70,6 @@ const IrisPresentation: React.FC<
return (
<AbsoluteFill style={outerStyle}>
<AbsoluteFill style={style}>{children}</AbsoluteFill>
- {presentationDirection === 'exiting' ? null : (
- <AbsoluteFill style={svgContainerStyle}>
- <svg>
- <defs>
- <clipPath id={clipId}>
- <path d={translatedPath} fill="black" />
- </clipPath>
- </defs>
- </svg>
- </AbsoluteFill>
- )}
</AbsoluteFill>
);
};
diff --git a/packages/transitions/src/presentations/wipe.tsx b/packages/transitions/src/presentations/wipe.tsx
index 5e0f7c05f6..d59d237363 100644
--- a/packages/transitions/src/presentations/wipe.tsx
+++ b/packages/transitions/src/presentations/wipe.tsx
@@ -1,72 +1,53 @@
-import React, {useMemo, useState} from 'react';
-import {AbsoluteFill, random} from 'remotion';
+import React, {useMemo} from 'react';
+import {AbsoluteFill} from 'remotion';
import type {
TransitionPresentation,
TransitionPresentationComponentProps,
} from '../types.js';
-const makePathIn = (progress: number, direction: WipeDirection) => {
+const makePolygonIn = (progress: number, direction: WipeDirection) => {
+ const p = progress * 100;
switch (direction) {
case 'from-left':
- return `
-M 0 0
-L ${progress} 0
-L ${progress} 1
-L 0 1
-Z`;
-
+ return `polygon(0% 0%, ${p}% 0%, ${p}% 100%, 0% 100%)`;
case 'from-top-left':
- return `
-M 0 0
-L ${progress * 2} 0
-L 0 ${progress * 2}
-Z`;
-
+ return `polygon(0% 0%, ${p * 2}% 0%, 0% ${p * 2}%)`;
case 'from-top':
- return `
-M 0 0
-L 1 0
-L 1 ${progress}
-L 0 ${progress}
-Z`;
-
+ return `polygon(0% 0%, 100% 0%, 100% ${p}%, 0% ${p}%)`;
case 'from-top-right':
- return `
-M 1 0
-L ${1 - progress * 2} 0
-L 1 ${progress * 2}
-Z`;
-
+ return `polygon(100% 0%, ${100 - p * 2}% 0%, 100% ${p * 2}%)`;
case 'from-right':
- return `
-M 1 0
-L 1 1
-L ${1 - progress} 1
-L ${1 - progress} 0
-Z`;
-
+ return `polygon(100% 0%, 100% 100%, ${100 - p}% 100%, ${100 - p}% 0%)`;
case 'from-bottom-right':
- return `
-M 1 1
-L ${1 - progress * 2} 1
-L 1 ${1 - progress * 2}
-Z`;
-
+ return `polygon(100% 100%, ${100 - p * 2}% 100%, 100% ${100 - p * 2}%)`;
case 'from-bottom':
- return `
-M 0 1
-L 1 1
-L 1 ${1 - progress}
-L 0 ${1 - progress}
-Z`;
-
+ return `polygon(0% 100%, 100% 100%, 100% ${100 - p}%, 0% ${100 - p}%)`;
case 'from-bottom-left':
- return `
-M 0 1
-L 0 ${1 - progress * 2}
-L ${progress * 2} 1
-Z`;
+ return `polygon(0% 100%, 0% ${100 - p * 2}%, ${p * 2}% 100%)`;
+ default:
+ throw new Error(`Unknown direction ${JSON.stringify(direction)}`);
+ }
+};
+const makePolygonOut = (progress: number, direction: WipeDirection) => {
+ const p = progress * 100;
+ switch (direction) {
+ case 'from-left':
+ return `polygon(100% 100%, ${100 - p}% 100%, ${100 - p}% 0%, 100% 0%)`;
+ case 'from-top-left':
+ return `polygon(100% 100%, ${100 - p * 2}% 100%, 100% ${100 - p * 2}%)`;
+ case 'from-top':
+ return `polygon(100% 100%, 0% 100%, 0% ${100 - p}%, 100% ${100 - p}%)`;
+ case 'from-top-right':
+ return `polygon(0% 100%, ${p * 2}% 100%, 0% ${100 - p * 2}%)`;
+ case 'from-right':
+ return `polygon(0% 0%, ${p}% 0%, ${p}% 100%, 0% 100%)`;
+ case 'from-bottom-right':
+ return `polygon(0% 0%, ${p * 2}% 0%, 0% ${p * 2}%)`;
+ case 'from-bottom':
+ return `polygon(100% 0%, 0% 0%, 0% ${p}%, 100% ${p}%)`;
+ case 'from-bottom-left':
+ return `polygon(100% 0%, ${100 - p * 2}% 0%, 100% ${p * 2}%)`;
default:
throw new Error(`Unknown direction ${JSON.stringify(direction)}`);
}
@@ -90,75 +71,6 @@ export type WipeProps = {
innerExitStyle?: React.CSSProperties;
};
-const makePathOut = (progress: number, direction: WipeDirection) => {
- switch (direction) {
- case 'from-left':
- return `
-M 1 1
-L ${1 - progress} 1
-L ${1 - progress} 0
-L 1 0
-Z`;
-
- case 'from-top-left':
- return `
-M 1 1
-L ${1 - 2 * progress} 1
-L 1 ${1 - 2 * progress}
-Z`;
-
- case 'from-top':
- return `
-M 1 1
-L 0 1
-L 0 ${1 - progress}
-L 1 ${1 - progress}
-Z`;
-
- case 'from-top-right':
- return `
-M 0 1
-L ${progress * 2} 1
-L 0 ${1 - progress * 2}
-Z`;
-
- case 'from-right':
- return `
-M 0 0
-L ${progress} 0
-L ${progress} 1
-L 0 1
-Z`;
-
- case 'from-bottom-right':
- return `
-M 0 0
-L ${progress * 2} 0
-L 0 ${progress * 2}
-Z`;
-
- case 'from-bottom':
- return `
-M 1 0
-L 0 0
-L 0 ${progress}
-L 1 ${progress}
-Z`;
-
- case 'from-bottom-left':
- return `
-M 1 0
-L ${1 - progress * 2} 0
-L 1 ${progress * 2}
-Z`;
-
- default:
- throw new Error(`Unknown direction ${JSON.stringify(direction)}`);
- }
-};
-
-const svgContainerStyle: React.CSSProperties = {pointerEvents: 'none'};
-
const WipePresentation: React.FC<
TransitionPresentationComponentProps<WipeProps>
> = ({
@@ -173,17 +85,15 @@ const WipePresentation: React.FC<
outerExitStyle,
},
}) => {
- const [clipId] = useState(() => String(random(null)));
-
const progressInDirection =
presentationDirection === 'entering'
? presentationProgress
: 1 - presentationProgress;
- const path =
+ const clipPath =
presentationDirection === 'entering'
- ? makePathIn(progressInDirection, direction)
- : makePathOut(progressInDirection, direction);
+ ? makePolygonIn(progressInDirection, direction)
+ : makePolygonOut(progressInDirection, direction);
const style: React.CSSProperties = useMemo(() => {
return {
@@ -191,12 +101,12 @@ const WipePresentation: React.FC<
height: '100%',
justifyContent: 'center',
alignItems: 'center',
- clipPath: `url(#${clipId})`,
+ clipPath,
...(presentationDirection === 'entering'
? innerEnterStyle
: innerExitStyle),
};
- }, [clipId, innerEnterStyle, innerExitStyle, presentationDirection]);
+ }, [clipPath, innerEnterStyle, innerExitStyle, presentationDirection]);
const outerStyle = useMemo(() => {
return presentationDirection === 'entering'
@@ -204,26 +114,9 @@ const WipePresentation: React.FC<
: outerExitStyle;
}, [outerEnterStyle, outerExitStyle, presentationDirection]);
- const svgStyle: React.CSSProperties = useMemo(() => {
- return {
- width: '100%',
- height: '100%',
- pointerEvents: 'none',
- };
- }, []);
-
return (
<AbsoluteFill style={outerStyle}>
<AbsoluteFill style={style}>{children}</AbsoluteFill>
- <AbsoluteFill style={svgContainerStyle}>
- <svg viewBox="0 0 1 1" style={svgStyle}>
- <defs>
- <clipPath id={clipId} clipPathUnits="objectBoundingBox">
- <path d={path} fill="black" />
- </clipPath>
- </defs>
- </svg>
- </AbsoluteFill>
</AbsoluteFill>
);
};
diff --git a/packages/web-renderer/src/drawing/clip-path.ts b/packages/web-renderer/src/drawing/clip-path.ts
new file mode 100644
index 0000000000..fcfa5c7aa8
--- /dev/null
+++ b/packages/web-renderer/src/drawing/clip-path.ts
@@ -0,0 +1,313 @@
+type ClipPathNone = {type: 'none'};
+type ClipPathPolygon = {
+ type: 'polygon';
+ points: {x: number; y: number}[];
+};
+type ClipPathPath = {type: 'path'; d: string};
+type ClipPathCircle = {
+ type: 'circle';
+ radius: number;
+ cx: number;
+ cy: number;
+};
+type ClipPathEllipse = {
+ type: 'ellipse';
+ rx: number;
+ ry: number;
+ cx: number;
+ cy: number;
+};
+type ClipPathInset = {
+ type: 'inset';
+ top: number;
+ right: number;
+ bottom: number;
+ left: number;
+};
+
+type ParsedClipPath =
+ | ClipPathNone
+ | ClipPathPolygon
+ | ClipPathPath
+ | ClipPathCircle
+ | ClipPathEllipse
+ | ClipPathInset;
+
+function resolveLength(value: string, reference: number): number {
+ value = value.trim();
+ if (value.endsWith('%')) {
+ return (parseFloat(value) / 100) * reference;
+ }
+
+ if (value.endsWith('px')) {
+ return parseFloat(value);
+ }
+
+ return parseFloat(value);
+}
+
+function parsePosition(
+ parts: string[],
+ width: number,
+ height: number,
+): {x: number; y: number} {
+ if (parts.length === 0) {
+ return {x: width / 2, y: height / 2};
+ }
+
+ if (parts.length === 1) {
+ const val = resolveLength(parts[0], width);
+ return {x: val, y: val};
+ }
+
+ return {
+ x: resolveLength(parts[0], width),
+ y: resolveLength(parts[1], height),
+ };
+}
+
+function parsePolygon(args: string, rect: DOMRect): ClipPathPolygon {
+ const pointStrings = args.split(',');
+ const points = pointStrings.map((pointStr) => {
+ const coords = pointStr.trim().split(/\s+/);
+ return {
+ x: resolveLength(coords[0], rect.width) + rect.left,
+ y: resolveLength(coords[1], rect.height) + rect.top,
+ };
+ });
+
+ return {type: 'polygon', points};
+}
+
+function parsePath(args: string): ClipPathPath {
+ const match = args.match(/^(?:(?:nonzero|evenodd)\s*,\s*)?["'](.+)["']$/);
+ if (!match) {
+ return {type: 'path', d: args.replace(/["']/g, '')};
+ }
+
+ return {type: 'path', d: match[1]};
+}
+
+function parseCircle(args: string, rect: DOMRect): ClipPathCircle {
+ const atIndex = args.indexOf(' at ');
+ let radiusStr: string;
+ let positionParts: string[];
+
+ if (atIndex !== -1) {
+ radiusStr = args.slice(0, atIndex).trim();
+ positionParts = args
+ .slice(atIndex + 4)
+ .trim()
+ .split(/\s+/);
+ } else {
+ radiusStr = args.trim();
+ positionParts = [];
+ }
+
+ const closestSide = Math.min(rect.width, rect.height) / 2;
+ const farthestSide = Math.max(rect.width, rect.height) / 2;
+ let radius: number;
+ if (radiusStr === 'closest-side' || radiusStr === '') {
+ radius = closestSide;
+ } else if (radiusStr === 'farthest-side') {
+ radius = farthestSide;
+ } else {
+ const refSize =
+ Math.sqrt(rect.width * rect.width + rect.height * rect.height) /
+ Math.SQRT2;
+ radius = resolveLength(radiusStr, refSize);
+ }
+
+ const position = parsePosition(positionParts, rect.width, rect.height);
+
+ return {
+ type: 'circle',
+ radius,
+ cx: position.x + rect.left,
+ cy: position.y + rect.top,
+ };
+}
+
+function parseEllipse(args: string, rect: DOMRect): ClipPathEllipse {
+ const atIndex = args.indexOf(' at ');
+ let radiiStr: string;
+ let positionParts: string[];
+
+ if (atIndex !== -1) {
+ radiiStr = args.slice(0, atIndex).trim();
+ positionParts = args
+ .slice(atIndex + 4)
+ .trim()
+ .split(/\s+/);
+ } else {
+ radiiStr = args.trim();
+ positionParts = [];
+ }
+
+ const radiiParts = radiiStr.split(/\s+/);
+ let rx: number;
+ let ry: number;
+
+ if (radiiParts.length >= 2) {
+ rx = resolveLength(radiiParts[0], rect.width);
+ ry = resolveLength(radiiParts[1], rect.height);
+ } else {
+ rx = rect.width / 2;
+ ry = rect.height / 2;
+ }
+
+ const position = parsePosition(positionParts, rect.width, rect.height);
+
+ return {
+ type: 'ellipse',
+ rx,
+ ry,
+ cx: position.x + rect.left,
+ cy: position.y + rect.top,
+ };
+}
+
+function parseInset(args: string, rect: DOMRect): ClipPathInset {
+ const parts = args.split(/\s+/);
+ let top: number;
+ let right: number;
+ let bottom: number;
+ let left: number;
+
+ if (parts.length === 1) {
+ top = right = bottom = left = resolveLength(parts[0], rect.height);
+ } else if (parts.length === 2) {
+ top = bottom = resolveLength(parts[0], rect.height);
+ right = left = resolveLength(parts[1], rect.width);
+ } else if (parts.length === 3) {
+ top = resolveLength(parts[0], rect.height);
+ right = left = resolveLength(parts[1], rect.width);
+ bottom = resolveLength(parts[2], rect.height);
+ } else {
+ top = resolveLength(parts[0], rect.height);
+ right = resolveLength(parts[1], rect.width);
+ bottom = resolveLength(parts[2], rect.height);
+ left = resolveLength(parts[3], rect.width);
+ }
+
+ return {type: 'inset', top, right, bottom, left};
+}
+
+export function parseClipPath(clipPath: string, rect: DOMRect): ParsedClipPath {
+ if (clipPath === 'none' || clipPath === '') {
+ return {type: 'none'};
+ }
+
+ const polygonMatch = clipPath.match(/^polygon\((.+)\)$/);
+ if (polygonMatch) {
+ return parsePolygon(polygonMatch[1], rect);
+ }
+
+ const pathMatch = clipPath.match(/^path\((.+)\)$/);
+ if (pathMatch) {
+ return parsePath(pathMatch[1]);
+ }
+
+ const circleMatch = clipPath.match(/^circle\((.+)\)$/);
+ if (circleMatch) {
+ return parseCircle(circleMatch[1], rect);
+ }
+
+ const ellipseMatch = clipPath.match(/^ellipse\((.+)\)$/);
+ if (ellipseMatch) {
+ return parseEllipse(ellipseMatch[1], rect);
+ }
+
+ const insetMatch = clipPath.match(/^inset\((.+)\)$/);
+ if (insetMatch) {
+ return parseInset(insetMatch[1], rect);
+ }
+
+ return {type: 'none'};
+}
+
+export function setClipPath({
+ ctx,
+ clipPath,
+ rect,
+}: {
+ ctx: OffscreenCanvasRenderingContext2D;
+ clipPath: string;
+ rect: DOMRect;
+}): () => void {
+ const parsed = parseClipPath(clipPath, rect);
+
+ if (parsed.type === 'none') {
+ return () => {};
+ }
+
+ ctx.save();
+
+ switch (parsed.type) {
+ case 'polygon': {
+ ctx.beginPath();
+ for (let i = 0; i < parsed.points.length; i++) {
+ const point = parsed.points[i];
+ if (i === 0) {
+ ctx.moveTo(point.x, point.y);
+ } else {
+ ctx.lineTo(point.x, point.y);
+ }
+ }
+
+ ctx.closePath();
+ ctx.clip();
+ break;
+ }
+
+ case 'path': {
+ const path2d = new Path2D();
+ const offsetMatrix = new DOMMatrix().translate(rect.left, rect.top);
+ path2d.addPath(new Path2D(parsed.d), offsetMatrix);
+ ctx.clip(path2d);
+ break;
+ }
+
+ case 'circle': {
+ ctx.beginPath();
+ ctx.arc(parsed.cx, parsed.cy, parsed.radius, 0, Math.PI * 2);
+ ctx.closePath();
+ ctx.clip();
+ break;
+ }
+
+ case 'ellipse': {
+ ctx.beginPath();
+ ctx.ellipse(
+ parsed.cx,
+ parsed.cy,
+ parsed.rx,
+ parsed.ry,
+ 0,
+ 0,
+ Math.PI * 2,
+ );
+ ctx.closePath();
+ ctx.clip();
+ break;
+ }
+
+ case 'inset': {
+ const x = rect.left + parsed.left;
+ const y = rect.top + parsed.top;
+ const w = rect.width - parsed.left - parsed.right;
+ const h = rect.height - parsed.top - parsed.bottom;
+ ctx.beginPath();
+ ctx.rect(x, y, w, h);
+ ctx.clip();
+ break;
+ }
+
+ default:
+ break;
+ }
+
+ return () => {
+ ctx.restore();
+ };
+}
diff --git a/packages/web-renderer/src/drawing/draw-element.ts b/packages/web-renderer/src/drawing/draw-element.ts
index 7fa7214f75..3f5413f46c 100644
--- a/packages/web-renderer/src/drawing/draw-element.ts
+++ b/packages/web-renderer/src/drawing/draw-element.ts
@@ -1,6 +1,7 @@
import type {LogLevel} from 'remotion';
import type {InternalState} from '../internal-state';
import {parseBorderRadius, setBorderRadius} from './border-radius';
+import {setClipPath} from './clip-path';
import {drawBackground} from './draw-background';
import {drawBorder} from './draw-border';
import {drawBorderRadius} from './draw-box-shadow';
@@ -50,6 +51,12 @@ export const drawElement = async ({
scale,
});
+ const finishClipPath = setClipPath({
+ ctx: context,
+ clipPath: computedStyle.clipPath,
+ rect,
+ });
+
const finishOpacity = setOpacity({
ctx: context,
opacity,
@@ -126,6 +133,7 @@ export const drawElement = async ({
cleanupAfterChildren: () => {
finishFilter();
finishOpacity();
+ finishClipPath();
finishOverflowHidden();
},
};
diff --git a/packages/web-renderer/src/test/Root.tsx b/packages/web-renderer/src/test/Root.tsx
index 1e78fa6411..10755fbde3 100644
--- a/packages/web-renderer/src/test/Root.tsx
+++ b/packages/web-renderer/src/test/Root.tsx
@@ -16,6 +16,11 @@ import {borderRadiusNone} from './fixtures/border-radius-none';
import {borderRadiusPercentage} from './fixtures/border-radius-percentage';
import {borderRadiusSimple} from './fixtures/border-radius-simple';
import {boxShadow} from './fixtures/box-shadow';
+import {clipPathCircle} from './fixtures/clip-path-circle';
+import {clipPathEllipse} from './fixtures/clip-path-ellipse';
+import {clipPathInset} from './fixtures/clip-path-inset';
+import {clipPathPath} from './fixtures/clip-path-path';
+import {clipPathPolygon} from './fixtures/clip-path-polygon';
import {threeDFlattening} from './fixtures/clipped';
import {complexNestedSvg} from './fixtures/complex-nested-svg';
import {deeplyNestedTransform} from './fixtures/deeply-nested-transform';
@@ -171,6 +176,13 @@ export const Root: React.FC = () => {
<Composition {...manyLayers} />
<Composition {...threeDFlattening} />
</Folder>
+ <Folder name="clip-path">
+ <Composition {...clipPathPolygon} />
+ <Composition {...clipPathPath} />
+ <Composition {...clipPathCircle} />
+ <Composition {...clipPathInset} />
+ <Composition {...clipPathEllipse} />
+ </Folder>
</>
);
};
diff --git a/packages/web-renderer/src/test/__screenshots__/clip-path.test.tsx/clip-path-circle-chromium-darwin.png b/packages/web-renderer/src/test/__screenshots__/clip-path.test.tsx/clip-path-circle-chromium-darwin.png
new file mode 100644
index 0000000000..e866547b89
Binary files /dev/null and b/packages/web-renderer/src/test/__screenshots__/clip-path.test.tsx/clip-path-circle-chromium-darwin.png differ
diff --git a/packages/web-renderer/src/test/__screenshots__/clip-path.test.tsx/clip-path-circle-firefox-darwin.png b/packages/web-renderer/src/test/__screenshots__/clip-path.test.tsx/clip-path-circle-firefox-darwin.png
new file mode 100644
index 0000000000..d80d6c19f4
Binary files /dev/null and b/packages/web-renderer/src/test/__screenshots__/clip-path.test.tsx/clip-path-circle-firefox-darwin.png differ
diff --git a/packages/web-renderer/src/test/__screenshots__/clip-path.test.tsx/clip-path-circle-webkit-darwin.png b/packages/web-renderer/src/test/__screenshots__/clip-path.test.tsx/clip-path-circle-webkit-darwin.png
new file mode 100644
index 0000000000..33961c8a37
Binary files /dev/null and b/packages/web-renderer/src/test/__screenshots__/clip-path.test.tsx/clip-path-circle-webkit-darwin.png differ
diff --git a/packages/web-renderer/src/test/__screenshots__/clip-path.test.tsx/clip-path-ellipse-chromium-darwin.png b/packages/web-renderer/src/test/__screenshots__/clip-path.test.tsx/clip-path-ellipse-chromium-darwin.png
new file mode 100644
index 0000000000..3925eb3ff7
Binary files /dev/null and b/packages/web-renderer/src/test/__screenshots__/clip-path.test.tsx/clip-path-ellipse-chromium-darwin.png differ
diff --git a/packages/web-renderer/src/test/__screenshots__/clip-path.test.tsx/clip-path-ellipse-firefox-darwin.png b/packages/web-renderer/src/test/__screenshots__/clip-path.test.tsx/clip-path-ellipse-firefox-darwin.png
new file mode 100644
index 0000000000..962a2aea8b
Binary files /dev/null and b/packages/web-renderer/src/test/__screenshots__/clip-path.test.tsx/clip-path-ellipse-firefox-darwin.png differ
diff --git a/packages/web-renderer/src/test/__screenshots__/clip-path.test.tsx/clip-path-ellipse-webkit-darwin.png b/packages/web-renderer/src/test/__screenshots__/clip-path.test.tsx/clip-path-ellipse-webkit-darwin.png
new file mode 100644
index 0000000000..a2eafc13f1
Binary files /dev/null and b/packages/web-renderer/src/test/__screenshots__/clip-path.test.tsx/clip-path-ellipse-webkit-darwin.png differ
diff --git a/packages/web-renderer/src/test/__screenshots__/clip-path.test.tsx/clip-path-inset-chromium-darwin.png b/packages/web-renderer/src/test/__screenshots__/clip-path.test.tsx/clip-path-inset-chromium-darwin.png
new file mode 100644
index 0000000000..da5aa32385
Binary files /dev/null and b/packages/web-renderer/src/test/__screenshots__/clip-path.test.tsx/clip-path-inset-chromium-darwin.png differ
diff --git a/packages/web-renderer/src/test/__screenshots__/clip-path.test.tsx/clip-path-inset-firefox-darwin.png b/packages/web-renderer/src/test/__screenshots__/clip-path.test.tsx/clip-path-inset-firefox-darwin.png
new file mode 100644
index 0000000000..da5aa32385
Binary files /dev/null and b/packages/web-renderer/src/test/__screenshots__/clip-path.test.tsx/clip-path-inset-firefox-darwin.png differ
diff --git a/packages/web-renderer/src/test/__screenshots__/clip-path.test.tsx/clip-path-inset-webkit-darwin.png b/packages/web-renderer/src/test/__screenshots__/clip-path.test.tsx/clip-path-inset-webkit-darwin.png
new file mode 100644
index 0000000000..da5aa32385
Binary files /dev/null and b/packages/web-renderer/src/test/__screenshots__/clip-path.test.tsx/clip-path-inset-webkit-darwin.png differ
diff --git a/packages/web-renderer/src/test/__screenshots__/clip-path.test.tsx/clip-path-path-chromium-darwin.png b/packages/web-renderer/src/test/__screenshots__/clip-path.test.tsx/clip-path-path-chromium-darwin.png
new file mode 100644
index 0000000000..0970e9dfc7
Binary files /dev/null and b/packages/web-renderer/src/test/__screenshots__/clip-path.test.tsx/clip-path-path-chromium-darwin.png differ
diff --git a/packages/web-renderer/src/test/__screenshots__/clip-path.test.tsx/clip-path-path-firefox-darwin.png b/packages/web-renderer/src/test/__screenshots__/clip-path.test.tsx/clip-path-path-firefox-darwin.png
new file mode 100644
index 0000000000..9e0641536f
Binary files /dev/null and b/packages/web-renderer/src/test/__screenshots__/clip-path.test.tsx/clip-path-path-firefox-darwin.png differ
diff --git a/packages/web-renderer/src/test/__screenshots__/clip-path.test.tsx/clip-path-path-webkit-darwin.png b/packages/web-renderer/src/test/__screenshots__/clip-path.test.tsx/clip-path-path-webkit-darwin.png
new file mode 100644
index 0000000000..58ac3be474
Binary files /dev/null and b/packages/web-renderer/src/test/__screenshots__/clip-path.test.tsx/clip-path-path-webkit-darwin.png differ
diff --git a/packages/web-renderer/src/test/__screenshots__/clip-path.test.tsx/clip-path-polygon-chromium-darwin.png b/packages/web-renderer/src/test/__screenshots__/clip-path.test.tsx/clip-path-polygon-chromium-darwin.png
new file mode 100644
index 0000000000..53da89b893
Binary files /dev/null and b/packages/web-renderer/src/test/__screenshots__/clip-path.test.tsx/clip-path-polygon-chromium-darwin.png differ
diff --git a/packages/web-renderer/src/test/__screenshots__/clip-path.test.tsx/clip-path-polygon-firefox-darwin.png b/packages/web-renderer/src/test/__screenshots__/clip-path.test.tsx/clip-path-polygon-firefox-darwin.png
new file mode 100644
index 0000000000..6648f6ea7d
Binary files /dev/null and b/packages/web-renderer/src/test/__screenshots__/clip-path.test.tsx/clip-path-polygon-firefox-darwin.png differ
diff --git a/packages/web-renderer/src/test/__screenshots__/clip-path.test.tsx/clip-path-polygon-webkit-darwin.png b/packages/web-renderer/src/test/__screenshots__/clip-path.test.tsx/clip-path-polygon-webkit-darwin.png
new file mode 100644
index 0000000000..8bd5cb62ee
Binary files /dev/null and b/packages/web-renderer/src/test/__screenshots__/clip-path.test.tsx/clip-path-polygon-webkit-darwin.png differ
diff --git a/packages/web-renderer/src/test/clip-path.test.tsx b/packages/web-renderer/src/test/clip-path.test.tsx
new file mode 100644
index 0000000000..f7f810f2db
--- /dev/null
+++ b/packages/web-renderer/src/test/clip-path.test.tsx
@@ -0,0 +1,89 @@
+import {test} from 'vitest';
+import {renderStillOnWeb} from '../render-still-on-web';
+import '../symbol-dispose';
+import {clipPathCircle} from './fixtures/clip-path-circle';
+import {clipPathEllipse} from './fixtures/clip-path-ellipse';
+import {clipPathInset} from './fixtures/clip-path-inset';
+import {clipPathPath} from './fixtures/clip-path-path';
+import {clipPathPolygon} from './fixtures/clip-path-polygon';
+import {testImage} from './utils';
+
+test('Should render clip-path: polygon()', async () => {
+ const still = await renderStillOnWeb({
+ licenseKey: 'free-license',
+ composition: clipPathPolygon,
+ frame: 0,
+ inputProps: {},
+ });
+ const blob = await still.blob({format: 'png'});
+
+ await testImage({
+ blob,
+ testId: 'clip-path-polygon',
+ allowedMismatchedPixelRatio: 0.02,
+ });
+});
+
+test('Should render clip-path: path()', async () => {
+ const still = await renderStillOnWeb({
+ licenseKey: 'free-license',
+ composition: clipPathPath,
+ frame: 0,
+ inputProps: {},
+ });
+ const blob = await still.blob({format: 'png'});
+
+ await testImage({
+ blob,
+ testId: 'clip-path-path',
+ allowedMismatchedPixelRatio: 0.02,
+ });
+});
+
+test('Should render clip-path: circle()', async () => {
+ const still = await renderStillOnWeb({
+ licenseKey: 'free-license',
+ composition: clipPathCircle,
+ frame: 0,
+ inputProps: {},
+ });
+ const blob = await still.blob({format: 'png'});
+
+ await testImage({
+ blob,
+ testId: 'clip-path-circle',
+ allowedMismatchedPixelRatio: 0.02,
+ });
+});
+
+test('Should render clip-path: inset()', async () => {
+ const still = await renderStillOnWeb({
+ licenseKey: 'free-license',
+ composition: clipPathInset,
+ frame: 0,
+ inputProps: {},
+ });
+ const blob = await still.blob({format: 'png'});
+
+ await testImage({
+ blob,
+ testId: 'clip-path-inset',
+ allowedMismatchedPixelRatio: 0.02,
+ });
+});
+
+test('Should render clip-path: ellipse()', async () => {
+ const still = await renderStillOnWeb({
+ licenseKey: 'free-license',
+ composition: clipPathEllipse,
+ frame: 0,
+ inputProps: {},
+ });
+ const blob = await still.blob({format: 'png'});
+
+ await testImage({
+ blob,
+ testId: 'clip-path-ellipse',
+ allowedMismatchedPixelRatio: 0.02,
+ });
+});
diff --git a/packages/web-renderer/src/test/fixtures/clip-path-circle.tsx b/packages/web-renderer/src/test/fixtures/clip-path-circle.tsx
new file mode 100644
index 0000000000..3e6cc2d35c
--- /dev/null
+++ b/packages/web-renderer/src/test/fixtures/clip-path-circle.tsx
@@ -0,0 +1,31 @@
+import React from 'react';
+import {AbsoluteFill} from 'remotion';
+
+const Component: React.FC = () => {
+ return (
+ <AbsoluteFill
+ style={{
+ justifyContent: 'center',
+ alignItems: 'center',
+ }}
+ >
+ <div
+ style={{
+ width: 150,
+ height: 150,
+ backgroundColor: 'green',
+ clipPath: 'circle(50% at 50% 50%)',
+ }}
+ />
+ </AbsoluteFill>
+ );
+};
+
+export const clipPathCircle = {
+ component: Component,
+ id: 'clip-path-circle',
+ width: 200,
+ height: 200,
+ fps: 30,
+ durationInFrames: 1,
+} as const;
diff --git a/packages/web-renderer/src/test/fixtures/clip-path-ellipse.tsx b/packages/web-renderer/src/test/fixtures/clip-path-ellipse.tsx
new file mode 100644
index 0000000000..6fced3151c
--- /dev/null
+++ b/packages/web-renderer/src/test/fixtures/clip-path-ellipse.tsx
@@ -0,0 +1,31 @@
+import React from 'react';
+import {AbsoluteFill} from 'remotion';
+
+const Component: React.FC = () => {
+ return (
+ <AbsoluteFill
+ style={{
+ justifyContent: 'center',
+ alignItems: 'center',
+ }}
+ >
+ <div
+ style={{
+ width: 150,
+ height: 150,
+ backgroundColor: 'orange',
+ clipPath: 'ellipse(40% 30% at 50% 50%)',
+ }}
+ />
+ </AbsoluteFill>
+ );
+};
+
+export const clipPathEllipse = {
+ component: Component,
+ id: 'clip-path-ellipse',
+ width: 200,
+ height: 200,
+ fps: 30,
+ durationInFrames: 1,
+} as const;
diff --git a/packages/web-renderer/src/test/fixtures/clip-path-inset.tsx b/packages/web-renderer/src/test/fixtures/clip-path-inset.tsx
new file mode 100644
index 0000000000..a3817a3e4c
--- /dev/null
+++ b/packages/web-renderer/src/test/fixtures/clip-path-inset.tsx
@@ -0,0 +1,31 @@
+import React from 'react';
+import {AbsoluteFill} from 'remotion';
+
+const Component: React.FC = () => {
+ return (
+ <AbsoluteFill
+ style={{
+ justifyContent: 'center',
+ alignItems: 'center',
+ }}
+ >
+ <div
+ style={{
+ width: 150,
+ height: 150,
+ backgroundColor: 'purple',
+ clipPath: 'inset(20px 30px 40px 10px)',
+ }}
+ />
+ </AbsoluteFill>
+ );
+};
+
+export const clipPathInset = {
+ component: Component,
+ id: 'clip-path-inset',
+ width: 200,
+ height: 200,
+ fps: 30,
+ durationInFrames: 1,
+} as const;
diff --git a/packages/web-renderer/src/test/fixtures/clip-path-path.tsx b/packages/web-renderer/src/test/fixtures/clip-path-path.tsx
new file mode 100644
index 0000000000..840eb7305e
--- /dev/null
+++ b/packages/web-renderer/src/test/fixtures/clip-path-path.tsx
@@ -0,0 +1,31 @@
+import React from 'react';
+import {AbsoluteFill} from 'remotion';
+
+const Component: React.FC = () => {
+ return (
+ <AbsoluteFill
+ style={{
+ justifyContent: 'center',
+ alignItems: 'center',
+ }}
+ >
+ <div
+ style={{
+ width: 150,
+ height: 150,
+ backgroundColor: 'red',
+ clipPath: 'path("M 75 0 L 150 150 L 0 150 Z")',
+ }}
+ />
+ </AbsoluteFill>
+ );
+};
+
+export const clipPathPath = {
+ component: Component,
+ id: 'clip-path-path',
+ width: 200,
+ height: 200,
+ fps: 30,
+ durationInFrames: 1,
+} as const;
diff --git a/packages/web-renderer/src/test/fixtures/clip-path-polygon.tsx b/packages/web-renderer/src/test/fixtures/clip-path-polygon.tsx
new file mode 100644
index 0000000000..7f8472bb80
--- /dev/null
+++ b/packages/web-renderer/src/test/fixtures/clip-path-polygon.tsx
@@ -0,0 +1,31 @@
+import React from 'react';
+import {AbsoluteFill} from 'remotion';
+
+const Component: React.FC = () => {
+ return (
+ <AbsoluteFill
+ style={{
+ justifyContent: 'center',
+ alignItems: 'center',
+ }}
+ >
+ <div
+ style={{
+ width: 150,
+ height: 150,
+ backgroundColor: 'blue',
+ clipPath: 'polygon(50% 0%, 100% 100%, 0% 100%)',
+ }}
+ />
+ </AbsoluteFill>
+ );
+};
+
+export const clipPathPolygon = {
+ component: Component,
+ id: 'clip-path-polygon',
+ width: 200,
+ height: 200,
+ fps: 30,
+ durationInFrames: 1,
+} as const;