topotopo 0.4.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 (336) hide show
  1. package/NOTICE +10 -10
  2. package/README.md +460 -117
  3. package/dist/cli.js +323 -146
  4. package/dist/config.d.ts +48 -0
  5. package/dist/config.js +170 -0
  6. package/dist/core/bake.d.ts +14 -3
  7. package/dist/core/bake.js +153 -4
  8. package/dist/core/bevel.d.ts +3 -1
  9. package/dist/core/bevel.js +76 -3
  10. package/dist/core/decimate.d.ts +65 -0
  11. package/dist/core/decimate.js +409 -3
  12. package/dist/core/erosion.d.ts +37 -0
  13. package/dist/core/erosion.js +41 -1
  14. package/dist/core/geometry.d.ts +5 -1
  15. package/dist/core/geometry.js +203 -3
  16. package/dist/core/heightfield.d.ts +27 -4
  17. package/dist/core/heightfield.js +54 -16
  18. package/dist/core/intrinsics.d.ts +7 -0
  19. package/dist/core/intrinsics.js +94 -0
  20. package/dist/core/manifold.d.ts +12 -1
  21. package/dist/core/manifold.js +78 -6
  22. package/dist/core/materials.d.ts +7 -0
  23. package/dist/core/materials.js +45 -0
  24. package/dist/core/noise.d.ts +9 -0
  25. package/dist/core/noise.js +10 -1
  26. package/dist/core/polymerge.d.ts +21 -0
  27. package/dist/core/polymerge.js +327 -0
  28. package/dist/core/repair.d.ts +2 -0
  29. package/dist/core/repair.js +2 -0
  30. package/dist/core/report.d.ts +70 -0
  31. package/dist/core/report.js +275 -0
  32. package/dist/core/scene.js +2 -1
  33. package/dist/core/sha256.d.ts +4 -0
  34. package/dist/core/sha256.js +69 -0
  35. package/dist/core/shapes.d.ts +3 -0
  36. package/dist/core/shapes.js +34 -0
  37. package/dist/core/snippet-lib.d.ts +14 -1
  38. package/dist/core/snippet-lib.js +39 -13
  39. package/dist/core/tangents.d.ts +2 -0
  40. package/dist/core/tangents.js +5 -1
  41. package/dist/core/texnoise.d.ts +6 -1
  42. package/dist/core/texnoise.js +6 -2
  43. package/dist/core/texsdf.d.ts +131 -0
  44. package/dist/core/texsdf.js +637 -0
  45. package/dist/core/texture.d.ts +163 -9
  46. package/dist/core/texture.js +844 -20
  47. package/dist/core/topology.d.ts +10 -0
  48. package/dist/core/topology.js +168 -0
  49. package/dist/core/unwrap.d.ts +72 -0
  50. package/dist/core/unwrap.js +800 -0
  51. package/dist/core/usercode.d.ts +27 -0
  52. package/dist/core/usercode.js +87 -0
  53. package/dist/core/uv.d.ts +4 -18
  54. package/dist/core/uv.js +35 -188
  55. package/dist/core/uvislands.d.ts +62 -0
  56. package/dist/core/uvislands.js +574 -0
  57. package/dist/core/uvoverlap.d.ts +58 -0
  58. package/dist/core/uvoverlap.js +220 -0
  59. package/dist/core/uvpack.d.ts +64 -0
  60. package/dist/core/uvpack.js +628 -0
  61. package/dist/core/uvreport.d.ts +61 -0
  62. package/dist/core/uvreport.js +207 -143
  63. package/dist/core/wrangle.d.ts +6 -1
  64. package/dist/core/wrangle.js +27 -16
  65. package/dist/core/xatlas.d.ts +16 -1
  66. package/dist/core/xatlas.js +66 -62
  67. package/dist/engines.d.ts +63 -0
  68. package/dist/engines.js +180 -0
  69. package/dist/explain.d.ts +4 -3
  70. package/dist/explain.js +129 -12
  71. package/dist/graph/engine.d.ts +92 -29
  72. package/dist/graph/engine.js +298 -148
  73. package/dist/graph/expr.d.ts +6 -3
  74. package/dist/graph/expr.js +18 -8
  75. package/dist/graph/outputs.d.ts +23 -0
  76. package/dist/graph/outputs.js +41 -0
  77. package/dist/graph/packages.d.ts +72 -0
  78. package/dist/graph/packages.js +261 -0
  79. package/dist/graph/parallel.d.ts +3 -1
  80. package/dist/graph/parallel.js +4 -1
  81. package/dist/graph/params.d.ts +6 -0
  82. package/dist/graph/params.js +34 -7
  83. package/dist/graph/scope.d.ts +55 -0
  84. package/dist/graph/scope.js +14 -0
  85. package/dist/graph/types.d.ts +75 -12
  86. package/dist/graph/types.js +4 -2
  87. package/dist/graph/vars.d.ts +16 -0
  88. package/dist/graph/vars.js +80 -0
  89. package/dist/host/artifacts.d.ts +10 -1
  90. package/dist/host/artifacts.js +37 -6
  91. package/dist/host/cook.d.ts +241 -0
  92. package/dist/host/cook.js +844 -0
  93. package/dist/host/export-targets.d.ts +42 -5
  94. package/dist/host/export-targets.js +72 -13
  95. package/dist/host/godot-commands.d.ts +4 -0
  96. package/dist/host/godot-commands.js +21 -0
  97. package/dist/host/godot.d.ts +183 -0
  98. package/dist/host/godot.js +916 -0
  99. package/dist/host/node.d.ts +12 -7
  100. package/dist/host/node.js +27 -9
  101. package/dist/host/pool.js +51 -2
  102. package/dist/host/sidecars.d.ts +8 -0
  103. package/dist/host/sidecars.js +50 -0
  104. package/dist/host/types.d.ts +19 -6
  105. package/dist/host/version.d.ts +1 -0
  106. package/dist/host/version.js +3 -0
  107. package/dist/host/worker.js +5 -2
  108. package/dist/index.d.ts +2 -2
  109. package/dist/index.js +1 -1
  110. package/dist/inspect.d.ts +80 -2
  111. package/dist/inspect.js +265 -30
  112. package/dist/io/common.d.ts +25 -5
  113. package/dist/io/export.js +2 -1
  114. package/dist/io/files.d.ts +23 -4
  115. package/dist/io/files.js +60 -8
  116. package/dist/io/gltf.js +134 -47
  117. package/dist/io/heightmap.d.ts +3 -0
  118. package/dist/io/heightmap.js +1 -0
  119. package/dist/io/import.js +10 -0
  120. package/dist/io/inspect-scene.d.ts +55 -0
  121. package/dist/io/inspect-scene.js +155 -0
  122. package/dist/io/kinds.d.ts +81 -0
  123. package/dist/io/kinds.js +163 -0
  124. package/dist/io/points.d.ts +2 -1
  125. package/dist/io/points.js +3 -1
  126. package/dist/io/sidecars.d.ts +24 -0
  127. package/dist/io/sidecars.js +57 -0
  128. package/dist/io/source.d.ts +65 -0
  129. package/dist/io/source.js +112 -0
  130. package/dist/io/targets.d.ts +47 -3
  131. package/dist/io/targets.js +148 -13
  132. package/dist/io/textures.js +21 -1
  133. package/dist/io/unreal.js +5 -1
  134. package/dist/mcp/docs.d.ts +10 -1
  135. package/dist/mcp/docs.js +786 -143
  136. package/dist/mcp/inputs.d.ts +12 -5
  137. package/dist/mcp/inputs.js +50 -13
  138. package/dist/mcp/server.js +56 -27
  139. package/dist/mcp/tools.d.ts +14 -7
  140. package/dist/mcp/tools.js +196 -103
  141. package/dist/mcp/verify.d.ts +2 -2
  142. package/dist/mcp/verify.js +1 -1
  143. package/dist/mcp/workspace.d.ts +15 -0
  144. package/dist/mcp/workspace.js +349 -0
  145. package/dist/nodes/attributes.js +198 -1
  146. package/dist/nodes/bake.js +151 -47
  147. package/dist/nodes/beam.d.ts +1 -0
  148. package/dist/nodes/beam.js +201 -0
  149. package/dist/nodes/bevel.js +51 -3
  150. package/dist/nodes/cloth.js +2 -0
  151. package/dist/nodes/code.js +21 -9
  152. package/dist/nodes/curves.js +433 -93
  153. package/dist/nodes/flow.js +53 -33
  154. package/dist/nodes/generate.js +12 -38
  155. package/dist/nodes/heightfield.js +248 -77
  156. package/dist/nodes/imageops.js +16 -19
  157. package/dist/nodes/index.d.ts +1 -0
  158. package/dist/nodes/index.js +1 -0
  159. package/dist/nodes/material.js +89 -24
  160. package/dist/nodes/measure.js +43 -17
  161. package/dist/nodes/particles.js +2 -0
  162. package/dist/nodes/pcg.js +6 -5
  163. package/dist/nodes/procedural.js +4 -3
  164. package/dist/nodes/remesh.js +71 -15
  165. package/dist/nodes/scene.js +4 -2
  166. package/dist/nodes/sdf.js +10 -5
  167. package/dist/nodes/solid.js +20 -5
  168. package/dist/nodes/splines.d.ts +15 -1
  169. package/dist/nodes/splines.js +112 -105
  170. package/dist/nodes/texture.d.ts +21 -6
  171. package/dist/nodes/texture.js +1318 -185
  172. package/dist/nodes/topology.d.ts +7 -0
  173. package/dist/nodes/topology.js +133 -6
  174. package/dist/nodes/transform.js +6 -2
  175. package/dist/nodes/uv.js +192 -174
  176. package/dist/nodes/wasmcall.js +5 -1
  177. package/dist/open.d.ts +19 -0
  178. package/dist/open.js +12 -0
  179. package/dist/package.d.ts +288 -0
  180. package/dist/package.js +772 -0
  181. package/dist/packages/check.d.ts +32 -0
  182. package/dist/packages/check.js +169 -0
  183. package/dist/packages/commands.d.ts +57 -0
  184. package/dist/packages/commands.js +537 -0
  185. package/dist/packages/registry.d.ts +796 -0
  186. package/dist/packages/registry.js +2998 -0
  187. package/dist/packages/update.d.ts +124 -0
  188. package/dist/packages/update.js +476 -0
  189. package/dist/render/options.d.ts +2 -0
  190. package/dist/render/options.js +44 -5
  191. package/dist/render/preview.d.ts +15 -4
  192. package/dist/render/preview.js +6 -4
  193. package/dist/render/raster.d.ts +66 -5
  194. package/dist/render/raster.js +506 -138
  195. package/dist/render/texview.d.ts +6 -0
  196. package/dist/render/texview.js +27 -0
  197. package/dist/scan.d.ts +61 -0
  198. package/dist/scan.js +228 -0
  199. package/dist/session.d.ts +311 -0
  200. package/dist/session.js +849 -0
  201. package/dist/viewer/app/api.js +48 -6
  202. package/dist/viewer/app/cooking.js +78 -0
  203. package/dist/viewer/app/embed.js +27 -7
  204. package/dist/viewer/app/export-popover.js +118 -16
  205. package/dist/viewer/app/grid.js +5 -1
  206. package/dist/viewer/app/guides.js +122 -0
  207. package/dist/viewer/app/keymap.js +6 -3
  208. package/dist/viewer/app/layers.js +4 -4
  209. package/dist/viewer/app/main.js +185 -52
  210. package/dist/viewer/app/markers.js +60 -0
  211. package/dist/viewer/app/outliner.js +72 -27
  212. package/dist/viewer/app/output-info.js +45 -0
  213. package/dist/viewer/app/outputs.css +147 -8
  214. package/dist/viewer/app/outputs.js +168 -54
  215. package/dist/viewer/app/packages.js +614 -0
  216. package/dist/viewer/app/props.js +176 -52
  217. package/dist/viewer/app/scene.js +30 -5
  218. package/dist/viewer/app/select.js +4 -3
  219. package/dist/viewer/app/status.js +12 -15
  220. package/dist/viewer/app/style.css +65 -7
  221. package/dist/viewer/app/vars.js +47 -0
  222. package/dist/viewer/app/welcome.js +72 -0
  223. package/dist/viewer/graph-file.d.ts +62 -0
  224. package/dist/viewer/graph-file.js +175 -0
  225. package/dist/viewer/index.html +23 -10
  226. package/dist/viewer/json-edit.d.ts +13 -0
  227. package/dist/viewer/json-edit.js +274 -0
  228. package/dist/viewer/outputs.d.ts +49 -5
  229. package/dist/viewer/outputs.js +264 -56
  230. package/dist/viewer/packages.d.ts +121 -0
  231. package/dist/viewer/packages.js +584 -0
  232. package/dist/viewer/server.d.ts +14 -9
  233. package/dist/viewer/server.js +266 -28
  234. package/dist/web/app/web.css +419 -0
  235. package/dist/web/app/web.js +188 -0
  236. package/dist/{gallery → web}/bake.d.ts +4 -4
  237. package/dist/{gallery → web}/bake.js +24 -15
  238. package/dist/web/folder-page.d.ts +101 -0
  239. package/dist/web/folder-page.js +146 -0
  240. package/dist/web/folders.d.ts +280 -0
  241. package/dist/web/folders.js +970 -0
  242. package/dist/web/library.d.ts +91 -0
  243. package/dist/web/library.js +228 -0
  244. package/dist/web/markdown.d.ts +45 -0
  245. package/dist/web/markdown.js +677 -0
  246. package/dist/web/pages.d.ts +258 -0
  247. package/dist/web/pages.js +301 -0
  248. package/dist/web/server.d.ts +24 -0
  249. package/dist/web/server.js +1068 -0
  250. package/dist/workspace.d.ts +88 -118
  251. package/dist/workspace.js +358 -460
  252. package/integrations/godot/addons/topotopo/LICENSE +202 -0
  253. package/integrations/godot/addons/topotopo/README.md +57 -0
  254. package/integrations/godot/addons/topotopo/context_menu.gd +43 -0
  255. package/integrations/godot/addons/topotopo/dock.gd +266 -0
  256. package/integrations/godot/addons/topotopo/dock.tscn +72 -0
  257. package/integrations/godot/addons/topotopo/export_filter.gd +72 -0
  258. package/integrations/godot/addons/topotopo/gltf_instancing.gd +131 -0
  259. package/integrations/godot/addons/topotopo/icons/topotopo.svg +1 -0
  260. package/integrations/godot/addons/topotopo/inspector.gd +38 -0
  261. package/integrations/godot/addons/topotopo/instances_post_import.gd +111 -0
  262. package/integrations/godot/addons/topotopo/package.gd +23 -0
  263. package/integrations/godot/addons/topotopo/package_importer.gd +187 -0
  264. package/integrations/godot/addons/topotopo/plugin.cfg +7 -0
  265. package/integrations/godot/addons/topotopo/plugin.gd +970 -0
  266. package/integrations/godot/addons/topotopo/record.gd +435 -0
  267. package/integrations/godot/addons/topotopo/runner.gd +458 -0
  268. package/integrations/godot/addons/topotopo/tools/check.gd +42 -0
  269. package/integrations/godot/addons/topotopo/watcher.gd +199 -0
  270. package/kernels/pkg/README.md +2 -1
  271. package/kernels/pkg-simd/README.md +2 -1
  272. package/library/architecture/versions/1.0/architecture.topo +12 -0
  273. package/{shelf → library/architecture/versions/1.0/graphs}/arch.json +3 -3
  274. package/{shelf → library/architecture/versions/1.0/graphs}/beam_truss.json +6 -6
  275. package/{shelf → library/architecture/versions/1.0/graphs}/brick_wall.json +8 -8
  276. package/{shelf → library/architecture/versions/1.0/graphs}/door_frame.json +3 -3
  277. package/{shelf → library/architecture/versions/1.0/graphs}/hex_grid_floor.json +3 -2
  278. package/{shelf → library/architecture/versions/1.0/graphs}/house.json +8 -8
  279. package/library/architecture/versions/1.0/graphs/lineup.json +42 -0
  280. package/{shelf → library/architecture/versions/1.0/graphs}/pillar.json +3 -2
  281. package/{shelf → library/architecture/versions/1.0/graphs}/railing.json +5 -5
  282. package/{shelf → library/architecture/versions/1.0/graphs}/roof_gable.json +2 -2
  283. package/{shelf → library/architecture/versions/1.0/graphs}/roof_hip.json +2 -2
  284. package/{shelf → library/architecture/versions/1.0/graphs}/roof_skeleton.json +2 -1
  285. package/{shelf → library/architecture/versions/1.0/graphs}/scaffold.json +4 -4
  286. package/{shelf → library/architecture/versions/1.0/graphs}/spiral_stairs.json +3 -2
  287. package/{shelf → library/architecture/versions/1.0/graphs}/stairs.json +6 -6
  288. package/{shelf → library/architecture/versions/1.0/graphs}/tile_floor.json +3 -2
  289. package/{shelf → library/architecture/versions/1.0/graphs}/wall_segment.json +10 -10
  290. package/{shelf → library/architecture/versions/1.0/graphs}/window_frame.json +2 -2
  291. package/library/architecture/versions/1.0/version.json +1119 -0
  292. package/{shelf → library/nature/versions/1.0/graphs}/bush.json +2 -2
  293. package/{shelf → library/nature/versions/1.0/graphs}/cliff_block.json +4 -3
  294. package/{shelf → library/nature/versions/1.0/graphs}/forest_patch.json +5 -5
  295. package/{shelf → library/nature/versions/1.0/graphs}/grass_clumps.json +2 -2
  296. package/library/nature/versions/1.0/graphs/lineup.json +24 -0
  297. package/{shelf → library/nature/versions/1.0/graphs}/log.json +6 -6
  298. package/{shelf → library/nature/versions/1.0/graphs}/rock.json +5 -4
  299. package/{shelf → library/nature/versions/1.0/graphs}/scatter_rocks.json +5 -5
  300. package/{shelf → library/nature/versions/1.0/graphs}/tree_lowpoly.json +3 -2
  301. package/library/nature/versions/1.0/nature.topo +12 -0
  302. package/library/nature/versions/1.0/version.json +534 -0
  303. package/{shelf → library/props/versions/1.0/graphs}/barrel.json +5 -4
  304. package/{shelf → library/props/versions/1.0/graphs}/crate.json +3 -3
  305. package/library/props/versions/1.0/graphs/lineup.json +18 -0
  306. package/{shelf → library/props/versions/1.0/graphs}/pallet.json +4 -3
  307. package/{shelf → library/props/versions/1.0/graphs}/pipe_run.json +3 -3
  308. package/{shelf → library/props/versions/1.0/graphs}/sandbag_wall.json +5 -5
  309. package/library/props/versions/1.0/props.topo +12 -0
  310. package/library/props/versions/1.0/version.json +336 -0
  311. package/{shelf → library/street/versions/1.0/graphs}/bench.json +5 -5
  312. package/{shelf → library/street/versions/1.0/graphs}/bollard.json +2 -1
  313. package/{shelf → library/street/versions/1.0/graphs}/cable.json +4 -4
  314. package/{shelf → library/street/versions/1.0/graphs}/fence.json +7 -7
  315. package/{shelf → library/street/versions/1.0/graphs}/lamp_post.json +2 -2
  316. package/library/street/versions/1.0/graphs/lineup.json +22 -0
  317. package/{shelf → library/street/versions/1.0/graphs}/road_strip.json +2 -2
  318. package/{shelf → library/street/versions/1.0/graphs}/sign_post.json +1 -1
  319. package/library/street/versions/1.0/street.topo +12 -0
  320. package/library/street/versions/1.0/version.json +421 -0
  321. package/package.json +17 -8
  322. package/dist/gallery/app/gallery.css +0 -100
  323. package/dist/gallery/app/gallery.js +0 -80
  324. package/dist/gallery/cli.d.ts +0 -4
  325. package/dist/gallery/cli.js +0 -157
  326. package/dist/gallery/library.d.ts +0 -124
  327. package/dist/gallery/library.js +0 -366
  328. package/dist/gallery/pages.d.ts +0 -94
  329. package/dist/gallery/pages.js +0 -148
  330. package/dist/gallery/server.d.ts +0 -21
  331. package/dist/gallery/server.js +0 -391
  332. package/dist/graph/migrate.d.ts +0 -23
  333. package/dist/graph/migrate.js +0 -58
  334. package/dist/mcp/library.d.ts +0 -12
  335. package/dist/mcp/library.js +0 -159
  336. package/shelf/index.json +0 -190
