@popcorn245/cornfield 0.38.0 → 0.40.0

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/explorer/main.js CHANGED
@@ -28,10 +28,11 @@ import { updateSearchStatus } from './search-status.js';
28
28
  import { render, resize, fitGraphToViewport, fitPadding, isNodeVisible, setRenderer, getRenderer, ensureFlowLoop, renderNow, holdFrames } from './render.js';
29
29
  import { createRenderer } from './renderer.js';
30
30
  import { clearFreeformPositions, layoutOrbit, loadFreeformPositions } from './layout.js';
31
- import { closeLegendMenu, toggleAllLayers, toggleLayer, toggleLegendMenu } from './layers.js';
31
+ import { clickWithLegendMenu, setProjectLayers, toggleAllLayers, toggleLayer, toggleLayerKinds, toggleLegendMenu } from './layers.js';
32
32
  import { closeDrawer, copySpec, selectNode, startRun } from './panels.js';
33
33
  import { initScenarioUi, maybeStartDemo, playOutage } from './scenario-ui.js';
34
34
  import { initSheets } from './sheets.js';
35
+ import { initReviewColumn } from './review-column.js';
35
36
  import { loadTopology, setView, syncViewUi } from './view.js';
36
37
  import { bindCanvasInput } from './input.js';
37
38
  import { initProposals } from './proposal.js';
