@johnoscott/isometric-engine 0.0.0-stage → 0.10.1

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 (310) hide show
  1. package/EDITOR-GUIDE.md +355 -0
  2. package/LICENSE +21 -0
  3. package/LICENSES/ajv.txt +22 -0
  4. package/LICENSES/lucide-static.txt +43 -0
  5. package/LICENSES/yaml.txt +13 -0
  6. package/README.md +62 -2
  7. package/assets/app.css +269 -0
  8. package/assets/default-theme.yaml +99 -0
  9. package/assets/icons.svg +1 -0
  10. package/assets/marks.css +39 -0
  11. package/assets/skin.css +181 -0
  12. package/iso-editor.d.ts +4 -0
  13. package/iso-editor.js +550 -0
  14. package/iso-render.d.ts +3 -0
  15. package/iso-render.js +388 -0
  16. package/iso-systems.d.ts +4 -0
  17. package/iso-systems.js +389 -0
  18. package/js/iso-core/compile-schema.js +22 -0
  19. package/js/iso-core/depth.js +55 -0
  20. package/js/iso-core/errors.js +65 -0
  21. package/js/iso-core/glyphs.js +100 -0
  22. package/js/iso-core/index.js +55 -0
  23. package/js/iso-core/kernel.js +158 -0
  24. package/js/iso-core/metrics.json +1 -0
  25. package/js/iso-core/package.json +6 -0
  26. package/js/iso-core/parse.js +79 -0
  27. package/js/iso-core/schema-errors.js +170 -0
  28. package/js/iso-core/shims/crypto.js +125 -0
  29. package/js/iso-core/shims/path.js +49 -0
  30. package/js/iso-core/svg-dom.js +144 -0
  31. package/js/iso-core/theme.js +48 -0
  32. package/js/iso-core/vdom.js +48 -0
  33. package/js/iso-editor/adapter.js +0 -0
  34. package/js/iso-editor/clipboard.js +152 -0
  35. package/js/iso-editor/commands.js +173 -0
  36. package/js/iso-editor/complete.js +55 -0
  37. package/js/iso-editor/doc.js +182 -0
  38. package/js/iso-editor/index.js +105 -0
  39. package/js/iso-editor/model.js +210 -0
  40. package/js/iso-editor/outline.js +111 -0
  41. package/js/iso-editor/package.json +6 -0
  42. package/js/iso-editor/path.js +19 -0
  43. package/js/iso-editor/providers.js +96 -0
  44. package/js/iso-editor/schema-nav.js +117 -0
  45. package/js/iso-editor/splice.js +443 -0
  46. package/js/iso-editor/storage-keys.js +6 -0
  47. package/js/iso-editor/ui/actions.js +116 -0
  48. package/js/iso-editor/ui/canvas-layer.js +0 -0
  49. package/js/iso-editor/ui/canvas.js +1403 -0
  50. package/js/iso-editor/ui/clip.js +133 -0
  51. package/js/iso-editor/ui/dialog.js +26 -0
  52. package/js/iso-editor/ui/flat-canvas.js +54 -0
  53. package/js/iso-editor/ui/icons.js +15 -0
  54. package/js/iso-editor/ui/keys.js +26 -0
  55. package/js/iso-editor/ui/later.js +28 -0
  56. package/js/iso-editor/ui/layer.js +11 -0
  57. package/js/iso-editor/ui/menu.js +105 -0
  58. package/js/iso-editor/ui/monaco-entry.js +2 -0
  59. package/js/iso-editor/ui/mount-kit.js +0 -0
  60. package/js/iso-editor/ui/mount.js +767 -0
  61. package/js/iso-editor/ui/pane.js +0 -0
  62. package/js/iso-editor/ui/part.js +0 -0
  63. package/js/iso-editor/ui/plain-icons.js +34 -0
  64. package/js/iso-editor/ui/props.js +314 -0
  65. package/js/iso-editor/ui/scope-css.js +81 -0
  66. package/js/iso-editor/ui/setup.js +149 -0
  67. package/js/iso-editor/ui/text.js +323 -0
  68. package/js/iso-editor/ui/tree.js +728 -0
  69. package/js/iso-editor/validate.js +33 -0
  70. package/js/iso-editor/window/protocol.js +8 -0
  71. package/js/iso-objects/assemble.js +43 -0
  72. package/js/iso-objects/assets.js +88 -0
  73. package/js/iso-objects/board.js +162 -0
  74. package/js/iso-objects/compile.js +60 -0
  75. package/js/iso-objects/css.js +154 -0
  76. package/js/iso-objects/flat.js +696 -0
  77. package/js/iso-objects/focus.js +16 -0
  78. package/js/iso-objects/geometry.js +76 -0
  79. package/js/iso-objects/index.js +93 -0
  80. package/js/iso-objects/kinds.js +12 -0
  81. package/js/iso-objects/labels.js +325 -0
  82. package/js/iso-objects/package.json +6 -0
  83. package/js/iso-objects/place.js +347 -0
  84. package/js/iso-objects/route.js +461 -0
  85. package/js/iso-objects/scene.js +350 -0
  86. package/js/iso-objects/steps.js +246 -0
  87. package/js/iso-objects/types.js +0 -0
  88. package/js/iso-systems/catalog.js +42 -0
  89. package/js/iso-systems/compile.js +34 -0
  90. package/js/iso-systems/css.js +8 -0
  91. package/js/iso-systems/index.js +16 -0
  92. package/js/iso-systems/nodes.js +124 -0
  93. package/js/iso-systems/package.json +6 -0
  94. package/js/iso-systems/schema.json +311 -0
  95. package/js/iso-systems/validate.js +35 -0
  96. package/js/iso-viewer/bundle.js +20 -0
  97. package/js/iso-viewer/card-motion.js +228 -0
  98. package/js/iso-viewer/dom.js +14 -0
  99. package/js/iso-viewer/dual-view.js +212 -0
  100. package/js/iso-viewer/flat-view.js +124 -0
  101. package/js/iso-viewer/history.js +990 -0
  102. package/js/iso-viewer/index.js +98 -0
  103. package/js/iso-viewer/morph.js +192 -0
  104. package/js/iso-viewer/overlay.js +199 -0
  105. package/js/iso-viewer/package.json +6 -0
  106. package/js/iso-viewer/page.js +138 -0
  107. package/js/iso-viewer/player.js +409 -0
  108. package/js/iso-viewer/still.js +81 -0
  109. package/js/iso-viewer/timeline-contract.js +14 -0
  110. package/js/iso-viewer/timeline-engine.js +475 -0
  111. package/js/iso-viewer/timeline-export.js +36 -0
  112. package/js/iso-viewer/timeline-scale.js +116 -0
  113. package/js/iso-viewer/timeline-scope.js +58 -0
  114. package/js/iso-viewer/timeline-search.js +216 -0
  115. package/js/iso-viewer/timeline-time.js +55 -0
  116. package/js/iso-viewer/view-css.js +68 -0
  117. package/js/iso-viewer/viewport.js +177 -0
  118. package/package.json +511 -4
  119. package/src/iso-core/compile-schema.ts +23 -0
  120. package/src/iso-core/depth.ts +56 -0
  121. package/src/iso-core/errors.ts +73 -0
  122. package/src/iso-core/glyphs.ts +108 -0
  123. package/src/iso-core/index.ts +27 -0
  124. package/src/iso-core/kernel.ts +163 -0
  125. package/src/iso-core/metrics.json +1 -0
  126. package/src/iso-core/package.json +6 -0
  127. package/src/iso-core/parse.ts +91 -0
  128. package/src/iso-core/schema-errors.ts +163 -0
  129. package/src/iso-core/shims/crypto.ts +37 -0
  130. package/src/iso-core/shims/path.ts +24 -0
  131. package/src/iso-core/svg-dom.ts +103 -0
  132. package/src/iso-core/theme.ts +64 -0
  133. package/src/iso-core/vdom.ts +41 -0
  134. package/src/iso-editor/adapter.ts +147 -0
  135. package/src/iso-editor/clipboard.ts +163 -0
  136. package/src/iso-editor/commands.ts +191 -0
  137. package/src/iso-editor/complete.ts +73 -0
  138. package/src/iso-editor/doc.ts +207 -0
  139. package/src/iso-editor/index.ts +67 -0
  140. package/src/iso-editor/model.ts +234 -0
  141. package/src/iso-editor/outline.ts +126 -0
  142. package/src/iso-editor/package.json +6 -0
  143. package/src/iso-editor/path.ts +18 -0
  144. package/src/iso-editor/providers.ts +113 -0
  145. package/src/iso-editor/schema-nav.ts +129 -0
  146. package/src/iso-editor/splice.ts +477 -0
  147. package/src/iso-editor/storage-keys.ts +6 -0
  148. package/src/iso-editor/ui/actions.ts +119 -0
  149. package/src/iso-editor/ui/app.css +230 -0
  150. package/src/iso-editor/ui/canvas-layer.ts +56 -0
  151. package/src/iso-editor/ui/canvas.ts +1227 -0
  152. package/src/iso-editor/ui/clip.ts +97 -0
  153. package/src/iso-editor/ui/dialog.ts +25 -0
  154. package/src/iso-editor/ui/flat-canvas.ts +51 -0
  155. package/src/iso-editor/ui/icons.ts +21 -0
  156. package/src/iso-editor/ui/keys.ts +30 -0
  157. package/src/iso-editor/ui/later.ts +22 -0
  158. package/src/iso-editor/ui/layer.ts +7 -0
  159. package/src/iso-editor/ui/marks.css +39 -0
  160. package/src/iso-editor/ui/menu.ts +67 -0
  161. package/src/iso-editor/ui/monaco-entry.ts +6 -0
  162. package/src/iso-editor/ui/mount-kit.ts +35 -0
  163. package/src/iso-editor/ui/mount.ts +684 -0
  164. package/src/iso-editor/ui/pane.ts +45 -0
  165. package/src/iso-editor/ui/part.ts +45 -0
  166. package/src/iso-editor/ui/plain-icons.ts +83 -0
  167. package/src/iso-editor/ui/props.ts +347 -0
  168. package/src/iso-editor/ui/scope-css.ts +65 -0
  169. package/src/iso-editor/ui/setup.ts +153 -0
  170. package/src/iso-editor/ui/skin.css +181 -0
  171. package/src/iso-editor/ui/text.ts +262 -0
  172. package/src/iso-editor/ui/tree.ts +657 -0
  173. package/src/iso-editor/validate.ts +62 -0
  174. package/src/iso-editor/window/protocol.ts +33 -0
  175. package/src/iso-objects/assemble.ts +57 -0
  176. package/src/iso-objects/assets.ts +122 -0
  177. package/src/iso-objects/board.ts +169 -0
  178. package/src/iso-objects/compile.ts +76 -0
  179. package/src/iso-objects/css.ts +163 -0
  180. package/src/iso-objects/flat.ts +653 -0
  181. package/src/iso-objects/focus.ts +14 -0
  182. package/src/iso-objects/geometry.ts +86 -0
  183. package/src/iso-objects/index.ts +33 -0
  184. package/src/iso-objects/kinds.ts +56 -0
  185. package/src/iso-objects/labels.ts +310 -0
  186. package/src/iso-objects/package.json +6 -0
  187. package/src/iso-objects/place.ts +318 -0
  188. package/src/iso-objects/route.ts +444 -0
  189. package/src/iso-objects/scene.ts +376 -0
  190. package/src/iso-objects/steps.ts +234 -0
  191. package/src/iso-objects/types.ts +68 -0
  192. package/src/iso-systems/catalog.ts +31 -0
  193. package/src/iso-systems/compile.ts +39 -0
  194. package/src/iso-systems/css.ts +9 -0
  195. package/src/iso-systems/index.ts +12 -0
  196. package/src/iso-systems/nodes.ts +126 -0
  197. package/src/iso-systems/package.json +6 -0
  198. package/src/iso-systems/schema.json +311 -0
  199. package/src/iso-systems/validate.ts +34 -0
  200. package/src/iso-viewer/bundle.ts +15 -0
  201. package/src/iso-viewer/card-motion.ts +237 -0
  202. package/src/iso-viewer/dom.ts +13 -0
  203. package/src/iso-viewer/dual-view.ts +212 -0
  204. package/src/iso-viewer/flat-view.ts +127 -0
  205. package/src/iso-viewer/history.ts +781 -0
  206. package/src/iso-viewer/index.ts +40 -0
  207. package/src/iso-viewer/morph.ts +191 -0
  208. package/src/iso-viewer/overlay.ts +212 -0
  209. package/src/iso-viewer/package.json +6 -0
  210. package/src/iso-viewer/page.ts +150 -0
  211. package/src/iso-viewer/player.ts +321 -0
  212. package/src/iso-viewer/still.ts +74 -0
  213. package/src/iso-viewer/timeline-contract.ts +342 -0
  214. package/src/iso-viewer/timeline-engine.ts +420 -0
  215. package/src/iso-viewer/timeline-export.ts +31 -0
  216. package/src/iso-viewer/timeline-scale.ts +129 -0
  217. package/src/iso-viewer/timeline-scope.ts +56 -0
  218. package/src/iso-viewer/timeline-search.ts +198 -0
  219. package/src/iso-viewer/timeline-time.ts +54 -0
  220. package/src/iso-viewer/view-css.ts +59 -0
  221. package/src/iso-viewer/viewport.ts +142 -0
  222. package/types/iso-core/compile-schema.d.ts +11 -0
  223. package/types/iso-core/depth.d.ts +6 -0
  224. package/types/iso-core/errors.d.ts +24 -0
  225. package/types/iso-core/glyphs.d.ts +19 -0
  226. package/types/iso-core/index.d.ts +17 -0
  227. package/types/iso-core/kernel.d.ts +130 -0
  228. package/types/iso-core/metrics.json +1 -0
  229. package/types/iso-core/parse.d.ts +18 -0
  230. package/types/iso-core/schema-errors.d.ts +14 -0
  231. package/types/iso-core/shims/crypto.d.ts +9 -0
  232. package/types/iso-core/svg-dom.d.ts +15 -0
  233. package/types/iso-core/theme.d.ts +38 -0
  234. package/types/iso-core/vdom.d.ts +26 -0
  235. package/types/iso-editor/adapter.d.ts +178 -0
  236. package/types/iso-editor/clipboard.d.ts +23 -0
  237. package/types/iso-editor/commands.d.ts +32 -0
  238. package/types/iso-editor/complete.d.ts +25 -0
  239. package/types/iso-editor/doc.d.ts +50 -0
  240. package/types/iso-editor/index.d.ts +57 -0
  241. package/types/iso-editor/model.d.ts +96 -0
  242. package/types/iso-editor/outline.d.ts +28 -0
  243. package/types/iso-editor/path.d.ts +7 -0
  244. package/types/iso-editor/providers.d.ts +43 -0
  245. package/types/iso-editor/schema-nav.d.ts +34 -0
  246. package/types/iso-editor/splice.d.ts +53 -0
  247. package/types/iso-editor/storage-keys.d.ts +5 -0
  248. package/types/iso-editor/ui/actions.d.ts +23 -0
  249. package/types/iso-editor/ui/canvas-layer.d.ts +65 -0
  250. package/types/iso-editor/ui/canvas.d.ts +307 -0
  251. package/types/iso-editor/ui/clip.d.ts +14 -0
  252. package/types/iso-editor/ui/dialog.d.ts +7 -0
  253. package/types/iso-editor/ui/flat-canvas.d.ts +2 -0
  254. package/types/iso-editor/ui/icons.d.ts +5 -0
  255. package/types/iso-editor/ui/keys.d.ts +7 -0
  256. package/types/iso-editor/ui/later.d.ts +12 -0
  257. package/types/iso-editor/ui/layer.d.ts +2 -0
  258. package/types/iso-editor/ui/menu.d.ts +21 -0
  259. package/types/iso-editor/ui/mount-kit.d.ts +31 -0
  260. package/types/iso-editor/ui/mount.d.ts +146 -0
  261. package/types/iso-editor/ui/pane.d.ts +60 -0
  262. package/types/iso-editor/ui/part.d.ts +40 -0
  263. package/types/iso-editor/ui/plain-icons.d.ts +10 -0
  264. package/types/iso-editor/ui/props.d.ts +57 -0
  265. package/types/iso-editor/ui/scope-css.d.ts +5 -0
  266. package/types/iso-editor/ui/setup.d.ts +49 -0
  267. package/types/iso-editor/ui/text.d.ts +19 -0
  268. package/types/iso-editor/ui/tree.d.ts +100 -0
  269. package/types/iso-editor/validate.d.ts +36 -0
  270. package/types/iso-editor/window/protocol.d.ts +60 -0
  271. package/types/iso-objects/assemble.d.ts +35 -0
  272. package/types/iso-objects/assets.d.ts +49 -0
  273. package/types/iso-objects/board.d.ts +36 -0
  274. package/types/iso-objects/compile.d.ts +35 -0
  275. package/types/iso-objects/css.d.ts +16 -0
  276. package/types/iso-objects/flat.d.ts +130 -0
  277. package/types/iso-objects/focus.d.ts +1 -0
  278. package/types/iso-objects/geometry.d.ts +59 -0
  279. package/types/iso-objects/index.d.ts +26 -0
  280. package/types/iso-objects/kinds.d.ts +53 -0
  281. package/types/iso-objects/labels.d.ts +92 -0
  282. package/types/iso-objects/place.d.ts +25 -0
  283. package/types/iso-objects/route.d.ts +67 -0
  284. package/types/iso-objects/scene.d.ts +63 -0
  285. package/types/iso-objects/steps.d.ts +90 -0
  286. package/types/iso-objects/types.d.ts +140 -0
  287. package/types/iso-systems/catalog.d.ts +4 -0
  288. package/types/iso-systems/compile.d.ts +6 -0
  289. package/types/iso-systems/css.d.ts +3 -0
  290. package/types/iso-systems/index.d.ts +5 -0
  291. package/types/iso-systems/nodes.d.ts +3 -0
  292. package/types/iso-viewer/card-motion.d.ts +56 -0
  293. package/types/iso-viewer/dom.d.ts +1 -0
  294. package/types/iso-viewer/dual-view.d.ts +44 -0
  295. package/types/iso-viewer/flat-view.d.ts +25 -0
  296. package/types/iso-viewer/history.d.ts +91 -0
  297. package/types/iso-viewer/index.d.ts +31 -0
  298. package/types/iso-viewer/morph.d.ts +28 -0
  299. package/types/iso-viewer/overlay.d.ts +135 -0
  300. package/types/iso-viewer/page.d.ts +13 -0
  301. package/types/iso-viewer/still.d.ts +26 -0
  302. package/types/iso-viewer/timeline-contract.d.ts +345 -0
  303. package/types/iso-viewer/timeline-engine.d.ts +20 -0
  304. package/types/iso-viewer/timeline-export.d.ts +5 -0
  305. package/types/iso-viewer/timeline-scale.d.ts +44 -0
  306. package/types/iso-viewer/timeline-scope.d.ts +33 -0
  307. package/types/iso-viewer/timeline-search.d.ts +52 -0
  308. package/types/iso-viewer/timeline-time.d.ts +8 -0
  309. package/types/iso-viewer/view-css.d.ts +7 -0
  310. package/types/iso-viewer/viewport.d.ts +50 -0
