@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
@@ -3,7 +3,13 @@
3
3
  // ring, a move flies, a refusal bounces; lines play from when they were seen.
4
4
  import { describe, it, expect } from "vitest";
5
5
  import { liveShow, stampArrivals, lineKey, showKey, currentMigration, carveDrawable, boxName, LIVE } from "./dots-live.js";
6
- import { buildScene, takeoffsBy } from "./dots-scene.js";
6
+ import { buildScene, takeoffsBy, cardGridShape, focusRect, cardsReadable, BOX } from "./dots-scene.js";
7
+ import { directorScale } from "./dots-lod.js";
8
+ import { tourFocus } from "./dots-tour.js";
9
+ import { readFileSync } from "node:fs";
10
+ import { fileURLToPath } from "node:url";
11
+ import { gridScale, gridSlots, unitKeyOf, GRID } from "./dots-cards.js";
12
+ import { SMALL_STAGE, tourGlow } from "./dots.js";
7
13
  import { liveBeat, liveTipsBetween, liveEndTip } from "./dots-kiosk.js";
8
14
  import { dotsCarving, dotsActive } from "./dots.js";
9
15
 
@@ -218,3 +224,147 @@ describe("an adoption, a split, and the team rosters written after it", () => {
218
224
  expect(ends).toEqual({ "tl11-team-a": 3, terralith: 1 });
219
225
  });
220
226
  });
