@johnoscott/isometric-engine 0.12.6 → 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 (71) hide show
  1. package/EDITOR-GUIDE.md +9 -2
  2. package/README.md +1 -1
  3. package/assets/app.css +6 -0
  4. package/assets/marks.css +2 -0
  5. package/iso-editor.js +194 -184
  6. package/iso-render.js +157 -148
  7. package/iso-systems.js +170 -159
  8. package/js/iso-editor/make-way.js +62 -0
  9. package/js/iso-editor/ui/canvas.js +477 -216
  10. package/js/iso-editor/ui/palette-look.js +53 -0
  11. package/js/iso-editor/ui/setup.js +3 -0
  12. package/js/iso-objects/ants.js +36 -0
  13. package/js/iso-objects/index.js +47 -1
  14. package/js/iso-objects/looks.js +25 -0
  15. package/js/iso-objects/motion-builder.js +130 -0
  16. package/js/iso-objects/motion-doc.js +500 -0
  17. package/js/iso-objects/motion-entry.js +32 -0
  18. package/js/iso-objects/motion.js +635 -0
  19. package/js/iso-objects/resolve.js +238 -0
  20. package/js/iso-objects/scene.js +15 -13
  21. package/js/iso-objects/timeline.js +553 -0
  22. package/js/iso-systems/compile.js +59 -1
  23. package/js/iso-systems/index.js +4 -1
  24. package/js/iso-systems/render.js +20 -0
  25. package/js/iso-systems/schema.json +39 -0
  26. package/js/iso-viewer/page.js +2 -1
  27. package/js/iso-viewer/player.js +23 -34
  28. package/package.json +46 -1
  29. package/src/iso-editor/make-way.ts +89 -0
  30. package/src/iso-editor/ui/app.css +4 -0
  31. package/src/iso-editor/ui/canvas.ts +390 -170
  32. package/src/iso-editor/ui/marks.css +2 -0
  33. package/src/iso-editor/ui/palette-look.ts +51 -0
  34. package/src/iso-editor/ui/setup.ts +8 -0
  35. package/src/iso-objects/ants.ts +53 -0
  36. package/src/iso-objects/compile.ts +4 -1
  37. package/src/iso-objects/index.ts +14 -1
  38. package/src/iso-objects/looks.ts +21 -0
  39. package/src/iso-objects/motion-builder.ts +79 -0
  40. package/src/iso-objects/motion-doc.ts +361 -0
  41. package/src/iso-objects/motion-entry.ts +12 -0
  42. package/src/iso-objects/motion.ts +616 -0
  43. package/src/iso-objects/resolve.ts +196 -0
  44. package/src/iso-objects/scene.ts +29 -13
  45. package/src/iso-objects/timeline.ts +443 -0
  46. package/src/iso-objects/types.ts +20 -2
  47. package/src/iso-systems/compile.ts +58 -3
  48. package/src/iso-systems/index.ts +4 -1
  49. package/src/iso-systems/render.ts +41 -0
  50. package/src/iso-systems/schema.json +39 -0
  51. package/src/iso-viewer/page.ts +2 -1
  52. package/src/iso-viewer/player.ts +24 -41
  53. package/types/iso-editor/make-way.d.ts +40 -0
  54. package/types/iso-editor/ui/canvas.d.ts +33 -12
  55. package/types/iso-editor/ui/palette-look.d.ts +5 -0
  56. package/types/iso-editor/ui/setup.d.ts +5 -0
  57. package/types/iso-objects/ants.d.ts +33 -0
  58. package/types/iso-objects/compile.d.ts +3 -0
  59. package/types/iso-objects/index.d.ts +14 -1
  60. package/types/iso-objects/looks.d.ts +4 -0
  61. package/types/iso-objects/motion-builder.d.ts +105 -0
  62. package/types/iso-objects/motion-doc.d.ts +787 -0
  63. package/types/iso-objects/motion-entry.d.ts +10 -0
  64. package/types/iso-objects/motion.d.ts +200 -0
  65. package/types/iso-objects/resolve.d.ts +20 -0
  66. package/types/iso-objects/scene.d.ts +11 -0
  67. package/types/iso-objects/timeline.d.ts +46 -0
  68. package/types/iso-objects/types.d.ts +32 -0
  69. package/types/iso-systems/compile.d.ts +20 -3
  70. package/types/iso-systems/index.d.ts +4 -1
  71. package/types/iso-systems/render.d.ts +21 -0
