@popcorn245/cornfield 0.42.0 → 0.44.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/core/color.js +38 -8
- package/core/contrast.js +70 -5
- package/core/delta-e.js +66 -0
- package/core/layers.js +8 -0
- package/core/map-tokens.js +83 -0
- package/core/schema.js +29 -7
- package/core/strings.js +2 -0
- package/core/validate.js +4 -2
- package/explorer/capped.js +6 -5
- package/explorer/cloud-model.js +10 -7
- package/explorer/css-color.js +99 -0
- package/explorer/diff-marks.js +3 -1
- package/explorer/edge-key.js +59 -0
- package/explorer/explorer.css +116 -64
- package/explorer/flows.js +0 -2
- package/explorer/forge-panel.js +2 -3
- package/explorer/glyphs.js +130 -0
- package/explorer/house-model.js +2 -2
- package/explorer/index.html +3 -17
- package/explorer/keyboard-model.js +4 -1
- package/explorer/keyboard.js +14 -2
- package/explorer/kind-letters.js +9 -5
- package/explorer/labels.js +33 -34
- package/explorer/layers.js +93 -34
- package/explorer/main.js +3 -2
- package/explorer/map-style.js +13 -71
- package/explorer/panels.js +92 -7
- package/explorer/render.js +2 -2
- package/explorer/renderer-canvas2d.js +169 -26
- package/explorer/renderer-webgl.js +51 -17
- package/explorer/scene.js +67 -48
- package/explorer/selection-model.js +150 -0
- package/explorer/selection-view.js +36 -0
- package/explorer/shaders.js +76 -13
- package/explorer/spatial.js +7 -4
- package/explorer/state.js +4 -0
- package/explorer/tokens.css +13 -0
- package/package.json +1 -1
package/explorer/layers.js
CHANGED
|
@@ -10,25 +10,29 @@ import { state, touchScene, escHtml } from './state.js';
|
|
|
10
10
|
import { render, ensureFlowLoop, isNodeVisible } from './render.js';
|
|
11
11
|
import { renderFlowLegend } from './flows.js';
|
|
12
12
|
import { WHEN_STYLES } from './cloud-model.js';
|
|
13
|
+
import { edgeKeyHtml, keySwatch } from './edge-key.js';
|
|
13
14
|
import { themed } from './theme-model.js';
|
|
14
15
|
import { onThemeChange } from './theme.js';
|
|
16
|
+
import { NODE_THEMES } from '../core/schema.js';
|
|
15
17
|
import { STARTING_LAYERS, clientLayers, kindLetters, orderRows, startingLayerOf } from '../core/layers.js';
|
|
16
18
|
import { rowKeyOf, shownByProposal } from './layer-model.js';
|
|
17
|
-
import { layerShows } from './scene.js';
|
|
18
|
-
import { getMapStyle,
|
|
19
|
+
import { fillOfNode, groupOf, layerShows } from './scene.js';
|
|
20
|
+
import { STROKE_TOKEN, cssColor, fillOf, getMapStyle, kindToken, onMapStyleChange, pageReader, setMapSubjects } from './map-style.js';
|
|
21
|
+
import { over, parseColor, contrast } from '../core/color.js';
|
|
22
|
+
import { DARK_GROUND, LIGHT_GROUND } from './theme-model.js';
|
|
19
23
|
import { t } from './strings.js';
|
|
20
24
|
|
|
21
|
-
/** The
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
};
|
|
25
|
+
/** The types a starting row's nodes have (House: floors and rooms; Cloud and the Public web: `external`), or none for a row that is not a node type */
|
|
26
|
+
const typesOf = (l) => (l.match && l.match.type ? [].concat(l.match.type) : []);
|
|
27
|
+
/** The dot of the two rows that are not a node type: Data Flow's lines and the ring of a run in flight. Every other row's built-in dot is its
|
|
28
|
+
* first type's colour in core/schema.js NODE_THEMES, the colour the map draws its nodes in when the theme sets none (one table, not two) */
|
|
29
|
+
const NOT_A_TYPE = { flow: '#fb923c', runs: '#5eead4' };
|
|
30
|
+
const builtIn = (l) => { const type = typesOf(l)[0]; return type && NODE_THEMES[type] ? NODE_THEMES[type].color : NOT_A_TYPE[l.key]; };
|
|
27
31
|
/** The starting layers that start off: the infra layer is its own view, and the physical world's are loaded when first turned on (spec 0029) */
|
|
28
32
|
const STARTS_OFF = new Set(['stack', 'machine', 'container', 'device', 'house', 'persona']);
|
|
29
33
|
|
|
30
34
|
/** The starting rows (core/layers.js STARTING_LAYERS) with the colour of their dot */
|
|
31
|
-
export const LAYER_DEFS = STARTING_LAYERS.map((l) => ({ ...l, color:
|
|
35
|
+
export const LAYER_DEFS = STARTING_LAYERS.map((l) => ({ ...l, color: builtIn(l) }));
|
|
32
36
|
|
|
33
37
|
const layerListeners = new Set();
|
|
34
38
|
/** Calls `fn` after a layer goes on or off (live.js starts or stops the live layer). Returns how to stop. */
|
|
@@ -77,22 +81,53 @@ export function clickWithLegendMenu(target, act) {
|
|
|
77
81
|
const defaultOf = (key) => (Object.hasOwn(state.layerDefaults, key) ? state.layerDefaults[key] : !STARTS_OFF.has(key));
|
|
78
82
|
const isOn = (key) => state.activeLayers[key] !== false;
|
|
79
83
|
|
|
80
|
-
/**
|
|
81
|
-
* A project layer's dot: the theme's `--corn-map-group-<key>`, else the colour of the first node the layer holds (a project layer has no
|
|
82
|
-
* colour of its own in the config: it is the theme's to give, so the contrast check sees it).
|
|
83
|
-
*/
|
|
84
|
-
function projectColor(layer) {
|
|
85
|
-
const set = getMapStyle().values[groupToken(layer.key)];
|
|
86
|
-
if (set) return set;
|
|
87
|
-
const first = state.nodes.find((n) => rowKeyOf(state, n) === layer.key);
|
|
88
|
-
return first ? first.color : NO_COLOR;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
84
|
const NO_COLOR = '#94a3b8';
|
|
92
85
|
/** A colour as the dot's style may hold it: a hex or an rgb()/rgba() of numbers, else the plain grey. A node's colour is the map's data
|
|
93
86
|
* (a proposal can set it), so it is checked before it reaches a style attribute, and escaped there all the same */
|
|
94
|
-
const
|
|
95
|
-
const
|
|
87
|
+
const NUM = '\\d{1,3}(?:\\.\\d+)?%?';
|
|
88
|
+
const SWATCH_RE = new RegExp(`^(?:#(?:[0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})|rgba?\\(\\s*${NUM}(?:\\s*,\\s*|\\s+)${NUM}(?:\\s*,\\s*|\\s+)${NUM}(?:\\s*[,/]\\s*(?:\\d*\\.)?\\d+%?)?\\s*\\))$`, 'i');
|
|
89
|
+
const swatch = (c) => (typeof c === 'string' && c.length <= 64 && SWATCH_RE.test(c.trim()) ? c.trim() : NO_COLOR);
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* The colour of a row's dot: the fill the map draws for the row's nodes, by the map's own order (map-style.js `fillOf`: the type's or layer's
|
|
93
|
+
* token, then the starting group's), else the row's built-in colour on this ground (`themed`). `node` is what the row's nodes are: for a
|
|
94
|
+
* starting row its type (`typeOfRow`: a row of two types, House, speaks for its first, floors, so `--corn-map-group-house` is its dot unless
|
|
95
|
+
* the theme gives floors a colour of their own) and its key as the group; for a project row its first node's type with the layer. A finer kind's token is left out: a dot is a row's, not a kind's.
|
|
96
|
+
* A token's value is the theme's text and a node's colour is the project's: both go through `swatch` before they reach a style.
|
|
97
|
+
*/
|
|
98
|
+
function rowColor(node, built) {
|
|
99
|
+
const fill = fillOf(getMapStyle().values, node);
|
|
100
|
+
// The built-in is a node's colour (project data): normalised as the map's renderers read it (`cssColor`, the reader of the tokens), so a
|
|
101
|
+
// name or an `hsl()` the map draws is the dot too; anything that is not a colour is the grey
|
|
102
|
+
return fill ? swatch(fill) : swatch(cssColor(themed(built, state.theme)));
|
|
103
|
+
}
|
|
104
|
+
/** The type a row's dot speaks for: of a row of several types (House), the first one the map holds, else the first; a row with no type, its key */
|
|
105
|
+
const typeOfRow = (l) => { const types = typesOf(l); return (types.length > 1 && types.find((ty) => state.nodes.some((n) => n.type === ty))) || types[0] || l.key; };
|
|
106
|
+
|
|
107
|
+
/** The ground of the menu: its surface laid over the page, as `--corn-surface-1` and `--corn-ground` say, else the theme's own ground */
|
|
108
|
+
function menuSurface() {
|
|
109
|
+
const fallback = state.theme === 'light' ? LIGHT_GROUND : DARK_GROUND;
|
|
110
|
+
const read = pageReader();
|
|
111
|
+
if (!read) return fallback;
|
|
112
|
+
const ground = parseColor(read('--corn-ground'));
|
|
113
|
+
const surface = parseColor(read('--corn-surface-1'));
|
|
114
|
+
if (!ground[3] || !surface[3]) return fallback;
|
|
115
|
+
const [r, g, b] = over(surface, over(ground, [0, 0, 0, 1]));
|
|
116
|
+
return `rgb(${r}, ${g}, ${b})`;
|
|
117
|
+
}
|
|
118
|
+
/** The outline a dot or swatch gets when its fill is under 3:1 on the menu: the map's own outline colour when the theme sets one, else the CSS default (`.is-ringed`). The fill is never changed */
|
|
119
|
+
function ringOf(color, surface) {
|
|
120
|
+
if (contrast(color, surface) >= 3) return null;
|
|
121
|
+
const stroke = getMapStyle().values[STROKE_TOKEN];
|
|
122
|
+
return { stroke: stroke ? swatch(stroke) : '' };
|
|
123
|
+
}
|
|
124
|
+
/** A swatch of `color` on this menu: the fill, a soft glow on a dark ground, and the outline when it is needed. `extra` is more attributes (a kind's is `aria-hidden`) */
|
|
125
|
+
function dot(color, on, surface, extra = '') {
|
|
126
|
+
const ring = ringOf(color, surface);
|
|
127
|
+
const glow = on && state.theme !== 'light' ? (/^#[0-9a-f]{6}$/i.test(color) ? `0 0 8px ${color}90` : `0 0 8px color-mix(in srgb, ${color} 56%, transparent)`) : 'none';
|
|
128
|
+
const style = `background-color: ${color}; box-shadow: ${glow}${ring && ring.stroke ? `; --hx-dot-ring: ${ring.stroke}` : ''}`;
|
|
129
|
+
return `<span class="hx-dot${extra ? ' hx-kind-swatch' : ''}${ring ? ' is-ringed' : ''}" data-corn="swatch"${extra} style="${escHtml(style)}"></span>`;
|
|
130
|
+
}
|
|
96
131
|
|
|
97
132
|
/**
|
|
98
133
|
* The rows: the project layers that hold a node, then the starting ones in their usual order (`layers.order` first of all), and one more
|
|
@@ -100,6 +135,7 @@ const swatch = (c) => (typeof c === 'string' && SWATCH_RE.test(c.trim()) ? c.tri
|
|
|
100
135
|
* `root` is always shown and has no row. The overlays are the rows with `overlay`: the menu draws them under their own heading.
|
|
101
136
|
*/
|
|
102
137
|
function layerRows() {
|
|
138
|
+
const dotted = (l) => { const type = typeOfRow(l); return { ...l, color: rowColor({ type, group: l.key }, NODE_THEMES[type] ? NODE_THEMES[type].color : l.color) }; };
|
|
103
139
|
const held = new Set();
|
|
104
140
|
const left = new Set(); // starting layers a project layer took nodes from
|
|
105
141
|
state.nodes.forEach((n) => {
|
|
@@ -109,17 +145,21 @@ function layerRows() {
|
|
|
109
145
|
const own = startingLayerOf(n);
|
|
110
146
|
if (own !== key) left.add(own);
|
|
111
147
|
});
|
|
112
|
-
const
|
|
148
|
+
const projectDot = (l) => {
|
|
149
|
+
const first = state.nodes.find((n) => rowKeyOf(state, n) === l.key);
|
|
150
|
+
return { color: rowColor(first ? { type: first.type, layer: l.key, group: groupOf(first) } : { type: l.key, layer: l.key }, first ? fillOfNode(first) : NO_COLOR) };
|
|
151
|
+
};
|
|
152
|
+
const project = state.projectLayers.filter((l) => held.has(l.key)).map((l) => ({ key: l.key, label: l.label, desc: l.desc || '', project: true, ...projectDot(l) }));
|
|
113
153
|
// A starting row a project layer has taken every node from goes (spec 0009 D7, example 3); with no project layer, every starting row stays, as it always was
|
|
114
|
-
const starting = LAYER_DEFS.filter((l) => !l.overlay && (held.has(l.key) || !left.has(l.key)));
|
|
154
|
+
const starting = LAYER_DEFS.filter((l) => !l.overlay && (held.has(l.key) || !left.has(l.key))).map(dotted);
|
|
115
155
|
const known = new Set([...LAYER_DEFS.map((l) => l.key), ...state.projectLayers.map((l) => l.key)]);
|
|
116
156
|
const extra = [];
|
|
117
157
|
held.forEach((key) => {
|
|
118
158
|
if (known.has(key)) return;
|
|
119
159
|
known.add(key);
|
|
120
|
-
extra.push({ key, label: key.charAt(0).toUpperCase() + key.slice(1), color:
|
|
160
|
+
extra.push({ key, label: key.charAt(0).toUpperCase() + key.slice(1), color: rowColor({ type: key, group: key }, NO_COLOR), desc: `Nodes of the type ${key}` });
|
|
121
161
|
});
|
|
122
|
-
return { layers: [...orderRows(project, starting, state.layerOrder), ...extra], overlays: LAYER_DEFS.filter((l) => l.overlay) };
|
|
162
|
+
return { layers: [...orderRows(project, starting, state.layerOrder), ...extra], overlays: LAYER_DEFS.filter((l) => l.overlay).map(dotted) };
|
|
123
163
|
}
|
|
124
164
|
|
|
125
165
|
/** The chip says how many layers are on: " · 13 of 20". An overlay (Runs in flight) is not a layer: it is not counted */
|
|
@@ -194,20 +234,28 @@ function kindsByRow(rowOf) {
|
|
|
194
234
|
if (!key) return;
|
|
195
235
|
if (!rows.has(key)) rows.set(key, new Map());
|
|
196
236
|
const id = `${n.type}\u0000${n.kind}`;
|
|
197
|
-
const entry = rows.get(key).get(id) || { kind: n.kind, letters: letters.get(n.type).get(n.kind), n: 0 };
|
|
237
|
+
const entry = rows.get(key).get(id) || { type: n.type, kind: n.kind, letters: letters.get(n.type).get(n.kind), n: 0 };
|
|
198
238
|
entry.n++;
|
|
199
239
|
rows.get(key).set(id, entry);
|
|
200
240
|
});
|
|
201
241
|
return new Map([...rows].map(([k, m]) => [k, [...m.values()].sort((a, b) => a.kind.localeCompare(b.kind))]));
|
|
202
242
|
}
|
|
203
243
|
|
|
244
|
+
/** The swatch of a kind: the theme's `--corn-map-kind-<type>-<kind>`, as the map draws that kind, or nothing when the token is unset (the node then has its type's colour, which is the row's dot). Decoration: the letters and the name say which kind it is */
|
|
245
|
+
function kindSwatch(k, surface, pad) {
|
|
246
|
+
const fill = getMapStyle().values[kindToken(k.type, k.kind)];
|
|
247
|
+
if (!fill) return pad ? '<span class="hx-dot hx-kind-swatch is-blank" aria-hidden="true"></span>' : ''; // nothing to see, but the letters of the rows stay in line
|
|
248
|
+
return dot(swatch(fill), true, surface, ' aria-hidden="true"');
|
|
249
|
+
}
|
|
250
|
+
|
|
204
251
|
/** What a viewer sees as "kinds" for a row: the disclosure button and, when open, the key rows. A key is a key, not a toggle (spec 0009 D5) */
|
|
205
|
-
function kindsHtml(layer, kinds) {
|
|
252
|
+
function kindsHtml(layer, kinds, surface) {
|
|
206
253
|
if (!kinds || !kinds.length) return '';
|
|
207
254
|
const open = openKinds.has(layer.key);
|
|
208
255
|
const id = `layer-kinds-${layer.key}`;
|
|
209
256
|
const words = `${kinds.length} ${kinds.length === 1 ? 'kind' : 'kinds'}`;
|
|
210
|
-
const
|
|
257
|
+
const padded = kinds.some((k) => getMapStyle().values[kindToken(k.type, k.kind)]);
|
|
258
|
+
const list = open ? `<ul class="hx-kind-keys" id="${escHtml(id)}">${kinds.map((k) => `<li class="hx-kind-key" data-corn="kind-key">${kindSwatch(k, surface, padded)}<span class="hx-kind-letter" aria-hidden="true">${escHtml(k.letters)}</span><span class="hx-kind-name">${escHtml(k.kind)}</span><span class="hx-count" data-corn="count">${k.n}</span></li>`).join('')}</ul>` : '';
|
|
211
259
|
return `<div class="hx-kinds"><button type="button" class="hx-textbtn hx-kinds-btn" data-action="toggle-layer-kinds" data-layer="${escHtml(layer.key)}" aria-expanded="${open}" aria-controls="${escHtml(id)}" data-corn="layer-kinds" data-corn-kind="quiet">${open ? '▾' : '▸'} ${escHtml(words)}</button>${list}</div>`;
|
|
212
260
|
}
|
|
213
261
|
|
|
@@ -223,8 +271,10 @@ function syncMapSubjects() {
|
|
|
223
271
|
setMapSubjects({ kinds, layers: state.projectLayers.map((l) => l.key) });
|
|
224
272
|
}
|
|
225
273
|
|
|
274
|
+
let drawing = false;
|
|
226
275
|
export function renderLayerToggles() {
|
|
227
|
-
|
|
276
|
+
drawing = true;
|
|
277
|
+
try { syncMapSubjects(); } finally { drawing = false; } // reading the tokens of a new kind may tell the style listener below: this draw already has them
|
|
228
278
|
paintCount();
|
|
229
279
|
const container = document.getElementById('layer-toggles-container');
|
|
230
280
|
if (!container) return;
|
|
@@ -244,22 +294,22 @@ export function renderLayerToggles() {
|
|
|
244
294
|
counts.runs = state.runsMap ? state.runsMap.flight.size : 0;
|
|
245
295
|
const kinds = kindsByRow(rowOf);
|
|
246
296
|
const { layers, overlays } = layerRows();
|
|
297
|
+
const surface = menuSurface();
|
|
247
298
|
|
|
248
299
|
const row = (layer) => {
|
|
249
300
|
const on = isOn(layer.key);
|
|
250
|
-
const color = escHtml(swatch(themed(swatch(layer.color), state.theme))); // the dot is the colour the map draws on this ground
|
|
251
301
|
const shown = byProposal[layer.key] ? `<span class="hx-faint hx-layer-note" data-corn="layer-note">+${byProposal[layer.key]} shown by the proposal</span>` : '';
|
|
252
302
|
return `
|
|
253
303
|
<button type="button" class="hx-toggle-row${on ? '' : ' is-off'}" data-action="toggle-layer" data-layer="${escHtml(layer.key)}" aria-pressed="${on}" title="${escHtml(layer.desc)}" data-corn="row">
|
|
254
304
|
<span class="hx-toggle-label">
|
|
255
|
-
|
|
305
|
+
${dot(swatch(layer.color), on, surface)}
|
|
256
306
|
<span class="hx-toggle-name">${escHtml(layer.label)}</span>${layer.live ? '<span class="hx-live-tag" data-corn="live-tag">live</span>' : ''}
|
|
257
307
|
</span>
|
|
258
308
|
<span class="hx-toggle-meta">${shown}
|
|
259
309
|
<span class="hx-count" data-corn="count">${(UNIT[layer.key] || String)(counts[layer.key] || 0)}</span>
|
|
260
310
|
<span class="hx-tick">${on ? '✓' : '—'}</span>
|
|
261
311
|
</span>
|
|
262
|
-
</button>${kindsHtml(layer, kinds.get(layer.key))}`;
|
|
312
|
+
</button>${kindsHtml(layer, kinds.get(layer.key), surface)}`;
|
|
263
313
|
};
|
|
264
314
|
|
|
265
315
|
// The focus stays where it was across the redraw: the same row or disclosure, found again by what it names
|
|
@@ -272,9 +322,16 @@ export function renderLayerToggles() {
|
|
|
272
322
|
if (again && typeof again.focus === 'function') again.focus({ preventScroll: true });
|
|
273
323
|
}
|
|
274
324
|
renderFlowLegend();
|
|
325
|
+
renderEdgeKey();
|
|
275
326
|
renderCloudLegend();
|
|
276
327
|
}
|
|
277
328
|
|
|
329
|
+
/** The Key (spec 0008 D7): each kind of line as the map draws it (edge-key.js) */
|
|
330
|
+
export function renderEdgeKey() {
|
|
331
|
+
const el = document.getElementById('edge-key');
|
|
332
|
+
if (el) el.innerHTML = edgeKeyHtml();
|
|
333
|
+
}
|
|
334
|
+
|
|
278
335
|
/** What a call into a cloud node looks like for its `when` (spec 0031 section 6), while the Cloud layer is on */
|
|
279
336
|
export function renderCloudLegend() {
|
|
280
337
|
const el = document.getElementById('cloud-legend');
|
|
@@ -283,7 +340,7 @@ export function renderCloudLegend() {
|
|
|
283
340
|
el.hidden = false;
|
|
284
341
|
el.innerHTML = `
|
|
285
342
|
<div class="hx-menu-title" data-corn="menu-title"><span>Cloud: when an outage bites</span></div>
|
|
286
|
-
${Object.entries(WHEN_STYLES).map(([when, s]) => `<div class="hx-legend-row"><span class="hx-legend-swatch
|
|
343
|
+
${Object.entries(WHEN_STYLES).map(([when, s]) => `<div class="hx-legend-row"><span class="hx-legend-swatch hx-legend-swatch--wide hx-swatch-when--${when}">${keySwatch({ end: 'triangle', ticks: s.ticks })}</span><span>${s.legend}</span></div>`).join('')}
|
|
287
344
|
<div class="hx-legend-row"><span class="hx-legend-swatch"></span><span class="hx-faint"><span class="hx-cloud-browser">(browser)</span> the visitor's browser makes the call, not our server</span></div>`;
|
|
288
345
|
}
|
|
289
346
|
|
|
@@ -341,3 +398,5 @@ export function toggleLayerKinds(key) {
|
|
|
341
398
|
|
|
342
399
|
// The dots and the legends are drawn in the theme's colours: drawn again when it changes (theme.js)
|
|
343
400
|
onThemeChange(() => renderLayerToggles());
|
|
401
|
+
// ... and when the map's own tokens change (a named theme, its stylesheet arriving, light and dark): the same signal the map is drawn again on
|
|
402
|
+
onMapStyleChange(() => { if (!drawing) renderLayerToggles(); });
|
package/explorer/main.js
CHANGED
|
@@ -46,7 +46,7 @@ import { initLive } from './live.js';
|
|
|
46
46
|
import { initHouse } from './house.js';
|
|
47
47
|
import { houseOffered } from './house-model.js';
|
|
48
48
|
import { initChecks } from './check.js';
|
|
49
|
-
import { initKeyboard } from './keyboard.js';
|
|
49
|
+
import { frameThem, initKeyboard } from './keyboard.js';
|
|
50
50
|
import { initForgePanel } from './forge-panel.js';
|
|
51
51
|
import { initReviewTokens } from './review-tokens.js';
|
|
52
52
|
import { loadClientConfig, loadSources, applyBranding } from './plugins.js';
|
|
@@ -128,7 +128,8 @@ const ACTIONS = {
|
|
|
128
128
|
'close-drawer': () => closeDrawer(),
|
|
129
129
|
'copy-spec': (el) => copySpec(el),
|
|
130
130
|
'start-run': () => startRun(),
|
|
131
|
-
'select-node': (el) => selectNode(nodeById(el.dataset.id)),
|
|
131
|
+
'select-node': (el) => selectNode(nodeById(el.dataset.id), { frame: true }), // a link or a list row: the camera follows (spec 0008 D6)
|
|
132
|
+
'frame-selection': () => frameThem(),
|
|
132
133
|
'play-outage': (el) => playOutage(el.dataset.id), // the cloud panel's Play button (spec 0031 section 8)
|
|
133
134
|
'retry': () => loadTopology(),
|
|
134
135
|
'set-theme': (el) => setThemeChoice(el.dataset.choice),
|
package/explorer/map-style.js
CHANGED
|
@@ -35,8 +35,10 @@
|
|
|
35
35
|
|
|
36
36
|
import { NODE_THEMES } from '../core/schema.js';
|
|
37
37
|
import { parseColor } from './theme-model.js';
|
|
38
|
+
import { cssColor, rgbaText } from './css-color.js';
|
|
39
|
+
export { cssColor };
|
|
38
40
|
import { LABEL_MIN_FLOOR, looksFor } from './scene.js';
|
|
39
|
-
import { iconKeyShape, iconKeysFor, mapGroupToken, mapKindToken } from '../core/layers.js';
|
|
41
|
+
import { iconKeyShape, iconKeysFor, mapFillNames, mapGroupToken, mapKindToken } from '../core/layers.js';
|
|
40
42
|
|
|
41
43
|
/** The node kinds (topology types) and the groups (layers a node can belong to) the tokens exist for */
|
|
42
44
|
export const MAP_KINDS = Object.freeze(Object.keys(NODE_THEMES));
|
|
@@ -55,6 +57,8 @@ export const FONT_TOKEN = '--corn-map-font';
|
|
|
55
57
|
export const EDGE_WIDTH_TOKEN = '--corn-map-edge-width';
|
|
56
58
|
export const GLOW_TOKEN = '--corn-map-glow';
|
|
57
59
|
export const LABEL_MIN_TOKEN = '--corn-map-label-min';
|
|
60
|
+
/** The ink of a node's glyph and of a finer kind's letters (spec 0008 D8); `auto` is the white or the dark that reads on the node's fill (glyphs.js) */
|
|
61
|
+
export const GLYPH_TOKEN = '--corn-map-glyph';
|
|
58
62
|
/** The largest label minimum a theme may ask for: bigger text would leave no room for another label */
|
|
59
63
|
export const MAX_LABEL_MIN = 24;
|
|
60
64
|
/** The width an ordinary line has with no theme (scene.js `flowEdge`): the `--corn-map-edge-width` scales every line by its ratio to this */
|
|
@@ -86,6 +90,7 @@ export const MAP_COLOR_TOKENS = Object.freeze([
|
|
|
86
90
|
STROKE_TOKEN,
|
|
87
91
|
LABEL_TOKEN,
|
|
88
92
|
LABEL_HALO_TOKEN,
|
|
93
|
+
GLYPH_TOKEN,
|
|
89
94
|
...MAP_EDGE_KINDS.map(edgeToken),
|
|
90
95
|
...MAP_MARKS.map(stateToken),
|
|
91
96
|
...MAP_STATES.map(stateToken),
|
|
@@ -97,75 +102,6 @@ export const mapTokenNames = () => [...MAP_COLOR_TOKENS, STROKE_WIDTH_TOKEN, COL
|
|
|
97
102
|
// Reading a token
|
|
98
103
|
// ---------------------------------------------------------------------------
|
|
99
104
|
|
|
100
|
-
let probe;
|
|
101
|
-
const normalised = new Map();
|
|
102
|
-
|
|
103
|
-
/** A canvas context to normalise a colour the way the browser reads it (`hsl()`, a name, `color-mix()`), or null where there is none */
|
|
104
|
-
function probeContext() {
|
|
105
|
-
if (probe !== undefined) return probe;
|
|
106
|
-
probe = null;
|
|
107
|
-
try { if (typeof document !== 'undefined') probe = document.createElement('canvas').getContext('2d', { willReadFrequently: true }) || null; } catch { probe = null; }
|
|
108
|
-
return probe;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* A token's value as a colour the renderers can use (`#rrggbb`, `rgb()`, `rgba()`), or null for `auto`, empty, or anything that is not a colour.
|
|
113
|
-
* @param {string} value
|
|
114
|
-
* @returns {string | null}
|
|
115
|
-
*/
|
|
116
|
-
export function cssColor(value) {
|
|
117
|
-
const s = typeof value === 'string' ? value.trim() : '';
|
|
118
|
-
if (!s || s.toLowerCase() === 'auto') return null;
|
|
119
|
-
if (inRange(s)) return s;
|
|
120
|
-
if (/^transparent$/i.test(s)) return 'rgba(0, 0, 0, 0)';
|
|
121
|
-
if (normalised.has(s)) return normalised.get(s);
|
|
122
|
-
let out = null;
|
|
123
|
-
const ctx = isColor(s) && !/currentcolor/i.test(s) ? probeContext() : null; // a canvas has no current colour: it would read as black
|
|
124
|
-
if (ctx) {
|
|
125
|
-
try {
|
|
126
|
-
// The browser's own reading: a value it refuses leaves fillStyle as it was, so two different starting colours tell a refusal
|
|
127
|
-
// from a colour that happens to equal the first one
|
|
128
|
-
const read = (from) => { ctx.fillStyle = from; ctx.fillStyle = s; return String(ctx.fillStyle); };
|
|
129
|
-
const a = read('#010203');
|
|
130
|
-
const got = a !== '#010203' ? a : read('#040506') !== '#040506' ? a : null;
|
|
131
|
-
// A colour the browser keeps in another space (`oklch()`, `color(display-p3 ...)`) is read back as the sRGB pixel it paints
|
|
132
|
-
out = got === null ? null : parseable(got) ? got : pixelOf(ctx, s);
|
|
133
|
-
} catch { out = null; }
|
|
134
|
-
}
|
|
135
|
-
normalised.set(s, out);
|
|
136
|
-
return out;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/** Whether CSS itself reads `s` as a colour (a canvas is more lenient: it takes `rgb(1.2.3, 0, 0)`); true where the page cannot say */
|
|
140
|
-
function isColor(s) {
|
|
141
|
-
try { return typeof CSS === 'undefined' || typeof CSS.supports !== 'function' || CSS.supports('color', s); } catch { return false; }
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/** `#rgb`, `#rrggbb`, `rgb()` or `rgba()` with every channel in range: what both renderers read as written */
|
|
145
|
-
function inRange(s) {
|
|
146
|
-
if (!parseable(s)) return false;
|
|
147
|
-
// The numbers as written: parseColor clamps them, and an out-of-range channel must go to the browser to be read
|
|
148
|
-
const nums = /^rgba?\(/i.test(s.trim()) ? s.slice(s.indexOf('(') + 1, s.lastIndexOf(')')).split(',').map(Number) : null;
|
|
149
|
-
if (nums && (nums.slice(0, 3).some((c) => !(c >= 0 && c <= 255)) || (nums.length > 3 && !(nums[3] > 0 && nums[3] <= 1)))) return false;
|
|
150
|
-
const [r, g, b, a] = parseColor(s);
|
|
151
|
-
return [r, g, b].every((c) => Number.isFinite(c) && c >= 0 && c <= 255) && Number.isFinite(a) && a > 0 && a <= 1;
|
|
152
|
-
}
|
|
153
|
-
/** The forms parseColor (theme-model.js) reads; anything else is normalised by the browser first */
|
|
154
|
-
const COLOR_RE = /^#(?:[0-9a-f]{3}|[0-9a-f]{6})$|^rgba?\(\s*[\d.]+\s*,\s*[\d.]+\s*,\s*[\d.]+\s*(?:,\s*[\d.]+\s*)?\)$/i;
|
|
155
|
-
const parseable = (s) => COLOR_RE.test(s.trim());
|
|
156
|
-
|
|
157
|
-
/** The sRGB pixel `css` paints, as `rgba()` (or null when the context cannot be read) */
|
|
158
|
-
function pixelOf(ctx, css) {
|
|
159
|
-
if (!ctx.getImageData || !ctx.fillRect) return null;
|
|
160
|
-
ctx.clearRect(0, 0, 1, 1);
|
|
161
|
-
ctx.fillStyle = css;
|
|
162
|
-
ctx.fillRect(0, 0, 1, 1);
|
|
163
|
-
const [r, g, b, a] = ctx.getImageData(0, 0, 1, 1).data;
|
|
164
|
-
return rgbaText(r, g, b, a / 255);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
const rgbaText = (r, g, b, a) => `rgba(${r}, ${g}, ${b}, ${+a.toFixed(3)})`;
|
|
168
|
-
|
|
169
105
|
/** `token` as the colour of something that was `original`: the token's colour, with the original's own alpha kept (a faint line stays faint) */
|
|
170
106
|
export function withAlphaOf(token, original) {
|
|
171
107
|
const [r, g, b, a] = parseColor(token);
|
|
@@ -453,6 +389,12 @@ export function watchMapStyle(doc) {
|
|
|
453
389
|
|
|
454
390
|
const firstOf = (values, names) => { for (const n of names) if (values[n]) return values[n]; return null; };
|
|
455
391
|
|
|
392
|
+
/** The tokens that can fill a node, most specific first (core/layers.js `mapFillNames`, the one place the order is written) */
|
|
393
|
+
export const fillNames = mapFillNames;
|
|
394
|
+
|
|
395
|
+
/** The theme's fill for a node of that kind, layer, type and group (`values` of a style), or null: the node then draws its own colour (`auto`) */
|
|
396
|
+
export const fillOf = (values, node) => firstOf(values, fillNames(node));
|
|
397
|
+
|
|
456
398
|
/** A line's shape in the theme: its width scaled to `--corn-map-edge-width`, its glow and its packet's by `--corn-map-glow` (nothing at `auto`) */
|
|
457
399
|
function shapeEdge(e, style) {
|
|
458
400
|
const scale = style.edgeWidth == null ? 1 : style.edgeWidth / BASE_EDGE_WIDTH;
|
|
@@ -486,7 +428,7 @@ function compute(scene, style) {
|
|
|
486
428
|
const painted = scene.painted || { nodes: new Set(), edges: new Set() };
|
|
487
429
|
const nodes = scene.nodes.map((n) => {
|
|
488
430
|
// Which fill wins, most specific first (spec 0009 D6): the finer kind, the project layer, the type, the starting layer
|
|
489
|
-
const fill = !painted.nodes.has(n.id) &&
|
|
431
|
+
const fill = !painted.nodes.has(n.id) && fillOf(values, n);
|
|
490
432
|
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
|
|
491
433
|
const glows = style.glow != null && style.glow !== 1 && n.glow > 0;
|
|
492
434
|
if (!fill && !label && !stroke && !icon && !glows) return n;
|
package/explorer/panels.js
CHANGED
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
* cloud node (spec 0031) its plan, what breaks if it is down and who uses it, by when (cloud-model.js).
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { state, nodeById, nameOf, escHtml, touchScene } from './state.js';
|
|
10
|
-
import { render } from './render.js';
|
|
9
|
+
import { state, nodeById, nameOf, escHtml, touchScene, viewEdges } from './state.js';
|
|
10
|
+
import { render, onPaint } from './render.js';
|
|
11
11
|
import { flowSummary } from './flows.js';
|
|
12
12
|
import { clearScenario } from './scenario-ui.js';
|
|
13
13
|
import { kindOfMark, fieldRows, MARK_WORDS } from './proposal-model.js';
|
|
@@ -23,6 +23,9 @@ import { capped, toggleCapped } from './capped.js';
|
|
|
23
23
|
import { dismissHint } from './hint.js';
|
|
24
24
|
import { canStartAgent, openProposalStart } from './forge-panel.js';
|
|
25
25
|
import { sayResult, clearResult, showResultIn, RESULT_MS } from './feedback.js';
|
|
26
|
+
import { activeSubgraph, connectedLine, farEnds, kindPanelWord, linesByKind } from './selection-model.js';
|
|
27
|
+
import { frameSelection, reach } from './selection-view.js';
|
|
28
|
+
import { announce } from './keyboard.js';
|
|
26
29
|
|
|
27
30
|
const $ = (id) => document.getElementById(id);
|
|
28
31
|
|
|
@@ -220,24 +223,105 @@ function diffSection(node) {
|
|
|
220
223
|
return `<div class="hx-sec-block" data-proposal-mark="${escHtml(node.mark)}" data-corn="section"><h3 class="hx-sec-title">In this proposal</h3>${node.why ? `<p class="hx-why">${escHtml(node.why)}</p>` : ''}<div class="hx-diff hx-diff--${escHtml(kind)}" data-corn="diff-block"${markStateAttr(node.mark)}>${rows.join('')}</div></div>`;
|
|
221
224
|
}
|
|
222
225
|
|
|
226
|
+
// ---------------------------------------------------------------------------
|
|
227
|
+
// What the selection lights: the lines by kind, the switch, Frame them (spec 0008 D5 and D6)
|
|
228
|
+
// ---------------------------------------------------------------------------
|
|
229
|
+
|
|
230
|
+
/** The most rows a kind's list shows before "and N more" */
|
|
231
|
+
export const LINES_CAP = 12;
|
|
232
|
+
|
|
233
|
+
/** The lit set the panel describes: the same rule the scene lights by (selection-model.js) */
|
|
234
|
+
const litNow = () => activeSubgraph(state.selectedNode, viewEdges(), { throughChildren: state.throughChildren, kind: state.selectedKind });
|
|
235
|
+
|
|
236
|
+
/** The panel's "Calls 12 · Reads 9" chips, the chosen kind's far ends, the switch, and the line that says how much is on screen, with Frame them */
|
|
237
|
+
function linesHtml(node) {
|
|
238
|
+
const sub = litNow();
|
|
239
|
+
if (!sub || !sub.kinds.size) return '';
|
|
240
|
+
const kinds = linesByKind(sub);
|
|
241
|
+
const chips = kinds.map(({ kind, count, word }) => `<button type="button" class="hx-lines-kind" data-corn="lines-kind" data-corn-kind="quiet" data-lines-kind="${escHtml(kind)}" data-focus-key="kind:${escHtml(kind)}" aria-pressed="${sub.kind === kind}">${escHtml(word)} <span class="hx-lines-count" data-corn="count">${count}</span></button>`).join('');
|
|
242
|
+
const open = sub.kind ? farEnds(sub, sub.kind).map((r) => `<button type="button" class="hx-linkbtn" data-corn="node-link" data-action="select-node" data-id="${escHtml(r.id)}"><span class="hx-sr-only">${r.out ? 'to ' : 'from '}</span><span aria-hidden="true">${r.out ? '→' : '←'}</span> ${escHtml(nameOf(r.id))}</button>`) : [];
|
|
243
|
+
const list = open.length ? `<div class="hx-lines-list">${capped(open, LINES_CAP)}</div>` : '';
|
|
244
|
+
const hasChildren = activeSubgraph(node, viewEdges(), { throughChildren: false }).childIds.size > 0;
|
|
245
|
+
const through = hasChildren ? `<label class="hx-lines-switch"><input type="checkbox" data-corn="lines-switch" data-lines-switch data-focus-key="switch"${state.throughChildren ? ' checked' : ''}> <span>${escHtml(t('throughChildren'))}</span></label>` : '';
|
|
246
|
+
const { connected, off } = reach();
|
|
247
|
+
return `<div class="hx-sec-block hx-lines" id="drawer-lines" data-corn="lines-by-kind"><h3 class="hx-sec-title">Lines</h3><div class="hx-chips" role="group" aria-label="Lit lines by kind">${chips}</div>${list}${through}<div class="hx-lines-reach"><span data-lines-reach>${escHtml(connectedLine(connected, off))}</span> <button type="button" data-corn="frame-button" data-corn-kind="secondary" class="hx-btn hx-btn--secondary" data-action="frame-selection" data-focus-key="frame">${escHtml(t('frame'))}</button></div></div>`;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/** Draws the lines block again after a switch or a kind was chosen; the focus stays on the control that was used */
|
|
251
|
+
function paintLines() {
|
|
252
|
+
const box = $('drawer-lines');
|
|
253
|
+
if (!box || !state.selectedNode) return;
|
|
254
|
+
const key = document.activeElement && box.contains(document.activeElement) ? document.activeElement.dataset.focusKey : '';
|
|
255
|
+
const html = linesHtml(state.selectedNode);
|
|
256
|
+
const holder = document.createElement('div');
|
|
257
|
+
holder.innerHTML = html;
|
|
258
|
+
const next = holder.firstElementChild;
|
|
259
|
+
if (next) box.replaceWith(next); else box.remove();
|
|
260
|
+
if (key) { const again = $('drawer-lines'); const el = again && [...again.querySelectorAll('[data-focus-key]')].find((x) => x.dataset.focusKey === key); if (el) el.focus(); }
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/** One step through the panel's lines controls: a kind's chip lights that kind alone (the same chip again lights them all), the switch widens the set */
|
|
264
|
+
function onLinesClick(e) {
|
|
265
|
+
const chip = e.target.closest && e.target.closest('[data-lines-kind]');
|
|
266
|
+
if (!chip || !state.selectedNode) return false;
|
|
267
|
+
const kind = chip.dataset.linesKind;
|
|
268
|
+
state.selectedKind = state.selectedKind === kind ? null : kind;
|
|
269
|
+
touchScene();
|
|
270
|
+
render();
|
|
271
|
+
paintLines();
|
|
272
|
+
const sub = litNow();
|
|
273
|
+
announce(sub && sub.kind ? `Showing ${kindPanelWord(sub.kind).toLowerCase()} only: ${sub.edges.length} ${sub.edges.length === 1 ? 'line' : 'lines'}` : 'Showing every kind of line');
|
|
274
|
+
return true;
|
|
275
|
+
}
|
|
276
|
+
function onLinesChange(e) {
|
|
277
|
+
const box = e.target.closest && e.target.closest('[data-lines-switch]');
|
|
278
|
+
if (!box || !state.selectedNode) return;
|
|
279
|
+
state.throughChildren = !!box.checked;
|
|
280
|
+
state.selectedKind = null; // the set changed under the chosen kind: it may not be in it
|
|
281
|
+
touchScene();
|
|
282
|
+
render();
|
|
283
|
+
paintLines();
|
|
284
|
+
const sub = litNow();
|
|
285
|
+
announce(`${state.throughChildren ? 'Including' : 'Not including'} its children's lines: ${sub ? sub.connectedNodeIds.size - 1 : 0} connected`);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/** Keeps "9 connected · 3 off screen" true as the camera moves (after every draw, while a node is selected and its panel is open) */
|
|
289
|
+
onPaint(() => {
|
|
290
|
+
if (!state.selectedNode) return;
|
|
291
|
+
const el = document.querySelector('[data-lines-reach]');
|
|
292
|
+
if (!el) return;
|
|
293
|
+
const { connected, off } = reach();
|
|
294
|
+
const text = connectedLine(connected, off);
|
|
295
|
+
if (el.textContent !== text) el.textContent = text;
|
|
296
|
+
});
|
|
297
|
+
|
|
223
298
|
// ---------------------------------------------------------------------------
|
|
224
299
|
// The drawer
|
|
225
300
|
// ---------------------------------------------------------------------------
|
|
226
301
|
let selectToken = 0;
|
|
227
302
|
|
|
228
|
-
/**
|
|
229
|
-
|
|
303
|
+
/**
|
|
304
|
+
* Selects a node: lights what is one edge from it on the map and fills the side panel. `frame` is for a selection that did not come
|
|
305
|
+
* from a click on the map (a search, a list, a link, the keyboard): the camera then flies to the node and what it lights (selection-model.js);
|
|
306
|
+
* a click leaves the camera where it is (spec 0008 D6).
|
|
307
|
+
*/
|
|
308
|
+
export async function selectNode(node, { frame = false } = {}) {
|
|
230
309
|
if (!node) return;
|
|
231
310
|
const token = ++selectToken;
|
|
232
311
|
clearScenario();
|
|
233
312
|
dismissHint(); // a node has been picked: the hint's job is done for this session
|
|
313
|
+
if (!state.selectedNode || state.selectedNode.id !== node.id) state.selectedKind = null; // a kind chosen for one node means nothing for the next
|
|
234
314
|
state.selectedNode = node;
|
|
235
315
|
state.selectedEdge = null;
|
|
236
316
|
touchScene();
|
|
237
317
|
render();
|
|
238
318
|
|
|
239
319
|
const metaList = $('drawer-meta-list');
|
|
240
|
-
if (!metaList.dataset.moreBound) {
|
|
320
|
+
if (!metaList.dataset.moreBound) {
|
|
321
|
+
metaList.dataset.moreBound = '1';
|
|
322
|
+
metaList.addEventListener('click', (e) => { if (!onLinesClick(e)) toggleCapped(e.target); });
|
|
323
|
+
metaList.addEventListener('change', onLinesChange);
|
|
324
|
+
}
|
|
241
325
|
const openBtn = $('drawer-open-btn');
|
|
242
326
|
const title = $('drawer-title');
|
|
243
327
|
|
|
@@ -257,7 +341,7 @@ export async function selectNode(node) {
|
|
|
257
341
|
if (token !== selectToken) return;
|
|
258
342
|
|
|
259
343
|
const facts = `${node.file ? section('File', [code(node.file)]) : ''}${flowSummary(node)}${dataSummary(node)}`;
|
|
260
|
-
metaList.innerHTML = `${facts ? `<div class="hx-facts">${facts}</div>` : ''}
|
|
344
|
+
metaList.innerHTML = `${linesHtml(node)}${facts ? `<div class="hx-facts">${facts}</div>` : ''}
|
|
261
345
|
<div id="drawer-live">${liveSection(node)}</div>
|
|
262
346
|
${nodeMockupsHtml(node.id)}
|
|
263
347
|
<div id="drawer-threads">${threadsSection(node)}</div>
|
|
@@ -285,7 +369,8 @@ export async function selectNode(node) {
|
|
|
285
369
|
$('spec-drawer').inert = false; // closed, it waits off screen: inert, so Tab never reaches its buttons (MAP-02)
|
|
286
370
|
$('drawer-backdrop').hidden = false;
|
|
287
371
|
showSheet('drawer'); // on a phone it takes Work's place (the node sheet and Work take turns), and comes back from away when its node is tapped again
|
|
288
|
-
|
|
372
|
+
if (frame) frameSelection(); // the panel is open now, so what it covers is known
|
|
373
|
+
else keepSelectedInView();
|
|
289
374
|
}
|
|
290
375
|
|
|
291
376
|
/**
|
package/explorer/render.js
CHANGED
|
@@ -22,8 +22,8 @@ import { ZOOM_MIN, ZOOM_FLOOR } from './camera.js';
|
|
|
22
22
|
// ---------------------------------------------------------------------------
|
|
23
23
|
export const isNodeVisible = (node) => nodeVisible(state, node);
|
|
24
24
|
|
|
25
|
-
/** The focus subgraph: the selected node
|
|
26
|
-
export const getActiveSubgraph = (selected, edges = viewEdges()) => activeSubgraph(selected, edges);
|
|
25
|
+
/** The focus subgraph: the selected node and every node one edge away (selection-model.js); the switch and the kind come from the state */
|
|
26
|
+
export const getActiveSubgraph = (selected, edges = viewEdges(), opts = { throughChildren: !!state.throughChildren, kind: state.selectedKind || null }) => activeSubgraph(selected, edges, opts);
|
|
27
27
|
|
|
28
28
|
// ---------------------------------------------------------------------------
|
|
29
29
|
// Scene and renderer
|