@popcorn245/cornfield 0.50.1 → 0.51.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,220 @@
1
+ /**
2
+ * @module explorer/proposal-marks
3
+ *
4
+ * What a proposal's marks do to the map (spec 0012 B2, TOPO-09), the part a map draws with: which nodes and edges each view shows
5
+ * (`showsNode`, `showsEdge`), the mark a scene carries (`markIn`), a changed item as it was (`beforeOf`), what Diff keeps bright and the camera
6
+ * fits (`touchedIds`), and where an added node sits (`placeAddedNodes`, `orderAddedLast`, `pinLanes`). Pure: no DOM, no state.
7
+ *
8
+ * proposal-model.js re-exports all of it, with the bar's, the panel's and the list's words, which only a review and cornfield's page use: a map
9
+ * alone (scene.js, engine/topology.js, layer-model.js) imports this module and so does not carry those (the components' size budget, spec 0011 D11).
10
+ */
11
+
12
+ /**
13
+ * What a marked item IS, under the mark it is drawn with: a what-if `edit` (whatif-model.js) is drawn in violet
14
+ * but is still an addition or a removal (`editOp`), and the views and the layout treat it as one.
15
+ * @returns {'none'|'added'|'changed'|'removed'}
16
+ */
17
+ export const kindOfMark = (item) => (item.mark === 'edit' ? item.editOp || 'none' : item.mark || 'none');
18
+
19
+ /** Whether an item carries a mark (any but none) */
20
+ export const hasMark = (item) => !!item && !!item.mark && item.mark !== 'none';
21
+
22
+ // ---------------------------------------------------------------------------
23
+ // What each view shows
24
+ // ---------------------------------------------------------------------------
25
+
26
+ /** Is this node drawn in `view`? (`view` null = no proposal is open: everything is) */
27
+ export function showsNode(view, node) {
28
+ if (view === 'before') return kindOfMark(node) !== 'added';
29
+ if (view === 'after') return kindOfMark(node) !== 'removed';
30
+ return true;
31
+ }
32
+
33
+ /** Is this edge drawn in `view`? The same rule: Before hides what is added, After what is removed */
34
+ export function showsEdge(view, edge) {
35
+ return showsNode(view, edge);
36
+ }
37
+
38
+ /**
39
+ * The mark a scene carries in `view`: the proposal's own in Diff and none in Before and After; a
40
+ * what-if `edit` is the maintainer's own and shows in all three.
41
+ * @returns {'none'|'added'|'changed'|'removed'|'edit'}
42
+ */
43
+ export function markIn(view, item) {
44
+ const mark = item.mark || 'none';
45
+ if (mark === 'edit') return 'edit';
46
+ return view === 'diff' ? mark : 'none';
47
+ }
48
+
49
+ /**
50
+ * A changed node or edge as it was before the proposal: each field in `before` is put back
51
+ * (`null` there means the item did not have it, so it is dropped). Anything else comes back as it is.
52
+ */
53
+ export function beforeOf(item) {
54
+ if (item.mark !== 'changed' || !item.before) return item;
55
+ const out = { ...item };
56
+ for (const [field, value] of Object.entries(item.before)) {
57
+ if (value === null) delete out[field];
58
+ else out[field] = value;
59
+ }
60
+ return out;
61
+ }
62
+
63
+ /**
64
+ * Which nodes a proposal touches, for dimming and for fitting the camera.
65
+ * - `touched`: nodes with a mark, and both ends of a marked edge: what Diff keeps bright
66
+ * - `near`: `touched` and what they connect to, except the children a touched node owns (a touched
67
+ * app would otherwise bring all its hundreds of pages): what the camera fits
68
+ * @param {{id:string, mark?:string}[]} nodes
69
+ * @param {{from:string, to:string, kind?:string, dashed?:boolean, mark?:string}[]} edges
70
+ */
71
+ export function touchedIds(nodes, edges) {
72
+ const touched = new Set();
73
+ for (const n of nodes) if (hasMark(n)) touched.add(n.id);
74
+ for (const e of edges) if (hasMark(e)) { touched.add(e.from); touched.add(e.to); }
75
+ const near = new Set(touched);
76
+ for (const e of edges) {
77
+ const owns = !e.kind && !e.dashed;
78
+ if (touched.has(e.from) && !(owns && !touched.has(e.to))) near.add(e.to);
79
+ if (touched.has(e.to)) near.add(e.from);
80
+ }
81
+ return { touched, near };
82
+ }
83
+
84
+ // ---------------------------------------------------------------------------
85
+ // Where an added node sits
86
+ // ---------------------------------------------------------------------------
87
+
88
+ /** An ownership edge: a solid line with no kind (the parent → child link) */
89
+ const isOwnership = (e) => !e.kind && !e.dashed;
90
+
91
+ /**
92
+ * Gives every node marked `added` a position, next to the node it hangs off: its parent when it has
93
+ * one, else something it connects to, else a spot on a ring around the centre. Existing nodes never
94
+ * move: the base layout is pinned, which is why the Before view and the Diff view show the same
95
+ * picture. The spot is the first free one on widening rings around the anchor, starting on the side
96
+ * facing away from the centre, where the map has room. Writes `x` and `y`; touches nothing else.
97
+ * @param {{id:string, x:number, y:number, mark?:string}[]} nodes the applied nodes; the existing ones already have x and y
98
+ * @param {{from:string, to:string, kind?:string, dashed?:boolean}[]} edges
99
+ * @param {{gap?: number}} [opts] `gap`: the closest two nodes may sit (world units)
100
+ */
101
+ export function placeAddedNodes(nodes, edges, { gap = 74 } = {}) {
102
+ const byId = new Map(nodes.map((n) => [n.id, n]));
103
+ const placed = nodes.filter((n) => kindOfMark(n) !== 'added');
104
+ const added = nodes.filter((n) => kindOfMark(n) === 'added');
105
+ if (!added.length) return;
106
+ const done = new Set(placed.map((n) => n.id));
107
+
108
+ const anchorOf = (n) => {
109
+ const own = edges.find((e) => isOwnership(e) && e.to === n.id && byId.has(e.from));
110
+ if (own) return own.from;
111
+ const other = edges.find((e) => (e.from === n.id && byId.has(e.to)) || (e.to === n.id && byId.has(e.from)));
112
+ return other ? (other.from === n.id ? other.to : other.from) : null;
113
+ };
114
+
115
+ const free = (x, y) => placed.every((p) => Math.hypot(p.x - x, p.y - y) >= gap);
116
+ const put = (n, ax, ay) => {
117
+ const out = Math.atan2(ay, ax) || -Math.PI / 2; // away from the centre
118
+ const base = ax === 0 && ay === 0 ? -Math.PI / 2 : out;
119
+ let fallback = null;
120
+ for (let r = 96; r <= 96 + 40 * 12; r += 40) {
121
+ const steps = Math.max(8, Math.round((2 * Math.PI * r) / gap));
122
+ for (let k = 0; k < steps; k++) {
123
+ // 0, +1, -1, +2, -2 ... steps either side of the outward direction
124
+ const turn = Math.ceil(k / 2) * (k % 2 ? 1 : -1) * ((2 * Math.PI) / steps);
125
+ const x = ax + Math.cos(base + turn) * r;
126
+ const y = ay + Math.sin(base + turn) * r;
127
+ if (!fallback) fallback = { x, y };
128
+ if (free(x, y)) { n.x = x; n.y = y; return; }
129
+ }
130
+ }
131
+ n.x = fallback.x; n.y = fallback.y;
132
+ };
133
+
134
+ // Parents first: an added node can hang off another added node, in any order in the file
135
+ let pending = added.slice();
136
+ for (let pass = 0; pass <= added.length && pending.length; pass++) {
137
+ const next = [];
138
+ for (const n of pending) {
139
+ const anchor = byId.get(anchorOf(n));
140
+ if (anchor && done.has(anchor.id)) {
141
+ put(n, anchor.x, anchor.y);
142
+ placed.push(n);
143
+ done.add(n.id);
144
+ } else {
145
+ next.push(n); // its anchor is another added node not placed yet, or it has none (settled below)
146
+ }
147
+ }
148
+ if (next.length === pending.length) break;
149
+ pending = next;
150
+ }
151
+ // No anchor, or an anchor that never got a place: a spot beside the centre
152
+ for (const n of pending) {
153
+ put(n, 0, 0);
154
+ placed.push(n);
155
+ }
156
+ }
157
+
158
+ /**
159
+ * The data-flow lanes fill a column in order; an added node goes last in its column, so the nodes
160
+ * that were there keep their rows. Reorders each tier's `nodes` in place, stably.
161
+ * @param {{tiers: {nodes: {mark?:string}[]}[]}|null} flow `buildDataFlow` result
162
+ */
163
+ export function orderAddedLast(flow) {
164
+ if (!flow) return;
165
+ for (const tier of flow.tiers) {
166
+ tier.nodes = [...tier.nodes.filter((n) => kindOfMark(n) !== 'added'), ...tier.nodes.filter((n) => kindOfMark(n) === 'added')];
167
+ }
168
+ }
169
+
170
+ /** The distance between two rows of a lane (layout.js `LANE_ROW`) */
171
+ const LANE_ROW = 50;
172
+
173
+ /**
174
+ * The data-flow lanes while a proposal is open: the base map's lane layout is pinned and the added
175
+ * nodes take free cells of their lane, so no node that was there moves (laying the lanes out again
176
+ * would re-flow a whole lane when one node more tips it into another row). An added node goes in the
177
+ * free cells at the foot of its lane's last column, then in new rows below it; `flow.top` moves up
178
+ * so the lane bands still cover them.
179
+ *
180
+ * Writes `x`, `y`, `r` of each existing node from `baseFlow`'s node of the same id, `x` and `y` of each
181
+ * added one, and `flow.headers` / `flow.top`. `flow` is the applied map's flow (`buildDataFlow` over
182
+ * the applied nodes, added nodes last in their tier), `baseFlow` the base map's, already laid out.
183
+ * @param {{tiers: {key:string, nodes: object[]}[], headers?: object[], top?: number}} flow
184
+ * @param {{tiers: {key:string, nodes: object[]}[], headers: object[], top: number}} baseFlow
185
+ * @returns {boolean} false when the lanes cannot be pinned (a tier has nodes now that had none, so it has no column
186
+ * to join): the caller lays the lanes out afresh
187
+ */
188
+ export function pinLanes(flow, baseFlow) {
189
+ const baseTier = new Map(baseFlow.tiers.map((t) => [t.key, t]));
190
+ if (flow.tiers.some((t) => t.nodes.length && !baseTier.get(t.key)?.nodes.length)) return false;
191
+
192
+ // `headers` has one entry per tier that has nodes, in tier order
193
+ const headerOf = new Map(baseFlow.tiers.filter((t) => t.nodes.length).map((t, i) => [t.key, baseFlow.headers[i]]));
194
+ const was = new Map(baseFlow.tiers.flatMap((t) => t.nodes).map((n) => [n.id, n]));
195
+ flow.headers = baseFlow.headers.map((h) => ({ ...h }));
196
+ let top = baseFlow.top;
197
+
198
+ for (const tier of flow.tiers) {
199
+ if (!tier.nodes.length) continue;
200
+ const kept = tier.nodes.filter((n) => was.has(n.id));
201
+ const added = tier.nodes.filter((n) => !was.has(n.id));
202
+ for (const n of kept) { const b = was.get(n.id); n.x = b.x; n.y = b.y; n.r = b.r; }
203
+ if (!added.length) continue;
204
+
205
+ const rows = headerOf.get(tier.key).rows;
206
+ const lastX = Math.max(...kept.map((n) => n.x));
207
+ const rowY = (k) => (k - (rows - 1) / 2) * LANE_ROW;
208
+ const taken = new Set(kept.filter((n) => n.x === lastX).map((n) => Math.round(n.y)));
209
+ let k = 0;
210
+ for (const n of added) {
211
+ while (taken.has(Math.round(rowY(k)))) k++;
212
+ n.x = lastX;
213
+ n.y = rowY(k);
214
+ taken.add(Math.round(n.y));
215
+ top = Math.min(top, -(n.y + 40)); // the bands run from `top` down to `-top + 40`
216
+ }
217
+ }
218
+ flow.top = top;
219
+ return true;
220
+ }
@@ -16,88 +16,23 @@
16
16
  * after the map as it would be: what the proposal removes is hidden, no marks
