@intentius/behold 0.29.40 → 0.29.42
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/AGENTS.md +180 -10
- package/README.md +6 -2
- package/dist/cli.js +16121 -13141
- package/example-writes/README.md +1 -1
- package/example-writes/chant.config.ts +0 -6
- package/package.json +5 -2
- package/web/app.js +327 -21
- package/web/carve-export.js +142 -0
- package/web/carve-narration.js +294 -0
- package/web/carve-narration.test.js +48 -0
- package/web/change-set-overlay.js +147 -0
- package/web/change-set-overlay.test.js +83 -0
- package/web/dots-border.js +66 -0
- package/web/dots-border.test.js +27 -0
- package/web/dots-kiosk.js +279 -0
- package/web/dots-kiosk.test.js +60 -0
- package/web/dots-layout.d.ts +10 -0
- package/web/dots-layout.js +201 -0
- package/web/dots-live.js +316 -0
- package/web/dots-live.test.js +220 -0
- package/web/dots-lod.js +122 -0
- package/web/dots-lod.test.js +78 -0
- package/web/dots-recording.d.ts +7 -0
- package/web/dots-recording.js +247 -0
- package/web/dots-recording.test.js +71 -0
- package/web/dots-scene.js +294 -0
- package/web/dots-scene.test.js +118 -0
- package/web/dots-timeline.js +128 -0
- package/web/dots-timeline.test.js +83 -0
- package/web/dots-tour.js +153 -0
- package/web/dots.js +2124 -0
- package/web/dots.test.js +15 -0
- package/web/event-help-modal.js +1 -1
- package/web/index.html +215 -121
- package/web/kiosk-carve.js +225 -0
- package/web/kiosk-carve.test.js +26 -0
- package/web/kiosk-event-help-ui.js +7 -1
- package/web/kiosk-link.js +68 -0
- package/web/kiosk-link.test.js +69 -0
- package/web/kiosk-metrics.js +2 -2
- package/web/kiosk-trace.js +1 -1
- package/web/kiosk.html +186 -135
- package/web/kiosk.js +65 -7
- package/web/motion.js +42 -0
- package/web/motion.test.js +64 -0
- package/web/operator.js +1 -1
- package/web/run-playhead.js +102 -19
- package/web/run-playhead.test.js +81 -11
- package/web/terralith.html +2 -2
- package/web/theme.js +99 -26
- package/web/theme.test.js +70 -6
- package/web/tooltip.js +212 -0
- package/web/tooltip.test.js +193 -0
- package/web/tour-player.js +204 -0
- package/web/tour-player.test.js +115 -0
- package/web/tours/behold.tour.v1.schema.json +182 -0
- package/web/tours/terralith.json +330 -0
- package/web/trunk-lane.js +406 -0
- package/web/trunk-lane.test.js +224 -0
- package/web/workspace-gates.js +29 -4
- package/web/workspace-gates.test.js +23 -2
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
// #715: the dots layer's live driver. The route's answer (src/terragucci-carve.ts)
|
|
2
|
+
// becomes a show: one dot per resource, keyed by live id; a stamp leaves a
|
|
3
|
+
// ring, a move flies, a refusal bounces; lines play from when they were seen.
|
|
4
|
+
import { describe, it, expect } from "vitest";
|
|
5
|
+
import { liveShow, stampArrivals, lineKey, showKey, currentMigration, carveDrawable, boxName, LIVE } from "./dots-live.js";
|
|
6
|
+
import { buildScene, takeoffsBy } from "./dots-scene.js";
|
|
7
|
+
import { liveBeat, liveTipsBetween, liveEndTip } from "./dots-kiosk.js";
|
|
8
|
+
import { dotsCarving, dotsActive } from "./dots.js";
|
|
9
|
+
|
|
10
|
+
const T = Date.parse("2026-10-16T10:00:00Z");
|
|
11
|
+
const at = (s) => new Date(T + s * 1000).toISOString();
|
|
12
|
+
|
|
13
|
+
// A stock terralith (addresses only), adopted (stamped), then split: two moves and a refusal.
|
|
14
|
+
const stock = {
|
|
15
|
+
estate: "terralith",
|
|
16
|
+
at: at(-60),
|
|
17
|
+
count: 4,
|
|
18
|
+
resources: [
|
|
19
|
+
{ address: "module.team_a.aws_iam_role.app", type: "aws_iam_role", marked: false },
|
|
20
|
+
{ address: "module.team_a.aws_iam_role_policy.app", type: "aws_iam_role_policy", marked: false, follows: "module.team_a.aws_iam_role.app" },
|
|
21
|
+
{ address: "module.team_b.aws_iam_role.app", type: "aws_iam_role", marked: false },
|
|
22
|
+
{ address: "aws_vpc.main", type: "aws_vpc", marked: false },
|
|
23
|
+
],
|
|
24
|
+
};
|
|
25
|
+
const adopt = {
|
|
26
|
+
name: "adopt",
|
|
27
|
+
running: false,
|
|
28
|
+
counts: { moved: 0, stamped: 3, refused: 0, skipped: 1, left: 0 },
|
|
29
|
+
lines: [
|
|
30
|
+
{ at: at(0), estate_from: "terralith", estate_to: "terralith", address: "module.team_a.aws_iam_role.app", live_id: "role-a", outcome: "stamped" },
|
|
31
|
+
{ at: at(1), estate_from: "terralith", estate_to: "terralith", address: "module.team_b.aws_iam_role.app", live_id: "role-b", outcome: "stamped" },
|
|
32
|
+
{ at: at(2), estate_from: "terralith", estate_to: "terralith", address: "aws_vpc.main", live_id: "vpc-1", outcome: "stamped" },
|
|
33
|
+
{ at: at(3), estate_from: "terralith", estate_to: "terralith", address: "module.team_a.aws_iam_role_policy.app", outcome: "skipped" },
|
|
34
|
+
],
|
|
35
|
+
};
|
|
36
|
+
const split = (lines) => ({ name: "carve", running: true, counts: { moved: 1, stamped: 0, refused: lines.length > 2 ? 1 : 0, skipped: 0, left: 1 }, lines });
|
|
37
|
+
const moveA = { at: at(10), estate_from: "terralith", estate_to: "team-a", address: "module.team_a.aws_iam_role.app", live_id: "role-a", outcome: "moved" };
|
|
38
|
+
const followA = { at: at(10), estate_from: "terralith", estate_to: "team-a", address: "module.team_a.aws_iam_role_policy.app", outcome: "moved", follows: "module.team_a.aws_iam_role.app" };
|
|
39
|
+
const refuseB = { at: at(11), estate_from: "terralith", estate_to: "team-b", address: "module.team_b.aws_iam_role.app", live_id: "role-b", outcome: "refused", reason: "Unexpected changes in the marker rewrite" };
|
|
40
|
+
const answer = (migrations, estates = [stock]) => ({ live: true, source: "/tmp/reports", estates, migrations, demo: { title: "Carving the terralith", next: "carve: 1 of 2 moved" }, running: migrations.some((m) => m.running) });
|
|
41
|
+
|
|
42
|
+
describe("the live carve as a show (#715)", () => {
|
|
43
|
+
it("keys a dot by live id once a stamp names it, and plays stock, adopt, split in order", () => {
|
|
44
|
+
const a = answer([adopt, split([moveA, followA, refuseB])]);
|
|
45
|
+
const seen = stampArrivals(a, new Map(), T + 20_000, { first: true });
|
|
46
|
+
const show = liveShow(a, seen, T + 20_000);
|
|
47
|
+
expect(show.kind).toBe("live");
|
|
48
|
+
expect(show.source).toBe("terralith");
|
|
49
|
+
expect(show.roster).toHaveLength(4);
|
|
50
|
+
expect([...show.owners0.values()].every((e) => e === "terralith")).toBe(true);
|
|
51
|
+
expect(show.ownersEnd.get("module.team_a.aws_iam_role.app")).toBe("team-a");
|
|
52
|
+
// The policy follows its role.
|
|
53
|
+
expect(show.ownersEnd.get("module.team_a.aws_iam_role_policy.app")).toBe("team-a");
|
|
54
|
+
// The refused move leaves it where it was.
|
|
55
|
+
expect(show.ownersEnd.get("module.team_b.aws_iam_role.app")).toBe("terralith");
|
|
56
|
+
expect(show.events.filter((e) => e.kind === "adopt")).toHaveLength(3);
|
|
57
|
+
const writes = show.events.filter((e) => e.kind === "write");
|
|
58
|
+
expect(writes.map((w) => w.ok)).toEqual([true, false]);
|
|
59
|
+
expect(writes[0].followers).toEqual(["module.team_a.aws_iam_role_policy.app"]);
|
|
60
|
+
expect(writes[1].refusalSummary).toMatch(/marker rewrite/);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("joins a destination roster's resource to its dot by live id, not as a second dot", () => {
|
|
64
|
+
const teamA = { estate: "team-a", at: at(12), count: 1, resources: [{ address: "aws_iam_role.app", type: "aws_iam_role", live_id: "role-a", marked: true }] };
|
|
65
|
+
const a = answer([adopt, split([moveA])], [stock, teamA]);
|
|
66
|
+
const show = liveShow(a, stampArrivals(a, new Map(), T + 20_000, { first: true }), T + 20_000);
|
|
67
|
+
expect(show.roster).toHaveLength(4);
|
|
68
|
+
expect(show.estates).toContain("team-a");
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("draws the first read's lines where they ended, and flies a later line from when it was seen", () => {
|
|
72
|
+
const first = answer([adopt]);
|
|
73
|
+
const seen0 = stampArrivals(first, new Map(), T + 5_000, { first: true });
|
|
74
|
+
expect(seen0.get(lineKey("adopt", adopt.lines[0]))).toBe(T);
|
|
75
|
+
const later = answer([adopt, split([moveA, refuseB])]);
|
|
76
|
+
const now = T + 30_000;
|
|
77
|
+
const seen1 = stampArrivals(later, seen0, now);
|
|
78
|
+
expect(seen1.get(lineKey("carve", moveA))).toBe(now);
|
|
79
|
+
// Real time: a line of the same read is drawn when it is read, with no pacing.
|
|
80
|
+
expect(seen1.get(lineKey("carve", refuseB))).toBe(now);
|
|
81
|
+
const show0 = liveShow(first, seen0, T + 5_000);
|
|
82
|
+
const show1 = liveShow(later, seen1, now, { t0: show0.t0 });
|
|
83
|
+
expect(show1.t0).toBe(show0.t0);
|
|
84
|
+
expect(showKey(show1)).not.toBe(showKey(show0));
|
|
85
|
+
const scene = buildScene(show1);
|
|
86
|
+
const flight = scene.flights.find((f) => f.address === "module.team_a.aws_iam_role.app");
|
|
87
|
+
// One to one: the flight starts at its arrival, in the show's own clock.
|
|
88
|
+
expect(flight.start).toBe(now - show1.t0);
|
|
89
|
+
expect(takeoffsBy(scene, now - show1.t0 - 1)).toBe(0);
|
|
90
|
+
// The role and its policy, which follows it, take off together.
|
|
91
|
+
expect(takeoffsBy(scene, now - show1.t0 + 1)).toBe(2);
|
|
92
|
+
expect(scene.flights.find((f) => f.address === "module.team_a.aws_iam_role_policy.app").parent).toBe("module.team_a.aws_iam_role.app");
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it("says what is happening from demo.json and the newest line, and tips the first landing and refusal", () => {
|
|
96
|
+
const a = answer([adopt, split([moveA, followA, refuseB])]);
|
|
97
|
+
const seen = stampArrivals(a, new Map(), T, { first: true });
|
|
98
|
+
const show = liveShow(a, seen, T + 20_000);
|
|
99
|
+
const scene = buildScene(show);
|
|
100
|
+
const m = currentMigration(a);
|
|
101
|
+
expect(m.name).toBe("carve");
|
|
102
|
+
const mid = liveBeat(scene, T + 11_500 - show.t0, { demo: a.demo, migration: m });
|
|
103
|
+
expect(mid.title).toBe("Carving the terralith");
|
|
104
|
+
expect(mid.next.text).toBe("carve: 1 of 2 moved");
|
|
105
|
+
expect(mid.line.tone).toBe("bad");
|
|
106
|
+
const tips = liveTipsBetween(scene, -1, T + 20_000 - show.t0);
|
|
107
|
+
expect(tips.map((t) => t.key).sort()).toEqual(["land:team-a", "refused"]);
|
|
108
|
+
const done = liveBeat(scene, T + 20_000 - show.t0, { demo: null, migration: { ...m, running: false } });
|
|
109
|
+
expect(done.phase).toBe("settled");
|
|
110
|
+
expect(done.focus).toEqual({ kind: "all" });
|
|
111
|
+
expect(liveEndTip(m, 0).key).toBe("end:carve");
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
describe("the gate, in the page (#715)", () => {
|
|
116
|
+
it("draws nothing for a shut gate or an empty carve", () => {
|
|
117
|
+
expect(carveDrawable(null)).toBe(false);
|
|
118
|
+
expect(carveDrawable({ live: false, reason: "no choudoufu roots" })).toBe(false);
|
|
119
|
+
expect(carveDrawable({ live: true, estates: [], migrations: [] })).toBe(false);
|
|
120
|
+
expect(carveDrawable(answer([], [stock]))).toBe(true);
|
|
121
|
+
});
|
|
122
|
+
it("leaves the layer unmounted, with no director and no zoom limit of its own", () => {
|
|
123
|
+
expect(dotsActive()).toBe(false);
|
|
124
|
+
expect(dotsCarving()).toBe(false);
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
// The live local run's cycle 5: the adoption's 82 lines came in one read, all
|
|
129
|
+
// within a second. The stock root and the estate it became are one box.
|
|
130
|
+
describe("an adoption as one box changing its name", () => {
|
|
131
|
+
const N = 82;
|
|
132
|
+
const addr = (i) => `aws_iam_role.r${String(i).padStart(2, "0")}`;
|
|
133
|
+
const stockRoster = { estate: "terralith", at: at(-120), count: N, resources: Array.from({ length: N }, (_, i) => ({ address: addr(i), type: "aws_iam_role", marked: false })) };
|
|
134
|
+
// As the route gives them: a stamp's empty estate_from reads as the estate it is stamped into.
|
|
135
|
+
const stamps = Array.from({ length: N }, (_, i) => ({ at: at(1), estate_from: "tl5-terralith", estate_to: "tl5-terralith", address: addr(i), ...(i % 2 ? {} : { live_id: `role-${i}` }), outcome: i % 2 ? "skipped" : "stamped" }));
|
|
136
|
+
const adoptM = { name: "adopt", running: true, counts: { moved: 0, stamped: 41, refused: 0, skipped: 41, left: 0 }, lines: stamps };
|
|
137
|
+
const mid = { ...answer([adoptM], [stockRoster]), adopted: [{ from: "terralith", to: "tl5-terralith" }] };
|
|
138
|
+
|
|
139
|
+
it("draws a batch of lines in real time: the whole read at once, as the burst it was", () => {
|
|
140
|
+
const now = T + 10_000;
|
|
141
|
+
const seen = stampArrivals(mid, new Map(), now);
|
|
142
|
+
const times = stamps.map((l) => seen.get(lineKey("adopt", l)));
|
|
143
|
+
expect(LIVE.stepMs).toBe(0);
|
|
144
|
+
expect(new Set(times)).toEqual(new Set([now]));
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it("slowed, paces a batch stepMs apart, after any still waiting to play", () => {
|
|
148
|
+
const now = T + 10_000;
|
|
149
|
+
const stepMs = 50;
|
|
150
|
+
const seen = stampArrivals(mid, new Map(), now, { stepMs });
|
|
151
|
+
const times = stamps.map((l) => seen.get(lineKey("adopt", l))).sort((a, b) => a - b);
|
|
152
|
+
expect(times[0]).toBe(now);
|
|
153
|
+
expect(times[N - 1]).toBe(now + (N - 1) * stepMs);
|
|
154
|
+
// A line of the next read waits behind the batch.
|
|
155
|
+
const more = { ...mid, migrations: [{ ...adoptM, lines: [...stamps, { ...stamps[0], at: at(2), address: "aws_s3_bucket.late" }] }] };
|
|
156
|
+
const next = stampArrivals(more, seen, now + 500, { stepMs });
|
|
157
|
+
expect(next.get(lineKey("adopt", { ...stamps[0], at: at(2), address: "aws_s3_bucket.late" }))).toBe(now + N * stepMs);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it("rings the stock root's dots in place, in one box that takes the estate's name with the first stamp", () => {
|
|
161
|
+
const now = T + 10_000;
|
|
162
|
+
const seen = stampArrivals(mid, new Map(), now);
|
|
163
|
+
const show = liveShow(mid, seen, now + 1);
|
|
164
|
+
expect(show.roster).toHaveLength(N);
|
|
165
|
+
expect(show.estates).toEqual(["terralith"]);
|
|
166
|
+
expect(show.events.filter((e) => e.kind === "write")).toHaveLength(0);
|
|
167
|
+
expect(show.events.filter((e) => e.kind === "adopt")).toHaveLength(41);
|
|
168
|
+
expect(boxName(show, "terralith", now - 1)).toBe("terralith");
|
|
169
|
+
expect(boxName(show, "terralith", now)).toBe("tl5-terralith");
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it("after the adoption, draws the estate's roster in the same box, with the same dots", () => {
|
|
173
|
+
const estate = { estate: "tl5-terralith", at: at(12), count: N, resources: stockRoster.resources.map((r, i) => ({ ...r, ...(i % 2 ? {} : { live_id: `role-${i}` }), marked: i % 2 === 0 })) };
|
|
174
|
+
const done = { ...answer([{ ...adoptM, running: false }], [estate]), adopted: [{ from: "terralith", to: "tl5-terralith" }] };
|
|
175
|
+
// A page loaded after it: the lines are the past, the box has the estate's name.
|
|
176
|
+
const show = liveShow(done, stampArrivals(done, new Map(), T + 60_000, { first: true }), T + 60_000);
|
|
177
|
+
expect(show.roster).toHaveLength(N);
|
|
178
|
+
expect(show.estates).toEqual(["terralith"]);
|
|
179
|
+
expect(boxName(show, "terralith", T + 60_000)).toBe("tl5-terralith");
|
|
180
|
+
expect([...show.ownersEnd.values()].every((e) => e === "terralith")).toBe(true);
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
// The live run's cycle 8: after the split, wave 1 writes each team's roster from its plan, with no live ids, so the
|
|
185
|
+
// team's resources are named by address only. They are the dots the split's lines moved there, not a second set.
|
|
186
|
+
describe("a destination roster written after the move", () => {
|
|
187
|
+
it("joins the moved dots by address, so the team's box holds each resource once", () => {
|
|
188
|
+
const left = { estate: "tl8-terralith", at: at(30), count: 1, resources: [{ address: "aws_vpc.main", type: "aws_vpc", live_id: "vpc-1", marked: true }] };
|
|
189
|
+
const team = { estate: "tl8-team-a", at: at(40), count: 3, resources: ["aws_iam_role.r", "aws_iam_role_policy.p", "aws_cloudwatch_log_group.l"].map((address) => ({ address, type: address.split(".")[0], marked: false })) };
|
|
190
|
+
const mv = (address, o = {}) => ({ at: at(20), estate_from: "tl8-terralith", estate_to: "tl8-team-a", address, outcome: "moved", ...o });
|
|
191
|
+
const splitM = { name: "split", running: false, counts: { moved: 3, stamped: 0, refused: 0, skipped: 0, left: 0 }, lines: [mv("aws_iam_role.r", { live_id: "role-r" }), mv("aws_iam_role_policy.p", { follows: "aws_iam_role.r" }), mv("aws_cloudwatch_log_group.l", { live_id: "logs" })] };
|
|
192
|
+
const a = answer([splitM], [left, team]);
|
|
193
|
+
const show = liveShow(a, stampArrivals(a, new Map(), T + 60_000, { first: true }), T + 60_000);
|
|
194
|
+
expect(show.roster).toHaveLength(4);
|
|
195
|
+
const ends = {};
|
|
196
|
+
for (const e of show.ownersEnd.values()) ends[e] = (ends[e] ?? 0) + 1;
|
|
197
|
+
expect(ends).toEqual({ "tl8-team-a": 3, "tl8-terralith": 1 });
|
|
198
|
+
// They start in the terralith, where the lines say they came from.
|
|
199
|
+
expect(show.owners0.get("aws_iam_role.r")).toBe("tl8-terralith");
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
// The live run's cycle 11: the adoption's stamps, then the split, then wave 1's team rosters with no live ids. The
|
|
204
|
+
// boxes read 26 for team rosters of 13: the stamps had made each resource's dot and the team roster made another.
|
|
205
|
+
describe("an adoption, a split, and the team rosters written after it", () => {
|
|
206
|
+
it("draws each resource once, so a team's box counts what its roster holds", () => {
|
|
207
|
+
const addrs = ["aws_iam_role.r", "aws_iam_role_policy.p", "aws_cloudwatch_log_group.l"];
|
|
208
|
+
const left = { estate: "tl11-terralith", at: at(30), count: 1, resources: [{ address: "aws_vpc.main", type: "aws_vpc", live_id: "vpc-1", marked: true }] };
|
|
209
|
+
const team = { estate: "tl11-team-a", at: at(40), count: 3, resources: addrs.map((address) => ({ address, type: address.split(".")[0], marked: false })) };
|
|
210
|
+
const ids = { "aws_iam_role.r": "role-r", "aws_iam_role_policy.p": "role-r:p", "aws_cloudwatch_log_group.l": "logs", "aws_vpc.main": "vpc-1" };
|
|
211
|
+
const adoptM = { name: "adopt", running: false, counts: { moved: 0, stamped: 3, refused: 0, skipped: 1, left: 0 }, lines: [...addrs, "aws_vpc.main"].map((address) => ({ at: at(5), estate_from: "tl11-terralith", estate_to: "tl11-terralith", address, live_id: ids[address], outcome: address.includes("policy") ? "skipped" : "stamped" })) };
|
|
212
|
+
const splitM = { name: "split", running: false, counts: { moved: 3, stamped: 0, refused: 0, skipped: 0, left: 0 }, lines: addrs.map((address) => ({ at: at(20), estate_from: "tl11-terralith", estate_to: "tl11-team-a", address, ...(address.includes("policy") ? { follows: "aws_iam_role.r" } : { live_id: ids[address] }), outcome: "moved" })) };
|
|
213
|
+
const a = { ...answer([adoptM, splitM], [left, team]), adopted: [{ from: "terralith", to: "tl11-terralith" }] };
|
|
214
|
+
const show = liveShow(a, stampArrivals(a, new Map(), T + 60_000, { first: true }), T + 60_000);
|
|
215
|
+
expect(show.roster.map((r) => r.address).sort()).toEqual([...addrs, "aws_vpc.main"].sort());
|
|
216
|
+
const ends = {};
|
|
217
|
+
for (const e of show.ownersEnd.values()) ends[e] = (ends[e] ?? 0) + 1;
|
|
218
|
+
expect(ends).toEqual({ "tl11-team-a": 3, terralith: 1 });
|
|
219
|
+
});
|
|
220
|
+
});
|
package/web/dots-lod.js
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// Level of detail for the dots layer (#712, #715): each mark picks its form from
|
|
2
|
+
// how many pixels it covers at the current zoom, and the morph between two
|
|
3
|
+
// forms follows the zoom position, never a clock. Stopping halfway stays
|
|
4
|
+
// halfway; zooming back in runs it backwards. Pure.
|
|
5
|
+
|
|
6
|
+
/** Starting points, in CSS pixels on screen. */
|
|
7
|
+
export const LOD = {
|
|
8
|
+
/** A card at least this wide stays a card. */
|
|
9
|
+
cardPx: 90,
|
|
10
|
+
/** A card narrower than this is a dot. */
|
|
11
|
+
dotPx: 24,
|
|
12
|
+
/** An estate box at least this wide (its larger side) is still all dots. */
|
|
13
|
+
discFromPx: 72,
|
|
14
|
+
/** An estate box smaller than this is one disc. */
|
|
15
|
+
discPx: 48,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/** 0 at or above `hi`, 1 at or below `lo`, linear in log(px) between. */
|
|
19
|
+
export function bandT(px, hi, lo) {
|
|
20
|
+
if (!(px > 0)) return 1;
|
|
21
|
+
if (px >= hi) return 0;
|
|
22
|
+
if (px <= lo) return 1;
|
|
23
|
+
return Math.log(hi / px) / Math.log(hi / lo);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Smoothstep, so a morph starts and ends at rest. */
|
|
27
|
+
export function smooth(t) {
|
|
28
|
+
const x = Math.max(0, Math.min(1, t));
|
|
29
|
+
return x * x * (3 - 2 * x);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Card to dot: 0 is a card, 1 a dot. Under reduced motion it switches at the
|
|
34
|
+
* geometric middle of the band, with no in-between.
|
|
35
|
+
*/
|
|
36
|
+
export function cardMorph(cardPx, { reduced = false, lod = LOD } = {}) {
|
|
37
|
+
if (reduced) return cardPx < Math.sqrt(lod.cardPx * lod.dotPx) ? 1 : 0;
|
|
38
|
+
return smooth(bandT(cardPx, lod.cardPx, lod.dotPx));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Dots to disc for one estate box: 0 is dots, 1 a disc. Reduced motion switches at `discPx`. */
|
|
42
|
+
export function discMorph(boxPx, { reduced = false, lod = LOD } = {}) {
|
|
43
|
+
if (reduced) return boxPx < lod.discPx ? 1 : 0;
|
|
44
|
+
return smooth(bandT(boxPx, lod.discFromPx, lod.discPx));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function lerp(a, b, t) {
|
|
48
|
+
return a + (b - a) * t;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** A dot between its card's centre, its slot and its estate's disc. */
|
|
52
|
+
export function morphPoint(card, slot, disc, tCard, tDisc) {
|
|
53
|
+
const from = card ?? slot;
|
|
54
|
+
const x = lerp(from.x, slot.x, tCard);
|
|
55
|
+
const y = lerp(from.y, slot.y, tCard);
|
|
56
|
+
return { x: lerp(x, disc.x, tDisc), y: lerp(y, disc.y, tDisc) };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* A disc's radius in the same units as `pitch`: its area is the area its
|
|
61
|
+
* resources cover as dots, so area stays proportional to the count.
|
|
62
|
+
*/
|
|
63
|
+
export function discRadius(count, pitch) {
|
|
64
|
+
return Math.sqrt(Math.max(0, count) / Math.PI) * pitch * 1.8;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** What the marks on screen are, from the card morph and every box's disc morph. */
|
|
68
|
+
export function levelOf(tCard, tDiscs) {
|
|
69
|
+
const ds = [...tDiscs];
|
|
70
|
+
const allDisc = ds.length > 0 && ds.every((t) => t >= 1);
|
|
71
|
+
const anyDisc = ds.some((t) => t > 0);
|
|
72
|
+
if (tCard <= 0) return "cards";
|
|
73
|
+
if (tCard < 1) return "cards-dots";
|
|
74
|
+
if (allDisc) return "discs";
|
|
75
|
+
if (anyDisc) return "dots-discs";
|
|
76
|
+
return "dots";
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** The line naming the marks at a level. */
|
|
80
|
+
export function caption(level) {
|
|
81
|
+
switch (level) {
|
|
82
|
+
case "cards":
|
|
83
|
+
return "each card is a resource";
|
|
84
|
+
case "cards-dots":
|
|
85
|
+
return "cards shrinking to dots: each dot is a resource";
|
|
86
|
+
case "dots":
|
|
87
|
+
return "each dot is a resource, in its estate's box and colour";
|
|
88
|
+
case "dots-discs":
|
|
89
|
+
return "each dot is a resource; each disc is an estate, sized by resources";
|
|
90
|
+
case "discs":
|
|
91
|
+
return "each disc is an estate, sized by resources";
|
|
92
|
+
default:
|
|
93
|
+
return "";
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* The rail's three marks as viewBox widths, for a pane `paneW` x `paneH` px:
|
|
99
|
+
* Cards puts a card at `cardAt` px; Resources fits the whole scene
|
|
100
|
+
* (`sceneW` x `sceneH` viewBox units) while the smallest estate box is still
|
|
101
|
+
* dots; Estates puts the typical box (default: the largest) under the disc threshold.
|
|
102
|
+
*/
|
|
103
|
+
export function railMarks({ paneW, paneH = paneW, cardW, sceneW, sceneH = 0, smallestBox, largestBox, typicalBox = largestBox, lod = LOD, cardAt = 140 }) {
|
|
104
|
+
const cards = (paneW * cardW) / cardAt;
|
|
105
|
+
let resources = Math.max(sceneW, (sceneH * paneW) / Math.max(1, paneH)) * 1.12;
|
|
106
|
+
// Far enough that the cards have all but become dots, however few there are.
|
|
107
|
+
resources = Math.max(resources, cards * 1.5, (paneW * cardW) / (lod.dotPx * 1.25));
|
|
108
|
+
// Close enough that the smallest box stays dots: that wins over the cards, so
|
|
109
|
+
// a small estate is still dots at this mark even when its cards are large.
|
|
110
|
+
if (smallestBox > 0) resources = Math.min(resources, (smallestBox * paneW) / (lod.discFromPx * 1.1));
|
|
111
|
+
resources = Math.max(resources, cards * 1.2);
|
|
112
|
+
// The typical box just under the disc size: most estates are discs, and a far larger one may still be dots.
|
|
113
|
+
const estates = Math.max((paneW * typicalBox) / (lod.discPx * 0.98), resources * 1.5);
|
|
114
|
+
return { cards, resources, estates };
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** Where a viewBox width sits on the rail: 0 at Cards, 0.5 at Resources, 1 at Estates (log scale, clamped). */
|
|
118
|
+
export function railPos(vbW, marks) {
|
|
119
|
+
const l = (v) => Math.log(Math.max(1e-9, v));
|
|
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
|
+
return Math.max(0.5, Math.min(1, 0.5 + (0.5 * (l(vbW) - l(marks.resources))) / (l(marks.estates) - l(marks.resources))));
|
|
122
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { LOD, bandT, smooth, cardMorph, discMorph, morphPoint, discRadius, levelOf, caption, railMarks, railPos } from "./dots-lod.js";
|
|
3
|
+
|
|
4
|
+
describe("dots level of detail (#712)", () => {
|
|
5
|
+
it("is a card at or above the card size and a dot at or below the dot size", () => {
|
|
6
|
+
expect(cardMorph(LOD.cardPx)).toBe(0);
|
|
7
|
+
expect(cardMorph(200)).toBe(0);
|
|
8
|
+
expect(cardMorph(LOD.dotPx)).toBe(1);
|
|
9
|
+
expect(cardMorph(5)).toBe(1);
|
|
10
|
+
});
|
|
11
|
+
it("morphs in between by the zoom, monotonically, with no jump at either end", () => {
|
|
12
|
+
let prev = 0;
|
|
13
|
+
for (let px = 90; px >= 24; px -= 0.5) {
|
|
14
|
+
const t = cardMorph(px);
|
|
15
|
+
expect(t).toBeGreaterThanOrEqual(prev);
|
|
16
|
+
expect(t - prev).toBeLessThan(0.05);
|
|
17
|
+
prev = t;
|
|
18
|
+
}
|
|
19
|
+
expect(cardMorph(89.9)).toBeLessThan(0.001);
|
|
20
|
+
expect(cardMorph(24.1)).toBeGreaterThan(0.999);
|
|
21
|
+
});
|
|
22
|
+
it("is a function of the size alone, so stopping halfway stays halfway and zooming back reverses it", () => {
|
|
23
|
+
const mid = Math.sqrt(90 * 24);
|
|
24
|
+
expect(cardMorph(mid)).toBeCloseTo(0.5, 5);
|
|
25
|
+
expect(cardMorph(mid)).toBe(cardMorph(mid));
|
|
26
|
+
});
|
|
27
|
+
it("switches at a threshold with no in-between under reduced motion", () => {
|
|
28
|
+
const vals = new Set();
|
|
29
|
+
for (let px = 100; px > 10; px -= 1) vals.add(cardMorph(px, { reduced: true }));
|
|
30
|
+
expect([...vals].sort()).toEqual([0, 1]);
|
|
31
|
+
expect(discMorph(LOD.discPx - 1, { reduced: true })).toBe(1);
|
|
32
|
+
expect(discMorph(LOD.discPx + 1, { reduced: true })).toBe(0);
|
|
33
|
+
});
|
|
34
|
+
it("condenses an estate's dots into a disc below the disc size", () => {
|
|
35
|
+
expect(discMorph(LOD.discFromPx)).toBe(0);
|
|
36
|
+
expect(discMorph(LOD.discPx)).toBe(1);
|
|
37
|
+
expect(discMorph((LOD.discFromPx + LOD.discPx) / 2)).toBeGreaterThan(0);
|
|
38
|
+
});
|
|
39
|
+
it("bandT and smooth stay in [0, 1]", () => {
|
|
40
|
+
expect(bandT(0, 90, 24)).toBe(1);
|
|
41
|
+
expect(bandT(NaN, 90, 24)).toBe(1);
|
|
42
|
+
expect(smooth(-1)).toBe(0);
|
|
43
|
+
expect(smooth(2)).toBe(1);
|
|
44
|
+
});
|
|
45
|
+
it("interpolates a dot from its card through its slot to its disc", () => {
|
|
46
|
+
const card = { x: 0, y: 0 };
|
|
47
|
+
const slot = { x: 10, y: 0 };
|
|
48
|
+
const disc = { x: 10, y: 10 };
|
|
49
|
+
expect(morphPoint(card, slot, disc, 0, 0)).toEqual({ x: 0, y: 0 });
|
|
50
|
+
expect(morphPoint(card, slot, disc, 1, 0)).toEqual({ x: 10, y: 0 });
|
|
51
|
+
expect(morphPoint(card, slot, disc, 0.5, 0)).toEqual({ x: 5, y: 0 });
|
|
52
|
+
expect(morphPoint(card, slot, disc, 1, 1)).toEqual({ x: 10, y: 10 });
|
|
53
|
+
expect(morphPoint(null, slot, disc, 0, 0)).toEqual({ x: 10, y: 0 });
|
|
54
|
+
});
|
|
55
|
+
it("sizes a disc so its area is proportional to its resource count", () => {
|
|
56
|
+
const a = (n) => Math.PI * discRadius(n, 1) ** 2;
|
|
57
|
+
expect(a(400) / a(100)).toBeCloseTo(4, 6);
|
|
58
|
+
expect(discRadius(0, 1)).toBe(0);
|
|
59
|
+
});
|
|
60
|
+
it("names the level and the marks", () => {
|
|
61
|
+
expect(levelOf(0, [])).toBe("cards");
|
|
62
|
+
expect(levelOf(0.4, [0])).toBe("cards-dots");
|
|
63
|
+
expect(levelOf(1, [0, 0])).toBe("dots");
|
|
64
|
+
expect(levelOf(1, [0, 1])).toBe("dots-discs");
|
|
65
|
+
expect(levelOf(1, [1, 1])).toBe("discs");
|
|
66
|
+
expect(caption("dots")).toMatch(/each dot is a resource/);
|
|
67
|
+
expect(caption("discs")).toMatch(/each disc is an estate, sized by resources/);
|
|
68
|
+
});
|
|
69
|
+
it("orders the rail's marks and places the camera on them", () => {
|
|
70
|
+
const m = railMarks({ paneW: 1000, paneH: 800, cardW: 300, sceneW: 20000, sceneH: 8000, smallestBox: 2000, largestBox: 6000 });
|
|
71
|
+
expect(m.cards).toBeLessThan(m.resources);
|
|
72
|
+
expect(m.resources).toBeLessThan(m.estates);
|
|
73
|
+
expect(railPos(m.cards, m)).toBe(0);
|
|
74
|
+
expect(railPos(m.resources, m)).toBeCloseTo(0.5, 6);
|
|
75
|
+
expect(railPos(m.estates, m)).toBe(1);
|
|
76
|
+
expect(railPos(m.estates * 10, m)).toBe(1);
|
|
77
|
+
});
|
|
78
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Types for src/dots-preview.ts, which reads sources with the page's own reader (#712).
|
|
2
|
+
export function readCarve(text: string): any;
|
|
3
|
+
export function ownersAt(rec: any, upto: number, parents: Map<string, string>): Map<string, string>;
|
|
4
|
+
export function carveShow(rec: any, parents: Map<string, string>): any;
|
|
5
|
+
export function walkthroughShow(model: any): any;
|
|
6
|
+
export function ownersAtTime(show: any, t: number): Map<string, string>;
|
|
7
|
+
export function phaseAt(show: any, t: number): { id: string; t: number } | null;
|