diff --git a/src/app/components/logo/logoMark.css.ts b/src/app/components/logo/logoMark.css.ts new file mode 100644 index 00000000..4c967088 --- /dev/null +++ b/src/app/components/logo/logoMark.css.ts @@ -0,0 +1,9 @@ +import { globalStyle, style } from '@vanilla-extract/css'; + +/** + * The Ratatoskr mark is white on transparent (Meta's matte). On any light theme (they all carry `prism-light`) a class + * of this name darkens it to the dark ink; put it on every that shows the mark on a themed surface. The favicon and + * notification icons are files the browser draws and cannot take it. + */ +export const LogoMark = style({}); +globalStyle(`body.prism-light .${LogoMark}`, { filter: 'brightness(0.18)' }); diff --git a/src/app/features/scene/SkyStateControl.tsx b/src/app/features/scene/SkyStateControl.tsx index 4e67bd81..b664dc07 100644 --- a/src/app/features/scene/SkyStateControl.tsx +++ b/src/app/features/scene/SkyStateControl.tsx @@ -39,7 +39,8 @@ const LABEL: Record = { export function SkyStateControl() { const state = useSkyState(); const [cords, setCords] = useState(); - const configuredStyle = useClientConfig().backgroundScene?.style; + const backgroundScene = useClientConfig().backgroundScene; + const configuredStyle = backgroundScene?.style; const sceneStyle: ServedSceneStyle = getSceneStyleOverride() ?? (configuredStyle === 'terrain' ? 'terrain' : 'ridge'); @@ -85,32 +86,36 @@ export function SkyStateControl() { ))} - - Background - - {SERVED_SCENE_STYLES.map((st) => ( - { - setCords(undefined); - if (st !== sceneStyle) setSceneStyle(st); - }} - after={sceneStyle === st ? : undefined} - > - - {STYLE_LABEL[st]} - - - ))} + {backgroundScene && ( + <> + + Background + + {SERVED_SCENE_STYLES.map((st) => ( + { + setCords(undefined); + if (st !== sceneStyle) setSceneStyle(st); + }} + after={sceneStyle === st ? : undefined} + > + + {STYLE_LABEL[st]} + + + ))} + + )} diff --git a/src/app/features/scene/ridge/Ridge.ts b/src/app/features/scene/ridge/Ridge.ts index d2312aaf..69a88864 100644 --- a/src/app/features/scene/ridge/Ridge.ts +++ b/src/app/features/scene/ridge/Ridge.ts @@ -180,7 +180,7 @@ export function createRidgeScene(opts: RidgeOptions): Scene | null { built = undefined; }; - /** True while the host has no area to paint (a scene started in a hidden or collapsed container). */ + /** True while there is nothing to paint on: the canvas has no client size and the window itself is 0 x 0 (`viewSize` falls back to the window). */ const hasNoArea = () => { const { w, h, scale } = viewSize(); const size = layerSize(w, h, scale); diff --git a/src/app/features/scene/sceneButtons.css.ts b/src/app/features/scene/sceneButtons.css.ts index 301d5671..5c96e71b 100644 --- a/src/app/features/scene/sceneButtons.css.ts +++ b/src/app/features/scene/sceneButtons.css.ts @@ -9,7 +9,6 @@ globalStyle(controls, { backgroundColor: 'transparent', boxShadow: 'none', border: 'none', - outline: 'none', color: 'inherit', }); globalStyle( @@ -21,6 +20,11 @@ globalStyle( ].join(', '), { backgroundColor: 'color-mix(in srgb, currentColor 12%, transparent)' } ); +// A visible keyboard focus ring in the control's own ink, on top of the hover wash. +globalStyle([`${scene} .epr39zd:focus-visible`, `${scene} ._1bv8u1w6:focus-visible`].join(', '), { + outline: '2px solid currentColor', + outlineOffset: '2px', +}); globalStyle(`${scene} .epr39zd`, { fontWeight: 700, textDecoration: 'underline', diff --git a/src/app/features/scene/skyTheme.test.ts b/src/app/features/scene/skyTheme.test.ts index 80bc0423..18435ae6 100644 --- a/src/app/features/scene/skyTheme.test.ts +++ b/src/app/features/scene/skyTheme.test.ts @@ -1,4 +1,4 @@ -import { describe, expect, it } from 'vitest'; +import { describe, expect, it, vi } from 'vitest'; import { atStandardTime } from './standardTime.testkit'; import { baked } from '../../../sky/baked'; import { AA, NIGHT_SKY_LIGHTEST, contrast, luminance } from '../../../sky/skyTokens.js'; @@ -9,10 +9,15 @@ import { MembersDrawer } from '../room/MembersDrawer.css'; import { RoomViewTyping } from '../room/RoomViewTyping.css'; import { FOOTER_TINT, SKY_PLATE_FALLBACK } from './skyPlate'; import { SkyPlate, plateRegions } from './skyPlate.css'; -import { getResolvedSkyState, setSkyClock, skyBackdrop } from './skyState'; +import { + getResolvedSkyState, + setSkyClock, + skyBackdrop, + subscribe as subscribeSky, +} from './skyState'; import type { SkyBackdrop } from './skyState'; import type { FixedSkyState } from './skyBand'; -import { skyThemeId } from './skyTheme'; +import { sceneThemeId, skyThemeId } from './skyTheme'; const SKY = { 'midnight-sky': baked.midnight, 'noonday-sky': baked.noonday } as const; const fixed = (['day', 'dusk', 'night'] as const).flatMap((s) => { @@ -39,17 +44,47 @@ describe('skyThemeId', () => { expect(skyThemeId('night')).toBe('midnight-sky'); }); - it('picks the theme of the state auto resolves to, at any hour', () => { + it('picks none for auto, at any hour: auto never overrides a signed-in theme', () => { [0, 6, 12, 18, 23].forEach((h) => { setSkyClock(() => atStandardTime(h, 10)); - const id = skyThemeId('auto'); - expect(id).toBeDefined(); - expect(id).toBe(skyThemeId(getResolvedSkyState())); + expect(skyThemeId('auto')).toBeUndefined(); }); - setSkyClock(() => atStandardTime(12)); - expect(skyThemeId('auto')).toBe('noonday-sky'); - setSkyClock(() => atStandardTime(0)); - expect(skyThemeId('auto')).toBe('midnight-sky'); + setSkyClock(); + }); + + describe('sceneThemeId, the theme the page wears', () => { + it('a fixed state always picks its theme, whatever the scene or the person chose', () => { + [true, false].forEach((scene) => + [true, false].forEach((chose) => { + expect(sceneThemeId('day', 'night', scene, chose)).toBe('noonday-sky'); + expect(sceneThemeId('night', 'day', scene, chose)).toBe('midnight-sky'); + }) + ); + }); + + it('auto follows the resolved sky only while a scene is on and the person chose no theme', () => { + expect(sceneThemeId('auto', 'day', true, false)).toBe('noonday-sky'); + expect(sceneThemeId('auto', 'dusk', true, false)).toBe('noonday-sky'); + expect(sceneThemeId('auto', 'night', true, false)).toBe('midnight-sky'); + expect(sceneThemeId('auto', 'day', false, false)).toBeUndefined(); + expect(sceneThemeId('auto', 'day', true, true)).toBeUndefined(); + }); + }); + + it('the resolved sky a hook subscribes to changes as the clock crosses, so theme classes follow', () => { + vi.useFakeTimers(); + let hour = 12; + setSkyClock(() => atStandardTime(hour, 10)); + const seen: string[] = []; + const off = subscribeSky((s) => seen.push(s)); + expect(getResolvedSkyState()).toBe('day'); + hour = 0; + setSkyClock(() => atStandardTime(hour, 10)); + vi.advanceTimersByTime(61_000); + expect(seen).toEqual(['night']); + expect(getResolvedSkyState()).toBe('night'); + off(); + vi.useRealTimers(); setSkyClock(); }); diff --git a/src/app/features/scene/skyTheme.ts b/src/app/features/scene/skyTheme.ts index dbd46501..3d427cb2 100644 --- a/src/app/features/scene/skyTheme.ts +++ b/src/app/features/scene/skyTheme.ts @@ -10,7 +10,7 @@ // derived outside this code (src/sky/skyTokens.js). Midnight Sky's link is derived there against the lightest Night sky // (4.53 on it, 5.43 on the darkest). The plate (skyPlate.css.ts) is still in the shell, pending // its removal. -import { resolveSkyState, type FixedSkyState, type SkyState } from './skyState'; +import type { FixedSkyState, SkyState } from './skyState'; export type SkyThemeId = 'midnight-sky' | 'noonday-sky'; @@ -21,4 +21,19 @@ const BY_STATE: Record = { }; export const skyThemeId = (state: SkyState): SkyThemeId | undefined => - BY_STATE[resolveSkyState(state)]; + state === 'auto' ? undefined : BY_STATE[state]; + +/** + * The theme the page wears: a fixed sky state always picks its theme; 'auto' follows the resolved sky (`resolved`, the + * clock's state) only while a scene is on and the person has not chosen a theme of their own, and otherwise picks none. + * Signed-out pages choose no theme, so they pass `userChoseTheme: false`. + */ +export const sceneThemeId = ( + state: SkyState, + resolved: FixedSkyState, + sceneOn: boolean, + userChoseTheme: boolean +): SkyThemeId | undefined => { + if (state !== 'auto') return BY_STATE[state]; + return sceneOn && !userChoseTheme ? BY_STATE[resolved] : undefined; +}; diff --git a/src/app/features/settings/about/About.tsx b/src/app/features/settings/about/About.tsx index 6b304965..9ec74305 100644 --- a/src/app/features/settings/about/About.tsx +++ b/src/app/features/settings/about/About.tsx @@ -4,6 +4,7 @@ import { Page, PageContent, PageHeader } from '../../../components/page'; import { SequenceCard } from '../../../components/sequence-card'; import { SequenceCardStyle } from '../styles.css'; import { SettingTile } from '../../../components/setting-tile'; +import { LogoMark } from '../../../components/logo/logoMark.css'; import RatatoskrSVG from '../../../../../public/res/svg/ratatoskr.svg'; import { clearCacheAndReload } from '../../../../client/initMatrix'; import { useMatrixClient } from '../../../hooks/useMatrixClient'; @@ -37,6 +38,7 @@ export function About({ requestClose }: AboutProps) { Ratatoskr logo useSyncExternalStore(subscribe, getSkyState); + +/** The sky being drawn: day, dusk or night. Unlike the choice it changes as the clock crosses, so it re-renders. */ +export const useResolvedSkyState = (): FixedSkyState => + useSyncExternalStore(subscribe, getResolvedSkyState); + +/** Whether a background scene runs on this device and config (the tier the scene host will mount). */ +export const useSceneOn = (): boolean => + resolveTier(useClientConfig().backgroundScene, readCapabilities(navigator)) !== 'off'; diff --git a/src/app/hooks/useTheme.ts b/src/app/hooks/useTheme.ts index 00ac1ee9..60f89757 100644 --- a/src/app/hooks/useTheme.ts +++ b/src/app/hooks/useTheme.ts @@ -10,10 +10,10 @@ import { } from '../../colors.css'; import '../../gamecult.css'; import '../../sky.css'; -import { settingsAtom } from '../state/settings'; +import { defaultThemeId, settingsAtom } from '../state/settings'; import { useSetting } from '../state/hooks/settings'; -import { skyThemeId } from '../features/scene/skyTheme'; -import { useSkyState } from './useSkyState'; +import { sceneThemeId } from '../features/scene/skyTheme'; +import { useResolvedSkyState, useSceneOn, useSkyState } from './useSkyState'; export enum ThemeKind { Light = 'light', @@ -102,20 +102,29 @@ export const useSystemThemeKind = (): ThemeKind => { return themeKind; }; -/** The theme the sky state asks for, or undefined while it is 'auto': auto never overrides a person's theme. */ -export const useSkyTheme = (): Theme | undefined => { - const id = skyThemeId(useSkyState()); - return id === NoondaySkyTheme.id ? NoondaySkyTheme : id && MidnightSkyTheme; -}; +const toTheme = (id: ReturnType): Theme | undefined => + id === NoondaySkyTheme.id ? NoondaySkyTheme : id && MidnightSkyTheme; + +/** A theme the person chose: the system scheme, or one other than the default. A saved Midnight Sky is the default. */ +const chosenTheme = (useSystemTheme: boolean, themeId?: string) => + useSystemTheme || (themeId !== undefined && themeId !== defaultThemeId); + +/** The theme the sky asks for on a page with no theme of its own (signed out), or undefined for none. */ +export const useSkyTheme = (): Theme | undefined => + toTheme(sceneThemeId(useSkyState(), useResolvedSkyState(), useSceneOn(), false)); export const useActiveTheme = (): Theme => { - const skyTheme = useSkyTheme(); + const sky = useSkyState(); + const resolved = useResolvedSkyState(); + const sceneOn = useSceneOn(); const systemThemeKind = useSystemThemeKind(); const themes = useThemes(); const [systemTheme] = useSetting(settingsAtom, 'useSystemTheme'); const [themeId] = useSetting(settingsAtom, 'themeId'); const [lightThemeId] = useSetting(settingsAtom, 'lightThemeId'); const [darkThemeId] = useSetting(settingsAtom, 'darkThemeId'); + // A person's own theme wins over 'auto'; a fixed sky state is itself a choice and wins over the theme. + const skyTheme = toTheme(sceneThemeId(sky, resolved, sceneOn, chosenTheme(systemTheme, themeId))); if (skyTheme) return skyTheme; diff --git a/src/app/pages/auth/AuthLayout.tsx b/src/app/pages/auth/AuthLayout.tsx index 0d5c9406..49c7b774 100644 --- a/src/app/pages/auth/AuthLayout.tsx +++ b/src/app/pages/auth/AuthLayout.tsx @@ -21,6 +21,7 @@ import { import { AsyncStatus, useAsyncCallback } from '../../hooks/useAsyncCallback'; import { LOGIN_PATH, REGISTER_PATH, RESET_PASSWORD_PATH } from '../paths'; import RatatoskrSVG from '../../../../public/res/svg/ratatoskr.svg'; +import { LogoMark } from '../../components/logo/logoMark.css'; import { SkyStateControl } from '../../features/scene/SkyStateControl'; import { ServerPicker } from './ServerPicker'; import { AutoDiscoveryAction, autoDiscovery } from '../../cs-api'; @@ -135,7 +136,11 @@ export function AuthLayout() {
- Ratatoskr logo + Ratatoskr logo Ratatoskr diff --git a/src/app/pages/auth/styles.css.ts b/src/app/pages/auth/styles.css.ts index f16617e8..56ee090f 100644 --- a/src/app/pages/auth/styles.css.ts +++ b/src/app/pages/auth/styles.css.ts @@ -34,9 +34,6 @@ export const AuthLogo = style([ }, ]); -// The mark is white (Meta's matte); on the light sky theme it takes the dark ink instead. -globalStyle('body.noonday-sky img[src*="ratatoskr"]', { filter: 'brightness(0.18)' }); - export const AuthHeader = style({ padding: `0 ${config.space.S400}`, borderBottomWidth: config.borderWidth.B300, diff --git a/src/app/pages/client/WelcomePage.tsx b/src/app/pages/client/WelcomePage.tsx index 74869c3f..8b63af73 100644 --- a/src/app/pages/client/WelcomePage.tsx +++ b/src/app/pages/client/WelcomePage.tsx @@ -1,6 +1,7 @@ import React from 'react'; import { Box, Button, Icon, Icons, Text, config, toRem } from 'folds'; import { Page, PageHero, PageHeroSection } from '../../components/page'; +import { LogoMark } from '../../components/logo/logoMark.css'; import RatatoskrSVG from '../../../../public/res/svg/ratatoskr.svg'; export function WelcomePage() { @@ -14,7 +15,15 @@ export function WelcomePage() { > } + icon={ + Ratatoskr logo + } title="Welcome to Ratatoskr" subTitle={ diff --git a/src/app/state/settings.ts b/src/app/state/settings.ts index 2b48fb59..9ca2496f 100644 --- a/src/app/state/settings.ts +++ b/src/app/state/settings.ts @@ -58,8 +58,10 @@ export interface Settings { soundscapeVoiceCap: number; } +export const defaultThemeId = 'midnight-sky'; + const defaultSettings: Settings = { - themeId: 'midnight-sky', + themeId: defaultThemeId, useSystemTheme: false, lightThemeId: undefined, darkThemeId: undefined,