@johnoscott/isometric-engine 0.14.1 → 0.15.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.
Files changed (54) hide show
  1. package/README.md +1 -1
  2. package/iso-editor.js +199 -190
  3. package/iso-render.js +157 -148
  4. package/iso-systems.js +170 -159
  5. package/js/iso-objects/ants.js +36 -0
  6. package/js/iso-objects/index.js +47 -1
  7. package/js/iso-objects/looks.js +25 -0
  8. package/js/iso-objects/motion-builder.js +130 -0
  9. package/js/iso-objects/motion-doc.js +500 -0
  10. package/js/iso-objects/motion-entry.js +32 -0
  11. package/js/iso-objects/motion.js +635 -0
  12. package/js/iso-objects/resolve.js +238 -0
  13. package/js/iso-objects/scene.js +15 -13
  14. package/js/iso-objects/timeline.js +553 -0
  15. package/js/iso-systems/compile.js +59 -1
  16. package/js/iso-systems/index.js +4 -1
  17. package/js/iso-systems/render.js +20 -0
  18. package/js/iso-systems/schema.json +39 -0
  19. package/js/iso-viewer/page.js +2 -1
  20. package/js/iso-viewer/player.js +23 -34
  21. package/package.json +46 -1
  22. package/src/iso-objects/ants.ts +53 -0
  23. package/src/iso-objects/compile.ts +4 -1
  24. package/src/iso-objects/index.ts +14 -1
  25. package/src/iso-objects/looks.ts +21 -0
  26. package/src/iso-objects/motion-builder.ts +79 -0
  27. package/src/iso-objects/motion-doc.ts +361 -0
  28. package/src/iso-objects/motion-entry.ts +12 -0
  29. package/src/iso-objects/motion.ts +616 -0
  30. package/src/iso-objects/resolve.ts +196 -0
  31. package/src/iso-objects/scene.ts +29 -13
  32. package/src/iso-objects/timeline.ts +443 -0
  33. package/src/iso-objects/types.ts +20 -2
  34. package/src/iso-systems/compile.ts +58 -3
  35. package/src/iso-systems/index.ts +4 -1
  36. package/src/iso-systems/render.ts +41 -0
  37. package/src/iso-systems/schema.json +39 -0
  38. package/src/iso-viewer/page.ts +2 -1
  39. package/src/iso-viewer/player.ts +24 -41
  40. package/types/iso-objects/ants.d.ts +33 -0
  41. package/types/iso-objects/compile.d.ts +3 -0
  42. package/types/iso-objects/index.d.ts +14 -1
  43. package/types/iso-objects/looks.d.ts +4 -0
  44. package/types/iso-objects/motion-builder.d.ts +105 -0
  45. package/types/iso-objects/motion-doc.d.ts +787 -0
  46. package/types/iso-objects/motion-entry.d.ts +10 -0
  47. package/types/iso-objects/motion.d.ts +200 -0
  48. package/types/iso-objects/resolve.d.ts +20 -0
  49. package/types/iso-objects/scene.d.ts +11 -0
  50. package/types/iso-objects/timeline.d.ts +46 -0
  51. package/types/iso-objects/types.d.ts +32 -0
  52. package/types/iso-systems/compile.d.ts +20 -3
  53. package/types/iso-systems/index.d.ts +4 -1
  54. package/types/iso-systems/render.d.ts +21 -0