@@ -125,9 +126,10 @@ const ACTIONS = {
125
126
  'reset-view': () => fitGraphToViewport(fitPadding()),
126
127
  'fit': () => fitGraphToViewport(fitPadding()),
127
128
  'toggle-layers-menu': () => toggleLegendMenu(),
128
- 'layers-all': () => toggleAllLayers(true),
129
- 'layers-none': () => toggleAllLayers(false),
130
- 'toggle-layer': (el) => toggleLayer(el.dataset.layer),
129
+ 'layers-all': () => toggleAllLayers(true, { viewer: true }),
130
+ 'layers-none': () => toggleAllLayers(false, { viewer: true }),
131
+ 'toggle-layer': (el) => toggleLayer(el.dataset.layer, { viewer: true }),
132
+ 'toggle-layer-kinds': (el) => toggleLayerKinds(el.dataset.layer),
131
133
  'toggle-freeform': () => toggleFreeformMode(),
132
134
  'reset-positions': () => resetFreeformPositions(),
133
135
  'preset-map': () => {
@@ -150,16 +152,14 @@ const ACTIONS = {
150
152
  'set-theme': (el) => setThemeChoice(el.dataset.choice),
151
153
  };
152
154
 
153
- document.addEventListener('click', (e) => {
155
+ // Any click outside the Layers menu closes it; a click on one of its rows does not (layers.js clickWithLegendMenu reads which before the action)
156
+ document.addEventListener('click', (e) => clickWithLegendMenu(e.target, () => {
154
157
  const target = e.target.closest('[data-action]');
155
158
  if (target) {
156
159
  const action = ACTIONS[target.dataset.action];
157
160
  if (action) action(target);
158
161
  }
159
- // Any click outside the Layers menu closes it
160
- const menu = $('legend-dropdown');
161
- if (menu && !menu.hidden && !menu.contains(e.target) && !$('legend-toggle-btn').contains(e.target)) closeLegendMenu();
162
- });
162
+ }));
163
163
 
164
164
  // ---------------------------------------------------------------------------
165
165
  // /?bench=1: the scripted pan-and-zoom of bench.js on the map as loaded
@@ -211,6 +211,7 @@ initKeyboard(); // the map, the panel, the search and the Layers menu by keyboar
211
211
  initAccountMenu(); // the one menu at the right of the header (account-menu.js)
212
212
  initSheets();
213
213
  initScenarioUi();
214
+ initReviewColumn(); // the review column: the changes, and the personas with their scenarios (review-column.js)
214
215
  window.addEventListener('resize', resize);
215
216
  $('node-search').addEventListener('input', (e) => handleSearch(e.target.value));
216
217
  $('mobile-node-search').addEventListener('input', (e) => handleSearch(e.target.value));
@@ -218,7 +219,7 @@ $('mobile-node-search').addEventListener('input', (e) => handleSearch(e.target.v
218
219
  resize();
219
220
  syncViewUi();
220
221
  // /?proposal=<slug> opens a proposal over the map, /?view=dataflow the data-flow preset: both have a link
221
- const configReady = loadClientConfig().then((config) => { applyBranding(document, config); watchHeaderFit(document); watchHint(document); watchFocusRoom(document); applyMapTheme(document, config.theme); syncViewUi(); return config; }); // the brand, then the theme's icons for the map; the hint again, in the repo's words
222
+ const configReady = loadClientConfig().then((config) => { applyBranding(document, config); watchHeaderFit(document); watchHint(document); watchFocusRoom(document); applyMapTheme(document, config.theme); setProjectLayers(config.layers); syncViewUi(); return config; }); // the brand, then the theme's icons for the map; the hint again, in the repo's words
222
223
  loadTopology().then(async (ok) => {
223
224
  if (!ok) return;
224
225
  // The sources the repo's cornfield.config.js names (plugins.js): a live layer, a house, devices, a checker; each optional
@@ -35,6 +35,7 @@
35
35
  import { NODE_THEMES } from '../core/schema.js';
36
36
  import { parseColor } from './theme-model.js';
37
37
  import { looksFor } from './scene.js';
38
+ import { iconKeyShape, iconKeysFor, mapGroupToken, mapKindToken } from '../core/layers.js';
38
39
 
39
40
  /** The node kinds (topology types) and the groups (layers a node can belong to) the tokens exist for */
40
41
  export const MAP_KINDS = Object.freeze(Object.keys(NODE_THEMES));
@@ -69,6 +70,8 @@ export const ICON_URL_PREFIX = '/cornfield/theme/assets/';
69
70
 
70
71
  export const nodeToken = (kind) => `--corn-map-node-${kind}`;
71
72
  export const groupToken = (group) => `--corn-map-group-${group}`;
73
+ /** The fill token of a finer kind: `--corn-map-kind-service-timer`, or null for a kind that cannot be a part of a name (core/layers.js) */
74
+ export const kindToken = (type, kind) => mapKindToken(type, kind);
72
75
  export const edgeToken = (kind) => `--corn-map-edge-${kind}`;
73
76
  export const stateToken = (name) => `--corn-map-${name}`;
74
77
 
@@ -215,12 +218,13 @@ function factorOf(value) {
215
218
  /**
216
219
  * The tokens as the page computes them.
217
220
  * @param {(name: string) => string} read the value of a custom property
221
+ * @param {string[]} [extra] more colour tokens to read: those of the finer kinds and project layers on the map (`setMapSubjects`)
218
222
  * @returns {{values: Record<string, string>, strokeWidth: number, font: string | null, edgeWidth: number | null, glow: number | null}}
219
223
  * `values` holds only the tokens that are a colour (not `auto`); `font`, `edgeWidth` and `glow` are null at `auto` or when the value is not one
220
224
  */
221
- export function readMapTokens(read) {
225
+ export function readMapTokens(read, extra = []) {
222
226
  const values = {};
223
- for (const name of MAP_COLOR_TOKENS) {
227
+ for (const name of [...MAP_COLOR_TOKENS, ...extra]) {
224
228
  const c = cssColor(read(name));
225
229
  if (c) values[name] = c;
226
230
  }
@@ -266,7 +270,7 @@ export function createIconStore(urls, { load = loadImage, onChange = () => {}, w
266
270
  const entries = new Map();
267
271
  let ready = 0;
268
272
  for (const [kind, url] of Object.entries(urls || {})) {
269
- if (!MAP_KINDS.includes(kind) || typeof url !== 'string' || !url.startsWith(ICON_URL_PREFIX) || url.includes('..')) continue;
273
+ if (!iconKeyShape(kind) || typeof url !== 'string' || !url.startsWith(ICON_URL_PREFIX) || url.includes('..')) continue;
270
274
  const entry = { status: 'loading', image: null };
271
275
  entries.set(kind, entry);
272
276
  Promise.resolve().then(() => load(url)).then((image) => {
@@ -323,6 +327,22 @@ function changed() {
323
327
  listeners.forEach((fn) => fn(current));
324
328
  }
325
329
 
330
+ /** The tokens of the finer kinds and project layers on the map, read besides the fixed list (their names come from the map and the config, through core/layers.js, which refuses a name that is not a plain one) */
331
+ let subjectTokens = [];
332
+ const MAX_SUBJECT_TOKENS = 500;
333
+
334
+ /**
335
+ * Tells the style which finer kinds (`[type, kind]`) and project layers (keys) are on the map, so the tokens that colour them
336
+ * (`--corn-map-kind-<type>-<kind>`, `--corn-map-group-<key>`) are read. True when the set changed and a token differed.
337
+ * @param {{kinds?: [string, string][], layers?: string[]}} [subjects]
338
+ */
339
+ export function setMapSubjects({ kinds = [], layers = [] } = {}) {
340
+ const names = [...new Set([...kinds.map(([t, k]) => mapKindToken(t, k)), ...layers.map((l) => mapGroupToken(l))].filter(Boolean))].sort().slice(0, MAX_SUBJECT_TOKENS);
341
+ if (names.length === subjectTokens.length && names.every((n, i) => n === subjectTokens[i])) return false;
342
+ subjectTokens = names;
343
+ return refreshMapStyle();
344
+ }
345
+
326
346
  /** @returns {MapStyle} */
327
347
  export const getMapStyle = () => current;
328
348
 
@@ -338,7 +358,7 @@ export function onMapStyleChange(fn) {
338
358
  */
339
359
  export function refreshMapStyle(read = pageReader()) {
340
360
  if (!read) return false;
341
- const next = readMapTokens(read);
361
+ const next = readMapTokens(read, subjectTokens);
342
362
  const same = next.strokeWidth === tokens.strokeWidth && next.font === tokens.font && next.edgeWidth === tokens.edgeWidth && next.glow === tokens.glow
343
363
  && Object.keys(next.values).length === Object.keys(tokens.values).length
344
364
  && Object.entries(next.values).every(([k, v]) => tokens.values[k] === v);
@@ -379,6 +399,7 @@ export function resetMapStyle() {
379
399
  tokens = NO_TOKENS;
380
400
  icons = null;
381
401
  pixelated = false;
402
+ subjectTokens = [];
382
403
  changed();
383
404
  }
384
405
 
@@ -452,8 +473,9 @@ function compute(scene, style) {
452
473
  const stroke = values[STROKE_TOKEN];
453
474
  const painted = scene.painted || { nodes: new Set(), edges: new Set() };
454
475
  const nodes = scene.nodes.map((n) => {
455
- const fill = !painted.nodes.has(n.id) && firstOf(values, [nodeToken(n.type), groupToken(n.group || n.type)]);
456
- const icon = style.icons && style.icons.get(n.type) ? n.type : null;
476
+ // Which fill wins, most specific first (spec 0009 D6): the finer kind, the project layer, the type, the starting layer
477
+ const fill = !painted.nodes.has(n.id) && firstOf(values, [kindToken(n.type, n.kind), n.layer ? mapGroupToken(n.layer) : null, nodeToken(n.type), groupToken(n.group || n.type)].filter(Boolean));
478
+ const icon = style.icons ? iconKeysFor(n.type, n.kind, n.layer).find((k) => style.icons.get(k)) || null : null; // the same order: kind, layer, type
457
479
  const glows = style.glow != null && style.glow !== 1 && n.glow > 0;
458
480
  if (!fill && !label && !stroke && !icon && !glows) return n;
459
481
  const out = { ...n };
@@ -100,7 +100,8 @@ function dataSummary(node) {
100
100
  const row = (e, side) => `${nm(e[side])}${e.label && e.label !== 'imports' ? ` · ${escHtml(e.label)}` : ''}`;
101
101
  // The summary is the first sentence of the description above: shown again only when the description does not hold it
102
102
  const again = node.summary && !String(node.desc || '').includes(node.summary);
103
- return section('Kind:', [line(`${code(node.kind)}${again ? `<div class="hx-faint">${escHtml(node.summary)}</div>` : ''}`)])
103
+ // The kind is in the badge ("Service · timer", typeWords): it has no row of its own
104
+ return (again ? section('Summary:', [line(`<span class="hx-faint">${escHtml(node.summary)}</span>`)]) : '')
104
105
  + section('Started by:', [...(node.triggers || []).map((t) => line(escHtml(t))), ...edgesOf('triggers', 'to', node.id).map((e) => line(row(e, 'from')))])
105
106
  + section('Jobs:', (node.jobs || []).map((j) => line(`${code(j.name)} · cron ${code(j.cron)}`)))
106
107
  + section('Runs:', edgesOf('triggers', 'from', node.id).map((e) => line(row(e, 'to'))))
@@ -179,10 +180,11 @@ export function repaintThreads() {
179
180
  // The head: type · host, and what the open proposal does to the node
180
181
  // ---------------------------------------------------------------------------
181
182
 
182
- /** "Page", "Cloud", "Public web": the kind of node, in words */
183
+ /** "Page", "Cloud", "Public web", "Service · timer": the kind of node, in words, with its finer kind (spec 0009 D5) after a dot. A kind is text, shown as text */
183
184
  function typeWords(node) {
184
185
  if (node.type === 'external' && node.kind) return node.kind === 'web' ? 'Public web' : 'Cloud';
185
- return node.type.charAt(0).toUpperCase() + node.type.slice(1);
186
+ const type = node.type.charAt(0).toUpperCase() + node.type.slice(1);
187
+ return typeof node.kind === 'string' && node.kind ? `${type} · ${node.kind}` : type;
186
188
  }
187
189
 
188
190
  /** The host a node answers on, when it has one */
@@ -27,9 +27,10 @@ import { edgePoint, looksFor } from './scene.js';
27
27
  import { onThemeChange } from './theme.js';
28
28
  import { looksWith, onMapStyleChange } from './map-style.js';
29
29
  import {
30
- PROPOSAL_VIEWS, MARKS, MARK_WORDS, chipText, barCounts, parseProposalQuery, proposalPanelHtml, touchedIds, viewWords, openedWords, jumpWords,
30
+ PROPOSAL_VIEWS, MARK_WORDS, chipText, barCounts, parseProposalQuery, proposalPanelHtml, touchedIds, viewWords, jumpWords,
31
31
  sourceChip, pullNumberOf, notFoundWords, otherCopies, malformedLinkWords,
32
32
  } from './proposal-model.js';
33
+ import { renderReviewColumn, reviewOpenedLine, showSection, setPullHead } from './review-column.js';
33
34
  import { applyProposal, edgeKey, proposalProblems, summarize } from '../core/proposal.js';
34
35
  import { reviewWords } from './review-model.js';
35
36
  import { collapseSheet, visibleMapRect, isPhone } from './sheets.js';
@@ -123,7 +124,7 @@ export async function openProposal(slug, source = null) {
123
124
  try { item = await res.json(); } catch { throw new Error(`${slug} could not be opened: cornfield sent a file this page could not read.`); }
124
125
  showProposal(item, { slug, source: source || (found ? decodeURIComponent(found) : null), pinSource: !!source, view: 'diff', fit: true });
125
126
  // said once, here: a proposal opens on a person's asking, never on a background refresh
126
- announce(openedWords($('proposal-title').textContent, summarize(state.proposal), state.proposalView));
127
+ announce(reviewOpenedLine($('proposal-title').textContent));
127
128
  return true;
128
129
  } catch (err) {
129
130
  console.error('Opening the proposal failed', err);
@@ -235,7 +236,7 @@ function swapMap(nodes, edges) {
235
236
 
236
237
  /**
237
238
  * Frames what the proposal changes (nodes added, changed or removed, and both ends of a changed edge; not what they connect to) in the part of the
238
- * map nothing covers (the bar, the node panel, a phone's sheets), at a zoom up to 1 so their labels read. Only what is drawn counts: a change on a
239
+ * map nothing covers (the bar, the review column, the node panel, a phone's sheets), at a zoom up to 1 so their labels read. Only what is drawn counts: a change on a
239
240
  * layer that is off is not framed (the map would centre on ground the viewer cannot see). When the change is wider than FRAME_ZOOM_MIN shows,
240
241
  * the biggest part of it that fits there is framed, not the whole at a zoom where it is a speck (the change list reaches the rest). A proposal that changes nothing drawn shows the whole map.
241
242
  */
@@ -326,6 +327,7 @@ async function loadPullInfo(n) {
326
327
  const res = await fetch(`/api/forge/pulls/${n}`);
327
328
  const body = res.ok ? await res.json() : null;
328
329
  if (body && body.ok !== false && body.pull) pullInfo.set(n, { pull: body.pull, checks: Array.isArray(body.checks) ? body.checks : null });
330
+ if (body && body.pull && pullNumberOf(state.proposalSource) === n) setPullHead(body.pull.head && typeof body.pull.head.sha === 'string' ? body.pull.head.sha : ''); // what was seen is kept per PR head
329
331
  } catch { /* no forge, or not signed in: the chip keeps what it has */ }
330
332
  if (state.proposal && pullNumberOf(state.proposalSource) === n) paintSource();
331
333
  }
@@ -347,7 +349,7 @@ export function renderBar() {
347
349
  bar.hidden = !open;
348
350
  const legend = $('proposal-legend');
349
351
  if (legend) legend.hidden = !open;
350
- if (!open) { closeMore(); toggleMode(false); collapseSheet('proposal'); if (hooks.bar) hooks.bar(false); return; }
352
+ if (!open) { closeMore(); toggleMode(false); collapseSheet('proposal'); renderReviewColumn(); if (hooks.bar) hooks.bar(false); return; }
351
353
 
352
354
  bar.classList.remove('is-error');
353
355
  $('proposal-message').hidden = true;
@@ -357,14 +359,18 @@ export function renderBar() {
357
359
  paintSource();
358
360
  const summary = $('proposal-summary');
359
361
  summary.textContent = (p && typeof p.summary === 'string' && p.summary) || '';
360
- const title = $('proposal-title');
361
- title.title = summary.textContent; // the toolbar stays one row: the summary is the title's tooltip, and shows above the list of changes
362
- summary.hidden = !summary.textContent || $('proposal-changes').hidden;
362
+ summary.hidden = !summary.textContent;
363
+ $('proposal-title').title = summary.textContent; // the bar stays one row: the summary is also the title's tooltip, and leads the review column
363
364
 
364
365
  const counts = summarize(p);
365
366
  const chip = $('proposal-chip');
366
- chip.innerHTML = barCounts(counts).map((c) => `${c.mark ? `<span class="hx-mark-dot hx-mark-dot--${c.mark}" data-corn="mark-dot"${markStateAttr(c.mark)} aria-hidden="true"></span>` : ''}${escHtml(c.text)}`).join('<span class="hx-proposal-sep" aria-hidden="true"> · </span>');
367
- chip.title = 'Click for the list of changes.';
367
+ // The counts name their lists: the changes part shows the Changes section, "5 scenarios" the Scenarios section (the review column, review-column.js)
368
+ const parts = barCounts(counts);
369
+ chip.innerHTML = parts.map((c) => {
370
+ const dot = c.mark ? `<span class="hx-mark-dot hx-mark-dot--${c.mark}" data-corn="mark-dot"${markStateAttr(c.mark)} aria-hidden="true"></span>` : '';
371
+ if (!c.mark && /scenarios?$/.test(c.text)) return `<button type="button" class="hx-proposal-count" data-action="review-show-scenarios" data-corn-kind="quiet" title="Show the personas and their scenarios">${escHtml(c.text)}</button>`;
372
+ return `<button type="button" class="hx-proposal-count" data-action="review-show-changes" data-corn-kind="quiet" title="Show the list of changes">${dot}${escHtml(c.text)}</button>`;
373
+ }).join('<span class="hx-proposal-sep" aria-hidden="true"> · </span>');
368
374
  $('proposal-mode').textContent = t(state.proposalView);
369
375
 
370
376
  for (const btn of bar.querySelectorAll('[data-action="proposal-view"]')) {
@@ -380,40 +386,12 @@ export function renderBar() {
380
386
  $('proposal-errors-count').textContent = `${plural(errors.length, 'problem')} in this proposal`;
381
387
  $('proposal-errors-list').innerHTML = problemsHtml(errors);
382
388
  }
383
- renderChanges();
389
+ renderReviewColumn();
384
390
  if (hooks.bar) hooks.bar(true);
385
391
  }
386
392
 
387
- /** The list behind the chip: every marked node and edge, one row each, to pick one without finding it on the map */
388
- function renderChanges() {
389
- const list = $('proposal-changes');
390
- if (!list) return;
391
- // The ownership edge a `parent` adds, and the edges of a removed node, are consequences: the list holds what the proposal says
392
- const said = new Set(['add', 'change', 'remove'].flatMap((op) => asList((state.effectiveProposal || state.proposal)?.edges?.[op]).map(edgeKey)));
393
- const rows = [];
394
- for (const mark of [...MARKS, 'edit']) {
395
- for (const n of state.nodes.filter((x) => x.mark === mark)) {
396
- rows.push(`<button type="button" class="hx-change-row" data-action="proposal-focus" data-kind="node" data-key="${escHtml(n.id)}" data-corn="row"><span class="hx-mark-dot hx-mark-dot--${mark}" data-corn="mark-dot"${markStateAttr(mark)}></span><span class="hx-change-what">${escHtml(MARK_WORDS[mark])}</span><span class="hx-name">${escHtml(n.label)}</span><span class="hx-faint">${escHtml(n.type)}</span></button>`);
397
- }
398
- for (const e of state.edges.filter((x) => x.mark === mark && said.has(edgeKey(x)))) {
399
- rows.push(`<button type="button" class="hx-change-row" data-action="proposal-focus" data-kind="edge" data-key="${escHtml(edgeKey(e))}" data-corn="row"><span class="hx-mark-dot hx-mark-dot--${mark}" data-corn="mark-dot"${markStateAttr(mark)}></span><span class="hx-change-what">${escHtml(MARK_WORDS[mark])}</span><span class="hx-name">${escHtml(nameOf(e.from))} → ${escHtml(nameOf(e.to))}</span><span class="hx-faint">${escHtml(e.kind || 'ownership')}</span></button>`);
400
- }
401
- }
402
- list.innerHTML = rows.join('') || '<p class="hx-faint">This proposal changes nothing on the map.</p>';
403
- }
404
-
405
- function toggleChanges(refocus = false) {
406
- const list = $('proposal-changes');
407
- if (!list) return;
408
- list.hidden = !list.hidden;
409
- $('proposal-summary').hidden = list.hidden || !$('proposal-summary').textContent;
410
- $('proposal-chip').setAttribute('aria-expanded', String(!list.hidden));
411
- // The list sits after the toolbar's buttons in the page, so focus goes into it when it opens (its first row), and back to the chip when it closes by Escape
412
- if (!list.hidden) { if (!isPhone()) list.querySelector('button')?.focus(); } else if (refocus) $('proposal-chip').focus();
413
- }
414
-
415
393
  /**
416
- * Picks a row of the changes list: select it, centre it in the part of the map the open list, the node panel and (on a phone) the sheets leave free,
394
+ * Picks a row of the changes list: select it, centre it in the part of the map the review column, the node panel and (on a phone) the sheets leave free,
417
395
  * at a zoom where its label reads, and make sure the current view shows it
418
396
  */
419
397
  function focusChange(kind, key) {
@@ -629,7 +607,8 @@ const ACTIONS = {
629
607
  'proposal-view': (el) => { setProposalView(el.dataset.view); toggleMode(false); },
630
608
  'toggle-proposal-mode': () => toggleMode(),
631
609
  'toggle-proposal-more': () => (moreOpen() ? closeMore() : openMore()),
632
- 'toggle-proposal-changes': () => toggleChanges(),
610
+ 'review-show-changes': () => showSection('changes'),
611
+ 'review-show-scenarios': () => showSection('scenarios'),
633
612
  'proposal-way': (el) => (el.dataset.way === 'open' ? openProposal(el.dataset.slug, el.dataset.source || null) : el.dataset.way === 'retry' ? retryOpen(el.dataset.slug, el.dataset.source || null) : el.dataset.way === 'close' ? closeAfterFailure() : openSpecs()),
634
613
  'proposal-focus': (el) => focusChange(el.dataset.kind, el.dataset.key),
635
614
  };
@@ -670,51 +649,6 @@ function openSpecs() {
670
649
  function onKey(e) {
671
650
  if (e.key === 'Escape' && menuOpen()) closeMenu();
672
651
  onMoreKey(e);
673
- // Escape inside the list of changes folds it back onto its chip
674
- const list = $('proposal-changes');
675
- if (e.key === 'Escape' && !e.defaultPrevented && list && !list.hidden && list.contains(document.activeElement)) { e.preventDefault(); toggleChanges(true); }
676
- if (e.key === 'Tab' && !e.defaultPrevented && !e.ctrlKey && !e.metaKey && !e.altKey) tabThroughList(e);
677
- }
678
-
679
- /** The lists the toolbar opens, each after the button that opens it: the changes (the counts) and the scenarios (Play) */
680
- const OPENERS = [['proposal-chip', 'proposal-changes'], ['proposal-play', 'proposal-scenarios']];
681
- const TABBABLE = 'button, a[href], input, select, textarea, summary, [tabindex]';
682
- const canTab = (el) => el.tabIndex >= 0 && !el.disabled && !el.closest('[hidden]') && (typeof el.checkVisibility !== 'function' || el.checkVisibility());
683
- const tabbables = (root) => [...root.querySelectorAll(TABBABLE)].filter(canTab);
684
-
685
- /**
686
- * An open list sits in the page under the whole toolbar, so Tab would reach it only after Approve and ⋯ (WCAG 2.4.3). The bar's Tab order is
687
- * the page's with each open list moved to right after the button that opened it: Tab goes from the button into the list, from its last row on
688
- * to the toolbar's next control, and Shift+Tab the same way back. Where that order and the page's agree, the browser moves the focus itself.
689
- */
690
- function tabThroughList(e) {
691
- const bar = $('proposal-bar');
692
- if (!bar || bar.hidden) return;
693
- const open = OPENERS.map(([b, l]) => [$(b), $(l)]).filter(([btn, list]) => btn && list && !list.hidden && bar.contains(list) && canTab(btn));
694
- if (!open.length) return;
695
- const all = tabbables(bar);
696
- let order = all.filter((el) => !open.some(([, list]) => list.contains(el)));
697
- for (const [btn, list] of open) {
698
- const at = order.indexOf(btn);
699
- if (at >= 0) order = [...order.slice(0, at + 1), ...all.filter((el) => list.contains(el)), ...order.slice(at + 1)];
700
- }
701
- const active = document.activeElement;
702
- let to = null;
703
- if (active && bar.contains(active)) {
704
- const i = order.indexOf(active);
705
- if (i < 0) return;
706
- const next = order[i + (e.shiftKey ? -1 : 1)];
707
- const natural = all[all.indexOf(active) + (e.shiftKey ? -1 : 1)];
708
- if (next === natural) return;
709
- if (next) to = next;
710
- else if (!e.shiftKey) to = tabbables(document).find((el) => !bar.contains(el) && (bar.compareDocumentPosition(el) & Node.DOCUMENT_POSITION_FOLLOWING)) || null; // out of the bar, past the list's rows
711
- } else if (e.shiftKey && active) {
712
- // Coming back into the bar from after it: its last control in this order, not the last row of a list
713
- const page = tabbables(document);
714
- const prev = page[page.indexOf(active) - 1];
715
- if (prev && bar.contains(prev) && prev !== order[order.length - 1]) to = order[order.length - 1];
716
- }
717
- if (to) { e.preventDefault(); to.focus(); }
718
652
  }
719
653
 
720
654
  /** The marks' colours for the legend and the panel (the --hx-mark-* variables), the same the map draws on this ground */
@@ -753,7 +687,7 @@ export async function initProposals() {
753
687
  return false;
754
688
  }
755
689
  const ok = await openProposal(asked.slug, asked.source);
756
- if (ok && asked.view) { setProposalView(asked.view, { quiet: true }); announce(openedWords($('proposal-title').textContent, summarize(state.proposal), state.proposalView)); }
690
+ if (ok && asked.view) { setProposalView(asked.view, { quiet: true }); announce(`${reviewOpenedLine($('proposal-title').textContent)} ${viewWords(state.proposalView)}.`); }
757
691
  return ok;
758
692
  }
759
693
 
@@ -10,6 +10,7 @@
10
10
 
11
11
  import { CORE_RATIO, ARROW, EDGE_STRIKE, MARK_MIN_PX, edgePoint, looksFor, packetPoint } from './scene.js';
12
12
  import { ICON_RATIO, getMapStyle, looksWith, styledScene } from './map-style.js';
13
+ import { LETTER_RATIO, letterImage, showsLetters } from './kind-letters.js';
13
14
 
14
15
  const TAU = Math.PI * 2;
15
16
  /** A glow thinner than this on screen (px) is not drawn: zoomed out it is a fraction of a pixel, and costs a stroke or fill per edge and node */
@@ -217,6 +218,14 @@ function drawNode(ctx, node, zoom, looks, style) {
217
218
  const side = node.r * ICON_RATIO;
218
219
  ctx.imageSmoothingEnabled = !style.pixelated;
219
220
  ctx.drawImage(image, node.x - side / 2, node.y - side / 2, side, side);
221
+ } else if (showsLetters(node, zoom)) {
222
+ // A finer kind's letters (spec 0009 D5), where a theme's icon would be: the shortest start of its name, once the node is wide enough
223
+ const letters = letterImage(node.letters);
224
+ if (letters) {
225
+ const side = node.r * LETTER_RATIO;
226
+ ctx.imageSmoothingEnabled = true;
227
+ ctx.drawImage(letters, node.x - side / 2, node.y - side / 2, side, side);
228
+ }
220
229
  }
221
230
  ctx.restore();
222
231
  }
@@ -26,6 +26,7 @@
26
26
 
27
27
  import { ARROW, CORE_RATIO, EDGE_STRIKE, MARK_MIN_PX, edgePoint, looksFor, parseColor } from './scene.js';
28
28
  import { ICON_RATIO, getMapStyle, looksWith, styledScene } from './map-style.js';
29
+ import { LETTER_MIN_PX, LETTER_RATIO, isLetterKey, letterImage, letterKey, lettersOfKey } from './kind-letters.js';
29
30
  import {
30
31
  CURVE_SEGMENTS, EDGE_FRAG, GRID_FRAG, GRID_VERT, ICON_FRAG, ICON_VERT, LANE_FRAG, LANE_VERT, NODE_FRAG, NODE_VERT, PACKET_FRAG, PACKET_VERT,
31
32
  RING_FRAG, RING_VERT, TIP_FRAG, TIP_VERT, edgeVert,
@@ -194,22 +195,29 @@ export function packStrokes(scene) {
194
195
  }
195
196
 
196
197
  /**
197
- * The icons of the nodes that have one, grouped by kind (one texture, one draw each), in scene order within a kind.
198
+ * The icons of the nodes that have one, grouped by kind (one texture, one draw each), in scene order within a kind. A node with no theme icon
199
+ * but a finer kind's letters (spec 0009 D5) goes in a group of its own letters (`letters:j`), drawn from the image in explorer/kind-letters.js;
200
+ * a group says its smallest node's radius (`minR`), for the zoom below which its letters are not drawn.
198
201
  * @param {import('./scene.js').Scene} scene a scene through `styledScene`
199
- * @param {(kind: string) => boolean} has whether the kind's image has loaded
200
- * @returns {{data: Float32Array, count: number, stride: number, groups: {kind: string, first: number, count: number}[]}}
202
+ * @param {(kind: string) => boolean} has whether the kind's image has loaded (a letters key: whether its image could be made)
203
+ * @returns {{data: Float32Array, count: number, stride: number, groups: {kind: string, first: number, count: number, minR: number}[]}}
201
204
  */
202
205
  export function packIcons(scene, has) {
203
206
  const byKind = new Map();
204
207
  scene.nodes.forEach((n) => {
205
- if (!n.icon || !has(n.icon)) return;
206
- if (!byKind.has(n.icon)) byKind.set(n.icon, []);
207
- byKind.get(n.icon).push([n.x, n.y, n.r * ICON_RATIO, n.alpha]);
208
+ let kind = n.icon && has(n.icon) ? n.icon : null;
209
+ let side = n.r * ICON_RATIO;
210
+ if (!kind && !n.icon && n.letters && has(letterKey(n.letters))) { kind = letterKey(n.letters); side = n.r * LETTER_RATIO; }
211
+ if (!kind) return;
212
+ if (!byKind.has(kind)) byKind.set(kind, { rows: [], minR: Infinity });
213
+ const group = byKind.get(kind);
214
+ group.rows.push([n.x, n.y, side, n.alpha]);
215
+ group.minR = Math.min(group.minR, n.r);
208
216
  });
209
217
  const groups = [];
210
218
  const rows = [];
211
- for (const [kind, list] of byKind) {
212
- groups.push({ kind, first: rows.length, count: list.length });
219
+ for (const [kind, { rows: list, minR }] of byKind) {
220
+ groups.push({ kind, first: rows.length, count: list.length, minR });
213
221
  rows.push(...list);
214
222
  }
215
223
  const data = new Float32Array(rows.length * ICON_STRIDE);
@@ -492,7 +500,7 @@ export function createWebglRenderer(canvas, opts = {}) {
492
500
  gpu.iconStore = style.icons;
493
501
  }
494
502
  if (scene !== packedScene || scene.version !== packedVersion) {
495
- packed = { ...packScene(scene), strokes: packStrokes(scene), icons: packIcons(scene, (kind) => !!(style.icons && style.icons.get(kind))) };
503
+ packed = { ...packScene(scene), strokes: packStrokes(scene), icons: packIcons(scene, (kind) => (isLetterKey(kind) ? !!letterImage(lettersOfKey(kind)) : !!(style.icons && style.icons.get(kind)))) };
496
504
  packedScene = scene;
497
505
  packedVersion = scene.version;
498
506
  upload();
@@ -539,9 +547,11 @@ export function createWebglRenderer(canvas, opts = {}) {
539
547
  gl.bindVertexArray(icons.vao);
540
548
  gl.bindBuffer(gl.ARRAY_BUFFER, icons.buffer);
541
549
  for (const group of packed.icons.groups) {
542
- const image = style.icons && style.icons.get(group.kind);
550
+ const letters = isLetterKey(group.kind);
551
+ if (letters && group.minR * 2 * camera.zoom < LETTER_MIN_PX) continue; // too small on screen: the letters would be a smudge (kind-letters.js)
552
+ const image = letters ? letterImage(lettersOfKey(group.kind)) : style.icons && style.icons.get(group.kind);
543
553
  if (!image) continue;
544
- gl.bindTexture(gl.TEXTURE_2D, textureOf(group.kind, image, !!style.pixelated));
554
+ gl.bindTexture(gl.TEXTURE_2D, textureOf(group.kind, image, !!style.pixelated && !letters));
545
555
  gl.vertexAttribPointer(1, 4, gl.FLOAT, false, ICON_STRIDE * 4, group.first * ICON_STRIDE * 4); // this kind's rows
546
556
  gl.drawArraysInstanced(gl.TRIANGLE_STRIP, 0, 4, group.count);
547
557
  stats.draws++;