@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,444 @@
1
+ // Routes: orthogonal paths on the floor between node sides, auto-routed around nodes, with lanes where several
2
+ // routes share a side, and steps up and down where a path crosses onto a raised region (as the references draw
3
+ // them: [12.6,2.6,zm] → [12.6,2.6,zd]).
4
+
5
+ import type { Box, P3 } from '../iso-core/kernel.ts';
6
+ import { didYouMean, type Diag } from '../iso-core/errors.ts';
7
+ import type { Placed, RawScene } from './types.ts';
8
+ import { WALL_T, type Layout, type Located } from './place.ts';
9
+ import { regionKind } from './kinds.ts';
10
+
11
+ export type Side = 'n' | 'e' | 's' | 'w' | 'top';
12
+ export interface RawRoute {
13
+ id: string; from: string; to: string; kind?: string; via?: (number[] | string)[]; points?: number[][];
14
+ lane?: number; arrow?: boolean; cross?: boolean;
15
+ label?: string | { text: string; along?: number; side?: 'left' | 'right'; at?: number[]; dir?: 'x' | 'y'; anchor?: 'start' | 'middle' | 'end' };
16
+ appears?: string | number; disappears?: string | number;
17
+ }
18
+ export interface Routed {
19
+ id: string; raw: RawRoute; path: string; kind: string;
20
+ points: P3[];
21
+ from?: Placed; to?: Placed;
22
+ }
23
+
24
+ const GRID = 0.2;
25
+ const OUT = 0.05; // ends stop this far from a face, so arrowheads show
26
+ const LANE = 0.6; // spacing of parallel routes on one side
27
+ const INFLATE = 0.25; // clearance around obstacles
28
+
29
+ interface End { node: Placed; side: Side; explicit: boolean; p: [number, number]; z: number }
30
+
31
+ const sideNormal: Record<Exclude<Side, 'top'>, [number, number]> = { n: [0, -1], s: [0, 1], e: [1, 0], w: [-1, 0] };
32
+
33
+ export function parseEnd(s: string): { id: string; side?: Side } {
34
+ const m = /^(.*?)(?:\.(n|e|s|w|top))?$/.exec(s)!;
35
+ return { id: m[1], side: m[2] as Side | undefined };
36
+ }
37
+
38
+ /** Floor height under a point: the deepest raised region containing it. */
39
+ /** the regions that make a floor (not walled ones, zones or tunnels: their kinds say floor: false), with their depth:
40
+ * per layout, once (a label's search asks for the floor under every corner of every spot it weighs, and a large
41
+ * drawing has hundreds of items) */
42
+ const floors = new WeakMap<Layout, { r: Layout['items'][number]; d: number }[]>();
43
+ export function floorAt(layout: Layout, x: number, y: number): number {
44
+ let fs = floors.get(layout);
45
+ if (!fs) {
46
+ fs = [];
47
+ for (const r of layout.items) {
48
+ if (r.type !== 'region') continue;
49
+ if (!regionKind(layout.catalog, r.region!.kind)?.floor) continue;
50
+ let d = 0; for (let a = r.parent; a; a = a.parent) d++;
51
+ fs.push({ r, d });
52
+ }
53
+ floors.set(layout, fs);
54
+ }
55
+ let best = 0, depth = -1;
56
+ for (const { r, d } of fs) {
57
+ const b = r.box, e = 1e-6;
58
+ if (x >= b.x0 - e && x <= b.x1 + e && y >= b.y0 - e && y <= b.y1 + e && d > depth) { depth = d; best = r.floor; }
59
+ }
60
+ return best;
61
+ }
62
+
63
+ function autoSide(a: Box, b: Box): Exclude<Side, 'top'> {
64
+ const ac = [(a.x0 + a.x1) / 2, (a.y0 + a.y1) / 2], bc = [(b.x0 + b.x1) / 2, (b.y0 + b.y1) / 2];
65
+ const dx = bc[0] - ac[0], dy = bc[1] - ac[1];
66
+ // prefer the axis with a clear gap between the boxes
67
+ const gapX = Math.max(b.x0 - a.x1, a.x0 - b.x1), gapY = Math.max(b.y0 - a.y1, a.y0 - b.y1);
68
+ if (gapX > 0 && (gapY <= 0 || gapX >= gapY)) return dx > 0 ? 'e' : 'w';
69
+ if (gapY > 0) return dy > 0 ? 's' : 'n';
70
+ return Math.abs(dx) >= Math.abs(dy) ? (dx > 0 ? 'e' : 'w') : (dy > 0 ? 's' : 'n');
71
+ }
72
+
73
+ export interface RouteResult { routes: Routed[]; diags: Diag[] }
74
+
75
+ /**
76
+ * The search steps routing may take in one scene. The heaviest diagram in this repo takes about 57,000
77
+ * (the session-messaging reproduction in repro/); a drawing with 40 more nodes took 11 million, and minutes. Past the budget,
78
+ * the routes left are drawn as plain elbows and the scene says so, so a large diagram draws in about a second.
79
+ */
80
+ export const ROUTE_BUDGET = 500_000;
81
+
82
+ export function routeAll(scene: RawScene, scenePath: string, layout: Layout, src: Located, kinds: Set<string>, snap?: number): RouteResult {
83
+ const diags: Diag[] = [];
84
+ const err = (path: string, message: string, hint?: string, severity: 'error' | 'warning' = 'error') => {
85
+ const p = src.locate(path); diags.push({ severity, message, line: p.line, col: p.col, path, hint });
86
+ };
87
+ const raws = (scene.routes ?? []) as RawRoute[];
88
+ const budget = { left: ROUTE_BUDGET };
89
+ let overBudget = 0;
90
+ const nodeIds = () => layout.items.map(i => i.id);
91
+ const seen = new Map<string, number>();
92
+ const routes: Routed[] = [];
93
+
94
+ // ---- resolve ends ----
95
+ const ends: { r: Routed; a?: End; b?: End }[] = [];
96
+ raws.forEach((raw, i) => {
97
+ const path = `${scenePath}/routes/${i}`;
98
+ if (seen.has(raw.id) || layout.byId.has(raw.id)) err(path + '/id', `duplicate id "${raw.id}"`);
99
+ seen.set(raw.id, i);
100
+ const kind = raw.kind ?? 'send';
101
+ if (!kinds.has(kind)) err(path + '/kind', `unknown flow kind "${kind}"` + dym(kind, kinds), `kinds: ${[...kinds].join(', ')}; add one under "kinds:"`);
102
+ const r: Routed = { id: raw.id, raw, path, kind, points: [] };
103
+ const get = (s: string, key: 'from' | 'to') => {
104
+ const { id } = parseEnd(s);
105
+ const p = layout.byId.get(id);
106
+ if (!p) { err(`${path}/${key}`, `unknown node "${id}"` + dym(id, nodeIds())); return undefined; }
107
+ return p;
108
+ };
109
+ r.from = get(raw.from, 'from'); r.to = get(raw.to, 'to');
110
+ routes.push(r);
111
+ ends.push({ r });
112
+ });
113
+
114
+ // sides and lanes
115
+ type Slot = { e: End; other: [number, number] };
116
+ const slots = new Map<string, Slot[]>();
117
+ for (const it of ends) {
118
+ const { r } = it;
119
+ if (!r.from || !r.to || r.raw.points) continue;
120
+ const fs = parseEnd(r.raw.from).side, ts = parseEnd(r.raw.to).side;
121
+ const first = r.raw.via?.[0], last = r.raw.via?.[r.raw.via.length - 1];
122
+ const toward = (v: (number[] | string) | undefined, fallback: Placed): Box => {
123
+ if (Array.isArray(v)) return { x0: v[0], x1: v[0], y0: v[1], y1: v[1], z0: 0, z1: 0 };
124
+ if (typeof v === 'string') { const p = layout.byId.get(parseEnd(v).id); if (p) return p.box; }
125
+ return fallback.box;
126
+ };
127
+ const mk = (n: Placed, s: Side | undefined, other: Box): End => {
128
+ const side = s ?? autoSide(n.box, other);
129
+ return { node: n, side, explicit: !!s, p: [0, 0], z: 0 };
130
+ };
131
+ it.a = mk(r.from, fs, toward(first, r.to));
132
+ it.b = mk(r.to, ts, toward(last, r.from));
133
+ const ob = toward(first, r.to), oa = toward(last, r.from);
134
+ for (const [e, o] of [[it.a, ob], [it.b, oa]] as [End, Box][]) {
135
+ const key = `${e.node.id}.${e.side}`;
136
+ if (!slots.has(key)) slots.set(key, []);
137
+ slots.get(key)!.push({ e, other: [(o.x0 + o.x1) / 2, (o.y0 + o.y1) / 2] });
138
+ }
139
+ }
140
+ for (const [, list] of slots) {
141
+ const e0 = list[0].e, b = e0.node.box, side = e0.side;
142
+ const along = side === 'e' || side === 'w' ? 1 : 0; // the coordinate that varies along the side
143
+ list.sort((p, q) => p.other[along] - q.other[along]);
144
+ const lo = along ? b.y0 : b.x0, hi = along ? b.y1 : b.x1, mid = (lo + hi) / 2;
145
+ const span = Math.max(0, hi - lo - 0.3), step = list.length > 1 ? Math.min(LANE, span / (list.length - 1)) : 0;
146
+ list.forEach((s, i) => {
147
+ const off = (i - (list.length - 1) / 2) * step;
148
+ const c = mid + off;
149
+ const z = s.e.node.box.z0;
150
+ if (side === 'top') { s.e.p = [(b.x0 + b.x1) / 2, (b.y0 + b.y1) / 2]; s.e.z = b.z1; return; }
151
+ const [nx, ny] = sideNormal[side];
152
+ s.e.p = along ? [nx > 0 ? b.x1 + OUT : b.x0 - OUT, c] : [c, ny > 0 ? b.y1 + OUT : b.y0 - OUT];
153
+ s.e.z = z;
154
+ });
155
+ }
156
+
157
+ // ---- obstacles ----
158
+ const obstacles: Box[] = [];
159
+ for (const p of layout.items) {
160
+ if (p.type === 'node') obstacles.push(p.box);
161
+ }
162
+ const walls: Box[] = [];
163
+ for (const f of layout.items.filter(p => regionKind(layout.catalog, p.region?.kind)?.shape === 'walled')) {
164
+ const { x0, y0, x1, y1 } = f.box, t = WALL_T, g = f.region!.gate;
165
+ const sides: [Box, 'n' | 'e' | 's' | 'w'][] = [
166
+ [{ x0, y0, x1, y1: y0 + t, z0: 0, z1: 0 }, 'n'], [{ x0, y0: y1 - t, x1, y1, z0: 0, z1: 0 }, 's'],
167
+ [{ x0, y0, x1: x0 + t, y1, z0: 0, z1: 0 }, 'w'], [{ x0: x1 - t, y0, x1, y1, z0: 0, z1: 0 }, 'e'],
168
+ ];
169
+ for (const [w, side] of sides) {
170
+ if (g && g.side === side) {
171
+ // the gate is passable only through its node (an obstacle like any node) or its gap when it has no node
172
+ if (g.node) continue;
173
+ const at = g.at ?? 0.5, gw = g.width ?? 2;
174
+ if (side === 'e' || side === 'w') { const c = y0 + (y1 - y0) * at; walls.push({ ...w, y1: c - gw / 2 }, { ...w, y0: c + gw / 2 }); }
175
+ else { const c = x0 + (x1 - x0) * at; walls.push({ ...w, x1: c - gw / 2 }, { ...w, x0: c + gw / 2 }); }
176
+ } else walls.push(w);
177
+ }
178
+ }
179
+
180
+ // ---- route each ----
181
+ const used = new Map<string, number>();
182
+ for (const it of ends) {
183
+ const { r, a, b } = it;
184
+ if (r.raw.points) {
185
+ r.points = r.raw.points.map(q => [q[0], q[1], q.length > 2 ? q[2] : floorAt(layout, q[0], q[1]) + 0.01] as P3);
186
+ continue;
187
+ }
188
+ if (!a || !b) continue;
189
+ const vias: { p: [number, number]; dir?: [number, number] }[] = [];
190
+ (r.raw.via ?? []).forEach((v, vi) => {
191
+ if (Array.isArray(v)) {
192
+ if (snap) {
193
+ const q = (u: number) => Math.round(Math.round(u / snap) * snap * 1e9) / 1e9;
194
+ v.forEach((u, k) => { if (Math.abs(u / snap - Math.round(u / snap)) > 1e-6) err(`${r.path}/via/${vi}/${k}`, `${u} is not on the ${snap} grid; it is drawn at ${q(u)}`, undefined, 'warning'); });
195
+ vias.push({ p: [q(v[0]), q(v[1])] });
196
+ } else vias.push({ p: [v[0], v[1]] });
197
+ }
198
+ else {
199
+ const { id, side } = parseEnd(v), n = layout.byId.get(id);
200
+ if (!n) { err(`${r.path}/via/${vi}`, `unknown node "${id}"` + dym(id, nodeIds())); return; }
201
+ const s = (side && side !== 'top') ? side : 'n';
202
+ const [nx, ny] = sideNormal[s], bx = n.box;
203
+ vias.push({ p: [nx ? (nx > 0 ? bx.x1 + 0.4 : bx.x0 - 0.4) : (bx.x0 + bx.x1) / 2, ny ? (ny > 0 ? bx.y1 + 0.4 : bx.y0 - 0.4) : (bx.y0 + bx.y1) / 2] });
204
+ }
205
+ });
206
+ const obs = obstacles.filter(o => o !== a.node.box && o !== b.node.box).concat(r.raw.cross ? [] : walls);
207
+ // nodes standing on an end node, or that an end stands on, do not block it
208
+ const blockers = obs.filter(o => !contains(a.node.box, o) && !contains(b.node.box, o) && !contains(o, a.node.box) && !contains(o, b.node.box));
209
+ const startDir = a.side === 'top' ? undefined : sideNormal[a.side];
210
+ const endDir = b.side === 'top' ? undefined : sideNormal[b.side];
211
+ const stops = [a.p, ...vias.map(v => v.p), b.p];
212
+ let pts2: [number, number][] = [a.p];
213
+ let dir = startDir;
214
+ let ok = true;
215
+ for (let i = 0; i + 1 < stops.length; i++) {
216
+ const last = i + 2 === stops.length;
217
+ const seg = astar(stops[i], stops[i + 1], blockers, used, dir, last && endDir ? [-endDir[0], -endDir[1]] as [number, number] : undefined, budget);
218
+ if (!seg) { ok = false; break; }
219
+ pts2.push(...seg.slice(1));
220
+ const n = pts2.length;
221
+ if (n >= 2) { const dx = Math.sign(pts2[n - 1][0] - pts2[n - 2][0]), dy = Math.sign(pts2[n - 1][1] - pts2[n - 2][1]); dir = [dx, dy]; }
222
+ }
223
+ if (!ok && budget.left <= 0) { overBudget++; pts2 = [a.p, [b.p[0], a.p[1]], b.p]; }
224
+ else if (!ok) {
225
+ err(r.path, `no path found for route "${r.id}" from "${a.node.id}" to "${b.node.id}"`, 'add "via" points, or use "points" to draw it by hand', 'warning');
226
+ pts2 = [a.p, [b.p[0], a.p[1]], b.p];
227
+ }
228
+ pts2 = simplify(pts2);
229
+ for (let i = 0; i + 1 < pts2.length; i++) mark(used, pts2[i], pts2[i + 1]);
230
+ r.points = withHeights(layout, pts2, a, b);
231
+ }
232
+
233
+ if (overBudget) err(scenePath, `${overBudget} of ${routes.length} routes were drawn as plain elbows: the scene is too large to route them all around what stands in the way (${ROUTE_BUDGET.toLocaleString('en')} search steps)`, 'split it into scenes, or give the busiest routes "via" points or "points"', 'warning');
234
+ // ---- route ids must be unique across nodes too; report steps referencing them later ----
235
+ return { routes, diags };
236
+ }
237
+
238
+ function contains(outer: Box, inner: Box): boolean {
239
+ return inner.x0 >= outer.x0 - 1e-6 && inner.x1 <= outer.x1 + 1e-6 && inner.y0 >= outer.y0 - 1e-6 && inner.y1 <= outer.y1 + 1e-6 && inner.z0 >= outer.z1 - 1e-6;
240
+ }
241
+
242
+ const key = (x: number, y: number) => `${Math.round(x / GRID)},${Math.round(y / GRID)}`;
243
+ function mark(used: Map<string, number>, a: [number, number], b: [number, number]) {
244
+ const n = Math.max(1, Math.round(Math.hypot(b[0] - a[0], b[1] - a[1]) / GRID));
245
+ for (let i = 0; i <= n; i++) { const k = key(a[0] + (b[0] - a[0]) * i / n, a[1] + (b[1] - a[1]) * i / n); used.set(k, (used.get(k) ?? 0) + 1); }
246
+ }
247
+
248
+ function blocked(x: number, y: number, obs: Box[]): boolean {
249
+ for (const o of obs) if (x > o.x0 - INFLATE && x < o.x1 + INFLATE && y > o.y0 - INFLATE && y < o.y1 + INFLATE) return true;
250
+ return false;
251
+ }
252
+
253
+ /**
254
+ * Orthogonal A* on a GRID lattice from a to b, avoiding obstacles. Costs: length, a penalty per bend, a small cost on
255
+ * cells other routes use (so lanes spread). The first move goes along startDir, the last along endDir, when given.
256
+ */
257
+ function astar(a: [number, number], b: [number, number], obs: Box[], used: Map<string, number>, startDir?: [number, number], endDir?: [number, number], budget = { left: Infinity }): [number, number][] | null {
258
+ // a straight line needs no search
259
+ if ((Math.abs(a[0] - b[0]) < 1e-6 || Math.abs(a[1] - b[1]) < 1e-6) && clear(a, b, obs)) {
260
+ const d: [number, number] = [Math.sign(b[0] - a[0]), Math.sign(b[1] - a[1])];
261
+ const okStart = !startDir || (startDir[0] === d[0] && startDir[1] === d[1]);
262
+ const okEnd = !endDir || (endDir[0] === d[0] && endDir[1] === d[1]);
263
+ if (okStart && okEnd) return [a, b];
264
+ }
265
+ // the scene's budget spent: no search (and none of its arrays)
266
+ if (budget.left <= 0) return null;
267
+ // lattice anchored at a; b is joined from the nearest lattice point
268
+ const gx = (x: number) => Math.round((x - a[0]) / GRID), gy = (y: number) => Math.round((y - a[1]) / GRID);
269
+ const X = (i: number) => a[0] + i * GRID, Y = (j: number) => a[1] + j * GRID;
270
+ const ti = gx(b[0]), tj = gy(b[1]);
271
+ const pad = 30;
272
+ const minI = Math.min(0, ti) - pad, maxI = Math.max(0, ti) + pad, minJ = Math.min(0, tj) - pad, maxJ = Math.max(0, tj) + pad;
273
+ const BEND = 1.2, STEP = GRID, USED = 0.06;
274
+ const dirs: [number, number][] = [[1, 0], [-1, 0], [0, 1], [0, -1]];
275
+ type S = { i: number; j: number; d: number; g: number; f: number; prev?: S; idx: number; hp: number };
276
+ // per lattice cell, worked out once a search: whether it's blocked, what other routes' use of it costs, and the best
277
+ // cost so far to reach it heading each way (numbers in typed arrays, not string keys: the same answers, faster)
278
+ const W = maxI - minI + 1, H = maxJ - minJ + 1;
279
+ const cell = (i: number, j: number) => (i - minI) * H + (j - minJ);
280
+ const blockedAt = new Int8Array(W * H).fill(-1);
281
+ const usedAt = new Float64Array(W * H).fill(-1);
282
+ const best = new Float64Array(W * H * 4).fill(Infinity);
283
+ const isBlocked = (i: number, j: number) => { const c = cell(i, j); if (blockedAt[c] < 0) blockedAt[c] = blocked(X(i), Y(j), obs) ? 1 : 0; return blockedAt[c] === 1; };
284
+ const usedCost = (i: number, j: number) => { const c = cell(i, j); if (usedAt[c] < 0) usedAt[c] = used.get(key(X(i), Y(j))) ?? 0; return usedAt[c]; };
285
+ const open = openList<S>();
286
+ const h = (i: number, j: number) => (Math.abs(i - ti) + Math.abs(j - tj)) * STEP;
287
+ const sd = startDir ? dirs.findIndex(d => d[0] === startDir[0] && d[1] === startDir[1]) : -1;
288
+ open.push({ i: 0, j: 0, d: sd, g: 0, f: h(0, 0), idx: 0, hp: 0 });
289
+ const startNear = (i: number, j: number) => Math.abs(i) + Math.abs(j) <= 2;
290
+ const endNear = (i: number, j: number) => Math.abs(i - ti) + Math.abs(j - tj) <= 2;
291
+ let iter = 0;
292
+ while (open.length() && iter++ < 200000) {
293
+ if (budget.left-- <= 0) return null;
294
+ const s = open.take();
295
+ if (s.i === ti && s.j === tj) {
296
+ if (endDir && s.d >= 0 && (dirs[s.d][0] !== endDir[0] || dirs[s.d][1] !== endDir[1])) { /* arrives the wrong way: keep searching */ }
297
+ else {
298
+ const out: [number, number][] = [];
299
+ for (let q: S | undefined = s; q; q = q.prev) out.push([X(q.i), Y(q.j)]);
300
+ out.reverse();
301
+ out[0] = a;
302
+ return fixEnd(simplify(out), b);
303
+ }
304
+ }
305
+ for (let di = 0; di < 4; di++) {
306
+ const d = dirs[di];
307
+ if (s.d >= 0 && d[0] === -dirs[s.d][0] && d[1] === -dirs[s.d][1]) continue;
308
+ const i = s.i + d[0], j = s.j + d[1];
309
+ if (i < minI || i > maxI || j < minJ || j > maxJ) continue;
310
+ if (!startNear(i, j) && !endNear(i, j) && isBlocked(i, j)) continue;
311
+ if ((startNear(i, j) || endNear(i, j)) && isBlocked(i, j) && !(i === ti && j === tj)) {
312
+ // near the ends, allow only moves straight out of the face
313
+ const out = startNear(i, j) ? startDir : endDir && [-endDir[0], -endDir[1]];
314
+ if (!out || (startNear(i, j) ? (d[0] !== out[0] || d[1] !== out[1]) : (d[0] !== endDir![0] || d[1] !== endDir![1]))) continue;
315
+ }
316
+ const bend = s.d >= 0 && s.d !== di ? BEND : 0;
317
+ const g = s.g + STEP + bend + usedCost(i, j) * USED;
318
+ const kk = cell(i, j) * 4 + di;
319
+ if (best[kk] <= g) continue;
320
+ best[kk] = g;
321
+ open.push({ i, j, d: di, g, f: g + h(i, j), prev: s, idx: 0, hp: 0 });
322
+ }
323
+ }
324
+ return null;
325
+ }
326
+
327
+ /**
328
+ * A* open list, taking the state with the lowest f, ties to the one earliest in the list, where taking one moves the
329
+ * last into its place (so the order is exactly that of the array scan this replaces, and every route is the same).
330
+ * A binary heap ordered by (f, position): O(log n) a step instead of a scan of the whole list, which on a large drawing
331
+ * (tens of thousands of open states, hundreds of thousands of steps) took minutes.
332
+ */
333
+ export function openList<T extends { f: number; idx: number; hp: number }>() {
334
+ const arr: T[] = [], heap: T[] = [];
335
+ const less = (a: T, b: T) => a.f < b.f || (a.f === b.f && a.idx < b.idx);
336
+ const swap = (x: number, y: number) => { const t = heap[x]; heap[x] = heap[y]; heap[y] = t; heap[x].hp = x; heap[y].hp = y; };
337
+ const up = (k: number) => { while (k > 0) { const p = (k - 1) >> 1; if (!less(heap[k], heap[p])) break; swap(k, p); k = p; } };
338
+ const down = (k: number) => {
339
+ for (;;) {
340
+ const l = 2 * k + 1, r = l + 1;
341
+ let m = k;
342
+ if (l < heap.length && less(heap[l], heap[m])) m = l;
343
+ if (r < heap.length && less(heap[r], heap[m])) m = r;
344
+ if (m === k) return;
345
+ swap(k, m); k = m;
346
+ }
347
+ };
348
+ return {
349
+ length: () => arr.length,
350
+ push(s: T) { s.idx = arr.length; arr.push(s); s.hp = heap.length; heap.push(s); up(s.hp); },
351
+ take(): T {
352
+ const s = heap[0], lastH = heap.pop()!;
353
+ if (heap.length) { heap[0] = lastH; lastH.hp = 0; down(0); }
354
+ // the list: the last state moves into the taken one's place (an earlier position: it rises in the heap)
355
+ const last = arr.pop()!;
356
+ if (last !== s) { arr[s.idx] = last; last.idx = s.idx; up(last.hp); }
357
+ return s;
358
+ },
359
+ };
360
+ }
361
+
362
+ /**
363
+ * The lattice is anchored at the start, so only the end was snapped: move the corner before it onto the exact end
364
+ * coordinate, keeping every segment straight.
365
+ */
366
+ function fixEnd(lat: [number, number][], b: [number, number]): [number, number][] {
367
+ const q = lat.map(x => [x[0], x[1]] as [number, number]);
368
+ const n = q.length, L = q[n - 1];
369
+ if (n >= 2) {
370
+ const prev = q[n - 2];
371
+ if (Math.abs(prev[1] - L[1]) < 1e-9) { prev[1] = b[1]; if (n >= 3 && Math.abs(q[n - 3][1] - L[1]) < 1e-9) q[n - 3][1] = b[1]; }
372
+ else if (Math.abs(prev[0] - L[0]) < 1e-9) { prev[0] = b[0]; if (n >= 3 && Math.abs(q[n - 3][0] - L[0]) < 1e-9) q[n - 3][0] = b[0]; }
373
+ }
374
+ q[n - 1] = b;
375
+ return simplify(q);
376
+ }
377
+
378
+ function clear(a: [number, number], b: [number, number], obs: Box[]): boolean {
379
+ const n = Math.max(1, Math.round(Math.hypot(b[0] - a[0], b[1] - a[1]) / (GRID / 2)));
380
+ for (let i = 2; i < n - 1; i++) if (blocked(a[0] + (b[0] - a[0]) * i / n, a[1] + (b[1] - a[1]) * i / n, obs)) return false;
381
+ return true;
382
+ }
383
+
384
+ export function simplify(p: [number, number][]): [number, number][] {
385
+ const out: [number, number][] = [];
386
+ for (const q of p) {
387
+ const n = out.length;
388
+ if (n && Math.abs(out[n - 1][0] - q[0]) < 1e-6 && Math.abs(out[n - 1][1] - q[1]) < 1e-6) continue;
389
+ if (n >= 2) {
390
+ const a = out[n - 2], b = out[n - 1];
391
+ const col = (Math.abs(a[0] - b[0]) < 1e-6 && Math.abs(b[0] - q[0]) < 1e-6) || (Math.abs(a[1] - b[1]) < 1e-6 && Math.abs(b[1] - q[1]) < 1e-6);
392
+ if (col) { out[n - 1] = q; continue; }
393
+ }
394
+ out.push(q);
395
+ }
396
+ return out;
397
+ }
398
+
399
+ /** Give each point its floor height, with a vertical step where a segment crosses a region edge. */
400
+ function withHeights(layout: Layout, p: [number, number][], a: End, b: End): P3[] {
401
+ const edgesX = new Set<number>(), edgesY = new Set<number>();
402
+ for (const r of layout.items) {
403
+ if (r.type !== 'region' || !regionKind(layout.catalog, r.region!.kind)?.floor) continue;
404
+ edgesX.add(r.box.x0); edgesX.add(r.box.x1); edgesY.add(r.box.y0); edgesY.add(r.box.y1);
405
+ }
406
+ const out: P3[] = [];
407
+ const zf = (x: number, y: number) => floorAt(layout, x, y) + 0.01;
408
+ for (let i = 0; i + 1 < p.length; i++) {
409
+ const [x0, y0] = p[i], [x1, y1] = p[i + 1];
410
+ const cuts = [0, 1];
411
+ if (Math.abs(y0 - y1) < 1e-6) for (const e of edgesX) { const t = (e - x0) / (x1 - x0); if (t > 1e-6 && t < 1 - 1e-6) cuts.push(t); }
412
+ else for (const e of edgesY) { const t = (e - y0) / (y1 - y0); if (t > 1e-6 && t < 1 - 1e-6) cuts.push(t); }
413
+ cuts.sort((m, n) => m - n);
414
+ for (let c = 0; c + 1 < cuts.length; c++) {
415
+ const t0 = cuts[c], t1 = cuts[c + 1], tm = (t0 + t1) / 2;
416
+ const z = zf(x0 + (x1 - x0) * tm, y0 + (y1 - y0) * tm);
417
+ const P: P3 = [x0 + (x1 - x0) * t0, y0 + (y1 - y0) * t0, z], Q: P3 = [x0 + (x1 - x0) * t1, y0 + (y1 - y0) * t1, z];
418
+ const last = out[out.length - 1];
419
+ if (last && (Math.abs(last[0] - P[0]) > 1e-6 || Math.abs(last[1] - P[1]) > 1e-6 || Math.abs(last[2] - P[2]) > 1e-6)) out.push(P);
420
+ else if (!last) out.push(P);
421
+ out.push(Q);
422
+ }
423
+ }
424
+ // ends sit at the floor their node stands on
425
+ if (out.length) { out[0][2] = a.side === 'top' ? a.z : a.node.box.z0 + 0.01; out[out.length - 1][2] = b.side === 'top' ? b.z : b.node.box.z0 + 0.01; }
426
+ // drop collinear points at equal height
427
+ const res: P3[] = [];
428
+ for (const q of out) {
429
+ const n = res.length;
430
+ if (n >= 2) {
431
+ const u = res[n - 2], v = res[n - 1];
432
+ const same = Math.abs(u[2] - v[2]) < 1e-9 && Math.abs(v[2] - q[2]) < 1e-9;
433
+ const col = (Math.abs(u[0] - v[0]) < 1e-6 && Math.abs(v[0] - q[0]) < 1e-6) || (Math.abs(u[1] - v[1]) < 1e-6 && Math.abs(v[1] - q[1]) < 1e-6);
434
+ if (same && col) { res[n - 1] = q; continue; }
435
+ }
436
+ res.push(q);
437
+ }
438
+ return res;
439
+ }
440
+
441
+ function dym(w: string, c: Iterable<string>): string {
442
+ const d = didYouMean(w, c);
443
+ return d ? ` (did you mean "${d}"?)` : '';
444
+ }