@@ -0,0 +1,238 @@
1
+ import { themeParts } from "../iso-core/theme.js";
2
+ const WRITTEN = /* @__PURE__ */ new Set([
3
+ "fill",
4
+ "stroke",
5
+ "stroke-width",
6
+ "stroke-dasharray",
7
+ "stroke-linecap",
8
+ "stroke-linejoin",
9
+ "opacity",
10
+ "fill-opacity",
11
+ "stroke-opacity",
12
+ "font-size",
13
+ "font-weight",
14
+ "font-family",
15
+ "letter-spacing",
16
+ "text-anchor",
17
+ "dominant-baseline",
18
+ "paint-order",
19
+ "display",
20
+ "stop-color",
21
+ "stop-opacity"
22
+ ]);
23
+ const LEFT = new Set("cursor pointer-events transition animation transform-box transform-origin user-select".split(" "));
24
+ function readPart(s, child) {
25
+ const p = { classes: [], not: [], attrs: [], child };
26
+ let rest = s;
27
+ const eat = (re) => {
28
+ const m = re.exec(rest);
29
+ if (m) rest = rest.slice(m[0].length);
30
+ return m;
31
+ };
32
+ const t = eat(/^[a-zA-Z][\w-]*/);
33
+ if (t) p.tag = t[0];
34
+ else eat(/^\*/);
35
+ while (rest) {
36
+ let m;
37
+ if (m = eat(/^\.([\w-]+)/)) p.classes.push(m[1]);
38
+ else if (m = eat(/^:not\(\.([\w-]+)\)/)) p.not.push(m[1]);
39
+ else if (m = eat(/^\[([\w-]+)(?:="([^"]*)")?\]/)) p.attrs.push([m[1], m[2]]);
40
+ else throw new Error(`resolve: a selector it doesn't know: ${s}`);
41
+ }
42
+ return p;
43
+ }
44
+ function readCss(css) {
45
+ const text = css.replace(/\/\*[\s\S]*?\*\//g, "").replace(/@keyframes[^{]*\{(?:[^{}]*\{[^}]*\})*[^{}]*\}/g, "").replace(/@media[^{]*\{(?:[^{}]*\{[^}]*\})*[^{}]*\}/g, "");
46
+ if (/@/.test(text.replace(/"[^"]*"/g, ""))) throw new Error("resolve: an at-rule it doesn't know");
47
+ const rules = [];
48
+ for (const m of text.matchAll(/([^{}]+)\{([^{}]*)\}/g)) {
49
+ const decls = m[2].split(";").map((d) => d.trim()).filter(Boolean).map((d) => {
50
+ const i = d.indexOf(":"), k = d.slice(0, i).trim(), v = d.slice(i + 1).trim();
51
+ return [k, v.replace(/\s*!important$/, ""), /!important$/.test(v)];
52
+ });
53
+ 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]}`);
54
+ for (const sel of m[1].split(",").map((x) => x.trim()).filter(Boolean)) {
55
+ if (sel.includes(":root") || sel.includes("::") || /^(html|body)\b/.test(sel)) continue;
56
+ const toks = sel.replace(/\s*>\s*/g, " >").split(/\s+/);
57
+ const parts = toks.map((x) => readPart(x.replace(/^>/, ""), x.startsWith(">")));
58
+ const spec = parts.reduce((n, p) => n + 10 * (p.classes.length + p.not.length + p.attrs.length) + (p.tag ? 1 : 0), 0);
59
+ rules.push({ parts, spec, order: rules.length, decls });
60
+ }
61
+ }
62
+ return rules;
63
+ }
64
+ function read(svg) {
65
+ const root = { name: "#root", attrs: [], children: [] };
66
+ let top = root;
67
+ for (const m of svg.matchAll(/<\/[a-zA-Z][\w:-]*>|<([a-zA-Z][\w:-]*)((?:\s+[\w:-]+="[^"]*")*)\s*(\/?)>|([^<]+)/g)) {
68
+ if (m[4] !== void 0) {
69
+ top.children.push(m[4]);
70
+ continue;
71
+ }
72
+ if (m[1] === void 0) {
73
+ top = top.parent;
74
+ continue;
75
+ }
76
+ const el = { name: m[1], attrs: [...m[2].matchAll(/([\w:-]+)="([^"]*)"/g)].map((a) => [a[1], a[2]]), children: [], parent: top };
77
+ top.children.push(el);
78
+ if (!m[3]) top = el;
79
+ }
80
+ return root.children[0];
81
+ }
82
+ const write = (e) => 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}>` : "/>"}`;
83
+ const get = (e, k) => e.attrs.find((a) => a[0] === k)?.[1];
84
+ const put = (e, k, v) => {
85
+ const a = e.attrs.find((x) => x[0] === k);
86
+ if (a) a[1] = v;
87
+ else e.attrs.push([k, v]);
88
+ };
89
+ const classesOf = (e) => (get(e, "class") ?? "").split(/\s+/).filter(Boolean);
90
+ function fits(e, p) {
91
+ if (p.tag && p.tag !== e.name) return false;
92
+ const c = classesOf(e);
93
+ return p.classes.every((x) => c.includes(x)) && !p.not.some((x) => c.includes(x)) && p.attrs.every(([k, v]) => {
94
+ const g = get(e, k);
95
+ return g !== void 0 && (v === void 0 || g === v);
96
+ });
97
+ }
98
+ function matches(e, parts, i = parts.length - 1) {
99
+ if (!fits(e, parts[i])) return false;
100
+ if (i === 0) return true;
101
+ let up = e.parent;
102
+ if (parts[i].child) return !!up && up.name !== "#root" && matches(up, parts, i - 1);
103
+ for (; up && up.name !== "#root"; up = up.parent) if (matches(up, parts, i - 1)) return true;
104
+ return false;
105
+ }
106
+ const num = (s) => s.endsWith("%") ? parseFloat(s) / 100 : parseFloat(s);
107
+ function hsl(h, s, l, a) {
108
+ 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;
109
+ 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];
110
+ return [(r + m) * 255, (g + m) * 255, (b + m) * 255, a];
111
+ }
112
+ function split(s, sep) {
113
+ const out = [];
114
+ let depth = 0, cur = "";
115
+ for (const ch of s) {
116
+ if (ch === "(") depth++;
117
+ if (ch === ")") depth--;
118
+ if (ch === sep && depth === 0) {
119
+ out.push(cur.trim());
120
+ cur = "";
121
+ } else cur += ch;
122
+ }
123
+ return [...out, cur.trim()].filter(Boolean);
124
+ }
125
+ const NAMED = { transparent: [0, 0, 0, 0], black: [0, 0, 0, 1], white: [255, 255, 255, 1] };
126
+ function colour(v) {
127
+ const s = v.trim();
128
+ if (Object.hasOwn(NAMED, s)) return NAMED[s];
129
+ let m = /^#([0-9a-f]{3,8})$/i.exec(s);
130
+ if (m) {
131
+ const x = m[1].length < 6 ? [...m[1]].map((c) => c + c).join("") : m[1];
132
+ 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];
133
+ }
134
+ m = /^hsla?\((.*)\)$/.exec(s);
135
+ if (m) {
136
+ const [c, a] = m[1].split("/").map((x) => x.trim()), [h, sat, l, a2] = c.split(/[\s,]+/);
137
+ return hsl(parseFloat(h), num(sat), num(l), a !== void 0 ? num(a) : a2 !== void 0 ? num(a2) : 1);
138
+ }
139
+ m = /^rgba?\((.*)\)$/.exec(s);
140
+ if (m) {
141
+ const [r, g, b, a] = m[1].split(/[\s,/]+/).filter(Boolean);
142
+ return [num(r), num(g), num(b), a === void 0 ? 1 : num(a)];
143
+ }
144
+ m = /^color-mix\(in srgb\s*,(.*)\)$/.exec(s);
145
+ if (m) {
146
+ const [x, y] = split(m[1], ",").map((p) => {
147
+ const q = /^(.*?)\s+([\d.]+)%$/.exec(p);
148
+ return q ? { c: colour(q[1]), p: Number(q[2]) / 100 } : { c: colour(p), p: void 0 };
149
+ });
150
+ if (!x?.c || !y?.c) return void 0;
151
+ const px = x.p ?? (y.p === void 0 ? 0.5 : 1 - y.p), py = y.p ?? 1 - px, sum = px + py, a = (x.c[3] * px + y.c[3] * py) / sum;
152
+ const mix = (i) => a === 0 ? 0 : (x.c[i] * x.c[3] * px + y.c[i] * y.c[3] * py) / sum / a;
153
+ return [mix(0), mix(1), mix(2), a * Math.min(1, sum)];
154
+ }
155
+ return void 0;
156
+ }
157
+ const hex = (c) => "#" + [c[0], c[1], c[2]].map((v) => Math.max(0, Math.min(255, Math.round(v))).toString(16).padStart(2, "0")).join("");
158
+ const short = (v) => String(Math.round(v * 1e4) / 1e4);
159
+ function vars(v, env, seen = 0) {
160
+ if (seen > 20) throw new Error(`resolve: a custom property in a loop: ${v}`);
161
+ const i = v.indexOf("var(");
162
+ if (i < 0) return v;
163
+ let depth = 0, j = i + 3;
164
+ do {
165
+ if (v[j] === "(") depth++;
166
+ if (v[j] === ")") depth--;
167
+ j++;
168
+ } while (depth > 0 && j < v.length);
169
+ const [name, ...fall] = split(v.slice(i + 4, j - 1), ",");
170
+ const val = env.get(name) ?? (fall.length ? fall.join(",") : void 0);
171
+ if (val === void 0) throw new Error(`resolve: no value for ${name}`);
172
+ return vars(v.slice(0, i) + val + v.slice(j), env, seen + 1);
173
+ }
174
+ const tokens = (decls) => new Map(decls.split(";").filter(Boolean).map((d) => {
175
+ const i = d.indexOf(":");
176
+ return [d.slice(0, i).trim(), d.slice(i + 1).trim()];
177
+ }));
178
+ const FONT_STACKS = { sans: "system-ui, -apple-system, Segoe UI, Roboto, sans-serif", mono: "ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" };
179
+ function resolveSvg(svg, o) {
180
+ const t = themeParts(o.theme), fonts = o.fonts ?? FONT_STACKS;
181
+ const rules = readCss(`.mono{font-family:${fonts.mono.replace(/"/g, "")}}
182
+ ${t.rest}
183
+ ${o.css}`);
184
+ const root = read(svg);
185
+ put(root, "font-family", fonts.sans.replace(/"/g, ""));
186
+ const walk = (e, env0) => {
187
+ let env = env0;
188
+ const won = /* @__PURE__ */ new Map();
189
+ const offer = (k, v, rank) => {
190
+ const w = won.get(k);
191
+ 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 });
192
+ };
193
+ 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]);
194
+ const style = get(e, "style");
195
+ if (style) {
196
+ for (const d of style.split(";").map((x) => x.trim()).filter(Boolean)) {
197
+ const i = d.indexOf(":");
198
+ offer(d.slice(0, i).trim(), d.slice(i + 1).trim(), [0, 1e6, 0]);
199
+ }
200
+ e.attrs = e.attrs.filter((a) => a[0] !== "style");
201
+ }
202
+ for (const [k, w] of won) if (k.startsWith("--")) {
203
+ if (env === env0) env = new Map(env0);
204
+ env.set(k, w.v);
205
+ }
206
+ const alpha = {};
207
+ for (const [k, w] of won) {
208
+ if (!WRITTEN.has(k)) continue;
209
+ const v = vars(w.v, env).trim();
210
+ if (k === "fill" || k === "stroke" || k === "stop-color") {
211
+ if (v === "none" || v === "currentColor" || v === "inherit" || v.startsWith("url(")) {
212
+ put(e, k, v);
213
+ continue;
214
+ }
215
+ const c = colour(v);
216
+ if (!c) throw new Error(`resolve: a colour it doesn't know: ${v}`);
217
+ put(e, k, hex(c));
218
+ if (c[3] !== 1) alpha[k === "stop-color" ? "stop" : k] = c[3];
219
+ } else put(e, k, k === "letter-spacing" || k === "font-size" || k === "stroke-width" ? v : v.replace(/"/g, ""));
220
+ }
221
+ for (const [k, a] of Object.entries(alpha)) put(e, `${k}-opacity`, short(a * Number(get(e, `${k}-opacity`) ?? 1)));
222
+ if (get(e, "opacity") === "0") {
223
+ put(e, "display", "none");
224
+ e.attrs = e.attrs.filter((a) => a[0] !== "opacity");
225
+ }
226
+ for (const a of e.attrs) if (/var\(|hsl\(|color-mix/.test(a[1])) {
227
+ const v = vars(a[1], env), c = colour(v);
228
+ a[1] = c ? hex(c) : v;
229
+ }
230
+ for (const c of e.children) if (typeof c !== "string") walk(c, env);
231
+ };
232
+ walk(root, tokens(o.mode === "dark" ? `${t.light};${t.dark}` : t.light));
233
+ return write(root);
234
+ }
235
+ export {
236
+ FONT_STACKS,
237
+ resolveSvg
238
+ };
@@ -9,6 +9,7 @@ import { assembly } from "./assemble.js";
9
9
  import { colorRef } from "../iso-core/theme.js";
10
10
  const regionRole = (cat, r) => r.role ?? regionKind(cat, r.kind)?.role;
11
11
  const shapeOf = (cat, r) => regionKind(cat, r.region.kind)?.shape;
12
+ const wrap = (id, part, svg, what = "item") => svg ? tag("g", { [`data-${what}`]: id, "data-part": part }, svg) : "";
12
13
  function renderScene({ scene, layout, routes, steps, theme, id, gridStep = 1 }) {
13
14
  const k = new Kernel();
14
15
  const L = { base: "", floor: "", flows: "", blocks: [], air: "", labels: "", marks: "", badges: "" };
@@ -27,24 +28,24 @@ function renderScene({ scene, layout, routes, steps, theme, id, gridStep = 1 })
27
28
  for (const r of ordered) L.base += drawFlatRegion(k, cat, r, visAttr(r.id), gridStep);
28
29
  for (const r of regions.filter((r2) => shapeOf(cat, r2) === "walled")) {
29
30
  for (const w of wallsOf(r)) obs.solids.push(silhouette(w));
30
- 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)) });
31
+ 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))) });
31
32
  const g2 = r.region.gate;
