topotopo 0.4.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE +10 -10
- package/README.md +460 -117
- package/dist/cli.js +327 -147
- package/dist/config.d.ts +48 -0
- package/dist/config.js +170 -0
- package/dist/core/bake.d.ts +14 -3
- package/dist/core/bake.js +153 -4
- package/dist/core/bevel.d.ts +3 -1
- package/dist/core/bevel.js +76 -3
- package/dist/core/decimate.d.ts +65 -0
- package/dist/core/decimate.js +409 -3
- package/dist/core/erosion.d.ts +37 -0
- package/dist/core/erosion.js +41 -1
- package/dist/core/geometry.d.ts +5 -1
- package/dist/core/geometry.js +203 -3
- package/dist/core/heightfield.d.ts +27 -4
- package/dist/core/heightfield.js +54 -16
- package/dist/core/intrinsics.d.ts +7 -0
- package/dist/core/intrinsics.js +94 -0
- package/dist/core/manifold.d.ts +12 -1
- package/dist/core/manifold.js +78 -6
- package/dist/core/materials.d.ts +7 -0
- package/dist/core/materials.js +45 -0
- package/dist/core/noise.d.ts +9 -0
- package/dist/core/noise.js +10 -1
- package/dist/core/polymerge.d.ts +21 -0
- package/dist/core/polymerge.js +327 -0
- package/dist/core/repair.d.ts +2 -0
- package/dist/core/repair.js +2 -0
- package/dist/core/report.d.ts +70 -0
- package/dist/core/report.js +275 -0
- package/dist/core/scene.js +2 -1
- package/dist/core/sha256.d.ts +4 -0
- package/dist/core/sha256.js +69 -0
- package/dist/core/shapes.d.ts +3 -0
- package/dist/core/shapes.js +34 -0
- package/dist/core/snippet-lib.d.ts +14 -1
- package/dist/core/snippet-lib.js +39 -13
- package/dist/core/tangents.d.ts +2 -0
- package/dist/core/tangents.js +5 -1
- package/dist/core/texnoise.d.ts +6 -1
- package/dist/core/texnoise.js +6 -2
- package/dist/core/texsdf.d.ts +131 -0
- package/dist/core/texsdf.js +637 -0
- package/dist/core/texture.d.ts +163 -9
- package/dist/core/texture.js +844 -20
- package/dist/core/topology.d.ts +10 -0
- package/dist/core/topology.js +168 -0
- package/dist/core/unwrap.d.ts +72 -0
- package/dist/core/unwrap.js +800 -0
- package/dist/core/usercode.d.ts +27 -0
- package/dist/core/usercode.js +87 -0
- package/dist/core/uv.d.ts +4 -18
- package/dist/core/uv.js +35 -188
- package/dist/core/uvislands.d.ts +62 -0
- package/dist/core/uvislands.js +574 -0
- package/dist/core/uvoverlap.d.ts +58 -0
- package/dist/core/uvoverlap.js +220 -0
- package/dist/core/uvpack.d.ts +64 -0
- package/dist/core/uvpack.js +628 -0
- package/dist/core/uvreport.d.ts +61 -0
- package/dist/core/uvreport.js +207 -143
- package/dist/core/wrangle.d.ts +6 -1
- package/dist/core/wrangle.js +27 -16
- package/dist/core/xatlas.d.ts +16 -1
- package/dist/core/xatlas.js +66 -62
- package/dist/engines.d.ts +63 -0
- package/dist/engines.js +180 -0
- package/dist/explain.d.ts +4 -3
- package/dist/explain.js +129 -12
- package/dist/graph/engine.d.ts +92 -29
- package/dist/graph/engine.js +298 -148
- package/dist/graph/expr.d.ts +6 -3
- package/dist/graph/expr.js +18 -8
- package/dist/graph/outputs.d.ts +23 -0
- package/dist/graph/outputs.js +41 -0
- package/dist/graph/packages.d.ts +72 -0
- package/dist/graph/packages.js +261 -0
- package/dist/graph/parallel.d.ts +3 -1
- package/dist/graph/parallel.js +4 -1
- package/dist/graph/params.d.ts +6 -0
- package/dist/graph/params.js +34 -7
- package/dist/graph/scope.d.ts +55 -0
- package/dist/graph/scope.js +14 -0
- package/dist/graph/types.d.ts +75 -12
- package/dist/graph/types.js +4 -2
- package/dist/graph/vars.d.ts +16 -0
- package/dist/graph/vars.js +80 -0
- package/dist/host/artifacts.d.ts +10 -1
- package/dist/host/artifacts.js +37 -6
- package/dist/host/cook.d.ts +241 -0
- package/dist/host/cook.js +844 -0
- package/dist/host/export-targets.d.ts +42 -5
- package/dist/host/export-targets.js +72 -13
- package/dist/host/godot-commands.d.ts +4 -0
- package/dist/host/godot-commands.js +21 -0
- package/dist/host/godot.d.ts +183 -0
- package/dist/host/godot.js +916 -0
- package/dist/host/node.d.ts +12 -7
- package/dist/host/node.js +27 -9
- package/dist/host/pool.js +51 -2
- package/dist/host/sidecars.d.ts +8 -0
- package/dist/host/sidecars.js +50 -0
- package/dist/host/types.d.ts +19 -6
- package/dist/host/version.d.ts +1 -0
- package/dist/host/version.js +3 -0
- package/dist/host/worker.js +5 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/inspect.d.ts +80 -2
- package/dist/inspect.js +265 -30
- package/dist/io/common.d.ts +25 -5
- package/dist/io/export.js +2 -1
- package/dist/io/files.d.ts +23 -4
- package/dist/io/files.js +60 -8
- package/dist/io/gltf.js +134 -47
- package/dist/io/heightmap.d.ts +3 -0
- package/dist/io/heightmap.js +1 -0
- package/dist/io/import.js +10 -0
- package/dist/io/inspect-scene.d.ts +55 -0
- package/dist/io/inspect-scene.js +155 -0
- package/dist/io/kinds.d.ts +81 -0
- package/dist/io/kinds.js +163 -0
- package/dist/io/points.d.ts +2 -1
- package/dist/io/points.js +3 -1
- package/dist/io/sidecars.d.ts +24 -0
- package/dist/io/sidecars.js +57 -0
- package/dist/io/source.d.ts +65 -0
- package/dist/io/source.js +112 -0
- package/dist/io/targets.d.ts +47 -3
- package/dist/io/targets.js +148 -13
- package/dist/io/textures.js +21 -1
- package/dist/io/unreal.js +5 -1
- package/dist/mcp/docs.d.ts +10 -1
- package/dist/mcp/docs.js +786 -143
- package/dist/mcp/inputs.d.ts +12 -5
- package/dist/mcp/inputs.js +50 -13
- package/dist/mcp/server.js +56 -27
- package/dist/mcp/tools.d.ts +14 -7
- package/dist/mcp/tools.js +198 -103
- package/dist/mcp/verify.d.ts +2 -2
- package/dist/mcp/verify.js +1 -1
- package/dist/mcp/workspace.d.ts +15 -0
- package/dist/mcp/workspace.js +349 -0
- package/dist/nodes/attributes.js +198 -1
- package/dist/nodes/bake.js +151 -47
- package/dist/nodes/beam.d.ts +1 -0
- package/dist/nodes/beam.js +201 -0
- package/dist/nodes/bevel.js +51 -3
- package/dist/nodes/cloth.js +2 -0
- package/dist/nodes/code.js +21 -9
- package/dist/nodes/curves.js +433 -93
- package/dist/nodes/flow.js +53 -33
- package/dist/nodes/generate.js +12 -38
- package/dist/nodes/heightfield.js +248 -77
- package/dist/nodes/imageops.js +16 -19
- package/dist/nodes/index.d.ts +1 -0
- package/dist/nodes/index.js +1 -0
- package/dist/nodes/material.js +89 -24
- package/dist/nodes/measure.js +43 -17
- package/dist/nodes/particles.js +2 -0
- package/dist/nodes/pcg.js +6 -5
- package/dist/nodes/procedural.js +4 -3
- package/dist/nodes/remesh.js +71 -15
- package/dist/nodes/scene.js +4 -2
- package/dist/nodes/sdf.js +10 -5
- package/dist/nodes/solid.js +20 -5
- package/dist/nodes/splines.d.ts +15 -1
- package/dist/nodes/splines.js +112 -105
- package/dist/nodes/texture.d.ts +21 -6
- package/dist/nodes/texture.js +1318 -185
- package/dist/nodes/topology.d.ts +7 -0
- package/dist/nodes/topology.js +133 -6
- package/dist/nodes/transform.js +6 -2
- package/dist/nodes/uv.js +192 -174
- package/dist/nodes/wasmcall.js +5 -1
- package/dist/open.d.ts +19 -0
- package/dist/open.js +12 -0
- package/dist/package.d.ts +288 -0
- package/dist/package.js +772 -0
- package/dist/packages/check.d.ts +32 -0
- package/dist/packages/check.js +169 -0
- package/dist/packages/commands.d.ts +57 -0
- package/dist/packages/commands.js +537 -0
- package/dist/packages/registry.d.ts +796 -0
- package/dist/packages/registry.js +2998 -0
- package/dist/packages/update.d.ts +124 -0
- package/dist/packages/update.js +476 -0
- package/dist/render/options.d.ts +2 -0
- package/dist/render/options.js +57 -5
- package/dist/render/preview.d.ts +17 -4
- package/dist/render/preview.js +6 -4
- package/dist/render/raster.d.ts +74 -5
- package/dist/render/raster.js +527 -143
- package/dist/render/texview.d.ts +6 -0
- package/dist/render/texview.js +27 -0
- package/dist/scan.d.ts +61 -0
- package/dist/scan.js +228 -0
- package/dist/session.d.ts +311 -0
- package/dist/session.js +849 -0
- package/dist/viewer/app/api.js +48 -6
- package/dist/viewer/app/cooking.js +78 -0
- package/dist/viewer/app/embed.js +27 -7
- package/dist/viewer/app/export-popover.js +118 -16
- package/dist/viewer/app/grid.js +5 -1
- package/dist/viewer/app/guides.js +122 -0
- package/dist/viewer/app/keymap.js +6 -3
- package/dist/viewer/app/layers.js +4 -4
- package/dist/viewer/app/main.js +185 -52
- package/dist/viewer/app/markers.js +60 -0
- package/dist/viewer/app/outliner.js +72 -27
- package/dist/viewer/app/output-info.js +45 -0
- package/dist/viewer/app/outputs.css +147 -8
- package/dist/viewer/app/outputs.js +168 -54
- package/dist/viewer/app/packages.js +614 -0
- package/dist/viewer/app/props.js +176 -52
- package/dist/viewer/app/scene.js +30 -5
- package/dist/viewer/app/select.js +4 -3
- package/dist/viewer/app/status.js +12 -15
- package/dist/viewer/app/style.css +65 -7
- package/dist/viewer/app/vars.js +47 -0
- package/dist/viewer/app/welcome.js +72 -0
- package/dist/viewer/graph-file.d.ts +62 -0
- package/dist/viewer/graph-file.js +175 -0
- package/dist/viewer/index.html +23 -10
- package/dist/viewer/json-edit.d.ts +13 -0
- package/dist/viewer/json-edit.js +274 -0
- package/dist/viewer/outputs.d.ts +49 -5
- package/dist/viewer/outputs.js +264 -56
- package/dist/viewer/packages.d.ts +121 -0
- package/dist/viewer/packages.js +584 -0
- package/dist/viewer/server.d.ts +14 -9
- package/dist/viewer/server.js +266 -28
- package/dist/web/app/web.css +419 -0
- package/dist/web/app/web.js +188 -0
- package/dist/{gallery → web}/bake.d.ts +4 -4
- package/dist/{gallery → web}/bake.js +24 -15
- package/dist/web/folder-page.d.ts +101 -0
- package/dist/web/folder-page.js +146 -0
- package/dist/web/folders.d.ts +280 -0
- package/dist/web/folders.js +970 -0
- package/dist/web/library.d.ts +91 -0
- package/dist/web/library.js +228 -0
- package/dist/web/markdown.d.ts +45 -0
- package/dist/web/markdown.js +677 -0
- package/dist/web/pages.d.ts +258 -0
- package/dist/web/pages.js +301 -0
- package/dist/web/server.d.ts +24 -0
- package/dist/web/server.js +1068 -0
- package/dist/workspace.d.ts +88 -118
- package/dist/workspace.js +358 -460
- package/integrations/godot/addons/topotopo/LICENSE +202 -0
- package/integrations/godot/addons/topotopo/README.md +57 -0
- package/integrations/godot/addons/topotopo/context_menu.gd +43 -0
- package/integrations/godot/addons/topotopo/dock.gd +266 -0
- package/integrations/godot/addons/topotopo/dock.tscn +72 -0
- package/integrations/godot/addons/topotopo/export_filter.gd +72 -0
- package/integrations/godot/addons/topotopo/gltf_instancing.gd +131 -0
- package/integrations/godot/addons/topotopo/icons/topotopo.svg +1 -0
- package/integrations/godot/addons/topotopo/inspector.gd +38 -0
- package/integrations/godot/addons/topotopo/instances_post_import.gd +111 -0
- package/integrations/godot/addons/topotopo/package.gd +23 -0
- package/integrations/godot/addons/topotopo/package_importer.gd +187 -0
- package/integrations/godot/addons/topotopo/plugin.cfg +7 -0
- package/integrations/godot/addons/topotopo/plugin.gd +970 -0
- package/integrations/godot/addons/topotopo/record.gd +435 -0
- package/integrations/godot/addons/topotopo/runner.gd +458 -0
- package/integrations/godot/addons/topotopo/tools/check.gd +42 -0
- package/integrations/godot/addons/topotopo/watcher.gd +199 -0
- package/kernels/pkg/README.md +2 -1
- package/kernels/pkg-simd/README.md +2 -1
- package/library/architecture/versions/1.0/architecture.topo +12 -0
- package/{shelf → library/architecture/versions/1.0/graphs}/arch.json +3 -3
- package/{shelf → library/architecture/versions/1.0/graphs}/beam_truss.json +6 -6
- package/{shelf → library/architecture/versions/1.0/graphs}/brick_wall.json +8 -8
- package/{shelf → library/architecture/versions/1.0/graphs}/door_frame.json +3 -3
- package/{shelf → library/architecture/versions/1.0/graphs}/hex_grid_floor.json +3 -2
- package/{shelf → library/architecture/versions/1.0/graphs}/house.json +8 -8
- package/library/architecture/versions/1.0/graphs/lineup.json +42 -0
- package/{shelf → library/architecture/versions/1.0/graphs}/pillar.json +3 -2
- package/{shelf → library/architecture/versions/1.0/graphs}/railing.json +5 -5
- package/{shelf → library/architecture/versions/1.0/graphs}/roof_gable.json +2 -2
- package/{shelf → library/architecture/versions/1.0/graphs}/roof_hip.json +2 -2
- package/{shelf → library/architecture/versions/1.0/graphs}/roof_skeleton.json +2 -1
- package/{shelf → library/architecture/versions/1.0/graphs}/scaffold.json +4 -4
- package/{shelf → library/architecture/versions/1.0/graphs}/spiral_stairs.json +3 -2
- package/{shelf → library/architecture/versions/1.0/graphs}/stairs.json +6 -6
- package/{shelf → library/architecture/versions/1.0/graphs}/tile_floor.json +3 -2
- package/{shelf → library/architecture/versions/1.0/graphs}/wall_segment.json +10 -10
- package/{shelf → library/architecture/versions/1.0/graphs}/window_frame.json +2 -2
- package/library/architecture/versions/1.0/version.json +1119 -0
- package/{shelf → library/nature/versions/1.0/graphs}/bush.json +2 -2
- package/{shelf → library/nature/versions/1.0/graphs}/cliff_block.json +4 -3
- package/{shelf → library/nature/versions/1.0/graphs}/forest_patch.json +5 -5
- package/{shelf → library/nature/versions/1.0/graphs}/grass_clumps.json +2 -2
- package/library/nature/versions/1.0/graphs/lineup.json +24 -0
- package/{shelf → library/nature/versions/1.0/graphs}/log.json +6 -6
- package/{shelf → library/nature/versions/1.0/graphs}/rock.json +5 -4
- package/{shelf → library/nature/versions/1.0/graphs}/scatter_rocks.json +5 -5
- package/{shelf → library/nature/versions/1.0/graphs}/tree_lowpoly.json +3 -2
- package/library/nature/versions/1.0/nature.topo +12 -0
- package/library/nature/versions/1.0/version.json +534 -0
- package/{shelf → library/props/versions/1.0/graphs}/barrel.json +5 -4
- package/{shelf → library/props/versions/1.0/graphs}/crate.json +3 -3
- package/library/props/versions/1.0/graphs/lineup.json +18 -0
- package/{shelf → library/props/versions/1.0/graphs}/pallet.json +4 -3
- package/{shelf → library/props/versions/1.0/graphs}/pipe_run.json +3 -3
- package/{shelf → library/props/versions/1.0/graphs}/sandbag_wall.json +5 -5
- package/library/props/versions/1.0/props.topo +12 -0
- package/library/props/versions/1.0/version.json +336 -0
- package/{shelf → library/street/versions/1.0/graphs}/bench.json +5 -5
- package/{shelf → library/street/versions/1.0/graphs}/bollard.json +2 -1
- package/{shelf → library/street/versions/1.0/graphs}/cable.json +4 -4
- package/{shelf → library/street/versions/1.0/graphs}/fence.json +7 -7
- package/{shelf → library/street/versions/1.0/graphs}/lamp_post.json +2 -2
- package/library/street/versions/1.0/graphs/lineup.json +22 -0
- package/{shelf → library/street/versions/1.0/graphs}/road_strip.json +2 -2
- package/{shelf → library/street/versions/1.0/graphs}/sign_post.json +1 -1
- package/library/street/versions/1.0/street.topo +12 -0
- package/library/street/versions/1.0/version.json +421 -0
- package/package.json +13 -8
- package/dist/gallery/app/gallery.css +0 -100
- package/dist/gallery/app/gallery.js +0 -80
- package/dist/gallery/cli.d.ts +0 -4
- package/dist/gallery/cli.js +0 -157
- package/dist/gallery/library.d.ts +0 -124
- package/dist/gallery/library.js +0 -366
- package/dist/gallery/pages.d.ts +0 -94
- package/dist/gallery/pages.js +0 -148
- package/dist/gallery/server.d.ts +0 -21
- package/dist/gallery/server.js +0 -391
- package/dist/graph/migrate.d.ts +0 -23
- package/dist/graph/migrate.js +0 -58
- package/dist/mcp/library.d.ts +0 -12
- package/dist/mcp/library.js +0 -159
- package/shelf/index.json +0 -190
package/dist/viewer/server.js
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
// Live preview web server: serves the viewer page (index.html, a shell loading the ES modules of app/ and three.js
|
|
2
|
-
// from /vendor/three/) that shows any graph/node of the
|
|
2
|
+
// from /vendor/three/) that shows any graph/node of the package and refreshes over
|
|
3
3
|
// Server-Sent Events whenever a graph is rebuilt/edited.
|
|
4
|
-
// It is also the human's control surface: files dropped on the page are stored in the
|
|
4
|
+
// It is also the human's control surface: files dropped on the page are stored in the package's inputs/ (under
|
|
5
5
|
// `topotopo view`, the inputs/ beside the graph file) and shown as reference layers, the graph's exposed vars are set
|
|
6
6
|
// from generated controls (POST /api/vars), and markers clicked into the view (sites, paths, zones, volumes) become
|
|
7
7
|
// inputs/markers.json (POST /api/markers).
|
|
8
|
+
// Cooks report their progress (the node cooking, the time) as {cook} events, and POST /api/cook/stop stops them at
|
|
9
|
+
// the next node boundary. A new value supersedes the cook of the one before: the latest value wins.
|
|
10
|
+
// Over a graph file (`topotopo view`, ViewerOptions.source) the controls set session values over the graph, which
|
|
11
|
+
// survive reloads of the file; POST /api/vars/save writes them into its vars.
|
|
12
|
+
// The packages the open package uses (/api/packages*, src/viewer/packages.ts): their updates, the before/after of one and
|
|
13
|
+
// Update, and following a package's working folder for the viewer's session. /api/package says which package the
|
|
14
|
+
// viewer shows (the page's title, its default graph, and what an empty package or a folder that is no package says),
|
|
15
|
+
// with TopoTopo's built-in packages for the welcome.
|
|
8
16
|
// Bound to 127.0.0.1 only; requests must name this server as their Host, and writes must come from its own page.
|
|
9
17
|
import http from 'node:http';
|
|
10
18
|
import fs from 'node:fs';
|
|
@@ -13,16 +21,24 @@ import zlib from 'node:zlib';
|
|
|
13
21
|
import { Transform } from 'node:stream';
|
|
14
22
|
import { pipeline } from 'node:stream/promises';
|
|
15
23
|
import { fileURLToPath } from 'node:url';
|
|
24
|
+
import { varDeclaration, graphVarValue } from '../session.js';
|
|
16
25
|
import { GeoBuilder } from '../core/geometry.js';
|
|
17
26
|
import { exportGeometry } from '../io/export.js';
|
|
18
27
|
import { previewGLB } from '../render/preview.js';
|
|
19
28
|
import { summarize } from '../inspect.js';
|
|
20
29
|
import { withHeightfieldPreview } from '../core/heightfield.js';
|
|
21
|
-
import { wiringOf } from '../graph/engine.js';
|
|
30
|
+
import { STOPPED, wiringOf } from '../graph/engine.js';
|
|
31
|
+
import { packagesNamedIn } from '../graph/packages.js';
|
|
22
32
|
import { createOutputs } from './outputs.js';
|
|
33
|
+
import { createPackages } from './packages.js';
|
|
34
|
+
import { PackageUses, builtinLibrary, isDefaultOutput } from '../packages/registry.js';
|
|
35
|
+
import { packageDirOf, packageId, readManifest } from '../package.js';
|
|
23
36
|
import { renderGeometry } from '../render/raster.js';
|
|
24
37
|
import { encodePNG } from '../render/png.js';
|
|
25
38
|
import { imageFromPNGFile } from '../io/textures.js';
|
|
39
|
+
import { SIDECAR_NAMES, SIDECAR_TEXT } from '../io/sidecars.js';
|
|
40
|
+
import { outputKind } from '../io/kinds.js';
|
|
41
|
+
import { sidecarFile } from '../host/sidecars.js';
|
|
26
42
|
// the page's guide rules, shared so the page and this server check a marker list the same way
|
|
27
43
|
import { MARKER_KINDS as KINDS, MarkerError, parseMarkers as parseMarkerList } from './app/markers.js';
|
|
28
44
|
// index.html and app/ sit next to this module (the build copies them to dist/viewer/)
|
|
@@ -46,6 +62,11 @@ class HttpError extends Error {
|
|
|
46
62
|
status;
|
|
47
63
|
constructor(status, msg) { super(msg); this.status = status; }
|
|
48
64
|
}
|
|
65
|
+
/** A built-in package's outputs in a line, its line-up left out: "7 outputs: bench, bollard, cable …". */
|
|
66
|
+
function outputsLine(v, most = 6) {
|
|
67
|
+
const names = Object.entries(v.outputs).filter(([, o]) => !isDefaultOutput(v, o)).map(([k]) => k);
|
|
68
|
+
return `${names.length} output${names.length === 1 ? '' : 's'}${names.length ? `: ${names.slice(0, most).join(', ')}${names.length > most ? ' …' : ''}` : ''}`;
|
|
69
|
+
}
|
|
49
70
|
/** The shape every geometry route serves: the same GLB options as /api/geo; images alone show as textured quads. */
|
|
50
71
|
const toGLB = (g) => previewGLB(g);
|
|
51
72
|
const issueText = (e) => `[${e.node}] ${e.message}`;
|
|
@@ -150,14 +171,81 @@ export async function startViewer(ws, port = Number(process.env.TOPOTOPO_PORT ??
|
|
|
150
171
|
for (const c of clients)
|
|
151
172
|
c.write(msg);
|
|
152
173
|
};
|
|
153
|
-
|
|
154
|
-
const
|
|
174
|
+
// a graph changed: after a stop the page keeps the geometry it has instead of fetching (and cooking) it again
|
|
175
|
+
const graphChanged = (ev) => broadcast({ ...ev, ...(ws.held(ev.graph) ? { stopped: true } : {}) });
|
|
176
|
+
ws.listeners.add(graphChanged);
|
|
177
|
+
/** The package the viewer shows: that of the packages attached to the session, else the one its folder is in. */
|
|
178
|
+
const packageOf = (refresh = false) => {
|
|
179
|
+
const pk = ws.packages instanceof PackageUses ? ws.packages : null;
|
|
180
|
+
if (refresh && pk?.dir)
|
|
181
|
+
pk.refresh();
|
|
182
|
+
const dir = pk ? pk.dir : packageDirOf(ws.dir);
|
|
183
|
+
let m = pk?.manifest ?? null;
|
|
184
|
+
if (!pk && dir)
|
|
185
|
+
try {
|
|
186
|
+
m = readManifest(dir);
|
|
187
|
+
}
|
|
188
|
+
catch { /* unreadable: no package to name */ }
|
|
189
|
+
return m && dir ? { id: packageId(dir), title: m.title, description: m.description, graph: m.graph, name: m.name ?? null, dir } : null;
|
|
190
|
+
};
|
|
191
|
+
// TopoTopo's built-in packages, read once: they change only with TopoTopo itself
|
|
192
|
+
let builtin = null;
|
|
193
|
+
/**
|
|
194
|
+
* GET /api/package: the package the viewer shows (null for a folder that is in no package), the folder, the graph
|
|
195
|
+
* file of `topotopo view`, and TopoTopo's built-in packages.
|
|
196
|
+
*/
|
|
197
|
+
const packageInfo = () => {
|
|
198
|
+
builtin ??= builtinLibrary().map((b) => {
|
|
199
|
+
const v = b.versions.at(-1);
|
|
200
|
+
return { name: b.name, title: b.manifest.title, description: b.manifest.description, version: v?.version ?? null, outputs: v ? outputsLine(v) : '0 outputs' };
|
|
201
|
+
});
|
|
202
|
+
return { package: packageOf(true), folder: ws.dir, file: opts.source?.label ?? null, builtin };
|
|
203
|
+
};
|
|
204
|
+
// the package's default graph cooks its cards first
|
|
205
|
+
const makeOutputs = () => createOutputs(ws, () => broadcast({ outputs: true }), { source: opts.source, first: () => packageOf()?.graph });
|
|
155
206
|
let outputs = makeOutputs();
|
|
207
|
+
const makePackages = () => createPackages(ws, broadcast);
|
|
208
|
+
let packages = makePackages();
|
|
209
|
+
// ---------------------------------------------------------------- the state of the cooks
|
|
210
|
+
// {cook: {graph, running, last}} events: each node of the graph as it starts (before it can hold the thread for
|
|
211
|
+
// long: the session yields there), the rest of the progress at most every 100 ms, the end at once. A cook that
|
|
212
|
+
// only finds cached results is announced only when it lasts past 120 ms.
|
|
213
|
+
const sessionMode = (graph) => opts.source?.graph === graph;
|
|
214
|
+
const cookState = (graph) => {
|
|
215
|
+
const last = ws.lastCook.get(graph);
|
|
216
|
+
return { running: ws.activity(graph), last: last ? { ...last, error: last.error ? { node: last.error.node, message: last.error.message } : undefined } : null };
|
|
217
|
+
};
|
|
218
|
+
const cookTimers = new Map(), cookSent = new Map();
|
|
219
|
+
const sendCook = (graph) => {
|
|
220
|
+
cookTimers.delete(graph);
|
|
221
|
+
const state = cookState(graph), sent = cookSent.get(graph), last = JSON.stringify(state.last);
|
|
222
|
+
if (!state.running && !sent?.running && sent?.last === last)
|
|
223
|
+
return;
|
|
224
|
+
cookSent.set(graph, { at: performance.now(), running: !!state.running, last });
|
|
225
|
+
broadcast({ cook: { graph, ...state } });
|
|
226
|
+
};
|
|
227
|
+
const onActivity = (graph, ev) => {
|
|
228
|
+
if (closed)
|
|
229
|
+
return;
|
|
230
|
+
if (ev?.phase === 'start' && ev.depth === 0) {
|
|
231
|
+
clearTimeout(cookTimers.get(graph));
|
|
232
|
+
sendCook(graph);
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
if (cookTimers.has(graph))
|
|
236
|
+
return;
|
|
237
|
+
const sent = cookSent.get(graph), running = !!ws.activity(graph);
|
|
238
|
+
const wait = !running ? 0 : sent?.running ? Math.max(0, 100 - (performance.now() - sent.at)) : 120;
|
|
239
|
+
cookTimers.set(graph, setTimeout(() => sendCook(graph), wait));
|
|
240
|
+
};
|
|
241
|
+
ws.activityListeners.add(onActivity);
|
|
156
242
|
// ---------------------------------------------------------------- inputs/
|
|
157
243
|
let inputsVersion = 0;
|
|
158
244
|
const inputsChanged = () => broadcast({ inputs: ++inputsVersion });
|
|
159
|
-
|
|
160
|
-
const
|
|
245
|
+
// an export's sidecar (kind "metadata") says what it is: the page shows it with the file it describes
|
|
246
|
+
const listInputs = () => ws.listInputs().filter((f) => !PART_RE.test(f.path))
|
|
247
|
+
.map((f) => (f.sidecar ? { ...f, about: `${SIDECAR_NAMES[f.sidecar.role]}: ${SIDECAR_TEXT[f.sidecar.role]}` } : f));
|
|
248
|
+
const inputsWhere = () => opts.inputsWhere ?? (path.dirname(ws.inputDir) === ws.dir ? (packageOf() ? 'in the package' : 'in this folder') : `in ${path.dirname(ws.inputDir)}`);
|
|
161
249
|
// Files copied into inputs/ by other means (file manager, an agent) show up too, once the folder exists. The viewer
|
|
162
250
|
// does not make it just to watch it (`topotopo view`'s inputs/ beside the graph file appears with the first drop):
|
|
163
251
|
// uploads and listings start the watch when the folder is there by then.
|
|
@@ -212,8 +300,8 @@ export async function startViewer(ws, port = Number(process.env.TOPOTOPO_PORT ??
|
|
|
212
300
|
/** The one-node graph that loads an input. */
|
|
213
301
|
const inputGraph = (rel, abs) => {
|
|
214
302
|
// "inputs/<rel>", the path a graph's file node uses, resolves against the host's base directory: the folder that
|
|
215
|
-
// holds inputs/ under the MCP server (
|
|
216
|
-
//
|
|
303
|
+
// holds inputs/ under the MCP server (its folder) and under `topotopo view` (the graph file's folder). A
|
|
304
|
+
// session whose engine resolves paths elsewhere (an embedding app, a test) gets the absolute path.
|
|
217
305
|
const ref = `inputs/${rel}`;
|
|
218
306
|
const p = path.resolve(ws.engine.host.resolvePath(ref)) === abs ? ref : abs;
|
|
219
307
|
return { nodes: { f: { type: 'file', params: { path: p } } }, output: 'f' };
|
|
@@ -308,16 +396,49 @@ export async function startViewer(ws, port = Number(process.env.TOPOTOPO_PORT ??
|
|
|
308
396
|
return { ok: true, count: list.length, path: list.length ? 'markers.json' : null, ...counts };
|
|
309
397
|
};
|
|
310
398
|
// ---------------------------------------------------------------- POST /api/vars
|
|
311
|
-
// One
|
|
312
|
-
//
|
|
399
|
+
// One cook at a time per graph. A request that arrives while one runs stops it at its next node boundary (the
|
|
400
|
+
// latest value wins; values in between may never cook); the waiting requests are merged (the latest value of each
|
|
401
|
+
// var wins) and applied by a single further cook. Every request is answered once its values are applied, or when a
|
|
402
|
+
// stop (POST /api/cook/stop) ends the cook. Over a graph file the values are session values, set at once; in a
|
|
403
|
+
// package they edit the stored graph (an agent reads them there).
|
|
313
404
|
const varQueues = new Map();
|
|
405
|
+
const varsState = (name) => {
|
|
406
|
+
const g = ws.graphs.get(name);
|
|
407
|
+
return { vars: g ? ws.effectiveGraph(name).vars ?? {} : {}, graphVars: g?.vars ?? {}, overrides: Object.keys(ws.sessionVars(name)) };
|
|
408
|
+
};
|
|
409
|
+
const reply = (name, report) => ({ status: 200, body: { ok: report.ok, ms: report.ms, errors: report.errors.map(issueText), ...varsState(name), ...(report.stopped ? { stopped: report.stopped } : {}) } });
|
|
410
|
+
/** Session values a request sets, checked against the graph: its own vars only, and a graph that still validates. */
|
|
411
|
+
const sessionErrors = (name, vars) => {
|
|
412
|
+
const g = ws.getGraph(name);
|
|
413
|
+
const unknown = Object.keys(vars).filter((k) => varDeclaration(g, k) === null);
|
|
414
|
+
if (unknown.length)
|
|
415
|
+
return [`graph ${name} has no var ${unknown.map((k) => JSON.stringify(k)).join(', ')}: the controls set the graph's own vars`];
|
|
416
|
+
const trial = { ...(ws.effectiveGraph(name).vars ?? {}) };
|
|
417
|
+
for (const [k, v] of Object.entries(vars)) {
|
|
418
|
+
const back = graphVarValue(g, k);
|
|
419
|
+
if (v !== null)
|
|
420
|
+
trial[k] = v;
|
|
421
|
+
else if (back === undefined)
|
|
422
|
+
delete trial[k];
|
|
423
|
+
else
|
|
424
|
+
trial[k] = back;
|
|
425
|
+
}
|
|
426
|
+
// nothing is written yet: a package the graph names for the first time counts as the version its first use adds
|
|
427
|
+
const tried = { ...g, vars: trial };
|
|
428
|
+
return ws.engine.validate(tried, '', ws.dryScope(tried).scope).errors.map(issueText);
|
|
429
|
+
};
|
|
314
430
|
const applyBatch = async (name, b) => {
|
|
315
|
-
|
|
316
|
-
if (!prev)
|
|
431
|
+
if (!ws.graphs.get(name))
|
|
317
432
|
return { status: 404, body: { ok: false, ms: 0, errors: [`no graph ${name}`] } };
|
|
433
|
+
if (sessionMode(name)) {
|
|
434
|
+
const report = await ws.cook(name, undefined, undefined, { kind: 'edit' });
|
|
435
|
+
if (!report.stopped)
|
|
436
|
+
ws.bump(name);
|
|
437
|
+
return reply(name, report);
|
|
438
|
+
}
|
|
318
439
|
try {
|
|
319
|
-
const {
|
|
320
|
-
return
|
|
440
|
+
const { report } = await ws.edit(name, [{ op: 'vars', vars: b.vars }], { kind: 'edit' });
|
|
441
|
+
return reply(name, report);
|
|
321
442
|
}
|
|
322
443
|
catch (e) {
|
|
323
444
|
// rejected edits carry their issues (one string each); op errors are plain messages
|
|
@@ -325,6 +446,12 @@ export async function startViewer(ws, port = Number(process.env.TOPOTOPO_PORT ??
|
|
|
325
446
|
}
|
|
326
447
|
};
|
|
327
448
|
const applyVars = (name, vars) => new Promise((resolve) => {
|
|
449
|
+
if (sessionMode(name)) {
|
|
450
|
+
const errors = sessionErrors(name, vars);
|
|
451
|
+
if (errors.length)
|
|
452
|
+
return resolve({ status: 400, body: { ok: false, ms: 0, errors } });
|
|
453
|
+
ws.setSessionVars(name, vars);
|
|
454
|
+
}
|
|
328
455
|
let q = varQueues.get(name);
|
|
329
456
|
if (!q)
|
|
330
457
|
varQueues.set(name, q = { busy: false, next: null });
|
|
@@ -334,8 +461,11 @@ export async function startViewer(ws, port = Number(process.env.TOPOTOPO_PORT ??
|
|
|
334
461
|
}
|
|
335
462
|
else
|
|
336
463
|
q.next = { vars: { ...vars }, waiters: [resolve] };
|
|
337
|
-
|
|
464
|
+
// the latest value wins: the cook of the values before (and the previews of them) stop at their next node boundary
|
|
465
|
+
if (q.busy) {
|
|
466
|
+
ws.stop(name, ['edit', 'preview'], { superseded: true });
|
|
338
467
|
return;
|
|
468
|
+
}
|
|
339
469
|
q.busy = true;
|
|
340
470
|
(async () => {
|
|
341
471
|
try {
|
|
@@ -343,6 +473,13 @@ export async function startViewer(ws, port = Number(process.env.TOPOTOPO_PORT ??
|
|
|
343
473
|
const b = q.next;
|
|
344
474
|
q.next = null;
|
|
345
475
|
const r = await applyBatch(name, b).catch((e) => ({ status: 500, body: { ok: false, ms: 0, errors: [String(e?.message ?? e)] } }));
|
|
476
|
+
// superseded: its values are in the batch that came after it, and that cook answers its requests too
|
|
477
|
+
const later = q.next;
|
|
478
|
+
if (r.body.stopped && later) {
|
|
479
|
+
later.vars = { ...b.vars, ...later.vars };
|
|
480
|
+
later.waiters.unshift(...b.waiters);
|
|
481
|
+
continue;
|
|
482
|
+
}
|
|
346
483
|
for (const w of b.waiters)
|
|
347
484
|
w(r);
|
|
348
485
|
}
|
|
@@ -352,6 +489,42 @@ export async function startViewer(ws, port = Number(process.env.TOPOTOPO_PORT ??
|
|
|
352
489
|
}
|
|
353
490
|
})();
|
|
354
491
|
});
|
|
492
|
+
/** POST /api/cook/stop: stop every cook of the graph, and the values waiting to cook (they stay set). */
|
|
493
|
+
const stopCooks = (name) => {
|
|
494
|
+
const n = ws.stop(name);
|
|
495
|
+
const q = varQueues.get(name), waiting = q?.next;
|
|
496
|
+
if (q)
|
|
497
|
+
q.next = null;
|
|
498
|
+
if (waiting) {
|
|
499
|
+
const at = ws.activity(name)?.node ?? ws.engine.findOutput(ws.getGraph(name)).name;
|
|
500
|
+
const r = { status: 200, body: { ok: false, ms: 0, errors: [], ...varsState(name), stopped: at } };
|
|
501
|
+
for (const w of waiting.waiters)
|
|
502
|
+
w(r);
|
|
503
|
+
}
|
|
504
|
+
// nothing cooks it again on its own until the graph or a value changes
|
|
505
|
+
if (n || waiting)
|
|
506
|
+
ws.hold(name);
|
|
507
|
+
return { ok: true, stopping: n > 0 };
|
|
508
|
+
};
|
|
509
|
+
/** POST /api/vars/save: the session values into the graph file's vars; the graph holds them from now on. */
|
|
510
|
+
const saveVars = (name) => {
|
|
511
|
+
const src = opts.source;
|
|
512
|
+
if (!src || src.graph !== name)
|
|
513
|
+
throw new HttpError(400, sessionMode(name)
|
|
514
|
+
? 'this viewer cannot write the graph file: start it with `topotopo view <graph.json>` to save values'
|
|
515
|
+
: `graph ${name} is the package's own: its values are saved as they change`);
|
|
516
|
+
const values = ws.sessionVars(name), names = Object.keys(values);
|
|
517
|
+
if (names.length) {
|
|
518
|
+
try {
|
|
519
|
+
src.save(names.map((k) => ({ path: ['vars', k], value: values[k] })));
|
|
520
|
+
}
|
|
521
|
+
catch (e) {
|
|
522
|
+
throw new HttpError(500, `could not write ${src.label}: ${e?.message ?? e}`);
|
|
523
|
+
}
|
|
524
|
+
ws.bump(name);
|
|
525
|
+
}
|
|
526
|
+
return { ok: true, saved: names, file: src.label, ...varsState(name) };
|
|
527
|
+
};
|
|
355
528
|
const readJSON = (req, max = 4 << 20) => new Promise((resolve, reject) => {
|
|
356
529
|
const chunks = [];
|
|
357
530
|
let n = 0;
|
|
@@ -390,6 +563,8 @@ export async function startViewer(ws, port = Number(process.env.TOPOTOPO_PORT ??
|
|
|
390
563
|
route = u.pathname;
|
|
391
564
|
if (await outputs.handle(req, res, u, readJSON))
|
|
392
565
|
return;
|
|
566
|
+
if (await packages.handle(req, res, u, readJSON))
|
|
567
|
+
return;
|
|
393
568
|
if (u.pathname === '/' || u.pathname === '/index.html')
|
|
394
569
|
return send(200, fs.readFileSync(path.join(here, 'index.html')), MIME['.html']);
|
|
395
570
|
// the page's modules and style sheet
|
|
@@ -413,16 +588,28 @@ export async function startViewer(ws, port = Number(process.env.TOPOTOPO_PORT ??
|
|
|
413
588
|
req.on('close', () => clients.delete(res));
|
|
414
589
|
return;
|
|
415
590
|
}
|
|
591
|
+
if (u.pathname === '/api/package')
|
|
592
|
+
return json(200, packageInfo());
|
|
416
593
|
if (u.pathname === '/api/graphs') {
|
|
417
594
|
const out = [...ws.graphs].map(([name, g]) => {
|
|
418
595
|
const last = ws.lastReport.get(name);
|
|
419
596
|
return {
|
|
420
|
-
|
|
421
|
-
|
|
597
|
+
// a cook that failed validation (a package update the graph must follow) has no target
|
|
598
|
+
name, output: last?.target || g.output || null, version: ws.versions.get(name) ?? 0,
|
|
599
|
+
// vars: what the controls show; graphVars: the graph's own; overrides: the session values among them
|
|
600
|
+
...varsState(name), params: g.params ?? {},
|
|
601
|
+
// "file": the controls set session values over a graph file (saveable when it names the file); "package":
|
|
602
|
+
// they edit the stored graph
|
|
603
|
+
mode: sessionMode(name) ? 'file' : 'package', file: opts.source?.graph === name ? opts.source.label : null,
|
|
604
|
+
cook: cookState(name),
|
|
422
605
|
nodes: Object.entries(g.nodes).map(([n, spec]) => {
|
|
423
606
|
const def = ws.engine.resolveDef(spec.type);
|
|
424
607
|
const r = last?.results.get(n);
|
|
425
|
-
|
|
608
|
+
// the packages it names, as its type or in its nested graphs: the Scene tree marks those with an update
|
|
609
|
+
const named = packagesNamedIn({ nodes: { [n]: spec } });
|
|
610
|
+
// its error: from its cook, or from the graph's validation (a slider a package version does not have)
|
|
611
|
+
const error = r?.error?.message ?? (last && !last.ok ? last.errors.find((e) => e.node === n)?.message : undefined) ?? null;
|
|
612
|
+
return { name: n, type: spec.type, in: def ? wiringOf(spec, def).list : [], error, ms: r?.ms ?? null, ...(named.length ? { packages: named } : {}) };
|
|
426
613
|
}),
|
|
427
614
|
};
|
|
428
615
|
});
|
|
@@ -451,6 +638,27 @@ export async function startViewer(ws, port = Number(process.env.TOPOTOPO_PORT ??
|
|
|
451
638
|
const r = await applyVars(name, vars);
|
|
452
639
|
return json(r.status, r.body);
|
|
453
640
|
}
|
|
641
|
+
if (u.pathname === '/api/vars/save' || u.pathname === '/api/cook/stop') {
|
|
642
|
+
if (req.method !== 'POST')
|
|
643
|
+
throw new HttpError(405, 'POST required');
|
|
644
|
+
const name = u.searchParams.get('graph') ?? 'main';
|
|
645
|
+
const body = await readJSON(req);
|
|
646
|
+
if (!ws.graphs.has(name))
|
|
647
|
+
throw new HttpError(404, `no graph ${name}`);
|
|
648
|
+
if (u.pathname === '/api/cook/stop')
|
|
649
|
+
return json(200, stopCooks(name));
|
|
650
|
+
// the save may carry the values the page shows (some may still be on their way): they are set first
|
|
651
|
+
const vars = body?.vars;
|
|
652
|
+
if (vars !== undefined && (!vars || typeof vars !== 'object' || Array.isArray(vars)))
|
|
653
|
+
throw new HttpError(400, '"vars" must be an object {name: value}');
|
|
654
|
+
if (vars && Object.keys(vars).length && sessionMode(name)) {
|
|
655
|
+
const errors = sessionErrors(name, vars);
|
|
656
|
+
if (errors.length)
|
|
657
|
+
throw new HttpError(400, errors.join('; '));
|
|
658
|
+
ws.setSessionVars(name, vars);
|
|
659
|
+
}
|
|
660
|
+
return json(200, saveVars(name));
|
|
661
|
+
}
|
|
454
662
|
if (u.pathname === '/api/inputs') {
|
|
455
663
|
if (req.method === 'POST') {
|
|
456
664
|
const r = await upload(req, u);
|
|
@@ -477,6 +685,8 @@ export async function startViewer(ws, port = Number(process.env.TOPOTOPO_PORT ??
|
|
|
477
685
|
return send(200, fs.readFileSync(abs), mime);
|
|
478
686
|
if (u.pathname === '/api/input_image')
|
|
479
687
|
throw new HttpError(400, 'choose a PNG, JPEG or WebP image');
|
|
688
|
+
if (sidecarFile(abs))
|
|
689
|
+
throw new HttpError(400, `inputs/${rel} is an export's sidecar (metadata), not geometry: it has no thumbnail`);
|
|
480
690
|
const stat = fs.statSync(abs), key = `${abs}:${stat.size}:${stat.mtimeMs}`;
|
|
481
691
|
if (!inputThumbs.has(key)) {
|
|
482
692
|
if (inputThumbs.size >= 128)
|
|
@@ -495,6 +705,14 @@ export async function startViewer(ws, port = Number(process.env.TOPOTOPO_PORT ??
|
|
|
495
705
|
}
|
|
496
706
|
if (u.pathname === '/api/input' || u.pathname === '/api/input_info') {
|
|
497
707
|
const { rel, abs } = inputPath(u.searchParams.get('path'));
|
|
708
|
+
// an export's sidecar (io/sidecars.ts) is metadata of the file beside it: described, never cooked
|
|
709
|
+
const side = sidecarFile(abs);
|
|
710
|
+
if (side) {
|
|
711
|
+
const what = `${SIDECAR_NAMES[side.role]} of ${side.of ? `inputs/${path.relative(ws.inputDir, side.of).split(path.sep).join('/')}` : 'an export that is not in inputs/'}: ${SIDECAR_TEXT[side.role]}`;
|
|
712
|
+
if (u.pathname === '/api/input_info')
|
|
713
|
+
return json(200, { path: rel, summary: `${what} (metadata, not geometry)`, metadata: true });
|
|
714
|
+
throw new HttpError(400, `inputs/${rel} is ${what}: metadata, not geometry to show`);
|
|
715
|
+
}
|
|
498
716
|
if (u.pathname === '/api/input_info' && imageType(abs)) {
|
|
499
717
|
let summary = `${imageType(abs)} · ${fs.statSync(abs).size} bytes`;
|
|
500
718
|
// Preserve the existing PNG summary contract without cooking a file-node graph.
|
|
@@ -514,16 +732,23 @@ export async function startViewer(ws, port = Number(process.env.TOPOTOPO_PORT ??
|
|
|
514
732
|
}
|
|
515
733
|
if (u.pathname === '/api/geo' || u.pathname === '/api/info') {
|
|
516
734
|
const name = u.searchParams.get('graph') ?? 'main';
|
|
517
|
-
const node = u.searchParams.get('node') || undefined;
|
|
518
735
|
const g = ws.graphs.get(name);
|
|
519
736
|
if (!g)
|
|
520
737
|
return send(404, JSON.stringify({ error: `no graph ${name}` }), MIME['.json']);
|
|
521
|
-
|
|
738
|
+
// a preview with the session values; the output by name, so it never counts as the graph's own cook (lastCook).
|
|
739
|
+
// After a stop the output is the last finished cook's: asking for it does not cook again what was stopped.
|
|
740
|
+
const last = ws.lastReport.get(name);
|
|
741
|
+
const node = u.searchParams.get('node') || ws.engine.findOutput(g).name;
|
|
742
|
+
const r = !u.searchParams.get('node') && ws.held(name) && last?.ok && last.target === node ? last : await ws.cook(name, node, undefined, { kind: 'preview' });
|
|
743
|
+
if (r.stopped)
|
|
744
|
+
return send(409, JSON.stringify({ error: `${STOPPED} at ${r.stopped}`, stopped: r.stopped }), MIME['.json']);
|
|
522
745
|
if (!r.ok || !r.geo)
|
|
523
746
|
return send(500, JSON.stringify({ error: r.errors.map(issueText).join('\n') }), MIME['.json']);
|
|
747
|
+
// info: what it is (io/kinds.ts), for the properties and their heightfield layer picker
|
|
524
748
|
if (u.pathname === '/api/info')
|
|
525
|
-
return send(200, JSON.stringify({ target: r.target, summary: summarize(r.geo), ms: r.ms }), MIME['.json']);
|
|
526
|
-
|
|
749
|
+
return send(200, JSON.stringify({ target: r.target, summary: summarize(r.geo), ms: r.ms, about: outputKind(r.geo) }), MIME['.json']);
|
|
750
|
+
// heightfields: the layer drawn in red (the page's layer picker; the mask by default)
|
|
751
|
+
return send(200, await previewGLB(r.geo, { heightfieldLayer: u.searchParams.get('heightfield_layer') || undefined }), MIME['.glb']);
|
|
527
752
|
}
|
|
528
753
|
send(404, 'not found');
|
|
529
754
|
}
|
|
@@ -559,20 +784,29 @@ export async function startViewer(ws, port = Number(process.env.TOPOTOPO_PORT ??
|
|
|
559
784
|
return {
|
|
560
785
|
url: `http://127.0.0.1:${actual}/`,
|
|
561
786
|
clients: () => clients.size,
|
|
562
|
-
|
|
787
|
+
pokePackages: (pkg, rel) => packages.poke(pkg, rel),
|
|
788
|
+
setSession: (next) => {
|
|
563
789
|
if (next === ws || closed)
|
|
564
790
|
return;
|
|
565
|
-
ws.listeners.delete(
|
|
791
|
+
ws.listeners.delete(graphChanged);
|
|
792
|
+
ws.activityListeners.delete(onActivity);
|
|
566
793
|
outputs.close();
|
|
794
|
+
packages.close();
|
|
567
795
|
clearTimeout(watchTimer);
|
|
796
|
+
for (const t of cookTimers.values())
|
|
797
|
+
clearTimeout(t);
|
|
798
|
+
cookTimers.clear();
|
|
799
|
+
cookSent.clear();
|
|
568
800
|
unwatch();
|
|
569
801
|
varQueues.clear();
|
|
570
802
|
inputThumbs.clear();
|
|
571
803
|
ws = next;
|
|
572
|
-
ws.listeners.add(
|
|
804
|
+
ws.listeners.add(graphChanged);
|
|
805
|
+
ws.activityListeners.add(onActivity);
|
|
573
806
|
outputs = makeOutputs();
|
|
807
|
+
packages = makePackages();
|
|
574
808
|
watchInputs();
|
|
575
|
-
// the pages reconnect (EventSource retries) and reload graphs, layers and guides from the new
|
|
809
|
+
// the pages reconnect (EventSource retries) and reload graphs, layers and guides from the new package
|
|
576
810
|
for (const c of clients)
|
|
577
811
|
c.end();
|
|
578
812
|
clients.clear();
|
|
@@ -580,10 +814,14 @@ export async function startViewer(ws, port = Number(process.env.TOPOTOPO_PORT ??
|
|
|
580
814
|
close: () => {
|
|
581
815
|
closed = true;
|
|
582
816
|
outputs.close();
|
|
817
|
+
packages.close();
|
|
583
818
|
clearInterval(keepAlive);
|
|
584
819
|
clearTimeout(watchTimer);
|
|
820
|
+
for (const t of cookTimers.values())
|
|
821
|
+
clearTimeout(t);
|
|
585
822
|
unwatch();
|
|
586
|
-
ws.listeners.delete(
|
|
823
|
+
ws.listeners.delete(graphChanged);
|
|
824
|
+
ws.activityListeners.delete(onActivity);
|
|
587
825
|
for (const c of clients)
|
|
588
826
|
c.end();
|
|
589
827
|
server.close();
|