From e4ae831b5abd5f7113fbdd760b0f0ae92cffd9c6 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Fri, 20 Nov 2026 23:00:30 +0100 Subject: [PATCH] The drawn sky alone decides theme and ink while a scene is on sceneThemeId is a function of the resolved sky and sceneOn; the person's theme stands only where no sky is drawn. Deletes userChoseTheme, chosenTheme, themeChosen and skyThemeId (ratatoskr:ruling:ink-follows-drawn-sky). Co-Authored-By: Claude Sonnet 5.5 --- src/app/features/scene/skyInk.test.ts | 23 ++----- src/app/features/scene/skyInk.ts | 6 +- src/app/features/scene/skyTheme.test.ts | 61 ++++++------------- src/app/features/scene/skyTheme.ts | 39 +++--------- src/app/features/settings/general/General.tsx | 2 - src/app/hooks/useTheme.test.ts | 40 ------------ src/app/hooks/useTheme.ts | 29 +++------ src/app/state/settings.ts | 1 - 8 files changed, 42 insertions(+), 159 deletions(-) delete mode 100644 src/app/hooks/useTheme.test.ts diff --git a/src/app/features/scene/skyInk.test.ts b/src/app/features/scene/skyInk.test.ts index 25708204..616569f9 100644 --- a/src/app/features/scene/skyInk.test.ts +++ b/src/app/features/scene/skyInk.test.ts @@ -136,29 +136,18 @@ describe('userColorInk', () => { }); }); -describe('sceneInk: an explicit theme wins over the auto ink', () => { - it('is the sky state and viewport only while the sky theme is worn and a scene runs', () => { - // auto, scene on, no theme of the person's own: the sky theme is worn. - expect(sceneInk(sceneThemeId('auto', 'dusk', true, false), true, 'dusk', true)).toEqual({ +describe('sceneInk: the drawn sky decides the ink', () => { + it('is the sky state and viewport while a scene runs, and nothing without one', () => { + expect(sceneInk(sceneThemeId('dusk', true), true, 'dusk', true)).toEqual({ state: 'dusk', phone: true, }); - // auto, but the person chose a theme: it wins, the theme's own ink stands. - expect(sceneInk(sceneThemeId('auto', 'dusk', true, true), true, 'dusk', true)).toBeUndefined(); - // a fixed sky state does not override the person's theme either: the theme's own ink stands. - expect( - sceneInk(sceneThemeId('night', 'night', true, true), true, 'night', false) - ).toBeUndefined(); - // a fixed sky state with no theme of the person's own: the sky theme's ink applies. - expect(sceneInk(sceneThemeId('night', 'night', true, false), true, 'night', false)).toEqual({ + expect(sceneInk(sceneThemeId('night', true), true, 'night', false)).toEqual({ state: 'night', phone: false, }); - // no scene behind the page: nothing for the ink to be measured against. - expect( - sceneInk(sceneThemeId('auto', 'day', false, false), false, 'day', false) - ).toBeUndefined(); - expect(sceneInk(sceneThemeId('day', 'day', true, false), false, 'day', false)).toBeUndefined(); + // no scene behind the page: the person's theme and its ink stand. + expect(sceneInk(sceneThemeId('day', false), false, 'day', false)).toBeUndefined(); }); }); diff --git a/src/app/features/scene/skyInk.ts b/src/app/features/scene/skyInk.ts index e1de9063..d12d558b 100644 --- a/src/app/features/scene/skyInk.ts +++ b/src/app/features/scene/skyInk.ts @@ -10,7 +10,7 @@ // not a GPU; ratatoskr-sidebar-contrast-20261110/results.md, T3). These are the scene's own patches, not // the bare sky: the terrain under the timeline is what the ink sits on, and at night its snow (0.103, phone 0.149) is // lighter than the sky was when these were measured (0.0816). -// Only a person whose theme is the sky's (no explicit theme of their own, sceneThemeId) wears this ink. +// The page wears this ink whenever the drawn sky decides its theme (a scene is on, sceneThemeId). import chroma from 'chroma-js'; import { AA, luminance } from '../../../sky/skyTokens.js'; import { baked } from '../../../sky/baked'; @@ -25,8 +25,8 @@ export interface SkyInk { } /** - * The ink in force: only while the page wears the sky's theme (`themeId`, from sceneThemeId, so a person's explicit - * theme, which that function lets win over 'auto', keeps its own ink) and a scene runs behind it. Otherwise undefined. + * The ink in force: only while the page wears the sky's theme (`themeId`, from sceneThemeId, defined only while a + * scene is on) and a scene runs behind it. With no scene the person's theme and its own ink stand: undefined. */ export const sceneInk = ( themeId: SkyThemeId | undefined, diff --git a/src/app/features/scene/skyTheme.test.ts b/src/app/features/scene/skyTheme.test.ts index ec53dc17..c78f3928 100644 --- a/src/app/features/scene/skyTheme.test.ts +++ b/src/app/features/scene/skyTheme.test.ts @@ -14,53 +14,36 @@ import { setSkyClock, subscribe as subscribeSky, } from './skyState'; -import { sceneThemeId, skyThemeId } from './skyTheme'; +import { sceneThemeId } from './skyTheme'; const SKY = { 'midnight-sky': baked.midnight, 'noonday-sky': baked.noonday } as const; const r2 = (n: number) => n.toFixed(2); -const fixed = (['day', 'dusk', 'night'] as const).flatMap((s) => { - const id = skyThemeId(s); - return id ? [[s, id] as const] : []; +const fixed = (['day', 'dusk', 'night'] as const).flatMap((st) => { + const id = sceneThemeId(st, true); + return id ? [[st, id] as const] : []; }); -describe('skyThemeId', () => { - it('picks a theme for each explicit state', () => { - expect(skyThemeId('day')).toBe('noonday-sky'); - expect(skyThemeId('dusk')).toBe('noonday-sky'); - expect(skyThemeId('night')).toBe('midnight-sky'); +describe('sceneThemeId, the theme the page wears', () => { + it('with a scene on, the drawn sky gives its theme, whatever theme a person stored', () => { + expect(sceneThemeId('day', true)).toBe('noonday-sky'); + expect(sceneThemeId('dusk', true)).toBe('noonday-sky'); + expect(sceneThemeId('night', true)).toBe('midnight-sky'); }); - it('picks none for auto, at any hour: auto never overrides a signed-in theme', () => { - [0, 6, 12, 18, 23].forEach((h) => { + it('auto draws the clock sky and that sky decides', () => { + [0, 12, 23].forEach((h) => { setSkyClock(() => atStandardTime(h, 10)); - expect(skyThemeId('auto')).toBeUndefined(); + expect(sceneThemeId(getResolvedSkyState(), true)).toBe( + h === 12 ? 'noonday-sky' : 'midnight-sky' + ); }); setSkyClock(); }); - describe('sceneThemeId, the theme the page wears', () => { - it('a fixed state picks its theme, whatever the scene, while the person chose no theme', () => { - [true, false].forEach((scene) => { - expect(sceneThemeId('day', 'night', scene, false)).toBe('noonday-sky'); - expect(sceneThemeId('night', 'day', scene, false)).toBe('midnight-sky'); - }); - }); - - it('a theme the person chose wins over every sky state, fixed or auto', () => { - (['auto', 'day', 'dusk', 'night'] as const).forEach((state) => - [true, false].forEach((scene) => - expect(sceneThemeId(state, 'night', scene, true)).toBeUndefined() - ) - ); - }); - - 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('with the scene off no sky is drawn, so the person theme stands', () => { + (['day', 'dusk', 'night'] as const).forEach((st) => + expect(sceneThemeId(st, false)).toBeUndefined() + ); }); it('the resolved sky a hook subscribes to changes as the clock crosses, so theme classes follow', () => { @@ -79,14 +62,6 @@ describe('skyThemeId', () => { vi.useRealTimers(); setSkyClock(); }); - - it('is what a wiring that follows the sky reads: the resolved state names a theme', () => { - setSkyClock(() => atStandardTime(12)); - expect(skyThemeId(getResolvedSkyState())).toBe('noonday-sky'); - setSkyClock(() => atStandardTime(0)); - expect(skyThemeId(getResolvedSkyState())).toBe('midnight-sky'); - setSkyClock(); - }); }); describe('the plate, where text cannot rest on bare sky', () => { diff --git a/src/app/features/scene/skyTheme.ts b/src/app/features/scene/skyTheme.ts index ee1cba40..fef313ec 100644 --- a/src/app/features/scene/skyTheme.ts +++ b/src/app/features/scene/skyTheme.ts @@ -1,16 +1,8 @@ -// Which theme a sky state lights the page with. 'auto' picks none: it never overrides a person's theme -// (the stored one when signed in, Midnight Sky when signed out). A wiring that follows the sky when no theme -// is stored reads `getResolvedSkyState` (skyState.ts) and passes that fixed state here. -// -// Day and Dusk take the dark ink of Noonday Sky, Night the light ink of Midnight Sky. Each state's -// drawn sky is held to a luminance budget (ridge/toneMap.ts, bands in skyState.ts `FixedSkyState`) in which that ink's TEXT clears 4.5:1 on -// bare sky: Day at least 0.2983 (dark ink), Night at most 0.0931 (light ink). Dusk's floor is higher, the bound of -// the dark link (0.4554), so its link clears as well. skyTheme.test.ts pins the measured text and link ratios. Night's -// link ink is not in the band, and the themes' link colours are 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 type { FixedSkyState, SkyState } from './skyState'; +// Which theme the drawn sky lights the page with. While a scene is on, the sky being drawn (the fixed pick, or the +// clock's state under 'auto'; `useResolvedSkyState`) alone decides the theme and, with it, the ink: Day and Dusk +// wear Noonday Sky, Night wears Midnight Sky. A person's own theme (the theme menu) stands only where no sky is +// drawn, that is with the scene off. +import type { FixedSkyState } from './skyState'; export type SkyThemeId = 'midnight-sky' | 'noonday-sky'; @@ -20,21 +12,6 @@ const BY_STATE: Record = { night: 'midnight-sky', }; -export const skyThemeId = (state: SkyState): SkyThemeId | undefined => - state === 'auto' ? undefined : BY_STATE[state]; - -/** - * The theme the page wears: a theme the person chose always wins, and picks none here. Otherwise a fixed sky state - * picks its theme, and 'auto' follows the resolved sky (`resolved`, the clock's state) only while a scene is on. - * 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 (userChoseTheme) return undefined; - if (state !== 'auto') return BY_STATE[state]; - return sceneOn ? BY_STATE[resolved] : undefined; -}; +/** The theme the page wears: the drawn sky's while a scene is on, otherwise none (the person's theme stands). */ +export const sceneThemeId = (resolved: FixedSkyState, sceneOn: boolean): SkyThemeId | undefined => + sceneOn ? BY_STATE[resolved] : undefined; diff --git a/src/app/features/settings/general/General.tsx b/src/app/features/settings/general/General.tsx index e0835eff..90d2da3a 100644 --- a/src/app/features/settings/general/General.tsx +++ b/src/app/features/settings/general/General.tsx @@ -82,7 +82,6 @@ function SelectTheme({ disabled }: { disabled?: boolean }) { const themes = useThemes(); const themeNames = useThemeNames(); const [themeId, setThemeId] = useSetting(settingsAtom, 'themeId'); - const [, setThemeChosen] = useSetting(settingsAtom, 'themeChosen'); const [menuCords, setMenuCords] = useState(); const selectedTheme = themes.find((theme) => theme.id === themeId) ?? LightTheme; @@ -92,7 +91,6 @@ function SelectTheme({ disabled }: { disabled?: boolean }) { const handleThemeSelect = (theme: Theme) => { setThemeId(theme.id); - setThemeChosen(true); setMenuCords(undefined); }; diff --git a/src/app/hooks/useTheme.test.ts b/src/app/hooks/useTheme.test.ts deleted file mode 100644 index dcb96e49..00000000 --- a/src/app/hooks/useTheme.test.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { readFileSync } from 'fs'; -import { beforeAll, describe, expect, it, vi } from 'vitest'; - -// settings.ts reads localStorage when it loads, and this suite runs without a DOM. -vi.stubGlobal('localStorage', { getItem: () => null, setItem: () => undefined }); -let chosenTheme: typeof import('./useTheme').chosenTheme; -let defaultThemeId: string; -beforeAll(async () => { - ({ chosenTheme } = await import('./useTheme')); - ({ defaultThemeId } = await import('../state/settings')); -}); - -describe('chosenTheme: what counts as a theme the person chose', () => { - it('is not a theme before anything was picked: no id saved, or the default saved', () => { - expect(chosenTheme(false, undefined, undefined)).toBe(false); - expect(chosenTheme(false, defaultThemeId, undefined)).toBe(false); - expect(chosenTheme(false, defaultThemeId, false)).toBe(false); - }); - - it('is a pick of Midnight Sky made in the theme menu, which sets the flag', () => { - expect(chosenTheme(false, defaultThemeId, true)).toBe(true); - }); - - it('is a saved id other than the default, with or without the flag', () => { - expect(chosenTheme(false, 'dark-theme', undefined)).toBe(true); - expect(chosenTheme(false, 'noonday-sky', true)).toBe(true); - }); - - it('is the system scheme', () => { - expect(chosenTheme(true, defaultThemeId, undefined)).toBe(true); - }); - - it('the theme menu sets the flag together with the id', () => { - const tsx = readFileSync( - `${process.cwd()}/src/app/features/settings/general/General.tsx`, - 'utf8' - ); - expect(tsx).toMatch(/setThemeId\(theme\.id\);\s*setThemeChosen\(true\);/); - }); -}); diff --git a/src/app/hooks/useTheme.ts b/src/app/hooks/useTheme.ts index 730b12d4..69afc382 100644 --- a/src/app/hooks/useTheme.ts +++ b/src/app/hooks/useTheme.ts @@ -10,11 +10,11 @@ import { } from '../../colors.css'; import '../../gamecult.css'; import '../../sky.css'; -import { defaultThemeId, settingsAtom } from '../state/settings'; +import { settingsAtom } from '../state/settings'; import { useSetting } from '../state/hooks/settings'; import { sceneThemeId } from '../features/scene/skyTheme'; import { sceneInk, type SkyInk } from '../features/scene/skyInk'; -import { useResolvedSkyState, useSceneOn, useSkyState } from './useSkyState'; +import { useResolvedSkyState, useSceneOn } from './useSkyState'; import { ScreenSize, useScreenSizeContext } from './useScreenSize'; export enum ThemeKind { @@ -107,28 +107,13 @@ export const useSystemThemeKind = (): ThemeKind => { const toTheme = (id: ReturnType): Theme | undefined => id === NoondaySkyTheme.id ? NoondaySkyTheme : id && MidnightSkyTheme; -/** - * A theme the person chose: the system scheme, any pick made in the theme menu (`themeChosen`, which also covers - * Midnight Sky, the default), or a saved id other than the default (picks from before the flag existed). - */ -export const chosenTheme = (useSystemTheme: boolean, themeId?: string, themeChosen?: boolean) => - useSystemTheme || themeChosen === true || (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. */ +/** The theme the drawn sky asks for while a scene is on, or undefined for none (signed-out pages then wear Midnight Sky). */ export const useSkyTheme = (): Theme | undefined => - toTheme(sceneThemeId(useSkyState(), useResolvedSkyState(), useSceneOn(), false)); + toTheme(sceneThemeId(useResolvedSkyState(), useSceneOn())); -/** The sky theme the signed-in page wears, or undefined when the person's own theme wins. */ -const useSceneSkyThemeId = (): ReturnType => { - const sky = useSkyState(); - const resolved = useResolvedSkyState(); - const sceneOn = useSceneOn(); - const [systemTheme] = useSetting(settingsAtom, 'useSystemTheme'); - const [themeId] = useSetting(settingsAtom, 'themeId'); - const [themeChosen] = useSetting(settingsAtom, 'themeChosen'); - // A person's own theme wins over the sky, fixed or 'auto'. - return sceneThemeId(sky, resolved, sceneOn, chosenTheme(systemTheme, themeId, themeChosen)); -}; +/** The sky theme the page wears while a scene is on, or undefined when the person's own theme stands. */ +const useSceneSkyThemeId = (): ReturnType => + sceneThemeId(useResolvedSkyState(), useSceneOn()); /** The ink the page wears over the scene (`sceneInk`, skyInk.ts), or undefined when the theme's own ink stands. */ export const useSceneInk = (): SkyInk | undefined => { diff --git a/src/app/state/settings.ts b/src/app/state/settings.ts index 21c449af..e5737196 100644 --- a/src/app/state/settings.ts +++ b/src/app/state/settings.ts @@ -19,7 +19,6 @@ export enum MessageLayout { export interface Settings { themeId?: string; /** Set when a theme is picked in the menu, so a picked default (Midnight Sky) reads as chosen. Absent until then. */ - themeChosen?: boolean; useSystemTheme: boolean; lightThemeId?: string; darkThemeId?: string;