fix(studio): suppress inline ease button on ambiguous collapsed-row segments

The collapsed clip row merges a clip's source animations and dedups keyframes
by percentage (last ease wins), so an inline ease segment where two animations
collide at the same clip % with different eases targeted an arbitrary tween.
Flag such merged keyframes (easeAmbiguous) at both merge sites (deduplicateKeyframes
and updateKeyframeCacheFromParsed), computed before the ease overwrite, and hide
the inline ease button on those segments; unambiguous segments are unchanged and
the user edits colliding ones by expanding the clip's per-lane view.
This commit is contained in:
Miguel Angel Simon Sierra
2026-07-16 11:25:47 -04:00
parent 629ea7e82f
commit 9027a579ad
6 changed files with 116 additions and 9 deletions
@@ -56,6 +56,18 @@ export function updateKeyframeCacheFromParsed(
const prev = byPct.get(kf.percentage);
if (prev) {
prev.properties = { ...prev.properties, ...kf.properties };
// Mirror deduplicateKeyframes: a same-% collision across different
// source animations with different eases is an ambiguous merged
// segment — flag it (before the ease overwrite) so the collapsed row
// suppresses the inline ease button there.
if (
prev.animationId !== undefined &&
kf.animationId !== undefined &&
prev.animationId !== kf.animationId &&
prev.ease !== kf.ease
) {
prev.easeAmbiguous = true;
}
if (kf.ease) prev.ease = kf.ease;
} else {
byPct.set(kf.percentage, { ...kf, properties: { ...kf.properties } });
@@ -1,6 +1,6 @@
import { describe, expect, it } from "vitest";
import type { GsapAnimation } from "@hyperframes/core/gsap-parser";
import { synthesizeFlatTweenKeyframes } from "./gsapTweenSynth";
import { deduplicateKeyframes, synthesizeFlatTweenKeyframes } from "./gsapTweenSynth";
function anim(overrides: Partial<GsapAnimation>): GsapAnimation {
return {
@@ -53,3 +53,30 @@ describe("synthesizeFlatTweenKeyframes", () => {
expect(out).not.toBeNull();
});
});
describe("deduplicateKeyframes ease ambiguity", () => {
it("flags a same-% collision from different animations with different eases", () => {
const merged = deduplicateKeyframes([
{ percentage: 45, properties: { x: 10 }, ease: "power2.in", animationId: "#a-position" },
{ percentage: 45, properties: { opacity: 1 }, ease: "power2.out", animationId: "#a-visual" },
]);
const kf = merged.find((k) => k.percentage === 45);
expect(kf?.easeAmbiguous).toBe(true);
});
it("does not flag when the colliding eases match", () => {
const merged = deduplicateKeyframes([
{ percentage: 45, properties: { x: 10 }, ease: "power2.in", animationId: "#a-position" },
{ percentage: 45, properties: { opacity: 1 }, ease: "power2.in", animationId: "#a-visual" },
]);
expect(merged.find((k) => k.percentage === 45)?.easeAmbiguous).toBeFalsy();
});
it("does not flag a same-% collision within a single animation", () => {
const merged = deduplicateKeyframes([
{ percentage: 45, properties: { x: 10 }, ease: "power2.in", animationId: "#a-position" },
{ percentage: 45, properties: { y: 20 }, ease: "power2.out", animationId: "#a-position" },
]);
expect(merged.find((k) => k.percentage === 45)?.easeAmbiguous).toBeFalsy();
});
});
+16 -4
View File
@@ -5,14 +5,26 @@ import type {
} from "@hyperframes/core/gsap-parser";
import { PROPERTY_DEFAULTS } from "./gsapShared";
export function deduplicateKeyframes(
keyframes: GsapPercentageKeyframe[],
): GsapPercentageKeyframe[] {
const byPct = new Map<number, GsapPercentageKeyframe>();
export function deduplicateKeyframes<
T extends GsapPercentageKeyframe & { animationId?: string; easeAmbiguous?: boolean },
>(keyframes: T[]): T[] {
const byPct = new Map<number, T>();
for (const kf of keyframes) {
const existing = byPct.get(kf.percentage);
if (existing) {
existing.properties = { ...existing.properties, ...kf.properties };
// Two different source animations with a keyframe at the same clip % but
// different eases: the merged segment's ease target is ambiguous. Flag it
// (compared before the ease overwrite below) so the collapsed clip row
// hides the inline ease button there and the user edits per-lane instead.
if (
existing.animationId !== undefined &&
kf.animationId !== undefined &&
existing.animationId !== kf.animationId &&
existing.ease !== kf.ease
) {
existing.easeAmbiguous = true;
}
if (kf.ease) existing.ease = kf.ease;
} else {
byPct.set(kf.percentage, { ...kf, properties: { ...kf.properties } });
@@ -337,4 +337,52 @@ describe("TimelineClipDiamonds", () => {
expect(suppressClickRef.current).toBe(true);
act(() => root.unmount());
});
const renderSegmentLane = (lastAmbiguous: boolean) => {
const host = document.createElement("div");
document.body.append(host);
const root = createRoot(host);
const kf = (percentage: number, extra: Record<string, unknown> = {}) => ({
percentage,
tweenPercentage: percentage,
propertyGroup: "position",
animationId: "anim-1",
properties: { x: percentage },
...extra,
});
act(() => {
root.render(
<TimelineDiamondLane
keyframesData={{
format: "percentage",
keyframes: [kf(0), kf(50), kf(100, { easeAmbiguous: lastAmbiguous })],
}}
clipWidthPx={200}
clipHeightPx={48}
accentColor="#4ba3d2"
isSelected
currentPercentage={0}
elementId="clip-1"
selectedKeyframes={new Set()}
onSelectSegment={vi.fn()}
groupAware
/>,
);
});
return { host, root };
};
it("hides the inline ease button on an ambiguous merged segment", () => {
// Segments 0->50 and 50->100; the 50->100 segment ends on the ambiguous
// keyframe, so its hover/ease-button area is not rendered.
const { host, root } = renderSegmentLane(true);
expect(host.querySelectorAll("[data-keyframe-ease-segment]").length).toBe(1);
act(() => root.unmount());
});
it("keeps the inline ease button on unambiguous merged segments", () => {
const { host, root } = renderSegmentLane(false);
expect(host.querySelectorAll("[data-keyframe-ease-segment]").length).toBe(2);
act(() => root.unmount());
});
});
@@ -21,6 +21,9 @@ export interface TimelineDiamondKeyframe {
animationId?: string;
properties: Record<string, number | string>;
ease?: string;
/** Set when 2+ source animations collide at this percentage with different
* eases — the collapsed row hides the inline ease button on this segment. */
easeAmbiguous?: boolean;
}
interface KeyframeCacheEntry {
@@ -203,9 +206,11 @@ export const TimelineDiamondLane = memo(function TimelineDiamondLane({
const x1 = Math.max(0, Math.min(clipWidthPx, (prev.percentage / 100) * clipWidthPx));
const x2 = Math.max(0, Math.min(clipWidthPx, (kf.percentage / 100) * clipWidthPx));
if (x2 - x1 < 1) return null;
// Always a group-aware target for the ease button: the segment ease is
// per-keyframe (each keyframe carries its own animationId/tweenPercentage),
// so the button resolves unambiguously even in the merged inline clip row.
// Group-aware target for the ease button: the segment ease is
// per-keyframe (each keyframe carries its own animationId/tweenPercentage).
// On a merged inline row the button is hidden where the segment is
// ambiguous (two source animations collide at this % with different
// eases) — see easeAmbiguous below; the user edits those per-lane.
const target = keyframeTarget(kf, true);
const ease = kf.ease ?? globalEase;
return (
@@ -224,7 +229,7 @@ export const TimelineDiamondLane = memo(function TimelineDiamondLane({
borderRadius: 1,
}}
/>
{onSelectSegment && (
{onSelectSegment && !kf.easeAmbiguous && (
<div
className="absolute"
data-keyframe-ease-segment=""
@@ -14,6 +14,9 @@ export interface KeyframeCacheEntry {
animationId?: string;
properties: Record<string, number | string>;
ease?: string;
/** Set when 2+ source animations collide at this percentage with different
* eases — the collapsed row hides the inline ease button on this segment. */
easeAmbiguous?: boolean;
}>;
ease?: string;
easeEach?: string;