topotopo 0.3.0 → 0.5.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 (354) hide show
  1. package/NOTICE +40 -10
  2. package/README.md +475 -111
  3. package/dist/cli.js +328 -133
  4. package/dist/config.d.ts +48 -0
  5. package/dist/config.js +170 -0
  6. package/dist/core/analysis.d.ts +5 -1
  7. package/dist/core/analysis.js +8 -3
  8. package/dist/core/bake.d.ts +16 -8
  9. package/dist/core/bake.js +165 -29
  10. package/dist/core/bevel.d.ts +3 -1
  11. package/dist/core/bevel.js +238 -97
  12. package/dist/core/decimate.d.ts +65 -0
  13. package/dist/core/decimate.js +409 -3
  14. package/dist/core/erosion.d.ts +37 -0
  15. package/dist/core/erosion.js +41 -1
  16. package/dist/core/geometry.d.ts +5 -1
  17. package/dist/core/geometry.js +204 -4
  18. package/dist/core/heightfield.d.ts +27 -4
  19. package/dist/core/heightfield.js +54 -16
  20. package/dist/core/imageops.d.ts +6 -0
  21. package/dist/core/imageops.js +51 -0
  22. package/dist/core/intrinsics.d.ts +7 -0
  23. package/dist/core/intrinsics.js +94 -0
  24. package/dist/core/manifold.d.ts +12 -1
  25. package/dist/core/manifold.js +78 -6
  26. package/dist/core/materials.d.ts +11 -0
  27. package/dist/core/materials.js +56 -0
  28. package/dist/core/noise.d.ts +9 -0
  29. package/dist/core/noise.js +10 -1
  30. package/dist/core/packed.js +11 -0
  31. package/dist/core/particles.d.ts +1 -1
  32. package/dist/core/particles.js +1 -1
  33. package/dist/core/polymerge.d.ts +21 -0
  34. package/dist/core/polymerge.js +327 -0
  35. package/dist/core/rbd.js +13 -1
  36. package/dist/core/repair.d.ts +2 -0
  37. package/dist/core/repair.js +2 -0
  38. package/dist/core/report.d.ts +70 -0
  39. package/dist/core/report.js +275 -0
  40. package/dist/core/scatter.d.ts +1 -1
  41. package/dist/core/scatter.js +1 -1
  42. package/dist/core/scene.d.ts +20 -0
  43. package/dist/core/scene.js +72 -0
  44. package/dist/core/sha256.d.ts +4 -0
  45. package/dist/core/sha256.js +69 -0
  46. package/dist/core/shapes.d.ts +3 -0
  47. package/dist/core/shapes.js +34 -0
  48. package/dist/core/snippet-lib.d.ts +15 -2
  49. package/dist/core/snippet-lib.js +40 -14
  50. package/dist/core/solidify.d.ts +38 -0
  51. package/dist/core/solidify.js +356 -0
  52. package/dist/core/tangents.d.ts +54 -0
  53. package/dist/core/tangents.js +218 -0
  54. package/dist/core/texcoord.d.ts +4 -0
  55. package/dist/core/texcoord.js +14 -0
  56. package/dist/core/texnoise.d.ts +6 -1
  57. package/dist/core/texnoise.js +6 -2
  58. package/dist/core/texsdf.d.ts +131 -0
  59. package/dist/core/texsdf.js +637 -0
  60. package/dist/core/texture.d.ts +163 -9
  61. package/dist/core/texture.js +844 -20
  62. package/dist/core/topology.d.ts +32 -0
  63. package/dist/core/topology.js +238 -7
  64. package/dist/core/traceimage.d.ts +7 -0
  65. package/dist/core/traceimage.js +221 -0
  66. package/dist/core/tritri.d.ts +5 -0
  67. package/dist/core/tritri.js +120 -0
  68. package/dist/core/unwrap.d.ts +72 -0
  69. package/dist/core/unwrap.js +800 -0
  70. package/dist/core/usercode.d.ts +27 -0
  71. package/dist/core/usercode.js +87 -0
  72. package/dist/core/uv.d.ts +15 -16
  73. package/dist/core/uv.js +36 -189
  74. package/dist/core/uvislands.d.ts +62 -0
  75. package/dist/core/uvislands.js +574 -0
  76. package/dist/core/uvoverlap.d.ts +58 -0
  77. package/dist/core/uvoverlap.js +220 -0
  78. package/dist/core/uvpack.d.ts +64 -0
  79. package/dist/core/uvpack.js +628 -0
  80. package/dist/core/uvreport.d.ts +127 -0
  81. package/dist/core/uvreport.js +372 -0
  82. package/dist/core/wrangle.d.ts +6 -1
  83. package/dist/core/wrangle.js +27 -16
  84. package/dist/core/xatlas.d.ts +16 -1
  85. package/dist/core/xatlas.js +95 -61
  86. package/dist/engines.d.ts +63 -0
  87. package/dist/engines.js +180 -0
  88. package/dist/explain.d.ts +4 -3
  89. package/dist/explain.js +129 -12
  90. package/dist/graph/engine.d.ts +92 -29
  91. package/dist/graph/engine.js +298 -148
  92. package/dist/graph/expr.d.ts +6 -3
  93. package/dist/graph/expr.js +18 -8
  94. package/dist/graph/outputs.d.ts +23 -0
  95. package/dist/graph/outputs.js +41 -0
  96. package/dist/graph/packages.d.ts +72 -0
  97. package/dist/graph/packages.js +261 -0
  98. package/dist/graph/parallel.d.ts +3 -1
  99. package/dist/graph/parallel.js +4 -1
  100. package/dist/graph/params.d.ts +6 -0
  101. package/dist/graph/params.js +34 -7
  102. package/dist/graph/scope.d.ts +55 -0
  103. package/dist/graph/scope.js +14 -0
  104. package/dist/graph/types.d.ts +75 -12
  105. package/dist/graph/types.js +4 -2
  106. package/dist/graph/vars.d.ts +16 -0
  107. package/dist/graph/vars.js +80 -0
  108. package/dist/host/artifacts.d.ts +10 -1
  109. package/dist/host/artifacts.js +37 -6
  110. package/dist/host/cook.d.ts +241 -0
  111. package/dist/host/cook.js +844 -0
  112. package/dist/host/export-targets.d.ts +42 -5
  113. package/dist/host/export-targets.js +72 -13
  114. package/dist/host/godot-commands.d.ts +4 -0
  115. package/dist/host/godot-commands.js +21 -0
  116. package/dist/host/godot.d.ts +183 -0
  117. package/dist/host/godot.js +916 -0
  118. package/dist/host/node.d.ts +12 -7
  119. package/dist/host/node.js +27 -9
  120. package/dist/host/pool.js +51 -2
  121. package/dist/host/sidecars.d.ts +8 -0
  122. package/dist/host/sidecars.js +50 -0
  123. package/dist/host/types.d.ts +19 -6
  124. package/dist/host/version.d.ts +1 -0
  125. package/dist/host/version.js +3 -0
  126. package/dist/host/worker.js +5 -2
  127. package/dist/index.d.ts +5 -3
  128. package/dist/index.js +3 -2
  129. package/dist/inspect.d.ts +84 -1
  130. package/dist/inspect.js +271 -24
  131. package/dist/io/common.d.ts +33 -5
  132. package/dist/io/export.js +2 -1
  133. package/dist/io/files.d.ts +23 -4
  134. package/dist/io/files.js +60 -8
  135. package/dist/io/gltf.js +355 -51
  136. package/dist/io/heightmap.d.ts +3 -0
  137. package/dist/io/heightmap.js +1 -0
  138. package/dist/io/import.js +10 -0
  139. package/dist/io/inspect-scene.d.ts +55 -0
  140. package/dist/io/inspect-scene.js +155 -0
  141. package/dist/io/kinds.d.ts +81 -0
  142. package/dist/io/kinds.js +163 -0
  143. package/dist/io/points.d.ts +2 -1
  144. package/dist/io/points.js +3 -1
  145. package/dist/io/sidecars.d.ts +24 -0
  146. package/dist/io/sidecars.js +57 -0
  147. package/dist/io/source.d.ts +65 -0
  148. package/dist/io/source.js +112 -0
  149. package/dist/io/targets.d.ts +47 -3
  150. package/dist/io/targets.js +149 -14
  151. package/dist/io/textures.js +21 -1
  152. package/dist/io/unreal.js +5 -1
  153. package/dist/mcp/docs.d.ts +10 -1
  154. package/dist/mcp/docs.js +816 -119
  155. package/dist/mcp/inputs.d.ts +12 -5
  156. package/dist/mcp/inputs.js +50 -13
  157. package/dist/mcp/server.js +70 -24
  158. package/dist/mcp/tools.d.ts +14 -7
  159. package/dist/mcp/tools.js +207 -108
  160. package/dist/mcp/verify.d.ts +2 -2
  161. package/dist/mcp/verify.js +1 -1
  162. package/dist/mcp/workspace.d.ts +15 -0
  163. package/dist/mcp/workspace.js +349 -0
  164. package/dist/nodes/attributes.js +198 -1
  165. package/dist/nodes/bake.js +207 -83
  166. package/dist/nodes/beam.d.ts +1 -0
  167. package/dist/nodes/beam.js +201 -0
  168. package/dist/nodes/bevel.js +54 -5
  169. package/dist/nodes/cloth.js +2 -0
  170. package/dist/nodes/code.js +22 -10
  171. package/dist/nodes/curves.js +440 -93
  172. package/dist/nodes/flow.js +53 -33
  173. package/dist/nodes/generate.js +13 -39
  174. package/dist/nodes/heightfield.js +248 -77
  175. package/dist/nodes/imageops.d.ts +1 -0
  176. package/dist/nodes/imageops.js +203 -0
  177. package/dist/nodes/index.d.ts +4 -0
  178. package/dist/nodes/index.js +4 -0
  179. package/dist/nodes/material.js +91 -23
  180. package/dist/nodes/measure.js +45 -18
  181. package/dist/nodes/particles.js +2 -0
  182. package/dist/nodes/pcg.js +6 -5
  183. package/dist/nodes/procedural.js +4 -3
  184. package/dist/nodes/rbd.js +1 -1
  185. package/dist/nodes/remesh.js +71 -15
  186. package/dist/nodes/scene.d.ts +1 -0
  187. package/dist/nodes/scene.js +55 -0
  188. package/dist/nodes/sdf.js +10 -5
  189. package/dist/nodes/solid.js +20 -5
  190. package/dist/nodes/solidify.d.ts +1 -0
  191. package/dist/nodes/solidify.js +52 -0
  192. package/dist/nodes/splines.d.ts +15 -1
  193. package/dist/nodes/splines.js +112 -105
  194. package/dist/nodes/texture.d.ts +21 -6
  195. package/dist/nodes/texture.js +1318 -185
  196. package/dist/nodes/topology.d.ts +7 -0
  197. package/dist/nodes/topology.js +133 -6
  198. package/dist/nodes/transform.js +11 -3
  199. package/dist/nodes/util.d.ts +1 -1
  200. package/dist/nodes/uv.js +192 -174
  201. package/dist/nodes/wasmcall.js +6 -2
  202. package/dist/open.d.ts +19 -0
  203. package/dist/open.js +12 -0
  204. package/dist/package.d.ts +288 -0
  205. package/dist/package.js +772 -0
  206. package/dist/packages/check.d.ts +32 -0
  207. package/dist/packages/check.js +169 -0
  208. package/dist/packages/commands.d.ts +57 -0
  209. package/dist/packages/commands.js +537 -0
  210. package/dist/packages/registry.d.ts +796 -0
  211. package/dist/packages/registry.js +2998 -0
  212. package/dist/packages/update.d.ts +124 -0
  213. package/dist/packages/update.js +476 -0
  214. package/dist/render/options.d.ts +2 -0
  215. package/dist/render/options.js +44 -5
  216. package/dist/render/pbr.d.ts +28 -0
  217. package/dist/render/pbr.js +378 -0
  218. package/dist/render/preview.d.ts +69 -0
  219. package/dist/render/preview.js +26 -0
  220. package/dist/render/raster.d.ts +78 -7
  221. package/dist/render/raster.js +600 -145
  222. package/dist/render/texview.d.ts +7 -1
  223. package/dist/render/texview.js +34 -2
  224. package/dist/scan.d.ts +61 -0
  225. package/dist/scan.js +228 -0
  226. package/dist/session.d.ts +311 -0
  227. package/dist/session.js +849 -0
  228. package/dist/viewer/app/api.js +48 -6
  229. package/dist/viewer/app/camera.js +1 -1
  230. package/dist/viewer/app/cooking.js +78 -0
  231. package/dist/viewer/app/embed.js +100 -0
  232. package/dist/viewer/app/export-popover.js +118 -16
  233. package/dist/viewer/app/grid.js +6 -2
  234. package/dist/viewer/app/guides.js +123 -1
  235. package/dist/viewer/app/keymap.js +7 -4
  236. package/dist/viewer/app/layers.js +5 -5
  237. package/dist/viewer/app/main.js +186 -53
  238. package/dist/viewer/app/markers.js +61 -1
  239. package/dist/viewer/app/outliner.js +72 -27
  240. package/dist/viewer/app/output-info.js +45 -0
  241. package/dist/viewer/app/outputs.css +147 -8
  242. package/dist/viewer/app/outputs.js +168 -54
  243. package/dist/viewer/app/packages.js +614 -0
  244. package/dist/viewer/app/props.js +177 -53
  245. package/dist/viewer/app/scene.js +35 -6
  246. package/dist/viewer/app/select.js +5 -4
  247. package/dist/viewer/app/selection.js +1 -1
  248. package/dist/viewer/app/status.js +12 -15
  249. package/dist/viewer/app/style.css +66 -8
  250. package/dist/viewer/app/units.js +1 -1
  251. package/dist/viewer/app/vars.js +48 -1
  252. package/dist/viewer/app/welcome.js +72 -0
  253. package/dist/viewer/graph-file.d.ts +62 -0
  254. package/dist/viewer/graph-file.js +175 -0
  255. package/dist/viewer/index.html +24 -11
  256. package/dist/viewer/json-edit.d.ts +13 -0
  257. package/dist/viewer/json-edit.js +274 -0
  258. package/dist/viewer/outputs.d.ts +49 -5
  259. package/dist/viewer/outputs.js +264 -56
  260. package/dist/viewer/packages.d.ts +121 -0
  261. package/dist/viewer/packages.js +584 -0
  262. package/dist/viewer/server.d.ts +24 -7
  263. package/dist/viewer/server.js +289 -31
  264. package/dist/web/app/web.css +419 -0
  265. package/dist/web/app/web.js +188 -0
  266. package/dist/web/bake.d.ts +34 -0
  267. package/dist/web/bake.js +153 -0
  268. package/dist/web/folder-page.d.ts +101 -0
  269. package/dist/web/folder-page.js +146 -0
  270. package/dist/web/folders.d.ts +280 -0
  271. package/dist/web/folders.js +970 -0
  272. package/dist/web/library.d.ts +91 -0
  273. package/dist/web/library.js +228 -0
  274. package/dist/web/markdown.d.ts +45 -0
  275. package/dist/web/markdown.js +677 -0
  276. package/dist/web/pages.d.ts +258 -0
  277. package/dist/web/pages.js +301 -0
  278. package/dist/web/server.d.ts +24 -0
  279. package/dist/web/server.js +1068 -0
  280. package/dist/workspace.d.ts +88 -105
  281. package/dist/workspace.js +359 -375
  282. package/integrations/godot/addons/topotopo/LICENSE +202 -0
  283. package/integrations/godot/addons/topotopo/README.md +57 -0
  284. package/integrations/godot/addons/topotopo/context_menu.gd +43 -0
  285. package/integrations/godot/addons/topotopo/dock.gd +266 -0
  286. package/integrations/godot/addons/topotopo/dock.tscn +72 -0
  287. package/integrations/godot/addons/topotopo/export_filter.gd +72 -0
  288. package/integrations/godot/addons/topotopo/gltf_instancing.gd +131 -0
  289. package/integrations/godot/addons/topotopo/icons/topotopo.svg +1 -0
  290. package/integrations/godot/addons/topotopo/inspector.gd +38 -0
  291. package/integrations/godot/addons/topotopo/instances_post_import.gd +111 -0
  292. package/integrations/godot/addons/topotopo/package.gd +23 -0
  293. package/integrations/godot/addons/topotopo/package_importer.gd +187 -0
  294. package/integrations/godot/addons/topotopo/plugin.cfg +7 -0
  295. package/integrations/godot/addons/topotopo/plugin.gd +970 -0
  296. package/integrations/godot/addons/topotopo/record.gd +435 -0
  297. package/integrations/godot/addons/topotopo/runner.gd +458 -0
  298. package/integrations/godot/addons/topotopo/tools/check.gd +42 -0
  299. package/integrations/godot/addons/topotopo/watcher.gd +199 -0
  300. package/kernels/pkg/README.md +23 -29
  301. package/kernels/pkg-simd/README.md +23 -29
  302. package/library/architecture/versions/1.0/architecture.topo +12 -0
  303. package/{shelf → library/architecture/versions/1.0/graphs}/arch.json +3 -3
  304. package/{shelf → library/architecture/versions/1.0/graphs}/beam_truss.json +6 -6
  305. package/{shelf → library/architecture/versions/1.0/graphs}/brick_wall.json +8 -8
  306. package/{shelf → library/architecture/versions/1.0/graphs}/door_frame.json +3 -3
  307. package/{shelf → library/architecture/versions/1.0/graphs}/hex_grid_floor.json +3 -2
  308. package/{shelf → library/architecture/versions/1.0/graphs}/house.json +8 -8
  309. package/library/architecture/versions/1.0/graphs/lineup.json +42 -0
  310. package/{shelf → library/architecture/versions/1.0/graphs}/pillar.json +3 -2
  311. package/{shelf → library/architecture/versions/1.0/graphs}/railing.json +5 -5
  312. package/{shelf → library/architecture/versions/1.0/graphs}/roof_gable.json +2 -2
  313. package/{shelf → library/architecture/versions/1.0/graphs}/roof_hip.json +2 -2
  314. package/{shelf → library/architecture/versions/1.0/graphs}/roof_skeleton.json +2 -1
  315. package/{shelf → library/architecture/versions/1.0/graphs}/scaffold.json +4 -4
  316. package/{shelf → library/architecture/versions/1.0/graphs}/spiral_stairs.json +3 -2
  317. package/{shelf → library/architecture/versions/1.0/graphs}/stairs.json +6 -6
  318. package/{shelf → library/architecture/versions/1.0/graphs}/tile_floor.json +3 -2
  319. package/{shelf → library/architecture/versions/1.0/graphs}/wall_segment.json +10 -10
  320. package/{shelf → library/architecture/versions/1.0/graphs}/window_frame.json +2 -2
  321. package/library/architecture/versions/1.0/version.json +1119 -0
  322. package/{shelf → library/nature/versions/1.0/graphs}/bush.json +2 -2
  323. package/{shelf → library/nature/versions/1.0/graphs}/cliff_block.json +4 -3
  324. package/{shelf → library/nature/versions/1.0/graphs}/forest_patch.json +5 -5
  325. package/{shelf → library/nature/versions/1.0/graphs}/grass_clumps.json +2 -2
  326. package/library/nature/versions/1.0/graphs/lineup.json +24 -0
  327. package/{shelf → library/nature/versions/1.0/graphs}/log.json +6 -6
  328. package/{shelf → library/nature/versions/1.0/graphs}/rock.json +5 -4
  329. package/{shelf → library/nature/versions/1.0/graphs}/scatter_rocks.json +5 -5
  330. package/{shelf → library/nature/versions/1.0/graphs}/tree_lowpoly.json +3 -2
  331. package/library/nature/versions/1.0/nature.topo +12 -0
  332. package/library/nature/versions/1.0/version.json +534 -0
  333. package/{shelf → library/props/versions/1.0/graphs}/barrel.json +5 -4
  334. package/{shelf → library/props/versions/1.0/graphs}/crate.json +3 -3
  335. package/library/props/versions/1.0/graphs/lineup.json +18 -0
  336. package/{shelf → library/props/versions/1.0/graphs}/pallet.json +4 -3
  337. package/{shelf → library/props/versions/1.0/graphs}/pipe_run.json +3 -3
  338. package/{shelf → library/props/versions/1.0/graphs}/sandbag_wall.json +5 -5
  339. package/library/props/versions/1.0/props.topo +12 -0
  340. package/library/props/versions/1.0/version.json +336 -0
  341. package/{shelf → library/street/versions/1.0/graphs}/bench.json +5 -5
  342. package/{shelf → library/street/versions/1.0/graphs}/bollard.json +2 -1
  343. package/{shelf → library/street/versions/1.0/graphs}/cable.json +4 -4
  344. package/{shelf → library/street/versions/1.0/graphs}/fence.json +7 -7
  345. package/{shelf → library/street/versions/1.0/graphs}/lamp_post.json +2 -2
  346. package/library/street/versions/1.0/graphs/lineup.json +22 -0
  347. package/{shelf → library/street/versions/1.0/graphs}/road_strip.json +2 -2
  348. package/{shelf → library/street/versions/1.0/graphs}/sign_post.json +1 -1
  349. package/library/street/versions/1.0/street.topo +12 -0
  350. package/library/street/versions/1.0/version.json +421 -0
  351. package/package.json +23 -8
  352. package/dist/graph/migrate.d.ts +0 -23
  353. package/dist/graph/migrate.js +0 -58
  354. package/shelf/index.json +0 -190
