Skip to content

πŸŽ₯ Make videos programmatically with React

`@remotion/canvas`: show full path geometry in outlines when cropped

Jonny Burger27dbec4a4636
diff --git a/packages/canvas/src/canvas-outline-polygon.tsx b/packages/canvas/src/canvas-outline-polygon.tsx
index b71dc1dc8e..b39078b146 100644
--- a/packages/canvas/src/canvas-outline-polygon.tsx
+++ b/packages/canvas/src/canvas-outline-polygon.tsx
@@ -1,4 +1,4 @@
-import React, {forwardRef, memo, useCallback, useId, useMemo} from 'react';
+import React, {forwardRef, memo, useCallback, useMemo} from 'react';
import type {CanvasOutline} from './outline-geometry';
export type CanvasOutlinePolygonProps = Omit<
@@ -46,23 +46,6 @@ export const CanvasOutlinePolygon = memo(
() => outline.points.map((point) => `${point.x},${point.y}`).join(' '),
[outline.points],
);
- // `useId()` contains characters that are unsafe inside `url(#...)`.
- const clipId = `clip-${useId().replace(/[^a-zA-Z0-9]/g, '')}`;
- // Like the element's own CSS `clip-path`, only clip the geometry when a
- // crop is actually applied - otherwise a path running along its
- // bounding box edge would lose half its stroke.
- const isCropped = useMemo(() => {
- const uncropped = outline.uncroppedPoints;
- if (uncropped === null) {
- return false;
- }
-
- return outline.points.some(
- (point, index) =>
- Math.abs(point.x - uncropped[index].x) > 0.01 ||
- Math.abs(point.y - uncropped[index].y) > 0.01,
- );
- }, [outline.points, outline.uncroppedPoints]);
const matrixTransform = useMemo(
() =>
outline.path === null
@@ -83,13 +66,6 @@ export const CanvasOutlinePolygon = memo(
return (
<g>
- {matrixTransform === null || !isCropped ? null : (
- <defs>
- <clipPath id={clipId}>
- <polygon points={points} />
- </clipPath>
- </defs>
- )}
<polygon
{...props}
ref={ref}
@@ -111,7 +87,6 @@ export const CanvasOutlinePolygon = memo(
<path
d={outline.path?.d ?? ''}
transform={matrixTransform}
- clipPath={isCropped ? `url(#${clipId})` : undefined}
fill="none"
stroke={stroke}
strokeOpacity={visible ? 1 : 0}
diff --git a/packages/canvas/src/outline-geometry.ts b/packages/canvas/src/outline-geometry.ts
index 0e33ca2eb9..eaf2d98b11 100644
--- a/packages/canvas/src/outline-geometry.ts
+++ b/packages/canvas/src/outline-geometry.ts
@@ -26,9 +26,9 @@ export type CanvasOutline = {
];
/**
* The SVG geometry of a path element, in the same space as
- * `uncroppedPoints`. Crop is not baked in β€” like the CSS `clip-path`
- * applied to the element, it clips the geometry at render time. Null for
- * non-path elements, or when the geometry cannot be read.
+ * `uncroppedPoints`. Crop is not baked in β€” the outline always shows the
+ * full geometry. Null for non-path elements, or when the geometry cannot
+ * be read.
*/
readonly path: CanvasOutlinePath | null;
};
diff --git a/packages/example/src/VisualModeTests/InteractivePaths.tsx b/packages/example/src/VisualModeTests/InteractivePaths.tsx
index 1571b097fb..383d0819c8 100644
--- a/packages/example/src/VisualModeTests/InteractivePaths.tsx
+++ b/packages/example/src/VisualModeTests/InteractivePaths.tsx
@@ -26,6 +26,7 @@ export const InteractivePaths: React.FC = () => {
stroke="#facc15"
strokeWidth={26}
strokeLinecap="round"
+ cropRight={0.5318}
/>
<text x={90} y={470} style={labelStyle}>
open curve