@popcorn245/cornfield 0.34.1 → 0.34.3

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/core/contrast.js CHANGED
@@ -23,6 +23,8 @@ import path from 'node:path';
23
23
  import { fileURLToPath } from 'node:url';
24
24
  import { MAX_MIX_DEPTH, readColor, over, toHex, luminance, ratio, splitTop } from './color.js';
25
25
  import { MAX_THEME_BYTES, cssProblems, withoutComments } from './theme.js';
26
+ import { DIFF_MARK_COLORS, DIFF_LABEL_ALPHA, markOpacity } from '../explorer/diff-marks.js';
27
+ import { lightColor } from '../explorer/theme-model.js';
26
28
 
27
29
  /** WCAG 2.1 AA: text, and large text and user-interface parts */
28
30
  export const MIN_TEXT = 4.5;
@@ -397,6 +399,9 @@ export const UI_PAIRS = Object.freeze([
397
399
  ...['--corn-ok', '--corn-edit-text', '--corn-bad', '--corn-warn', '--corn-text-3'].flatMap((fg) => ['--corn-surface-2', '--corn-surface-3'].map((bg) => [fg, bg, 'a state pill\'s border'])),
398
400
  ]);
399
401
 
402
+ /** The dots that name a diff mark in the bar, the change list and the legend (explorer.css `.hx-mark-dot--*`), each a ring on the ground */
403
+ const DIFF_DOT_PAIRS = Object.freeze(['added', 'changed', 'removed', 'edit'].map((m) => [`--corn-${m}`, GROUND, `the ${m} mark's dot`]));
404
+
400
405
  /**
401
406
  * Every pair that is read against each other: `{ fg, bg, min, kind, use? }`, `fg` and `bg` each a token or a CSS colour value. A pair
402
407
  * listed twice is checked once, at the higher minimum. How a translucent `bg` is composited: see checkState.
@@ -415,6 +420,7 @@ export function contrastPairs() {
415
420
  for (const bg of SOLID_FILLS) add(GROUND, bg, MIN_TEXT, 'text');
416
421
  for (const [fg, bg] of PAINTED_TEXT) add(fg, bg, MIN_TEXT, 'text');
417
422
  for (const [fg, bg, use] of UI_PAIRS) add(fg, bg, MIN_UI, 'ui', use);
423
+ for (const [fg, bg, use] of DIFF_DOT_PAIRS) add(fg, bg, MIN_UI, 'ui', use);
418
424
  return [...pairs.values()];
419
425
  }
420
426
 
@@ -500,6 +506,62 @@ function checkState(props, theme, mode) {
500
506
  const { image, ...rest } = worst;
501
507
  out.push({ ...finding, ...rest, ...(image ? { groundImage: true } : {}) });
502
508
  }
509
+ out.push(...diffMapFindings(props, theme, mode, grounds, isColor(g) ? over(g, canvas) : null));
510
+ return out;
511
+ }
512
+
513
+ // ---------------------------------------------------------------------------
514
+ // The map's diff marks and dimmed labels (0.34 review, F19 and F23)
515
+ //
516
+ // The canvas draws a proposal's marks in `--corn-map-added|changed|removed|edit` (`auto` is the default look, explorer/diff-marks.js)
517
+ // and a label a diff dims at DIFF_LABEL_ALPHA. Each is read at 3:1 against every ground the map draws: the ground, each glow of
518
+ // `--corn-ground-image` at its strongest, and all of them laid over each other (the darkest and the lightest the map shows), at the
519
+ // opacity it is drawn at (a removed mark is faded, an edge is never fainter than EDGE_MIN_ALPHA). Nothing here reads node fills:
520
+ // those are another check.
521
+ // ---------------------------------------------------------------------------
522
+
523
+ /** Every ground the map can show: the page ground, each glow at its peak over it, and all the glows stacked */
524
+ function mapGrounds(grounds, base, props) {
525
+ const out = grounds.map((x) => ({ ...x }));
526
+ if (base && props.has('--corn-ground-image')) {
527
+ const r = expand('var(--corn-ground-image)', props);
528
+ if ('text' in r) {
529
+ let stack = base;
530
+ for (const layer of layerTexts(r.text).slice(0, 16)) {
531
+ let peak = null;
532
+ for (const c of colorsIn(layer, 0)) if (!peak || c[3] > peak[3]) peak = c;
533
+ if (peak && peak[3] > 0) stack = over(peak, stack);
534
+ }
535
+ if (stack !== base) out.push({ color: stack, image: true });
536
+ }
537
+ }
538
+ return out;
539
+ }
540
+
541
+ /** The pairs the map's diff marks make: `[token, default colour (auto), opacity, what it is]` */
542
+ const DIFF_MAP_PAIRS = (mode) => [
543
+ ...['added', 'changed', 'removed', 'edit'].map((m) => [`--corn-map-${m}`, DIFF_MARK_COLORS[mode][m], markOpacity(m), `the ${m} mark on the map, drawn at ${Math.round(markOpacity(m) * 100)}% opacity`]),
544
+ ['--corn-map-label', mode === 'light' ? lightColor('#f8fafc', 'text') : '#f8fafc', DIFF_LABEL_ALPHA, `a label the diff dims, drawn at ${Math.round(DIFF_LABEL_ALPHA * 100)}% opacity`],
545
+ ];
546
+
547
+ function diffMapFindings(props, theme, mode, grounds, base) {
548
+ const out = [];
549
+ const list = mapGrounds(grounds, base, props);
550
+ for (const [token, auto, opacity, use] of DIFF_MAP_PAIRS(mode)) {
551
+ const finding = { theme, mode, fg: token, bg: GROUND, min: MIN_UI, kind: 'ui', use };
552
+ const raw = (props.get(token) || 'auto').trim();
553
+ const fg0 = raw.toLowerCase() === 'auto' ? readColor(auto) : resolveColor(props, token);
554
+ if (!isColor(fg0)) { out.push({ ...finding, problem: fg0 ? fg0.problem : `${token} is not a colour cornfield reads` }); continue; }
555
+ if (!list.length) continue;
556
+ let worst = null;
557
+ for (const { color: ground, image } of list) {
558
+ const fg = over([fg0[0], fg0[1], fg0[2], fg0[3] * opacity], ground);
559
+ const r = ratio(luminance(fg), luminance(ground));
560
+ if (!worst || r < worst.ratio) worst = { fgValue: toHex(fg), bgValue: toHex(ground), ratio: r, image };
561
+ }
562
+ const { image, ...rest } = worst;
563
+ out.push({ ...finding, ...rest, ...(image ? { groundImage: true } : {}) });
564
+ }
503
565
  return out;
504
566
  }