227
+
228
+ describe("a small stage, laid out for its cards", () => {
229
+ it("picks the columns that bring a card grid nearest the stage's shape", () => {
230
+ const g = cardGridShape(14, { cell: 6, aspect: 3.2, target: 1.9 });
231
+ expect([g.cols, g.h]).toEqual([3, 30]);
232
+ expect(g.w).toBeCloseTo(57.6);
233
+ expect(cardGridShape(14, { cell: 6, aspect: 3.2, target: 0.9 }).cols).toBe(2);
234
+ expect(cardGridShape(0, { cell: 6, aspect: 3.2 }).cols).toBe(1);
235
+ });
236
+ it("gives each box its whole card grid at the small stage's cell, which holds through the carve", () => {
237
+ const a = answer([adopt, split([moveA, followA, refuseB])]);
238
+ const show = liveShow(a, stampArrivals(a, new Map(), T + 20_000, { first: true }), T + 20_000);
239
+ const wide = buildScene(show, { sourceAspect: 1, cardGrid: SMALL_STAGE, avail: { w: 1600, h: 500 } });
240
+ const plain = buildScene(show, { sourceAspect: 1 });
241
+ const src = wide.layoutAt(0).boxes.get(show.source);
242
+ // Wider than the dots alone need, in the stage's shape.
243
+ expect(src.w).toBeGreaterThan(plain.layoutAt(0).boxes.get(show.source).w);
244
+ expect(src.w / src.h).toBeGreaterThan(1);
245
+ const n = wide.landing.length;
246
+ const layouts = [0, n].map((k) => wide.layoutAt(k));
247
+ expect(gridScale(layouts, unitKeyOf(wide.rosterBy), { maxK: SMALL_STAGE.cell })).toBeCloseTo(SMALL_STAGE.cell);
248
+ // The source box keeps its size as resources leave, so no card moves for a box resizing.
249
+ const end = wide.layoutAt(n).boxes.get(show.source);
250
+ expect([end.w, end.h]).toEqual([src.w, src.h]);
251
+ // Every card's cell sits inside its box.
252
+ for (const L of layouts) {
253
+ const slots = gridSlots(L, SMALL_STAGE.cell, unitKeyOf(wide.rosterBy));
254
+ for (const [addr, p] of slots) {
255
+ const b = L.boxes.get(L.owners.get(addr));
256
+ expect(p.x).toBeGreaterThanOrEqual(b.x + BOX.pad);
257
+ expect(p.x).toBeLessThanOrEqual(b.x + b.w - BOX.pad);
258
+ expect(p.y).toBeLessThanOrEqual(b.y + b.h);
259
+ }
260
+ }
261
+ expect(SMALL_STAGE.aspect).toBe(GRID.aspect);
262
+ });
263
+ it("leaves a big estate's boxes as the dots need them", () => {
264
+ const big = { ...stock, count: 60, resources: Array.from({ length: 60 }, (_, i) => ({ address: `aws_s3_bucket.b${i}`, type: "aws_s3_bucket", marked: false })) };
265
+ const a = answer([], [big]);
266
+ const show = liveShow(a, stampArrivals(a, new Map(), T, { first: true }), T);
267
+ const g = buildScene(show, { sourceAspect: 1, cardGrid: SMALL_STAGE, avail: { w: 1600, h: 500 } });
268
+ const p = buildScene(show, { sourceAspect: 1 });
269
+ expect(g.layoutAt(0).boxes.get(show.source)).toEqual(p.layoutAt(0).boxes.get(show.source));
270
+ });
271
+ });
272
+
273
+ describe("every chapter of the terralith tour frames a small carve as cards", () => {
274
+ // The thin terralith (terragucci#1155): 14 resources, team B's 5 carved out alone.
275
+ const team = ["aws_iam_role.app", "aws_iam_role_policy.inline", "aws_cloudwatch_log_group.app", "aws_s3_bucket.data", "aws_sqs_queue.jobs"].map((a) => `module.team_b.${a}`);
276
+ const rest = Array.from({ length: 9 }, (_, i) => `aws_s3_bucket.shared_${i}`);
277
+ const thin = { estate: "terralith", at: at(-60), count: 14, resources: [...rest, ...team].map((address) => ({ address, type: address.split(".").slice(-2)[0], marked: false })) };
278
+ const carve = { name: "split", running: false, counts: { moved: 5, stamped: 0, refused: 0, skipped: 0, left: 0 }, lines: team.map((address, i) => ({ at: at(10 + i), estate_from: "terralith", estate_to: "team-b", address, live_id: `b-${i}`, outcome: "moved" })) };
279
+ const tour = JSON.parse(readFileSync(fileURLToPath(new URL("./tours/terralith.json", import.meta.url)), "utf8"));
280
+ // Watch at 1280x800 (the frame's measurements on the live loop): the stage the director frames in, and the area
281
+ // the scene is laid out for, both clear of the tour's caption; a card name's width; one pitch's px at the dots cap.
282
+ const stage = { w: 1088, h: 494 };
283
+ const avail = { w: 914, h: 478 };
284
+ const need = 150;
285
+ const dotsCapPP = 7;
286
+ const cardWP = SMALL_STAGE.cell * (GRID.aspect - GRID.gap);
287
+ it("in each chapter's focus, at each beat's start and end", () => {
288
+ const a = answer([carve], [thin]);
289
+ const show = liveShow(a, stampArrivals(a, new Map(), T + 30_000, { first: true }), T + 30_000);
290
+ expect(show.roster.length).toBeLessThanOrEqual(SMALL_STAGE.max);
291
+ const scene = buildScene(show, { sourceAspect: 1, cardGrid: SMALL_STAGE, avail });
292
+ // A beat's start (nothing moved yet) and its end (every move landed).
293
+ const ends = [0, 1e15];
294
+ for (const ch of tour.chapters) {
295
+ // The chapter's visuals as the tour has them once fired: a light lit on team B's resources, the changed one first.
296
+ const shown = (ch.show || []).filter((s) => s.light).map(() => ({ kind: "light", lit: team.map((address, i) => ({ address, estates: ["team-b"], changed: i === 1 })) }));
297
+ const focus = tourFocus({ at: { chapter: ch }, shown }, scene.estates, []);
298
+ expect(["all", "source", "box"]).toContain(focus.kind);
299
+ if (ch.id === "team") expect(focus).toEqual({ kind: "box", estate: "team-b" });
300
+ for (const t of ends) {
301
+ for (const f of [focus, { kind: "estate", estate: "team-b" }, { kind: "source" }]) {
302
+ const r = focusRect(scene, f, t);
303
+ const fit = Math.min(stage.w / (r.w + 7), stage.h / (r.h + 7));
304
+ const s = directorScale({ fit, dotsCap: dotsCapPP, cardsAt: (need * 1.1) / cardWP, small: true });
305
+ // Framed past the dots cap, with each card wide enough to read its name, or nearly.
306
+ expect(s, `${ch.id} ${f.kind} at ${t}`).toBeGreaterThan(dotsCapPP);
307
+ expect(s * cardWP, `${ch.id} ${f.kind} at ${t}`).toBeGreaterThan(need * 0.85);
308
+ }
309
+ }
310
+ }
311
+ });
312
+ it("lights the team beat's changed card and dims the rest of what the plan planned", () => {
313
+ expect(tourGlow({ changed: true }, true, "c")).toEqual({ colour: "c", a: 1, ring: true, dim: false });
314
+ expect(tourGlow({ changed: false }, true, "c")).toMatchObject({ dim: true, ring: false });
315
+ expect(tourGlow({ changed: false }, true, "c").a).toBeLessThan(tourGlow({ changed: false }, false, "c").a);
316
+ // A plan that changes nothing it planned: every planned card lit alike.
317
+ expect(tourGlow({ changed: false }, false, "c")).toMatchObject({ dim: false, a: 0.85 });
318
+ });
319
+ it("spreads each dot to its card's cell, never piled in a corner of the box, at a beat's start and end", () => {
320
+ const a = answer([carve], [thin]);
321
+ const show = liveShow(a, stampArrivals(a, new Map(), T + 30_000, { first: true }), T + 30_000);
322
+ const scene = buildScene(show, { sourceAspect: 1, cardGrid: SMALL_STAGE, avail });
323
+ for (const k of [0, scene.landing.length]) {
324
+ const L = scene.layoutAt(k);
325
+ const by = new Map();
326
+ for (const [addr, s] of L.slots) {
327
+ const e = L.owners.get(addr);
328
+ const b = L.boxes.get(e);
329
+ expect(s.x).toBeGreaterThan(b.x);
330
+ expect(s.x).toBeLessThan(b.x + b.w);
331
+ expect(s.y).toBeGreaterThan(b.y);
332
+ expect(s.y).toBeLessThan(b.y + b.h);
333
+ if (!by.has(e)) by.set(e, []);
334
+ by.get(e).push(s);
335
+ }
336
+ for (const [e, list] of by) {
337
+ // One cell apart at least, and the cluster spans the box, not a corner of it.
338
+ for (let i = 0; i < list.length; i++) for (let j = i + 1; j < list.length; j++) expect(Math.hypot(list[i].x - list[j].x, list[i].y - list[j].y)).toBeGreaterThanOrEqual(SMALL_STAGE.cell - 1e-6);
339
+ const b = L.boxes.get(e);
340
+ const xs = list.map((s) => s.x);
341
+ const cx = (Math.min(...xs) + Math.max(...xs)) / 2;
342
+ expect(Math.abs(cx - (b.x + b.w / 2))).toBeLessThan(SMALL_STAGE.cell);
343
+ }
344
+ // The cards land on the dots' own cells: no slide inside the box.
345
+ const cards = gridSlots(L, SMALL_STAGE.cell, unitKeyOf(scene.rosterBy));
346
+ for (const [addr, c] of cards) {
347
+ expect(c.x).toBeCloseTo(L.slots.get(addr).x);
348
+ expect(c.y).toBeCloseTo(L.slots.get(addr).y);
349
+ }
350
+ }
351
+ });
352
+ it("keeps the dots on a stage too narrow for the cards to read: a phone, the in-between widths", () => {
353
+ const a = answer([carve], [thin]);
354
+ const show = liveShow(a, stampArrivals(a, new Map(), T + 30_000, { first: true }), T + 30_000);
355
+ const scene = buildScene(show, { sourceAspect: 1, cardGrid: SMALL_STAGE, avail });
356
+ // The Watch stage at 1280x800 and 1920x1080 reads; a phone (390 wide, its graph 40vh) and a 768 tablet do not.
357
+ expect(cardsReadable(scene, { w: 1088, h: 494 }, need)).toBe(true);
358
+ expect(cardsReadable(scene, { w: 1738, h: 700 }, need)).toBe(true);
359
+ expect(cardsReadable(scene, { w: 208, h: 320 }, need)).toBe(false);
360
+ expect(cardsReadable(scene, { w: 586, h: 420 }, need)).toBe(false);
361
+ // The width where it turns follows from the card's readable width, not a breakpoint: longer names need more.
362
+ let w = 200;
363
+ while (!cardsReadable(scene, { w, h: 2000 }, need)) w += 10;
364
+ let w2 = 200;
365
+ while (!cardsReadable(scene, { w: w2, h: 2000 }, need * 1.4)) w2 += 10;
366
+ expect(w2).toBeGreaterThan(w);
367
+ // A scene laid out for the dots alone is never a small stage.
368
+ expect(cardsReadable(buildScene(show, { sourceAspect: 1 }), { w: 4000, h: 4000 }, need)).toBe(false);
369
+ });
370
+ });
package/web/dots-lod.js CHANGED
@@ -120,3 +120,23 @@ export function railPos(vbW, marks) {
120
120
  if (vbW <= marks.resources) return Math.max(0, Math.min(0.5, (0.5 * (l(vbW) - l(marks.cards))) / (l(marks.resources) - l(marks.cards))));
121
121
  return Math.max(0.5, Math.min(1, 0.5 + (0.5 * (l(vbW) - l(marks.resources))) / (l(marks.estates) - l(marks.resources))));
122
122
  }
