truemap-cli 0.2.0 → 0.5.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.
@@ -0,0 +1,329 @@
1
+ // Draws the wires of every .tm-map from data-to="id id:label". Used by the page SDK and by exported pages.
2
+ // Plain script, no dependencies: defines window.truemapWires.draw().
3
+ //
4
+ // Rules that keep the map honest:
5
+ // - a wire only touches its own two boxes; layers in between are crossed through free columns
6
+ // - every horizontal run in a gap between layers gets its own track (wires from the same box may share one)
7
+ // - a gap grows when it needs more tracks
8
+ // - exits leave from the middle of a box, entries arrive in its left third (upward ones: right third)
9
+ (() => {
10
+ if (window.truemapWires) return;
11
+ const SVGNS = 'http://www.w3.org/2000/svg';
12
+ const LANE = 9; const R = 7;
13
+
14
+ // An orthogonal path through the given points with rounded corners.
15
+ function ortho(points) {
16
+ const pts = points.filter((p, i) => i === 0 || p[0] !== points[i - 1][0] || p[1] !== points[i - 1][1]);
17
+ let d = `M${pts[0][0]},${pts[0][1]}`;
18
+ for (let i = 1; i < pts.length - 1; i++) {
19
+ const [px, py] = pts[i - 1]; const [x, y] = pts[i]; const [nx, ny] = pts[i + 1];
20
+ const l1 = Math.hypot(x - px, y - py); const l2 = Math.hypot(nx - x, ny - y);
21
+ if (!l1 || !l2 || (px === x && x === nx) || (py === y && y === ny)) continue;
22
+ const rr = Math.min(R, l1 / 2, l2 / 2);
23
+ d += ` L${x - ((x - px) / l1) * rr},${y - ((y - py) / l1) * rr} Q${x},${y} ${x + ((nx - x) / l2) * rr},${y + ((ny - y) / l2) * rr}`;
24
+ }
25
+ const last = pts[pts.length - 1];
26
+ return `${d} L${last[0]},${last[1]}`;
27
+ }
28
+
29
+ function drawMap(map) {
30
+ map.querySelector(':scope > svg.tm-wires')?.remove();
31
+ const sources = [...map.querySelectorAll('[data-to]')];
32
+ if (!sources.length) return false;
33
+ // Coordinates live in the map's scroll space, so wires scroll with the boxes.
34
+ const box = map.getBoundingClientRect();
35
+ const ox = box.left + map.clientLeft - map.scrollLeft; const oy = box.top + map.clientTop - map.scrollTop;
36
+ const rel = (r) => ({ l: r.left - ox, r: r.right - ox, t: r.top - oy, b: r.bottom - oy, cx: (r.left + r.right) / 2 - ox, cy: (r.top + r.bottom) / 2 - oy });
37
+ const rects = [...map.querySelectorAll('.tm-node, .tm-step')].map((n) => ({ n, ...rel(n.getBoundingClientRect()) }));
38
+ const rectOf = new Map(rects.map((o) => [o.n, o]));
39
+
40
+ // Rows: boxes that overlap vertically. Gap i lies between row i and row i+1.
41
+ const rows = [];
42
+ for (const o of [...rects].sort((p, q) => p.t - q.t)) {
43
+ const row = rows.find((w) => o.t < w.b - 2 && o.b > w.t + 2);
44
+ if (row) { row.t = Math.min(row.t, o.t); row.b = Math.max(row.b, o.b); row.items.push(o); } else rows.push({ t: o.t, b: o.b, items: [o] });
45
+ }
46
+ rows.sort((p, q) => p.t - q.t);
47
+ const rowOf = (o) => rows.findIndex((w) => w.items.includes(o));
48
+
49
+ const edges = [];
50
+ for (const src of sources) {
51
+ for (const spec of src.getAttribute('data-to').split(/[\s,]+/).filter(Boolean)) {
52
+ const [id, ...labelParts] = spec.split(':');
53
+ const dst = document.getElementById(id);
54
+ if (!dst || dst === src || !map.contains(dst) || !rectOf.has(src) || !rectOf.has(dst)) continue;
55
+ const a = rectOf.get(src); const b = rectOf.get(dst);
56
+ const ra = rowOf(a); const rb = rowOf(b);
57
+ edges.push({ src, dst, a, b, ra, rb, dir: rb > ra ? 'down' : rb < ra ? 'up' : 'same', label: labelParts.join(':').replace(/\\_/g, '\u0001').replace(/_/g, ' ').replace(/\u0001/g, '_') });
58
+ }
59
+ }
60
+ const group = (key, pick) => {
61
+ const m = new Map();
62
+ for (const e of edges.filter(pick)) (m.get(e[key]) || m.set(e[key], []).get(e[key])).push(e);
63
+ for (const l of m.values()) l.sort((p, q) => (key === 'src' ? p.b.cx - q.b.cx : p.a.cx - q.a.cx));
64
+ return m;
65
+ };
66
+ const downOut = group('src', (e) => e.dir === 'down'); const downIn = group('dst', (e) => e.dir === 'down');
67
+ const upOut = group('src', (e) => e.dir === 'up'); const upIn = group('dst', (e) => e.dir === 'up');
68
+ const slot = (list, e) => list.indexOf(e) - (list.length - 1) / 2;
69
+
70
+ // Free vertical columns through rows lo..hi (exclusive of the wire's own boxes), one wire per column.
71
+ const columns = [];
72
+ function column(e, lo, hi, prefer) {
73
+ const blockers = rects.filter((o) => { const r = rowOf(o); return r > lo && r < hi; });
74
+ const free = (x) => !blockers.some((o) => x > o.l - 7 && x < o.r + 7)
75
+ && !columns.some((c) => Math.abs(c.x - x) < 8 && c.src !== e.src && c.lo < hi && c.hi > lo);
76
+ const cands = [prefer[0], prefer[1], ...blockers.flatMap((o) => [o.l - 13, o.r + 13])];
77
+ for (const c of [...cands]) for (let k = 1; k <= 4; k++) cands.push(c + k * 9, c - k * 9);
78
+ const x = cands.filter(free).sort((p, q) => Math.abs(p - prefer[0]) + Math.abs(p - prefer[1]) - Math.abs(q - prefer[0]) - Math.abs(q - prefer[1]))[0] ?? prefer[0];
79
+ columns.push({ x, lo, hi, src: e.src });
80
+ return x;
81
+ }
82
+
83
+ // Plan every wire. Horizontal runs in a gap are recorded as lane requests and get their y later.
84
+ const lanes = new Map(); // gap index -> [{x1, x2, src, ref}]
85
+ const lane = (gap, x1, x2, e) => { const ref = { y: null, gap }; ref.item = { x1: Math.min(x1, x2), x2: Math.max(x1, x2), src: e.src, ref }; (lanes.get(gap) || lanes.set(gap, []).get(gap)).push(ref.item); return ref; };
86
+ const plans = [];
87
+ for (const e of edges) {
88
+ const { a, b } = e;
89
+ if (e.dir === 'down') {
90
+ const sx = a.cx + slot(downOut.get(e.src), e) * 14; const sy = a.b; const ty = b.t - 6;
91
+ const ins = downIn.get(e.dst); const ti = ins.indexOf(e);
92
+ const straight = ins.length === 1 && Math.abs(a.cx - b.cx) < 4;
93
+ const tx = straight ? b.cx : Math.min(b.l + 26 + ti * 14, b.cx - 14);
94
+ if (e.rb === e.ra + 1) {
95
+ if (Math.abs(sx - tx) < 1) plans.push({ e, pts: [[sx, sy], [tx, ty]], head: 'down', tx, ty, label: { x: sx + 6, y: sy + 13 } });
96
+ else { const y = lane(e.ra, sx, tx, e); plans.push({ e, pts: [[sx, sy], [sx, y], [tx, y], [tx, ty]], head: 'down', tx, ty, label: { x: sx + 6, y: sy + 13 } }); }
97
+ } else {
98
+ const x = column(e, e.ra, e.rb, [sx, tx]);
99
+ const y1 = lane(e.ra, sx, x, e); const y2 = lane(e.rb - 1, x, tx, e);
100
+ plans.push({ e, pts: [[sx, sy], [sx, y1], [x, y1], [x, y2], [tx, y2], [tx, ty]], head: 'down', tx, ty, label: { x: sx + 6, y: sy + 13 } });
101
+ }
102
+ } else if (e.dir === 'up') {
103
+ const sx = a.r - 26 - (slot(upOut.get(e.src), e) + (upOut.get(e.src).length - 1) / 2) * 14; const sy = a.t;
104
+ const tx = b.r - 26 - upIn.get(e.dst).indexOf(e) * 14; const ty = b.b + 6;
105
+ if (e.rb === e.ra - 1) {
106
+ const y = lane(e.rb, sx, tx, e);
107
+ plans.push({ e, pts: [[sx, sy], [sx, y], [tx, y], [tx, ty]], head: 'up', tx, ty, label: { x: sx + 6, y: sy - 6 } });
108
+ } else {
109
+ const x = column(e, e.rb, e.ra, [sx, tx]);
110
+ const y1 = lane(e.ra - 1, sx, x, e); const y2 = lane(e.rb, x, tx, e);
111
+ plans.push({ e, pts: [[sx, sy], [sx, y1], [x, y1], [x, y2], [tx, y2], [tx, ty]], head: 'up', tx, ty, label: { x: sx + 6, y: sy - 6 } });
112
+ }
113
+ } else {
114
+ const blocked = rects.some((o) => o.n !== e.src && o.n !== e.dst && rowOf(o) === e.ra && o.l >= Math.min(a.r, b.r) - 1 && o.r <= Math.max(a.l, b.l) + 1);
115
+ if (!blocked) { // side by side
116
+ const right = b.l >= a.r; const sx = right ? a.r : a.l; const tx = right ? b.l - 6 : b.r + 6;
117
+ plans.push({ e, pts: [[sx, a.cy], [(sx + tx) / 2, a.cy], [(sx + tx) / 2, b.cy], [tx, b.cy]], head: right ? 'right' : 'left', tx, ty: b.cy, label: { x: (sx + tx) / 2, y: Math.min(a.t, b.t) - 6, middle: true } });
118
+ } else { // boxes in between: over the row (under it for the first row)
119
+ const over = e.ra > 0;
120
+ const sx = a.cx + (b.cx > a.cx ? 18 : -18); const tx = b.cx + (b.cx > a.cx ? -18 : 18);
121
+ const sy = over ? a.t : a.b; const ty = over ? b.t - 6 : b.b + 6;
122
+ const y = lane(over ? e.ra - 1 : e.ra, sx, tx, e);
123
+ plans.push({ e, pts: [[sx, sy], [sx, y], [tx, y], [tx, ty]], head: over ? 'down' : 'up', tx, ty, label: { x: sx + 6, y: over ? sy - 6 : sy + 13 } });
124
+ }
125
+ }
126
+ }
127
+
128
+ // Entries keep clear of unrelated vertical lines in the same gap (at least 18px), sliding within the
129
+ // target box, so an entry never looks like the continuation of another box's exit.
130
+ const stems = [];
131
+ for (const p of plans) {
132
+ const P = p.pts;
133
+ if (P.length === 2 && P[0][0] === P[1][0] && p.head === 'down') { stems.push({ p, kind: 'straight', gap: p.e.ra, x: () => P[0][0] }); continue; }
134
+ if (P.length < 4 || typeof P[1][1] !== 'object') continue;
135
+ stems.push({ p, kind: 'exit', gap: P[1][1].gap, x: () => P[0][0] });
136
+ stems.push({ p, kind: 'entry', gap: P[P.length - 2][1].gap, x: () => P[P.length - 1][0] });
137
+ }
138
+ const shares = (p, q) => [p.e.src, p.e.dst].some((n) => n === q.e.src || n === q.e.dst);
139
+ for (const s of stems.filter((t) => t.kind === 'entry')) {
140
+ const clash = (x) => stems.some((o) => o.p !== s.p && !shares(o.p, s.p) && o.gap === s.gap && Math.abs(o.x() - x) < 18);
141
+ const x0 = s.x(); if (!clash(x0)) continue;
142
+ const b = s.p.e.b; const cands = [];
143
+ for (let k = 1; k <= 16; k++) cands.push(x0 + k * 7, x0 - k * 7);
144
+ const nx = cands.find((x) => x > b.l + 10 && x < b.r - 10 && !clash(x));
145
+ if (nx === undefined) continue;
146
+ const P = s.p.pts; P[P.length - 1][0] = nx; P[P.length - 2][0] = nx; s.p.tx = nx;
147
+ const item = P[P.length - 2][1].item; item.x1 = Math.min(item.x1, nx); item.x2 = Math.max(item.x2, nx);
148
+ }
149
+
150
+ // Tracks: interval colouring per gap. Wires from the same box may share a track.
151
+ let grow = false;
152
+ for (const [gap, items] of lanes) {
153
+ items.sort((p, q) => p.x1 - q.x1);
154
+ const tracks = [];
155
+ for (const it of items) {
156
+ let t = tracks.find((k) => k.srcs.has(it.src) || k.end < it.x1 - 10);
157
+ if (!t) { t = { end: -Infinity, srcs: new Set() }; tracks.push(t); }
158
+ if (!(t.srcs.has(it.src) || t.end < it.x1 - 10)) { t.srcs.clear(); }
159
+ t.end = Math.max(t.end, it.x2); t.srcs.add(it.src); it.track = tracks.indexOf(t);
160
+ }
161
+ const top = gap >= 0 && gap < rows.length - 1 ? rows[gap].b : rows[0].t - 40;
162
+ const bottom = gap >= 0 && gap < rows.length - 1 ? rows[gap + 1].t : rows[0].t;
163
+ const need = tracks.length * LANE + 22;
164
+ if (gap >= 0 && gap < rows.length - 1 && bottom - top < need) {
165
+ // Make room: push the next layer down.
166
+ const layer = rows[gap + 1].items[0].n.closest('.tm-layer');
167
+ if (layer) {
168
+ const cur = parseFloat(getComputedStyle(layer).marginTop) || 0;
169
+ layer.dataset.tmGrown = '1';
170
+ layer.style.marginTop = `${cur + (need - (bottom - top))}px`;
171
+ grow = true;
172
+ }
173
+ }
174
+ const mid = (top + bottom) / 2;
175
+ for (const it of items) it.ref.y = mid + (it.track - (tracks.length - 1) / 2) * LANE;
176
+ }
177
+ if (grow) return true; // layout changed: draw again
178
+
179
+ // Draw.
180
+ const w = map.scrollWidth; const h = map.scrollHeight;
181
+ const svg = document.createElementNS(SVGNS, 'svg');
182
+ svg.setAttribute('class', 'tm-wires'); svg.setAttribute('aria-hidden', 'true');
183
+ svg.setAttribute('width', w); svg.setAttribute('height', h); svg.setAttribute('viewBox', `0 0 ${w} ${h}`);
184
+ const segsOf = new Map(); // plan -> its straight segments, for label placement
185
+ for (const p of plans) {
186
+ const pts = p.pts.map(([x, y]) => [x, typeof y === 'object' ? y.y : y]);
187
+ p.resolved = pts;
188
+ segsOf.set(p, pts.slice(1).map((q, i) => [pts[i][0], pts[i][1], q[0], q[1]]));
189
+ }
190
+ const isKey = (p) => p.e.src.classList.contains('is-key') && p.e.dst.classList.contains('is-key');
191
+ for (const p of plans) {
192
+ const { e } = p;
193
+ const key = isKey(p);
194
+ const ext = e.dst.classList.contains('is-ext') || e.src.classList.contains('is-ext');
195
+ const pts = p.resolved;
196
+ const path = document.createElementNS(SVGNS, 'path');
197
+ path.setAttribute('d', ortho(pts)); path.setAttribute('class', `tm-wire${key ? ' is-key' : ''}${ext ? ' is-ext' : ''}`);
198
+ const { tx, ty } = p;
199
+ const head = { down: `M${tx - 4.5},${ty - 1} L${tx + 4.5},${ty - 1} L${tx},${ty + 6} Z`, up: `M${tx - 4.5},${ty + 1} L${tx + 4.5},${ty + 1} L${tx},${ty - 6} Z`,
200
+ right: `M${tx - 1},${ty - 4.5} L${tx - 1},${ty + 4.5} L${tx + 6},${ty} Z`, left: `M${tx + 1},${ty - 4.5} L${tx + 1},${ty + 4.5} L${tx - 6},${ty} Z` }[p.head];
201
+ const arrow = document.createElementNS(SVGNS, 'path');
202
+ arrow.setAttribute('d', head); arrow.setAttribute('class', `tm-wire-head${key ? ' is-key' : ''}`);
203
+ for (const el of [path, arrow]) { el.dataset.from = e.src.id; el.dataset.to = e.dst.id; }
204
+ svg.appendChild(path); svg.appendChild(arrow);
205
+ }
206
+ // key wires on top
207
+ [...svg.querySelectorAll('.tm-wire.is-key, .tm-wire-head.is-key')].forEach((el) => svg.appendChild(el));
208
+ map.insertBefore(svg, map.firstChild);
209
+ map.__tm = { plans, segsOf, rects, w, h, svg, isKey };
210
+ placeLabels(map, labelState);
211
+ markScroll(map);
212
+ return false;
213
+ }
214
+
215
+ // ---------- labels: placed for what is visible right now ----------
216
+ // Only some labels show at a time: the main path's by default; a hovered box's own wires; a lit path's wires.
217
+ // Each time that changes, the visible labels are placed afresh. A label goes on its own wire, at the first spot
218
+ // (walking from where the wire leaves its box) that touches no box, no other shown label and no wire that is
219
+ // drawn strongly at that moment. With no such spot the label is left off the map; the box's peek still lists it.
220
+ let labelState = {};
221
+ const segHits = ([x1, y1, x2, y2], b) => (x1 === x2
222
+ ? x1 > b.l - 2 && x1 < b.r + 2 && Math.max(y1, y2) > b.t && Math.min(y1, y2) < b.b
223
+ : y1 > b.t - 2 && y1 < b.b + 2 && Math.max(x1, x2) > b.l && Math.min(x1, x2) < b.r);
224
+ function placeLabels(map, state) {
225
+ const m = map.__tm; if (!m) return;
226
+ const { plans, segsOf, rects, w, h, svg, isKey } = m;
227
+ for (const el of svg.querySelectorAll('.tm-wire-label, .tm-wire-plate')) el.remove();
228
+ const hot = state.hot || null; const focus = state.focus && state.focus.size ? state.focus : null;
229
+ const isHot = (p) => !!hot && (p.e.src.id === hot || p.e.dst.id === hot);
230
+ const isFocus = (p) => !!focus && focus.has(p.e.src.id) && focus.has(p.e.dst.id);
231
+ const shown = (p) => (focus ? isFocus(p) || isHot(p) : isKey(p) || isHot(p));
232
+ // Wires a label must keep clear of: the ones drawn strongly right now. Faint wires pass under the label's
233
+ // paper plate, which interrupts them the way a map interrupts a road under a place name.
234
+ const strong = (p) => (focus ? isFocus(p) || isHot(p) : isKey(p) || isHot(p));
235
+ const order = focus ? [...plans.filter(isFocus), ...plans.filter((p) => !isFocus(p) && isHot(p))]
236
+ : [...plans.filter(isKey), ...plans.filter((p) => !isKey(p) && isHot(p))];
237
+ const placed = []; const used = new Map();
238
+ for (const p of order) {
239
+ const { e } = p;
240
+ const texts = used.get(e.src) || used.set(e.src, []).get(e.src);
241
+ if (!e.label || texts.includes(e.label)) continue;
242
+ const lw = e.label.length * 6.4;
243
+ const cands = [];
244
+ for (const [x1, y1, x2, y2] of segsOf.get(p)) {
245
+ if (x1 === x2) {
246
+ const lo = Math.min(y1, y2); const hi = Math.max(y1, y2);
247
+ for (let y = lo + 15; y <= hi - 1; y += 7) cands.push({ x: x1 + 6, y, anchor: 'start' }, { x: x1 - 6, y, anchor: 'end' });
248
+ } else {
249
+ const lo = Math.min(x1, x2); const hi = Math.max(x1, x2);
250
+ for (let x = lo + 6; x + lw <= hi - 2; x += 12) cands.push({ x, y: y1 - 5, anchor: 'start' }, { x, y: y1 + 14, anchor: 'start' });
251
+ }
252
+ }
253
+ const boxOf = (c) => { const l = c.anchor === 'end' ? c.x - lw : c.x; return { l, r: l + lw, t: c.y - 10, b: c.y + 3 }; };
254
+ const free = (c) => {
255
+ const b = boxOf(c);
256
+ if (b.l < 2 || b.r > w - 2 || b.t < 0 || b.b > h) return false;
257
+ if (rects.some((o) => b.l < o.r + 3 && b.r > o.l - 3 && b.t < o.b + 3 && b.b > o.t - 3)) return false;
258
+ if (placed.some((q) => b.l < q.r + 6 && b.r > q.l - 6 && b.t < q.b + 2 && b.b > q.t - 2)) return false;
259
+ for (const [q, segs] of segsOf) if (q !== p && strong(q) && segs.some((sg) => segHits(sg, b))) return false;
260
+ return true;
261
+ };
262
+ const c = cands.find(free);
263
+ if (!c) continue;
264
+ placed.push(boxOf(c));
265
+ const cls = `${isKey(p) ? ' is-key' : ''}${isHot(p) ? ' is-hot' : ''}${isFocus(p) ? ' is-focus' : ''}`;
266
+ const t = document.createElementNS(SVGNS, 'text');
267
+ t.setAttribute('class', `tm-wire-label${cls}`);
268
+ t.setAttribute('x', c.x); t.setAttribute('y', c.y);
269
+ if (c.anchor !== 'start') t.setAttribute('text-anchor', c.anchor);
270
+ t.dataset.from = e.src.id; t.dataset.to = e.dst.id;
271
+ t.textContent = e.label;
272
+ // the paper plate under the label: faint wires stop at its edge instead of running through the words
273
+ const bb = boxOf(c); const plate = document.createElementNS(SVGNS, 'rect');
274
+ plate.setAttribute('class', `tm-wire-plate${cls}`);
275
+ plate.setAttribute('x', bb.l - 3); plate.setAttribute('y', bb.t - 1); plate.setAttribute('width', bb.r - bb.l + 6); plate.setAttribute('height', bb.b - bb.t + 3); plate.setAttribute('rx', 3);
276
+ plate.dataset.from = e.src.id; plate.dataset.to = e.dst.id;
277
+ svg.appendChild(plate); svg.appendChild(t);
278
+ texts.push(e.label);
279
+ }
280
+ }
281
+ function labels(state = {}) {
282
+ labelState = { hot: state.hot || null, focus: state.focus ? new Set(state.focus) : null };
283
+ for (const map of document.querySelectorAll('.tm-map, .tm-blueprint')) placeLabels(map, labelState);
284
+ }
285
+
286
+ function drawWires() {
287
+ document.documentElement.style.setProperty('--tm-vw', `${document.documentElement.clientWidth}px`);
288
+ for (const map of document.querySelectorAll('.tm-map, .tm-blueprint')) {
289
+ // Start from the authored spacing, then let gaps grow as the tracks require.
290
+ for (const l of map.querySelectorAll('.tm-layer[data-tm-grown]')) { l.style.marginTop = ''; delete l.dataset.tmGrown; }
291
+ for (let pass = 0; pass < 4 && drawMap(map); pass++) { /* re-layout */ }
292
+ if (map.querySelector(':scope > svg.tm-wires') === null && map.querySelector('[data-to]')) drawMap(map);
293
+ }
294
+ }
295
+ // A map wider than the window fades at the edge it can scroll towards.
296
+ function markScroll(map) {
297
+ map.classList.toggle('tm-scrolls', map.scrollWidth - map.clientWidth - map.scrollLeft > 4);
298
+ if (!map.__tmScroll) { map.__tmScroll = true; map.addEventListener('scroll', () => markScroll(map), { passive: true }); }
299
+ }
300
+ // Hover and path buttons without the truemap workspace (used by exported pages; the SDK has its own).
301
+ function interact() {
302
+ let hot = null; let lit = [];
303
+ const mark = () => {
304
+ const ids = new Set(lit);
305
+ for (const el of document.querySelectorAll('.tm-wire, .tm-wire-head, .tm-wire-label')) {
306
+ el.classList.toggle('is-hot', !!hot && (el.dataset.from === hot.id || el.dataset.to === hot.id));
307
+ el.classList.toggle('is-focus', ids.has(el.dataset.from) && ids.has(el.dataset.to));
308
+ }
309
+ labels({ hot: hot?.id || null, focus: lit });
310
+ };
311
+ document.addEventListener('mousemove', (e) => {
312
+ const box = e.target.closest?.('.tm-map .tm-node, .tm-blueprint .tm-node') || null;
313
+ if (box !== hot) { hot = box; mark(); }
314
+ });
315
+ document.addEventListener('click', (e) => {
316
+ const btn = e.target.closest?.('[data-tm-flow]'); if (!btn) return;
317
+ const ids = btn.getAttribute('data-tm-flow').split(/[\s,]+/).filter(Boolean);
318
+ const same = lit.length && ids.join() === lit.join();
319
+ lit = same ? [] : ids;
320
+ document.documentElement.toggleAttribute('data-tm-focusing', !!lit.length);
321
+ for (const el of document.querySelectorAll('[data-tm-focus]')) el.removeAttribute('data-tm-focus');
322
+ for (const id of lit) document.getElementById(id)?.setAttribute('data-tm-focus', '');
323
+ for (const b of document.querySelectorAll('[data-tm-flow]')) b.setAttribute('aria-pressed', String(!same && b === btn));
324
+ mark();
325
+ });
326
+ window.truemapWires.mark = mark;
327
+ }
328
+ window.truemapWires = { draw: drawWires, interact, labels };
329
+ })();