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.
@@ -0,0 +1,75 @@
1
+ /**
2
+ * @module explorer/header-fit
3
+ *
4
+ * Keeps the header's left group (the brand, the View switch, the Layers chip) inside its box (CF review F46). A brand wordmark can be wider
5
+ * than the room a phone leaves, and the group used to scroll sideways behind a scrollbar nobody could see, with House half out of sight.
6
+ * Nothing here guesses a width: it measures. With the wordmark shown, if the group's content is wider than its box the wordmark goes
7
+ * (`data-brand-short` on the group, explorer.css hides it and the logo stays); if the content still does not fit, `data-overflow` is set, and
8
+ * explorer.css draws a fade at the edge it scrolls under, so a scroll is never silent. The brand button keeps its accessible name either way.
9
+ */
10
+
11
+ export const SHORT_ATTR = 'data-brand-short';
12
+ export const OVERFLOW_ATTR = 'data-overflow';
13
+
14
+ /** Whether an element's content is wider than its box (a pixel of rounding is not) */
15
+ const wider = (el) => el.scrollWidth > el.clientWidth + 1;
16
+
17
+ /**
18
+ * Measures the header's left group once and sets (or clears) its two attributes.
19
+ * @param {Element} left the `.hx-header-left` group
20
+ * @returns {{short: boolean, overflow: boolean}}
21
+ */
22
+ export function fitLeft(left) {
23
+ left.removeAttribute(SHORT_ATTR);
24
+ left.removeAttribute(OVERFLOW_ATTR);
25
+ let short = false;
26
+ if (left.querySelector('[data-corn="brand-wordmark"]') && wider(left)) {
27
+ left.setAttribute(SHORT_ATTR, '');
28
+ short = true;
29
+ }
30
+ const overflow = wider(left);
31
+ if (overflow) left.setAttribute(OVERFLOW_ATTR, '');
32
+ return { short, overflow };
33
+ }
34
+
35
+ /**
36
+ * Fits the header now and whenever its room or its content changes: the window resizing, the wordmark image arriving, a font arriving, a chip's text changing.
37
+ * @param {Document} doc
38
+ * @returns {() => void} how to stop
39
+ */
40
+ export function watchHeaderFit(doc) {
41
+ const left = doc.querySelector('.hx-header-left');
42
+ const win = doc.defaultView;
43
+ if (!left || !win) return () => {};
44
+ let queued = false;
45
+ const run = () => { queued = false; fitLeft(left); };
46
+ const soon = () => {
47
+ if (queued) return;
48
+ queued = true;
49
+ if (win.requestAnimationFrame) win.requestAnimationFrame(run); else run();
50
+ };
51
+ const stops = [];
52
+ if (win.ResizeObserver) {
53
+ const ro = new win.ResizeObserver(soon);
54
+ ro.observe(doc.documentElement);
55
+ ro.observe(left);
56
+ stops.push(() => ro.disconnect());
57
+ } else {
58
+ win.addEventListener('resize', soon);
59
+ stops.push(() => win.removeEventListener('resize', soon));
60
+ }
61
+ if (win.MutationObserver) {
62
+ const mo = new win.MutationObserver(soon);
63
+ mo.observe(left, { childList: true, subtree: true, characterData: true, attributes: true, attributeFilter: ['hidden'] }); // a chip or the House button coming or going
64
+ stops.push(() => mo.disconnect());
65
+ }
66
+ left.addEventListener('load', soon, true); // the wordmark's <img>: load does not bubble, so captured
67
+ stops.push(() => left.removeEventListener('load', soon, true));
68
+ const fonts = doc.fonts;
69
+ if (fonts && fonts.addEventListener) {
70
+ fonts.addEventListener('loadingdone', soon);
71
+ stops.push(() => fonts.removeEventListener('loadingdone', soon));
72
+ }
73
+ soon();
74
+ return () => stops.forEach((fn) => fn());
75
+ }
@@ -0,0 +1,92 @@
1
+ /**
2
+ * @module explorer/hint
3
+ *
4
+ * The hint at the map's corner ("Click a node for what it is"; CF review F56). Three rules:
5
+ * - its words follow the pointer: `hintInspect` / `hintDrag` for a mouse or a trackpad, `hintInspectTouch` / `hintDragTouch` where the
6
+ * main pointer is coarse (a finger). A repo that sets only `hintInspect` (or `hintDrag`) gets its words on both;
7
+ * - it goes once the person has selected a node, for the rest of the session (sessionStorage; the Flow view's own description stays,
8
+ * since it says what Flow is, not how to use the map);
9
+ * - it is never shown over an open proposal, a node panel, the Work panel or a sheet.
10
+ * The icon is `[data-corn="hint-icon"]`, so a theme can restyle or replace it.
11
+ */
12
+
13
+ import { state } from './state.js';
14
+ import { isOverridden, t } from './strings.js';
15
+
16
+ export const HINT_STORAGE_KEY = 'cornfield:hint-done';
17
+
18
+ const $ = (id) => document.getElementById(id);
19
+
20
+ /** Whether the main pointer is a finger (`(pointer: coarse)`) */
21
+ export function coarsePointer(win = typeof window !== 'undefined' ? window : null) {
22
+ try { return !!(win && win.matchMedia && win.matchMedia('(pointer: coarse)').matches); } catch { return false; }
23
+ }
24
+
25
+ /** The words by the pointer: the Touch ones on a finger, unless the repo set only the plain key (then its words serve both) */
26
+ export function hintWords(plain, touch, coarse) {
27
+ return coarse && (touch.set || !plain.set) ? touch.text : plain.text;
28
+ }
29
+
30
+ /** The hint for the view in force */
31
+ export function hintText(coarse = coarsePointer()) {
32
+ if (state.view === 'dataflow') return t('hintDataFlow');
33
+ return state.isFreeform
34
+ ? hintWords({ text: t('hintDrag'), set: isOverridden('hintDrag') }, { text: t('hintDragTouch'), set: isOverridden('hintDragTouch') }, coarse)
35
+ : hintWords({ text: t('hintInspect'), set: isOverridden('hintInspect') }, { text: t('hintInspectTouch'), set: isOverridden('hintInspectTouch') }, coarse);
36
+ }
37
+
38
+ let dismissed = false;
39
+ try { dismissed = window.sessionStorage.getItem(HINT_STORAGE_KEY) === '1'; } catch { dismissed = false; }
40
+
41
+ /** Remembers that a node was selected: the hint is not shown again this session */
42
+ export function dismissHint() {
43
+ if (dismissed) return;
44
+ dismissed = true;
45
+ try { window.sessionStorage.setItem(HINT_STORAGE_KEY, '1'); } catch { /* storage blocked: it holds for this page load */ }
46
+ syncHint();
47
+ }
48
+
49
+ /** For tests: the hint is new again */
50
+ export function resetHintForTests() {
51
+ dismissed = false;
52
+ try { window.sessionStorage.removeItem(HINT_STORAGE_KEY); } catch { /* none */ }
53
+ }
54
+
55
+ /** What covers the map: an open proposal, the node panel, the Work panel, a sheet of the dock */
56
+ export function mapCovered(doc = document) {
57
+ const open = (sel) => doc.querySelector(sel);
58
+ const bar = open('#proposal-bar');
59
+ if (bar && !bar.hidden) return true;
60
+ const drawer = open('#spec-drawer');
61
+ if (drawer && drawer.classList.contains('drawer-open')) return true;
62
+ const work = open('#forge-panel');
63
+ if (work && work.classList.contains('forge-open')) return true;
64
+ return !!doc.querySelector('[data-corn="scenario-player"]'); // a scenario is playing (a sheet on a phone)
65
+ }
66
+
67
+ /** Words, and whether it shows, for the state of the page now */
68
+ export function syncHint() {
69
+ const text = $('instruction-badge-text');
70
+ const words = hintText();
71
+ if (text && text.textContent !== words) text.textContent = words;
72
+ const hint = text && text.closest('[data-corn="hint"]');
73
+ if (!hint) return;
74
+ const hide = mapCovered() || (dismissed && state.view !== 'dataflow');
75
+ if (hint.hidden !== hide) hint.hidden = hide;
76
+ }
77
+
78
+ /** Keeps the hint right as panels open and close, and as the pointer kind changes. Returns how to stop. */
79
+ export function watchHint(doc = document) {
80
+ const win = doc.defaultView;
81
+ const stops = [];
82
+ const stage = doc.querySelector('[data-corn="stage"]') || doc.body;
83
+ if (win && win.MutationObserver && stage) {
84
+ const mo = new win.MutationObserver(syncHint);
85
+ mo.observe(stage, { attributes: true, attributeFilter: ['class', 'hidden', 'inert'], childList: true, subtree: true });
86
+ stops.push(() => mo.disconnect());
87
+ }
88
+ const media = win && win.matchMedia ? win.matchMedia('(pointer: coarse)') : null;
89
+ if (media && media.addEventListener) { media.addEventListener('change', syncHint); stops.push(() => media.removeEventListener('change', syncHint)); }
90
+ syncHint();
91
+ return () => stops.forEach((fn) => fn());
92
+ }
@@ -39,6 +39,17 @@ import { outageFor } from './outage-model.js';
39
39
 
