Skip to content

🎥 Make videos programmatically with React

Merge remote-tracking branch 'origin/main' into HEAD

Jonny Burger09f1eec7f9e5
diff --cc packages/canvas/src/index.ts
index e2e76708f9,75dd96e6b8..c4f2c1df58
--- a/packages/canvas/src/index.ts
+++ b/packages/canvas/src/index.ts
@@@ -3,9 -3,59 +3,60 @@@ export {Canvas} from './canvas'
export type {CanvasProps} from './canvas';
export {createCanvasController, useCanvasController} from './canvas-controller';
export type {CanvasController} from './canvas-controller';
+ export {
+ createCanvasHoverController,
+ useCanvasHover,
+ useCanvasSequenceHover,
+ useIsCanvasSequenceHovered,
+ } from './hover';
+ export type {CanvasHover, CanvasHoverController} from './hover';
+ export type {
+ CanvasOutline,
+ CanvasOutlinePoint,
+ CanvasOutlineUv,
+ CanvasOutlineCrop,
+ CanvasOutlineTarget,
+ } from './outline-geometry';
+ export {getCanvasOutlinePoint, getCanvasOutlineUv} from './outline-geometry';
+ export {
+ measureCanvasOutlineTargets,
+ cropCanvasOutlinePoints,
+ canvasOutlinesAreEqual,
+ getTransformedSvgViewportPoints,
+ } from './outline-measurement';
+ export {orderCanvasOutlinesForRendering} from './outline-order';
+ export type {
+ CanvasOutlineOrderTarget,
+ CanvasOutlineSequenceParent,
+ } from './outline-order';
+ export {useCanvasOutlineMeasurements} from './use-canvas-outline-measurements';
+ export {useCanvasOutlines} from './use-canvas-outlines';
+ export type {CanvasOutlineRenderTarget} from './use-canvas-outlines';
+ export {CanvasOutlinePolygon} from './canvas-outline-polygon';
+ export type {CanvasOutlinePolygonProps} from './canvas-outline-polygon';
+ export {
+ getCanvasOutlineSelectionInteraction,
+ handleCanvasOutlinePointerDown,
+ } from './outline-interaction';
+ export type {CanvasOutlinePointerDownDecision} from './outline-interaction';
+ export {
+ getCanvasActiveOutlineTargets,
+ getCanvasOutlineActivity,
+ getCanvasOutlineLayoutTargets,
+ getCanvasSelectableOutlines,
+ getCanvasSelectedSequenceKeys,
+ getCanvasSequenceKeysContainingSelection,
+ getCanvasVisibleOutlineTargets,
+ } from './outline-targets';
+ export type {
+ CanvasSelectableOutline,
+ CanvasOutlineLayoutTarget,
+ } from './outline-targets';
+ export {getCanvasSequenceNodePathInfo} from './sequence-node-path';
+ export type {CanvasSequenceNodePathResolver} from './sequence-node-path';
export {getConnectedCompositions} from './get-connected-compositions';
export {
+ getParentSequencePlaybackRate,
getCascadedStart,
getCascadedStartWithTrim,
getTimelineVisibleDuration,
diff --cc packages/canvas/src/outline-targets.ts
index 0000000000,551601aff5..35f10180cf
mode 000000,100644..100644
--- a/packages/canvas/src/outline-targets.ts
+++ b/packages/canvas/src/outline-targets.ts
@@@ -1,0 -1,246 +1,248 @@@
+ import type {RefObject} from 'react';
+ import type {TSequence} from 'remotion';
+ import type {
+ SequenceNodePathInfo,
+ TimelineTrackData,
+ } from './get-timeline-sequence-sort-key';
+ import type {CanvasHover} from './hover';
+ import {
+ getCanvasSequenceSelectionKey,
+ type CanvasSelectionItem,
+ } from './selection';
+ import type {CanvasSequenceNodePathResolver} from './sequence-node-path';
+ import {timelineSequenceNodePathToKey} from './timeline-sequence-node-path-to-key';
+
+ export type CanvasSelectableOutline = {
+ readonly depth: number;
+ readonly keyframeDisplayOffset: number;
++ readonly keyframePlaybackRate: number;
+ readonly key: string;
+ readonly nodePathInfo: SequenceNodePathInfo;
+ readonly sequence: TSequence;
+ };
+
+ export type CanvasOutlineLayoutTarget = CanvasSelectableOutline & {
+ readonly nodePathKey: string;
+ readonly ref: RefObject<Element | null>;
+ readonly selected: boolean;
+ readonly containsSelection: boolean;
+ readonly showSelectedOutline: boolean;
+ readonly selection: Extract<CanvasSelectionItem, {type: 'sequence'}>;
+ };
+
+ export const getCanvasVisibleOutlineTargets = <
+ T extends {readonly sequence: Pick<TSequence, 'from' | 'duration'>},
+ >({
+ targets,
+ timelinePosition,
+ }: {
+ readonly targets: readonly T[];
+ readonly timelinePosition: number;
+ }): T[] => {
+ return targets.filter(
+ ({sequence}) =>
+ timelinePosition >= sequence.from &&
+ timelinePosition < sequence.from + sequence.duration,
+ );
+ };
+
+ /** A null timeline position includes all registered, selectable instances. */
+ export const getCanvasSelectableOutlines = ({
+ tracks,
+ timelinePosition,
+ resolveSequenceNodePathInfo,
+ }: {
+ readonly tracks: readonly TimelineTrackData[];
+ readonly timelinePosition: number | null;
+ readonly resolveSequenceNodePathInfo: CanvasSequenceNodePathResolver | null;
+ }): CanvasSelectableOutline[] => {
+ const selectableOutlines = tracks
+ .flatMap((track, index): CanvasSelectableOutline[] => {
+ const {sequence} = track;
+ if (!sequence.showInTimeline || sequence.refForOutline === null) {
+ return [];
+ }
+
+ const nodePathInfo =
+ resolveSequenceNodePathInfo === null
+ ? track.nodePathInfo
+ : resolveSequenceNodePathInfo(track, index);
+ if (nodePathInfo === null || nodePathInfo.auxiliaryKeys.length !== 0) {
+ return [];
+ }
+
+ return [
+ {
+ depth: track.depth,
+ keyframeDisplayOffset: track.keyframeDisplayOffset,
++ keyframePlaybackRate: track.keyframePlaybackRate,
+ key: getCanvasSequenceSelectionKey(nodePathInfo),
+ nodePathInfo,
+ sequence,
+ },
+ ];
+ })
+ .sort((a, b) => a.depth - b.depth);
+
+ return timelinePosition === null
+ ? selectableOutlines
+ : getCanvasVisibleOutlineTargets({
+ targets: selectableOutlines,
+ timelinePosition,
+ });
+ };
+
+ export const getCanvasSelectedSequenceKeys = (
+ selectedItems: readonly CanvasSelectionItem[],
+ ): Set<string> => {
+ return new Set(
+ selectedItems
+ .filter((item) => item.type === 'sequence')
+ .map((item) => getCanvasSequenceSelectionKey(item.nodePathInfo)),
+ );
+ };
+
+ export const getCanvasSequenceKeysContainingSelection = (
+ selectedItems: readonly CanvasSelectionItem[],
+ ): Set<string> => {
+ return new Set(
+ selectedItems
+ .filter((item) => item.type !== 'guide')
+ .map((item) => getCanvasSequenceSelectionKey(item.nodePathInfo)),
+ );
+ };
+
+ /** Keeps every instance of an active source while the canvas is inactive. */
+ export const getCanvasActiveOutlineTargets = <
+ T extends Pick<CanvasSelectableOutline, 'key' | 'nodePathInfo'>,
+ >({
+ targets,
+ selectedSequenceKeys,
+ sequenceKeysContainingSelection,
+ hoveredNodePathKey,
+ measureAll,
+ }: {
+ readonly targets: readonly T[];
+ readonly selectedSequenceKeys: ReadonlySet<string>;
+ readonly sequenceKeysContainingSelection: ReadonlySet<string>;
+ readonly hoveredNodePathKey: string | null;
+ readonly measureAll: boolean;
+ }): readonly T[] => {
+ if (measureAll) {
+ return targets;
+ }
+
+ const activeNodePathKeys = new Set<string>();
+ for (const {key, nodePathInfo} of targets) {
+ const nodePathKey = timelineSequenceNodePathToKey(
+ nodePathInfo.sequenceSubscriptionKey,
+ );
+ if (
+ selectedSequenceKeys.has(key) ||
+ sequenceKeysContainingSelection.has(key) ||
+ nodePathKey === hoveredNodePathKey
+ ) {
+ activeNodePathKeys.add(nodePathKey);
+ }
+ }
+
+ return targets.filter(({nodePathInfo}) =>
+ activeNodePathKeys.has(
+ timelineSequenceNodePathToKey(nodePathInfo.sequenceSubscriptionKey),
+ ),
+ );
+ };
+
+ /** Builds selection state shared by canvas instances of the same source. */
+ export const getCanvasOutlineLayoutTargets = ({
+ selectableOutlines,
+ selectedSequenceKeys,
+ sequenceKeysContainingSelection,
+ targetKey,
+ }: {
+ readonly selectableOutlines: readonly CanvasSelectableOutline[];
+ readonly selectedSequenceKeys: ReadonlySet<string>;
+ readonly sequenceKeysContainingSelection: ReadonlySet<string>;
+ readonly targetKey: string | null;
+ }): CanvasOutlineLayoutTarget[] => {
+ const firstNodePathInfoBySourceNode = new Map<string, SequenceNodePathInfo>();
+ const selectedSourceNodeKeys = new Set<string>();
+ for (const {key, nodePathInfo} of selectableOutlines) {
+ const sourceNodeKey = timelineSequenceNodePathToKey(
+ nodePathInfo.sequenceSubscriptionKey,
+ );
+ if (selectedSequenceKeys.has(key)) {
+ selectedSourceNodeKeys.add(sourceNodeKey);
+ }
+
+ const currentFirst = firstNodePathInfoBySourceNode.get(sourceNodeKey);
+ if (currentFirst === undefined || nodePathInfo.index < currentFirst.index) {
+ firstNodePathInfoBySourceNode.set(sourceNodeKey, nodePathInfo);
+ }
+ }
+
+ return selectableOutlines.flatMap((selectableOutline) => {
+ const {key, nodePathInfo, sequence} = selectableOutline;
+ if (targetKey !== null && targetKey !== key) {
+ return [];
+ }
+
+ if (sequence.refForOutline === null) {
+ throw new Error('Expected sequence to have a ref for outline');
+ }
+
+ const nodePathKey = timelineSequenceNodePathToKey(
+ nodePathInfo.sequenceSubscriptionKey,
+ );
+ const selectionNodePathInfo =
+ firstNodePathInfoBySourceNode.get(nodePathKey);
+ if (selectionNodePathInfo === undefined) {
+ throw new Error('Expected a first sequence for the source node');
+ }
+
+ const containsSelection = sequenceKeysContainingSelection.has(key);
+ return [
+ {
+ ...selectableOutline,
+ nodePathKey,
+ ref: sequence.refForOutline,
+ selected: selectedSequenceKeys.has(key),
+ containsSelection,
+ showSelectedOutline:
+ containsSelection || selectedSourceNodeKeys.has(nodePathKey),
+ selection: {
+ type: 'sequence' as const,
+ nodePathInfo: selectionNodePathInfo,
+ },
+ },
+ ];
+ });
+ };
+
+ /** Activation keeps frame subscriptions out of an idle outline overlay. */
+ export const getCanvasOutlineActivity = ({
+ canvasHovered,
+ dragging,
+ contextMenuOpen,
+ hasSelection,
+ hoveredSequence,
+ }: {
+ readonly canvasHovered: boolean;
+ readonly dragging: boolean;
+ readonly contextMenuOpen: boolean;
+ readonly hasSelection: boolean;
+ readonly hoveredSequence: CanvasHover | null;
+ }) => {
+ const measureAllOutlines = canvasHovered || dragging || contextMenuOpen;
+ return {
+ measurementActive:
+ measureAllOutlines ||
+ hasSelection ||
+ hoveredSequence?.source === 'timeline',
+ measureAllOutlines,
+ hoveredTimelineNodePathKey:
+ hoveredSequence?.source === 'timeline'
+ ? hoveredSequence.nodePathKey
+ : null,
+ };
+ };
diff --cc packages/studio/src/components/SelectedOutlineOverlay.tsx
index c4689b1593,946b0d03dc..6a813890ff
--- a/packages/studio/src/components/SelectedOutlineOverlay.tsx
+++ b/packages/studio/src/components/SelectedOutlineOverlay.tsx
@@@ -55,11 -62,9 +62,12 @@@ import
} from './selected-outline-types';
import {SelectedOutlineKeyboardControls} from './SelectedOutlineKeyboardControls';
import {SelectedOutlineRenderer} from './SelectedOutlineRenderer';
-import {getKeyframeDisplayOffset} from './Timeline/get-timeline-keyframes';
+import {
+ getKeyframeDisplayOffset,
+ getKeyframeSourceFrame,
+} from './Timeline/get-timeline-keyframes';
import {
+ useCurrentTimelineSelectionStateAsRef,
useTimelineSelection,
type TimelineSelection,
type TimelineSelectionInteraction,
@@@ -265,49 -272,15 +275,20 @@@ const calculateOutlineTargets = (
const previewInteractive =
connectedClientId !== null && studioInteractivityEnabled;
- const firstNodePathInfoBySourceNode = new Map<string, SequenceNodePathInfo>();
- const selectedSourceNodeKeys = new Set<string>();
- for (const {key, nodePathInfo} of selectableOutlines) {
- const sourceNodeKey = timelineSequenceNodePathToKey(
- nodePathInfo.sequenceSubscriptionKey,
- );
- if (selectedSequenceKeys.has(key)) {
- selectedSourceNodeKeys.add(sourceNodeKey);
- }
-
- const currentFirst = firstNodePathInfoBySourceNode.get(sourceNodeKey);
- if (currentFirst === undefined || nodePathInfo.index < currentFirst.index) {
- firstNodePathInfoBySourceNode.set(sourceNodeKey, nodePathInfo);
- }
- }
-
- return selectableOutlines.flatMap((selectableOutline) => {
+ return getCanvasOutlineLayoutTargets({
+ selectableOutlines,
+ selectedSequenceKeys,
+ sequenceKeysContainingSelection,
+ targetKey,
+ }).flatMap((canvasLayoutTarget) => {
- const {key, keyframeDisplayOffset, nodePathInfo, sequence} =
- canvasLayoutTarget;
+ const {
+ key,
+ keyframeDisplayOffset,
+ keyframePlaybackRate,
+ nodePathInfo,
+ sequence,
- } = selectableOutline;
- if (targetKey !== null && targetKey !== key) {
- return [];
- }
-
- if (sequence.refForOutline === null) {
- throw new Error('Expected sequence to have a ref for outline');
- }
-
- const selected = selectedSequenceKeys.has(key);
- const containsSelection = sequenceKeysContainingSelection.has(key);
++ } = canvasLayoutTarget;
const nodePath = nodePathInfo.sequenceSubscriptionKey;
- const sourceNodeKey = timelineSequenceNodePathToKey(nodePath);
- const showSelectedOutline =
- containsSelection || selectedSourceNodeKeys.has(sourceNodeKey);
- const selectionNodePathInfo =
- firstNodePathInfoBySourceNode.get(sourceNodeKey);
- if (selectionNodePathInfo === undefined) {
- throw new Error('Expected a first sequence for the source node');
- }
const {controls} = sequence;
const nodePropStatuses = Internals.getPropStatusesCtx(
diff --cc packages/studio/src/components/selected-outline-types.ts
index 3f7b188c69,0611c1ba75..6de0bf5386
--- a/packages/studio/src/components/selected-outline-types.ts
+++ b/packages/studio/src/components/selected-outline-types.ts
@@@ -5,12 -10,8 +10,9 @@@ import type
InteractivitySchema,
InteractivitySchemaField,
SequencePropsSubscriptionKey,
- TSequence,
} from 'remotion';
- import type {SequenceNodePathInfo} from '../helpers/get-timeline-sequence-sort-key';
import type {ComboboxValue} from './NewComposition/ComboBox';
+import type {KeyframeSourceFrame} from './Timeline/get-timeline-keyframes';
- import type {TimelineSelection} from './Timeline/TimelineSelection';
export type SelectedOutlineContextMenuOpenResult =
| false