iso-explainer 1.0.0 → 1.1.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 +17 -8
- package/README.pt-BR.md +14 -13
- package/package.json +1 -1
- package/skills/iso-explainer/SKILL.md +24 -17
- package/skills/iso-explainer/assets/figure/figure.mjs +93 -0
- package/skills/iso-explainer/assets/runtime/ANATOMY-LICENSE.txt +21 -0
- package/skills/iso-explainer/assets/runtime/app.js +60 -20
- package/skills/iso-explainer/assets/runtime/engine.js +113 -66
- package/skills/iso-explainer/assets/runtime/kit.js +676 -0
- package/skills/iso-explainer/assets/runtime/looks-core.js +162 -0
- package/skills/iso-explainer/assets/runtime/looks.js +508 -0
- package/skills/iso-explainer/assets/runtime/styles.css +461 -447
- package/skills/iso-explainer/assets/templates/starter.course.json +6 -6
- package/skills/iso-explainer/examples/arquitetura-pedidos.docs.json +12 -10
- package/skills/iso-explainer/examples/catalogo-looks.course.json +599 -0
- package/skills/iso-explainer/examples/engenharia-na-pratica.course.json +11 -6
- package/skills/iso-explainer/examples/figures/token-bucket.build.mjs +111 -0
- package/skills/iso-explainer/examples/figures/token-bucket.html +959 -95
- package/skills/iso-explainer/examples/historia-pedidos.story.json +12 -10
- package/skills/iso-explainer/references/engine.md +1 -1
- package/skills/iso-explainer/references/entities.md +5 -3
- package/skills/iso-explainer/references/figure-craft.md +62 -0
- package/skills/iso-explainer/references/inside.md +20 -10
- package/skills/iso-explainer/references/layout.md +12 -0
- package/skills/iso-explainer/references/looks.md +60 -0
- package/skills/iso-explainer/references/story-mode.md +2 -2
- package/skills/iso-explainer/scripts/build.mjs +5 -3
- package/skills/iso-explainer/scripts/lib/layout.mjs +111 -0
- package/skills/iso-explainer/scripts/lib/resolve.mjs +20 -2
- package/skills/iso-explainer/scripts/snapshot.mjs +159 -97
- package/skills/iso-explainer/scripts/validate.mjs +33 -16
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
// iso-explainer · engine.js
|
|
2
2
|
// Isometric SVG stage: projection, primitives, entity renderers, dark-theme remap,
|
|
3
3
|
// and the Stage class (scene diff -> tween timeline, auto camera, link labels, packets).
|
|
4
|
-
// Original implementation. Depends
|
|
4
|
+
// Original implementation. Depends on icons.js and looks.js (object looks built with the vendored anatomy kit).
|
|
5
5
|
import { ICONS } from './icons.js';
|
|
6
|
+
import { LOOKS, lookOf } from './looks.js';
|
|
7
|
+
import { lookP, PX_PER_Z, darkHex } from './looks-core.js';
|
|
6
8
|
|
|
7
9
|
/* ───────────────────────── numbers & projection ───────────────────────── */
|
|
8
10
|
|
|
@@ -53,43 +55,7 @@ export const TONES = {
|
|
|
53
55
|
};
|
|
54
56
|
const LEVEL = (v) => (v < 0.6 ? '#7fc278' : v < 0.85 ? '#efb041' : '#e5534b');
|
|
55
57
|
|
|
56
|
-
|
|
57
|
-
- near-neutral warm colours invert lightness (paper → charcoal, ink → cream)
|
|
58
|
-
- light pastels become deep, low-saturation tones
|
|
59
|
-
- mid tones stay, dark tones become light.
|
|
60
|
-
UPPERCASE hex is never remapped (use it for colours that must stay fixed). */
|
|
61
|
-
const hexToHsl = (hex) => {
|
|
62
|
-
const n = parseInt(hex.length === 4 ? hex.slice(1).replace(/./g, '$&$&') : hex.slice(1), 16);
|
|
63
|
-
const r = ((n >> 16) & 255) / 255, g = ((n >> 8) & 255) / 255, b = (n & 255) / 255;
|
|
64
|
-
const max = Math.max(r, g, b), min = Math.min(r, g, b), c = max - min, l = (max + min) / 2;
|
|
65
|
-
let h = 0;
|
|
66
|
-
if (c) {
|
|
67
|
-
h = max === r ? ((g - b) / c) % 6 : max === g ? (b - r) / c + 2 : (r - g) / c + 4;
|
|
68
|
-
h *= 60; if (h < 0) h += 360;
|
|
69
|
-
}
|
|
70
|
-
const s = c ? c / (1 - Math.abs(2 * l - 1)) : 0;
|
|
71
|
-
return { h, s, l, c };
|
|
72
|
-
};
|
|
73
|
-
const hslToHex = (h, s, l) => {
|
|
74
|
-
const c = (1 - Math.abs(2 * l - 1)) * s, x = c * (1 - Math.abs(((h / 60) % 2) - 1)), m = l - c / 2;
|
|
75
|
-
const [r, g, b] = h < 60 ? [c, x, 0] : h < 120 ? [x, c, 0] : h < 180 ? [0, c, x] : h < 240 ? [0, x, c] : h < 300 ? [x, 0, c] : [c, 0, x];
|
|
76
|
-
const t = (v) => Math.round(clamp01(v + m) * 255).toString(16).padStart(2, '0');
|
|
77
|
-
return `#${t(r)}${t(g)}${t(b)}`;
|
|
78
|
-
};
|
|
79
|
-
const darkCache = new Map();
|
|
80
|
-
export function darkHex(hex) {
|
|
81
|
-
if (darkCache.has(hex)) return darkCache.get(hex);
|
|
82
|
-
const { h, s, l, c } = hexToHsl(hex);
|
|
83
|
-
let out;
|
|
84
|
-
if (c < 0.05 || (c < 0.14 && h >= 10 && h <= 64)) {
|
|
85
|
-
const L = l >= 0.88 ? 0.11 + (l - 0.9) * 0.9 : 1 - l;
|
|
86
|
-
out = hslToHex(c < 0.02 ? 34 : h, 0.12, Math.max(0.06, Math.min(0.93, L)));
|
|
87
|
-
} else if (l >= 0.66) out = hslToHex(h, Math.min(s, 0.5) * 0.62, 0.17 + (l - 0.66) * 0.55);
|
|
88
|
-
else if (l >= 0.36) out = hex;
|
|
89
|
-
else out = hslToHex(h, Math.min(s, 0.6), 0.8);
|
|
90
|
-
darkCache.set(hex, out);
|
|
91
|
-
return out;
|
|
92
|
-
}
|
|
58
|
+
// Dark theme remap (darkHex) lives in looks-core.js so figures share it.
|
|
93
59
|
export const isDark = () => typeof document !== 'undefined' && document.documentElement.dataset.theme === 'dark';
|
|
94
60
|
export const themed = (svg) => (!svg || !isDark() ? svg : svg.replace(/#[0-9a-f]{6}\b|#[0-9a-f]{3}\b/g, darkHex));
|
|
95
61
|
|
|
@@ -215,15 +181,14 @@ export function prism({ x0, x1, y0, y1, h, radius = 9 }) {
|
|
|
215
181
|
bevel: roundLine([L, B, R], 8),
|
|
216
182
|
};
|
|
217
183
|
}
|
|
218
|
-
function paintPrism(g, color, { stroke =
|
|
184
|
+
function paintPrism(g, color, { stroke = '#484139', sw = 1 } = {}) {
|
|
219
185
|
return `
|
|
220
186
|
<path d="${g.sil}" fill="url(#g-${color}-side)"/>
|
|
221
187
|
<path d="${g.right}" fill="#3a2a14" opacity=".06"/>
|
|
222
188
|
<path d="${g.top}" fill="url(#g-${color}-top)"/>
|
|
223
189
|
<path d="${g.sheen}" fill="#ffffff" opacity=".22" filter="url(#blur-sm)"/>
|
|
224
|
-
<path d="${g.bevel}" transform="translate(0 1.4)" fill="none" stroke="#ffffff" stroke-opacity=".
|
|
225
|
-
<path d="${g.
|
|
226
|
-
<path d="${g.sil}" fill="none" stroke="${stroke}" stroke-width="${sw}" stroke-linejoin="round"/>`;
|
|
190
|
+
<path class="prism-bevel" d="${g.bevel}" transform="translate(0 1.4)" fill="none" stroke="#ffffff" stroke-opacity=".55" stroke-width="1" stroke-linecap="round"/>
|
|
191
|
+
<path class="prism-outline" d="${g.sil}" fill="none" stroke="${stroke}" stroke-width="${sw}" stroke-linejoin="round"/>`;
|
|
227
192
|
}
|
|
228
193
|
const shadowOf = (g, h, lift, alpha) => {
|
|
229
194
|
const dy = Math.min(9, 3 + h * 0.15), fade = 1 - Math.min(1, lift / 140) * 0.85;
|
|
@@ -242,8 +207,8 @@ export function pill(cx, cy, text, { tone = 'paper', size = 10.5, icon = null }
|
|
|
242
207
|
const x = cx - w / 2, y = cy - h / 2, tx = x + 9 + (icon ? 15 : 0) + tw / 2;
|
|
243
208
|
const body = lines.map((l, i) => svgText(tx, cy + size * 0.36 + (i - (lines.length - 1) / 2) * lh, l, size, 700, t.fg)).join('');
|
|
244
209
|
return `<g class="pill">
|
|
245
|
-
<rect x="${r2(x)}" y="${r2(y +
|
|
246
|
-
<rect x="${r2(x)}" y="${r2(y)}" width="${r2(w)}" height="${h}" rx="10.5" fill="${t.bg}" stroke="
|
|
210
|
+
<rect x="${r2(x)}" y="${r2(y + 1.5)}" width="${r2(w)}" height="${h}" rx="10.5" fill="${DROP}" opacity=".16"/>
|
|
211
|
+
<rect x="${r2(x)}" y="${r2(y)}" width="${r2(w)}" height="${h}" rx="10.5" fill="${t.bg}" stroke="#82776b" stroke-width=".85"/>
|
|
247
212
|
${icon ? iconSVG(icon, x + 15, cy, 12, { stroke: 2.2, color: t.fg }) : ''}${body}</g>`;
|
|
248
213
|
}
|
|
249
214
|
function meterPill(cx, cy, v, icon = 'cpu') {
|
|
@@ -300,7 +265,56 @@ export const DEFAULTS = {
|
|
|
300
265
|
panel: { title: '', icon: 'sparkles', lines: [], bars: [], w: 0, opacity: 1, lift: 0, corner: null },
|
|
301
266
|
};
|
|
302
267
|
|
|
303
|
-
|
|
268
|
+
// A block drawn as a look: the object stands on a plinth in the block's colour; state overlays
|
|
269
|
+
// (heat, dead, dim) and pills work as for plain blocks; the label moves to a plate below.
|
|
270
|
+
const lookCache = new Map();
|
|
271
|
+
const lookKey = (name, e) => `${name}|${e.d ?? e.s ?? e.r * 2}|${e.w ?? e.s ?? e.r * 2}|${e.color}|${e.items ?? ''}`;
|
|
272
|
+
function renderLook(e, name, se) {
|
|
273
|
+
const L = LOOKS[name], d = e.d ?? e.s ?? e.r * 2, w = e.w ?? e.s ?? e.r * 2, key = lookKey(name, e);
|
|
274
|
+
if (!lookCache.has(key)) lookCache.set(key, L.build(e, lookP([0, 0]), PALETTE[e.color] || PALETTE.blue));
|
|
275
|
+
const built = lookCache.get(key), st = se ? (se.look?.name === name ? se.look : (se.look = { name, s: L.state() })) : { s: L.state() };
|
|
276
|
+
const hx = d / 2, hy = w / 2, topPx = built.env.top * PX_PER_Z, lift = e.lift;
|
|
277
|
+
const g = prism({ x0: e.x - hx, x1: e.x + hx, y0: e.y - hy, y1: e.y + hy, h: topPx, radius: 9 });
|
|
278
|
+
const [ox, oy] = iso(e.x, e.y, 0);
|
|
279
|
+
const layers = built.layers.map((l) => (typeof l === 'string' ? l : `<g data-live="${l.live}">${l.draw(st.s, e)}</g>`)).join('');
|
|
280
|
+
const fade = 1 - e.dead * 0.5 - e.dim * 0.35;
|
|
281
|
+
const X = iso(e.x, e.y, 0)[0];
|
|
282
|
+
const body = `<g opacity="${r2(e.opacity)}">
|
|
283
|
+
${shadowOf(g, topPx * 0.5, lift, 0.14)}
|
|
284
|
+
<g transform="translate(0 ${r2(-lift)})">
|
|
285
|
+
${e.heat > 0.01 ? `<g class="pulse"><path d="${g.sil}" fill="#f0552f" opacity="${r2(e.heat * 0.55)}" filter="url(#glow)"/></g>` : ''}
|
|
286
|
+
<g class="look look--${name}" transform="translate(${r2(ox)} ${r2(oy)})" opacity="${r2(fade)}">${layers}</g>
|
|
287
|
+
${e.heat > 0.01 ? `<path d="${g.sil}" fill="#f0552f" opacity="${r2(e.heat * 0.18)}"/>` : ''}
|
|
288
|
+
${e.dead > 0.01 ? `<path d="${g.sil}" fill="#b9b2a8" opacity="${r2(e.dead * 0.55)}"/>` : ''}
|
|
289
|
+
${e.dim > 0.01 ? `<path d="${g.sil}" fill="#f4ebe0" opacity="${r2(e.dim * 0.5)}"/>` : ''}
|
|
290
|
+
${e.dead > 0.01 ? `<g opacity="${r2(e.dead)}" stroke="#c0392b" stroke-width="3.2" stroke-linecap="round"><path d="M${r2(X - 9)},${r2(g.ty - 10)} L${r2(X + 9)},${r2(g.ty + 8)} M${r2(X + 9)},${r2(g.ty - 10)} L${r2(X - 9)},${r2(g.ty + 8)}"/></g>` : ''}
|
|
291
|
+
</g></g>`;
|
|
292
|
+
const labels = Array.isArray(e.label) ? e.label : e.label ? [e.label] : [];
|
|
293
|
+
// name plate under the plinth: bold name in a pill, the sub line as quiet text beneath it
|
|
294
|
+
const name1 = labels.join(' '), ly = g.Bd[1] - lift + 15, subW = e.sub ? textWidth(e.sub, 9.5, 600) : 0;
|
|
295
|
+
let over = '';
|
|
296
|
+
const boxes = [boxOf(g.outline.map(([x, y]) => [x, y - lift]))];
|
|
297
|
+
if (name1) {
|
|
298
|
+
over += `<g opacity="${r2(e.labelFade ?? 1)}">${pill(X, ly, name1, { size: 11 })}${e.sub ? svgText(X, ly + 22, e.sub, 9.5, 600, '#6f6961', 'stroke="#f4ebe0" stroke-width="1.6" paint-order="stroke" stroke-linejoin="round"') : ''}</g>`;
|
|
299
|
+
const half = Math.max(pillWidth(name1, 11), subW) / 2;
|
|
300
|
+
boxes.push([X - half, ly - PILL_H / 2, X + half, ly + PILL_H / 2 + (e.sub ? 16 : 2)]);
|
|
301
|
+
}
|
|
302
|
+
const below = e.pills === 'below', y0 = below ? ly + 34 : g.T[1] - lift - 17;
|
|
303
|
+
const pe = name === 'database' ? { ...e, cpu: -1 } : e; // the database shows its level in the glass gauge
|
|
304
|
+
const stk = pillStack(pe, X, y0, below);
|
|
305
|
+
over = over || stk.svg ? `<g opacity="${r2(e.opacity)}">${over}${stk.svg}</g>` : '';
|
|
306
|
+
const poly = g.outline.map(([x, y]) => [x, y - lift]);
|
|
307
|
+
const bottom = (name1 ? (e.sub ? 46 : 32) : 14) + (below ? stk.n * 26 : 0);
|
|
308
|
+
return {
|
|
309
|
+
body, over, poly, live: !!L.tick,
|
|
310
|
+
boxes: [...boxes, ...stackRects(pe, X, y0, below)],
|
|
311
|
+
bounds: widen(boxOf(g.outline, [8, below ? 8 : 8 + Math.max(stk.n, 1) * 26, 8, bottom]), X, Math.max(stackHalfWidth(pe), name1 ? Math.max(pillWidth(name1, 11), subW) / 2 : 0)),
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
function renderBlock(e, se) {
|
|
316
|
+
const look = lookOf(e);
|
|
317
|
+
if (look) return renderLook(e, look, se);
|
|
304
318
|
const hx = (e.d ?? e.s) / 2, hy = (e.w ?? e.s) / 2;
|
|
305
319
|
const g = prism({ x0: e.x - hx, x1: e.x + hx, y0: e.y - hy, y1: e.y + hy, h: e.h, radius: e.radius ?? 9 });
|
|
306
320
|
const lift = e.lift, ty = g.ty;
|
|
@@ -318,7 +332,7 @@ function renderBlock(e) {
|
|
|
318
332
|
const fade = 1 - e.dead * 0.5 - e.dim * 0.35;
|
|
319
333
|
const cross = e.dead > 0.01 ? `<g opacity="${r2(e.dead)}" stroke="#c0392b" stroke-width="3.2" stroke-linecap="round"><path d="M${r2(X - 9)},${r2(ty - 10)} L${r2(X + 9)},${r2(ty + 8)} M${r2(X + 9)},${r2(ty - 10)} L${r2(X - 9)},${r2(ty + 8)}"/></g>` : '';
|
|
320
334
|
const body = `<g opacity="${r2(e.opacity)}">
|
|
321
|
-
${shadowOf(g, e.h, lift, 0.
|
|
335
|
+
${shadowOf(g, e.h, lift, 0.18)}
|
|
322
336
|
<g transform="translate(0 ${r2(-lift)})">
|
|
323
337
|
${e.heat > 0.01 ? `<g class="pulse"><path d="${g.sil}" fill="#f0552f" opacity="${r2(e.heat * 0.7)}" filter="url(#glow)"/></g>` : ''}
|
|
324
338
|
${paintPrism(g, PALETTE[e.color] ? e.color : 'blue')}
|
|
@@ -409,7 +423,9 @@ function renderDevice(e) {
|
|
|
409
423
|
return { body, over, poly: dpoly, boxes: dboxes, bounds: boxOf([...base.outline, anchor], tagStackBounds(e.tags, ax, base.outline)) };
|
|
410
424
|
}
|
|
411
425
|
|
|
412
|
-
function renderDb(e) {
|
|
426
|
+
function renderDb(e, se) {
|
|
427
|
+
const look = lookOf(e);
|
|
428
|
+
if (look) return renderLook(e, look, se);
|
|
413
429
|
const rx = Math.SQRT2 * 14 * e.r, ry = rx / 2, [cx, cy] = iso(e.x, e.y, 0), lift = e.lift;
|
|
414
430
|
const bot = cy - lift, top = bot - e.h;
|
|
415
431
|
const col = PALETTE[e.color] ? e.color : 'purple';
|
|
@@ -610,7 +626,7 @@ const ENTER_FROM = { crowd: { count: 0, lift: 26 }, device: { lift: 40 }, ghost:
|
|
|
610
626
|
const EXIT_TO = { crowd: { count: 0 }, queue: { n: 0, opacity: 1 }, ghost: {}, zone: {}, panel: { lift: -10 } };
|
|
611
627
|
const same = (a, b) => JSON.stringify(a ?? null) === JSON.stringify(b ?? null);
|
|
612
628
|
|
|
613
|
-
function defsSVG() {
|
|
629
|
+
function defsSVG(gridPatternId) {
|
|
614
630
|
let g = '';
|
|
615
631
|
for (const [k, c] of Object.entries(PALETTE)) {
|
|
616
632
|
g += `<linearGradient id="g-${k}-top" x1="0" y1="0" x2="0.35" y2="1"><stop offset="0" stop-color="${c.top[0]}"/><stop offset="1" stop-color="${c.top[1]}"/></linearGradient>
|
|
@@ -627,23 +643,27 @@ function defsSVG() {
|
|
|
627
643
|
<marker id="arrow" viewBox="0 0 10 10" refX="8.6" refY="5" markerWidth="5.2" markerHeight="5.2" orient="auto-start-reverse" markerUnits="strokeWidth"><path d="M1,1.2 L9,5 L1,8.8 Z" fill="${INK}" stroke="${INK}" stroke-width="1" stroke-linejoin="round"/></marker>
|
|
628
644
|
<marker id="arrow-muted" viewBox="0 0 10 10" refX="8.6" refY="5" markerWidth="5.2" markerHeight="5.2" orient="auto-start-reverse" markerUnits="strokeWidth"><path d="M1,1.2 L9,5 L1,8.8 Z" fill="#a59c90" stroke="#a59c90" stroke-width="1" stroke-linejoin="round"/></marker>
|
|
629
645
|
<marker id="arrow-red" viewBox="0 0 10 10" refX="8.6" refY="5" markerWidth="5.2" markerHeight="5.2" orient="auto-start-reverse" markerUnits="strokeWidth"><path d="M1,1.2 L9,5 L1,8.8 Z" fill="#c0392b" stroke="#c0392b" stroke-width="1" stroke-linejoin="round"/></marker>
|
|
630
|
-
<pattern id="
|
|
646
|
+
<pattern id="${gridPatternId}" patternUnits="userSpaceOnUse" x="0" y="-7" width="28" height="14"><path d="M0 7 L14 0 L28 7 L14 14 Z" fill="none" stroke="#a8916f" stroke-opacity=".3" stroke-width=".8"/></pattern>`;
|
|
631
647
|
}
|
|
632
648
|
|
|
649
|
+
let stageCount = 0;
|
|
633
650
|
export class Stage {
|
|
634
651
|
constructor(host, { reducedMotion = false } = {}) {
|
|
635
652
|
this.host = host;
|
|
636
653
|
this.reduced = reducedMotion;
|
|
654
|
+
// Fragment IDs resolve across the document, including when two SVG stages are open.
|
|
655
|
+
const gridId = `isx-grid-${++stageCount}`, fadeId = `${gridId}-fade`, maskId = `${gridId}-mask`;
|
|
656
|
+
this.gridPatternId = `${gridId}-pattern`;
|
|
637
657
|
this.svg = el('svg', { class: 'stage-svg', xmlns: NS, preserveAspectRatio: 'xMidYMid meet', role: 'img' });
|
|
638
|
-
this.svg.innerHTML = `<defs class="defs-theme">${themed(defsSVG())}</defs>
|
|
639
|
-
<defs><radialGradient id="
|
|
640
|
-
<mask id="
|
|
641
|
-
<rect class="stage-grid" x="-6000" y="-6000" width="12000" height="12000" fill="url(
|
|
658
|
+
this.svg.innerHTML = `<defs class="defs-theme">${themed(defsSVG(this.gridPatternId))}</defs>
|
|
659
|
+
<defs><radialGradient id="${fadeId}" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#fff"/><stop offset=".42" stop-color="#fff" stop-opacity=".92"/><stop offset=".78" stop-color="#fff" stop-opacity=".35"/><stop offset="1" stop-color="#fff" stop-opacity="0"/></radialGradient>
|
|
660
|
+
<mask id="${maskId}" maskUnits="userSpaceOnUse" x="-6000" y="-6000" width="12000" height="12000"><rect x="-6000" y="-6000" width="12000" height="12000" fill="url(#${fadeId})"/></mask></defs>
|
|
661
|
+
<rect class="stage-grid" x="-6000" y="-6000" width="12000" height="12000" fill="url(#${this.gridPatternId})" mask="url(#${maskId})"/>
|
|
642
662
|
<g class="layer-floor"></g><g class="layer-links"></g><g class="layer-packets"></g><g class="layer-ents"></g><g class="layer-over"></g><g class="layer-hud"></g>`;
|
|
643
663
|
host.appendChild(this.svg);
|
|
644
664
|
const q = (s) => this.svg.querySelector(s);
|
|
645
665
|
this.L = { floor: q('.layer-floor'), links: q('.layer-links'), packets: q('.layer-packets'), ents: q('.layer-ents'), over: q('.layer-over'), hud: q('.layer-hud') };
|
|
646
|
-
this.fadeGrad = q(
|
|
666
|
+
this.fadeGrad = q(`#${fadeId}`);
|
|
647
667
|
this.defs = q('.defs-theme');
|
|
648
668
|
this.ents = new Map(); this.links = new Map(); this.plans = new Map();
|
|
649
669
|
this.scenes = []; this.scene = null; this.flows = []; this.packets = [];
|
|
@@ -683,10 +703,15 @@ export class Stage {
|
|
|
683
703
|
let b = [Infinity, Infinity, -Infinity, -Infinity], panel = null;
|
|
684
704
|
const grow = (r) => { b = [Math.min(b[0], r[0]), Math.min(b[1], r[1]), Math.max(b[2], r[2]), Math.max(b[3], r[3])]; };
|
|
685
705
|
const shapes = {};
|
|
706
|
+
// Focus steps (docs/story "dim" pattern): the camera frames what is in focus; dimmed context stays
|
|
707
|
+
// visible around it but does not shrink the picture. Without focus, everything is framed.
|
|
708
|
+
const inFocus = (e) => (e.dim || 0) < 0.5;
|
|
709
|
+
const focusing = Object.values(ents).filter((e) => e.type !== 'panel' && e.type !== 'zone').some((e) => !inFocus(e))
|
|
710
|
+
&& Object.values(ents).filter((e) => e.type !== 'panel' && e.type !== 'zone' && inFocus(e)).length >= 2;
|
|
686
711
|
for (const [id, e] of Object.entries(ents)) {
|
|
687
712
|
if (e.type === 'panel') { if (this.showCards) panel = { ...renderPanel(e).size, corner: e.corner }; continue; }
|
|
688
713
|
const r = RENDER[e.type](e);
|
|
689
|
-
shapes[id] = r.poly; grow(r.bounds); boxes.push(r.bounds);
|
|
714
|
+
shapes[id] = r.poly; if (!focusing || (inFocus(e) && e.type !== 'zone')) grow(r.bounds); boxes.push(r.bounds);
|
|
690
715
|
if (e.type !== 'zone') { const bx = r.boxes || [r.bounds]; obstacles.push(bx[0]); texts.push(...bx.slice(1)); }
|
|
691
716
|
if (r.poly && e.type !== 'zone') polys.push(r.poly);
|
|
692
717
|
}
|
|
@@ -697,7 +722,8 @@ export class Stage {
|
|
|
697
722
|
pts = clipStart(pts, shapes[l.from], 3);
|
|
698
723
|
if (l.to) pts = clipEnd(pts, shapes[l.to], l.heads === 'none' ? 3 : 4);
|
|
699
724
|
paths[id] = pts;
|
|
700
|
-
|
|
725
|
+
const framed = !focusing || (!l.dim && inFocus(ents[l.from]) && (!l.to || inFocus(ents[l.to])));
|
|
726
|
+
for (const [x, y] of samplePath(pts)) { samples.push([x, y, id]); if (framed) grow([x - 3, y - 3, x + 3, y + 3]); }
|
|
701
727
|
}
|
|
702
728
|
const picks = {};
|
|
703
729
|
for (const [id, l] of Object.entries(scene.links || {})) {
|
|
@@ -707,14 +733,14 @@ export class Stage {
|
|
|
707
733
|
for (const s of labelSpots(paths[id], l.labelAt ?? 0.5, w, h)) {
|
|
708
734
|
let cost = s.drift * 90 + (s.side < 0 ? 2 : 0) + (s.onLine ? 12 : 0);
|
|
709
735
|
const pad = [s.rect[0] - 3, s.rect[1] - 3, s.rect[2] + 3, s.rect[3] + 3];
|
|
710
|
-
for (const o of obstacles) { const a = overlap(pad, o); if (a) cost +=
|
|
736
|
+
for (const o of obstacles) { const a = overlap(pad, o); if (a) cost += 240 + a / 2; } // a label on an object hides the object: as bad as two labels on each other
|
|
711
737
|
for (const o of texts) { const a = overlap(pad, o); if (a) cost += 260 + a / 2; }
|
|
712
738
|
for (const o of labelRects) { const a = overlap([s.rect[0] - 4, s.rect[1] - 4, s.rect[2] + 4, s.rect[3] + 4], o); if (a) cost += 300 + a / 2; }
|
|
713
739
|
for (const [x, y, lid] of samples) if (lid !== id && x > s.rect[0] - 3 && x < s.rect[2] + 3 && y > s.rect[1] - 3 && y < s.rect[3] + 3) cost += 14;
|
|
714
740
|
if (!best || cost < best.cost) best = { ...s, cost };
|
|
715
741
|
}
|
|
716
742
|
picks[id] = { t: best.t, side: best.side, gap: best.gap };
|
|
717
|
-
labelRects.push(best.rect); grow([best.rect[0] - 2, best.rect[1] - 2, best.rect[2] + 2, best.rect[3] + 4]);
|
|
743
|
+
labelRects.push(best.rect); if (!focusing || !l.dim) grow([best.rect[0] - 2, best.rect[1] - 2, best.rect[2] + 2, best.rect[3] + 4]);
|
|
718
744
|
}
|
|
719
745
|
if (b[0] === Infinity) b = [-100, -60, 100, 60];
|
|
720
746
|
return { b, boxes: [...obstacles, ...texts, ...labelRects], polys, panel, picks };
|
|
@@ -796,8 +822,10 @@ export class Stage {
|
|
|
796
822
|
setCam(c) {
|
|
797
823
|
this.cam = c;
|
|
798
824
|
const d = this.displayCam(c);
|
|
825
|
+
const pixelWidth = Math.max(1, this.host.clientWidth);
|
|
826
|
+
this.svg.classList.toggle('is-magnified', pixelWidth > d.w);
|
|
799
827
|
this.svg.setAttribute('viewBox', `${r2(d.x)} ${r2(d.y)} ${r2(d.w)} ${r2(d.h)}`);
|
|
800
|
-
this.L.hud.setAttribute('transform', `translate(${r2(d.x)} ${r2(d.y)}) scale(${(d.w /
|
|
828
|
+
this.L.hud.setAttribute('transform', `translate(${r2(d.x)} ${r2(d.y)}) scale(${(d.w / pixelWidth).toFixed(5)})`);
|
|
801
829
|
const cx = d.x + d.w / 2, cy = d.y + d.h / 2;
|
|
802
830
|
this.fadeGrad.setAttribute('cx', r2(cx)); this.fadeGrad.setAttribute('cy', r2(cy)); this.fadeGrad.setAttribute('r', r2(d.w * 0.56));
|
|
803
831
|
this.fadeGrad.setAttribute('gradientTransform', `translate(${r2(cx)} ${r2(cy)}) scale(1 0.6) translate(${r2(-cx)} ${r2(-cy)})`);
|
|
@@ -979,7 +1007,7 @@ export class Stage {
|
|
|
979
1007
|
this.onSettle?.();
|
|
980
1008
|
}
|
|
981
1009
|
retheme() {
|
|
982
|
-
this.defs.innerHTML = themed(defsSVG());
|
|
1010
|
+
this.defs.innerHTML = themed(defsSVG(this.gridPatternId));
|
|
983
1011
|
for (const e of this.ents.values()) this.renderEntity(e);
|
|
984
1012
|
for (const l of this.links.values()) l.labelKey = null;
|
|
985
1013
|
this.updateLinks(true);
|
|
@@ -998,14 +1026,15 @@ export class Stage {
|
|
|
998
1026
|
e.overEl.innerHTML = `<g transform="translate(${r2(e.cur.sx || 0)} ${r2((e.cur.sy || 0) - (e.cur.lift || 0))}) scale(${r2(this.hudScale)})">${themed(p.over)}</g>`;
|
|
999
1027
|
e.poly = null; return;
|
|
1000
1028
|
}
|
|
1001
|
-
const r = RENDER[e.cur.type](e.cur);
|
|
1029
|
+
const r = RENDER[e.cur.type](e.cur, e);
|
|
1002
1030
|
let over = r.over;
|
|
1003
1031
|
const insp = !!e.cur.inside && !!r.poly;
|
|
1004
1032
|
if (insp) { // magnifier badge on the right-top corner of the outline
|
|
1005
1033
|
const tip = r.poly.reduce((a, p) => (p[0] > a[0] + 0.5 || (Math.abs(p[0] - a[0]) <= 0.5 && p[1] < a[1]) ? p : a), r.poly[0]);
|
|
1006
|
-
over += `<g class="inspect-badge" opacity="${r2(e.cur.opacity ?? 1)}" transform="translate(${r2(tip[0] - 2)} ${r2(tip[1] - 6)})"><circle class="inspect-badge__ring" r="11" fill="none" stroke="#5fae57" stroke-width="
|
|
1034
|
+
over += `<g class="inspect-badge" opacity="${r2(e.cur.opacity ?? 1)}" transform="translate(${r2(tip[0] - 2)} ${r2(tip[1] - 6)})"><circle class="inspect-badge__ring" r="11" fill="none" stroke="#5fae57" stroke-width="1"/><circle r="10" fill="#dcefd2" stroke="#66835c" stroke-width=".9"/>${iconSVG('zoom-in', 0, 0, 12, { stroke: 1.45, color: INK })}</g>`;
|
|
1007
1035
|
}
|
|
1008
1036
|
e.el.innerHTML = themed(r.body); e.overEl.innerHTML = themed(over); e.poly = r.poly; e.bounds = r.bounds;
|
|
1037
|
+
e.liveEls = r.live ? Object.fromEntries([...e.el.querySelectorAll('[data-live]')].map((n) => [n.dataset.live, n])) : null;
|
|
1009
1038
|
if (insp !== !!e.insp) {
|
|
1010
1039
|
e.insp = insp;
|
|
1011
1040
|
for (const n of [e.el, e.overEl]) { n.classList.toggle('is-inspectable', insp); if (insp) { n.setAttribute('tabindex', '0'); n.setAttribute('role', 'button'); } else { n.removeAttribute('tabindex'); n.removeAttribute('role'); } }
|
|
@@ -1094,8 +1123,8 @@ export class Stage {
|
|
|
1094
1123
|
launch(route, kind, f) {
|
|
1095
1124
|
if (!route.every((id) => this.links.has(id))) return;
|
|
1096
1125
|
const g = el('g', { class: `pkt pkt--${kind}` });
|
|
1097
|
-
g.innerHTML = kind === 'ping' || kind === 'kill' ? '<circle r="
|
|
1098
|
-
: kind === 'write' ? '<rect x="-4.
|
|
1126
|
+
g.innerHTML = kind === 'ping' || kind === 'kill' ? '<circle r="4.4"/>' : kind === 'heavy' ? '<rect x="-7" y="-7" width="14" height="14" rx="3.5"/>'
|
|
1127
|
+
: kind === 'write' ? '<rect x="-4.9" y="-4.9" width="9.8" height="9.8" rx="2"/>' : kind === 'msg' || kind === 'poison' ? '<rect x="-5.8" y="-5.8" width="11.6" height="11.6" rx="2.6"/>' : '<circle r="5.3"/>';
|
|
1099
1128
|
this.L.packets.appendChild(g);
|
|
1100
1129
|
this.packets.push({ route, seg: 0, d: 0, kind, el: g, back: false, bounce: !!f.bounce, dwell: 0, speed: f.speed || 1, hold: f.hold || 0 });
|
|
1101
1130
|
}
|
|
@@ -1118,7 +1147,8 @@ export class Stage {
|
|
|
1118
1147
|
const span = b - a;
|
|
1119
1148
|
if (p.d >= span) {
|
|
1120
1149
|
const end = l.el.getPointAtLength(p.back ? a : b);
|
|
1121
|
-
if (!p.back && Math.random() < (l.spec.fail || 0)) { this.burst(end.x, end.y, 'fail'); p.el.remove(); continue; }
|
|
1150
|
+
if (!p.back && Math.random() < (l.spec.fail || 0)) { this.burst(end.x, end.y, 'fail'); this.ping(l.spec.to, p.kind, true); p.el.remove(); continue; }
|
|
1151
|
+
if (!p.back) this.ping(l.spec.to, p.kind, false);
|
|
1122
1152
|
if (!p.back && p.seg < p.route.length - 1) { p.seg++; p.d = 0; p.dwell = 0.16; p.el.style.opacity = 0; keep.push(p); continue; }
|
|
1123
1153
|
if (p.bounce && !p.back) { p.back = true; p.d = 0; if (p.hold) { p.dwell = p.hold; p.el.classList.add('pkt--held'); } else p.el.classList.add('pkt--back'); keep.push(p); continue; }
|
|
1124
1154
|
if (p.back && p.seg > 0) { p.seg--; p.d = 0; p.dwell = 0.16; p.el.style.opacity = 0; keep.push(p); continue; }
|
|
@@ -1131,6 +1161,23 @@ export class Stage {
|
|
|
1131
1161
|
this.packets = keep;
|
|
1132
1162
|
}
|
|
1133
1163
|
|
|
1164
|
+
/* ── looks: live parts ── */
|
|
1165
|
+
ping(id, kind, failed) {
|
|
1166
|
+
const e = id && this.ents.get(id);
|
|
1167
|
+
if (e?.look && LOOKS[e.look.name].ping) LOOKS[e.look.name].ping(e.look.s, kind, failed);
|
|
1168
|
+
}
|
|
1169
|
+
stepLooks(dt) {
|
|
1170
|
+
if (this.reduced) return;
|
|
1171
|
+
for (const e of this.ents.values()) {
|
|
1172
|
+
if (!e.liveEls || !e.look) continue;
|
|
1173
|
+
const L = LOOKS[e.look.name], dirty = L.tick(e.look.s, dt, e.cur);
|
|
1174
|
+
if (!dirty) continue;
|
|
1175
|
+
const built = lookCache.get(lookKey(e.look.name, e.cur));
|
|
1176
|
+
if (!built) continue;
|
|
1177
|
+
for (const l of built.layers) if (typeof l !== 'string' && dirty[l.live] && e.liveEls[l.live]) e.liveEls[l.live].innerHTML = themed(l.draw(e.look.s, e.cur));
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
|
|
1134
1181
|
/* ── frame loop ── */
|
|
1135
1182
|
tick(t) {
|
|
1136
1183
|
const dt = Math.min(0.05, (t - this.last) / 1000); this.last = t;
|
|
@@ -1172,6 +1219,6 @@ export class Stage {
|
|
|
1172
1219
|
if (t >= this.anim.end) { const a = this.anim; this.anim = null; this.updateLinks(true); this.settle(a); }
|
|
1173
1220
|
}
|
|
1174
1221
|
if (this.blend && !this.anim) this.setCam(this.cam);
|
|
1175
|
-
if (!this.paused) this.stepPackets(dt);
|
|
1222
|
+
if (!this.paused) { this.stepPackets(dt); this.stepLooks(dt); }
|
|
1176
1223
|
}
|
|
1177
1224
|
}
|