Skip to content

Commit 8f5f4d2

Browse files
committed
feat(studio): bulk-edit easing for merged keyframes
1 parent c02a44c commit 8f5f4d2

18 files changed

Lines changed: 622 additions & 52 deletions

‎packages/studio/src/components/StudioRightPanel.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import type { EditHistoryKind } from "../utils/editHistory";
1919
import { useSlideshowPersist, type UseSlideshowPersistParams } from "../hooks/useSlideshowPersist";
2020
import { useSlideshowTabState } from "../hooks/useSlideshowTabState";
2121
import { DesignPanelPromoteProvider } from "./DesignPanelPromoteProvider";
22-
2322
import { useStudioPlaybackContext, useStudioShellContext } from "../contexts/StudioContext";
2423
import { usePanelLayoutContext } from "../contexts/PanelLayoutContext";
2524
import { useFileManagerContext } from "../contexts/FileManagerContext";
@@ -156,6 +155,7 @@ export function StudioRightPanel({
156155
handleUpdateArcSegment,
157156
handleUnroll,
158157
handleUpdateKeyframeEase,
158+
handleUpdateSegmentEase,
159159
handleSetAllKeyframeEases,
160160
handleGsapAddKeyframe,
161161
handleGsapRemoveKeyframe,
@@ -406,6 +406,7 @@ export function StudioRightPanel({
406406
onUnroll={handleUnroll}
407407
onUpdateKeyframeEase={handleUpdateKeyframeEase}
408408
onSetAllKeyframeEases={handleSetAllKeyframeEases}
409+
onUpdateSegmentEase={handleUpdateSegmentEase}
409410
recordingState={recordingState}
410411
recordingDuration={recordingDuration}
411412
onToggleRecording={onToggleRecording}

‎packages/studio/src/components/editor/AnimationCard.test.tsx‎

Lines changed: 188 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,88 @@
22

33
import React, { act } from "react";
44
import { createRoot } from "react-dom/client";
5+
import type { GsapAnimation } from "@hyperframes/core/gsap-parser";
56
import { afterEach, describe, expect, it, vi } from "vitest";
67
import { AnimationCard } from "./AnimationCard";
7-
import type { GsapAnimation } from "@hyperframes/core/gsap-parser";
88
import { EASE_PRESETS } from "./easePresetLibrary";
9+
import type { AnimationKeyframeTarget } from "../../hooks/gsapTweenSynth";
910

1011
const trackStudioSegmentEaseEdit = vi.hoisted(() => vi.fn());
1112
vi.mock("../../telemetry/events", () => ({ trackStudioSegmentEaseEdit }));
1213

1314
(globalThis as unknown as { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
1415

16+
const ANIMATION: GsapAnimation = {
17+
id: "position-tween",
18+
targetSelector: "#clip-1",
19+
method: "to",
20+
position: 0,
21+
duration: 2,
22+
ease: "power1.out",
23+
properties: { x: 200 },
24+
keyframes: {
25+
format: "percentage",
26+
keyframes: [
27+
{ percentage: 0, properties: { x: 0 } },
28+
{ percentage: 50, properties: { x: 100 } },
29+
{ percentage: 100, properties: { x: 200 } },
30+
],
31+
},
32+
};
33+
34+
const FLAT_ANIMATION: GsapAnimation = {
35+
...ANIMATION,
36+
id: "flat-position-tween",
37+
keyframes: undefined,
38+
};
39+
1540
afterEach(() => {
1641
document.body.innerHTML = "";
1742
trackStudioSegmentEaseEdit.mockClear();
1843
});
1944

20-
function baseAnimation(overrides: Partial<GsapAnimation> = {}): GsapAnimation {
21-
return {
22-
id: "anim-1",
23-
method: "to",
24-
position: 0.8,
25-
duration: 1.2,
26-
ease: "power2.out",
27-
properties: { opacity: 1 },
28-
...overrides,
29-
} as GsapAnimation;
45+
function renderFocusCard(
46+
focusedSegment: {
47+
tweenPercentage: number;
48+
collidingAnimationTargets?: AnimationKeyframeTarget[];
49+
} | null,
50+
onEaseCommit = vi.fn(),
51+
defaultExpanded = false,
52+
animation = ANIMATION,
53+
onUpdateMeta = vi.fn(),
54+
onUpdateSegmentEase = vi.fn(),
55+
) {
56+
const host = document.createElement("div");
57+
document.body.append(host);
58+
const root = createRoot(host);
59+
const render = (nextFocusedSegment: { tweenPercentage: number } | null) => {
60+
act(() => {
61+
root.render(
62+
<AnimationCard
63+
animation={animation}
64+
defaultExpanded={defaultExpanded}
65+
focusedSegment={nextFocusedSegment}
66+
onFocusSegmentConsumed={vi.fn()}
67+
onUpdateProperty={vi.fn()}
68+
onUpdateMeta={onUpdateMeta}
69+
onDeleteAnimation={vi.fn()}
70+
onAddProperty={vi.fn()}
71+
onRemoveProperty={vi.fn()}
72+
onUpdateKeyframeEase={onEaseCommit}
73+
onUpdateSegmentEase={onUpdateSegmentEase}
74+
/>,
75+
);
76+
});
77+
};
78+
render(focusedSegment);
79+
return { host, root, render };
3080
}
3181

32-
const noop = () => {};
82+
function findButton(host: HTMLElement, text: string): HTMLButtonElement | undefined {
83+
return Array.from(host.querySelectorAll("button")).find((button) =>
84+
button.textContent?.includes(text),
85+
);
86+
}
3387

3488
function selectPreset(host: HTMLElement, presetId: string): string {
3589
const presetConfig = EASE_PRESETS.find((candidate) => candidate.id === presetId);
@@ -45,6 +99,8 @@ function selectPreset(host: HTMLElement, presetId: string): string {
4599
return presetConfig.ease;
46100
}
47101

102+
const noop = () => {};
103+
48104
/** Every test mounts the same card; only expansion, flat mode, and the spies differ. */
49105
function renderCard({
50106
animation = baseAnimation(),
@@ -82,6 +138,126 @@ function renderCard({
82138
return { host, root };
83139
}
84140

141+
function restoreScrollIntoView(descriptor: PropertyDescriptor | undefined): void {
142+
if (descriptor) Object.defineProperty(HTMLElement.prototype, "scrollIntoView", descriptor);
143+
else Reflect.deleteProperty(HTMLElement.prototype, "scrollIntoView");
144+
}
145+
146+
describe("AnimationCard", () => {
147+
it("scrolls a focused segment into view but not a manually toggled segment", () => {
148+
const originalScrollIntoView = Object.getOwnPropertyDescriptor(
149+
HTMLElement.prototype,
150+
"scrollIntoView",
151+
);
152+
const scrollIntoView = vi.fn();
153+
Object.defineProperty(HTMLElement.prototype, "scrollIntoView", {
154+
configurable: true,
155+
value: scrollIntoView,
156+
});
157+
158+
const view = renderFocusCard({ tweenPercentage: 50 });
159+
try {
160+
expect(scrollIntoView).toHaveBeenCalledOnce();
161+
expect(scrollIntoView).toHaveBeenCalledWith({ block: "nearest", behavior: "smooth" });
162+
163+
view.render(null);
164+
const manualToggle = findButton(view.host, "50% → 100%");
165+
expect(manualToggle).toBeDefined();
166+
act(() => manualToggle?.click());
167+
expect(scrollIntoView).toHaveBeenCalledOnce();
168+
} finally {
169+
act(() => view.root.unmount());
170+
restoreScrollIntoView(originalScrollIntoView);
171+
}
172+
});
173+
174+
it("tracks a committed segment ease alongside the existing update", () => {
175+
const onEaseCommit = vi.fn();
176+
const view = renderFocusCard(null, onEaseCommit, true);
177+
const segment = findButton(view.host, "0% → 50%");
178+
expect(segment).toBeDefined();
179+
act(() => segment?.click());
180+
const ease = selectPreset(view.host, "quad-out");
181+
182+
expect(onEaseCommit).toHaveBeenCalledWith(ANIMATION.id, 50, ease);
183+
expect(trackStudioSegmentEaseEdit).toHaveBeenCalledWith({ action: "commit", ease });
184+
act(() => view.root.unmount());
185+
});
186+
187+
it("commits a focused multi-id segment ease through the bulk callback", () => {
188+
const onUpdateKeyframeEase = vi.fn();
189+
const onUpdateSegmentEase = vi.fn();
190+
const collidingAnimationTargets = [
191+
{ animationId: ANIMATION.id, tweenPercentage: 50 },
192+
{ animationId: "scale-tween", tweenPercentage: 75 },
193+
{ animationId: "opacity-tween", tweenPercentage: 25 },
194+
];
195+
const view = renderFocusCard(
196+
{ tweenPercentage: 50, collidingAnimationTargets },
197+
onUpdateKeyframeEase,
198+
false,
199+
ANIMATION,
200+
vi.fn(),
201+
onUpdateSegmentEase,
202+
);
203+
const ease = selectPreset(view.host, "quad-out");
204+
205+
expect(onUpdateSegmentEase).toHaveBeenCalledExactlyOnceWith(collidingAnimationTargets, ease);
206+
expect(onUpdateKeyframeEase).not.toHaveBeenCalled();
207+
act(() => view.root.unmount());
208+
});
209+
210+
it("keeps a focused single-id segment ease on the single callback", () => {
211+
const onUpdateKeyframeEase = vi.fn();
212+
const onUpdateSegmentEase = vi.fn();
213+
const view = renderFocusCard(
214+
{
215+
tweenPercentage: 50,
216+
collidingAnimationTargets: [{ animationId: ANIMATION.id, tweenPercentage: 50 }],
217+
},
218+
onUpdateKeyframeEase,
219+
false,
220+
ANIMATION,
221+
vi.fn(),
222+
onUpdateSegmentEase,
223+
);
224+
225+
const ease = selectPreset(view.host, "quad-out");
226+
227+
expect(onUpdateKeyframeEase).toHaveBeenCalledExactlyOnceWith(ANIMATION.id, 50, ease);
228+
expect(onUpdateSegmentEase).not.toHaveBeenCalled();
229+
act(() => view.root.unmount());
230+
});
231+
232+
it("commits a focused flat tween segment ease through tween metadata", () => {
233+
const onUpdateMeta = vi.fn();
234+
const onUpdateKeyframeEase = vi.fn();
235+
const view = renderFocusCard(
236+
{ tweenPercentage: 100 },
237+
onUpdateKeyframeEase,
238+
false,
239+
FLAT_ANIMATION,
240+
onUpdateMeta,
241+
);
242+
const ease = selectPreset(view.host, "quad-out");
243+
244+
expect(onUpdateMeta).toHaveBeenCalledExactlyOnceWith(FLAT_ANIMATION.id, { ease });
245+
expect(onUpdateKeyframeEase).not.toHaveBeenCalled();
246+
act(() => view.root.unmount());
247+
});
248+
});
249+
250+
function baseAnimation(overrides: Partial<GsapAnimation> = {}): GsapAnimation {
251+
return {
252+
id: "anim-1",
253+
method: "to",
254+
position: 0.8,
255+
duration: 1.2,
256+
ease: "power2.out",
257+
properties: { opacity: 1 },
258+
...overrides,
259+
} as GsapAnimation;
260+
}
85261
describe("AnimationCard ease editing", () => {
86262
it("commits one preset change to the selected keyframe segment", () => {
87263
const onUpdateKeyframeEase = vi.fn();

‎packages/studio/src/components/editor/AnimationCard.tsx‎

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,16 @@ import {
1818
parseNumericOrString,
1919
BOOLEAN_PROPS,
2020
} from "./AnimationCardParts";
21+
import type { AnimationKeyframeTarget } from "../../hooks/gsapTweenSynth";
2122

2223
interface AnimationCardProps extends GsapAnimationEditCallbacks {
2324
animation: GsapAnimation;
2425
defaultExpanded: boolean;
2526
flat?: boolean;
26-
focusedSegment?: { tweenPercentage: number } | null;
27+
focusedSegment?: {
28+
tweenPercentage: number;
29+
collidingAnimationTargets?: AnimationKeyframeTarget[];
30+
} | null;
2731
onFocusSegmentConsumed?: () => void;
2832
}
2933

@@ -47,13 +51,17 @@ export const AnimationCard = memo(function AnimationCard({
4751
onSetArcPath,
4852
onUpdateArcSegment,
4953
onUpdateKeyframeEase,
54+
onUpdateSegmentEase,
5055
onSetAllKeyframeEases,
5156
onUnroll,
5257
}: AnimationCardProps) {
5358
const [expanded, setExpanded] = useState(defaultExpanded);
5459
const [addingProp, setAddingProp] = useState(false);
5560
const [addingFromProp, setAddingFromProp] = useState(false);
5661
const [expandedKfPct, setExpandedKfPct] = useState<number | null>(null);
62+
const [focusedCollidingAnimationTargets, setFocusedCollidingAnimationTargets] = useState<
63+
AnimationKeyframeTarget[] | undefined
64+
>();
5765
const cardRef = useRef<HTMLDivElement>(null);
5866
const pendingAutoScrollRef = useRef(false);
5967

@@ -62,6 +70,7 @@ export const AnimationCard = memo(function AnimationCard({
6270
setExpanded(true);
6371
pendingAutoScrollRef.current = true;
6472
setExpandedKfPct(focusedSegment.tweenPercentage);
73+
setFocusedCollidingAnimationTargets(focusedSegment.collidingAnimationTargets);
6574
onFocusSegmentConsumed?.();
6675
}, [focusedSegment, onFocusSegmentConsumed]);
6776

@@ -288,9 +297,21 @@ export const AnimationCard = memo(function AnimationCard({
288297
keyframes={animation.keyframes.keyframes}
289298
globalEase={animation.keyframes.easeEach ?? animation.ease ?? "none"}
290299
expandedPct={expandedKfPct}
291-
onToggle={setExpandedKfPct}
300+
collidingAnimationTargets={focusedCollidingAnimationTargets}
301+
onToggle={(pct) => {
302+
setExpandedKfPct(pct);
303+
setFocusedCollidingAnimationTargets(undefined);
304+
}}
292305
onEaseCommit={(pct, ease) => {
293-
onUpdateKeyframeEase(animation.id, pct, ease);
306+
if (
307+
focusedCollidingAnimationTargets &&
308+
focusedCollidingAnimationTargets.length > 1 &&
309+
onUpdateSegmentEase
310+
) {
311+
onUpdateSegmentEase(focusedCollidingAnimationTargets, ease);
312+
} else {
313+
onUpdateKeyframeEase(animation.id, pct, ease);
314+
}
294315
trackStudioSegmentEaseEdit({ action: "commit", ease });
295316
}}
296317
onApplyAll={

‎packages/studio/src/components/editor/EaseCurveSection.test.tsx‎

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,30 @@ import React, { act, useState } from "react";
44
import { createRoot } from "react-dom/client";
55
import { afterEach, describe, expect, it, vi } from "vitest";
66
import { EaseCurveSection, MiniCurveSvg } from "./EaseCurveSection";
7+
import type { AnimationKeyframeTarget } from "../../hooks/gsapTweenSynth";
78

89
(globalThis as unknown as { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
910

1011
afterEach(() => {
1112
document.body.innerHTML = "";
1213
});
1314

14-
function renderSection(ease = "none", onCustomEaseCommit = vi.fn()) {
15+
function renderSection(
16+
ease = "none",
17+
onCustomEaseCommit = vi.fn(),
18+
collidingAnimationTargets?: AnimationKeyframeTarget[],
19+
) {
1520
const host = document.createElement("div");
1621
document.body.append(host);
1722
const root = createRoot(host);
1823
act(() => {
19-
root.render(<EaseCurveSection ease={ease} onCustomEaseCommit={onCustomEaseCommit} />);
24+
root.render(
25+
<EaseCurveSection
26+
ease={ease}
27+
onCustomEaseCommit={onCustomEaseCommit}
28+
collidingAnimationTargets={collidingAnimationTargets}
29+
/>,
30+
);
2031
});
2132
return { host, root, onCustomEaseCommit };
2233
}
@@ -82,6 +93,29 @@ function editorLabel(host: HTMLElement): string | null {
8293
}
8394

8495
describe("EaseCurveSection preset grid", () => {
96+
it("shows the number of properties for a multi-id segment", () => {
97+
const { host, root } = renderSection("power2.out", vi.fn(), [
98+
{ animationId: "move-x", tweenPercentage: 20 },
99+
{ animationId: "move-y", tweenPercentage: 50 },
100+
{ animationId: "fade", tweenPercentage: 80 },
101+
]);
102+
103+
expect(host.textContent).toContain("Applies to 3 properties");
104+
105+
act(() => root.unmount());
106+
});
107+
108+
it.each([undefined, [{ animationId: "move-x", tweenPercentage: 20 }]])(
109+
"does not show a property count for a non-colliding segment",
110+
(collidingAnimationTargets) => {
111+
const { host, root } = renderSection("power2.out", vi.fn(), collidingAnimationTargets);
112+
113+
expect(host.textContent).not.toContain("Applies to");
114+
115+
act(() => root.unmount());
116+
},
117+
);
118+
85119
it.each([
86120
["curve", "none", "linear", ["flow-7", "spring-bouncy"]],
87121
["spring", "spring(0.42)", "spring-bouncy", ["linear", "flow-7"]],

0 commit comments

Comments
 (0)