@@ -4323,9 +4323,48 @@ export function initSandboxRuntimeModular(): void {
43234323 }
43244324 }
43254325 } ;
4326+ // GSAP reads the transform of an element it cannot lay out by moving it out and back before its next
4327+ // element, past the text between; a host the visibility pass hid by display is laid out, unseen and inert, meanwhile.
4328+ const layOutHiddenHosts = ( hosts : Element [ ] ) : ( ( ) => void ) => {
4329+ const hidden = hosts . filter ( ( host ) : host is StylableElement =>
4330+ displayBeforeHide . has ( host as StylableElement ) ,
4331+ ) ;
4332+ const opacities = hidden . map ( ( host ) => {
4333+ const before = displayBeforeHide . get ( host ) ! ;
4334+ if ( before . value ) host . style . setProperty ( "display" , before . value , before . priority ) ;
4335+ else host . style . removeProperty ( "display" ) ;
4336+ const opacity = {
4337+ value : host . style . getPropertyValue ( "opacity" ) ,
4338+ priority : host . style . getPropertyPriority ( "opacity" ) ,
4339+ inert : host . hasAttribute ( "inert" ) ,
4340+ } ;
4341+ host . style . setProperty ( "opacity" , "0" , "important" ) ;
4342+ host . setAttribute ( "inert" , "" ) ;
4343+ return opacity ;
4344+ } ) ;
4345+ return ( ) =>
4346+ hidden . forEach ( ( host , i ) => {
4347+ const ours =
4348+ host . style . getPropertyValue ( "opacity" ) === "0" &&
4349+ host . style . getPropertyPriority ( "opacity" ) === "important" ;
4350+ const { value, priority, inert } = opacities [ i ] ! ;
4351+ if ( ours && value ) host . style . setProperty ( "opacity" , value , priority ) ;
4352+ else if ( ours ) host . style . removeProperty ( "opacity" ) ;
4353+ if ( ! inert ) host . removeAttribute ( "inert" ) ;
4354+ if ( displayBeforeHide . has ( host ) ) host . style . display = "none" ;
4355+ } ) ;
4356+ } ;
4357+ const runSceneScripts = async ( hosts : Element [ ] , scripts : Element [ ] ) => {
4358+ const putHidesBack = layOutHiddenHosts ( hosts ) ;
4359+ try {
4360+ await runSceneScriptsLaidOut ( hosts , scripts ) ;
4361+ } finally {
4362+ putHidesBack ( ) ;
4363+ }
4364+ } ;
43264365 // Runs a scene's scripts, then records what they started after returning: a script resumed by a font
43274366 // wait builds there, past the recorder that wraps it. With several scenes, a late animation's scene is unknown.
4328- const runSceneScripts = async ( hosts : Element [ ] , scripts : Element [ ] ) => {
4367+ const runSceneScriptsLaidOut = async ( hosts : Element [ ] , scripts : Element [ ] ) => {
43294368 const globalTimeline = window . gsap ?. globalTimeline ;
43304369 const before = new Set < unknown > ( globalTimeline ?. getChildren ?.( false , true , true ) ) ;
43314370 await runScriptsAfterFonts ( scripts ) ;
0 commit comments