@intentius/behold 0.29.45 → 0.29.47

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intentius/behold",
3
- "version": "0.29.45",
3
+ "version": "0.29.47",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "description": "behold — a live control plane on chant. See your whole estate (every substrate in one graph), coloured by drift; act through delegated, gated Ops.",
package/web/app.js CHANGED
@@ -13,6 +13,7 @@ import { createRefreshQueue } from "./refresh-queue.js";
13
13
  import { readViewQuery, writeViewQuery, settleView, settlePlace, refusalLine } from "./view-url.js";
14
14
  import { quietCardLines, readEmbed, selectMessage, viewFromMessage, wheelPx, wheelZoomsBare } from "./embed.js";
15
15
  import { WORDS as POP_WORDS, cardRoot as popCardRoot, placePopover, popReduce, popState, resourcePopover, rootPopover } from "./kiosk-popover.js";
16
+ import { shiftInto } from "./float-place.js"; // behold#764
16
17
  import { cssString, hoverCss, hoverFromMessage, hoverLinks, hoverMessage, isLightBg, rootPaint, rootText } from "./kiosk-roots.js";
17
18
  import { gateCards } from "./workspace-gates.js";
18
19
  import { cornerOf, estateLine, hrefOf as tgHref, legend as tgLegend, markLine, rootRows as tgRootRows, waveCards } from "./terragucci.js";
