@@ -60,3 +60,157 @@ describe("gsap adapter on a step", () => {
6060 expect ( gsap . getProperty ( box , "x" ) ) . toBe ( 10 ) ;
6161 } ) ;
6262} ) ;
63+
64+ describe ( "gsap adapter at a tween's start" , ( ) => {
65+ // An edit at 2 s turns the later tween into keyframes; its first keyframe must win over the from() end.
66+ it . each ( [ 0 , 1 , 2 , 2.5 , 3 ] ) (
67+ "shows the tween that starts at the seek time, seeking from %s s" ,
68+ ( from ) => {
69+ const box = document . body . appendChild ( document . createElement ( "div" ) ) ;
70+ const timeline = gsap . timeline ( { paused : true } ) ;
71+ timeline . from ( box , { x : - 60 , duration : 2 , ease : "none" } , 0 ) ;
72+ timeline . to ( box , { keyframes : { "0%" : { x : 5 } , "100%" : { x : 60 } } , duration : 1 } , 2 ) ;
73+ timeline . totalTime ( from , true ) ;
74+ createGsapAdapter ( { getTimeline : ( ) => timeline as unknown as RuntimeTimelineLike } ) . seek ( {
75+ time : 2 ,
76+ } ) ;
77+ expect ( gsap . getProperty ( box , "x" ) ) . toBe ( 5 ) ;
78+ } ,
79+ ) ;
80+
81+ it ( "leaves a tween that starts later alone after a seek past the end" , ( ) => {
82+ const box = document . body . appendChild ( document . createElement ( "div" ) ) ;
83+ const timeline = gsap . timeline ( { paused : true } ) ;
84+ timeline . to ( box , { x : - 400 , duration : 0.4 } , 4.8 ) ;
85+ timeline . to ( box , { x : 0 , duration : 0.4 } , 16 ) ;
86+ const adapter = createGsapAdapter ( {
87+ getTimeline : ( ) => timeline as unknown as RuntimeTimelineLike ,
88+ } ) ;
89+ for ( const time of [ 20 , 0 , 4 ] ) adapter . seek ( { time } ) ;
90+ expect ( gsap . getProperty ( box , "x" ) ) . toBe ( 0 ) ;
91+ } ) ;
92+
93+ it . each ( [
94+ { order : "keyframes, then a set" , x : 42 } ,
95+ { order : "a set, then keyframes" , x : 5 } ,
96+ ] ) ( "keeps the authored order of $order at the seek time" , ( { order, x } ) => {
97+ const box = document . body . appendChild ( document . createElement ( "div" ) ) ;
98+ const timeline = gsap . timeline ( { paused : true } ) ;
99+ timeline . from ( box , { x : - 60 , duration : 2 , ease : "none" } , 0 ) ;
100+ const keyframes = ( ) =>
101+ timeline . to ( box , { keyframes : { "0%" : { x : 5 } , "100%" : { x : 60 } } , duration : 1 } , 2 ) ;
102+ const set = ( ) => timeline . set ( box , { x : 42 } , 2 ) ;
103+ if ( order . startsWith ( "keyframes" ) ) {
104+ keyframes ( ) ;
105+ set ( ) ;
106+ } else {
107+ set ( ) ;
108+ keyframes ( ) ;
109+ }
110+ const adapter = createGsapAdapter ( {
111+ getTimeline : ( ) => timeline as unknown as RuntimeTimelineLike ,
112+ } ) ;
113+ for ( const from of [ 0 , 1 , 2 , 2.5 , 3 ] ) {
114+ timeline . totalTime ( from , true ) ;
115+ adapter . seek ( { time : 2 } ) ;
116+ expect ( gsap . getProperty ( box , "x" ) ) . toBe ( x ) ;
117+ }
118+ } ) ;
119+
120+ it ( "shows a keyframed tween's start inside a nested timeline, seeking onto it twice" , ( ) => {
121+ const box = document . body . appendChild ( document . createElement ( "div" ) ) ;
122+ const timeline = gsap . timeline ( { paused : true } ) ;
123+ const scene = gsap . timeline ( ) ;
124+ scene . from ( box , { x : - 60 , duration : 2 , ease : "none" } , 0 ) ;
125+ scene . to ( box , { keyframes : { "0%" : { x : 5 } , "100%" : { x : 60 } } , duration : 1 } , 2 ) ;
126+ timeline . add ( scene , 0.5 ) ;
127+ const adapter = createGsapAdapter ( {
128+ getTimeline : ( ) => timeline as unknown as RuntimeTimelineLike ,
129+ } ) ;
130+ adapter . seek ( { time : 2.5 } ) ;
131+ adapter . seek ( { time : 2.5 } ) ;
132+ expect ( gsap . getProperty ( box , "x" ) ) . toBe ( 5 ) ;
133+ } ) ;
134+
135+ it ( "does not start a tween that begins just after the seek time" , ( ) => {
136+ const box = document . body . appendChild ( document . createElement ( "div" ) ) ;
137+ const timeline = gsap . timeline ( { paused : true } ) ;
138+ timeline . to ( box , { x : 100 , duration : 10 , ease : "none" } , 0 ) ;
139+ timeline . to ( box , { x : 200 , duration : 1 , ease : "none" , overwrite : "auto" } , 2.0005 ) ;
140+ const adapter = createGsapAdapter ( {
141+ getTimeline : ( ) => timeline as unknown as RuntimeTimelineLike ,
142+ } ) ;
143+ adapter . seek ( { time : 2 } ) ;
144+ adapter . seek ( { time : 1 } ) ;
145+ expect ( gsap . getProperty ( box , "x" ) ) . toBe ( 10 ) ;
146+ } ) ;
147+
148+ it ( "keeps a relative repeatRefresh tween on its iteration at a repeat boundary" , ( ) => {
149+ const box = document . body . appendChild ( document . createElement ( "div" ) ) ;
150+ const timeline = gsap . timeline ( { paused : true } ) ;
151+ timeline . to ( box , { x : "+=10" , duration : 1 , repeat : 1 , repeatRefresh : true , ease : "none" } , 0 ) ;
152+ const adapter = createGsapAdapter ( {
153+ getTimeline : ( ) => timeline as unknown as RuntimeTimelineLike ,
154+ } ) ;
155+ adapter . seek ( { time : 1 } ) ;
156+ adapter . seek ( { time : 1 } ) ;
157+ expect ( gsap . getProperty ( box , "x" ) ) . toBe ( 10 ) ;
158+ } ) ;
159+
160+ it . each ( [
161+ {
162+ shape : "a stagger whose next target starts 0.1 us later with overwrite auto" ,
163+ build : ( timeline : gsap . core . Timeline , o : { x : number } ) => {
164+ timeline . to ( o , { x : 100 , duration : 10 , ease : "none" } , 0 ) ;
165+ timeline . to ( [ { x : 0 } , o ] , { x : 200 , duration : 1 , stagger : 1e-7 , overwrite : "auto" } , 2 ) ;
166+ } ,
167+ seeks : [ 2 , 1 ] ,
168+ x : 10 ,
169+ } ,
170+ {
171+ shape : "a reversed keyframed tween" ,
172+ build : ( timeline : gsap . core . Timeline , o : { x : number } ) => {
173+ const tween = gsap . to ( o , { keyframes : { "0%" : { x : 5 } , "100%" : { x : 60 } } , duration : 1 } ) ;
174+ timeline . add ( tween , 1 ) ;
175+ tween . timeScale ( - 1 ) ;
176+ } ,
177+ seeks : [ 1 ] ,
178+ x : 60 ,
179+ } ,
180+ {
181+ shape : "a paused keyframed tween" ,
182+ build : ( timeline : gsap . core . Timeline , o : { x : number } ) => {
183+ const tween = gsap . to ( o , {
184+ keyframes : { "0%" : { x : 5 } , "100%" : { x : 60 } } ,
185+ duration : 1 ,
186+ ease : "none" ,
187+ } ) ;
188+ timeline . add ( tween , 1 ) ;
189+ tween . totalTime ( 0.5 ) . pause ( ) ;
190+ } ,
191+ seeks : [ 1 , 1 ] ,
192+ x : 32.5 ,
193+ } ,
194+ {
195+ shape : "a 0.4 us repeatRefresh keyframed tween" ,
196+ build : ( timeline : gsap . core . Timeline , o : { x : number } ) => {
197+ const keyframes = [
198+ { x : "+=10" , duration : 2e-7 } ,
199+ { x : "+=10" , duration : 2e-7 } ,
200+ ] ;
201+ timeline . to ( o , { keyframes, repeat : 2 , repeatRefresh : true , ease : "none" } , 2 ) ;
202+ } ,
203+ seeks : [ 2 , 2 ] ,
204+ x : 0 ,
205+ } ,
206+ ] ) ( "leaves $shape as GSAP renders it at its start" , ( { build, seeks, x } ) => {
207+ const o = { x : 0 } ;
208+ const timeline = gsap . timeline ( { paused : true } ) ;
209+ build ( timeline , o ) ;
210+ const adapter = createGsapAdapter ( {
211+ getTimeline : ( ) => timeline as unknown as RuntimeTimelineLike ,
212+ } ) ;
213+ for ( const time of seeks ) adapter . seek ( { time } ) ;
214+ expect ( o . x ) . toBeCloseTo ( x , 6 ) ;
215+ } ) ;
216+ } ) ;
0 commit comments