cornfield 0.24.0 → 0.26.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.
@@ -172,7 +172,7 @@ export function proposalPanelHtml(item) {
172
172
  const body = rows.map((r) => (item.mark === 'changed'
173
173
  ? `<div class="hx-change"><span class="hx-change-field">${escHtml(r.field)}</span><span class="hx-change-before">${escHtml(r.before) || '<em>nothing</em>'}</span><span class="hx-change-arrow" aria-hidden="true">→</span><span class="hx-change-after">${escHtml(r.after) || '<em>nothing</em>'}</span></div>`
174
174
  : `<div class="hx-change"><span class="hx-change-field">${escHtml(r.field)}</span><span class="hx-change-after">${escHtml(r.after)}</span></div>`)).join('');
175
- return `<div class="hx-sec hx-proposal-sec hx-proposal-sec--${escHtml(item.mark)}" data-proposal-mark="${escHtml(item.mark)}">
175
+ return `<div class="hx-sec hx-proposal-sec hx-proposal-sec--${escHtml(item.mark)}" data-proposal-mark="${escHtml(item.mark)}" data-corn="section">
176
176
  <strong class="hx-strong"><span class="hx-mark-dot hx-mark-dot--${escHtml(item.mark)}"></span>${escHtml(item.mark === 'edit' ? `${item.editOp === 'removed' ? 'Removed' : 'Added'} by your edit` : `${MARK_WORDS[item.mark] || item.mark} by this proposal`)}</strong>
177
177
  ${item.why ? `<div class="hx-why">${escHtml(item.why)}</div>` : ''}
178
178
  ${body}
@@ -282,10 +282,10 @@ function renderChanges() {
282
282
  const rows = [];
283
283
  for (const mark of [...MARKS, 'edit']) {
284
284
  for (const n of state.nodes.filter((x) => x.mark === mark)) {
285
- rows.push(`<button type="button" class="hx-change-row" data-action="proposal-focus" data-kind="node" data-key="${escHtml(n.id)}"><span class="hx-mark-dot hx-mark-dot--${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>`);
285
+ 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}"></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>`);
286
286
  }
287
287
  for (const e of state.edges.filter((x) => x.mark === mark && said.has(edgeKey(x)))) {
288
- rows.push(`<button type="button" class="hx-change-row" data-action="proposal-focus" data-kind="edge" data-key="${escHtml(edgeKey(e))}"><span class="hx-mark-dot hx-mark-dot--${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>`);
288
+ 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}"></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>`);
289
289
  }
290
290
  }
291
291
  list.innerHTML = rows.join('') || '<p class="hx-faint">This proposal changes nothing on the map.</p>';
@@ -350,13 +350,13 @@ export function proposalRowHtml(entry, current) {
350
350
  const meta = [`<span class="hx-proposal-where">${escHtml(where(entry))}</span>`];
351
351
  if (entry.spec) meta.push(`<span>spec ${escHtml(entry.spec)}</span>`);
352
352
  if (entry.error) {
353
- return `<div class="hx-proposal-item is-broken">${head}<span class="hx-proposal-sum hx-error-text">${escHtml(entry.error)}</span><span class="hx-proposal-meta">${meta.join('')}</span></div>`;
353
+ return `<div class="hx-proposal-item is-broken" data-corn="row">${head}<span class="hx-proposal-sum hx-error-text">${escHtml(entry.error)}</span><span class="hx-proposal-meta">${meta.join('')}</span></div>`;
354
354
  }
355
355
  if (entry.counts) meta.push(`<span>${escHtml(chipText(entry.counts))}</span>`);
356
356
  const reviewed = reviewWords(entry.review, Date.now()); // "Approved 3 minutes ago", from the listing
357
357
  if (reviewed) meta.push(`<span class="hx-proposal-reviewed">${escHtml(reviewed)}</span>`);
358
358
  if (entry.errors) meta.push(`<span class="hx-warn">${escHtml(plural(entry.errors, 'problem'))}</span>`);
359
- return `<button type="button" class="hx-proposal-item${mine ? ' is-current' : ''}" data-action="open-proposal" data-slug="${escHtml(entry.slug)}" data-source="${escHtml(entry.source)}">${head}${entry.summary ? `<span class="hx-proposal-sum">${escHtml(entry.summary)}</span>` : ''}<span class="hx-proposal-meta">${meta.join('')}</span></button>`;
359
+ return `<button type="button" class="hx-proposal-item${mine ? ' is-current' : ''}" data-action="open-proposal" data-slug="${escHtml(entry.slug)}" data-source="${escHtml(entry.source)}" data-corn="row">${head}${entry.summary ? `<span class="hx-proposal-sum">${escHtml(entry.summary)}</span>` : ''}<span class="hx-proposal-meta">${meta.join('')}</span></button>`;
360
360
  }
361
361
 