@@ -43,9 +43,10 @@ export declare function exprRealmSetup(bridge: any): any;
43
43
  /**
44
44
  * True when an expression is straight-line code that cannot run long, so it may run without the host's timer:
45
45
  * numbers, plain strings, names, operators, member reads, array literals, and up to SIMPLE_MAX_CALLS calls whose
46
- * callee is a bare name (a helper or reference function; vars hold data) or Math.<name>. Anything else (function
47
- * literals, loops and other statements, regular expressions, templates, comments, object literals, assignments,
48
- * spread, `new`, method calls, longer sources) is "not simple" and runs timed.
46
+ * callee is a bare name (a helper or reference function; vars hold data), Math.<name> or Number.<name> (both frozen,
47
+ * their functions pure). Anything else (function literals, loops and other statements, regular expressions,
48
+ * templates, comments, object literals, assignments, spread, `new`, method calls, longer sources) is "not simple"
49
+ * and runs timed.
49
50
  */
50
51
  export declare function isSimpleExpr(src: string): boolean;
51
52
  /** fn(scope) returns the expression's function (strict, no parameters), created inside `with (scope)` */
@@ -85,6 +86,8 @@ interface Runtime {
85
86
  lib: any;
86
87
  /** the `this` expressions run with */
87
88
  noThis: any;
89
+ /** what `vars` is: the old way of reading graph vars, a guard that says to read them by their bare name */
90
+ varsGuard: any;
88
91
  copyIn: (v: any) => any;
89
92
  error: (kind: string, msg: string) => any;
90
93
  compileSource: (source: string) => any;
@@ -1,3 +1,4 @@
1
+ import { makeVarsGuard } from '../core/snippet-lib.js';
1
2
  export class ExprError extends Error {
2
3
  }
3
4
  /** Thrown by reference functions while validating without cooking (dry run): the value is only known at cook time. */
@@ -6,12 +7,13 @@ export class DeferredExpr extends Error {
6
7
  export const TIME_KEYS = new Set(['frame', 'time', 'fps', 'timeInc']);
7
8
  export const DEFAULT_TIME = { frame: 1, time: 0, fps: 24, timeInc: 1 / 24 };
8
9
  /** Functions of "=expr" params that read other nodes: upstream geometry, or another node's parameter. */
9
- export const REF_FUNCS = ['npoints', 'nprims', 'nvertices', 'bbox', 'centroid', 'detail', 'point', 'prim', 'ch'];
10
+ export const REF_FUNCS = ['npoints', 'nprims', 'nvertices', 'bbox', 'centroid', 'detail', 'point', 'prim', 'primintrinsic', 'ch'];
10
11
  /** The helper names every expression can use besides graph vars, time and REF_FUNCS (documented in topic "expressions"). */
11
12
  export const EXPR_HELPERS = [
12
13
  'sin', 'cos', 'tan', 'asin', 'acos', 'atan', 'atan2', 'sqrt', 'pow', 'exp', 'log', 'abs', 'floor', 'ceil', 'round',
13
14
  'min', 'max', 'sign', 'hypot', 'PI', 'E', 'TAU', 'clamp', 'fit', 'lerp', 'smoothstep', 'frac', 'mod', 'radians',
14
- 'degrees', 'rand', 'pick', 'Math', 'NaN', 'Infinity', 'undefined',
15
+ 'degrees', 'rand', 'pick', 'Number', 'parseFloat', 'parseInt', 'String', 'Boolean', 'isFinite', 'isNaN', 'Math', 'NaN',
16
+ 'Infinity', 'undefined',
15
17
  ];
16
18
  const NO_COOK_FNS = Object.fromEntries(REF_FUNCS.map((f) => [f, () => { throw new ExprError(`${f}() only works in node params of a cooked graph`); }]));
17
19
  // ---------------------------------------------------------------- the library, built inside the sandbox realm
@@ -159,6 +161,9 @@ export function exprRealmSetup(bridge) {
159
161
  degrees: (r) => (r * 180) / M.PI,
160
162
  rand: (x, seed = 0) => hash32(hashNumber(x) ^ hash32(M.floor(seed * 7919) + 0x632be5ab)) / 4294967296,
161
163
  pick: (arr, i) => arr[((M.floor(i) % arr.length) + arr.length) % arr.length],
164
+ // conversions: the realm's own (frozen) functions
165
+ Number: G.Number, parseFloat: G.parseFloat, parseInt: G.parseInt, String: G.String, Boolean: G.Boolean,
166
+ isFinite: G.isFinite, isNaN: G.isNaN,
162
167
  Math: M, NaN: NaN, Infinity: Infinity, undefined: undefined,
163
168
  };
164
169
  for (const k of O.keys(helpers))
@@ -221,9 +226,10 @@ const SIMPLE_MAX_CALLS = 32;
221
226
  /**
222
227
  * True when an expression is straight-line code that cannot run long, so it may run without the host's timer:
223
228
  * numbers, plain strings, names, operators, member reads, array literals, and up to SIMPLE_MAX_CALLS calls whose
224
- * callee is a bare name (a helper or reference function; vars hold data) or Math.<name>. Anything else (function
225
- * literals, loops and other statements, regular expressions, templates, comments, object literals, assignments,
226
- * spread, `new`, method calls, longer sources) is "not simple" and runs timed.
229
+ * callee is a bare name (a helper or reference function; vars hold data), Math.<name> or Number.<name> (both frozen,
230
+ * their functions pure). Anything else (function literals, loops and other statements, regular expressions,
231
+ * templates, comments, object literals, assignments, spread, `new`, method calls, longer sources) is "not simple"
232
+ * and runs timed.
227
233
  */
228
234
  export function isSimpleExpr(src) {
229
235
  if (src.length > SIMPLE_MAX_LENGTH)
@@ -267,10 +273,10 @@ export function isSimpleExpr(src) {
267
273
  if (tok === '/' && (!operand || src[i] === '/' || src[i] === '*'))
268
274
  return false; // regular expression or comment
269
275
  if (tok === '(' && operand) {
270
- // a call: only of a bare name, or of Math.<name>
276
+ // a call: only of a bare name, or of Math.<name> / Number.<name>
271
277
  const callee = before, p2 = prev[prev.length - 2], p3 = prev[prev.length - 3], p4 = prev[prev.length - 4];
272
278
  const bare = /^[A-Za-z_$]/.test(callee) && !LITERAL_WORDS.has(callee) && p2 !== '.' && p2 !== '?.';
273
- const math = /^[A-Za-z_$]/.test(callee) && p2 === '.' && p3 === 'Math' && p4 !== '.' && p4 !== '?.';
279
+ const math = /^[A-Za-z_$]/.test(callee) && p2 === '.' && (p3 === 'Math' || p3 === 'Number') && p4 !== '.' && p4 !== '?.';
274
280
  if (!(bare || math) || ++calls > SIMPLE_MAX_CALLS)
275
281
  return false;
276
282
  }
@@ -316,8 +322,10 @@ function runtimeFor(host) {
316
322
  },
317
323
  };
318
324
  const realm = sb ? sb.compile(`(${exprRealmSetup.toString()})`)(bridge) : exprRealmSetup(bridge);
325
+ // made inside the (now locked down) realm, like the library: its errors are that realm's
326
+ const varsGuard = sb ? sb.compile(`(${makeVarsGuard.toString()})()`) : makeVarsGuard();
319
327
  rt = {
320
- lib: realm.lib, noThis: realm.noThis, copyIn: realm.copyIn, error: realm.error,
328
+ lib: realm.lib, noThis: realm.noThis, varsGuard, copyIn: realm.copyIn, error: realm.error,
321
329
  compileSource: sb ? (s) => sb.compile(s) : (s) => new Function(`return ${s}`)(),
322
330
  checkBody: sb ? (b) => sb.checkSyntax(b) : fallbackCheck,
323
331
  run: sb ? (job, ms) => sb.run(job, ms) : (job) => job(),
@@ -563,6 +571,8 @@ const SCOPE = {
563
571
  s.onTime?.();
564
572
  return s.time[k];
565
573
  }
574
+ if (k === 'vars')
575
+ return s.rt.varsGuard;
566
576
  throw s.rt.error('ReferenceError', unknownName(k));
567
577
  },
568
578
  set(s, k) {
@@ -0,0 +1,23 @@
1
+ /**
2
+ * The kinds of a published output: a mesh, packed instances, points, curves, a terrain (heightfields), textures (images
3
+ * alone), a material (materials and the maps they use, no geometry), a volume, or a scene that holds several of these
4
+ * (a street with its lamp posts as instances).
5
+ */
6
+ export declare const KINDS: readonly ['mesh', 'instances', 'points', 'curves', 'terrain', 'textures', 'material', 'volume', 'scene'];
7
+ export type Kind = (typeof KINDS)[number];
8
+ export declare const isKind: (k: unknown) => k is Kind;
9
+ /** A tag: lower-case letters, digits and "-", starting with a letter or digit, at most 64 characters. */
10
+ export declare const TAG_RE: RegExp;
11
+ /** At most this many tags per output. */
12
+ export declare const MAX_TAGS = 16;
13
+ export declare const KIND_HINT: string;
14
+ export declare const TAG_HINT = "a tag is lower-case letters, digits and -, starting with a letter or digit, at most 64 characters (\"conifer\", \"low-poly\"); an output has at most 16 tags, each once";
15
+ /** What is wrong with a named output's kind, tags and description, each with the rule as its hint (none: nothing). */
16
+ export declare function outputFieldIssues(out: {
17
+ kind?: unknown;
18
+ tags?: unknown;
19
+ description?: unknown;
20
+ }): {
21
+ message: string;
22
+ hint: string;
23
+ }[];
@@ -0,0 +1,41 @@
1
+ // What a published output says about itself beside its node and label (GraphSpec.outputs): its kind, which publishing
2
+ // detects from the cooked output (io/kinds.ts publishedKind) and an author may pin ("kind": "mesh") to have it checked,
3
+ // its tags, free words that search finds it by, and its description. Engine.validate checks them wherever a graph is
4
+ // read; publishing (src/packages/registry.ts) blocks on them as well.
5
+ /**
6
+ * The kinds of a published output: a mesh, packed instances, points, curves, a terrain (heightfields), textures (images
7
+ * alone), a material (materials and the maps they use, no geometry), a volume, or a scene that holds several of these
8
+ * (a street with its lamp posts as instances).
9
+ */
10
+ export const KINDS = ['mesh', 'instances', 'points', 'curves', 'terrain', 'textures', 'material', 'volume', 'scene'];
11
+ export const isKind = (k) => typeof k === 'string' && KINDS.includes(k);
12
+ /** A tag: lower-case letters, digits and "-", starting with a letter or digit, at most 64 characters. */
13
+ export const TAG_RE = /^[a-z0-9][a-z0-9-]{0,63}$/;
14
+ /** At most this many tags per output. */
15
+ export const MAX_TAGS = 16;
16
+ export const KIND_HINT = `the kinds: ${KINDS.join(', ')}; without "kind" publishing records the kind the output cooks to`;
17
+ export const TAG_HINT = `a tag is lower-case letters, digits and -, starting with a letter or digit, at most 64 characters ("conifer", "low-poly"); an output has at most ${MAX_TAGS} tags, each once`;
18
+ /** What is wrong with a named output's kind, tags and description, each with the rule as its hint (none: nothing). */
19
+ export function outputFieldIssues(out) {
20
+ const issues = [];
21
+ if (out.kind !== undefined && !isKind(out.kind))
22
+ issues.push({ message: `"kind" ${JSON.stringify(out.kind)} is not a kind`, hint: KIND_HINT });
23
+ const tags = out.tags;
24
+ if (tags !== undefined) {
25
+ if (!Array.isArray(tags) || tags.some((t) => typeof t !== 'string'))
26
+ issues.push({ message: `"tags" must be a list of words, such as ["conifer", "low-poly"], got ${JSON.stringify(tags)?.slice(0, 80)}`, hint: TAG_HINT });
27
+ else {
28
+ for (const t of tags)
29
+ if (!TAG_RE.test(t))
30
+ issues.push({ message: `tag ${JSON.stringify(t)} is malformed`, hint: TAG_HINT });
31
+ if (tags.length > MAX_TAGS)
32
+ issues.push({ message: `${tags.length} tags, more than ${MAX_TAGS}`, hint: TAG_HINT });
33
+ const twice = [...new Set(tags.filter((t, i) => tags.indexOf(t) !== i))];
34
+ if (twice.length)
35
+ issues.push({ message: `tag${twice.length > 1 ? 's' : ''} ${twice.map((t) => `"${t}"`).join(', ')} given twice`, hint: TAG_HINT });
36
+ }
37
+ }
38
+ if (out.description !== undefined && typeof out.description !== 'string')
39
+ issues.push({ message: `"description" must be a string, got ${JSON.stringify(out.description)?.slice(0, 80)}`, hint: 'what the output is, in a sentence or two; without one, the description of its graph is recorded' });
40
+ return issues;
41
+ }
@@ -0,0 +1,72 @@
1
+ import type { Engine } from './engine.ts';
2
+ import type { Kind } from './outputs.ts';
3
+ import type { Scope } from './scope.ts';
4
+ import type { GraphSpec, NodeDef } from './types.ts';
5
+ /** What the node type of a package output cooks (NodeDef.package). */
6
+ export interface PackageOutput {
7
+ /** "owner/name" */
8
+ package: string;
9
+ /** the published version ("1.3"), or null for a working folder followed this session */
10
+ version: string | null;
11
+ /** the version's hash; a followed working folder's: the hash its files have now */
12
+ hash: string;
13
+ /** what keys its results: the hash, for a followed working folder the hash of every folder followed */
14
+ signature: string;
15
+ /** the output's name, null for the package's default output */
16
+ output: string | null;
17
+ /** the graph that holds it (its name in graphs/) and the node it cooks */
18
+ graph: string;
19
+ spec: GraphSpec;
20
+ node: string;
21
+ /** the version's scope: its own assets, graphs, files and packages */
22
+ scope: Scope;
23
+ /** the author's note on the version */
24
+ note?: string;
25
+ /** the output's label in its graph */
26
+ label?: string;
27
+ /**
28
+ * what it is and the words search finds it by: as the version records them, or for a working folder the kind its
29
+ * author pinned and its tags (src/graph/outputs.ts)
30
+ */
31
+ kind?: Kind;
32
+ tags?: string[];
33
+ /** a problem every cook repeats (a copy edited by hand) */
34
+ warning?: string;
35
+ /**
36
+ * How the root names a file of the version, given its absolute path: relative to the root's folder when the version
37
+ * lies inside the root's package, so exports stay portable, else the absolute path. The registry gives it (the core
38
+ * has no paths); absent, texture paths are absolute.
39
+ */
40
+ rootPath?: (absolute: string) => string;
41
+ }
42
+ /** "studio/trees 1.3", or "studio/trees (working folder)" for one followed this session. */
43
+ export declare const packageAt: (o: Pick<PackageOutput, 'package' | 'version'>) => string;
44
+ /**
45
+ * The node type of a package output: the vars of its graph that its node reads (varsRead) are its params, and its
46
+ * graph's input nodes the inputs, as for assets. A graph that describes itself gives the catalog's summary (its
47
+ * description's first sentence) and the rest of the text.
48
+ */
49
+ export declare function packageOutputDef(o: PackageOutput): NodeDef;
50
+ /** The packages ("owner/name") a graph names as node types, in its nested graphs too (foreach and solver bodies). */
51
+ export declare function packagesNamedIn(graph: GraphSpec): string[];
52
+ /** The nodes of a graph a cook of `node` reaches: the node, its inputs and the nodes its expressions read, upstream. */
53
+ export declare function upstreamOf(g: GraphSpec, node: string): string[];
54
+ /**
55
+ * The vars of a graph that a cook of its node `node` reads: the vars named in the "=expr" params, code and other text
56
+ * params of the nodes it reaches (upstream), and in the nested graphs of those nodes (all of their nodes: a foreach
57
+ * body reads its graph's vars). They are the params of a package output that cooks that node; a var the node does not
58
+ * read changes nothing about it. Sorted.
59
+ */
60
+ export declare function varsRead(graph: GraphSpec, node: string): string[];
61
+ /**
62
+ * The outputs of package `pkg` that a cook of node `node` of `graph` names in `scope` (the package's own scope): by full
63
+ * name, upstream of the node, in the nested graphs of those nodes (all of their nodes), and in the asset and graph_ref
64
+ * graphs they cook there. Each output by its name, "" for the package's default output ("owner/name" alone).
65
+ */
66
+ export declare function ownOutputsNamed(pkg: string, graph: GraphSpec, node: string, scope: Scope): string[];
67
+ /**
68
+ * The package versions a graph uses, directly or through the packages, assets, graph_ref graphs and nested graphs it
69
+ * names: "owner/name@version" → the version's hash, and "owner/name@working" → the hash of a working folder followed
70
+ * this session. Keys sorted. Exports record them (io/source.ts), so an export can be made again.
71
+ */
72
+ export declare function packagesUsed(engine: Engine, graph: GraphSpec, scope?: Scope): Record<string, string>;
@@ -0,0 +1,261 @@
1
+ // Packages, the engine side: the node type of a package output, and the packages a graph names and uses. The host's
2
+ // package registry (src/packages/registry.ts) reads the versions from disk and gives each scope its PackageResolver
3
+ // (src/graph/scope.ts): the package's root resolves names by the package's uses, a version by its own.
4
+ //
5
+ // A published package has a full name ("owner/name") and versions: frozen copies of its graphs, assets
6
+ // and inputs. A graph uses an output of one as a node type, "owner/name/output", or "owner/name" for the package's
7
+ // default output. A package output cooks its graph in the version's own scope (its assets, graphs, files and
8
+ // packages), so nothing leaks between a package and the packages it uses, and two versions of one package cook side by side.
9
+ // Its signature is the version's hash and the node it cooks: a frozen version cooks once for the package and once for
10
+ // the packages that use it (which name its texture files differently).
11
+ //
12
+ // A package's graphs name its own outputs by full name too (a built-in package whose pieces build on each other: a house of the
13
+ // package's walls): they resolve to the same version, or the same working folder, with no entry in its uses. Outputs that
14
+ // name each other in a loop do not resolve (ownOutputsNamed finds what each output names).
15
+ import { isGraph } from './types.js';
16
+ import { Geometry } from '../core/geometry.js';
17
+ import { rebaseTexturePaths } from '../core/materials.js';
18
+ import { codeVarNames } from '../core/usercode.js';
19
+ import { graphInterface } from './engine.js';
20
+ import { scanValue } from './params.js';
21
+ import { getNodeDef } from './registry.js';
22
+ import { parsePackageName } from './scope.js';
23
+ import { NodeError } from './types.js';
24
+ /** "studio/trees 1.3", or "studio/trees (working folder)" for one followed this session. */
25
+ export const packageAt = (o) => (o.version === null ? `${o.package} (working folder)` : `${o.package} ${o.version}`);
26
+ /**
27
+ * The node type of a package output: the vars of its graph that its node reads (varsRead) are its params, and its
28
+ * graph's input nodes the inputs, as for assets. A graph that describes itself gives the catalog's summary (its
29
+ * description's first sentence) and the rest of the text.
30
+ */
31
+ export function packageOutputDef(o) {
32
+ const type = o.output === null ? o.package : `${o.package}/${o.output}`;
33
+ const at = packageAt(o);
34
+ const { params: all, inputs } = graphInterface(o.spec);
35
+ const read = new Set(varsRead(o.spec, o.node));
36
+ const params = Object.fromEntries(Object.entries(all).filter(([k]) => read.has(k)));
37
+ const what = `${o.output === null ? 'the default output' : `output "${o.output}"`} of package ${at}${o.label ? ` (${o.label})` : ''}`;
38
+ const desc = typeof o.spec.description === 'string' ? o.spec.description.trim() : '';
39
+ const split = /^(.+?[.!?])\s+(.+)$/s.exec(desc);
40
+ const cooks = `it cooks node "${o.node}" of the package's graph "${o.graph}"; its params are the vars of that graph the node reads.`;
41
+ return {
42
+ type,
43
+ category: 'package',
44
+ summary: desc ? split?.[1] ?? desc : what,
45
+ description: [split?.[2] ?? '', o.note ? `${at}: ${o.note}` : '', desc ? `${what[0].toUpperCase()}${what.slice(1)}: ${cooks}` : `${cooks[0].toUpperCase()}${cooks.slice(1)}`].filter(Boolean).join('\n'),
46
+ inputs,
47
+ params,
48
+ package: o,
49
+ // the version is frozen: its hash and the node say what it cooks, in a scope of its own (no usesScope); a result
50
+ // for the root names its textures as the root does (rootPath), one for another scope absolutely
51
+ signatureExtra: (_p, scope) => `${o.signature}|${o.graph}/${o.node}${o.rootPath && scope.id ? '|nested' : ''}`,
52
+ // the package's own nodes unpack what they need
53
+ packed: 'keep',
54
+ async cook(ctx) {
55
+ if (o.warning)
56
+ ctx.warn(o.warning);
57
+ const r = await ctx.subcook(o.spec, {
58
+ scope: o.scope, target: o.node, vars: ctx.p,
59
+ inputs: ctx.inputs.map((g, i) => ({ geo: g ?? new Geometry(), sig: ctx.inputSigs[i] ?? 'none' })),
60
+ });
61
+ for (const w of r.warnings)
62
+ ctx.warn(`[${w.node}] ${w.message}`);
63
+ if (!r.ok || !r.geo)
64
+ throw new NodeError(`${type} (${at}) failed: ${r.errors.map((e) => `${e.node}: ${e.message}`).join('; ')}`);
65
+ // texture paths relative to the version's folder would be read from the package's: they name the version's files.
66
+ // Inside another package's scope they are absolute (that package names them for the root in turn, its own and
67
+ // those of the packages it uses alike); for the root, as the root names them.
68
+ const forRoot = !ctx.scope.id ? o.rootPath : undefined;
69
+ return rebaseTexturePaths(r.geo, (p, relative) => {
70
+ const abs = relative ? o.scope.files.resolvePath(p) : p;
71
+ return forRoot ? forRoot(abs) : abs;
72
+ });
73
+ },
74
+ };
75
+ }
76
+ /** The packages ("owner/name") a graph names as node types, in its nested graphs too (foreach and solver bodies). */
77
+ export function packagesNamedIn(graph) {
78
+ const out = new Set();
79
+ const walk = (g, depth) => {
80
+ if (depth > 64)
81
+ return;
82
+ for (const node of Object.values(g.nodes)) {
83
+ if (!node || typeof node !== 'object')
84
+ continue;
85
+ if (typeof node.type === 'string' && node.type.includes('/')) {
86
+ const n = parsePackageName(node.type);
87
+ if (typeof n !== 'string')
88
+ out.add(n.package);
89
+ }
90
+ if (node.params && typeof node.params === 'object')
91
+ for (const v of Object.values(node.params))
92
+ if (isGraph(v))
93
+ walk(v, depth + 1);
94
+ }
95
+ };
96
+ if (isGraph(graph))
97
+ walk(graph, 0);
98
+ return [...out];
99
+ }
100
+ /** The nodes of a graph a cook of `node` reaches: the node, its inputs and the nodes its expressions read, upstream. */
101
+ export function upstreamOf(g, node) {
102
+ const keep = new Set(), todo = [node];
103
+ while (todo.length) {
104
+ const n = todo.pop();
105
+ if (keep.has(n) || !Object.hasOwn(g.nodes, n))
106
+ continue;
107
+ keep.add(n);
108
+ const spec = g.nodes[n];
109
+ const wired = typeof spec?.in === 'string' ? [spec.in] : Array.isArray(spec?.in) ? spec.in : spec?.in && typeof spec.in === 'object' ? Object.values(spec.in) : [];
110
+ for (const w of wired)
111
+ if (typeof w === 'string')
112
+ todo.push(w);
113
+ const refs = scanValue(Object.values(spec?.params ?? {}));
114
+ todo.push(...refs.geo, ...refs.ch.map((c) => c.node));
115
+ }
116
+ return [...keep];
117
+ }
118
+ /**
119
+ * The vars of a graph that a cook of its node `node` reads: the vars named in the "=expr" params, code and other text
120
+ * params of the nodes it reaches (upstream), and in the nested graphs of those nodes (all of their nodes: a foreach
121
+ * body reads its graph's vars). They are the params of a package output that cooks that node; a var the node does not
122
+ * read changes nothing about it. Sorted.
123
+ */
124
+ export function varsRead(graph, node) {
125
+ const vars = graph.vars ?? {};
126
+ if (!Object.keys(vars).length)
127
+ return [];
128
+ const out = new Set();
129
+ const names = (s) => { for (const n of codeVarNames(s, vars))
130
+ out.add(n); };
131
+ // a param's value: "=expr" anywhere; whole text where text is read as code or an expression (code, groups, strings)
132
+ const value = (v, text, depth) => {
133
+ if (depth > 64)
134
+ return;
135
+ if (typeof v === 'string') {
136
+ if (v.startsWith('=') || text)
137
+ names(v);
138
+ }
139
+ else if (Array.isArray(v))
140
+ for (const x of v)
141
+ value(x, text, depth + 1);
142
+ else if (isGraph(v))
143
+ for (const n of Object.keys(v.nodes))
144
+ nodeParams(v, n, depth + 1);
145
+ else if (v && typeof v === 'object')
146
+ for (const x of Object.values(v))
147
+ value(x, text, depth + 1);
148
+ };
149
+ const nodeParams = (g, n, depth) => {
150
+ const spec = g.nodes[n];
151
+ if (!spec || typeof spec !== 'object' || !spec.params || typeof spec.params !== 'object')
152
+ return;
153
+ const def = typeof spec.type === 'string' ? getNodeDef(spec.type) : undefined;
154
+ for (const [k, v] of Object.entries(spec.params)) {
155
+ const t = def?.params[k]?.type;
156
+ value(v, t === undefined || t === 'code' || t === 'group' || t === 'string' || t === 'json', depth);
157
+ }
158
+ };
159
+ if (!Object.hasOwn(graph.nodes, node))
160
+ return [];
161
+ for (const n of upstreamOf(graph, node))
162
+ nodeParams(graph, n, 0);
163
+ return [...out].sort();
164
+ }
165
+ /**
166
+ * The outputs of package `pkg` that a cook of node `node` of `graph` names in `scope` (the package's own scope): by full
167
+ * name, upstream of the node, in the nested graphs of those nodes (all of their nodes), and in the asset and graph_ref
168
+ * graphs they cook there. Each output by its name, "" for the package's default output ("owner/name" alone).
169
+ */
170
+ export function ownOutputsNamed(pkg, graph, node, scope) {
171
+ const out = new Set();
172
+ const done = new Map();
173
+ // `from`: the node whose upstream is cooked, null for every node of the graph
174
+ const visit = (g, from, depth) => {
175
+ if (depth > 64 || !isGraph(g))
176
+ return;
177
+ let seen = done.get(g);
178
+ if (!seen)
179
+ done.set(g, seen = new Set());
180
+ const key = from ?? '\u0000all';
181
+ if (seen.has(key))
182
+ return;
183
+ seen.add(key);
184
+ const at = (x, n) => (typeof n === 'string' && n && Object.hasOwn(x.nodes, n) ? n : null);
185
+ for (const name of from === null ? Object.keys(g.nodes) : upstreamOf(g, from)) {
186
+ const spec = g.nodes[name];
187
+ if (!spec || typeof spec !== 'object' || typeof spec.type !== 'string')
188
+ continue;
189
+ if (spec.type.includes('/')) {
190
+ const n = parsePackageName(spec.type);
191
+ if (typeof n !== 'string' && n.package === pkg)
192
+ out.add(n.output ?? '');
193
+ }
194
+ else {
195
+ const asset = scope.assets.get(spec.type);
196
+ if (asset)
197
+ visit(asset.graph, at(asset.graph, asset.graph.output), depth + 1);
198
+ else if (getNodeDef(spec.type)?.type === 'graph_ref' && typeof spec.params?.graph === 'string') {
199
+ const ref = scope.graphs?.(spec.params.graph);
200
+ if (ref && isGraph(ref))
201
+ visit(ref, at(ref, spec.params.node) ?? at(ref, ref.output), depth + 1);
202
+ }
203
+ }
204
+ if (spec.params && typeof spec.params === 'object')
205
+ for (const v of Object.values(spec.params))
206
+ if (isGraph(v))
207
+ visit(v, null, depth + 1);
208
+ }
209
+ };
210
+ visit(graph, node, 0);
211
+ return [...out];
212
+ }
213
+ /**
214
+ * The package versions a graph uses, directly or through the packages, assets, graph_ref graphs and nested graphs it
215
+ * names: "owner/name@version" → the version's hash, and "owner/name@working" → the hash of a working folder followed
216
+ * this session. Keys sorted. Exports record them (io/source.ts), so an export can be made again.
217
+ */
218
+ export function packagesUsed(engine, graph, scope = engine.root) {
219
+ const out = {};
220
+ const seen = new Map();
221
+ const once = (g, s, depth) => {
222
+ let set = seen.get(s);
223
+ if (!set)
224
+ seen.set(s, set = new Set());
225
+ if (set.has(g))
226
+ return;
227
+ set.add(g);
228
+ walk(g, s, depth);
229
+ };
230
+ const walk = (g, s, depth) => {
231
+ if (depth > 64 || !isGraph(g))
232
+ return;
233
+ for (const node of Object.values(g.nodes)) {
234
+ if (!node || typeof node !== 'object' || typeof node.type !== 'string')
235
+ continue;
236
+ const def = engine.resolveDef(node.type, s);
237
+ const o = def?.package;
238
+ if (o) {
239
+ out[`${o.package}@${o.version ?? 'working'}`] = o.hash;
240
+ once(o.spec, o.scope, depth + 1);
241
+ }
242
+ else if (def) {
243
+ // an asset's graph and a graph_ref's graph cook in the same scope
244
+ const asset = engine.asset(node.type, s);
245
+ if (asset?.def === def)
246
+ once(asset.graph, s, depth + 1);
247
+ else if (def.type === 'graph_ref' && typeof node.params?.graph === 'string') {
248
+ const ref = s.graphs?.(node.params.graph);
249
+ if (ref)
250
+ once(ref, s, depth + 1);
251
+ }
252
+ }
253
+ if (node.params && typeof node.params === 'object')
254
+ for (const v of Object.values(node.params))
255
+ if (isGraph(v))
256
+ walk(v, s, depth + 1);
257
+ }
258
+ };
259
+ once(graph, scope, 0);
260
+ return Object.fromEntries(Object.entries(out).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)));
261
+ }
@@ -1,5 +1,5 @@
1
1
  import type { TypedArray } from '../core/kernels.ts';
2
- import type { WorkerPool } from '../host/types.ts';
2
+ import type { StopSignal, WorkerPool } from '../host/types.ts';
3
3
  export interface KernelJob {
4
4
  /** number of elements: kernels process [0, count) */
5
5
  count: number;
@@ -36,6 +36,8 @@ export interface ParallelOptions {
36
36
  * the worker's realm; on this thread it runs in the main realm); registry kernels default to KERNELS[kernel].run.
37
37
  */
38
38
  serial?: () => any;
39
+ /** the cook's stop signal (set by the engine): chunks not done when it is aborted stop, and the job fails as STOPPED */
40
+ signal?: StopSignal;
39
41
  }
40
42
  export interface ParallelRun {
41
43
  /** true when the job ran on worker threads */
@@ -11,6 +11,7 @@
11
11
  // this thread.
12
12
  // Host-agnostic: needs only SharedArrayBuffer and the Host's WorkerPool.
13
13
  import { KERNELS, hashArrays } from '../core/kernels.js';
14
+ import { NodeError, STOPPED } from './types.js';
14
15
  /** memo for kernels run on this thread: shared data is not cached here, so objects are built per run */
15
16
  const localCtx = { sharedKey: '', memo: (_key, make) => make() };
16
17
  const DEFAULT_MIN = 50000;
@@ -100,11 +101,13 @@ export function parallelMap(pool, kernel, job, opts = {}, stats) {
100
101
  const tasks = [];
101
102
  for (let c = 0; c < chunks; c++) {
102
103
  const start = Math.floor((c * job.count) / chunks), end = Math.floor(((c + 1) * job.count) / chunks);
103
- tasks.push(pool.run({ kernel, args, range: [start, end], arrays, shared, timeoutMs: opts.timeoutMs }));
104
+ tasks.push(pool.run({ kernel, args, range: [start, end], arrays, shared, timeoutMs: opts.timeoutMs, ...(opts.signal ? { signal: opts.signal } : {}) }));
104
105
  }
105
106
  return Promise.allSettled(tasks).then((settled) => {
106
107
  const failed = settled.find((r) => r.status === 'rejected');
107
108
  if (failed) {
109
+ if (settled.some((r) => r.status === 'rejected' && r.reason?.code === 'STOPPED'))
110
+ throw new NodeError(STOPPED);
108
111
  // no worker could start (e.g. the worker module failed to load): do the work here instead
109
112
  if (settled.some((r) => r.status === 'rejected' && r.reason?.code === 'POOL_UNAVAILABLE')) {
110
113
  for (const v of inPlace)
@@ -34,6 +34,12 @@ export declare function vecOut<T extends any[]>(a: T): T;
34
34
  export declare function parseColor(v: any): [number, number, number] | null;
35
35
  export declare class ParamError extends Error {
36
36
  }
37
+ /**
38
+ * The option of an enum a value picks, or undefined: the option itself (===); for a numeric option the same number
39
+ * written as text ("8" → 8); for a text option its text, then its case- and underscore-insensitive form; with text
40
+ * options only, a whole number is an index into them.
41
+ */
42
+ export declare function enumOption(opts: readonly (string | number)[], v: any): string | number | undefined;
37
43
  /**
38
44
  * Coerce a raw value to the param's type. Numbers outside the declared min/max are clamped, and `note` (when given)
39
45
  * is told, so a cook can warn: a silent clamp hides mistakes such as an asset range narrower than its caller's.
@@ -21,6 +21,9 @@ export function didYouMean(word, candidates, max = 3) {
21
21
  let d = levenshtein(w, nc);
22
22
  if (nc.includes(w) || w.includes(nc))
23
23
  d = Math.min(d, 1);
24
+ // a package output by its own name ("stairs" for "topotopo/architecture/stairs") comes first
25
+ if (c.includes('/') && norm(c.slice(c.lastIndexOf('/') + 1)) === w)
26
+ d = 0;
24
27
  return { c, d };
25
28
  })
26
29
  .filter((x) => x.d <= Math.max(2, Math.floor(w.length / 3)))
@@ -192,6 +195,31 @@ function toNum(v) {
192
195
  }
193
196
  export class ParamError extends Error {
194
197
  }
198
+ /**
199
+ * The option of an enum a value picks, or undefined: the option itself (===); for a numeric option the same number
200
+ * written as text ("8" → 8); for a text option its text, then its case- and underscore-insensitive form; with text
201
+ * options only, a whole number is an index into them.
202
+ */
203
+ export function enumOption(opts, v) {
204
+ const same = opts.find((o) => o === v);
205
+ if (same !== undefined)
206
+ return same;
207
+ if (typeof v === 'string' && v.trim() !== '') {
208
+ const n = Number(v);
209
+ const num = opts.find((o) => typeof o === 'number' && o === n);
210
+ if (num !== undefined)
211
+ return num;
212
+ }
213
+ if (typeof v !== 'string' && typeof v !== 'number' && typeof v !== 'boolean')
214
+ return undefined;
215
+ const s = String(v);
216
+ const text = opts.find((o) => typeof o === 'string' && o === s) ?? opts.find((o) => typeof o === 'string' && norm(o) === norm(s));
217
+ if (text !== undefined)
218
+ return text;
219
+ if (typeof v === 'number' && Number.isInteger(v) && v >= 0 && v < opts.length && opts.every((o) => typeof o === 'string'))
220
+ return opts[v];
221
+ return undefined;
222
+ }
195
223
  /**
196
224
  * Coerce a raw value to the param's type. Numbers outside the declared min/max are clamped, and `note` (when given)
197
225
  * is told, so a cook can warn: a silent clamp hides mistakes such as an asset range narrower than its caller's.
@@ -245,13 +273,11 @@ export function coerce(name, pd, v, note) {
245
273
  throw bad('a code string');
246
274
  return v;
247
275
  case 'enum': {
248
- const s = String(v);
276
+ // options are strings or numbers; the value is the option itself, so numeric options give numbers
249
277
  const opts = pd.options ?? [];
250
- const hit = opts.find((o) => o === s) ?? opts.find((o) => norm(o) === norm(s));
251
- if (hit)
278
+ const hit = enumOption(opts, v);
279
+ if (hit !== undefined)
252
280
  return hit;
253
- if (typeof v === 'number' && Number.isInteger(v) && v >= 0 && v < opts.length)
254
- return opts[v];
255
281
  throw new ParamError(`param "${name}" must be one of: ${opts.join(' | ')} (got ${JSON.stringify(v)})`);
256
282
  }
257
283
  case 'vec2':
@@ -334,8 +360,9 @@ export function resolveParams(def, raw, vars, env = {}) {
334
360
  for (const [k, v] of Object.entries(raw ?? {})) {
335
361
  const name = resolveParamName(def, k);
336
362
  if (!name) {
337
- const sugg = didYouMean(k, Object.keys(def.params));
338
- errors.push(`unknown param "${k}"` + (sugg.length ? ` — did you mean ${sugg.map((s) => `"${s}"`).join(' or ')}?` : '') +
363
+ const now = def.renamed?.[k];
364
+ const sugg = now ? [] : didYouMean(k, Object.keys(def.params));
365
+ errors.push(`unknown param "${k}"` + (now ? `: ${now}.` : sugg.length ? ` — did you mean ${sugg.map((s) => `"${s}"`).join(' or ')}?` : '') +
339
366
  ` Valid params: ${Object.keys(def.params).join(', ') || '(none)'}`);
340
367
  continue;
341
368
  }