cornfield 0.34.0 → 0.34.2

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/strings.js CHANGED
@@ -19,6 +19,7 @@ export const STRINGS = Object.freeze({
19
19
  proposals: 'Proposals',
20
20
  issuesAndPrs: 'Work',
21
21
  searchPlaceholder: 'Search...',
22
+ searchNoMatch: 'No match for',
22
23
  signOut: 'Sign out',
23
24
  poweredBy: 'powered by cornfield',
24
25
  // The proposal bar and the review
@@ -31,6 +32,7 @@ export const STRINGS = Object.freeze({
31
32
  sendBackWithNote: 'Send back with this note',
32
33
  reviewNoteLabel: 'Note for the drafting agent',
33
34
  reviewNotePlaceholder: 'What should change?',
35
+ openSpecsList: 'Open the Specs list',
34
36
  // The Work panel: its tabs run in the order of the loop
35
37
  tabSpecs: 'Specs',
36
38
  tabPulls: 'PRs',
@@ -10,19 +10,27 @@
10
10
  * @typedef {{ x: number, y: number, zoom: number }} Camera
11
11
  */
12
12
 
13
+ /** The floor of a map that fits above it; a bigger map (or a smaller screen) needs a lower one: render.js `getMinZoom()` */
13
14
  export const ZOOM_MIN = 0.25;
14
15
  export const ZOOM_MAX = 3.0;
16
+ /** Whatever the map, never below this (a bounding box of nothing, a map of a million px) */
17
+ export const ZOOM_FLOOR = 0.005;
15
18
 
16
- export const clampZoom = (zoom) => Math.max(ZOOM_MIN, Math.min(ZOOM_MAX, zoom));
19
+ /** `min` is the floor for this map and screen (`getMinZoom()`); it never rises above the default floor */
20
+ export const clampZoom = (zoom, min = ZOOM_MIN) => Math.max(Math.max(ZOOM_FLOOR, Math.min(min, ZOOM_MIN)), Math.min(ZOOM_MAX, zoom));
21
+
22
+ /** Zooming out is never zooming in: below the floor already (the layers changed), a step out stays where it is */
23
+ const stepZoom = (from, to, min) => (to < from ? Math.min(from, clampZoom(to, min)) : clampZoom(to, min));
17
24
 
18
25
  /**
19
26
  * The camera after zooming by `factor` with the screen point (px, py) held still.
20
27
  * @param {Camera} camera
21
28
  * @param {number} factor
29
+ * @param {number} [min] the floor for this map
22
30
  * @returns {Camera}
23
31
  */
24
- export function zoomAbout(camera, factor, px, py) {
25
- const zoom = clampZoom(camera.zoom * factor);
32
+ export function zoomAbout(camera, factor, px, py, min = ZOOM_MIN) {
33
+ const zoom = stepZoom(camera.zoom, camera.zoom * factor, min);
26
34
  const wx = (px - camera.x) / camera.zoom; // the world point under the pointer
27
35
  const wy = (py - camera.y) / camera.zoom;
28
36
  return { x: px - wx * zoom, y: py - wy * zoom, zoom };
@@ -45,9 +53,140 @@ export const pinchStart = (camera, dist, mid) => ({ x: camera.x, y: camera.y, zo
45
53
  * @param {{ x: number, y: number }} mid their middle now
46
54
  * @returns {Camera}
47
55
  */
48
- export function pinchCamera(start, dist, mid) {
49
- const zoom = clampZoom(start.zoom * (dist / start.dist));
56
+ export function pinchCamera(start, dist, mid, min = ZOOM_MIN) {
57
+ const zoom = stepZoom(start.zoom, start.zoom * (dist / start.dist), min);
50
58
  const wx = (start.mid.x - start.x) / start.zoom;
51
59
  const wy = (start.mid.y - start.y) / start.zoom;
52
60
  return { x: mid.x - wx * zoom, y: mid.y - wy * zoom, zoom };
53
61
  }
62
+
63
+ // ---------------------------------------------------------------------------
64
+ // Framing: put these nodes in the part of the map nothing covers
65
+ // ---------------------------------------------------------------------------
66
+
67
+ /** The zoom at which a node's label is about 11px on screen (labels are 11px in world units from LABEL_ZOOM up, scene.js): where a step or a picked change is shown */
68
+ export const READ_ZOOM = 1.0;
69
+ /**
70
+ * The lowest zoom a change is framed at when it opens (proposal.js `fitToChange`): below it node discs and marks run together, so a change
71
+ * wider than this shows is framed where most of it is (`largestGroup`), not shrunk to a speck; the rest is a row of the change list away.
72
+ * The map's own floor (render.js `getMinZoom()`, low enough for the whole map) is what hand zoom and Fit go down to.
73
+ */
74
+ export const FRAME_ZOOM_MIN = 0.18;
75
+
76
+ /**
77
+ * The part of a `width` × `height` map that nothing covers, given what covers it from each side (px).
78
+ * Never smaller than `minSize` in either direction: when the covers leave less, they are eased until it fits.
79
+ * @param {number} width
80
+ * @param {number} height
81
+ * @param {{ top?: number, bottom?: number, left?: number, right?: number }} [covers]
82
+ * @param {number} [minSize]
83
+ * @returns {{ x: number, y: number, width: number, height: number }}
84
+ */
85
+ export function freeRect(width, height, covers = {}, minSize = 120) {
86
+ const take = (total, a = 0, b = 0) => {
87
+ const lo = Math.max(0, a);
88
+ const hi = Math.max(0, b);
89
+ const room = Math.max(0, total - minSize);
90
+ const scale = lo + hi > room && lo + hi > 0 ? room / (lo + hi) : 1;
91
+ return [lo * scale, hi * scale];
92
+ };
93
+ const [top, bottom] = take(height, covers.top, covers.bottom);
94
+ const [left, right] = take(width, covers.left, covers.right);
95
+ return { x: left, y: top, width: Math.max(0, width - left - right), height: Math.max(0, height - top - bottom) };
96
+ }
97
+
98
+ /** The box a node needs on the map (world px): its disc, a little room round it and its label below */
99
+ const boxOf = (n) => {
100
+ const r = n.r || 18;
101
+ return { left: n.x - r - 25, right: n.x + r + 25, top: n.y - r - 25, bottom: n.y + r + 35 };
102
+ };
103
+ const padFor = (padding, rect) => Math.min(padding, rect.width / 4, rect.height / 4);
104
+
105
+ /**
106
+ * The camera that shows `items` (nodes with `x`, `y` and maybe `r`) inside `rect`, with their labels (room below each) and `padding` px to spare.
107
+ * The zoom is the largest that fits, between `minZoom` and `maxZoom`; when even `minZoom` does not fit, `minZoom` wins and the nodes
108
+ * are centred (the fit never goes under the floor it is given; see `largestGroup` for what to frame then).
109
+ * @param {{ x: number, y: number, r?: number }[]} items
110
+ * @param {{ x: number, y: number, width: number, height: number }} rect CSS px, in the canvas's own coordinates
111
+ * @param {{ padding?: number, maxZoom?: number, minZoom?: number }} [opts]
112
+ * @returns {Camera | null} null for no items
113
+ */
114
+ export function frameNodes(items, rect, { padding = 40, maxZoom = 1, minZoom = ZOOM_MIN } = {}) {
115
+ if (!items.length) return null;
116
+ let minX = Infinity;
117
+ let maxX = -Infinity;
118
+ let minY = Infinity;
119
+ let maxY = -Infinity;
120
+ for (const n of items) {
121
+ const b = boxOf(n);
122
+ minX = Math.min(minX, b.left);
123
+ maxX = Math.max(maxX, b.right);
124
+ minY = Math.min(minY, b.top);
125
+ maxY = Math.max(maxY, b.bottom);
126
+ }
127
+ const pad = padFor(padding, rect);
128
+ const fit = Math.min((rect.width - pad * 2) / (maxX - minX), (rect.height - pad * 2) / (maxY - minY));
129
+ const zoom = Math.max(minZoom, Math.min(maxZoom, fit));
130
+ return { x: rect.x + rect.width / 2 - ((minX + maxX) / 2) * zoom, y: rect.y + rect.height / 2 - ((minY + maxY) / 2) * zoom, zoom };
131
+ }
132
+
133
+ /** Whether every one of `items` is inside `rect` (with `margin` px to spare) under `camera` */
134
+ export function allInside(items, camera, rect, margin = 0) {
135
+ return items.every((n) => {
136
+ const sx = camera.x + n.x * camera.zoom;
137
+ const sy = camera.y + n.y * camera.zoom;
138
+ return sx >= rect.x + margin && sx <= rect.x + rect.width - margin && sy >= rect.y + margin && sy <= rect.y + rect.height - margin;
139
+ });
140
+ }
141
+
142
+ /**
143
+ * The most of `items` that fit in `rect` together at `minZoom`: all of them when they fit, else the biggest group a window of that size
144
+ * holds (so a change spread wider than the lowest zoom shows is framed where most of it is, not on the empty ground between).
145
+ * @param {{ x: number, y: number, r?: number }[]} items
146
+ * @param {{ x: number, y: number, width: number, height: number }} rect
147
+ * @param {{ padding?: number, minZoom?: number }} [opts]
148
+ */
149
+ export function largestGroup(items, rect, { padding = 40, minZoom = FRAME_ZOOM_MIN } = {}) {
150
+ if (items.length < 2) return items;
151
+ const pad = padFor(padding, rect);
152
+ const w = (rect.width - pad * 2) / minZoom;
153
+ const h = (rect.height - pad * 2) / minZoom;
154
+ const boxes = items.map(boxOf);
155
+ const holds = (left, top) => items.filter((_, i) => boxes[i].left >= left && boxes[i].right <= left + w && boxes[i].top >= top && boxes[i].bottom <= top + h);
156
+ // Every window worth trying has its left edge on some node's box and its top edge on some node's (a big change: only each node's own corner)
157
+ const lefts = boxes.map((b) => b.left);
158
+ const tops = boxes.map((b) => b.top);
159
+ let best = [];
160
+ const pairs = items.length <= 120 ? lefts.flatMap((l) => tops.map((t) => [l, t])) : boxes.map((b) => [b.left, b.top]);
161
+ for (const [l, t] of pairs) {
162
+ if (best.length === items.length) break;
163
+ const got = holds(l, t);
164
+ if (got.length > best.length) best = got;
165
+ }
166
+ return best.length ? best : [items[0]];
167
+ }
168
+
169
+ /**
170
+ * The camera panned (never zoomed) so a world point is inside `box` (screen px), or null when it already is. A point
171
+ * outside is put in the middle of the box, on the axis it is outside of. `pad` is the room it needs from the edge
172
+ * (its disc and a little more); a box smaller than twice that is the centre only.
173
+ * @param {Camera} camera
174
+ * @param {{ x: number, y: number }} point world position
175
+ * @param {{ left: number, top: number, right: number, bottom: number }} box the part of the screen that shows the map
176
+ * @param {number} [pad]
177
+ * @returns {Camera|null}
178
+ */
179
+ export function panIntoView(camera, point, box, pad = 0) {
180
+ const sx = camera.x + point.x * camera.zoom;
181
+ const sy = camera.y + point.y * camera.zoom;
182
+ const px = Math.min(pad, (box.right - box.left) / 2);
183
+ const py = Math.min(pad, (box.bottom - box.top) / 2);
184
+ const outX = sx < box.left + px || sx > box.right - px;
185
+ const outY = sy < box.top + py || sy > box.bottom - py;
186
+ if (!outX && !outY) return null;
187
+ return {
188
+ x: outX ? (box.left + box.right) / 2 - point.x * camera.zoom : camera.x,
189
+ y: outY ? (box.top + box.bottom) / 2 - point.y * camera.zoom : camera.y,
190
+ zoom: camera.zoom,
191
+ };
192
+ }
@@ -624,15 +624,16 @@ button.hx-proposal-item:focus-visible { outline: var(--corn-focus-width) solid v
624
624
 
625
625
  /* The proposal bar */
626
626
  .hx-proposal-bar { max-height: 50dvh; overflow-y: auto; padding: 0 var(--corn-space-4) var(--corn-space-3); }
627
- .hx-proposal-bar[data-sheet-state="peek"] > :not(.hx-sheet-handle):not(#proposal-message):not(#proposal-body),
627
+ .hx-proposal-bar[data-sheet-state="peek"] > :not(.hx-sheet-handle):not(#proposal-message):not(#proposal-ways):not(#proposal-body),
628
628
  .hx-proposal-bar[data-sheet-state="peek"] #proposal-body > :not(.hx-proposal-head),
629
- .hx-proposal-bar[data-sheet-state="peek"] .hx-proposal-head > :is(.hx-proposal-tools, .hx-proposal-more, .hx-proposal-more-menu, .hx-review) { display: none; }
629
+ .hx-proposal-bar[data-sheet-state="peek"] .hx-proposal-head > :is(.hx-proposal-tools, .hx-proposal-more, .hx-proposal-more-menu) { display: none; }
630
+ .hx-proposal-bar[data-sheet-state="peek"] .hx-review > :not([data-review-hint]):not([data-review-msg]) { display: none; } /* the peek keeps the reason Approve is off, and a refusal */
630
631
  .hx-proposal-bar[data-sheet-state="expanded"] .hx-scenarios, .hx-proposal-bar[data-sheet-state="expanded"] .hx-proposal-changes, .hx-proposal-bar[data-sheet-state="expanded"] .hx-whatif-panel { max-height: none; overflow: visible; }
631
632
 
632
633
  /* The scenario player: the title, then the step counter and its text on two lines */
633
634
  .hx-player { max-height: 50dvh; overflow: hidden; gap: var(--corn-space-2); padding: 0 var(--corn-space-4) var(--corn-space-4); --sheet-pb: var(--corn-space-4); }
634
635
  .hx-player[data-sheet-state="expanded"] { overflow-y: auto; }
635
- .hx-player[data-sheet-state="peek"] > :not(.hx-sheet-handle):not(.hx-player-head):not(.hx-player-text):not(.hx-player-track) { display: none; }
636
+ .hx-player[data-sheet-state="peek"] > :not(.hx-sheet-handle):not(.hx-player-head):not(.hx-player-text):not(.hx-player-controls):not(.hx-player-track) { display: none; } /* Previous, Pause and Next stay in the peek */
636
637
  .hx-player[data-sheet-state="peek"] .hx-player-text { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; min-height: 0; overflow: hidden; font-size: var(--corn-text-md); }
637
638
 
638
639
  /* The node panel: its title and type until expanded */
@@ -1004,3 +1005,51 @@ a.hx-forge-row:hover, button.hx-forge-row:hover { background: var(--corn-surface
1004
1005
  .hx-more[hidden] { display: none; }
1005
1006
  .hx-more-btn { display: block; margin-top: var(--corn-space-1); min-height: 0; padding: 0; font-size: var(--corn-text-sm); }
1006
1007
  @media (max-width: 767px) { .hx-more-btn { min-height: 44px; } }
1008
+
1009
+ /* ---- the review flow, 0.34 design review (explorer/proposal.js, review.js, scenario-ui.js) -----------------------------
1010
+ F08 the source chip on the bar; F11 the player's controls in a phone peek; F14 the note above the keyboard; F15 the reason
1011
+ Approve is off in a peek; F16 the ways on from a bad link; F21 reflow at 400% zoom and with text spacing raised. */
1012
+ .hx-proposal-source { display: inline-flex; align-items: center; min-width: 0; max-width: 100%; padding: calc(var(--corn-space-1) / 2) var(--corn-space-3); border: var(--corn-border) solid var(--corn-line); border-radius: var(--corn-radius-pill); background: var(--corn-surface-2); color: var(--corn-text-2); font-size: var(--corn-text-xs); line-height: 1.4; text-decoration: none; overflow-wrap: anywhere; }
1013
+ .hx-proposal-source[hidden] { display: none; }
1014
+ a.hx-proposal-source { min-height: 24px; } /* a link: at least the WCAG 2.5.8 target (44px on a phone, below) */
1015
+ a.hx-proposal-source:hover { color: var(--corn-text); text-decoration: underline; }
1016
+ a.hx-proposal-source:focus-visible { outline: var(--corn-focus-width) solid var(--corn-focus); outline-offset: 2px; }
1017
+ .hx-proposal-source[data-corn-state="draft"] { border-color: color-mix(in srgb, var(--corn-changed) 50%, transparent); }
1018
+ .hx-proposal-ways { display: flex; flex-wrap: wrap; gap: var(--corn-space-2) var(--corn-space-3); margin-top: var(--corn-space-3); }
1019
+ .hx-proposal-ways[hidden] { display: none; }
1020
+ .hx-proposal-ways .hx-btn { height: auto; min-height: 32px; padding: var(--corn-space-1) var(--corn-space-4); white-space: normal; text-align: left; }
1021
+ .hx-btn[aria-disabled="true"] { opacity: 0.6; cursor: progress; } /* a review being posted: the button keeps the focus */
1022
+
1023
+ @media (max-width: 767px) {
1024
+ .hx-proposal-source { grid-column: 1 / -1; order: 1; justify-self: start; }
1025
+ .hx-player-controls .hx-btn { min-height: 44px; padding: 0 var(--corn-space-2); white-space: nowrap; }
1026
+ .hx-proposal-ways .hx-btn, a.hx-proposal-source { min-height: 44px; } /* targets a thumb can hit */
1027
+ .hx-proposal-source { padding: 0; border: 0; border-radius: 0; background: none; } /* a line of the sheet, not a pill 44px tall */
1028
+ a.hx-proposal-source { text-decoration: underline; text-underline-offset: 3px; }
1029
+ .hx-player-controls { gap: var(--corn-space-2); }
1030
+ /* While a scenario plays the proposal sheet folds to its title and counts: the player needs the room */
1031
+ .hx-dock:has(> .hx-player) .hx-proposal-bar[data-sheet-state="peek"] .hx-proposal-actions { display: none; }
1032
+ /* The note open: the field, Cancel and the send button are all there is, so all of them stay above the keyboard */
1033
+ .hx-proposal-bar:has(.hx-review-form:not([hidden])) :is(.hx-proposal-name, .hx-proposal-source, .hx-proposal-counts, .hx-proposal-tools, .hx-proposal-more, .hx-review-status, .hx-review-line) { display: none; }
1034
+ .hx-proposal-bar:has(.hx-review-form:not([hidden])) .hx-proposal-actions { order: 4; grid-template-columns: 1fr; }
1035
+ .hx-proposal-bar:has(.hx-review-form:not([hidden])) .hx-proposal-actions .hx-btn--approve { display: none; }
1036
+ /* Reflow: nothing is wider than the sheet, and long words and counts wrap instead of being cut */
1037
+ .hx-proposal-bar { overflow-x: hidden; overflow-wrap: anywhere; }
1038
+ .hx-proposal-head { grid-template-columns: minmax(0, 1fr) auto; }
1039
+ .hx-proposal-chip { flex-wrap: wrap; max-width: 100%; white-space: normal; text-align: left; }
1040
+ .hx-proposal-counts { min-width: 0; }
1041
+ }
1042
+ /* A short window (400% zoom is 225px tall): an open sheet may take the window, and the node panel's title wraps */
1043
+ @media (max-width: 767px) and (max-height: 480px) {
1044
+ .hx-proposal-bar[data-sheet-state="expanded"], .hx-player[data-sheet-state="expanded"] { max-height: calc(100dvh - var(--corn-space-3)); }
1045
+ .hx-drawer[data-sheet-state="peek"] .hx-drawer-title { overflow: visible; text-overflow: clip; white-space: normal; }
1046
+ }
1047
+
1048
+ /* Search with no match (F24): one line under the field, a polite live region. Empty it takes no room. */
1049
+ .hx-search { position: relative; }
1050
+ .hx-search-status { position: absolute; top: calc(100% + var(--corn-space-2)); left: 0; right: 0; z-index: 40; padding: var(--corn-space-2) var(--corn-space-3); border-radius: var(--corn-radius-sm); border: var(--corn-border) solid var(--corn-line); background: var(--corn-surface-2); color: var(--corn-text); font-size: var(--corn-text-sm); overflow-wrap: anywhere; }
1051
+ .hx-search-status:empty { display: none; }
1052
+ .hx-mobile-search .hx-search-status { top: calc(100% - var(--corn-space-1)); left: var(--corn-space-3); right: var(--corn-space-3); }
1053
+
1054
+ /* The node panel's facts break at word boundaries only (F60): "hook" is never "hoo / k". A long path or name still wraps, at its slashes and dashes, and only as a last resort anywhere. */
1055
+ .hx-fact-v { overflow-wrap: break-word; word-break: normal; }
@@ -88,7 +88,7 @@ import {
88
88
  threadsUrl, threadUrl, issueUrl, IDEAS_URL, threadKindWords, threadMeta, litForThread, mentionsIndex, ideaRequest, ideaWords,
89
89
  } from './forge-panel-model.js';
90
90
  import { cornStateAttr } from './corn-state.js';
91
- import { proposalListing, onProposalListing, loadProposalList } from './proposal.js';
91
+ import { proposalListing, onProposalListing, loadProposalList, hooks as proposalHooks } from './proposal.js';
92
92
  import { specRowHtml } from './proposal-model.js';
93
93
  import { t } from './strings.js';
94
94
 
@@ -2213,6 +2213,7 @@ export function initForgePanel(config, opts = {}) {
2213
2213
  const panel = $('forge-panel');
2214
2214
  if (!config || !config.forge || !config.signIn || !panel) return false;
2215
2215
  ui.config = config;
2216
+ proposalHooks.openSpecs = () => openForge({ tab: 'specs' }); // a bad proposal link's way on
2216
2217
  if (opts.clock) now = opts.clock;
2217
2218
  for (const toggle of document.querySelectorAll('[data-action="toggle-forge"]')) toggle.hidden = false;
2218
2219
  panel.hidden = false;
@@ -116,6 +116,7 @@
116
116
  <svg class="hx-search-icon" viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" aria-hidden="true" focusable="false"><circle cx="7" cy="7" r="4.5" /><path d="M10.5 10.5L14 14" /></svg>
117
117
  <input type="text" id="node-search" class="hx-search-input" placeholder="Search..." data-corn-string-placeholder="searchPlaceholder" aria-label="Search nodes" aria-keyshortcuts="/" data-corn="search-input" />
118
118
  <kbd class="hx-kbd" aria-hidden="true">/</kbd>
119
+ <div id="search-status" class="hx-search-status" role="status" aria-live="polite" data-corn="search-status"></div>
119
120
  </div>
120
121
 
121
122
  <!-- The Work toggle (explorer/forge-panel.js): opens the Work panel; shown only when the config names a forge -->
@@ -174,6 +175,7 @@
174
175
  <input type="text" id="mobile-node-search" class="hx-input hx-input--wide" placeholder="Search nodes, apps, components..." aria-label="Search nodes" data-corn="search-input" />
175
176
  <button type="button" class="hx-textbtn" data-action="clear-search" aria-label="Clear search" data-corn-kind="quiet">✕</button>
176
177
  <button type="button" class="hx-textbtn" data-action="close-mobile-search" data-corn-kind="quiet">Cancel</button>
178
+ <div id="mobile-search-status" class="hx-search-status" role="status" aria-live="polite" data-corn="search-status"></div>
177
179
  </div>
178
180
 
179
181
  <!-- The map -->
@@ -193,9 +195,11 @@
193
195
  <!-- The open proposal, a toolbar: title, counts, Before / Diff / After, Play, Edit, Send back, Approve, ⋯ (proposal.js, review.js, whatif.js, scenario-ui.js) -->
194
196
  <section id="proposal-bar" class="hx-proposal-bar glass" aria-label="Open proposal" hidden data-corn="proposal-bar">
195
197
  <p id="proposal-message" class="hx-proposal-message" role="status" hidden></p>
198
+ <div id="proposal-ways" class="hx-proposal-ways" role="group" aria-label="Ways on" data-corn="proposal-ways" hidden></div>
196
199
  <div id="proposal-body">
197
200
  <div class="hx-proposal-head" role="group" aria-label="Proposal actions">
198
201
  <strong id="proposal-title" class="hx-proposal-name"></strong>
202
+ <a id="proposal-source" class="hx-proposal-source" data-corn="proposal-source" hidden></a>
199
203
  <div class="hx-proposal-counts">
200
204
  <button type="button" id="proposal-chip" class="hx-proposal-chip" data-action="toggle-proposal-changes" aria-expanded="false"></button>
201
205
  <button type="button" id="proposal-mode" class="hx-proposal-mode" data-action="toggle-proposal-mode" data-peek-ok aria-expanded="false" aria-controls="proposal-seg" title="Before, Diff or After"></button>
package/explorer/input.js CHANGED
@@ -13,7 +13,7 @@
13
13
  */
14
14
 
15
15
  import { state, touchScene } from './state.js';
16
- import { render, getSpatialIndex, queueFrameWork, screenToWorld } from './render.js';
16
+ import { render, getSpatialIndex, queueFrameWork, screenToWorld, getMinZoom } from './render.js';
17
17
  import { saveFreeformPositions } from './layout.js';
18
18
  import { selectNode, closeDrawer } from './panels.js';
19
19
  import { hitTestScreen } from './spatial.js';
@@ -98,7 +98,7 @@ function onPointerDown(e) {
98
98
  /** One frame's worth of pointer movement: the pinch, the node being dragged, or the pan, from the latest position */
99
99
  function applyMoves() {
100
100
  if (pendingPinch && pinch) {
101
- Object.assign(state.camera, pinchCamera(pinch, pendingPinch.dist, pendingPinch.mid));
101
+ Object.assign(state.camera, pinchCamera(pinch, pendingPinch.dist, pendingPinch.mid, getMinZoom()));
102
102
  }
103
103
  pendingPinch = null;
104
104
 
@@ -210,7 +210,7 @@ export function bindCanvasInput() {
210
210
  canvas.addEventListener('wheel', (e) => {
211
211
  e.preventDefault();
212
212
  const p = getPointerPos(e);
213
- Object.assign(state.camera, zoomAbout(state.camera, e.deltaY < 0 ? 1.12 : 0.88, p.x, p.y));
213
+ Object.assign(state.camera, zoomAbout(state.camera, e.deltaY < 0 ? 1.12 : 0.88, p.x, p.y, getMinZoom()));
214
214
  render(); // a camera change is cheap; the draw is one per frame however many wheel events arrive
215
215
  }, { passive: false });
216
216
  }
@@ -18,7 +18,7 @@
18
18
  */
19
19
 
20
20
  import { state, touchScene } from './state.js';
21
- import { render, fitGraphToViewport, fitPadding, isNodeVisible } from './render.js';
21
+ import { render, fitGraphToViewport, fitPadding, isNodeVisible, getMinZoom } from './render.js';
22
22
  import { zoomAbout } from './camera.js';
23
23
  import { selectNode, closeDrawer } from './panels.js';
24
24
  import { saveFreeformPositions } from './layout.js';
@@ -99,7 +99,7 @@ function onMapKey(e) {
99
99
  render();
100
100
  break;
101
101
  case 'zoom':
102
- Object.assign(camera, zoomAbout(camera, action.factor, width / 2, height / 2));
102
+ Object.assign(camera, zoomAbout(camera, action.factor, width / 2, height / 2, getMinZoom()));
103
103
  render();
104
104
  announce(K.zoomWords(camera.zoom));
105
105
  break;
@@ -6,7 +6,7 @@
6
6
  * two layers by their kind (spec 0031): Cloud, and the Public web; the Cloud legend says what a call's `when` looks like.
7
7
  */
8
8
 
9
- import { state, touchScene } from './state.js';
9
+ import { state, touchScene, escHtml } from './state.js';
10
10
  import { render, ensureFlowLoop } from './render.js';
11
11
  import { renderFlowLegend } from './flows.js';
12
12
  import { layerOf } from './live-model.js';
@@ -23,6 +23,8 @@ export const LAYER_DEFS = [
23
23
  { key: 'token', label: 'Design Tokens', color: '#ec4899', desc: 'Pollen CSS' },
24
24
  { key: 'tool', label: 'Dev Tools', color: '#f43f5e', desc: 'Utilities' },
25
25
  { key: 'flow', label: 'Data Flow', color: '#fb923c', desc: 'Tiers & sync' },
26
+ { key: 'core', label: 'Core', color: '#14b8a6', desc: 'The shared core: what the apps and packages are built on. Shows with Packages or Atoms' },
27
+ { key: 'store', label: 'Stores', color: '#fb923c', desc: 'Storage tiers and the ends of the data flows. Shows with Data Flow' },
26
28
  { key: 'table', label: 'Tables', color: '#fde047', desc: 'SQLite tables, reads & writes' },
27
29
  { key: 'rom', label: 'ROM', color: '#f0abfc', desc: 'Render on Mutation' },
28
30
  { key: 'service', label: 'Services', color: '#84cc16', desc: 'API jobs, webhooks and hooks' },
@@ -62,12 +64,32 @@ export function closeLegendMenu() {
62
64
  setLegendMenu(false);
63
65
  }
64
66
 
65
- /** The chip says how many layers are on: " · 13 of 20" */
67
+ /** The key of the row a node is under (the Layers menu has a row for every type on the map) */
68
+ const rowKey = (n) => (n.type === 'external' ? externalLayer(n) : layerOf(n.type));
69
+
70
+ /**
71
+ * The rows: the defined ones, and one more for any node type on this map that none of them covers (a type a plugin or
72
+ * a newer sync adds), so every type present can be turned off. `root` is always shown and has no row.
73
+ */
74
+ function layerRows() {
75
+ const known = new Set(LAYER_DEFS.map((l) => l.key));
76
+ const extra = [];
77
+ state.nodes.forEach((n) => {
78
+ const key = rowKey(n);
79
+ if (key === 'root' || known.has(key)) return;
80
+ known.add(key);
81
+ extra.push({ key, label: key.charAt(0).toUpperCase() + key.slice(1), color: '#94a3b8', desc: `Nodes of the type ${key}` });
82
+ });
83
+ return [...LAYER_DEFS, ...extra];
84
+ }
85
+
86
+ /** The chip says how many layers are on: " · 13 of 20". An overlay (Runs in flight) is not a layer: it is not counted */
66
87
  function paintCount() {
67
88
  const el = document.getElementById('layers-count');
68
89
  if (!el) return;
69
- const on = LAYER_DEFS.filter((l) => state.activeLayers[l.key] !== false).length;
70
- el.textContent = ` · ${on} of ${LAYER_DEFS.length}`;
90
+ const layers = layerRows().filter((l) => !l.overlay);
91
+ const on = layers.filter((l) => state.activeLayers[l.key] !== false).length;
92
+ el.textContent = ` · ${on} of ${layers.length}`;
71
93
  }
72
94
 
73
95
  export function renderLayerToggles() {
@@ -75,22 +97,24 @@ export function renderLayerToggles() {
75
97
  const container = document.getElementById('layer-toggles-container');
76
98
  if (!container) return;
77
99
 
100
+ // Nodes by row. Data Flow has no nodes of its own: it counts its links, and says so; Runs in flight counts runs
78
101
  const counts = {};
79
- state.nodes.forEach((n) => { const key = n.type === 'external' ? externalLayer(n) : layerOf(n.type); counts[key] = (counts[key] || 0) + 1; });
102
+ state.nodes.forEach((n) => { const key = rowKey(n); counts[key] = (counts[key] || 0) + 1; });
80
103
  counts.flow = state.edges.filter((e) => e.kind === 'flow').length;
81
104
  counts.runs = state.runsMap ? state.runsMap.flight.size : 0;
105
+ const unit = { flow: (n) => `${n} ${n === 1 ? 'link' : 'links'}`, runs: (n) => `${n} in flight` };
82
106
 
83
- container.innerHTML = LAYER_DEFS.map((layer) => {
107
+ container.innerHTML = layerRows().map((layer) => {
84
108
  const on = state.activeLayers[layer.key] !== false;
85
109
  const color = themed(layer.color, state.theme); // the dot is the colour the map draws on this ground
86
110
  return `
87
- <button type="button" class="hx-toggle-row${on ? '' : ' is-off'}" data-action="toggle-layer" data-layer="${layer.key}" aria-pressed="${on}" title="${layer.desc}" data-corn="row">
111
+ <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">
88
112
  <span class="hx-toggle-label">
89
113
  <span class="hx-dot" style="background-color: ${color}; box-shadow: ${on && state.theme !== 'light' ? `0 0 8px ${color}90` : 'none'}"></span>
90
- <span class="hx-toggle-name">${layer.label}</span>${layer.live ? '<span class="hx-live-tag">live</span>' : ''}
114
+ <span class="hx-toggle-name">${escHtml(layer.label)}</span>${layer.live ? '<span class="hx-live-tag">live</span>' : ''}
91
115
  </span>
92
116
  <span class="hx-toggle-meta">
93
- <span class="hx-count">${counts[layer.key] || 0}</span>
117
+ <span class="hx-count">${(unit[layer.key] || String)(counts[layer.key] || 0)}</span>
94
118
  <span class="hx-tick">${on ? '✓' : '—'}</span>
95
119
  </span>
96
120
  </button>`;
@@ -83,6 +83,68 @@ function ringPack(items, { first = 110, gap = 76, spacing = 90 } = {}) {
83
83
  return { offsets, radii };
84
84
  }
85
85
 
86
+ /**
87
+ * A cluster's whole pack: `children` in rings around the centre, and a child that has children of its own (a store
88
+ * owning 46 outside services) gets its own rings, placed on an outer ring of this cluster with room for them.
89
+ * `kidsOf(node)` says who hangs under a node. Returns `{ children, offsets, radii, subs, extent }`: `subs[i]` is the
90
+ * child i's own pack (or null), `extent` how far the whole thing reaches from the centre.
91
+ */
92
+ function packTree(children, kidsOf, spacingOf, byOrder, seen = new Set()) {
93
+ const withSub = [];
94
+ const plain = [];
95
+ children.forEach((c) => {
96
+ const kids = seen.has(c.id) ? [] : kidsOf(c);
97
+ if (!kids.length) { plain.push(c); return; }
98
+ seen.add(c.id);
99
+ const sub = packTree(kids.sort(byOrder), kidsOf, spacingOf, byOrder, seen);
100
+ withSub.push({ c, sub, fp: sub.extent });
101
+ });
102
+ withSub.sort((a, b) => b.fp - a.fp);
103
+ const pack = ringPack(plain, { spacing: spacingOf(children) });
104
+ const out = {
105
+ children: [...plain], offsets: [...pack.offsets], radii: pack.radii, subs: plain.map(() => null),
106
+ extent: pack.radii.length ? pack.radii[pack.radii.length - 1] + 40 : 0,
107
+ };
108
+ if (withSub.length) {
109
+ const lastR = pack.radii.length ? pack.radii[pack.radii.length - 1] : 0;
110
+ const fpMax = withSub[0].fp;
111
+ const arc = withSub.reduce((sum, w) => sum + 2 * w.fp + 30, 0);
112
+ // Each takes arc in proportion to its size; two of them are a chord apart, not an arc, so the ring is as wide as
113
+ // the closest pair needs (for three or more large ones, more than the arc says)
114
+ const mids = [];
115
+ let a = -Math.PI / 2;
116
+ withSub.forEach((w) => { const share = ((2 * w.fp + 30) / arc) * Math.PI * 2; mids.push(a + share / 2); a += share; });
117
+ let r = Math.max(110, lastR + fpMax + 40, arc / (2 * Math.PI));
118
+ for (let i = 0; i < withSub.length; i++) {
119
+ for (let j = i + 1; j < withSub.length; j++) {
120
+ const half = Math.sin(Math.abs(mids[j] - mids[i]) / 2);
121
+ if (half > 1e-6) r = Math.max(r, (withSub[i].fp + withSub[j].fp + 30) / (2 * half));
122
+ }
123
+ }
124
+ withSub.forEach((w, i) => {
125
+ out.children.push(w.c);
126
+ out.offsets.push({ x: Math.cos(mids[i]) * r, y: Math.sin(mids[i]) * r });
127
+ out.subs.push(w.sub);
128
+ });
129
+ out.bigRadius = r;
130
+ out.extent = Math.max(out.extent, r + fpMax);
131
+ }
132
+ return out;
133
+ }
134
+
135
+ /** Puts a pack's children (and theirs) around (ox, oy); a child's own rings are added to `clusters` */
136
+ function placePack(pack, ox, oy, clusters) {
137
+ pack.children.forEach((c, i) => {
138
+ c.x = ox + pack.offsets[i].x;
139
+ c.y = oy + pack.offsets[i].y;
140
+ const sub = pack.subs[i];
141
+ if (sub) {
142
+ clusters.push({ x: c.x, y: c.y, radii: sub.radii });
143
+ placePack(sub, c.x, c.y, clusters);
144
+ }
145
+ });
146
+ }
147
+
86
148
  export function computeOrbitalLayout() {
87
149
  touchScene(); // positions and rings change
88
150
  const { nodes, edges } = state;
@@ -90,9 +152,19 @@ export function computeOrbitalLayout() {
90
152
  state.rings = { rings: [], clusters: [] };
91
153
  const LAYOUT = state.rings;
92
154
 
155
+ const ids = new Set(nodes.map((n) => n.id));
93
156
  const parentMap = {};
94
157
  edges.forEach((e) => {
95
- if (!e.dashed && !e.kind && e.from && e.to && !parentMap[e.to]) parentMap[e.to] = e.from;
158
+ // A parent that is not on the map (an edge a proposal left behind) is no parent: the node would sit on the centre
159
+ if (!e.dashed && !e.kind && e.from && e.to && ids.has(e.from) && e.from !== e.to && !parentMap[e.to]) parentMap[e.to] = e.from;
160
+ });
161
+ // Nor is a parent that is its own ancestor: the first node of a loop loses its parent, so the loop hangs from it
162
+ nodes.forEach((n) => {
163
+ const path = new Set([n.id]);
164
+ for (let p = parentMap[n.id]; p; p = parentMap[p]) {
165
+ if (path.has(p)) { delete parentMap[p]; break; }
166
+ path.add(p);
167
+ }
96
168
  });
97
169
 
98
170
  // topology.json stores no positions; a node the passes below do not place starts at the centre
@@ -102,11 +174,18 @@ export function computeOrbitalLayout() {
102
174
 
103
175
  const isData = (n) => DATA_TYPES.includes(n.type);
104
176
  const hasChildren = new Set(Object.values(parentMap));
105
- // A data store with tables of its own is a cluster like an app; other data rings the root
177
+ const parentsOfNonData = new Set(nodes.filter((k) => parentMap[k.id] && !isData(k)).map((k) => parentMap[k.id]));
178
+ // A data store with children of its own (tables, outside services) is a cluster like an app; other data rings the root
179
+ // and so is any node with no parent but children of its own (its children need somewhere to go)
106
180
  const isHub = (n) => n.id !== 'root' && (isData(n)
107
- ? n.type === 'store' && hasChildren.has(n.id) && !parentMap[n.id]
108
- : parentMap[n.id] === 'root' || (!parentMap[n.id] && ['app', 'pkg', 'tool', 'external', 'stack'].includes(n.type)));
109
- const hubs = nodes.filter(isHub);
181
+ ? hasChildren.has(n.id) && (!parentMap[n.id] || parentMap[n.id] === 'root')
182
+ && (n.type === 'store' || parentsOfNonData.has(n.id))
183
+ : parentMap[n.id] === 'root' || (!parentMap[n.id] && (hasChildren.has(n.id) || ['app', 'pkg', 'tool', 'external', 'stack'].includes(n.type))));
184
+ const firstHubs = new Set(nodes.filter(isHub).map((h) => h.id));
185
+ // A data node that would ring the root (its parent is no hub) but has other nodes under it is a cluster too: the
186
+ // data ring has no room for them
187
+ const hubs = nodes.filter((n) => firstHubs.has(n.id)
188
+ || (n.id !== 'root' && isData(n) && parentsOfNonData.has(n.id) && !firstHubs.has(parentMap[n.id])));
110
189
  const hubIds = new Set(hubs.map((h) => h.id));
111
190
  const typeRank = (n) => { const i = CHILD_TYPE_ORDER.indexOf(n.type); return i < 0 ? 99 : i; };
112
191
  const byTypeThenLabel = (a, b) => typeRank(a) - typeRank(b) || String(a.label).localeCompare(String(b.label));
@@ -124,15 +203,15 @@ export function computeOrbitalLayout() {
124
203
  const coreExtent = data.length ? dataR + 50 : 60;
125
204
  if (data.length) LAYOUT.rings.push({ x: 0, y: 0, r: dataR });
126
205
 
127
- // 2. Pack each hub's children (relative to the hub)
206
+ // 2. Pack each hub's children (relative to the hub). A child with children of its own (a store that owns the
207
+ // outside services) gets rings of its own, and they count in the cluster's extent.
208
+ const kidsOf = (n) => (n.id === 'root' ? [] : nodes.filter((k) => parentMap[k.id] === n.id && !hubIds.has(k.id) && !isData(k) && k.id !== 'root'));
209
+ const spacingOf = (list) => Math.min(170, Math.max(84, ...list.map((c) => labelWidth(c) * 0.8 + 26)));
128
210
  const packs = new Map();
129
211
  hubs.forEach((hub) => {
130
212
  const children = nodes.filter((n) => parentMap[n.id] === hub.id && !hubIds.has(n.id)).sort(byTypeThenLabel);
131
213
  if (!children.length) return;
132
- const spacing = Math.min(170, Math.max(84, ...children.map((c) => labelWidth(c) * 0.8 + 26)));
133
- const pack = ringPack(children, { spacing });
134
- const extent = pack.radii[pack.radii.length - 1] + 40;
135
- packs.set(hub.id, { children, ...pack, extent });
214
+ packs.set(hub.id, packTree(children, kidsOf, spacingOf, byTypeThenLabel, new Set([hub.id])));
136
215
  });
137
216
 
138
217
  // 3. Hubs with children around the core, arc proportional to cluster size
@@ -143,19 +222,21 @@ export function computeOrbitalLayout() {
143
222
  const hubR = Math.max(coreExtent + maxExtent + GAP, need / (2 * Math.PI));
144
223
  let angle = -Math.PI / 2;
145
224
  big.forEach((hub) => {
146
- const { extent, children, offsets, radii } = packs.get(hub.id);
147
- const share = ((2 * extent + GAP) / need) * Math.PI * 2;
225
+ const pack = packs.get(hub.id);
226
+ const share = ((2 * pack.extent + GAP) / need) * Math.PI * 2;
148
227
  const a = angle + share / 2;
149
228
  hub.x = Math.cos(a) * hubR;
150
229
  hub.y = Math.sin(a) * hubR;
151
- children.forEach((c, i) => { c.x = hub.x + offsets[i].x; c.y = hub.y + offsets[i].y; });
152
- LAYOUT.clusters.push({ x: hub.x, y: hub.y, radii });
230
+ LAYOUT.clusters.push({ x: hub.x, y: hub.y, radii: pack.radii });
231
+ placePack(pack, hub.x, hub.y, LAYOUT.clusters);
153
232
  angle += share;
154
233
  });
155
234
  if (big.length) LAYOUT.rings.push({ x: 0, y: 0, r: hubR });
156
235
 
157
- // 4. Childless hubs on an outer ring
158
- const leaves = hubs.filter((h) => !packs.has(h.id)).sort(byTypeThenLabel);
236
+ // 4. Childless hubs on an outer ring, and with them any node that has no parent and is none of the above
237
+ // (it would otherwise sit on the centre, under whatever else is there)
238
+ const homeless = nodes.filter((n) => n.id !== 'root' && !parentMap[n.id] && !isData(n) && !hubIds.has(n.id));
239
+ const leaves = [...hubs.filter((h) => !packs.has(h.id)), ...homeless].sort(byTypeThenLabel);
159
240
  const leafSpacing = Math.max(120, ...leaves.map((n) => labelWidth(n) + 30));
160
241
  const leafR = Math.max(hubR + maxExtent + 90, (leaves.length * leafSpacing) / (2 * Math.PI));
161
242
  leaves.forEach((n, i) => {
@@ -165,13 +246,23 @@ export function computeOrbitalLayout() {
165
246
  });
166
247
  if (leaves.length) LAYOUT.rings.push({ x: 0, y: 0, r: leafR });
167
248
 
168
- // Anything left (a child of a non-hub) sits just outside its parent
249
+ // Anything still on the centre is a child of a node the passes above did not pack (a child of a data node on the
250
+ // core ring, say): it goes in rings around its parent, with its own children in rings around it, never on one point
251
+ const placedAt = (n) => n.id === 'root' || n.x !== 0 || n.y !== 0;
252
+ const stuckUnder = new Map();
169
253
  nodes.forEach((n) => {
170
- const p = parentMap[n.id] && nodes.find((x) => x.id === parentMap[n.id]);
171
- if (!p || hubIds.has(p.id) || p.id === 'root' || isData(n) || hubIds.has(n.id)) return;
172
- const d = Math.hypot(p.x, p.y) || 1;
173
- n.x = p.x + (p.x / d) * 70;
174
- n.y = p.y + (p.y / d) * 70;
254
+ const pid = parentMap[n.id];
255
+ if (placedAt(n) || !pid) return;
256
+ (stuckUnder.get(pid) || stuckUnder.set(pid, []).get(pid)).push(n);
257
+ });
258
+ const byId = new Map(nodes.map((n) => [n.id, n]));
259
+ stuckUnder.forEach((list, pid) => {
260
+ const p = byId.get(pid);
261
+ if (!p || !placedAt(p)) return; // its parent is stuck too: it is placed with it, in the parent's pack
262
+ if (list.every(placedAt)) return; // placed already, in a pack higher up
263
+ const pack = packTree(list.sort(byTypeThenLabel), kidsOf, spacingOf, byTypeThenLabel, new Set([pid]));
264
+ LAYOUT.clusters.push({ x: p.x, y: p.y, radii: pack.radii });
265
+ placePack(pack, p.x, p.y, LAYOUT.clusters);
175
266
  });
176
267
  }
177
268