@johnoscott/isometric-engine 0.0.0-stage → 0.9.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/EDITOR-GUIDE.md +317 -0
- package/LICENSE +21 -0
- package/LICENSES/ajv.txt +22 -0
- package/LICENSES/lucide-static.txt +43 -0
- package/LICENSES/yaml.txt +13 -0
- package/README.md +62 -2
- package/assets/app.css +265 -0
- package/assets/default-theme.yaml +99 -0
- package/assets/icons.svg +1 -0
- package/assets/marks.css +35 -0
- package/assets/skin.css +181 -0
- package/iso-editor.d.ts +4 -0
- package/iso-editor.js +550 -0
- package/iso-render.d.ts +3 -0
- package/iso-render.js +388 -0
- package/iso-systems.d.ts +4 -0
- package/iso-systems.js +389 -0
- package/js/iso-core/compile-schema.js +22 -0
- package/js/iso-core/depth.js +55 -0
- package/js/iso-core/errors.js +65 -0
- package/js/iso-core/glyphs.js +100 -0
- package/js/iso-core/index.js +55 -0
- package/js/iso-core/kernel.js +158 -0
- package/js/iso-core/metrics.json +1 -0
- package/js/iso-core/package.json +6 -0
- package/js/iso-core/parse.js +79 -0
- package/js/iso-core/schema-errors.js +170 -0
- package/js/iso-core/shims/crypto.js +125 -0
- package/js/iso-core/shims/path.js +49 -0
- package/js/iso-core/svg-dom.js +144 -0
- package/js/iso-core/theme.js +48 -0
- package/js/iso-core/vdom.js +48 -0
- package/js/iso-editor/adapter.js +0 -0
- package/js/iso-editor/clipboard.js +152 -0
- package/js/iso-editor/commands.js +173 -0
- package/js/iso-editor/complete.js +55 -0
- package/js/iso-editor/doc.js +182 -0
- package/js/iso-editor/index.js +105 -0
- package/js/iso-editor/model.js +210 -0
- package/js/iso-editor/outline.js +111 -0
- package/js/iso-editor/package.json +6 -0
- package/js/iso-editor/path.js +19 -0
- package/js/iso-editor/providers.js +96 -0
- package/js/iso-editor/schema-nav.js +117 -0
- package/js/iso-editor/splice.js +441 -0
- package/js/iso-editor/storage-keys.js +6 -0
- package/js/iso-editor/ui/actions.js +116 -0
- package/js/iso-editor/ui/canvas-layer.js +0 -0
- package/js/iso-editor/ui/canvas.js +1205 -0
- package/js/iso-editor/ui/clip.js +133 -0
- package/js/iso-editor/ui/dialog.js +26 -0
- package/js/iso-editor/ui/flat-canvas.js +54 -0
- package/js/iso-editor/ui/icons.js +15 -0
- package/js/iso-editor/ui/keys.js +26 -0
- package/js/iso-editor/ui/later.js +28 -0
- package/js/iso-editor/ui/layer.js +11 -0
- package/js/iso-editor/ui/menu.js +105 -0
- package/js/iso-editor/ui/monaco-entry.js +2 -0
- package/js/iso-editor/ui/mount-kit.js +0 -0
- package/js/iso-editor/ui/mount.js +767 -0
- package/js/iso-editor/ui/pane.js +0 -0
- package/js/iso-editor/ui/part.js +0 -0
- package/js/iso-editor/ui/plain-icons.js +34 -0
- package/js/iso-editor/ui/props.js +314 -0
- package/js/iso-editor/ui/scope-css.js +81 -0
- package/js/iso-editor/ui/setup.js +145 -0
- package/js/iso-editor/ui/text.js +323 -0
- package/js/iso-editor/ui/tree.js +728 -0
- package/js/iso-editor/validate.js +33 -0
- package/js/iso-editor/window/protocol.js +8 -0
- package/js/iso-objects/assemble.js +43 -0
- package/js/iso-objects/assets.js +88 -0
- package/js/iso-objects/board.js +162 -0
- package/js/iso-objects/compile.js +60 -0
- package/js/iso-objects/css.js +154 -0
- package/js/iso-objects/flat.js +696 -0
- package/js/iso-objects/focus.js +16 -0
- package/js/iso-objects/geometry.js +76 -0
- package/js/iso-objects/index.js +93 -0
- package/js/iso-objects/kinds.js +12 -0
- package/js/iso-objects/labels.js +325 -0
- package/js/iso-objects/package.json +6 -0
- package/js/iso-objects/place.js +347 -0
- package/js/iso-objects/route.js +461 -0
- package/js/iso-objects/scene.js +350 -0
- package/js/iso-objects/steps.js +246 -0
- package/js/iso-objects/types.js +0 -0
- package/js/iso-systems/catalog.js +42 -0
- package/js/iso-systems/compile.js +34 -0
- package/js/iso-systems/css.js +8 -0
- package/js/iso-systems/index.js +16 -0
- package/js/iso-systems/nodes.js +124 -0
- package/js/iso-systems/package.json +6 -0
- package/js/iso-systems/schema.json +311 -0
- package/js/iso-systems/validate.js +35 -0
- package/js/iso-viewer/bundle.js +20 -0
- package/js/iso-viewer/card-motion.js +228 -0
- package/js/iso-viewer/dom.js +14 -0
- package/js/iso-viewer/dual-view.js +212 -0
- package/js/iso-viewer/flat-view.js +124 -0
- package/js/iso-viewer/history.js +990 -0
- package/js/iso-viewer/index.js +98 -0
- package/js/iso-viewer/morph.js +192 -0
- package/js/iso-viewer/overlay.js +199 -0
- package/js/iso-viewer/package.json +6 -0
- package/js/iso-viewer/page.js +138 -0
- package/js/iso-viewer/player.js +409 -0
- package/js/iso-viewer/still.js +81 -0
- package/js/iso-viewer/timeline-contract.js +14 -0
- package/js/iso-viewer/timeline-engine.js +475 -0
- package/js/iso-viewer/timeline-export.js +36 -0
- package/js/iso-viewer/timeline-scale.js +116 -0
- package/js/iso-viewer/timeline-scope.js +58 -0
- package/js/iso-viewer/timeline-search.js +216 -0
- package/js/iso-viewer/timeline-time.js +55 -0
- package/js/iso-viewer/view-css.js +68 -0
- package/js/iso-viewer/viewport.js +177 -0
- package/package.json +502 -4
- package/src/iso-core/compile-schema.ts +23 -0
- package/src/iso-core/depth.ts +56 -0
- package/src/iso-core/errors.ts +73 -0
- package/src/iso-core/glyphs.ts +108 -0
- package/src/iso-core/index.ts +27 -0
- package/src/iso-core/kernel.ts +163 -0
- package/src/iso-core/metrics.json +1 -0
- package/src/iso-core/package.json +6 -0
- package/src/iso-core/parse.ts +91 -0
- package/src/iso-core/schema-errors.ts +163 -0
- package/src/iso-core/shims/crypto.ts +37 -0
- package/src/iso-core/shims/path.ts +24 -0
- package/src/iso-core/svg-dom.ts +103 -0
- package/src/iso-core/theme.ts +64 -0
- package/src/iso-core/vdom.ts +41 -0
- package/src/iso-editor/adapter.ts +128 -0
- package/src/iso-editor/clipboard.ts +163 -0
- package/src/iso-editor/commands.ts +191 -0
- package/src/iso-editor/complete.ts +73 -0
- package/src/iso-editor/doc.ts +207 -0
- package/src/iso-editor/index.ts +67 -0
- package/src/iso-editor/model.ts +234 -0
- package/src/iso-editor/outline.ts +126 -0
- package/src/iso-editor/package.json +6 -0
- package/src/iso-editor/path.ts +18 -0
- package/src/iso-editor/providers.ts +113 -0
- package/src/iso-editor/schema-nav.ts +129 -0
- package/src/iso-editor/splice.ts +472 -0
- package/src/iso-editor/storage-keys.ts +6 -0
- package/src/iso-editor/ui/actions.ts +119 -0
- package/src/iso-editor/ui/app.css +230 -0
- package/src/iso-editor/ui/canvas-layer.ts +56 -0
- package/src/iso-editor/ui/canvas.ts +1071 -0
- package/src/iso-editor/ui/clip.ts +97 -0
- package/src/iso-editor/ui/dialog.ts +25 -0
- package/src/iso-editor/ui/flat-canvas.ts +51 -0
- package/src/iso-editor/ui/icons.ts +21 -0
- package/src/iso-editor/ui/keys.ts +30 -0
- package/src/iso-editor/ui/later.ts +22 -0
- package/src/iso-editor/ui/layer.ts +7 -0
- package/src/iso-editor/ui/marks.css +35 -0
- package/src/iso-editor/ui/menu.ts +67 -0
- package/src/iso-editor/ui/monaco-entry.ts +6 -0
- package/src/iso-editor/ui/mount-kit.ts +35 -0
- package/src/iso-editor/ui/mount.ts +684 -0
- package/src/iso-editor/ui/pane.ts +45 -0
- package/src/iso-editor/ui/part.ts +45 -0
- package/src/iso-editor/ui/plain-icons.ts +83 -0
- package/src/iso-editor/ui/props.ts +347 -0
- package/src/iso-editor/ui/scope-css.ts +65 -0
- package/src/iso-editor/ui/setup.ts +144 -0
- package/src/iso-editor/ui/skin.css +181 -0
- package/src/iso-editor/ui/text.ts +262 -0
- package/src/iso-editor/ui/tree.ts +657 -0
- package/src/iso-editor/validate.ts +62 -0
- package/src/iso-editor/window/protocol.ts +33 -0
- package/src/iso-objects/assemble.ts +57 -0
- package/src/iso-objects/assets.ts +122 -0
- package/src/iso-objects/board.ts +169 -0
- package/src/iso-objects/compile.ts +76 -0
- package/src/iso-objects/css.ts +163 -0
- package/src/iso-objects/flat.ts +653 -0
- package/src/iso-objects/focus.ts +14 -0
- package/src/iso-objects/geometry.ts +86 -0
- package/src/iso-objects/index.ts +33 -0
- package/src/iso-objects/kinds.ts +56 -0
- package/src/iso-objects/labels.ts +310 -0
- package/src/iso-objects/package.json +6 -0
- package/src/iso-objects/place.ts +318 -0
- package/src/iso-objects/route.ts +444 -0
- package/src/iso-objects/scene.ts +376 -0
- package/src/iso-objects/steps.ts +234 -0
- package/src/iso-objects/types.ts +68 -0
- package/src/iso-systems/catalog.ts +31 -0
- package/src/iso-systems/compile.ts +39 -0
- package/src/iso-systems/css.ts +9 -0
- package/src/iso-systems/index.ts +12 -0
- package/src/iso-systems/nodes.ts +126 -0
- package/src/iso-systems/package.json +6 -0
- package/src/iso-systems/schema.json +311 -0
- package/src/iso-systems/validate.ts +34 -0
- package/src/iso-viewer/bundle.ts +15 -0
- package/src/iso-viewer/card-motion.ts +237 -0
- package/src/iso-viewer/dom.ts +13 -0
- package/src/iso-viewer/dual-view.ts +212 -0
- package/src/iso-viewer/flat-view.ts +127 -0
- package/src/iso-viewer/history.ts +781 -0
- package/src/iso-viewer/index.ts +40 -0
- package/src/iso-viewer/morph.ts +191 -0
- package/src/iso-viewer/overlay.ts +212 -0
- package/src/iso-viewer/package.json +6 -0
- package/src/iso-viewer/page.ts +150 -0
- package/src/iso-viewer/player.ts +321 -0
- package/src/iso-viewer/still.ts +74 -0
- package/src/iso-viewer/timeline-contract.ts +342 -0
- package/src/iso-viewer/timeline-engine.ts +420 -0
- package/src/iso-viewer/timeline-export.ts +31 -0
- package/src/iso-viewer/timeline-scale.ts +129 -0
- package/src/iso-viewer/timeline-scope.ts +56 -0
- package/src/iso-viewer/timeline-search.ts +198 -0
- package/src/iso-viewer/timeline-time.ts +54 -0
- package/src/iso-viewer/view-css.ts +59 -0
- package/src/iso-viewer/viewport.ts +142 -0
- package/types/iso-core/compile-schema.d.ts +11 -0
- package/types/iso-core/depth.d.ts +6 -0
- package/types/iso-core/errors.d.ts +24 -0
- package/types/iso-core/glyphs.d.ts +19 -0
- package/types/iso-core/index.d.ts +17 -0
- package/types/iso-core/kernel.d.ts +130 -0
- package/types/iso-core/metrics.json +1 -0
- package/types/iso-core/parse.d.ts +18 -0
- package/types/iso-core/schema-errors.d.ts +14 -0
- package/types/iso-core/shims/crypto.d.ts +9 -0
- package/types/iso-core/svg-dom.d.ts +15 -0
- package/types/iso-core/theme.d.ts +38 -0
- package/types/iso-core/vdom.d.ts +26 -0
- package/types/iso-editor/adapter.d.ts +145 -0
- package/types/iso-editor/clipboard.d.ts +23 -0
- package/types/iso-editor/commands.d.ts +32 -0
- package/types/iso-editor/complete.d.ts +25 -0
- package/types/iso-editor/doc.d.ts +50 -0
- package/types/iso-editor/index.d.ts +57 -0
- package/types/iso-editor/model.d.ts +96 -0
- package/types/iso-editor/outline.d.ts +28 -0
- package/types/iso-editor/path.d.ts +7 -0
- package/types/iso-editor/providers.d.ts +43 -0
- package/types/iso-editor/schema-nav.d.ts +34 -0
- package/types/iso-editor/splice.d.ts +53 -0
- package/types/iso-editor/storage-keys.d.ts +5 -0
- package/types/iso-editor/ui/actions.d.ts +23 -0
- package/types/iso-editor/ui/canvas-layer.d.ts +65 -0
- package/types/iso-editor/ui/canvas.d.ts +279 -0
- package/types/iso-editor/ui/clip.d.ts +14 -0
- package/types/iso-editor/ui/dialog.d.ts +7 -0
- package/types/iso-editor/ui/flat-canvas.d.ts +2 -0
- package/types/iso-editor/ui/icons.d.ts +5 -0
- package/types/iso-editor/ui/keys.d.ts +7 -0
- package/types/iso-editor/ui/later.d.ts +12 -0
- package/types/iso-editor/ui/layer.d.ts +2 -0
- package/types/iso-editor/ui/menu.d.ts +21 -0
- package/types/iso-editor/ui/mount-kit.d.ts +31 -0
- package/types/iso-editor/ui/mount.d.ts +146 -0
- package/types/iso-editor/ui/pane.d.ts +60 -0
- package/types/iso-editor/ui/part.d.ts +40 -0
- package/types/iso-editor/ui/plain-icons.d.ts +10 -0
- package/types/iso-editor/ui/props.d.ts +57 -0
- package/types/iso-editor/ui/scope-css.d.ts +5 -0
- package/types/iso-editor/ui/setup.d.ts +40 -0
- package/types/iso-editor/ui/text.d.ts +19 -0
- package/types/iso-editor/ui/tree.d.ts +100 -0
- package/types/iso-editor/validate.d.ts +36 -0
- package/types/iso-editor/window/protocol.d.ts +60 -0
- package/types/iso-objects/assemble.d.ts +35 -0
- package/types/iso-objects/assets.d.ts +49 -0
- package/types/iso-objects/board.d.ts +36 -0
- package/types/iso-objects/compile.d.ts +35 -0
- package/types/iso-objects/css.d.ts +16 -0
- package/types/iso-objects/flat.d.ts +130 -0
- package/types/iso-objects/focus.d.ts +1 -0
- package/types/iso-objects/geometry.d.ts +59 -0
- package/types/iso-objects/index.d.ts +26 -0
- package/types/iso-objects/kinds.d.ts +53 -0
- package/types/iso-objects/labels.d.ts +92 -0
- package/types/iso-objects/place.d.ts +25 -0
- package/types/iso-objects/route.d.ts +67 -0
- package/types/iso-objects/scene.d.ts +63 -0
- package/types/iso-objects/steps.d.ts +90 -0
- package/types/iso-objects/types.d.ts +140 -0
- package/types/iso-systems/catalog.d.ts +4 -0
- package/types/iso-systems/compile.d.ts +6 -0
- package/types/iso-systems/css.d.ts +3 -0
- package/types/iso-systems/index.d.ts +5 -0
- package/types/iso-systems/nodes.d.ts +3 -0
- package/types/iso-viewer/card-motion.d.ts +56 -0
- package/types/iso-viewer/dom.d.ts +1 -0
- package/types/iso-viewer/dual-view.d.ts +44 -0
- package/types/iso-viewer/flat-view.d.ts +25 -0
- package/types/iso-viewer/history.d.ts +91 -0
- package/types/iso-viewer/index.d.ts +31 -0
- package/types/iso-viewer/morph.d.ts +28 -0
- package/types/iso-viewer/overlay.d.ts +135 -0
- package/types/iso-viewer/page.d.ts +13 -0
- package/types/iso-viewer/still.d.ts +26 -0
- package/types/iso-viewer/timeline-contract.d.ts +345 -0
- package/types/iso-viewer/timeline-engine.d.ts +20 -0
- package/types/iso-viewer/timeline-export.d.ts +5 -0
- package/types/iso-viewer/timeline-scale.d.ts +44 -0
- package/types/iso-viewer/timeline-scope.d.ts +33 -0
- package/types/iso-viewer/timeline-search.d.ts +52 -0
- package/types/iso-viewer/timeline-time.d.ts +8 -0
- package/types/iso-viewer/view-css.d.ts +7 -0
- package/types/iso-viewer/viewport.d.ts +50 -0
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
import { Kernel, FONTS, S, tag, iso, pt, n1, esc, textWidth } from "../iso-core/kernel.js";
|
|
2
|
+
import { drawCloud } from "./assets.js";
|
|
3
|
+
import { regionKind, nodeKindOr } from "./kinds.js";
|
|
4
|
+
import { depthSort } from "../iso-core/depth.js";
|
|
5
|
+
import { labelRect, Obstacles, placeCallout, placeNodeLabel, polyBounds, silhouette } from "./labels.js";
|
|
6
|
+
import { WALL_T, gateBox } from "./place.js";
|
|
7
|
+
import { floorAt } from "./route.js";
|
|
8
|
+
import { assembly } from "./assemble.js";
|
|
9
|
+
import { colorRef } from "../iso-core/theme.js";
|
|
10
|
+
const regionRole = (cat, r) => r.role ?? regionKind(cat, r.kind)?.role;
|
|
11
|
+
const shapeOf = (cat, r) => regionKind(cat, r.region.kind)?.shape;
|
|
12
|
+
function renderScene({ scene, layout, routes, steps, theme, id, gridStep = 1 }) {
|
|
13
|
+
const k = new Kernel();
|
|
14
|
+
const L = { base: "", floor: "", flows: "", blocks: [], air: "", labels: "", marks: "", badges: "" };
|
|
15
|
+
const obs = new Obstacles();
|
|
16
|
+
obs.budget.spots = LABEL_BUDGET;
|
|
17
|
+
const visAttr = (oid) => steps.vis[oid] ? { "data-vis": "1" } : {};
|
|
18
|
+
const regions = layout.items.filter((p) => p.type === "region");
|
|
19
|
+
const depthOf = (p) => {
|
|
20
|
+
let d = 0;
|
|
21
|
+
for (let a = p.parent; a; a = a.parent) d++;
|
|
22
|
+
return d;
|
|
23
|
+
};
|
|
24
|
+
const cat = layout.catalog;
|
|
25
|
+
const flat = regions.filter((r) => shapeOf(cat, r) !== "walled" && shapeOf(cat, r) !== "tunnel");
|
|
26
|
+
const ordered = depthSort(flat.map((r) => ({ box: r.box, r }))).map((x) => x.r).sort((a, b) => depthOf(a) - depthOf(b));
|
|
27
|
+
for (const r of ordered) L.base += drawFlatRegion(k, cat, r, visAttr(r.id), gridStep);
|
|
28
|
+
for (const r of regions.filter((r2) => shapeOf(cat, r2) === "walled")) {
|
|
29
|
+
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
|
+
const g2 = r.region.gate;
|
|
32
|
+
if (g2 && !g2.node) {
|
|
33
|
+
const b = gateBox(r, g2.height ?? (r.region.height ?? 0.8) + 0.3, 0.3, 0.3);
|
|
34
|
+
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
|
+
}
|
|
37
|
+
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
|
+
}
|
|
40
|
+
}
|
|
41
|
+
for (const r of regions.filter((r2) => shapeOf(cat, r2) === "tunnel")) L.air += drawTunnel(k, r, visAttr(r.id));
|
|
42
|
+
const nodes = layout.items.filter((p) => p.type === "node");
|
|
43
|
+
for (const p of nodes) {
|
|
44
|
+
const n = p.node, a = nodeKindOr(cat, n.asset);
|
|
45
|
+
const ghost = n.ghost || (n.deco ?? []).includes("ghost");
|
|
46
|
+
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
|
+
obs.polys.push({ poly: silhouette(p.box), owner: p.id });
|
|
49
|
+
obs.solids.push(silhouette(p.box));
|
|
50
|
+
}
|
|
51
|
+
const blocks = depthSort(L.blocks).map((i) => i.svg).join("");
|
|
52
|
+
const markers = /* @__PURE__ */ new Set();
|
|
53
|
+
const paths = {};
|
|
54
|
+
for (const r of routes) {
|
|
55
|
+
if (r.points.length < 2) continue;
|
|
56
|
+
const scr = r.points.map((q) => iso(q[0], q[1], q[2]));
|
|
57
|
+
scr.forEach((q) => k.bounds.add(q));
|
|
58
|
+
const d = "M" + scr.map(pt).join(" L");
|
|
59
|
+
paths[r.id] = d;
|
|
60
|
+
const arrow = r.raw.arrow !== false;
|
|
61
|
+
if (arrow) markers.add(r.kind);
|
|
62
|
+
L.flows += tag(
|
|
63
|
+
"g",
|
|
64
|
+
{ "data-hl": r.id, "data-id": r.id, ...visAttr(r.id) },
|
|
65
|
+
tag("path", { d, class: `flow f-${r.kind}`, "marker-end": arrow ? `url(#ah-${id}-${r.kind})` : void 0 })
|
|
66
|
+
);
|
|
67
|
+
obs.lines.push({ pts: scr, owner: r.id });
|
|
68
|
+
}
|
|
69
|
+
for (const kd of markers) {
|
|
70
|
+
k.def(`ah-${id}-${kd}`, tag(
|
|
71
|
+
"marker",
|
|
72
|
+
{ id: `ah-${id}-${kd}`, viewBox: "0 0 10 10", refX: "7", refY: "5", markerWidth: "4.2", markerHeight: "4.2", orient: "auto-start-reverse" },
|
|
73
|
+
tag("path", { d: "M0,0 L10,5 L0,10 z", style: `fill:${colorRef(theme, theme.kinds[kd]?.color ?? "control")}` })
|
|
74
|
+
));
|
|
75
|
+
}
|
|
76
|
+
for (const q of k.planePolys) obs.slants.push(q);
|
|
77
|
+
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
|
+
const warnings = [];
|
|
80
|
+
for (const r of routes) if (r.raw.label && r.points.length >= 2) {
|
|
81
|
+
const out = routeLabel(k, r, obs, visAttr(r.id), layout);
|
|
82
|
+
L.floor += out.svg;
|
|
83
|
+
if (out.warning) warnings.push({ path: `${r.path}/label`, message: out.warning });
|
|
84
|
+
if (obs.budget.over && !obs.budget.told) {
|
|
85
|
+
obs.budget.told = true;
|
|
86
|
+
warnings.push({ path: r.path, message: `from route "${r.id}" on, route labels were placed without weighing what other labels and lines cover: the scene is too large to search every spot (${LABEL_BUDGET.toLocaleString("en")} spots); split it into scenes, or give the labels "along", "side" or "at"` });
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
(scene.notes ?? []).forEach((note, i) => {
|
|
90
|
+
const s = drawNote(k, note, layout, routes, `${id}-note-${i}`);
|
|
91
|
+
if (note.floor) L.floor += s;
|
|
92
|
+
else L.labels += s;
|
|
93
|
+
});
|
|
94
|
+
const callouts = [];
|
|
95
|
+
const byStep = /* @__PURE__ */ new Map();
|
|
96
|
+
for (const sy of steps.says) {
|
|
97
|
+
const o = byStep.get(sy.step) ?? obs.fork();
|
|
98
|
+
byStep.set(sy.step, o);
|
|
99
|
+
const w = textWidth(sy.text, FONTS.say) + 18;
|
|
100
|
+
const spot = placeCallout(w, sy.ax, sy.ay, { x: sy.x, y: sy.y, anchor: sy.anchor }, o);
|
|
101
|
+
o.rects.push({ r: spot.rect, owner: "" });
|
|
102
|
+
callouts.push({ step: sy.step, ...spot.rect, text: sy.text });
|
|
103
|
+
const left = spot.rect.x + 2;
|
|
104
|
+
k.bounds.addRect(spot.rect.x, spot.rect.y, spot.rect.w, spot.rect.h);
|
|
105
|
+
const c = colorRef(theme, theme.kinds[sy.kind]?.color ?? "control");
|
|
106
|
+
L.marks += tag(
|
|
107
|
+
"g",
|
|
108
|
+
{ class: "say", "data-step": sy.step },
|
|
109
|
+
tag("rect", { x: left, y: spot.y - 12, width: w, height: 24, rx: 12, style: `stroke:${c}` }) + tag("text", { x: left + w / 2, y: spot.y + 4, "text-anchor": "middle", style: `fill:${c}` }, esc(sy.text))
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
for (const m of steps.marks) {
|
|
113
|
+
const [X, Y] = iso(...m.p);
|
|
114
|
+
k.bounds.addRect(X - 12, Y - 12, 24, 24);
|
|
115
|
+
L.marks += tag(
|
|
116
|
+
"g",
|
|
117
|
+
{ class: "xm", "data-step": m.step, "data-hl": m.on },
|
|
118
|
+
tag("circle", { cx: X, cy: Y, r: 10 }) + tag("path", { d: `M${n1(X - 4.5)},${n1(Y - 4.5)} L${n1(X + 4.5)},${n1(Y + 4.5)} M${n1(X + 4.5)},${n1(Y - 4.5)} L${n1(X - 4.5)},${n1(Y + 4.5)}` })
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
for (const b of steps.badges) {
|
|
122
|
+
const [X, Y] = iso(...b.p);
|
|
123
|
+
k.bounds.addRect(X - 13, Y - 13, 26, 26);
|
|
124
|
+
L.badges += tag(
|
|
125
|
+
"g",
|
|
126
|
+
{ class: `badge c-${b.kind}`, "data-go": b.step, "data-badge": b.step, tabindex: "0", role: "button", "aria-label": `Step ${b.num}` },
|
|
127
|
+
tag("circle", { cx: X, cy: Y, r: 11.5 }) + tag("text", { x: X, y: Y + 0.5 }, String(b.num))
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
const bb = k.bounds, pad = 22;
|
|
131
|
+
const vb = bb.empty ? [0, 0, 100, 100] : [Math.floor(bb.x0 - pad), Math.floor(bb.y0 - pad), Math.ceil(bb.x1 - bb.x0 + pad * 2), Math.ceil(bb.y1 - bb.y0 + pad * 2)];
|
|
132
|
+
const defs = [...k.defs.values()].join("");
|
|
133
|
+
const g = (name, inner) => tag("g", { class: "g-" + name }, inner);
|
|
134
|
+
const svg = tag("svg", {
|
|
135
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
136
|
+
viewBox: vb.join(" "),
|
|
137
|
+
role: "img",
|
|
138
|
+
"aria-label": scene.aria ?? scene.title,
|
|
139
|
+
"data-scene": id
|
|
140
|
+
}, tag("defs", {}, defs) + g("base", L.base) + g("floor", L.floor) + g("flows", L.flows) + g("blocks", blocks) + g("air", L.air) + g("labels", L.labels) + g("marks", L.marks) + g("badges", L.badges) + g("anim", ""));
|
|
141
|
+
return { svg, viewBox: vb, texts: k.texts, paths, warnings, callouts, assembly: assembly(layout, routes, vb) };
|
|
142
|
+
}
|
|
143
|
+
function gridLines(b, step) {
|
|
144
|
+
const z = b.z1 + 2e-3, e = 1e-6, d = [];
|
|
145
|
+
const seg = (a, c) => {
|
|
146
|
+
const p = iso(a[0], a[1], z), q = iso(c[0], c[1], z);
|
|
147
|
+
d.push(`M${pt(p)}L${pt(q)}`);
|
|
148
|
+
};
|
|
149
|
+
for (let x = Math.ceil((b.x0 + e) / step) * step; x < b.x1 - e; x += step) seg([x, b.y0], [x, b.y1]);
|
|
150
|
+
for (let y = Math.ceil((b.y0 + e) / step) * step; y < b.y1 - e; y += step) seg([b.x0, y], [b.x1, y]);
|
|
151
|
+
return d.length ? tag("path", { class: "grid", d: d.join("") }) : "";
|
|
152
|
+
}
|
|
153
|
+
function drawFlatRegion(k, cat, r, vis, gridStep = 1) {
|
|
154
|
+
const R = r.region, b = r.box, role = regionRole(cat, R), rk = regionKind(cat, R.kind), shape = rk?.shape;
|
|
155
|
+
const attrs = { "data-id": r.id, "data-dim": "1", ...vis };
|
|
156
|
+
let s = "";
|
|
157
|
+
if (shape === "cloud") s = tag("g", { class: `blk k-${role} cloud`, ...attrs }, drawCloud(k, b));
|
|
158
|
+
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
|
+
else s = tag("g", { class: `blk k-${role}${R.ghost ? " ghost" : ""}`, ...attrs }, k.blockFaces(b) + gridLines(b, gridStep));
|
|
160
|
+
const style = R["label-style"] ?? rk?.labelStyle;
|
|
161
|
+
if (R.label && style !== "none") {
|
|
162
|
+
if (style === "face") {
|
|
163
|
+
const big = shape === "slab";
|
|
164
|
+
const z = big ? b.z0 + 0.28 : b.z0 + Math.min(0.1, (b.z1 - b.z0) * 0.25);
|
|
165
|
+
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"));
|
|
166
|
+
} else if (style === "face-right") {
|
|
167
|
+
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"));
|
|
168
|
+
} else {
|
|
169
|
+
const m = shape === "cloud" ? "middle" : "start";
|
|
170
|
+
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;
|
|
171
|
+
s += tag("g", attrs, k.floorText(x, y, b.z1 + 0.01, R.label, "slabname sm", "x", m));
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return s;
|
|
175
|
+
}
|
|
176
|
+
function wallsOf(r) {
|
|
177
|
+
const { x0, y0, x1, y1, z0, z1 } = r.box, t = WALL_T, g = r.region.gate;
|
|
178
|
+
const walls = [];
|
|
179
|
+
const W = (b) => {
|
|
180
|
+
if (b.x1 - b.x0 > 1e-6 && b.y1 - b.y0 > 1e-6) walls.push({ ...b, z0, z1 });
|
|
181
|
+
};
|
|
182
|
+
const span = (lo, hi, side) => {
|
|
183
|
+
if (!g || g.side !== side) return [[lo, hi]];
|
|
184
|
+
const at = g.at ?? 0.5, w = g.width ?? 2;
|
|
185
|
+
const c = side === "e" || side === "w" ? y0 + (y1 - y0) * at : x0 + (x1 - x0) * at;
|
|
186
|
+
return [[lo, c - w / 2], [c + w / 2, hi]];
|
|
187
|
+
};
|
|
188
|
+
for (const [a, b] of span(x0, x1, "n")) W({ x0: a, y0, x1: b, y1: y0 + t });
|
|
189
|
+
for (const [a, b] of span(y0 + t, y1 - t, "w")) W({ x0, y0: a, x1: x0 + t, y1: b });
|
|
190
|
+
for (const [a, b] of span(y0 + t, y1 - t, "e")) W({ x0: x1 - t, y0: a, x1, y1: b });
|
|
191
|
+
for (const [a, b] of span(x0, x1, "s")) W({ x0: a, y0: y1 - t, x1: b, y1 });
|
|
192
|
+
return walls;
|
|
193
|
+
}
|
|
194
|
+
function nodeLabel(k, cat, p, obs, vis) {
|
|
195
|
+
const n = p.node, a = nodeKindOr(cat, n.asset), b = p.box;
|
|
196
|
+
const t = { name: n.label, sub: n.sub };
|
|
197
|
+
const la = n["label-at"];
|
|
198
|
+
let spot;
|
|
199
|
+
if (la) {
|
|
200
|
+
const sb = polyBounds(silhouette(b));
|
|
201
|
+
const side = la.side ?? "above", midY = sb.y + Math.min(sb.h, 60) * 0.45;
|
|
202
|
+
if (side === "right") spot = { x: sb.x + sb.w + 8, y: midY, anchor: "start" };
|
|
203
|
+
else if (side === "left") spot = { x: sb.x - 8, y: midY, anchor: "end" };
|
|
204
|
+
else if (side === "below") spot = { x: sb.x + sb.w / 2, y: sb.y + sb.h + 14, anchor: "middle" };
|
|
205
|
+
else spot = placeNodeLabel(t, b, silhouette(b), new Obstacles(), p.id);
|
|
206
|
+
spot = { ...spot, x: spot.x + (la.dx ?? 0), y: spot.y + (la.dy ?? 0) };
|
|
207
|
+
} else {
|
|
208
|
+
const pref = a.label ? a.label(b, n, !!n.sub) : void 0;
|
|
209
|
+
spot = placeNodeLabel(t, b, silhouette(b), obs, p.id, pref);
|
|
210
|
+
}
|
|
211
|
+
obs.rects.push({ r: labelRect(t, spot.x, spot.y, spot.anchor), owner: "" });
|
|
212
|
+
let s = "";
|
|
213
|
+
if (n.label) s += k.text(spot.x, spot.y, n.label, "lbl", FONTS.lbl, spot.anchor, {}, p.id);
|
|
214
|
+
if (n.sub) s += k.text(spot.x, n.label ? spot.y + 14 : spot.y, n.sub, "sub mono", FONTS.sub, spot.anchor, {}, p.id);
|
|
215
|
+
return tag("g", { "data-id": p.id, "data-dim": "1", ...vis }, s);
|
|
216
|
+
}
|
|
217
|
+
function drawTunnel(k, r, vis) {
|
|
218
|
+
const { x0, y0, x1, y1, z0, z1 } = r.box;
|
|
219
|
+
let s = k.blockFaces(r.box);
|
|
220
|
+
const alongX = x1 - x0 >= y1 - y0, n = Math.max(1, Math.round((alongX ? x1 - x0 : y1 - y0) / 1.6));
|
|
221
|
+
for (let i = 1; i < n; i++) {
|
|
222
|
+
const t = alongX ? x0 + (x1 - x0) * i / n : y0 + (y1 - y0) * i / n;
|
|
223
|
+
s += k.poly(alongX ? [[t, y0, z1], [t, y1, z1], [t, y1, z0]] : [[x0, t, z1], [x1, t, z1], [x1, t, z0]], "rib");
|
|
224
|
+
}
|
|
225
|
+
const label = r.region.label;
|
|
226
|
+
if (label && r.region["label-style"] !== "none") {
|
|
227
|
+
s += alongX ? k.faceText(x0 + 0.35, y1, z0 + 0.14, label, "tunname", FONTS.tunname, "left", "start") : k.faceText(x1, y1 - 0.35, z0 + 0.18, label, "tunname", FONTS.tunname, "right", "start");
|
|
228
|
+
}
|
|
229
|
+
return tag("g", { class: "tunnel", "data-id": r.id, "data-dim": "1", ...vis }, s);
|
|
230
|
+
}
|
|
231
|
+
const LABEL_BUDGET = 2e4;
|
|
232
|
+
function routeLabel(k, r, obs, vis, layout) {
|
|
233
|
+
const L = typeof r.raw.label === "string" ? { text: r.raw.label } : r.raw.label;
|
|
234
|
+
const cls = `floor mono t-${r.kind}`, attrs = { "data-hl": r.id, ...vis };
|
|
235
|
+
const font = FONTS.floor;
|
|
236
|
+
if (L.at) {
|
|
237
|
+
const z = L.at.length > 2 ? L.at[2] : r.points[0][2];
|
|
238
|
+
return { svg: k.floorText(L.at[0], L.at[1], z, L.text, cls, L.dir ?? "x", L.anchor ?? "start", attrs) };
|
|
239
|
+
}
|
|
240
|
+
const P = r.points;
|
|
241
|
+
const segs = [];
|
|
242
|
+
for (let i = 0; i + 1 < P.length; i++) {
|
|
243
|
+
const a = P[i], b = P[i + 1];
|
|
244
|
+
if (Math.abs(a[2] - b[2]) > 1e-6) continue;
|
|
245
|
+
segs.push({ i, len: Math.hypot(b[0] - a[0], b[1] - a[1]) });
|
|
246
|
+
}
|
|
247
|
+
if (!segs.length) return { svg: "", warning: `label "${L.text}" of route "${r.id}" was dropped: the route has no level segment` };
|
|
248
|
+
const order = L.along ? segs.filter((sg) => sg.i === Math.min(L.along - 1, P.length - 2)) : [...segs].sort((a, b) => b.len - a.len);
|
|
249
|
+
const GAP = 0.22, hgt = 11 / S;
|
|
250
|
+
const attempt = (text2) => {
|
|
251
|
+
const w = textWidth(text2, font) / S;
|
|
252
|
+
let best, bestCost = Infinity;
|
|
253
|
+
let rank = 0;
|
|
254
|
+
search:
|
|
255
|
+
for (const sg of order.length ? order : segs) {
|
|
256
|
+
const a = P[sg.i], b = P[sg.i + 1], z = a[2];
|
|
257
|
+
const alongX = Math.abs(a[1] - b[1]) < 1e-6;
|
|
258
|
+
const lo = alongX ? Math.min(a[0], b[0]) : Math.min(a[1], b[1]), hi = alongX ? Math.max(a[0], b[0]) : Math.max(a[1], b[1]);
|
|
259
|
+
const line = alongX ? a[1] : a[0];
|
|
260
|
+
const sides = L.side === "left" ? [-1] : L.side === "right" ? [1] : [-1, 1];
|
|
261
|
+
const starts = [];
|
|
262
|
+
for (let t = lo + 0.3; t <= Math.max(lo + 0.3, hi - w - 0.2) + 1e-9; t += 0.4) starts.push(t);
|
|
263
|
+
for (let t = hi - w - 0.2 + 0.4; t < hi + 0.5 && hi - lo < w + 0.5; t += 0.6) starts.push(t);
|
|
264
|
+
for (const sd of sides) for (const st of starts) {
|
|
265
|
+
if (bestCost <= rank * 0.5) break search;
|
|
266
|
+
const base = sd < 0 ? line - GAP : line + GAP + hgt;
|
|
267
|
+
let x, y, poly;
|
|
268
|
+
if (alongX) {
|
|
269
|
+
x = st;
|
|
270
|
+
y = base;
|
|
271
|
+
poly = [iso(x, y - hgt, z), iso(x + w, y - hgt, z), iso(x + w, y, z), iso(x, y, z)];
|
|
272
|
+
} else {
|
|
273
|
+
x = base;
|
|
274
|
+
y = st + w;
|
|
275
|
+
poly = [iso(x - hgt, y, z), iso(x - hgt, y - w, z), iso(x, y - w, z), iso(x, y, z)];
|
|
276
|
+
}
|
|
277
|
+
const corners = alongX ? [[x, y - hgt], [x + w, y - hgt], [x + w, y], [x, y]] : [[x - hgt, y], [x - hgt, y - w], [x, y - w], [x, y]];
|
|
278
|
+
if (corners.some(([u, v]) => Math.abs(floorAt(layout, u, v) + 0.01 - z) > 1e-3)) {
|
|
279
|
+
rank++;
|
|
280
|
+
continue;
|
|
281
|
+
}
|
|
282
|
+
const hidden = obs.hiddenPoly(poly);
|
|
283
|
+
const known = hidden * 50 + rank * 0.5;
|
|
284
|
+
const weigh = obs.budget.spots-- > 0;
|
|
285
|
+
if (!weigh) obs.budget.over = true;
|
|
286
|
+
const cost = known >= bestCost ? Infinity : weigh ? known + obs.costPoly(poly, bestCost - known) : known;
|
|
287
|
+
rank++;
|
|
288
|
+
if (cost < bestCost) {
|
|
289
|
+
bestCost = cost;
|
|
290
|
+
best = { x, y, z, dir: alongX ? "x" : "y", rect: polyBounds(poly), poly, hidden };
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
return best && best.hidden < 6 ? best : void 0;
|
|
295
|
+
};
|
|
296
|
+
let text = L.text, spot = attempt(text), warning;
|
|
297
|
+
if (!spot) {
|
|
298
|
+
const words = L.text.split(/(\s+)/);
|
|
299
|
+
for (let n = words.length - 1; n > 0 && !spot; n--) {
|
|
300
|
+
const t = words.slice(0, n).join("").trimEnd().replace(/[\s,;:·–-]+$/, "") + "\u2026";
|
|
301
|
+
if (t.length < 6) break;
|
|
302
|
+
const sp = attempt(t);
|
|
303
|
+
if (sp) {
|
|
304
|
+
spot = sp;
|
|
305
|
+
text = t;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
warning = spot ? `label of route "${r.id}" shortened to "${text}": no clear floor for the whole text` : `label "${L.text}" of route "${r.id}" was dropped: blocks cover every spot beside it`;
|
|
309
|
+
if (spot) warning += '; give it "along", "side" or "at", or move the nodes apart';
|
|
310
|
+
else warning += '; give it "at: [x, y]", or move the nodes apart';
|
|
311
|
+
}
|
|
312
|
+
if (!spot) return { svg: "", warning };
|
|
313
|
+
obs.slants.push(spot.poly);
|
|
314
|
+
return { svg: k.floorText(spot.x, spot.y, spot.z + 0.01, text, cls, spot.dir, "start", attrs), warning };
|
|
315
|
+
}
|
|
316
|
+
const shrink = (r, d) => ({ x: r.x + d, y: r.y + d, w: Math.max(0, r.w - 2 * d), h: Math.max(0, r.h - 2 * d) });
|
|
317
|
+
function drawNote(k, note, layout, routes, id) {
|
|
318
|
+
const route = note.on ? routes.find((r) => r.id === note.on) : void 0;
|
|
319
|
+
const on = note.on && !route ? layout.byId.get(note.on) : void 0;
|
|
320
|
+
const at = note.at;
|
|
321
|
+
const attrs = { "data-id": id, "data-hl": route?.id, "data-dim": route ? void 0 : "1" };
|
|
322
|
+
const kind = note.kind ?? route?.kind ?? "control";
|
|
323
|
+
if (note.floor) {
|
|
324
|
+
const z = at && at.length > 2 ? at[2] : route ? route.points[0][2] : on ? on.floor : 0.36;
|
|
325
|
+
const [x, y] = at ? [at[0], at[1]] : route ? [route.points[0][0] + 0.35, route.points[0][1] - 0.25] : on ? [on.box.x0 + 0.3, on.box.y1 - 0.3] : [0, 0];
|
|
326
|
+
return k.floorText(x, y, z + 0.01, note.floor, `floor mono t-${kind}`, note.dir ?? "x", note.anchor ?? "start", attrs);
|
|
327
|
+
}
|
|
328
|
+
if (note.face) {
|
|
329
|
+
const b = on?.box;
|
|
330
|
+
const [x, y, z] = at ? [at[0], at[1], at[2] ?? 0.45] : b ? [b.x0 + 0.3, b.y1, b.z0 + 0.13] : [0, 0, 0];
|
|
331
|
+
return k.faceText(x, y, z, note.face, "slabname sm", FONTS.sm, "left", note.anchor ?? "start", attrs);
|
|
332
|
+
}
|
|
333
|
+
if (note.label || note.sub) {
|
|
334
|
+
const b = on?.box;
|
|
335
|
+
const p3 = at ? [at[0], at[1], at[2] ?? 0.36] : b ? [(b.x0 + b.x1) / 2, (b.y0 + b.y1) / 2, b.z1 + 0.75] : [0, 0, 0];
|
|
336
|
+
const [X, Y] = iso(p3[0], p3[1], p3[2]);
|
|
337
|
+
const x = X + (note.dx ?? 0), y = Y - 18 + (note.dy ?? 0), anchor = note.anchor ?? "middle";
|
|
338
|
+
let s = "";
|
|
339
|
+
if (note.label) s += k.text(x, y, note.label, "lbl", FONTS.lbl, anchor);
|
|
340
|
+
if (note.sub) s += k.text(x, note.label ? y + 14 : y, note.sub, "sub mono", FONTS.sub, anchor);
|
|
341
|
+
return tag("g", attrs, s);
|
|
342
|
+
}
|
|
343
|
+
return "";
|
|
344
|
+
}
|
|
345
|
+
export {
|
|
346
|
+
LABEL_BUDGET,
|
|
347
|
+
regionRole,
|
|
348
|
+
renderScene,
|
|
349
|
+
wallsOf
|
|
350
|
+
};
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { iso } from "../iso-core/kernel.js";
|
|
2
|
+
import { nodeKind } from "./kinds.js";
|
|
3
|
+
import { didYouMean } from "../iso-core/errors.js";
|
|
4
|
+
import { colorRef } from "../iso-core/theme.js";
|
|
5
|
+
function durationFor(caption) {
|
|
6
|
+
return Math.max(5600, Math.min(12500, 2600 + caption.length * 40));
|
|
7
|
+
}
|
|
8
|
+
function resolveSteps(scene, scenePath, layout, routes, src, theme) {
|
|
9
|
+
const diags = [];
|
|
10
|
+
const err = (path, message, hint, severity = "error") => {
|
|
11
|
+
const p = src.locate(path);
|
|
12
|
+
diags.push({ severity, message, line: p.line, col: p.col, path, hint });
|
|
13
|
+
};
|
|
14
|
+
const raws = scene.steps ?? [];
|
|
15
|
+
const kinds = new Set(Object.keys(theme.kinds));
|
|
16
|
+
const routeById = new Map(routes.map((r) => [r.id, r]));
|
|
17
|
+
const allIds = () => [...layout.byId.keys(), ...routeById.keys()];
|
|
18
|
+
const stepIds = /* @__PURE__ */ new Map();
|
|
19
|
+
raws.forEach((s, i) => {
|
|
20
|
+
if (s.id) {
|
|
21
|
+
if (stepIds.has(s.id)) err(`${scenePath}/steps/${i}/id`, `duplicate step id "${s.id}"`);
|
|
22
|
+
stepIds.set(s.id, i + 1);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
const N = raws.length;
|
|
26
|
+
const stepOf = (ref, path) => {
|
|
27
|
+
if (typeof ref === "number") {
|
|
28
|
+
if (ref < 1 || ref > N) {
|
|
29
|
+
err(path, `there is no step ${ref}; this scene has ${N} step(s)`);
|
|
30
|
+
return void 0;
|
|
31
|
+
}
|
|
32
|
+
return ref;
|
|
33
|
+
}
|
|
34
|
+
const n = stepIds.get(ref);
|
|
35
|
+
if (n === void 0) err(path, `unknown step "${ref}"` + dym(ref, stepIds.keys()));
|
|
36
|
+
return n;
|
|
37
|
+
};
|
|
38
|
+
const color = (k) => colorRef(theme, theme.kinds[k]?.color ?? "control");
|
|
39
|
+
const kindsUsed = [];
|
|
40
|
+
const use = (k) => {
|
|
41
|
+
if (!kindsUsed.includes(k)) kindsUsed.push(k);
|
|
42
|
+
};
|
|
43
|
+
for (const r of routes) use(r.kind);
|
|
44
|
+
const vis = {};
|
|
45
|
+
const initial = (id, appears, disappears, path) => {
|
|
46
|
+
if (appears === void 0 && disappears === void 0) return;
|
|
47
|
+
const a = appears !== void 0 ? stepOf(appears, path + "/appears") : 1;
|
|
48
|
+
const d = disappears !== void 0 ? stepOf(disappears, path + "/disappears") : N + 1;
|
|
49
|
+
vis[id] = Array.from({ length: N }, (_, i) => i + 1 >= (a ?? 1) && i + 1 < (d ?? N + 1));
|
|
50
|
+
};
|
|
51
|
+
for (const p of layout.items) initial(p.id, p.appears, p.disappears, p.path);
|
|
52
|
+
for (const r of routes) initial(r.id, r.raw.appears, r.raw.disappears, r.path);
|
|
53
|
+
const steps = [];
|
|
54
|
+
const says = [], marks = [], badges = [];
|
|
55
|
+
const routeEnds = () => {
|
|
56
|
+
for (const r of routes) {
|
|
57
|
+
if (r.raw.appears !== void 0 || r.raw.disappears !== void 0) continue;
|
|
58
|
+
const ends = [r.from, r.to].map((p) => p && (vis[p.id] ?? ancestorVis(p)));
|
|
59
|
+
if (!ends.some(Boolean)) continue;
|
|
60
|
+
vis[r.id] = Array.from({ length: N }, (_, i) => ends.every((v) => !v || v[i]));
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
const ancestorVis = (p) => {
|
|
64
|
+
for (let a = p.parent; a; a = a.parent) if (vis[a.id]) return vis[a.id];
|
|
65
|
+
return void 0;
|
|
66
|
+
};
|
|
67
|
+
raws.forEach((s, i) => {
|
|
68
|
+
const n = i + 1, path = `${scenePath}/steps/${i}`;
|
|
69
|
+
const kind = s.kind ?? "control";
|
|
70
|
+
if (!kinds.has(kind)) err(path + "/kind", `unknown flow kind "${kind}"` + dym(kind, kinds));
|
|
71
|
+
use(kind);
|
|
72
|
+
const lit = /* @__PURE__ */ new Set();
|
|
73
|
+
const phases = [];
|
|
74
|
+
(s.animate ?? []).forEach((ph, pi) => {
|
|
75
|
+
const list = Array.isArray(ph) ? ph : [ph];
|
|
76
|
+
const toks = [];
|
|
77
|
+
list.forEach((ref, ri) => {
|
|
78
|
+
const rp = Array.isArray(ph) ? `${path}/animate/${pi}/${ri}` : `${path}/animate/${pi}`;
|
|
79
|
+
let id, k;
|
|
80
|
+
if (typeof ref === "string") {
|
|
81
|
+
const m = /^([^:\s]+)\s*(?::\s*(\S+))?$/.exec(ref.trim());
|
|
82
|
+
id = m ? m[1] : ref;
|
|
83
|
+
k = m?.[2];
|
|
84
|
+
} else {
|
|
85
|
+
const e = Object.entries(ref)[0];
|
|
86
|
+
id = e[0];
|
|
87
|
+
k = e[1];
|
|
88
|
+
}
|
|
89
|
+
const r = routeById.get(id);
|
|
90
|
+
if (!r) {
|
|
91
|
+
err(rp, `unknown route "${id}"` + dym(id, routeById.keys()));
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
if (k && !kinds.has(k)) {
|
|
95
|
+
err(rp, `unknown flow kind "${k}"` + dym(k, kinds));
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
const tk = k ?? r.kind;
|
|
99
|
+
use(tk);
|
|
100
|
+
toks.push({ route: id, kind: tk, color: color(tk) });
|
|
101
|
+
lit.add(id);
|
|
102
|
+
if (r.from) lit.add(r.from.id);
|
|
103
|
+
if (r.to) lit.add(r.to.id);
|
|
104
|
+
});
|
|
105
|
+
if (toks.length) phases.push(toks);
|
|
106
|
+
});
|
|
107
|
+
const pulses = [];
|
|
108
|
+
(s.pulse ?? []).forEach((id, pi) => {
|
|
109
|
+
const p = layout.byId.get(id);
|
|
110
|
+
if (!p) {
|
|
111
|
+
err(`${path}/pulse/${pi}`, `unknown node "${id}"` + dym(id, layout.byId.keys()));
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
let x, y, z, r;
|
|
115
|
+
const a = p.node ? nodeKind(layout.catalog, p.node.asset) : void 0;
|
|
116
|
+
if (a?.pulse) [x, y, z, r] = a.pulse(p.box);
|
|
117
|
+
else {
|
|
118
|
+
const b = p.box;
|
|
119
|
+
x = (b.x0 + b.x1) / 2;
|
|
120
|
+
y = (b.y0 + b.y1) / 2;
|
|
121
|
+
z = b.z1;
|
|
122
|
+
r = Math.max(22, Math.min(60, (b.x1 - b.x0 + b.y1 - b.y0) * 8.5));
|
|
123
|
+
}
|
|
124
|
+
const [X, Y] = iso(x, y, z);
|
|
125
|
+
pulses.push([X, Y, r * 1.7, r * 0.98]);
|
|
126
|
+
lit.add(id);
|
|
127
|
+
});
|
|
128
|
+
(s.highlight ?? []).forEach((id, hi) => {
|
|
129
|
+
if (!layout.byId.has(id) && !routeById.has(id)) err(`${path}/highlight/${hi}`, `unknown id "${id}"` + dym(id, allIds()));
|
|
130
|
+
lit.add(id);
|
|
131
|
+
});
|
|
132
|
+
for (const [key, val] of [["show", true], ["hide", false]]) {
|
|
133
|
+
(s[key] ?? []).forEach((id, hi) => {
|
|
134
|
+
if (!layout.byId.has(id) && !routeById.has(id)) {
|
|
135
|
+
err(`${path}/${key}/${hi}`, `unknown id "${id}"` + dym(id, allIds()));
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
const v = vis[id] ?? (vis[id] = Array(N).fill(!val));
|
|
139
|
+
for (let j = i; j < N; j++) v[j] = val;
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
(s.say ?? []).forEach((c, ci) => {
|
|
143
|
+
let X, Y;
|
|
144
|
+
if (Array.isArray(c.at)) [X, Y] = iso(c.at[0], c.at[1], c.at[2] ?? 0.36);
|
|
145
|
+
else {
|
|
146
|
+
const p = layout.byId.get(c.at);
|
|
147
|
+
if (!p) {
|
|
148
|
+
err(`${path}/say/${ci}/at`, `unknown node "${c.at}"` + dym(c.at, layout.byId.keys()));
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
const b = p.box;
|
|
152
|
+
[X, Y] = iso((b.x0 + b.x1) / 2, (b.y0 + b.y1) / 2, b.z1 + 0.75);
|
|
153
|
+
}
|
|
154
|
+
const k = c.kind ?? kind;
|
|
155
|
+
if (!kinds.has(k)) err(`${path}/say/${ci}/kind`, `unknown flow kind "${k}"` + dym(k, kinds));
|
|
156
|
+
says.push({ step: n, x: X + (c.dx ?? 0), y: Y + (c.dy ?? (Array.isArray(c.at) ? 0 : -46)), ax: X, ay: Y, text: c.text, kind: k, anchor: c.anchor ?? "middle" });
|
|
157
|
+
});
|
|
158
|
+
(s.mark ?? []).forEach((m, mi) => {
|
|
159
|
+
if (m.at) {
|
|
160
|
+
marks.push({ step: n, p: [m.at[0], m.at[1], m.at[2] ?? 0.36] });
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
const r = m.on ? routeById.get(m.on) : void 0;
|
|
164
|
+
if (!r) {
|
|
165
|
+
err(`${path}/mark/${mi}`, m.on ? `unknown route "${m.on}"` + dym(m.on, routeById.keys()) : 'a mark needs "on: ROUTE" or "at: [x, y]"');
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
const end = r.points[r.points.length - 1];
|
|
169
|
+
marks.push({ step: n, p: [end[0], end[1], end[2] + 0.6], on: r.id });
|
|
170
|
+
lit.add(r.id);
|
|
171
|
+
});
|
|
172
|
+
if (scene.badges && s.badge !== false) {
|
|
173
|
+
let p = Array.isArray(s.badge) ? [s.badge[0], s.badge[1], s.badge[2] ?? 0.36] : void 0;
|
|
174
|
+
const target = typeof s.badge === "string" ? s.badge : phases[0]?.[0]?.route;
|
|
175
|
+
const r = target ? routeById.get(target) : void 0;
|
|
176
|
+
if (p) {
|
|
177
|
+
} else if (r) p = midpoint(r.points);
|
|
178
|
+
else if (target && layout.byId.get(target)) {
|
|
179
|
+
const b = layout.byId.get(target).box;
|
|
180
|
+
p = [(b.x0 + b.x1) / 2, (b.y0 + b.y1) / 2, b.z1 + 0.3];
|
|
181
|
+
} else if (typeof s.badge === "string") err(`${path}/badge`, `unknown id "${s.badge}"` + dym(s.badge, allIds()));
|
|
182
|
+
if (p) badges.push({ step: n, num: s.number ?? n, kind, p });
|
|
183
|
+
}
|
|
184
|
+
for (const id of [...lit]) for (let a = layout.byId.get(id)?.parent; a; a = a.parent) lit.add(a.id);
|
|
185
|
+
for (const t of layout.items) if (t.region?.kind === "tunnel" && (t.region.around ?? []).some((r) => lit.has(r))) lit.add(t.id);
|
|
186
|
+
let focus;
|
|
187
|
+
if (s.focus?.length) {
|
|
188
|
+
let x0 = Infinity, y0 = Infinity, x1 = -Infinity, y1 = -Infinity;
|
|
189
|
+
s.focus.forEach((id, fi) => {
|
|
190
|
+
const p = layout.byId.get(id);
|
|
191
|
+
if (!p) {
|
|
192
|
+
err(`${path}/focus/${fi}`, `unknown node or region "${id}"` + dym(id, layout.byId.keys()));
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
const b = p.box;
|
|
196
|
+
for (const [x, y, z] of [[b.x0, b.y0, b.z1], [b.x1, b.y0, b.z0], [b.x0, b.y1, b.z0], [b.x1, b.y1, b.z0], [b.x1, b.y0, b.z1], [b.x0, b.y1, b.z1]]) {
|
|
197
|
+
const [X, Y] = iso(x, y, z);
|
|
198
|
+
x0 = Math.min(x0, X);
|
|
199
|
+
y0 = Math.min(y0, Y);
|
|
200
|
+
x1 = Math.max(x1, X);
|
|
201
|
+
y1 = Math.max(y1, Y);
|
|
202
|
+
}
|
|
203
|
+
lit.add(id);
|
|
204
|
+
});
|
|
205
|
+
if (x0 < Infinity) focus = [Math.round(x0 - 60), Math.round(y0 - 70), Math.round(x1 + 60), Math.round(y1 + 40)];
|
|
206
|
+
}
|
|
207
|
+
const caption = s.caption ?? "";
|
|
208
|
+
steps.push({
|
|
209
|
+
n,
|
|
210
|
+
num: s.number ?? n,
|
|
211
|
+
kind,
|
|
212
|
+
color: color(kind),
|
|
213
|
+
heading: s.heading,
|
|
214
|
+
caption,
|
|
215
|
+
command: s.command ?? "",
|
|
216
|
+
phases,
|
|
217
|
+
pulses,
|
|
218
|
+
lit: [...lit],
|
|
219
|
+
duration: s.duration === void 0 || s.duration === "auto" ? durationFor(caption) : s.duration,
|
|
220
|
+
...focus ? { focus } : {}
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
routeEnds();
|
|
224
|
+
return { steps, says, marks, badges, vis, diags, kindsUsed };
|
|
225
|
+
}
|
|
226
|
+
function midpoint(pts) {
|
|
227
|
+
const seg = pts.slice(1).map((q, i) => Math.hypot(q[0] - pts[i][0], q[1] - pts[i][1], q[2] - pts[i][2]));
|
|
228
|
+
let half = seg.reduce((a, b) => a + b, 0) / 2;
|
|
229
|
+
for (let i = 0; i < seg.length; i++) {
|
|
230
|
+
if (half <= seg[i] && seg[i] > 0) {
|
|
231
|
+
const t = half / seg[i], a = pts[i], b = pts[i + 1];
|
|
232
|
+
return [a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t, a[2] + (b[2] - a[2]) * t];
|
|
233
|
+
}
|
|
234
|
+
half -= seg[i];
|
|
235
|
+
}
|
|
236
|
+
return pts[0];
|
|
237
|
+
}
|
|
238
|
+
function dym(w, c) {
|
|
239
|
+
const d = didYouMean(w, c);
|
|
240
|
+
return d ? ` (did you mean "${d}"?)` : "";
|
|
241
|
+
}
|
|
242
|
+
export {
|
|
243
|
+
durationFor,
|
|
244
|
+
midpoint,
|
|
245
|
+
resolveSteps
|
|
246
|
+
};
|
|
File without changes
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { NODE_ASSETS } from "./nodes.js";
|
|
2
|
+
const FENCE_SWATCH = "border-color:hsl(38 80% 45%);background:hsl(38 80% 55% / .2)";
|
|
3
|
+
const REGION_KINDS = {
|
|
4
|
+
slab: { shape: "slab", pad: 1.2, z: [-0.8, 0.35], floor: true, role: "slab", labelStyle: "face" },
|
|
5
|
+
pad: { shape: "block", pad: 0.6, z: [0, 0.2], floor: true, role: "pad", labelStyle: "floor" },
|
|
6
|
+
fence: {
|
|
7
|
+
shape: "walled",
|
|
8
|
+
pad: 0.7,
|
|
9
|
+
z: [0, 0.8],
|
|
10
|
+
floor: false,
|
|
11
|
+
role: "fence",
|
|
12
|
+
labelStyle: "face",
|
|
13
|
+
legend: { label: "Fence", swatch: FENCE_SWATCH, box: true, auto: true },
|
|
14
|
+
css: ".fz{fill:var(--fence-text)!important;opacity:1!important}\n"
|
|
15
|
+
},
|
|
16
|
+
vm: {
|
|
17
|
+
shape: "block",
|
|
18
|
+
pad: 0.6,
|
|
19
|
+
z: [0, 0.45],
|
|
20
|
+
floor: true,
|
|
21
|
+
role: "sandbox",
|
|
22
|
+
labelStyle: "face",
|
|
23
|
+
legend: { label: "Sandbox VM", swatch: "border-color:hsl(170 35% 40%);background:hsl(170 40% 50% / .2)", box: true, auto: true }
|
|
24
|
+
},
|
|
25
|
+
platform: { shape: "block", pad: 0.6, z: [0, 0.7], floor: true, role: "server", labelStyle: "face-right" },
|
|
26
|
+
cloud: { shape: "cloud", pad: 0.8, z: [0, 0.2], floor: true, role: "cloud", labelStyle: "floor" },
|
|
27
|
+
zone: { shape: "zone", pad: 0.5, z: [0, 5e-3], floor: false, role: "grey", labelStyle: "floor" },
|
|
28
|
+
tunnel: {
|
|
29
|
+
shape: "tunnel",
|
|
30
|
+
pad: 0,
|
|
31
|
+
z: [0, 0.8],
|
|
32
|
+
floor: false,
|
|
33
|
+
role: "socket",
|
|
34
|
+
labelStyle: "none",
|
|
35
|
+
legend: { label: "Tailscale tunnel", swatch: "border-color:hsl(205 70% 50%);border-top-width:9px;opacity:.35", box: false, auto: false }
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
const systems = { regions: REGION_KINDS, nodes: NODE_ASSETS, defaultNode: "block" };
|
|
39
|
+
export {
|
|
40
|
+
REGION_KINDS,
|
|
41
|
+
systems
|
|
42
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { parse } from "../iso-core/parse.js";
|
|
2
|
+
import { validateSchema } from "./validate.js";
|
|
3
|
+
import { place } from "../iso-objects/place.js";
|
|
4
|
+
import { extendTheme, loadTheme } from "../iso-core/theme.js";
|
|
5
|
+
import { compileRaw } from "../iso-objects/compile.js";
|
|
6
|
+
import { systems } from "./catalog.js";
|
|
7
|
+
function compile(source, themeText, opts = {}) {
|
|
8
|
+
const parsed = parse(source);
|
|
9
|
+
const diags = [...parsed.diags];
|
|
10
|
+
if (diags.some((d) => d.severity === "error")) return { ok: false, diags, catalog: systems, scenes: [] };
|
|
11
|
+
const schemaDiags = validateSchema(parsed);
|
|
12
|
+
diags.push(...schemaDiags);
|
|
13
|
+
const doc = parsed.data;
|
|
14
|
+
if (schemaDiags.length) {
|
|
15
|
+
try {
|
|
16
|
+
const theme = extendTheme(loadTheme(themeText), doc.roles ?? {}, doc.kinds ?? {});
|
|
17
|
+
const bad = schemaDiags.map((d) => d.path);
|
|
18
|
+
(Array.isArray(doc.scenes) ? doc.scenes : []).forEach((raw, i) => {
|
|
19
|
+
try {
|
|
20
|
+
const layout = place(raw, `/scenes/${i}`, parsed, theme, systems, doc.roles ?? {});
|
|
21
|
+
diags.push(...layout.diags.filter((d) => !bad.some((b) => d.path === b || d.path.startsWith(b + "/"))));
|
|
22
|
+
} catch {
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
} catch {
|
|
26
|
+
}
|
|
27
|
+
diags.sort((a, b) => a.line - b.line || a.col - b.col);
|
|
28
|
+
return { ok: false, diags, catalog: systems, scenes: [] };
|
|
29
|
+
}
|
|
30
|
+
return compileRaw(doc, themeText, systems, parsed, source, opts, diags);
|
|
31
|
+
}
|
|
32
|
+
export {
|
|
33
|
+
compile
|
|
34
|
+
};
|