Delete the sky-backdrop contrast apparatus, the sun-disc floor and dead star/tone code; keep stars out of the moon disc
Some checks failed
Build pull request / Build pull request (pull_request) Has been cancelled

skyBackdrop/BACKDROPS and the tests that held login text against sky bounds are gone (the bounds were false: the look is tuned by eye). The vertex-carry guard asserts placement only. d3-celestial's BSD-3 text is in THIRD_PARTY_NOTICES.md.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-11-20 21:50:20 +01:00
commit 01d74b8188
18 changed files with 93 additions and 279 deletions

21
THIRD_PARTY_NOTICES.md Normal file
View file

@ -0,0 +1,21 @@
# Third-party notices
## d3-celestial (constellation lines)
The constellation line chains in `src/app/features/scene/ridge/nightSkyData.ts` are derived from
`data/constellations.lines.json` of d3-celestial, https://github.com/ofrohn/d3-celestial,
under the licence below.
```
Copyright (c) 2015, Olaf Frohn
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.```

View file

@ -43,7 +43,7 @@ Presets (`PRESETS` in `ridgeSheet.ts`; swiss and poster take every key not named
| physical | PHYSICAL_LOOK (Lambert, no noise, sky haze, full ink) |
| swiss | reliefLight {mix 0.7, azimuthDeg -45, elevationDeg 40}, contrastByDistance 0.9, hazeScale 6, hazeTint [0, 0.05, 0.25], nearWarm 0.5, inkScale 0.6 |
| poster | reliefWeight 0.15, cardToneStep 0.25, cardGradient 0.5, inkKeep {edge 0.25, occlude 0.9, crease 1}, hazeScale 4 |
| painterly | DEFAULT_LOOK: groundNoise 0.35, cloudShadows 0.5, nearWarm 0.6, hazeScale 2, inkScale 0.4, celBands 3, celSoftness 0.05, celAmbientAway 0.7, nightAmbient [0.5, 0.66, 1.1] |
| painterly | DEFAULT_LOOK: groundNoise 0.35, cloudShadows 0.5, nearWarm 0.6, hazeScale 2, inkScale 0.4, celBands 3, celSoftness 0.05, celAmbientAway 0.7 |
| painterly-cel-2 / -3 / -4 | painterly with celBands 2 / 3 / 4 |
Night sets (`ridgeSheet.html`): `?moments=2026-11-24T22:00Z,2026-12-09T20:00Z` pins explicit UTC moments (the sun, moon and stars are those of the moment); `?night=1` renders the next new moon, first quarter and full moon from today (`&from=YYYY-MM-DD`) at four hours each (`&hours=18,21,0,4`, UTC) plus deep dusk of the full-moon evening; `&lines=1` draws the constellation lines (the Sky menu's hidden toggle). Use `&w=300` for the 13-column set. The night look's knobs: `NIGHT_LOOK` in `ridge/nightSky.ts` (star point spread, contrast exponents, moon size, earthshine, line opacity), `NIGHT_CEILING` and `SCOTOPIC` in `ridge/toneMap.ts`, the night `Budget` (key, targets, partial adaptation).

View file

@ -19,7 +19,7 @@ export const terrainCredit = (
export const STARS_CREDIT =
'Stars: Yale Bright Star Catalogue, 5th revised ed. (Hoffleit and Warren 1991), public domain, CDS VizieR V/50';
export const STARS_SOURCE_URL = 'http://tdc-www.harvard.edu/catalogs/bsc5.dat.gz';
/** The constellation lines: d3-celestial by Olaf Frohn, BSD-3-Clause (the repository's LICENSE, 2015). The licence asks for its notice to travel with redistributions. */
/** The constellation lines: d3-celestial by Olaf Frohn, BSD-3-Clause (the repository's LICENSE, 2015). The licence asks for its notice to travel with redistributions: the full text is in `THIRD_PARTY_NOTICES.md` at the repository root. */
export const LINES_CREDIT =
'Constellation lines: d3-celestial by Olaf Frohn (BSD-3-Clause, copyright 2015 Olaf Frohn), https://github.com/ofrohn/d3-celestial';
export const LINES_SOURCE_URL =

View file

@ -18,12 +18,18 @@ import type { RidgeLook } from './lightCards';
import { parseManifest } from './manifest';
import { wireManifest } from './manifest.fixture';
import type { PhysicalSky } from './physicalSky';
import { ACES_FIT, ACES_IN, ACES_OUT, LIFT_ONLY } from './toneMap';
import { ACES_FIT, ACES_IN, ACES_OUT, BLACK_LIFT, makeCurve } from './toneMap';
const manifest = parseManifest(wireManifest(), '/d/');
const RAD = Math.PI / 180;
const dot = (a: readonly number[], b: readonly number[]) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
/** A display curve that is the straight line from the black lift to white: a fixture, the cards only need some curve to carry. */
const FLAT_CURVE = makeCurve(
[0, 0.25, 0.5, 0.75, 1],
[0, 0.25, 0.5, 0.75, 1].map((v) => BLACK_LIFT + (1 - BLACK_LIFT) * v)
);
describe("the sun in a column's frame", () => {
it.each([5, 30, 60, 89])(
'at elevation %i it lights an up-facing normal by sin e and a normal facing it by 1',
@ -96,13 +102,13 @@ describe('the lighting inputs', () => {
({
sun: { azimuth: 214, elevation },
atm: a,
fit: { display: { exposure: 12, curve: LIFT_ONLY } },
fit: { display: { exposure: 12, curve: FLAT_CURVE } },
view: manifest.view,
} as unknown as PhysicalSky);
it("takes the display of the sky's own fit, so terrain and sky share one exposure", () => {
const l = lightingOf(manifest, sky(30));
expect([l.exposure, l.curve]).toEqual([12, LIFT_ONLY]);
expect([l.exposure, l.curve]).toEqual([12, FLAT_CURVE]);
[0.1, 0.2, 0.3].forEach((a, i) => expect(l.key.ambient[i]).toBeCloseTo(a, 6)); // plus the airglow's
expect(l.logDMin).toBe(4.6);
expect(l.logDSpan).toBeCloseTo(11.5 - 4.6, 12);
@ -196,7 +202,7 @@ describe('the look reaches the shader', () => {
irradiance: { direct: [0, 0, 0], ambient: [0.1, 0.2, 0.3] },
radiance: (_a: number, _b: number, o: number[]) => o.fill(0),
},
fit: { display: { exposure: 1, curve: LIFT_ONLY } },
fit: { display: { exposure: 1, curve: FLAT_CURVE } },
view: manifest.view,
} as unknown as PhysicalSky;
const one = { ...manifest, cards: manifest.cards.slice(0, 1) };
@ -261,7 +267,7 @@ function sky30(): PhysicalSky {
transmittanceToSpace: (_m: number, o: number[]) => o.fill(1),
irradiance: { direct: [0, 0, 0], ambient: [0, 0, 0] },
},
fit: { display: { exposure: 1, curve: LIFT_ONLY } },
fit: { display: { exposure: 1, curve: FLAT_CURVE } },
} as unknown as PhysicalSky;
}
@ -283,7 +289,7 @@ describe('night key light', () => {
? {}
: { moon: { azimuth: 150, elevation: moonEl, ratio: 2.5e-6, atm: atmOf([0.4, 0.5, 0.8]) } },
atm: atmOf([0.001, 0.001, 0.002]),
fit: { display: { exposure: 1, curve: LIFT_ONLY } },
fit: { display: { exposure: 1, curve: FLAT_CURVE } },
view: manifest.view,
} as unknown as PhysicalSky);

View file

@ -129,7 +129,7 @@ describe('painting', () => {
});
describe('the stars under the figures', () => {
it('carry every constellation-line vertex in the sky strip, even under a full moon, at the app framing', async () => {
it('carry every constellation-line vertex in the sky strip that the moon does not cover, even under a full moon, at the app framing', async () => {
const { windowFor } = await import('./view');
const { linesAt } = await import('./starCatalogue');
const cam = windowFor(FALLBACK_VIEW, 1100, 619).camera;
@ -142,13 +142,14 @@ describe('the stars under the figures', () => {
chain.forEach((q) => {
const a = onScreen(cam, q.azimuth, q.elevation);
if (a.x < 0 || a.x > 1 || a.y < 0 || a.y > 0.8) return;
// The moon is drawn over the stars, and a star inside its disc is not placed.
if (nb.moon && Math.hypot((nb.moon.x - a.x) * 1100, (nb.moon.y - a.y) * 619) < Math.max(2, nb.moon.radius * 619)) return;
vertices += 1;
// Visible: the star's centre is at least 20 of 255 lighter than the sky behind it in some channel.
const lift = (c: string, d: string) => Math.max(...c.match(/\d+/g)!.map((v, i) => Number(v) - Number(d.match(/\d+/g)![i])));
if (nb.stars.some((s) => Math.hypot((s.x - a.x) * 1100, (s.y - a.y) * 619) < 4 && lift(s.fill, s.cover) >= 20)) carried += 1;
// Placement only: a catalogue star is drawn within a few px of the vertex. How bright it is is the look's.
if (nb.stars.some((s) => Math.hypot((s.x - a.x) * 1100, (s.y - a.y) * 619) < 4)) carried += 1;
})
);
expect(vertices).toBeGreaterThan(20);
expect(carried / vertices).toBeGreaterThan(0.8); // a regression guard on the starting star values, not a look gate: low vertices sit in the moonlit haze (0.85 at HORIZON_AT 0.85)
expect(carried).toBe(vertices);
});
});

View file

@ -125,10 +125,43 @@ export function nightBodies(p: PhysicalSky, px: SkyPixels, withLines: boolean):
const add = [0, 0, 0];
const tot = [0, 0, 0];
const out = [0, 0, 0];
let moon: MoonDraw | undefined;
const mo = p.moon;
const mAt = onScreen(camera, mo.azimuth, mo.elevation);
if (mo.elevation > -1 && mAt.x > -0.05 && mAt.x < 1.05 && mAt.y > -0.05 && mAt.y < 1.05) {
domeAt(dome, mAt.x, mAt.y, bg);
const trans = [0, 0, 0];
p.atm.transmittanceToSpace(Math.max(Math.sin(mo.elevation * RAD), 0), trans);
const top = Math.max(...trans, 1e-9);
const tint = [1, 0.96, 0.88];
const surface = moonSurface(mo);
for (let i = 0; i < 3; i += 1) add[i] = surface * tint[i] * (trans[i] / top) ** 0.6;
composite(bg, add, NIGHT_LOOK.moonContrastExp, tot);
display8(tot[0], tot[1], tot[2], display, out);
const lit = css(out);
// Earthshine: a fraction of the full moon's surface, the more the thinner the crescent.
const full = moonSurface({ ...mo, ratio: mo.ratio / Math.max(mo.illuminated, 0.02), illuminated: 1 });
for (let i = 0; i < 3; i += 1) add[i] = NIGHT_LOOK.earthshine * full * (1.1 - mo.illuminated) * [0.9, 1, 1.15][i];
composite(bg, add, NIGHT_LOOK.moonContrastExp, tot);
display8(tot[0], tot[1], tot[2], display, out);
moon = {
x: mAt.x,
y: mAt.y,
radius: ((mo.radius / RAD) * NIGHT_LOOK.moonScale) / camera.vfovDeg,
illuminated: mo.illuminated,
phaseAngle: mo.phaseAngleDeg * RAD,
limb: limbAngle(mo, p.sun),
lit,
dark: css(out),
};
}
const stars: Star[] = [];
for (const s of starsAt(p.sun.time, place.lat, place.lon, MAG_LIMIT, -0.5)) {
const at = onScreen(camera, s.azimuth, s.elevation);
if (at.x < -0.02 || at.x > 1.02 || at.y < -0.02 || at.y > 1.02) continue;
// The moon is painted over the stars: one inside its disc is never seen, and its twinkle would be painted over the moon.
if (moon && Math.hypot((at.x - moon.x) * px.w, (at.y - moon.y) * px.h) < Math.max(2, moon.radius * px.h)) continue;
const back = [0, 0, 0];
domeAt(dome, at.x, at.y, back);
const m = extinguished(s.mag, s.elevation);
@ -161,37 +194,6 @@ export function nightBodies(p: PhysicalSky, px: SkyPixels, withLines: boolean):
});
}
let moon: MoonDraw | undefined;
const mo = p.moon;
const mAt = onScreen(camera, mo.azimuth, mo.elevation);
if (mo.elevation > -1 && mAt.x > -0.05 && mAt.x < 1.05 && mAt.y > -0.05 && mAt.y < 1.05) {
domeAt(dome, mAt.x, mAt.y, bg);
const trans = [0, 0, 0];
p.atm.transmittanceToSpace(Math.max(Math.sin(mo.elevation * RAD), 0), trans);
const top = Math.max(...trans, 1e-9);
const tint = [1, 0.96, 0.88];
const surface = moonSurface(mo);
for (let i = 0; i < 3; i += 1) add[i] = surface * tint[i] * (trans[i] / top) ** 0.6;
composite(bg, add, NIGHT_LOOK.moonContrastExp, tot);
display8(tot[0], tot[1], tot[2], display, out);
const lit = css(out);
// Earthshine: a fraction of the full moon's surface, the more the thinner the crescent.
const full = moonSurface({ ...mo, ratio: mo.ratio / Math.max(mo.illuminated, 0.02), illuminated: 1 });
for (let i = 0; i < 3; i += 1) add[i] = NIGHT_LOOK.earthshine * full * (1.1 - mo.illuminated) * [0.9, 1, 1.15][i];
composite(bg, add, NIGHT_LOOK.moonContrastExp, tot);
display8(tot[0], tot[1], tot[2], display, out);
moon = {
x: mAt.x,
y: mAt.y,
radius: ((mo.radius / RAD) * NIGHT_LOOK.moonScale) / camera.vfovDeg,
illuminated: mo.illuminated,
phaseAngle: mo.phaseAngleDeg * RAD,
limb: limbAngle(mo, p.sun),
lit,
dark: css(out),
};
}
const lines: LineDraw[] = [];
if (withLines && p.state === 'night') {
for (const chain of linesAt(p.sun.time, place.lat, place.lon)) {

View file

@ -9,7 +9,7 @@ import { windowFor } from './view';
import type { PhysicalSky } from './physicalSky';
// The Aqua method on tonemapped pixels: paint the sky the way the host canvas does and measure the WCAG luminance of every 8-bit
// texel, against the bounds the page text was checked against (`skyBackdrop`, 4.5:1). Over the weather, the day of the year, and
// texel, against the display range the sky was fitted to (`ridgeDrawn`). Over the weather, the day of the year, and
// viewports of different shape (the fit is made on one 16:9 grid and the paint on another).
const lin = (v: number): number => {
const c = v / 255;
@ -35,7 +35,7 @@ const VIEWPORTS: [number, number][] = [
];
describe.each(['day', 'dusk', 'night'] as FixedSkyState[])(
'the %s sky stays inside its backdrop bounds',
'the %s sky stays inside its fitted display range',
(state) => {
it('over weather, season and viewport shape', () => {
const b = ridgeDrawn(state);
@ -89,23 +89,6 @@ describe('weather in the sky', () => {
});
describe('the sun disc', () => {
it('keeps the display floor the dark link was fitted to, at every hour it is drawn', () => {
const lin = (c: number) =>
c / 255 <= 0.04045 ? c / 255 / 12.92 : ((c / 255 + 0.055) / 1.055) ** 2.4;
let drawn = 0;
for (const state of ['day', 'dusk'] as FixedSkyState[]) {
for (let m = 0; m < 24 * 60; m += 10) {
const sky = makePhysicalSky(state, new Date(Date.UTC(2026, 10, 11, 0, m)), 0, FALLBACK_VIEW);
const d = paintSky(sky, 1280, 720, facingSun(sky, 1280, 720)).sunDisc;
if (!d) continue;
drawn += 1;
expect(
0.2126 * lin(d.rgb[0]) + 0.7152 * lin(d.rgb[1]) + 0.0722 * lin(d.rgb[2])
).toBeGreaterThanOrEqual(0.4744);
}
}
expect(drawn).toBeGreaterThan(0);
});
const disc = (sky: PhysicalSky) => paintSky(sky, 1280, 720, facingSun(sky, 1280, 720));
const noon = new Date('2026-12-21T11:00:00Z'); // about 18 degrees: higher suns are above the top of the window
it('is drawn by the host, in a clear sky by day, white with the sun high', () => {

View file

@ -7,7 +7,7 @@ import type { Atmosphere } from './earthAtmosphere';
import { domeSize, renderDome, SUN_RADIUS, sunOnScreen } from './skyDome';
import type { Dome } from './skyDome';
import type { Srgb } from './skyColour';
import { display8, fitDisplay, MARGIN } from './toneMap';
import { display8, fitDisplay } from './toneMap';
import type { Display, Fit } from './toneMap';
import { moonAt } from './nightSky';
import type { MoonSample, NightLight } from './nightSky';
@ -136,8 +136,6 @@ export function paintSky(p: PhysicalSky, cssW: number, cssH: number, camera: Cam
return { w, h, data, dome, camera, sunDisc: sunDisc(p, camera) };
}
/** The luma the disc must keep: the day/dusk floor of toneMap's budget. */
const DISC_FLOOR = 0.4744 + MARGIN;
const smooth01 = (a: number, b: number, v: number): number => {
const t = Math.min(1, Math.max(0, (v - a) / (b - a)));
return t * t * (3 - 2 * t);
@ -155,13 +153,6 @@ function sunDisc(p: PhysicalSky, camera: Camera): SkyPixels['sunDisc'] {
p.atm.transmittanceToSpace(Math.max(Math.sin((p.sun.elevation * Math.PI) / 180), 0), trans);
const top = Math.max(...trans, 1e-9);
const rgb = trans.map((t) => Math.round(255 * (t / top) ** 0.6));
// The disc sits on the sky, so it keeps the display floor the dark link was fitted to: mix toward white until it does.
const lin = (c: number): number =>
c / 255 <= 0.04045 ? c / 255 / 12.92 : ((c / 255 + 0.055) / 1.055) ** 2.4;
const luma = (c: number[]): number =>
0.2126 * lin(c[0]) + 0.7152 * lin(c[1]) + 0.0722 * lin(c[2]);
for (let m = 0; luma(rgb) < DISC_FLOOR && m < 40; m += 1)
for (let i = 0; i < 3; i += 1) rgb[i] = Math.round(rgb[i] + (255 - rgb[i]) * 0.1);
return {
...at,
rgb: rgb as unknown as Srgb,

View file

@ -114,22 +114,6 @@ export function activeAt(stars: number, t: number): Twinkling[] {
// ---- Drawing --------------------------------------------------------------------------------
/** Bake `stars` into `ctx` (canvas `w` x `h` device px, `scale` device px per CSS px) at base brightness. */
export function drawStars(
ctx: CanvasRenderingContext2D,
stars: readonly Star[],
w: number,
h: number,
scale: number
) {
stars.forEach((s) => {
ctx.fillStyle = s.fill;
ctx.beginPath();
ctx.arc(s.x * w, s.y * h, s.r * scale, 0, 2 * Math.PI);
ctx.fill();
});
}
/**
* The overlay pass: clear, then for each active star whose gain is off base, cover the baked star with the sky behind it and draw it again
* at the gain. A star at base draws nothing.

View file

@ -121,8 +121,6 @@ export interface Budget {
/** The most the curve may steepen the sky's own spread about its median (display luminance per unit of ACES output): a nearly flat overcast sky is not blown up into a gradient. */
maxGain: number;
}
/** Display luminance slack for the 8-bit rounding and the smooth upscale of the baked grid. */
export const MARGIN = 0.004;
/** The one absolute lift of day and dusk: what black is drawn as, display-linear. The rest of the range is made by the curve. */
@ -207,12 +205,6 @@ export function applyCurve(c: Curve, v: number): number {
);
}
/** The straight line from the black lift to white: what a display with no fitted curve does. */
export const LIFT_ONLY: Curve = makeCurve(
[0, 0.25, 0.5, 0.75, 1],
[0, 0.25, 0.5, 0.75, 1].map((v) => BLACK_LIFT + (1 - BLACK_LIFT) * v)
);
/** The display transform of a sky: exposure, then ACES, then the fitted curve in display-linear. */
export interface Display {
exposure: number;

View file

@ -2,44 +2,17 @@ import { afterEach, describe, expect, it, vi } from 'vitest';
import { FALLBACK_VIEW } from './ridge/view';
import { ELSEWHERE_VIEW } from './ridge/manifest.fixture';
import { atStandardTime } from './standardTime.testkit';
import { baked } from '../../../sky/baked';
import { AA, luminance } from '../../../sky/skyTokens.js';
import { ridgeDrawn, ridgeSkyFor, ridgeSkyKey, loadWeather } from './skyForState';
import { DAY_FROM, setSkyClock, skyBackdrop } from './skyState';
import type { FixedSkyState } from './skyState';
import { skyThemeId } from './skyTheme';
import { DAY_FROM, setSkyClock } from './skyState';
import { BUDGET } from './ridge/toneMap';
const STATES = ['day', 'dusk', 'night'] as const;
const SKY = { 'midnight-sky': baked.midnight, 'noonday-sky': baked.noonday } as const;
/**
* The band each state needs, from the ink itself: dark ink needs a backdrop of at least
* AA * (L + 0.05) - 0.05, light ink at most (L + 0.05) / AA - 0.05. Day 0.2983, night 0.0931; dusk is bound by its
* link (0.4554), the darker ink to clear, whose floor also holds the text.
*/
const needs = (state: FixedSkyState) => {
const sky = SKY[skyThemeId(state)];
const l = luminance(sky.tokens.Background.OnContainer);
const link = luminance(sky.link);
return state === 'night'
? { floor: 0, ceiling: (l + 0.05) / AA - 0.05 }
: { floor: AA * ((state === 'dusk' ? link : l) + 0.05) - 0.05, ceiling: 1 };
};
afterEach(() => {
setSkyClock();
vi.unstubAllGlobals();
});
describe('the bands the text ink needs', () => {
it('are the numbers the shaping was set from', () => {
expect(needs('day').floor).toBeCloseTo(0.2983, 3);
expect(needs('dusk').floor).toBeCloseTo(0.4554, 3);
expect(needs('night').ceiling).toBeCloseTo(0.0931, 3);
});
});
describe('ridgeSkyFor', () => {
it('carries the physical sky of the state', () => {
for (const state of STATES) {
@ -92,24 +65,17 @@ describe('ridgeSkyFor', () => {
expect(ridgeSkyKey('day', FALLBACK_VIEW, 0.3)).not.toBe(ridgeSkyKey('night', FALLBACK_VIEW, 0.3));
});
// Night has no ink ceiling: its display top is a tunable (NIGHT_CEILING, ruling ridge-night-real-sky: the operator tunes it by eye),
// because the moon and the stars are drawn through the same display.
// Each state's ceiling is its budget's (night's is a tunable, NIGHT_CEILING: the operator tunes it by eye).
it.each(STATES)('%s: the display is the curve of its budget: black lift at the floor, and its ceiling', (state) => {
const r = ridgeDrawn(state);
expect(r.darkest).toBe(BUDGET[state].floor);
if (state !== 'night') expect(r.lightest).toBeLessThanOrEqual(needs(state).ceiling);
expect(r.lightest).toBeLessThanOrEqual(BUDGET[state].ceiling);
const fit = ridgeSkyFor(state, FALLBACK_VIEW, 0.3).physical?.fit;
expect(fit?.lo).toBeGreaterThanOrEqual(r.darkest - 1e-9);
expect(fit?.hi).toBeLessThanOrEqual(r.lightest + 1e-9);
});
});
describe('skyBackdrop holds the ridge sky', () => {
it.each(['day', 'dusk'] as const)('%s: the backdrop bound contains the ridge display ceiling', (state) => {
expect(skyBackdrop(state).lightest).toBeGreaterThanOrEqual(ridgeDrawn(state).lightest);
});
});
describe('loadWeather', () => {
it('reads the file again for another place inside the refresh window: the weather it set belongs to the sun of the place it was read for', async () => {
const fetched = vi.fn(async () => ({ ok: false, status: 404, json: async () => ({}) }));

View file

@ -1,7 +1,6 @@
// What the ridge scene is told for a sky state. 'auto' is a choice, not a sky: it draws the sky it
// resolves to (`resolveSkyState`, the clock), so the scene paints one of day, dusk or night, fitted to that
// state's luminance budget (ridge/toneMap.ts). `skyBackdrop` bounds what comes out, and the login text was
// checked against that bound.
// state's luminance budget (ridge/toneMap.ts).
import type { SkyColours } from './ridge/skyColour';
import { makePhysicalSky } from './ridge/physicalSky';
import type { Place, View } from './ridge/view';

View file

@ -1,7 +1,7 @@
import chroma from 'chroma-js';
import { describe, expect, it } from 'vitest';
import { baked } from '../../../sky/baked';
import { AA, NIGHT_SKY_LIGHTEST, luminance } from '../../../sky/skyTokens.js';
import { AA, luminance } from '../../../sky/skyTokens.js';
import { indexColorMXID } from '../../../util/colorMXID';
import type { FixedSkyState } from './skyState';
import {
@ -115,8 +115,6 @@ describe('inkForState', () => {
expect(chroma(aqua).oklch()[0]).toBeLessThanOrEqual(NIGHT_INK_MAX_L);
expect(chroma(aqua).oklch()[1]).toBeGreaterThan(0.08);
expect(patchRatio(aqua, 'night', true)).toBeGreaterThan(3.9);
// The one-patch figure is what the cap gives up; against the sky's own lightest (skyBackdrop) it clears AA.
expect((luminance(aqua) + 0.05) / (NIGHT_SKY_LIGHTEST + 0.05)).toBeGreaterThanOrEqual(AA);
});
it('leaves a colour that already clears its patch untouched, and a non-colour alone', () => {

View file

@ -8,8 +8,8 @@
// until it clears 4.5:1 (WCAG) against the LIGHTEST 24x12 patch of terrain under the timeline in that state
// and viewport. Measured 2026-11-10 on the demo's terrain scene at 1920x1080 and 390x844 (Chrome, SwiftShader,
// not a GPU; ratatoskr-sidebar-contrast-20261110/results.md, T3). These are the scene's own patches, not
// `skyBackdrop` (skyState.ts): that is the bare sky's extreme (day 0.90, dusk 0.97), which the terrain under the
// timeline never shows, and at night the terrain's snow (0.103, phone 0.149) is lighter than the sky (0.0816).
// 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.
import chroma from 'chroma-js';
import { AA, luminance } from '../../../sky/skyTokens.js';

View file

@ -1,13 +1,8 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { atStandardTime } from './standardTime.testkit';
import { baked } from '../../../sky/baked';
import { luminance } from '../../../sky/skyTokens.js';
import {
SKY_STATES,
SKY_STATE_KEY,
resolveSkyState,
setSkyClock,
skyBackdrop,
type SkyState,
} from './skyState';
@ -106,39 +101,6 @@ describe('sky state', () => {
});
});
describe('skyBackdrop', () => {
it('puts night below day and dusk', () => {
expect(skyBackdrop('night').lightest).toBeLessThan(skyBackdrop('day').darkest);
expect(skyBackdrop('night').lightest).toBeLessThan(skyBackdrop('dusk').lightest);
expect(skyBackdrop('dusk').lightest).toBeGreaterThanOrEqual(skyBackdrop('day').lightest);
});
it('holds the baked gradients for day and night', () => {
const lum = (g: readonly string[]) => g.map(luminance);
expect(skyBackdrop('day').lightest).toBeGreaterThanOrEqual(
Math.max(...lum(baked.noonday.gradient)) - 1e-9
);
expect(skyBackdrop('night').darkest).toBeLessThanOrEqual(
Math.min(...lum(baked.midnight.gradient)) + 1e-9
);
});
it('is the band of the sky auto resolves to, not the union of all three', () => {
const at = (h: number) => setSkyClock(() => atStandardTime(h, 0));
at(12);
expect(skyBackdrop('auto')).toEqual(skyBackdrop('day'));
at(0);
expect(skyBackdrop('auto')).toEqual(skyBackdrop('night'));
setSkyClock();
});
it('never has darkest above lightest', () => {
SKY_STATES.forEach((s) =>
expect(skyBackdrop(s).darkest).toBeLessThanOrEqual(skyBackdrop(s).lightest)
);
});
});
describe('auto follows the clock', () => {
const local = (h: number, m = 0) => atStandardTime(h, m); // local solar time ~ local clock
let storage: ReturnType<typeof fakeStorage>;

View file

@ -1,8 +1,7 @@
// Which sky the signed-out page is drawn against. The choice is one value, kept in one
// localStorage key; whoever draws the sky (the scene, the title bar's control) reads it here, and
// `skyBackdrop` says how light or dark the sky behind the login text can be in each state, so the
// text colours can be checked against it. 'auto' is a choice, not a sky: it resolves from the
// clock to day, dusk or night (`resolveSkyState`), and every sky drawn is one of those three.
// localStorage key; whoever draws the sky (the scene, the title bar's control) reads it here.
// 'auto' is a choice, not a sky: it resolves from the clock to day, dusk or night
// (`resolveSkyState`), and every sky drawn is one of those three.
import { sunElevation } from '../../../sky/sun.js';
export type SkyState = 'auto' | 'day' | 'dusk' | 'night';
@ -153,25 +152,3 @@ export function subscribe(cb: (s: FixedSkyState) => void): () => void {
sync();
};
}
/**
* Relative luminance (WCAG, 0..1) of the lightest and darkest sky the state can show behind the
* page. Light ink is worst against `lightest`, dark ink against `darkest`. 'auto' is the band of
* the sky it resolves to now.
*/
export interface SkyBackdrop {
readonly darkest: number;
readonly lightest: number;
}
// What the ridge sky can show behind the page in each state (its display budget, ridge/toneMap.ts `BUDGET`, holds whatever the
// sun's elevation; physicalSky.test.ts sweeps the sun's year against these). Held as constants so this module, which the main chunk
// loads, does not pull in the sky generator. The bounds are at least as wide as the budgets: the login text was checked against them.
// Bounds what the 8-bit screen shows too (one step each way for rounding and dither), rounded outward to six places.
const BACKDROPS: Record<FixedSkyState, SkyBackdrop> = {
day: { darkest: 0.461063, lightest: 1 },
dusk: { darkest: 0.460352, lightest: 1 },
night: { darkest: 0, lightest: 0.081642 },
};
export const skyBackdrop = (state: SkyState): SkyBackdrop => BACKDROPS[resolveSkyState(state)];

View file

@ -1,7 +1,7 @@
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';
import { AA, contrast } from '../../../sky/skyTokens.js';
import { Editor } from '../../components/editor/Editor.css';
import { PageContent, PageNavContent } from '../../components/page/style.css';
import { CallStatus } from '../call-status/styles.css';
@ -12,30 +12,17 @@ import { SkyPlate, plateRegions } from './skyPlate.css';
import {
getResolvedSkyState,
setSkyClock,
skyBackdrop,
subscribe as subscribeSky,
} from './skyState';
import type { FixedSkyState, SkyBackdrop } from './skyState';
import { sceneThemeId, skyThemeId } 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] : [];
});
// WCAG contrast of an ink against the sky it is worst on, measured as skyState.test.ts does: the
// sky can show any luminance between its darkest and lightest, and contrast is lowest where the
// backdrop is closest to the ink, which is the ink's own luminance clamped into that range.
const against = (ink: string, bg: number) => {
const li = luminance(ink);
const [hi, lo] = li > bg ? [li, bg] : [bg, li];
return (hi + 0.05) / (lo + 0.05);
};
const ratio = (ink: string, b: SkyBackdrop) =>
against(ink, Math.min(b.lightest, Math.max(b.darkest, luminance(ink))));
const r2 = (n: number) => n.toFixed(2);
describe('skyThemeId', () => {
it('picks a theme for each explicit state', () => {
expect(skyThemeId('day')).toBe('noonday-sky');
@ -102,61 +89,6 @@ describe('skyThemeId', () => {
});
});
describe('ink of the theme a state picks, on bare sky', () => {
// Per state: the picked theme, its text ink and link, and their WCAG ratios on the sky the scenes
// draw (skyBackdrop, the worst case over its band). Text clears 4.5 in every state. Link clears
// in every state: the links are derived in src/sky/skyTokens.js, outside the band, and these numbers are recorded as
// they are measured. Midnight's link is brightened in its own hue until it clears the lightest Night sky
// (NIGHT_SKY_LIGHTEST); Dusk's dark link needs a backdrop of about 0.4554, which the dusk floor is set above.
// 'auto' resolves from the clock to one of these three and has the same numbers.
const cells: [FixedSkyState, string, string, string, string, string][] = [
['day', 'noonday-sky', '#342d25', '6.60', '#2a4f27', '4.55'],
['dusk', 'noonday-sky', '#342d25', '6.59', '#2a4f27', '4.54'],
['night', 'midnight-sky', '#aeccff', '4.89', '#8ad1bd', '4.53'],
];
it.each(cells)(
'%s with %s: text %s is %s, link %s is %s',
(state, id, ink, want, link, wantLink) => {
const sky = SKY[id as keyof typeof SKY];
expect(sky.tokens.Background.OnContainer).toBe(ink);
expect(sky.link).toBe(link);
expect(r2(ratio(ink, skyBackdrop(state)))).toBe(want);
expect(r2(ratio(link, skyBackdrop(state)))).toBe(wantLink);
}
);
it.each(cells)('%s: text clears AA', (state, _id, ink) => {
expect(ratio(ink, skyBackdrop(state))).toBeGreaterThanOrEqual(AA);
});
it('link clears AA in every state', () => {
const link = (s: FixedSkyState, id: keyof typeof SKY) => ratio(SKY[id].link, skyBackdrop(s));
expect(link('day', 'noonday-sky')).toBeGreaterThanOrEqual(AA);
expect(link('dusk', 'noonday-sky')).toBeGreaterThanOrEqual(AA);
expect(link('night', 'midnight-sky')).toBeGreaterThanOrEqual(AA);
});
it('keeps the lightest Night sky the link was fitted to equal to the Night backdrop (no drift)', () => {
expect(NIGHT_SKY_LIGHTEST).toBe(skyBackdrop('night').lightest);
});
it.each([
[12, 'day'],
[18, 'dusk'],
[0, 'night'],
] as const)('auto at %s:00 has the numbers of %s', (hour, state) => {
setSkyClock(() => atStandardTime(hour, hour === 18 ? 10 : 0));
const id = skyThemeId(getResolvedSkyState()) as keyof typeof SKY;
expect(id).toBe(skyThemeId(state));
const { tokens, link } = SKY[id];
const text = tokens.Background.OnContainer;
expect(r2(ratio(text, skyBackdrop('auto')))).toBe(r2(ratio(text, skyBackdrop(state))));
expect(r2(ratio(link, skyBackdrop('auto')))).toBe(r2(ratio(link, skyBackdrop(state))));
setSkyClock();
});
});
describe('the plate, where text cannot rest on bare sky', () => {
// Each theme's plate: fill, ink, link and the WCAG ratios of ink and link on the fill.
const plates = [
@ -217,7 +149,7 @@ describe('regions that sit on the plate', () => {
describe('the sign-in footer band', () => {
// The footer line is the plate's ink on a band that mixes FOOTER_TINT of the plate's fill over the blurred scene,
// as the browser does: per channel, in encoded sRGB (not in linear light, which flatters dark scenes). The scene
// behind it is the scene, taken as grey: as dark as 0, as light as the sky state's lightest backdrop. Ink
// behind it is the scene, taken as grey: as dark as 0 or as light as 1 (a sky's range is whatever the look draws). Ink
// contrast is lowest at one of those two ends, so both are checked.
const encode = (l: number) => (l <= 0.0031308 ? 12.92 * l : 1.055 * l ** (1 / 2.4) - 0.055);
const channels = (hex: string) => [1, 3, 5].map((i) => parseInt(hex.slice(i, i + 2), 16) / 255);
@ -235,7 +167,7 @@ describe('the sign-in footer band', () => {
'%s: the ink clears AA over the darkest and the lightest scene behind it',
(state, id) => {
const { Other, OtherText } = SKY[id].bubbles;
[0, skyBackdrop(state).lightest].forEach((behind) => {
[0, 1].forEach((behind) => {
expect(contrast(OtherText, bandOver(Other, behind))).toBeGreaterThanOrEqual(AA);
});
}

View file

@ -19,8 +19,8 @@ const luma = (c) => 0.2126 * c[0] + 0.7152 * c[1] + 0.0722 * c[2];
export const GRADIENT_STOPS = 7;
export const AA = 4.5; // WCAG 2.x AA, normal text
// The lightest the Night sky draws behind the page (src/app/features/scene/skyState.ts, `skyBackdrop('night')`; a test in
// skyTheme.test.ts fails if the two drift). Midnight Sky's link also sits on bare sky, so it must clear AA against this.
// The Night sky's luminance the Midnight Sky link was fitted against (a derivation input, not a bound the scene is held to:
// the look is tuned by eye). The link is brightened in its own hue until it clears AA against this.
export const NIGHT_SKY_LIGHTEST = 0.081642;
// Where and when the theme is lit. Equinox, 45N on the prime meridian: noon sun at 45 degrees.