@@ -0,0 +1,196 @@
1
+ // A self-contained drawing: the renderer's SVG with its stylesheets worked out and written on the elements, as plain
2
+ // presentation attributes (no <style>, no custom properties, no hsl() or color-mix()), so it looks the same with no
3
+ // page around it and in a rasteriser that knows no CSS. Pure: the stylesheets are the engine's own (the theme's, the
4
+ // drawing's, a host's marks'), read by a small reader that knows what they use and throws at what it doesn't.
5
+
6
+ import type { Theme } from './types.ts';
7
+ import { themeParts } from '../iso-core/theme.ts';
8
+
9
+ export type ThemeMode = 'light' | 'dark';
10
+
11
+ interface Part { tag?: string; classes: string[]; not: string[]; attrs: [string, string | undefined][]; child: boolean }
12
+ interface Rule { parts: Part[]; spec: number; order: number; decls: [string, string, boolean][] }
13
+ interface El { name: string; attrs: [string, string][]; children: (El | string)[]; parent?: El }
14
+
15
+ /** what a declaration becomes: the attribute of its name */
16
+ const WRITTEN = new Set(['fill', 'stroke', 'stroke-width', 'stroke-dasharray', 'stroke-linecap', 'stroke-linejoin', 'opacity', 'fill-opacity', 'stroke-opacity', 'font-size', 'font-weight', 'font-family',
17
+ 'letter-spacing', 'text-anchor', 'dominant-baseline', 'paint-order', 'display', 'stop-color', 'stop-opacity']);
18
+ /** what a still has no use for */
19
+ const LEFT = new Set('cursor pointer-events transition animation transform-box transform-origin user-select'.split(' '));
20
+
21
+ function readPart(s: string, child: boolean): Part {
22
+ const p: Part = { classes: [], not: [], attrs: [], child };
23
+ let rest = s;
24
+ const eat = (re: RegExp) => { const m = re.exec(rest); if (m) rest = rest.slice(m[0].length); return m; };
25
+ const t = eat(/^[a-zA-Z][\w-]*/);
26
+ if (t) p.tag = t[0]; else eat(/^\*/);
27
+ while (rest) {
28
+ let m: RegExpExecArray | null;
29
+ if ((m = eat(/^\.([\w-]+)/))) p.classes.push(m[1]);
30
+ else if ((m = eat(/^:not\(\.([\w-]+)\)/))) p.not.push(m[1]);
31
+ else if ((m = eat(/^\[([\w-]+)(?:="([^"]*)")?\]/))) p.attrs.push([m[1], m[2]]);
32
+ else throw new Error(`resolve: a selector it doesn't know: ${s}`);
33
+ }
34
+ return p;
35
+ }
36
+ function readCss(css: string): Rule[] {
37
+ const text = css.replace(/\/\*[\s\S]*?\*\//g, '').replace(/@keyframes[^{]*\{(?:[^{}]*\{[^}]*\})*[^{}]*\}/g, '').replace(/@media[^{]*\{(?:[^{}]*\{[^}]*\})*[^{}]*\}/g, '');
38
+ if (/@/.test(text.replace(/"[^"]*"/g, ''))) throw new Error('resolve: an at-rule it doesn\'t know');
39
+ const rules: Rule[] = [];
40
+ for (const m of text.matchAll(/([^{}]+)\{([^{}]*)\}/g)) {
41
+ const decls = m[2].split(';').map(d => d.trim()).filter(Boolean).map(d => {
42
+ const i = d.indexOf(':'), k = d.slice(0, i).trim(), v = d.slice(i + 1).trim();
43
+ return [k, v.replace(/\s*!important$/, ''), /!important$/.test(v)] as [string, string, boolean];
44
+ });
45
+ for (const d of decls) if (!d[0].startsWith('--') && !WRITTEN.has(d[0]) && !LEFT.has(d[0])) throw new Error(`resolve: a property it doesn't know: ${d[0]}`);
46
+ for (const sel of m[1].split(',').map(x => x.trim()).filter(Boolean)) {
47
+ if (sel.includes(':root') || sel.includes('::') || /^(html|body)\b/.test(sel)) continue;
48
+ const toks = sel.replace(/\s*>\s*/g, ' >').split(/\s+/);
49
+ const parts = toks.map(x => readPart(x.replace(/^>/, ''), x.startsWith('>')));
50
+ const spec = parts.reduce((n, p) => n + 10 * (p.classes.length + p.not.length + p.attrs.length) + (p.tag ? 1 : 0), 0);
51
+ rules.push({ parts, spec, order: rules.length, decls });
52
+ }
53
+ }
54
+ return rules;
55
+ }
56
+
57
+ function read(svg: string): El {
58
+ const root: El = { name: '#root', attrs: [], children: [] };
59
+ let top = root;
60
+ for (const m of svg.matchAll(/<\/[a-zA-Z][\w:-]*>|<([a-zA-Z][\w:-]*)((?:\s+[\w:-]+="[^"]*")*)\s*(\/?)>|([^<]+)/g)) {
61
+ if (m[4] !== undefined) { top.children.push(m[4]); continue; }
62
+ if (m[1] === undefined) { top = top.parent!; continue; }
63
+ const el: El = { name: m[1], attrs: [...m[2].matchAll(/([\w:-]+)="([^"]*)"/g)].map(a => [a[1], a[2]]), children: [], parent: top };
64
+ top.children.push(el);
65
+ if (!m[3]) top = el;
66
+ }
67
+ return root.children[0] as El;
68
+ }
69
+ const write = (e: El | string): string => (typeof e === 'string' ? e : `<${e.name}${e.attrs.map(([k, v]) => ` ${k}="${v}"`).join('')}${e.children.length || e.name === 'g' ? `>${e.children.map(write).join('')}</${e.name}>` : '/>'}`);
70
+ const get = (e: El, k: string) => e.attrs.find(a => a[0] === k)?.[1];
71
+ const put = (e: El, k: string, v: string) => { const a = e.attrs.find(x => x[0] === k); if (a) a[1] = v; else e.attrs.push([k, v]); };
72
+ const classesOf = (e: El) => (get(e, 'class') ?? '').split(/\s+/).filter(Boolean);
73
+
74
+ function fits(e: El, p: Part): boolean {
75
+ if (p.tag && p.tag !== e.name) return false;
76
+ const c = classesOf(e);
77
+ return p.classes.every(x => c.includes(x)) && !p.not.some(x => c.includes(x)) && p.attrs.every(([k, v]) => { const g = get(e, k); return g !== undefined && (v === undefined || g === v); });
78
+ }
79
+ function matches(e: El, parts: Part[], i = parts.length - 1): boolean {
80
+ if (!fits(e, parts[i])) return false;
81
+ if (i === 0) return true;
82
+ let up = e.parent;
83
+ if (parts[i].child) return !!up && up.name !== '#root' && matches(up, parts, i - 1);
84
+ for (; up && up.name !== '#root'; up = up.parent) if (matches(up, parts, i - 1)) return true;
85
+ return false;
86
+ }
87
+
88
+ // ---------- colours ----------
89
+
90
+ type Rgba = [number, number, number, number];
91
+ const num = (s: string) => (s.endsWith('%') ? parseFloat(s) / 100 : parseFloat(s));
92
+ function hsl(h: number, s: number, l: number, a: number): Rgba {
93
+ const c = (1 - Math.abs(2 * l - 1)) * s, hp = ((h % 360) + 360) % 360 / 60, x = c * (1 - Math.abs(hp % 2 - 1)), m = l - c / 2;
94
+ const [r, g, b] = hp < 1 ? [c, x, 0] : hp < 2 ? [x, c, 0] : hp < 3 ? [0, c, x] : hp < 4 ? [0, x, c] : hp < 5 ? [x, 0, c] : [c, 0, x];
95
+ return [(r + m) * 255, (g + m) * 255, (b + m) * 255, a];
96
+ }
97
+ /** the parts of a list at its top level */
98
+ function split(s: string, sep: string): string[] {
99
+ const out: string[] = []; let depth = 0, cur = '';
100
+ for (const ch of s) { if (ch === '(') depth++; if (ch === ')') depth--; if (ch === sep && depth === 0) { out.push(cur.trim()); cur = ''; } else cur += ch; }
101
+ return [...out, cur.trim()].filter(Boolean);
102
+ }
103
+ const NAMED: Record<string, Rgba> = { transparent: [0, 0, 0, 0], black: [0, 0, 0, 1], white: [255, 255, 255, 1] };
104
+ function colour(v: string): Rgba | undefined {
105
+ const s = v.trim();
106
+ if (Object.hasOwn(NAMED, s)) return NAMED[s];
107
+ let m = /^#([0-9a-f]{3,8})$/i.exec(s);
108
+ if (m) {
109
+ const x = m[1].length < 6 ? [...m[1]].map(c => c + c).join('') : m[1];
110
+ return [parseInt(x.slice(0, 2), 16), parseInt(x.slice(2, 4), 16), parseInt(x.slice(4, 6), 16), x.length === 8 ? parseInt(x.slice(6), 16) / 255 : 1];
111
+ }
112
+ m = /^hsla?\((.*)\)$/.exec(s);
113
+ if (m) {
114
+ const [c, a] = m[1].split('/').map(x => x.trim()), [h, sat, l, a2] = c.split(/[\s,]+/);
115
+ return hsl(parseFloat(h), num(sat), num(l), a !== undefined ? num(a) : a2 !== undefined ? num(a2) : 1);
116
+ }
117
+ m = /^rgba?\((.*)\)$/.exec(s);
118
+ if (m) { const [r, g, b, a] = m[1].split(/[\s,/]+/).filter(Boolean); return [num(r), num(g), num(b), a === undefined ? 1 : num(a)]; }
119
+ m = /^color-mix\(in srgb\s*,(.*)\)$/.exec(s);
120
+ if (m) {
121
+ const [x, y] = split(m[1], ',').map(p => { const q = /^(.*?)\s+([\d.]+)%$/.exec(p); return q ? { c: colour(q[1]), p: Number(q[2]) / 100 } : { c: colour(p), p: undefined as number | undefined }; });
122
+ if (!x?.c || !y?.c) return undefined;
123
+ const px = x.p ?? (y.p === undefined ? 0.5 : 1 - y.p), py = y.p ?? 1 - px, sum = px + py, a = (x.c[3] * px + y.c[3] * py) / sum;
124
+ const mix = (i: 0 | 1 | 2) => (a === 0 ? 0 : (x.c![i] * x.c![3] * px + y.c![i] * y.c![3] * py) / sum / a);
125
+ return [mix(0), mix(1), mix(2), a * Math.min(1, sum)];
126
+ }
127
+ return undefined;
128
+ }
129
+ const hex = (c: Rgba) => '#' + [c[0], c[1], c[2]].map(v => Math.max(0, Math.min(255, Math.round(v))).toString(16).padStart(2, '0')).join('');
130
+ const short = (v: number) => String(Math.round(v * 10000) / 10000);
131
+
132
+ /** custom properties put in, the nearest first */
133
+ function vars(v: string, env: Map<string, string>, seen = 0): string {
134
+ if (seen > 20) throw new Error(`resolve: a custom property in a loop: ${v}`);
135
+ const i = v.indexOf('var(');
136
+ if (i < 0) return v;
137
+ let depth = 0, j = i + 3;
138
+ do { if (v[j] === '(') depth++; if (v[j] === ')') depth--; j++; } while (depth > 0 && j < v.length);
139
+ const [name, ...fall] = split(v.slice(i + 4, j - 1), ',');
140
+ const val = env.get(name) ?? (fall.length ? fall.join(',') : undefined);
141
+ if (val === undefined) throw new Error(`resolve: no value for ${name}`);
142
+ return vars(v.slice(0, i) + val + v.slice(j), env, seen + 1);
143
+ }
144
+
145
+ const tokens = (decls: string) => new Map(decls.split(';').filter(Boolean).map(d => { const i = d.indexOf(':'); return [d.slice(0, i).trim(), d.slice(i + 1).trim()] as [string, string]; }));
146
+
147
+ export interface ResolveOptions {
148
+ mode: ThemeMode;
149
+ theme: Theme;
150
+ /** the drawing's stylesheets, in order, after the theme's */
151
+ css: string;
152
+ /** the fonts the texts ask for (a stack each) */
153
+ fonts?: { sans: string; mono: string };
154
+ }
155
+ export const FONT_STACKS = { sans: 'system-ui, -apple-system, Segoe UI, Roboto, sans-serif', mono: 'ui-monospace, SFMono-Regular, Menlo, Consolas, monospace' };
156
+
157
+ /** The drawing, self-contained, in one of its theme's modes. What its stylesheets hide is left out of the paint (display
158
+ * none); ids, classes and data- attributes stay. */
159
+ export function resolveSvg(svg: string, o: ResolveOptions): string {
160
+ const t = themeParts(o.theme), fonts = o.fonts ?? FONT_STACKS;
161
+ const rules = readCss(`.mono{font-family:${fonts.mono.replace(/"/g, '')}}\n${t.rest}\n${o.css}`);
162
+ const root = read(svg);
163
+ put(root, 'font-family', fonts.sans.replace(/"/g, ''));
164
+ const walk = (e: El, env0: Map<string, string>) => {
165
+ let env = env0;
166
+ // the winning declaration of each property: !important, then specificity, then order; a style attribute over all but !important
167
+ const won = new Map<string, { v: string; rank: [number, number, number] }>();
168
+ const offer = (k: string, v: string, rank: [number, number, number]) => { const w = won.get(k); if (!w || rank[0] > w.rank[0] || (rank[0] === w.rank[0] && (rank[1] > w.rank[1] || (rank[1] === w.rank[1] && rank[2] >= w.rank[2])))) won.set(k, { v, rank }); };
169
+ for (const r of rules) if (matches(e, r.parts)) for (const [k, v, imp] of r.decls) offer(k, v, [imp ? 1 : 0, r.spec, r.order]);
170
+ const style = get(e, 'style');
171
+ if (style) {
172
+ for (const d of style.split(';').map(x => x.trim()).filter(Boolean)) { const i = d.indexOf(':'); offer(d.slice(0, i).trim(), d.slice(i + 1).trim(), [0, 1e6, 0]); }
173
+ e.attrs = e.attrs.filter(a => a[0] !== 'style');
174
+ }
175
+ for (const [k, w] of won) if (k.startsWith('--')) { if (env === env0) env = new Map(env0); env.set(k, w.v); }
176
+ const alpha: Record<string, number> = {};
177
+ for (const [k, w] of won) {
178
+ if (!WRITTEN.has(k)) continue;
179
+ const v = vars(w.v, env).trim();
180
+ if (k === 'fill' || k === 'stroke' || k === 'stop-color') {
181
+ if (v === 'none' || v === 'currentColor' || v === 'inherit' || v.startsWith('url(')) { put(e, k, v); continue; }
182
+ const c = colour(v);
183
+ if (!c) throw new Error(`resolve: a colour it doesn't know: ${v}`);
184
+ put(e, k, hex(c));
185
+ if (c[3] !== 1) alpha[k === 'stop-color' ? 'stop' : k] = c[3];
186
+ } else put(e, k, k === 'letter-spacing' || k === 'font-size' || k === 'stroke-width' ? v : v.replace(/"/g, ''));
187
+ }
188
+ for (const [k, a] of Object.entries(alpha)) put(e, `${k}-opacity`, short(a * Number(get(e, `${k}-opacity`) ?? 1)));
189
+ if (get(e, 'opacity') === '0') { put(e, 'display', 'none'); e.attrs = e.attrs.filter(a => a[0] !== 'opacity'); }
190
+ // a presentation attribute as the renderer wrote it (a marker's fill) may name a token too
191
+ for (const a of e.attrs) if (/var\(|hsl\(|color-mix/.test(a[1])) { const v = vars(a[1], env), c = colour(v); a[1] = c ? hex(c) : v; }
192
+ for (const c of e.children) if (typeof c !== 'string') walk(c, env);
193
+ };
194
+ walk(root, tokens(o.mode === 'dark' ? `${t.light};${t.dark}` : t.light));
195
+ return write(root);
196
+ }
@@ -25,6 +25,13 @@ export interface RenderedScene {
25
25
  paths: Record<string, string>;
26
26
  /** things drawn worse than asked, e.g. a route label shortened or dropped */
27
27
  warnings: RenderWarning[];
28
+ /** (0.15.0) a self-contained drawing's own colours, for what a state adds to it (a token's rim and fill) */
29
+ inks?: { surface: string; control: string; kinds?: Record<string, string> };
30
+ /** the drawing with every thing that has a look of this name in it, as SVG text (what a switch takes the thing's parts from);
31
+ * none when nothing declares one */
32
+ variants?: Record<string, string>;
33
+ /** the looks each thing declares */
34
+ looks?: Record<string, string[]>;
28
35
  /** the assemble intro's timeline */
29
36
  assembly: Assembly;
30
37
  /** callout pills in screen px, per step, for layout tests */
@@ -34,6 +41,14 @@ export interface RenderWarning { path: string; message: string }
34
41
 
35
42
  interface Item { box: Box; svg: string }
36
43
 
44
+ /** (0.15.0) A thing's parts in a layer, in a wrapper of their own: `<g data-item=ID data-part=…>` (block, wall-1…, gate,
45
+ * name, label, note), a route's `<g data-route=ID data-part=…>` (line, with its arrowhead's marker; label). A wrapper has
46
+ * no transform and no class: a host (and motion.ts) moves and fades wrappers, never what is inside them, whose texts
47
+ * have transforms, and whose classes have opacities, of their own. One wrapper a part and a layer, not one a thing: its
48
+ * block, walls and label are painted in different layers, among other things' (its data-id stays on every part of it;
49
+ * data-item and data-part together are one wrapper's). */
50
+ const wrap = (id: string, part: string, svg: string, what: 'item' | 'route' = 'item') => (svg ? tag('g', { [`data-${what}`]: id, 'data-part': part }, svg) : '');
51
+
37
52
  export interface SceneInput { scene: RawScene; layout: Layout; routes: Routed[]; steps: Steps; theme: Theme; id: string; gridStep?: number }
38
53
 
39
54
  export function renderScene({ scene, layout, routes, steps, theme, id, gridStep = 1 }: SceneInput): RenderedScene {
@@ -53,20 +68,20 @@ export function renderScene({ scene, layout, routes, steps, theme, id, gridStep
53
68
  for (const r of ordered) L.base += drawFlatRegion(k, cat, r, visAttr(r.id), gridStep);
54
69
  for (const r of regions.filter(r => shapeOf(cat, r) === 'walled')) {
55
70
  for (const w of wallsOf(r)) obs.solids.push(silhouette(w));
56
- for (const w of wallsOf(r)) L.blocks.push({ box: w, svg: tag('g', { class: `blk k-${regionRole(cat, r.region!)} wall${r.region!.ghost ? ' ghost' : ''}`, 'data-id': r.id, 'data-dim': '1', ...visAttr(r.id) }, k.blockFaces(w)) });
71
+ for (const [i, w] of wallsOf(r).entries()) L.blocks.push({ box: w, svg: wrap(r.id, `wall-${i + 1}`, tag('g', { class: `blk k-${regionRole(cat, r.region!)} wall${r.region!.ghost ? ' ghost' : ''}`, 'data-id': r.id, 'data-dim': '1', ...visAttr(r.id) }, k.blockFaces(w))) });
57
72
  const g = r.region!.gate;
58
73
  if (g && !g.node) {
59
74
  const b = gateBox(r, g.height ?? (r.region!.height ?? 0.8) + 0.3, 0.3, 0.3);
60
75
  obs.solids.push(silhouette(b));
61
- L.blocks.push({ box: b, svg: tag('g', { class: 'blk k-gate', 'data-id': r.id, ...visAttr(r.id) }, k.blockFaces(b)) });
76
+ L.blocks.push({ box: b, svg: wrap(r.id, 'gate', tag('g', { class: 'blk k-gate', 'data-id': r.id, ...visAttr(r.id) }, k.blockFaces(b))) });
62
77
  }
63
78
  if (r.region!.label && (r.region!['label-style'] ?? 'face') !== 'none') {
64
- L.labels += k.faceText(r.box.x0 + 0.3, r.box.y1, r.box.z0 + 0.13, r.region!.label, 'slabname sm fz', FONTS.sm, 'left', 'start', { 'data-id': r.id, ...visAttr(r.id) });
79
+ L.labels += wrap(r.id, 'name', k.faceText(r.box.x0 + 0.3, r.box.y1, r.box.z0 + 0.13, r.region!.label, 'slabname sm fz', FONTS.sm, 'left', 'start', { 'data-id': r.id, ...visAttr(r.id) }));
65
80
  }
66
81
  }
67
82
 
68
83
  // ---- tunnels: translucent tubes in the air layer ----
69
- for (const r of regions.filter(r => shapeOf(cat, r) === 'tunnel')) L.air += drawTunnel(k, r, visAttr(r.id));
84
+ for (const r of regions.filter(r => shapeOf(cat, r) === 'tunnel')) L.air += wrap(r.id, 'block', drawTunnel(k, r, visAttr(r.id)));
70
85
 
71
86
  // ---- nodes ----
72
87
  const nodes = layout.items.filter(p => p.type === 'node');
@@ -74,7 +89,7 @@ export function renderScene({ scene, layout, routes, steps, theme, id, gridStep
74
89
  const n = p.node!, a = nodeKindOr(cat, n.asset);
75
90
  const ghost = n.ghost || (n.deco ?? []).includes('ghost');
76
91
  const cls = ['blk', `k-${n.role ?? a.role}`, a.cls, ghost ? 'ghost' : ''].filter(Boolean).join(' ');
77
- L.blocks.push({ box: p.box, svg: tag('g', { class: cls, 'data-id': p.id, 'data-dim': '1', ...visAttr(p.id) }, a.draw(k, p.box, n)) });
92
+ L.blocks.push({ box: p.box, svg: wrap(p.id, 'block', tag('g', { class: cls, 'data-id': p.id, 'data-dim': '1', ...visAttr(p.id) }, a.draw(k, p.box, n))) });
78
93
  obs.polys.push({ poly: silhouette(p.box), owner: p.id });
79
94
  obs.solids.push(silhouette(p.box));
80
95
  }
@@ -91,8 +106,8 @@ export function renderScene({ scene, layout, routes, steps, theme, id, gridStep
91
106
  paths[r.id] = d;
92
107
  const arrow = r.raw.arrow !== false;
93
108
  if (arrow) markers.add(r.kind);
94
- L.flows += tag('g', { 'data-hl': r.id, 'data-id': r.id, ...visAttr(r.id) },
95
- tag('path', { d, class: `flow f-${r.kind}`, 'marker-end': arrow ? `url(#ah-${id}-${r.kind})` : undefined }));
109
+ L.flows += wrap(r.id, 'line', tag('g', { 'data-hl': r.id, 'data-id': r.id, ...visAttr(r.id) },
110
+ tag('path', { d, class: `flow f-${r.kind}`, 'marker-end': arrow ? `url(#ah-${id}-${r.kind})` : undefined })), 'route');
96
111
  obs.lines.push({ pts: scr, owner: r.id });
97
112
  }
98
113
  for (const kd of markers) {
@@ -105,13 +120,13 @@ export function renderScene({ scene, layout, routes, steps, theme, id, gridStep
105
120
  // ---- node labels: biggest first, each clear of nodes, routes and the labels before it ----
106
121
  const labelled = nodes.filter(p => p.node!.label || p.node!.sub)
107
122
  .sort((a, b) => (b.box.x1 - b.box.x0) * (b.box.y1 - b.box.y0) - (a.box.x1 - a.box.x0) * (a.box.y1 - a.box.y0));
108
- for (const p of labelled) L.labels += nodeLabel(k, cat, p, obs, visAttr(p.id));
123
+ for (const p of labelled) L.labels += wrap(p.id, 'label', nodeLabel(k, cat, p, obs, visAttr(p.id)));
109
124
 
110
125
  // ---- route labels and notes ----
111
126
  const warnings: RenderWarning[] = [];
112
127
  for (const r of routes) if (r.raw.label && r.points.length >= 2) {
113
128
  const out = routeLabel(k, r, obs, visAttr(r.id), layout);
114
- L.floor += out.svg;
129
+ L.floor += wrap(r.id, 'label', out.svg, 'route');
115
130
  if (out.warning) warnings.push({ path: `${r.path}/label`, message: out.warning });
116
131
  if (obs.budget.over && !obs.budget.told) {
117
132
  obs.budget.told = true;
@@ -119,7 +134,7 @@ export function renderScene({ scene, layout, routes, steps, theme, id, gridStep
119
134
  }
120
135
  }
121
136
  (scene.notes ?? []).forEach((note, i) => {
122
- const s = drawNote(k, note, layout, routes, `${id}-note-${i}`);
137
+ const s = wrap(`${id}-note-${i}`, 'note', drawNote(k, note, layout, routes, `${id}-note-${i}`));
123
138
  if (note.floor) L.floor += s; else L.labels += s;
124
139
  });
125
140
 
@@ -180,6 +195,7 @@ function drawFlatRegion(k: Kernel, cat: KindCatalog, r: Placed, vis: Attrs, grid
180
195
  if (shape === 'cloud') s = tag('g', { class: `blk k-${role} cloud`, ...attrs }, drawCloud(k, b));
181
196
  else if (shape === 'zone') s = tag('g', { class: `zone k-${role}`, ...attrs }, k.poly([[b.x0, b.y0, b.z1], [b.x1, b.y0, b.z1], [b.x1, b.y1, b.z1], [b.x0, b.y1, b.z1]]));
182
197
  else s = tag('g', { class: `blk k-${role}${R.ghost ? ' ghost' : ''}`, ...attrs }, k.blockFaces(b) + gridLines(b, gridStep));
198
+ s = wrap(r.id, 'block', s);
183
199
  const style = R['label-style'] ?? rk?.labelStyle;
184
200
  if (R.label && style !== 'none') {
185
201
  if (style === 'face') {
@@ -187,13 +203,13 @@ function drawFlatRegion(k: Kernel, cat: KindCatalog, r: Placed, vis: Attrs, grid
187
203
  const h = b.z1 - b.z0, cap = (f: { size: number }) => (f.size * 0.73) / S, thin = shape === 'slab' && 0.28 + cap(FONTS.slabname) + 0.08 > h;
188
204
  const big = shape === 'slab' && !thin;
189
205
  const z = big ? b.z0 + 0.28 : thin ? b.z0 + Math.max(0.02, (h - cap(FONTS.sm)) / 2) : b.z0 + Math.min(0.1, h * 0.25);
190
- s += tag('g', attrs, k.faceText(b.x0 + (big ? 0.6 : 0.3), b.y1, z, R.label, big ? 'slabname' : 'slabname sm', big ? FONTS.slabname : FONTS.sm, 'left', 'start'));
206
+ s += wrap(r.id, 'name', tag('g', attrs, k.faceText(b.x0 + (big ? 0.6 : 0.3), b.y1, z, R.label, big ? 'slabname' : 'slabname sm', big ? FONTS.slabname : FONTS.sm, 'left', 'start')));
191
207
  } else if (style === 'face-right') {
192
- s += tag('g', attrs, k.faceText(b.x1, b.y0 + 0.6, b.z0 + Math.max(0.14, (b.z1 - b.z0) * 0.2), R.label, 'slabname', FONTS.slabname, 'right', 'end'));
208
+ s += wrap(r.id, 'name', tag('g', attrs, k.faceText(b.x1, b.y0 + 0.6, b.z0 + Math.max(0.14, (b.z1 - b.z0) * 0.2), R.label, 'slabname', FONTS.slabname, 'right', 'end')));
193
209
  } else {
194
210
  const m = shape === 'cloud' ? 'middle' : 'start';
195
211
  const x = shape === 'cloud' ? (b.x0 + b.x1) / 2 : b.x0 + 0.35, y = shape === 'cloud' ? (b.y0 + b.y1) / 2 : b.y1 - 0.35;
196
- s += tag('g', attrs, k.floorText(x, y, b.z1 + 0.01, R.label, 'slabname sm', 'x', m));
212
+ s += wrap(r.id, 'name', tag('g', attrs, k.floorText(x, y, b.z1 + 0.01, R.label, 'slabname sm', 'x', m)));
197
213
  }
198
214
  }
199
215
  return s;