@@ -50,38 +50,26 @@ const placedAlone = (animation: GsapAnimation) =>
5050const lengthOf = ( animation : GsapAnimation ) =>
5151 animation . method === "set" ? 0 : animation . durationUnresolved ? undefined : animation . duration ;
5252
53- interface ReadScript {
54- shape : string | null ;
55- animations ?: GsapAnimation [ ] ;
56- }
57-
58- /** The last two scripts read, by text: a repeat drag starts from the script the last one saved. */
59- const readScripts = new Map < string , ReadScript > ( ) ;
53+ /** The last two script shapes, by text: a repeat drag starts from the script the last one saved. */
54+ const shapes = new Map < string , string | null > ( ) ;
6055
61- function readScript ( code : string ) : ReadScript {
62- let read = readScripts . get ( code ) ;
63- if ( ! read ) {
64- read = { shape : scriptShape ( code , true ) } ;
65- if ( readScripts . size >= 2 ) readScripts . delete ( readScripts . keys ( ) . next ( ) . value ! ) ;
66- readScripts . set ( code , read ) ;
67- }
68- return read ;
56+ function shapeOf ( code : string ) : string | null {
57+ const shape = shapes . has ( code ) ? ( shapes . get ( code ) as string | null ) : scriptShape ( code , true ) ;
58+ shapes . delete ( code ) ;
59+ shapes . set ( code , shape ) ;
60+ if ( shapes . size > 2 ) shapes . delete ( shapes . keys ( ) . next ( ) . value ! ) ;
61+ return shape ;
6962}
7063
71- const timedAnimations = ( code : string ) : GsapAnimation [ ] => {
72- const read = readScript ( code ) ;
73- return ( read . animations ??= parseGsapScriptAcorn ( code ) . animations . filter ( onTimeline ) ) ;
74- } ;
75-
7664/** Decides, from the two scripts alone, whether a saved edit moved tweens and nothing else. */
7765export function planLiveRetime ( before : string , after : string ) : LiveRetimePlan {
7866 // The preview runs the script re-printed by the bundler; a timing edit rewrites numbers only.
79- const { shape } = readScript ( before ) ;
80- if ( shape === null || shape !== readScript ( after ) . shape ) return RERUN ;
67+ const shape = shapeOf ( before ) ;
68+ if ( shape === null || shape !== shapeOf ( after ) ) return RERUN ;
8169 const keys = timelineKeys ( after ) ;
8270 if ( keys . length !== 1 || timelineKeys ( before ) . join ( ) !== keys . join ( ) ) return RERUN ;
83- const was = timedAnimations ( before ) ;
84- const now = timedAnimations ( after ) ;
71+ const was = parseGsapScriptAcorn ( before ) . animations . filter ( onTimeline ) ;
72+ const now = parseGsapScriptAcorn ( after ) . animations . filter ( onTimeline ) ;
8573 if ( was . length !== now . length ) return RERUN ;
8674 const tweens : TweenTiming [ ] = [ ] ;
8775 for ( const [ index , next ] of now . entries ( ) ) {
0 commit comments