Skip to content

🎥 Make videos programmatically with React

Align transition trim highlights with diagonal edges

JonnyBurger1daa4eb53b01
diff --git a/packages/studio/src/components/Timeline/TimelineSequence.tsx b/packages/studio/src/components/Timeline/TimelineSequence.tsx
index 7cd86a2dcb..ec3a49e70d 100644
--- a/packages/studio/src/components/Timeline/TimelineSequence.tsx
+++ b/packages/studio/src/components/Timeline/TimelineSequence.tsx
@@ -571,10 +571,40 @@ const TimelineSequenceBar: React.FC<{
style.height,
style.marginLeft,
]);
+ const trimShape = useMemo(() => {
+ if (activeTrimEdge === null || isTransition || frameIncrement === null) {
+ return null;
+ }
+
+ return getTimelineSceneShape({
+ sceneRange,
+ offsetInFrames: Number(style.marginLeft) / frameIncrement,
+ durationInFrames: Number(style.width) / frameIncrement,
+ pixelsPerFrame: frameIncrement,
+ height:
+ s.timelineTrack?.role === 'clip'
+ ? Number(style.height)
+ : (sceneClipHeight ?? Number(style.height)),
+ cropHeight: Number(style.height),
+ });
+ }, [
+ activeTrimEdge,
+ isTransition,
+ frameIncrement,
+ sceneRange,
+ style.marginLeft,
+ style.width,
+ style.height,
+ s.timelineTrack?.role,
+ sceneClipHeight,
+ ]);
+ const diagonalTrimEdge =
+ activeTrimEdge === null ? null : (trimShape?.edges[activeTrimEdge] ?? null);
// Back the antialiased rounded edge only when the glow is at the painted layer edge.
const trimHighlightColor = isAtTrimLimit ? RED : '#00E500';
const sequenceBackground =
activeTrimEdge === null ||
+ diagonalTrimEdge !== null ||
(activeTrimEdge === 'left' && leftTrimHighlight?.left !== negativeStartEnd)
? style.background
: `linear-gradient(to ${activeTrimEdge === 'left' ? 'right' : 'left'}, ${trimHighlightColor} 0 2px, transparent 2px), ${style.background ?? TRANSPARENT}`;
@@ -720,7 +750,37 @@ const TimelineSequenceBar: React.FC<{
) : null}
{activeTrimEdge === null ||
- (activeTrimEdge === 'left' && leftTrimHighlight === null) ? null : (
+ (activeTrimEdge === 'left' &&
+ leftTrimHighlight === null) ? null : diagonalTrimEdge !== null &&
+ trimShape ? (
+ <svg
+ aria-hidden="true"
+ style={{
+ position: 'absolute',
+ left: 0,
+ top: 0,
+ width: Number(style.width),
+ height: Number(style.height),
+ clipPath: trimShape.clipPath,
+ overflow: 'hidden',
+ pointerEvents: 'none',
+ }}
+ >
+ <path
+ d={diagonalTrimEdge}
+ fill="none"
+ stroke={trimHighlightColor}
+ strokeWidth={EDGE_DRAG_HIGHLIGHT_WIDTH}
+ style={{filter: 'blur(4px)'}}
+ />
+ <path
+ d={diagonalTrimEdge}
+ fill="none"
+ stroke={trimHighlightColor}
+ strokeWidth={4}
+ />
+ </svg>
+ ) : (
<div
aria-hidden="true"
style={{
diff --git a/packages/studio/src/components/Timeline/get-timeline-scene-clip-path.ts b/packages/studio/src/components/Timeline/get-timeline-scene-clip-path.ts
index 7e8932bb30..2f70c7f75b 100644
--- a/packages/studio/src/components/Timeline/get-timeline-scene-clip-path.ts
+++ b/packages/studio/src/components/Timeline/get-timeline-scene-clip-path.ts
@@ -19,6 +19,7 @@ export const getTimelineSceneShape = ({
}: TimelineSceneClipOptions): {
readonly clipPath: string;
readonly points: string;
+ readonly edges: {readonly left: string | null; readonly right: string | null};
} | null => {
if (
sceneRange === null ||
@@ -31,7 +32,11 @@ export const getTimelineSceneShape = ({
}
if (sceneRange.end <= sceneRange.from) {
- return {clipPath: 'inset(0 100% 0 0)', points: ''};
+ return {
+ clipPath: 'inset(0 100% 0 0)',
+ points: '',
+ edges: {left: null, right: null},
+ };
}
// Move only the outgoing diagonal inward by one perpendicular pixel, so
@@ -53,8 +58,31 @@ export const getTimelineSceneShape = ({
},
{x: sceneRange.from, y: 100},
];
-
+ const edgePoints = points.map(
+ ({x, y}) =>
+ `${(x - offsetInFrames) * pixelsPerFrame},${(y / 100) * height}`,
+ );
const visibleHeight = cropHeight ?? height;
+ const edges: {left: string | null; right: string | null} = {
+ left: null,
+ right: null,
+ };
+ for (const [edge, start, end, transition] of [
+ ['left', 0, 3, sceneRange.transitionInEnd],
+ ['right', 1, 2, sceneRange.transitionOutStart],
+ ] as const) {
+ const bottomX =
+ points[start].x +
+ (points[end].x - points[start].x) * Math.min(1, visibleHeight / height);
+ if (
+ transition !== null &&
+ Math.max(points[start].x, bottomX) > offsetInFrames &&
+ Math.min(points[start].x, bottomX) < offsetInFrames + durationInFrames
+ ) {
+ edges[edge] = `M${edgePoints[start]}L${edgePoints[end]}`;
+ }
+ }
+
// Intersect with the rendered bar without changing the parent row's slope.
// Expanded rows can be taller than the child bar whose outline is visible.
for (const {boundary, keepGreater, axis} of [
@@ -104,10 +132,15 @@ export const getTimelineSceneShape = ({
}
if (points.length === 0) {
- return {clipPath: 'inset(0 100% 0 0)', points: ''};
+ return {
+ clipPath: 'inset(0 100% 0 0)',
+ points: '',
+ edges: {left: null, right: null},
+ };
}
return {
+ edges,
clipPath: `polygon(${points
.map(
({x, y}) =>