topotopo 0.3.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE +40 -10
- package/README.md +475 -111
- package/dist/cli.js +328 -133
- package/dist/config.d.ts +48 -0
- package/dist/config.js +170 -0
- package/dist/core/analysis.d.ts +5 -1
- package/dist/core/analysis.js +8 -3
- package/dist/core/bake.d.ts +16 -8
- package/dist/core/bake.js +165 -29
- package/dist/core/bevel.d.ts +3 -1
- package/dist/core/bevel.js +238 -97
- 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 +204 -4
- package/dist/core/heightfield.d.ts +27 -4
- package/dist/core/heightfield.js +54 -16
- package/dist/core/imageops.d.ts +6 -0
- package/dist/core/imageops.js +51 -0
- 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 +11 -0
- package/dist/core/materials.js +56 -0
- package/dist/core/noise.d.ts +9 -0
- package/dist/core/noise.js +10 -1
- package/dist/core/packed.js +11 -0
- package/dist/core/particles.d.ts +1 -1
- package/dist/core/particles.js +1 -1
- package/dist/core/polymerge.d.ts +21 -0
- package/dist/core/polymerge.js +327 -0
- package/dist/core/rbd.js +13 -1
- 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/scatter.d.ts +1 -1
- package/dist/core/scatter.js +1 -1
- package/dist/core/scene.d.ts +20 -0
- package/dist/core/scene.js +72 -0
- 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 +15 -2
- package/dist/core/snippet-lib.js +40 -14
- package/dist/core/solidify.d.ts +38 -0
- package/dist/core/solidify.js +356 -0
- package/dist/core/tangents.d.ts +54 -0
- package/dist/core/tangents.js +218 -0
- package/dist/core/texcoord.d.ts +4 -0
- package/dist/core/texcoord.js +14 -0
- 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 +32 -0
- package/dist/core/topology.js +238 -7
- package/dist/core/traceimage.d.ts +7 -0
- package/dist/core/traceimage.js +221 -0
- package/dist/core/tritri.d.ts +5 -0
- package/dist/core/tritri.js +120 -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 +15 -16
- package/dist/core/uv.js +36 -189
- 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 +127 -0
- package/dist/core/uvreport.js +372 -0
- 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 +95 -61
- 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 +5 -3
- package/dist/index.js +3 -2
- package/dist/inspect.d.ts +84 -1
- package/dist/inspect.js +271 -24
- package/dist/io/common.d.ts +33 -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 +355 -51
- 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 +149 -14
- 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 +816 -119
- package/dist/mcp/inputs.d.ts +12 -5
- package/dist/mcp/inputs.js +50 -13
- package/dist/mcp/server.js +70 -24
- package/dist/mcp/tools.d.ts +14 -7
- package/dist/mcp/tools.js +207 -108
- 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 +207 -83
- package/dist/nodes/beam.d.ts +1 -0
- package/dist/nodes/beam.js +201 -0
- package/dist/nodes/bevel.js +54 -5
- package/dist/nodes/cloth.js +2 -0
- package/dist/nodes/code.js +22 -10
- package/dist/nodes/curves.js +440 -93
- package/dist/nodes/flow.js +53 -33
- package/dist/nodes/generate.js +13 -39
- package/dist/nodes/heightfield.js +248 -77
- package/dist/nodes/imageops.d.ts +1 -0
- package/dist/nodes/imageops.js +203 -0
- package/dist/nodes/index.d.ts +4 -0
- package/dist/nodes/index.js +4 -0
- package/dist/nodes/material.js +91 -23
- package/dist/nodes/measure.js +45 -18
- package/dist/nodes/particles.js +2 -0
- package/dist/nodes/pcg.js +6 -5
- package/dist/nodes/procedural.js +4 -3
- package/dist/nodes/rbd.js +1 -1
- package/dist/nodes/remesh.js +71 -15
- package/dist/nodes/scene.d.ts +1 -0
- package/dist/nodes/scene.js +55 -0
- package/dist/nodes/sdf.js +10 -5
- package/dist/nodes/solid.js +20 -5
- package/dist/nodes/solidify.d.ts +1 -0
- package/dist/nodes/solidify.js +52 -0
- 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 +11 -3
- package/dist/nodes/util.d.ts +1 -1
- package/dist/nodes/uv.js +192 -174
- package/dist/nodes/wasmcall.js +6 -2
- 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 +44 -5
- package/dist/render/pbr.d.ts +28 -0
- package/dist/render/pbr.js +378 -0
- package/dist/render/preview.d.ts +69 -0
- package/dist/render/preview.js +26 -0
- package/dist/render/raster.d.ts +78 -7
- package/dist/render/raster.js +600 -145
- package/dist/render/texview.d.ts +7 -1
- package/dist/render/texview.js +34 -2
- 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/camera.js +1 -1
- package/dist/viewer/app/cooking.js +78 -0
- package/dist/viewer/app/embed.js +100 -0
- package/dist/viewer/app/export-popover.js +118 -16
- package/dist/viewer/app/grid.js +6 -2
- package/dist/viewer/app/guides.js +123 -1
- package/dist/viewer/app/keymap.js +7 -4
- package/dist/viewer/app/layers.js +5 -5
- package/dist/viewer/app/main.js +186 -53
- package/dist/viewer/app/markers.js +61 -1
- 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 +177 -53
- package/dist/viewer/app/scene.js +35 -6
- package/dist/viewer/app/select.js +5 -4
- package/dist/viewer/app/selection.js +1 -1
- package/dist/viewer/app/status.js +12 -15
- package/dist/viewer/app/style.css +66 -8
- package/dist/viewer/app/units.js +1 -1
- package/dist/viewer/app/vars.js +48 -1
- 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 +24 -11
- 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 +24 -7
- package/dist/viewer/server.js +289 -31
- package/dist/web/app/web.css +419 -0
- package/dist/web/app/web.js +188 -0
- package/dist/web/bake.d.ts +34 -0
- package/dist/web/bake.js +153 -0
- 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 -105
- package/dist/workspace.js +359 -375
- 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 +23 -29
- package/kernels/pkg-simd/README.md +23 -29
- 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 +23 -8
- package/dist/graph/migrate.d.ts +0 -23
- package/dist/graph/migrate.js +0 -58
- package/shelf/index.json +0 -190
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
// Minimal edits to JSON text: set or remove values at key paths and leave every other character as it was, so the
|
|
2
|
+
// formatting, key order, number spellings (2.0) and string escapes (…) a person or a tool wrote survive. The live
|
|
3
|
+
// viewer writes a graph file this way when it sets an export target or saves tuned values (graph-file.ts).
|
|
4
|
+
// editJSONText('{\n "vars": { "s": 2.0 }\n}', [{ path: ['vars', 's'], value: 5 }]) → '{\n "vars": { "s": 5 }\n}'
|
|
5
|
+
// A value equal to the one in the text keeps its spelling. A new member goes after the object's last one, laid out
|
|
6
|
+
// like its siblings (one per line with their indent, or inline). The result is checked against the same edits applied
|
|
7
|
+
// to the parsed value: editJSONText never returns text that means something else.
|
|
8
|
+
/** The value spans of a JSON text (positions of every object member and array item). Throws SyntaxError. */
|
|
9
|
+
function parseSpans(text) {
|
|
10
|
+
let i = text.charCodeAt(0) === 0xfeff ? 1 : 0;
|
|
11
|
+
const fail = (what) => { throw new SyntaxError(`${what} at position ${i}`); };
|
|
12
|
+
const space = () => { for (let c = text.charCodeAt(i); c === 32 || c === 9 || c === 10 || c === 13; c = text.charCodeAt(++i))
|
|
13
|
+
; };
|
|
14
|
+
const string = () => {
|
|
15
|
+
for (i++; i < text.length; i++) {
|
|
16
|
+
const c = text.charCodeAt(i);
|
|
17
|
+
if (c === 34) {
|
|
18
|
+
i++;
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
if (c === 92)
|
|
22
|
+
i++;
|
|
23
|
+
else if (c < 32)
|
|
24
|
+
fail('control character in a string');
|
|
25
|
+
}
|
|
26
|
+
fail('unterminated string');
|
|
27
|
+
};
|
|
28
|
+
const NUMBER = /-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?/y;
|
|
29
|
+
const value = () => {
|
|
30
|
+
space();
|
|
31
|
+
const start = i, c = text[i];
|
|
32
|
+
if (c === '{') {
|
|
33
|
+
const members = [];
|
|
34
|
+
i++;
|
|
35
|
+
space();
|
|
36
|
+
if (text[i] === '}') {
|
|
37
|
+
i++;
|
|
38
|
+
return { kind: 'object', start, end: i, members };
|
|
39
|
+
}
|
|
40
|
+
for (;;) {
|
|
41
|
+
space();
|
|
42
|
+
if (text[i] !== '"')
|
|
43
|
+
fail('expected a key');
|
|
44
|
+
const keyStart = i;
|
|
45
|
+
string();
|
|
46
|
+
const key = JSON.parse(text.slice(keyStart, i));
|
|
47
|
+
space();
|
|
48
|
+
if (text[i] !== ':')
|
|
49
|
+
fail('expected ":"');
|
|
50
|
+
i++;
|
|
51
|
+
members.push({ key, keyStart, value: value() });
|
|
52
|
+
space();
|
|
53
|
+
if (text[i] === ',') {
|
|
54
|
+
i++;
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
if (text[i] === '}') {
|
|
58
|
+
i++;
|
|
59
|
+
return { kind: 'object', start, end: i, members };
|
|
60
|
+
}
|
|
61
|
+
fail('expected "," or "}"');
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (c === '[') {
|
|
65
|
+
const items = [];
|
|
66
|
+
i++;
|
|
67
|
+
space();
|
|
68
|
+
if (text[i] === ']') {
|
|
69
|
+
i++;
|
|
70
|
+
return { kind: 'array', start, end: i, items };
|
|
71
|
+
}
|
|
72
|
+
for (;;) {
|
|
73
|
+
items.push(value());
|
|
74
|
+
space();
|
|
75
|
+
if (text[i] === ',') {
|
|
76
|
+
i++;
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
if (text[i] === ']') {
|
|
80
|
+
i++;
|
|
81
|
+
return { kind: 'array', start, end: i, items };
|
|
82
|
+
}
|
|
83
|
+
fail('expected "," or "]"');
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (c === '"') {
|
|
87
|
+
string();
|
|
88
|
+
return { kind: 'scalar', start, end: i };
|
|
89
|
+
}
|
|
90
|
+
NUMBER.lastIndex = i;
|
|
91
|
+
const n = NUMBER.exec(text);
|
|
92
|
+
if (n?.[0]) {
|
|
93
|
+
i += n[0].length;
|
|
94
|
+
return { kind: 'scalar', start, end: i };
|
|
95
|
+
}
|
|
96
|
+
for (const lit of ['true', 'false', 'null'])
|
|
97
|
+
if (text.startsWith(lit, i)) {
|
|
98
|
+
i += lit.length;
|
|
99
|
+
return { kind: 'scalar', start, end: i };
|
|
100
|
+
}
|
|
101
|
+
return fail(i < text.length ? `unexpected "${c}"` : 'unexpected end');
|
|
102
|
+
};
|
|
103
|
+
const root = value();
|
|
104
|
+
space();
|
|
105
|
+
if (i < text.length)
|
|
106
|
+
fail('unexpected text after the value');
|
|
107
|
+
return root;
|
|
108
|
+
}
|
|
109
|
+
/** Equal as JSON values (key order ignored). */
|
|
110
|
+
function same(a, b) {
|
|
111
|
+
if (a === b)
|
|
112
|
+
return true;
|
|
113
|
+
if (typeof a !== 'object' || typeof b !== 'object' || a === null || b === null || Array.isArray(a) !== Array.isArray(b))
|
|
114
|
+
return false;
|
|
115
|
+
const ka = Object.keys(a), kb = Object.keys(b);
|
|
116
|
+
return ka.length === kb.length && ka.every((k) => Object.hasOwn(b, k) && same(a[k], b[k]));
|
|
117
|
+
}
|
|
118
|
+
/** How the text writes things: line ending, indent step, a space after ":" and ",", \u escapes for non-ASCII. */
|
|
119
|
+
function styleOf(text, root) {
|
|
120
|
+
const nl = text.includes('\r\n') ? '\r\n' : '\n';
|
|
121
|
+
let unit = ' ';
|
|
122
|
+
if (root.kind === 'object' && root.members.length) {
|
|
123
|
+
const before = text.slice(0, root.members[0].keyStart), line = before.lastIndexOf('\n');
|
|
124
|
+
if (line >= 0)
|
|
125
|
+
unit = before.slice(line + 1) || unit;
|
|
126
|
+
}
|
|
127
|
+
const colons = text.match(/"\s*:( ?)/g) ?? [];
|
|
128
|
+
const spaced = colons.filter((m) => m.endsWith(' ')).length >= colons.length / 2;
|
|
129
|
+
// only escapes, never raw: keep writing them (a tool that writes ASCII-only JSON)
|
|
130
|
+
const escapes = /\\u00[89a-f][0-9a-f]|\\u0[1-9a-f][0-9a-f]{2}|\\u[1-9a-f][0-9a-f]{3}/i.test(text) && !/[^\u0000-\u007f]/.test(text);
|
|
131
|
+
return { nl, unit, colon: spaced ? ': ' : ':', comma: spaced ? ', ' : ',', escapes };
|
|
132
|
+
}
|
|
133
|
+
/** A value written inline in the text's style. */
|
|
134
|
+
function write(v, st) {
|
|
135
|
+
if (v === null || typeof v !== 'object') {
|
|
136
|
+
const s = JSON.stringify(v) ?? 'null';
|
|
137
|
+
return st.escapes && typeof v === 'string' ? s.replace(/[\u0080-]/g, (ch) => '\\u' + ch.charCodeAt(0).toString(16).padStart(4, '0')) : s;
|
|
138
|
+
}
|
|
139
|
+
if (Array.isArray(v))
|
|
140
|
+
return '[' + v.map((x) => write(x === undefined ? null : x, st)).join(st.comma) + ']';
|
|
141
|
+
const entries = Object.entries(v).filter(([, x]) => x !== undefined);
|
|
142
|
+
return '{' + entries.map(([k, x]) => write(k, st) + st.colon + write(x, st)).join(st.comma) + '}';
|
|
143
|
+
}
|
|
144
|
+
/** The indent of the line `pos` is on. */
|
|
145
|
+
function lineIndent(text, pos) {
|
|
146
|
+
const line = text.lastIndexOf('\n', pos - 1) + 1;
|
|
147
|
+
return /^[ \t]*/.exec(text.slice(line, pos))[0];
|
|
148
|
+
}
|
|
149
|
+
const splice = (text, s, by) => text.slice(0, s.start) + by + text.slice(s.end);
|
|
150
|
+
/** Text with `key: value` set in object `o` (replaced in place, or added after its last member). */
|
|
151
|
+
function setMember(text, o, key, value, st) {
|
|
152
|
+
const m = o.members.findLast((x) => x.key === key);
|
|
153
|
+
if (m) {
|
|
154
|
+
if (same(JSON.parse(text.slice(m.value.start, m.value.end)), value))
|
|
155
|
+
return text;
|
|
156
|
+
return splice(text, m.value, write(value, st));
|
|
157
|
+
}
|
|
158
|
+
const member = write(key, st) + st.colon + write(value, st);
|
|
159
|
+
if (!o.members.length) {
|
|
160
|
+
// an empty object: one member on its own line when the text spreads over lines, else inline
|
|
161
|
+
if (!text.includes('\n'))
|
|
162
|
+
return splice(text, o, `{${member}}`);
|
|
163
|
+
const indent = lineIndent(text, o.start);
|
|
164
|
+
return splice(text, o, `{${st.nl}${indent}${st.unit}${member}${st.nl}${indent}}`);
|
|
165
|
+
}
|
|
166
|
+
const first = o.members[0], last = o.members[o.members.length - 1];
|
|
167
|
+
const gap = text.slice(o.start + 1, first.keyStart);
|
|
168
|
+
const at = last.value.end;
|
|
169
|
+
if (gap.includes('\n'))
|
|
170
|
+
return text.slice(0, at) + ',' + st.nl + lineIndent(text, first.keyStart) + member + text.slice(at);
|
|
171
|
+
// inline: the separator the members use (", " or ",")
|
|
172
|
+
const sep = o.members.length > 1 ? /,(\s*)$/.exec(text.slice(o.members[0].value.end, o.members[1].keyStart))?.[1] ?? '' : gap;
|
|
173
|
+
return text.slice(0, at) + ',' + sep + member + text.slice(at);
|
|
174
|
+
}
|
|
175
|
+
/** Text without member `key` of object `o` (its comma and the space before the next member go with it). */
|
|
176
|
+
function removeMember(text, o, key) {
|
|
177
|
+
const j = o.members.findLastIndex((x) => x.key === key);
|
|
178
|
+
if (j < 0)
|
|
179
|
+
return text;
|
|
180
|
+
const m = o.members[j];
|
|
181
|
+
if (o.members.length === 1)
|
|
182
|
+
return splice(text, { start: o.start + 1, end: o.end - 1 }, '');
|
|
183
|
+
if (j < o.members.length - 1)
|
|
184
|
+
return splice(text, { start: m.keyStart, end: o.members[j + 1].keyStart }, '');
|
|
185
|
+
return splice(text, { start: o.members[j - 1].value.end, end: m.value.end }, '');
|
|
186
|
+
}
|
|
187
|
+
/** One edit on the text. */
|
|
188
|
+
function editOnce(text, e) {
|
|
189
|
+
const root = parseSpans(text), st = styleOf(text, root);
|
|
190
|
+
if (!e.path.length)
|
|
191
|
+
return e.value === undefined ? text : (same(JSON.parse(text.replace(/^/, '')), e.value) ? text : splice(text, root, write(e.value, st)));
|
|
192
|
+
let node = root;
|
|
193
|
+
for (let d = 0; d < e.path.length; d++) {
|
|
194
|
+
const k = e.path[d], lastStep = d === e.path.length - 1;
|
|
195
|
+
// what to put at k: the value, or (when the rest of the path is missing) objects holding it
|
|
196
|
+
const nested = () => e.path.slice(d + 1).reduceRight((v, key) => ({ [key]: v }), e.value);
|
|
197
|
+
if (node.kind === 'object') {
|
|
198
|
+
const m = node.members.findLast((x) => x.key === String(k));
|
|
199
|
+
if (lastStep || !m || (m.value.kind !== 'object' && m.value.kind !== 'array')) {
|
|
200
|
+
if (e.value === undefined)
|
|
201
|
+
return lastStep ? removeMember(text, node, String(k)) : text;
|
|
202
|
+
return setMember(text, node, String(k), lastStep ? e.value : nested(), st);
|
|
203
|
+
}
|
|
204
|
+
node = m.value;
|
|
205
|
+
}
|
|
206
|
+
else if (node.kind === 'array') {
|
|
207
|
+
const idx = typeof k === 'number' ? k : Number.NaN;
|
|
208
|
+
if (!Number.isInteger(idx) || idx < 0 || idx > node.items.length)
|
|
209
|
+
throw new Error(`JSON edit: no item ${k} in the array at ${JSON.stringify(e.path.slice(0, d))}`);
|
|
210
|
+
if (e.value === undefined)
|
|
211
|
+
throw new Error('JSON edit: removing array items is not supported');
|
|
212
|
+
const item = node.items[idx];
|
|
213
|
+
if (!item) {
|
|
214
|
+
// one past the end: appended
|
|
215
|
+
const add = write(lastStep ? e.value : nested(), st);
|
|
216
|
+
return node.items.length ? text.slice(0, node.items[node.items.length - 1].end) + st.comma + add + text.slice(node.items[node.items.length - 1].end) : splice(text, node, `[${add}]`);
|
|
217
|
+
}
|
|
218
|
+
if (lastStep || (item.kind !== 'object' && item.kind !== 'array')) {
|
|
219
|
+
const v = lastStep ? e.value : nested();
|
|
220
|
+
return same(JSON.parse(text.slice(item.start, item.end)), v) ? text : splice(text, item, write(v, st));
|
|
221
|
+
}
|
|
222
|
+
node = item;
|
|
223
|
+
}
|
|
224
|
+
else
|
|
225
|
+
throw new Error(`JSON edit: ${JSON.stringify(e.path.slice(0, d))} is not an object or an array`);
|
|
226
|
+
}
|
|
227
|
+
return text;
|
|
228
|
+
}
|
|
229
|
+
/** `value` with the edits applied, the way JSON.parse of the edited text must read. */
|
|
230
|
+
export function applyJSONEdits(value, edits) {
|
|
231
|
+
let root = structuredClone(value);
|
|
232
|
+
for (const e of edits) {
|
|
233
|
+
if (!e.path.length) {
|
|
234
|
+
if (e.value !== undefined)
|
|
235
|
+
root = structuredClone(e.value);
|
|
236
|
+
continue;
|
|
237
|
+
}
|
|
238
|
+
let o = root;
|
|
239
|
+
for (let d = 0; d < e.path.length - 1; d++) {
|
|
240
|
+
const k = e.path[d];
|
|
241
|
+
if (o[k] === null || typeof o[k] !== 'object') {
|
|
242
|
+
if (e.value === undefined) {
|
|
243
|
+
o = null;
|
|
244
|
+
break;
|
|
245
|
+
}
|
|
246
|
+
o[k] = {};
|
|
247
|
+
}
|
|
248
|
+
o = o[k];
|
|
249
|
+
}
|
|
250
|
+
if (!o)
|
|
251
|
+
continue;
|
|
252
|
+
const last = e.path[e.path.length - 1];
|
|
253
|
+
if (e.value === undefined) {
|
|
254
|
+
if (!Array.isArray(o))
|
|
255
|
+
delete o[last];
|
|
256
|
+
}
|
|
257
|
+
else
|
|
258
|
+
o[last] = structuredClone(e.value);
|
|
259
|
+
}
|
|
260
|
+
return root;
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* The JSON text with the edits made, every other character kept. Throws SyntaxError when the text is not JSON, and
|
|
264
|
+
* Error for an edit it cannot make (a key inside a number, removing an array item).
|
|
265
|
+
*/
|
|
266
|
+
export function editJSONText(text, edits) {
|
|
267
|
+
const want = applyJSONEdits(JSON.parse(text.replace(/^/, '')), edits);
|
|
268
|
+
let out = text;
|
|
269
|
+
for (const e of edits)
|
|
270
|
+
out = editOnce(out, e);
|
|
271
|
+
if (!same(JSON.parse(out.replace(/^/, '')), want))
|
|
272
|
+
throw new Error('JSON edit: the edited text does not read back as the edited value');
|
|
273
|
+
return out;
|
|
274
|
+
}
|
package/dist/viewer/outputs.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import type http from 'node:http';
|
|
2
|
-
import type {
|
|
2
|
+
import type { Session } from '../session.ts';
|
|
3
|
+
import type { GraphSource } from './graph-file.ts';
|
|
4
|
+
import type { FormatFit, HeightfieldInfo, OutputKind } from '../io/kinds.ts';
|
|
5
|
+
import type { Kind } from '../graph/outputs.ts';
|
|
6
|
+
import type { SidecarRole } from '../io/sidecars.ts';
|
|
3
7
|
export interface OutputEntry {
|
|
4
8
|
origin?: 'published' | 'saved';
|
|
5
9
|
id: string;
|
|
@@ -7,7 +11,30 @@ export interface OutputEntry {
|
|
|
7
11
|
graph?: string;
|
|
8
12
|
node?: string;
|
|
9
13
|
parent?: string;
|
|
10
|
-
|
|
14
|
+
/** how the page shows it: as a 3D model, a 2D image, or only as files to download */
|
|
15
|
+
view: 'model' | 'image' | 'file';
|
|
16
|
+
/** its kind (io/kinds.ts, the words everything shows) once cooked, "empty" for nothing; "metadata" for a sidecar or manifest without its export */
|
|
17
|
+
kind?: Kind | 'empty' | 'metadata';
|
|
18
|
+
/** the parts it holds (io/kinds.ts): what the page can show of it */
|
|
19
|
+
parts?: OutputKind;
|
|
20
|
+
/** its size in a few words ("2049 × 2049 samples, 2 m apart"), and its bounding size (x, y, z metres) */
|
|
21
|
+
about?: string;
|
|
22
|
+
size?: [number, number, number] | null;
|
|
23
|
+
/** the graph's default output (its output node) */
|
|
24
|
+
default?: boolean;
|
|
25
|
+
/** a named output's tags (its "tags" in the graph's outputs) */
|
|
26
|
+
tags?: string[];
|
|
27
|
+
/** it shows the last finished result, not the values now: its cook was stopped */
|
|
28
|
+
stale?: boolean;
|
|
29
|
+
/** the packages it uses whose working folder this session shows live: it shows their unpublished edits (its exports use the published versions) */
|
|
30
|
+
live?: string[];
|
|
31
|
+
/** a named output: the kind its graph pins ("kind" in its outputs), and what it says when it cooks to another */
|
|
32
|
+
pinned?: string;
|
|
33
|
+
warning?: string;
|
|
34
|
+
/** its heightfield (samples, spacing, layers with their ranges): the page colours the terrain by a layer */
|
|
35
|
+
heightfield?: HeightfieldInfo;
|
|
36
|
+
/** a published output: the formats that write it, best first (io/kinds.ts) */
|
|
37
|
+
formats?: FormatFit[];
|
|
11
38
|
status: 'loading' | 'ready' | 'error';
|
|
12
39
|
revision: string;
|
|
13
40
|
error?: string;
|
|
@@ -33,22 +60,39 @@ export interface OutputEntry {
|
|
|
33
60
|
size: number;
|
|
34
61
|
files: number;
|
|
35
62
|
};
|
|
63
|
+
/** saved files, the main one first; a sidecar with what it is ("heightmap sidecar: height range, …") */
|
|
36
64
|
files?: {
|
|
37
65
|
id: string;
|
|
38
66
|
name: string;
|
|
39
67
|
size: number;
|
|
68
|
+
role?: SidecarRole;
|
|
69
|
+
about?: string;
|
|
40
70
|
}[];
|
|
71
|
+
/** a saved output's Download: the one file, or a zip of them all (named so) */
|
|
72
|
+
download?: {
|
|
73
|
+
name: string;
|
|
74
|
+
zip: boolean;
|
|
75
|
+
};
|
|
41
76
|
}
|
|
42
77
|
/** Predictable ZIP bytes, retaining the bundle directory structure. */
|
|
43
78
|
export declare function outputZip(files: {
|
|
44
79
|
name: string;
|
|
45
80
|
bytes: Uint8Array;
|
|
46
81
|
}[]): Uint8Array;
|
|
82
|
+
/**
|
|
83
|
+
* The files a download of an export carries: all it writes, except the standalone record of a format whose one file
|
|
84
|
+
* carries the record itself (glb, gltf: io/files.ts SOURCE_INSIDE), so a GLB downloads as itself.
|
|
85
|
+
*/
|
|
86
|
+
export declare function downloadFiles<T extends {
|
|
87
|
+
path: string;
|
|
88
|
+
}>(format: string, files: T[], sourceManifest?: string): T[];
|
|
47
89
|
export interface OutputsOptions {
|
|
48
|
-
/**
|
|
49
|
-
|
|
90
|
+
/** the graph file a graph comes from (topotopo view): a target set on the page goes into it as a minimal edit */
|
|
91
|
+
source?: GraphSource;
|
|
92
|
+
/** the graph whose results cook first (the package's default graph, which the page shows first) */
|
|
93
|
+
first?: () => string | null | undefined;
|
|
50
94
|
}
|
|
51
|
-
export declare function createOutputs(ws:
|
|
95
|
+
export declare function createOutputs(ws: Session, changed: () => void, opts?: OutputsOptions): {
|
|
52
96
|
close(): void;
|
|
53
97
|
handle(req: http.IncomingMessage, res: http.ServerResponse, u: URL, readJSON: (r: http.IncomingMessage) => Promise<any>): Promise<boolean>;
|
|
54
98
|
};
|