17
17
  *
18
18
  * Switching the view never moves a node: all three draw the same positions.
19
+ *
20
+ * What a map draws with (the views, the marks, where an added node sits) is proposal-marks.js's, re-exported here: a map alone imports that
21
+ * module and does not carry the bar's, the panel's and the list's words below.
19
22
  */
20
23
 
21
24
  import { escapeHtml as escHtml } from '../core/text.js';
22
25
  import { markStateAttr, stateIconHtml } from './corn-state.js';
23
26
  import { specStateOf, specStateWords, SPEC_STATE_WORDS, SPEC_STATE_CORN } from './waiting-model.js';
27
+ import { hasMark, kindOfMark, showsNode, showsEdge, markIn, beforeOf, touchedIds, placeAddedNodes, orderAddedLast, pinLanes } from './proposal-marks.js';
28
+
29
+ export { kindOfMark, showsNode, showsEdge, markIn, beforeOf, touchedIds, placeAddedNodes, orderAddedLast, pinLanes };
24
30
 
25
31
  export const PROPOSAL_VIEWS = ['before', 'diff', 'after'];
26
32
 
27
33
  /** The marks a proposal puts on the map, in the order the counts chip and the legend list them */
28
34
  export const MARKS = ['added', 'changed', 'removed'];
29
35
 