32
33
  if (g2 && !g2.node) {
33
34
  const b = gateBox(r, g2.height ?? (r.region.height ?? 0.8) + 0.3, 0.3, 0.3);
34
35
  obs.solids.push(silhouette(b));
35
- L.blocks.push({ box: b, svg: tag("g", { class: "blk k-gate", "data-id": r.id, ...visAttr(r.id) }, k.blockFaces(b)) });
36
+ 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))) });
36
37
  }
37
38
  if (r.region.label && (r.region["label-style"] ?? "face") !== "none") {
38
- 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) });
39
+ 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) }));
39
40
  }
40
41
  }
41
- for (const r of regions.filter((r2) => shapeOf(cat, r2) === "tunnel")) L.air += drawTunnel(k, r, visAttr(r.id));
42
+ for (const r of regions.filter((r2) => shapeOf(cat, r2) === "tunnel")) L.air += wrap(r.id, "block", drawTunnel(k, r, visAttr(r.id)));
42
43
  const nodes = layout.items.filter((p) => p.type === "node");
43
44
  for (const p of nodes) {
44
45
  const n = p.node, a = nodeKindOr(cat, n.asset);
45
46
  const ghost = n.ghost || (n.deco ?? []).includes("ghost");
46
47
  const cls = ["blk", `k-${n.role ?? a.role}`, a.cls, ghost ? "ghost" : ""].filter(Boolean).join(" ");
47
- 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)) });
48
+ 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))) });
48
49
  obs.polys.push({ poly: silhouette(p.box), owner: p.id });