@@ -4499,6 +4500,95 @@ function tgReadShow(svg) {
4499
4500
  const hot = new Set(tgReadHot);
4500
4501
  for (const el of svg.querySelectorAll("[data-tg-read]")) el.classList.toggle("tg-hot", hot.has(el.getAttribute("data-tg-read")));
4501
4502
  for (const g of svg.querySelectorAll("g[data-tg-read-pill].tg-hot")) g.parentNode.appendChild(g);
4503
+ tgPillsKeepIn(svg);
4504
+ }
4505
+ /**
4506
+ * behold#764: a kiosk frame's shown pills stay inside what the frame shows. A pill is placed when the reads are drawn,
4507
+ * against the shot's viewBox then; the camera moves after, and a pointed card lights the pills of readers it has
4508
+ * panned out of view (331px over the frame's top on /tofu-fanout). A pill whose reader is out of view does not show
4509
+ * (tg-off): its leader would point at nothing. One whose reader shows slides in by as little as keeps it inside
4510
+ * (shiftInto), its leader and dot left on the reader's card. Run after each light and each camera move.
4511
+ */
4512
+ function tgPillsKeepIn(svg) {
4513
+ if (!embedOpts.bare || !svg || !svg.getScreenCTM) return;
4514
+ const ctm = svg.getScreenCTM();
4515
+ const scale = ctm && ctm.a ? ctm.a : 1;
4516
+ const host = document.getElementById("graph");
4517
+ const pane = host ? host.getBoundingClientRect() : { left: 0, top: 0, right: window.innerWidth, bottom: window.innerHeight };
4518
+ const coveredBelow = kioskShot && kioskShot.insets ? Math.max(0, kioskShot.insets.bottom || 0) : 0;
4519
+ const bottom = Math.min(pane.bottom, window.innerHeight - coveredBelow);
4520
+ const view = { left: Math.max(0, pane.left), top: Math.max(0, pane.top), width: Math.min(window.innerWidth, pane.right) - Math.max(0, pane.left), height: bottom - Math.max(0, pane.top) };
4521
+ for (const g of svg.querySelectorAll("g[data-tg-read-pill]")) {
4522
+ const lead = g.querySelector(":scope > line");
4523
+ const dot = g.querySelector(":scope > circle");
4524
+ const body = g.querySelector(":scope > rect");
4525
+ if (!lead || !dot || !body) continue;
4526
+ // Where the draw put it, kept on the group: each pass starts from there.
4527
+ if (!g.dataset.tgAt) {
4528
+ const m = /translate\(([-\d.e]+)[ ,]+([-\d.e]+)\)/.exec(g.getAttribute("transform") || "");
4529
+ if (!m) continue;
4530
+ g.dataset.tgAt = `${m[1]} ${m[2]} ${lead.getAttribute("x1")} ${lead.getAttribute("y1")} ${lead.getAttribute("x2")} ${lead.getAttribute("y2")}`;
4531
+ }
4532
+ const [cx, cy, lx1, ly1, lx2, ly2] = g.dataset.tgAt.split(" ").map(Number);
4533
+ const set = (x, y) => {
4534
+ g.setAttribute("transform", `translate(${x} ${y})`);
4535
+ const ax = cx + lx1 - x;
4536
+ const ay = cy + ly1 - y;
4537
+ const bx = Number(body.getAttribute("x"));
4538
+ const by = Number(body.getAttribute("y"));
4539
+ const near = tgNearestOn({ x: bx, y: by, x2: bx + Number(body.getAttribute("width")), y2: by + Number(body.getAttribute("height")) }, { x: ax, y: ay });
4540
+ const moved = x !== cx || y !== cy;
4541
+ lead.setAttribute("x1", String(ax));
4542
+ lead.setAttribute("y1", String(ay));
4543
+ lead.setAttribute("x2", String(moved ? near.x : lx2));
4544
+ lead.setAttribute("y2", String(moved ? near.y : ly2));
4545
+ dot.setAttribute("cx", String(ax));
4546
+ dot.setAttribute("cy", String(ay));
4547
+ };
4548
+ set(cx, cy);
4549
+ g.style.display = ""; // measured where it is drawn, then hidden again below if its reader is out of view
4550
+ if (!(view.width > 0 && view.height > 0)) continue;
4551
+ const d = dot.getBoundingClientRect();
4552
+ const dx0 = d.left + d.width / 2;
4553
+ const dy0 = d.top + d.height / 2;
4554
+ const off = dx0 < view.left || dx0 > view.left + view.width || dy0 < view.top || dy0 > view.top + view.height;
4555
+ g.classList.toggle("tg-off", off);
4556
+ // Gone at once, whatever its fade or flash is doing (an opacity rule lost to a running transition on the kiosk).
4557
+ g.style.display = off ? "none" : "";
4558
+ if (off) continue;
4559
+ const r = body.getBoundingClientRect();
4560
+ const { dx, dy } = shiftInto({ left: r.left, top: r.top, width: r.width, height: r.height }, view, 8);
4561
+ if (dx || dy) set(cx + dx / scale, cy + dy / scale);
4562
+ }
4563
+ // behold#748's outside mark, the same way: its box and tag slide in (its ring stays on the card, its leader's
4564
+ // card end too). It was 2px over the frame's top on /choudoufu-fanout at the end of the run.
4565
+ for (const g of svg.querySelectorAll("g[data-tg-outside]")) {
4566
+ const ring = g.firstElementChild;
4567
+ const lead = g.querySelector(":scope > line");
4568
+ const moving = [...g.children].filter((c) => c !== ring && c !== lead && c.localName !== "circle" && c.localName !== "title");
4569
+ if (!moving.length) continue;
4570
+ if (!g.dataset.tgAt) g.dataset.tgAt = lead ? `${lead.getAttribute("x2")} ${lead.getAttribute("y2")}` : "";
4571
+ for (const c of moving) c.removeAttribute("transform");
4572
+ if (lead && g.dataset.tgAt) {
4573
+ const [x2, y2] = g.dataset.tgAt.split(" ");
4574
+ lead.setAttribute("x2", x2);
4575
+ lead.setAttribute("y2", y2);
4576
+ }
4577
+ if (!(view.width > 0 && view.height > 0)) continue;
4578
+ const rs = moving.map((c) => c.getBoundingClientRect()).filter((r) => r.width > 0);
4579
+ if (!rs.length) continue;
4580
+ const left = Math.min(...rs.map((r) => r.left));
4581
+ const top = Math.min(...rs.map((r) => r.top));
4582
+ const box = { left, top, width: Math.max(...rs.map((r) => r.right)) - left, height: Math.max(...rs.map((r) => r.bottom)) - top };
4583
+ const { dx, dy } = shiftInto(box, view, 8);
4584
+ if (!dx && !dy) continue;
4585
+ for (const c of moving) c.setAttribute("transform", `translate(${dx / scale} ${dy / scale})`);
4586
+ if (lead && g.dataset.tgAt) {
4587
+ const [x2, y2] = g.dataset.tgAt.split(" ").map(Number);
4588
+ lead.setAttribute("x2", String(x2 + dx / scale));
4589
+ lead.setAttribute("y2", String(y2 + dy / scale));
4590
+ }
4591
+ }
4502
4592
  }
4503
4593
  let tgReadWired = false;
