33 * SceneViewport until the user opens a scene.
44 */
55
6- import React , { useEffect , useMemo , useState } from 'react' ;
6+ import React , { useEffect , useLayoutEffect , useMemo , useRef , useState } from 'react' ;
77import { useI18n } from '@/infrastructure/i18n' ;
88import { isReducedMotionPreferred } from '@/shared/utils/motionPreference' ;
99import { OpenBitFunMark } from '@openbitfun/ui/brand' ;
@@ -16,10 +16,22 @@ const DELETE_MS = 55;
1616const PHRASE_HOLD_MS = 2200 ;
1717const PHRASE_GAP_MS = 450 ;
1818const YOUR_WORD_INDEX = 2 ;
19+ const COMPACT_MAX_WIDTH = 560 ;
20+ const TINY_MAX_WIDTH = 400 ;
21+
22+ type WelcomeDensity = 'regular' | 'compact' | 'tiny' ;
23+
24+ function densityForWidth ( width : number ) : WelcomeDensity {
25+ if ( width <= TINY_MAX_WIDTH ) return 'tiny' ;
26+ if ( width <= COMPACT_MAX_WIDTH ) return 'compact' ;
27+ return 'regular' ;
28+ }
1929
2030const WelcomeScene : React . FC = ( ) => {
2131 const { t } = useI18n ( 'common' ) ;
32+ const sceneRef = useRef < HTMLElement > ( null ) ;
2233 const [ text , setText ] = useState ( '' ) ;
34+ const [ density , setDensity ] = useState < WelcomeDensity > ( 'regular' ) ;
2335 const [ reducedMotion , setReducedMotion ] = useState ( isReducedMotionPreferred ) ;
2436 const [ startupEntry ] = useState ( isStartupOverlayPresent ) ;
2537 const [ startupPending , setStartupPending ] = useState ( startupEntry ) ;
@@ -44,6 +56,30 @@ const WelcomeScene: React.FC = () => {
4456 [ impossible , dreams , your , suffix , think , ideas , create , explore ] ,
4557 ) ;
4658
59+ // The type scale follows the scene width through a plain attribute instead of
60+ // CSS container queries. WebKit resolves container queries inside layout and
61+ // can keep stale inline positions for the `white-space: pre` brand text when
62+ // the scene first lays out narrow (startup, window resize) and then widens:
63+ // the glyphs repaint at the larger size while the tagline stays where the
64+ // smaller text ended, so the two lines overlap. An attribute change goes
65+ // through ordinary style invalidation before layout, which re-measures text.
66+ useLayoutEffect ( ( ) => {
67+ const scene = sceneRef . current ;
68+ if ( ! scene ) return ;
69+ const apply = ( width : number ) => {
70+ // A hidden or detached scene reports zero; keep the last real tier.
71+ if ( width > 0 ) setDensity ( densityForWidth ( width ) ) ;
72+ } ;
73+ apply ( scene . getBoundingClientRect ( ) . width ) ;
74+ if ( typeof ResizeObserver === 'undefined' ) return ;
75+ const observer = new ResizeObserver ( entries => {
76+ const entry = entries [ entries . length - 1 ] ;
77+ if ( entry ) apply ( entry . contentRect . width ) ;
78+ } ) ;
79+ observer . observe ( scene ) ;
80+ return ( ) => observer . disconnect ( ) ;
81+ } , [ ] ) ;
82+
4783 useEffect ( ( ) => {
4884 if ( ! startupPending ) return ;
4985 const handleHandoff = ( ) => setStartupPending ( false ) ;
@@ -107,10 +143,12 @@ const WelcomeScene: React.FC = () => {
107143
108144 return (
109145 < section
146+ ref = { sceneRef }
110147 className = "welcome-scene"
111148 data-testid = "welcome-scene"
112149 data-openbitfun-scene = "welcome"
113150 data-openbitfun-part = "root"
151+ data-density = { density }
114152 data-startup-entry = { startupEntry ? '' : undefined }
115153 data-startup-pending = { startupPending ? '' : undefined }
116154 aria-labelledby = "welcome-scene-title"
0 commit comments