40
40
  /** World units per floor viewBox unit */
41
41
  export const HOUSE_SCALE = 2;
42
+
43
+ /** The node types only a house plan has: a floor and a room (a device can be derived from code, with no plan to put it on) */
44
+ const HOUSE_ONLY_TYPES = ['floor', 'room'];
45
+ /**
46
+ * Whether the House view is offered: the repo names a source that can answer for a house (`sources.house`, `live` or `devices`), or the
47
+ * map already holds a floor or a room. With neither there is no plan to draw (a device derived from code has nowhere to go), only an
48
+ * empty one, so the button is not there (CF review F47) and the view is not an error to explain.
49
+ * @param {boolean} hasSource
50
+ * @param {{ type?: string }[]} nodes
51
+ */
52
+ export const houseOffered = (hasSource, nodes) => !!hasSource || (Array.isArray(nodes) && nodes.some((n) => HOUSE_ONLY_TYPES.includes(n.type)));
42
53
  /** The radius each kind of thing is drawn at in the House view: a machine a size larger than a device, a room small */
43
54
  export const HOUSE_SIZES = { room: 8, floor: 14, device: 13, machine: 20, persona: 18, phone: 11, stack: 16, container: 9, app: 11, pkg: 14, external: 12 };
44
55
  /** One slot of a room's grid (world units): room for a device and its label */
