Skip to content

Commit 0938959

Browse files
committed
feat(studio): timeline glue swap — Timeline/TimelineCanvas onto the NLE engine
What: flips the timeline glue to its final form (23 files): Timeline and TimelineCanvas rebuilt on TimelineLanes/TimelineOverlays, useTimelineClipDrag drives preview/commit through the new drag engine, range selection goes multi-select, playback loop moves to useTimelinePlayerLoop. Deletes the 9 old-engine files this orphans (group drag, marquee selection, snap targets, layer gutter, selection overlays + their suites) — each is compile- or gate-forced by this swap, verified by probe. Why: second swap step; timeline-only, canvas and App untouched. How: modified files to final content + forced deletions. playerStore/timelineEditing/timelineCallbacks stay at their coexistence form until the app swap (the old App still runs on them). Test plan: tsc --noEmit; bunx vitest run (full suite); fallow audit clean.
1 parent 5b35c76 commit 0938959

34 files changed

Lines changed: 1597 additions & 3729 deletions

‎.fallowrc.jsonc‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,15 @@
123123
"packages/cli/src/cloud/_gen/**",
124124
],
125125
"ignoreExports": [
126+
// TEMP(studio-dnd): consumers land later in the stack; removed by studio-dnd/pr22.
127+
{
128+
"file": "packages/studio/src/player/components/timelineEditing.ts",
129+
"exports": [
130+
"selectTimelineElementsInMarquee",
131+
"TimelineGroupResizeEdge",
132+
"TimelineGroupTimingMember",
133+
],
134+
},
126135
// TEMP(studio-dnd): consumers land later in the stack; removed by studio-dnd/pr22.
127136
{
128137
"file": "packages/studio/src/hooks/timelineElementsMove.ts",
@@ -668,6 +677,10 @@
668677
// complexity pre-dates the computed-timeline work. Exempted at file level
669678
// rather than refactored as scope creep.
670679
"ignore": [
680+
// TEMP(studio-dnd): coexistence-window complexity flare (inherited/CRAP-no-coverage);
681+
// removed by studio-dnd/pr22 when the final config lands.
682+
"packages/studio/src/components/editor/LayersPanel.test.ts",
683+
"packages/studio/src/player/lib/timelineIframeHelpers.ts",
671684
// TEMP(studio-dnd): coexistence-window complexity flare (inherited/CRAP-no-coverage);
672685
// removed by studio-dnd/pr22 when the final config lands.
673686
"packages/studio/src/components/sidebar/AssetCard.tsx",

‎packages/studio/src/hooks/domSelectionTestHarness.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
// Shared harness helpers for selection hook tests (useDomSelection,
22
// usePreviewInteraction). Test-only module.
3+
import type React from "react";
4+
import { act } from "react";
5+
import { createRoot, type Root } from "react-dom/client";
36
import type { DomEditSelection } from "../components/editor/domEditing";
47

58
export function installReactActEnvironment(): void {
@@ -9,6 +12,17 @@ export function installReactActEnvironment(): void {
912
});
1013
}
1114

15+
/** Mount a React element into a fresh detached host and return its root. */
16+
export function mountReactHarness(node: React.ReactElement): Root {
17+
const host = document.createElement("div");
18+
document.body.append(host);
19+
const root = createRoot(host);
20+
act(() => {
21+
root.render(node);
22+
});
23+
return root;
24+
}
25+
1226
export function makeSelection(label: string, element: HTMLElement): DomEditSelection {
1327
return {
1428
element,

‎packages/studio/src/hooks/useAnimatedPropertyCommit.test.tsx‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// @vitest-environment happy-dom
22

33
import React, { act } from "react";
4-
import { createRoot } from "react-dom/client";
54
import { afterEach, describe, expect, it, vi } from "vitest";
65
import type { GsapAnimation } from "@hyperframes/core/gsap-parser";
76
import type { DomEditSelection } from "../components/editor/domEditingTypes";
87
import { usePlayerStore } from "../player/store/playerStore";
98
import { useAnimatedPropertyCommit } from "./useAnimatedPropertyCommit";
9+
import { mountReactHarness } from "./domSelectionTestHarness";
1010

1111
(globalThis as unknown as { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
1212

@@ -58,13 +58,7 @@ function renderHookWith(
5858
onReady(commitAnimatedProperties);
5959
return null;
6060
}
61-
const host = document.createElement("div");
62-
document.body.append(host);
63-
const root = createRoot(host);
64-
act(() => {
65-
root.render(<Harness />);
66-
});
67-
return root;
61+
return mountReactHarness(<Harness />);
6862
}
6963

7064
function renderCommitHook(

‎packages/studio/src/player/components/PlayheadIndicator.tsx‎

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,44 @@
22
/**
33
* Shared playhead visual used by TimelineCanvas (real playhead) and
44
* TimelineEditorNotice (animated illustration).
5+
*
6+
* The vertical line + glow span the full track height; the grab-handle HEAD is
7+
* `position: sticky; top: 0` so it pins to the top of the (vertically) scrolling
8+
* track area — the ruler is sticky too, so the head stays visible and grabbable
9+
* no matter how far the tracks are scrolled. The head is OUTLINE-only at rest and
10+
* FILLED while the playhead is actively held/scrubbed (`scrubbing`).
511
*/
612
interface PlayheadIndicatorProps {
713
/** CSS color, defaults to the HF accent variable */
814
color?: string;
915
/** Glow shadow color, defaults to translucent accent */
1016
glowColor?: string;
17+
/** Whether the playhead is being actively scrubbed — fills the head. */
18+
scrubbing?: boolean;
19+
/**
20+
* When false, the head chip is rendered in normal flow (top:1) instead of the
21+
* sticky pin — used by the static illustration where there is no scroll area.
22+
*/
23+
stickyHead?: boolean;
1124
}
1225

1326
export function PlayheadIndicator({
1427
color = "var(--hf-accent, #3CE6AC)",
1528
glowColor = "rgba(60,230,172,0.14)",
29+
scrubbing = false,
30+
stickyHead = true,
1631
}: PlayheadIndicatorProps) {
32+
// Head chip dimensions — used to compute the centering offset and the
33+
// point where the vertical line starts (so it begins at the head's bottom
34+
// edge rather than running through the hollow diamond center).
35+
const HEAD_W = 9;
36+
const HEAD_H = 9;
37+
// marginTop(1) + HEAD_H = where the line should start.
38+
const HEAD_TOTAL_H = 1 + HEAD_H;
39+
1740
return (
1841
<>
42+
{/* Glow — spans full height, centered on the line. */}
1943
<div
2044
aria-hidden="true"
2145
className="absolute top-0 bottom-0"
@@ -26,23 +50,44 @@ export function PlayheadIndicator({
2650
background: `radial-gradient(closest-side, ${glowColor}, transparent)`,
2751
}}
2852
/>
53+
{/* Vertical line — starts at the bottom edge of the head chip so nothing
54+
shows through the hollow diamond center. */}
2955
<div
30-
className="absolute top-0 bottom-0"
56+
className="absolute bottom-0"
3157
style={{
3258
left: "50%",
59+
top: HEAD_TOTAL_H,
3360
width: 1,
3461
marginLeft: -0.5,
3562
background: color,
3663
boxShadow: `0 0 6px ${glowColor}`,
3764
}}
3865
/>
39-
<div className="absolute" style={{ left: "50%", top: 1, transform: "translateX(-50%)" }}>
66+
{/* Head chip — sticky so it pins to the ruler while tracks scroll.
67+
Centering logic: wrapper width = HEAD_W (chip forces it). The line sits
68+
at wrapper.left + HEAD_W/2 (left:"50%" of wrapper). The sticky element's
69+
natural flow position is wrapper.left; so placing it there with no
70+
horizontal translate puts its LEFT edge at wrapper.left and its CENTER
71+
at wrapper.left + HEAD_W/2 — exactly on the line. */}
72+
<div
73+
className={stickyHead ? "sticky" : "absolute"}
74+
style={{
75+
left: 0,
76+
top: stickyHead ? 0 : 1,
77+
// Zero height keeps it from covering rows (sticky strip trick).
78+
height: stickyHead ? 0 : undefined,
79+
}}
80+
>
4081
<div
4182
style={{
42-
width: 9,
43-
height: 9,
83+
width: HEAD_W,
84+
height: HEAD_H,
4485
borderRadius: 2,
45-
background: color,
86+
marginTop: 1,
87+
// Outline-only at rest, filled while scrubbing.
88+
background: scrubbing ? color : "transparent",
89+
border: `1.5px solid ${color}`,
90+
boxSizing: "border-box",
4691
boxShadow: `0 1px 3px rgba(0,0,0,0.55), 0 0 5px ${glowColor}`,
4792
transform: "rotate(45deg)",
4893
}}

‎packages/studio/src/player/components/Timeline.test.ts‎

Lines changed: 102 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,14 @@ import {
1818
shouldHandleTimelineDeleteKey,
1919
shouldAutoScrollTimeline,
2020
} from "./Timeline";
21-
import { RULER_H, TRACK_H } from "./timelineLayout";
21+
import {
22+
GUTTER,
23+
MIN_TIMELINE_EXTENT_S,
24+
RULER_H,
25+
TRACK_H,
26+
getTimelineDisplayContentWidth,
27+
getTimelineFitPps,
28+
} from "./timelineLayout";
2229
import { formatTime } from "../lib/time";
2330
import { usePlayerStore } from "../store/playerStore";
2431
import { TimelineEditProvider } from "../../contexts/TimelineEditContext";
@@ -323,55 +330,55 @@ describe("generateTicks", () => {
323330
});
324331

325332
describe("formatTime", () => {
326-
it("formats 0 seconds as 0:00", () => {
327-
expect(formatTime(0)).toBe("0:00");
333+
it("formats 0 seconds as 00:00", () => {
334+
expect(formatTime(0)).toBe("00:00");
328335
});
329336

330337
// fallow-ignore-next-line code-duplication
331338
it("formats seconds below a minute", () => {
332-
expect(formatTime(5)).toBe("0:05");
333-
expect(formatTime(30)).toBe("0:30");
334-
expect(formatTime(59)).toBe("0:59");
339+
expect(formatTime(5)).toBe("00:05");
340+
expect(formatTime(30)).toBe("00:30");
341+
expect(formatTime(59)).toBe("00:59");
335342
});
336343

337344
it("formats exactly one minute", () => {
338-
expect(formatTime(60)).toBe("1:00");
345+
expect(formatTime(60)).toBe("01:00");
339346
});
340347

341348
it("formats minutes and seconds", () => {
342-
expect(formatTime(90)).toBe("1:30");
343-
expect(formatTime(125)).toBe("2:05");
349+
expect(formatTime(90)).toBe("01:30");
350+
expect(formatTime(125)).toBe("02:05");
344351
});
345352

346353
it("floors fractional seconds", () => {
347-
expect(formatTime(5.7)).toBe("0:05");
348-
expect(formatTime(59.9)).toBe("0:59");
349-
expect(formatTime(90.5)).toBe("1:30");
354+
expect(formatTime(5.7)).toBe("00:05");
355+
expect(formatTime(59.9)).toBe("00:59");
356+
expect(formatTime(90.5)).toBe("01:30");
350357
});
351358

352359
it("handles large values", () => {
353360
expect(formatTime(600)).toBe("10:00");
354361
expect(formatTime(3661)).toBe("61:01");
355362
});
356363

357-
it("zero-pads seconds to two digits", () => {
358-
expect(formatTime(1)).toBe("0:01");
359-
expect(formatTime(9)).toBe("0:09");
360-
expect(formatTime(61)).toBe("1:01");
364+
it("zero-pads minutes and seconds to two digits", () => {
365+
expect(formatTime(1)).toBe("00:01");
366+
expect(formatTime(9)).toBe("00:09");
367+
expect(formatTime(61)).toBe("01:01");
361368
});
362369
});
363370

364371
describe("formatTimelineTickLabel", () => {
365372
it("uses minute-second labels for normal timeline intervals", () => {
366-
expect(formatTimelineTickLabel(90, 180, 5)).toBe("1:30");
373+
expect(formatTimelineTickLabel(90, 180, 5)).toBe("01:30");
367374
});
368375

369376
it("uses hour labels for long timelines", () => {
370377
expect(formatTimelineTickLabel(3661, 4000, 60)).toBe("1:01:01");
371378
});
372379

373380
it("shows subsecond labels when the major ruler interval is below one second", () => {
374-
expect(formatTimelineTickLabel(1.5, 3, 0.5)).toBe("0:01.5");
381+
expect(formatTimelineTickLabel(1.5, 3, 0.5)).toBe("00:01.5");
375382
});
376383
});
377384

@@ -390,6 +397,80 @@ describe("shouldAutoScrollTimeline", () => {
390397
});
391398
});
392399

400+
describe("getTimelineFitPps (min 60s extent)", () => {
401+
const viewport = 632; // usable width = 632 - GUTTER - 2 = 598
402+
403+
it("computes fit pps against the 60s floor for short compositions", () => {
404+
// A 10s comp maps 60s onto the viewport → the comp takes ~1/6 of the width.
405+
const pps = getTimelineFitPps(viewport, 10);
406+
expect(pps).toBeCloseTo((viewport - GUTTER - 2) / MIN_TIMELINE_EXTENT_S);
407+
expect(10 * pps).toBeCloseTo((viewport - GUTTER - 2) / 6);
408+
});
409+
410+
it("keeps filling the viewport with the composition when it is 60s or longer", () => {
411+
expect(getTimelineFitPps(viewport, 60)).toBeCloseTo((viewport - GUTTER - 2) / 60);
412+
expect(getTimelineFitPps(viewport, 120)).toBeCloseTo((viewport - GUTTER - 2) / 120);
413+
});
414+
415+
it("falls back to 100 pps before the viewport is measured", () => {
416+
expect(getTimelineFitPps(0, 10)).toBe(100);
417+
expect(getTimelineFitPps(GUTTER, 10)).toBe(100);
418+
expect(getTimelineFitPps(Number.NaN, 10)).toBe(100);
419+
});
420+
421+
it("uses the floor for zero/invalid durations", () => {
422+
expect(getTimelineFitPps(viewport, 0)).toBeCloseTo(
423+
(viewport - GUTTER - 2) / MIN_TIMELINE_EXTENT_S,
424+
);
425+
expect(getTimelineFitPps(viewport, Number.NaN)).toBeCloseTo(
426+
(viewport - GUTTER - 2) / MIN_TIMELINE_EXTENT_S,
427+
);
428+
});
429+
});
430+
431+
describe("getTimelineDisplayContentWidth", () => {
432+
it("always spans at least MIN_TIMELINE_EXTENT_S seconds of content", () => {
433+
// 10s of content at 20 pps = 200px; the floor keeps 60s (1200px) rendered.
434+
expect(
435+
getTimelineDisplayContentWidth({ trackContentWidth: 200, viewportWidth: 400, pps: 20 }),
436+
).toBe(MIN_TIMELINE_EXTENT_S * 20);
437+
});
438+
439+
it("still fills the viewport when that is larger than the 60s floor", () => {
440+
expect(
441+
getTimelineDisplayContentWidth({ trackContentWidth: 200, viewportWidth: 2000, pps: 5 }),
442+
).toBe(2000 - GUTTER - 2);
443+
});
444+
445+
it("tracks a drag ghost past every other bound (drag-to-extend)", () => {
446+
expect(
447+
getTimelineDisplayContentWidth({
448+
trackContentWidth: 500,
449+
viewportWidth: 400,
450+
pps: 5,
451+
dragGhostEndPx: 5000,
452+
}),
453+
).toBe(5000);
454+
});
455+
456+
it("tracks a resize (trim) ghost past every other bound (trim-to-extend)", () => {
457+
expect(
458+
getTimelineDisplayContentWidth({
459+
trackContentWidth: 500,
460+
viewportWidth: 400,
461+
pps: 5,
462+
resizeGhostEndPx: 4200,
463+
}),
464+
).toBe(4200);
465+
});
466+
467+
it("keeps long content authoritative", () => {
468+
expect(
469+
getTimelineDisplayContentWidth({ trackContentWidth: 9000, viewportWidth: 400, pps: 50 }),
470+
).toBe(9000);
471+
});
472+
});
473+
393474
describe("getTimelineScrollLeftForZoomTransition", () => {
394475
it("resets horizontal scroll when switching from manual zoom back to fit", () => {
395476
expect(getTimelineScrollLeftForZoomTransition("manual", "fit", 480)).toBe(0);
@@ -524,7 +605,9 @@ describe("resolveTimelineAssetDrop", () => {
524605
trackOrder: [0, 3, 7],
525606
},
526607
432,
527-
310,
608+
// clientY updated for TRACKS_TOP_PAD=72: rectTop(200) + RULER_H(24) +
609+
// TRACKS_TOP_PAD(72) + TRACK_H(48) + TRACK_H/2(24) = 368 → row 1 → track 3.
610+
368,
528611
),
529612
).toEqual({ start: 3, track: 3 });
530613
});

0 commit comments

Comments
 (0)