30
- const hasMark = (item) => !!item && !!item.mark && item.mark !== 'none';
31
-
32
- /**
33
- * What a marked item IS, under the mark it is drawn with: a what-if `edit` (whatif-model.js) is drawn in violet
34
- * but is still an addition or a removal (`editOp`), and the views and the layout treat it as one.
35
- * @returns {'none'|'added'|'changed'|'removed'}
36
- */
37
- export const kindOfMark = (item) => (item.mark === 'edit' ? item.editOp || 'none' : item.mark || 'none');
38
-
39
- // ---------------------------------------------------------------------------
40
- // What each view shows
41
- // ---------------------------------------------------------------------------
42
-
43
- /** Is this node drawn in `view`? (`view` null = no proposal is open: everything is) */
44
- export function showsNode(view, node) {
45
- if (view === 'before') return kindOfMark(node) !== 'added';
46
- if (view === 'after') return kindOfMark(node) !== 'removed';
47
- return true;
48
- }
49
-
50
- /** Is this edge drawn in `view`? The same rule: Before hides what is added, After what is removed */
51
- export function showsEdge(view, edge) {
52
- return showsNode(view, edge);
53
- }
54
-
55
- /**
56
- * The mark a scene carries in `view`: the proposal's own in Diff and none in Before and After; a
57
- * what-if `edit` is the maintainer's own and shows in all three.
58
- * @returns {'none'|'added'|'changed'|'removed'|'edit'}
59
- */
60
- export function markIn(view, item) {
61
- const mark = item.mark || 'none';
62
- if (mark === 'edit') return 'edit';
63
- return view === 'diff' ? mark : 'none';
64
- }
65
-
66
- /**
67
- * A changed node or edge as it was before the proposal: each field in `before` is put back
68
- * (`null` there means the item did not have it, so it is dropped). Anything else comes back as it is.
69
- */
70
- export function beforeOf(item) {
71
- if (item.mark !== 'changed' || !item.before) return item;
72
- const out = { ...item };
73
- for (const [field, value] of Object.entries(item.before)) {
74
- if (value === null) delete out[field];
75
- else out[field] = value;
76
- }
77
- return out;
78
- }
79
-
80
- /**
81
- * Which nodes a proposal touches, for dimming and for fitting the camera.
82
- * - `touched`: nodes with a mark, and both ends of a marked edge: what Diff keeps bright
83
- * - `near`: `touched` and what they connect to, except the children a touched node owns (a touched
84
- * app would otherwise bring all its hundreds of pages): what the camera fits
85
- * @param {{id:string, mark?:string}[]} nodes
86
- * @param {{from:string, to:string, kind?:string, dashed?:boolean, mark?:string}[]} edges
87
- */
88
- export function touchedIds(nodes, edges) {
89
- const touched = new Set();
90
- for (const n of nodes) if (hasMark(n)) touched.add(n.id);
91
- for (const e of edges) if (hasMark(e)) { touched.add(e.from); touched.add(e.to); }
92
- const near = new Set(touched);
93
- for (const e of edges) {
94
- const owns = !e.kind && !e.dashed;
95
- if (touched.has(e.from) && !(owns && !touched.has(e.to))) near.add(e.to);
96
- if (touched.has(e.to)) near.add(e.from);
97
- }
98
- return { touched, near };
99
- }
100
-
101
36
  // ---------------------------------------------------------------------------
