@intentius/behold 0.29.25 → 0.29.26
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 +3 -1
- package/demos.json +15 -0
- package/dist/cli.js +604 -371
- package/example-choudoufu-estate/README.md +2 -2
- package/example-choudoufu-estate/scripts/choudoufu-up.sh +2 -2
- package/example-terralith/README.md +32 -0
- package/example-terralith/phases/adopt/migrations/adopt.yml +12 -0
- package/example-terralith/phases/adopt/terralith/main.tf +138 -0
- package/example-terralith/phases/split/migrations/split.yml +29 -0
- package/example-terralith/phases/split/team-a/main.tf +52 -0
- package/example-terralith/phases/split/team-b/main.tf +52 -0
- package/example-terralith/phases/split/team-c/main.tf +52 -0
- package/example-terralith/phases/split/terralith/main.tf +27 -0
- package/example-terralith/scripts/lib.sh +64 -0
- package/example-terralith/scripts/terralith-down.sh +9 -0
- package/example-terralith/scripts/terralith-step.sh +88 -0
- package/example-terralith/scripts/terralith-up.sh +50 -0
- package/example-terralith/terralith/main.tf +141 -0
- package/package.json +2 -1
- package/web/app.js +51 -7
- package/web/identity-mark.js +61 -0
- package/web/identity-mark.test.js +32 -0
- package/web/pending.js +2 -0
- package/web/pending.test.js +7 -0
- package/web/terralith-steps.js +93 -0
- package/web/terralith-steps.test.js +71 -0
- package/web/terralith.html +105 -0
- package/web/terralith.js +211 -0
- /package/example-choudoufu-estate/monolith/{carve.json → split.json} +0 -0
package/web/terralith.js
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
// `behold demo terralith`'s page: one estate per box, one card per resource,
|
|
2
|
+
// and a phase stepper. Moving between phases is a FLIP: every card keeps its
|
|
3
|
+
// address as its id, so a card glides from the terralith into the team box
|
|
4
|
+
// the split spawned, while that box fades in. Decisions live in
|
|
5
|
+
// terralith-steps.js and identity-mark.js; this file only draws.
|
|
6
|
+
|
|
7
|
+
import { PHASES, boxSubtitle, cardFace, cardNews, flipDelta, legendFor, phaseById, shownPhase, stepperItems } from "./terralith-steps.js";
|
|
8
|
+
import { identityMark, tagGlyphSvg } from "./identity-mark.js";
|
|
9
|
+
|
|
10
|
+
const POLL_MS = 3000;
|
|
11
|
+
const GLIDE_MS = 900;
|
|
12
|
+
|
|
13
|
+
const el = (tag, cls, text) => {
|
|
14
|
+
const e = document.createElement(tag);
|
|
15
|
+
if (cls) e.className = cls;
|
|
16
|
+
if (text != null) e.textContent = text;
|
|
17
|
+
return e;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const glyph = (kind, color) =>
|
|
21
|
+
kind === "none" ? "" : `<svg width="14" height="14" viewBox="0 0 14 14" aria-hidden="true">${tagGlyphSvg(kind, 1, 1, 12, color)}</svg>`;
|
|
22
|
+
|
|
23
|
+
function wantedFromUrl() {
|
|
24
|
+
return new URLSearchParams(location.search).get("phase");
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function setUrl(id) {
|
|
28
|
+
const u = new URL(location.href);
|
|
29
|
+
u.searchParams.set("phase", id);
|
|
30
|
+
history.replaceState(null, "", u);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function renderSteps(host, model, shownId, onPick) {
|
|
34
|
+
host.replaceChildren();
|
|
35
|
+
for (const s of stepperItems(model, shownId)) {
|
|
36
|
+
const li = el("li", `t-step${s.ran ? " ran" : ""}${s.shown ? " shown" : ""}${s.next ? " next" : ""}`);
|
|
37
|
+
const b = el("b", null, String(s.n));
|
|
38
|
+
li.append(b, document.createTextNode(s.label + (s.next ? " · next" : "")));
|
|
39
|
+
if (s.ran) {
|
|
40
|
+
li.tabIndex = 0;
|
|
41
|
+
li.setAttribute("role", "button");
|
|
42
|
+
if (s.shown) li.setAttribute("aria-current", "step");
|
|
43
|
+
li.addEventListener("click", () => onPick(s.id));
|
|
44
|
+
li.addEventListener("keydown", (e) => (e.key === "Enter" || e.key === " ") && onPick(s.id));
|
|
45
|
+
}
|
|
46
|
+
host.appendChild(li);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function renderLead(host, phase) {
|
|
51
|
+
host.replaceChildren();
|
|
52
|
+
const copy = phaseById(phase.id);
|
|
53
|
+
const left = el("div");
|
|
54
|
+
left.append(el("h2", null, `${phase.n}. ${copy.title}`), el("p", null, copy.lead), el("p", "t-facts", copy.facts(phase)));
|
|
55
|
+
const legend = el("ul", "t-legend");
|
|
56
|
+
legend.setAttribute("aria-label", "What the tag on a card means");
|
|
57
|
+
for (const m of legendFor(phase)) {
|
|
58
|
+
const li = el("li");
|
|
59
|
+
li.innerHTML = glyph(m.glyph, "var(--managed)") || "<i></i>";
|
|
60
|
+
li.append(el("strong", null, m.label), el("span", null, m.tip));
|
|
61
|
+
legend.appendChild(li);
|
|
62
|
+
}
|
|
63
|
+
host.append(left, legend);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function renderNext(host, model) {
|
|
67
|
+
if (!model.next) {
|
|
68
|
+
host.hidden = true;
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
host.hidden = false;
|
|
72
|
+
host.replaceChildren();
|
|
73
|
+
const copy = phaseById(model.next.id);
|
|
74
|
+
const code = el("code", null, model.next.command);
|
|
75
|
+
const btn = el("button", "t-copy", "copy");
|
|
76
|
+
btn.type = "button";
|
|
77
|
+
btn.addEventListener("click", async () => {
|
|
78
|
+
try {
|
|
79
|
+
await navigator.clipboard.writeText(model.next.command);
|
|
80
|
+
btn.textContent = "copied";
|
|
81
|
+
} catch {
|
|
82
|
+
btn.textContent = "select and copy";
|
|
83
|
+
}
|
|
84
|
+
setTimeout(() => (btn.textContent = "copy"), 1600);
|
|
85
|
+
});
|
|
86
|
+
host.append(el("strong", null, `Next: ${copy ? copy.label.toLowerCase() : model.next.id}`), code, btn);
|
|
87
|
+
host.append(el("span", "t-why", "Run it in the demo copy. The write is yours; this page moves on when the phase lands."));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function cardEl(card, phaseId) {
|
|
91
|
+
const face = cardFace(card);
|
|
92
|
+
const mark = identityMark(card.identity);
|
|
93
|
+
const c = el("div", `t-card${phaseId === "split" && card.moved ? " moved" : ""}`);
|
|
94
|
+
c.dataset.card = card.id;
|
|
95
|
+
c.title = [card.id, card.liveId ? `live id: ${card.liveId}` : "", mark ? mark.tip : ""].filter(Boolean).join("\n");
|
|
96
|
+
c.append(el("div", "k", face.kind), el("div", "n", face.name));
|
|
97
|
+
// Under the name: the mark, then the phase's news about this card.
|
|
98
|
+
if (mark) {
|
|
99
|
+
const m = el("div", `m${mark.glyph === "solid" ? " solid" : ""}`);
|
|
100
|
+
m.innerHTML = glyph(mark.glyph, "currentColor");
|
|
101
|
+
m.append(el("span", "w", mark.label));
|
|
102
|
+
c.appendChild(m);
|
|
103
|
+
}
|
|
104
|
+
const news = cardNews(card, phaseId);
|
|
105
|
+
if (news) c.appendChild(el("div", news === "drifted" ? "news drifted" : "news", news));
|
|
106
|
+
return c;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function renderStage(host, phase) {
|
|
110
|
+
host.replaceChildren();
|
|
111
|
+
for (const box of phase.boxes) {
|
|
112
|
+
const b = el("section", `t-box${box.stock ? " stock" : ""}${box.spawned ? " spawned" : ""}`);
|
|
113
|
+
b.dataset.box = box.id;
|
|
114
|
+
const head = el("div", "t-box-head");
|
|
115
|
+
head.append(el("h3", null, box.id), el("span", null, `${boxSubtitle(box)} · ${box.cards.length}`));
|
|
116
|
+
const cards = el("div", "t-cards");
|
|
117
|
+
for (const card of box.cards) cards.appendChild(cardEl(card, phase.id));
|
|
118
|
+
b.append(head, cards);
|
|
119
|
+
host.appendChild(b);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Where every card and box is now, by id. */
|
|
124
|
+
function measure(root) {
|
|
125
|
+
const at = new Map();
|
|
126
|
+
for (const n of root.querySelectorAll("[data-card]")) at.set("c:" + n.dataset.card, n.getBoundingClientRect());
|
|
127
|
+
for (const n of root.querySelectorAll("[data-box]")) at.set("b:" + n.dataset.box, n.getBoundingClientRect());
|
|
128
|
+
return at;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** The glide: each card starts where it was and moves to where it is. A box new to this phase fades in. */
|
|
132
|
+
function play(root, before) {
|
|
133
|
+
if (!before || matchMedia("(prefers-reduced-motion: reduce)").matches) return;
|
|
134
|
+
for (const n of root.querySelectorAll("[data-box]")) {
|
|
135
|
+
if (!before.has("b:" + n.dataset.box)) n.classList.add("spawning");
|
|
136
|
+
}
|
|
137
|
+
for (const n of root.querySelectorAll("[data-card]")) {
|
|
138
|
+
const d = flipDelta(before.get("c:" + n.dataset.card), n.getBoundingClientRect());
|
|
139
|
+
if (!d) continue;
|
|
140
|
+
n.style.transition = "none";
|
|
141
|
+
n.style.transform = `translate(${d.dx}px, ${d.dy}px)`;
|
|
142
|
+
n.style.zIndex = "2";
|
|
143
|
+
}
|
|
144
|
+
// One frame at the old place, then the glide.
|
|
145
|
+
requestAnimationFrame(() =>
|
|
146
|
+
requestAnimationFrame(() => {
|
|
147
|
+
for (const n of root.querySelectorAll("[data-card]")) {
|
|
148
|
+
if (!n.style.transform) continue;
|
|
149
|
+
n.style.transition = `transform ${GLIDE_MS}ms cubic-bezier(.25,.8,.25,1)`;
|
|
150
|
+
n.style.transform = "";
|
|
151
|
+
n.addEventListener("transitionend", () => {
|
|
152
|
+
n.style.transition = "";
|
|
153
|
+
n.style.zIndex = "";
|
|
154
|
+
}, { once: true });
|
|
155
|
+
}
|
|
156
|
+
}),
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export function startTerralith(doc) {
|
|
161
|
+
const steps = doc.getElementById("t-steps");
|
|
162
|
+
const lead = doc.getElementById("t-lead");
|
|
163
|
+
const next = doc.getElementById("t-next");
|
|
164
|
+
const stage = doc.getElementById("t-stage");
|
|
165
|
+
const notes = doc.getElementById("t-notes");
|
|
166
|
+
let model = null;
|
|
167
|
+
let shownId = null;
|
|
168
|
+
let lastKey = "";
|
|
169
|
+
|
|
170
|
+
const show = (id, { animate = true } = {}) => {
|
|
171
|
+
const phase = shownPhase(model, id);
|
|
172
|
+
renderSteps(steps, model, phase ? phase.id : null, (pick) => show(pick));
|
|
173
|
+
renderNext(next, model);
|
|
174
|
+
if (!phase) {
|
|
175
|
+
lead.replaceChildren(el("p", "t-empty", `No phase has run yet. Run ${model.next ? model.next.command : "scripts/terralith-up.sh"} in the demo copy.`));
|
|
176
|
+
stage.replaceChildren();
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
const before = animate && shownId && shownId !== phase.id ? measure(stage) : null;
|
|
180
|
+
shownId = phase.id;
|
|
181
|
+
setUrl(phase.id);
|
|
182
|
+
renderLead(lead, phase);
|
|
183
|
+
renderStage(stage, phase);
|
|
184
|
+
notes.hidden = !phase.notes.length;
|
|
185
|
+
notes.textContent = phase.notes.length ? `Some files could not be read: ${phase.notes.join("; ")}` : "";
|
|
186
|
+
play(stage, before);
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
const load = async () => {
|
|
190
|
+
try {
|
|
191
|
+
const res = await fetch("/api/terralith", { cache: "no-store" });
|
|
192
|
+
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
193
|
+
const fresh = await res.json();
|
|
194
|
+
const key = JSON.stringify(fresh.phases.map((p) => [p.id, p.at]));
|
|
195
|
+
if (key === lastKey) return;
|
|
196
|
+
const grew = model && fresh.phases.length > model.phases.length;
|
|
197
|
+
lastKey = key;
|
|
198
|
+
model = fresh;
|
|
199
|
+
// A phase that just landed is shown at once, gliding from the one before.
|
|
200
|
+
show(grew ? fresh.phases[fresh.phases.length - 1].id : shownId || wantedFromUrl(), { animate: !!grew });
|
|
201
|
+
} catch (err) {
|
|
202
|
+
if (!model) lead.replaceChildren(el("p", "t-empty", `Waiting for the demo server (${err instanceof Error ? err.message : String(err)}).`));
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
void load();
|
|
207
|
+
setInterval(load, POLL_MS);
|
|
208
|
+
return { show: (id) => show(id) };
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export { PHASES };
|
|
File without changes
|