4504
4594
  function wireTgReadHover() {
@@ -4517,6 +4607,7 @@ function ensureTgReadStyle() {
4517
4607
  st.id = "tg-read-style";
4518
4608
  st.textContent = `#graph g[data-tg-read-pill] { opacity: 0; }
4519
4609
  #graph g[data-tg-read-pill].tg-hot, #graph g[data-tg-read-pill].tg-shown { opacity: 1 !important; }
4610
+ #graph g[data-tg-read-pill].tg-off { opacity: 0 !important; animation: none; }
4520
4611
  #graph g[data-tg-read-pill].tg-hot { transition: opacity .15s ease; }
4521
4612
  #graph g[data-tg-read-pill].tg-flash { animation: tg-read-flash 6s linear both; }
4522
4613
  #graph line[data-tg-read].tg-hot { stroke-width: 5; filter: drop-shadow(0 0 3px var(--bg)); }
@@ -5292,6 +5383,7 @@ function kioskPopRender() {
5292
5383
  const content = !card || !answer ? null : kioskCompMode() ? rootPopover(answer, kioskRootOfComponent(id), resourcesByComponent[id]) : resourcePopover(answer, id);
5293
5384
  if (!content) {
5294
5385
  if (pop) pop.hidden = true;
5386
+ kioskTellPop(pop);
5295
5387
  return;
5296
5388
  }
5297
5389
  if (!pop) {
@@ -5352,12 +5444,34 @@ function kioskPopRender() {
5352
5444
  const touchOnly = typeof matchMedia === "function" && matchMedia("(hover: none)").matches;
5353
5445
  add("p", "k-pop-hint", kioskPop.pinned ? (touchOnly ? POP_WORDS.tapPinnedHint : POP_WORDS.pinnedHint) : POP_WORDS.pinHint);
5354
5446
  pop.hidden = false;
5447
+ // behold#764: measured at its own height, then capped (its body scrolls) when the frame's view is shorter.
5448
+ pop.style.maxHeight = "";
5355
5449
  const cb = card.getBoundingClientRect();
5356
5450
  const pb = pop.getBoundingClientRect();
5357
- const at = placePopover({ left: cb.left, top: cb.top, width: cb.width, height: cb.height }, { width: pb.width, height: pb.height }, { width: window.innerWidth, height: window.innerHeight });
5451
+ // The part of the frame that shows: Watch's caption and track cover its bottom (the shot's insets), unless that leaves too little.
5452
+ const coveredBelow = kioskShot && kioskShot.insets ? Math.max(0, kioskShot.insets.bottom || 0) : 0;
5453
+ const height = window.innerHeight - coveredBelow >= 240 ? window.innerHeight - coveredBelow : window.innerHeight;
5454
+ const at = placePopover({ left: cb.left, top: cb.top, width: cb.width, height: cb.height }, { width: pb.width, height: pb.height }, { width: window.innerWidth, height });
5455
+ pop.style.maxHeight = at.maxHeight ? `${Math.floor(at.maxHeight)}px` : "";
5358
5456
  pop.style.left = `${Math.round(at.left)}px`;
5359
5457
  pop.style.top = `${Math.round(at.top)}px`;
5458
+ kioskTellPop(pop);
5459
+ }
5460
+ /** behold#764: tell the kiosk where the card's details popover is (or that none is open), so its modals never cover it. */
5461
+ function kioskTellPop(pop) {
5462
+ if (!embedOpts.bare || !embedOpts.host || window.parent === window) return;
5463
+ const r = pop && !pop.hidden ? pop.getBoundingClientRect() : null;
5464
+ const at = r && r.width ? { x: Math.round(r.left), y: Math.round(r.top), w: Math.round(r.width), h: Math.round(r.height) } : null;
5465
+ const key = JSON.stringify(at);
5466
+ if (key === kioskPopTold) return;
5467
+ kioskPopTold = key;
5468
+ try {
5469
+ window.parent.postMessage({ type: "behold:pop", at }, embedOpts.host);
5470
+ } catch {
5471
+ /* the parent went away */
5472
+ }
5360
5473
  }
5474
+ var kioskPopTold = "null"; // var: kioskPopRender may run before this line is reached
5361
5475
  /** Wire the frame's pointer once: the popover, and the hover links to the kiosk. Bare frames only. */
5362
5476
  // --- behold#571: the kiosk's Watch mode -------------------------------------
5363
5477
  // The kiosk sends a `behold:shot` (web/kiosk-shot.js) with each step: the
@@ -5570,6 +5684,7 @@ function kioskTellBoxes() {
5570
5684
  boxesQueued = false;
5571
5685
  const svg = currentSvg();
5572
5686
  if (!svg) return;
5687
+ tgPillsKeepIn(svg); // behold#764: the camera moved; the shown pills stay in view
5573
5688
  const waves = {};
5574
5689
  const rect = (r) => ({ x: Math.round(r.left), y: Math.round(r.top), w: Math.round(r.width), h: Math.round(r.height) });
5575
5690
  for (const r of svg.querySelectorAll("rect[data-group-id]")) {
@@ -113,6 +113,10 @@ export const MODAL_STYLE = `
113
113
  /* behold#744: a modal placed off the cards leaves the graph to the pointer (hover a card or a line), not under a sheet that swallows it. */
114
114
  .eh-modal-wrap.eh-modal-placed { align-items: flex-start; justify-content: flex-start; pointer-events: none; }
115
115
  .eh-modal-wrap.eh-modal-placed > .eh-modal { pointer-events: auto; }
116
+ /* behold#764: a card's details popover is open: no sheet over it, and a modal that cannot stand clear of it waits out of sight. */
117
+ .eh-modal-wrap.eh-modal-keep { background: transparent; pointer-events: none; }
118
+ .eh-modal-wrap.eh-modal-keep > .eh-modal { pointer-events: auto; }
119
+ .eh-modal-wrap.eh-modal-yield > .eh-modal { visibility: hidden; pointer-events: none; }
116
120
  .eh-modal { position: relative; width: min(36em, calc(100vw - 32px)); max-height: calc(100vh - 48px); overflow-y: auto; padding: 1em 1.2em 1.1em; border-radius: 12px; background: var(--surface-pane-b, var(--panel)); color: var(--fg);
117
121
  border: 2px solid var(--bar, var(--focus)); box-shadow: 0 16px 48px color-mix(in srgb, var(--shadow) 80%, transparent); font-size: 1.05em; }
118
122
  .eh-modal-held { --bar: var(--bar-foreign, var(--foreign)); } .eh-modal-failed { --bar: var(--bar-degraded, var(--degraded)); } .eh-modal-applied { --bar: var(--bar-managed, var(--managed)); }
@@ -159,6 +163,11 @@ export function modalStyle(doc) {
159
163
  * graph's frame) when given, else the window. When no spot clears `avoid`,
160
164
  * the one that covers least of it.
161
165
  */
166
+ /** behold#764: whether box `a` covers any of rect `b` (both `{ left, top, width, height }`). */
167
+ export function coversRect(a, b) {
168
+ return !!a && !!b && a.left < b.left + b.width && a.left + a.width > b.left && a.top < b.top + b.height && a.top + a.height > b.top;
169
+ }
170
+
162
171
  export function modalSpot(win, size, avoid, { prefer = [], bounds = null, margin = 16, step = 24 } = {}) {
163
172
  const grow = (a) => ({ x0: a.left - 12, y0: a.top - 12, x1: a.left + a.width + 12, y1: a.top + a.height + 12 });
164
173
  const rects = (avoid || []).filter((a) => a && a.width > 0 && a.height > 0).map(grow);
@@ -216,9 +225,12 @@ export function openEventModal(host, { mode, kind, data = {}, actions = {}, doc
216
225
  wrap.appendChild(box);
217
226
  host.appendChild(wrap);
218
227
 
219
- const close = () => {
228
+ // behold#764: who closed it, on its state for onClose: "viewer" (×, Escape, a click on the sheet), else the page
229
+ // (its time, its event, the next modal), so a closed "Waiting on…" stays closed for the wait it was about.
230
+ const close = (by = null) => {
220
231
  if (st.closed) return;
221
232
  st.closed = true;
233
+ st.closedBy = by === "viewer" ? "viewer" : "page";
222
234
  clearTimer(timer);
223
235
  if (watchTimer) clearTimer(watchTimer);
224
236
  if (doc.removeEventListener) doc.removeEventListener("keydown", onKey);
@@ -227,11 +239,11 @@ export function openEventModal(host, { mode, kind, data = {}, actions = {}, doc
227
239
  onClose(st);
228
240
  };
229
241
  const onKey = (e) => {
230
- if (e && e.key === ESC) close();
242
+ if (e && e.key === ESC) close("viewer");
231
243
  };
232
244
  if (doc.addEventListener) doc.addEventListener("keydown", onKey);
233
245
  wrap.addEventListener("click", (e) => {
234
- if (e && e.target === wrap) close();
246
+ if (e && e.target === wrap) close("viewer");
235
247
  });
236
248
  // Hovered, it holds: its time to close starts again when the pointer leaves.
237
249
  box.addEventListener("pointerenter", () => (st.hovered = true));
@@ -247,7 +259,7 @@ export function openEventModal(host, { mode, kind, data = {}, actions = {}, doc
247
259
  const x = el("button", "eh-modal-close", "×");
248
260
  x.type = "button";
249
261
  x.setAttribute("aria-label", "Close");
250
- x.addEventListener("click", close);
262
+ x.addEventListener("click", () => close("viewer"));
251
263
  box.appendChild(x);
252
264
  const line = modeLine(mode, kind, { at: data.at, now: t, resolved: st.resolved, outcome: st.outcome, replayAt: data.replayAt, action: data.action, fix: !!data.fix });
253
265
  if (line) box.appendChild(el("p", `eh-modal-mode eh-modal-${mode}`, line));
@@ -331,17 +343,42 @@ export function openEventModal(host, { mode, kind, data = {}, actions = {}, doc
331
343
  }
332
344
  // behold#631: a modal that must keep things in view (a failed card and the cards it blocked) moves off them.
333
345
  const placeClear = () => {
334
- if (typeof data.avoid !== "function" || !box.getBoundingClientRect || !doc.defaultView) return;
346
+ // behold#764: what it must never cover, whatever else it keeps off: the card's details popover a viewer has open.
347
+ const keep = typeof data.keepClear === "function" ? data.keepClear() : null;
348
+ if ((typeof data.avoid !== "function" && !keep) || !box.getBoundingClientRect || !doc.defaultView) {
349
+ // The popover closed: the modal steps back into sight, its sheet as it was.
350
+ if (st.kept && wrap.classList) {
351
+ wrap.classList.toggle("eh-modal-yield", false);
352
+ wrap.classList.toggle("eh-modal-keep", false);
353
+ // Moved off the popover alone (no `avoid` of its own): back to the middle.
354
+ wrap.classList.toggle("eh-modal-placed", false);
355
+ box.style.marginLeft = "";
356
+ box.style.marginTop = "";
357
+ }
358
+ st.kept = false;
359
+ st.yielded = false;
360
+ return;
361
+ }
362
+ // Measured where it would stand: a modal that yielded is hidden, not gone.
335
363
  const r = box.getBoundingClientRect();
336
364
  if (!r.width) return;
337
365
  const win = { w: doc.defaultView.innerWidth, h: doc.defaultView.innerHeight };
338
- const spot = modalSpot(win, { w: r.width, h: r.height }, data.avoid() || [], { prefer: typeof data.prefer === "function" ? data.prefer() || [] : [], bounds: typeof data.bounds === "function" ? data.bounds() : null });
366
+ const avoid = [...(typeof data.avoid === "function" ? data.avoid() || [] : []), ...(keep ? [keep] : [])];
367
+ const spot = modalSpot(win, { w: r.width, h: r.height }, avoid, { prefer: typeof data.prefer === "function" ? data.prefer() || [] : [], bounds: typeof data.bounds === "function" ? data.bounds() : null });
339
368
  wrap.classList.toggle("eh-modal-placed", !!spot);
369
+ wrap.classList.toggle("eh-modal-keep", !!keep);
370
+ st.kept = !!keep;
340
371
  box.style.marginLeft = spot ? `${Math.round(spot.left)}px` : "";
341
372
  box.style.marginTop = spot ? `${Math.round(spot.top)}px` : "";
373
+ // Where no spot clears the popover, the modal steps out of sight until it closes; its sheet never tints over it.
374
+ const at = spot ? { left: spot.left, top: spot.top } : { left: (win.w - r.width) / 2, top: (win.h - r.height) / 2 };
375
+ st.yielded = !!keep && coversRect({ ...at, width: r.width, height: r.height }, keep);
376
+ wrap.classList.toggle("eh-modal-yield", st.yielded);
342
377
  };
343
378
  const tick = () => {
344
379
  if (st.closed) return;
380
+ // behold#764: out of sight behind a details popover, its time to close waits, as a hovered one's does.
381
+ if (st.closeAt !== null && st.yielded) st.closeAt = Math.max(st.closeAt, now() + 2_000);
345
382
  if (st.closeAt !== null && !st.hovered && now() >= st.closeAt) return close();
346
383
  render();
347
384
  placeClear();
@@ -369,7 +406,7 @@ export function openEventModal(host, { mode, kind, data = {}, actions = {}, doc
369
406
  Object.assign(data, next);
370
407
  render();
371
408
  },
372
- close,
409
+ close: () => close(),
373
410
  };
374
411
  return api;
375
412
  }
@@ -0,0 +1,85 @@
1
+ // behold#764: where a floating dialog goes, kept inside what can be seen.
2
+ // On the fan-out kiosks wave 3's cards sit at the very top of the graph, and
3
+ // a dialog put above (or levelled with) one of them, or one taller than the
4
+ // space left, ran off the top of its window. Every floating thing of the
5
+ // kiosk (the frame's card popover, the job box and its log drawer, the
6
+ // approval callout, the event-help tips, the tooltip) places itself with
7
+ // these: beside its anchor on the first side it fits, else on the side with
8
+ // the most room, never past the view's edges less a margin; taller than the
9
+ // view, it gets a max height and its body scrolls.
10
+ //
11
+ // Pure: rects in, a position out. All boxes are `{ left, top, width, height }`
12
+ // in one window's pixels; the view is the part of that window that shows (a
13
+ // frame's window, or the kiosk's graph above its caption).
14
+
15
+ /** The room kept between a dialog and the view's edge, in px. */
16
+ export const FLOAT_MARGIN = 8;
17
+
18
+ const clamp = (v, lo, hi) => Math.max(lo, Math.min(v, Math.max(lo, hi)));
19
+
20
+ /**
21
+ * The smallest move `{ dx, dy }` that puts `rect` inside `view` less `margin`.
22
+ * A rect bigger than the view keeps its top (or left) edge in: what a dialog
23
+ * starts with is what is read first.
24
+ */
25
+ export function shiftInto(rect, view, margin = FLOAT_MARGIN) {
26
+ const x0 = view.left + margin;
27
+ const y0 = view.top + margin;
28
+ const x1 = view.left + view.width - margin;
29
+ const y1 = view.top + view.height - margin;
30
+ const left = clamp(rect.left, x0, x1 - rect.width);
31
+ const top = clamp(rect.top, y0, y1 - rect.height);
32
+ return { dx: left - rect.left, dy: top - rect.top };
33
+ }
34
+
35
+ /** Whether `rect` lies inside `view` less `margin` (half a pixel's slack for rounding). */
36
+ export function fitsIn(rect, view, margin = FLOAT_MARGIN) {
37
+ return rect.left >= view.left + margin - 0.5 && rect.top >= view.top + margin - 0.5 && rect.left + rect.width <= view.left + view.width - margin + 0.5 && rect.top + rect.height <= view.top + view.height - margin + 0.5;
38
+ }
39
+
40
+ /**
41
+ * Where a dialog of `size` (`{ width, height }`) goes beside `anchor` inside
42
+ * `view`. `sides` is the order to try ("right", "left", "below", "above"):
43
+ * the first side with room for the whole dialog wins. With none, the side
44
+ * with the most room for it, as a share of its size. Along its side the
45
+ * dialog starts level with the anchor's top (beside) or left (above, below),
46
+ * slid as little as keeps it in the view. A dialog taller than the view
47
+ * less its margins gets `maxHeight` (else null): the caller caps it there and
48
+ * lets its body scroll. `arrow` is how far along the dialog's near edge the
49
+ * anchor's middle is (its notch or leader points there), kept 12px off its
50
+ * corners. Returns `{ left, top, side, maxHeight, arrow }`.
51
+ */
52
+ export function placeFloat(anchor, size, view, { sides = ["right", "left", "below", "above"], gap = 12, margin = FLOAT_MARGIN } = {}) {
53
+ const vx0 = view.left + margin;
54
+ const vy0 = view.top + margin;
55
+ const vx1 = view.left + view.width - margin;
56
+ const vy1 = view.top + view.height - margin;
57
+ const maxH = Math.max(0, vy1 - vy0);
58
+ const maxW = Math.max(0, vx1 - vx0);
59
+ const h = Math.min(size.height, maxH);
60
+ const w = Math.min(size.width, maxW);
61
+ const right = anchor.left + anchor.width;
62
+ const bottom = anchor.top + anchor.height;
63
+ const room = {
64
+ right: vx1 - (right + gap),
65
+ left: anchor.left - gap - vx0,
66
+ below: vy1 - (bottom + gap),
67
+ above: anchor.top - gap - vy0,
68
+ };
69
+ const need = (side) => (side === "right" || side === "left" ? w : h);
70
+ const at = (side) => {
71
+ if (side === "right") return { left: right + gap, top: clamp(anchor.top, vy0, vy1 - h) };
72
+ if (side === "left") return { left: anchor.left - gap - w, top: clamp(anchor.top, vy0, vy1 - h) };
73
+ if (side === "below") return { left: clamp(anchor.left, vx0, vx1 - w), top: bottom + gap };
74
+ return { left: clamp(anchor.left, vx0, vx1 - w), top: anchor.top - gap - h };
75
+ };
76
+ let side = sides.find((s) => room[s] >= need(s));
77
+ if (!side) side = [...sides].sort((a, b) => room[b] / need(b) - room[a] / need(a))[0];
78
+ const p = at(side);
79
+ const left = clamp(p.left, vx0, vx1 - w);
80
+ const top = clamp(p.top, vy0, vy1 - h);
81
+ const beside = side === "right" || side === "left";
82
+ const mid = beside ? anchor.top + anchor.height / 2 - top : anchor.left + anchor.width / 2 - left;
83
+ const arrow = Math.max(12, Math.min((beside ? h : w) - 12, mid));
84
+ return { left, top, side, maxHeight: size.height > maxH ? maxH : null, arrow };
85
+ }
@@ -0,0 +1,117 @@
1
+ // behold#764: every floating dialog of the kiosk stays inside what can be seen.
2
+ import { describe, expect, it } from "vitest";
3
+ import { FLOAT_MARGIN, fitsIn, placeFloat, shiftInto } from "./float-place.js";
4
+ import { placePopover } from "./kiosk-popover.js";
5
+ import { placeBeside } from "./kiosk-watch.js";
6
+ import { placeTip } from "./tooltip.js";
7
+ import { tipSpot } from "./kiosk-event-help-ui.js";
8
+
9
+ const box = (left, top, width, height) => ({ left, top, width, height });
10
+ const overlaps = (a, b) => a.left < b.left + b.width && a.left + a.width > b.left && a.top < b.top + b.height && a.top + a.height > b.top;
11
+
12
+ describe("shiftInto", () => {
13
+ const view = box(0, 0, 1000, 600);
14
+ it("leaves a rect inside alone, and moves one outside by as little as brings it in", () => {
15
+ expect(shiftInto(box(100, 100, 200, 100), view)).toEqual({ dx: 0, dy: 0 });
16
+ expect(shiftInto(box(100, -331, 262, 31), view)).toEqual({ dx: 0, dy: 339 });
17
+ expect(shiftInto(box(-105, 373, 390, 46), view)).toEqual({ dx: 113, dy: 0 });
18
+ expect(shiftInto(box(900, 580, 200, 40), view)).toEqual({ dx: -108, dy: -28 });
19
+ });
20
+ it("keeps the top and left edges in for a rect bigger than the view", () => {
21
+ expect(shiftInto(box(50, -94, 2000, 900), view)).toEqual({ dx: -42, dy: 102 });
22
+ });
23
+ it("works in a view that does not start at 0", () => {
24
+ expect(shiftInto(box(0, 0, 50, 50), box(100, 80, 400, 300), 4)).toEqual({ dx: 104, dy: 84 });
25
+ });
26
+ });
27
+
28
+ describe("placeFloat", () => {
29
+ const view = box(0, 0, 1356, 686); // the kiosk's graph frame at 1366x768
30
+ const size = { width: 412, height: 141 };
31
+ const sides = [["right"], ["left"], ["below"], ["above"]];
32
+
33
+ it("a wave 3 card at the very top of the view: no side puts the dialog past the top", () => {
34
+ const card = box(574, 8, 110, 50);
35
+ for (const [s] of sides) {
36
+ const p = placeFloat(card, size, view, { sides: [s, "below"] });
37
+ expect(fitsIn({ ...p, ...size }, view)).toBe(true);
38
+ }
39
+ // Asked for above first, with no room there, it goes below.
40
+ expect(placeFloat(card, size, view, { sides: ["above", "below"] }).side).toBe("below");
41
+ });
42
+
43
+ it("flips to the side with room: below when there is none above, beside when that fits better", () => {
44
+ expect(placeFloat(box(500, 20, 300, 60), { width: 300, height: 200 }, box(0, 0, 1000, 700), { sides: ["above", "below"] })).toMatchObject({ side: "below", top: 92 });
45
+ // A card as wide as the view, at its top: no room above or below for a tall dialog; to its side when that has room.
46
+ const p = placeFloat(box(20, 10, 600, 650), { width: 300, height: 400 }, box(0, 0, 1000, 700), { sides: ["above", "below", "right"] });
47
+ expect(p.side).toBe("right");
48
+ expect(fitsIn({ ...p, width: 300, height: 400 }, box(0, 0, 1000, 700))).toBe(true);
49
+ });
50
+
51
+ it("never covers its anchor when a side has room, and keeps its leader's end on the anchor", () => {
52
+ const card = box(574, 84, 110, 50);
53
+ const p = placeFloat(card, size, view);
54
+ expect(overlaps({ ...p, ...size }, card)).toBe(false);
55
+ expect(p.side).toBe("right");
56
+ // The notch points at the card's middle, along the dialog's near edge.
57
+ expect(p.top + p.arrow).toBe(card.top + card.height / 2);
58
+ });
59
+
60
+ it("a dialog taller than the view is capped there, its top inside the view", () => {
61
+ const p = placeFloat(box(400, 300, 300, 80), { width: 442, height: 900 }, view);
62
+ expect(p.maxHeight).toBe(686 - 2 * FLOAT_MARGIN);
63
+ expect(p.top).toBe(FLOAT_MARGIN);
64
+ expect(fitsIn({ left: p.left, top: p.top, width: 442, height: p.maxHeight }, view)).toBe(true);
65
+ expect(placeFloat(box(400, 300, 300, 80), size, view).maxHeight).toBeNull();
66
+ });
67
+
68
+ it("stays inside the view for any anchor, at both kiosk sizes", () => {
69
+ for (const v of [box(0, 0, 1910, 981), box(0, 0, 1356, 686), box(5, 77, 1356, 400)]) {
70
+ for (let x = -200; x < v.width + 200; x += 97) {
71
+ for (let y = -200; y < v.height + 200; y += 89) {
72
+ for (const s of [size, { width: 535, height: 771 }, { width: 30, height: 20 }]) {
73
+ const p = placeFloat(box(x, y, 110, 50), s, v);
74
+ const h = p.maxHeight || s.height;
75
+ expect(fitsIn({ left: p.left, top: p.top, width: Math.min(s.width, v.width - 16), height: h }, v)).toBe(true);
76
+ }
77
+ }
78
+ }
79
+ }
80
+ });
81
+ });
82
+
83
+ describe("the dialogs that use it", () => {
84
+ it("the card popover: right of a top-row card, inside the frame, capped when taller", () => {
85
+ const frame = { width: 1356, height: 686 };
86
+ const p = placePopover(box(574, 84, 110, 50), { width: 412, height: 141 }, frame);
87
+ expect(p).toMatchObject({ side: "right", left: 696, top: 84, maxHeight: null });
88
+ const tall = placePopover(box(574, 0, 110, 50), { width: 412, height: 900 }, frame);
89
+ expect(tall.top).toBe(8);
90
+ expect(tall.maxHeight).toBe(670);
91
+ });
92
+
93
+ it("the job box's drawer, opened taller than the graph above the caption: kept below the view's top, capped (was 94px off it)", () => {
94
+ // 1366x768: the graph shows from 77px to the caption's top at 480px; the drawer opened is 569px tall.
95
+ const view = { x: 5, y: 77, w: 1356, h: 403 };
96
+ const p = placeBeside({ x: 120, y: 250, w: 920, h: 300 }, { w: 442, h: 569 }, view);
97
+ expect(p.y).toBeGreaterThanOrEqual(view.y + 8);
98
+ expect(p.maxHeight).toBe(403 - 16);
99
+ expect(p.y + p.maxHeight).toBeLessThanOrEqual(view.y + view.h - 8);
100
+ // Its old "below" spot was 18px under a wave box low in the view: now it never runs past the top for that either.
101
+ const low = placeBeside({ x: 0, y: 300, w: 1356, h: 160 }, { w: 442, h: 300 }, view);
102
+ expect(low.y).toBeGreaterThanOrEqual(view.y + 8);
103
+ expect(low.y + 300).toBeLessThanOrEqual(view.y + view.h - 8);
104
+ });
105
+
106
+ it("the tooltip: inside the window when it fits neither below nor above", () => {
107
+ const p = placeTip({ left: 100, right: 140, top: 300, bottom: 320 }, { width: 200, height: 500 }, { width: 800, height: 600 });
108
+ expect(p.top).toBeGreaterThanOrEqual(8);
109
+ expect(p.top + 500).toBeLessThanOrEqual(600 - 8 + 0.5);
110
+ });
111
+
112
+ it("an event-help tip under a card low in the window stays inside its bottom", () => {
113
+ const p = tipSpot({ left: 400, top: 10, width: 300, height: 700 }, { w: 240, h: 30 }, { w: 1440, h: 760 });
114
+ expect(p.below).toBe(true);
115
+ expect(p.y + 30).toBeLessThanOrEqual(760 - 8);
116
+ });
117
+ });
package/web/index.html CHANGED
@@ -523,8 +523,12 @@
523
523
  /* behold#571: the marks drawn over a card let the pointer through to it, so pointing anywhere on the card opens its popover. */
524
524
  .bare #graph text[data-tg-root], .bare #graph g[data-tg-root] { pointer-events: none; }
525
525
  /* behold#571: the kiosk frame's popover, beside the card it describes. */
526
- #k-pop { position: fixed; z-index: 50; max-width: min(30em, 46vw); padding: 0.7em 0.9em 0.6em; background: var(--panel); color: var(--fg);
527
- border: 1px solid var(--rule); border-radius: 8px; box-shadow: 0 6px 22px color-mix(in srgb, var(--shadow) 70%, transparent);
526
+ /* behold#764: capped to the frame's view by placePopover (max-height), its body scrolls. */
527
+ /* behold#764: on the kiosk's raised surface (its modals' and callouts'), not --panel: in Batman --panel is within a
528
+ few steps of the cards and wave boxes under it, so the popover read as see-through over the graph. A focus-tinted
529
+ border and a deeper shadow set it apart in every theme. */
530
+ #k-pop { position: fixed; z-index: 50; max-width: min(30em, 46vw); overflow-y: auto; overscroll-behavior: contain; padding: 0.7em 0.9em 0.6em; background: var(--surface-pane-b, var(--panel)); color: var(--fg);
531
+ border: 1.5px solid color-mix(in srgb, var(--focus) 70%, var(--rule)); border-radius: 8px; box-shadow: 0 10px 34px color-mix(in srgb, var(--shadow) 80%, transparent);
528
532
  font: 14px/1.4 var(--font-ui); pointer-events: auto; }
529
533
  #k-pop[hidden] { display: none; }
530
534
  /* behold#571: on a phone the popover takes the frame's width, less a margin. */