102
37
  // The counts chip, the legend, the address
103
38
  // ---------------------------------------------------------------------------
@@ -149,6 +84,22 @@ export const openedWords = (title, counts, view) => `Proposal ${title}: ${barCou
149
84
  export const jumpWords = (markWord, name) => `${name}, ${String(markWord).toLowerCase()}. The map is on it.`;
150
85
 
151
86
  const SLUG = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
87
+ /** The longest name the server takes for a proposal (server/submit-review.js) */
88
+ const MAX_NAME = 200;
89
+
90
+ /**
91
+ * Whether `name` can be a proposal's name: a file name in the proposals folder (what the server's routes take), so it is one path segment and never
92
+ * `.` or `..`: it starts with a letter or a digit and holds only letters, digits, `.`, `_` and `-`. A name that is not one is never asked for.
93
+ * @param {unknown} name
94
+ */
95
+ export const isProposalName = (name) => typeof name === 'string' && name.length <= MAX_NAME && SLUG.test(name);
96
+
97
+ /** What to say of a value that was given as a proposal's name and is not one; shown as text, cut to 60 characters */
98
+ export function notANameWords(raw) {
99
+ const text = String(raw ?? '');
100
+ const shown = text.length > 60 ? `${text.slice(0, 59)}\u2026` : text;
101
+ return shown.trim() ? `\u201c${shown}\u201d is not a proposal's name.` : 'That is not a proposal\'s name.';
102
+ }
152
103
 
