Skip to content

Commit c253dec

Browse files
committed
feat(studio): add keyframe ease editor
1 parent d84e999 commit c253dec

13 files changed

Lines changed: 1599 additions & 252 deletions

‎packages/parsers/src/gsapWriter.reviewFixes.test.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,17 @@ tl.to(".a", { keyframes: { "0%": { x: 0 }, "100%": { x: 100 } }, duration: 1, ea
299299
// The original top-level `ease: "none"` is untouched (no second top-level ease).
300300
expect((out.match(/ease: "power2.inOut"/g) ?? []).length).toBe(0);
301301
});
302+
303+
it("round-trips an editor-authored CustomEase through write and reparse", () => {
304+
const customEase = "custom(M0,0 C0.18,0.9 0.32,1.2 1,1)";
305+
const id = parseGsapScriptAcornForWrite(KF)?.located[0]?.id ?? "";
306+
const out = updateKeyframeInScript(KF, id, 100, { x: 100 }, customEase);
307+
const keyframe = parseGsapScriptAcornForWrite(
308+
out,
309+
)?.located[0]?.animation.keyframes?.keyframes.find(({ percentage }) => percentage === 100);
310+
311+
expect(keyframe?.ease).toBe(customEase);
312+
});
302313
});
303314

304315
// ── #8 — convertToKeyframes preserves builtin vars like `delay` ──

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

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,16 @@ import { createRoot } from "react-dom/client";
55
import { afterEach, describe, expect, it, vi } from "vitest";
66
import { AnimationCard } from "./AnimationCard";
77
import type { GsapAnimation } from "@hyperframes/core/gsap-parser";
8+
import { EASE_PRESETS } from "./easePresetLibrary";
9+
10+
const trackStudioSegmentEaseEdit = vi.hoisted(() => vi.fn());
11+
vi.mock("../../telemetry/events", () => ({ trackStudioSegmentEaseEdit }));
812

