The sun¶
nilam derives and proves a whole palette from one number, the hue. Since 0.9.0 it takes a second: where the sun is.
Open it full-screen · drag the sky, press space to play the day.
A position t on a dial runs from deepest night (0) through noon (0.5) and back to night (1).
The page takes the light's tint, and every step, ink, status, the loader ramp, the shadows and
the rim are re-solved from that page by the same solver, under the same contracts. Then the
prover runs the full contract set at 97 positions. Nothing is excused.
At noon the result is the light palette you already have, to the last digit. At midnight it is the dark palette. Dark mode was never a switch; it is the night end of one continuous solve.
import { mountSun } from 'nilam/sun';
const sun = mountSun(document.documentElement, { hue: 285, t: 0.5 });
sun.set(0.3); // drag: at most one solve per animation frame
sun.follow('clock'); // local time drives it; 04:00 to 20:00 is the arc, outside is night
sun.unmount(); // back to the stylesheet's light-dark() tokens
Nothing else changes. The components read the same tokens they always did; the runtime writes
those tokens onto the element, plus --shadow-1..3, --rim, and the sun's own --sun,
--sun-el and --sun-az, and sets color-scheme to the measured mode so native controls follow.
Why the lights switch¶
Text is solved against the card, the worst surface it may sit on. The card sits 1.13:1 (light) or 1.17:1 (dark) from the page. With that step in the way, no ink reaches 7:1 while the page is between lightness 0.40 and 0.72, and for part of that band not even 4.5:1. That is not a property of nilam; it is WCAG's formula, which has no room in the middle.
So the dial never goes there. As the sun clears elevation 0.05 the page steps from the last legal dark value to the first legal light one in a single move, and the polarity flips with it. That is the one discontinuity in the system. Everything either side is continuous.
proveSun asserts it: at every sampled position the page is outside the band, the mode equals
what the page can actually carry, and every family passes every contract, 7:1 included.
What is chosen, and what is solved¶
Chosen: the shape of the day, the two page-lightness ramps, and the path the light's hue takes
at dusk — brand → violet → rose → amber, the order a real sunset runs, the short way round the
wheel through red and never through green. Those are the sun, and they are declared in
src/sun.mjs.
Solved: every colour, from those. Change a chosen curve so that a contract breaks anywhere on the dial and the build fails, naming the position.
Light physics¶
A shadow points away from the sun, lengthens and softens as the sun drops, and takes a little
of the sky's blue, because a shadow is lit by the sky and not by the sun. At noon the offset
is zero and the tint is black, so --shadow-1..3 are nilam.scale.css to the character.
In dark polarity the shadows are the scale's dark ones, untouched: they cannot be seen there
(Learn 6) and the rim does the work. A warm rim on the sun-facing edge
fades in within 0.3 of elevation of the horizon and is gone by midnight, so at both ends of the
dial --rim is again exactly the shipped value.
Honest limits¶
- It needs JavaScript. Without the module you have the stylesheet, which is the two ends of the dial. There is no CSS-only stepped fallback yet.
- sRGB only, live. The P3 palette is solved and proven at build time for the two ends and is not re-solved on the fly.
follow('clock')is a clock, not an ephemeris. A 16-hour arc from 04:00 to 20:00. Real sunrise needs latitude, longitude and a permission prompt, and this does not ask for one.- Writing the tokens replaces
light-dark()for the mounted subtree. A.darkisland inside it no longer flips on its own; the sun decides. - One shadow law. Long, soft shadows at low sun are the model. If your product wants the
calmer variant, mount the sun and override
--shadow-2and--shadow-3after it.
The defect the sun found¶
Steps 7, 8, 11 and 12 were solved against step 3 and asserted against both step 3 and the card. In light the card is white and step 3 is the harder ground, so the assertion on the card passed with room. In dark the card has step 3's lightness with the chroma removed, and at equal OKLab lightness an achromatic grey carries slightly more luminance than a violet or a red. The card was the harder ground. The shipped dark palette cleared "11 on surface" by 0.011 to 0.046.
Move the page toward dawn and the margin runs out: 4.45:1 on a card at t = 0.125. The solve now targets whichever ground is harder for the ink's direction. Forty-eight dark-mode values moved, by at most 0.0023 in lightness. Every visual baseline held within tolerance. It is the twenty-sixth defect found in this package, and the first found by the prover before a person.