@@ -34,7 +34,7 @@
34
34
  .hx-house-people[hidden] { display: none; }
35
35
  .hx-house-chip { min-height: 28px; padding: var(--corn-space-1) var(--corn-space-4); border: var(--corn-border) solid color-mix(in srgb, var(--corn-text-3) 25%, transparent); border-radius: var(--corn-radius-pill); background: color-mix(in srgb, var(--corn-ground) 80%, transparent); color: var(--corn-text-2); font-weight: 600; font-size: var(--corn-text-sm); line-height: 1.2; font-family: inherit; cursor: pointer; white-space: nowrap; }
36
36
  .hx-house-chip:hover { border-color: color-mix(in srgb, var(--corn-hue-lime) 50%, transparent); color: var(--corn-text); }
37
- .hx-house-chip:focus-visible { outline: var(--corn-focus-width) solid var(--corn-focus); outline-offset: 2px; }
37
+ .hx-house-chip:focus-visible { outline: var(--corn-focus-width) solid var(--corn-focus); outline-offset: var(--corn-focus-offset); }
38
38
  .hx-house-chip[aria-pressed="true"] { background: var(--corn-hue-lime); border-color: var(--corn-hue-lime); color: var(--corn-ground); }
39
39
  .hx-house-chip--person { border-color: color-mix(in srgb, var(--corn-hue-pink) 45%, transparent); }
40
40
  .hx-house-chip--software, .hx-house-chip--cloud { border-style: dashed; }
package/explorer/house.js CHANGED
@@ -49,11 +49,14 @@ const cfg = () => state.house || (state.house = newHouseState());
49
49
 
