@intentius/behold 0.29.42 → 0.29.44

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.
Files changed (68) hide show
  1. package/AGENTS.md +77 -0
  2. package/dist/cli.js +3969 -1918
  3. package/package.json +1 -1
  4. package/web/app.js +1463 -80
  5. package/web/carve-narration.js +33 -1
  6. package/web/chant-live-pace.js +138 -0
  7. package/web/chant-live-pace.test.js +116 -0
  8. package/web/chant-pr-marks.js +417 -39
  9. package/web/chant-pr-marks.test.js +208 -4
  10. package/web/collision-marks.js +124 -0
  11. package/web/collision-marks.test.js +89 -0
  12. package/web/cone.js +269 -0
  13. package/web/cone.test.js +213 -0
  14. package/web/dots-cards.js +362 -0
  15. package/web/dots-cards.test.js +303 -0
  16. package/web/dots-live.test.js +151 -1
  17. package/web/dots-lod.js +20 -0
  18. package/web/dots-lod.test.js +19 -1
  19. package/web/dots-scene.js +110 -10
  20. package/web/dots.js +489 -87
  21. package/web/embed.js +17 -1
  22. package/web/embed.test.js +19 -1
  23. package/web/event-help-modal.js +85 -3
  24. package/web/event-help-modal.test.js +85 -1
  25. package/web/feature-flags.js +143 -0
  26. package/web/feature-flags.test.js +96 -0
  27. package/web/index.html +33 -0
  28. package/web/kiosk-carve.js +59 -6
  29. package/web/kiosk-event-help-ui.js +150 -19
  30. package/web/kiosk-event-help.js +102 -15
  31. package/web/kiosk-event-help.test.js +58 -1
  32. package/web/kiosk-metrics.js +4 -3
  33. package/web/kiosk-runs.js +8 -5
  34. package/web/kiosk-shot.js +157 -3
  35. package/web/kiosk-shot.test.js +223 -1
  36. package/web/kiosk-source.js +43 -0
  37. package/web/kiosk-source.test.js +39 -0
  38. package/web/kiosk-story-gate.test.js +44 -0
  39. package/web/kiosk-track.js +312 -0
  40. package/web/kiosk-track.test.js +148 -0
  41. package/web/kiosk-unknown-step.test.js +58 -0
  42. package/web/kiosk-vendor.js +71 -4
  43. package/web/kiosk-vendor.test.js +103 -3
  44. package/web/kiosk-watch.js +154 -1
  45. package/web/kiosk-watch.test.js +53 -1
  46. package/web/kiosk.html +57 -22
  47. package/web/kiosk.js +566 -53
  48. package/web/kiosk.test.js +2 -1
  49. package/web/small-stage.test.js +150 -0
  50. package/web/terragucci-blocked.test.js +192 -0
  51. package/web/terragucci-change.js +197 -17
  52. package/web/terragucci-components-live.js +189 -13
  53. package/web/terragucci-live-pace.js +92 -0
  54. package/web/terragucci-wave-results.test.js +125 -0
  55. package/web/terralith.html +7 -7
  56. package/web/tg-outside.js +124 -0
  57. package/web/tg-outside.test.js +100 -0
  58. package/web/tg-read-pills.js +122 -0
  59. package/web/tg-read-pills.test.js +117 -0
  60. package/web/theme.js +13 -1
  61. package/web/theme.test.js +21 -1
  62. package/web/tooltip.js +19 -7
  63. package/web/tooltip.test.js +15 -0
  64. package/web/tours/terralith.json +4 -4
  65. package/web/trunk-lane.test.js +1 -1
  66. package/web/view-url.js +8 -2
  67. package/web/why.js +129 -1
  68. package/web/why.test.js +113 -1
@@ -77,6 +77,8 @@ body.k-carving.k-watch #k-carve { display: grid; }
77
77
  /* behold#725: sentence case. The tour file writes its labels in lower case ("cycle time"), so the label raises its first letter. */
78
78
  #k-carve .cx-label::first-letter, #k-carve .cx-follow-label::first-letter, #k-carve .cx-ch-kicker::first-letter, #k-carve .cx-num dt::first-letter { text-transform: uppercase; }
79
79
  #k-carve .cx-num dd { margin: 0; font-size: 1.25em; font-weight: 600; color: var(--fg); font-variant-numeric: tabular-nums; }
80
+ /* The quiet line: what runs while nothing new comes in (web/kiosk-watch.js quietWords). One muted line, no spinner. */
81
+ #k-carve .cx-quiet { margin: 0; padding-left: var(--s3); color: var(--muted); font-size: 0.92em; line-height: 1.35; font-variant-numeric: tabular-nums; }
80
82
  #k-carve .cx-notes { margin: 0; font: 12px/1.35 var(--font-mono); color: var(--ink2, var(--muted)); padding-left: var(--s3); overflow-wrap: anywhere; }