123
+
124
+ /** How much past the legible card size the director may frame a small stage: enough to fill it, not so much that a card is a poster. */
125
+ export const CARDS_FRAME_GROW = 1.6;
126
+
127
+ /**
128
+ * The director's zoom (screen px per viewBox unit) for a box it frames.
129
+ * `fit`: the zoom that fits the box in the stage; `dotsCap`: the closest it
130
+ * goes while dots must stay dots; `cardsAt`: the zoom at which each card is
131
+ * wide enough to read its name (the rail's Cards mark), or null when the
132
+ * layer draws no cards. A few resources fit the stage at that zoom: the
133
+ * director frames them as cards, up to CARDS_FRAME_GROW past it. `small`: a
134
+ * small stage (web/dots.js SMALL_STAGE), framed at the zoom that fits even
135
+ * when its cards are still part way to dots, never at the dots cap, which
136
+ * would leave it a third of the size that fits. A big estate keeps the dots
137
+ * framing.
138
+ */
139
+ export function directorScale({ fit, dotsCap, cardsAt = null, small = false, grow = CARDS_FRAME_GROW }) {
140
+ if (cardsAt > 0 && (small || fit >= cardsAt)) return Math.min(fit, cardsAt * grow);
141
+ return Math.min(fit, dotsCap);
142
+ }
@@ -1,5 +1,5 @@
1
1
  import { describe, it, expect } from "vitest";