50
50
  /**
51
51
  * Starts the House view's machinery. Nothing is drawn until the view opens.
52
- * @param {{ floor?: { element?: string, render: (plan: object, floorId: string) => string, defaultPlan?: () => object, editUrl?: string | ((floorId: string) => string) } | null }} [opts]
52
+ * @param {{ offered?: boolean, floor?: { element?: string, render: (plan: object, floorId: string) => string, defaultPlan?: () => object, editUrl?: string | ((floorId: string) => string) } | null }} [opts]
53
53
  */
54
54
  export function initHouse(opts = {}) {
55
55
  hook = opts.floor || null;
56
56
  const c = cfg();
57
+ c.offered = opts.offered !== false;
58
+ const offer = $('preset-house-btn');
59
+ if (offer) offer.hidden = !c.offered; // nothing to show: the View switch is Map and Flow only
57
60
  c.defaultPlan = hook && typeof hook.defaultPlan === 'function' ? hook.defaultPlan() : null;
58
61
  c.phone = isPhone();
59
62
  mount();
@@ -68,7 +71,7 @@ export function initHouse(opts = {}) {
68
71
  }
69
72
  addFrameClient({ wants: () => false, tick: followCamera });
70
73
  }
71
- if (typeof window !== 'undefined' && new URLSearchParams(window.location.search).get('view') === 'house') openHouse();
74
+ if (c.offered && typeof window !== 'undefined' && new URLSearchParams(window.location.search).get('view') === 'house') openHouse();
72
75
  syncHouse();
73
76
  }
74
77
 
@@ -46,7 +46,7 @@
46
46
 
47
47
  <!-- The Layers chip: how many of the layers are on; it opens the layers menu. On a phone it sits on the map, top left -->
48
48
  <div class="hx-menu-wrap hx-layers">
49
- <button type="button" id="legend-toggle-btn" class="hx-layers-chip" data-action="toggle-layers-menu" aria-expanded="false" aria-controls="legend-dropdown" data-corn="layers-button"><span data-corn-string="layers">Layers</span><span id="layers-count" class="hx-layers-count"></span></button>
49
+ <button type="button" id="legend-toggle-btn" class="hx-layers-chip" data-action="toggle-layers-menu" aria-expanded="false" aria-controls="legend-dropdown" data-corn="layers-button"><span data-corn-string="layers">Layers</span><span id="layers-count" class="hx-layers-count" data-corn="count"></span></button>
50
50
 
51
51
  <!-- Interactive section toggles and the legend -->
52
52
  <div id="legend-dropdown" class="hx-menu glass" hidden data-corn="layers-menu">
@@ -122,7 +122,7 @@
122
122
  <!-- The Work toggle (explorer/forge-panel.js): opens the Work panel; shown only when the config names a forge -->
123
123
  <button type="button" id="forge-btn" class="hx-work" data-action="toggle-forge" aria-expanded="false" aria-controls="forge-panel" aria-label="Work" data-corn-string-aria-label="issuesAndPrs" title="Issues, pull requests and deploys: a pull request lights the nodes it changes, a deploy the nodes it restarted" hidden data-corn="forge-button">
124
124
  <span data-corn-string="issuesAndPrs">Work</span>
125
- <span id="forge-btn-lit" class="hx-forge-lit" hidden></span>
125
+ <span id="forge-btn-lit" class="hx-forge-lit" data-corn="count" hidden></span>
126
126
  </button>
127
127
 
128
128
  <!-- The one account menu (explorer/account-menu.js): who, Theme, Freeform layout, Review tokens, Proposals, the links, Sign out, and what powers it -->
@@ -235,24 +235,27 @@
235
235
  </section>
236
236
 
237
237
  <!-- The Work panel (forge-panel.js): Specs, PRs, Issues, Threads, Runs and Deploys, in the order of the loop. A slide-over from the left on desktop, a bottom sheet on a phone; hidden and inert until the config names a forge. `forge-panel` on the inner box is the old name of the hook, kept for one release (docs/theming.md) -->
238
+ <p id="offline-banner" class="hx-offline" data-corn="notice" hidden></p>
238
239
  <aside id="forge-panel" class="hx-forge glass" aria-label="Work" inert hidden data-corn="work-panel">
239
240
  <div class="hx-forge-body" data-corn="forge-panel">
