@@ -36,6 +36,46 @@ export interface TimelineEditCallbackDeps {
3636 handleRazorSplitAll : ( splitTime : number ) => Promise < void > | void ;
3737}
3838
39+ interface TimelineKeyframeTargetAnimation {
40+ id : string ;
41+ propertyGroup ?: string | null ;
42+ keyframes ?: unknown ;
43+ }
44+
45+ interface TimelineCachedKeyframe {
46+ percentage : number ;
47+ tweenPercentage ?: number ;
48+ propertyGroup ?: string ;
49+ }
50+
51+ /**
52+ * Resolve a rendered timeline diamond back to the animation that authored it.
53+ * Flat tweens use synthesized diamonds, so a mixed flat tween may have neither
54+ * a property group nor real keyframes. It is safe to fall back only when that
55+ * flat tween is the selection's sole animation; multiple candidates remain
56+ * unresolved rather than retiming an arbitrary tween.
57+ */
58+ export function resolveTimelineKeyframeTarget (
59+ pct : number ,
60+ keyframes : ReadonlyArray < TimelineCachedKeyframe > ,
61+ animations : ReadonlyArray < TimelineKeyframeTargetAnimation > ,
62+ ) : { animId : string ; tweenPct : number } | null {
63+ const kf = keyframes . find ( ( item ) => Math . abs ( item . percentage - pct ) < 0.2 ) ;
64+ const group = kf ?. propertyGroup ;
65+ const groupedCandidates = group
66+ ? animations . filter ( ( animation ) => animation . propertyGroup === group )
67+ : [ ] ;
68+ const groupedKeyframed = groupedCandidates . find ( ( animation ) => animation . keyframes ) ;
69+ const soleGroupedFlat =
70+ groupedCandidates . length === 1 && ! groupedCandidates [ 0 ] ?. keyframes
71+ ? groupedCandidates [ 0 ]
72+ : undefined ;
73+ const keyframed = animations . find ( ( animation ) => animation . keyframes ) ;
74+ const soleFlat = animations . length === 1 && ! animations [ 0 ] ?. keyframes ? animations [ 0 ] : undefined ;
75+ const animation = groupedKeyframed ?? soleGroupedFlat ?? keyframed ?? soleFlat ;
76+ return animation ? { animId : animation . id , tweenPct : kf ?. tweenPercentage ?? pct } : null ;
77+ }
78+
3979/**
4080 * Builds the timeline edit callback bag (move/resize/split/razor plus the
4181 * keyframe-diamond callbacks) provided to `<Timeline>` via TimelineEditProvider.
@@ -76,12 +116,7 @@ export function useTimelineEditCallbacks({
76116 // fallow-ignore-next-line complexity
77117 ( pct : number ) : { animId : string ; tweenPct : number } | null => {
78118 const cached = usePlayerStore . getState ( ) . keyframeCache . get ( domEditSelection ?. id ?? "" ) ;
79- const kf = cached ?. keyframes . find ( ( k ) => Math . abs ( k . percentage - pct ) < 0.2 ) ;
80- const group = kf ?. propertyGroup ;
81- const anim =
82- ( group ? selectedGsapAnimations . find ( ( a ) => a . propertyGroup === group ) : undefined ) ??
83- selectedGsapAnimations . find ( ( a ) => a . keyframes ) ;
84- return anim ? { animId : anim . id , tweenPct : kf ?. tweenPercentage ?? pct } : null ;
119+ return resolveTimelineKeyframeTarget ( pct , cached ?. keyframes ?? [ ] , selectedGsapAnimations ) ;
85120 } ,
86121 [ domEditSelection ?. id , selectedGsapAnimations ] ,
87122 ) ;
@@ -154,12 +189,19 @@ export function useTimelineEditCallbacks({
154189 decision . position != null &&
155190 decision . duration != null
156191 ) {
157- handleGsapResizeKeyframedTween (
158- target . animId ,
159- decision . position ,
160- decision . duration ,
161- decision . pctRemap ,
162- ) ;
192+ if ( anim . keyframes ) {
193+ handleGsapResizeKeyframedTween (
194+ target . animId ,
195+ decision . position ,
196+ decision . duration ,
197+ decision . pctRemap ,
198+ ) ;
199+ } else {
200+ handleGsapUpdateMeta ( target . animId , {
201+ position : decision . position ,
202+ duration : decision . duration ,
203+ } ) ;
204+ }
163205 }
164206 } ,
165207 onChangeKeyframeEase : ( _elId : string , _pct : number , ease : string ) => {
0 commit comments