diff --git a/src/web-ui/src/app/scenes/welcome/WelcomeScene.scss b/src/web-ui/src/app/scenes/welcome/WelcomeScene.scss index 193e4daa7f..c05d18d203 100644 --- a/src/web-ui/src/app/scenes/welcome/WelcomeScene.scss +++ b/src/web-ui/src/app/scenes/welcome/WelcomeScene.scss @@ -11,7 +11,6 @@ min-width: 0; min-height: 0; overflow: hidden; - container-type: inline-size; background: var(--openbitfun-color-surface-scene); &__content { @@ -133,32 +132,35 @@ 50% { opacity: 0; } } -@container (max-width: 560px) { - .welcome-scene { - &__content { +// Width tiers come from `data-density` (set by WelcomeScene from a +// ResizeObserver), not container queries; see the component for why. +.welcome-scene { + &[data-density='compact'], + &[data-density='tiny'] { + .welcome-scene__content { padding-inline: var(--openbitfun-space-4); } + } - &__brand, - &__tagline { + &[data-density='compact'] { + .welcome-scene__brand, + .welcome-scene__tagline { font-size: var(--openbitfun-type-heading-display-font-size); } - &__logo { + .welcome-scene__logo { width: 48px; height: 48px; } } -} -@container (max-width: 400px) { - .welcome-scene { - &__brand, - &__tagline { + &[data-density='tiny'] { + .welcome-scene__brand, + .welcome-scene__tagline { font-size: var(--openbitfun-type-flow-title-font-size); } - &__logo { + .welcome-scene__logo { width: 36px; height: 36px; } diff --git a/src/web-ui/src/app/scenes/welcome/WelcomeScene.test.tsx b/src/web-ui/src/app/scenes/welcome/WelcomeScene.test.tsx index a20e33489a..feffd7e10a 100644 --- a/src/web-ui/src/app/scenes/welcome/WelcomeScene.test.tsx +++ b/src/web-ui/src/app/scenes/welcome/WelcomeScene.test.tsx @@ -95,4 +95,32 @@ describe('welcome startup timing', () => { await act(async () => { await vi.advanceTimersByTimeAsync(5000); }); expect(phrase()).toBe(initial); }); + + it('switches the type scale through a width attribute, not container queries', () => { + let notify: ((entries: Array<{ contentRect: { width: number } }>) => void) | undefined; + const disconnect = vi.fn(); + vi.stubGlobal('ResizeObserver', class { + constructor(callback: typeof notify) { notify = callback; } + observe() {} + disconnect = disconnect; + }); + act(() => root.render()); + const scene = container.querySelector('section')!; + // jsdom lays out nothing, so a zero width must keep the regular tier. + expect(scene.dataset.density).toBe('regular'); + + // Startup or a resize can lay the scene out narrow before it widens. + act(() => notify!([{ contentRect: { width: 360 } }])); + expect(scene.dataset.density).toBe('tiny'); + act(() => notify!([{ contentRect: { width: 520 } }])); + expect(scene.dataset.density).toBe('compact'); + act(() => notify!([{ contentRect: { width: 0 } }])); + expect(scene.dataset.density).toBe('compact'); + act(() => notify!([{ contentRect: { width: 1200 } }])); + expect(scene.dataset.density).toBe('regular'); + + act(() => root.unmount()); + expect(disconnect).toHaveBeenCalled(); + root = createRoot(container); + }); }); diff --git a/src/web-ui/src/app/scenes/welcome/WelcomeScene.tsx b/src/web-ui/src/app/scenes/welcome/WelcomeScene.tsx index d794684ba9..d35ef12c32 100644 --- a/src/web-ui/src/app/scenes/welcome/WelcomeScene.tsx +++ b/src/web-ui/src/app/scenes/welcome/WelcomeScene.tsx @@ -3,7 +3,7 @@ * SceneViewport until the user opens a scene. */ -import React, { useEffect, useMemo, useState } from 'react'; +import React, { useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react'; import { useI18n } from '@/infrastructure/i18n'; import { isReducedMotionPreferred } from '@/shared/utils/motionPreference'; import { OpenBitFunMark } from '@openbitfun/ui/brand'; @@ -16,10 +16,22 @@ const DELETE_MS = 55; const PHRASE_HOLD_MS = 2200; const PHRASE_GAP_MS = 450; const YOUR_WORD_INDEX = 2; +const COMPACT_MAX_WIDTH = 560; +const TINY_MAX_WIDTH = 400; + +type WelcomeDensity = 'regular' | 'compact' | 'tiny'; + +function densityForWidth(width: number): WelcomeDensity { + if (width <= TINY_MAX_WIDTH) return 'tiny'; + if (width <= COMPACT_MAX_WIDTH) return 'compact'; + return 'regular'; +} const WelcomeScene: React.FC = () => { const { t } = useI18n('common'); + const sceneRef = useRef(null); const [text, setText] = useState(''); + const [density, setDensity] = useState('regular'); const [reducedMotion, setReducedMotion] = useState(isReducedMotionPreferred); const [startupEntry] = useState(isStartupOverlayPresent); const [startupPending, setStartupPending] = useState(startupEntry); @@ -44,6 +56,30 @@ const WelcomeScene: React.FC = () => { [impossible, dreams, your, suffix, think, ideas, create, explore], ); + // The type scale follows the scene width through a plain attribute instead of + // CSS container queries. WebKit resolves container queries inside layout and + // can keep stale inline positions for the `white-space: pre` brand text when + // the scene first lays out narrow (startup, window resize) and then widens: + // the glyphs repaint at the larger size while the tagline stays where the + // smaller text ended, so the two lines overlap. An attribute change goes + // through ordinary style invalidation before layout, which re-measures text. + useLayoutEffect(() => { + const scene = sceneRef.current; + if (!scene) return; + const apply = (width: number) => { + // A hidden or detached scene reports zero; keep the last real tier. + if (width > 0) setDensity(densityForWidth(width)); + }; + apply(scene.getBoundingClientRect().width); + if (typeof ResizeObserver === 'undefined') return; + const observer = new ResizeObserver(entries => { + const entry = entries[entries.length - 1]; + if (entry) apply(entry.contentRect.width); + }); + observer.observe(scene); + return () => observer.disconnect(); + }, []); + useEffect(() => { if (!startupPending) return; const handleHandoff = () => setStartupPending(false); @@ -107,10 +143,12 @@ const WelcomeScene: React.FC = () => { return (