505
567
 
package/core/proposal.js CHANGED
@@ -721,11 +721,18 @@ export function proposalProblems(topology, proposal) {
721
721
  /**
722
722
  * The numbers behind the counts chip ("3 added · 1 changed · 1 removed"): nodes and edges counted together.
723
723
  * @param {object} proposal
724
- * @returns {{ added: number, changed: number, removed: number, scenarios: number }}
724
+ * `nodes` and `edges` give the same counts apart, for the words that say what is counted.
725
+ * @param {object} proposal
726
+ * @returns {{ added: number, changed: number, removed: number, scenarios: number, nodes: { added: number, changed: number, removed: number }, edges: { added: number, changed: number, removed: number } }}
725
727
  */
726
728
  export function summarize(proposal) {
727
- const count = (op) => asList(proposal?.nodes?.[op]).length + asList(proposal?.edges?.[op]).length;
728
- return { added: count('add'), changed: count('change'), removed: count('remove'), scenarios: asList(proposal?.scenarios).length };
729
+ const of = (group) => ({ added: asList(group?.add).length, changed: asList(group?.change).length, removed: asList(group?.remove).length });
730
+ const nodes = of(proposal?.nodes);
731
+ const edges = of(proposal?.edges);
732
+ return {
733
+ added: nodes.added + edges.added, changed: nodes.changed + edges.changed, removed: nodes.removed + edges.removed,
734
+ scenarios: asList(proposal?.scenarios).length, nodes, edges,
735
+ };
729
736
  }
730
737
 
731
738
  /**
package/core/strings.js CHANGED
@@ -32,6 +32,7 @@ export const STRINGS = Object.freeze({
32
32
  sendBackWithNote: 'Send back with this note',
33
33
  reviewNoteLabel: 'Note for the drafting agent',
34
34
  reviewNotePlaceholder: 'What should change?',
35
+ openSpecsList: 'Open the Specs list',
35
36
  // The Work panel: its tabs run in the order of the loop
36
37
  tabSpecs: 'Specs',
37
38
  tabPulls: 'PRs',
@@ -60,6 +60,112 @@ export function pinchCamera(start, dist, mid, min = ZOOM_MIN) {
60
60
  return { x: mid.x - wx * zoom, y: mid.y - wy * zoom, zoom };
61
61
  }
62
62
 
63
+ // ---------------------------------------------------------------------------
64
+ // Framing: put these nodes in the part of the map nothing covers
65
+ // ---------------------------------------------------------------------------
66
+
67
+ /** The zoom at which a node's label is about 11px on screen (labels are 11px in world units from LABEL_ZOOM up, scene.js): where a step or a picked change is shown */
68
+ export const READ_ZOOM = 1.0;
69
+ /**
70
+ * The lowest zoom a change is framed at when it opens (proposal.js `fitToChange`): below it node discs and marks run together, so a change
71
+ * wider than this shows is framed where most of it is (`largestGroup`), not shrunk to a speck; the rest is a row of the change list away.
72
+ * The map's own floor (render.js `getMinZoom()`, low enough for the whole map) is what hand zoom and Fit go down to.
73
+ */
74
+ export const FRAME_ZOOM_MIN = 0.18;
75
+
76
+ /**
77
+ * The part of a `width` × `height` map that nothing covers, given what covers it from each side (px).
78
+ * Never smaller than `minSize` in either direction: when the covers leave less, they are eased until it fits.
79
+ * @param {number} width
80
+ * @param {number} height
81
+ * @param {{ top?: number, bottom?: number, left?: number, right?: number }} [covers]
82
+ * @param {number} [minSize]
83
+ * @returns {{ x: number, y: number, width: number, height: number }}
84
+ */
85
+ export function freeRect(width, height, covers = {}, minSize = 120) {
86
+ const take = (total, a = 0, b = 0) => {
87
+ const lo = Math.max(0, a);
88
+ const hi = Math.max(0, b);
89
+ const room = Math.max(0, total - minSize);
90
+ const scale = lo + hi > room && lo + hi > 0 ? room / (lo + hi) : 1;
91
+ return [lo * scale, hi * scale];
92
+ };
93
+ const [top, bottom] = take(height, covers.top, covers.bottom);
94
+ const [left, right] = take(width, covers.left, covers.right);
95
+ return { x: left, y: top, width: Math.max(0, width - left - right), height: Math.max(0, height - top - bottom) };
96
+ }
97
+
98
+ /** The box a node needs on the map (world px): its disc, a little room round it and its label below */
99
+ const boxOf = (n) => {
100
+ const r = n.r || 18;
101
+ return { left: n.x - r - 25, right: n.x + r + 25, top: n.y - r - 25, bottom: n.y + r + 35 };
102
+ };
103
+ const padFor = (padding, rect) => Math.min(padding, rect.width / 4, rect.height / 4);
104
+
105
+ /**
106
+ * The camera that shows `items` (nodes with `x`, `y` and maybe `r`) inside `rect`, with their labels (room below each) and `padding` px to spare.
107
+ * The zoom is the largest that fits, between `minZoom` and `maxZoom`; when even `minZoom` does not fit, `minZoom` wins and the nodes
108
+ * are centred (the fit never goes under the floor it is given; see `largestGroup` for what to frame then).
109
+ * @param {{ x: number, y: number, r?: number }[]} items
110
+ * @param {{ x: number, y: number, width: number, height: number }} rect CSS px, in the canvas's own coordinates
111
+ * @param {{ padding?: number, maxZoom?: number, minZoom?: number }} [opts]
112
+ * @returns {Camera | null} null for no items
113
+ */
114
+ export function frameNodes(items, rect, { padding = 40, maxZoom = 1, minZoom = ZOOM_MIN } = {}) {
115
+ if (!items.length) return null;
116
+ let minX = Infinity;
117
+ let maxX = -Infinity;
118
+ let minY = Infinity;
119
+ let maxY = -Infinity;
120
+ for (const n of items) {
121
+ const b = boxOf(n);
122
+ minX = Math.min(minX, b.left);
123
+ maxX = Math.max(maxX, b.right);
124
+ minY = Math.min(minY, b.top);
125
+ maxY = Math.max(maxY, b.bottom);
126
+ }
127
+ const pad = padFor(padding, rect);
128
+ const fit = Math.min((rect.width - pad * 2) / (maxX - minX), (rect.height - pad * 2) / (maxY - minY));
129
+ const zoom = Math.max(minZoom, Math.min(maxZoom, fit));
130
+ return { x: rect.x + rect.width / 2 - ((minX + maxX) / 2) * zoom, y: rect.y + rect.height / 2 - ((minY + maxY) / 2) * zoom, zoom };
131
+ }
132
+
133
+ /** Whether every one of `items` is inside `rect` (with `margin` px to spare) under `camera` */
134
+ export function allInside(items, camera, rect, margin = 0) {
135
+ return items.every((n) => {
136
+ const sx = camera.x + n.x * camera.zoom;
137
+ const sy = camera.y + n.y * camera.zoom;
138
+ return sx >= rect.x + margin && sx <= rect.x + rect.width - margin && sy >= rect.y + margin && sy <= rect.y + rect.height - margin;
139
+ });
140
+ }
141
+
142
+ /**
143
+ * The most of `items` that fit in `rect` together at `minZoom`: all of them when they fit, else the biggest group a window of that size
144
+ * holds (so a change spread wider than the lowest zoom shows is framed where most of it is, not on the empty ground between).
145
+ * @param {{ x: number, y: number, r?: number }[]} items
146
+ * @param {{ x: number, y: number, width: number, height: number }} rect
147
+ * @param {{ padding?: number, minZoom?: number }} [opts]
148
+ */
149
+ export function largestGroup(items, rect, { padding = 40, minZoom = FRAME_ZOOM_MIN } = {}) {
150
+ if (items.length < 2) return items;
151
+ const pad = padFor(padding, rect);
152
+ const w = (rect.width - pad * 2) / minZoom;
153
+ const h = (rect.height - pad * 2) / minZoom;
154
+ const boxes = items.map(boxOf);
155
+ const holds = (left, top) => items.filter((_, i) => boxes[i].left >= left && boxes[i].right <= left + w && boxes[i].top >= top && boxes[i].bottom <= top + h);
156
+ // Every window worth trying has its left edge on some node's box and its top edge on some node's (a big change: only each node's own corner)
157
+ const lefts = boxes.map((b) => b.left);
158
+ const tops = boxes.map((b) => b.top);
159
+ let best = [];
160
+ const pairs = items.length <= 120 ? lefts.flatMap((l) => tops.map((t) => [l, t])) : boxes.map((b) => [b.left, b.top]);
161
+ for (const [l, t] of pairs) {
162
+ if (best.length === items.length) break;
163
+ const got = holds(l, t);
164
+ if (got.length > best.length) best = got;
165
+ }
166
+ return best.length ? best : [items[0]];
167
+ }
168
+
63
169
  /**
64
170
  * The camera panned (never zoomed) so a world point is inside `box` (screen px), or null when it already is. A point
65
171
  * outside is put in the middle of the box, on the axis it is outside of. `pad` is the room it needs from the edge
package/explorer/check.js CHANGED
@@ -195,6 +195,9 @@ function summary() {
195
195
  }
196
196
 
197
197
  /** Paints the step's state on the bar: called with every bar update */
198
+ /** The words last written into each player's check line (paintChecks) */
199
+ const lineHtml = new WeakMap();
200
+
198
201
  export function paintChecks(bar, snap) {
199
202
  if (!bar || !current) return;
200
203
  if (!bar.querySelector('.hx-player-as')) {
@@ -214,7 +217,9 @@ export function paintChecks(bar, snap) {
214
217
  pill.textContent = words.pill;
215
218
  pill.title = words.line;
216
219
  line.dataset.tone = words.tone;
217
- line.innerHTML = `${escHtml(words.line)}${words.detail ? ` <span class="hx-player-check-detail">${escHtml(words.detail)}</span>` : ''}`;
220
+ // painted every frame: the live line is rewritten only when its words change, so a verdict is said once
221
+ const html = `${escHtml(words.line)}${words.detail ? ` <span class="hx-player-check-detail">${escHtml(words.detail)}</span>` : ''}`;
222
+ if (lineHtml.get(line) !== html) { lineHtml.set(line, html); line.innerHTML = html; }
218
223
  }
219
224
  fillMenu(row.querySelector('[data-check=as]'));
220
225
  row.querySelector('[data-check=recheck]').disabled = current.answer.status === 'pending';
@@ -0,0 +1,35 @@
1
+ /**
2
+ * @module explorer/diff-marks
3
+ *
4
+ * What the map draws for a proposal's diff marks, as plain data with no imports, so the scene (scene.js), the renderers and the
5
+ * contrast check (core/contrast.js, for `cornfield validate`) read one list. The colours are the defaults behind `--corn-map-added|
6
+ * changed|removed|edit: auto`, and the same hexes are `--corn-added|changed|removed|edit` in tokens.css (the dots in the bar).
7
+ *
8
+ * Every mark is at least 3:1 (WCAG 1.4.11) against the darkest and lightest ground the map draws, at the opacity it is drawn at:
9
+ * an edge never fainter than EDGE_MIN_ALPHA, and a removed mark at REMOVED_ALPHA over that. A label a diff dims is drawn at
10
+ * DIFF_LABEL_ALPHA: de-emphasised, never hidden (3:1 as well).
11
+ */
12
+
13
+ /** The default mark colours, for the dark and the light ground */
14
+ export const DIFF_MARK_COLORS = Object.freeze({
15
+ dark: Object.freeze({ added: '#2dd4bf', changed: '#fbbf24', removed: '#fa9292', edit: '#b49cfb' }),
16
+ light: Object.freeze({ added: '#197c6f', changed: '#8f6703', removed: '#e20b0b', edit: '#6839f6' }),
17
+ });
18
+
19
+ /** How much of a removed node and its edge is left: faded, but still 3:1 */
20
+ export const REMOVED_ALPHA = 0.85;
21
+ /** The least opacity a mark's edge is drawn at (scene.js lifts an edge to this before the mark's own fade) */
22
+ export const EDGE_MIN_ALPHA = 0.9;
23
+ /** The opacity each mark is drawn at at its faintest (an edge; a what-if edit that removes something is faded like a removal): the contrast check measures this */
24
+ export const markOpacity = (mark) => EDGE_MIN_ALPHA * (mark === 'removed' || mark === 'edit' ? REMOVED_ALPHA : 1);
25
+
26
+ /** The opacity of the label of a node a diff dims (the node itself is at PROPOSAL_DIM_ALPHA) */
27
+ export const DIFF_LABEL_ALPHA = 0.6;
28
+
29
+ /** How a mark differs without colour: the ring's dash (`null` is solid) and whether it is struck through. Four marks, four styles. */
30
+ export const MARK_SHAPES = Object.freeze({
31
+ added: Object.freeze({ ringDash: Object.freeze([5, 4]), edgeDash: Object.freeze([7, 5]), strike: false }), // a dashed ring
32
+ changed: Object.freeze({ ringDash: null, edgeDash: null, strike: false }), // a plain solid ring
33
+ removed: Object.freeze({ ringDash: null, edgeDash: Object.freeze([3, 4]), strike: true }), // a faded ring, struck through
34
+ edit: Object.freeze({ ringDash: Object.freeze([2, 5]), edgeDash: Object.freeze([2, 5]), strike: false }), // a dotted ring: short marks, wide gaps (a 1.5/3.5 dot blurred into a solid ring at 1x)
35
+ });
@@ -428,8 +428,8 @@ button.hx-proposal-item:focus-visible { outline: var(--corn-focus-width) solid v
428
428
  .hx-legend-row .hx-mark-dot, .hx-change-row .hx-mark-dot { margin-right: 0; }
429
429
  .hx-mark-dot--added { border-color: var(--corn-added); border-style: dashed; }
430
430
  .hx-mark-dot--changed { border-color: var(--corn-changed); }
431
- .hx-mark-dot--removed { border-color: var(--corn-removed); background: color-mix(in srgb, var(--corn-removed) 25%, transparent); opacity: 0.7; }
432
- .hx-mark-dot--edit { border-color: var(--corn-edit); }
431
+ .hx-mark-dot--removed { border-color: var(--corn-removed); background: color-mix(in srgb, var(--corn-removed) 25%, transparent); }
432
+ .hx-mark-dot--edit { border-color: var(--corn-edit); border-style: dotted; } /* a dotted ring: not the changed mark's solid one, with or without colour */
433
433
 
434
434
  /* The panel's proposal block: why, and what changes */
435
435
  .hx-proposal-sec { padding: var(--corn-space-3) var(--corn-space-3); border: var(--corn-border) solid var(--corn-line); border-left-width: var(--corn-border-strong); border-radius: var(--corn-radius-sm); background: color-mix(in srgb, var(--corn-ground) 55%, transparent); margin: 0 0 var(--corn-space-2); font-family: var(--corn-font); }
@@ -624,15 +624,16 @@ button.hx-proposal-item:focus-visible { outline: var(--corn-focus-width) solid v
624
624
 
625
625
  /* The proposal bar */
626
626
  .hx-proposal-bar { max-height: 50dvh; overflow-y: auto; padding: 0 var(--corn-space-4) var(--corn-space-3); }
627
- .hx-proposal-bar[data-sheet-state="peek"] > :not(.hx-sheet-handle):not(#proposal-message):not(#proposal-body),
627
+ .hx-proposal-bar[data-sheet-state="peek"] > :not(.hx-sheet-handle):not(#proposal-message):not(#proposal-ways):not(#proposal-body),
628
628
  .hx-proposal-bar[data-sheet-state="peek"] #proposal-body > :not(.hx-proposal-head),
629
- .hx-proposal-bar[data-sheet-state="peek"] .hx-proposal-head > :is(.hx-proposal-tools, .hx-proposal-more, .hx-proposal-more-menu, .hx-review) { display: none; }
629
+ .hx-proposal-bar[data-sheet-state="peek"] .hx-proposal-head > :is(.hx-proposal-tools, .hx-proposal-more, .hx-proposal-more-menu) { display: none; }
630
+ .hx-proposal-bar[data-sheet-state="peek"] .hx-review > :not([data-review-hint]):not([data-review-msg]) { display: none; } /* the peek keeps the reason Approve is off, and a refusal */
630
631
  .hx-proposal-bar[data-sheet-state="expanded"] .hx-scenarios, .hx-proposal-bar[data-sheet-state="expanded"] .hx-proposal-changes, .hx-proposal-bar[data-sheet-state="expanded"] .hx-whatif-panel { max-height: none; overflow: visible; }
631
632
 
632
633
  /* The scenario player: the title, then the step counter and its text on two lines */
633
634
  .hx-player { max-height: 50dvh; overflow: hidden; gap: var(--corn-space-2); padding: 0 var(--corn-space-4) var(--corn-space-4); --sheet-pb: var(--corn-space-4); }
634
635
  .hx-player[data-sheet-state="expanded"] { overflow-y: auto; }
635
- .hx-player[data-sheet-state="peek"] > :not(.hx-sheet-handle):not(.hx-player-head):not(.hx-player-text):not(.hx-player-track) { display: none; }
636
+ .hx-player[data-sheet-state="peek"] > :not(.hx-sheet-handle):not(.hx-player-head):not(.hx-player-text):not(.hx-player-controls):not(.hx-player-track) { display: none; } /* Previous, Pause and Next stay in the peek */
636
637
  .hx-player[data-sheet-state="peek"] .hx-player-text { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; min-height: 0; overflow: hidden; font-size: var(--corn-text-md); }
637
638
 
638
639
  /* The node panel: its title and type until expanded */
@@ -1005,6 +1006,45 @@ a.hx-forge-row:hover, button.hx-forge-row:hover { background: var(--corn-surface
1005
1006
  .hx-more-btn { display: block; margin-top: var(--corn-space-1); min-height: 0; padding: 0; font-size: var(--corn-text-sm); }
1006
1007
  @media (max-width: 767px) { .hx-more-btn { min-height: 44px; } }
1007
1008
 
1009
+ /* ---- the review flow, 0.34 design review (explorer/proposal.js, review.js, scenario-ui.js) -----------------------------
1010
+ F08 the source chip on the bar; F11 the player's controls in a phone peek; F14 the note above the keyboard; F15 the reason
1011
+ Approve is off in a peek; F16 the ways on from a bad link; F21 reflow at 400% zoom and with text spacing raised. */
1012
+ .hx-proposal-source { display: inline-flex; align-items: center; min-width: 0; max-width: 100%; padding: calc(var(--corn-space-1) / 2) var(--corn-space-3); border: var(--corn-border) solid var(--corn-line); border-radius: var(--corn-radius-pill); background: var(--corn-surface-2); color: var(--corn-text-2); font-size: var(--corn-text-xs); line-height: 1.4; text-decoration: none; overflow-wrap: anywhere; }
1013
+ .hx-proposal-source[hidden] { display: none; }
1014
+ a.hx-proposal-source { min-height: 24px; } /* a link: at least the WCAG 2.5.8 target (44px on a phone, below) */
1015
+ a.hx-proposal-source:hover { color: var(--corn-text); text-decoration: underline; }
1016
+ a.hx-proposal-source:focus-visible { outline: var(--corn-focus-width) solid var(--corn-focus); outline-offset: 2px; }
1017
+ .hx-proposal-source[data-corn-state="draft"] { border-color: color-mix(in srgb, var(--corn-changed) 50%, transparent); }
1018
+ .hx-proposal-ways { display: flex; flex-wrap: wrap; gap: var(--corn-space-2) var(--corn-space-3); margin-top: var(--corn-space-3); }
1019
+ .hx-proposal-ways[hidden] { display: none; }
1020
+ .hx-proposal-ways .hx-btn { height: auto; min-height: 32px; padding: var(--corn-space-1) var(--corn-space-4); white-space: normal; text-align: left; }
1021
+ .hx-btn[aria-disabled="true"] { opacity: 0.6; cursor: progress; } /* a review being posted: the button keeps the focus */
1022
+
1023
+ @media (max-width: 767px) {
1024
+ .hx-proposal-source { grid-column: 1 / -1; order: 1; justify-self: start; }
1025
+ .hx-player-controls .hx-btn { min-height: 44px; padding: 0 var(--corn-space-2); white-space: nowrap; }
1026
+ .hx-proposal-ways .hx-btn, a.hx-proposal-source { min-height: 44px; } /* targets a thumb can hit */
1027
+ .hx-proposal-source { padding: 0; border: 0; border-radius: 0; background: none; } /* a line of the sheet, not a pill 44px tall */
1028
+ a.hx-proposal-source { text-decoration: underline; text-underline-offset: 3px; }
1029
+ .hx-player-controls { gap: var(--corn-space-2); }
1030
+ /* While a scenario plays the proposal sheet folds to its title and counts: the player needs the room */
1031
+ .hx-dock:has(> .hx-player) .hx-proposal-bar[data-sheet-state="peek"] .hx-proposal-actions { display: none; }
1032
+ /* The note open: the field, Cancel and the send button are all there is, so all of them stay above the keyboard */
1033
+ .hx-proposal-bar:has(.hx-review-form:not([hidden])) :is(.hx-proposal-name, .hx-proposal-source, .hx-proposal-counts, .hx-proposal-tools, .hx-proposal-more, .hx-review-status, .hx-review-line) { display: none; }
1034
+ .hx-proposal-bar:has(.hx-review-form:not([hidden])) .hx-proposal-actions { order: 4; grid-template-columns: 1fr; }
1035
+ .hx-proposal-bar:has(.hx-review-form:not([hidden])) .hx-proposal-actions .hx-btn--approve { display: none; }
1036
+ /* Reflow: nothing is wider than the sheet, and long words and counts wrap instead of being cut */
1037
+ .hx-proposal-bar { overflow-x: hidden; overflow-wrap: anywhere; }
1038
+ .hx-proposal-head { grid-template-columns: minmax(0, 1fr) auto; }
1039
+ .hx-proposal-chip { flex-wrap: wrap; max-width: 100%; white-space: normal; text-align: left; }
1040
+ .hx-proposal-counts { min-width: 0; }
1041
+ }
1042
+ /* A short window (400% zoom is 225px tall): an open sheet may take the window, and the node panel's title wraps */
1043
+ @media (max-width: 767px) and (max-height: 480px) {
1044
+ .hx-proposal-bar[data-sheet-state="expanded"], .hx-player[data-sheet-state="expanded"] { max-height: calc(100dvh - var(--corn-space-3)); }
1045
+ .hx-drawer[data-sheet-state="peek"] .hx-drawer-title { overflow: visible; text-overflow: clip; white-space: normal; }
1046
+ }
1047
+
1008
1048
  /* Search with no match (F24): one line under the field, a polite live region. Empty it takes no room. */
1009
1049
  .hx-search { position: relative; }
1010
1050
  .hx-search-status { position: absolute; top: calc(100% + var(--corn-space-2)); left: 0; right: 0; z-index: 40; padding: var(--corn-space-2) var(--corn-space-3); border-radius: var(--corn-radius-sm); border: var(--corn-border) solid var(--corn-line); background: var(--corn-surface-2); color: var(--corn-text); font-size: var(--corn-text-sm); overflow-wrap: anywhere; }
@@ -1013,3 +1053,18 @@ a.hx-forge-row:hover, button.hx-forge-row:hover { background: var(--corn-surface
1013
1053
 
1014
1054
  /* The node panel's facts break at word boundaries only (F60): "hook" is never "hoo / k". A long path or name still wraps, at its slashes and dashes, and only as a last resort anywhere. */
1015
1055
  .hx-fact-v { overflow-wrap: break-word; word-break: normal; }
1056
+
1057
+ /* ---------------------------------------------------------------------------
1058
+ Target sizes (0.34 review, F57): a thumb target is 44x44 (hit area, the drawn size may be smaller), and a change row is
1059
+ 28px at a desk. Phone width or a coarse pointer. test/explorer/target-size.test.js holds this list.
1060
+ --------------------------------------------------------------------------- */
1061
+ .hx-change-row { min-height: 28px; }
1062
+ .hx-run .hx-link { display: inline-flex; align-items: center; min-height: 24px; } /* a run card's links sit on lines 14px apart: 24px at a desk (WCAG 2.5.8) */
1063
+ @media (max-width: 767px), (pointer: coarse) {
1064
+ .hx-change-row, .hx-toggle-row, .hx-textbtn, .hx-player-speed, .hx-player .hx-close,
1065
+ .hx-confirm .hx-btn, .hx-confirm .hx-forge-input, .hx-confirm .hx-forge-select, .hx-mobile-search .hx-input { min-height: 44px; }
1066
+ .hx-textbtn, .hx-player-speed, .hx-player .hx-close, .hx-confirm .hx-btn { min-width: 44px; }
1067
+ .hx-proposal-chip { flex-wrap: wrap; white-space: normal; text-align: left; } /* the counts say what they count, so they are longer: they wrap rather than clip */
1068
+ .hx-sheet-handle { height: 44px; } /* the grip is drawn the same; the button itself is 44px (a hit area stretched past it is clipped by the sheet above, and covers its title below) */
1069
+ .hx-run .hx-link, .hx-forge-check .hx-link { display: inline-flex; align-items: center; min-height: 44px; }
1070
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * The one list of what the keyboard can stop on, shared by every dialog that keeps the focus inside itself
3
+ * (Review tokens, Start an agent, the confirm step, the mockup window). A trap that names its own selector leaves
4
+ * something out (the Kind of token select once), so they all ask here.
5
+ */
6
+
7
+ /** Every control a Tab can land on: links, buttons, fields, selects, summaries, frames and anything with a tabindex that is not -1 */
8
+ export const FOCUSABLE = 'a[href], button, input:not([type="hidden"]), select, textarea, summary, iframe, [contenteditable="true"], [tabindex]:not([tabindex="-1"])';
9
+
10
+ /**
11
+ * The stops inside `root`, in DOM order: not disabled, not hidden, not inert and not under a hidden or inert ancestor.
12
+ * @param {Element} root
13
+ * @returns {HTMLElement[]}
14
+ */
15
+ export function focusableIn(root) {
16
+ if (!root) return [];
17
+ return [...root.querySelectorAll(FOCUSABLE)].filter((el) => !el.disabled && !el.closest('[hidden], [inert]') && el.getAttribute('tabindex') !== '-1');
18
+ }
19
+
20
+ /**
21
+ * Keeps a Tab inside `root`: from the last stop it goes to the first, and Shift+Tab the other way round.
22
+ * @param {KeyboardEvent} e a keydown; nothing happens unless it is a Tab
23
+ * @param {Element} root
24
+ * @returns {boolean} whether it handled the key
25
+ */
26
+ export function trapTab(e, root) {
27
+ if (e.key !== 'Tab') return false;
28
+ const stops = focusableIn(root);
29
+ e.preventDefault();
30
+ if (!stops.length) return true;
31
+ const at = stops.indexOf(document.activeElement);
32
+ const next = e.shiftKey ? (at <= 0 ? stops.length - 1 : at - 1) : (at === -1 || at === stops.length - 1 ? 0 : at + 1);
33
+ stops[next].focus();
34
+ return true;
35
+ }
@@ -70,6 +70,7 @@ import { state, nodeById, escHtml, touchScene, onSceneTouch } from './state.js';
70
70
  import { render, isNodeVisible } from './render.js';
71
71
  import { selectNode, repaintThreads } from './panels.js';
72
72
  import { announce, centreOn } from './keyboard.js';
73
+ import { trapTab } from './focusables.js';
73
74
  import { isPhone, registerSheet, expandSheet, collapseSheet } from './sheets.js';
74
75
  import { relativeTime } from './review-model.js';
75
76
  import { LAYER_DEFS, toggleLayer } from './layers.js';
@@ -88,7 +89,7 @@ import {
88
89
  threadsUrl, threadUrl, issueUrl, IDEAS_URL, threadKindWords, threadMeta, litForThread, mentionsIndex, ideaRequest, ideaWords,
89
90
  } from './forge-panel-model.js';
90
91
  import { cornStateAttr } from './corn-state.js';
91
- import { proposalListing, onProposalListing, loadProposalList } from './proposal.js';
92
+ import { proposalListing, onProposalListing, loadProposalList, hooks as proposalHooks } from './proposal.js';
92
93
  import { specRowHtml } from './proposal-model.js';
93
94
  import { t } from './strings.js';
94
95
 
@@ -1584,13 +1585,7 @@ function onConfirmKey(e) {
1584
1585
  if (!ui.busy) closeConfirm();
1585
1586
  return;
1586
1587
  }
1587
- if (e.key !== 'Tab') return;
1588
- const buttons = [...confirmEl().querySelectorAll('button:not([disabled])')];
1589
- if (!buttons.length) { e.preventDefault(); return; }
1590
- const at = buttons.indexOf(document.activeElement);
1591
- const next = e.shiftKey ? (at <= 0 ? buttons.length - 1 : at - 1) : (at === -1 || at === buttons.length - 1 ? 0 : at + 1);
1592
- e.preventDefault();
1593
- buttons[next].focus();
1588
+ trapTab(e, confirmEl());
1594
1589
  }
1595
1590
 
1596
1591
  function onConfirmClick(e) {
@@ -1784,13 +1779,7 @@ function onAgentKey(e) {
1784
1779
  if (!ui.agent || !ui.agent.posting) closeAgent();
1785
1780
  return;
1786
1781
  }
1787
- if (e.key !== 'Tab') return;
1788
- const fields = [...agentEl().querySelectorAll('select, textarea, input, button')].filter((el) => !el.disabled && !el.closest('[hidden]'));
1789
- if (!fields.length) { e.preventDefault(); return; }
1790
- const at = fields.indexOf(document.activeElement);
1791
- const next = e.shiftKey ? (at <= 0 ? fields.length - 1 : at - 1) : (at === -1 || at === fields.length - 1 ? 0 : at + 1);
1792
- e.preventDefault();
1793
- fields[next].focus();
1782
+ trapTab(e, agentEl());
1794
1783
  }
1795
1784
 
1796
1785
  function onAgentClick(e) {
@@ -2213,6 +2202,7 @@ export function initForgePanel(config, opts = {}) {
2213
2202
  const panel = $('forge-panel');
2214
2203
  if (!config || !config.forge || !config.signIn || !panel) return false;
2215
2204
  ui.config = config;
2205
+ proposalHooks.openSpecs = () => openForge({ tab: 'specs' }); // a bad proposal link's way on
2216
2206
  if (opts.clock) now = opts.clock;
2217
2207
  for (const toggle of document.querySelectorAll('[data-action="toggle-forge"]')) toggle.hidden = false;
2218
2208
  panel.hidden = false;
@@ -74,9 +74,9 @@
74
74
  <div id="proposal-legend" class="hx-menu-section" hidden>
75
75
  <div class="hx-menu-title"><span>Proposal marks</span></div>
76
76
  <div class="hx-legend-row"><span class="hx-mark-dot hx-mark-dot--added"></span><span>Added: dashed ring</span></div>
77
- <div class="hx-legend-row"><span class="hx-mark-dot hx-mark-dot--changed"></span><span>Changed: amber ring</span></div>
78
- <div class="hx-legend-row"><span class="hx-mark-dot hx-mark-dot--removed"></span><span>Removed: red, faded, label struck through</span></div>
79
- <div class="hx-legend-row"><span class="hx-mark-dot hx-mark-dot--edit"></span><span>Your edit: violet</span></div>
77
+ <div class="hx-legend-row"><span class="hx-mark-dot hx-mark-dot--changed"></span><span>Changed: solid ring</span></div>
78
+ <div class="hx-legend-row"><span class="hx-mark-dot hx-mark-dot--removed"></span><span>Removed: faded ring, label struck through</span></div>
79
+ <div class="hx-legend-row"><span class="hx-mark-dot hx-mark-dot--edit"></span><span>Your edit: dotted ring</span></div>
80
80
  </div>
81
81
 
82
82
  <div class="hx-menu-section">
@@ -195,9 +195,11 @@
195
195
  <!-- The open proposal, a toolbar: title, counts, Before / Diff / After, Play, Edit, Send back, Approve, ⋯ (proposal.js, review.js, whatif.js, scenario-ui.js) -->
196
196
  <section id="proposal-bar" class="hx-proposal-bar glass" aria-label="Open proposal" hidden data-corn="proposal-bar">
197
197
  <p id="proposal-message" class="hx-proposal-message" role="status" hidden></p>
198
+ <div id="proposal-ways" class="hx-proposal-ways" role="group" aria-label="Ways on" data-corn="proposal-ways" hidden></div>
198
199
  <div id="proposal-body">
199
200
  <div class="hx-proposal-head" role="group" aria-label="Proposal actions">
200
201
  <strong id="proposal-title" class="hx-proposal-name"></strong>
202
+ <a id="proposal-source" class="hx-proposal-source" data-corn="proposal-source" hidden></a>
201
203
  <div class="hx-proposal-counts">
202
204
  <button type="button" id="proposal-chip" class="hx-proposal-chip" data-action="toggle-proposal-changes" aria-expanded="false"></button>
203
205
  <button type="button" id="proposal-mode" class="hx-proposal-mode" data-action="toggle-proposal-mode" data-peek-ok aria-expanded="false" aria-controls="proposal-seg" title="Before, Diff or After"></button>
@@ -24,6 +24,7 @@ import { hooks } from './proposal.js';
24
24
  import { mockupsOf } from '../core/proposal.js';
25
25
  import { mockupsFor, mockupsSectionHtml, stateWords } from './mockups-model.js';
26
26
  import { cornState } from './corn-state.js';
27
+ import { focusableIn, trapTab } from './focusables.js';
27
28
 
28
29
  const $ = (id) => document.getElementById(id);
29
30
 
@@ -79,8 +80,6 @@ export async function refreshMockups() {
79
80
  // The window
80
81
  // ---------------------------------------------------------------------------
81
82
 
82
- const FOCUSABLE = 'button, [href], iframe, [tabindex]:not([tabindex="-1"])';
83
-
84
83
  /** Shuts the window and gives the focus back to the button that opened it */
85
84
  export function closeMockup() {
86
85
  if (!dialog) return;
@@ -99,13 +98,8 @@ function onKey(e) {
99
98
  e.stopPropagation();
100
99
  closeMockup();
101
100
  } else if (e.key === 'Tab') {
102
- const stops = [...dialog.querySelectorAll(FOCUSABLE)];
103
- const at = stops.indexOf(document.activeElement);
104
- const next = e.shiftKey ? (at <= 0 ? stops.length - 1 : at - 1) : (at < 0 || at === stops.length - 1 ? 0 : at + 1);
105
- if (stops.length) {
106
- e.preventDefault();
107
- stops[next].focus();
108
- }
101
+ // the frame is a stop too, though it holds the focus rather than a tabindex
102
+ if (focusableIn(dialog).length) trapTab(e, dialog);
109
103
  }
110
104
  }
111
105
 
@@ -48,14 +48,22 @@ function brandImage(doc, src, kind, alt = '') {
48
48
  return img;
49
49
  }
50
50
 
51
+ /** The brand button's name starts with what it shows (the title, or the wordmark's alt), so "click Big map" works (WCAG 2.5.3) */
52
+ function nameBrandButton(doc) {
53
+ const button = doc.getElementById('cf-brand');
54
+ const text = doc.getElementById('cf-title');
55
+ if (!button || !text) return;
56
+ const img = text.querySelector && text.querySelector('img');
57
+ const shown = (text.textContent || '').trim() || (img && img.getAttribute('alt')) || '';
58
+ if (shown) button.setAttribute('aria-label', `${shown}: reset the view`);
59
+ }
60
+
51
61
  /**
52
62
  * The repo's brand in the header (docs/config.md#brand): the logo takes the brand mark's place and the wordmark the title text, inside
53
63
  * the same button, so its accessible name stays. The header text stays the repo's own title; `appName` replaces "cornfield" where
54
64
  * cornfield names itself: the button's accessible name and the page's heading (the tab title and the manifest are the server's).
55
65
  */
56
66
  function applyBrand(doc, brand, title) {
57
- const button = doc.getElementById('cf-brand');
58
- if (button && brand.appName) button.setAttribute('aria-label', `${brand.appName}: reset the view`);
59
67
  const text = doc.getElementById('cf-title');
60
68
  if (brand.logo && typeof doc.createElement === 'function') {
61
69
  const mark = doc.getElementById('cf-mark');
@@ -105,6 +113,7 @@ export function applyBranding(doc, config) {
105
113
  const heading = doc.getElementById('cf-heading');
106
114
  if (heading && config.title) heading.textContent = `${config.title}: the map`;
107
115
  if (config.brand) applyBrand(doc, config.brand, config.title);
116
+ nameBrandButton(doc);
108
117
  initThemePicker(doc, config.theme);
109
118
  paintAccount(doc, config);
110
119
  }