Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions src/web-ui/src/app/scenes/welcome/WelcomeScene.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
min-width: 0;
min-height: 0;
overflow: hidden;
container-type: inline-size;
background: var(--openbitfun-color-surface-scene);

&__content {
Expand Down Expand Up @@ -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;
}
Expand Down
28 changes: 28 additions & 0 deletions src/web-ui/src/app/scenes/welcome/WelcomeScene.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(<WelcomeScene />));
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);
});
});
40 changes: 39 additions & 1 deletion src/web-ui/src/app/scenes/welcome/WelcomeScene.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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<HTMLElement>(null);
const [text, setText] = useState('');
const [density, setDensity] = useState<WelcomeDensity>('regular');
const [reducedMotion, setReducedMotion] = useState(isReducedMotionPreferred);
const [startupEntry] = useState(isStartupOverlayPresent);
const [startupPending, setStartupPending] = useState(startupEntry);
Expand All @@ -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);
Expand Down Expand Up @@ -107,10 +143,12 @@ const WelcomeScene: React.FC = () => {

return (
<section
ref={sceneRef}
className="welcome-scene"
data-testid="welcome-scene"
data-openbitfun-scene="welcome"
data-openbitfun-part="root"
data-density={density}
data-startup-entry={startupEntry ? '' : undefined}
data-startup-pending={startupPending ? '' : undefined}
aria-labelledby="welcome-scene-title"
Expand Down
Loading