913
(globalThis as unknown as { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
1014

1115
afterEach(() => {
1216
document.body.innerHTML = "";
17+
trackStudioSegmentEaseEdit.mockClear();
1318
});
1419

1520
function baseAnimation(overrides: Partial<GsapAnimation> = {}): GsapAnimation {
@@ -26,6 +31,101 @@ function baseAnimation(overrides: Partial<GsapAnimation> = {}): GsapAnimation {
2631

2732
const noop = () => {};
2833

34+
function selectPreset(host: HTMLElement, presetId: string): string {
35+
const presetConfig = EASE_PRESETS.find((candidate) => candidate.id === presetId);
36+
if (!presetConfig) throw new Error(`Missing ease preset: ${presetId}`);
37+
38+
const dropdown = host.querySelector<HTMLButtonElement>("[data-ease-type-dropdown]");
39+
expect(dropdown).not.toBeNull();
40+
act(() => dropdown?.click());
41+
42+
const preset = host.querySelector<HTMLButtonElement>(`[data-ease-preset-id="${presetId}"]`);
43+
expect(preset).not.toBeNull();
44+
act(() => preset?.click());
45+
return presetConfig.ease;
46+
}
47+
48+
function renderExpandedCard({
49+
animation,
50+
flat,
51+
onUpdateMeta = vi.fn(),
52+
onUpdateKeyframeEase = vi.fn(),
53+
}: {
54+
animation: GsapAnimation;
55+
flat?: boolean;
56+
onUpdateMeta?: ReturnType<typeof vi.fn>;
57+
onUpdateKeyframeEase?: ReturnType<typeof vi.fn>;
58+
}) {
59+
const host = document.createElement("div");
60+
document.body.append(host);
61+
const root = createRoot(host);
62+
act(() => {
63+
root.render(
64+
<AnimationCard
65+
animation={animation}
66+
defaultExpanded
67+
flat={flat}
68+
onUpdateProperty={noop}
69+
onUpdateMeta={onUpdateMeta}
70+
onDeleteAnimation={noop}
71+
onAddProperty={noop}
72+
onRemoveProperty={noop}
73+
onUpdateKeyframeEase={onUpdateKeyframeEase}
74+
/>,
75+
);
76+
});
77+
return { host, root };
78+
}
79+
80+
describe("AnimationCard ease editing", () => {
81+
it("commits one preset change to the selected keyframe segment", () => {
82+
const onUpdateKeyframeEase = vi.fn();
83+
const animation = baseAnimation({
84+
keyframes: {
85+
format: "percentage",
86+
keyframes: [
87+
{ percentage: 0, properties: { opacity: 0 } },
88+
{ percentage: 50, properties: { opacity: 0.5 } },
89+
{ percentage: 100, properties: { opacity: 1 } },
90+
],
91+
},
92+
});
93+
const view = renderExpandedCard({ animation, onUpdateKeyframeEase });
94+
95+
const segment = Array.from(view.host.querySelectorAll("button")).find((button) =>
96+
button.textContent?.includes("0% → 50%"),
97+
);
98+
expect(segment).toBeDefined();
99+
act(() => segment?.click());
100+
const ease = selectPreset(view.host, "quad-out");
101+
102+
expect(onUpdateKeyframeEase).toHaveBeenCalledExactlyOnceWith(animation.id, 50, ease);
103+
expect(trackStudioSegmentEaseEdit).toHaveBeenCalledExactlyOnceWith({
104+
ease,
105+
});
106+
act(() => view.root.unmount());
107+
});
108+
109+
it("commits one preset change through flat tween metadata", () => {
110+
const onUpdateMeta = vi.fn();
111+
const onUpdateKeyframeEase = vi.fn();
112+
const animation = baseAnimation({ id: "flat-tween" });
113+
const view = renderExpandedCard({
114+
animation,
115+
flat: true,
116+
onUpdateMeta,
117+
onUpdateKeyframeEase,
118+
});
119+
120+
const ease = selectPreset(view.host, "quad-out");
121+
122+
expect(onUpdateMeta).toHaveBeenCalledExactlyOnceWith(animation.id, { ease });
123+
expect(onUpdateKeyframeEase).not.toHaveBeenCalled();
124+
expect(trackStudioSegmentEaseEdit).not.toHaveBeenCalled();
125+
act(() => view.root.unmount());
126+
});
127+
});
128+
29129
describe("AnimationCard flat branch", () => {
30130
it("renders a mint border-left and panel-token colors when flat", () => {
31131
const host = document.createElement("div");

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { memo, useCallback, useMemo, useState } from "react";
22
import type { GsapAnimation } from "@hyperframes/core/gsap-parser";
33
import { SUPPORTED_EASES, SUPPORTED_PROPS } from "@hyperframes/core/gsap-constants";
4+
import { trackStudioSegmentEaseEdit } from "../../telemetry/events";
45
import { RESPONSIVE_GRID } from "./propertyPanelHelpers";
56
import { MetricField, SelectField } from "./propertyPanelPrimitives";
67
import { controlPointsForGsapEase } from "./studioMotion";
@@ -264,7 +265,10 @@ export const AnimationCard = memo(function AnimationCard({
264265
globalEase={animation.keyframes.easeEach ?? animation.ease ?? "none"}
265266
expandedPct={expandedKfPct}
266267
onToggle={setExpandedKfPct}
267-
onEaseCommit={(pct, ease) => onUpdateKeyframeEase(animation.id, pct, ease)}
268+
onEaseCommit={(pct, ease) => {
269+
onUpdateKeyframeEase(animation.id, pct, ease);
270+
trackStudioSegmentEaseEdit({ ease });
271+
}}
268272
onApplyAll={
269273
onSetAllKeyframeEases
270274
? (ease) => onSetAllKeyframeEases(animation.id, ease)
@@ -292,7 +296,6 @@ export const AnimationCard = memo(function AnimationCard({
292296
/>
293297
<EaseCurveSection
294298
ease={easeName}
295-
duration={animation.duration}
296299
onCustomEaseCommit={(customEase) => {
297300
const easeKey = animation.keyframes ? "easeEach" : "ease";
298301
onUpdateMeta(animation.id, { [easeKey]: customEase });

0 commit comments

Comments
 (0)