@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.
Files changed (310) hide show
  1. package/EDITOR-GUIDE.md +317 -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 +265 -0
  8. package/assets/default-theme.yaml +99 -0
  9. package/assets/icons.svg +1 -0
  10. package/assets/marks.css +35 -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 +441 -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 +1205 -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 +145 -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 +502 -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 +128 -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 +472 -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 +1071 -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 +35 -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 +144 -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 +145 -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 +279 -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 +40 -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,16 @@
1
+ function focusView(full, box) {
2
+ if (!box) return full;
3
+ const [x0, y0, x1, y1] = box, ar = full[2] / full[3];
4
+ let w = x1 - x0, h = y1 - y0;
5
+ if (w / h < ar) w = h * ar;
6
+ else h = w / ar;
7
+ w = Math.min(w, full[2]);
8
+ h = Math.min(h, full[3]);
9
+ const cx = (x0 + x1) / 2, cy = (y0 + y1) / 2;
10
+ const x = Math.max(full[0], Math.min(full[0] + full[2] - w, cx - w / 2));
11
+ const y = Math.max(full[1], Math.min(full[1] + full[3] - h, cy - h / 2));
12
+ return [x, y, w, h];
13
+ }
14
+ export {
15
+ focusView
16
+ };
@@ -0,0 +1,76 @@
1
+ import { C, S, iso } from "../iso-core/kernel.js";
2
+ import { regionKind } from "./kinds.js";
3
+ function screenToGrid(dx, dy) {
4
+ const a = dx / (C * S), b = 2 * dy / S;
5
+ return [(a + b) / 2, (b - a) / 2];
6
+ }
7
+ function localAt(sc, id) {
8
+ const p = sc.layout.byId.get(id);
9
+ if (!p) return void 0;
10
+ const o = p.parent ? [p.parent.box.x0, p.parent.box.y0] : [0, 0];
11
+ return [p.box.x0 - o[0], p.box.y0 - o[1]];
12
+ }
13
+ function boxSilhouette(b) {
14
+ const pts = [];
15
+ for (const x of [b.x0, b.x1]) for (const y of [b.y0, b.y1]) for (const z of [b.z0, b.z1]) pts.push(iso(x, y, z));
16
+ return hull(pts);
17
+ }
18
+ function floorOf(b) {
19
+ return [[b.x0, b.y0], [b.x1, b.y0], [b.x1, b.y1], [b.x0, b.y1]].map(([x, y]) => iso(x, y, b.z0));
20
+ }
21
+ function hull(p) {
22
+ const pts = [...new Map(p.map((q) => [`${q[0].toFixed(3)},${q[1].toFixed(3)}`, q])).values()].sort((a, b) => a[0] - b[0] || a[1] - b[1]);
23
+ if (pts.length < 3) return pts;
24
+ const cross = (o, a, b) => (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0]);
25
+ const lo = [], hi = [];
26
+ for (const q of pts) {
27
+ while (lo.length >= 2 && cross(lo[lo.length - 2], lo[lo.length - 1], q) <= 1e-9) lo.pop();
28
+ lo.push(q);
29
+ }
30
+ for (const q of [...pts].reverse()) {
31
+ while (hi.length >= 2 && cross(hi[hi.length - 2], hi[hi.length - 1], q) <= 1e-9) hi.pop();
32
+ hi.push(q);
33
+ }
34
+ return [...lo.slice(0, -1), ...hi.slice(0, -1)];
35
+ }
36
+ const paddingOf = (cat, region) => region?.padding ?? regionKind(cat, region?.kind)?.pad ?? 0;
37
+ function snapMove(start, d, step, size, parent) {
38
+ const snap = (v) => Math.round(v / step) * step;
39
+ let x = snap(start[0] + d[0]), y = snap(start[1] + d[1]);
40
+ const clamped = { left: false, right: false, top: false, bottom: false };
41
+ if (parent) {
42
+ const lo = Math.ceil(parent.pad / step - 1e-9) * step;
43
+ const hiX = Math.floor((parent.w - parent.pad - size[0]) / step + 1e-9) * step, hiY = Math.floor((parent.d - parent.pad - size[1]) / step + 1e-9) * step;
44
+ if (x < lo) {
45
+ x = lo;
46
+ clamped.left = true;
47
+ }
48
+ if (hiX >= lo && x > hiX) {
49
+ x = hiX;
50
+ clamped.right = true;
51
+ }
52
+ if (y < lo) {
53
+ y = lo;
54
+ clamped.top = true;
55
+ }
56
+ if (hiY >= lo && y > hiY) {
57
+ y = hiY;
58
+ clamped.bottom = true;
59
+ }
60
+ }
61
+ const r = (v) => Math.round(v * 1e3) / 1e3;
62
+ return { at: [r(x), r(y)], delta: [r(x - start[0]), r(y - start[1])], clamped };
63
+ }
64
+ function overlaps(a, others) {
65
+ const e = 1e-6;
66
+ return others.some((b) => a.x0 < b.x1 - e && a.x1 > b.x0 + e && a.y0 < b.y1 - e && a.y1 > b.y0 + e);
67
+ }
68
+ export {
69
+ boxSilhouette,
70
+ floorOf,
71
+ localAt,
72
+ overlaps,
73
+ paddingOf,
74
+ screenToGrid,
75
+ snapMove
76
+ };
@@ -0,0 +1,93 @@
1
+ import { regionKind, nodeKind, nodeKindOr, wallHeight, kindsCss } from "./kinds.js";
2
+ import { drawDecos, boxAsset, plate, cloudPath, drawCloud, defaultLabel, registerMarks, markCss, iconPainter, facePainter, placeholderIcon } from "./assets.js";
3
+ import { WALL_T, place, gateBox, overlap2 } from "./place.js";
4
+ import { parseEnd, floorAt, ROUTE_BUDGET, routeAll, openList, simplify } from "./route.js";
5
+ import { silhouette, polyBounds, polyRectArea, rectArea, lineRectArea, Obstacles, labelRect, placeNodeLabel, calloutRect, placeCallout, inConvex, convexOverlap } from "./labels.js";
6
+ import { offscreen, assembly } from "./assemble.js";
7
+ import { durationFor, resolveSteps, midpoint } from "./steps.js";
8
+ import { focusView } from "./focus.js";
9
+ import { regionRole, renderScene, wallsOf, LABEL_BUDGET } from "./scene.js";
10
+ import { PAGE_CSS, drawingCss, baseCss, MARKS_CSS, PLAYER_UI_CSS, GRID_CSS, PLAYER_CSS } from "./css.js";
11
+ import { noSource, compileRaw } from "./compile.js";
12
+ import { screenToGrid, localAt, boxSilhouette, floorOf, paddingOf, snapMove, overlaps } from "./geometry.js";
13
+ import { FLAT_DEFAULTS, FLAT_FONTS, metricsMeasure, boardErrors, placeBoard, layoutFlat, flatHit } from "./flat.js";
14
+ import { boardOf, BOARD_3D, BOARD_CSS, cardAsset, boardCatalog, boardDiagram } from "./board.js";
15
+ export {
16
+ BOARD_3D,
17
+ BOARD_CSS,
18
+ FLAT_DEFAULTS,
19
+ FLAT_FONTS,
20
+ GRID_CSS,
21
+ LABEL_BUDGET,
22
+ MARKS_CSS,
23
+ Obstacles,
24
+ PAGE_CSS,
25
+ PLAYER_CSS,
26
+ PLAYER_UI_CSS,
27
+ ROUTE_BUDGET,
28
+ WALL_T,
29
+ assembly,
30
+ baseCss,
31
+ boardCatalog,
32
+ boardDiagram,
33
+ boardErrors,
34
+ boardOf,
35
+ boxAsset,
36
+ boxSilhouette,
37
+ calloutRect,
38
+ cardAsset,
39
+ cloudPath,
40
+ compileRaw,
41
+ convexOverlap,
42
+ defaultLabel,
43
+ drawCloud,
44
+ drawDecos,
45
+ drawingCss,
46
+ durationFor,
47
+ facePainter,
48
+ flatHit,
49
+ floorAt,
50
+ floorOf,
51
+ focusView,
52
+ gateBox,
53
+ iconPainter,
54
+ inConvex,
55
+ kindsCss,
56
+ labelRect,
57
+ layoutFlat,
58
+ lineRectArea,
59
+ localAt,
60
+ markCss,
61
+ metricsMeasure,
62
+ midpoint,
63
+ noSource,
64
+ nodeKind,
65
+ nodeKindOr,
66
+ offscreen,
67
+ openList,
68
+ overlap2,
69
+ overlaps,
70
+ paddingOf,
71
+ parseEnd,
72
+ place,
73
+ placeBoard,
74
+ placeCallout,
75
+ placeNodeLabel,
76
+ placeholderIcon,
77
+ plate,
78
+ polyBounds,
79
+ polyRectArea,
80
+ rectArea,
81
+ regionKind,
82
+ regionRole,
83
+ registerMarks,
84
+ renderScene,
85
+ resolveSteps,
86
+ routeAll,
87
+ screenToGrid,
88
+ silhouette,
89
+ simplify,
90
+ snapMove,
91
+ wallHeight,
92
+ wallsOf
93
+ };
@@ -0,0 +1,12 @@
1
+ const regionKind = (cat, name) => name !== void 0 && Object.hasOwn(cat.regions, name) ? cat.regions[name] : void 0;
2
+ const nodeKind = (cat, name) => cat.nodes[name ?? cat.defaultNode];
3
+ const nodeKindOr = (cat, name) => nodeKind(cat, name) ?? cat.nodes[cat.defaultNode];
4
+ const wallHeight = (cat) => Object.values(cat.regions).find((r) => r.shape === "walled")?.z[1] ?? 0.8;
5
+ const kindsCss = (cat) => Object.values(cat.regions).map((r) => r.css ?? "").join("");
6
+ export {
7
+ kindsCss,
8
+ nodeKind,
9
+ nodeKindOr,
10
+ regionKind,
11
+ wallHeight
12
+ };
@@ -0,0 +1,325 @@
1
+ import { iso, textWidth, FONTS } from "../iso-core/kernel.js";
2
+ function silhouette(b) {
3
+ return [iso(b.x0, b.y0, b.z1), iso(b.x1, b.y0, b.z1), iso(b.x1, b.y0, b.z0), iso(b.x1, b.y1, b.z0), iso(b.x0, b.y1, b.z0), iso(b.x0, b.y1, b.z1)];
4
+ }
5
+ function polyBounds(p) {
6
+ const xs = p.map((q) => q[0]), ys = p.map((q) => q[1]);
7
+ const x = Math.min(...xs), y = Math.min(...ys);
8
+ return { x, y, w: Math.max(...xs) - x, h: Math.max(...ys) - y };
9
+ }
10
+ function polyRectArea(poly, r) {
11
+ let pts = poly;
12
+ const clip = (inside, cross) => {
13
+ const out = [];
14
+ for (let i = 0; i < pts.length; i++) {
15
+ const a2 = pts[i], b = pts[(i + 1) % pts.length];
16
+ const ia = inside(a2), ib = inside(b);
17
+ if (ia) out.push(a2);
18
+ if (ia !== ib) out.push(cross(a2, b));
19
+ }
20
+ pts = out;
21
+ };
22
+ const atX = (x) => (a2, b) => [x, a2[1] + (b[1] - a2[1]) * (x - a2[0]) / (b[0] - a2[0])];
23
+ const atY = (y) => (a2, b) => [a2[0] + (b[0] - a2[0]) * (y - a2[1]) / (b[1] - a2[1]), y];
24
+ clip((p) => p[0] >= r.x, atX(r.x));
25
+ if (!pts.length) return 0;
26
+ clip((p) => p[0] <= r.x + r.w, atX(r.x + r.w));
27
+ if (!pts.length) return 0;
28
+ clip((p) => p[1] >= r.y, atY(r.y));
29
+ if (!pts.length) return 0;
30
+ clip((p) => p[1] <= r.y + r.h, atY(r.y + r.h));
31
+ if (!pts.length) return 0;
32
+ let a = 0;
33
+ for (let i = 0; i < pts.length; i++) {
34
+ const p = pts[i], q = pts[(i + 1) % pts.length];
35
+ a += p[0] * q[1] - q[0] * p[1];
36
+ }
37
+ return Math.abs(a) / 2;
38
+ }
39
+ function rectArea(a, b) {
40
+ const w = Math.min(a.x + a.w, b.x + b.w) - Math.max(a.x, b.x), h = Math.min(a.y + a.h, b.y + b.h) - Math.max(a.y, b.y);
41
+ return w > 0 && h > 0 ? w * h : 0;
42
+ }
43
+ function lineRectArea(pts, r) {
44
+ let a = 0;
45
+ for (let i = 0; i + 1 < pts.length; i++) {
46
+ const p = pts[i], q = pts[i + 1], len = Math.hypot(q[0] - p[0], q[1] - p[1]), n = Math.max(1, Math.ceil(len / 4));
47
+ for (let j = 0; j < n; j++) {
48
+ const x = p[0] + (q[0] - p[0]) * (j + 0.5) / n, y = p[1] + (q[1] - p[1]) * (j + 0.5) / n;
49
+ if (x >= r.x && x <= r.x + r.w && y >= r.y && y <= r.y + r.h) a += len / n * 4;
50
+ }
51
+ }
52
+ return a;
53
+ }
54
+ const CELL = 64;
55
+ class Buckets {
56
+ cells = /* @__PURE__ */ new Map();
57
+ n = 0;
58
+ add(id, x0, y0, x1, y1) {
59
+ for (let cx = Math.floor(x0 / CELL); cx <= Math.floor(x1 / CELL); cx++) for (let cy = Math.floor(y0 / CELL); cy <= Math.floor(y1 / CELL); cy++) {
60
+ const k = cx * 1048576 + cy;
61
+ let list = this.cells.get(k);
62
+ if (!list) this.cells.set(k, list = []);
63
+ if (list[list.length - 1] !== id) list.push(id);
64
+ }
65
+ }
66
+ /** the ids whose buckets meet the box, ascending, each once */
67
+ query(x0, y0, x1, y1) {
68
+ const out = /* @__PURE__ */ new Set();
69
+ for (let cx = Math.floor(x0 / CELL); cx <= Math.floor(x1 / CELL); cx++) for (let cy = Math.floor(y0 / CELL); cy <= Math.floor(y1 / CELL); cy++) {
70
+ const list = this.cells.get(cx * 1048576 + cy);
71
+ if (list) for (const id of list) out.add(id);
72
+ }
73
+ return [...out].sort((p, q) => p - q);
74
+ }
75
+ }
76
+ const boundsOf = (p) => {
77
+ let x0 = Infinity, y0 = Infinity, x1 = -Infinity, y1 = -Infinity;
78
+ for (const [x, y] of p) {
79
+ if (x < x0) x0 = x;
80
+ if (x > x1) x1 = x;
81
+ if (y < y0) y0 = y;
82
+ if (y > y1) y1 = y;
83
+ }
84
+ return [x0, y0, x1, y1];
85
+ };
86
+ const indexes = /* @__PURE__ */ new WeakMap();
87
+ function indexOf(list, box) {
88
+ let ix = indexes.get(list);
89
+ if (!ix || ix.n > list.length) indexes.set(list, ix = new Buckets());
90
+ for (; ix.n < list.length; ix.n++) {
91
+ const [x0, y0, x1, y1] = box(list[ix.n]);
92
+ ix.add(ix.n, x0, y0, x1, y1);
93
+ }
94
+ return ix;
95
+ }
96
+ function segmentsOf(lines) {
97
+ let ix = indexes.get(lines);
98
+ if (!ix || ix.n > lines.length) indexes.set(lines, ix = new Buckets());
99
+ for (; ix.n < lines.length; ix.n++) {
100
+ const pts = lines[ix.n].pts;
101
+ for (let i = 0; i + 1 < pts.length; i++) {
102
+ const a = pts[i], b = pts[i + 1], id = ix.n * 65536 + i;
103
+ const k = Math.max(1, Math.ceil(Math.hypot(b[0] - a[0], b[1] - a[1]) / (CELL / 2)));
104
+ for (let m = 0; m < k; m++) {
105
+ const u0 = m / k, u1 = (m + 1) / k;
106
+ const x0 = a[0] + (b[0] - a[0]) * u0, y0 = a[1] + (b[1] - a[1]) * u0, x1 = a[0] + (b[0] - a[0]) * u1, y1 = a[1] + (b[1] - a[1]) * u1;
107
+ ix.add(id, Math.min(x0, x1) - 1, Math.min(y0, y1) - 1, Math.max(x0, x1) + 1, Math.max(y0, y1) + 1);
108
+ }
109
+ }
110
+ }
111
+ return ix;
112
+ }
113
+ const near = (ix, x0, y0, x1, y1) => ix.query(x0, y0, x1, y1);
114
+ const polyBox = (p) => boundsOf(p);
115
+ const rectBox = (r) => [r.x, r.y, r.x + r.w, r.y + r.h];
116
+ function sampleRange(a, b, n, [x0, y0, x1, y1]) {
117
+ let lo = 0, hi = n - 1;
118
+ for (const k of [0, 1]) {
119
+ const d = b[k] - a[k], min = k ? y0 : x0, max = k ? y1 : x1;
120
+ if (Math.abs(d) < 1e-12) {
121
+ if (a[k] < min || a[k] > max) return [1, 0];
122
+ continue;
123
+ }
124
+ let t0 = (min - a[k]) / d * n - 0.5, t1 = (max - a[k]) / d * n - 0.5;
125
+ if (t0 > t1) [t0, t1] = [t1, t0];
126
+ lo = Math.max(lo, Math.floor(t0) - 1);
127
+ hi = Math.min(hi, Math.ceil(t1) + 1);
128
+ }
129
+ return [lo, hi];
130
+ }
131
+ class Obstacles {
132
+ polys = [];
133
+ rects = [];
134
+ lines = [];
135
+ /** everything drawn over the floor (nodes, walls, gates): floor text under them is hidden */
136
+ solids = [];
137
+ /** text lying in a plane (floor and face labels), as parallelograms */
138
+ slants = [];
139
+ /** label spots the scene may still weigh (see LABEL_BUDGET in src/iso-objects/scene.ts); shared with forks */
140
+ budget = { spots: Infinity, over: false, told: false };
141
+ /** px² of a rectangle hidden under solids */
142
+ hidden(r) {
143
+ let c = 0;
144
+ for (const i of near(indexOf(this.solids, polyBox), ...rectBox(r))) c += polyRectArea(this.solids[i], r);
145
+ return c;
146
+ }
147
+ /** px² of a convex polygon (slanted floor text) hidden under solids */
148
+ hiddenPoly(q) {
149
+ let c = 0;
150
+ for (const i of near(indexOf(this.solids, polyBox), ...boundsOf(q))) c += convexOverlap(q, this.solids[i]);
151
+ return c;
152
+ }
153
+ /** like cost(), for a convex polygon */
154
+ costPoly(q, limit = Infinity) {
155
+ const qb = boundsOf(q);
156
+ let c = 0;
157
+ for (const i of near(indexOf(this.polys, (p) => polyBox(p.poly)), ...qb)) c += convexOverlap(q, this.polys[i].poly);
158
+ for (const i of near(indexOf(this.rects, (x) => rectBox(x.r)), ...qb)) c += polyRectArea(q, this.rects[i].r) * 2;
159
+ for (const i of near(indexOf(this.slants, polyBox), ...qb)) c += convexOverlap(q, this.slants[i]) * 2;
160
+ if (c >= limit) return c;
161
+ for (const id of near(segmentsOf(this.lines), ...qb)) {
162
+ if (c >= limit) return c;
163
+ const pts = this.lines[Math.floor(id / 65536)].pts, i = id % 65536;
164
+ const a = pts[i], b = pts[i + 1];
165
+ const len = Math.hypot(b[0] - a[0], b[1] - a[1]), n = Math.max(1, Math.ceil(len / 4));
166
+ const [j0, j1] = sampleRange(a, b, n, qb);
167
+ for (let j = j0; j <= j1; j++) if (inConvex(q, [a[0] + (b[0] - a[0]) * (j + 0.5) / n, a[1] + (b[1] - a[1]) * (j + 0.5) / n])) c += len / n * 4 * 0.6;
168
+ }
169
+ return c;
170
+ }
171
+ /** px² a rectangle shares with nodes, labels and (weighted by lineW) route lines */
172
+ cost(r, owner, lineW = 0.6) {
173
+ const rb = rectBox(r);
174
+ let c = 0;
175
+ for (const i of near(indexOf(this.polys, (p) => polyBox(p.poly)), ...rb)) {
176
+ const p = this.polys[i];
177
+ c += polyRectArea(p.poly, r) * (p.owner === owner ? 1.5 : 1);
178
+ }
179
+ for (const i of near(indexOf(this.rects, (x) => rectBox(x.r)), ...rb)) {
180
+ const q = this.rects[i];
181
+ if (q.owner !== owner || !owner) c += rectArea(q.r, r) * 2;
182
+ }
183
+ for (const i of near(indexOf(this.slants, polyBox), ...rb)) c += polyRectArea(this.slants[i], r) * 2;
184
+ if (lineW) {
185
+ let line = -1, a = 0;
186
+ for (const id of near(segmentsOf(this.lines), ...rb)) {
187
+ const li = Math.floor(id / 65536);
188
+ if (li !== line) {
189
+ if (line >= 0) c += a * lineW;
190
+ line = li;
191
+ a = 0;
192
+ }
193
+ const pts = this.lines[li].pts, i = id % 65536, p = pts[i], q = pts[i + 1];
194
+ const len = Math.hypot(q[0] - p[0], q[1] - p[1]), n = Math.max(1, Math.ceil(len / 4));
195
+ const [j0, j1] = sampleRange(p, q, n, rb);
196
+ for (let j = j0; j <= j1; j++) {
197
+ const x = p[0] + (q[0] - p[0]) * (j + 0.5) / n, y = p[1] + (q[1] - p[1]) * (j + 0.5) / n;
198
+ if (x >= r.x && x <= r.x + r.w && y >= r.y && y <= r.y + r.h) a += len / n * 4;
199
+ }
200
+ }
201
+ if (line >= 0) c += a * lineW;
202
+ }
203
+ return c;
204
+ }
205
+ /** a copy whose added rectangles do not reach this one (callouts of one step) */
206
+ fork() {
207
+ const o = new Obstacles();
208
+ o.budget = this.budget;
209
+ o.polys = this.polys;
210
+ o.lines = this.lines;
211
+ o.solids = this.solids;
212
+ o.rects = [...this.rects];
213
+ o.slants = this.slants;
214
+ return o;
215
+ }
216
+ }
217
+ const LINE = 14;
218
+ function labelRect(t, x, y, anchor) {
219
+ const w = Math.max(t.name ? textWidth(t.name, FONTS.lbl) : 0, t.sub ? textWidth(t.sub, FONTS.sub) : 0) + 4;
220
+ const lines = (t.name ? 1 : 0) + (t.sub ? 1 : 0);
221
+ const top = y - (t.name ? 11 : 9) - 1;
222
+ const h = (lines - 1) * LINE + (t.name ? 11 : 9) + 4;
223
+ const left = anchor === "start" ? x - 2 : anchor === "end" ? x - w + 2 : x - w / 2;
224
+ return { x: left, y: top, w, h };
225
+ }
226
+ function placeNodeLabel(t, box, own, obs, owner, preferred) {
227
+ const sb = polyBounds(own);
228
+ const cx = iso((box.x0 + box.x1) / 2, (box.y0 + box.y1) / 2, box.z1)[0];
229
+ const lines = (t.name ? 1 : 0) + (t.sub ? 1 : 0);
230
+ const blockBelowBaseline = (lines - 1) * LINE + 4;
231
+ const aboveY = sb.y - 6 - blockBelowBaseline;
232
+ const midY = sb.y + Math.min(sb.h, 60) * 0.45;
233
+ const cands = [];
234
+ if (preferred) cands.push({ ...preferred, pen: 0 });
235
+ cands.push({ x: cx, y: aboveY, anchor: "middle", pen: preferred ? 20 : 0 });
236
+ for (const up of [12, 24, 40]) cands.push({ x: cx, y: aboveY - up, anchor: "middle", pen: 20 + up });
237
+ for (const dx of [-30, 30, -60, 60]) cands.push({ x: cx + dx, y: aboveY - 4, anchor: "middle", pen: 30 + Math.abs(dx) });
238
+ cands.push({ x: sb.x + sb.w + 8, y: midY, anchor: "start", pen: 120 });
239
+ cands.push({ x: sb.x - 8, y: midY, anchor: "end", pen: 120 });
240
+ cands.push({ x: cx, y: sb.y + sb.h + 14, anchor: "middle", pen: 300 });
241
+ let best, bestCost = Infinity;
242
+ for (const c of cands) {
243
+ const rect = labelRect(t, c.x, c.y, c.anchor);
244
+ const cost = obs.cost(rect, owner, 0.15) * 2 + c.pen;
245
+ if (cost < bestCost) {
246
+ bestCost = cost;
247
+ best = { x: c.x, y: c.y, anchor: c.anchor, rect };
248
+ }
249
+ }
250
+ return best;
251
+ }
252
+ function calloutRect(w, x, y, anchor) {
253
+ const left = anchor === "start" ? x : anchor === "end" ? x - w : x - w / 2;
254
+ return { x: left - 2, y: y - 14, w: w + 4, h: 28 };
255
+ }
256
+ function placeCallout(w, ax, ay, preferred, obs) {
257
+ const cands = [{ ...preferred, pen: 0 }];
258
+ for (const dy of [-46, -66, -86, -106, -126, -146]) for (const dx of [0, -70, 70, -140, 140]) {
259
+ cands.push({ x: ax + dx, y: ay + dy, anchor: "middle", pen: 10 + (-dy - 46) * 0.5 + Math.abs(dx) * 0.4 });
260
+ }
261
+ for (const dy of [34, 60, 86]) cands.push({ x: ax, y: ay + dy, anchor: "middle", pen: 60 + dy * 0.3 });
262
+ const pdx = preferred.x - ax, pdy = preferred.y - ay;
263
+ for (const k of [-1, 1]) for (const d of [16, 32, 48]) cands.push({ ...preferred, y: ay + pdy + k * d, x: ax + pdx, pen: 5 + d });
264
+ for (const k of [-1, 1]) for (const d of [30, 60, 90]) for (const e of [0, 16, -16]) cands.push({ ...preferred, x: ax + pdx + k * d, y: ay + pdy + e, pen: 8 + d * 0.6 + Math.abs(e) });
265
+ let best, bestCost = Infinity;
266
+ for (const c of cands) {
267
+ const rect = calloutRect(w, c.x, c.y, c.anchor);
268
+ const cost = obs.cost(rect, void 0, 0.05) * 3 + c.pen;
269
+ if (cost < bestCost) {
270
+ bestCost = cost;
271
+ best = { x: c.x, y: c.y, anchor: c.anchor, rect };
272
+ }
273
+ }
274
+ return best;
275
+ }
276
+ const area = (p) => {
277
+ let a = 0;
278
+ for (let i = 0; i < p.length; i++) {
279
+ const u = p[i], v = p[(i + 1) % p.length];
280
+ a += u[0] * v[1] - v[0] * u[1];
281
+ }
282
+ return a / 2;
283
+ };
284
+ const ccw = (p) => area(p) < 0 ? [...p].reverse() : p;
285
+ function inConvex(poly, q) {
286
+ const p = ccw(poly);
287
+ for (let i = 0; i < p.length; i++) {
288
+ const a = p[i], b = p[(i + 1) % p.length];
289
+ if ((b[0] - a[0]) * (q[1] - a[1]) - (b[1] - a[1]) * (q[0] - a[0]) < 0) return false;
290
+ }
291
+ return true;
292
+ }
293
+ function convexOverlap(a, b) {
294
+ let out = ccw(a);
295
+ const c = ccw(b);
296
+ for (let i = 0; i < c.length && out.length; i++) {
297
+ const e0 = c[i], e1 = c[(i + 1) % c.length];
298
+ const side = (p) => (e1[0] - e0[0]) * (p[1] - e0[1]) - (e1[1] - e0[1]) * (p[0] - e0[0]);
299
+ const inp = out;
300
+ out = [];
301
+ for (let j = 0; j < inp.length; j++) {
302
+ const p = inp[j], q = inp[(j + 1) % inp.length], sp = side(p), sq = side(q);
303
+ if (sp >= 0) out.push(p);
304
+ if (sp >= 0 !== sq >= 0) {
305
+ const t = sp / (sp - sq);
306
+ out.push([p[0] + (q[0] - p[0]) * t, p[1] + (q[1] - p[1]) * t]);
307
+ }
308
+ }
309
+ }
310
+ return out.length >= 3 ? Math.abs(area(out)) : 0;
311
+ }
312
+ export {
313
+ Obstacles,
314
+ calloutRect,
315
+ convexOverlap,
316
+ inConvex,
317
+ labelRect,
318
+ lineRectArea,
319
+ placeCallout,
320
+ placeNodeLabel,
321
+ polyBounds,
322
+ polyRectArea,
323
+ rectArea,
324
+ silhouette
325
+ };
@@ -0,0 +1,6 @@
1
+ {
2
+ "//": "iso-objects (L1) has no side effects: bundles drop the modules they do not use. LAYERS.md S1, S2.",
3
+ "type": "module",
4
+ "private": true,
5
+ "sideEffects": false
6
+ }