truemap-cli 0.5.1 → 0.5.3
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 -0
- package/kit/tokens.css +67 -0
- package/kit/truemap.css +23 -73
- package/package.json +1 -1
- package/skills/truemap/SKILL.md +2 -2
- package/src/changes.js +10 -8
- package/src/check.js +66 -8
- package/src/cli.js +41 -10
- package/src/contrast.js +93 -0
- package/src/export.js +12 -7
- package/src/guide.md +34 -9
- package/src/outline.js +7 -3
- package/src/server.js +81 -23
- package/src/theme.js +11 -10
- package/src/ui/diagram.js +139 -27
- package/src/ui/sdk.js +52 -55
- package/src/ui/workspace.css +19 -34
- package/src/ui/workspace.html +1 -0
- package/src/ui/workspace.js +61 -14
package/src/ui/diagram.js
CHANGED
|
@@ -102,7 +102,9 @@
|
|
|
102
102
|
// The layered layout, computed top to bottom ("rows"); left to right is the same picture turned.
|
|
103
103
|
// - Groups are bands of rows in the author's order: a group never shares a row with another, so groups
|
|
104
104
|
// never overlap or interleave.
|
|
105
|
-
// - Inside a group a box sits one row below the boxes that call it (longest path).
|
|
105
|
+
// - Inside a group a box sits one row below the boxes that call it (longest path). Top to bottom, a
|
|
106
|
+
// group that fits the width is one row; one that does not wraps into as few rows as fit, callers
|
|
107
|
+
// first, so a box is never above the boxes that call it.
|
|
106
108
|
// - A connection that skips rows reserves a narrow slot in each row it crosses.
|
|
107
109
|
// - Order within rows: barycenter sweeps, keeping the order with the fewest crossings.
|
|
108
110
|
// - Positions: as close to the connected boxes as the ordering and spacing allow (block merging).
|
|
@@ -134,13 +136,15 @@
|
|
|
134
136
|
const intra = E.filter((x) => gOf[x.a] === g && gOf[x.b] === g);
|
|
135
137
|
// width of the row in its first order: only neighbours that call each other need room for a label
|
|
136
138
|
const inOrder = [...members].sort((u, v) => local.get(u) - local.get(v) || u - v);
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
const pair = intra.filter((x) => (x.a === inOrder[k - 1] && x.b ===
|
|
140
|
-
|
|
141
|
-
}
|
|
142
|
-
const
|
|
143
|
-
|
|
139
|
+
const sepAt = inOrder.map((i, k) => {
|
|
140
|
+
if (!k) return 0;
|
|
141
|
+
const pair = intra.filter((x) => (x.a === inOrder[k - 1] && x.b === i) || (x.b === inOrder[k - 1] && x.a === i));
|
|
142
|
+
return pair.length ? Math.max(...pair.map((x) => (x.e.lw ? x.e.lw + 30 : 28))) : NODESEP;
|
|
143
|
+
});
|
|
144
|
+
const fit = (room - gutter - 24) / 0.82;
|
|
145
|
+
const wrap = new Map();
|
|
146
|
+
if (!lr) { let row = 0; let w = 0; inOrder.forEach((i, k) => { if (k && w + sepAt[k] + S[i].w > fit) { row++; w = 0; } else w += sepAt[k]; w += S[i].w; wrap.set(i, row); }); }
|
|
147
|
+
for (const i of members) { rank[i] = base + (lr ? local.get(i) : wrap.get(i)); localRank[i] = local.get(i); top = Math.max(top, rank[i]); }
|
|
144
148
|
bands.push({ g, from: base, to: top });
|
|
145
149
|
base = top + 1;
|
|
146
150
|
}
|
|
@@ -200,6 +204,38 @@
|
|
|
200
204
|
}
|
|
201
205
|
for (let r = 0; r < R; r++) rows[r] = best[r];
|
|
202
206
|
number();
|
|
207
|
+
// A call inside a row between boxes that aren't neighbours is drawn as a loop under the row, across
|
|
208
|
+
// the wires leaving every box it passes. Finish the order with neighbour swaps that cut crossings and
|
|
209
|
+
// loop lengths together; callers stay left of callees, and on a tie the author's order stays.
|
|
210
|
+
const authorK = new Map(); for (const row of rows) [...row].sort((p, q) => p.order - q.order).forEach((it, k) => authorK.set(it, k));
|
|
211
|
+
const cost = () => {
|
|
212
|
+
let c = crossings();
|
|
213
|
+
for (const x of sameEdges) c += 2 * (Math.abs(item[x.a].k - item[x.b].k) - 1);
|
|
214
|
+
for (const row of rows) for (const it of row) if (!it.dummy) c += 0.001 * Math.abs(it.k - authorK.get(it));
|
|
215
|
+
return c;
|
|
216
|
+
};
|
|
217
|
+
const callsOk = (row) => sameEdges.every((x) => item[x.a].row !== row[0]?.row || item[x.a].k < item[x.b].k);
|
|
218
|
+
let cur = cost();
|
|
219
|
+
const renumber = (row) => row.forEach((it, k) => { it.k = k; });
|
|
220
|
+
for (let pass = 0; pass < 6; pass++) {
|
|
221
|
+
let better = false;
|
|
222
|
+
for (const row of rows) {
|
|
223
|
+
// take each box (or wire slot) out and put it back where the whole drawing costs least
|
|
224
|
+
for (const it of [...row]) {
|
|
225
|
+
const from = row.indexOf(it); let bestAt = from;
|
|
226
|
+
row.splice(from, 1);
|
|
227
|
+
for (let at = 0; at <= row.length; at++) {
|
|
228
|
+
if (at === from) continue;
|
|
229
|
+
row.splice(at, 0, it); renumber(row);
|
|
230
|
+
const c = callsOk(row) ? cost() : Infinity;
|
|
231
|
+
if (c < cur - 1e-9) { cur = c; bestAt = at; better = true; }
|
|
232
|
+
row.splice(at, 1);
|
|
233
|
+
}
|
|
234
|
+
row.splice(bestAt, 0, it); renumber(row);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
if (!better) break;
|
|
238
|
+
}
|
|
203
239
|
// 3. positions across the rows
|
|
204
240
|
const pairGap = new Map();
|
|
205
241
|
for (const x of sameEdges) { const k = [x.a, x.b].sort((u, v) => u - v).join('|'); pairGap.set(k, Math.max(pairGap.get(k) || 0, x.e.lw ? x.e.lw + 30 : 28)); }
|
|
@@ -223,12 +259,20 @@
|
|
|
223
259
|
for (const b of blocks) b.items.forEach((k, j) => { row[k].x = b.pos + b.off[j]; });
|
|
224
260
|
}
|
|
225
261
|
for (const row of rows) { let x = 0; row.forEach((it, k) => { if (k) x += sep(row[k - 1], it); it.x = x + it.w / 2; x += it.w; }); const c = x / 2; for (const it of row) it.x -= c; }
|
|
262
|
+
// A box is pulled toward everything it connects to, in its own row too: a pair linked to the rest only
|
|
263
|
+
// by calls inside a row would otherwise keep its first place, past every wire slot at the row's end.
|
|
264
|
+
// A box with no connections at all sits under the middle of the drawing.
|
|
265
|
+
const beside = new Map();
|
|
266
|
+
for (const x of sameEdges) { link(beside, item[x.a], item[x.b]); link(beside, item[x.b], item[x.a]); }
|
|
267
|
+
const near = (p) => [...(up.get(p) || []), ...(down.get(p) || []), ...(beside.get(p) || [])];
|
|
268
|
+
const linked = rows.flat().filter((p) => near(p).length);
|
|
226
269
|
for (let it = 0; it < 10; it++) {
|
|
227
270
|
const seq = it % 2 === 0 ? [...rows.keys()] : [...rows.keys()].reverse();
|
|
271
|
+
const mid = linked.length ? (Math.min(...linked.map((p) => p.x - p.w / 2)) + Math.max(...linked.map((p) => p.x + p.w / 2))) / 2 : 0;
|
|
228
272
|
for (const r of seq) {
|
|
229
273
|
const want = rows[r].map((p) => {
|
|
230
|
-
const ns =
|
|
231
|
-
return ns.length ? ns.reduce((s, q) => s + q.x, 0) / ns.length :
|
|
274
|
+
const ns = near(p);
|
|
275
|
+
return ns.length ? ns.reduce((s, q) => s + q.x, 0) / ns.length : mid;
|
|
232
276
|
});
|
|
233
277
|
settle(rows[r], want);
|
|
234
278
|
}
|
|
@@ -272,10 +316,24 @@
|
|
|
272
316
|
const step = Math.min(16, (it.w * 0.7) / Math.max(1, keys.length));
|
|
273
317
|
return new Map(keys.map((k, i) => [k, it.x + (i - (keys.length - 1) / 2) * step]));
|
|
274
318
|
};
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
319
|
+
// A box's bottom edge carries its exits down and both ends of its loops under the row; each gets its own
|
|
320
|
+
// point there, ordered by where the line goes, so a loop in and a loop out never share a vertical line.
|
|
321
|
+
const bottom = new Map();
|
|
322
|
+
const atBottom = (i, key, other, set) => { if (!bottom.has(i)) bottom.set(i, new Map()); const B = bottom.get(i); if (!B.has(key)) B.set(key, { other, sets: [] }); B.get(key).sets.push(set); };
|
|
323
|
+
for (const [a, list] of out) for (const x of list) atBottom(a, `>${x.bundle}`, x.chain[1].x, (v) => { x.exit = v; });
|
|
324
|
+
for (const x of E) {
|
|
325
|
+
if (!x.same || adjacent(x)) continue;
|
|
326
|
+
x.below = {};
|
|
327
|
+
atBottom(x.a, `${x.e.name}:a`, item[x.b].x, (v) => { x.below.px = v; });
|
|
328
|
+
atBottom(x.b, `${x.e.name}:b`, item[x.a].x, (v) => { x.below.qx = v; });
|
|
329
|
+
}
|
|
330
|
+
for (const [i, B] of bottom) {
|
|
331
|
+
// exits in the middle by where they go; loops to the left and right, the farther one further out so
|
|
332
|
+
// they nest instead of crossing
|
|
333
|
+
const cx = item[i].x; const W = 1e6;
|
|
334
|
+
const rankOf = (k) => { const o = B.get(k).other; return k.startsWith('>') ? o : o < cx ? -W - o : W - o; };
|
|
335
|
+
const ports = portX(item[i], [...B.keys()], (k) => k, rankOf);
|
|
336
|
+
for (const [k, v] of B) for (const set of v.sets) set(ports.get(k));
|
|
279
337
|
}
|
|
280
338
|
for (const [b, list] of inc) {
|
|
281
339
|
const it = item[b];
|
|
@@ -288,7 +346,7 @@
|
|
|
288
346
|
for (const x of E) {
|
|
289
347
|
const pts = [];
|
|
290
348
|
if (x.same) {
|
|
291
|
-
if (!adjacent(x))
|
|
349
|
+
if (!adjacent(x)) hops.push({ x, k: 0, row: item[x.a].row, px: x.below.px, qx: x.below.qx, key: `${x.e.name}:same` });
|
|
292
350
|
x.pts = pts; continue;
|
|
293
351
|
}
|
|
294
352
|
for (let k = 0; k + 1 < x.chain.length; k++) {
|
|
@@ -298,16 +356,52 @@
|
|
|
298
356
|
}
|
|
299
357
|
x.pts = pts;
|
|
300
358
|
}
|
|
359
|
+
// Two lines never run down one vertical in a gap, or one reads as the other's continuation: a loop end
|
|
360
|
+
// or an entry that lands on another line slides along its box to a free spot.
|
|
361
|
+
const stems = [];
|
|
362
|
+
for (const h of hops) {
|
|
363
|
+
const x = h.x; const last = h.k + 1 === (x.same ? 1 : x.chain.length - 1);
|
|
364
|
+
stems.push({ h, end: 'px', key: x.same ? `${x.e.name}:a` : h.k === 0 ? `>${x.bundle}` : `${x.e.name}:${h.k}p`, box: x.same ? item[x.a] : null });
|
|
365
|
+
stems.push({ h, end: 'qx', key: `${x.e.name}:${h.k}q`, box: last ? item[x.b] : null });
|
|
366
|
+
}
|
|
367
|
+
const clash = (s, v) => stems.some((o) => o !== s && o.h.row === s.h.row && o.h.x !== s.h.x && o.key !== s.key && Math.abs(o.h[o.end] - v) < 5);
|
|
368
|
+
for (const s of stems) {
|
|
369
|
+
if (!s.box || !clash(s, s.h[s.end])) continue;
|
|
370
|
+
const v0 = s.h[s.end]; const lo = s.box.x - s.box.w / 2 + 6; const hi = s.box.x + s.box.w / 2 - 6;
|
|
371
|
+
let v;
|
|
372
|
+
for (let d = 6; v === undefined && d < s.box.w; d += 6) v = [v0 + d, v0 - d].find((c) => c > lo && c < hi && !clash(s, c));
|
|
373
|
+
if (v === undefined) continue;
|
|
374
|
+
s.h[s.end] = v;
|
|
375
|
+
if (s.h.x.same) s.h.x.below[s.end] = v; else s.h.x.entry = v;
|
|
376
|
+
}
|
|
301
377
|
for (const h of hops) {
|
|
302
378
|
if (Math.abs(h.px - h.qx) < 1) continue;
|
|
303
379
|
if (!lanes.has(h.row)) lanes.set(h.row, new Map());
|
|
304
380
|
const L = lanes.get(h.row);
|
|
381
|
+
if (!L.has(h.key)) L.set(h.key, { lo: Infinity, hi: -Infinity, tops: [], bottoms: [] });
|
|
305
382
|
const cur = L.get(h.key);
|
|
306
|
-
|
|
383
|
+
cur.lo = Math.min(cur.lo, h.px, h.qx); cur.hi = Math.max(cur.hi, h.px, h.qx);
|
|
384
|
+
// a line comes into its lane from above at px and leaves downwards at qx; a loop goes back up at qx
|
|
385
|
+
cur.tops.push(h.px); (h.x.same ? cur.tops : cur.bottoms).push(h.qx);
|
|
307
386
|
}
|
|
387
|
+
// In a gap, a lane whose line comes down from above through another lane's run has to sit above it, and
|
|
388
|
+
// one whose line goes on down through it has to sit below; order the lanes to break as few as possible.
|
|
389
|
+
const inside = (v, B) => v > B.lo + 1 && v < B.hi - 1;
|
|
390
|
+
const wrong = (A, B) => A.bottoms.filter((v) => inside(v, B)).length + B.tops.filter((v) => inside(v, A)).length; // A placed above B
|
|
391
|
+
const orderLanes = (list) => {
|
|
392
|
+
for (let pass = 0; pass < list.length; pass++) {
|
|
393
|
+
let moved = false;
|
|
394
|
+
for (let i = 0; i + 1 < list.length; i++) {
|
|
395
|
+
const A = list[i][1]; const B = list[i + 1][1];
|
|
396
|
+
if (wrong(B, A) < wrong(A, B)) { [list[i], list[i + 1]] = [list[i + 1], list[i]]; moved = true; }
|
|
397
|
+
}
|
|
398
|
+
if (!moved) break;
|
|
399
|
+
}
|
|
400
|
+
return list;
|
|
401
|
+
};
|
|
308
402
|
const laneY = new Map();
|
|
309
403
|
for (const [row, L] of lanes) {
|
|
310
|
-
const g = gapAfter[row]; const list = [...L.entries()].sort((p, q) => p[1].lo - q[1].lo);
|
|
404
|
+
const g = gapAfter[row]; const list = orderLanes([...L.entries()].sort((p, q) => p[1].lo - q[1].lo));
|
|
311
405
|
const span = g.bottom - g.top; const step = Math.min(11, Math.max(6, (span - 16) / Math.max(1, list.length)));
|
|
312
406
|
list.forEach(([key], i) => laneY.set(`${row}|${key}`, g.top + span / 2 + (i - (list.length - 1) / 2) * step));
|
|
313
407
|
}
|
|
@@ -349,7 +443,9 @@
|
|
|
349
443
|
if (x.e.back) pts = pts.reverse();
|
|
350
444
|
return [x.e.name, pts];
|
|
351
445
|
}));
|
|
352
|
-
|
|
446
|
+
// the gaps between rows and how many lanes run in each, so a label can stay out of a crowded one
|
|
447
|
+
const gaps = gapAfter.map((g, r) => g && { a: g.top, b: g.bottom, n: lanes.get(r)?.size || 0 }).filter(Boolean);
|
|
448
|
+
return { width: lr ? H : W, height: lr ? W : H, pos, bands: bandBoxes, routes, dir, gutter: lr ? 0 : gutter, gaps };
|
|
353
449
|
}
|
|
354
450
|
|
|
355
451
|
function layout(fig) {
|
|
@@ -378,6 +474,8 @@
|
|
|
378
474
|
const asked = (fig.getAttribute('data-direction') || '').toUpperCase();
|
|
379
475
|
let L = layered(m, edges, asked === 'TB' ? 'TB' : 'LR', labelW, room);
|
|
380
476
|
if (!asked && L.width > room) L = layered(m, edges, 'TB', labelW, room);
|
|
477
|
+
// wire slots make a wrapped row wider than its boxes: wrap tighter until it fits at the smallest scale
|
|
478
|
+
for (let fitTo = room; L.dir === 'TB' && L.width * 0.7 > room - 16 && fitTo > 240;) { fitTo *= 0.85; L = layered(m, edges, 'TB', labelW, fitTo); }
|
|
381
479
|
fig.dataset.laidOut = L.dir;
|
|
382
480
|
if (L.dir === 'TB' && L.width < room) {
|
|
383
481
|
const dx = (room - L.width) / 2;
|
|
@@ -448,17 +546,29 @@
|
|
|
448
546
|
lab.style.left = `${best.l - l + 3}px`; lab.style.top = `${best.t - t + 2}px`;
|
|
449
547
|
taken.push(best);
|
|
450
548
|
}
|
|
451
|
-
// Edge labels sit on their own edge, at the first spot along it that covers no box
|
|
452
|
-
//
|
|
549
|
+
// Edge labels sit on their own edge, at the first spot along it that covers no box, no other label and,
|
|
550
|
+
// where it can, no other line. At rest a label shows on the main path, and on any other line where it
|
|
551
|
+
// found such a clean spot outside a gap crowded with three or more lanes; the rest wait for their line
|
|
552
|
+
// to be lit.
|
|
553
|
+
// The same word on several edges from one box is said once, on the most important of them ("creates ×3").
|
|
554
|
+
// Once a box is selected or a flow is lit, each lit edge says its own plain word instead: the repeats
|
|
555
|
+
// show, and the count hides (kit CSS). Repeats are placed last, so the map at rest is laid out the same.
|
|
453
556
|
const seen = new Set();
|
|
454
557
|
placed.sort((x, y) => (y.key - x.key));
|
|
455
558
|
for (const pl of placed) { const k = `${pl.e.from}|${pl.e.label}`; pl.dup = seen.has(k); seen.add(k); }
|
|
456
559
|
const bundleSize = new Map();
|
|
457
560
|
for (const pl of placed) { const k = `${pl.e.from}|${pl.e.label}`; bundleSize.set(k, (bundleSize.get(k) || 0) + 1); }
|
|
458
|
-
|
|
561
|
+
// every line as straight runs, to keep labels off lines that aren't theirs (a shared trunk is one line)
|
|
562
|
+
const runs = [];
|
|
563
|
+
for (const e of edges) { const pts = L.routes.get(e.name) || []; for (let i = 0; i + 1 < pts.length; i++) runs.push({ e, a: pts[i], b: pts[i + 1] }); }
|
|
564
|
+
const lineHits = (r, e) => runs.filter((s) => !(s.e === e || (s.e.from === e.from && s.e.label === e.label))
|
|
565
|
+
&& Math.min(s.a.x, s.b.x) < r.r - 1 && Math.max(s.a.x, s.b.x) > r.l + 1 && Math.min(s.a.y, s.b.y) < r.b - 1 && Math.max(s.a.y, s.b.y) > r.t + 1).length;
|
|
566
|
+
const lanesAt = (p) => { const v = L.dir === 'LR' ? p.x : p.y; return (L.gaps || []).find((g) => v > g.a && v < g.b)?.n || 0; };
|
|
567
|
+
for (const { e, path, key, dup } of [...placed.filter((pl) => !pl.dup), ...placed.filter((pl) => pl.dup)]) {
|
|
459
568
|
const t = document.createElement('span'); t.className = `tm-dg-label${key ? ' is-main' : ''}${dup ? ' is-dup' : ''}`;
|
|
460
569
|
const many = bundleSize.get(`${e.from}|${e.label}`) || 1;
|
|
461
|
-
t.textContent =
|
|
570
|
+
t.textContent = e.label;
|
|
571
|
+
if (!dup && many > 1) t.dataset.many = `×${many}`;
|
|
462
572
|
t.dataset.from = e.from; t.dataset.to = e.to;
|
|
463
573
|
m.stage.appendChild(t);
|
|
464
574
|
const w = t.offsetWidth; const h = t.offsetHeight; const L = path.getTotalLength();
|
|
@@ -466,19 +576,21 @@
|
|
|
466
576
|
const trunk = bundleSize.get(`${e.from}|${e.label}`) > 1;
|
|
467
577
|
// try every few pixels along the line, nearest the preferred spot first; take the first free one,
|
|
468
578
|
// otherwise the least crowded; a label that would still cover a box only shows when its line is lit
|
|
469
|
-
const pref = trunk ? 0.15 : 0.5;
|
|
579
|
+
const pref = trunk && !dup ? 0.15 : 0.5;
|
|
470
580
|
const fr = [pref]; for (let d = 0.04; d < 0.96; d += 0.04) { if (pref + d < 0.97) fr.push(pref + d); if (pref - d > 0.03) fr.push(pref - d); }
|
|
471
|
-
let bestCost = Infinity;
|
|
581
|
+
let bestCost = Infinity; let bestLines = Infinity; let clean = null;
|
|
472
582
|
const overlap = (a, list) => list.reduce((n, o) => n + Math.max(0, Math.min(a.r, o.r) - Math.max(a.l, o.l)) * Math.max(0, Math.min(a.b, o.b) - Math.max(a.t, o.t)), 0);
|
|
473
583
|
for (const f of fr) {
|
|
474
584
|
const p = path.getPointAtLength(L * f);
|
|
475
585
|
const r = { l: p.x - w / 2, r: p.x + w / 2, t: p.y - h / 2, b: p.y + h / 2 };
|
|
476
586
|
const cost = overlap(r, boxes) * 4 + overlap(r, badges) * 4 + overlap(r, taken) * 2;
|
|
477
|
-
|
|
478
|
-
if (
|
|
587
|
+
const lines = cost ? Infinity : lineHits(r, e);
|
|
588
|
+
if (cost < bestCost || (cost === bestCost && lines < bestLines)) { bestCost = cost; bestLines = lines; best = r; }
|
|
589
|
+
if (!cost && !lines) { clean = p; break; }
|
|
479
590
|
}
|
|
480
591
|
if (bestCost > 0) t.classList.add('is-crowded');
|
|
481
|
-
if (!dup &&
|
|
592
|
+
else if (clean && !key && !dup && many === 1 && lanesAt(clean) < 3) t.classList.add('is-rest'); // a count ("creates ×3") waits for its lines to be lit
|
|
593
|
+
if (!t.classList.contains('is-crowded')) taken.push(best);
|
|
482
594
|
t.style.left = `${(best.l + best.r) / 2}px`; t.style.top = `${(best.t + best.b) / 2}px`;
|
|
483
595
|
}
|
|
484
596
|
// main-path edges on top
|
package/src/ui/sdk.js
CHANGED
|
@@ -76,8 +76,11 @@
|
|
|
76
76
|
w.classList.toggle('is-focus', ids.has(from) && ids.has(to));
|
|
77
77
|
w.classList.toggle('is-hot', !!hot && (from === hot || to === hot));
|
|
78
78
|
}
|
|
79
|
+
const sel = selected?.id;
|
|
79
80
|
for (const w of document.querySelectorAll('.tm-dg-edge, .tm-dg-head, .tm-dg-label')) {
|
|
80
81
|
w.classList.toggle('is-focus', ids.has(w.dataset.from) && ids.has(w.dataset.to));
|
|
82
|
+
// a re-laid map (its space changed) keeps the selected box's lines lit
|
|
83
|
+
w.classList.toggle('is-sel', !!sel && (w.dataset.from === sel || w.dataset.to === sel));
|
|
81
84
|
}
|
|
82
85
|
// labels are placed afresh for what is now visible
|
|
83
86
|
window.truemapWires?.labels?.({ hot: hot || null, focus: [...ids] });
|
|
@@ -274,7 +277,7 @@
|
|
|
274
277
|
b.style.top = `${fitsRight ? g.t : above ? g.t - bh - 12 : g.b + 12}px`;
|
|
275
278
|
} else { b.style.left = `${scrollX + vw - 320}px`; b.style.top = `${scrollY + 16}px`; }
|
|
276
279
|
}
|
|
277
|
-
if (card?.target) ring(card.target, 'active');
|
|
280
|
+
if (card?.target && !card.target.closest('.tm-diagram')) ring(card.target, 'active'); // a map box shows its own selection
|
|
278
281
|
else if (annotating && hovered) ring(hovered, 'hover');
|
|
279
282
|
}
|
|
280
283
|
function setAnnotate(on) {
|
|
@@ -292,80 +295,61 @@
|
|
|
292
295
|
shadow.innerHTML = `<style>
|
|
293
296
|
:host { all: initial; }
|
|
294
297
|
* { box-sizing: border-box; }
|
|
295
|
-
.card { position: absolute; z-index: 10; width: 360px; background: #fff; color: #141413; border: 1px solid #d2d2cb; border-radius: 10px;
|
|
296
|
-
box-shadow: 0 12px 32px -12px rgba(20,20,19,.28); font: 14px/1.45
|
|
298
|
+
.card { position: absolute; z-index: 10; width: 360px; background: var(--tm-sheet, #fff); color: var(--tm-ink, #141413); border: 1px solid var(--tm-rule-strong, #d2d2cb); border-radius: 10px;
|
|
299
|
+
box-shadow: 0 12px 32px -12px rgba(20,20,19,.28); font: 14px/1.45 var(--tm-font, system-ui, sans-serif); padding: 12px; }
|
|
297
300
|
.what { display: flex; align-items: baseline; gap: 8px; min-width: 0; margin: 0 2px 6px; }
|
|
298
301
|
.card.viewing { width: 320px; }
|
|
299
302
|
.card.viewing textarea, .card.viewing .suggest, .card.viewing [data-act="add"], .card.viewing [data-act="cancel"], .card.viewing .hint { display: none; }
|
|
300
303
|
.card:not(.viewing) [data-act="comment"] { display: none; }
|
|
301
304
|
.card.viewing .foot { justify-content: flex-start; margin-top: 4px; }
|
|
302
305
|
.card.viewing .sum { margin-bottom: 6px; }
|
|
303
|
-
.sum { margin: 0 2px 10px; font-size: 13px; line-height: 1.45; color: #
|
|
304
|
-
.sum .flag { margin-top: 4px; font-size: 12px; color: #a35f00; }
|
|
305
|
-
@media (prefers-color-scheme: dark) { .sum { color: #c4c4bd; } .sum .flag { color: #e0a548; } }
|
|
306
|
+
.sum { margin: 0 2px 10px; font-size: 13px; line-height: 1.45; color: var(--tm-graphite, #6c6c65); }
|
|
307
|
+
.sum .flag { margin-top: 4px; font-size: 12px; color: var(--tm-changed, #a35f00); }
|
|
306
308
|
.what b { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
|
|
307
|
-
.what code { font: 11.5px
|
|
308
|
-
textarea { width: 100%; min-height: 72px; max-height: 220px; resize: none; font: inherit; color: inherit; background: #
|
|
309
|
-
textarea:focus { border-color: #141413; background: #fff; }
|
|
309
|
+
.what code { font: 11.5px var(--tm-code, ui-monospace, Consolas, monospace); color: var(--tm-pencil, #9a9a92); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 1; }
|
|
310
|
+
textarea { width: 100%; min-height: 72px; max-height: 220px; resize: none; font: inherit; color: inherit; background: color-mix(in oklab, var(--tm-wash, #f2f2ef) 45%, var(--tm-sheet, #fff)); border: 1px solid var(--tm-rule, #e6e6e1); border-radius: 7px; padding: 9px 10px; outline: none; }
|
|
311
|
+
textarea:focus { border-color: var(--tm-ink, #141413); background: var(--tm-sheet, #fff); }
|
|
310
312
|
.suggest { display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 8px 2px 0; }
|
|
311
|
-
.suggest button { all: unset; cursor: pointer; font-size: 12.5px; color: #141413; }
|
|
313
|
+
.suggest button { all: unset; cursor: pointer; font-size: 12.5px; color: var(--tm-ink, #141413); }
|
|
312
314
|
.suggest button:hover { text-decoration: underline; text-underline-offset: 3px; }
|
|
313
315
|
.foot { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
|
|
314
316
|
.foot .btn { white-space: nowrap; }
|
|
315
317
|
.foot [data-act="details"] { padding-left: 2px; text-decoration: underline; text-underline-offset: 3px; }
|
|
316
|
-
.hint { flex: 1; font-size: 11.5px; color: #9a9a92; line-height: 1.3; }
|
|
317
|
-
.btn { all: unset; cursor: pointer; font: 500 13px/1
|
|
318
|
-
.btn:hover { background: #f2f2ef; color: #141413; }
|
|
319
|
-
.btn.primary { background: #141413; color: #fff; }
|
|
320
|
-
.btn.primary:hover { background: #
|
|
321
|
-
.btn.danger { color: #c0392b; }
|
|
322
|
-
.btn:focus-visible { outline: 2px solid #141413; outline-offset: 2px; }
|
|
323
|
-
.ring { position: absolute; border: 1.5px solid #141413; border-radius: 8px; pointer-events: none; }
|
|
318
|
+
.hint { flex: 1; font-size: 11.5px; color: var(--tm-pencil, #9a9a92); line-height: 1.3; }
|
|
319
|
+
.btn { all: unset; cursor: pointer; font: 500 13px/1 var(--tm-font, system-ui, sans-serif); padding: 8px 11px; border-radius: 6px; color: var(--tm-graphite, #6c6c65); }
|
|
320
|
+
.btn:hover { background: var(--tm-wash, #f2f2ef); color: var(--tm-ink, #141413); }
|
|
321
|
+
.btn.primary { background: var(--tm-accent, #141413); color: var(--tm-accent-text, #fff); }
|
|
322
|
+
.btn.primary:hover { background: color-mix(in oklab, var(--tm-accent, #141413) 84%, var(--tm-sheet, #fff)); }
|
|
323
|
+
.btn.danger { color: var(--tm-broken, #c0392b); }
|
|
324
|
+
.btn:focus-visible { outline: 2px solid var(--tm-ink, #141413); outline-offset: 2px; }
|
|
325
|
+
.ring { position: absolute; border: 1.5px solid var(--tm-ink, #141413); border-radius: 8px; pointer-events: none; }
|
|
324
326
|
.ring.active { border-width: 2px; }
|
|
325
|
-
.ring.agent { border: 2px solid #141413; border-radius: 9px; }
|
|
326
|
-
.bubble { position: absolute; width: 300px; background: #141413; color: #
|
|
327
|
-
.bubble-who { font-size: 11.5px; font-weight: 600; color: #ffe27a; margin-bottom: 3px; }
|
|
327
|
+
.ring.agent { border: 2px solid var(--tm-ink, #141413); border-radius: 9px; }
|
|
328
|
+
.bubble { position: absolute; width: 300px; background: var(--tm-ink, #141413); color: var(--tm-paper, #fff); border-radius: 10px; padding: 10px 30px 11px 12px; box-shadow: 0 14px 34px -14px rgba(20,20,19,.5); font: 13.5px/1.5 var(--tm-font, system-ui, sans-serif); pointer-events: auto; }
|
|
329
|
+
.bubble-who { font-size: 11.5px; font-weight: 600; color: color-mix(in oklab, var(--tm-paper, #fff) 70%, var(--tm-mark, #ffe27a)); margin-bottom: 3px; }
|
|
328
330
|
.bubble-text { white-space: pre-wrap; }
|
|
329
|
-
.bubble-x { all: unset; position: absolute; top: 6px; right: 8px; cursor: pointer; color: #
|
|
330
|
-
.bubble-x:hover { color: #fff; background:
|
|
331
|
-
.ring.noted { border-color:
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
.select-btn {
|
|
336
|
-
|
|
337
|
-
@media (prefers-color-scheme: dark) {
|
|
338
|
-
.card { background: #1b1b1a; color: #f2f2ee; border-color: #44443f; box-shadow: 0 12px 32px -12px rgba(0,0,0,.6); }
|
|
339
|
-
textarea { background: #161615; border-color: #2f2f2c; }
|
|
340
|
-
textarea:focus { background: #161615; border-color: #f2f2ee; }
|
|
341
|
-
.suggest button { color: #f2f2ee; }
|
|
342
|
-
.btn { color: #a0a098; } .btn:hover { background: #252523; color: #f2f2ee; }
|
|
343
|
-
.btn.primary { background: #f2f2ee; color: #141413; }
|
|
344
|
-
.pin { border-color: #161615; }
|
|
345
|
-
}
|
|
346
|
-
.planact { position: absolute; display: flex; gap: 4px; padding: 4px; background: #fff; border: 1px solid #d2d2cb; border-radius: 999px; box-shadow: 0 8px 22px -10px rgba(20,20,19,.4); pointer-events: auto; z-index: 3; animation: pa-in .22s cubic-bezier(.2,.8,.3,1.2) both; }
|
|
331
|
+
.bubble-x { all: unset; position: absolute; top: 6px; right: 8px; cursor: pointer; color: color-mix(in oklab, var(--tm-paper, #fff) 60%, var(--tm-ink, #141413)); font-size: 16px; line-height: 1; padding: 2px 4px; border-radius: 4px; }
|
|
332
|
+
.bubble-x:hover { color: var(--tm-paper, #fff); background: color-mix(in oklab, var(--tm-paper, #fff) 12%, transparent); }
|
|
333
|
+
.ring.noted { border-color: color-mix(in oklab, var(--tm-ink, #141413) 40%, transparent); }
|
|
334
|
+
.pin { position: absolute; width: 20px; height: 20px; border-radius: 50%; background: var(--tm-mark, #ffe27a); color: var(--tm-ink, #141413);
|
|
335
|
+
font: 600 11px/20px var(--tm-code, ui-monospace, Consolas, monospace); text-align: center; cursor: pointer; border: 2px solid var(--tm-sheet, #fff); box-shadow: 0 1px 3px rgba(20,20,19,.25); }
|
|
336
|
+
.select-btn { position: absolute; all: unset; position: absolute; cursor: pointer; background: var(--tm-accent, #141413); color: var(--tm-accent-text, #fff); font: 500 12.5px/1 var(--tm-font, system-ui, sans-serif); padding: 7px 10px; border-radius: 6px; box-shadow: 0 6px 18px -8px rgba(20,20,19,.5); }
|
|
337
|
+
.select-btn:hover { background: var(--tm-accent, #141413); }
|
|
338
|
+
.planact { position: absolute; display: flex; gap: 4px; padding: 4px; background: var(--tm-sheet, #fff); border: 1px solid var(--tm-rule-strong, #d2d2cb); border-radius: 999px; box-shadow: 0 8px 22px -10px rgba(20,20,19,.4); pointer-events: auto; z-index: 3; animation: pa-in .22s cubic-bezier(.2,.8,.3,1.2) both; }
|
|
347
339
|
@keyframes pa-in { from { opacity: 0; transform: translateY(4px) scale(.92); } to { opacity: 1; transform: none; } }
|
|
348
|
-
.planact button { all: unset; display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; cursor: pointer; color: #141413; transition: transform .12s ease, background-color .12s ease; }
|
|
349
|
-
.planact button:hover { background: #f2f2ef; transform: scale(1.1); }
|
|
350
|
-
.planact button.ok { background: #141413; color: #fff; }
|
|
351
|
-
.planact button.ok:hover { background: #
|
|
352
|
-
.planact button:focus-visible { outline: 2px solid #141413; outline-offset: 2px; }
|
|
340
|
+
.planact button { all: unset; display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; cursor: pointer; color: var(--tm-ink, #141413); transition: transform .12s ease, background-color .12s ease; }
|
|
341
|
+
.planact button:hover { background: var(--tm-wash, #f2f2ef); transform: scale(1.1); }
|
|
342
|
+
.planact button.ok { background: var(--tm-accent, #141413); color: var(--tm-accent-text, #fff); }
|
|
343
|
+
.planact button.ok:hover { background: color-mix(in oklab, var(--tm-accent, #141413) 84%, var(--tm-sheet, #fff)); }
|
|
344
|
+
.planact button:focus-visible { outline: 2px solid var(--tm-ink, #141413); outline-offset: 2px; }
|
|
353
345
|
.planact svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
|
|
354
|
-
.planact .wait { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; color: #2f7a4f; }
|
|
355
|
-
.planact .wait.revise { color: #6c6c65; animation: pa-pulse 1.4s ease-in-out infinite; }
|
|
346
|
+
.planact .wait { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; color: var(--tm-fine, #2f7a4f); }
|
|
347
|
+
.planact .wait.revise { color: var(--tm-graphite, #6c6c65); animation: pa-pulse 1.4s ease-in-out infinite; }
|
|
356
348
|
@keyframes pa-pulse { 50% { opacity: .35; } }
|
|
357
349
|
@media (prefers-reduced-motion: reduce) { .planact, .planact .wait.revise { animation: none; } .planact button { transition: none; } }
|
|
358
|
-
@media (prefers-color-scheme: dark) {
|
|
359
|
-
.planact { background: #1b1b1a; border-color: #44443f; }
|
|
360
|
-
.planact button { color: #f2f2ee; } .planact button:hover { background: #252523; }
|
|
361
|
-
.planact button.ok { background: #f2f2ee; color: #141413; }
|
|
362
|
-
.planact .wait { color: #7cc49c; }
|
|
363
|
-
}
|
|
364
350
|
</style><div id="rings"></div><div id="pins"></div><div id="slot"></div><div id="planact"></div>`;
|
|
365
|
-
{ const st = shadow.querySelector('style'); if (typeof tmThemeable === 'function') st.textContent = tmThemeable(st.textContent, { host: true }); }
|
|
366
351
|
const applyTheme = (t) => {
|
|
367
352
|
if (t === 'light' || t === 'dark') document.documentElement.setAttribute('data-theme', t); else document.documentElement.removeAttribute('data-theme');
|
|
368
|
-
host.classList.toggle('tm-dark', t === 'dark'); host.classList.toggle('tm-light', t === 'light');
|
|
369
353
|
};
|
|
370
354
|
applyTheme(document.documentElement.getAttribute('data-theme'));
|
|
371
355
|
const pinsEl = shadow.getElementById('pins');
|
|
@@ -396,6 +380,19 @@
|
|
|
396
380
|
let left = u.r + 10; let top = u.t - h / 2;
|
|
397
381
|
if (left + w > scrollX + vw - 8) { left = Math.max(scrollX + 8, u.r - w); top = u.t - h - 14; }
|
|
398
382
|
if (top < scrollY + 4) top = u.b + 10;
|
|
383
|
+
// Never on top of a box, the badge above it ("Plan: edit") or a group's name: the first free spot beside
|
|
384
|
+
// the plan's boxes.
|
|
385
|
+
const doc = (r) => ({ l: r.left + scrollX, t: r.top + scrollY, r: r.right + scrollX, b: r.bottom + scrollY });
|
|
386
|
+
const walls = [...document.querySelectorAll('.tm-node, .tm-step, .tm-dg-glabel')].filter((el) => el.getBoundingClientRect().width).map((el) => { const r = doc(el.getBoundingClientRect()); return { l: r.l - 6, t: r.t - 18, r: r.r + 12, b: r.b + 6 }; });
|
|
387
|
+
// nor on a wire's label, including one that only shows when its box is selected
|
|
388
|
+
for (const el of document.querySelectorAll('.tm-dg-label')) { const b = el.getBoundingClientRect(); if (b.width) { const r = doc(b); walls.push({ l: r.l - 4, t: r.t - 4, r: r.r + 4, b: r.b + 4 }); } }
|
|
389
|
+
const free = ([x, y]) => x >= scrollX + 8 && x + w <= scrollX + vw - 8 && y >= 4 && !walls.some((o) => x < o.r && x + w > o.l && y < o.b && y + h > o.t);
|
|
390
|
+
const spots = [[left, top]];
|
|
391
|
+
for (const r of rs.map(doc)) {
|
|
392
|
+
const mid = (r.t + r.b) / 2 - h / 2;
|
|
393
|
+
spots.push([r.r + 16, mid], [r.l - 10 - w, mid], [r.r - w, r.t - h - 20], [r.r - w, r.b + 10]);
|
|
394
|
+
}
|
|
395
|
+
[left, top] = spots.find(free) || spots[0];
|
|
399
396
|
box.style.left = `${left}px`; box.style.top = `${top}px`;
|
|
400
397
|
box.onclick = (e) => {
|
|
401
398
|
const act = e.target.closest('[data-pa]')?.dataset.pa; if (!act) return;
|
|
@@ -489,7 +486,7 @@ el.querySelector('.hint').textContent = ''; el.querySelector('[data-act="add"]')
|
|
|
489
486
|
el.addEventListener('click', (e) => {
|
|
490
487
|
const act = e.target.closest('[data-act]')?.dataset.act;
|
|
491
488
|
if (act === 'add') finish(planComment);
|
|
492
|
-
else if (act === 'details') peek(target);
|
|
489
|
+
else if (act === 'details') { closeCard(); peek(target); }
|
|
493
490
|
else if (act === 'comment') { el.classList.remove('viewing'); el.setAttribute('aria-label', 'Comment'); ta.focus({ preventScroll: true }); }
|
|
494
491
|
else if (act === 'cancel') closeCard();
|
|
495
492
|
else if (act === 'remove') { removeNote(noteId, true); closeCard(); }
|
package/src/ui/workspace.css
CHANGED
|
@@ -1,39 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
@font-face { font-family: "Instrument Sans"; font-weight: 600; font-display: swap; src: url("/__truemap/fonts/instrument-sans-latin-600-normal.woff2") format("woff2"); }
|
|
4
|
-
@font-face { font-family: "Commit Mono"; font-weight: 400; font-display: swap; src: url("/__truemap/fonts/commit-mono-latin-400-normal.woff2") format("woff2"); }
|
|
5
|
-
|
|
6
|
-
/* One fixed system: neutrals and ink carry structure and selection. The accent (ink by default, the
|
|
7
|
-
project's own colour when truemap finds one) marks the primary action. A highlighter marks what the
|
|
8
|
-
agent points at. Status colours mean status and nothing else. */
|
|
1
|
+
/* Colours and fonts come from /__truemap/tokens.css (truemap's tokens, then the project's theme.css),
|
|
2
|
+
so the workspace and the pages always share one look. These names are the workspace's shorthand. */
|
|
9
3
|
:root {
|
|
10
|
-
--bg:
|
|
11
|
-
--chrome:
|
|
12
|
-
--surface:
|
|
13
|
-
--line:
|
|
14
|
-
--line-strong:
|
|
15
|
-
--ink:
|
|
16
|
-
--text:
|
|
17
|
-
--muted:
|
|
18
|
-
--faint:
|
|
19
|
-
--accent:
|
|
20
|
-
--accent-text:
|
|
21
|
-
--mark:
|
|
22
|
-
--changed:
|
|
23
|
-
--broken:
|
|
24
|
-
--fine:
|
|
25
|
-
--font:
|
|
26
|
-
--code:
|
|
4
|
+
--bg: var(--tm-paper);
|
|
5
|
+
--chrome: var(--tm-chrome);
|
|
6
|
+
--surface: var(--tm-wash);
|
|
7
|
+
--line: var(--tm-rule);
|
|
8
|
+
--line-strong: var(--tm-rule-strong);
|
|
9
|
+
--ink: var(--tm-ink);
|
|
10
|
+
--text: var(--tm-text);
|
|
11
|
+
--muted: var(--tm-graphite);
|
|
12
|
+
--faint: var(--tm-pencil);
|
|
13
|
+
--accent: var(--tm-accent);
|
|
14
|
+
--accent-text: var(--tm-accent-text);
|
|
15
|
+
--mark: var(--tm-mark);
|
|
16
|
+
--changed: var(--tm-changed);
|
|
17
|
+
--broken: var(--tm-broken);
|
|
18
|
+
--fine: var(--tm-fine);
|
|
19
|
+
--font: var(--tm-font);
|
|
20
|
+
--code: var(--tm-code);
|
|
27
21
|
--panel-w: 420px;
|
|
28
|
-
color-scheme: light dark;
|
|
29
|
-
}
|
|
30
|
-
@media (prefers-color-scheme: dark) {
|
|
31
|
-
:root {
|
|
32
|
-
--bg: #161615; --chrome: #1b1b1a; --surface: #252523; --line: #2f2f2c; --line-strong: #44443f;
|
|
33
|
-
--ink: #f2f2ee; --text: #dadad4; --muted: #a0a098; --faint: #75756e;
|
|
34
|
-
--accent: #f2f2ee; --accent-text: #141413; --mark: #6b5a12;
|
|
35
|
-
--changed: #e0a548; --broken: #ef8574; --fine: #7cc49c;
|
|
36
|
-
}
|
|
37
22
|
}
|
|
38
23
|
|
|
39
24
|
* { box-sizing: border-box; }
|
package/src/ui/workspace.html
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
<meta name="referrer" content="no-referrer">
|
|
7
7
|
<title>truemap</title>
|
|
8
8
|
<link rel="icon" href="data:image/svg+xml,%3Csvg xmlns=%27http://www.w3.org/2000/svg%27 viewBox=%270 0 20 20%27%3E%3Cpath d=%27M10 2.2 15.6 17.6 10 14.4 4.4 17.6z%27 fill=%27%23fff%27 stroke=%27%2317202b%27 stroke-width=%271.5%27 stroke-linejoin=%27round%27/%3E%3Cpath d=%27M10 2.2V14.4L4.4 17.6z%27 fill=%27%23141413%27/%3E%3C/svg%3E">
|
|
9
|
+
<link rel="stylesheet" href="/__truemap/tokens.css" id="tokensCss">
|
|
9
10
|
<link rel="stylesheet" href="/__truemap/workspace.css">
|
|
10
11
|
<script>window.TRUEMAP_TOKEN = "__TRUEMAP_TOKEN__"; window.TRUEMAP_CONTENT = "__TRUEMAP_CONTENT__";</script>
|
|
11
12
|
</head>
|