153
104
  /**
154
105
  * What `/?proposal=<slug>&source=<where>&proposalView=<view>` asks for, or null when it does not
@@ -385,8 +336,7 @@ export function malformedLinkWords(search) {
385
336
  if (!params.has('proposal')) return null;
386
337
  const raw = params.get('proposal') || '';
387
338
  if (SLUG.test(raw)) return null;
388
- const shown = raw.length > 60 ? `${raw.slice(0, 59)}\u2026` : raw;
389
- return shown.trim() ? `This link does not name a proposal: \u201c${shown}\u201d is not a proposal's name.` : 'This link does not name a proposal.';
339
+ return raw.trim() ? `This link does not name a proposal: ${notANameWords(raw)}` : 'This link does not name a proposal.';
390
340
  }
391
341
 
392
342
  /**
@@ -404,144 +354,6 @@ export function otherCopies(listing, slug, source) {
404
354
  .map((e) => ({ slug: e.slug, source: e.source, label: pullNumberOf(e.source) ? `Open the copy in PR #${pullNumberOf(e.source)}${e.pull && e.pull.draft ? ' (draft)' : ''}` : `Open the copy ${e.source === 'checkout' ? 'in the checkout' : `in worktree ${e.source}`}` }));
405
355
  }
406
356
 
407
- // ---------------------------------------------------------------------------
408
- // Where an added node sits
409
- // ---------------------------------------------------------------------------
410
-
411
- /** An ownership edge: a solid line with no kind (the parent → child link) */
412
- const isOwnership = (e) => !e.kind && !e.dashed;
413
-
414
- /**
415
- * Gives every node marked `added` a position, next to the node it hangs off: its parent when it has
416
- * one, else something it connects to, else a spot on a ring around the centre. Existing nodes never
417
- * move: the base layout is pinned, which is why the Before view and the Diff view show the same
418
- * picture. The spot is the first free one on widening rings around the anchor, starting on the side
419
- * facing away from the centre, where the map has room. Writes `x` and `y`; touches nothing else.
420
- * @param {{id:string, x:number, y:number, mark?:string}[]} nodes the applied nodes; the existing ones already have x and y
421
- * @param {{from:string, to:string, kind?:string, dashed?:boolean}[]} edges
422
- * @param {{gap?: number}} [opts] `gap`: the closest two nodes may sit (world units)
423
- */
424
- export function placeAddedNodes(nodes, edges, { gap = 74 } = {}) {
425
- const byId = new Map(nodes.map((n) => [n.id, n]));
426
- const placed = nodes.filter((n) => kindOfMark(n) !== 'added');
427
- const added = nodes.filter((n) => kindOfMark(n) === 'added');
428
- if (!added.length) return;
429
- const done = new Set(placed.map((n) => n.id));
430
-
431
- const anchorOf = (n) => {
432
- const own = edges.find((e) => isOwnership(e) && e.to === n.id && byId.has(e.from));
433
- if (own) return own.from;
434
- const other = edges.find((e) => (e.from === n.id && byId.has(e.to)) || (e.to === n.id && byId.has(e.from)));
435
- return other ? (other.from === n.id ? other.to : other.from) : null;
436
- };
437
-
438
- const free = (x, y) => placed.every((p) => Math.hypot(p.x - x, p.y - y) >= gap);
439
- const put = (n, ax, ay) => {
440
- const out = Math.atan2(ay, ax) || -Math.PI / 2; // away from the centre
441
- const base = ax === 0 && ay === 0 ? -Math.PI / 2 : out;
442
- let fallback = null;
443
- for (let r = 96; r <= 96 + 40 * 12; r += 40) {
444
- const steps = Math.max(8, Math.round((2 * Math.PI * r) / gap));
445
- for (let k = 0; k < steps; k++) {
446
- // 0, +1, -1, +2, -2 ... steps either side of the outward direction
447
- const turn = Math.ceil(k / 2) * (k % 2 ? 1 : -1) * ((2 * Math.PI) / steps);
448
- const x = ax + Math.cos(base + turn) * r;
449
- const y = ay + Math.sin(base + turn) * r;
450
- if (!fallback) fallback = { x, y };
451
- if (free(x, y)) { n.x = x; n.y = y; return; }
452
- }
453
- }
454
- n.x = fallback.x; n.y = fallback.y;
455
- };
456
-
457
- // Parents first: an added node can hang off another added node, in any order in the file
458
- let pending = added.slice();
459
- for (let pass = 0; pass <= added.length && pending.length; pass++) {
460
- const next = [];
461
- for (const n of pending) {
462
- const anchor = byId.get(anchorOf(n));
463
- if (anchor && done.has(anchor.id)) {
464
- put(n, anchor.x, anchor.y);
465
- placed.push(n);
466
- done.add(n.id);
467
- } else {
468
- next.push(n); // its anchor is another added node not placed yet, or it has none (settled below)
469
- }
470
- }
471
- if (next.length === pending.length) break;
472
- pending = next;
473
- }
474
- // No anchor, or an anchor that never got a place: a spot beside the centre
475
- for (const n of pending) {
476
- put(n, 0, 0);
477
- placed.push(n);
478
- }
479
- }
480
-
481
- /**
482
- * The data-flow lanes fill a column in order; an added node goes last in its column, so the nodes
483
- * that were there keep their rows. Reorders each tier's `nodes` in place, stably.
484
- * @param {{tiers: {nodes: {mark?:string}[]}[]}|null} flow `buildDataFlow` result
485
- */
486
- export function orderAddedLast(flow) {
487
- if (!flow) return;
488
- for (const tier of flow.tiers) {
489
- tier.nodes = [...tier.nodes.filter((n) => kindOfMark(n) !== 'added'), ...tier.nodes.filter((n) => kindOfMark(n) === 'added')];
490
- }
491
- }
492
-
493
- /** The distance between two rows of a lane (layout.js `LANE_ROW`) */
494
- const LANE_ROW = 50;
495
-
496
- /**
497
- * The data-flow lanes while a proposal is open: the base map's lane layout is pinned and the added
498
- * nodes take free cells of their lane, so no node that was there moves (laying the lanes out again
499
- * would re-flow a whole lane when one node more tips it into another row). An added node goes in the
500
- * free cells at the foot of its lane's last column, then in new rows below it; `flow.top` moves up
501
- * so the lane bands still cover them.
502
- *
503
- * Writes `x`, `y`, `r` of each existing node from `baseFlow`'s node of the same id, `x` and `y` of each
504
- * added one, and `flow.headers` / `flow.top`. `flow` is the applied map's flow (`buildDataFlow` over
505
- * the applied nodes, added nodes last in their tier), `baseFlow` the base map's, already laid out.
506
- * @param {{tiers: {key:string, nodes: object[]}[], headers?: object[], top?: number}} flow
507
- * @param {{tiers: {key:string, nodes: object[]}[], headers: object[], top: number}} baseFlow
508
- * @returns {boolean} false when the lanes cannot be pinned (a tier has nodes now that had none, so it has no column
509
- * to join): the caller lays the lanes out afresh
510
- */
511
- export function pinLanes(flow, baseFlow) {
512
- const baseTier = new Map(baseFlow.tiers.map((t) => [t.key, t]));
513
- if (flow.tiers.some((t) => t.nodes.length && !baseTier.get(t.key)?.nodes.length)) return false;
514
-
515
- // `headers` has one entry per tier that has nodes, in tier order
516
- const headerOf = new Map(baseFlow.tiers.filter((t) => t.nodes.length).map((t, i) => [t.key, baseFlow.headers[i]]));
517
- const was = new Map(baseFlow.tiers.flatMap((t) => t.nodes).map((n) => [n.id, n]));
518
- flow.headers = baseFlow.headers.map((h) => ({ ...h }));
519
- let top = baseFlow.top;
520
-
521
- for (const tier of flow.tiers) {
522
- if (!tier.nodes.length) continue;
523
- const kept = tier.nodes.filter((n) => was.has(n.id));
524
- const added = tier.nodes.filter((n) => !was.has(n.id));
525
- for (const n of kept) { const b = was.get(n.id); n.x = b.x; n.y = b.y; n.r = b.r; }
526
- if (!added.length) continue;
527
-
528
- const rows = headerOf.get(tier.key).rows;
529
- const lastX = Math.max(...kept.map((n) => n.x));
530
- const rowY = (k) => (k - (rows - 1) / 2) * LANE_ROW;
531
- const taken = new Set(kept.filter((n) => n.x === lastX).map((n) => Math.round(n.y)));
532
- let k = 0;
533
- for (const n of added) {
534
- while (taken.has(Math.round(rowY(k)))) k++;
535
- n.x = lastX;
536
- n.y = rowY(k);
537
- taken.add(Math.round(n.y));
538
- top = Math.min(top, -(n.y + 40)); // the bands run from `top` down to `-top + 40`
539
- }
540
- }
541
- flow.top = top;
542
- return true;
543
- }
544
-
545
357
  /**
546
358
  * The reviewer's own what-if edits, counted apart from the proposal's (spec 0007 D5): "yours: +1 node, 1 step changed". Never added to the proposal's
547
359
  * numbers, so the reviewer can still tell what the agent proposed. Empty for no edits.
@@ -52,7 +52,8 @@
52
52
  */
