Skip to content

Write HTML. Render video. Built for agents.

fix(studio): keyframed animations keep their ease through every Studio edit (#5051)

Miguel Ángel0d5e395cd31d
diff --git a/packages/parsers/src/gsapParser.test.ts b/packages/parsers/src/gsapParser.test.ts
index 97f1ecf8de..78bab7cef2 100644
--- a/packages/parsers/src/gsapParser.test.ts
+++ b/packages/parsers/src/gsapParser.test.ts
@@ -1607,9 +1607,8 @@ describe("native GSAP keyframes parsing", () => {
const script = `
const tl = gsap.timeline({ paused: true });
tl.to("#hero", {
- keyframes: { "0%": { x: 0 }, "50%": { x: 100, ease: "back.out(1.7)" }, "100%": { x: 200 } },
+ keyframes: { "0%": { x: 0 }, "50%": { x: 100, ease: "back.out(1.7)" }, "100%": { x: 200 }, easeEach: "power2.out" },
ease: "none",
- easeEach: "power2.out",
duration: 5
}, 0);
`;
@@ -1618,7 +1617,7 @@ describe("native GSAP keyframes parsing", () => {
// Tween-level ease
expect(anim.ease).toBe("none");
- // easeEach on keyframes data (set from tween-level)
+ // easeEach inside the keyframes object, the only place GSAP reads it
expect(anim.keyframes!.easeEach).toBe("power2.out");
// Per-keyframe ease
expect(anim.keyframes!.keyframes[1].ease).toBe("back.out(1.7)");
diff --git a/packages/parsers/src/gsapParser.ts b/packages/parsers/src/gsapParser.ts
index ccd84bfc94..40756d5208 100644
--- a/packages/parsers/src/gsapParser.ts
+++ b/packages/parsers/src/gsapParser.ts
@@ -23,6 +23,7 @@ import {
resolveConversionProps,
mergePercentageKeyframes,
authorsKeyframes,
+ plainPercentKey,
} from "./gsapSerialize";
export type {
@@ -1074,11 +1075,6 @@ function tweenCallToAnimation(
}
}
- // Apply tween-level easeEach to keyframes data.
- if (keyframesData && typeof vars.easeEach === "string") {
- keyframesData.easeEach = vars.easeEach as string;
- }
-
// When motionPath is present, reconstruct x/y as keyframe waypoints.
if (motionPathResult) {
const { waypoints } = motionPathResult;
@@ -2089,7 +2085,7 @@ function buildKeyframeObjectCode(
const props = keyframePropsToCode(kf);
if (kf.ease) props.push(`ease: ${JSON.stringify(kf.ease)}`);
if (kf.auto) props.push(`_auto: 1`);
- return `${JSON.stringify(`${kf.percentage}%`)}: { ${props.join(", ")} }`;
+ return `${JSON.stringify(plainPercentKey(kf.percentage))}: { ${props.join(", ")} }`;
});
if (options?.easeEach) entries.push(`easeEach: ${JSON.stringify(options.easeEach)}`);
return `{ ${entries.join(", ")} }`;
@@ -2251,7 +2247,7 @@ function convertArrayKeyframesToObjectNode(varsArg: AstNode, scope: ScopeBinding
el.properties = (el.properties ?? []).filter(
(property: AstNode) => !isObjectProperty(property) || propKeyName(property) !== "duration",
);
- return `${JSON.stringify(`${timing.percentages[i]}%`)}: ${recast.print(el).code}`;
+ return `${JSON.stringify(plainPercentKey(timing.percentages[i]!))}: ${recast.print(el).code}`;
});
prop.value = parseExpr(`{ ${entries.join(", ")}, easeEach: "none" }`);
return prop.value;
@@ -2290,7 +2286,7 @@ function locateKeyframeCtx(script: string, animationId: string, percentage: numb
if (!loc) return null;
const kfNode = findKeyframesObjectNode(loc.target.call.varsArg);
if (!kfNode) return null;
- return { loc, kfNode, pctKey: `${percentage}%` };
+ return { loc, kfNode, pctKey: plainPercentKey(percentage) };
}
/**
@@ -2323,7 +2319,7 @@ export function addKeyframeToScript(
kfNode = findKeyframesObjectNode(loc.target.call.varsArg);
if (!kfNode) return script;
}
- const pctKey = `${percentage}%`;
+ const pctKey = plainPercentKey(percentage);
const newValueNode = buildKeyframeValueNode(properties, ease);
@@ -2525,11 +2521,16 @@ export function moveKeyframeInScript(
entries.push({ pct: toPercentage, value: movedValue });
entries.sort((a, b) => a.pct - b.pct);
- kfNode.properties = entries.map((e) => {
- const p = parseExpr(`{ ${JSON.stringify(`${e.pct}%`)}: {} }`).properties[0];
- p.value = e.value;
- return p;
- });
+ const pctProps = new Set(filterPercentageProps(kfNode));
+ const kept = (kfNode.properties ?? []).filter((p: AstNode) => !pctProps.has(p));
+ kfNode.properties = [
+ ...entries.map((e) => {
+ const p = parseExpr(`{ ${JSON.stringify(plainPercentKey(e.pct))}: {} }`).properties[0];
+ p.value = e.value;
+ return p;
+ }),
+ ...kept,
+ ];
return recast.print(loc.parsed.ast).code;
}
@@ -2566,7 +2567,7 @@ export function resizeKeyframedTweenInScript(
seen.add(match.prop);
// Replace only the key node; the value node (incl. _auto + per-keyframe ease)
// stays verbatim. easeEach is a sibling non-percentage prop, left untouched.
- match.prop.key = parseExpr(`{ ${JSON.stringify(`${to}%`)}: 0 }`).properties[0].key;
+ match.prop.key = parseExpr(`{ ${JSON.stringify(plainPercentKey(to))}: 0 }`).properties[0].key;
}
applyUpdatesToCall(loc.target.call, {
@@ -3370,7 +3371,8 @@ export function splitIntoPropertyGroups(
typeof anim.position === "number" ? anim.position : 0,
anim.duration ?? 0.5,
groupKeyframes,
- anim.keyframes.easeEach ?? anim.ease,
+ anim.keyframes.ease ?? anim.ease,
+ anim.keyframes.easeEach,
);
result = addResult.script;
} else {
diff --git a/packages/parsers/src/gsapParserAcorn.full.test.ts b/packages/parsers/src/gsapParserAcorn.full.test.ts
index ccdca7a08f..3f313c7dfc 100644
--- a/packages/parsers/src/gsapParserAcorn.full.test.ts
+++ b/packages/parsers/src/gsapParserAcorn.full.test.ts
@@ -945,9 +945,8 @@ describe("native GSAP keyframes parsing", () => {
const script = `
const tl = gsap.timeline({ paused: true });
tl.to("#hero", {
- keyframes: { "0%": { x: 0 }, "50%": { x: 100, ease: "back.out(1.7)" }, "100%": { x: 200 } },
+ keyframes: { "0%": { x: 0 }, "50%": { x: 100, ease: "back.out(1.7)" }, "100%": { x: 200 }, easeEach: "power2.out" },
ease: "none",
- easeEach: "power2.out",
duration: 5
}, 0);
`;
diff --git a/packages/parsers/src/gsapParserAcorn.ts b/packages/parsers/src/gsapParserAcorn.ts
index 4f88013de6..bb0da7e174 100644
--- a/packages/parsers/src/gsapParserAcorn.ts
+++ b/packages/parsers/src/gsapParserAcorn.ts
@@ -1326,10 +1326,6 @@ function tweenCallToAnimation(
}
}
- if (keyframesData && typeof vars.easeEach === "string") {
- keyframesData.easeEach = vars.easeEach as string;
- }
-
if (motionPathResult) {
const { waypoints } = motionPathResult;
if (!keyframesData) {
diff --git a/packages/parsers/src/gsapSerialize.ts b/packages/parsers/src/gsapSerialize.ts
index d3be5b1b78..9fbb975bf3 100644
--- a/packages/parsers/src/gsapSerialize.ts
+++ b/packages/parsers/src/gsapSerialize.ts
@@ -322,6 +322,12 @@ export function serializeValue(value: unknown): string {
return String(value);
}
+export function plainPercentKey(percentage: number): string {
+ const text =
+ Math.abs(percentage) < 1e-6 ? percentage.toFixed(20).replace(/\.?0+$/, "") : String(percentage);
+ return `${text}%`;
+}
+
export function safeJsKey(key: string): string {
return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(key) ? key : JSON.stringify(key);
}
diff --git a/packages/parsers/src/gsapUnroll.ts b/packages/parsers/src/gsapUnroll.ts
index 8946e01eeb..0f48f2e772 100644
--- a/packages/parsers/src/gsapUnroll.ts
+++ b/packages/parsers/src/gsapUnroll.ts
@@ -18,7 +18,11 @@ import * as acorn from "acorn";
import * as acornWalk from "acorn-walk";
import MagicString from "magic-string";
import type { GsapAnimation } from "./gsapSerialize.js";
-import { serializeValue as valueToCode, safeJsKey as safeKey } from "./gsapSerialize.js";
+import {
+ serializeValue as valueToCode,
+ safeJsKey as safeKey,
+ plainPercentKey,
+} from "./gsapSerialize.js";
import { parseGsapScriptAcorn } from "./gsapParserAcorn.js";
import { isFunctionNode, isTimelineRooted } from "./gsapInline.js";
@@ -43,7 +47,7 @@ function keyframesEntry(anim: GsapAnimation): string {
const kfs = (anim.keyframes?.keyframes ?? []).map((k) => {
const body = propEntries(k.properties);
if (k.ease) body.push(`ease: ${valueToCode(k.ease)}`);
- return `"${k.percentage}%": { ${body.join(", ")} }`;
+ return `${JSON.stringify(plainPercentKey(k.percentage))}: { ${body.join(", ")} }`;
});
if (anim.keyframes?.easeEach) kfs.push(`easeEach: ${valueToCode(anim.keyframes.easeEach)}`);
return `keyframes: { ${kfs.join(", ")} }`;
diff --git a/packages/parsers/src/gsapWriter.parity.test.ts b/packages/parsers/src/gsapWriter.parity.test.ts
index bf7da23c19..49c96c362a 100644
--- a/packages/parsers/src/gsapWriter.parity.test.ts
+++ b/packages/parsers/src/gsapWriter.parity.test.ts
@@ -62,6 +62,7 @@ import {
retimeClipTweensInScript,
type ClipTweenRetime,
dedupePositionWritesInScript as dedupePosAcorn,
+ replaceTweenWithKeyframesInScript as replaceTweenWithKeyframesAcorn,
} from "./gsapWriterAcorn.js";
function acornId(script: string): string {
@@ -1454,6 +1455,94 @@ describe("parity: moveKeyframeInScript (recast vs acorn)", () => {
});
});
+describe("a keyframe percentage below 1e-6", () => {
+ const tiny = 1.2860082304526747e-7;
+ const readBack = (out: string) =>
+ parseGsapScriptAcorn(out).animations[0]!.keyframes?.keyframes.map((kf) => kf.percentage);
+
+ const steps = [
+ { percentage: 0, properties: { x: 0 } },
+ { percentage: tiny, properties: { x: 1 } },
+ { percentage: 100, properties: { x: 10 } },
+ ];
+
+ it.each([
+ ["recast", addWithKfRecast],
+ ["acorn", addWithKfAcorn],
+ ])("is written as a decimal key apart from 0% (%s)", (_name, add) => {
+ const base = `const tl = gsap.timeline({ paused: true });`;
+ const out = add(base, "#a", 0, 2, steps).script;
+ expect(out).not.toMatch(/\de-\d/);
+ expect(readBack(out)).toEqual([0, expect.closeTo(tiny, 12), 100]);
+ });
+
+ it("stays apart from 0% when replace-with-keyframes writes both", () => {
+ const script = `const tl = gsap.timeline({ paused: true });
+tl.to("#a", { duration: 2, x: 10, ease: "power4.in" }, 0);`;
+ const out = replaceTweenWithKeyframesAcorn(script, acornId(script), {
+ targetSelector: "#a",
+ position: 0,
+ duration: 2,
+ ease: "power4.in",
+ keyframes: steps,
+ })!;
+ expect(readBack(out)).toEqual([0, expect.closeTo(tiny, 12), 100]);
+ });
+});
+
+describe("a tween-level easeEach, which GSAP ignores", () => {
+ const script = `const tl = gsap.timeline({ paused: true });
+tl.to("#a", { duration: 1, keyframes: { "0%": { x: 0 }, "100%": { x: 10 } }, easeEach: "power4.in" }, 0);`;
+ it.each([
+ ["recast", parseGsapScript],
+ ["acorn", parseGsapScriptAcorn],
+ ])("is not reported as the keyframes' ease (%s)", (_name, parse) => {
+ expect(parse(script).animations[0]!.keyframes?.easeEach).toBeUndefined();
+ });
+});
+
+describe("a keyframe drag keeps the keyframes' eases", () => {
+ const writers = [
+ ["recast", updateAnimRecast, moveKeyframeRecast],
+ ["acorn", updateAnimAcorn, moveKeyframeAcorn],
+ ] as const;
+
+ for (const [writer, update, move] of writers) {
+ it(`${writer}: an ease set with Studio's ease control survives a diamond drag`, () => {
+ const script = `const tl = gsap.timeline({ paused: true });
+tl.to("#a", { duration: 2, keyframes: { "0%": { x: 0 }, "50%": { x: 5 }, "100%": { x: 10 } } }, 0);`;
+ const id = acornId(script);
+ const eased = update(script, id, { easeEach: "power2.out", resetKeyframeEases: true });
+ expect(parseGsapScriptAcorn(eased).animations[0]!.keyframes?.easeEach).toBe("power2.out");
+
+ const kf = parseGsapScriptAcorn(move(eased, id, 50, 60)).animations[0]!.keyframes!;
+ expect(kf.keyframes.map((k) => k.percentage)).toEqual([0, 60, 100]);
+ expect(kf.easeEach).toBe("power2.out");
+ });
+
+ it(`${writer}: splitting into property groups keeps the keyframes' eases`, () => {
+ const script = `const tl = gsap.timeline({ paused: true });
+tl.to("#a", { duration: 2, keyframes: { "0%": { x: 0, opacity: 0 }, "100%": { x: 10, opacity: 1 }, ease: "sine.inOut", easeEach: "power2.out" } }, 0);`;
+ const splitGroups = writer === "acorn" ? splitGroupsAcorn : splitGroupsRecast;
+ const groups = parseGsapScriptAcorn(splitGroups(script, acornId(script)).script).animations;
+ expect(groups).toHaveLength(2);
+ for (const group of groups) {
+ expect(group.keyframes?.easeEach).toBe("power2.out");
+ expect(group.keyframes?.ease ?? group.ease).toBe("sine.inOut");
+ }
+ });
+
+ it(`${writer}: an ease authored on the keyframes survives a diamond drag`, () => {
+ const script = `const tl = gsap.timeline({ paused: true });
+tl.to("#a", { duration: 2, keyframes: { "0%": { x: 0 }, "50%": { x: 5 }, "100%": { x: 10 }, ease: "sine.inOut" } }, 0);`;
+ const kf = parseGsapScriptAcorn(move(script, acornId(script), 50, 60)).animations[0]!
+ .keyframes!;
+ expect(kf.keyframes.map((k) => k.percentage)).toEqual([0, 60, 100]);
+ expect(kf.ease).toBe("sine.inOut");
+ });
+ }
+});
+
// Regression: array-form `keyframes: [...]` has no explicit percentages, so
// locateWithKeyframes/findKeyframesObjectNode (which only match the object
// form) resolved to nothing and the move silently no-op'd — Studio's "Move to
diff --git a/packages/parsers/src/gsapWriterAcorn.ts b/packages/parsers/src/gsapWriterAcorn.ts
index e3a797f208..c6cba95ce1 100644
--- a/packages/parsers/src/gsapWriterAcorn.ts
+++ b/packages/parsers/src/gsapWriterAcorn.ts
@@ -19,6 +19,7 @@ import {
extractArcWaypoints,
buildMotionPathObjectCode,
mergePercentageKeyframes,
+ plainPercentKey,
} from "./gsapSerialize.js";
import {
parseGsapScriptAcornForWrite,
@@ -1225,7 +1226,7 @@ function convertArrayKeyframesToObject(script: string, target: Node): string {
if (!timing) return script;
const entries = els.map((el, i) => {
const { duration: _duration, ...record } = records[i]!;
- return `${JSON.stringify(`${timing.percentages[i]}%`)}: ${recordToCode(record)}`;
+ return `${JSON.stringify(plainPercentKey(timing.percentages[i]!))}: ${recordToCode(record)}`;
});
const ms = new MagicString(script);
ms.overwrite(
@@ -1328,7 +1329,13 @@ export function addKeyframeToScript(
ms.overwrite(existing.prop.value.start, existing.prop.value.end, recordToCode(targetRecord));
}
} else {
- insertNewKeyframe(ms, kfNode, percentage, `${percentage}%`, recordToCode(targetRecord));
+ insertNewKeyframe(
+ ms,
+ kfNode,
+ percentage,
+ plainPercentKey(percentage),
+ recordToCode(targetRecord),
+ );
}
for (const [prop, rec] of [...endpointOverwrites, ...backfillOverwrites]) {
ms.overwrite(prop.value.start, prop.value.end, recordToCode(rec));
@@ -1507,9 +1514,14 @@ export function moveKeyframeInScript(
entries.push({ pct: toPercentage, record: valueNodeToRecord(match.prop.value, src) });
entries.sort((a, b) => a.pct - b.pct);
- const body = entries
- .map((e) => `${JSON.stringify(`${e.pct}%`)}: ${recordToCode(e.record)}`)
- .join(", ");
+ const pctProps = new Set(percentagePropsOf(kfNode));
+ const kept = (kfNode.properties ?? [])
+ .filter((p: Node) => !pctProps.has(p))
+ .map((p: Node) => src.slice(p.start, p.end));
+ const body = [
+ ...entries.map((e) => `${JSON.stringify(plainPercentKey(e.pct))}: ${recordToCode(e.record)}`),
+ ...kept,
+ ].join(", ");
const ms = new MagicString(src);
ms.overwrite(kfNode.start, kfNode.end, `{ ${body} }`);
return ms.toString();
@@ -1554,7 +1566,7 @@ export function resizeKeyframedTweenInScript(
const ms = new MagicString(src);
for (const { keyNode, to } of edits) {
- ms.overwrite(keyNode.start, keyNode.end, JSON.stringify(`${to}%`));
+ ms.overwrite(keyNode.start, keyNode.end, JSON.stringify(plainPercentKey(to)));
}
overwritePosition(ms, target.call, newPosition);
// Resizing is an explicit duration-authoring gesture. Promote GSAP's implicit
@@ -1753,7 +1765,7 @@ function buildKeyframeObjectCode(
const props = Object.entries(kf.properties).map(([k, v]) => `${safeKey(k)}: ${valueToCode(v)}`);
if (kf.ease) props.push(`ease: ${valueToCode(kf.ease)}`);
if (kf.auto) props.push(`_auto: 1`);
- return `${JSON.stringify(`${kf.percentage}%`)}: { ${props.join(", ")} }`;
+ return `${JSON.stringify(plainPercentKey(kf.percentage))}: { ${props.join(", ")} }`;
});
if (easeEach) entries.push(`easeEach: ${valueToCode(easeEach)}`);
return `{ ${entries.join(", ")} }`;
@@ -1995,7 +2007,8 @@ function addGroupAnimToScript(
pos,
anim.duration ?? 0.5,
groupKeyframes,
- anim.keyframes.easeEach ?? anim.ease,
+ anim.keyframes.ease ?? anim.ease,
+ anim.keyframes.easeEach,
);
}
const groupProperties = filterGroupProperties(anim.properties, propSet);
diff --git a/packages/studio/src/components/editor/AnimationCard.test.tsx b/packages/studio/src/components/editor/AnimationCard.test.tsx
index e0e96ab0aa..da53d9fb99 100644
--- a/packages/studio/src/components/editor/AnimationCard.test.tsx
+++ b/packages/studio/src/components/editor/AnimationCard.test.tsx
@@ -149,6 +149,66 @@ function restoreScrollIntoView(descriptor: PropertyDescriptor | undefined): void
}
describe("AnimationCard", () => {
+ it("heads a keyframed card with the segment ease and names the run ease on its own line", () => {
+ const view = renderFocusCard(null, vi.fn(), true);
+ expect(view.host.querySelector("[data-card-ease]")?.textContent).toBe("power1.inOut");
+ expect(view.host.querySelector("[data-card-run-ease]")?.textContent).toBe(
+ "Run ease: power1.out",
+ );
+ act(() => view.root.unmount());
+ });
+
+ it("heads a keyframed card Mixed when its segments differ, with no run line for a linear run", () => {
+ const animation: GsapAnimation = {
+ ...ANIMATION,
+ ease: undefined,
+ keyframes: {
+ format: "percentage",
+ keyframes: [
+ { percentage: 0, properties: { x: 0 } },
+ { percentage: 50, properties: { x: 100 }, ease: "expo.in" },
+ { percentage: 100, properties: { x: 200 } },
+ ],
+ },
+ };
+ const view = renderFocusCard(null, vi.fn(), true, animation);
+ expect(view.host.querySelector("[data-card-ease]")?.textContent).toBe("Mixed");
+ expect(view.host.querySelector("[data-card-run-ease]")).toBeNull();
+ act(() => view.root.unmount());
+ });
+
+ it("labels segments with rounded percentages, never float noise or exponents", () => {
+ const animation: GsapAnimation = {
+ ...ANIMATION,
+ keyframes: {
+ format: "percentage",
+ keyframes: [
+ { percentage: 0, properties: { x: 0 } },
+ { percentage: 1.2860082304526747e-7, properties: { x: 1 } },
+ { percentage: 0.13484773662551455, properties: { x: 2 } },
+ { percentage: 100, properties: { x: 200 } },
+ ],
+ },
+ };
+ const view = renderFocusCard(null, vi.fn(), true, animation);
+ const labels = [
+ ...view.host.querySelectorAll("[data-ease-segment-pct] button span:first-child"),
+ ];
+ expect(labels.map((label) => label.textContent)).toEqual([
+ "0% → <0.001%",
+ "<0.001% → 0.135%",
+ "0.135% → 100%",
+ ]);
+ act(() => view.root.unmount());
+ });
+
+ it("labels an unset segment with the ease GSAP plays, not the tween's run ease", () => {
+ const view = renderFocusCard(null, vi.fn(), true);
+ const labels = [...view.host.querySelectorAll("[data-ease-segment-pct] button span.ml-auto")];
+ expect(labels.map((label) => label.textContent)).toEqual(["power1.inOut", "power1.inOut"]);
+ act(() => view.root.unmount());
+ });
+
it("scrolls a focused segment into view but not a manually toggled segment", () => {
const originalScrollIntoView = Object.getOwnPropertyDescriptor(
HTMLElement.prototype,
diff --git a/packages/studio/src/components/editor/AnimationCard.tsx b/packages/studio/src/components/editor/AnimationCard.tsx
index 19ea4fabc8..ac0f41fffa 100644
--- a/packages/studio/src/components/editor/AnimationCard.tsx
+++ b/packages/studio/src/components/editor/AnimationCard.tsx
@@ -6,7 +6,8 @@ import { RESPONSIVE_GRID } from "./propertyPanelHelpers";
import { MetricField, SelectField } from "./propertyPanelPrimitives";
import { controlPointsForGsapEase } from "./studioMotion";
import { EASE_LABELS, METHOD_LABELS, METHOD_TOOLTIPS, PROP_LABELS } from "./gsapAnimationConstants";
-import { buildTweenSummary } from "./gsapAnimationHelpers";
+import { buildTweenSummary, uniformSegmentEase } from "./gsapAnimationHelpers";
+import { keyframedTweenEases } from "../../utils/gsapKeyframeEases";
import { EaseCurveSection } from "./EaseCurveSection";
import { ArcPathControls } from "./ArcPathControls";
import type { GsapAnimationEditCallbacks } from "./gsapAnimationCallbacks";
@@ -31,6 +32,9 @@ interface AnimationCardProps extends GsapAnimationEditCallbacks {
onFocusSegmentConsumed?: () => void;
}
+const easeDisplayName = (ease: string) =>
+ ease.startsWith("custom(") ? "Custom curve" : (EASE_LABELS[ease] ?? ease);
+
// fallow-ignore-next-line complexity
export const AnimationCard = memo(function AnimationCard({
animation,
@@ -152,9 +156,9 @@ export const AnimationCard = memo(function AnimationCard({
const methodLabel = METHOD_LABELS[animation.method] ?? animation.method;
const easeName =
(animation.keyframes ? animation.keyframes.easeEach : undefined) ?? animation.ease ?? "none";
- const easeLabel = easeName.startsWith("custom(")
- ? "Custom curve"
- : (EASE_LABELS[easeName] ?? easeName);
+ const headerEase = animation.keyframes ? uniformSegmentEase(animation) : easeName;
+ const easeLabel = headerEase === null ? "Mixed" : easeDisplayName(headerEase);
+ const runEase = animation.keyframes ? keyframedTweenEases(animation).run : undefined;
const endTime =
typeof animation.position === "number"
? animation.position + (animation.duration ?? 0)
@@ -217,7 +221,8 @@ export const AnimationCard = memo(function AnimationCard({
</span>
<span
className={`ml-auto text-[10px] ${flat ? "text-panel-text-3" : "text-neutral-500"}`}
- title={easeName}
+ title={headerEase ?? "Mixed"}
+ data-card-ease
>
{easeLabel}
</span>
@@ -254,6 +259,11 @@ export const AnimationCard = memo(function AnimationCard({
Keyframed — click a segment below to edit its curve
</p>
)}
+ {runEase && runEase !== "none" && (
+ <p className="mt-1 text-[9px] text-neutral-500" data-card-run-ease>
+ Run ease: {easeDisplayName(runEase)}
+ </p>
+ )}
</div>
<button
type="button"
@@ -296,7 +306,7 @@ export const AnimationCard = memo(function AnimationCard({
{animation.keyframes && onUpdateKeyframeEase ? (
<KeyframeEaseList
keyframes={animation.keyframes.keyframes}
- globalEase={animation.keyframes.easeEach ?? animation.ease ?? "none"}
+ globalEase={keyframedTweenEases(animation).segment({})}
expandedPct={expandedKfPct}
collidingAnimationTargets={focusedCollidingAnimationTargets}
onToggle={(pct) => {
diff --git a/packages/studio/src/components/editor/KeyframeEaseList.tsx b/packages/studio/src/components/editor/KeyframeEaseList.tsx
index 66793b60e5..7cc11bbe57 100644
--- a/packages/studio/src/components/editor/KeyframeEaseList.tsx
+++ b/packages/studio/src/components/editor/KeyframeEaseList.tsx
@@ -1,6 +1,7 @@
import type { GsapPercentageKeyframe } from "@hyperframes/core/gsap-parser";
import { EASE_LABELS } from "./gsapAnimationConstants";
import { EaseCurveSection } from "./EaseCurveSection";
+import { roundTo3 } from "../../utils/rounding";
import type { AnimationKeyframeTarget } from "../../hooks/gsapTweenSynth";
// The full GSAP easing vocabulary offered by the "Set all…" bulk control —
@@ -41,6 +42,8 @@ const APPLY_ALL_EASES = [
"bounce.inOut",
] as const;
+const percentLabel = (pct: number) => (pct > 0 && pct < 0.001 ? "<0.001" : String(roundTo3(pct)));
+
export function KeyframeEaseList({
keyframes,
globalEase,
@@ -91,7 +94,7 @@ export function KeyframeEaseList({
if (i === 0) return null;
const segEase = kf.ease ?? globalEase;
const isExpanded = expandedPct === kf.percentage;
- const label = `${keyframes[i - 1].percentage}% → ${kf.percentage}%`;
+ const label = `${percentLabel(keyframes[i - 1].percentage)}% → ${percentLabel(kf.percentage)}%`;
const easeLabel = segEase.startsWith("custom(")
? "Custom"
: (EASE_LABELS[segEase] ?? segEase);
diff --git a/packages/studio/src/components/editor/gsapAnimationHelpers.test.ts b/packages/studio/src/components/editor/gsapAnimationHelpers.test.ts
index c60fbbae95..da97d94a3c 100644
--- a/packages/studio/src/components/editor/gsapAnimationHelpers.test.ts
+++ b/packages/studio/src/components/editor/gsapAnimationHelpers.test.ts
@@ -52,6 +52,35 @@ describe("buildTweenSummary", () => {
expect(s).toContain("opacity");
});
+ it("describes a keyframed tween by its keyframes and the segment ease it plays", () => {
+ const keyframes = {
+ easeEach: "power3.out",
+ keyframes: [
+ { percentage: 0, properties: { x: 0 } },
+ { percentage: 50, properties: { x: 300, opacity: 0.5 } },
+ { percentage: 100, properties: { x: 600 } },
+ ],
+ };
+ expect(buildTweenSummary(anim({ ease: undefined, keyframes } as Partial<GsapAnimation>))).toBe(
+ "Starting at 0s, over 1s, animate #box's move x, opacity through 3 keyframes, each segment eased power3.out.",
+ );
+ });
+
+ it("names a keyframed tween's run ease and mixed segment eases", () => {
+ const keyframes = {
+ keyframes: [
+ { percentage: 0, properties: { x: 0 } },
+ { percentage: 50, properties: { x: 300 }, ease: "expo.in" },
+ { percentage: 100, properties: { x: 600 } },
+ ],
+ };
+ expect(
+ buildTweenSummary(anim({ ease: "sine.inOut", keyframes } as Partial<GsapAnimation>)),
+ ).toBe(
+ "Starting at 0s, over 1s, animate #box's move x through 3 keyframes, with per-keyframe easing, across a sine.inOut run.",
+ );
+ });
+
it("describes a set tween", () => {
const s = buildTweenSummary(anim({ method: "set", properties: { opacity: 0 } }));
expect(s).toMatch(/^At 0s, instantly set/);
diff --git a/packages/studio/src/components/editor/gsapAnimationHelpers.ts b/packages/studio/src/components/editor/gsapAnimationHelpers.ts
index ac9c2b5e37..b0f059ac0a 100644
--- a/packages/studio/src/components/editor/gsapAnimationHelpers.ts
+++ b/packages/studio/src/components/editor/gsapAnimationHelpers.ts
@@ -1,5 +1,6 @@
import type { GsapAnimation } from "@hyperframes/parsers/gsap-parser";
import { EASE_LABELS, PERCENT_PROPS, PROP_LABELS, PROP_UNITS } from "./gsapAnimationConstants";
+import { keyframedTweenEases } from "../../utils/gsapKeyframeEases";
function formatPropValue(prop: string, v: number | string): string {
const unit = PROP_UNITS[prop] ?? "";
@@ -7,6 +8,38 @@ function formatPropValue(prop: string, v: number | string): string {
return `${v}${unit}`;
}
+const easeLabel = (ease: string) =>
+ ease.startsWith("custom(") ? "custom" : (EASE_LABELS[ease] ?? ease);
+
+export function uniformSegmentEase(animation: GsapAnimation): string | null {
+ const eases = keyframedTweenEases(animation);
+ const steps = animation.keyframes?.keyframes ?? [];
+ const segmentEases = new Set(steps.slice(1).map((kf) => eases.segment(kf)));
+ if (segmentEases.size === 0) return eases.segment({});
+ return segmentEases.size === 1 ? [...segmentEases][0]! : null;
+}
+
+function keyframedTweenSummary(
+ animation: GsapAnimation,
+ pos: number | string,
+ dur: number,
+): string {
+ const steps = animation.keyframes?.keyframes ?? [];
+ const props = [...new Set(steps.flatMap((kf) => Object.keys(kf.properties)))];
+ const propText = props.map((p) => (PROP_LABELS[p] ?? p).toLowerCase()).join(", ");
+ const segmentEase = uniformSegmentEase(animation);
+ const segmentText =
+ steps.length < 2
+ ? ""
+ : segmentEase
+ ? `, each segment eased ${easeLabel(segmentEase)}`
+ : ", with per-keyframe easing";
+ const run = keyframedTweenEases(animation).run;
+ const runText = run && run !== "none" ? `, across a ${easeLabel(run)} run` : "";
+ const count = `${steps.length} keyframe${steps.length === 1 ? "" : "s"}`;
+ return `Starting at ${pos}s, over ${dur}s, animate ${animation.targetSelector}'s ${propText || "no properties yet"} through ${count}${segmentText}${runText}.`;
+}
+
// fallow-ignore-next-line complexity
export function buildTweenSummary(animation: GsapAnimation): string {
const easeName = animation.ease ?? "none";
@@ -16,6 +49,7 @@ export function buildTweenSummary(animation: GsapAnimation): string {
const dur = animation.duration ?? 0;
const rawPos = animation.position;
const pos = typeof rawPos === "number" ? parseFloat(rawPos.toFixed(3)) : rawPos;
+ if (animation.keyframes) return keyframedTweenSummary(animation, pos, dur);
const propDescs = props.map(([p, v]) => {
const label = (PROP_LABELS[p] ?? p).toLowerCase();
return `${label} to ${formatPropValue(p, v)}`;
diff --git a/packages/studio/src/hooks/gsapPlaybackTestHarness.ts b/packages/studio/src/hooks/gsapPlaybackTestHarness.ts
new file mode 100644
index 0000000000..eebcd696ba
--- /dev/null
+++ b/packages/studio/src/hooks/gsapPlaybackTestHarness.ts
@@ -0,0 +1,28 @@
+import { gsap } from "gsap";
+
+type KeyframeMutation = {
+ duration: number;
+ ease?: string;
+ easeEach?: string;
+ keyframes: Array<{
+ percentage: number;
+ properties: Record<string, number | string>;
+ ease?: string;
+ }>;
+};
+
+/** Plays a replace-with-keyframes mutation in real GSAP and reads `x` at `time` seconds. */
+export function xAtTime(mutation: KeyframeMutation, time: number): number {
+ const target = { x: 0, y: 0, opacity: 1 };
+ const frames: Record<string, unknown> = mutation.easeEach ? { easeEach: mutation.easeEach } : {};
+ for (const kf of mutation.keyframes) {
+ frames[`${kf.percentage}%`] = { ...kf.properties, ...(kf.ease ? { ease: kf.ease } : {}) };
+ }
+ const vars = {
+ duration: mutation.duration,
+ keyframes: frames,
+ ...(mutation.ease ? { ease: mutation.ease } : {}),
+ };
+ gsap.timeline({ paused: true }).to(target, vars, 0).seek(time);
+ return target.x;
+}
diff --git a/packages/studio/src/hooks/gsapShared.test.ts b/packages/studio/src/hooks/gsapShared.test.ts
index c2fad2245d..1ce1028fa9 100644
--- a/packages/studio/src/hooks/gsapShared.test.ts
+++ b/packages/studio/src/hooks/gsapShared.test.ts
@@ -4,6 +4,7 @@ import {
idFromSelector,
idSelector,
isInstantHold,
+ keyframeEases,
parsePercentageKeyframes,
resolveClipTimingBasis,
playsNear,
@@ -11,6 +12,16 @@ import {
toClipPercentage,
} from "./gsapShared";
+describe("keyframeEases", () => {
+ it("carries the keyframes' own ease into the tween ease, which GSAP plays the same", () => {
+ const anim = {
+ ease: "back.out",
+ keyframes: { keyframes: [], ease: "sine.inOut", easeEach: "power2.out" },
+ } as unknown as GsapAnimation;
+ expect(keyframeEases(anim)).toEqual({ ease: "sine.inOut", easeEach: "power2.out" });
+ });
+});
+
describe("isInstantHold", () => {
const animation = (method: GsapAnimation["method"], duration?: number) =>
({ method, duration }) as unknown as GsapAnimation;
diff --git a/packages/studio/src/hooks/gsapShared.ts b/packages/studio/src/hooks/gsapShared.ts
index bf5e8a47f6..a406c6138e 100644
--- a/packages/studio/src/hooks/gsapShared.ts
+++ b/packages/studio/src/hooks/gsapShared.ts
@@ -41,7 +41,7 @@ export const PROPERTY_DEFAULTS: Record<string, number> = {
* since GSAP eases each percentage segment power1.inOut whatever the tween-level ease says. */
export function keyframeEases(anim: GsapAnimation): { ease?: string; easeEach?: string } {
if (!anim.keyframes) return { easeEach: anim.ease };
- return { ease: anim.ease, easeEach: anim.keyframes.easeEach };
+ return { ease: runEaseOf(anim), easeEach: anim.keyframes.easeEach };
}
/**
diff --git a/packages/studio/src/hooks/keyframeEase.realGsap.test.ts b/packages/studio/src/hooks/keyframeEase.realGsap.test.ts
new file mode 100644
index 0000000000..10246d399a
--- /dev/null
+++ b/packages/studio/src/hooks/keyframeEase.realGsap.test.ts
@@ -0,0 +1,37 @@
+// Real gsap: the ease the parser reports for keyframes must be the one GSAP plays.
+import { parseGsapScriptAcorn } from "@hyperframes/core/gsap-parser-acorn";
+import { gsap } from "gsap";
+import { describe, expect, it } from "vitest";
+
+const STEPS = { "0%": { x: 0 }, "100%": { x: 10 } };
+
+function xAt(vars: gsap.TweenVars, time = 0.3): number {
+ const target = { x: 0 };
+ gsap
+ .timeline({ paused: true })
+ .to(target, { duration: 1, ...vars }, 0)
+ .seek(time);
+ return target.x;
+}
+
+const parsedEaseEach = (vars: string) =>
+ parseGsapScriptAcorn(`const tl = gsap.timeline({ paused: true });
+tl.to("#a", { duration: 1, ${vars} }, 0);`).animations[0]!.keyframes?.easeEach;
+
+describe("the keyframes ease the parser reports", () => {
+ it("is not a tween-level easeEach, which GSAP ignores", () => {
+ expect(xAt({ keyframes: STEPS, easeEach: "power4.in" })).toBe(xAt({ keyframes: STEPS }));
+ expect(
+ parsedEaseEach('keyframes: { "0%": { x: 0 }, "100%": { x: 10 } }, easeEach: "power4.in"'),
+ ).toBeUndefined();
+ });
+
+ it("is an easeEach inside the keyframes, which GSAP plays", () => {
+ expect(xAt({ keyframes: { ...STEPS, easeEach: "power4.in" } })).not.toBe(
+ xAt({ keyframes: STEPS }),
+ );
+ expect(
+ parsedEaseEach('keyframes: { "0%": { x: 0 }, "100%": { x: 10 }, easeEach: "power4.in" }'),
+ ).toBe("power4.in");
+ });
+});
diff --git a/packages/studio/src/hooks/useAnimatedPropertyCommit.test.tsx b/packages/studio/src/hooks/useAnimatedPropertyCommit.test.tsx
index 0c28f3fa47..a95cc22248 100644
--- a/packages/studio/src/hooks/useAnimatedPropertyCommit.test.tsx
+++ b/packages/studio/src/hooks/useAnimatedPropertyCommit.test.tsx
@@ -10,6 +10,7 @@ import { mountReactHarness, withInlineLayoutBox } from "./domSelectionTestHarnes
import { writeSizeWithCrop } from "../components/editor/cropResize";
import { trackStudioEvent } from "../utils/studioTelemetry";
import { trackKeyframeCommit } from "../utils/keyframeUsage";
+import { xAtTime } from "./gsapPlaybackTestHarness";
import type { CommitMutationOptions, CommitMutation } from "./gsapScriptCommitTypes";
vi.mock("../utils/studioTelemetry", () => ({ trackStudioEvent: vi.fn() }));
@@ -205,6 +206,38 @@ function renderCommitHook(
// canvas nudge exercises (not the raw drag intercept) — with auto-keyframe
// off, it must shift the whole tween instead of adding/updating a keyframe
// at the playhead.
+describe("useAnimatedPropertyCommit — extending a keyframed tween to the playhead", () => {
+ it("keeps the tween's eases and each keyframe's own ease", async () => {
+ usePlayerStore.setState({ autoKeyframeEnabled: true, currentTime: 3, activeKeyframePct: null });
+ const eased = {
+ ...keyframedAnim,
+ ease: "power2.inOut",
+ keyframes: {
+ easeEach: "power2.out",
+ keyframes: [
+ { percentage: 0, properties: { x: 0, y: 0 }, ease: "expo.in" },
+ { percentage: 100, properties: { x: 100, y: 0 } },
+ ],
+ },
+ } as unknown as GsapAnimation;
+ const mutations: Array<Record<string, unknown>> = [];
+ let commit!: Commit;
+ const root = renderHookWith(
+ [eased],
+ (mutation) => mutations.push(mutation),
+ (ready) => (commit = ready),
+ );
+ await act(async () => commit(selection, { x: 50 }));
+ act(() => root.unmount());
+
+ const replace = mutations.find((m) => m.type === "replace-with-keyframes")!;
+ expect(replace).toMatchObject({ ease: "power2.inOut", easeEach: "power2.out" });
+ expect((replace.keyframes as Array<{ ease?: string }>)[0]!.ease).toBe("expo.in");
+ // The old end keyframe still plays at 2 s once the tween runs to the playhead at 3 s.
+ expect(xAtTime(replace as unknown as Parameters<typeof xAtTime>[0], 2)).toBeCloseTo(100, 0);
+ });
+});
+
describe("useAnimatedPropertyCommit — autoKeyframeEnabled toggle (#1808)", () => {
async function runCommitWithAutoKeyframe(enabled: boolean) {
usePlayerStore.setState({ autoKeyframeEnabled: enabled, currentTime: 0 });
diff --git a/packages/studio/src/hooks/useAnimatedPropertyCommit.ts b/packages/studio/src/hooks/useAnimatedPropertyCommit.ts
index b5ba08d4d6..a5521f681f 100644
--- a/packages/studio/src/hooks/useAnimatedPropertyCommit.ts
+++ b/packages/studio/src/hooks/useAnimatedPropertyCommit.ts
@@ -18,6 +18,7 @@ import {
selectorFromSelection,
computeElementPercentage,
isInstantHold,
+ keyframeEases,
writeTargetSelector,
tweenTargetsElement,
} from "./gsapShared";
@@ -375,7 +376,7 @@ async function commitKeyframeProps(
for (const k of Object.keys(properties)) {
if (!(k in p) && backfillDefaults[k] != null) p[k] = backfillDefaults[k];
}
- return { percentage: newPct, properties: p };
+ return { percentage: newPct, properties: p, ...(kf.ease ? { ease: kf.ease } : {}) };
});
remapped.push({ percentage: toNewPct(ct), properties });
remapped.sort((a, b) => a.percentage - b.percentage);
@@ -388,6 +389,7 @@ async function commitKeyframeProps(
position: roundTo3(newStart),
duration: roundTo3(newDuration),
keyframes: remapped,
+ ...keyframeEases(anim),
},
{ label: `Edit ${primaryProp} (extended keyframe)`, keyframeAction: "add", softReload: true },
);
diff --git a/packages/studio/src/hooks/useGestureCommit.test.tsx b/packages/studio/src/hooks/useGestureCommit.test.tsx
index 5166e049e4..93aaad0e36 100644
--- a/packages/studio/src/hooks/useGestureCommit.test.tsx
+++ b/packages/studio/src/hooks/useGestureCommit.test.tsx
@@ -10,6 +10,7 @@ import { mountReactHarness } from "./domSelectionTestHarness";
import type { CommitMutationOptions } from "./gsapScriptCommitTypes";
import { useGsapAwareEditing } from "./useGsapAwareEditing";
import { useGestureCommit } from "./useGestureCommit";
+import { xAtTime } from "./gsapPlaybackTestHarness";
vi.mock("../utils/studioTelemetry", () => ({ trackStudioEvent: vi.fn() }));
@@ -243,6 +244,94 @@ it.each([
},
);
+const FROM_0_TO_100 = [
+ { percentage: 0, properties: { x: 0 } },
+ { percentage: 100, properties: { x: 100 } },
+];
+
+function positionTween(
+ duration: number,
+ eases: { ease?: string; easeEach?: string } = {},
+ keyframes = FROM_0_TO_100,
+) {
+ return {
+ id: "card-position",
+ targetSelector: "#card",
+ propertyGroup: "position",
+ method: "to",
+ properties: { x: 0, y: 0 },
+ resolvedStart: 0,
+ position: 0,
+ duration,
+ ...(eases.ease ? { ease: eases.ease } : {}),
+ keyframes: {
+ ...(eases.easeEach ? { easeEach: eases.easeEach } : {}),
+ keyframes,
+ },
+ } as unknown as GsapAnimation;
+}
+
+/** Records the mocked 1 s gesture (x 0, 50, 100) from 0 s over `tween`; resolves to the merge mutation. */
+async function recordMergeInto(tween: GsapAnimation) {
+ const writer = vi.fn(
+ async (_mutation: Record<string, unknown>, options: CommitMutationOptions) => {
+ options.onResult?.({ ok: true, changed: true });
+ },
+ );
+ const hook = mountRecording(writer, [tween]);
+ act(() => hook().handleToggleRecording("button"));
+ await act(async () => {
+ hook().handleToggleRecording();
+ await vi.waitFor(() => expect(writer).toHaveBeenCalled());
+ });
+ expect(writer.mock.calls[0]![1]).toMatchObject({ label: "Gesture recording (merge)" });
+ return writer.mock.calls[0]![0] as unknown as Parameters<typeof xAtTime>[0] & {
+ type: string;
+ ease?: string;
+ easeEach?: string;
+ };
+}
+
+it("keeps the tween's eases when a recording merges into it", async () => {
+ const merge = await recordMergeInto(
+ positionTween(2, { ease: "back.out", easeEach: "power2.out" }),
+ );
+ expect(merge).toMatchObject({
+ type: "replace-with-keyframes",
+ ease: "back.out",
+ easeEach: "power2.out",
+ });
+ // Recorded segments the fitter left unset stay constant speed instead of taking easeEach.
+ expect(merge.keyframes.map((kf) => kf.ease)).toEqual([undefined, "none", "none", undefined]);
+});
+
+it("plays a recording merged into an eased tween at the times it was recorded", async () => {
+ const merge = await recordMergeInto(positionTween(3, { ease: "power2.out" }));
+ expect(xAtTime(merge, 0.5)).toBeCloseTo(50, 0);
+ expect(xAtTime(merge, 1)).toBeCloseTo(100, 0);
+});
+
+it("keeps recorded keyframes apart over the tail of a power4.out tween", async () => {
+ usePlayerStore.setState({ currentTime: 9 });
+ const merge = await recordMergeInto(positionTween(10, { ease: "power4.out" }));
+ expect(xAtTime(merge, 9.5)).toBeCloseTo(50, 0);
+});
+
+it("keeps a keyframe playing at 8.5 s when a recording covers 9-10 s of a power2.out tween", async () => {
+ usePlayerStore.setState({ currentTime: 9 });
+ const at8_5s = { percentage: 99.6625, properties: { x: 80 } };
+ const merge = await recordMergeInto(
+ positionTween(10, { ease: "power2.out" }, [FROM_0_TO_100[0]!, at8_5s, FROM_0_TO_100[1]!]),
+ );
+ expect(merge.keyframes).toContainEqual(at8_5s);
+ expect(xAtTime(merge, 8.5)).toBeCloseTo(80, 0);
+});
+
+it("writes merged keyframe percentages rounded, not as float noise", async () => {
+ const merge = await recordMergeInto(positionTween(3));
+ expect(merge.keyframes.map((kf) => kf.percentage)).toEqual([0, 16.667, 33.333, 100]);
+});
+
it("keeps a pending recording isolated until its writer settles", async () => {
let release!: () => void;
const pending = new Promise<void>((resolve) => {
diff --git a/packages/studio/src/hooks/useGestureCommit.ts b/packages/studio/src/hooks/useGestureCommit.ts
index adeadc2f12..fa232ab119 100644
--- a/packages/studio/src/hooks/useGestureCommit.ts
+++ b/packages/studio/src/hooks/useGestureCommit.ts
@@ -16,8 +16,15 @@ import { trackPreviewEditResult } from "../utils/previewFeatureUsage";
import { observeGsapGesture } from "./gsapGestureOutcome";
import { roundTo3 } from "../utils/rounding";
import { classifyPropertyGroup } from "@hyperframes/core/gsap-parser";
-import { isInstantHold, idSelector, writeTargetSelector, tweenTargetsElement } from "./gsapShared";
+import {
+ isInstantHold,
+ idSelector,
+ keyframeEases,
+ writeTargetSelector,
+ tweenTargetsElement,
+} from "./gsapShared";
import { useStableHandlers } from "./useStableHandlers";
+import { progressAtTime, runEaseOf, timeAtProgress, warpsTime } from "../utils/gsapKeyframeEases";
type RecordedKeyframe = {
percentage: number;
@@ -269,25 +276,34 @@ export function useGestureCommit({
if (overlaps) {
const existingKfs = existingPositionTween.keyframes?.keyframes ?? [];
- const rangeStartPct =
+ const startTimePct =
tweenDur > 0 ? Math.max(0, ((recStart - tweenStart) / tweenDur) * 100) : 0;
- const rangeEndPct =
+ const endTimePct =
tweenDur > 0 ? Math.min(100, ((recEnd - tweenStart) / tweenDur) * 100) : 100;
+ const runEase = runEaseOf(existingPositionTween);
+ const roundPct = warpsTime(runEase) ? (pct: number) => pct : roundTo3;
const preserved = existingKfs
- .filter(
- (kf) => kf.percentage < rangeStartPct - 0.5 || kf.percentage > rangeEndPct + 0.5,
- )
+ .filter((kf) => {
+ const playsAt = timeAtProgress(runEase, kf.percentage);
+ return playsAt < startTimePct - 0.5 || playsAt > endTimePct + 0.5;
+ })
.map((kf) => ({
percentage: kf.percentage,
properties: kf.properties,
...(kf.ease ? { ease: kf.ease } : {}),
}));
- const mapped = keyframes.map((kf) => ({
- percentage: rangeStartPct + (kf.percentage / 100) * (rangeEndPct - rangeStartPct),
+ const constantSpeed = { ease: "none" };
+ const mapped = keyframes.map((kf, index) => ({
+ percentage: roundPct(
+ progressAtTime(
+ runEase,
+ startTimePct + (kf.percentage / 100) * (endTimePct - startTimePct),
+ ),
+ ),
properties: kf.properties,
- ...(kf.ease ? { ease: kf.ease } : {}),
+ ...(kf.ease ? { ease: kf.ease } : index > 0 ? constantSpeed : {}),
}));
const merged = [...preserved, ...mapped].sort((a, b) => a.percentage - b.percentage);
@@ -303,6 +319,7 @@ export function useGestureCommit({
: tweenStart,
duration: tweenDur,
keyframes: merged,
+ ...keyframeEases(existingPositionTween),
},
{ label: "Gesture recording (merge)", softReload: true, keyframeAction: "add" },
);
diff --git a/packages/studio/src/utils/gsapKeyframeEases.ts b/packages/studio/src/utils/gsapKeyframeEases.ts
index 40b20b690a..569f40daa0 100644
--- a/packages/studio/src/utils/gsapKeyframeEases.ts
+++ b/packages/studio/src/utils/gsapKeyframeEases.ts
@@ -50,6 +50,8 @@ function timingEase(runEase: string | undefined): ((progress: number) => number)
return timingEases.get(runEase) ?? null;
}
+export const warpsTime = (runEase: string | undefined) => timingEase(runEase) !== null;
+
/** The keyframe progress (0-100) GSAP shows at `timePercentage` of a tween with this run ease. */
export function progressAtTime(runEase: string | undefined, timePercentage: number): number {
const run = timingEase(runEase);