Skip to content

🎥 Make videos programmatically with React

Merge remote-tracking branch 'origin/main' into codex/studio-transition-triangles

JonnyBurger7601dc214294
diff --cc packages/studio/src/components/Timeline/TimelineSequence.tsx
index 502ed5d86e,945b831328..57ca9b7468
--- a/packages/studio/src/components/Timeline/TimelineSequence.tsx
+++ b/packages/studio/src/components/Timeline/TimelineSequence.tsx
@@@ -17,7 -17,9 +17,8 @@@ import type
import {Internals} from 'remotion';
import {StudioServerConnectionCtx} from '../../helpers/client-id';
import {
- BLACK_ALPHA_22,
BLUE,
+ RED,
TIMELINE_AUDIO_GRADIENT,
TIMELINE_BACKGROUND_COLOR,
TIMELINE_CAPTIONS_GRADIENT,
@@@ -509,75 -480,47 +528,82 @@@ const TimelineSequenceBar: React.FC<
paintedEnd +
Math.min(1, Math.max(0, paintedEnd - paintedStart - 1))
: 0;
+ const selectionLeft = selectionBounds?.left ?? 0;
+ const selectionRight = Math.max(
+ visualRightInset,
+ Number(style.width) - selectionLeft - (selectionBounds?.width ?? 0),
+ );
+ const selectionWidth = Number(style.width) - selectionLeft - selectionRight;
+ const selectionShape = useMemo(() => {
+ if (
+ !(selected || containsSelection) ||
+ isTransition ||
+ frameIncrement === null ||
+ sceneRange === null ||
+ (sceneRange.transitionInEnd === null &&
+ sceneRange.transitionOutStart === null)
+ ) {
+ return null;
+ }
+
+ return getTimelineSceneShape({
+ sceneRange,
+ offsetInFrames:
+ (Number(style.marginLeft) + selectionLeft) / frameIncrement,
+ durationInFrames: selectionWidth / frameIncrement,
+ pixelsPerFrame: frameIncrement,
+ height:
+ s.timelineTrack?.role === 'clip'
+ ? Number(style.height)
+ : (sceneClipHeight ?? Number(style.height)),
+ cropHeight: Number(style.height),
+ });
+ }, [
+ containsSelection,
+ frameIncrement,
+ isTransition,
+ s.timelineTrack?.role,
+ sceneClipHeight,
+ sceneRange,
+ selected,
+ selectionLeft,
+ selectionWidth,
+ style.height,
+ style.marginLeft,
+ ]);
// Back the antialiased rounded edge only when the glow is at the painted layer edge.
+ const trimHighlightColor = isAtTrimLimit ? RED : '#00E500';
const sequenceBackground =
activeTrimEdge === null ||
(activeTrimEdge === 'left' && leftTrimHighlight?.left !== negativeStartEnd)
? style.background
- : `linear-gradient(to ${activeTrimEdge === 'left' ? 'right' : 'left'}, #00E500 0 2px, #00E50000 2px), ${style.background ?? TRANSPARENT}`;
+ : `linear-gradient(to ${activeTrimEdge === 'left' ? 'right' : 'left'}, ${trimHighlightColor} 0 2px, transparent 2px), ${style.background ?? TRANSPARENT}`;
- const actualStyle: React.CSSProperties = useMemo(() => {
+ const sceneClippingStyle: React.CSSProperties = useMemo(() => {
return {
- ...style,
- background: TRANSPARENT,
- opacity: 1,
- pointerEvents: isTransition ? 'none' : style.pointerEvents,
- maskImage:
+ clipPath:
s.timelineTrack?.role === 'clip' && frameIncrement !== null
- ? getTimelineSceneMask({
+ ? getTimelineSceneClipPath({
sceneRange,
offsetInFrames: Number(style.marginLeft) / frameIncrement,
durationInFrames: Number(style.width) / frameIncrement,
+ pixelsPerFrame: frameIncrement,
+ height: Number(style.height),
+ cropHeight: null,
})
: undefined,
- clipPath:
- s.timelineTrack?.role === 'clip' && sceneRange !== null
- ? `inset(0 ${Math.max(0, Number(style.width) - sceneRight)}px 0 ${Math.max(0, sceneLeft)}px)`
- : undefined,
};
- }, [style, isTransition, s.timelineTrack?.role, frameIncrement, sceneRange]);
- }, [
- style,
- s.timelineTrack?.role,
- frameIncrement,
- sceneRange,
- sceneLeft,
- sceneRight,
- ]);
++ }, [style, s.timelineTrack?.role, frameIncrement, sceneRange]);
+
+ const actualStyle: React.CSSProperties = useMemo(
+ () => ({
+ ...style,
+ background: TRANSPARENT,
+ opacity: 1,
+ pointerEvents: 'none',
+ }),
+ [style],
+ );
const premountIndicator = premount ? (
<div
@@@ -728,144 -692,86 +754,157 @@@
onPointerDown={selectable ? onPointerDown : undefined}
onClick={onClick ?? undefined}
>
- {/* Clip the paint to its scene, while keeping seam handles outside it hittable. */}
- <div
- style={{
- position: 'absolute',
- inset: 0,
- ...sceneClippingStyle,
- pointerEvents: 'auto',
- }}
- >
- {negativeStart ? (
- <>
- <TimelineSequenceNegativeStart
- left={negativeStart.left}
- width={negativeStart.width}
- leftEdgeVisible={leftEdgeVisible}
- clipped={negativeStartClipped}
- />
+ {isTransition ? (
+ frameIncrement === null ||
+ s.duration * frameIncrement < minTransitionAreaWidth ? null : (
+ <div
+ ref={ref}
+ role="group"
+ aria-label={s.displayName}
+ {...{[TIMELINE_MARQUEE_ITEM_ATTR]: true}}
+ data-timeline-transition-marker
+ style={{
+ position: 'absolute',
+ left:
+ Math.round(
+ (s.from + s.duration / 2) * frameIncrement -
+ transitionWidth / 2,
+ ) - Number(style.marginLeft),
+ top: transitionVerticalInset,
+ width: transitionWidth,
+ height: transitionHeight,
+ borderRadius: 4,
+ background: TIMELINE_BACKGROUND_COLOR,
+ pointerEvents: 'auto',
+ cursor: 'default',
+ boxShadow:
+ selected || containsSelection
+ ? `inset 0 0 0 2px ${WHITE}`
+ : undefined,
+ }}
+ >
+ <svg
+ aria-hidden="true"
+ width={transitionWidth}
+ height={transitionHeight}
+ viewBox="0 0 24 16"
+ style={{display: 'block'}}
+ >
+ <path
+ d="M7.5 4.5 16.5 11.5v-7l-9 7Z"
+ fill="none"
+ stroke={selected || containsSelection ? WHITE : WHITE_ALPHA_60}
+ strokeWidth={1}
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ />
+ </svg>
+ </div>
+ )
- ) : negativeStart ? (
- <>
- <TimelineSequenceNegativeStart
- left={negativeStart.left}
- width={negativeStart.width}
- leftEdgeVisible={leftEdgeVisible}
- clipped={negativeStartClipped}
- />
- <div
- style={{
- background: sequenceBackground,
- borderBottomLeftRadius: 0,
- borderBottomRightRadius: style.borderBottomRightRadius,
- borderTopLeftRadius: 0,
- borderTopRightRadius: style.borderTopRightRadius,
- boxSizing: 'border-box',
- height: '100%',
- left: negativeStartEnd,
- overflow: 'hidden',
- position: 'absolute',
- top: 0,
- width: `calc(100% - ${negativeStartEnd + visualRightInset}px)`,
- }}
- >
- <div
- style={{
- height: '100%',
- left: -negativeStartEnd,
- position: 'absolute',
- top: 0,
- width: `calc(100% + ${negativeStartEnd}px)`,
- }}
- >
- {content}
- </div>
- </div>
- </>
+ ) : (
+ <div
+ style={{
+ position: 'absolute',
+ inset: 0,
- right: visualRightInset,
- background: sequenceBackground,
- overflow: 'hidden',
- borderRadius: 'inherit',
++ ...sceneClippingStyle,
++ pointerEvents: 'auto',
+ }}
+ >
- {content}
++ {negativeStart ? (
++ <>
++ <TimelineSequenceNegativeStart
++ left={negativeStart.left}
++ width={negativeStart.width}
++ leftEdgeVisible={leftEdgeVisible}
++ clipped={negativeStartClipped}
++ />
++ <div
++ style={{
++ background: sequenceBackground,
++ borderBottomLeftRadius: 0,
++ borderBottomRightRadius: style.borderBottomRightRadius,
++ borderTopLeftRadius: 0,
++ borderTopRightRadius: style.borderTopRightRadius,
++ boxSizing: 'border-box',
++ height: '100%',
++ left: negativeStartEnd,
++ overflow: 'hidden',
++ position: 'absolute',
++ top: 0,
++ width: `calc(100% - ${negativeStartEnd + visualRightInset}px)`,
++ }}
++ >
++ <div
++ style={{
++ height: '100%',
++ left: -negativeStartEnd,
++ position: 'absolute',
++ top: 0,
++ width: `calc(100% + ${negativeStartEnd}px)`,
++ }}
++ >
++ {content}
++ </div>
++ </div>
++ </>
++ ) : (
+ <div
+ style={{
++ position: 'absolute',
++ inset: 0,
++ right: visualRightInset,
+ background: sequenceBackground,
- borderBottomLeftRadius: 0,
- borderBottomRightRadius: style.borderBottomRightRadius,
- borderTopLeftRadius: 0,
- borderTopRightRadius: style.borderTopRightRadius,
- boxSizing: 'border-box',
- height: '100%',
- left: negativeStartEnd,
+ overflow: 'hidden',
- position: 'absolute',
- top: 0,
- width: `calc(100% - ${negativeStartEnd + visualRightInset}px)`,
++ borderRadius: 'inherit',
+ }}
+ >
- <div
++ {content}
++ </div>
++ )}
++ {!isTransition &&
++ (selected || containsSelection) &&
++ selectionBounds ? (
++ selectionShape ? (
++ <svg
++ aria-hidden="true"
+ style={{
- height: '100%',
- left: -negativeStartEnd,
+ position: 'absolute',
++ left: selectionLeft,
+ top: 0,
- width: `calc(100% + ${negativeStartEnd}px)`,
++ width: selectionWidth,
++ height: Number(style.height),
++ clipPath: selectionShape.clipPath,
++ overflow: 'hidden',
++ pointerEvents: 'none',
+ }}
+ >
- {content}
- </div>
- </div>
- </>
- ) : (
- <div
- style={{
- position: 'absolute',
- inset: 0,
- right: visualRightInset,
- background: sequenceBackground,
- overflow: 'hidden',
- borderRadius: 'inherit',
- }}
- >
- {content}
- </div>
- )}
- {(selected || containsSelection) && selectionBounds ? (
- <div
- aria-hidden="true"
- style={{
- position: 'absolute',
- inset: 0,
- left: selectionBounds.left,
- right: Math.max(
- visualRightInset,
- Number(style.width) -
- selectionBounds.left -
- selectionBounds.width,
- ),
- borderRadius: 'inherit',
- boxShadow: `inset 0 0 0 2px ${WHITE}`,
- pointerEvents: 'none',
- }}
- />
- ) : null}
- </div>
++ <polygon
++ points={selectionShape.points}
++ fill="none"
++ stroke={WHITE}
++ // Half the stroke is clipped, matching the 2px inset outline.
++ strokeWidth={4}
++ strokeLinejoin="round"
++ vectorEffect="non-scaling-stroke"
++ />
++ </svg>
++ ) : (
++ <div
++ aria-hidden="true"
++ style={{
++ position: 'absolute',
++ inset: 0,
++ left: selectionLeft,
++ right: selectionRight,
++ borderRadius: 'inherit',
++ boxShadow: `inset 0 0 0 2px ${WHITE}`,
++ pointerEvents: 'none',
++ }}
++ />
++ )
++ ) : null}
+ </div>
+ )}
- {!isTransition && (selected || containsSelection) && selectionBounds ? (
- selectionShape ? (
- <svg
- aria-hidden="true"
- style={{
- position: 'absolute',
- left: selectionLeft,
- top: 0,
- width: selectionWidth,
- height: Number(style.height),
- clipPath: selectionShape.clipPath,
- overflow: 'hidden',
- pointerEvents: 'none',
- }}
- >
- <polygon
- points={selectionShape.points}
- fill="none"
- stroke={WHITE}
- // Half the stroke is clipped, matching the 2px inset outline.
- strokeWidth={4}
- strokeLinejoin="round"
- vectorEffect="non-scaling-stroke"
- />
- </svg>
- ) : (
- <div
- aria-hidden="true"
- style={{
- position: 'absolute',
- inset: 0,
- left: selectionLeft,
- right: selectionRight,
- borderRadius: 'inherit',
- boxShadow: `inset 0 0 0 2px ${WHITE}`,
- pointerEvents: 'none',
- }}
- />
- )
- ) : null}
<div style={{pointerEvents: 'auto'}}>{edgeDragHandles}</div>
</div>
);