Watch
0
0
Fork
You've already forked hyperhive
0

swarm ui: the context limit zones line up with their handles and legend

The zones were drawn by percentage of the full track, but a range input's thumb travels its own range less one thumb width, and the range starts at 5. So the colour edges sat off the handles. The zones now follow the thumb's travel (a tested helper in soft-context), and the Firefox thumb has the same size as the other. The legend bars had no colour either, as the item rule reset the border colour; their rule is now more specific.
This commit is contained in:
iris 2026-11-18 22:11:04 +01:00 • committed by mara
commit d4dc8b48b1
4 changed files with 44 additions and 11 deletions

View file

@ -1,4 +1,8 @@
/* <ContextLimits> — one track with three zones and two thumbs over it. */
/* <ContextLimits> — one track with three zones and two thumbs over it. A range
input's thumb travels the track less one thumb width, its centre running from
half a thumb in to half a thumb short of the far end, so the zone edges sit at
the same spots: a place `p` along the range (0 to 100, `along` in
`soft-context.ts`) is at `calc(thumb / 2 + (100% - thumb) * p / 100)`. */
.ui-context-limits {
box-sizing: border-box;
width: 100%;
@ -14,6 +18,11 @@
}
.ui-context-limits-track {
--thumb: 1em;
--fresh-at: calc(
var(--thumb) / 2 + (100% - var(--thumb)) * var(--fresh) / 100
);
--soft-at: calc(var(--thumb) / 2 + (100% - var(--thumb)) * var(--soft) / 100);
position: relative;
height: 1.8em;
margin: 0.4em 0 0.6em;
@ -30,9 +39,10 @@
border-radius: 0.3em;
background: linear-gradient(
to right,
color-mix(in srgb, var(--muted) 40%, transparent) 0 var(--fresh),
color-mix(in srgb, var(--green) 60%, transparent) var(--fresh) var(--soft),
color-mix(in srgb, var(--purple) 65%, transparent) var(--soft) 100%
color-mix(in srgb, var(--muted) 40%, transparent) 0 var(--fresh-at),
color-mix(in srgb, var(--green) 60%, transparent) var(--fresh-at)
var(--soft-at),
color-mix(in srgb, var(--purple) 65%, transparent) var(--soft-at) 100%
);
}
@ -58,7 +68,8 @@
pointer-events: auto;
-webkit-appearance: none;
appearance: none;
width: 1em;
box-sizing: border-box;
width: var(--thumb);
height: 1.6em;
border: 2px solid var(--fg);
border-radius: 0.35em;
@ -67,8 +78,9 @@
}
.ui-context-limits-handle::-moz-range-thumb {
pointer-events: auto;
width: 0.8em;
height: 1.4em;
box-sizing: border-box;
width: var(--thumb);
height: 1.6em;
border: 2px solid var(--fg);
border-radius: 0.35em;
background: var(--bg-elev);
@ -120,10 +132,12 @@
padding-inline-start: 0.6em;
border-inline-start: 3px solid transparent;
}
.ui-context-limits-legend-fresh {
/* Under `.ui-context-limits-legend li` for specificity: that rule's shorthand
would otherwise leave the bar clear. */
.ui-context-limits-legend .ui-context-limits-legend-fresh {
border-inline-start-color: var(--green);
}
.ui-context-limits-legend-soft {
.ui-context-limits-legend .ui-context-limits-legend-soft {
border-inline-start-color: var(--purple);
}
.ui-context-limits-source {

View file

@ -9,6 +9,7 @@
// Two native range inputs sit one over the other, so the keyboard and screen
// readers get two sliders; the track and its three zones are drawn behind them.
import {
along,
clampFresh,
clampSoft,
DEFAULT_FRESH_SESSION_PERCENT,
@ -41,8 +42,8 @@ export function ContextLimits({
<div
class="ui-context-limits-track"
style={{
"--fresh": `${limits.fresh}%`,
"--soft": `${limits.soft}%`,
"--fresh": String(along(limits.fresh)),
"--soft": String(along(limits.soft)),
}}
>
<div class="ui-context-limits-zones" aria-hidden="true" />

View file

@ -25,6 +25,16 @@ export function softContextValue(text: string): number | null | undefined {
: null;
}
/** How far along the slider's range a percentage sits, 0 to 100: the thumb's
* place, which the zones behind the slider are drawn to meet. */
export function along(percent: number): number {
return (
((percent - MIN_SOFT_CONTEXT_PERCENT) /
(MAX_SOFT_CONTEXT_PERCENT - MIN_SOFT_CONTEXT_PERCENT)) *
100
);
}
/** What the harness uses for the fresh-session threshold when none is set. */
export const DEFAULT_FRESH_SESSION_PERCENT = 50;
/** What the harness uses for the soft limit when none is set. */

View file

@ -3,6 +3,7 @@
import assert from "node:assert/strict";
import { test } from "node:test";
import {
along,
MAX_SOFT_CONTEXT_PERCENT,
MIN_SOFT_CONTEXT_PERCENT,
softContextValue,
@ -26,6 +27,13 @@ test("a whole percent from 5 to 100 is taken", () => {
);
});
test("a percentage sits along the slider's range, not the full track", () => {
assert.equal(along(MIN_SOFT_CONTEXT_PERCENT), 0);
assert.equal(along(MAX_SOFT_CONTEXT_PERCENT), 100);
assert.equal(along(52.5), 50);
assert.ok(along(50) < 50);
});
test("anything else is refused", () => {
for (const text of ["0", "4", "101", "-20", "20.5", "abc", "1e1", "20%"]) {
assert.equal(softContextValue(text), null, text);