241
+ <div class="hx-forge-top" data-corn="work-top">
240
242
  <div class="hx-forge-head">
241
243
  <h2 id="forge-title" class="hx-drawer-title" tabindex="-1">Work</h2>
242
244
  <button type="button" class="hx-btn hx-btn--quiet" data-action="refresh-forge" title="Ask the forge again" data-corn-kind="quiet">Refresh</button>
243
245
  <button type="button" class="hx-close" data-action="close-forge" aria-label="Close" data-corn-kind="icon">✕</button>
244
246
  </div>
245
247
  <div class="hx-forge-tabs" role="group" aria-label="Show" data-corn="tabs">
246
- <button type="button" class="hx-forge-tab" data-forge-kind="specs" aria-pressed="true" title="The proposals: what a change would add, change and remove" data-corn="tab"><span data-corn-string="tabSpecs">Specs</span><span class="hx-forge-count" hidden></span></button>
247
- <button type="button" class="hx-forge-tab" data-forge-kind="pulls" aria-pressed="false" title="Pull requests" data-corn="tab"><span data-corn-string="tabPulls">PRs</span><span class="hx-forge-count" hidden></span></button>
248
- <button type="button" class="hx-forge-tab" data-forge-kind="issues" aria-pressed="false" data-corn="tab"><span data-corn-string="tabIssues">Issues</span><span class="hx-forge-count" hidden></span></button>
249
- <button type="button" class="hx-forge-tab" data-forge-kind="threads" aria-pressed="false" title="Ideas and spec conversations, with the nodes they mention" data-corn="tab"><span data-corn-string="tabThreads">Threads</span><span class="hx-forge-count" hidden></span></button>
250
- <button type="button" class="hx-forge-tab" data-forge-kind="work" aria-pressed="false" title="Agent runs, and the work grouped by issue and proposal with agent-made work marked" data-corn="tab"><span data-corn-string="tabRuns">Runs</span><span class="hx-forge-count" hidden></span></button>
251
- <button type="button" class="hx-forge-tab" data-forge-kind="deploys" aria-pressed="false" data-corn="tab"><span data-corn-string="tabDeploys">Deploys</span><span class="hx-forge-count" hidden></span></button>
248
+ <button type="button" class="hx-forge-tab" data-forge-kind="specs" aria-pressed="true" title="The proposals: what a change would add, change and remove" data-corn="tab"><span data-corn-string="tabSpecs">Specs</span><span class="hx-forge-count" data-corn="count" hidden></span></button>
249
+ <button type="button" class="hx-forge-tab" data-forge-kind="pulls" aria-pressed="false" title="Pull requests" data-corn="tab"><span data-corn-string="tabPulls">PRs</span><span class="hx-forge-count" data-corn="count" hidden></span></button>
250
+ <button type="button" class="hx-forge-tab" data-forge-kind="issues" aria-pressed="false" data-corn="tab"><span data-corn-string="tabIssues">Issues</span><span class="hx-forge-count" data-corn="count" hidden></span></button>
251
+ <button type="button" class="hx-forge-tab" data-forge-kind="threads" aria-pressed="false" title="Ideas and spec conversations, with the nodes they mention" data-corn="tab"><span data-corn-string="tabThreads">Threads</span><span class="hx-forge-count" data-corn="count" hidden></span></button>
252
+ <button type="button" class="hx-forge-tab" data-forge-kind="work" aria-pressed="false" title="Agent runs, and the work grouped by issue and proposal with agent-made work marked" data-corn="tab"><span data-corn-string="tabRuns">Runs</span><span class="hx-forge-count" data-corn="count" hidden></span></button>
253
+ <button type="button" class="hx-forge-tab" data-forge-kind="deploys" aria-pressed="false" data-corn="tab"><span data-corn-string="tabDeploys">Deploys</span><span class="hx-forge-count" data-corn="count" hidden></span></button>
254
+ </div>
252
255
  </div>
253
256
  <div id="forge-bar" class="hx-forge-bar">
254
257
  <p id="forge-status" class="hx-forge-status hx-faint"></p>