49
50
  obs.solids.push(silhouette(p.box));
50
51
  }
@@ -59,11 +60,11 @@ function renderScene({ scene, layout, routes, steps, theme, id, gridStep = 1 })
59
60
  paths[r.id] = d;
60
61
  const arrow = r.raw.arrow !== false;
61
62
  if (arrow) markers.add(r.kind);
62
- L.flows += tag(
63
+ L.flows += wrap(r.id, "line", tag(
63
64
  "g",
64
65
  { "data-hl": r.id, "data-id": r.id, ...visAttr(r.id) },
65
66
  tag("path", { d, class: `flow f-${r.kind}`, "marker-end": arrow ? `url(#ah-${id}-${r.kind})` : void 0 })
66
- );
67
+ ), "route");
67
68
  obs.lines.push({ pts: scr, owner: r.id });
68
69
  }
69
70
  for (const kd of markers) {
@@ -75,11 +76,11 @@ function renderScene({ scene, layout, routes, steps, theme, id, gridStep = 1 })
75
76
  }
76
77
  for (const q of k.planePolys) obs.slants.push(q);
77
78
  const labelled = nodes.filter((p) => p.node.label || p.node.sub).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));
78
- for (const p of labelled) L.labels += nodeLabel(k, cat, p, obs, visAttr(p.id));
79
+ for (const p of labelled) L.labels += wrap(p.id, "label", nodeLabel(k, cat, p, obs, visAttr(p.id)));
79
80
  const warnings = [];
