@@ -198,6 +198,11 @@ function isVisibleGsapState(values: Record<string, string | number>): boolean {
198198 return false ;
199199}
200200
201+ function makesOverlayVisible ( win : GsapWindow ) : boolean {
202+ if ( win . method === "from" && isHiddenGsapState ( win . propertyValues ) ) return true ;
203+ return isVisibleGsapState ( win . propertyValues ) ;
204+ }
205+
201206function isSceneBoundaryExit ( win : GsapWindow ) : boolean {
202207 if ( win . end <= win . position ) return false ;
203208 if ( win . method !== "to" && win . method !== "fromTo" ) return false ;
@@ -310,11 +315,6 @@ function getSingleClassSelector(selector: string): string | null {
310315 return match ?. groups ?. name || null ;
311316}
312317
313- function getSingleIdSelector ( selector : string ) : string | null {
314- const match = selector . trim ( ) . match ( / ^ # (?< name > [ A - Z a - z 0 - 9 _ - ] + ) $ / ) ;
315- return match ?. groups ?. name || null ;
316- }
317-
318318function readStyleProperty ( style : string , property : string ) : string | null {
319319 const escapedProperty = property . replace ( / [ . * + ? ^ $ { } ( ) | [ \] \\ ] / g, "\\$&" ) ;
320320 const match = style . match ( new RegExp ( `(?:^|;)\\s*${ escapedProperty } \\s*:\\s*([^;]+)` , "i" ) ) ;
@@ -357,6 +357,39 @@ function styleLooksFullFrameOverlay(style: string): boolean {
357357 return coversFrame && styleHasOpaqueBackground ( style ) ;
358358}
359359
360+ function collectSimpleStyleRules ( styles : LintContext [ "styles" ] ) : Map < string , string > {
361+ const rules = new Map < string , string > ( ) ;
362+ for ( const style of styles ) {
363+ for ( const [ , selectorList , body ] of style . content . matchAll ( / ( [ ^ { } ] + ) \{ ( [ ^ } ] + ) \} / g) ) {
364+ if ( ! selectorList || ! body ) continue ;
365+ for ( const selector of selectorList . split ( "," ) ) {
366+ const token = selector . trim ( ) ;
367+ if ( ! / ^ [ # . ] [ A - Z a - z 0 - 9 _ - ] + $ / . test ( token ) ) continue ;
368+ rules . set ( token , `${ rules . get ( token ) || "" } ;${ body } ` ) ;
369+ }
370+ }
371+ }
372+ return rules ;
373+ }
374+
375+ function tagSimpleSelectors ( tag : OpenTag ) : string [ ] {
376+ const selectors : string [ ] = [ ] ;
377+ const id = readAttr ( tag . raw , "id" ) ;
378+ if ( id ) selectors . push ( `#${ id } ` ) ;
379+ const classes = readAttr ( tag . raw , "class" ) ?. split ( / \s + / ) . filter ( Boolean ) ?? [ ] ;
380+ for ( const className of classes ) selectors . push ( `.${ className } ` ) ;
381+ return selectors ;
382+ }
383+
384+ function combinedTagStyle ( tag : OpenTag , styleRules : Map < string , string > ) : string {
385+ const styles = [ readAttr ( tag . raw , "style" ) || "" ] ;
386+ for ( const selector of tagSimpleSelectors ( tag ) ) {
387+ const ruleStyle = styleRules . get ( selector ) ;
388+ if ( ruleStyle ) styles . push ( ruleStyle ) ;
389+ }
390+ return styles . filter ( Boolean ) . join ( ";" ) ;
391+ }
392+
360393// fallow-ignore-next-line complexity
361394function cssTransformToGsapProps ( cssTransform : string ) : string | null {
362395 const parts : string [ ] = [ ] ;
@@ -474,7 +507,7 @@ function extractStandaloneGsapTransformCalls(script: string): GsapTransformCall[
474507export const gsapRules : LintRule < LintContext > [ ] = [
475508 // overlapping_gsap_tweens + gsap_animates_clip_element + unscoped_gsap_selector
476509 // fallow-ignore-next-line complexity
477- async ( { source, tags, scripts, rootCompositionId } ) => {
510+ async ( { source, tags, scripts, styles , rootCompositionId } ) => {
478511 const findings : HyperframeLintFinding [ ] = [ ] ;
479512
480513 // Build clip element selector map
@@ -499,6 +532,8 @@ export const gsapRules: LintRule<LintContext>[] = [
499532
500533 const classUsage = countClassUsage ( tags ) ;
501534 const clipStartBoundariesByComposition = collectClipStartBoundariesByComposition ( source , tags ) ;
535+ const styleRules = collectSimpleStyleRules ( styles ) ;
536+ const reportedVisibleOverlayKeys = new Set < string > ( ) ;
502537
503538 for ( const script of scripts ) {
504539 const localTimelineCompId = readRegisteredTimelineCompositionId ( script . content ) ;
@@ -563,16 +598,18 @@ export const gsapRules: LintRule<LintContext>[] = [
563598
564599 // gsap_fullscreen_overlay_starts_visible
565600 for ( const tag of tags ) {
566- const id = readAttr ( tag . raw , "id" ) ;
567- if ( ! id ) continue ;
568- const inlineStyle = readAttr ( tag . raw , "style" ) ;
569- if ( ! inlineStyle || ! styleLooksFullFrameOverlay ( inlineStyle ) ) continue ;
570- if ( styleHasHiddenInitialState ( inlineStyle ) ) continue ;
601+ const selectors = tagSimpleSelectors ( tag ) ;
602+ if ( selectors . length === 0 ) continue ;
603+ const overlayKey = readAttr ( tag . raw , "id" ) || String ( tag . index ) ;
604+ if ( reportedVisibleOverlayKeys . has ( overlayKey ) ) continue ;
605+ const authoredStyle = combinedTagStyle ( tag , styleRules ) ;
606+ if ( ! authoredStyle || ! styleLooksFullFrameOverlay ( authoredStyle ) ) continue ;
607+ if ( styleHasHiddenInitialState ( authoredStyle ) ) continue ;
571608
572- const selector = `#${ id } ` ;
573609 const visibilityWindows = gsapWindows
574610 . filter ( ( win ) => {
575- if ( getSingleIdSelector ( win . targetSelector ) !== id ) return false ;
611+ const tokens = targetedSelectorTokens ( win . targetSelector ) ;
612+ if ( ! selectors . some ( ( selector ) => tokens . has ( selector ) ) ) return false ;
576613 return win . properties . some ( ( prop ) =>
577614 [ "opacity" , "autoAlpha" , "visibility" , "display" ] . includes ( prop ) ,
578615 ) ;
@@ -583,23 +620,28 @@ export const gsapRules: LintRule<LintContext>[] = [
583620 win . position <= SCENE_BOUNDARY_EPSILON_SECONDS && isHiddenGsapState ( win . propertyValues ) ,
584621 ) ;
585622 if ( startsHiddenAtZero ) continue ;
586- const firstVisible = visibilityWindows . find ( ( win ) =>
587- isVisibleGsapState ( win . propertyValues ) ,
588- ) ;
623+ const firstVisible = visibilityWindows . find ( ( win ) => makesOverlayVisible ( win ) ) ;
589624 if ( ! firstVisible ) continue ;
625+ const selector =
626+ selectors . find ( ( candidate ) =>
627+ targetedSelectorTokens ( firstVisible . targetSelector ) . has ( candidate ) ,
628+ ) ||
629+ selectors [ 0 ] ||
630+ tag . name ;
590631 const laterHidden = visibilityWindows . some (
591632 ( win ) => win . position >= firstVisible . position && isHiddenGsapState ( win . propertyValues ) ,
592633 ) ;
593- if ( ! laterHidden ) continue ;
634+ if ( firstVisible . method !== "from" && ! laterHidden ) continue ;
594635
636+ reportedVisibleOverlayKeys . add ( overlayKey ) ;
595637 findings . push ( {
596638 code : "gsap_fullscreen_overlay_starts_visible" ,
597639 severity : "error" ,
598640 message :
599641 `Full-frame overlay "${ selector } " starts visible before its first GSAP opacity tween at ` +
600642 `${ firstVisible . position . toFixed ( 2 ) } s. It will cover earlier render frames, often as a blank/white video.` ,
601643 selector,
602- elementId : id ,
644+ elementId : readAttr ( tag . raw , "id" ) || undefined ,
603645 fixHint :
604646 `Add \`opacity: 0\` to "${ selector } " in CSS/inline styles, or add ` +
605647 `\`tl.set("${ selector } ", { opacity: 0 }, 0)\` before the reveal tween.` ,
0 commit comments