@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 +1 -1
- package/web/app.js +116 -1
- package/web/event-help-modal.js +44 -7
- package/web/float-place.js +85 -0
- package/web/float-place.test.js +117 -0
- package/web/index.html +6 -2
- package/web/kiosk-event-help-ui.js +44 -11
- package/web/kiosk-event-help.js +75 -2
- package/web/kiosk-modal-sticky.test.js +294 -0
- package/web/kiosk-popover.js +6 -22
- package/web/kiosk-watch.js +16 -9
- package/web/kiosk.html +13 -1
- package/web/kiosk.js +27 -4
- package/web/terragucci-change.js +32 -1
- package/web/terragucci-wave-results.test.js +56 -1
- package/web/tooltip.js +5 -2
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
// lights, the glows and the modals off; the trail stays, since it is the
|
|
20
20
|
// record.
|
|
21
21
|
|
|
22
|
-
import { EH_STORE, HIGHLIGHT_MS, LATE_ORDER, TIP_MS, cycleFacts, storyKey, ehSnapshot, ehStore, ehStored, highlightOpens, highlightShown, highlightTurn, modalQueue, modalShownElsewhere, newEvents, storyTrail, tipsQueue, tipsShown } from "./kiosk-event-help.js";
|
|
22
|
+
import { EH_STORE, HIGHLIGHT_MS, LATE_ORDER, TIP_MS, createDismissals, cycleFacts, dismissKey, stepWrittenAt, storyKey, ehSnapshot, ehStore, ehStored, highlightOpens, highlightShown, highlightTurn, modalQueue, modalShownElsewhere, newEvents, storyTrail, tipsQueue, tipsShown, waitingOpens } from "./kiosk-event-help.js";
|
|
23
23
|
|
|
24
24
|
/** 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. */
|
|
25
25
|
export const SETTLE_MS = 8_000;
|
|
@@ -114,7 +114,11 @@ export function tipSpot(rect, size, win, labels = []) {
|
|
|
114
114
|
if (y >= 8) spots.push({ x: spots[0].x, y, below: false });
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
|
-
|
|
117
|
+
// behold#764: below, kept inside the window's bottom when its height is known (a tip under a card low in the view).
|
|
118
|
+
const belowY = win.h ? Math.max(8, Math.min(rect.top + rect.height + 12, win.h - h - 8)) : rect.top + rect.height + 12;
|
|
119
|
+
spots.push(...along(belowY, true));
|
|
120
|
+
// An anchor too narrow for any spot along it to reach: the centred spot, still inside the window.
|
|
121
|
+
if (!spots.length) spots.push({ x: clampX(mid - w / 2), y: aboveY >= 8 ? aboveY : belowY, below: aboveY < 8 });
|
|
118
122
|
let best = null;
|
|
119
123
|
for (const p of spots) {
|
|
120
124
|
const c = covered(p);
|
|
@@ -138,7 +142,7 @@ export function toneOf(kind) {
|
|
|
138
142
|
* lights them across the panes as a hover does (null puts them out);
|
|
139
143
|
* `panel(kind)` builds the real panel the modal shows (the approval panel).
|
|
140
144
|
*/
|
|
141
|
-
export function startEventHelp({ doc = document, store = null, switchHost = null, trailHost, tipsHost, modalHost, get, light = () => {}, panel = () => null, openTrace = () => {}, now = () => Date.now(), shown = now, reduced = () => typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches }) {
|
|
145
|
+
export function startEventHelp({ doc = document, store = null, session = null, switchHost = null, trailHost, tipsHost, modalHost, get, light = () => {}, panel = () => null, openTrace = () => {}, now = () => Date.now(), shown = now, reduced = () => typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches }) {
|
|
142
146
|
if (doc.head && !doc.getElementById("eh-style")) {
|
|
143
147
|
const style = doc.createElement("style");
|
|
144
148
|
style.id = "eh-style";
|
|
@@ -147,6 +151,13 @@ export function startEventHelp({ doc = document, store = null, switchHost = null
|
|
|
147
151
|
}
|
|
148
152
|
modalStyle(doc);
|
|
149
153
|
const st = { bootAt: now(), maxOrder: -Infinity, appliedAt: new Map(), on: ehStored(store), cycle: null, seen: null, trail: new Map(), failed: new Set(), tips: null, modals: null, modal: null, lastInput: -Infinity, lit: null, litUntil: 0, nodes: new Map(), glows: [] };
|
|
154
|
+
// behold#764: the story modals the viewer closed this visit (sessionStorage, `session`), which do not open again for the same thing.
|
|
155
|
+
st.closed = createDismissals(session);
|
|
156
|
+
/** The onClose of a story modal about `key` of `kind`: a close by the viewer is kept, so the same thing never reopens it. */
|
|
157
|
+
const closedBy = (kind, d, key) => (ms) => {
|
|
158
|
+
st.modal = null;
|
|
159
|
+
if (ms && ms.closedBy === "viewer") st.closed.add(dismissKey(kind, d, key));
|
|
160
|
+
};
|
|
150
161
|
const el = (tag, cls, text) => {
|
|
151
162
|
const n = doc.createElement(tag);
|
|
152
163
|
if (cls) n.className = cls;
|
|
@@ -212,6 +223,11 @@ export function startEventHelp({ doc = document, store = null, switchHost = null
|
|
|
212
223
|
const now = (get && get()) || h;
|
|
213
224
|
return ((now && now.boxes && now.boxes.labels) || []).map((l) => fromFrame(now, l)).filter(Boolean);
|
|
214
225
|
};
|
|
226
|
+
/** behold#764: the card's details popover the frame has open (its `pop`, read fresh), in the window's coordinates, or null. */
|
|
227
|
+
const popRect = (at) => {
|
|
228
|
+
const h = (get && get()) || at;
|
|
229
|
+
return h && h.pop ? fromFrame(h, h.pop) : null;
|
|
230
|
+
};
|
|
215
231
|
/** behold#631: the graph's area above the bottom band (the track or trail, and the caption): where a chant modal may go. */
|
|
216
232
|
const graphArea = (h) => {
|
|
217
233
|
const F = frameRect(h);
|
|
@@ -254,7 +270,7 @@ export function startEventHelp({ doc = document, store = null, switchHost = null
|
|
|
254
270
|
|
|
255
271
|
// ---- tips ----------------------------------------------------------------
|
|
256
272
|
const place = (node, rect, h) => {
|
|
257
|
-
const win = { w: doc.defaultView ? doc.defaultView.innerWidth : 1600 };
|
|
273
|
+
const win = { w: doc.defaultView ? doc.defaultView.innerWidth : 1600, h: doc.defaultView ? doc.defaultView.innerHeight : 0 };
|
|
258
274
|
// The frame's edge labels, in the window's coordinates (behold#695).
|
|
259
275
|
const F = h ? frameRect(h) : null;
|
|
260
276
|
const labels = F && h.boxes && Array.isArray(h.boxes.labels) ? h.boxes.labels.map((l) => ({ x: F.left + l.x, y: F.top + l.y, w: l.w, h: l.h })) : [];
|
|
@@ -428,6 +444,8 @@ export function startEventHelp({ doc = document, store = null, switchHost = null
|
|
|
428
444
|
data = { title: "Applied", lines: [...(h.label ? [{ text: h.label }] : []), ...(r ? r.counts.map((c) => ({ text: c })) : [])], replayAt: t };
|
|
429
445
|
}
|
|
430
446
|
const kind = event.kind === "refused" ? "failed" : event.kind;
|
|
447
|
+
// behold#764: never over the card's details popover a viewer has open.
|
|
448
|
+
data.keepClear = () => popRect(h);
|
|
431
449
|
// behold#631: a chant failure's modal keeps clear of the failed card and the cards it blocked.
|
|
432
450
|
// It must leave the failed wave and the wave after it in view (`avoid`), and covers as few other cards as it can.
|
|
433
451
|
// behold#741: a terragucci story's modals do the same: off the cards they are about (a held wave's, a failed one's),
|
|
@@ -441,7 +459,7 @@ export function startEventHelp({ doc = document, store = null, switchHost = null
|
|
|
441
459
|
data.bounds = () => graphArea(h);
|
|
442
460
|
}
|
|
443
461
|
// A chant kiosk counts down on the clock its track and caption use, so all three say the same second.
|
|
444
|
-
const api = openEventModal(modalHost, { mode, kind, data, doc, now: event.chant ? now : shown, reduced: reduced(), onClose: (
|
|
462
|
+
const api = openEventModal(modalHost, { mode, kind, data, doc, now: event.chant ? now : shown, reduced: reduced(), onClose: closedBy(kind, d, event.id) });
|
|
445
463
|
st.modal = { api, event, kind, step: d ? d.step : null, cycle: d ? d.cycle : null, pull: d ? d.pull : null };
|
|
446
464
|
};
|
|
447
465
|
/** behold#631: the "Waiting on…" modal's words: what is waited on, why it matters, and how long it usually takes. */
|
|
@@ -450,6 +468,7 @@ export function startEventHelp({ doc = document, store = null, switchHost = null
|
|
|
450
468
|
lines: w.why ? [{ text: w.why }] : [],
|
|
451
469
|
progress: { fraction: w.fraction, words: w.words },
|
|
452
470
|
...offCards(h),
|
|
471
|
+
keepClear: () => popRect(h),
|
|
453
472
|
});
|
|
454
473
|
/**
|
|
455
474
|
* Where a modal about no one card goes (the "Waiting on…" one, a step's highlight): never over a card, since any
|
|
@@ -462,7 +481,9 @@ export function startEventHelp({ doc = document, store = null, switchHost = null
|
|
|
462
481
|
const offCards = (at) => ({
|
|
463
482
|
avoid: () => {
|
|
464
483
|
const h = (get && get()) || at;
|
|
465
|
-
|
|
484
|
+
// behold#764: nor over the job box (the log drawer) or the approval callout beside a wave.
|
|
485
|
+
const overs = doc.querySelectorAll ? [...doc.querySelectorAll("#k-drawer.k-placed, #k-callout.k-placed")].filter((n) => !n.hidden && n.getBoundingClientRect).map((n) => n.getBoundingClientRect()).filter((r) => r.width > 0) : [];
|
|
486
|
+
return [...Object.keys((h.boxes && h.boxes.roots) || {}).map((r) => fromFrame(h, h.boxes.roots[r])).filter(Boolean), ...pillRects(h), ...overs];
|
|
466
487
|
},
|
|
467
488
|
prefer: () => {
|
|
468
489
|
const h = (get && get()) || at;
|
|
@@ -478,14 +499,16 @@ export function startEventHelp({ doc = document, store = null, switchHost = null
|
|
|
478
499
|
});
|
|
479
500
|
const openWaiting = (w, h) => {
|
|
480
501
|
const d = h.demo;
|
|
481
|
-
const api = openEventModal(modalHost, { mode: "narrated", kind: "waiting", data: waitingData(w, h), doc, now, reduced: reduced(), onClose: (
|
|
502
|
+
const api = openEventModal(modalHost, { mode: "narrated", kind: "waiting", data: waitingData(w, h), doc, now, reduced: reduced(), onClose: closedBy("waiting", d, w.key) });
|
|
482
503
|
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 };
|
|
483
504
|
if (st.story) for (const n of st.nodes.values()) n.style.visibility = "hidden";
|
|
484
505
|
};
|
|
485
506
|
/** behold#757: a step's highlight, as a modal off the cards: up HIGHLIGHT_MS (longer while hovered), or until its step goes. */
|
|
486
507
|
const openHighlight = (hl, h) => {
|
|
487
508
|
const d = h.demo;
|
|
488
|
-
const data = { title: hl.title, lines: [{ text: hl.body }], closeAfter: HIGHLIGHT_MS, ...offCards(h) };
|
|
509
|
+
const data = { title: hl.title, lines: [{ text: hl.body }], closeAfter: HIGHLIGHT_MS, ...offCards(h), keepClear: () => popRect(h) };
|
|
510
|
+
// behold#764: once per cycle, step and title for the visit, a reload included: kept as it opens.
|
|
511
|
+
st.closed.add(dismissKey("highlight", d, hl.id));
|
|
489
512
|
const api = openEventModal(modalHost, { mode: h.replay ? "replay" : "narrated", kind: "highlight", data, doc, now, reduced: reduced(), onClose: () => (st.modal = null) });
|
|
490
513
|
st.modal = { api, event: { kind: "highlight", subjects: { roots: [], wave: null } }, kind: "highlight", key: hl.key, step: d ? d.step : null, cycle: d ? d.cycle : null, pull: d ? d.pull : null };
|
|
491
514
|
for (const n of st.nodes.values()) n.style.visibility = "hidden";
|
|
@@ -532,6 +555,10 @@ export function startEventHelp({ doc = document, store = null, switchHost = null
|
|
|
532
555
|
st.trail.clear();
|
|
533
556
|
st.failed.clear();
|
|
534
557
|
}
|
|
558
|
+
// behold#764: a replay looping round to its start (its step's time goes back) is a new telling: what the viewer closed opens again.
|
|
559
|
+
const at = stepWrittenAt(h.demo);
|
|
560
|
+
if (at !== null && st.writtenAt !== undefined && st.writtenAt !== null && at < st.writtenAt) st.closed.clear();
|
|
561
|
+
st.writtenAt = at;
|
|
535
562
|
for (const f of facts) if ((f.kind === "failed" || f.kind === "refused") && Number.isInteger(f.subjects.wave)) st.failed.add(f.subjects.wave);
|
|
536
563
|
// While the page settles, everything is the story so far.
|
|
537
564
|
const settling = now() - st.bootAt < SETTLE_MS;
|
|
@@ -585,7 +612,10 @@ export function startEventHelp({ doc = document, store = null, switchHost = null
|
|
|
585
612
|
}
|
|
586
613
|
// behold#757: the step's highlight, once per cycle, step and title, before the critical modals: one due now waits
|
|
587
614
|
// behind it in the queue, and opens when it closes if its step is still the step.
|
|
588
|
-
|
|
615
|
+
// behold#764: a highlight this visit already showed (before a reload) is not shown again; none opens over a details popover.
|
|
616
|
+
const pop = popRect(h);
|
|
617
|
+
if (st.hl.pending && st.closed.has(dismissKey("highlight", h.demo, st.hl.pending.id))) st.hl = highlightShown(st.hl);
|
|
618
|
+
if (highlightOpens({ pending: st.hl.pending, on: st.on, watch: !!h.watch, held: !!h.held, modal: st.modal ? st.modal.kind : null, pop })) {
|
|
589
619
|
if (st.modal) st.modal.api.close();
|
|
590
620
|
openHighlight(st.hl.pending, h);
|
|
591
621
|
st.hl = highlightShown(st.hl);
|
|
@@ -594,7 +624,9 @@ export function startEventHelp({ doc = document, store = null, switchHost = null
|
|
|
594
624
|
// Its result is the Applied card beside the graph; a modal would say it twice, over the cards.
|
|
595
625
|
// On a held small stage in Watch no modal opens: nothing overlays the graph there, and the caption says each step.
|
|
596
626
|
const told = (e) => modalShownElsewhere(e, { watch: !!h.watch, held: !!h.held });
|
|
597
|
-
|
|
627
|
+
// behold#764: one the viewer closed stays closed; one due while a details popover is open waits for it to close.
|
|
628
|
+
const closedOne = (e) => st.closed.has(dismissKey(e.kind === "refused" ? "failed" : e.kind, h.demo, e.id));
|
|
629
|
+
st.modals = modalQueue(st.modals, { add: (h.chant ? news.filter((f) => f.kind !== "held" && f.kind !== "applied") : news).filter((e) => !told(e) && !closedOne(e)), now: now(), lastInput: st.lastInput, open: !!st.modal || !!pop });
|
|
598
630
|
// 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.
|
|
599
631
|
if (st.modals.next && stillNow(st.modals.next, h.demo)) {
|
|
600
632
|
openModal(st.modals.next, h);
|
|
@@ -603,7 +635,8 @@ export function startEventHelp({ doc = document, store = null, switchHost = null
|
|
|
603
635
|
}
|
|
604
636
|
// behold#631: a quiet stretch on a chant kiosk: "Waiting on …", when no other modal is up or due.
|
|
605
637
|
const held = st.waitingHold && h.waiting && st.waitingHold.key === h.waiting.key && now() < st.waitingHold.until;
|
|
606
|
-
|
|
638
|
+
const closedWait = !!h.waiting && st.closed.has(dismissKey("waiting", h.demo, h.waiting.key));
|
|
639
|
+
if (waitingOpens({ waiting: h.waiting, on: st.on, held, modal: st.modal, due: !!(st.modals && st.modals.next), pop, closed: closedWait })) openWaiting(h.waiting, h);
|
|
607
640
|
else if (h.waiting && st.modal && st.modal.kind === "waiting") st.modal.api.update(waitingData(h.waiting, h));
|
|
608
641
|
};
|
|
609
642
|
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);
|
package/web/kiosk-event-help.js
CHANGED
|
@@ -410,6 +410,79 @@ export function highlightShown(state) {
|
|
|
410
410
|
* small stage (nothing overlays the graph there), and no modal up but a
|
|
411
411
|
* "Waiting on…" one, which it replaces. A critical modal up keeps it waiting.
|
|
412
412
|
*/
|
|
413
|
-
export function highlightOpens({ pending = null, on = true, watch = false, held = false, modal = null } = {}) {
|
|
414
|
-
|
|
413
|
+
export function highlightOpens({ pending = null, on = true, watch = false, held = false, modal = null, pop = null } = {}) {
|
|
414
|
+
// behold#764: nor over the card's details popover a viewer has open (`pop`): it waits until that closes.
|
|
415
|
+
return !!pending && !!on && !!watch && !held && !pop && (!modal || modal === "waiting");
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
// ---------------------------------------------------------------------------
|
|
419
|
+
// behold#764: a story modal a viewer closes stays closed. "Waiting on the
|
|
420
|
+
// pipeline…" came straight back on the next look after its ×: the tick opens
|
|
421
|
+
// one whenever a wait is up and no modal is. A close by the viewer (×, Escape,
|
|
422
|
+
// a click on the sheet) is kept for what the modal was about: its kind, the
|
|
423
|
+
// cycle (and beat), the pull request, the step, and its own key (the wait's
|
|
424
|
+
// chapter, segment and what it waits on; a fact's id; a highlight's id). A new
|
|
425
|
+
// wait (a later step, a new pull request, a new cycle) opens again. Kept for
|
|
426
|
+
// the visit in sessionStorage, so a reload does not bring it back either; a
|
|
427
|
+
// replay that loops round to its start forgets them, as it does a highlight.
|
|
428
|
+
// A step's highlight is kept here once it has opened, so it is once per
|
|
429
|
+
// cycle, step and title across a reload too.
|
|
430
|
+
|
|
431
|
+
/** Where the visit's closed modals are kept (sessionStorage). */
|
|
432
|
+
export const DISMISS_STORE = "behold.eventHelp.closed";
|
|
433
|
+
/** At most this many are kept: the newest. */
|
|
434
|
+
export const DISMISS_MAX = 64;
|
|
435
|
+
|
|
436
|
+
/** What a story modal is about, as one key: kind, cycle, beat, pull request, step and its own key. */
|
|
437
|
+
export function dismissKey(kind, demo, key) {
|
|
438
|
+
const d = demo || {};
|
|
439
|
+
return [kind, d.cycle ?? "", d.beat || "", d.pull ?? "", d.step || "", key ?? ""].join("|");
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
/** When a step was written, in ms (a replay's `at`, a live step's `started_at`), or null. */
|
|
443
|
+
export const stepWrittenAt = (demo) => writtenAt(demo);
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* The visit's closed modals: `{ has(key), add(key), clear(), keys() }`, kept
|
|
447
|
+
* in `store` (sessionStorage) where it lets them be, in memory where it
|
|
448
|
+
* throws or is missing. Never localStorage: a closed modal is this visit's.
|
|
449
|
+
*/
|
|
450
|
+
export function createDismissals(store = null) {
|
|
451
|
+
let keys = [];
|
|
452
|
+
try {
|
|
453
|
+
const raw = store ? JSON.parse(store.getItem(DISMISS_STORE) || "[]") : [];
|
|
454
|
+
if (Array.isArray(raw)) keys = raw.filter((k) => typeof k === "string").slice(-DISMISS_MAX);
|
|
455
|
+
} catch {
|
|
456
|
+
keys = [];
|
|
457
|
+
}
|
|
458
|
+
const save = () => {
|
|
459
|
+
try {
|
|
460
|
+
if (store) store.setItem(DISMISS_STORE, JSON.stringify(keys));
|
|
461
|
+
} catch {
|
|
462
|
+
/* kept for this page only */
|
|
463
|
+
}
|
|
464
|
+
};
|
|
465
|
+
return {
|
|
466
|
+
has: (key) => keys.includes(key),
|
|
467
|
+
add(key) {
|
|
468
|
+
if (keys.includes(key)) return;
|
|
469
|
+
keys = [...keys, key].slice(-DISMISS_MAX);
|
|
470
|
+
save();
|
|
471
|
+
},
|
|
472
|
+
clear() {
|
|
473
|
+
if (!keys.length) return;
|
|
474
|
+
keys = [];
|
|
475
|
+
save();
|
|
476
|
+
},
|
|
477
|
+
keys: () => [...keys],
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
/**
|
|
482
|
+
* behold#764: whether the "Waiting on…" modal opens now: a wait is up, Tips
|
|
483
|
+
* on, no other modal up or due, the wait not just closed by news (`held`),
|
|
484
|
+
* no details popover open (`pop`), and the viewer has not closed this wait.
|
|
485
|
+
*/
|
|
486
|
+
export function waitingOpens({ waiting = null, on = true, held = false, modal = null, due = false, pop = null, closed = false } = {}) {
|
|
487
|
+
return !!waiting && !!on && !held && !modal && !due && !pop && !closed;
|
|
415
488
|
}
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
// behold#764: "'waiting on pipeline' keeps popping back after shutting and
|
|
2
|
+
// covering the detail overlay". A story modal the viewer closes stays closed
|
|
3
|
+
// for what it was about, across redraws and a reload; and no story modal
|
|
4
|
+
// opens over a card's details popover the viewer has open.
|
|
5
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
6
|
+
import { coversRect, openEventModal } from "./event-help-modal.js";
|
|
7
|
+
import { DISMISS_MAX, DISMISS_STORE, createDismissals, dismissKey, ehStore, highlightOpens, waitingOpens } from "./kiosk-event-help.js";
|
|
8
|
+
import { startEventHelp } from "./kiosk-event-help-ui.js";
|
|
9
|
+
|
|
10
|
+
const HL = { title: "Same orchestration as the commercial platforms", body: "Fifteen OpenTofu states, applied in dependency order." };
|
|
11
|
+
const demo = (step, more = {}) => ({ cycle: 9, scenario: "fan-out", title: "t", step, label: `the ${step} line`, started_at: "2026-10-18T00:00:00Z", next: null, pull: 3, commit: null, ...more });
|
|
12
|
+
const WAIT = { key: "0|0|the pipeline to start the plan", what: "the pipeline to start the plan", why: "Pull request 106 is open.", fraction: 0.3, words: "usually about 21 s" };
|
|
13
|
+
/** A sessionStorage stand-in that outlives one page: what a reload keeps. */
|
|
14
|
+
const session = () => {
|
|
15
|
+
const m = new Map();
|
|
16
|
+
return { getItem: (k) => (m.has(k) ? m.get(k) : null), setItem: (k, v) => m.set(k, String(v)), map: m };
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
describe("the closed modals' keys", () => {
|
|
20
|
+
it("say the kind, the cycle and beat, the pull request, the step and the modal's own key", () => {
|
|
21
|
+
expect(dismissKey("waiting", demo("pull-request"), WAIT.key)).toBe(`waiting|9||3|pull-request|${WAIT.key}`);
|
|
22
|
+
expect(dismissKey("waiting", demo("pull-request", { beat: "fix" }), "k")).not.toBe(dismissKey("waiting", demo("pull-request"), "k"));
|
|
23
|
+
// A new wait: a later step, a new pull request, a new cycle.
|
|
24
|
+
const k = dismissKey("waiting", demo("pull-request"), "k");
|
|
25
|
+
for (const d of [demo("merged"), demo("pull-request", { pull: 4 }), demo("pull-request", { cycle: 10 })]) expect(dismissKey("waiting", d, "k")).not.toBe(k);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("are kept in the store given (sessionStorage), so a new page reads them back", () => {
|
|
29
|
+
const store = session();
|
|
30
|
+
const a = createDismissals(store);
|
|
31
|
+
a.add("x");
|
|
32
|
+
a.add("x");
|
|
33
|
+
expect(JSON.parse(store.getItem(DISMISS_STORE))).toEqual(["x"]);
|
|
34
|
+
expect(createDismissals(store).has("x")).toBe(true);
|
|
35
|
+
a.clear();
|
|
36
|
+
expect(createDismissals(store).has("x")).toBe(false);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("keep the newest DISMISS_MAX, and live in memory where storage throws or holds junk", () => {
|
|
40
|
+
const store = session();
|
|
41
|
+
const a = createDismissals(store);
|
|
42
|
+
for (let i = 0; i < DISMISS_MAX + 5; i++) a.add(`k${i}`);
|
|
43
|
+
expect(a.keys()).toHaveLength(DISMISS_MAX);
|
|
44
|
+
expect(a.has("k0")).toBe(false);
|
|
45
|
+
expect(a.has(`k${DISMISS_MAX + 4}`)).toBe(true);
|
|
46
|
+
const broken = { getItem: () => { throw new Error("blocked"); }, setItem: () => { throw new Error("blocked"); } };
|
|
47
|
+
const b = createDismissals(broken);
|
|
48
|
+
b.add("y");
|
|
49
|
+
expect(b.has("y")).toBe(true);
|
|
50
|
+
store.setItem(DISMISS_STORE, "{not json");
|
|
51
|
+
expect(createDismissals(store).keys()).toEqual([]);
|
|
52
|
+
expect(createDismissals(null).has("z")).toBe(false);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
describe("when a story modal may open", () => {
|
|
57
|
+
it("the waiting one: not over a details popover, not for a wait the viewer closed, not over another modal", () => {
|
|
58
|
+
expect(waitingOpens({ waiting: WAIT })).toBe(true);
|
|
59
|
+
expect(waitingOpens({ waiting: WAIT, pop: { left: 0, top: 0, width: 10, height: 10 } })).toBe(false);
|
|
60
|
+
expect(waitingOpens({ waiting: WAIT, closed: true })).toBe(false);
|
|
61
|
+
expect(waitingOpens({ waiting: WAIT, modal: {} })).toBe(false);
|
|
62
|
+
expect(waitingOpens({ waiting: WAIT, due: true })).toBe(false);
|
|
63
|
+
expect(waitingOpens({ waiting: WAIT, on: false })).toBe(false);
|
|
64
|
+
expect(waitingOpens({ waiting: null })).toBe(false);
|
|
65
|
+
});
|
|
66
|
+
it("a highlight: waits while a details popover is open", () => {
|
|
67
|
+
const pending = { key: "k", ...HL };
|
|
68
|
+
expect(highlightOpens({ pending, on: true, watch: true, pop: { left: 0, top: 0, width: 10, height: 10 } })).toBe(false);
|
|
69
|
+
expect(highlightOpens({ pending, on: true, watch: true, pop: null })).toBe(true);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
describe("Tips: a closed modal stays closed, and none covers the details popover", () => {
|
|
74
|
+
let t;
|
|
75
|
+
beforeEach(() => {
|
|
76
|
+
vi.useFakeTimers();
|
|
77
|
+
t = 1_000_000;
|
|
78
|
+
});
|
|
79
|
+
afterEach(() => vi.useRealTimers());
|
|
80
|
+
const FRAME = { getBoundingClientRect: () => ({ left: 5, top: 77, width: 1356, height: 686, right: 1361, bottom: 763 }) };
|
|
81
|
+
/** One page of the kiosk; `store` is its sessionStorage, which a reload keeps. */
|
|
82
|
+
const page = (store, { pop = null } = {}) => {
|
|
83
|
+
const doc = fakeDoc();
|
|
84
|
+
const view = { demo: demo("pull-request"), watch: true, waiting: WAIT, frame: FRAME, pop };
|
|
85
|
+
const api = startEventHelp({ doc, store: shelf(), session: store, tipsHost: doc.body, modalHost: doc.body, now: () => t, get: () => ({ ...view, strip: null, stripReady: true }), reduced: () => true });
|
|
86
|
+
const modal = (kind) => all(doc.body).find((n) => n.className && n.className.split(" ").includes(`eh-modal-${kind}`));
|
|
87
|
+
const step = (ms = 1_000, more = {}) => {
|
|
88
|
+
Object.assign(view, more);
|
|
89
|
+
t += ms;
|
|
90
|
+
vi.advanceTimersByTime(ms);
|
|
91
|
+
api.tick();
|
|
92
|
+
};
|
|
93
|
+
const closeX = (kind) => {
|
|
94
|
+
const x = all(modal(kind)).find((n) => n.className === "eh-modal-close");
|
|
95
|
+
x.handlers.click.forEach((fn) => fn({}));
|
|
96
|
+
};
|
|
97
|
+
return { api, doc, view, modal, step, closeX };
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
it("the Waiting modal, closed with ×, does not come back on the next looks at the same wait", () => {
|
|
101
|
+
const k = page(session());
|
|
102
|
+
k.step();
|
|
103
|
+
expect(k.modal("waiting")).toBeDefined();
|
|
104
|
+
k.closeX("waiting");
|
|
105
|
+
expect(k.modal("waiting")).toBeUndefined();
|
|
106
|
+
for (let i = 0; i < 60; i++) k.step(1_000);
|
|
107
|
+
expect(k.modal("waiting")).toBeUndefined();
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it("closed with Escape, it stays closed too; a new wait (a later step) opens again", () => {
|
|
111
|
+
const k = page(session());
|
|
112
|
+
k.step();
|
|
113
|
+
k.doc.fire("keydown", { key: "Escape" });
|
|
114
|
+
k.step(5_000);
|
|
115
|
+
expect(k.modal("waiting")).toBeUndefined();
|
|
116
|
+
k.step(1_000, { demo: demo("merged"), waiting: { ...WAIT, key: "0|2|the pipeline to apply" } });
|
|
117
|
+
expect(k.modal("waiting")).toBeDefined();
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it("a close by the page (news, the wait ending) is no viewer's: the same wait may open again", () => {
|
|
121
|
+
const k = page(session());
|
|
122
|
+
k.step();
|
|
123
|
+
k.step(1_000, { waiting: null });
|
|
124
|
+
expect(k.modal("waiting")).toBeUndefined();
|
|
125
|
+
k.step(1_000, { waiting: WAIT });
|
|
126
|
+
expect(k.modal("waiting")).toBeDefined();
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it("survives a reload: the next page, with the same session, does not reopen the wait the viewer closed", () => {
|
|
130
|
+
const store = session();
|
|
131
|
+
const first = page(store);
|
|
132
|
+
first.step();
|
|
133
|
+
first.closeX("waiting");
|
|
134
|
+
const again = page(store);
|
|
135
|
+
for (let i = 0; i < 10; i++) again.step(1_000);
|
|
136
|
+
expect(again.modal("waiting")).toBeUndefined();
|
|
137
|
+
// A fresh visit (a new session) opens it.
|
|
138
|
+
const fresh = page(session());
|
|
139
|
+
fresh.step();
|
|
140
|
+
expect(fresh.modal("waiting")).toBeDefined();
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it("a step's highlight is once per cycle, step and title across a reload too", () => {
|
|
144
|
+
const store = session();
|
|
145
|
+
const first = page(store);
|
|
146
|
+
first.step(1_000, { demo: demo("failed", { highlight: HL }), waiting: null });
|
|
147
|
+
expect(first.modal("highlight")).toBeDefined();
|
|
148
|
+
first.closeX("highlight");
|
|
149
|
+
const again = page(store);
|
|
150
|
+
again.step(1_000, { demo: demo("failed", { highlight: HL }), waiting: null });
|
|
151
|
+
again.step(1_000);
|
|
152
|
+
expect(again.modal("highlight")).toBeUndefined();
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it("a replay looping round forgets what was closed: its wait opens again", () => {
|
|
156
|
+
const k = page(session());
|
|
157
|
+
k.step(1_000, { demo: demo("pull-request", { at: "2026-10-18T00:00:10Z" }) });
|
|
158
|
+
k.closeX("waiting");
|
|
159
|
+
k.step(1_000);
|
|
160
|
+
expect(k.modal("waiting")).toBeUndefined();
|
|
161
|
+
k.step(1_000, { demo: demo("pull-request", { at: "2026-10-18T00:00:00Z" }) });
|
|
162
|
+
expect(k.modal("waiting")).toBeDefined();
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it("opens no story modal while a card's details popover is open; the one held back opens once it closes", () => {
|
|
166
|
+
const k = page(session(), { pop: { x: 600, y: 80, w: 412, h: 141 } });
|
|
167
|
+
for (let i = 0; i < 5; i++) k.step(1_000);
|
|
168
|
+
expect(k.modal("waiting")).toBeUndefined();
|
|
169
|
+
k.step(1_000, { demo: demo("failed", { highlight: HL }), waiting: null });
|
|
170
|
+
expect(k.modal("highlight")).toBeUndefined();
|
|
171
|
+
k.step(1_000, { pop: null });
|
|
172
|
+
expect(k.modal("highlight")).toBeDefined();
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
describe("a modal already up when the details popover opens", () => {
|
|
177
|
+
/** A box the size of a modal, in the middle of a 1366x768 window. */
|
|
178
|
+
const layoutDoc = () => {
|
|
179
|
+
const doc = fakeDoc();
|
|
180
|
+
doc.defaultView = { innerWidth: 1366, innerHeight: 768 };
|
|
181
|
+
const make = doc.createElement;
|
|
182
|
+
doc.createElement = (tag) => {
|
|
183
|
+
const n = make(tag);
|
|
184
|
+
n.getBoundingClientRect = () => ({ left: 383, top: 284, width: 600, height: 200 });
|
|
185
|
+
return n;
|
|
186
|
+
};
|
|
187
|
+
return doc;
|
|
188
|
+
};
|
|
189
|
+
const classes = (n) => n.classes;
|
|
190
|
+
it("moves clear of it, its sheet no longer over it", () => {
|
|
191
|
+
const doc = layoutDoc();
|
|
192
|
+
let keep = null;
|
|
193
|
+
const timers = [];
|
|
194
|
+
openEventModal(doc.body, { mode: "narrated", kind: "waiting", data: { title: "Waiting on the pipeline", lines: [], keepClear: () => keep }, doc, now: () => 0, setTimer: (fn) => timers.push(fn), clearTimer() {} });
|
|
195
|
+
const wrap = doc.body.children[0];
|
|
196
|
+
const box = wrap.children[0];
|
|
197
|
+
expect(classes(wrap).has("eh-modal-keep")).toBe(false);
|
|
198
|
+
// The popover opens under the middle of the window, where the modal stands; the modal's next tick moves it.
|
|
199
|
+
keep = { left: 500, top: 300, width: 300, height: 140 };
|
|
200
|
+
timers.forEach((fn) => fn());
|
|
201
|
+
expect(classes(wrap).has("eh-modal-keep")).toBe(true);
|
|
202
|
+
expect(classes(wrap).has("eh-modal-placed")).toBe(true);
|
|
203
|
+
const at = { left: Number.parseFloat(box.style.marginLeft), top: Number.parseFloat(box.style.marginTop), width: 600, height: 200 };
|
|
204
|
+
expect(coversRect(at, keep)).toBe(false);
|
|
205
|
+
expect(classes(wrap).has("eh-modal-yield")).toBe(false);
|
|
206
|
+
// It closes: the modal goes back to the middle.
|
|
207
|
+
keep = null;
|
|
208
|
+
timers.forEach((fn) => fn());
|
|
209
|
+
expect(classes(wrap).has("eh-modal-keep")).toBe(false);
|
|
210
|
+
expect(classes(wrap).has("eh-modal-placed")).toBe(false);
|
|
211
|
+
expect(box.style.marginLeft).toBe("");
|
|
212
|
+
});
|
|
213
|
+
it("steps out of sight, its time held, where no spot clears it", () => {
|
|
214
|
+
const doc = layoutDoc();
|
|
215
|
+
const keep = { left: 0, top: 0, width: 1366, height: 768 };
|
|
216
|
+
let now = 0;
|
|
217
|
+
const timers = [];
|
|
218
|
+
const m = openEventModal(doc.body, { mode: "narrated", kind: "highlight", data: { title: "h", lines: [], closeAfter: 1_000, keepClear: () => keep }, doc, now: () => now, setTimer: (fn) => timers.push(fn), clearTimer() {} });
|
|
219
|
+
const wrap = doc.body.children[0];
|
|
220
|
+
expect(classes(wrap).has("eh-modal-yield")).toBe(true);
|
|
221
|
+
now = 5_000;
|
|
222
|
+
timers.forEach((fn) => fn());
|
|
223
|
+
expect(m.state.closed).toBe(false);
|
|
224
|
+
expect(m.state.closedBy).toBeUndefined();
|
|
225
|
+
m.close();
|
|
226
|
+
expect(m.state.closedBy).toBe("page");
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
/** Just enough of a DOM for Tips and its modal (kiosk-highlight.test.js's, with a classList that keeps its classes). */
|
|
231
|
+
function fakeDoc() {
|
|
232
|
+
const listeners = {};
|
|
233
|
+
const make = (tag) => {
|
|
234
|
+
const classes = new Set();
|
|
235
|
+
const n = {
|
|
236
|
+
tagName: tag.toUpperCase(),
|
|
237
|
+
children: [],
|
|
238
|
+
handlers: {},
|
|
239
|
+
textContent: "",
|
|
240
|
+
dataset: {},
|
|
241
|
+
classes,
|
|
242
|
+
style: { setProperty() {} },
|
|
243
|
+
classList: {
|
|
244
|
+
toggle: (c, on) => ((on === undefined ? !classes.has(c) : on) ? classes.add(c) : classes.delete(c)),
|
|
245
|
+
add: (...cs) => cs.forEach((c) => classes.add(c)),
|
|
246
|
+
remove: (...cs) => cs.forEach((c) => classes.delete(c)),
|
|
247
|
+
contains: (c) => classes.has(c),
|
|
248
|
+
},
|
|
249
|
+
appendChild(c) {
|
|
250
|
+
c.parent = n;
|
|
251
|
+
n.children.push(c);
|
|
252
|
+
return c;
|
|
253
|
+
},
|
|
254
|
+
append(...cs) {
|
|
255
|
+
cs.forEach((c) => typeof c === "object" && n.appendChild(c));
|
|
256
|
+
},
|
|
257
|
+
prepend(c) {
|
|
258
|
+
n.appendChild(c);
|
|
259
|
+
},
|
|
260
|
+
replaceChildren() {
|
|
261
|
+
n.children = [];
|
|
262
|
+
},
|
|
263
|
+
setAttribute() {},
|
|
264
|
+
addEventListener(ev, fn) {
|
|
265
|
+
(n.handlers[ev] ||= []).push(fn);
|
|
266
|
+
},
|
|
267
|
+
querySelector: () => null,
|
|
268
|
+
remove() {
|
|
269
|
+
if (n.parent) n.parent.children = n.parent.children.filter((x) => x !== n);
|
|
270
|
+
},
|
|
271
|
+
};
|
|
272
|
+
// className is the classList's words, as the DOM's is.
|
|
273
|
+
Object.defineProperty(n, "className", { get: () => [...classes].join(" "), set: (v) => { classes.clear(); String(v).split(/\s+/).filter(Boolean).forEach((c) => classes.add(c)); } });
|
|
274
|
+
return n;
|
|
275
|
+
};
|
|
276
|
+
return {
|
|
277
|
+
createElement: make,
|
|
278
|
+
head: make("head"),
|
|
279
|
+
body: make("body"),
|
|
280
|
+
getElementById: () => null,
|
|
281
|
+
querySelectorAll: () => [],
|
|
282
|
+
addEventListener: (ev, fn) => ((listeners[ev] ||= []).push(fn)),
|
|
283
|
+
removeEventListener(ev, fn) {
|
|
284
|
+
listeners[ev] = (listeners[ev] || []).filter((x) => x !== fn);
|
|
285
|
+
},
|
|
286
|
+
fire: (ev, e) => (listeners[ev] || []).forEach((fn) => fn(e)),
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
const all = (n) => (n ? [n, ...n.children.flatMap(all)] : []);
|
|
290
|
+
const shelf = () => {
|
|
291
|
+
const m = new Map();
|
|
292
|
+
ehStore({ setItem: (k, v) => m.set(k, v) }, true);
|
|
293
|
+
return { getItem: (k) => (m.has(k) ? m.get(k) : null), setItem: (k, v) => m.set(k, v) };
|
|
294
|
+
};
|
package/web/kiosk-popover.js
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
import { PICK_HOLD_MS } from "./kiosk-runs.js";
|
|
14
14
|
import { clock } from "./terragucci.js";
|
|
15
|
+
import { placeFloat } from "./float-place.js";
|
|
15
16
|
|
|
16
17
|
/** How many attribute lines the popover shows before "and N more". */
|
|
17
18
|
export const MAX_LINES = 6;
|
|
@@ -208,28 +209,11 @@ export function popReduce(s, ev, now) {
|
|
|
208
209
|
* that side, as near the card's top (or left) as the frame allows. When no
|
|
209
210
|
* side fits, the side with the most room, kept inside the frame. All boxes
|
|
210
211
|
* are `{ left, top, width, height }` in the frame's pixels.
|
|
212
|
+
* behold#764: the shared placement (web/float-place.js), so a card at the
|
|
213
|
+
* frame's very top never puts it off the top, and a popover taller than the
|
|
214
|
+
* frame gets `maxHeight` and scrolls.
|
|
211
215
|
*/
|
|
212
216
|
export function placePopover(card, pop, frame, { gap = 12, margin = 8 } = {}) {
|
|
213
|
-
const
|
|
214
|
-
|
|
215
|
-
const bottom = card.top + card.height;
|
|
216
|
-
const room = {
|
|
217
|
-
right: frame.width - margin - (right + gap),
|
|
218
|
-
left: card.left - gap - margin,
|
|
219
|
-
below: frame.height - margin - (bottom + gap),
|
|
220
|
-
above: card.top - gap - margin,
|
|
221
|
-
};
|
|
222
|
-
const at = (side) => {
|
|
223
|
-
if (side === "right") return { left: right + gap, top: clamp(card.top, margin, frame.height - margin - pop.height), side };
|
|
224
|
-
if (side === "left") return { left: card.left - gap - pop.width, top: clamp(card.top, margin, frame.height - margin - pop.height), side };
|
|
225
|
-
if (side === "below") return { left: clamp(card.left, margin, frame.width - margin - pop.width), top: bottom + gap, side };
|
|
226
|
-
return { left: clamp(card.left, margin, frame.width - margin - pop.width), top: card.top - gap - pop.height, side };
|
|
227
|
-
};
|
|
228
|
-
if (room.right >= pop.width) return at("right");
|
|
229
|
-
if (room.left >= pop.width) return at("left");
|
|
230
|
-
if (room.below >= pop.height) return at("below");
|
|
231
|
-
if (room.above >= pop.height) return at("above");
|
|
232
|
-
const best = Object.entries({ right: room.right / pop.width, left: room.left / pop.width, below: room.below / pop.height, above: room.above / pop.height }).sort((a, b) => b[1] - a[1])[0][0];
|
|
233
|
-
const p = at(best);
|
|
234
|
-
return { left: clamp(p.left, margin, frame.width - margin - pop.width), top: clamp(p.top, margin, frame.height - margin - pop.height), side: best };
|
|
217
|
+
const view = { left: frame.left || 0, top: frame.top || 0, width: frame.width, height: frame.height };
|
|
218
|
+
return placeFloat(card, pop, view, { gap, margin });
|
|
235
219
|
}
|
package/web/kiosk-watch.js
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
import { STEP_WORDS, focusRoots, matchingPull, matchingRun, scenarioHead, introText, aboutRows, nextWords, demoStage } from "./kiosk.js";
|
|
15
15
|
import { defaultJob, defaultStep, logLineWords, setupLine } from "./kiosk-runs.js";
|
|
16
16
|
import { backendLine, coneLine, coneOf } from "./cone.js";
|
|
17
|
+
import { placeFloat } from "./float-place.js";
|
|
17
18
|
|
|
18
19
|
/** The two modes, Watch first: it is the default. */
|
|
19
20
|
export const MODES = [
|
|
@@ -356,20 +357,26 @@ export function tailLines(runDoc, n = 2) {
|
|
|
356
357
|
/**
|
|
357
358
|
* Where an overlay of `size` goes beside `box` inside `view` (all pixels,
|
|
358
359
|
* `{x, y, w, h}`): to the right of the box when it fits, else to its left,
|
|
359
|
-
* else under it; its top level with the box's, kept inside the
|
|
360
|
-
* right it moves past any of `avoid` (the reads' labels) it
|
|
361
|
-
* `{ x, y, side }`, `side` "right", "left" or "
|
|
360
|
+
* else under it, else over it; its top level with the box's, kept inside the
|
|
361
|
+
* view. On the right it moves past any of `avoid` (the reads' labels) it
|
|
362
|
+
* would cover. `{ x, y, side }`, `side` "right", "left", "below" or "above".
|
|
363
|
+
* behold#764: never past the view's top or bottom. The job box's log drawer,
|
|
364
|
+
* opened, is taller than the graph above the caption at 1366x768, and was
|
|
365
|
+
* lifted 94px off the top; now it keeps the view's top, with `maxHeight` (the
|
|
366
|
+
* caller caps it there and its log scrolls) when it is taller than the view.
|
|
367
|
+
* No side with room: the side with the most (web/float-place.js).
|
|
362
368
|
*/
|
|
363
369
|
export function placeBeside(box, size, view, gap = 18, avoid = []) {
|
|
364
|
-
const
|
|
370
|
+
const fit = placeFloat({ left: box.x, top: box.y, width: box.w, height: box.h }, { width: size.w, height: size.h }, { left: view.x, top: view.y, width: view.w, height: view.h }, { sides: ["left", "below", "above", "right"], gap, margin: 8 });
|
|
371
|
+
const cap = fit.maxHeight ? { maxHeight: fit.maxHeight } : {};
|
|
372
|
+
const h = fit.maxHeight || size.h;
|
|
373
|
+
const top = Math.max(view.y + 8, Math.min(box.y, view.y + view.h - h - 8));
|
|
365
374
|
// Clear of the graph's own labels beside the box: past the right edge of any it would cover.
|
|
366
|
-
const over = (x) => avoid.filter((a) => a.x < x + size.w && a.x + a.w > x && a.y < top +
|
|
375
|
+
const over = (x) => avoid.filter((a) => a.x < x + size.w && a.x + a.w > x && a.y < top + h && a.y + a.h > top);
|
|
367
376
|
let right = box.x + box.w + gap;
|
|
368
377
|
for (let i = 0; i < 4 && over(right).length; i++) right = Math.max(...over(right).map((a) => a.x + a.w)) + gap / 2;
|
|
369
|
-
if (right + size.w <= view.x + view.w - 8) return { x: right, y: top, side: "right" };
|
|
370
|
-
|
|
371
|
-
const x = Math.max(view.x + 8, Math.min(box.x, view.x + view.w - size.w - 8));
|
|
372
|
-
return { x, y: Math.min(box.y + box.h + gap, view.y + view.h - size.h - 8), side: "below" };
|
|
378
|
+
if (right + size.w <= view.x + view.w - 8) return { x: right, y: top, side: "right", ...cap };
|
|
379
|
+
return { x: fit.left, y: fit.top, side: fit.side, ...cap };
|
|
373
380
|
}
|
|
374
381
|
|
|
375
382
|
// ---------------------------------------------------------------------------
|