80
81
  for (const r of routes) if (r.raw.label && r.points.length >= 2) {
81
82
  const out = routeLabel(k, r, obs, visAttr(r.id), layout);
82
- L.floor += out.svg;
83
+ L.floor += wrap(r.id, "label", out.svg, "route");
83
84
  if (out.warning) warnings.push({ path: `${r.path}/label`, message: out.warning });
84
85
  if (obs.budget.over && !obs.budget.told) {
85
86
  obs.budget.told = true;
@@ -87,7 +88,7 @@ function renderScene({ scene, layout, routes, steps, theme, id, gridStep = 1 })
87
88
  }
88
89
  }
89
90
  (scene.notes ?? []).forEach((note, i) => {
90
- const s = drawNote(k, note, layout, routes, `${id}-note-${i}`);
91
+ const s = wrap(`${id}-note-${i}`, "note", drawNote(k, note, layout, routes, `${id}-note-${i}`));
91
92
  if (note.floor) L.floor += s;
92
93
  else L.labels += s;
93
94
  });
@@ -157,19 +158,20 @@ function drawFlatRegion(k, cat, r, vis, gridStep = 1) {
157
158
  if (shape === "cloud") s = tag("g", { class: `blk k-${role} cloud`, ...attrs }, drawCloud(k, b));
158
159
  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]]));
159
160
  else s = tag("g", { class: `blk k-${role}${R.ghost ? " ghost" : ""}`, ...attrs }, k.blockFaces(b) + gridLines(b, gridStep));
161
+ s = wrap(r.id, "block", s);
160
162
  const style = R["label-style"] ?? rk?.labelStyle;
161
163
  if (R.label && style !== "none") {
162
164
  if (style === "face") {
163
165
  const h = b.z1 - b.z0, cap = (f) => f.size * 0.73 / S, thin = shape === "slab" && 0.28 + cap(FONTS.slabname) + 0.08 > h;
164
166
  const big = shape === "slab" && !thin;
165
167
  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);
166
- 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"));
168
+ 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")));
167
169
  } else if (style === "face-right") {
168
- 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"));
170
+ 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")));
169
171
  } else {
170
172
  const m = shape === "cloud" ? "middle" : "start";
171
173
  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;
172
- s += tag("g", attrs, k.floorText(x, y, b.z1 + 0.01, R.label, "slabname sm", "x", m));
174
+ s += wrap(r.id, "name", tag("g", attrs, k.floorText(x, y, b.z1 + 0.01, R.label, "slabname sm", "x", m)));
173
175
  }
174
176
  }
175
177
  return s;