2
- import { LOD, bandT, smooth, cardMorph, discMorph, morphPoint, discRadius, levelOf, caption, railMarks, railPos } from "./dots-lod.js";
2
+ import { CARDS_FRAME_GROW, LOD, bandT, smooth, cardMorph, discMorph, morphPoint, discRadius, levelOf, caption, railMarks, railPos, directorScale } from "./dots-lod.js";
3
3
 
4
4
  describe("dots level of detail (#712)", () => {
5
5
  it("is a card at or above the card size and a dot at or below the dot size", () => {
@@ -76,3 +76,21 @@ describe("dots level of detail (#712)", () => {
76
76
  expect(railPos(m.estates * 10, m)).toBe(1);
77
77
  });
78
78
  });
79
+
80
+ describe("the director's zoom", () => {
81
+ it("frames a stage that fits at the Cards level as cards, and a big one as dots", () => {
82
+ // 14 resources: the boxes fit at 3x, the cards read from 1.2x.
83
+ expect(directorScale({ fit: 3, dotsCap: 0.4, cardsAt: 1.2 })).toBeCloseTo(1.2 * CARDS_FRAME_GROW);
84
+ expect(directorScale({ fit: 1.5, dotsCap: 0.4, cardsAt: 1.2 })).toBe(1.5);
85
+ // A big estate only fits far out: dots, as before.
86
+ expect(directorScale({ fit: 0.3, dotsCap: 0.4, cardsAt: 1.2 })).toBe(0.3);
87
+ expect(directorScale({ fit: 0.9, dotsCap: 0.4, cardsAt: 1.2 })).toBe(0.4);
88
+ // No cards drawn: the dots cap holds.
89
+ expect(directorScale({ fit: 3, dotsCap: 0.4, cardsAt: null })).toBe(0.4);
90
+ // A small stage whose cards don't quite reach legible size is framed at the zoom that fits, not a third of it
91
+ // (the live terralith: fit 0.33, dots cap 0.1, cards legible at 0.41).
92
+ expect(directorScale({ fit: 0.33, dotsCap: 0.1, cardsAt: 0.41, small: true })).toBe(0.33);
93
+ expect(directorScale({ fit: 0.33, dotsCap: 0.1, cardsAt: 0.41 })).toBe(0.1);
94
+ expect(directorScale({ fit: 3, dotsCap: 0.1, cardsAt: 0.41, small: true })).toBeCloseTo(0.41 * CARDS_FRAME_GROW);
95
+ });
96
+ });
package/web/dots-scene.js CHANGED
@@ -121,6 +121,59 @@ export function choreograph(show, opts = {}) {
121
121
  return once;
122
122
  }
123
123
 
124
+ /**
125
+ * The inner rect a small estate's card grid needs, in pitches: `n` cells
126
+ * `aspect` cell heights wide and `cell` pitches high, in the number of
127
+ * columns that brings the grid nearest `target` (width / height). `{ w, h, cols }`.
128
+ */
129
+ export function cardGridShape(n, { cell, aspect, target = 1.6 }) {
130
+ const m = Math.max(1, n);
131
+ let best = null;
132
+ for (let c = 1; c <= m; c++) {
133
+ const w = c * aspect * cell;
134
+ const h = Math.ceil(m / c) * cell;
135
+ const off = Math.abs(Math.log(w / h / target));
136
+ if (!best || off < best.off - 1e-9) best = { w, h, cols: c, off };
137
+ }
138
+ return { w: best.w, h: best.h, cols: best.cols };
139
+ }
140
+
141
+ /**
142
+ * A small stage's card cells for an estate's resources, in pitches: rows of
143
+ * cells `aspect * cell` wide and `cell` high, centred in the inner rect `r`,
144
+ * in unit order then address, as web/dots-cards.js gridSlots lays the cards.
145
+ */
146
+ export function gridCells(rows, r, { cell, aspect }) {
147
+ const out = new Map();
148
+ const list = [...rows].sort((a, b) => {
149
+ const ka = unitOf(a.address, a.type);
150
+ const kb = unitOf(b.address, b.type);
151
+ return ka < kb ? -1 : ka > kb ? 1 : a.address < b.address ? -1 : a.address > b.address ? 1 : 0;
152
+ });
153
+ const n = list.length;
154
+ if (!n) return out;
155
+ const cw = aspect * cell;
156
+ const cols = Math.max(1, Math.min(n, Math.floor(r.w / cw + 1e-9)));
157
+ const nr = Math.ceil(n / cols);
158
+ const x0 = r.x + (r.w - cols * cw) / 2;
159
+ const y0 = r.y + Math.max(0, (r.h - nr * cell) / 2);
160
+ list.forEach((m, i) => out.set(m.address, { x: x0 + ((i % cols) + 0.5) * cw, y: y0 + (Math.floor(i / cols) + 0.5) * cell }));
161
+ return out;
162
+ }
163
+
164
+ /**
165
+ * Whether a small stage's cards read on a stage of `stage` px: the whole
166
+ * scene framed (the widest shot a tour takes), its cards at least `share` of
167
+ * the width a card's name needs (`need`, px). Too narrow a stage (a phone, two
168
+ * boxes side by side) keeps the dots.
169
+ */
170
+ export function cardsReadable(scene, stage, need, { pad = 3.5, gap = 0.12, share = 0.7 } = {}) {
171
+ const g = scene && scene.cardGrid;
172
+ if (!g || !stage || !(stage.w > 0) || !(stage.h > 0) || !(need > 0)) return false;
173
+ const pp = Math.min(stage.w / (scene.extent.w + 2 * pad), stage.h / (scene.extent.h + 2 * pad));
174
+ return pp * g.cell * (g.aspect - gap) >= need * share;
175
+ }
176
+
124
177
  /**
125
178
  * The scene: the flights, and the layout after every takeoff, in pitches.
126
179
  * `layoutAt(k)` is the layout once the first k landing flights have taken off
@@ -139,14 +192,28 @@ export function buildScene(show, opts = {}) {
139
192
  // Fixed widths: the source's from its first members, each estate's from its last.
140
193
  const width = new Map();
141
194
  const finalSize = new Map();
195
+ // A small stage (`cardGrid`: at most `max` resources, the layer drawing its own cards) is read at the Cards level:
196
+ // each box is as big as its card grid, in the stage's shape, so the director can frame readable cards. The boxes
197
+ // never change size as the carve moves resources, so a card never moves for a box resizing.
198
+ const grid = o.cardGrid && show.roster.length <= o.cardGrid.max ? o.cardGrid : null;
199
+ const minInner = new Map();
200
+ const stageAspect = o.avail && o.avail.w > 0 && o.avail.h > 0 ? o.avail.w / o.avail.h : 1.6;
142
201
  for (const e of estates) {
143
202
  const first = e === source ? membersOf(show.owners0, e) : membersOf(end, e);
144
203
  if (!first.length && e !== source) continue;
145
204
  const us = unitsOf(first);
146
205
  // The source's box takes its cards' shape on the page, so a card's dot has a short way to go.
147
- width.set(e, blockWidth(us, e === source && o.sourceAspect ? o.sourceAspect : 1.3));
148
- const p = packBlock(us, { width: width.get(e), fromEnd: e === source });
149
- finalSize.set(e, { w: p.w + 2 * BOX.pad, h: p.h + 2 * BOX.pad + BOX.title });
206
+ let wd = blockWidth(us, e === source && o.sourceAspect ? o.sourceAspect : 1.3);
207
+ if (grid) {
208
+ // Each box in the stage's own shape: the director frames one box at a time more often than all of them (the source, a landing).
209
+ const g = cardGridShape(first.length, { cell: grid.cell, aspect: grid.aspect, target: stageAspect });
210
+ minInner.set(e, g);
211
+ wd = Math.max(wd, g.w);
212
+ }
213
+ width.set(e, wd);
214
+ const p = packBlock(us, { width: wd, fromEnd: e === source });
215
+ const mi = minInner.get(e);
216
+ finalSize.set(e, { w: Math.max(p.w, mi ? mi.w : 0) + 2 * BOX.pad, h: Math.max(p.h, mi ? mi.h : 0) + 2 * BOX.pad + BOX.title });
150
217
  }
151
218
  const src = finalSize.get(source) ?? { w: 10, h: 10 };
152
219
  const dests = estates.filter((e) => e !== source && finalSize.has(e)).sort();
@@ -201,23 +268,33 @@ export function buildScene(show, opts = {}) {
201
268
  const fromEnd = e === source;
202
269
  const p = packBlock(unitsOf(ms), { width: width.get(e), fromEnd });
203
270
  const o = origin.get(e);
271
+ const mi = minInner.get(e);
272
+ const ih = Math.max(p.h, mi ? mi.h : 0);
204
273
  let bx;
205
274
  let by;
206
275
  if (fromEnd) {
207
276
  // Bottom edge fixed: the source loses its top rows as units leave.
208
277
  bx = o.x;
209
- by = o.y + src.h - (p.h + 2 * BOX.pad + BOX.title);
278
+ by = o.y + src.h - (ih + 2 * BOX.pad + BOX.title);
210
279
  } else {
211
280
  bx = o.x;
212
281
  by = o.y;
213
282
  }
214
283
  const ix = bx + BOX.pad;
215
- const iy = by + BOX.pad + BOX.title + (fromEnd ? p.h : 0);
216
- for (const [addr, s] of p.slots) slots.set(addr, { x: ix + s.x, y: iy + s.y, ...(s.parent ? { parent: s.parent } : {}) });
284
+ const iy = by + BOX.pad + BOX.title + (fromEnd ? ih : 0);
285
+ if (mi && ms.length) {
286
+ // A small stage's box is its card grid: each dot sits at its card's cell (web/dots-cards.js gridSlots, the
287
+ // same order and cells), spread over the box at every zoom, never piled in a corner at the dots' pitch.
288
+ const cells = gridCells(ms, { x: ix, y: by + BOX.pad + BOX.title, w: Math.max(p.w, mi.w), h: ih }, grid);
289
+ for (const [addr, c] of cells) {
290
+ const s = p.slots.get(addr);
291
+ slots.set(addr, { x: c.x, y: c.y, ...(s && s.parent ? { parent: s.parent } : {}) });
292
+ }
293
+ } else for (const [addr, s] of p.slots) slots.set(addr, { x: ix + s.x, y: iy + s.y, ...(s.parent ? { parent: s.parent } : {}) });
217
294
  // The source's box narrows to the dots it still holds once its last row is partial.
218
295
  let x0 = bx;
219
- let w = Math.max(p.w, ms.length ? 0 : 4) + 2 * BOX.pad;
220
- if (fromEnd && ms.length) {
296
+ let w = Math.max(p.w, ms.length ? 0 : 4, mi ? mi.w : 0) + 2 * BOX.pad;
297
+ if (fromEnd && ms.length && !mi) {
221
298
  let lo = Infinity;
222
299
  for (const [, sl] of p.slots) lo = Math.min(lo, sl.x);
223
300
  const cellHalf = 1.5;
@@ -225,14 +302,37 @@ export function buildScene(show, opts = {}) {
225
302
  x0 = bx + left;
226
303
  w = p.w - left + 2 * BOX.pad;
227
304
  }
228
- boxes.set(e, { x: x0, y: by, w, h: p.h + 2 * BOX.pad + BOX.title, members: ms.length });
305
+ boxes.set(e, { x: x0, y: by, w, h: ih + 2 * BOX.pad + BOX.title, members: ms.length });
229
306
  }
230
307
  const out = { k: kk, slots, boxes, owners };
231
308
  if (cache.size > 2000) cache.clear();
232
309
  cache.set(kk, out);
233
310
  return out;
234
311
  };
235
- return { show, flights, landing, estates, source, layoutAt, extent: { w: extentW, h: extentH }, sourceBox: src, finalSize, rosterBy };
312
+ return { show, flights, landing, estates, source, layoutAt, extent: { w: extentW, h: extentH }, sourceBox: src, finalSize, rosterBy, cardGrid: grid };
313
+ }
314
+
315
+ function unionBox(a, b) {
316
+ if (!a) return b;
317
+ if (!b) return a;
318
+ const x = Math.min(a.x, b.x);
319
+ const y = Math.min(a.y, b.y);
320
+ return { x, y, w: Math.max(a.x + a.w, b.x + b.w) - x, h: Math.max(a.y + a.h, b.y + b.h) - y };
321
+ }
322
+
323
+ /**
324
+ * The box the director frames for `focus` at show time `t`, in pitches: the
325
+ * whole scene ("all"), the source's box ("source"), or an estate's box (an
326
+ * "estate" the flock flies to, a tour chapter's "box") with the source's, so
327
+ * the flight is in the shot.
328
+ */
329
+ export function focusRect(scene, focus, t) {
330
+ const now = scene.layoutAt(takeoffsBy(scene, t)).boxes;
331
+ const fin = scene.layoutAt(scene.landing.length).boxes;
332
+ const src = now.get(scene.source) || scene.layoutAt(0).boxes.get(scene.source);
333
+ if (focus.kind === "all") return { x: 0, y: 0, w: scene.extent.w, h: scene.extent.h };
334
+ if (focus.kind === "source" || focus.estate === scene.source) return src;
335
+ return unionBox(src, fin.get(focus.estate) || now.get(focus.estate));
236
336
  }
237
337
 
238
338
  /** How many landing flights have taken off by replay time `t` (binary search). */