362
362
  function renderMenu(loading = false) {
@@ -41,6 +41,7 @@ export function rendererPreference(search) {
41
41
  function addStandIn(canvas) {
42
42
  const standIn = canvas.ownerDocument.createElement('canvas');
43
43
  standIn.className = 'hx-overlay';
44
+ standIn.setAttribute('data-corn', 'map-overlay');
44
45
  standIn.setAttribute('aria-hidden', 'true');
45
46
  canvas.after(standIn);
46
47
  return standIn;
@@ -55,7 +55,7 @@ function paint() {
55
55
  else {
56
56
  list.innerHTML = ui.tokens.map((t) => {
57
57
  const line = tokenLine(t, now());
58
- return `<li class="hx-tokens-item" data-state="${line.state}"><span class="hx-tokens-label">${escHtml(line.label)}</span> <span class="hx-tokens-meta hx-faint">${escHtml(line.status)} · ${escHtml(line.used)}</span> ${line.canRevoke ? `<button type="button" class="hx-btn hx-btn--quiet" data-revoke="${escHtml(String(line.id))}" aria-label="Revoke ${escHtml(line.label)}"${ui.busy ? ' disabled' : ''}>Revoke</button>` : ''}</li>`;
58
+ return `<li class="hx-tokens-item" data-state="${line.state}" data-corn="row"><span class="hx-tokens-label">${escHtml(line.label)}</span> <span class="hx-tokens-meta hx-faint">${escHtml(line.status)} · ${escHtml(line.used)}</span> ${line.canRevoke ? `<button type="button" class="hx-btn hx-btn--quiet" data-revoke="${escHtml(String(line.id))}" aria-label="Revoke ${escHtml(line.label)}"${ui.busy ? ' disabled' : ''} data-corn-kind="danger">Revoke</button>` : ''}</li>`;
59
59
  }).join('');
60
60
  }
61
61
  const intro = $('tokens-intro');
@@ -64,6 +64,7 @@ function paint() {
64
64
  msg.hidden = !ui.message;
65
65
  msg.textContent = ui.message ? ui.message.text : '';
66
66
  msg.classList.toggle('hx-forge-msg--bad', !!ui.message && !ui.message.ok);
67
+ if (ui.message && !ui.message.ok) msg.dataset.cornState = 'failure'; else delete msg.dataset.cornState;
67
68
  $('tokens-make').disabled = ui.busy;
68
69
  }
69
70
 
@@ -60,12 +60,13 @@ function mount() {
60
60
  root = document.createElement('div');
61
61
  root.id = 'review';
62
62
  root.className = 'hx-review';
63
+ root.dataset.corn = 'review-bar';
63
64
  root.setAttribute('aria-label', 'Approve or send back');
64
65
  root.innerHTML = `
65
66
  <label class="hx-review-label" for="review-note">Note for the drafting agent</label>
66
67
  <textarea id="review-note" class="hx-review-note" rows="2" maxlength="20000" placeholder="What should change? Needed to send it back, optional to approve."></textarea>
67
68
  <div class="hx-review-row">
68
- <button type="button" class="hx-btn hx-btn--approve" data-review="approved" title="Sign this proposal off">Approve</button>
69
+ <button type="button" class="hx-btn hx-btn--approve" data-review="approved" title="Sign this proposal off" data-corn-kind="approve">Approve</button>
69
70
  <button type="button" class="hx-btn" data-review="notes" title="Send it back to the drafting agent with the note and your edits">Send back</button>
70
71
  <span class="hx-review-status" data-review-status role="status"></span>
71
72
  </div>
@@ -108,6 +108,7 @@ export function syncRunOverlay(scene, camera) {
108
108
  el.className = `hx-run-mark hx-run-mark--${kind}`;
109
109
  el.dataset.node = node.id;
110
110
  el.dataset.kind = kind;
111
+ el.dataset.corn = 'run-mark';
111
112
  el.innerHTML = `<span class="hx-run-ring"></span>${kind === 'collision' ? `<span class="hx-run-tag"><span class="hx-run-sign">⚠</span> ${collisionTag(runs.length)}</span>` : ''}`;
112
113
  layer.append(el);
113
114
  marks.set(key, el);
@@ -10,6 +10,7 @@
10
10
 
11
11
  import { relativeTime } from './review-model.js';
12
12
  import { runTone, canRetry, aboutWords, statusWords, statusWhy, runMeta, canStop, canAnswer, groupRuns, compareTitle, limitRows, checksWords, timelineWords, nodeLabels, collisionWords, answerWords } from './runs-model.js';
13
+ import { cornStateAttr } from './corn-state.js';
13
14
 
14
15
 
15
16
  /**
@@ -84,8 +85,8 @@ function answerHtml(ctx, run) {
84
85
  const reply = ctx.replies && ctx.replies.get(run.runId) || '';
85
86
  return `${run.answer ? answeredHtml(ctx, run) : ''}<div class="hx-run-actions" role="group" aria-label="Answer run ${id}">
86
87
  <button type="button" class="hx-btn hx-forge-act" data-run-answer="continue" data-run-id="${id}" aria-label="Continue run ${id}"${off}>Continue</button>
87
- <button type="button" class="hx-btn hx-forge-act" data-run-answer="stop" data-run-id="${id}" aria-label="Stop run ${id}"${off}>Stop</button></div>
88
- <label class="hx-forge-field">Reply to run ${id}<input type="text" class="hx-forge-input" data-run-reply="${id}" value="${ctx.esc(reply)}" maxlength="4000" autocomplete="off" /></label>
88
+ <button type="button" class="hx-btn hx-forge-act" data-run-answer="stop" data-run-id="${id}" aria-label="Stop run ${id}"${off} data-corn-kind="danger">Stop</button></div>
89
+ <label class="hx-forge-field" data-corn="field">Reply to run ${id}<input type="text" class="hx-forge-input" data-run-reply="${id}" value="${ctx.esc(reply)}" maxlength="4000" autocomplete="off" /></label>
89
90
  <div class="hx-run-actions"><button type="button" class="hx-btn hx-forge-act" data-run-answer="reply" data-run-id="${id}" aria-label="Send reply to run ${id}"${off}>Reply</button></div>`;
90
91
  }
91
92
 
@@ -103,14 +104,14 @@ export function runHtml(ctx, run, all) {
103
104
  const note = run.report && run.report.note ? `<p class="hx-forge-meta">Runner: ${ctx.esc(run.report.note)}</p>` : '';
104
105
  const answering = canAnswer(run);
105
106
  const retry = canRetry(run) ? `<button type="button" class="hx-btn hx-forge-act" data-forge-retry="${ctx.esc(run.runId)}" aria-label="Start again on run ${ctx.esc(run.runId)}"${ctx.busy ? ' disabled' : ''}>Start again</button>` : '';
106
- const stop = canStop(run) && !answering ? `<button type="button" class="hx-btn hx-forge-act" data-forge-stop="${ctx.esc(run.runId)}" aria-label="Stop run ${ctx.esc(run.runId)}"${ctx.busy ? ' disabled' : ''}>Stop</button>` : '';
107
+ const stop = canStop(run) && !answering ? `<button type="button" class="hx-btn hx-forge-act" data-forge-stop="${ctx.esc(run.runId)}" aria-label="Stop run ${ctx.esc(run.runId)}"${ctx.busy ? ' disabled' : ''} data-corn-kind="danger">Stop</button>` : '';
107
108
  const names = nodeLabels(run.nodes, ctx.nodes);
108
109
  const collision = collisionWords(run, all, ctx.nodes);
109
110
  const limits = limitRows(run);
110
111
  const count = (run.timeline || []).length;
111
112
  const links = linksHtml(ctx, run);
112
- return `<li class="hx-run hx-forge-file" data-run="${ctx.esc(run.runId)}" tabindex="-1">
113
- <div class="hx-run-head"><span class="hx-forge-state hx-forge-state--${tone}">${ctx.esc(statusWords(run))}</span> <span class="hx-name">${ctx.esc(run.kind)} on ${ctx.esc(aboutWords(run.refs))}</span>${run.profile ? ` <span class="hx-faint">profile ${ctx.esc(run.profile)}</span>` : ''}</div>
113
+ return `<li class="hx-run hx-forge-file" data-run="${ctx.esc(run.runId)}" tabindex="-1" data-corn="run"${cornStateAttr(run.status)}>
114
+ <div class="hx-run-head"><span class="hx-forge-state hx-forge-state--${tone}" data-corn="state-pill"${cornStateAttr(run.status)}>${ctx.esc(statusWords(run))}</span> <span class="hx-name">${ctx.esc(run.kind)} on ${ctx.esc(aboutWords(run.refs))}</span>${run.profile ? ` <span class="hx-faint">profile ${ctx.esc(run.profile)}</span>` : ''}</div>
114
115
  ${collision ? `<p class="hx-run-collide"><span aria-hidden="true">⚠</span> ${ctx.esc(collision)}</p>` : ''}
115
116
  <p class="hx-forge-meta">${ctx.esc(runMeta(run, ctx.now))}</p>${why ? `<p class="hx-forge-why hx-faint">${ctx.esc(why)}</p>` : ''}${note}
116
117
  <dl class="hx-run-limits" aria-label="Limits and what the runner reported">${limits.length ? limits.map((r) => `<dt>${ctx.esc(r.name)}</dt><dd>limit: ${ctx.esc(r.limit)}; reported: ${ctx.esc(r.reported)}</dd>`).join('') : '<dt>Limits</dt><dd>none asked, nothing reported</dd>'}</dl>
@@ -180,18 +180,19 @@ function showBar(speed) {
180
180
  if (!stage) return;
181
181
  bar = document.createElement('div');
182
182
  bar.className = 'hx-player glass';
183
+ bar.dataset.corn = 'scenario-player';
183
184
  bar.setAttribute('role', 'region');
184
185
  bar.setAttribute('aria-label', 'Scenario player');
185
186
  bar.innerHTML = `
186
187
  <div class="hx-player-head">
187
188
  <span class="hx-player-title"></span>
188
189
  <select class="hx-player-speed" data-action="scenario-speed" aria-label="Time for each step" title="Time for each step">${SPEED_CHOICES.map((c) => `<option value="${c.value}">${c.label}</option>`).join('')}</select>
189
- <button type="button" class="hx-close" data-action="scenario-close" aria-label="Close the scenario">✕</button>
190
+ <button type="button" class="hx-close" data-action="scenario-close" aria-label="Close the scenario" data-corn-kind="icon">✕</button>
190
191
  </div>
191
192
  <p class="hx-player-text" aria-live="polite"><span class="hx-player-count"></span> · <span class="hx-player-step"></span></p>
192
193
  <div class="hx-player-controls">
193
194
  <button type="button" class="hx-btn" data-action="scenario-prev">◀ Previous</button>
194
- <button type="button" class="hx-btn hx-btn--active" data-action="scenario-toggle"></button>
195
+ <button type="button" class="hx-btn hx-btn--active" data-action="scenario-toggle" data-corn-kind="primary"></button>
195
196
  <button type="button" class="hx-btn" data-action="scenario-next">Next ▶</button>
196
197
  </div>
197
198
  <div class="hx-player-track" aria-hidden="true"><span class="hx-player-fill"></span></div>`;
@@ -326,6 +327,7 @@ export function refreshList() {
326
327
  const button = document.createElement('button');
327
328
  button.type = 'button';
328
329
  button.className = 'hx-scenarios-item';
330
+ button.dataset.corn = 'row';
329
331
  button.dataset.scenario = s.id;
330
332
  const steps = (s.steps || []).length;
331
333
  button.textContent = `${s.title} · ${steps} ${steps === 1 ? 'step' : 'steps'}`;
@@ -108,6 +108,7 @@ export function registerSheet(id, el) {
108
108
  handle = document.createElement('button');
109
109
  handle.type = 'button';
110
110
  handle.className = 'hx-sheet-handle';
111
+ handle.dataset.corn = 'sheet-handle';
111
112
  handle.innerHTML = '<span></span>';
112
113
  el.prepend(handle);
113
114
  }
@@ -23,10 +23,12 @@
23
23
  * lightColor(css, role) one colour for the light ground (memoised)
24
24
  * themed(css, theme, role) the same, or the colour untouched in the dark theme
25
25
  * lightenScene(scene) every colour of a built scene, in place (scene.js calls it)
26
- * contrast(a, b) the WCAG contrast ratio of two CSS colours
26
+ * contrast(a, b) the WCAG contrast ratio of two CSS colours (core/color.js)
27
27
  * parseColor(css) a CSS colour as [r, g, b, a] (scene.js re-exports it for the renderers)
28
28
  */
29
29
 
30
+ import { parseColor, luminance, ratio, contrast } from '../core/color.js';
31
+
30
32
  export const THEME_CHOICES = ['system', 'light', 'dark'];
31
33
  /** Where the choice is kept in the browser (theme.js); `?theme=` in the address wins over it, without being kept */
32
34
  export const THEME_STORAGE_KEY = 'topology-explorer:theme';
@@ -101,28 +103,9 @@ export function themeWords(choice, theme) {
101
103
  // Colour arithmetic
102
104
  // ---------------------------------------------------------------------------
103
105
 
104
- /** `#rgb`, `#rrggbb`, `rgb(...)` or `rgba(...)` → `[r, g, b, a]` (0..255, alpha 0..1); transparent for anything else. scene.js re-exports it. */
105
- export function parseColor(css) {
106
- const s = String(css).trim().toLowerCase();
107
- let m = /^#([0-9a-f]{3})$/.exec(s);
108
- if (m) return [...m[1]].map((h) => parseInt(h + h, 16)).concat(1);
109
- m = /^#([0-9a-f]{6})$/.exec(s);
110
- if (m) return [parseInt(m[1].slice(0, 2), 16), parseInt(m[1].slice(2, 4), 16), parseInt(m[1].slice(4, 6), 16), 1];
111
- m = /^rgba?\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)\s*(?:,\s*([\d.]+)\s*)?\)$/.exec(s);
112
- if (m) return [Number(m[1]), Number(m[2]), Number(m[3]), m[4] === undefined ? 1 : Number(m[4])];
113
- return [0, 0, 0, 0];
114
- }
115
-
116
- const channel = (v) => {
117
- const c = v / 255;
118
- return c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;
119
- };
120
- /** WCAG relative luminance of `[r, g, b]` (0..255) */
121
- export const luminance = ([r, g, b]) => 0.2126 * channel(r) + 0.7152 * channel(g) + 0.0722 * channel(b);
122
- const ratio = (la, lb) => (Math.max(la, lb) + 0.05) / (Math.min(la, lb) + 0.05);
123
-
124
- /** The WCAG contrast ratio of two opaque CSS colours (alpha is ignored) */
125
- export const contrast = (a, b) => ratio(luminance(parseColor(a)), luminance(parseColor(b)));
106
+ // The colour arithmetic (parseColor, luminance, ratio, contrast) is core/color.js, shared with `cornfield validate`'s contrast check;
107
+ // scene.js and the tests still import it from here.
108
+ export { parseColor, luminance, contrast };
126
109
 
127
110
  /** `[r, g, b]` (0..255) to `[h, s, l]` (h in degrees, s and l 0..1) */
128
111
  export function toHsl([r, g, b]) {
@@ -32,14 +32,14 @@
32
32
  /* Text */
33
33
  --corn-text: #f8fafc;
34
34
  --corn-text-2: #cbd5e1;
35
- --corn-text-3: #94a3b8;
35
+ --corn-text-3: #9aa9bc;
36
36
  --corn-text-on-accent: #fff;
37
37
  --corn-mockup-ground: #fff;
38
38
 
39
39
  /* Accent */
40
40
  --corn-accent: #4f46e5;
41
- --corn-accent-hover: #6366f1;
42
- --corn-accent-text: #818cf8;
41
+ --corn-accent-hover: #6265f1;
42
+ --corn-accent-text: #98a1fa;
43
43
  --corn-accent-soft: color-mix(in srgb, var(--corn-accent-hover) 20%, transparent);
44
44
  --corn-focus: #818cf8;
45
45
  --corn-brand-gradient: linear-gradient(135deg, #4299e1 0%, #818cf8 50%, #e53e3e 100%);
@@ -68,6 +68,9 @@
68
68
  --corn-hue-fuchsia: #e879f9;
69
69
  --corn-hue-pink: #f472b6;
70
70
  --corn-hue-lime: #a3e635;
71
+ /* The orange as text on its own tint (the data-flow note in the Layers menu): the tint is the hue at 12% */
72
+ --corn-hue-orange-text: var(--corn-hue-orange);
73
+ --corn-hue-orange-soft: color-mix(in srgb, var(--corn-hue-orange) 12%, transparent);
71
74
 
72
75
  /* Type */
73
76
  --corn-font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
@@ -135,10 +138,10 @@
135
138
  --corn-focus: #4f46e5;
136
139
  --corn-brand-gradient: linear-gradient(135deg, #2563eb 0%, #4f46e5 50%, #dc2626 100%);
137
140
 
138
- --corn-ok: #047857;
141
+ --corn-ok: #046f51;
139
142
  --corn-warn: #854d0e;
140
143
  --corn-bad: #b91c1c;
141
- --corn-info: #0369a1;
144
+ --corn-info: #03679e;
142
145
 
143
146
  --corn-added: #209a8b;
144
147
  --corn-changed: #b28103;
@@ -148,7 +151,8 @@
148
151
  --corn-hue-orange: #c2410c;
149
152
  --corn-hue-fuchsia: #a21caf;
150
153
  --corn-hue-pink: #be185d;
151
- --corn-hue-lime: #4d7c0f;
154
+ --corn-hue-lime: #4c7b0f;
155
+ --corn-hue-orange-text: #9a3412;
152
156
 
153
157
  --corn-house-line: color-mix(in srgb, var(--corn-hue-lime) 30%, transparent);
154
158
  --corn-house-room: color-mix(in srgb, var(--corn-hue-lime) 55%, transparent);
@@ -183,10 +187,10 @@
183
187
  --corn-focus: #4f46e5;
184
188
  --corn-brand-gradient: linear-gradient(135deg, #2563eb 0%, #4f46e5 50%, #dc2626 100%);
185
189
 
186
- --corn-ok: #047857;
190
+ --corn-ok: #046f51;
187
191
  --corn-warn: #854d0e;
188
192
  --corn-bad: #b91c1c;
189
- --corn-info: #0369a1;
193
+ --corn-info: #03679e;
190
194
 
191
195
  --corn-added: #209a8b;
192
196
  --corn-changed: #b28103;
@@ -196,7 +200,8 @@
196
200
  --corn-hue-orange: #c2410c;
197
201
  --corn-hue-fuchsia: #a21caf;
198
202
  --corn-hue-pink: #be185d;
199
- --corn-hue-lime: #4d7c0f;
203
+ --corn-hue-lime: #4c7b0f;
204
+ --corn-hue-orange-text: #9a3412;
200
205
 
201
206
  --corn-house-line: color-mix(in srgb, var(--corn-hue-lime) 30%, transparent);
202
207
  --corn-house-room: color-mix(in srgb, var(--corn-hue-lime) 55%, transparent);
@@ -227,6 +227,7 @@ function mount() {
227
227
  root = document.createElement('div');
228
228
  root.id = 'whatif';
229
229
  root.className = 'hx-whatif';
230
+ root.dataset.corn = 'whatif';
230
231
  root.setAttribute('aria-label', 'Try a change');
231
232
  root.innerHTML = `
232
233
  <div class="hx-whatif-row" role="toolbar" aria-label="Try a change">
@@ -238,8 +239,8 @@ function mount() {
238
239
  <button type="button" class="hx-btn" data-whatif="steps" aria-expanded="false" title="Add, reword, reorder or delete the steps of a scenario">Steps</button>
239
240
  </div>
240
241
  <p class="hx-whatif-hint" data-hint hidden>Drag from one node to another. Escape cancels.</p>
241
- <p class="hx-whatif-msg" data-msg="toolbar" role="status" hidden></p>
242
- <p class="hx-whatif-notice" data-notice role="status" hidden></p>
242
+ <p class="hx-whatif-msg" data-msg="toolbar" role="status" hidden data-corn="message"></p>
243
+ <p class="hx-whatif-notice" data-notice role="status" hidden data-corn="notice"></p>
243
244
  <div class="hx-whatif-panel" data-panel="confirm" hidden></div>
244
245
  <div class="hx-whatif-panel" data-panel="form" hidden></div>
245
246
  <div class="hx-whatif-panel" data-panel="edits" hidden></div>
@@ -316,7 +317,7 @@ function paintConfirm() {
316
317
  <div class="hx-whatif-actions">
317
318
  <button type="button" class="hx-btn hx-btn--active" data-whatif="close-keep">Close and keep my edits</button>
318
319
  <button type="button" class="hx-btn" data-whatif="close-discard">Close and throw them away</button>
319
- <button type="button" class="hx-btn hx-btn--quiet" data-whatif="close-cancel">Keep editing</button>
320
+ <button type="button" class="hx-btn hx-btn--quiet" data-whatif="close-cancel" data-corn-kind="quiet">Keep editing</button>
320
321
  </div>`;
321
322
  }
322
323
 
@@ -350,16 +351,16 @@ function paintForm() {
350
351
  box.innerHTML = `
351
352
  <form class="hx-whatif-form" data-form="node" autocomplete="off">
352
353
  <strong class="hx-strong">Add a node</strong>
353
- <label class="hx-whatif-field">Type <select name="nodeType">${typeOptions('page')}</select></label>
354
- <label class="hx-whatif-field">Label <input name="label" class="hx-whatif-input" placeholder="/meals" required></label>
355
- <label class="hx-whatif-field">Parent <select name="parent">${options.join('')}</select></label>
354
+ <label class="hx-whatif-field" data-corn="field">Type <select name="nodeType">${typeOptions('page')}</select></label>
355
+ <label class="hx-whatif-field" data-corn="field">Label <input name="label" class="hx-whatif-input" placeholder="/meals" required></label>
356
+ <label class="hx-whatif-field" data-corn="field">Parent <select name="parent">${options.join('')}</select></label>
356
357
  <p class="hx-faint hx-whatif-help">Click a node on the map to make it the parent. A page label starts with a slash, like /meals.</p>
357
- <label class="hx-whatif-field">Description <input name="desc" class="hx-whatif-input" placeholder="Optional"></label>
358
+ <label class="hx-whatif-field" data-corn="field">Description <input name="desc" class="hx-whatif-input" placeholder="Optional"></label>
358
359
  <div class="hx-whatif-actions">
359
360
  <button type="submit" class="hx-btn hx-btn--active">Add node</button>
360
- <button type="button" class="hx-btn hx-btn--quiet" data-whatif="cancel-form">Cancel</button>
361
+ <button type="button" class="hx-btn hx-btn--quiet" data-whatif="cancel-form" data-corn-kind="quiet">Cancel</button>
361
362
  </div>
362
- <p class="hx-whatif-msg" data-msg="form" role="alert" hidden></p>
363
+ <p class="hx-whatif-msg" data-msg="form" role="alert" hidden data-corn="message"></p>
363
364
  </form>`;
364
365
  box.querySelector('[name="nodeType"]').value = 'page';
365
366
  box.querySelector('[name="parent"]').value = parent;
@@ -372,14 +373,14 @@ function paintForm() {
372
373
  <form class="hx-whatif-form" data-form="edge" autocomplete="off">
373
374
  <strong class="hx-strong">Draw an edge</strong>
374
375
  <p class="hx-whatif-pair"><span class="hx-name">${escHtml(nameOf(form.from))}</span> → <span class="hx-name">${escHtml(nameOf(form.to))}</span></p>
375
- <label class="hx-whatif-field">Kind <select name="kind">${M.EDGE_CHOICES.map((c) => `<option value="${escHtml(c.value)}"${c.value === suggested ? ' selected' : ''}>${escHtml(c.label)}</option>`).join('')}</select></label>
376
- <label class="hx-whatif-field" data-flow-field hidden>Flow <select name="flow">${M.FLOW_KINDS.map((f) => `<option value="${escHtml(f)}">${escHtml(f)}</option>`).join('')}</select></label>
377
- <label class="hx-whatif-field">Label <input name="label" class="hx-whatif-input" placeholder="Optional"></label>
376
+ <label class="hx-whatif-field" data-corn="field">Kind <select name="kind">${M.EDGE_CHOICES.map((c) => `<option value="${escHtml(c.value)}"${c.value === suggested ? ' selected' : ''}>${escHtml(c.label)}</option>`).join('')}</select></label>
377
+ <label class="hx-whatif-field" data-flow-field hidden data-corn="field">Flow <select name="flow">${M.FLOW_KINDS.map((f) => `<option value="${escHtml(f)}">${escHtml(f)}</option>`).join('')}</select></label>
378
+ <label class="hx-whatif-field" data-corn="field">Label <input name="label" class="hx-whatif-input" placeholder="Optional"></label>
378
379
  <div class="hx-whatif-actions">
379
380
  <button type="submit" class="hx-btn hx-btn--active">Add edge</button>
380
- <button type="button" class="hx-btn hx-btn--quiet" data-whatif="cancel-form">Cancel</button>
381
+ <button type="button" class="hx-btn hx-btn--quiet" data-whatif="cancel-form" data-corn-kind="quiet">Cancel</button>
381
382
  </div>
382
- <p class="hx-whatif-msg" data-msg="form" role="alert" hidden></p>
383
+ <p class="hx-whatif-msg" data-msg="form" role="alert" hidden data-corn="message"></p>
383
384
  </form>`;
384
385
  box.querySelector('[name="kind"]').value = suggested;
385
386
  syncFlowField();
@@ -439,7 +440,7 @@ function paintEdits() {
439
440
  };
440
441
  const rows = state.whatIf.edits.map((edit, i) => `<li class="hx-whatif-edit"><span class="hx-mark-dot hx-mark-dot--edit"></span><span class="hx-whatif-edit-text">${escHtml(M.describeEdit(edit, words))}</span><button type="button" class="hx-textbtn" data-whatif="remove-edit" data-index="${i}" aria-label="Remove this edit: ${escHtml(M.describeEdit(edit, words))}">Remove</button></li>`);
441
442
  box.innerHTML = rows.length
442
- ? `<ol class="hx-whatif-list">${rows.join('')}</ol><p class="hx-whatif-msg" data-msg="edits" role="status" hidden></p>`
443
+ ? `<ol class="hx-whatif-list">${rows.join('')}</ol><p class="hx-whatif-msg" data-msg="edits" role="status" hidden data-corn="message"></p>`
443
444
  : '<p class="hx-faint">No edits yet. Add a node, draw an edge or change a step, and it appears here.</p>';
444
445
  paintMessages();
445
446
  }
@@ -474,17 +475,17 @@ function paintSteps() {
474
475
  box.innerHTML = `
475
476
  <div class="hx-whatif-form">
476
477
  <div class="hx-whatif-actions">
477
- <label class="hx-whatif-field">Scenario <select data-scenario-select>${scenarios.map((s) => `<option value="${escHtml(s.id)}"${s.id === ui.scenarioId ? ' selected' : ''}>${escHtml(s.title)}</option>`).join('')}<option value="${NEW}"${ui.scenarioId === NEW ? ' selected' : ''}>New scenario…</option></select></label>
478
+ <label class="hx-whatif-field" data-corn="field">Scenario <select data-scenario-select>${scenarios.map((s) => `<option value="${escHtml(s.id)}"${s.id === ui.scenarioId ? ' selected' : ''}>${escHtml(s.title)}</option>`).join('')}<option value="${NEW}"${ui.scenarioId === NEW ? ' selected' : ''}>New scenario…</option></select></label>
478
479
  ${scenario ? '<button type="button" class="hx-btn" data-whatif="play-scenario">Play</button>' : ''}
479
480
  </div>
480
481
  ${rows.length ? `<ol class="hx-whatif-list hx-whatif-steps">${rows.join('')}</ol>` : '<p class="hx-faint">No steps yet.</p>'}
481
482
  <form class="hx-whatif-addstep" data-form="step" autocomplete="off">
482
- ${ui.scenarioId === NEW ? `<label class="hx-whatif-field">Title <input name="title" class="hx-whatif-input" placeholder="Add a meal" value="${escHtml(ui.titleDraft)}"></label>` : ''}
483
- <label class="hx-whatif-field">New step <input name="text" class="hx-whatif-input" placeholder="What happens here?" value="${escHtml(ui.stepDraft)}"></label>
483
+ ${ui.scenarioId === NEW ? `<label class="hx-whatif-field" data-corn="field">Title <input name="title" class="hx-whatif-input" placeholder="Add a meal" value="${escHtml(ui.titleDraft)}"></label>` : ''}
484
+ <label class="hx-whatif-field" data-corn="field">New step <input name="text" class="hx-whatif-input" placeholder="What happens here?" value="${escHtml(ui.stepDraft)}"></label>
484
485
  <button type="submit" class="hx-btn hx-btn--active" data-step-add>Add step</button>
485
486
  <span class="hx-faint hx-whatif-pointing" data-step-target></span>
486
487
  </form>
487
- <p class="hx-whatif-msg" data-msg="steps" role="alert" hidden></p>
488
+ <p class="hx-whatif-msg" data-msg="steps" role="alert" hidden data-corn="message"></p>
488
489
  </div>`;
489
490
  paintStepTarget();
490
491
  paintMessages();
@@ -543,7 +544,7 @@ function edgeToHtml(n) {
543
544
  .slice(0, EDGE_TO_MAX);
544
545
  if (!others.length) return '';
545
546
  return `<div class="hx-whatif-addstep hx-whatif-edgeto">
546
- <label class="hx-whatif-field">Edge to <select data-edge-to>${others.map((o) => `<option value="${escHtml(o.id)}">${escHtml(o.label)} (${escHtml(o.type)})</option>`).join('')}</select></label>
547
+ <label class="hx-whatif-field" data-corn="field">Edge to <select data-edge-to>${others.map((o) => `<option value="${escHtml(o.id)}">${escHtml(o.label)} (${escHtml(o.type)})</option>`).join('')}</select></label>
547
548
  <button type="button" class="hx-btn" data-whatif="edge-to" data-from="${escHtml(n.id)}" title="Draw an edge from this node to the one picked, without dragging">Draw an edge</button>
548
549
  </div>`;
549
550
  }
@@ -555,7 +556,7 @@ function paintDrawer() {
555
556
  box.hidden = !open;
556
557
  if (!open) { box.innerHTML = ''; return; }
557
558
 
558
- const message = '<p class="hx-whatif-msg" data-msg="drawer" role="alert" hidden></p>';
559
+ const message = '<p class="hx-whatif-msg" data-msg="drawer" role="alert" hidden data-corn="message"></p>';
559
560
  const title = '<h3 class="hx-block-title">Try a change</h3>';
560
561
  if (state.selectedEdge) {
561
562
  const e = state.selectedEdge;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cornfield",
3
- "version": "0.24.0",
3
+ "version": "0.26.0",
4
4
  "description": "A self-hostable dev dashboard with the topology map at its centre: proposals on the map, scenarios, outages and what-if edits, for any repo.",
5
5
  "license": "MIT",
6
6
  "author": "popcorn245 (https://github.com/popcorn245)",
package/server/server.js CHANGED
@@ -78,7 +78,7 @@ import { createTriggers } from './triggers.js';
78
78
  export const CORNFIELD_DIR = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
79
79
  const EXPLORER_DIR = path.join(CORNFIELD_DIR, 'explorer');
80
80
  /** The pure core modules the explorer imports (no Node built-ins, no files): the only ones of core/ served */
81
- export const BROWSER_CORE = ['schema.js', 'proposal.js', 'personas.js', 'cloud.js', 'text.js', 'mentions.js'];
81
+ export const BROWSER_CORE = ['schema.js', 'proposal.js', 'personas.js', 'cloud.js', 'text.js', 'mentions.js', 'color.js'];
82
82
  /** cornfield's own browser sources, by request path */
83
83
  const BROWSER_PLUGINS = new Map(Object.values(BUILTIN_SOURCES).map((p) => [p, path.join(CORNFIELD_DIR, p)]));
84
84
  const PKG = JSON.parse(fs.readFileSync(path.join(CORNFIELD_DIR, 'package.json'), 'utf8'));
@@ -129,9 +129,9 @@ function themeHead(theme) {
129
129
  const u = fontUrl(f);
130
130
  if (u) out.push(`<link rel="stylesheet" href="${escapeHtml(u.href)}" referrerpolicy="no-referrer" />`);
131
131
  }
132
- if (theme.css) out.push('<link rel="stylesheet" href="/cornfield/theme.css" data-cf-theme="css" />');
132
+ if (theme.css) out.push('<link rel="stylesheet" href="/cornfield/theme.css" data-corn-theme="css" />');
133
133
  const { names, fallback } = themeNamesOf(theme);
134
- if (names.length) out.push(`<link rel="stylesheet" id="cf-theme-name-css"${fallback ? ` href="/cornfield/theme/${fallback}.css"` : ''} data-cf-theme="name" />`);
134
+ if (names.length) out.push(`<link rel="stylesheet" id="cf-theme-name-css"${fallback ? ` href="/cornfield/theme/${fallback}.css"` : ''} data-corn-theme="name" />`);
135
135
  return out.join('\n ');
136
136
  }
137
137