81
83
  /* A phone: in the page's flow under the graph, where Watch's caption goes (web/kiosk.html). */
82
84
  @media (max-width: 600px) {
@@ -96,12 +98,25 @@ body.k-carving.k-watch #k-carve { display: grid; }
96
98
  #k-carve .cx-card-title { font-size: 17px; }
97
99
  #k-carve .cx-card-line { font-size: 14px; }
98
100
  #k-carve .cx-num dd { font-size: 16px; }
101
+ #k-carve .cx-quiet { font-size: 13px; }
99
102
  }
103
+ /* While the carve has the stage in Watch, event-help's modal (web/event-help-modal.js) docks at the stage's top left,
104
+ under the top row and clear of the frame's zoom rail and its top-right controls, with no backdrop; the frame is
105
+ told its height as a top inset, so the director frames the boxes under it, never behind it. A phone keeps it centred. */
106
+ @media (min-width: 601px) {
107
+ body.k-carving.k-watch .eh-modal-wrap { inset: auto; top: var(--k-dock-top, 4em); left: var(--k-dock-left, 16px); display: block; background: transparent; pointer-events: none; }
108
+ body.k-carving.k-watch .eh-modal { pointer-events: auto; width: min(30em, var(--k-dock-w, 40vw)); max-height: 34vh; }
109
+ }
110
+ .eh-tip.eh-tip-dock::after { display: none; }
100
111
  /* Slowed playback, in Inspect's quiet rows: off (real time) unless a person picks it. */
101
112
  .k-slowed { font: 12px var(--font-ui); background: var(--well, transparent); color: var(--fg); border: 1px solid var(--line); border-radius: 5px; padding: 2px 8px; cursor: pointer; }
102
113
  .k-slowed[aria-pressed="true"] { border-color: var(--bar-pending); }