53
53
 
54
54
  import { edgeKey } from '../core/proposal.js';
55
- import { frameNodes, allInside, READ_ZOOM, ZOOM_MIN } from './camera.js';
55
+ import { frameNodes, ZOOM_MIN } from './camera.js';
56
+ import { allInside, READ_ZOOM } from './camera-frame.js';
56
57
 
57
58
  export const DEFAULT_STEP_MS = 5000;
58
59
  /** Where the viewer's speed is kept (localStorage); scenario-ui.js reads and writes it */
package/explorer/scene.js CHANGED
@@ -168,9 +168,9 @@
168
168
  */
169
169
 
170
170
  import { flowStyleOf } from './flow-style.js';
171
- import { beforeOf, markIn, showsEdge, showsNode, touchedIds } from './proposal-model.js';
171
+ import { beforeOf, markIn, showsEdge, showsNode, touchedIds } from './proposal-marks.js';
172
172
  import { decorateHouseScene, houseEdgeStyle, houseShowsNode, houseViewEdges } from './house-model.js';
173
- import { paintVerdict } from './check-model.js';
173
+ import { paintVerdict } from './verdict-paint.js';
174
174
  import { externalLayer, whenTicks } from './cloud-model.js';
175
175
  import { greying, lettersOf, projectLayerKey, shownByProposal, layersOf } from './layer-model.js';