@@ -1,4 +1,4 @@
1
- /* The viewer page (docs/design/viewer.md): a neutral editor UI around the viewport. Section 7 colours: viewport
1
+ /* The viewer page: a neutral editor UI around the viewport. Colours: viewport
2
2
  #2b2d31, selection orange #f0a030, guides one desaturated cyan. */
3
3
  :root {
4
4
  --bg: #1f2124; --panel: #26282c; --panel2: #2c2f33; --line: #3a3d42; --text: #d6d9dd; --dim: #8c939b; --faint: #5d636b;
@@ -32,6 +32,12 @@ input:focus, select:focus { outline: 1px solid var(--faint); outline-offset: -1p
32
32
  #top .tb select { color: var(--text); max-width: 180px; }
33
33
  #top .readout { font: var(--mono); color: var(--dim); min-width: 84px; }
34
34
  #top .mode { color: var(--sel); }
35
+ #top button.tb.on { border-color: var(--sel); color: var(--sel); }
36
+ #top .tools { gap: 0; }
37
+ #top .tools button { margin-left: -1px; border-radius: 0; }
38
+ #top .tools button:first-of-type { margin-left: 4px; border-radius: 3px 0 0 3px; }
39
+ #top .tools button:last-of-type { border-radius: 0 3px 3px 0; }
40
+ #top .tools button.on { border-color: var(--sel); color: var(--sel); position: relative; }
35
41
  .grow { flex: 1; }
36
42
 
37
43
  /* panels */
@@ -42,8 +48,9 @@ input:focus, select:focus { outline: 1px solid var(--faint); outline-offset: -1p
42
48
  .phead .count { margin-left: auto; letter-spacing: 0; }
43
49
  .pscroll { overflow: auto; min-height: 0; }
44
50
  #tree { flex: 1; }
45
- #props-body { flex: 0 0 var(--split); }
46
- #controls { flex: 1; }
51
+ /* the Controls first, as tall as they need up to the split; Properties below, scrolling */
52
+ #controls { flex: 0 1 auto; max-height: var(--split); min-height: 32px; }
53
+ #props-scroll { flex: 1; }
47
54
  .grip { position: absolute; z-index: 5; }
48
55
  .grip.v { top: 0; bottom: 0; width: 6px; cursor: col-resize; }
49
56
  #outliner .grip.v { right: -3px; }
@@ -63,6 +70,10 @@ input:focus, select:focus { outline: 1px solid var(--faint); outline-offset: -1p
63
70
  .row.part { border-left-color: rgba(240, 160, 48, 0.5); }
64
71
  .row .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
65
72
  .row .mt { color: var(--dim); font-size: 11px; white-space: nowrap; }
73
+ /* a node of a package with an update (in the accent colour), or one followed this session (in the guides' colour) */
74
+ .row .pmark { flex: none; color: var(--sel); font-size: 11px; white-space: nowrap; cursor: pointer; }
75
+ .row .pmark:hover { text-decoration: underline; }
76
+ .row .pmark.live { color: var(--guide); }
66
77
  .row .err { color: var(--err); }
67
78
  .row.err .nm { color: var(--err); }
68
79
  .row .eye { flex: 0 0 16px; width: 16px; height: 16px; padding: 0; border: 0; background: none; display: grid; place-items: center; cursor: pointer; color: var(--dim); }
@@ -97,6 +108,17 @@ input:focus, select:focus { outline: 1px solid var(--faint); outline-offset: -1p
97
108
  .vw .lbl { position: absolute; transform: translate(8px, -50%); padding: 0 4px; font: var(--font); color: var(--text); background: rgba(31, 33, 36, 0.78); border-radius: 2px; white-space: nowrap; }
98
109
  .vw .lbl.sel { color: var(--sel); }
99
110
  .vw .lbl.dimen { transform: translate(-50%, -130%); font: var(--mono); color: var(--sel); }
111
+ /* while there is no graph: the package's name, what to do, TopoTopo's built-in packages (welcome.js) */
112
+ #welcome { position: absolute; inset: 0; z-index: 3; display: grid; place-items: center; padding: 24px; overflow: auto; background: rgba(43, 45, 49, 0.82); }
113
+ .welcome-box { max-width: 560px; padding: 20px 24px; background: var(--panel); border: 1px solid var(--line); border-radius: 4px; font-size: 13px; line-height: 1.5; }
114
+ .welcome-box h1 { margin: 0; font-size: 20px; font-weight: 600; }
115
+ .welcome-box h2 { margin: 16px 0 6px; font-size: 12px; font-weight: 600; color: var(--dim); text-transform: uppercase; letter-spacing: .05em; }
116
+ .welcome-box p { margin: 8px 0; }
117
+ .welcome-box code { font: var(--mono); color: var(--text); background: var(--bg); padding: 1px 4px; border-radius: 2px; overflow-wrap: anywhere; }
118
+ .welcome-sub { color: var(--dim); font: var(--mono); overflow-wrap: anywhere; }
119
+ .welcome-lead { font-size: 14px; color: var(--sel); }
120
+ .welcome-builtin { margin: 0; padding-left: 18px; }
121
+ .welcome-builtin li { margin: 4px 0; }
100
122
  #boxsel { position: absolute; border: 1px dashed var(--sel); background: rgba(240, 160, 48, 0.06); pointer-events: none; }
101
123
  #viewport.placing #gl { cursor: crosshair; }
102
124
  #viewport.nav #gl { cursor: move; }
@@ -120,6 +142,9 @@ input:focus, select:focus { outline: 1px solid var(--faint); outline-offset: -1p
120
142
  .attrs td { padding: 1px 4px 1px 0; vertical-align: top; overflow-wrap: anywhere; }
121
143
  .attrs td:first-child { color: var(--dim); white-space: nowrap; }
122
144
  .summary { margin: 0; font: var(--mono); color: var(--text); white-space: pre-wrap; overflow-wrap: anywhere; }
145
+ /* the geometry summary, folded under its one-line kind */
146
+ .fold > summary { cursor: pointer; color: var(--dim); font-size: 11px; user-select: none; margin: 4px 0; }
147
+ .fold > summary:hover { color: var(--text); }
123
148
  .hint { color: var(--dim); font-size: 11px; overflow-wrap: anywhere; }
124
149
  .bad { border-color: var(--err) !important; }
125
150
  .danger:hover { border-color: var(--err); color: var(--err); }
@@ -128,7 +153,37 @@ input:focus, select:focus { outline: 1px solid var(--faint); outline-offset: -1p
128
153
  #controls { padding: 4px 6px 8px; }
129
154
  .ctl { display: flex; align-items: center; gap: 4px; min-height: 26px; padding: 1px 2px; }
130
155
  .ctl:hover { background: var(--hover-bg); }
131
- .ctl > .cl { flex: 0 0 92px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
156
+ .ctl > .cl { flex: 0 0 88px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
157
+ /* a value that differs from the graph file: a bar before its name, the name in the accent colour */
158
+ .ctl > .cmark { flex: 0 0 3px; width: 3px; height: 16px; border-radius: 1px; }
159
+ .ctl.changed > .cmark { background: var(--sel); }
160
+ .ctl.changed > .cl { color: var(--sel); }
161
+ /* above the controls: the cook state (always one line, so nothing below moves) and, over a graph file, the session */
162
+ #controls-bar { position: relative; flex: none; display: flex; flex-direction: column; gap: 2px; padding: 3px 8px 4px; border-bottom: 1px solid var(--line); }
163
+ #controls-bar::after { content: ''; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; pointer-events: none; }
164
+ /* while a cook runs: a still accent line. Nothing on the page moves on its own while a cook runs (an animation repaints
165
+ the page every frame, which takes the processor from the cook); the time the cook line counts shows it is alive */
166
+ #props.cooking #controls-bar::after { background: var(--sel); opacity: .7; }
167
+ #controls-bar .cookline { height: 20px; }
168
+ .sessionline { display: flex; align-items: center; gap: 6px; height: 22px; }
169
+ .sessionline .stext { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--dim); }
170
+ .sessionline button { flex: none; padding: 0 8px; height: 20px; }
171
+ .sessionline button:disabled { opacity: .45; cursor: default; }
172
+ /* the cook state: what cooks and for how long, how the last cook ended */
173
+ .cookline { display: flex; align-items: center; gap: 6px; min-width: 0; white-space: nowrap; color: var(--dim); }
174
+ .cookline .ctext { overflow: hidden; text-overflow: ellipsis; min-width: 0; font: var(--mono); }
175
+ .cookline .cdot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
176
+ .cookline .cstop { display: none; flex: none; padding: 0 8px; height: 18px; line-height: 1; }
177
+ .cookline.running, .cookline.stopping { color: var(--sel); }
178
+ .cookline.running .cdot, .cookline.stopping .cdot { background: var(--sel); }
179
+ .cookline.running .cstop { display: inline-block; }
180
+ .cookline.failed { color: var(--err); }
181
+ .cookline.failed .cdot { background: var(--err); }
182
+ .cookline.stopped { color: var(--text); }
183
+ .cookline.stopped .cdot { background: var(--dim); border-radius: 1px; }
184
+ .cookline.ok .cdot { background: var(--ok); }
185
+ .cookline.none .cdot { visibility: hidden; }
186
+ #status .cookline { max-width: 60%; }
132
187
  .ctl > .cw { flex: 1; display: flex; gap: 4px; align-items: center; min-width: 0; }
133
188
  .cw input { padding: 1px 4px; }
134
189
  .cw input[type=range] { flex: 1; min-width: 40px; padding: 0; border: 0; background: none; accent-color: var(--sel); }
@@ -147,15 +202,18 @@ input:focus, select:focus { outline: 1px solid var(--faint); outline-offset: -1p
147
202
 
148
203
  /* status bar */
149
204
  #status { grid-area: status; display: flex; align-items: center; gap: 8px; padding: 0 8px; background: var(--panel); border-top: 1px solid var(--line); white-space: nowrap; overflow: hidden; color: var(--dim); }
150
- #msg { overflow: hidden; text-overflow: ellipsis; min-width: 0; }
151
- #msg.err { color: var(--err); }
152
- #msg.ok { color: var(--ok); }
153
- #msg.busy { color: var(--sel); }
154
205
  #cook { overflow: hidden; text-overflow: ellipsis; min-width: 0; font: var(--mono); }
155
206
  #cook .err { color: var(--err); }
207
+ /* messages: over the view's lower left, clearing themselves (status.js) */
208
+ #notes { position: absolute; left: 8px; bottom: 8px; z-index: 5; display: flex; align-items: flex-start; gap: 6px; max-width: min(640px, calc(100% - 96px)); padding: 5px 4px 5px 10px; background: rgba(38, 40, 44, 0.94); border: 1px solid var(--line); border-radius: 3px; color: var(--text); }
209
+ #msg { min-width: 0; overflow-wrap: anywhere; white-space: pre-line; max-height: 6.5em; overflow: hidden; }
210
+ #notes.err { border-color: var(--err); } #notes.err #msg { color: var(--err); }
211
+ #notes.ok #msg { color: var(--ok); }
212
+ #notes.busy #msg { color: var(--sel); }
156
213
  #ask { display: flex; gap: 6px; align-items: center; color: var(--text); }
157
214
  #ask[hidden] { display: none; }
158
215
  #ask button { padding: 0 8px; }
216
+ #msg-close { flex: none; width: 18px; height: 18px; }
159
217
 
160
218
  /* drop zone */
161
219
  #drop { position: fixed; inset: 8px; z-index: 20; display: none; align-items: center; justify-content: center; text-align: center; border: 2px dashed var(--sel); background: rgba(240, 160, 48, 0.06); color: var(--sel); font-size: 15px; pointer-events: none; }
@@ -1,7 +1,7 @@
1
1
  // Units on screen: the adaptive grid's step and how lengths and coordinates are printed (metres, Y up).
2
2
  // Plain functions, tested in Node (test/viewer-logic.ts).
3
3
 
4
- /** The grid steps the views choose from (docs/design/viewer.md section 4), in metres. */
4
+ /** The grid steps the views choose from, in metres. */
5
5
  export const GRID_STEPS = [0.01, 0.1, 1, 10, 100, 1000];
6
6
  /** Major lines every this many steps. */
7
7
  export const MAJOR_EVERY = 10;
@@ -1,4 +1,4 @@
1
- // The Controls section's rules (docs/design/viewer.md section 8): which widget a var gets, a slider's range and step,
1
+ // The Controls section's rules: which widget a var gets, a slider's range and step,
2
2
  // how values print. Plain functions, tested in Node (test/viewer-logic.ts); props.js builds the widgets.
3
3
 
4
4
  export const isNum = (v) => typeof v === 'number' && Number.isFinite(v);
@@ -26,6 +26,18 @@ export function kindOf(vd, v) {
26
26
  return k;
27
27
  }
28
28
 
29
+ /**
30
+ * A menu's entries (a var with options): their texts, and the value an entry stands for: the option itself, so
31
+ * numeric options give numbers ([4, 8, 16] → 8, not "8"). A number var with text options only holds the option's
32
+ * index (byIndex). valueOf gives undefined for a text that is no option (an entry shown for a value outside them).
33
+ */
34
+ export function menuOf(vd, value) {
35
+ const opts = vd.options, texts = opts.map(String);
36
+ const byIndex = isNum(value) && opts.every((o) => typeof o === 'string') && !texts.includes(String(value));
37
+ const valueOf = (text) => { const i = texts.indexOf(text); return byIndex ? (i >= 0 ? i : undefined) : i >= 0 ? opts[i] : undefined; };
38
+ return { texts, byIndex, valueOf, textOf: (v) => (byIndex ? texts[v] : String(v)) };
39
+ }
40
+
29
41
  /** A value to show for a declared param that has neither a var nor a default. */
30
42
  export function blank(vd) {
31
43
  const t = vd?.type ?? '';
@@ -62,3 +74,38 @@ export const snapTo = (r, v) => +(r.lo + Math.round((v - r.lo) / r.step) * r.ste
62
74
  export function controlList(params = {}, vars = {}) {
63
75
  return { declared: Object.keys(params), other: Object.keys(vars).filter((k) => !(k in params)) };
64
76
  }
77
+
78
+ /**
79
+ * What a control's ↺ goes back to. Over a graph file ("file" mode) the graph's own value (graphVars), else its
80
+ * declared default, else a blank of its type; in a package the declared default (undefined: no reset).
81
+ */
82
+ export function baseValue(mode, vd, graphVars, k) {
83
+ if (mode !== 'file') return vd?.default;
84
+ if (graphVars && Object.hasOwn(graphVars, k)) return graphVars[k];
85
+ return vd?.default !== undefined ? vd.default : blank(vd);
86
+ }
87
+
88
+ /**
89
+ * A control's shape: its widget and what the widget is built from (the declaration, the value's kind and length). A
90
+ * row keeps its element while its shape stays; a new shape builds the row again.
91
+ */
92
+ export function rowShape(vd, value) {
93
+ return JSON.stringify([kindOf(vd, value), vd ?? null, jsonKind(value), Array.isArray(value) ? value.length : 0]);
94
+ }
95
+
96
+ /**
97
+ * Whether a value the server reported for var k may replace what its control shows. `issued`: when the report was
98
+ * asked for (a graph list read earlier stays as old as it was). Not while the person has a change of k on the way
99
+ * (pending, sent and not answered), is dragging it or typing in it, nor when an answer about k came after the report.
100
+ * st: {pending: {k: v}, unacked: Map, ackAt: Map(k → time), active: k | null, typing: (k) => bool}.
101
+ */
102
+ export function serverValueWins(st, k, issued) {
103
+ return !(k in st.pending) && !st.unacked.has(k) && !((st.ackAt.get(k) ?? -1e9) > issued) && st.active !== k && !st.typing(k);
104
+ }
105
+
106
+ /** The line above the Controls over a graph file: how many values differ from it. */
107
+ export function sessionText(changed, file) {
108
+ const where = file ?? 'the graph';
109
+ if (!changed) return `values as in ${where}`;
110
+ return `${changed} value${changed === 1 ? '' : 's'} differ${changed === 1 ? 's' : ''} from ${where}`;
111
+ }
@@ -0,0 +1,72 @@
1
+ // What the viewer says about the package it shows (GET /api/package): the page's title, the graph shown first, and the
2
+ // welcome in the viewport while there is no graph: a package's name with a pointer to TopoTopo's built-in packages and to the agent
3
+ // that builds the graphs, or, for a folder that is no package, that it is none and how to make it one. The plain
4
+ // functions are tested in Node (test/viewer-logic.ts).
5
+
6
+ const el = (tag, cls, text) => { const e = document.createElement(tag); if (cls) e.className = cls; if (text !== undefined) e.textContent = text; return e; };
7
+ const baseName = (p) => String(p ?? '').replace(/[\\/]+$/, '').split(/[\\/]/).pop() || String(p ?? '');
8
+
9
+ /** The browser tab's title: "<package> · TopoTopo", the graph file's or the folder's name before it. */
10
+ export function pageTitle(info) {
11
+ const name = info?.package ? info.package.title || info.package.id : info?.file ?? (info?.folder ? baseName(info.folder) : '');
12
+ return name ? `${name} · TopoTopo` : 'TopoTopo';
13
+ }
14
+
15
+ /** The graph shown first: the package's default graph when it has it, else the first. */
16
+ export const defaultGraph = (info, names) => (info?.package && names.includes(info.package.graph) ? info.package.graph : names[0] ?? null);
17
+
18
+ /**
19
+ * The welcome while there is no graph: {kind, title, sub, lead, steps, builtin}. kind "package" (a package without graphs)
20
+ * or "folder" (a folder that is no package).
21
+ */
22
+ export function welcomeOf(info) {
23
+ const builtin = info?.builtin ?? [];
24
+ if (info?.package) {
25
+ const p = info.package;
26
+ return {
27
+ kind: 'package', title: p.title || p.id, sub: `package ${p.id}${p.name ? ` · publishes as ${p.name}` : ''}`, builtin,
28
+ lead: 'This package has no graphs yet.',
29
+ steps: [
30
+ 'Ask your agent to build one here, for example: "Build a street with two houses, lamp posts and trees from TopoTopo\'s built-in packages."',
31
+ 'It shows here as soon as your agent builds it, and so does every change after that.',
32
+ ],
33
+ };
34
+ }
35
+ const folder = info?.folder ?? '';
36
+ return {
37
+ kind: 'folder', title: baseName(folder) || 'This folder', sub: folder, builtin,
38
+ lead: 'This folder is not a TopoTopo package.',
39
+ steps: [
40
+ 'A package keeps its graphs, the packages they use and their exports together, and shows in the web app.',
41
+ `Ask your agent to make this folder a package, or run: topotopo init "${folder}"`,
42
+ 'Your agent can also build a graph here as it is: it shows here at once.',
43
+ ],
44
+ };
45
+ }
46
+
47
+ /** The welcome panel in the viewport: shown while `show`, built from `info` (GET /api/package). */
48
+ export function renderWelcome(host, info, show) {
49
+ host.hidden = !show;
50
+ if (!show) { host.replaceChildren(); return; }
51
+ const w = welcomeOf(info), box = el('div', 'welcome-box');
52
+ box.append(el('h1', '', w.title), el('div', 'welcome-sub', w.sub), el('p', 'welcome-lead', w.lead));
53
+ for (const s of w.steps) {
54
+ // a command to type shows as one
55
+ const p = el('p'), at = s.indexOf('run: ');
56
+ if (at < 0) p.textContent = s; else p.append(s.slice(0, at + 5), el('code', '', s.slice(at + 5)));
57
+ box.append(p);
58
+ }
59
+ if (w.builtin.length) {
60
+ box.append(el('h2', '', 'TopoTopo\'s built-in packages: ready-made parts your agent can use'));
61
+ const list = el('ul', 'welcome-builtin');
62
+ for (const k of w.builtin) {
63
+ const li = el('li');
64
+ li.append(el('strong', '', k.title), el('span', 'dim', ` · ${k.name}${k.version ? ` ${k.version}` : ''}`), el('div', 'dim', k.outputs));
65
+ li.title = k.description;
66
+ list.append(li);
67
+ }
68
+ box.append(list);
69
+ }
70
+ box.append(el('p', 'dim', 'Reference files (meshes, curves, images) dropped anywhere on this page go to inputs/, where your agent reads them.'));
71
+ host.replaceChildren(box);
72
+ }
@@ -0,0 +1,62 @@
1
+ import '../nodes/index.ts';
2
+ import { Session } from '../session.ts';
3
+ import type { Viewer } from './server.ts';
4
+ import type { JSONEdit } from './json-edit.ts';
5
+ /** Where a graph's source lives when it is not the package's graphs/ folder (ViewerOptions.source). */
6
+ export interface GraphSource {
7
+ /** the package graph it holds */
8
+ graph: string;
9
+ /** its file name, for the page ("boxes.json") */
10
+ label: string;
11
+ /**
12
+ * Write these changes into the source, then store the graph as the source now has it (Session.setGraph, which
13
+ * also lets session values the graph now holds go). Throws when it cannot write.
14
+ */
15
+ save(edits: JSONEdit[]): void;
16
+ }
17
+ export declare class GraphFile implements GraphSource {
18
+ readonly graph: string;
19
+ readonly label: string;
20
+ readonly file: string;
21
+ private ws;
22
+ private log;
23
+ /** the file's text as last read or written: a change event that finds it again is the viewer's own write */
24
+ private text;
25
+ private watcher;
26
+ private timer;
27
+ private loading;
28
+ private again;
29
+ constructor(ws: Session, file: string, graph: string, log?: (line: string) => void);
30
+ /**
31
+ * Read the file into the package graph and cook it, unless it holds what the graph already is. A file that is not
32
+ * valid JSON (half saved, a typo) keeps the last good version. Loads never overlap: a change during one loads again.
33
+ */
34
+ load(): Promise<void>;
35
+ private loadOnce;
36
+ /** Cook the graph as it is, say how it went, and have the page read it again. */
37
+ cook(): Promise<void>;
38
+ save(edits: JSONEdit[]): void;
39
+ /** Follow saves of the file: its folder is watched, so editors that save by replacing the file are followed too. */
40
+ watch(): void;
41
+ close(): void;
42
+ }
43
+ export interface ViewGraphFileOptions {
44
+ /** the graph's name in the package and on the page (the file name, made a valid graph name) */
45
+ name: string;
46
+ port?: number;
47
+ /** where status lines go (default: stdout) */
48
+ log?: (line: string) => void;
49
+ /** packages ("owner/name") whose working folders the graph uses instead of their copies, for this session */
50
+ follow?: string[];
51
+ }
52
+ /**
53
+ * `topotopo view <graph.json>`: cook the file, serve the live viewer on it and follow its saves. The session is a
54
+ * scratch folder; inputs/ and exports/ are beside the graph file (inputs/ made by the first file dropped on the page).
55
+ */
56
+ export declare function viewGraphFile(file: string, opts: ViewGraphFileOptions): Promise<{
57
+ url: string;
58
+ viewer: Viewer;
59
+ ws: Session;
60
+ source: GraphFile;
61
+ close: () => void;
62
+ }>;
@@ -0,0 +1,175 @@
1
+ // `topotopo view <graph.json>`: the live viewer on one graph file, which stays the only source of the graph. GraphFile
2
+ // loads the file into a scratch session, follows its saves (the person's editor, an agent) and writes what the page
3
+ // changes back into it as minimal edits (json-edit.ts): an export target, the values "Save values to graph" keeps.
4
+ // The rest of the file stays as it was written. The values a person tunes are session values over the graph
5
+ // (Session.sessionVars): they survive every reload of the file, the viewer's own writes included. The graph uses the
6
+ // packages the file's package uses; one it names for the first time is added to the package, and a package
7
+ // followed with --follow (or the viewer's switch) re-cooks the graph whenever its working folder changes.
8
+ import fs from 'node:fs';
9
+ import os from 'node:os';
10
+ import path from 'node:path';
11
+ import '../nodes/index.js';
12
+ import { Engine } from '../graph/engine.js';
13
+ import { createNodeHost } from '../host/node.js';
14
+ import { openPackages } from '../packages/registry.js';
15
+ import { Session } from '../session.js';
16
+ import { startViewer } from './server.js';
17
+ import { exportsFolderFor } from '../host/export-targets.js';
18
+ import { applyJSONEdits, editJSONText } from './json-edit.js';
19
+ const errorText = (e) => String(e?.message ?? e);
20
+ export class GraphFile {
21
+ graph;
22
+ label;
23
+ file;
24
+ ws;
25
+ log;
26
+ /** the file's text as last read or written: a change event that finds it again is the viewer's own write */
27
+ text = null;
28
+ watcher = null;
29
+ timer;
30
+ loading = null;
31
+ again = false;
32
+ constructor(ws, file, graph, log = (l) => console.log(l)) {
33
+ this.ws = ws;
34
+ this.file = path.resolve(file);
35
+ this.graph = graph;
36
+ this.label = path.basename(file);
37
+ this.log = log;
38
+ }
39
+ /**
40
+ * Read the file into the package graph and cook it, unless it holds what the graph already is. A file that is not
41
+ * valid JSON (half saved, a typo) keeps the last good version. Loads never overlap: a change during one loads again.
42
+ */
43
+ load() {
44
+ if (this.loading) {
45
+ this.again = true;
46
+ return this.loading;
47
+ }
48
+ this.loading = (async () => {
49
+ try {
50
+ do {
51
+ this.again = false;
52
+ await this.loadOnce();
53
+ } while (this.again);
54
+ }
55
+ finally {
56
+ this.loading = null;
57
+ }
58
+ })();
59
+ return this.loading;
60
+ }
61
+ async loadOnce() {
62
+ let text;
63
+ try {
64
+ text = fs.readFileSync(this.file, 'utf8');
65
+ }
66
+ catch (e) {
67
+ this.log(`${this.file}: ${errorText(e)} (keeping the last good version)`);
68
+ return;
69
+ }
70
+ if (text === this.text && this.ws.graphs.has(this.graph))
71
+ return;
72
+ let spec;
73
+ try {
74
+ spec = JSON.parse(text.replace(/^/, ''));
75
+ }
76
+ catch (e) {
77
+ this.log(`${this.file}: ${errorText(e)} (keeping the last good version)`);
78
+ return;
79
+ }
80
+ this.text = text;
81
+ const cur = this.ws.graphs.get(this.graph);
82
+ try {
83
+ if (cur && JSON.stringify(spec) === JSON.stringify(cur))
84
+ return;
85
+ for (const n of this.ws.packages?.addFor(spec) ?? [])
86
+ this.log(n);
87
+ this.ws.setGraph(this.graph, spec);
88
+ }
89
+ catch (e) {
90
+ this.log(`${this.file}: ${errorText(e)} (keeping the last good version)`);
91
+ return;
92
+ }
93
+ await this.cook();
94
+ }
95
+ /** Cook the graph as it is, say how it went, and have the page read it again. */
96
+ async cook() {
97
+ const r = await this.ws.cook(this.graph);
98
+ const what = r.ok ? 'cooked' : r.stopped ? 'stopped' : 'FAILED';
99
+ this.log(`${what} ${this.graph} in ${r.ms.toFixed(0)} ms${r.ok ? '' : r.stopped ? ` at ${r.stopped}` : ': ' + r.errors.map((e) => `${e.node}: ${e.message}`).join('; ')}`);
100
+ // the graph changed, cooked or not: the page reads it again (a stopped cook leaves the last geometry in view)
101
+ this.ws.bump(this.graph);
102
+ }
103
+ save(edits) {
104
+ // the file as it is now: a save that has not been loaded yet is kept, the edits go on top of it
105
+ const before = fs.readFileSync(this.file, 'utf8');
106
+ let text;
107
+ try {
108
+ text = editJSONText(before, edits);
109
+ }
110
+ catch (e) {
111
+ if (e instanceof SyntaxError)
112
+ throw new Error(`${this.label} is not valid JSON now (${e.message}): fix it in the editor, then try again`);
113
+ // an edit the text editor cannot place: the content is still right, laid out as JSON.stringify does
114
+ text = JSON.stringify(applyJSONEdits(JSON.parse(before.replace(/^/, '')), edits), null, 2) + '\n';
115
+ this.log(`${this.file}: rewritten in full (${errorText(e)})`);
116
+ }
117
+ if (text !== before)
118
+ fs.writeFileSync(this.file, text);
119
+ this.text = text;
120
+ const spec = JSON.parse(text.replace(/^/, ''));
121
+ const cur = this.ws.graphs.get(this.graph);
122
+ if (!cur || JSON.stringify(spec) !== JSON.stringify(cur))
123
+ this.ws.setGraph(this.graph, spec);
124
+ }
125
+ /** Follow saves of the file: its folder is watched, so editors that save by replacing the file are followed too. */
126
+ watch() {
127
+ if (this.watcher)
128
+ return;
129
+ const base = path.basename(this.file);
130
+ try {
131
+ this.watcher = fs.watch(path.dirname(this.file), (_ev, f) => {
132
+ if (f && path.basename(String(f)) !== base)
133
+ return;
134
+ clearTimeout(this.timer);
135
+ this.timer = setTimeout(() => { this.load().catch((e) => this.log(errorText(e))); }, 150);
136
+ });
137
+ this.watcher.on('error', () => { this.watcher?.close(); this.watcher = null; });
138
+ this.watcher.unref();
139
+ }
140
+ catch (e) {
141
+ this.log(`${this.file}: cannot watch it (${errorText(e)}); restart the viewer after saving`);
142
+ }
143
+ }
144
+ close() {
145
+ clearTimeout(this.timer);
146
+ this.watcher?.close();
147
+ this.watcher = null;
148
+ }
149
+ }
150
+ /**
151
+ * `topotopo view <graph.json>`: cook the file, serve the live viewer on it and follow its saves. The session is a
152
+ * scratch folder; inputs/ and exports/ are beside the graph file (inputs/ made by the first file dropped on the page).
153
+ */
154
+ export async function viewGraphFile(file, opts) {
155
+ const log = opts.log ?? ((l) => console.log(l));
156
+ const dir = path.dirname(path.resolve(file));
157
+ const engine = new Engine(createNodeHost({ baseDir: dir }));
158
+ await engine.init();
159
+ const packages = openPackages(engine, dir, { follow: opts.follow });
160
+ // exports go into the package's exports/ (a graph file in no package: beside it), as the CLI's do
161
+ const ws = new Session(fs.mkdtempSync(path.join(os.tmpdir(), 'topotopo-view-')), engine, { inputs: path.join(dir, 'inputs'), exports: exportsFolderFor(file) });
162
+ ws.packages = packages;
163
+ ws.load();
164
+ for (const p of packages.check())
165
+ log(`warning: ${p}`);
166
+ for (const f of packages.following())
167
+ log(`following ${f.package}: its working folder ${f.dir} instead of its copy`);
168
+ const source = new GraphFile(ws, file, opts.name, log);
169
+ await source.load();
170
+ // the viewer cooks the graph again after a save in the working folder of a package it follows (src/viewer/packages.ts)
171
+ const viewer = await startViewer(ws, opts.port, { inputsWhere: `beside ${path.basename(file)}`, source });
172
+ log(`view: ${viewer.url} (watching ${file}; files dropped on the page go to ${path.join(path.dirname(file), 'inputs') + path.sep}; Ctrl+C to stop)`);
173
+ source.watch();
174
+ return { url: viewer.url, viewer, ws, source, close: () => { source.close(); viewer.close(); } };
175
+ }
@@ -3,9 +3,9 @@
3
3
  <head>
4
4
  <meta charset="utf-8">
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1">
6
- <title>TopoTopo Viewer</title>
6
+ <title>TopoTopo</title>
7
7
  <link rel="icon" href="data:,">
8
- <!-- the viewer page (docs/design/viewer.md): ES modules from /app/, three.js from /vendor/three/, no build step -->
8
+ <!-- the viewer page: ES modules from /app/, three.js from /vendor/three/, no build step -->
9
9
  <link rel="stylesheet" href="/app/style.css">
10
10
  <link rel="stylesheet" href="/app/outputs.css">
11
11
  <script type="importmap">{ "imports": { "three": "/vendor/three/build/three.module.js", "three/addons/": "/vendor/three/examples/jsm/" } }</script>
@@ -19,18 +19,26 @@
19
19
  <label class="tb" title="the current view's shading; see ? for active key bindings">shading <select id="view-shading"></select></label>
20
20
  <span class="tb readout" id="step" title="the current view's grid step"></span>
21
21
  <button class="tb" id="quad" title="single / quad view">quad</button>
22
+ <span class="tb tools" id="guide-tools" role="group" aria-label="guide tools" title="guides: nulls, curves, areas and volumes you place to direct the graph and the agent; they are saved as inputs/markers.json">guides
23
+ <button data-tool="selectMode" title="select and drag: drag a guide to move it, a point to move that point; double-click a curve to add a CV, a CV to remove it">select</button>
24
+ <button data-tool="placeNull" title="place nulls: click the ground or the geometry (Shift+1)">null</button>
25
+ <button data-tool="placeCurve" title="draw a curve: click its CVs, Enter finishes (Shift+2)">curve</button>
26
+ <button data-tool="placeArea" title="draw an area: click its corners, Enter closes it (Shift+3)">area</button>
27
+ <button data-tool="placeVolume" title="drag a volume: drag a rectangle on the ground (Shift+4)">volume</button>
28
+ </span>
29
+ <button class="tb" id="edge-check" title="edge check: draw open (pink), non-manifold (yellow) and flipped (violet) edges over the meshes, as the render tool does">edge check</button>
22
30
  <span class="grow"></span>
23
- <button class="tb" id="scene-view" title="back to the whole scene after looking at one output">Scene</button>
31
+ <button class="tb" id="scene-view" title="back to the whole scene: the graph's output with the reference layers and guides">Scene</button>
24
32
  <span class="tb mode" id="mode"></span>
25
33
  <label class="tb" title="keyboard and mouse bindings, remembered in this browser">keymap <select id="preset"></select></label>
26
34
  <button class="tb" id="help" title="the keymap (?)">?</button>
27
35
  </header>
28
36
  <aside id="outliner" class="panel">
29
- <div class="phead tabs" role="tablist" aria-label="Scene, outputs and inputs">
37
+ <div class="phead tabs" role="tablist" aria-label="Scene, outputs, inputs and packages">
30
38
  <button role="tab" id="tab-scene" data-tab="scene" aria-controls="tree">Scene</button>
31
39
  <button role="tab" id="tab-outputs" data-tab="outputs" aria-controls="outputs-pane">Outputs <span class="count"></span></button>
32
40
  <button role="tab" id="tab-inputs" data-tab="inputs" aria-controls="inputs-pane">Inputs <span class="count"></span></button>
33
- <button id="thumb-size" title="Cycle thumbnail size" aria-label="Cycle thumbnail size">56 px</button>
41
+ <button role="tab" id="tab-packages" data-tab="packages" aria-controls="packages-pane" hidden>Packages <span class="count"></span></button>
34
42
  </div>
35
43
  <div class="pscroll tabpane" id="tree" data-pane="scene" role="tabpanel" aria-labelledby="tab-scene"></div>
36
44
  <div class="pscroll tabpane" id="outputs-pane" data-pane="outputs" role="tabpanel" aria-labelledby="tab-outputs"><div id="outputs"></div></div>
@@ -39,25 +47,30 @@
39
47
  <input id="input-file" type="file" multiple hidden accept=".glb,.gltf,.obj,.stl,.ply,.geo,.bgeo,.blend,.csv,.json,.png,.jpg,.jpeg,.webp">
40
48
  <div id="inputs-list"></div>
41
49
  </div>
50
+ <div class="pscroll tabpane" id="packages-pane" data-pane="packages" role="tabpanel" aria-labelledby="tab-packages"><div id="packages"></div></div>
42
51
  <div class="grip v" data-grip="left" title="drag to resize"></div>
43
52
  </aside>
44
53
  <main id="viewport">
45
54
  <canvas id="gl"></canvas>
46
55
  <div id="views"></div>
47
56
  <div id="boxsel" hidden></div>
57
+ <div id="welcome" hidden></div>
58
+ <div id="notes" hidden><span id="msg"></span><span id="ask" hidden><span id="ask-text"></span><button id="ask-yes">Yes</button><button id="ask-no">No</button></span><button id="msg-close" class="ib" title="close" aria-label="close the message">×</button></div>
48
59
  </main>
49
60
  <aside id="props" class="panel">
50
61
  <div class="grip v" data-grip="right" title="drag to resize"></div>
51
- <div class="phead">Properties</div>
52
- <div id="output-details" hidden></div>
53
- <div class="pscroll" id="props-body"></div>
54
- <div class="grip h" data-grip="split" title="drag to resize"></div>
55
62
  <div class="phead">Controls <span class="count" id="controls-count"></span></div>
63
+ <div id="controls-bar">
64
+ <div class="cookline" id="controls-cook"><span class="cdot"></span><span class="ctext"></span></div>
65
+ <div class="sessionline" id="controls-session" hidden><span class="stext"></span><button id="vars-save" type="button">Save values</button><button id="vars-reset" type="button">Reset all</button></div>
66
+ </div>
56
67
  <div class="pscroll" id="controls"></div>
68
+ <div class="grip h" data-grip="split" title="drag to resize"></div>
69
+ <div class="phead">Properties</div>
70
+ <div class="pscroll" id="props-scroll"><div id="output-details" hidden></div><div id="props-body"></div></div>
57
71
  </aside>
58
72
  <footer id="status">
59
- <span id="msg"></span>
60
- <span id="ask" hidden><span id="ask-text"></span><button id="ask-yes">Yes</button><button id="ask-no">No</button></span>
73
+ <span class="cookline" id="status-cook"><span class="cdot"></span><span class="ctext"></span><button class="cstop" type="button" title="stop the cook at the next node">Stop</button></span>
61
74
  <span class="grow"></span>
62
75
  <span id="cook"></span>
63
76
  </footer>
@@ -0,0 +1,13 @@
1
+ export type JSONPath = readonly (string | number)[];
2
+ /** Set `value` at `path` (objects on the way are made); `value` undefined removes the member. */
3
+ export interface JSONEdit {
4
+ path: JSONPath;
5
+ value?: unknown;
6
+ }
7
+ /** `value` with the edits applied, the way JSON.parse of the edited text must read. */
8
+ export declare function applyJSONEdits(value: unknown, edits: readonly JSONEdit[]): unknown;
9
+ /**
10
+ * The JSON text with the edits made, every other character kept. Throws SyntaxError when the text is not JSON, and
11
+ * Error for an edit it cannot make (a key inside a number, removing an array item).
12
+ */
13
+ export declare function editJSONText(text: string, edits: readonly JSONEdit[]): string;