Write HTML. Render video. Built for agents.
JavaScript aiai-agentsanimationclaude-codeffmpegframeworkgsaphtmlhtml-to-videomcpmotion-graphicspuppeteerrenderingtypescriptvideo-editor
feat(studio): a host can hide the timeline's keyframe lanes and diamonds (#4715)
Miguel Ángel00a907d6b3ed
diff --git a/packages/studio/src/player/components/Timeline.showKeyframes.test.tsx b/packages/studio/src/player/components/Timeline.showKeyframes.test.tsxnew file mode 100644index 0000000000..5cea10d514--- /dev/null+++ b/packages/studio/src/player/components/Timeline.showKeyframes.test.tsx@@ -0,0 +1,91 @@+// @vitest-environment happy-dom++import React, { act } from "react";+import { createRoot } from "react-dom/client";+import { afterEach, describe, expect, it } from "vitest";+import { Timeline } from "./Timeline";+import { installTimelineMountEnv } from "./timelineMountTestEnv";+import { usePlayerStore } from "../store/playerStore";++(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;++installTimelineMountEnv();++afterEach(() => {+ document.body.innerHTML = "";+});++async function mountKeyframed(showKeyframes?: boolean, withLanes = true) {+ usePlayerStore.setState({+ duration: 10,+ currentTime: 0,+ timelineReady: true,+ selectedElementId: "card",+ elements: [{ id: "card", label: "Hero card", tag: "div", start: 0, duration: 4, track: 0 }],+ gsapAnimations: withLanes+ ? new Map([+ [+ "card",+ [+ {+ id: "card-position",+ targetSelector: "#card",+ method: "to",+ position: 0,+ duration: 2,+ properties: {},+ propertyGroup: "position",+ keyframes: {+ format: "percentage",+ keyframes: [+ { percentage: 0, properties: { x: 0 } },+ { percentage: 50, properties: { x: 100 } },+ ],+ },+ },+ ],+ ],+ ])+ : new Map(),+ keyframeCache: new Map([+ [+ "card",+ {+ format: "percentage",+ keyframes: [{ percentage: 50, properties: { x: 100 }, tweenPercentage: 50 }],+ },+ ],+ ]),+ });+ const host = document.createElement("div");+ document.body.append(host);+ const root = createRoot(host);+ await act(async () => root.render(<Timeline showKeyframes={showKeyframes} />));+ const diamonds = host.querySelectorAll('button[title="50%"]').length;+ const named = Array.from(host.querySelectorAll("[role=rowheader]")).some((h) =>+ h.textContent?.includes("Hero card"),+ );+ const lanes = host.textContent?.includes("Position") ?? false;+ act(() => root.unmount());+ return { diamonds, named, lanes };+}++describe("Timeline showKeyframes", () => {+ it("draws a keyframed clip's diamonds by default", async () => {+ expect((await mountKeyframed(undefined, false)).diamonds).toBeGreaterThan(0);+ });++ it("draws no keyframe diamonds when the host turns keyframes off", async () => {+ expect((await mountKeyframed(false, false)).diamonds).toBe(0);+ });++ it("draws the keyframe lanes by default and none when keyframes are off", async () => {+ expect((await mountKeyframed()).lanes).toBe(true);+ expect((await mountKeyframed(false)).lanes).toBe(false);+ });++ it("keeps each track's name in the header when keyframes are off", async () => {+ expect((await mountKeyframed()).named).toBe(true);+ expect((await mountKeyframed(false)).named).toBe(true);+ });+});diff --git a/packages/studio/src/player/components/TimelineTypes.ts b/packages/studio/src/player/components/TimelineTypes.tsindex 8648a4ec3f..f5aa1e03d0 100644--- a/packages/studio/src/player/components/TimelineTypes.ts+++ b/packages/studio/src/player/components/TimelineTypes.ts@@ -34,4 +34,5 @@ export interface TimelinePropscanPasteClip?: () => boolean;theme?: Partial<TimelineTheme>;showAudioEffects?: boolean;+ showKeyframes?: boolean;}diff --git a/packages/studio/src/player/components/useTimelineKeyframeData.ts b/packages/studio/src/player/components/useTimelineKeyframeData.tsnew file mode 100644index 0000000000..077b47f24b--- /dev/null+++ b/packages/studio/src/player/components/useTimelineKeyframeData.ts@@ -0,0 +1,14 @@+import { usePlayerStore, type KeyframeCacheEntry } from "../store/playerStore";+import type { GsapAnimation } from "@hyperframes/core/gsap-parser";++const HIDDEN = {+ gsapAnimations: new Map<string, GsapAnimation[]>(),+ keyframeCache: new Map<string, KeyframeCacheEntry>(),+};++/** The keyframe data the timeline draws, or none when the host hides keyframes. */+export function useTimelineKeyframeData(showKeyframes: boolean) {+ const gsapAnimations = usePlayerStore((s) => s.gsapAnimations);+ const keyframeCache = usePlayerStore((s) => s.keyframeCache);+ return showKeyframes ? { gsapAnimations, keyframeCache } : HIDDEN;+}diff --git a/packages/studio/src/player/components/useTimelineProviderState.tsx b/packages/studio/src/player/components/useTimelineProviderState.tsxindex b86cc78835..d2a473796c 100644--- a/packages/studio/src/player/components/useTimelineProviderState.tsx+++ b/packages/studio/src/player/components/useTimelineProviderState.tsx@@ -21,6 +21,7 @@ import { useTimelineGeometry } from "./useTimelineGeometry";import { useAutoExpandKeyframedClips } from "./useAutoExpandKeyframedClips";import { GUTTER, LABEL_COL_W } from "./timelineLayout";import { useTimelineLabelColumn } from "./useTimelineLabelColumn";+import { useTimelineKeyframeData } from "./useTimelineKeyframeData";import { useTimelineScrollViewport } from "./useTimelineScrollViewport";import { ClipContentOnceShown } from "./timelineClipChildren";import { useResolvedTimelineEditCallbacks } from "./useResolvedTimelineEditCallbacks";@@ -68,6 +69,7 @@ export function useTimelineProviderState({canPasteClip,theme: themeOverrides,showAudioEffects = true,+ showKeyframes = true,sessionEpoch = 0,previewIframeRef,onZIndexReorder,@@ -104,8 +106,9 @@ export function useTimelineProviderState({const selectedElementId = usePlayerStore((s) => s.selectedElementId);const selectedElementIds = usePlayerStore((s) => s.selectedElementIds);const focusedEaseSegment = usePlayerStore((s) => s.focusedEaseSegment);- const gsapAnimations = usePlayerStore((s) => s.gsapAnimations);- const { labelMode, contentOrigin } = useTimelineLabelColumn(gsapAnimations, timelineElements);+ const { gsapAnimations, keyframeCache } = useTimelineKeyframeData(showKeyframes);+ const namedAnimations = usePlayerStore((s) => s.gsapAnimations);+ const { labelMode, contentOrigin } = useTimelineLabelColumn(namedAnimations, timelineElements);const setSelectedElementId = usePlayerStore((s) => s.setSelectedElementId);const currentTime = usePlayerStore((s) => s.currentTime);const beatDragging = usePlayerStore((s) => s.beatDragging);@@ -130,7 +133,6 @@ export function useTimelineProviderState({() => getEffectiveTimelineDuration(duration, timelineElements),[duration, timelineElements],);- const keyframeCache = usePlayerStore((s) => s.keyframeCache);useAutoExpandKeyframedClips(gsapAnimations);const {tracks,