From 9027a579ad290dc471582b5dec124df8958ad71c Mon Sep 17 00:00:00 2001 From: Miguel Angel Simon Sierra Date: Wed, 15 Jul 2026 01:16:23 -0400 Subject: [PATCH] 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. --- .../src/hooks/gsapKeyframeCacheHelpers.ts | 12 +++++ .../studio/src/hooks/gsapTweenSynth.test.ts | 29 ++++++++++- packages/studio/src/hooks/gsapTweenSynth.ts | 20 ++++++-- .../components/TimelineClipDiamonds.test.tsx | 48 +++++++++++++++++++ .../components/TimelineClipDiamonds.tsx | 13 +++-- .../studio/src/player/store/keyframeSlice.ts | 3 ++ 6 files changed, 116 insertions(+), 9 deletions(-) diff --git a/packages/studio/src/hooks/gsapKeyframeCacheHelpers.ts b/packages/studio/src/hooks/gsapKeyframeCacheHelpers.ts index bcd2f405da..7c5d359560 100644 --- a/packages/studio/src/hooks/gsapKeyframeCacheHelpers.ts +++ b/packages/studio/src/hooks/gsapKeyframeCacheHelpers.ts @@ -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 } }); diff --git a/packages/studio/src/hooks/gsapTweenSynth.test.ts b/packages/studio/src/hooks/gsapTweenSynth.test.ts index 3d8d771222..8ea3f2a3e5 100644 --- a/packages/studio/src/hooks/gsapTweenSynth.test.ts +++ b/packages/studio/src/hooks/gsapTweenSynth.test.ts @@ -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 { 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(); + }); +}); diff --git a/packages/studio/src/hooks/gsapTweenSynth.ts b/packages/studio/src/hooks/gsapTweenSynth.ts index e2c18290a1..88453b1017 100644 --- a/packages/studio/src/hooks/gsapTweenSynth.ts +++ b/packages/studio/src/hooks/gsapTweenSynth.ts @@ -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(); +export function deduplicateKeyframes< + T extends GsapPercentageKeyframe & { animationId?: string; easeAmbiguous?: boolean }, +>(keyframes: T[]): T[] { + const byPct = new Map(); 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 } }); diff --git a/packages/studio/src/player/components/TimelineClipDiamonds.test.tsx b/packages/studio/src/player/components/TimelineClipDiamonds.test.tsx index c5d53175e7..535029df5d 100644 --- a/packages/studio/src/player/components/TimelineClipDiamonds.test.tsx +++ b/packages/studio/src/player/components/TimelineClipDiamonds.test.tsx @@ -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 = {}) => ({ + percentage, + tweenPercentage: percentage, + propertyGroup: "position", + animationId: "anim-1", + properties: { x: percentage }, + ...extra, + }); + act(() => { + root.render( + , + ); + }); + 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()); + }); }); diff --git a/packages/studio/src/player/components/TimelineClipDiamonds.tsx b/packages/studio/src/player/components/TimelineClipDiamonds.tsx index 7c810a1039..ccd31a63ec 100644 --- a/packages/studio/src/player/components/TimelineClipDiamonds.tsx +++ b/packages/studio/src/player/components/TimelineClipDiamonds.tsx @@ -21,6 +21,9 @@ export interface TimelineDiamondKeyframe { animationId?: string; properties: Record; 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 && (
; 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;