176
176
  import { NODE_THEMES, shapeOf } from '../core/schema.js';
@@ -6,21 +6,19 @@
6
6
  * activeSubgraph(selected, edges, opts) the lit set: the node and everything ONE edge away, of any kind (its parent and children
7
7
  * included); `throughChildren` adds the children's neighbours (the wider set every
8
8
  * selection lit before 0.35); `kind` keeps only the lines of that kind
9
- * linesByKind(subgraph) "Calls 12 · Reads 9 · Owns 4": the lit lines counted by kind, in a fixed order
10
9
  * countOffScreen(ids, camera, rect) how many of the lit nodes are outside the part of the map nothing covers
11
10
  * selectionCamera(node, lit, rect, opts) where the camera goes when a selection comes from search, a list, a link or the keyboard:
12
11
  * the node and its lit set framed if that fits at zoom 0.5 or closer, else the node
13
12
  * centred at zoom 1. A click on the map never asks for it (panels.js)
14
13
  *
14
+ * What the node panel says of it (`linesByKind`: "Calls 12 · Reads 9 · Owns 4", `farEnds`, `connectedLine`, `kindPanelWord`) is selection-words.js's.
15
+ *
15
16
  * An edge's `kind` is project data: it only ever selects a word from `KIND_WORDS` or is shown as escaped text; it never builds a
16
17
  * selector or a token name.
17
18
  */
18
19
 
19
20
  import { frameNodes } from './camera.js';
20
21
 
21
- /** The kinds a line is drawn as, in the order the panel lists them */
22
- export const LINE_KINDS = ['ownership', 'usage', 'flow', 'reads', 'writes', 'calls', 'triggers', 'delivers', 'runs-on', 'uses', 'extends'];
23
-
24
22
  /** The words for a kind: the panel's plural ("Calls 12"), and the word on a lit edge ("calls") */