103
114
  `;
104
115
 
116
+ /** The docked modal's gap from the stage's edges, and the room it leaves at the stage's right for the frame's zoom rail and controls, in px. */
117
+ export const DOCK_GAP = 12;
118
+ export const DOCK_RIGHT = 240;
119
+
105
120
  /** Whether a message is the framed dots layer's live state, from this origin. */
106
121
  export function liveCarveMessage(e, origin) {
107
122
  return !!(e && e.origin === origin && e.data && e.data.type === "behold:dots-state" && e.data.live === true);
@@ -115,13 +130,16 @@ export function liveCarveMessage(e, origin) {
115
130
  */
116
131
  export function startKioskCarve({ frame, watch, eh, origin = location.origin, isWatch = () => true }) {
117
132
  const trail = eh && eh.trailHost ? eh.trailHost : null;
118
- if (typeof window === "undefined" || typeof document === "undefined" || !watch || !watch.layer) return { tellMode() {}, caption: () => (watch ? watch.caption : null), slowedControl: () => null };
133
+ if (typeof window === "undefined" || typeof document === "undefined" || !watch || !watch.layer) return { tellMode() {}, caption: () => (watch ? watch.caption : null), slowedControl: () => null, lastWriteAt: () => null, setQuiet() {} };
119
134
  let node = null;
120
135
  let narration = null;
121
136
  let carving = false;
122
137
  // The frame last told the kiosk's mode: a frame swapped in (a new view) is told again.
123
138
  let told = null;
124
- let lastBottom = -1;
139
+ let lastBottom = "";
140
+ // The newest progress line the frame has told of, and the quiet line the kiosk works out from it (web/kiosk.js).
141
+ let writeAt = null;
142
+ let quiet = null;
125
143
  // Slowed playback: a person's choice, real time until then. One button, kept across the header's redraws.
126
144
  let slowed = 1;
127
145
  let slowedNode = null;
@@ -171,8 +189,32 @@ export function startKioskCarve({ frame, watch, eh, origin = location.origin, is
171
189
  const f = frame();
172
190
  return f ? f.getBoundingClientRect() : { left: 0, top: 0, width: window.innerWidth, height: window.innerHeight };
173
191
  },
192
+ quiet: () => quiet,
193
+ docked: () => carving && isWatch() && !phone(),
174
194
  });
175
195
  };
196
+ const phone = () => typeof matchMedia === "function" && matchMedia("(max-width: 600px)").matches;
197
+ /** Where event-help's modal docks while the carve has the stage: the stage's top left, in the window's px. */
198
+ const dock = () => {
199
+ const f = frame();
200
+ if (!f) return;
201
+ const g = f.getBoundingClientRect();
202
+ const root = document.documentElement;
203
+ root.style.setProperty("--k-dock-top", `${Math.round(g.top + DOCK_GAP)}px`);
204
+ root.style.setProperty("--k-dock-left", `${Math.round(g.left + DOCK_GAP)}px`);
205
+ // Clear of the frame's zoom rail and its top-right controls (web/kiosk.js FRAME_CONTROLS).
206
+ root.style.setProperty("--k-dock-w", `${Math.max(240, Math.round(g.width - DOCK_RIGHT - 2 * DOCK_GAP))}px`);
207
+ };
208
+ /** The lowest edge of what is docked at the stage's top (event-help's modal, an end bubble) below the stage's top, in px; 0 with none up or on a phone. */
209
+ const dockedBelow = (g) => {
210
+ if (phone() || !isWatch()) return 0;
211
+ let low = 0;
212
+ for (const m of document.querySelectorAll(".eh-modal-wrap .eh-modal, .eh-tip.eh-tip-dock")) {
213
+ const r = m.getBoundingClientRect();
214
+ if (r.height) low = Math.max(low, Math.round(r.bottom - g.top + DOCK_GAP));
215
+ }
216
+ return low;
217
+ };
176
218
  const insets = () => {
177
219
  const f = frame();
178
220
  if (!f || !node || !carving) return { top: 0, bottom: 0 };
@@ -182,7 +224,7 @@ export function startKioskCarve({ frame, watch, eh, origin = location.origin, is
182
224
  const tr = trail && !trail.hidden ? trail.getBoundingClientRect() : null;
183
225
  const top = tr && tr.height && tr.top < c.top && tr.bottom >= c.top - 2 ? tr.top : c.top;
184
226
  const over = c.height && top < g.bottom && c.bottom > g.top ? g.bottom - top : 0;
185
- return { top: 0, bottom: Math.max(0, Math.round(over)) };
227
+ return { top: dockedBelow(g), bottom: Math.max(0, Math.round(over)) };
186
228
  };
187
229
  const tellMode = () => {
188
230
  const f = frame();
@@ -208,12 +250,15 @@ export function startKioskCarve({ frame, watch, eh, origin = location.origin, is
208
250
  document.body.classList.toggle("k-carving", carving);
209
251
  tellMode();
210
252
  }
253
+ writeAt = typeof e.data.lastWriteAt === "number" ? e.data.lastWriteAt : null;
211
254
  // The caption shows only while the carve has the camera (body.k-carving); the Tips come either way.
212
255
  narration.update(e.data);
213
256
  // The caption's height follows its words: the frame keeps the boxes clear of it as it changes.
257
+ if (carving) dock();
214
258
  const ins = insets();
215
- if (ins.bottom !== lastBottom) {
216
- lastBottom = ins.bottom;
259
+ const key = `${ins.top}|${ins.bottom}`;
260
+ if (key !== lastBottom) {
261
+ lastBottom = key;
217
262
  tellMode();
218
263
  }
219
264
  });
@@ -221,5 +266,13 @@ export function startKioskCarve({ frame, watch, eh, origin = location.origin, is
221
266
  const caption = () => (carving && node && isWatch() ? node : watch.caption);
222
267
  /** The slowed control for Inspect's quiet rows, once a frame draws a live carve; null before. */
223
268
  const slowedControl = () => (node ? slowedButton() : null);
224
- return { tellMode, caption, slowedControl };
269
+ /** The newest progress line's time the frame has told of, in ms; null before one. */
270
+ const lastWriteAt = () => writeAt;
271
+ /** The quiet line from the kiosk, or null: drawn at once when it changes. */
272
+ const setQuiet = (q) => {
273
+ const was = quiet ? quiet.text : null;
274
+ quiet = q || null;
275
+ if (narration && (quiet ? quiet.text : null) !== was) narration.redraw();
276
+ };
277
+ return { tellMode, caption, slowedControl, lastWriteAt, setQuiet };
225
278
  }
@@ -16,11 +16,11 @@
16
16
  // lights, the glows and the modals off; the trail stays, since it is the
17
17
  // record.
18
18
 
19
- import { EH_STORE, LATE_ORDER, TIP_MS, cycleFacts, ehSnapshot, ehStore, ehStored, modalQueue, newEvents, storyTrail, tipsQueue } from "./kiosk-event-help.js";
19
+ import { EH_STORE, LATE_ORDER, TIP_MS, cycleFacts, storyKey, ehSnapshot, ehStore, ehStored, modalQueue, modalShownElsewhere, newEvents, storyTrail, tipsQueue, tipsShown } from "./kiosk-event-help.js";
20
20
 
21
21
  /** How long after the page opens (or the cycle turns) what arrives is the story so far, not news: the reads land one by one. */
22
22
  export const SETTLE_MS = 8_000;
23
- import { modalStyle, openEventModal } from "./event-help-modal.js";
23
+ import { FIX_VERBS, modalStyle, openEventModal } from "./event-help-modal.js";
24
24
 
25
25
  /** The switch's label, and its title. */
26
26
  export const TIPS_WORDS = "Tips";
@@ -65,6 +65,8 @@ body.k-watch #eh-trail { position: fixed; z-index: 7; left: 5px; right: 5px; pad
65
65
  @media (prefers-reduced-motion: reduce) { .eh-tip.eh-out { opacity: 0; } }
66
66
  @keyframes eh-pop { from { opacity: 0; transform: var(--eh-at) translateY(6px) scale(0.92); } to { opacity: 1; transform: var(--eh-at); } }
67
67
  @keyframes eh-pulse { 0%, 100% { outline-color: color-mix(in srgb, var(--eh-glow, var(--focus)) 35%, transparent); } 50% { outline-color: var(--eh-glow, var(--focus)); } }
68
+ /* behold#631: a chant kiosk's strip fades in at its left edge, so a chip scrolled past it never reads as a word cut short. */
69
+ #eh-trail.eh-trail-fade { -webkit-mask-image: linear-gradient(to right, transparent 0, #000 72px); mask-image: linear-gradient(to right, transparent 0, #000 72px); }
68
70
  @media (max-width: 600px) { #eh-trail { padding: 0.2em 16px; } body.k-watch #eh-trail { position: static; background: transparent; border: 0; } .eh-tip { max-width: 18em; } }
69
71
  `;
