@johnoscott/isometric-engine 0.14.1 → 0.16.0
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/README.md +1 -1
- package/iso-editor.js +249 -203
- package/iso-render.js +200 -154
- package/iso-systems.js +210 -162
- package/isometric-diagram.js +389 -0
- package/js/iso-core/index.js +5 -0
- package/js/iso-core/mono.js +242 -0
- package/js/iso-editor/ui/canvas.js +23 -1
- package/js/iso-objects/ants.js +36 -0
- package/js/iso-objects/index.js +55 -1
- package/js/iso-objects/looks.js +25 -0
- package/js/iso-objects/mono-paint.js +96 -0
- package/js/iso-objects/motion-builder.js +130 -0
- package/js/iso-objects/motion-doc.js +421 -0
- package/js/iso-objects/motion-entry.js +34 -0
- package/js/iso-objects/motion-schema.js +83 -0
- package/js/iso-objects/motion.js +640 -0
- package/js/iso-objects/resolve.js +238 -0
- package/js/iso-objects/scene.js +15 -13
- package/js/iso-objects/timeline.js +593 -0
- package/js/iso-systems/compile.js +83 -1
- package/js/iso-systems/index.js +4 -1
- package/js/iso-systems/render.js +20 -0
- package/js/iso-systems/schema.json +40 -0
- package/js/iso-viewer/index.js +6 -0
- package/js/iso-viewer/page.js +40 -16
- package/js/iso-viewer/play.js +340 -0
- package/js/iso-viewer/player.js +149 -175
- package/js/iso-viewer/transport.js +289 -0
- package/package.json +84 -2
- package/src/iso-core/index.ts +1 -0
- package/src/iso-core/mono.ts +306 -0
- package/src/iso-core/theme.ts +2 -1
- package/src/iso-editor/ui/canvas.ts +14 -1
- package/src/iso-objects/ants.ts +53 -0
- package/src/iso-objects/compile.ts +4 -1
- package/src/iso-objects/index.ts +16 -1
- package/src/iso-objects/looks.ts +21 -0
- package/src/iso-objects/mono-paint.ts +97 -0
- package/src/iso-objects/motion-builder.ts +79 -0
- package/src/iso-objects/motion-doc.ts +309 -0
- package/src/iso-objects/motion-entry.ts +13 -0
- package/src/iso-objects/motion-schema.ts +55 -0
- package/src/iso-objects/motion.ts +617 -0
- package/src/iso-objects/resolve.ts +196 -0
- package/src/iso-objects/scene.ts +32 -13
- package/src/iso-objects/timeline.ts +493 -0
- package/src/iso-objects/types.ts +22 -2
- package/src/iso-systems/compile.ts +86 -4
- package/src/iso-systems/index.ts +4 -1
- package/src/iso-systems/render.ts +45 -0
- package/src/iso-systems/schema.json +40 -0
- package/src/iso-viewer/index.ts +4 -0
- package/src/iso-viewer/page.ts +28 -11
- package/src/iso-viewer/play.ts +280 -0
- package/src/iso-viewer/player.ts +132 -150
- package/src/iso-viewer/transport.ts +272 -0
- package/types/iso-core/index.d.ts +1 -0
- package/types/iso-core/mono.d.ts +61 -0
- package/types/iso-core/theme.d.ts +2 -0
- package/types/iso-objects/ants.d.ts +34 -0
- package/types/iso-objects/compile.d.ts +3 -0
- package/types/iso-objects/index.d.ts +16 -1
- package/types/iso-objects/looks.d.ts +4 -0
- package/types/iso-objects/mono-paint.d.ts +20 -0
- package/types/iso-objects/motion-builder.d.ts +105 -0
- package/types/iso-objects/motion-doc.d.ts +193 -0
- package/types/iso-objects/motion-entry.d.ts +11 -0
- package/types/iso-objects/motion-schema.d.ts +594 -0
- package/types/iso-objects/motion.d.ts +202 -0
- package/types/iso-objects/resolve.d.ts +20 -0
- package/types/iso-objects/scene.d.ts +14 -0
- package/types/iso-objects/timeline.d.ts +66 -0
- package/types/iso-objects/types.d.ts +34 -0
- package/types/iso-systems/compile.d.ts +25 -3
- package/types/iso-systems/index.d.ts +4 -1
- package/types/iso-systems/render.d.ts +25 -0
- package/types/iso-viewer/index.d.ts +4 -0
- package/types/iso-viewer/play.d.ts +37 -0
- package/types/iso-viewer/transport.d.ts +73 -0
- package/types/player/isometric-diagram.d.ts +24 -0
package/js/iso-viewer/player.js
CHANGED
|
@@ -1,22 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const EASE_IN = "cubic-bezier(.16,.84,.3,1)";
|
|
5
|
-
function svgEl(tag, attrs, parent) {
|
|
6
|
-
const e = document.createElementNS(NS, tag);
|
|
7
|
-
for (const k in attrs) e.setAttribute(k, String(attrs[k]));
|
|
8
|
-
parent.appendChild(e);
|
|
9
|
-
return e;
|
|
10
|
-
}
|
|
1
|
+
import { paint, planOf } from "../iso-objects/motion.js";
|
|
2
|
+
import { bindMotion } from "../iso-objects/timeline.js";
|
|
3
|
+
import { transport } from "./transport.js";
|
|
11
4
|
const ease = (f) => f < 0.5 ? 2 * f * f : 1 - Math.pow(-2 * f + 2, 2) / 2;
|
|
5
|
+
const none = { ok: true, diags: [], duration: 0, beats: [], markers: {}, ambient: "on", loops: false, at: () => ({}), cues: () => void 0, beatAt: () => void 0, startOf: () => void 0 };
|
|
12
6
|
function init() {
|
|
13
7
|
const dataEl = document.getElementById("diagram-steps");
|
|
14
8
|
if (!dataEl) return;
|
|
15
9
|
const data = JSON.parse(dataEl.textContent || "{}");
|
|
16
10
|
const hash = location.hash;
|
|
17
11
|
const still = /still/.test(hash);
|
|
18
|
-
const
|
|
19
|
-
|
|
12
|
+
const asked = matchMedia("(prefers-reduced-motion: reduce)").matches && !still && !/motion/.test(hash);
|
|
13
|
+
let reduce = still;
|
|
20
14
|
const frozenT = Math.max(0, Math.min(1, Number((/[#&]t=([\d.]+)/.exec(hash) || [])[1] ?? 0.6)));
|
|
21
15
|
const wantScene = (/[#&]scene=([\w-]+)/.exec(hash) || [])[1];
|
|
22
16
|
const wantStep = Number((/[#&]step=?(\d+)/.exec(hash) || [])[1] || 0);
|
|
@@ -26,6 +20,7 @@ function init() {
|
|
|
26
20
|
if (still) document.documentElement.classList.add("still");
|
|
27
21
|
if (wantScene && !still) document.getElementById("scene-" + wantScene)?.scrollIntoView({ block: "start" });
|
|
28
22
|
const runners = [];
|
|
23
|
+
const offBtns = [];
|
|
29
24
|
for (const sd of data.scenes) {
|
|
30
25
|
const sec = document.getElementById("scene-" + sd.id);
|
|
31
26
|
if (sec) runners.push(makeRunner(sec, sd));
|
|
@@ -33,7 +28,6 @@ function init() {
|
|
|
33
28
|
function makeRunner(sec, sd) {
|
|
34
29
|
const STEPS = sd.steps, N = STEPS.length;
|
|
35
30
|
const svg = sec.querySelector("svg"), fig = sec.querySelector(".figure");
|
|
36
|
-
const anim = svg.querySelector(".g-anim");
|
|
37
31
|
const q = (s) => sec.querySelector(s);
|
|
38
32
|
const num = q(".cap-h .num"), hEl = q(".cap-h .h"), cnt = q(".cap-h .cnt");
|
|
39
33
|
const capT = q(".cap-t"), capC = q(".cap-c"), prog = q(".prog i"), dots = q(".dots");
|
|
@@ -56,11 +50,12 @@ function init() {
|
|
|
56
50
|
visEls.set(id, l);
|
|
57
51
|
}
|
|
58
52
|
}
|
|
59
|
-
const flowPath = (id) => svg.querySelector(`[data-hl="${CSS.escape(id)}"] path.flow`);
|
|
60
53
|
if (sd.dim === "all") svg.classList.add("dim-all");
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
54
|
+
const bound = sd.doc ? bindMotion(sd.source, sd.doc) : none, tl = bound.ok ? bound : none;
|
|
55
|
+
const tr = transport(tl, { loop: sd.loop });
|
|
56
|
+
tr.active = false;
|
|
57
|
+
let cur = 0, userPaused = false, active = false, stepping = false;
|
|
58
|
+
let assembling = false, assembled = false;
|
|
64
59
|
const setGrid = (on) => {
|
|
65
60
|
svg.classList.toggle("show-grid", on);
|
|
66
61
|
gridBtn?.setAttribute("aria-pressed", String(on));
|
|
@@ -75,72 +70,58 @@ function init() {
|
|
|
75
70
|
b.addEventListener("click", () => {
|
|
76
71
|
userPause();
|
|
77
72
|
finishAssemble();
|
|
78
|
-
show(i);
|
|
73
|
+
show(i, true);
|
|
79
74
|
});
|
|
80
75
|
dots?.appendChild(b);
|
|
81
76
|
});
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
if (
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
if (
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
if (!reduce && active) raf = requestAnimationFrame(tick);
|
|
77
|
+
const inkOf = new Map(STEPS.flatMap((s) => s.phases.flat().map((t) => [t.kind, t.color])));
|
|
78
|
+
function drawn() {
|
|
79
|
+
const S = reduce ? frozen() : tr.state(), s = STEPS[cur];
|
|
80
|
+
if (sd.own || !s) return S;
|
|
81
|
+
const out = {};
|
|
82
|
+
if (S.camera && !svg.classList.contains("all")) out.camera = S.camera;
|
|
83
|
+
if (S.tokens) out.tokens = S.tokens.map((k) => ({ ...k, color: k.color ?? (k.kind === void 0 ? void 0 : inkOf.get(k.kind)) }));
|
|
84
|
+
if (reduce) {
|
|
85
|
+
if (s.pulses.length) out.pulses = s.pulses.map(([x, y, rx, ry]) => ({ x, y, rx, ry, opacity: 0.85, color: s.color }));
|
|
86
|
+
} else if (S.pulses) out.pulses = s.pulses.flatMap(([x, y, rx, ry], k) => {
|
|
87
|
+
const p = S.pulses[k];
|
|
88
|
+
if (!p) return [];
|
|
89
|
+
const f = 1 - Math.pow(p.opacity ?? 1, 2), z = 0.35 + 1.15 * f;
|
|
90
|
+
return [{ x, y, rx: rx * z, ry: ry * z, opacity: 0.95 * (1 - f), color: s.color }];
|
|
91
|
+
});
|
|
92
|
+
return out;
|
|
100
93
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
const step = () => {
|
|
109
|
-
const f = D ? Math.min(1, (performance.now() - t0z) / D) : 1, e = ease(f);
|
|
110
|
-
view = from.map((v, k) => v + (target[k] - v) * e);
|
|
111
|
-
svg.setAttribute("viewBox", view.map((v) => v.toFixed(1)).join(" "));
|
|
112
|
-
if (f < 1) zoomTimer = window.setTimeout(step, 16);
|
|
113
|
-
};
|
|
114
|
-
step();
|
|
94
|
+
function frozen() {
|
|
95
|
+
const s = STEPS[cur], b = tl.beats[cur];
|
|
96
|
+
if (!s || !b) return {};
|
|
97
|
+
const S = tl.at(Math.max(b.start, b.end - 1), { ambient: "off" });
|
|
98
|
+
if (sd.own) return S;
|
|
99
|
+
const at = (kind) => kind === "blocked" ? frozenT < 0.7 ? frozenT / 0.7 : 1 - (frozenT - 0.7) / 0.3 * 0.25 : ease(frozenT);
|
|
100
|
+
return { ...S.camera ? { camera: S.camera } : {}, tokens: s.phases.flat().map((t) => ({ route: t.route, at: at(t.kind), kind: t.kind })) };
|
|
115
101
|
}
|
|
116
|
-
|
|
117
|
-
if (
|
|
118
|
-
|
|
119
|
-
|
|
102
|
+
const draw = () => {
|
|
103
|
+
if (assembling) return;
|
|
104
|
+
paint(svg, drawn());
|
|
105
|
+
if (prog && N) prog.style.width = (going() ? (tl.cues(tr.time)?.progress ?? 0) * 100 : (cur + 1) / N * 100) + "%";
|
|
106
|
+
};
|
|
107
|
+
const going = () => tr.playing && !stepping;
|
|
108
|
+
function look(i) {
|
|
120
109
|
const s = STEPS[i], n = s.n;
|
|
121
|
-
|
|
110
|
+
cur = i;
|
|
122
111
|
const lit = new Set(s.lit);
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
112
|
+
if (!sd.own) {
|
|
113
|
+
svg.classList.add("focus");
|
|
114
|
+
for (const e of hlEls) e.classList.toggle("hl", e.dataset.hl.split(" ").some((x) => lit.has(x)));
|
|
115
|
+
if (sd.dim === "all") {
|
|
116
|
+
for (const e of idEls) if (e.hasAttribute("data-dim")) e.classList.toggle("hl", lit.has(e.dataset.id));
|
|
117
|
+
}
|
|
118
|
+
for (const [id, els] of visEls) {
|
|
119
|
+
const v = sd.vis[id][i];
|
|
120
|
+
for (const e of els) e.classList.toggle("pre", !v);
|
|
121
|
+
}
|
|
127
122
|
}
|
|
128
123
|
for (const e of stepEls) e.classList.toggle("on", e.dataset.step === String(n));
|
|
129
124
|
svg.querySelectorAll("[data-badge]").forEach((b) => b.classList.toggle("on", b.dataset.badge === String(n)));
|
|
130
|
-
for (const [id, els] of visEls) {
|
|
131
|
-
const v = sd.vis[id][i];
|
|
132
|
-
for (const e of els) e.classList.toggle("pre", !v);
|
|
133
|
-
}
|
|
134
|
-
for (const [x, y, rx, ry] of s.pulses) svgEl("ellipse", { cx: x, cy: y, rx, ry, class: "pulse", style: `stroke:${s.color}` }, anim);
|
|
135
|
-
groups = s.phases.length;
|
|
136
|
-
s.phases.forEach((ph, gi) => ph.forEach((tk) => {
|
|
137
|
-
const path = flowPath(tk.route);
|
|
138
|
-
if (!path) return;
|
|
139
|
-
tokens.push({ path, len: path.getTotalLength(), gi, stop: tk.kind === "blocked", c: svgEl("circle", { r: 7, class: "tok", style: `fill:${tk.color}` }, anim) });
|
|
140
|
-
}));
|
|
141
|
-
t0 = performance.now();
|
|
142
|
-
tick(t0);
|
|
143
|
-
if (!reduce && active && !raf) raf = requestAnimationFrame(tick);
|
|
144
125
|
num.textContent = String(s.num);
|
|
145
126
|
num.style.background = s.color;
|
|
146
127
|
hEl.textContent = s.heading;
|
|
@@ -152,100 +133,84 @@ function init() {
|
|
|
152
133
|
d.classList.toggle("on", j === i);
|
|
153
134
|
d.classList.toggle("done", j < i);
|
|
154
135
|
});
|
|
155
|
-
restartProg();
|
|
156
136
|
}
|
|
157
|
-
function
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
137
|
+
function show(i, through = false) {
|
|
138
|
+
const b = tl.beats[i];
|
|
139
|
+
if (!N || !b) return;
|
|
140
|
+
tr.pause();
|
|
141
|
+
look(i);
|
|
142
|
+
tr.seek(b.start, { join: true });
|
|
143
|
+
if (through && !reduce && active) {
|
|
144
|
+
stepping = true;
|
|
145
|
+
tr.play({ until: Math.max(b.start + 1, b.end - 1) });
|
|
146
|
+
setBtn();
|
|
165
147
|
}
|
|
166
|
-
|
|
167
|
-
function schedule() {
|
|
168
|
-
clearTimeout(timer);
|
|
169
|
-
if (!playing) return;
|
|
170
|
-
timer = window.setTimeout(() => {
|
|
171
|
-
if (cur === N - 1 && !sd.loop) {
|
|
172
|
-
stop();
|
|
173
|
-
return;
|
|
174
|
-
}
|
|
175
|
-
show((cur + 1) % N);
|
|
176
|
-
schedule();
|
|
177
|
-
}, STEPS[cur].duration);
|
|
148
|
+
draw();
|
|
178
149
|
}
|
|
179
150
|
function setBtn() {
|
|
180
151
|
if (!playBtn) return;
|
|
181
|
-
playBtn.
|
|
182
|
-
|
|
183
|
-
|
|
152
|
+
playBtn.disabled = reduce;
|
|
153
|
+
if (reduce) {
|
|
154
|
+
playBtn.textContent = "Motion off";
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
const on = going();
|
|
158
|
+
playBtn.textContent = on ? "\u275A\u275A Pause" : "\u25B6 Play";
|
|
159
|
+
playBtn.setAttribute("aria-label", on ? "Pause" : "Play");
|
|
160
|
+
capBox?.setAttribute("aria-live", on ? "off" : "polite");
|
|
184
161
|
}
|
|
185
162
|
function play() {
|
|
186
163
|
if (reduce || !N || assembling) return;
|
|
187
|
-
|
|
164
|
+
if (stepping) tr.pause();
|
|
165
|
+
stepping = false;
|
|
166
|
+
tr.play();
|
|
188
167
|
setBtn();
|
|
189
|
-
|
|
190
|
-
schedule();
|
|
168
|
+
draw();
|
|
191
169
|
}
|
|
192
170
|
function stop() {
|
|
193
|
-
|
|
194
|
-
clearTimeout(timer);
|
|
195
|
-
setBtn();
|
|
196
|
-
restartProg();
|
|
171
|
+
tr.pause();
|
|
197
172
|
}
|
|
198
173
|
function userPause() {
|
|
199
174
|
userPaused = true;
|
|
200
175
|
stop();
|
|
201
176
|
}
|
|
202
|
-
|
|
203
|
-
|
|
177
|
+
tr.on("time", draw);
|
|
178
|
+
tr.on("beat", (b) => {
|
|
179
|
+
if (b.index !== cur) look(b.index);
|
|
180
|
+
});
|
|
181
|
+
tr.on("pause", () => {
|
|
182
|
+
stepping = false;
|
|
183
|
+
setBtn();
|
|
184
|
+
draw();
|
|
185
|
+
});
|
|
186
|
+
const plan = planOf(sd.source.model, "assemble");
|
|
187
|
+
let intro;
|
|
204
188
|
function finishAssemble() {
|
|
205
|
-
if (!assembling) return;
|
|
206
|
-
|
|
189
|
+
if (!assembling || !intro) return;
|
|
190
|
+
intro.dispose();
|
|
191
|
+
intro = void 0;
|
|
192
|
+
assembling = false;
|
|
193
|
+
assembled = true;
|
|
194
|
+
paint(svg, {});
|
|
195
|
+
if (N) show(cur);
|
|
196
|
+
if (active && !userPaused) play();
|
|
207
197
|
}
|
|
208
198
|
function assemble(freezeAt) {
|
|
209
|
-
|
|
210
|
-
|
|
199
|
+
intro?.dispose();
|
|
200
|
+
intro = void 0;
|
|
211
201
|
stop();
|
|
212
202
|
if (N) show(cur);
|
|
213
|
-
clearAnim();
|
|
214
203
|
svg.classList.remove("focus", "pre-assemble", "all");
|
|
215
204
|
assembling = true;
|
|
216
|
-
const run = (el, frames, delay, dur, easing = EASE_IN) => animations.push(el.animate(frames, { delay, duration: dur, easing, fill: "backwards" }));
|
|
217
|
-
const solid = ["base", "blocks", "air"].map(layer).filter(Boolean);
|
|
218
|
-
for (const p of A.pieces) {
|
|
219
|
-
const from = `translate(${p.dx}px, ${p.dy}px)`;
|
|
220
|
-
for (const L of solid) L.querySelectorAll(`[data-id="${CSS.escape(p.id)}"]`).forEach((el) => run(el, [{ transform: from }, { transform: "translate(0px, 0px)" }], p.delay, p.dur));
|
|
221
|
-
}
|
|
222
|
-
for (const r of A.routes) {
|
|
223
|
-
const g = layer("flows")?.querySelector(`[data-hl="${CSS.escape(r.id)}"]`);
|
|
224
|
-
const path = g?.querySelector("path.flow");
|
|
225
|
-
if (!g || !path) continue;
|
|
226
|
-
const len = path.getTotalLength();
|
|
227
|
-
run(g, [{ opacity: 0 }, { opacity: 1 }], r.delay, 80, "linear");
|
|
228
|
-
run(path, [{ strokeDasharray: `${len} ${len}`, strokeDashoffset: len }, { strokeDasharray: `${len} ${len}`, strokeDashoffset: 0 }], r.delay, r.dur, "ease-out");
|
|
229
|
-
}
|
|
230
|
-
for (const name of ["floor", "labels", "badges"]) {
|
|
231
|
-
const L = layer(name);
|
|
232
|
-
if (L) run(L, [{ opacity: 0 }, { opacity: 1 }], A.labels.delay, A.labels.dur, "ease-out");
|
|
233
|
-
}
|
|
234
205
|
if (freezeAt !== void 0) {
|
|
235
|
-
|
|
236
|
-
a.pause();
|
|
237
|
-
a.currentTime = freezeAt;
|
|
238
|
-
}
|
|
206
|
+
paint(svg, plan.at(freezeAt));
|
|
239
207
|
return;
|
|
240
208
|
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
if (active && !userPaused) play();
|
|
247
|
-
}, () => {
|
|
248
|
-
});
|
|
209
|
+
const run = intro = transport({ ...none, duration: plan.duration, at: (t) => plan.at(t) });
|
|
210
|
+
run.on("time", (t) => paint(svg, plan.at(t)));
|
|
211
|
+
run.on("end", finishAssemble);
|
|
212
|
+
paint(svg, plan.at(0));
|
|
213
|
+
run.play();
|
|
249
214
|
}
|
|
250
215
|
asmBtn?.addEventListener("click", () => {
|
|
251
216
|
userPaused = false;
|
|
@@ -254,36 +219,29 @@ function init() {
|
|
|
254
219
|
function setActive(on) {
|
|
255
220
|
if (on === active) return;
|
|
256
221
|
active = on;
|
|
222
|
+
tr.active = on && !reduce;
|
|
257
223
|
if (on) {
|
|
258
|
-
if (!reduce) {
|
|
259
|
-
t0 = performance.now();
|
|
260
|
-
raf = requestAnimationFrame(tick);
|
|
261
|
-
}
|
|
262
224
|
if (!userPaused) play();
|
|
263
|
-
} else
|
|
264
|
-
stop();
|
|
265
|
-
if (raf) cancelAnimationFrame(raf);
|
|
266
|
-
raf = 0;
|
|
267
|
-
}
|
|
225
|
+
} else stop();
|
|
268
226
|
}
|
|
269
227
|
playBtn?.addEventListener("click", () => {
|
|
270
|
-
if (
|
|
228
|
+
if (going()) userPause();
|
|
271
229
|
else {
|
|
272
230
|
userPaused = false;
|
|
273
231
|
finishAssemble();
|
|
274
|
-
if (cur === N - 1) show(0);
|
|
232
|
+
if (cur === N - 1 && !going()) show(0);
|
|
275
233
|
play();
|
|
276
234
|
}
|
|
277
235
|
});
|
|
278
236
|
q("[data-a=next]")?.addEventListener("click", () => {
|
|
279
237
|
userPause();
|
|
280
238
|
finishAssemble();
|
|
281
|
-
show(Math.min(N - 1, cur + 1));
|
|
239
|
+
show(Math.min(N - 1, cur + 1), true);
|
|
282
240
|
});
|
|
283
241
|
q("[data-a=prev]")?.addEventListener("click", () => {
|
|
284
242
|
userPause();
|
|
285
243
|
finishAssemble();
|
|
286
|
-
show(Math.max(0, cur - 1));
|
|
244
|
+
show(Math.max(0, cur - 1), true);
|
|
287
245
|
});
|
|
288
246
|
fig.addEventListener("keydown", (e) => {
|
|
289
247
|
const k = e.key;
|
|
@@ -292,20 +250,20 @@ function init() {
|
|
|
292
250
|
e.preventDefault();
|
|
293
251
|
userPause();
|
|
294
252
|
finishAssemble();
|
|
295
|
-
show(Math.min(N - 1, cur + 1));
|
|
253
|
+
show(Math.min(N - 1, cur + 1), true);
|
|
296
254
|
}
|
|
297
255
|
if (k === "ArrowLeft") {
|
|
298
256
|
e.preventDefault();
|
|
299
257
|
userPause();
|
|
300
258
|
finishAssemble();
|
|
301
|
-
show(Math.max(0, cur - 1));
|
|
259
|
+
show(Math.max(0, cur - 1), true);
|
|
302
260
|
}
|
|
303
261
|
});
|
|
304
262
|
svg.querySelectorAll(".badge").forEach((b) => {
|
|
305
263
|
const go = () => {
|
|
306
264
|
userPause();
|
|
307
265
|
finishAssemble();
|
|
308
|
-
show(Number(b.dataset.go) - 1);
|
|
266
|
+
show(Number(b.dataset.go) - 1, true);
|
|
309
267
|
};
|
|
310
268
|
b.addEventListener("click", go);
|
|
311
269
|
b.addEventListener("keydown", (e) => {
|
|
@@ -318,23 +276,39 @@ function init() {
|
|
|
318
276
|
});
|
|
319
277
|
const forced = wantStep && (!wantScene || wantScene === sd.id) ? Math.min(N, wantStep) - 1 : -1;
|
|
320
278
|
const frozenAssemble = wantAssemble && assembleAt !== void 0 && (!wantScene || wantScene === sd.id);
|
|
321
|
-
if (
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
}
|
|
330
|
-
if (asmBtn) asmBtn.disabled = true;
|
|
331
|
-
sec.querySelector("details.steps")?.setAttribute("open", "");
|
|
332
|
-
} else {
|
|
333
|
-
if (N) show(forced >= 0 ? forced : 0);
|
|
334
|
-
if (reduce && playBtn) {
|
|
335
|
-
playBtn.disabled = true;
|
|
336
|
-
playBtn.textContent = "Motion off";
|
|
279
|
+
if (N) show(forced >= 0 ? forced : 0);
|
|
280
|
+
setBtn();
|
|
281
|
+
function setMotion() {
|
|
282
|
+
svg.classList.remove("pre-assemble");
|
|
283
|
+
if (reduce) {
|
|
284
|
+
assembled = true;
|
|
285
|
+
finishAssemble();
|
|
286
|
+
stop();
|
|
337
287
|
}
|
|
288
|
+
svg.classList.toggle("all", reduce && N > 0);
|
|
289
|
+
tr.active = active && !reduce;
|
|
290
|
+
if (asmBtn) asmBtn.disabled = reduce;
|
|
291
|
+
if (reduce) sec.querySelector("details.steps")?.setAttribute("open", "");
|
|
292
|
+
if (N) show(reduce ? N - 1 : 0);
|
|
293
|
+
setBtn();
|
|
294
|
+
if (!reduce && active && !userPaused) play();
|
|
295
|
+
}
|
|
296
|
+
const tools = q(".tools");
|
|
297
|
+
if (asked && tools) {
|
|
298
|
+
const b = document.createElement("button");
|
|
299
|
+
b.type = "button";
|
|
300
|
+
b.className = "pbtn small";
|
|
301
|
+
b.dataset.a = "motion";
|
|
302
|
+
b.textContent = "Motion off";
|
|
303
|
+
b.title = "Draw everything in place, with nothing moving";
|
|
304
|
+
b.setAttribute("aria-pressed", "false");
|
|
305
|
+
b.addEventListener("click", () => {
|
|
306
|
+
reduce = !reduce;
|
|
307
|
+
for (const x of offBtns) x.setAttribute("aria-pressed", String(reduce));
|
|
308
|
+
for (const r of runners) r.setMotion();
|
|
309
|
+
});
|
|
310
|
+
offBtns.push(b);
|
|
311
|
+
tools.appendChild(b);
|
|
338
312
|
}
|
|
339
313
|
if (frozenAssemble) assemble(Number(assembleAt));
|
|
340
314
|
else if ((sd.assemble || wantAssemble) && !reduce && !window.__diagramNoIntro) {
|
|
@@ -364,9 +338,9 @@ function init() {
|
|
|
364
338
|
addEventListener("scroll", check, { passive: true });
|
|
365
339
|
setTimeout(check, 60);
|
|
366
340
|
}
|
|
367
|
-
return { fig, setActive };
|
|
341
|
+
return { fig, setActive, setMotion };
|
|
368
342
|
}
|
|
369
|
-
if (!
|
|
343
|
+
if (!still) {
|
|
370
344
|
const ratio = /* @__PURE__ */ new Map();
|
|
371
345
|
const pick = () => {
|
|
372
346
|
let best, br = 0;
|