@intentius/behold 0.29.41 → 0.29.43
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +32 -0
- package/dist/cli.js +111 -20
- package/package.json +1 -1
- package/web/app.js +12 -8
- package/web/carve-narration.js +32 -6
- package/web/carve-narration.test.js +31 -1
- package/web/dots-cards.js +362 -0
- package/web/dots-cards.test.js +303 -0
- package/web/dots.js +363 -74
- package/web/embed.js +16 -0
- package/web/embed.test.js +19 -1
- package/web/event-help-modal.js +1 -1
- package/web/index.html +192 -127
- package/web/kiosk-carve.js +26 -20
- package/web/kiosk-event-help-ui.js +1 -1
- package/web/kiosk-link.js +68 -0
- package/web/kiosk-link.test.js +69 -0
- package/web/kiosk-metrics.js +2 -2
- package/web/kiosk-trace.js +1 -1
- package/web/kiosk.html +186 -135
- package/web/kiosk.js +44 -1
- package/web/motion.js +42 -0
- package/web/motion.test.js +64 -0
- package/web/terralith.html +2 -2
- package/web/theme.js +99 -26
- package/web/theme.test.js +70 -6
- package/web/tooltip.js +212 -0
- package/web/tooltip.test.js +193 -0
- package/web/trunk-lane.js +160 -8
- package/web/trunk-lane.test.js +108 -1
package/web/kiosk.js
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
// A wave that failed says which waves applied before it and stay applied.
|
|
14
14
|
// Nothing here is all-or-nothing, and nothing says so.
|
|
15
15
|
|
|
16
|
+
import { linkState, linkWords, noteBack, noteRead, readFailed, shareLink } from "./kiosk-link.js";
|
|
16
17
|
import { CHANT_PANEL_STEPS, chantApprovalModel } from "./chant-pr-marks.js";
|
|
17
18
|
import { PICK_HOLD_MS, annMark, mergeRun, startRuns, statusIcon } from "./kiosk-runs.js";
|
|
18
19
|
import { MODES, MODE_STORE, badges as waveBadges, badgeTitle, behindStep, steadyRun, captionModel, doraLine, modeStored, placeBeside, resultModel, shotFor, stepTone, tailLines } from "./kiosk-watch.js";
|
|
@@ -2207,8 +2208,32 @@ export function startKiosk({ bar, frame, side, main, views, read = null, tools =
|
|
|
2207
2208
|
};
|
|
2208
2209
|
const CYCLE_REREAD_MS = 60_000;
|
|
2209
2210
|
|
|
2211
|
+
// behold#725: the stopped-updating cue. The demo poll and the event stream
|
|
2212
|
+
// report whether they came back; while one fails, a line over the header
|
|
2213
|
+
// says since when nothing has come in (web/kiosk-link.js).
|
|
2214
|
+
const link = linkState();
|
|
2215
|
+
let linkLine = null;
|
|
2216
|
+
let linkWas = null;
|
|
2217
|
+
const paintLink = () => {
|
|
2218
|
+
const words = linkWords(link);
|
|
2219
|
+
// The tour's live badge and its lag follow the cue (web/carve-narration.js liveBadge).
|
|
2220
|
+
if (words !== linkWas) { linkWas = words; shareLink(link); }
|
|
2221
|
+
if (!linkLine && !words) return;
|
|
2222
|
+
if (!linkLine) {
|
|
2223
|
+
const host = bar && bar.parentNode;
|
|
2224
|
+
if (!host || typeof document === "undefined" || !host.insertBefore) return;
|
|
2225
|
+
linkLine = el("p", "k-link");
|
|
2226
|
+
linkLine.setAttribute("role", "status");
|
|
2227
|
+
host.insertBefore(linkLine, bar);
|
|
2228
|
+
}
|
|
2229
|
+
linkLine.hidden = !words;
|
|
2230
|
+
linkLine.textContent = words || "";
|
|
2231
|
+
};
|
|
2232
|
+
|
|
2210
2233
|
const demo = async () => {
|
|
2211
2234
|
const live = await fetchJson("/api/terragucci/demo");
|
|
2235
|
+
noteRead(link, "poll", !readFailed(live), now());
|
|
2236
|
+
paintLink();
|
|
2212
2237
|
s.live = live;
|
|
2213
2238
|
if (!vendor) {
|
|
2214
2239
|
s.repo = live && live.demo ? live.demo.repo : null;
|
|
@@ -2238,6 +2263,17 @@ export function startKiosk({ bar, frame, side, main, views, read = null, tools =
|
|
|
2238
2263
|
|
|
2239
2264
|
if (typeof EventSource !== "undefined") {
|
|
2240
2265
|
const es = new EventSource("/api/terragucci/events");
|
|
2266
|
+
// behold#725: the browser retries a dropped stream by itself (CONNECTING);
|
|
2267
|
+
// one it closed for good (a 404, say) leaves the polls to carry the cue.
|
|
2268
|
+
es.addEventListener("open", () => { noteBack(link, "stream"); paintLink(); });
|
|
2269
|
+
es.addEventListener("error", () => {
|
|
2270
|
+
if (es.readyState === 2) noteBack(link, "stream");
|
|
2271
|
+
else noteRead(link, "stream", false, now());
|
|
2272
|
+
paintLink();
|
|
2273
|
+
});
|
|
2274
|
+
const heard = () => { noteRead(link, "stream", true, now()); paintLink(); };
|
|
2275
|
+
es.addEventListener("reports", heard);
|
|
2276
|
+
es.addEventListener("progress", heard);
|
|
2241
2277
|
es.addEventListener("reports", () => void reports(false));
|
|
2242
2278
|
es.addEventListener("progress", (e) => {
|
|
2243
2279
|
try {
|
|
@@ -2257,13 +2293,20 @@ export function startKiosk({ bar, frame, side, main, views, read = null, tools =
|
|
|
2257
2293
|
return s;
|
|
2258
2294
|
}
|
|
2259
2295
|
|
|
2296
|
+
// behold#725: `unreachable` marks a read that never got an answer, or got a
|
|
2297
|
+
// server error, so the stopped-updating cue can tell it from a source that
|
|
2298
|
+
// answered with an error of its own (kiosk-link.js readFailed).
|
|
2260
2299
|
async function defaultFetch(url) {
|
|
2261
2300
|
try {
|
|
2262
2301
|
const r = await fetch(url, { headers: { accept: "application/json" } });
|
|
2302
|
+
if (r.status >= 500) {
|
|
2303
|
+
const body = await r.json().catch(() => ({}));
|
|
2304
|
+
return { error: body.error || `${url} answered ${r.status}`, ...body, unreachable: true };
|
|
2305
|
+
}
|
|
2263
2306
|
const body = await r.json();
|
|
2264
2307
|
return r.ok ? body : { error: body.error || `${url} answered ${r.status}`, ...body };
|
|
2265
2308
|
} catch (e) {
|
|
2266
|
-
return { error: `${url}: ${e instanceof Error ? e.message : String(e)}
|
|
2309
|
+
return { error: `${url}: ${e instanceof Error ? e.message : String(e)}`, unreachable: true };
|
|
2267
2310
|
}
|
|
2268
2311
|
}
|
|
2269
2312
|
|
package/web/motion.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// behold#725: the page's motion, in one place. Every looping animation in
|
|
2
|
+
// index.html and kiosk.html runs on the root's --beat (a spinner turns once a
|
|
3
|
+
// beat, a pulse takes two), so they keep time with each other. This module
|
|
4
|
+
// marks the root with data-motion="paused" while the tab is hidden, and the
|
|
5
|
+
// stylesheets hold every animation where it is under that mark, so a tab in
|
|
6
|
+
// the background spends nothing on frames nobody sees. Reduced motion is the
|
|
7
|
+
// stylesheets' own business (prefers-reduced-motion); `motionReduced` is here
|
|
8
|
+
// for script that animates.
|
|
9
|
+
|
|
10
|
+
/** The beat in milliseconds: the stylesheets' --beat, for script that wants to keep time with them. */
|
|
11
|
+
export const BEAT_MS = 1200;
|
|
12
|
+
|
|
13
|
+
/** The mark the root carries while the tab is hidden; null when it is shown. */
|
|
14
|
+
export function motionMark(doc) {
|
|
15
|
+
return doc && doc.hidden ? "paused" : null;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** True when the viewer asked for reduced motion. */
|
|
19
|
+
export function motionReduced(win = typeof window !== "undefined" ? window : null) {
|
|
20
|
+
try {
|
|
21
|
+
return !!(win && win.matchMedia && win.matchMedia("(prefers-reduced-motion: reduce)").matches);
|
|
22
|
+
} catch {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Keep the root's data-motion in step with the tab's visibility. Returns a
|
|
29
|
+
* function that stops listening.
|
|
30
|
+
*/
|
|
31
|
+
export function installMotion(doc = typeof document !== "undefined" ? document : null) {
|
|
32
|
+
if (!doc || !doc.documentElement) return () => {};
|
|
33
|
+
const root = doc.documentElement;
|
|
34
|
+
const sync = () => {
|
|
35
|
+
const mark = motionMark(doc);
|
|
36
|
+
if (mark) root.setAttribute("data-motion", mark);
|
|
37
|
+
else root.removeAttribute("data-motion");
|
|
38
|
+
};
|
|
39
|
+
doc.addEventListener("visibilitychange", sync);
|
|
40
|
+
sync();
|
|
41
|
+
return () => doc.removeEventListener("visibilitychange", sync);
|
|
42
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { BEAT_MS, installMotion, motionMark, motionReduced } from "./motion.js";
|
|
3
|
+
|
|
4
|
+
// behold#725: a stand-in document, enough for installMotion: a hidden flag, a root's attributes, and its listeners.
|
|
5
|
+
const fakeDoc = (hidden = false) => {
|
|
6
|
+
const attrs = new Map();
|
|
7
|
+
const listeners = new Map();
|
|
8
|
+
return {
|
|
9
|
+
hidden,
|
|
10
|
+
documentElement: {
|
|
11
|
+
setAttribute: (k, v) => attrs.set(k, String(v)),
|
|
12
|
+
removeAttribute: (k) => attrs.delete(k),
|
|
13
|
+
getAttribute: (k) => (attrs.has(k) ? attrs.get(k) : null),
|
|
14
|
+
},
|
|
15
|
+
addEventListener: (type, fn) => listeners.set(type, fn),
|
|
16
|
+
removeEventListener: (type, fn) => { if (listeners.get(type) === fn) listeners.delete(type); },
|
|
17
|
+
fire: (type) => listeners.get(type) && listeners.get(type)(),
|
|
18
|
+
listening: (type) => listeners.has(type),
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
describe("the page's motion (behold#725)", () => {
|
|
23
|
+
it("keeps the stylesheets' beat", () => {
|
|
24
|
+
expect(BEAT_MS).toBe(1200);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("marks the root paused while the tab is hidden and clears the mark when it shows again", () => {
|
|
28
|
+
const doc = fakeDoc(false);
|
|
29
|
+
installMotion(doc);
|
|
30
|
+
expect(doc.documentElement.getAttribute("data-motion")).toBe(null);
|
|
31
|
+
doc.hidden = true;
|
|
32
|
+
doc.fire("visibilitychange");
|
|
33
|
+
expect(doc.documentElement.getAttribute("data-motion")).toBe("paused");
|
|
34
|
+
doc.hidden = false;
|
|
35
|
+
doc.fire("visibilitychange");
|
|
36
|
+
expect(doc.documentElement.getAttribute("data-motion")).toBe(null);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("starts paused on a page that opens in a background tab", () => {
|
|
40
|
+
const doc = fakeDoc(true);
|
|
41
|
+
installMotion(doc);
|
|
42
|
+
expect(doc.documentElement.getAttribute("data-motion")).toBe("paused");
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("stops listening when asked", () => {
|
|
46
|
+
const doc = fakeDoc(false);
|
|
47
|
+
const stop = installMotion(doc);
|
|
48
|
+
expect(doc.listening("visibilitychange")).toBe(true);
|
|
49
|
+
stop();
|
|
50
|
+
expect(doc.listening("visibilitychange")).toBe(false);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("does nothing without a document", () => {
|
|
54
|
+
expect(() => installMotion(null)()).not.toThrow();
|
|
55
|
+
expect(motionMark(null)).toBe(null);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("reads reduced motion from the media query, and a window that can't answer as no", () => {
|
|
59
|
+
expect(motionReduced({ matchMedia: (q) => ({ matches: q === "(prefers-reduced-motion: reduce)" }) })).toBe(true);
|
|
60
|
+
expect(motionReduced({ matchMedia: () => ({ matches: false }) })).toBe(false);
|
|
61
|
+
expect(motionReduced({ matchMedia: () => { throw new Error("no"); } })).toBe(false);
|
|
62
|
+
expect(motionReduced(null)).toBe(false);
|
|
63
|
+
});
|
|
64
|
+
});
|
package/web/terralith.html
CHANGED
|
@@ -11,11 +11,11 @@
|
|
|
11
11
|
<style>
|
|
12
12
|
/* The pre-paint fallback: Sea Shells' tokens (KIOSK_THEME in theme.js), which initTheme() replaces with the viewer's theme. */
|
|
13
13
|
:root {
|
|
14
|
-
--bg: #09141b; --panel: #1c2325; --line: #2c2e2d; --fg: #deb88d; --muted: #
|
|
14
|
+
--bg: #09141b; --panel: #1c2325; --line: #2c2e2d; --fg: #deb88d; --muted: #91877a; --ink2: #ceb395;
|
|
15
15
|
--edge: #4d483f; --managed: #027c9b; --foreign: #fca02f; --pending: #1e4950;
|
|
16
16
|
--degraded: #d15123; --neutral: #695e4e; --runtime: #50a3b5;
|
|
17
17
|
--rule: #3d4142; --focus: #364548; --active: #243235; --well: #01070d; --shadow: #010304;
|
|
18
|
-
--surface-box: #
|
|
18
|
+
--surface-box: #161a1d; --surface-pane-a: #1c2023; --surface-pane-b: #222629; --soft: #deb88d; --muted-ink: #9a9083;
|
|
19
19
|
--managed-ink: #0e7f9e; --foreign-ink: #fca02f; --pending-ink: #567b82; --runtime-ink: #50a3b5;
|
|
20
20
|
--font-ui: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
|
|
21
21
|
--font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
package/web/theme.js
CHANGED
|
@@ -148,10 +148,23 @@ function pushForContrast(hex, against, floor, dark) {
|
|
|
148
148
|
// actual message, so everything around them gives up chroma to let them land.
|
|
149
149
|
// Every one of them is still DERIVED: no chrome constant is a fixed colour, and
|
|
150
150
|
// all 552 palettes have to come out of here legible.
|
|
151
|
+
/** behold#725: the least contrast --muted and --muted-ink keep on the grounds they sit on (WCAG AA). */
|
|
152
|
+
export const MUTED_FLOOR = 4.5;
|
|
153
|
+
/** behold#725: the least contrast --ink2, the secondary prose ink, keeps on every ground (WCAG AAA). */
|
|
154
|
+
export const INK2_FLOOR = 7;
|
|
155
|
+
/** behold#725: how far --ink2 starts from --fg toward --bg before the floor holds it. */
|
|
156
|
+
export const INK2_EASE = 0.22;
|
|
157
|
+
|
|
151
158
|
export function tokensFor(th) {
|
|
152
159
|
const fgMix = (t) => mix(th.bg, th.fg, t);
|
|
153
160
|
const P = th.palette;
|
|
154
161
|
const panel = fgMix(0.09);
|
|
162
|
+
const kiosk = kioskSurfaces(th);
|
|
163
|
+
// The recessed ground (see `well` below), computed first so --ink2 can be held on it.
|
|
164
|
+
const well = (() => {
|
|
165
|
+
const b = hexToOklch(th.bg);
|
|
166
|
+
return oklchToHex({ ...b, L: clamp(b.L + (b.L < 0.16 ? 0.06 : -0.06), 0, 1) });
|
|
167
|
+
})();
|
|
155
168
|
// The active-control fill (tab strip, the picked option) — the panel pulled
|
|
156
169
|
// toward the accent, then pushed AWAY from the panel's own lightness so the
|
|
157
170
|
// fill is visible even on a palette whose blue slot happens to sit exactly at
|
|
@@ -173,8 +186,9 @@ export function tokensFor(th) {
|
|
|
173
186
|
// #240: secondary text needs an actual floor, not just "quieter than
|
|
174
187
|
// fg" — a handful of low-range palettes (Darkermatrix and friends) mix
|
|
175
188
|
// fg/panel close enough that the quieted 0.5 mix reads at ~1.25:1.
|
|
176
|
-
// Push its OKLCH L away from --panel's until it clears
|
|
177
|
-
|
|
189
|
+
// Push its OKLCH L away from --panel's until it clears MUTED_FLOOR
|
|
190
|
+
// (behold#725: 4.5:1, WCAG AA for body text; it was 3:1).
|
|
191
|
+
muted: pushForContrast(desaturate(fgMix(0.5), 0.75), panel, MUTED_FLOOR, th.dark),
|
|
178
192
|
edge: fgMix(0.32),
|
|
179
193
|
// The structural border — the panel shell, the pane edge, the footer rule.
|
|
180
194
|
// Tinted by the palette's OWN bright-black slot instead of being one more
|
|
@@ -190,10 +204,7 @@ export function tokensFor(th) {
|
|
|
190
204
|
// off the background (down, or UP on the near-black palettes where there is
|
|
191
205
|
// no "darker" left), keeping the bg's own hue so it never reads as a patch
|
|
192
206
|
// of a different theme.
|
|
193
|
-
well
|
|
194
|
-
const b = hexToOklch(th.bg);
|
|
195
|
-
return oklchToHex({ ...b, L: clamp(b.L + (b.L < 0.16 ? 0.06 : -0.06), 0, 1) });
|
|
196
|
-
})(),
|
|
207
|
+
well,
|
|
197
208
|
// Shadow/scrim base, used through color-mix() at the call site — a light
|
|
198
209
|
// theme's drop shadow must not be the same slab of black a dark one wants.
|
|
199
210
|
shadow: mix(th.bg, "#000000", th.dark ? 0.85 : 0.6),
|
|
@@ -211,10 +222,37 @@ export function tokensFor(th) {
|
|
|
211
222
|
// pending change).
|
|
212
223
|
runtime: th.palette[6], // cyan — runtime child (expected, not drift)
|
|
213
224
|
cat: [1, 2, 3, 4, 5, 6, 9, 10, 11, 12, 13, 14].map((i) => th.palette[i]),
|
|
214
|
-
...
|
|
225
|
+
...kiosk,
|
|
226
|
+
ink2: ink2For(th, ink2Grounds(th, { panel, well, kiosk })),
|
|
215
227
|
};
|
|
216
228
|
}
|
|
217
229
|
|
|
230
|
+
/**
|
|
231
|
+
* behold#725: every ground --ink2 is read on: the page, the app's panel and
|
|
232
|
+
* well, the kiosk's surfaces, and each of those under the zebra tint.
|
|
233
|
+
*/
|
|
234
|
+
export function ink2Grounds(th, { panel, well, kiosk }) {
|
|
235
|
+
const plain = [th.bg, panel, well, kiosk.surfaceBox, kiosk.surfacePaneA, kiosk.surfacePaneB];
|
|
236
|
+
return [...plain, ...plain.map((g) => mix(g, th.fg, ZEBRA))];
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* behold#725: the secondary prose ink. Sentences that sit under a heading or
|
|
241
|
+
* beside a value read in it, where --muted stays for keys and captions. It is
|
|
242
|
+
* --fg eased INK2_EASE of the way toward --bg, then pushed back until it
|
|
243
|
+
* clears INK2_FLOOR on every ground. Where --fg itself sits under the floor
|
|
244
|
+
* (a low-contrast palette), the push goes past --fg, as far as the gamut
|
|
245
|
+
* allows.
|
|
246
|
+
*/
|
|
247
|
+
function ink2For(th, grounds) {
|
|
248
|
+
const up = hexToOklch(th.fg).L >= hexToOklch(th.bg).L;
|
|
249
|
+
const pushed = pushAll(mix(th.fg, th.bg, INK2_EASE), grounds, INK2_FLOOR, up);
|
|
250
|
+
if (worstOn(pushed, grounds) >= INK2_FLOOR) return pushed;
|
|
251
|
+
// A mid-tone palette (Grass, Hot Dog Stand and nine others) where not even
|
|
252
|
+
// white or black reaches the floor on every ground: the best of the three.
|
|
253
|
+
return [pushed, "#ffffff", "#000000"].reduce((a, b) => (worstOn(b, grounds) > worstOn(a, grounds) + 0.01 ? b : a));
|
|
254
|
+
}
|
|
255
|
+
|
|
218
256
|
// --- the kiosk's surfaces (behold#571) -------------------------------------
|
|
219
257
|
// The kiosk lays several panes side by side; on one flat near-black they run
|
|
220
258
|
// together. Each region gets its own calm level instead: the page, a step up
|
|
@@ -230,6 +268,12 @@ export const SURFACE_STEPS = { box: 0.03, paneA: 0.055, paneB: 0.08 };
|
|
|
230
268
|
export const SOFT_CEILING = 13;
|
|
231
269
|
/** The least OKLCH lightness between two neighbouring levels, so each reads as its own box. */
|
|
232
270
|
export const MIN_STEP = 0.02;
|
|
271
|
+
/**
|
|
272
|
+
* behold#725: the share of --bg's OKLCH chroma the derived surfaces keep. A
|
|
273
|
+
* saturated ground (a deep blue or red) stacked three steps high reads loud;
|
|
274
|
+
* the surfaces keep its hue at under half its colour. --bg itself is left alone.
|
|
275
|
+
*/
|
|
276
|
+
export const SURFACE_CHROMA = 0.4;
|
|
233
277
|
|
|
234
278
|
/** The root dots' hues, by theme (behold#571): violet, orange, orchid, silver, tan. Never a state's. */
|
|
235
279
|
export const ROOT_HUES = {
|
|
@@ -255,7 +299,8 @@ function pushAll(hex, against, floor, dark) {
|
|
|
255
299
|
* on a light one; the other way where the palette leaves no room), `zebra`
|
|
256
300
|
* (the tint list rows alternate with), `soft` (body ink: --fg, eased toward
|
|
257
301
|
* --bg where it would glare, and never under 4.5:1 on any surface or zebra
|
|
258
|
-
* row), `mutedInk` (
|
|
302
|
+
* row), `mutedInk` (keys and captions, MUTED_FLOOR on all of them; behold#725
|
|
303
|
+
* raised it from 3:1), each state colour's
|
|
259
304
|
* `*Ink` (3:1 on all of them) and `roots` (the root dots, 3:1 on all of them).
|
|
260
305
|
*/
|
|
261
306
|
export function kioskSurfaces(th) {
|
|
@@ -275,13 +320,14 @@ export function kioskSurfaces(th) {
|
|
|
275
320
|
// Each level at least MIN_STEP of OKLCH lightness past the one before, as the
|
|
276
321
|
// colour rounds to 8 bits (near black, small steps all round to #000000).
|
|
277
322
|
const levels = [];
|
|
323
|
+
const ground = { ...b, C: b.C * SURFACE_CHROMA };
|
|
278
324
|
let prev = b.L;
|
|
279
325
|
for (const dl of [SURFACE_STEPS.box, SURFACE_STEPS.paneA - SURFACE_STEPS.box, SURFACE_STEPS.paneB - SURFACE_STEPS.paneA]) {
|
|
280
326
|
let want = prev + dir * dl;
|
|
281
|
-
let hex = oklchToHex({ ...
|
|
327
|
+
let hex = oklchToHex({ ...ground, L: clamp(want, 0, 1) });
|
|
282
328
|
for (let i = 0; i < 40 && Math.abs(hexToOklch(hex).L - prev) < MIN_STEP; i++) {
|
|
283
329
|
want += dir * 0.005;
|
|
284
|
-
hex = oklchToHex({ ...
|
|
330
|
+
hex = oklchToHex({ ...ground, L: clamp(want, 0, 1) });
|
|
285
331
|
}
|
|
286
332
|
levels.push(hex);
|
|
287
333
|
prev = hexToOklch(hex).L;
|
|
@@ -302,7 +348,7 @@ export function kioskSurfaces(th) {
|
|
|
302
348
|
soft = mix(th.fg, th.bg, lo);
|
|
303
349
|
}
|
|
304
350
|
soft = pushAll(soft, grounds, 4.5, lightInk);
|
|
305
|
-
const muted = pushAll(desaturate(mix(th.bg, th.fg, 0.5), 0.75), grounds,
|
|
351
|
+
const muted = pushAll(desaturate(mix(th.bg, th.fg, 0.5), 0.75), grounds, MUTED_FLOOR, lightInk);
|
|
306
352
|
const P = th.palette;
|
|
307
353
|
const ink = (c) => pushAll(c, grounds, 3, lightInk);
|
|
308
354
|
const hues = th.dark ? ROOT_HUES.dark : ROOT_HUES.light;
|
|
@@ -325,7 +371,7 @@ export function kioskSurfaces(th) {
|
|
|
325
371
|
// CSS custom properties behold's chrome (:root) reads. The pre-paint fallback
|
|
326
372
|
// block in index.html mirrors these for the DEFAULT theme — smoke/ui-smoke.mjs
|
|
327
373
|
// recomputes it from here and fails if the two ever drift apart.
|
|
328
|
-
const CSS_VARS = ["bg", "panel", "line", "fg", "muted", "edge", "managed", "foreign", "pending", "degraded", "neutral", "runtime", "rule", "focus", "active", "well", "shadow"];
|
|
374
|
+
const CSS_VARS = ["bg", "panel", "line", "fg", "muted", "ink2", "edge", "managed", "foreign", "pending", "degraded", "neutral", "runtime", "rule", "focus", "active", "well", "shadow"];
|
|
329
375
|
// behold#571: the kiosk's surfaces and ink, as --surface-box, --soft, --managed-ink and the like; the root dots as --root-0 … --root-4.
|
|
330
376
|
const KIOSK_VARS = { surfaceBox: "surface-box", surfacePaneA: "surface-pane-a", surfacePaneB: "surface-pane-b", zebra: "zebra", soft: "soft", mutedInk: "muted-ink", managedInk: "managed-ink", foreignInk: "foreign-ink", pendingInk: "pending-ink", degradedInk: "degraded-ink", runtimeInk: "runtime-ink" };
|
|
331
377
|
|
|
@@ -497,24 +543,51 @@ export function getTokens() { return _tokens; }
|
|
|
497
543
|
export function getThemeName() { return _active && _active.name; }
|
|
498
544
|
export function onThemeChange(cb) { _subs.add(cb); return () => _subs.delete(cb); }
|
|
499
545
|
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
if (
|
|
509
|
-
|
|
546
|
+
/**
|
|
547
|
+
* behold#725: every custom property applyTheme sets for `tokens`, as
|
|
548
|
+
* { "--name": value }. One list, so the page and the pre-paint copy
|
|
549
|
+
* (paintFor) can't drift apart.
|
|
550
|
+
*/
|
|
551
|
+
export function themeVars(tokens, th = _active) {
|
|
552
|
+
const vars = {};
|
|
553
|
+
for (const k of CSS_VARS) vars["--" + k] = tokens[k];
|
|
554
|
+
for (const [k, v] of Object.entries(KIOSK_VARS)) if (tokens[k]) vars["--" + v] = tokens[k];
|
|
555
|
+
(tokens.roots || []).forEach((c, i) => { vars[`--root-${i}`] = c; });
|
|
556
|
+
if (th) {
|
|
557
|
+
const pin = pinTokensFor(th);
|
|
558
|
+
for (const k of PIN_VARS) vars["--pin-" + k] = pin[k];
|
|
559
|
+
// behold#571: the state colours the graph frame draws as text and lines, legible on every ground (frameInks).
|
|
560
|
+
const inks = frameInks(th);
|
|
510
561
|
for (const k of FRAME_STATES) {
|
|
511
|
-
|
|
512
|
-
|
|
562
|
+
vars["--frame-" + k] = inks.box[k];
|
|
563
|
+
vars["--frame-card-" + k] = inks.card[k];
|
|
513
564
|
}
|
|
514
565
|
// behold#571: the left bars' colours, shared by the app, the kiosk and the lanes strip (barInks).
|
|
515
|
-
for (const [k, v] of Object.entries(barVars(
|
|
566
|
+
for (const [k, v] of Object.entries(barVars(th))) vars["--" + k] = v;
|
|
516
567
|
}
|
|
517
|
-
|
|
568
|
+
return vars;
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
/**
|
|
572
|
+
* behold#725: where applyTheme keeps the last theme it painted, for the
|
|
573
|
+
* inline script at the top of index.html and kiosk.html. theme.js is a module
|
|
574
|
+
* and runs after the first frame, so a viewer's own theme would open on the
|
|
575
|
+
* page's default for a moment. That script reads this record first and
|
|
576
|
+
* applies it when it belongs to the stored theme.
|
|
577
|
+
*/
|
|
578
|
+
export const PAINT_KEY = "behold.theme.paint";
|
|
579
|
+
/** The record applyTheme keeps under PAINT_KEY. */
|
|
580
|
+
export function paintFor(tokens, th = _active) {
|
|
581
|
+
return { name: th ? th.name : null, scheme: tokens.dark ? "dark" : "light", vars: themeVars(tokens, th) };
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
export function applyTheme(tokens = _tokens) {
|
|
585
|
+
if (!tokens || typeof document === "undefined") return;
|
|
586
|
+
const root = document.documentElement;
|
|
587
|
+
const paint = paintFor(tokens, _active);
|
|
588
|
+
for (const [k, v] of Object.entries(paint.vars)) root.style.setProperty(k, v);
|
|
589
|
+
root.style.setProperty("color-scheme", paint.scheme);
|
|
590
|
+
try { localStorage.setItem(PAINT_KEY, JSON.stringify(paint)); } catch { /* private mode or a full store: the next load opens on the default first */ }
|
|
518
591
|
}
|
|
519
592
|
|
|
520
593
|
export function setTheme(nameOrObj, { persist = true } = {}) {
|
package/web/theme.test.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
// sweeps all 552 palettes for the same assertion; this pins the exact
|
|
7
7
|
// palette the issue was filed against, with no browser involved.
|
|
8
8
|
import { describe, it, expect } from "vitest";
|
|
9
|
-
import { BAR_FLOOR, BAR_STATES, FRAME_STATES, MIN_STEP, barGrounds, barInks, barVars, SOFT_CEILING, ZEBRA, contrast, desaturate, frameGrounds, frameInks, hexToOklch, mix, pinTokensFor, tokensFor } from "./theme.js";
|
|
9
|
+
import { BAR_FLOOR, BAR_STATES, FRAME_STATES, INK2_FLOOR, MIN_STEP, MUTED_FLOOR, SURFACE_CHROMA, barGrounds, barInks, barVars, SOFT_CEILING, ZEBRA, contrast, desaturate, frameGrounds, frameInks, hexToOklch, ink2Grounds, mix, PAINT_KEY, paintFor, pinTokensFor, tokensFor } from "./theme.js";
|
|
10
10
|
import { THEMES } from "./themes.js";
|
|
11
11
|
|
|
12
12
|
describe("tokensFor — the --muted contrast floor (#240)", () => {
|
|
@@ -21,16 +21,48 @@ describe("tokensFor — the --muted contrast floor (#240)", () => {
|
|
|
21
21
|
expect(ratio).toBeLessThan(1.3);
|
|
22
22
|
});
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
// behold#725 raised the floor from 3:1 to 4.5:1.
|
|
25
|
+
it("clears the 4.5:1 floor on Darkermatrix after the push", () => {
|
|
26
|
+
expect(MUTED_FLOOR).toBe(4.5);
|
|
25
27
|
const t = tokensFor(THEMES["Darkermatrix"]);
|
|
26
|
-
expect(contrast(t.muted, t.panel)).toBeGreaterThanOrEqual(
|
|
28
|
+
expect(contrast(t.muted, t.panel)).toBeGreaterThanOrEqual(4.5);
|
|
27
29
|
});
|
|
28
30
|
|
|
29
31
|
it("holds the floor across every shipped palette, not just the one reported", () => {
|
|
32
|
+
const short = Object.values(THEMES).map((th) => [th.name, tokensFor(th)]).filter(([, t]) => contrast(t.muted, t.panel) < 4.5).map(([n, t]) => `${n} ${contrast(t.muted, t.panel).toFixed(2)}`);
|
|
33
|
+
expect(short).toEqual([]);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// behold#725: --ink2, the secondary prose ink, between --fg and --muted.
|
|
38
|
+
describe("tokensFor — the --ink2 level (behold#725)", () => {
|
|
39
|
+
const worst = (c, gs) => Math.min(...gs.map((g) => contrast(c, g)));
|
|
40
|
+
|
|
41
|
+
it("reads at 7:1 or better on every ground, or, where neither white nor black can, as well as the better of them", () => {
|
|
42
|
+
expect(INK2_FLOOR).toBe(7);
|
|
43
|
+
const bad = [];
|
|
30
44
|
for (const th of Object.values(THEMES)) {
|
|
31
45
|
const t = tokensFor(th);
|
|
32
|
-
|
|
46
|
+
const gs = ink2Grounds(th, { panel: t.panel, well: t.well, kiosk: t });
|
|
47
|
+
const w = worst(t.ink2, gs);
|
|
48
|
+
const reach = Math.max(worst("#ffffff", gs), worst("#000000", gs));
|
|
49
|
+
if (w < 7 && w < reach - 0.05) bad.push(`${th.name} ${t.ink2} ${w.toFixed(2)} (white or black reach ${reach.toFixed(2)})`);
|
|
33
50
|
}
|
|
51
|
+
expect(bad).toEqual([]);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("sits between --muted and --fg on Catppuccin Mocha, quieter than --fg and louder than --muted", () => {
|
|
55
|
+
const t = tokensFor(THEMES["Catppuccin Mocha"]);
|
|
56
|
+
expect(t.ink2).not.toBe(t.fg);
|
|
57
|
+
expect(contrast(t.ink2, t.panel)).toBeLessThan(contrast(t.fg, t.panel));
|
|
58
|
+
expect(contrast(t.ink2, t.panel)).toBeGreaterThan(contrast(t.muted, t.panel));
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("is held on the page, the app's panel and well, the kiosk's surfaces and their zebra rows", () => {
|
|
62
|
+
const th = THEMES["Sea Shells"];
|
|
63
|
+
const t = tokensFor(th);
|
|
64
|
+
const gs = ink2Grounds(th, { panel: t.panel, well: t.well, kiosk: t });
|
|
65
|
+
for (const g of [th.bg, t.panel, t.well, t.surfaceBox, t.surfacePaneA, t.surfacePaneB, mix(t.surfacePaneB, th.fg, ZEBRA)]) expect(gs).toContain(g);
|
|
34
66
|
});
|
|
35
67
|
});
|
|
36
68
|
|
|
@@ -55,8 +87,21 @@ describe("tokensFor — the kiosk's surfaces (behold#571)", () => {
|
|
|
55
87
|
expect(each((t, _th, { grounds }) => grounds.filter((g) => contrast(t.soft, g) < 4.5).map((g) => `${t.soft} on ${g} is ${contrast(t.soft, g).toFixed(2)}`)[0])).toEqual([]);
|
|
56
88
|
});
|
|
57
89
|
|
|
58
|
-
|
|
59
|
-
|
|
90
|
+
// behold#725 raised the floor from 3:1 to 4.5:1.
|
|
91
|
+
it("keeps secondary ink at 4.5:1 or better on every surface and zebra row", () => {
|
|
92
|
+
expect(each((t, _th, { grounds }) => grounds.filter((g) => contrast(t.mutedInk, g) < 4.5).map((g) => `${t.mutedInk} on ${g} is ${contrast(t.mutedInk, g).toFixed(2)}`)[0])).toEqual([]);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
// behold#725: a saturated ground stacked three levels high reads loud, so the surfaces keep under half its colour.
|
|
96
|
+
it("keeps at most SURFACE_CHROMA of --bg's chroma on each derived surface, and leaves --bg alone", () => {
|
|
97
|
+
expect(SURFACE_CHROMA).toBe(0.4);
|
|
98
|
+
expect(each((t, th) => {
|
|
99
|
+
expect(t.bg).toBe(th.bg);
|
|
100
|
+
const c = hexToOklch(th.bg).C;
|
|
101
|
+
// 8-bit rounding moves chroma a little, most of all near black.
|
|
102
|
+
const over = [t.surfaceBox, t.surfacePaneA, t.surfacePaneB].find((s) => hexToOklch(s).C > c * SURFACE_CHROMA + 0.012);
|
|
103
|
+
return over ? `${over} keeps ${hexToOklch(over).C.toFixed(3)} of ${c.toFixed(3)}` : null;
|
|
104
|
+
})).toEqual([]);
|
|
60
105
|
});
|
|
61
106
|
|
|
62
107
|
it("keeps the state colours and the root colours at 3:1 or better on every surface and zebra row", () => {
|
|
@@ -193,3 +238,22 @@ describe("the left bars (behold#571)", () => {
|
|
|
193
238
|
expect(contrast(barInks(th).neutral, t.surfacePaneB)).toBeGreaterThanOrEqual(3);
|
|
194
239
|
});
|
|
195
240
|
});
|
|
241
|
+
|
|
242
|
+
// behold#725: the record the pre-paint script in index.html and kiosk.html applies before theme.js runs.
|
|
243
|
+
describe("paintFor — the theme before first paint (behold#725)", () => {
|
|
244
|
+
it("names the theme, its colour scheme and every custom property applyTheme sets, --ink2 and the bars among them", () => {
|
|
245
|
+
const th = THEMES["Sea Shells"];
|
|
246
|
+
const t = tokensFor(th);
|
|
247
|
+
const p = paintFor(t, th);
|
|
248
|
+
expect(PAINT_KEY).toBe("behold.theme.paint");
|
|
249
|
+
expect(p.name).toBe("Sea Shells");
|
|
250
|
+
expect(p.scheme).toBe(th.dark ? "dark" : "light");
|
|
251
|
+
expect(p.vars["--ink2"]).toBe(t.ink2);
|
|
252
|
+
expect(p.vars["--muted"]).toBe(t.muted);
|
|
253
|
+
expect(p.vars["--surface-pane-a"]).toBe(t.surfacePaneA);
|
|
254
|
+
expect(p.vars["--bar-neutral"]).toBe(barInks(th).neutral);
|
|
255
|
+
expect(p.vars["--frame-focus"]).toBe(frameInks(th).box.focus);
|
|
256
|
+
expect(Object.keys(p.vars).every((k) => k.startsWith("--"))).toBe(true);
|
|
257
|
+
expect(JSON.parse(JSON.stringify(p))).toEqual(p);
|
|
258
|
+
});
|
|
259
|
+
});
|