255
- <button type="button" id="forge-filter-chip" class="hx-forge-chip" data-action="toggle-filters" aria-expanded="false" aria-controls="forge-filter-box" hidden>Filter<span class="hx-forge-count" hidden></span></button>
258
+ <button type="button" id="forge-filter-chip" class="hx-forge-chip" data-action="toggle-filters" aria-expanded="false" aria-controls="forge-filter-box" hidden>Filter<span class="hx-forge-count" data-corn="count" hidden></span></button>
256
259
  </div>
257
260
  <div id="forge-filter-box" class="hx-forge-controls" hidden>
258
261
  <div id="forge-work-filters" class="hx-forge-work-filters" hidden>
@@ -350,13 +353,14 @@
350
353
  <a id="drawer-open-btn" class="hx-open" href="#" target="_blank" rel="noreferrer" hidden>Open route ↗</a>
351
354
  <button type="button" id="drawer-run-btn" class="hx-btn hx-foot-btn" data-action="start-run" data-corn-string="startRun" hidden>Start a run</button>
352
355
  <button type="button" class="hx-btn hx-btn--quiet hx-foot-btn" data-action="copy-spec" data-corn-string="copySpec">Copy Spec</button>
356
+ <p id="copy-spec-result" class="hx-forge-result" data-corn="result" hidden></p>
353
357
  </div>
354
358
  </aside>
355
359
  </div>
356
360
 
357
361
  <div class="hx-hint glass" data-corn="hint">
358
- <span class="hx-accent" aria-hidden="true">👆</span>
359
- <span id="instruction-badge-text">Tap node to inspect live spec</span>
362
+ <span class="hx-accent hx-hint-icon" aria-hidden="true" data-corn="hint-icon"><svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linejoin="round" focusable="false"><path d="M3 2l9 4.2-4 1.4-1.4 4z" /></svg></span>
363
+ <span id="instruction-badge-text">Click a node to see what it is</span>
360
364
  </div>
361
365
 
362
366
  <!-- Loading and error states: a failed load never leaves a blank canvas -->
@@ -74,13 +74,13 @@ export function chooseLabels(scene, camera, viewport, opts = {}) {
74
74
  // Always there: the data-flow lanes' titles, notes and arrows ...
75
75
  for (const lane of scene.decor.lanes) {
76
76
  for (const t of [lane.title, lane.note, lane.arrow]) {
77
- if (t) out.push({ kind: 'lane', text: t.text, x: t.x, y: t.y, size: t.size, bold: t.bold, italic: false, color: t.color, alpha: 1, outline: null, align: 'center', family: FONT_NODE });
77
+ if (t) out.push({ kind: 'lane', text: t.text, x: t.x, y: t.y, size: t.size, bold: t.bold, italic: false, color: t.color, alpha: 1, outline: null, align: 'center', family: scene.labelFont || FONT_NODE });
78
78
  }
79
79
  }
80
80
  // ... and the labels on the selection's edges
81
81
  for (const edge of scene.edges) {
82
82
  const l = edge.label;
83
- if (l) out.push({ kind: 'edge', text: l.text, x: l.x, y: l.y, size: EDGE_LABEL_SIZE, bold: false, italic: !!l.italic, color: l.color, alpha: edge.alpha, outline: outline.edge, align: 'center', family: FONT_EDGE });
83
+ if (l) out.push({ kind: 'edge', text: l.text, x: l.x, y: l.y, size: EDGE_LABEL_SIZE, bold: false, italic: !!l.italic, color: l.color, alpha: edge.alpha, outline: outline.edge, align: 'center', family: scene.labelFont || FONT_EDGE });
84
84
  }
85
85
 
86
86
  // Node labels: level of detail, then the ones whose box reaches the viewport
@@ -116,7 +116,7 @@ export function chooseLabels(scene, camera, viewport, opts = {}) {
116
116
  }
117
117
 
118
118
  for (const { label, id } of kept) {
119
- out.push({ kind: 'node', id, text: label.text, x: label.x, y: label.y, size: label.size, bold: label.bold, italic: false, color: label.color, alpha: label.alpha, outline: outline.node, align: 'center', family: FONT_NODE, strike: !!label.strike });
119
+ out.push({ kind: 'node', id, text: label.text, x: label.x, y: label.y, size: label.size, bold: label.bold, italic: false, color: label.color, alpha: label.alpha, outline: outline.node, align: 'center', family: scene.labelFont || FONT_NODE, strike: !!label.strike });
120
120
  }
121
121
  return out;
122
122
  }
