cornfield 0.34.3 → 0.36.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/cli/cornfield.js +4 -2
- package/core/contrast.js +110 -5
- package/core/map-tokens.js +43 -0
- package/core/strings.js +4 -2
- package/core/validate.js +7 -3
- package/explorer/connection.js +62 -0
- package/explorer/corn-state.js +34 -2
- package/explorer/explorer.css +117 -35
- package/explorer/feedback.js +49 -0
- package/explorer/focus-room.js +26 -0
- package/explorer/forge-panel-model.js +41 -7
- package/explorer/forge-panel.js +224 -57
- package/explorer/header-fit.js +75 -0
- package/explorer/hint.js +92 -0
- package/explorer/house-model.js +11 -0
- package/explorer/house.css +1 -1
- package/explorer/house.js +5 -2
- package/explorer/index.html +15 -11
- package/explorer/labels.js +8 -6
- package/explorer/layers.js +1 -1
- package/explorer/live-model.js +6 -2
- package/explorer/main.js +7 -3
- package/explorer/map-style.js +107 -16
- package/explorer/panels.js +12 -4
- package/explorer/plugins.js +18 -3
- package/explorer/proposal-model.js +34 -5
- package/explorer/proposal.js +33 -10
- package/explorer/review.js +48 -7
- package/explorer/runs-model.js +42 -18
- package/explorer/runs-view.js +58 -20
- package/explorer/scenario-ui.js +1 -1
- package/explorer/sign-in.css +73 -0
- package/explorer/tokens.css +25 -6
- package/explorer/view.js +2 -3
- package/package.json +1 -1
- package/server/auth.js +94 -40
- package/server/forge-http.js +1 -1
- package/server/page-head.js +55 -0
- package/server/server.js +37 -46
package/cli/cornfield.js
CHANGED
|
@@ -106,7 +106,7 @@ async function sync(flags) {
|
|
|
106
106
|
|
|
107
107
|
async function validate(flags) {
|
|
108
108
|
const { config, derivers } = await setup(flags);
|
|
109
|
-
const { errors, warnings } = await validateRepo({ config, derivers });
|
|
109
|
+
const { errors, warnings, notes } = await validateRepo({ config, derivers });
|
|
110
110
|
warnings.forEach((w) => console.warn(` warning: ${w}`));
|
|
111
111
|
if (errors.length) {
|
|
112
112
|
console.error(`\nValidation failed with ${plural(errors.length, 'error')}:`);
|
|
@@ -114,7 +114,9 @@ async function validate(flags) {
|
|
|
114
114
|
console.error('');
|
|
115
115
|
return 1;
|
|
116
116
|
}
|
|
117
|
-
console.log(`\nValid: the schema holds, ${config.topology} matches the code, and every proposal checks out
|
|
117
|
+
console.log(`\nValid: the schema holds, ${config.topology} matches the code, and every proposal checks out.`);
|
|
118
|
+
(notes || []).forEach((n) => console.log(n));
|
|
119
|
+
console.log('');
|
|
118
120
|
return 0;
|
|
119
121
|
}
|
|
120
122
|
|
package/core/contrast.js
CHANGED
|
@@ -23,6 +23,7 @@ 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 { NODE_THEMES } from './schema.js';
|
|
26
27
|
import { DIFF_MARK_COLORS, DIFF_LABEL_ALPHA, markOpacity } from '../explorer/diff-marks.js';
|
|
27
28
|
import { lightColor } from '../explorer/theme-model.js';
|
|
28
29
|
|
|
@@ -347,11 +348,13 @@ const tint = (token, pct) => `color-mix(in srgb, var(${token}) ${pct}%, transpar
|
|
|
347
348
|
const toText = (token, pct) => `color-mix(in srgb, var(${token}) ${pct}%, var(--corn-text))`;
|
|
348
349
|
|
|
349
350
|
/** Text tokens: read on the ground and on every surface */
|
|
350
|
-
export const TEXT_TOKENS = Object.freeze(['--corn-text', '--corn-text-2', '--corn-text-3', '--corn-accent-text', '--corn-ok', '--corn-warn', '--corn-bad', '--corn-info', '--corn-added-text', '--corn-edit-text'
|
|
351
|
+
export const TEXT_TOKENS = Object.freeze(['--corn-text', '--corn-text-2', '--corn-text-3', '--corn-accent-text', '--corn-ok', '--corn-warn', '--corn-bad', '--corn-info', '--corn-added-text', '--corn-edit-text',
|
|
352
|
+
'--corn-run-requested', '--corn-run-claimed', '--corn-run-working', '--corn-run-waiting', '--corn-run-done', '--corn-run-failed', '--corn-run-stopped']);
|
|
351
353
|
/** The tinted backgrounds, with the text that sits on each */
|
|
352
354
|
export const SOFT_PAIRS = Object.freeze([
|
|
353
355
|
['--corn-ok', '--corn-ok-soft'],
|
|
354
356
|
['--corn-accent-text', '--corn-accent-soft'], ['--corn-hue-orange-text', '--corn-hue-orange-soft'],
|
|
357
|
+
['--corn-run-waiting-ink', '--corn-run-waiting'], // the waiting pill is solid: its word and icon in the ink, on the fill
|
|
355
358
|
]);
|
|
356
359
|
/** Solid fills that carry `--corn-ground` as their text (a pressed data-flow button, a chip, the What-if toggle, the House chip) */
|
|
357
360
|
export const SOLID_FILLS = Object.freeze(['--corn-ok', '--corn-warn', '--corn-bad', '--corn-info', '--corn-hue-orange', '--corn-hue-lime', '--corn-added-text', '--corn-edit-text']);
|
|
@@ -477,6 +480,98 @@ function colorsIn(text, depth) {
|
|
|
477
480
|
return out;
|
|
478
481
|
}
|
|
479
482
|
|
|
483
|
+
// ===========================================================================
|
|
484
|
+
// The map's colours (CF review F48): node fills and labels, against the ground
|
|
485
|
+
// Its own block: the pairs above are fixed lists, these depend on the tokens a theme sets (a kind, its group, the outline).
|
|
486
|
+
// ===========================================================================
|
|
487
|
+
|
|
488
|
+
/** The `--corn-map-group-*` a node type can sit in (explorer/scene.js `groupOf`): its own name, the house for a floor and a room, cloud or web for an outside system */
|
|
489
|
+
const MAP_GROUPS_OF = (type) => (type === 'floor' || type === 'room' ? ['house'] : type === 'external' ? ['cloud', 'web'] : [type]);
|
|
490
|
+
/** A node's outline and label are drawn on the map's own canvas: a fill under 3:1 needs the outline (WCAG 1.4.11) to be seen */
|
|
491
|
+
export const MAP_FILL_MIN = MIN_UI;
|
|
492
|
+
/** "a" or "an", for the type named after it (an atom, an app, a table) */
|
|
493
|
+
const anOf = (word) => (/^[aeiou]/i.test(word) ? 'an' : 'a');
|
|
494
|
+
/** What a map colour token holds: a colour, `auto` (the map keeps its own), or a problem naming why it cannot be read */
|
|
495
|
+
function mapToken(props, name) {
|
|
496
|
+
if (!props.has(name)) return { auto: true };
|
|
497
|
+
const raw = expand(`var(${name})`, props);
|
|
498
|
+
if ('problem' in raw) return { problem: raw.problem };
|
|
499
|
+
if (!raw.text.trim() || raw.text.trim().toLowerCase() === 'auto') return { auto: true };
|
|
500
|
+
const c = resolveColor(props, name);
|
|
501
|
+
return isColor(c) ? { color: c } : { problem: c.problem };
|
|
502
|
+
}
|
|
503
|
+
/** The worst ratio of a colour (composited over the ground) against each ground the page can show, with the colour it was worked out on */
|
|
504
|
+
function worstOnGrounds(c, grounds) {
|
|
505
|
+
let worst = null;
|
|
506
|
+
for (const { color: ground, image } of grounds) {
|
|
507
|
+
const fg = over(c, ground);
|
|
508
|
+
const r = ratio(luminance(fg), luminance(ground));
|
|
509
|
+
if (!worst || r < worst.ratio) worst = { ratio: r, fgValue: toHex(fg), bgValue: toHex(ground), image };
|
|
510
|
+
}
|
|
511
|
+
return worst;
|
|
512
|
+
}
|
|
513
|
+
/**
|
|
514
|
+
* The map's pairs for one page state: for each node type, its fill (the kind's token, else its group's, else the node's own colour from
|
|
515
|
+
* core/schema.js, deepened for the light ground) against the ground; the outline carries a fill under 3:1 when it is itself 3:1 against
|
|
516
|
+
* the fill and the ground; the label colour against the ground and against its halo. Always the same findings in the same order
|
|
517
|
+
* (checkSheets lines the two system settings up by position).
|
|
518
|
+
*/
|
|
519
|
+
function mapFindings(props, theme, mode, grounds) {
|
|
520
|
+
const out = [];
|
|
521
|
+
if (!grounds.length) return out;
|
|
522
|
+
const base = { theme, mode };
|
|
523
|
+
const ground = grounds[0].color;
|
|
524
|
+
const stroke = mapToken(props, '--corn-map-stroke');
|
|
525
|
+
const widthText = props.has('--corn-map-stroke-width') ? substitute(props.get('--corn-map-stroke-width'), props) : '1.5px';
|
|
526
|
+
const strokeOn = isColor(stroke.color) && !(Number.parseFloat(widthText) === 0);
|
|
527
|
+
for (const type of Object.keys(NODE_THEMES)) {
|
|
528
|
+
for (const group of MAP_GROUPS_OF(type)) {
|
|
529
|
+
const names = [`--corn-map-node-${type}`, `--corn-map-group-${group}`];
|
|
530
|
+
let name = null;
|
|
531
|
+
let fill = null;
|
|
532
|
+
let problem = null;
|
|
533
|
+
for (const n of names) {
|
|
534
|
+
const t = mapToken(props, n);
|
|
535
|
+
if (t.problem) { name = n; problem = t.problem; break; }
|
|
536
|
+
if (t.color) { name = n; fill = t.color; break; }
|
|
537
|
+
}
|
|
538
|
+
const label = type === 'external' ? `${type}, in the ${group} group` : type;
|
|
539
|
+
if (problem) { out.push({ ...base, fg: name, bg: GROUND, min: MAP_FILL_MIN, kind: 'ui', use: `the fill of ${anOf(label)} ${label} node`, problem }); continue; }
|
|
540
|
+
const own = !fill;
|
|
541
|
+
if (own) { name = names[0]; fill = readColor(mode === 'light' ? lightColor(NODE_THEMES[type].color) : NODE_THEMES[type].color); }
|
|
542
|
+
const shown = own ? `${name}, auto: the node's own colour` : name;
|
|
543
|
+
const f = worstOnGrounds(fill, grounds);
|
|
544
|
+
const finding = { ...base, fg: name, bg: GROUND, min: MAP_FILL_MIN, kind: 'ui', use: `the fill of ${anOf(label)} ${label} node`, fgValue: f.fgValue, bgValue: f.bgValue, ratio: f.ratio, ...(f.image ? { groundImage: true } : {}) };
|
|
545
|
+
if (f.ratio >= MAP_FILL_MIN || !strokeOn) {
|
|
546
|
+
out.push(f.ratio >= MAP_FILL_MIN ? finding : { ...finding, fg: shown, use: `the fill of ${anOf(label)} ${label} node; set --corn-map-stroke, an outline at ${MAP_FILL_MIN}:1 on the fill and on the ground, or a deeper fill` });
|
|
547
|
+
continue;
|
|
548
|
+
}
|
|
549
|
+
// Under 3:1: acceptable only when the outline is itself 3:1 against both the fill and the ground
|
|
550
|
+
const onGround = worstOnGrounds(stroke.color, grounds);
|
|
551
|
+
const onFill = ratio(luminance(over(stroke.color, over(fill, ground))), luminance(over(fill, ground)));
|
|
552
|
+
const weakest = onGround.ratio <= onFill ? { r: onGround.ratio, on: '--corn-ground', value: onGround.bgValue } : { r: onFill, on: name, value: toHex(over(fill, ground)) };
|
|
553
|
+
out.push({ ...base, fg: '--corn-map-stroke', bg: weakest.on, min: MAP_FILL_MIN, kind: 'ui', use: `the outline that carries the fill of ${anOf(label)} ${label} node, which is ${fmt(f.ratio)} on its own`, fgValue: onGround.fgValue, bgValue: weakest.value, ratio: weakest.r });
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
// Labels are text: the colour against the ground, and against the halo under it (the halo is the ground's own colour at `auto`)
|
|
557
|
+
const label = mapToken(props, '--corn-map-label');
|
|
558
|
+
const haloTok = mapToken(props, '--corn-map-label-halo');
|
|
559
|
+
const labelColor = label.color || (label.problem ? null : readColor(mode === 'light' ? lightColor('#f8fafc') : '#f8fafc'));
|
|
560
|
+
if (label.problem) out.push({ ...base, fg: '--corn-map-label', bg: GROUND, min: MIN_TEXT, kind: 'text', use: 'a node\'s label', problem: label.problem }, { ...base, fg: '--corn-map-label', bg: '--corn-map-label-halo', min: MIN_TEXT, kind: 'text', use: 'a node\'s label', problem: label.problem });
|
|
561
|
+
else {
|
|
562
|
+
const name = label.color ? '--corn-map-label' : '--corn-map-label (auto)';
|
|
563
|
+
const w = worstOnGrounds(labelColor, grounds);
|
|
564
|
+
out.push({ ...base, fg: name, bg: GROUND, min: MIN_TEXT, kind: 'text', use: 'a node\'s label on the ground', fgValue: w.fgValue, bgValue: w.bgValue, ratio: w.ratio, ...(w.image ? { groundImage: true } : {}) });
|
|
565
|
+
if (haloTok.problem) out.push({ ...base, fg: name, bg: '--corn-map-label-halo', min: MIN_TEXT, kind: 'text', use: 'a node\'s label on its halo', problem: haloTok.problem });
|
|
566
|
+
else {
|
|
567
|
+
const bg = haloTok.color ? over(haloTok.color, ground) : ground;
|
|
568
|
+
const fgc = over(labelColor, bg);
|
|
569
|
+
out.push({ ...base, fg: name, bg: '--corn-map-label-halo', min: MIN_TEXT, kind: 'text', use: 'a node\'s label on its halo', fgValue: toHex(fgc), bgValue: toHex(bg), ratio: ratio(luminance(fgc), luminance(bg)) });
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
return out;
|
|
573
|
+
}
|
|
574
|
+
|
|
480
575
|
/** Pair results for one page state: one per pair, the worst over the ground and the ground image */
|
|
481
576
|
function checkState(props, theme, mode) {
|
|
482
577
|
const out = [];
|
|
@@ -506,6 +601,7 @@ function checkState(props, theme, mode) {
|
|
|
506
601
|
const { image, ...rest } = worst;
|
|
507
602
|
out.push({ ...finding, ...rest, ...(image ? { groundImage: true } : {}) });
|
|
508
603
|
}
|
|
604
|
+
out.push(...mapFindings(props, theme, mode, grounds)); // the map's node fills and labels (their block above)
|
|
509
605
|
out.push(...diffMapFindings(props, theme, mode, grounds, isColor(g) ? over(g, canvas) : null));
|
|
510
606
|
return out;
|
|
511
607
|
}
|
|
@@ -592,7 +688,7 @@ export function checkSheets(themes) {
|
|
|
592
688
|
/** The pairs under their minimum: { fails, unresolved } */
|
|
593
689
|
export function contrastProblems(themes) {
|
|
594
690
|
const all = checkSheets(themes);
|
|
595
|
-
return { fails: all.filter((f) => f.ratio !== undefined && f.ratio < f.min), unresolved: all.filter((f) => f.problem) };
|
|
691
|
+
return { fails: all.filter((f) => f.ratio !== undefined && f.ratio < f.min), unresolved: all.filter((f) => f.problem), total: all.length };
|
|
596
692
|
}
|
|
597
693
|
|
|
598
694
|
const fmt = (r) => `${(Math.floor(r * 100) / 100).toFixed(2)}:1`;
|
|
@@ -646,17 +742,26 @@ export function themesToCheck(config) {
|
|
|
646
742
|
return themes;
|
|
647
743
|
}
|
|
648
744
|
|
|
745
|
+
/** The one line `validate` prints about the check (docs/theming.md#the-contrast-check): how many pairs, which themes, both levels, and what held */
|
|
746
|
+
export function contrastSummary(themes, total, failed = 0, unchecked = 0) {
|
|
747
|
+
const named = themes.length - 1;
|
|
748
|
+
const what = `${total} pairs of the standard theme${named > 0 ? ` and ${named} named theme${named > 1 ? 's' : ''}` : ''}, in light and dark`;
|
|
749
|
+
const rest = [failed ? `${failed} under their minimum` : '', unchecked ? `${unchecked} that could not be worked out` : ''].filter(Boolean).join(', ');
|
|
750
|
+
return `theme contrast: ${what}: ${rest ? rest : `all at or above their minimum (${MIN_TEXT}:1 for text, ${MIN_UI}:1 for the parts of the interface and the map's fills)`}.`;
|
|
751
|
+
}
|
|
752
|
+
|
|
649
753
|
/**
|
|
650
754
|
* The contrast check of a repo, for `cornfield validate`: every pair under its minimum is an error (a warning with
|
|
651
755
|
* `theme.contrast: 'warn'`), and a pair that could not be worked out is a warning naming the token and why.
|
|
652
756
|
* @param {{ root: string, theme?: { css?: string|null, names?: Record<string,string>, fonts?: string[], contrast?: string } }} config
|
|
653
|
-
* @returns {{ errors: string[], warnings: string[] }}
|
|
757
|
+
* @returns {{ errors: string[], warnings: string[], summary?: string }} `summary`: the one line of what was checked (absent when there was nothing to read)
|
|
654
758
|
*/
|
|
655
759
|
export function checkThemeContrast(config) {
|
|
656
760
|
const themes = themesToCheck(config);
|
|
657
761
|
if (!themes) return { errors: [], warnings: [] };
|
|
658
|
-
const { fails, unresolved } = contrastProblems(themes);
|
|
762
|
+
const { fails, unresolved, total } = contrastProblems(themes);
|
|
659
763
|
const lines = fails.map((f) => `theme contrast: ${describeFinding(f)}`);
|
|
660
764
|
const warnings = unresolved.map((f) => `theme contrast: ${describeFinding(f)}`);
|
|
661
|
-
|
|
765
|
+
const summary = contrastSummary(themes, total, fails.length, unresolved.length);
|
|
766
|
+
return (config.theme || {}).contrast === 'warn' ? { errors: [], warnings: [...lines, ...warnings], summary } : { errors: lines, warnings, summary };
|
|
662
767
|
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module core/map-tokens
|
|
3
|
+
*
|
|
4
|
+
* The map's non-colour tokens, as `cornfield validate` reads them: `--corn-map-font`, `--corn-map-edge-width` and `--corn-map-glow`. The
|
|
5
|
+
* map reads each with the same parser (explorer/map-style.js `readMapTokens`), and one it cannot read is drawn as if it were `auto`; this
|
|
6
|
+
* says so before the theme ships, as a warning naming the token, the theme, the level and what it may hold (docs/theming.md, The map).
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { expand, resolveProps, themesToCheck } from './contrast.js';
|
|
10
|
+
import { EDGE_WIDTH_TOKEN, FONT_TOKEN, GLOW_TOKEN, MAX_EDGE_WIDTH, MAX_GLOW, readMapTokens } from '../explorer/map-style.js';
|
|
11
|
+
|
|
12
|
+
const WANTS = {
|
|
13
|
+
[FONT_TOKEN]: ['font', 'a list of font families (quoted names or plain words, at most 8; no url(), and no punctuation but commas and quotes)'],
|
|
14
|
+
[EDGE_WIDTH_TOKEN]: ['edgeWidth', `a width in px over 0 and at most ${MAX_EDGE_WIDTH}`],
|
|
15
|
+
[GLOW_TOKEN]: ['glow', `a factor from 0 (no glow) to ${MAX_GLOW}`],
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* One warning per map token a theme sets to something the map cannot use (once per theme, whichever level shows it first).
|
|
20
|
+
* @param {{ root: string, theme?: object }} config
|
|
21
|
+
* @returns {string[]}
|
|
22
|
+
*/
|
|
23
|
+
export function mapTokenWarnings(config) {
|
|
24
|
+
const themes = themesToCheck(config);
|
|
25
|
+
if (!themes) return [];
|
|
26
|
+
const out = [];
|
|
27
|
+
for (const { theme, sheets, name } of themes) {
|
|
28
|
+
const said = new Set();
|
|
29
|
+
for (const mode of ['light', 'dark']) {
|
|
30
|
+
const props = resolveProps(sheets, { mode, system: mode, name });
|
|
31
|
+
const read = (token) => { if (!props.has(token)) return 'auto'; const r = expand(`var(${token})`, props); return 'text' in r ? r.text.trim() : ''; };
|
|
32
|
+
const got = readMapTokens(read);
|
|
33
|
+
for (const [token, [key, wants]] of Object.entries(WANTS)) {
|
|
34
|
+
const raw = read(token);
|
|
35
|
+
if (said.has(token) || raw.toLowerCase() === 'auto' || got[key] !== null) continue;
|
|
36
|
+
said.add(token);
|
|
37
|
+
const who = theme === 'standard' ? 'the standard theme' : `named theme "${theme}"`;
|
|
38
|
+
out.push(`theme: ${token} in ${who} (${mode}) is "${raw.slice(0, 60)}${raw.length > 60 ? '…' : ''}", which the map cannot use, so it draws as auto: write ${wants}, or auto.`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return out;
|
|
43
|
+
}
|
package/core/strings.js
CHANGED
|
@@ -55,8 +55,10 @@ export const STRINGS = Object.freeze({
|
|
|
55
55
|
startRun: 'Start a run',
|
|
56
56
|
copySpec: 'Copy Spec',
|
|
57
57
|
// The hint, loading and errors
|
|
58
|
-
hintInspect: '
|
|
59
|
-
|
|
58
|
+
hintInspect: 'Click a node to see what it is',
|
|
59
|
+
hintInspectTouch: 'Tap a node to see what it is',
|
|
60
|
+
hintDrag: 'Drag nodes to move • Double-click to inspect',
|
|
61
|
+
hintDragTouch: 'Drag nodes to move • Double-tap to inspect',
|
|
60
62
|
hintDataFlow: 'Data flow: browser → servers → API → tables → services → outside',
|
|
61
63
|
loading: 'Loading topology.json …',
|
|
62
64
|
errorTitle: 'The map could not be loaded',
|
package/core/validate.js
CHANGED
|
@@ -24,6 +24,7 @@ import { deriveTopology } from './derive.js';
|
|
|
24
24
|
import { missingPaths, planSync } from './sync.js';
|
|
25
25
|
import { repoPaths, repoReader } from './repo.js';
|
|
26
26
|
import { checkThemeContrast } from './contrast.js';
|
|
27
|
+
import { mapTokenWarnings } from './map-tokens.js';
|
|
27
28
|
import { BRAND_IMAGE_KEYS, brandAssetFile } from './brand.js';
|
|
28
29
|
import { MAX_THEME_BYTES, cssProblems, cssUrls, themeAssetFile, themeFileUrl, themeFiles, themeIconFileProblems, themeUrlTarget } from './theme.js';
|
|
29
30
|
|
|
@@ -252,10 +253,10 @@ export function readTopology(config) {
|
|
|
252
253
|
/**
|
|
253
254
|
* Everything `cornfield validate` checks.
|
|
254
255
|
* @param {{ config: object, derivers: { deriver: object, options?: object }[], topology?: object|null }} opts
|
|
255
|
-
* @returns {Promise<{ errors: string[], warnings: string[], derived: object|null }>}
|
|
256
|
+
* @returns {Promise<{ errors: string[], warnings: string[], derived: object|null, notes: string[] }>}
|
|
256
257
|
*/
|
|
257
258
|
export async function validateRepo({ config, derivers, topology = readTopology(config) }) {
|
|
258
|
-
if (!topology) return { errors: [`${config.topology} is missing: run cornfield sync to make it.`], warnings: [], derived: null };
|
|
259
|
+
if (!topology) return { errors: [`${config.topology} is missing: run cornfield sync to make it.`], warnings: [], derived: null, notes: [] };
|
|
259
260
|
const errors = validateTopology(topology);
|
|
260
261
|
try {
|
|
261
262
|
errors.push(...missingPaths(topology, repoPaths(config.root)));
|
|
@@ -264,6 +265,7 @@ export async function validateRepo({ config, derivers, topology = readTopology(c
|
|
|
264
265
|
}
|
|
265
266
|
let derived = null;
|
|
266
267
|
const warnings = [];
|
|
268
|
+
const notes = []; // what held, for a pass to say (the contrast check's one line)
|
|
267
269
|
try {
|
|
268
270
|
derived = await deriveTopology({ root: config.root, config, derivers, map: topology });
|
|
269
271
|
warnings.push(...derived.warnings);
|
|
@@ -282,6 +284,8 @@ export async function validateRepo({ config, derivers, topology = readTopology(c
|
|
|
282
284
|
const contrast = checkThemeContrast(config);
|
|
283
285
|
errors.push(...contrast.errors);
|
|
284
286
|
warnings.push(...contrast.warnings);
|
|
287
|
+
if (contrast.summary) notes.push(contrast.summary);
|
|
288
|
+
warnings.push(...mapTokenWarnings(config)); // a map font, line width or glow the map cannot read draws as auto
|
|
285
289
|
errors.push(...validateCloudNodes(topology, config.root));
|
|
286
290
|
errors.push(...validateProposalFiles(topology, path.join(config.root, config.proposals), config.root));
|
|
287
291
|
const io = repoReader(config.root);
|
|
@@ -293,5 +297,5 @@ export async function validateRepo({ config, derivers, topology = readTopology(c
|
|
|
293
297
|
errors.push(`Deriver "${deriver.name}" could not check the map: ${err.message}`);
|
|
294
298
|
}
|
|
295
299
|
}
|
|
296
|
-
return { errors, warnings, derived };
|
|
300
|
+
return { errors, warnings, derived, notes };
|
|
297
301
|
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module explorer/connection
|
|
3
|
+
*
|
|
4
|
+
* Whether the browser is online, said once and in one place. `isOffline()` is `navigator.onLine === false`; when it changes a banner
|
|
5
|
+
* (`#offline-banner`, index.html) says "You are offline" or "You are back online" and the live region announces it once. Every failure
|
|
6
|
+
* that has no answer from the server (a failed fetch) is worded by the caller with `isOffline()`: offline it is "You are offline", not
|
|
7
|
+
* "cornfield could not be reached", and an action says it was not sent and keeps what the person typed.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { announce } from './keyboard.js';
|
|
11
|
+
|
|
12
|
+
export const OFFLINE_WORDS = 'You are offline. Nothing is sent until you are back; what you have typed is kept.';
|
|
13
|
+
export const ONLINE_WORDS = 'You are back online.';
|
|
14
|
+
/** How long "back online" stays on the banner */
|
|
15
|
+
export const BACK_MS = 5000;
|
|
16
|
+
|
|
17
|
+
let wired = false;
|
|
18
|
+
let hideTimer = 0;
|
|
19
|
+
|
|
20
|
+
/** Whether the browser says it has no network */
|
|
21
|
+
export const isOffline = () => typeof navigator !== 'undefined' && navigator.onLine === false;
|
|
22
|
+
|
|
23
|
+
/** The words for an action that got no answer: offline, it was not sent (and what was typed is still there); online, the server did not answer */
|
|
24
|
+
export function notSentWords(what) {
|
|
25
|
+
return isOffline() ? `You are offline. ${what} was not sent; what you typed is kept. Try again when you are back.` : `cornfield did not answer. ${what} was not sent; what you typed is kept.`;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function paint(said) {
|
|
29
|
+
const el = document.getElementById('offline-banner');
|
|
30
|
+
if (!el) return;
|
|
31
|
+
clearTimeout(hideTimer);
|
|
32
|
+
el.hidden = false;
|
|
33
|
+
el.textContent = said;
|
|
34
|
+
el.dataset.cornState = isOffline() ? 'failure' : 'success';
|
|
35
|
+
if (!isOffline()) hideTimer = setTimeout(() => { el.hidden = true; }, BACK_MS);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function onChange() {
|
|
39
|
+
const words = isOffline() ? OFFLINE_WORDS : ONLINE_WORDS;
|
|
40
|
+
paint(words);
|
|
41
|
+
announce(words);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Listens for the browser going offline and coming back (once); says so now if the page opened offline */
|
|
45
|
+
export function initConnection() {
|
|
46
|
+
if (wired || typeof window === 'undefined') return;
|
|
47
|
+
wired = true;
|
|
48
|
+
window.addEventListener('offline', onChange);
|
|
49
|
+
window.addEventListener('online', onChange);
|
|
50
|
+
if (isOffline()) paint(OFFLINE_WORDS);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** For tests: forget the wiring */
|
|
54
|
+
export function resetConnectionForTests() {
|
|
55
|
+
if (wired && typeof window !== 'undefined') {
|
|
56
|
+
window.removeEventListener('offline', onChange);
|
|
57
|
+
window.removeEventListener('online', onChange);
|
|
58
|
+
}
|
|
59
|
+
wired = false;
|
|
60
|
+
clearTimeout(hideTimer);
|
|
61
|
+
hideTimer = 0;
|
|
62
|
+
}
|
package/explorer/corn-state.js
CHANGED
|
@@ -5,12 +5,16 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
/** Every value `data-corn-state` can take */
|
|
8
|
-
export const CORN_STATES = Object.freeze(['open', 'merged', 'closed', 'draft', 'queued', 'running', 'waiting', 'done', 'failed', 'stopped', 'success', 'failure']);
|
|
8
|
+
export const CORN_STATES = Object.freeze(['open', 'merged', 'closed', 'draft', 'queued', 'running', 'requested', 'claimed', 'working', 'waiting', 'done', 'failed', 'stopped', 'success', 'failure']);
|
|
9
|
+
|
|
10
|
+
/** The seven states of an agent run, in the order of its life: each has its own `data-corn-state`, colour token (`--corn-run-<state>`) and icon */
|
|
11
|
+
export const RUN_STATES = Object.freeze(['requested', 'claimed', 'working', 'waiting', 'done', 'failed', 'stopped']);
|
|
9
12
|
|
|
10
13
|
/** The internal words that map onto a public one: a run's status, a check's or deploy's conclusion, a mockup's review, a verdict, a notice */
|
|
11
14
|
const WORDS = Object.freeze({
|
|
12
15
|
// A run's status: it is waiting to start, it is running, it waits on someone, or it ended
|
|
13
|
-
|
|
16
|
+
// (a run that went quiet waits on someone; one asked to stop has not stopped yet, but is no longer under way)
|
|
17
|
+
quiet: 'waiting', 'stop-requested': 'stopped',
|
|
14
18
|
// A check's or deploy's conclusion
|
|
15
19
|
neutral: 'done', skipped: 'done', cancelled: 'stopped',
|
|
16
20
|
// A mockup's review state
|
|
@@ -32,3 +36,31 @@ export function cornStateAttr(word) {
|
|
|
32
36
|
const s = cornState(word);
|
|
33
37
|
return s ? ` data-corn-state="${s}"` : '';
|
|
34
38
|
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The icon of a state: a shape as well as a colour, so the states differ in greyscale and for a person who cannot tell the colours apart.
|
|
42
|
+
* Each shape is its own silhouette (a dashed ring, a ring with a dot, an arc that turns, a warning triangle, a tick, a cross, a square),
|
|
43
|
+
* drawn with `currentColor` so the pill's colour carries it. Only `working` and `running` move, and not under `prefers-reduced-motion`.
|
|
44
|
+
*/
|
|
45
|
+
const ICONS = Object.freeze({
|
|
46
|
+
requested: '<circle cx="6" cy="6" r="4.2" stroke-dasharray="2 1.8"/>',
|
|
47
|
+
queued: '<circle cx="6" cy="6" r="4.2" stroke-dasharray="2 1.8"/>',
|
|
48
|
+
claimed: '<circle cx="6" cy="6" r="4.2"/><circle cx="6" cy="6" r="1.4" fill="currentColor" stroke="none"/>',
|
|
49
|
+
working: '<path class="hx-state-spin" d="M6 1.8a4.2 4.2 0 1 1-4.2 4.2"/>',
|
|
50
|
+
running: '<path class="hx-state-spin" d="M6 1.8a4.2 4.2 0 1 1-4.2 4.2"/>',
|
|
51
|
+
waiting: '<path d="M6 1.2L11 10.4H1Z" stroke-linejoin="round"/><path d="M6 4.6v2.7M6 8.6v.1"/>',
|
|
52
|
+
done: '<path d="M2 6.4l2.6 2.6L10 3.4"/>',
|
|
53
|
+
success: '<path d="M2 6.4l2.6 2.6L10 3.4"/>',
|
|
54
|
+
failed: '<path d="M2.6 2.6l6.8 6.8M9.4 2.6L2.6 9.4"/>',
|
|
55
|
+
failure: '<path d="M2.6 2.6l6.8 6.8M9.4 2.6L2.6 9.4"/>',
|
|
56
|
+
stopped: '<rect x="2.4" y="2.4" width="7.2" height="7.2" rx="1" fill="currentColor"/>',
|
|
57
|
+
neutral: '<path d="M2.4 6h7.2"/>',
|
|
58
|
+
skipped: '<path d="M2.4 6h7.2"/>',
|
|
59
|
+
cancelled: '<circle cx="6" cy="6" r="4.2"/><path d="M3 9L9 3"/>',
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
/** The icon for a state word (a public `data-corn-state` value, or an internal word such as a check's `neutral`), as an inline SVG; '' when it has none */
|
|
63
|
+
export function stateIconHtml(word) {
|
|
64
|
+
const shape = ICONS[String(word || '')] || ICONS[cornState(word)];
|
|
65
|
+
return shape ? `<svg class="hx-state-icon" data-corn="state-icon" width="12" height="12" viewBox="0 0 12 12" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" aria-hidden="true" focusable="false">${shape}</svg>` : '';
|
|
66
|
+
}
|