@@ -474,6 +474,106 @@ describe("studio manual edits", () => {
474474 expect ( frames ) . toHaveLength ( 0 ) ;
475475 } ) ;
476476
477+ it ( "does not reapply every frame while the player is paused over unpaused scene timelines" , ( ) => {
478+ const window = new Window ( ) ;
479+ const frames : FrameRequestCallback [ ] = [ ] ;
480+ let playing = false ;
481+ const previewWindow = window as unknown as Parameters <
482+ typeof installStudioManualEditSeekReapply
483+ > [ 0 ] & {
484+ __player : Record < string , unknown > ;
485+ __timelines : Record < string , Record < string , unknown > > ;
486+ requestAnimationFrame : ( callback : FrameRequestCallback ) => number ;
487+ } ;
488+ previewWindow . requestAnimationFrame = ( callback : FrameRequestCallback ) => {
489+ frames . push ( callback ) ;
490+ return frames . length ;
491+ } ;
492+ previewWindow . __player = {
493+ play : ( ) => {
494+ playing = true ;
495+ } ,
496+ isPlaying : ( ) => playing ,
497+ } ;
498+ // A GSAP child of a paused master: not paused itself, inactive, time left.
499+ const master = { paused : ( ) => true } ;
500+ previewWindow . __timelines = {
501+ scene0 : {
502+ parent : master ,
503+ play : ( ) => { } ,
504+ paused : ( ) => false ,
505+ isActive : ( ) => false ,
506+ time : ( ) => 0 ,
507+ duration : ( ) => 5 ,
508+ } ,
509+ } ;
510+
511+ expect ( installStudioManualEditSeekReapply ( previewWindow , ( ) => { } ) ) . toBe ( true ) ;
512+ expect ( frames ) . toHaveLength ( 0 ) ;
513+
514+ ( previewWindow . __player . play as ( ) => void ) ( ) ;
515+ expect ( frames ) . toHaveLength ( 1 ) ;
516+ playing = false ;
517+ frames . shift ( ) ?.( 16 ) ;
518+ expect ( frames ) . toHaveLength ( 0 ) ;
519+ } ) ;
520+
521+ it ( "tolerates a timeline whose parent chain loops" , ( ) => {
522+ const window = new Window ( ) ;
523+ const previewWindow = window as unknown as Parameters <
524+ typeof installStudioManualEditSeekReapply
525+ > [ 0 ] & {
526+ __timelines : Record < string , Record < string , unknown > > ;
527+ requestAnimationFrame : ( callback : FrameRequestCallback ) => number ;
528+ } ;
529+ previewWindow . requestAnimationFrame = ( ) => 1 ;
530+ const loop : Record < string , unknown > = { paused : ( ) => false } ;
531+ loop . parent = loop ;
532+ previewWindow . __timelines = {
533+ scene0 : {
534+ parent : loop ,
535+ play : ( ) => { } ,
536+ paused : ( ) => false ,
537+ time : ( ) => 0 ,
538+ duration : ( ) => 5 ,
539+ } ,
540+ } ;
541+
542+ expect ( ( ) => installStudioManualEditSeekReapply ( previewWindow , ( ) => { } ) ) . not . toThrow ( ) ;
543+ } ) ;
544+
545+ it ( "keeps reapplying while Studio drives a timeline directly and the player reads idle" , ( ) => {
546+ const window = new Window ( ) ;
547+ const frames : FrameRequestCallback [ ] = [ ] ;
548+ let paused = true ;
549+ const previewWindow = window as unknown as Parameters <
550+ typeof installStudioManualEditSeekReapply
551+ > [ 0 ] & {
552+ __player : Record < string , unknown > ;
553+ __timeline : Record < string , unknown > ;
554+ requestAnimationFrame : ( callback : FrameRequestCallback ) => number ;
555+ } ;
556+ previewWindow . requestAnimationFrame = ( callback : FrameRequestCallback ) => {
557+ frames . push ( callback ) ;
558+ return frames . length ;
559+ } ;
560+ previewWindow . __player = { play : ( ) => { } , isPlaying : ( ) => false } ;
561+ previewWindow . __timeline = {
562+ play : ( ) => {
563+ paused = false ;
564+ } ,
565+ paused : ( ) => paused ,
566+ isActive : ( ) => ! paused ,
567+ time : ( ) => 1 ,
568+ duration : ( ) => 5 ,
569+ } ;
570+
571+ expect ( installStudioManualEditSeekReapply ( previewWindow , ( ) => { } ) ) . toBe ( true ) ;
572+ ( previewWindow . __timeline . play as ( ) => void ) ( ) ;
573+ frames . shift ( ) ?.( 16 ) ;
574+ expect ( frames ) . toHaveLength ( 1 ) ;
575+ } ) ;
576+
477577 it ( "stops playback reapply after an unpaused timeline has completed" , ( ) => {
478578 const window = new Window ( ) ;
479579 const frames : FrameRequestCallback [ ] = [ ] ;
0 commit comments