70
72
 
@@ -122,7 +124,7 @@ export function tipSpot(rect, size, win, labels = []) {
122
124
 
123
125
  /** A fact's tone, for its chip, its tip and its modal: the state colours the bars use. */
124
126
  export function toneOf(kind) {
125
- if (kind === "held") return "wait";
127
+ if (kind === "held" || kind === "blocked") return "wait";
126
128
  if (kind === "failed" || kind === "refused") return "bad";
127
129
  if (kind === "applied" || kind === "applied-wave" || kind === "approved" || kind === "known") return "ok";
128
130
  return "busy";
@@ -202,6 +204,19 @@ export function startEventHelp({ doc = document, store = null, switchHost = null
202
204
  const right = Math.min(r.left + r.width, F.right);
203
205
  return bottom - top > 8 && right - left > 8 ? { left, top, width: right - left, height: bottom - top, right, bottom } : null;
204
206
  };
207
+ /** behold#744: the read pills the frame shows now (its `labels`, read fresh at each placement), which a modal keeps off. */
208
+ const pillRects = (h) => {
209
+ const now = (get && get()) || h;
210
+ return ((now && now.boxes && now.boxes.labels) || []).map((l) => fromFrame(now, l)).filter(Boolean);
211
+ };
212
+ /** behold#631: the graph's area above the bottom band (the track or trail, and the caption): where a chant modal may go. */
213
+ const graphArea = (h) => {
214
+ const F = frameRect(h);
215
+ if (!F) return null;
216
+ const band = [doc.getElementById ? doc.getElementById("k-track") : null, trailHost, h.caption].filter((n) => n && !n.hidden && n.getBoundingClientRect).map((n) => n.getBoundingClientRect()).filter((r) => r.height > 0);
217
+ const bottom = Math.min(F.bottom, ...band.map((r) => r.top)) - 8;
218
+ return { left: F.left, top: F.top, width: F.width, height: Math.max(0, bottom - F.top) };
219
+ };
205
220
  const q = (sel) => [...doc.querySelectorAll(sel)].find((n) => visible(n.getBoundingClientRect()) && !n.closest("[hidden]"));
206
221
  /** The things an event is about, the one its tip points at first. */
207
222
  const anchorsOf = (ev, h) => {
@@ -248,15 +263,31 @@ export function startEventHelp({ doc = document, store = null, switchHost = null
248
263
  node.style.transform = at;
249
264
  };
250
265
  const trailChip = (id) => trailHost && trailHost.querySelector(`.eh-chip[data-eh-id="${CSS.escape(id)}"]`);
251
- const showTips = (h) => {
266
+ const showTips = (h, { asked = false } = {}) => {
267
+ // A held small stage in Watch: no bubble over the graph (its cards say it), but a chip the viewer clicks still shows.
268
+ if (asked) st.asked = true;
269
+ if (!st.asked && h && !tipsShown({ watch: !!h.watch, held: !!h.held })) {
270
+ for (const n of st.nodes.values()) n.remove();
271
+ st.nodes.clear();
272
+ st.tips = null;
273
+ return;
274
+ }
252
275
  const t = now();
253
276
  const prev = st.tips;
254
- st.tips = tipsQueue(st.tips, { now: t });
277
+ st.tips = tipsQueue(st.tips, { now: t, ...(st.tipsMax ? { max: st.tipsMax } : {}) });
278
+ // The tip a viewer asked for has had its time: the held stage's rule holds again.
279
+ if (!st.tips.shown.length && !st.tips.waiting.length) st.asked = false;
255
280
  const up = new Set(st.tips.shown.map((x) => x.event.id));
256
281
  // Each tip whose time is up shrinks toward its chip on the trail, then goes.
257
282
  for (const [id, node] of st.nodes) {
258
283
  if (up.has(id)) continue;
259
284
  st.nodes.delete(id);
285
+ // behold#631: on a chant kiosk a tip that goes leaves at once: no shrinking ghost under the next wave.
286
+ // behold#741: so on a terragucci kiosk telling a chapter-carrying scenario (st.story).
287
+ if (st.story) {
288
+ node.remove();
289
+ continue;
290
+ }
260
291
  const chip = trailChip(id) || (trailHost && trailHost.querySelector(".eh-chip:last-of-type"));
261
292
  if (chip && !reduced()) {
262
293
  const c = chip.getBoundingClientRect();
@@ -330,9 +361,11 @@ export function startEventHelp({ doc = document, store = null, switchHost = null
330
361
  let trailKey = "";
331
362
  const drawTrail = (h) => {
332
363
  if (!trailHost) return;
364
+ if (trailHost.classList) trailHost.classList.toggle("eh-trail-fade", !!(h.chant || h.story));
333
365
  const facts = [...st.trail.values()].sort((a, b) => a.order - b.order);
334
366
  const key = facts.map((f) => `${f.id}=${f.text}`).join(",");
335
- trailHost.hidden = !facts.length;
367
+ // behold#631: a chant kiosk's projected track stands in its place.
368
+ trailHost.hidden = !facts.length || !!h.hideTrail;
336
369
  if (h.watch && h.caption && trailHost.style) {
337
370
  const c = h.caption.getBoundingClientRect();
338
371
  trailHost.style.bottom = c.height ? `${Math.round((doc.defaultView ? doc.defaultView.innerHeight : 0) - c.top)}px` : "";
@@ -341,7 +374,11 @@ export function startEventHelp({ doc = document, store = null, switchHost = null
341
374
  trailKey = key;
342
375
  trailHost.replaceChildren(el("span", "eh-trail-label", TRAIL_WORDS));
343
376
  facts.forEach((f, i) => {
344
- if (i) trailHost.appendChild(el("span", "eh-sep", "›"));
377
+ // behold#631: a chant cycle's next pull request (the fix) starts its own run of chips, after a label that says so.
378
+ const prev = i ? facts[i - 1] : null;
379
+ if (prev && Number.isInteger(f.pull) && Number.isInteger(prev.pull) && f.pull !== prev.pull) {
380
+ trailHost.appendChild(el("span", "eh-sep eh-sep-pr", ` | then pull request #${f.pull}:`));
381
+ } else if (i) trailHost.appendChild(el("span", "eh-sep", "›"));
345
382
  const chip = el("button", "eh-chip", f.text);
346
383
  chip.type = "button";
347
384
  chip.dataset.ehId = f.id;
@@ -359,7 +396,7 @@ export function startEventHelp({ doc = document, store = null, switchHost = null
359
396
  for (const n of st.nodes.values()) n.remove();
360
397
  st.nodes.clear();
361
398
  st.tips = { shown: [], waiting: [f] };
362
- showTips(get());
399
+ showTips(get(), { asked: true });
363
400
  };
364
401
 
365
402
  // ---- modals --------------------------------------------------------------
@@ -372,14 +409,63 @@ export function startEventHelp({ doc = document, store = null, switchHost = null
372
409
  if (event.kind === "held") {
373
410
  data = { title: Number.isInteger(event.subjects.wave) ? `Wave ${event.subjects.wave} waits for an approval` : "The plan waits for an approval", lines: [{ text: event.text }], panel: panel("held"), command: h.approveLine || null, at: d && d.step === "waiting" && /approve/.test((d.next && d.next.action) || "") ? nextAt : null, from: t, replayAt: t };
374
411
  } else if (event.kind === "failed" || event.kind === "refused") {
375
- data = { title: `Wave ${event.subjects.wave} failed`, lines: [{ text: event.text, lit: true }, ...(h.label ? [{ text: h.label }] : [])], action: d && d.next ? d.next.action : null, at: nextAt, from: t, replayAt: t };
412
+ // behold#631: a chant failure's own line is the error chant printed. When the step's label already says why, the label is the line and
413
+ // the error goes in its tooltip; otherwise the error's most specific part, with the whole of it in the tooltip.
414
+ const lines = event.chant
415
+ ? h.label
416
+ ? [{ text: h.label, ...(event.raw || event.text ? { title: event.raw || event.text } : {}) }]
417
+ : [{ text: event.text, lit: true, ...(event.raw ? { title: event.raw } : {}) }]
418
+ : [{ text: event.text, lit: true }, ...(h.label ? [{ text: h.label }] : [])];
419
+ // A chant failure is the component's: half of its wave went ahead.
420
+ data = { title: event.chant && event.subjects.roots && event.subjects.roots[0] ? `${event.subjects.roots[0]} failed` : `Wave ${event.subjects.wave} failed`, lines, action: d && d.next ? d.next.action : null, at: nextAt, from: t, replayAt: t };
421
+ // What follows a chant failure is a fix's pull request, not a re-run.
422
+ if (event.chant) Object.assign(data, { fix: true, verbs: FIX_VERBS });
376
423
  } else {
377
424
  const r = h.result;
378
425
  data = { title: "Applied", lines: [...(h.label ? [{ text: h.label }] : []), ...(r ? r.counts.map((c) => ({ text: c })) : [])], replayAt: t };
379
426
  }
380
427
  const kind = event.kind === "refused" ? "failed" : event.kind;
381
- const api = openEventModal(modalHost, { mode, kind, data, doc, now: shown, reduced: reduced(), onClose: () => (st.modal = null) });
382
- st.modal = { api, event, kind, step: d ? d.step : null, cycle: d ? d.cycle : null };
428
+ // behold#631: a chant failure's modal keeps clear of the failed card and the cards it blocked.
429
+ // It must leave the failed wave and the wave after it in view (`avoid`), and covers as few other cards as it can.
430
+ // behold#741: a terragucci story's modals do the same: off the cards they are about (a held wave's, a failed one's),
431
+ // covering as few others as they can, above the bottom band.
432
+ if (event.chant || (st.story && !st.chant)) {
433
+ const box = (r) => fromFrame(h, h.boxes && h.boxes.roots ? h.boxes.roots[r] : null);
434
+ const wave = Number.isInteger(event.subjects.wave) ? (h.waves || []).find((w) => w.wave === event.subjects.wave) : null;
435
+ const must = event.avoid || (event.subjects.roots && event.subjects.roots.length ? event.subjects.roots : wave && Array.isArray(wave.roots) ? wave.roots : []);
436
+ data.avoid = () => [...must.map(box).filter(Boolean), ...pillRects(h)];
437
+ data.prefer = () => Object.keys((h.boxes && h.boxes.roots) || {}).filter((r) => !must.includes(r)).map(box).filter(Boolean);
438
+ data.bounds = () => graphArea(h);
439
+ }
440
+ // A chant kiosk counts down on the clock its track and caption use, so all three say the same second.
441
+ const api = openEventModal(modalHost, { mode, kind, data, doc, now: event.chant ? now : shown, reduced: reduced(), onClose: () => (st.modal = null) });
442
+ st.modal = { api, event, kind, step: d ? d.step : null, cycle: d ? d.cycle : null, pull: d ? d.pull : null };
443
+ };
444
+ /** behold#631: the "Waiting on…" modal's words: what is waited on, why it matters, and how long it usually takes. */
445
+ const waitingData = (w, h) => ({
446
+ title: `Waiting on ${w.what}`,
447
+ lines: w.why ? [{ text: w.why }] : [],
448
+ progress: { fraction: w.fraction, words: w.words },
449
+ // Never over a card: any card of the graph is to stay in view. Then, where it can, off the graph altogether
450
+ // (its wave boxes and the space between them, where a reach is drawn): the space beside it first.
451
+ // behold#744: nor over a read pill the frame shows.
452
+ avoid: () => [...Object.keys((h.boxes && h.boxes.roots) || {}).map((r) => fromFrame(h, h.boxes.roots[r])).filter(Boolean), ...pillRects(h)],
453
+ prefer: () => {
454
+ const waves = Object.values((h.boxes && h.boxes.waves) || {}).map((b) => fromFrame(h, b)).filter(Boolean);
455
+ if (!waves.length) return [];
456
+ const left = Math.min(...waves.map((b) => b.left));
457
+ const top = Math.min(...waves.map((b) => b.top));
458
+ const right = Math.max(...waves.map((b) => b.left + b.width));
459
+ const bottom = Math.max(...waves.map((b) => b.top + b.height));
460
+ return [{ left, top, width: right - left, height: bottom - top }];
461
+ },
462
+ bounds: () => graphArea(h),
463
+ });
464
+ const openWaiting = (w, h) => {
465
+ const d = h.demo;
466
+ const api = openEventModal(modalHost, { mode: "narrated", kind: "waiting", data: waitingData(w, h), doc, now, reduced: reduced(), onClose: () => (st.modal = null) });
467
+ st.modal = { api, event: { kind: "waiting", subjects: { roots: [], wave: null } }, kind: "waiting", key: w.key, step: d ? d.step : null, cycle: d ? d.cycle : null, pull: d ? d.pull : null };
468
+ if (st.story) for (const n of st.nodes.values()) n.style.visibility = "hidden";
383
469
  };
384
470
  /** The modal's real event: the approval landed, the waves ran again, the cycle moved on. */
385
471
  const settleModal = (h, facts) => {
@@ -392,6 +478,9 @@ export function startEventHelp({ doc = document, store = null, switchHost = null
392
478
  else if (d && (d.cycle !== m.cycle || !["waiting", "approved"].includes(d.step))) m.api.resolve(d.cycle === m.cycle ? "approved; the waves run again" : null);
393
479
  } else if (m.kind === "failed") {
394
480
  if (d && (d.cycle !== m.cycle || ["resumed", "applying", "waiting", "applied"].includes(d.step))) m.api.resolve(d.cycle === m.cycle ? "the waves run again" : null);
481
+ // behold#631: a chant failure's modal goes once the cycle moves on, to a new pull request or a new step (the fix's plan, its wait).
482
+ // behold#736: a terragucci story's too (#741's look): on fan-out-choudoufu it stayed over the fix's cone plan.
483
+ if ((m.event.chant || st.story) && d && (d.cycle !== m.cycle || d.pull !== m.pull || d.step !== m.step)) m.api.close();
395
484
  }
396
485
  };
397
486
 
@@ -407,13 +496,15 @@ export function startEventHelp({ doc = document, store = null, switchHost = null
407
496
  st.stripKey = stripKey;
408
497
  st.trail.clear();
409
498
  }
410
- const facts = cycleFacts(ehSnapshot({ demo: h.demo, answer: h.answer, progress: h.progress, runDoc: h.runDoc, runDocs: h.runDocs || [], approval: h.approval, metrics: h.metrics, waveTraces: h.waveTraces || {}, strip: h.strip || null, waves: h.waves || [], failed: [...st.failed] }));
411
- if (h.demo.cycle !== st.cycle) {
499
+ const facts = cycleFacts(ehSnapshot({ demo: h.demo, answer: h.answer, progress: h.progress, runDoc: h.runDoc, runDocs: h.runDocs || [], approval: h.approval, metrics: h.metrics, waveTraces: h.waveTraces || {}, strip: h.strip || null, waves: h.waves || [], failed: [...st.failed], chant: !!h.chant }));
500
+ // A new cycle, or a new beat of one (web/kiosk-event-help.js storyKey): a new story.
501
+ const story = storyKey({ cycle: h.demo.cycle, beat: h.demo.beat || null });
502
+ if (story !== st.cycle) {
412
503
  // A new cycle: a new story. Its first look is the trail so far, not news.
413
504
  // The first look at a page sees a cycle already under way: no news. A cycle that turns while the page is open is all news.
414
505
  if (st.cycle !== null) st.seen = new Set();
415
506
  else st.seen = null;
416
- st.cycle = h.demo.cycle;
507
+ st.cycle = story;
417
508
  st.maxOrder = -Infinity;
418
509
  st.trail.clear();
419
510
  st.failed.clear();
@@ -431,19 +522,59 @@ export function startEventHelp({ doc = document, store = null, switchHost = null
431
522
  for (const f of storyTrail(facts)) st.trail.set(f.id, f);
432
523
  drawTrail(h);
433
524
  settleModal(h, facts);
525
+ // A modal Inspect opened goes when the viewer turns to Watch on a held small stage, where nothing overlays the graph.
526
+ if (st.modal && modalShownElsewhere(st.modal.event, { watch: !!h.watch, held: !!h.held })) st.modal.api.close();
434
527
  if (!st.on) return;
435
- if (news.length) st.tips = tipsQueue(st.tips, { add: news, now: now() });
528
+ // behold#631: a new pull request of a chant cycle (the fix) starts with no tip of the one before.
529
+ if (h.chant && st.tipsPull !== undefined && st.tipsPull !== h.demo.pull) {
530
+ for (const n of st.nodes.values()) n.remove();
531
+ st.nodes.clear();
532
+ st.tips = null;
533
+ }
534
+ st.tipsPull = h.demo.pull;
535
+ // A chant wave's start is history once the wave has settled, outcome tip or not: its tip goes, so the tags follow the paced graph.
536
+ if (h.chant && st.tips) {
537
+ const done = new Set(facts.filter((f) => ["failed", "applied-wave", "blocked"].includes(f.kind) && Number.isInteger(f.subjects.wave)).map((f) => f.subjects.wave));
538
+ if (done.size) st.tips = { shown: st.tips.shown.filter((x) => !(x.event.kind === "started" && done.has(x.event.subjects.wave))), waiting: st.tips.waiting.filter((e) => !(e.kind === "started" && done.has(e.subjects.wave))) };
539
+ }
540
+ // A chant kiosk shows one tip at a time: two placed on one wave box land on each other.
541
+ // behold#741: so does a terragucci kiosk telling a chapter-carrying scenario (`h.story`); its story order stays its own.
542
+ st.tipsMax = h.chant || h.story ? 1 : undefined;
543
+ st.chant = !!h.chant;
544
+ st.story = !!(h.chant || h.story);
545
+ if (news.length) st.tips = tipsQueue(st.tips, { add: news, now: now(), ...(st.tipsMax ? { max: st.tipsMax } : {}) });
436
546
  // While a modal is up, the tips wait their turn behind it.
437
- if (!st.modal) showTips(h);
547
+ if (!st.modal && tipsShown({ watch: !!h.watch, held: !!h.held })) showTips(h);
548
+ // behold#631: on a chant kiosk no tip shows at all while a modal is open, not even one already up.
549
+ else if (st.story) for (const n of st.nodes.values()) n.style.visibility = "hidden";
438
550
  ageGlows();
439
- st.modals = modalQueue(st.modals, { add: news, now: now(), lastInput: st.lastInput, open: !!st.modal });
551
+ // behold#631: the "Waiting on…" modal goes the moment anything new arrives, or what it waits on changes;
552
+ // a critical modal (the failure) always wins over it.
553
+ if (st.modal && st.modal.kind === "waiting" && (news.length || !h.waiting || h.waiting.key !== st.modal.key)) {
554
+ // News closed it: the same wait does not come straight back over the news.
555
+ if (news.length && h.waiting) st.waitingHold = { key: h.waiting.key, until: now() + 4_000 };
556
+ st.modal.api.close();
557
+ }
558
+ // behold#631: a chant repo's approval is the card beside the graph; a modal over it would hide it, so its hold opens none.
559
+ // Its result is the Applied card beside the graph; a modal would say it twice, over the cards.
560
+ // On a held small stage in Watch no modal opens: nothing overlays the graph there, and the caption says each step.
561
+ const told = (e) => modalShownElsewhere(e, { watch: !!h.watch, held: !!h.held });
562
+ st.modals = modalQueue(st.modals, { add: (h.chant ? news.filter((f) => f.kind !== "held" && f.kind !== "applied") : news).filter((e) => !told(e)), now: now(), lastInput: st.lastInput, open: !!st.modal });
440
563
  // A modal opens only while its event is still the step's: one that waited out a viewer at the page and went by is history.
441
- if (st.modals.next && stillNow(st.modals.next, h.demo)) openModal(st.modals.next, h);
564
+ if (st.modals.next && stillNow(st.modals.next, h.demo)) {
565
+ openModal(st.modals.next, h);
566
+ // The tip put up this same tick goes under too.
567
+ if (st.story) for (const n of st.nodes.values()) n.style.visibility = "hidden";
568
+ }
569
+ // behold#631: a quiet stretch on a chant kiosk: "Waiting on …", when no other modal is up or due.
570
+ const held = st.waitingHold && h.waiting && st.waitingHold.key === h.waiting.key && now() < st.waitingHold.until;
571
+ if (h.waiting && st.on && !held && !st.modal && !(st.modals && st.modals.next)) openWaiting(h.waiting, h);
572
+ else if (h.waiting && st.modal && st.modal.kind === "waiting") st.modal.api.update(waitingData(h.waiting, h));
442
573
  };
443
574
  const stillNow = (e, d) => (e.kind === "held" ? d.step === "waiting" : e.kind === "failed" || e.kind === "refused" ? d.step === "failed" : e.kind === "applied" ? d.step === "applied" : false);
444
575
  /** Keep the tips on their things while the graph moves (a shot, a pan). */
445
576
  const follow = () => {
446
- if (st.on && st.tips && st.tips.shown.length) showTips(get());
577
+ if (st.on && st.tips && st.tips.shown.length && !(st.story && st.modal)) showTips(get());
447
578
  };
448
579
  return { tick, follow, state: st, store: EH_STORE };
449
580
  }