@@ -184,11 +184,12 @@ export function createLabelLayer(canvas, opts = {}) {
184
184
 
185
185
  // Text widths for the culling, measured once per font and string
186
186
  const widths = new Map();
187
+ let family = FONT_NODE; // the theme's label font (`--corn-map-font`) when it sets one, else the map's own
187
188
  const measure = (text, size, bold) => {
188
- const key = `${bold ? 'b' : 'n'}${size}|${text}`;
189
+ const key = `${bold ? 'b' : 'n'}${size}|${family}|${text}`;
189
190
  let w = widths.get(key);
190
191
  if (w === undefined) {
191
- ctx.font = fontOf({ italic: false, bold, size, family: FONT_NODE });
192
+ ctx.font = fontOf({ italic: false, bold, size, family });
192
193
  w = ctx.measureText(text).width;
193
194
  widths.set(key, w);
194
195
  }
@@ -213,7 +214,8 @@ export function createLabelLayer(canvas, opts = {}) {
213
214
  if (!dirty && drawn === lastScene && drawn.version === lastVersion && camera.x === lastX && camera.y === lastY && camera.zoom === lastZoom && styleKey === lastStyle) return false;
214
215
  lastScene = drawn; lastVersion = drawn.version; lastX = camera.x; lastY = camera.y; lastZoom = camera.zoom; lastStyle = styleKey;
215
216
  dirty = false;
216
- const scene = styledScene(drawn, style); // the label colours of the theme (map-style.js)
217
+ const scene = styledScene(drawn, style); // the label colours and font of the theme (map-style.js)
218
+ family = scene.labelFont || FONT_NODE;
217
219
 
218
220
  ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
219
221
  ctx.clearRect(0, 0, width, height);
@@ -114,7 +114,7 @@ export function renderLayerToggles() {
114
114
  <span class="hx-toggle-name">${escHtml(layer.label)}</span>${layer.live ? '<span class="hx-live-tag">live</span>' : ''}
115
115
  </span>
116
116
  <span class="hx-toggle-meta">
117
- <span class="hx-count">${(unit[layer.key] || String)(counts[layer.key] || 0)}</span>
117
+ <span class="hx-count" data-corn="count">${(unit[layer.key] || String)(counts[layer.key] || 0)}</span>
118
118
  <span class="hx-tick">${on ? '✓' : '—'}</span>
119
119
  </span>
120
120
  </button>`;
@@ -276,7 +276,11 @@ export function failureWords(error, { settable = false } = {}) {
276
276
  const reason = error && error.reason;
277
277
  const hint = error && typeof error.hint === 'string' && error.hint ? error.hint : '';
278
278
  let w;
279
- if (reason === 'no-token') {
279
+ if (error && error.notConfigured === true) {
280
+ // No live source is set: nothing is wrong, so the chip is neutral (off), not an error
281
+ const short = hint || 'no live source is set';
282
+ w = { text: `No live layer: ${short}`, short, tone: 'off', href: null, fix: '' };
283
+ } else if (reason === 'no-token') {
280
284
  const short = hint || 'no token';
281
285
  w = { text: `Live layer off: ${short}`, short, tone: 'off', href: error.href || null, fix: settable ? 'Set one in the Live menu.' : '' };
282
286
  } else if (reason === 'forbidden') {
@@ -308,7 +312,7 @@ export function chipModel(snap, { other = 0, now = Date.now(), house = false } =
308
312
  }
309
313
  if (snap.error) {
310
314
  const w = failureWords(snap.error);
311
- if (house) return { ...base, tone: w.tone, text: `Default plan, live layer ${w.tone === 'off' ? 'off' : 'unavailable'}`, lines: [w.house], href: w.href, note: errorNote(snap.error) };
315
+ if (house) return { ...base, tone: w.tone, text: snap.error.notConfigured === true ? 'Default plan, no live layer' : `Default plan, live layer ${w.tone === 'off' ? 'off' : 'unavailable'}`, lines: [w.house], href: w.href, note: errorNote(snap.error) };
312
316
  return { ...base, tone: w.tone, text: w.text, href: w.href, note: errorNote(snap.error) };
313
317
  }
314
318
  return { ...base, tone: 'idle', text: 'Live layer: loading…' };
package/explorer/main.js CHANGED
@@ -42,6 +42,7 @@ import { initMockups } from './mockups.js';
42
42
  import { benchMeta, measureParams, readoutLines, resultLine, runBench, showReadout } from './bench.js';
43
43
  import { initLive } from './live.js';
44
44
  import { initHouse } from './house.js';
45
+ import { houseOffered } from './house-model.js';
45
46
  import { initChecks } from './check.js';
46
47
  import { initKeyboard } from './keyboard.js';
47
48
  import { initForgePanel } from './forge-panel.js';
@@ -49,6 +50,9 @@ import { initReviewTokens } from './review-tokens.js';
49
50
  import { loadClientConfig, loadSources, applyBranding } from './plugins.js';
50
51
  import { initTheme, setThemeChoice } from './theme.js';
51
52
  import { initAccountMenu } from './account-menu.js';
53
+ import { watchHeaderFit } from './header-fit.js';
54
+ import { watchHint } from './hint.js';
55
+ import { watchFocusRoom } from './focus-room.js';
52
56
  import { applyMapTheme, onMapStyleChange, watchMapStyle } from './map-style.js';
53
57
 
54
58
  const $ = (id) => document.getElementById(id);
@@ -214,13 +218,13 @@ $('mobile-node-search').addEventListener('input', (e) => handleSearch(e.target.v
214
218
  resize();
215
219
  syncViewUi();
216
220
  // /?proposal=<slug> opens a proposal over the map, /?view=dataflow the data-flow preset: both have a link
217
- const configReady = loadClientConfig().then((config) => { applyBranding(document, config); applyMapTheme(document, config.theme); syncViewUi(); return config; }); // the brand, then the theme's icons for the map; the hint again, in the repo's words
221
+ const configReady = loadClientConfig().then((config) => { applyBranding(document, config); watchHeaderFit(document); watchHint(document); watchFocusRoom(document); applyMapTheme(document, config.theme); syncViewUi(); return config; }); // the brand, then the theme's icons for the map; the hint again, in the repo's words
218
222
  loadTopology().then(async (ok) => {
219
223
  if (!ok) return;
220
224
  // The sources the repo's cornfield.config.js names (plugins.js): a live layer, a house, devices, a checker; each optional
221
225
  const config = await configReady;
222
226
  state.forge = config.forge || null;
223
- const { liveSource, floorRenderer, checker } = await loadSources(config);
227
+ const { liveSource, floorRenderer, checker, houseSource } = await loadSources(config);
224
228
  const forgeOn = initForgePanel(config); // issues and PRs: only when the config names a forge (forge-panel.js)
225
229
  initReviewTokens(config); // review tokens for the review API: only for somebody signed in (review-tokens.js)
226
230
  initWhatIf(); // before a proposal can open, so its edits come with it
@@ -230,7 +234,7 @@ loadTopology().then(async (ok) => {
230
234
  // The live layer (live.js): loads only once a live layer goes on in the Layers menu; with no source it stays off
231
235
  initLive({ source: liveSource, onSelectionGone: closeDrawer });
232
236
  // The House view (house.js): a source's floor renderer draws the plan under the map (plain room boxes without one); /?view=house opens it
233
- initHouse({ floor: floorRenderer });
237
+ initHouse({ floor: floorRenderer, offered: houseOffered(houseSource, state.nodes) }); // no house source and no house in the map: no House button
234
238
  initChecks({ checker }); // scenarios ask the source's checker, when there is one (check.js)
235
239
  if (new URLSearchParams(window.location.search).get("view") === "dataflow") setView("dataflow");
236
240
  // /?run=, /?issue= and /?proposal=…&start=1 land on a run, an issue's Start button and a proposal's Start dialog (deep-link.js)