@@ -0,0 +1,347 @@
1
+ import { regionKind, nodeKind, nodeKindOr, wallHeight } from "./kinds.js";
2
+ import { didYouMean } from "../iso-core/errors.js";
3
+ const WALL_T = 0.16;
4
+ const REL = ["right-of", "left-of", "below", "behind"];
5
+ function place(scene, scenePath, src, theme, catalog, fileRoles = {}, snap) {
6
+ const diags = [];
7
+ const err = (path, message, hint, key = false, severity = "error") => {
8
+ const p = src.locate(path, { key });
9
+ diags.push({ severity, message, line: p.line, col: p.col, path, hint });
10
+ };
11
+ const items = [];
12
+ const byId = /* @__PURE__ */ new Map();
13
+ const roots = [];
14
+ const local = /* @__PURE__ */ new Map();
15
+ const roles = /* @__PURE__ */ new Set([...Object.keys(theme.roles), ...Object.keys(fileRoles)]);
16
+ function add(p, parent) {
17
+ const prev = byId.get(p.id);
18
+ if (prev) {
19
+ const at = src.locate(prev.path + "/id");
20
+ err(p.path + "/id", `duplicate id "${p.id}" (first used on line ${at.line})`);
21
+ return false;
22
+ }
23
+ byId.set(p.id, p);
24
+ items.push(p);
25
+ p.parent = parent;
26
+ if (parent) parent.children.push(p);
27
+ else roots.push(p);
28
+ return true;
29
+ }
30
+ const blank = () => ({ x0: 0, y0: 0, z0: 0, x1: 0, y1: 0, z1: 0 });
31
+ function addNode(n, path, parent) {
32
+ const p = { id: n.id, type: "node", path, children: [], box: blank(), floor: 0, node: n, appears: n.appears, disappears: n.disappears };
33
+ if (!add(p, parent)) return;
34
+ (n.nodes ?? []).forEach((c, i) => addNode(c, `${path}/nodes/${i}`, p));
35
+ }
36
+ function addRegion(r, path, parent) {
37
+ const p = { id: r.id, type: "region", path, children: [], box: blank(), floor: 0, region: r, appears: r.appears, disappears: r.disappears };
38
+ if (!add(p, parent)) return;
39
+ (r.nodes ?? []).forEach((c, i) => addNode(c, `${path}/nodes/${i}`, p));
40
+ (r.regions ?? []).forEach((c, i) => addRegion(c, `${path}/regions/${i}`, p));
41
+ }
42
+ (scene.regions ?? []).forEach((r, i) => addRegion(r, `${scenePath}/regions/${i}`, void 0));
43
+ (scene.nodes ?? []).forEach((n, i) => addNode(n, `${scenePath}/nodes/${i}`, void 0));
44
+ const ids = () => byId.keys();
45
+ const regionIds = () => items.filter((i) => i.type === "region").map((i) => i.id);
46
+ for (const p of [...items]) {
47
+ const raw = p.node ?? p.region;
48
+ if (raw.in !== void 0) {
49
+ const target = byId.get(raw.in);
50
+ if (!target) {
51
+ err(p.path + "/in", `unknown region "${raw.in}"` + hintFor(raw.in, regionIds()));
52
+ continue;
53
+ }
54
+ if (target.type !== "region") {
55
+ err(p.path + "/in", `"${raw.in}" is a node, not a region; put nodes on a node with its own "nodes:" list`);
56
+ continue;
57
+ }
58
+ if (p.parent && p.parent !== target) {
59
+ err(p.path + "/in", `"${p.id}" is written inside "${p.parent.id}" but says in: ${raw.in}; use one or the other`);
60
+ continue;
61
+ }
62
+ for (let a = target; a; a = a.parent) if (a === p) {
63
+ err(p.path + "/in", `"${p.id}" cannot be inside itself`);
64
+ continue;
65
+ }
66
+ if (!p.parent) {
67
+ roots.splice(roots.indexOf(p), 1);
68
+ p.parent = target;
69
+ target.children.push(p);
70
+ }
71
+ }
72
+ if (p.node) {
73
+ const a = p.node.asset;
74
+ if (a !== void 0 && !nodeKind(catalog, a)) err(p.path + "/asset", `unknown asset "${a}"` + hintFor(a, Object.keys(catalog.nodes)), `assets: ${Object.keys(catalog.nodes).join(", ")}`);
75
+ }
76
+ const role = (p.node ?? p.region).role;
77
+ if (role !== void 0 && !roles.has(role)) err(p.path + "/role", `unknown colour role "${role}"` + hintFor(role, roles), `add it under "roles:" at the top of the file, or use one of: ${[...roles].join(", ")}`);
78
+ }
79
+ for (const p of items) {
80
+ const g = p.region?.gate;
81
+ if (!g?.node) continue;
82
+ const gn = byId.get(g.node);
83
+ if (!gn) {
84
+ err(p.path + "/gate/node", `unknown node "${g.node}"` + hintFor(g.node, ids()));
85
+ continue;
86
+ }
87
+ if (gn.type !== "node") {
88
+ err(p.path + "/gate/node", `"${g.node}" is a region; a gate is a node`);
89
+ continue;
90
+ }
91
+ gn.placedBy = p.id;
92
+ const n = gn.node;
93
+ if (n.at || REL.some((r) => n[r])) err(gn.path, `"${gn.id}" is the gate of "${p.id}", which places it; its own placement is ignored`, void 0, false, "warning");
94
+ }
95
+ const gapOf = (raw) => raw.gap ?? scene.gap ?? 2;
96
+ function nodeSize(p) {
97
+ const n = p.node, a = nodeKindOr(catalog, n.asset);
98
+ const s = n.size;
99
+ let w = a.size[0], d = a.size[1], h = a.size[2];
100
+ if (s) {
101
+ w = s[0];
102
+ d = s[1];
103
+ if (s.length > 2) h = s[2];
104
+ }
105
+ if (p.placedBy) {
106
+ const walled = byId.get(p.placedBy).region, g = walled.gate;
107
+ const span = g.width ?? 2, thick = s ? Math.min(w, d) : 0.3;
108
+ h = s && s.length > 2 ? h : g.height ?? (walled.height ?? wallHeight(catalog)) + 0.3;
109
+ if (g.side === "e" || g.side === "w") {
110
+ w = thick;
111
+ d = span;
112
+ } else {
113
+ w = span;
114
+ d = thick;
115
+ }
116
+ }
117
+ return [w, d, h];
118
+ }
119
+ function layoutContainer(c, kids, padding, flow, fixed) {
120
+ for (const k of kids) layoutItem(k);
121
+ const placed = kids.filter((k) => !k.placedBy);
122
+ const sib = new Set(placed);
123
+ const done = /* @__PURE__ */ new Set();
124
+ const order = [];
125
+ const visiting = /* @__PURE__ */ new Set();
126
+ const deps = (k) => {
127
+ const raw = k.node ?? k.region, out2 = [];
128
+ for (const r of REL) {
129
+ const t = raw[r];
130
+ if (t === void 0) continue;
131
+ const tp = byId.get(t);
132
+ if (!tp) {
133
+ err(`${k.path}/${r}`, `unknown id "${t}"` + hintFor(t, ids()));
134
+ continue;
135
+ }
136
+ if (tp === k) {
137
+ err(`${k.path}/${r}`, `"${k.id}" cannot be placed ${r} itself`);
138
+ continue;
139
+ }
140
+ if (!sib.has(tp)) {
141
+ const where = (x) => x.parent ? `"${x.parent.id}"` : "the scene";
142
+ err(
143
+ `${k.path}/${r}`,
144
+ `"${t}" is in ${where(tp)} but "${k.id}" is in ${where(k)}; relative placement works between items in the same region`,
145
+ tp.placedBy ? `"${t}" is a gate, placed by its ${byId.get(tp.placedBy)?.region?.kind ?? "region"}` : `place "${k.id}" relative to something in ${where(k)}, or use "at:"`
146
+ );
147
+ continue;
148
+ }
149
+ out2.push(tp);
150
+ }
151
+ if (!out2.length && !raw.at) {
152
+ const i = placed.indexOf(k);
153
+ if (i > 0) out2.push(placed[i - 1]);
154
+ }
155
+ return out2;
156
+ };
157
+ const visit = (k) => {
158
+ if (done.has(k)) return;
159
+ if (visiting.has(k)) {
160
+ err(k.path, `placement loop: "${k.id}" is placed relative to something placed relative to it`);
161
+ return;
162
+ }
163
+ visiting.add(k);
164
+ deps(k).forEach(visit);
165
+ visiting.delete(k);
166
+ done.add(k);
167
+ order.push(k);
168
+ };
169
+ placed.forEach(visit);
170
+ for (const k of order) {
171
+ const raw = k.node ?? k.region, L = local.get(k);
172
+ const rel = REL.find((r) => raw[r] !== void 0 && byId.get(raw[r]) && sib.has(byId.get(raw[r])));
173
+ if (raw.at && rel) err(`${k.path}/at`, `"${k.id}" has both "at" and "${rel}"; "at" wins`, void 0, true, "warning");
174
+ if (raw.at) {
175
+ L.x = raw.at[0];
176
+ L.y = raw.at[1];
177
+ } else if (rel) relTo(L, local.get(byId.get(raw[rel])), rel, gapOf(raw), raw.align ?? "center");
178
+ else {
179
+ const i = placed.indexOf(k);
180
+ if (i > 0) relTo(L, local.get(placed[i - 1]), flow === "row" ? "right-of" : "below", gapOf(raw), "center");
181
+ else {
182
+ L.x = padding;
183
+ L.y = padding;
184
+ }
185
+ }
186
+ if (raw.shift) {
187
+ L.x += raw.shift[0];
188
+ L.y += raw.shift[1];
189
+ }
190
+ }
191
+ if (fixed || !placed.length) return { w: 0, d: 0 };
192
+ let mx = Infinity, my = Infinity, Mx = -Infinity, My = -Infinity;
193
+ for (const k of placed) {
194
+ const L = local.get(k);
195
+ mx = Math.min(mx, L.x);
196
+ my = Math.min(my, L.y);
197
+ Mx = Math.max(Mx, L.x + L.w);
198
+ My = Math.max(My, L.y + L.d);
199
+ }
200
+ const sx = Math.min(0, mx - padding), sy = Math.min(0, my - padding);
201
+ if (sx || sy) for (const k of placed) {
202
+ const L = local.get(k);
203
+ L.x -= sx;
204
+ L.y -= sy;
205
+ }
206
+ void c;
207
+ return { w: Mx - sx + padding, d: My - sy + padding };
208
+ }
209
+ function relTo(L, T, r, gap, align) {
210
+ const alignY = () => {
211
+ L.y = align === "start" ? T.y : align === "end" ? T.y + T.d - L.d : T.y + (T.d - L.d) / 2;
212
+ };
213
+ const alignX = () => {
214
+ L.x = align === "start" ? T.x : align === "end" ? T.x + T.w - L.w : T.x + (T.w - L.w) / 2;
215
+ };
216
+ if (r === "right-of") {
217
+ L.x = T.x + T.w + gap;
218
+ alignY();
219
+ } else if (r === "left-of") {
220
+ L.x = T.x - gap - L.w;
221
+ alignY();
222
+ } else if (r === "below") {
223
+ L.y = T.y + T.d + gap;
224
+ alignX();
225
+ } else {
226
+ L.y = T.y - gap - L.d;
227
+ alignX();
228
+ }
229
+ }
230
+ function layoutItem(p) {
231
+ if (p.type === "node") {
232
+ const [w2, d2, h2] = nodeSize(p);
233
+ local.set(p, { x: 0, y: 0, w: w2, d: d2, h: h2, z: p.node.z ?? 0 });
234
+ if (p.children.length) layoutContainer(p, p.children, 0, "row", true);
235
+ return;
236
+ }
237
+ const r = p.region;
238
+ const pad = r.padding ?? regionKind(catalog, r.kind)?.pad;
239
+ const fixed = !!r.size;
240
+ const fit = layoutContainer(p, p.children, pad, r.flow ?? "row", fixed);
241
+ let w = r.size ? r.size[0] : Math.max(fit.w, pad * 2 + 0.5);
242
+ let d = r.size ? r.size[1] : Math.max(fit.d, pad * 2 + 0.5);
243
+ if (!r.size && r.gate) {
244
+ const need = (r.gate.width ?? 2) + 1;
245
+ if (r.gate.side === "e" || r.gate.side === "w") d = Math.max(d, need);
246
+ else w = Math.max(w, need);
247
+ }
248
+ const h = r.size && r.size.length > 2 ? r.size[2] : r.height ?? regionKind(catalog, r.kind).z[1];
249
+ local.set(p, { x: 0, y: 0, w, d, h, z: 0 });
250
+ }
251
+ layoutContainer(void 0, roots, 0, scene.flow ?? "row", true);
252
+ function absolute(p, ox, oy, floor) {
253
+ const L = local.get(p);
254
+ const x0 = ox + L.x, y0 = oy + L.y;
255
+ if (p.type === "region") {
256
+ const rk = regionKind(catalog, p.region.kind), [dz0] = rk.z, onTop = rk.floor;
257
+ const dz = rk.shape === "slab" && regionKind(catalog, p.parent?.region?.kind)?.shape === "slab" ? 0 : dz0;
258
+ const lift = p.region.z ?? 0;
259
+ const z0 = floor + dz + lift, z1 = floor + L.h + lift;
260
+ p.box = { x0, y0, z0, x1: x0 + L.w, y1: y0 + L.d, z1 };
261
+ p.floor = onTop ? z1 : floor;
262
+ } else {
263
+ const z0 = floor + L.z;
264
+ p.box = { x0, y0, z0, x1: x0 + L.w, y1: y0 + L.d, z1: z0 + L.h };
265
+ p.floor = p.box.z1;
266
+ }
267
+ for (const k of p.children) if (!k.placedBy) absolute(k, x0, y0, p.floor);
268
+ }
269
+ for (const r of roots) if (!r.placedBy) absolute(r, 0, 0, 0);
270
+ if (snap) {
271
+ const q = (v) => Math.round(v / snap) * snap;
272
+ const fix = (v) => Math.round(v * 1e9) / 1e9;
273
+ for (const p of items) {
274
+ if (p.placedBy) continue;
275
+ const b = p.box;
276
+ let x0 = q(b.x0), x1 = q(b.x1), y0 = q(b.y0), y1 = q(b.y1);
277
+ if (x1 - x0 < snap) x1 = x0 + snap;
278
+ if (y1 - y0 < snap) y1 = y0 + snap;
279
+ p.box = { ...b, x0: fix(x0), x1: fix(x1), y0: fix(y0), y1: fix(y1) };
280
+ const raw = p.node ?? p.region;
281
+ if (raw.at) raw.at.forEach((v, i) => {
282
+ const r = v / snap;
283
+ if (Math.abs(r - Math.round(r)) > 1e-6) err(`${p.path}/at/${i}`, `${v} is not on the ${snap} grid; it is drawn at ${fix(q(v))}`, void 0, false, "warning");
284
+ });
285
+ }
286
+ }
287
+ for (const f of items) {
288
+ const g = f.region?.gate;
289
+ if (!g?.node) continue;
290
+ const gn = byId.get(g.node);
291
+ if (!gn || gn.placedBy !== f.id) continue;
292
+ gn.box = gateBox(f, local.get(gn).h, local.get(gn).w, local.get(gn).d);
293
+ gn.floor = gn.box.z1;
294
+ }
295
+ for (const p of items) {
296
+ const kids = p.children.filter((k) => !k.placedBy);
297
+ for (let i = 0; i < kids.length; i++) for (let j = i + 1; j < kids.length; j++) {
298
+ const a = kids[i], b = kids[j];
299
+ if (passive(a, catalog) || passive(b, catalog)) continue;
300
+ if (overlap2(a.box, b.box)) err(b.path, `"${b.id}" overlaps "${a.id}"`, `move one with "at", a relative placement, "gap" or "shift"`, false, "warning");
301
+ }
302
+ if (p.parent && p.parent.type === "region" && !p.placedBy) {
303
+ const r = p.parent.box, b = p.box, e = 1e-6;
304
+ if (b.x0 < r.x0 - e || b.y0 < r.y0 - e || b.x1 > r.x1 + e || b.y1 > r.y1 + e) err(p.path, `"${p.id}" sticks out of region "${p.parent.id}"`, `make "${p.parent.id}" bigger, or leave out its "size" so it fits its contents`, false, "warning");
305
+ }
306
+ }
307
+ {
308
+ const top = roots.filter((x) => !x.placedBy);
309
+ for (let i = 0; i < top.length; i++) for (let j = i + 1; j < top.length; j++) {
310
+ const a = top[i], b = top[j];
311
+ if (overlap2(a.box, b.box) && !passive(a, catalog) && !passive(b, catalog))
312
+ err(b.path, `"${b.id}" overlaps "${a.id}"`, `move one with "at", a relative placement, "gap" or "shift"`, false, "warning");
313
+ }
314
+ }
315
+ const seen = /* @__PURE__ */ new Set();
316
+ const out = diags.filter((d) => {
317
+ const k = d.path + d.message;
318
+ if (seen.has(k)) return false;
319
+ seen.add(k);
320
+ return true;
321
+ });
322
+ return { items, byId, roots, diags: out, catalog };
323
+ }
324
+ const passive = (p, cat) => p.type === "region" && ["zone", "tunnel"].includes(regionKind(cat, p.region.kind)?.shape ?? "");
325
+ function gateBox(f, h, w, d) {
326
+ const g = f.region.gate, b = f.box, base = f.box.z0;
327
+ const at = g.at ?? 0.5, span = g.width ?? 2;
328
+ if (g.side === "w" || g.side === "e") {
329
+ const x = g.side === "w" ? b.x0 + WALL_T / 2 : b.x1 - WALL_T / 2, cy = b.y0 + (b.y1 - b.y0) * at;
330
+ return { x0: x - w / 2, x1: x + w / 2, y0: cy - span / 2, y1: cy + span / 2, z0: base, z1: base + h };
331
+ }
332
+ const y = g.side === "n" ? b.y0 + WALL_T / 2 : b.y1 - WALL_T / 2, cx = b.x0 + (b.x1 - b.x0) * at;
333
+ return { x0: cx - span / 2, x1: cx + span / 2, y0: y - d / 2, y1: y + d / 2, z0: base, z1: base + h };
334
+ }
335
+ function overlap2(a, b, e = 1e-6) {
336
+ return a.x0 < b.x1 - e && b.x0 < a.x1 - e && a.y0 < b.y1 - e && b.y0 < a.y1 - e;
337
+ }
338
+ function hintFor(word, candidates) {
339
+ const d = didYouMean(word, candidates);
340
+ return d ? ` (did you mean "${d}"?)` : "";
341
+ }
342
+ export {
343
+ WALL_T,
344
+ gateBox,
345
+ overlap2,
346
+ place
347
+ };