Skip to content

🎥 Make videos programmatically with React

Merge main and preserve off-frame outline dragging

Jonny Burger8b9e7a4cd0dc
diff --cc packages/studio/src/components/SelectedOutlineOverlay.tsx
index d20c1f62ea,6b854158c4..946b0d03dc
--- a/packages/studio/src/components/SelectedOutlineOverlay.tsx
+++ b/packages/studio/src/components/SelectedOutlineOverlay.tsx
@@@ -828,13 -882,8 +834,13 @@@ const SelectedOutlineOverlayUnmemoized
() => getSelectedCropInfo(selectedItems),
[selectedItems],
);
- const getSelectableOutlines = useCallback(
- (timelinePosition: number | null) => {
+ const getSelectableOutlines = useMemo(() => {
+ // Resolve source identities once per sequence snapshot, on first demand.
+ // Playback only filters the cached candidates by their visible range.
+ let selectableOutlines: ReturnType<
+ typeof getSequencesWithSelectableOutlines
+ > | null = null;
- return (timelinePosition: number) => {
++ return (timelinePosition: number | null) => {
if (
isFullscreen ||
!isStudioSelectionEnabled() ||
@@@ -844,28 -893,22 +850,30 @@@
return [];
}
- return getSequencesWithSelectableOutlines({
- sequences,
- overrideIdsToNodePaths: overrideIdToNodePathMappings,
- compositions,
- timelinePosition,
+ selectableOutlines ??= getCanvasSelectableOutlines({
+ tracks: calculateTimeline({
+ sequences: [...sequences],
+ overrideIdsToNodePaths: overrideIdToNodePathMappings,
+ compositions,
+ }),
+ timelinePosition: null,
+ resolveSequenceNodePathInfo: null,
});
- return getCanvasVisibleOutlineTargets({
- targets: selectableOutlines,
- timelinePosition,
- });
- },
- [
- compositions,
- editorShowOutlines,
- isFullscreen,
- overrideIdToNodePathMappings,
- previewSelectionAvailable,
- sequences,
- ],
- );
++ return timelinePosition === null
++ ? selectableOutlines
++ : getCanvasVisibleOutlineTargets({
++ targets: selectableOutlines,
++ timelinePosition,
++ });
+ };
+ }, [
+ compositions,
+ editorShowOutlines,
+ isFullscreen,
+ overrideIdToNodePathMappings,
+ previewSelectionAvailable,
+ sequences,
+ ]);
const calculateOutlineTargetsForCurrentState =
useCallback<CalculateOutlineTargets>(
diff --cc packages/studio/src/components/SelectedOutlineRenderer.tsx
index 28860a9d0d,d3c1445a79..78a01f3a66
--- a/packages/studio/src/components/SelectedOutlineRenderer.tsx
+++ b/packages/studio/src/components/SelectedOutlineRenderer.tsx
@@@ -5,14 -4,23 +5,15 @@@ import React,
useLayoutEffect,
useMemo,
useRef,
- useState,
} from 'react';
import {timelineSequenceNodePathToKey} from '../helpers/timeline-node-path-key';
-import {
- useSetTimelineSequenceHover,
- useTimelineSequenceHoverState,
-} from '../state/timeline-sequence-hover';
+import {TimelineSequenceHoverContext} from '../state/timeline-sequence-hover';
import {ContextMenuForTarget} from './ContextMenu';
import type {SelectedOutline} from './selected-outline-geometry';
-import {
- measureOutlines,
- outlinesAreEqual,
-} from './selected-outline-measurement';
-import {orderOutlinesForRendering} from './selected-outline-order';
+import type {orderOutlinesForRendering} from './selected-outline-order';
import type {
SelectedOutlineContextMenuOpenHandler,
+ SelectedOutlineDragTarget,
SelectedOutlineLayoutTarget,
SelectedOutlineTarget,
} from './selected-outline-types';
diff --cc packages/studio/src/components/selected-outline-measurement.ts
index 9d8ef0f947,b22f0d553f..81f06c21e5
--- a/packages/studio/src/components/selected-outline-measurement.ts
+++ b/packages/studio/src/components/selected-outline-measurement.ts
@@@ -399,15 -607,163 +399,15 @@@ export const getSequencesWithSelectable
readonly sequences: readonly TSequence[];
readonly overrideIdsToNodePaths: OverrideIdToNodePaths;
readonly compositions?: readonly _InternalTypes['AnyComposition'][];
- readonly timelinePosition: number;
+ readonly timelinePosition: number | null;
}): SequenceWithSelectedOutline[] => {
- return calculateTimeline({
- sequences: [...sequences],
- overrideIdsToNodePaths,
- compositions,
- })
- .filter((track) => {
- if (track.nodePathInfo === null) {
- return false;
- }
-
- return (
- track.sequence.showInTimeline &&
- (timelinePosition === null ||
- (timelinePosition >= track.sequence.from &&
- timelinePosition <
- track.sequence.from + track.sequence.duration)) &&
- track.nodePathInfo.auxiliaryKeys.length === 0
- );
- })
- .filter((track) => track.sequence.refForOutline !== null)
- .sort((a, b) => a.depth - b.depth)
- .map((track) => {
- if (track.nodePathInfo === null) {
- throw new Error('Expected selected outline to have a node path');
- }
-
- return {
- depth: track.depth,
- keyframeDisplayOffset: track.keyframeDisplayOffset,
- key: getTimelineSequenceSelectionKey(track.nodePathInfo),
- nodePathInfo: track.nodePathInfo,
- sequence: track.sequence,
- };
- });
-};
-
-export const measureOutlines = (
- container: SVGSVGElement,
- targets: readonly SelectedOutlineLayoutTarget[],
- hoveredTimelineNodePathKey: string | null,
-): SelectedOutline[] => {
- return measureOutlineTargets(
- container,
- targets.map((target) => ({
- crop: target.crop,
- includeOutsideContainer:
- target.showSelectedOutline ||
- timelineSequenceNodePathToKey(
- target.nodePathInfo.sequenceSubscriptionKey,
- ) === hoveredTimelineNodePathKey,
- key: target.key,
- ref: target.ref,
- })),
- );
-};
-
-export const measureOutlineTargets = (
- container: Element,
- targets: readonly {
- readonly crop: SelectedOutlineLayoutTarget['crop'];
- readonly includeOutsideContainer: boolean;
- readonly key: string;
- readonly ref: React.RefObject<Element | null>;
- }[],
-): SelectedOutline[] => {
- // Reuse shared ancestor geometry within this synchronous batch only.
- resetBoxQuadsCache();
- const containerRect = container.getBoundingClientRect();
- const outlines: SelectedOutline[] = [];
-
- for (const target of targets) {
- const element = target.ref.current;
- if (element === null) {
- continue;
- }
-
- const uncroppedPoints = getElementOutlinePoints(
- element,
- containerRect,
- target.includeOutsideContainer,
- );
- if (uncroppedPoints === null) {
- continue;
- }
-
- const points = cropOutlinePoints(uncroppedPoints, target.crop);
-
- outlines.push({
- key: target.key,
- dimensions:
- element instanceof HTMLElement
- ? {
- width: element.offsetWidth,
- height: element.offsetHeight,
- }
- : element instanceof SVGSVGElement
- ? {
- width: element.width.baseVal.value,
- height: element.height.baseVal.value,
- }
- : null,
- uncroppedPoints,
- points,
- });
- }
-
- return outlines;
-};
-
-export const outlinesAreEqual = (
- a: readonly SelectedOutline[],
- b: readonly SelectedOutline[],
-): boolean => {
- if (a.length !== b.length) {
- return false;
- }
-
- for (let i = 0; i < a.length; i++) {
- if (a[i].key !== b[i].key) {
- return false;
- }
-
- if (
- a[i].dimensions?.width !== b[i].dimensions?.width ||
- a[i].dimensions?.height !== b[i].dimensions?.height
- ) {
- return false;
- }
-
- const aUncropped = a[i].uncroppedPoints;
- const bUncropped = b[i].uncroppedPoints;
- if ((aUncropped === null) !== (bUncropped === null)) {
- return false;
- }
-
- if (aUncropped !== null && bUncropped !== null) {
- for (let j = 0; j < aUncropped.length; j++) {
- if (
- Math.abs(aUncropped[j].x - bUncropped[j].x) > 0.01 ||
- Math.abs(aUncropped[j].y - bUncropped[j].y) > 0.01
- ) {
- return false;
- }
- }
- }
-
- for (let j = 0; j < a[i].points.length; j++) {
- if (
- Math.abs(a[i].points[j].x - b[i].points[j].x) > 0.01 ||
- Math.abs(a[i].points[j].y - b[i].points[j].y) > 0.01
- ) {
- return false;
- }
- }
- }
-
- return true;
+ return getCanvasSelectableOutlines({
+ tracks: calculateTimeline({
+ sequences: [...sequences],
+ overrideIdsToNodePaths,
+ compositions,
+ }),
+ timelinePosition,
+ resolveSequenceNodePathInfo: null,
+ });
};