25
23
  export const KIND_WORDS = Object.freeze({
26
24
  ownership: { panel: 'Owns', edge: 'owns' },
@@ -40,8 +38,6 @@ export const KIND_WORDS = Object.freeze({
40
38
  export const edgeKindOf = (e) => e.kind || (e.dashed ? 'usage' : 'ownership');
41
39
  export const edgeKeyOf = (e) => `${e.from}->${e.to}`;
42
40
 
43
- /** A kind's panel word; a kind this table does not know (a project's own) is shown as the text it is */
44
- export const kindPanelWord = (kind) => (Object.hasOwn(KIND_WORDS, kind) ? KIND_WORDS[kind].panel : String(kind));
45
41
  export const kindEdgeWord = (kind) => (Object.hasOwn(KIND_WORDS, kind) ? KIND_WORDS[kind].edge : String(kind));
46
42
 
47
43
  /**
@@ -75,37 +71,6 @@ export function activeSubgraph(selected, edges, { throughChildren = false, kind
75
71
  return { connectedNodeIds, connectedEdgeKeys, childIds, selectedId: id, edges: shown, kinds, kind: filter, throughChildren };
76
72
  }
77
73
 
78
- /**
79
- * The lit lines counted by kind, in LINE_KINDS order (a kind of the project's own after them, by name).
80
- * @param {NonNullable<ReturnType<typeof activeSubgraph>>} sub
81
- * @returns {{kind: string, count: number, word: string}[]}
82
- */
83
- export function linesByKind(sub) {
84
- const rank = (k) => { const i = LINE_KINDS.indexOf(k); return i < 0 ? LINE_KINDS.length : i; };
85
- return [...sub.kinds.entries()]
86
- .sort((a, b) => rank(a[0]) - rank(b[0]) || (a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0))
87
- .map(([kind, count]) => ({ kind, count, word: kindPanelWord(kind) }));
88
- }
89
-
90
- /**
91
- * The lit lines of one kind, as the node at their far end: { node id, whether the line leaves the selection }, in map order.
92
- * @param {NonNullable<ReturnType<typeof activeSubgraph>>} sub
93
- * @param {string} kind
94
- */
95
- export function farEnds(sub, kind) {
96
- const rows = [];
97
- const seen = new Set();
98
- for (const e of sub.edges) {
99
- if (edgeKindOf(e) !== kind) continue;
100
- const out = e.from === sub.selectedId;
101
- const other = out ? e.to : e.from;
102
- if (seen.has(other)) continue;
103
- seen.add(other);
104
- rows.push({ id: other, out });
105
- }
106
- return rows;
107
- }
108
-
109
74
  /** The screen point of a world point */
110
75
  const screenOf = (camera, n) => ({ x: camera.x + n.x * camera.zoom, y: camera.y + n.y * camera.zoom });
111
76
 
@@ -143,8 +108,3 @@ export function selectionCamera(node, lit, rect, { padding = 40 } = {}) {
143
108
  if (fit && fit.zoom >= FRAME_MIN_ZOOM) return { ...fit, framed: true };
144
109
  return { x: rect.x + rect.width / 2 - node.x * CENTRE_ZOOM, y: rect.y + rect.height / 2 - node.y * CENTRE_ZOOM, zoom: CENTRE_ZOOM, framed: false };
145
110
  }
146
-
147
- /** The words that say how much of a selection is in view: "27 connected · 9 off screen" */
148
- export function connectedLine(connected, off) {
149
- return off > 0 ? `${connected} connected · ${off} off screen` : `${connected} connected · all on screen`;
150
- }
@@ -5,7 +5,7 @@
5
5
  * lights, how many of them are off screen, and the camera that frames them. "Frame them" in the node panel and the `F` key call
6
6
  * `frameSelection`; a selection that comes from search, a list, a link or the keyboard calls it too (engine/selection.js), and a click on the map never does.
7
7
  */
8
- import { visibleMapRect } from './engine/sheets.js';
8
+ import { visibleMapRect } from './engine/map-rect.js';
9
9
  import { flyTo } from './engine/fly.js';
10
10
  import { countOffScreen, selectionCamera } from './selection-model.js';
11
11
 
@@ -0,0 +1,52 @@
1
+ /**
2
+ * @module explorer/selection-words
3
+ *
4
+ * What the node panel says of a selection (spec 0008 D6): the kinds of its lit lines in the panel's order (`LINE_KINDS`, `linesByKind`), a kind's
5
+ * panel word (`kindPanelWord`, from selection-model.js's `KIND_WORDS`), the node at the far end of each line (`farEnds`) and how much of it is in
6
+ * view (`connectedLine`). The selection itself and where the camera goes for it are selection-model.js's: a map alone does not carry the panel's
7
+ * words (the components' size budget, spec 0011 D11). Pure: no DOM, no state.
8
+ */
9
+
10
+ import { KIND_WORDS, edgeKindOf } from './selection-model.js';
11
+
12
+ /** The kinds a line is drawn as, in the order the panel lists them */
13
+ export const LINE_KINDS = ['ownership', 'usage', 'flow', 'reads', 'writes', 'calls', 'triggers', 'delivers', 'runs-on', 'uses', 'extends'];
14
+
15
+ /** A kind's panel word; a kind this table does not know (a project's own) is shown as the text it is */
16
+ export const kindPanelWord = (kind) => (Object.hasOwn(KIND_WORDS, kind) ? KIND_WORDS[kind].panel : String(kind));
17
+
18
+ /**
19
+ * The lit lines counted by kind, in LINE_KINDS order (a kind of the project's own after them, by name).
20
+ * @param {NonNullable<ReturnType<typeof activeSubgraph>>} sub
21
+ * @returns {{kind: string, count: number, word: string}[]}
22
+ */
23
+ export function linesByKind(sub) {
24
+ const rank = (k) => { const i = LINE_KINDS.indexOf(k); return i < 0 ? LINE_KINDS.length : i; };
25
+ return [...sub.kinds.entries()]
26
+ .sort((a, b) => rank(a[0]) - rank(b[0]) || (a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0))
27
+ .map(([kind, count]) => ({ kind, count, word: kindPanelWord(kind) }));
28
+ }
29
+
30
+ /**
31
+ * The lit lines of one kind, as the node at their far end: { node id, whether the line leaves the selection }, in map order.
32
+ * @param {NonNullable<ReturnType<typeof activeSubgraph>>} sub
33
+ * @param {string} kind
34
+ */
35
+ export function farEnds(sub, kind) {
36
+ const rows = [];
37
+ const seen = new Set();
38
+ for (const e of sub.edges) {
39
+ if (edgeKindOf(e) !== kind) continue;
40
+ const out = e.from === sub.selectedId;
41
+ const other = out ? e.to : e.from;
42
+ if (seen.has(other)) continue;
43
+ seen.add(other);
44
+ rows.push({ id: other, out });
45
+ }
46
+ return rows;
47
+ }
48
+
49
+ /** The words that say how much of a selection is in view: "27 connected · 9 off screen" */
50
+ export function connectedLine(connected, off) {
51
+ return off > 0 ? `${connected} connected · ${off} off screen` : `${connected} connected · all on screen`;
52
+ }