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,614 @@
|
|
|
1
|
+
// The Packages tab (src/viewer/packages.ts serves it), in every package: the package's name, Find packages (a search of
|
|
2
|
+
// TopoTopo's built-in packages and the packages of the places the package looks in, which says whether it can use each), and a box per package
|
|
3
|
+
// the package uses. A box says the package's name, the version in use and its state as a badge (up to date, update
|
|
4
|
+
// available, live); its source, as a two-way switch naming both states, "Published 1.1 | Live folder", where the
|
|
5
|
+
// package has a working folder of its own (TopoTopo's built-in packages only inside TopoTopo's own repository): Published is the
|
|
6
|
+
// frozen copy, Live shows the folder's edits as they are saved, for this session; the nodes that use it (a click shows
|
|
7
|
+
// that node); its outputs, folded, as aligned rows of name, kind and tags, marked where the package uses them; and,
|
|
8
|
+
// only when a newer version exists, Update. A save in a working folder the session does not follow is offered in that
|
|
9
|
+
// package's box, in words that do not assume the person is its author; using the switch, Not now or Update clears it.
|
|
10
|
+
// Update first runs the before/after: every place the package uses the updated package cooks with the version in use (a) and
|
|
11
|
+
// the new one (b); a place shows alone in the view as an output card does, as a, as b or both overlaid (the switch
|
|
12
|
+
// over the view), and says in one line what changed, its details folded. Nothing changes until the person confirms in
|
|
13
|
+
// the box; a big version whose graphs must change asks once more and gives a line to copy for the agent. A node of a
|
|
14
|
+
// package with an update or a live folder carries a mark in the Scene tree (nodeMark); its click opens the box.
|
|
15
|
+
// The plain functions are tested in Node (test/viewer-logic.ts).
|
|
16
|
+
import { api } from './api.js';
|
|
17
|
+
import { compareLine, fmtDuration } from './cooking.js';
|
|
18
|
+
import { kindTagsLine } from './output-info.js';
|
|
19
|
+
|
|
20
|
+
const el = (tag, cls, text) => { const e = document.createElement(tag); if (cls) e.className = cls; if (text !== undefined) e.textContent = text; return e; };
|
|
21
|
+
|
|
22
|
+
/** The day of an ISO time ("2026-10-28"), '' without one. */
|
|
23
|
+
export const day = (iso) => (typeof iso === 'string' ? iso.slice(0, 10) : '');
|
|
24
|
+
|
|
25
|
+
/** The places that have a package, as a box names them: the workspace "x", library "props", TopoTopo's built-in library. */
|
|
26
|
+
export const placesText = (places) => (places ?? []).join(', ');
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* An output of the version in use in a package's box: {name, kind, tags, used}; its name without the package ("pine"),
|
|
30
|
+
* or "(default)" for the package's default output named by the package alone. kind '' when its record has none.
|
|
31
|
+
*/
|
|
32
|
+
export const outputLine = (pkg, o) => ({ name: o.type.startsWith(`${pkg}/`) ? o.type.slice(pkg.length + 1) : '(default)', kind: o.kind ?? '', tags: o.tags ?? [], used: !!o.used });
|
|
33
|
+
|
|
34
|
+
/** "a small update", "a big update", "back to an older version", "back to an older big version" */
|
|
35
|
+
export const stepText = (t) => (t.big ? (t.up ? 'a big update' : 'back to an older big version') : t.up ? 'a small update' : 'back to an older version');
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* A package's state as its box's badge says it: {kind, text, title}. kind "live" (it shows its working folder's edits
|
|
39
|
+
* this session, said even when an update exists), "error", "update" (a newer version exists) or "current".
|
|
40
|
+
*/
|
|
41
|
+
export function packageState(p) {
|
|
42
|
+
const ups = [p.small ? `${p.small} is the newest ${p.version.split('.')[0]}.x` : '', p.big ? `${p.big} is a big version, a step of its own` : ''].filter(Boolean);
|
|
43
|
+
const updates = ups.length ? `${p.package} ${p.version} is in use: ${ups.join('; ')}` : '';
|
|
44
|
+
if (p.followed) {
|
|
45
|
+
return {
|
|
46
|
+
kind: 'live', text: 'live',
|
|
47
|
+
title: `this session shows the edits of ${p.followed.dir} (${p.followed.place})${p.version ? ` instead of the published copy of ${p.version}` : ''}; every save there cooks the scene again; nothing about it is saved${updates ? `\n${updates}` : ''}`,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
if (p.error) return { kind: 'error', text: 'not found', title: p.error };
|
|
51
|
+
if (!ups.length) return { kind: 'current', text: 'up to date', title: `${p.version} is the newest version in ${placesText(p.places) || 'the places the package looks in'}` };
|
|
52
|
+
return { kind: 'update', text: 'update available', title: updates };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** A folder by its last two names ("lib/crates"): the box has little room; its title has the whole path. */
|
|
56
|
+
export const shortDir = (dir) => String(dir ?? '').replace(/[\\/]+$/, '').split(/[\\/]/).slice(-2).join('/');
|
|
57
|
+
|
|
58
|
+
/** What the source switch says under it: the published copy, or the live folder. */
|
|
59
|
+
export function sourceText(p) {
|
|
60
|
+
if (p.followed) return `showing edits from ${shortDir(p.followed.dir)} as they are saved · exports use the published version · this session only`;
|
|
61
|
+
return p.version ? `the published copy of ${p.version}: it changes only when you update` : 'not published yet: only its folder exists';
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** The offer after a save in the working folder of a package the session does not follow; it does not assume the reader made it. */
|
|
65
|
+
export const savedOffer = (pkg) => `${pkg} has new edits in its working folder that are not published yet. Show them here for this session?`;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* The mark of a node in the Scene tree: {package, kind, text, title} when a package it names (its type, or in its nested
|
|
69
|
+
* graphs) shows its live folder this session ("live", said first) or has an update ("↑ 1.3"), else null. `rows`: the
|
|
70
|
+
* packages by name.
|
|
71
|
+
*/
|
|
72
|
+
export function nodeMark(names, rows) {
|
|
73
|
+
const ps = (names ?? []).map((n) => rows.get(n)).filter(Boolean);
|
|
74
|
+
const live = ps.find((p) => p.followed);
|
|
75
|
+
if (live) return { package: live.package, kind: 'live', text: 'live', title: `${live.package}: this session shows the unpublished edits of its working folder${live.small || live.big ? `; ${live.small ?? live.big} is out` : ''} (click: its box in the Packages tab)` };
|
|
76
|
+
const late = ps.find((p) => p.small || p.big);
|
|
77
|
+
if (late) {
|
|
78
|
+
const v = late.small ?? late.big;
|
|
79
|
+
const what = [late.small ? `${late.small} is a small update` : '', late.big ? `${late.big} ${late.small ? 'a big one' : 'is a big update'}` : ''].filter(Boolean).join(', ');
|
|
80
|
+
return { package: late.package, kind: 'update', text: `↑ ${v}`, title: `${late.package} ${late.version} is in use: ${what} (click: its box in the Packages tab)` };
|
|
81
|
+
}
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** A length that changed: metres from 1 m, centimetres under it ("1.62 m", "36 cm", "under 1 cm"). */
|
|
86
|
+
export function fmtChange(m) {
|
|
87
|
+
if (!Number.isFinite(m)) return '';
|
|
88
|
+
if (m >= 1) return `${+m.toFixed(2)} m`;
|
|
89
|
+
if (m >= 0.01) return `${Math.round(m * 100)} cm`;
|
|
90
|
+
return 'under 1 cm';
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** A place's line in a before/after: {kind, text}; kind "changed", "same" or "failed". */
|
|
94
|
+
export function placeVerdict(c, t) {
|
|
95
|
+
if (!c.before.ok && !c.after.ok) return { kind: 'failed', text: `does not cook with ${t.from} nor with ${t.to}` };
|
|
96
|
+
if (!c.after.ok) return { kind: 'failed', text: `does not cook with ${t.to}` };
|
|
97
|
+
if (!c.before.ok) return { kind: 'changed', text: `cooks with ${t.to} only` };
|
|
98
|
+
if (!c.diff || c.diff.identical) return { kind: 'same', text: 'no change' };
|
|
99
|
+
const v = c.diff.verdict ?? '';
|
|
100
|
+
// the shape: by how much, in metres or centimetres; the other verdicts without their asides
|
|
101
|
+
if (/^shape changed/.test(v) && Number.isFinite(c.diff.hausdorff)) return { kind: 'changed', text: `shape changed by up to ${fmtChange(c.diff.hausdorff)}${/topology differs/.test(v) ? ', and its faces differ' : ''}` };
|
|
102
|
+
return { kind: 'changed', text: v.replace(/ \([^)]*\)/g, '') || 'changed' };
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** An update in a line: "2 places: 1 does not cook with 2.0, 1 changes, …", or that nothing changes. */
|
|
106
|
+
export function shortText(r) {
|
|
107
|
+
const n = r.places.length, failed = r.places.filter((c) => !c.after.ok).length;
|
|
108
|
+
const changed = r.places.filter((c) => c.after.ok && (!c.before.ok || (c.diff && !c.diff.identical))).length, same = n - failed - changed;
|
|
109
|
+
if (!n) return `no graph of the package uses ${r.target.package}: nothing changes`;
|
|
110
|
+
if (!changed && !failed) return `nothing changes in the ${n === 1 ? 'place' : `${n} places`} the package uses it`;
|
|
111
|
+
const parts = [failed ? `${failed} ${failed === 1 ? 'does' : 'do'} not cook with ${r.target.to}` : '', changed ? `${changed} change${changed === 1 ? 's' : ''}` : '', same ? `${same} ${same === 1 ? 'stays' : 'stay'} the same` : ''];
|
|
112
|
+
return `${n} place${n === 1 ? '' : 's'}: ${parts.filter(Boolean).join(', ')}`;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** The line a person gives their agent for a big update whose graphs must change. */
|
|
116
|
+
export const agentLine = (r, id) => `update ${r.target.package} to ${r.target.to}${id ? ` in ${id}` : ''} and fix: ${r.mustChange.join('; ')}`;
|
|
117
|
+
|
|
118
|
+
/** What a place shows first: the overlay where it changed, else b, else a; null when it cooked with neither. */
|
|
119
|
+
export const firstView = (c) => (c.views.overlay && c.diff && !c.diff.identical ? 'overlay' : c.views.b ? 'b' : c.views.a ? 'a' : null);
|
|
120
|
+
|
|
121
|
+
/** The nodes that use a package, in short: "main › row, main › one", the graph left out when there is one. */
|
|
122
|
+
export const usedByText = (uses, oneGraph) => uses.map((u) => (oneGraph ? u.node : `${u.graph} › ${u.node}`)).join(', ');
|
|
123
|
+
|
|
124
|
+
export function createPackagesPanel(ctx, host) {
|
|
125
|
+
const P = { rows: new Map(), package: null, problems: [], running: null, result: null, ended: null, loaded: false };
|
|
126
|
+
const tab = document.getElementById('tab-packages');
|
|
127
|
+
/** the view each place was last shown as (a, b, overlay), by the id it has in the view */
|
|
128
|
+
const views = new Map();
|
|
129
|
+
const placeId = (r, c) => `compare:${r.id}:${c.index}`;
|
|
130
|
+
/** The place in the view (the output panel's isolated result) is the row marked selected. */
|
|
131
|
+
const markPlaces = () => { const id = ctx.outputs?.active?.id; for (const e of host.querySelectorAll('.pkg-place')) e.classList.toggle('sel', e.dataset.id === id); };
|
|
132
|
+
ctx.on('output', markPlaces);
|
|
133
|
+
let comparing = false, applying = false;
|
|
134
|
+
/** per package: a save in its working folder offered (until used or turned down), Update done in this page, confirming a big update */
|
|
135
|
+
const offers = new Set(), updated = new Map(), confirming = new Set();
|
|
136
|
+
/** the outputs lists the person opened, Find packages' words and its result */
|
|
137
|
+
const open = new Set();
|
|
138
|
+
let query = '', found = null, searchSeq = 0;
|
|
139
|
+
|
|
140
|
+
// the progress of an update's comparison, kept across renders; the status bar's Stop stops it (one Stop)
|
|
141
|
+
const line = el('div', 'cookline none'), lineText = el('span', 'ctext');
|
|
142
|
+
line.append(el('span', 'cdot'), lineText);
|
|
143
|
+
/** The before/after line: its progress while it runs, then how it ended. */
|
|
144
|
+
P.renderLine = () => {
|
|
145
|
+
const r = P.running;
|
|
146
|
+
let l;
|
|
147
|
+
if (r) l = compareLine(r, performance.now() - r.at);
|
|
148
|
+
else if (P.ended?.error) l = { kind: 'failed', text: P.ended.error, title: P.ended.error };
|
|
149
|
+
else if (P.result) {
|
|
150
|
+
const n = P.result.places.length;
|
|
151
|
+
l = P.result.stopped
|
|
152
|
+
? { kind: 'stopped', text: `stopped after ${n} of ${P.result.comparisons} place${P.result.comparisons === 1 ? '' : 's'}`, title: 'the places not compared are not listed; Compare again compares them all (what was cooked is reused)' }
|
|
153
|
+
: { kind: 'ok', text: `compared ${n} place${n === 1 ? '' : 's'} in ${fmtDuration(P.result.ms)}`, title: 'each place cooked with both versions' };
|
|
154
|
+
} else l = { kind: 'none', text: '', title: '' };
|
|
155
|
+
line.className = `cookline ${l.kind}`;
|
|
156
|
+
if (lineText.textContent !== l.text) lineText.textContent = l.text;
|
|
157
|
+
line.title = l.title;
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
const button = (label, cls, title, action) => {
|
|
161
|
+
const b = el('button', cls, label);
|
|
162
|
+
b.type = 'button';
|
|
163
|
+
b.title = title;
|
|
164
|
+
b.onclick = () => { b.blur(); action(); };
|
|
165
|
+
return b;
|
|
166
|
+
};
|
|
167
|
+
const list = (items, cls = '') => { const u = el('ul', `pkg-list ${cls}`); for (const x of items) u.append(el('li', '', x)); return u; };
|
|
168
|
+
const fold = (summary, body, isOpen = false, ontoggle) => { const d = el('details', 'pkg-fold'); d.open = isOpen; d.append(el('summary', '', summary), body); if (ontoggle) d.ontoggle = () => ontoggle(d.open); return d; };
|
|
169
|
+
const versions = (rows) => {
|
|
170
|
+
const box = el('div', 'pkg-versions');
|
|
171
|
+
for (const v of rows) {
|
|
172
|
+
const r = el('div', 'pkg-v');
|
|
173
|
+
r.append(el('span', 'pkg-vn', v.version), el('span', 'pkg-vd', day(v.published)), el('span', 'pkg-vt', v.note));
|
|
174
|
+
if (v.big || v.marked) { const tag = el('span', 'pkg-tag', 'big'); tag.title = v.big ? `${v.version} is a big version: something a package relies on goes away or means something else` : 'its author marked it big'; r.append(tag); }
|
|
175
|
+
box.append(r);
|
|
176
|
+
}
|
|
177
|
+
return box;
|
|
178
|
+
};
|
|
179
|
+
const copyBox = (text, label = 'Copy') => {
|
|
180
|
+
const box = el('div', 'pkg-copy'), field = el('input');
|
|
181
|
+
field.readOnly = true; field.value = text; field.setAttribute('aria-label', 'line for your agent');
|
|
182
|
+
const b = button(label, '', 'copy this line, then give it to your agent', async () => {
|
|
183
|
+
field.select();
|
|
184
|
+
try { await navigator.clipboard.writeText(text); } catch { document.execCommand('copy'); }
|
|
185
|
+
b.textContent = 'Copied'; setTimeout(() => { b.textContent = label; }, 1500);
|
|
186
|
+
});
|
|
187
|
+
box.append(field, b);
|
|
188
|
+
return box;
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
// ---------------------------------------------------------------- the tab
|
|
192
|
+
const bar = el('div', 'packages-bar'), head = el('div', 'pkg-package'), search = el('input', 'pkg-search'), results = el('div', 'pkg-found');
|
|
193
|
+
search.type = 'search'; search.placeholder = 'Find packages: tree, lamp, crate…'; search.setAttribute('aria-label', 'Find packages');
|
|
194
|
+
search.title = 'search the packages of the places this package looks in and TopoTopo\'s built-in packages by name, kind and tag';
|
|
195
|
+
let searchTimer = 0;
|
|
196
|
+
search.oninput = () => { clearTimeout(searchTimer); searchTimer = setTimeout(() => runSearch(search.value), 200); };
|
|
197
|
+
search.onkeydown = (e) => { if (e.key === 'Escape') { search.value = ''; runSearch(''); search.blur(); } };
|
|
198
|
+
bar.append(head, search);
|
|
199
|
+
const cardsBox = el('div', 'pkg-cards');
|
|
200
|
+
results.hidden = true;
|
|
201
|
+
host.replaceChildren(bar, results, cardsBox);
|
|
202
|
+
|
|
203
|
+
async function runSearch(q) {
|
|
204
|
+
query = q.trim();
|
|
205
|
+
const seq = ++searchSeq;
|
|
206
|
+
if (!query) { found = null; renderFound(); return; }
|
|
207
|
+
const j = await api.searchPackages(query);
|
|
208
|
+
if (seq !== searchSeq) return;
|
|
209
|
+
found = j;
|
|
210
|
+
renderFound();
|
|
211
|
+
}
|
|
212
|
+
/** Find packages' result: each output found, its kind and tags, whether the package uses it or can. */
|
|
213
|
+
function renderFound() {
|
|
214
|
+
results.hidden = !found;
|
|
215
|
+
if (!found) { results.replaceChildren(); return; }
|
|
216
|
+
if (!found.ok && found.error) { results.replaceChildren(el('div', 'err', found.error)); return; }
|
|
217
|
+
const parts = [];
|
|
218
|
+
const libs = (found.libraries ?? []).filter((l) => l.hits.length);
|
|
219
|
+
if (!libs.length) parts.push(el('div', 'pkg-sub', `Nothing found for "${query}". TopoTopo's built-in packages hold walls, houses, roofs, stairs, rocks, trees, props and roads.`));
|
|
220
|
+
for (const l of libs) {
|
|
221
|
+
parts.push(el('div', 'pkg-libhead', l.standing === 'builtin' ? 'TopoTopo\'s built-in packages' : `${l.place ?? `library "${l.name}"`}${l.standing === 'unlisted' ? ' · the workspace does not list it' : ''}`));
|
|
222
|
+
for (const h of l.hits.slice(0, 40)) {
|
|
223
|
+
const row = el('div', 'pkg-hit');
|
|
224
|
+
const name = el('code', '', h.type), kind = h.kind ? el('span', 'badge kind', h.kind) : null, tags = el('span', 'pkg-tags line');
|
|
225
|
+
for (const t of h.tags) tags.append(el('span', 'tag', t));
|
|
226
|
+
const state = h.used ? `in use (${h.used})` : h.self ? 'this package' : l.standing === 'unlisted' ? `the workspace would list library "${l.name}"` : 'ready to use';
|
|
227
|
+
row.append(name, ...(kind ? [kind] : []), el('span', 'pkg-hitstate dim', state), tags);
|
|
228
|
+
row.title = `${h.type}${h.label ? ` (${h.label})` : ''} · ${kindTagsLine(h)}${h.description ? `\n${h.description}` : ''}\nTo use it, ask your agent: use ${h.type}`;
|
|
229
|
+
row.append(button('Copy name', 'pkg-hitcopy', `copy ${h.type}: your agent uses it as a node type`, async () => {
|
|
230
|
+
try { await navigator.clipboard.writeText(h.type); ctx.message(`copied ${h.type}: ask your agent to use it`, 'ok'); } catch { ctx.message(h.type); }
|
|
231
|
+
}));
|
|
232
|
+
parts.push(row);
|
|
233
|
+
}
|
|
234
|
+
if (l.hits.length > 40) parts.push(el('div', 'pkg-sub', `and ${l.hits.length - 40} more: add words to narrow it`));
|
|
235
|
+
}
|
|
236
|
+
results.replaceChildren(...parts);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// ---------------------------------------------------------------- the boxes
|
|
240
|
+
function render() {
|
|
241
|
+
const rows = [...P.rows.values()];
|
|
242
|
+
const late = rows.filter((p) => p.small || p.big).length, live = rows.filter((p) => p.followed).length;
|
|
243
|
+
// in every package: Find packages works without packages too
|
|
244
|
+
ctx.setTabShown?.('packages', !!P.package);
|
|
245
|
+
const count = tab.querySelector('.count');
|
|
246
|
+
count.textContent = rows.length ? String(rows.length) : '';
|
|
247
|
+
count.classList.toggle('late', late > 0);
|
|
248
|
+
count.classList.toggle('live', live > 0 && !late);
|
|
249
|
+
count.title = [late ? `${late} of the ${rows.length} packages it uses ${late === 1 ? 'has' : 'have'} an update` : `it uses ${rows.length === 1 ? '1 package' : `${rows.length} packages`}`, live ? `${live} live this session` : ''].filter(Boolean).join('; ');
|
|
250
|
+
if (P.package) {
|
|
251
|
+
head.replaceChildren(el('strong', '', P.package.title || P.package.id), el('span', 'dim', ` · ${rows.length ? `${rows.length} package${rows.length === 1 ? '' : 's'} in use` : 'no packages yet'}`));
|
|
252
|
+
head.title = `${P.package.dir}\nThe package finds packages in ${[...(P.package.places ?? []), 'TopoTopo\'s built-in library'].join(', ')}, a name from the first place that has it; the copies of the versions it uses are kept with it (packages/), or in a workspace with the workspace (topotopo-packages/).`;
|
|
253
|
+
}
|
|
254
|
+
const parts = [];
|
|
255
|
+
if (P.problems.length) parts.push(list(P.problems, 'err'));
|
|
256
|
+
if (P.package?.name) parts.push(authorBox());
|
|
257
|
+
if (!rows.length && P.package) {
|
|
258
|
+
const e = el('div', 'pkg-empty');
|
|
259
|
+
e.append(el('p', '', 'This package uses no packages yet.'), el('p', 'dim', 'Packages are ready-made parts: TopoTopo\'s built-in packages (houses, walls, trees, rocks, props, roads) and your team\'s libraries. Find one above, then ask your agent to use it, for example: "add topotopo/street/lamp_post along the road".'));
|
|
260
|
+
parts.push(e);
|
|
261
|
+
}
|
|
262
|
+
for (const p of rows) parts.push(card(p));
|
|
263
|
+
cardsBox.replaceChildren(...parts);
|
|
264
|
+
// the cook lines show a before/after while it runs (main.js), and this box's line
|
|
265
|
+
if (ctx.renderCook) ctx.renderCook(); else P.renderLine();
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
function card(p) {
|
|
269
|
+
const box = el('div', `pkg-card${p.followed ? ' live' : ''}`);
|
|
270
|
+
box.dataset.package = p.package;
|
|
271
|
+
const st = packageState(p);
|
|
272
|
+
const h = el('div', 'pkg-head'), badge = el('span', `pkg-state ${st.kind}`, st.text);
|
|
273
|
+
badge.title = st.title;
|
|
274
|
+
h.append(el('span', 'pkg-name', p.package), el('span', 'pkg-ver', p.version ?? '—'), badge);
|
|
275
|
+
box.append(h);
|
|
276
|
+
if (p.version && (p.note || p.published)) box.append(el('div', 'pkg-note', [day(p.published), p.note].filter(Boolean).join(' · ')));
|
|
277
|
+
if (p.error) box.append(el('div', 'pkg-sub err', p.error));
|
|
278
|
+
// where it comes from: the published copy, or the live folder (the switch names both)
|
|
279
|
+
if (p.canFollow) box.append(sourceSwitch(p));
|
|
280
|
+
else box.append(el('div', 'pkg-note', p.builtin ? `${p.version ? `version ${p.version}` : 'not published'} from TopoTopo's built-in library` : sourceText(p)));
|
|
281
|
+
// a save in its working folder, offered here (cleared by the switch, Not now or Update)
|
|
282
|
+
if (offers.has(p.package) && !p.followed) {
|
|
283
|
+
const o = el('div', 'pkg-offer');
|
|
284
|
+
o.append(el('div', '', savedOffer(p.package)));
|
|
285
|
+
const acts = el('div', 'pkg-actions');
|
|
286
|
+
acts.append(button('Show live edits', 'primary', `show the edits of ${p.working[0]?.dir ?? 'its working folder'} for this session; exports use the published version`, () => P.follow(p.package, true)),
|
|
287
|
+
button('Not now', '', 'keep the published copy; the switch above does it later', () => { offers.delete(p.package); render(); }));
|
|
288
|
+
o.append(acts);
|
|
289
|
+
box.append(o);
|
|
290
|
+
}
|
|
291
|
+
// where the package uses it: a click shows that node
|
|
292
|
+
if (p.usedBy?.length) {
|
|
293
|
+
const graphs = new Set(p.usedBy.map((u) => u.graph)), u = el('div', 'pkg-used');
|
|
294
|
+
u.append(el('span', 'dim', 'Used by '));
|
|
295
|
+
for (const x of p.usedBy) {
|
|
296
|
+
const b = button(graphs.size === 1 ? x.node : `${x.graph} › ${x.node}`, 'pkg-node', `show node ${x.node} of graph ${x.graph} (${x.type})`, () => ctx.showNode?.(x.graph, x.node));
|
|
297
|
+
u.append(b);
|
|
298
|
+
}
|
|
299
|
+
box.append(u);
|
|
300
|
+
} else if (p.version) box.append(el('div', 'pkg-note', 'No graph of the package uses it now.'));
|
|
301
|
+
// its outputs, folded: aligned rows of name, kind and tags, marked where the package uses them
|
|
302
|
+
if (p.outputs?.length) {
|
|
303
|
+
const used = p.outputs.filter((o) => o.used).length;
|
|
304
|
+
const grid = el('div', 'pkg-outs');
|
|
305
|
+
for (const o of p.outputs) {
|
|
306
|
+
const l = outputLine(p.package, o), tags = el('span', 'pkg-tags line');
|
|
307
|
+
for (const t of l.tags) tags.append(el('span', 'tag', t));
|
|
308
|
+
tags.title = kindTagsLine(l);
|
|
309
|
+
const name = el('span', `pkg-on${l.used ? ' used' : ''}`, l.name);
|
|
310
|
+
name.title = `${o.type}${o.label ? ` (${o.label})` : ''} · ${kindTagsLine(l)}${l.used ? ' · used by the package' : ''}`;
|
|
311
|
+
grid.append(el('span', `pkg-in${l.used ? ' on' : ''}`, l.used ? '●' : ''), name, l.kind ? el('span', 'badge kind', l.kind) : el('span'), tags);
|
|
312
|
+
}
|
|
313
|
+
box.append(fold(`${p.outputs.length} output${p.outputs.length === 1 ? '' : 's'}${used ? ` · ${used} in use` : ''}`, grid, open.has(p.package), (on) => { if (on) open.add(p.package); else open.delete(p.package); }));
|
|
314
|
+
}
|
|
315
|
+
const r = P.result?.target.package === p.package ? P.result : null;
|
|
316
|
+
const running = P.running?.package === p.package ? P.running : null;
|
|
317
|
+
const done = updated.get(p.package);
|
|
318
|
+
if (done && !r && !running) {
|
|
319
|
+
const d = el('div', `pkg-done${done.mustChange?.length ? ' err' : ''}`, `Updated ${done.from} → ${done.to}${done.mustChange?.length ? ': the graphs must change, as listed below' : ': the scene cooked again with it'}.`);
|
|
320
|
+
box.append(d);
|
|
321
|
+
}
|
|
322
|
+
// Update, only when a newer version exists: it first shows the before/after
|
|
323
|
+
if ((p.small || p.big) && !r && !running) {
|
|
324
|
+
if (p.newer.length) box.append(fold(`What is new since ${p.version}`, versions([...p.newer].reverse())));
|
|
325
|
+
const acts = el('div', 'pkg-actions');
|
|
326
|
+
const at = (v, big) => `see what changes where the package uses ${p.package} with ${v}, then confirm${big ? `; ${v} is a big version: it also says what the graphs must change` : ''}. Nothing changes before you confirm`;
|
|
327
|
+
if (p.small) acts.append(button(`Update to ${p.small}…`, 'primary', at(p.small, false), () => P.compare(p.package, p.small)));
|
|
328
|
+
if (p.big) acts.append(button(`Update to ${p.big} (big)…`, p.small ? '' : 'primary', at(p.big, true), () => P.compare(p.package, p.big)));
|
|
329
|
+
for (const b of acts.children) b.disabled = comparing || applying;
|
|
330
|
+
box.append(acts);
|
|
331
|
+
}
|
|
332
|
+
if (p.mustChange) {
|
|
333
|
+
const m = el('div', 'pkg-must');
|
|
334
|
+
m.append(el('div', 'pkg-sub', `Updated to ${p.mustChange.to}: the package's graphs must change; until they do, they report these errors:`), list(p.mustChange.items, 'err'));
|
|
335
|
+
m.append(el('div', 'pkg-sub', 'Give your agent this line:'), copyBox(agentLine({ target: { package: p.package, to: p.mustChange.to }, mustChange: p.mustChange.items }, P.package?.id)));
|
|
336
|
+
m.append(button('Dismiss', '', 'hide this list (the nodes report their errors until the graphs change)', () => P.dismiss(p.package)));
|
|
337
|
+
box.append(m);
|
|
338
|
+
}
|
|
339
|
+
if (r || running) box.append(compareBlock(p, r, running));
|
|
340
|
+
return box;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/** "Source: [Published 1.1] [Live folder]": the two states, the one in use pressed, and what it means under it. */
|
|
344
|
+
function sourceSwitch(p) {
|
|
345
|
+
const wrap = el('div', 'pkg-source'), row = el('div', 'pkg-switch'), seg = el('div', 'pkg-seg');
|
|
346
|
+
seg.setAttribute('role', 'group'); seg.setAttribute('aria-label', `Source of ${p.package}`);
|
|
347
|
+
const one = p.followed ?? p.working[0];
|
|
348
|
+
const pub = button(p.version ? `Published ${p.version}` : 'Published', p.followed ? '' : 'on', p.version ? `the published copy of ${p.version}: frozen, it changes only when you update` : `${p.package} has no published version yet`, () => { if (p.followed) P.follow(p.package, false); });
|
|
349
|
+
const live = button('Live folder', p.followed ? 'on live' : '', `show the edits of ${one?.dir ?? 'its working folder'} as they are saved, for this session; exports use the published version`, () => { if (!p.followed) P.follow(p.package, true); });
|
|
350
|
+
pub.disabled = !p.version && !p.followed;
|
|
351
|
+
pub.setAttribute('aria-pressed', String(!p.followed)); live.setAttribute('aria-pressed', String(!!p.followed));
|
|
352
|
+
seg.append(pub, live);
|
|
353
|
+
row.append(el('span', 'dim', 'Source'), seg);
|
|
354
|
+
const note = el('div', `pkg-note${p.followed ? ' live' : ''}`, sourceText(p));
|
|
355
|
+
if (one) note.title = one.dir;
|
|
356
|
+
wrap.append(row, note);
|
|
357
|
+
return wrap;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/** In a package that publishes versions: its last version, unpublished changes, and Check publish (the publish dry run). */
|
|
361
|
+
let author = null, checking = false;
|
|
362
|
+
function authorBox() {
|
|
363
|
+
const box = el('div', 'pkg-card pkg-author'), name = P.package.name;
|
|
364
|
+
const h = el('div', 'pkg-head');
|
|
365
|
+
h.append(el('span', 'pkg-name', name), el('span', 'pkg-ver', author?.last ?? '—'), el('span', 'pkg-state author', 'this package'));
|
|
366
|
+
box.append(h);
|
|
367
|
+
if (!author) { box.append(el('div', 'pkg-note', '…')); return box; }
|
|
368
|
+
box.append(el('div', 'pkg-note', author.last ? `Last published: ${author.last} · ${day(author.published)}${author.note ? ` · ${author.note}` : ''}` : 'Not published yet.'));
|
|
369
|
+
box.append(el('div', `pkg-note${author.changed ? ' warn' : ''}`, author.changed === null ? '' : author.changed ? 'There are changes since the last version: publishing would make a new one.' : 'Nothing changed since the last version.'));
|
|
370
|
+
const acts = el('div', 'pkg-actions');
|
|
371
|
+
const b = button(checking ? 'Checking…' : 'Check publish', '', 'run every publishing check and cook every output, writing nothing: says the version it would get, what changed, and what blocks or warns', () => P.checkPublish());
|
|
372
|
+
b.disabled = checking;
|
|
373
|
+
acts.append(b);
|
|
374
|
+
box.append(acts);
|
|
375
|
+
const c = author.check;
|
|
376
|
+
if (c) {
|
|
377
|
+
const lines = [];
|
|
378
|
+
lines.push(el('div', `pkg-sub ${c.ok ? 'ok' : 'err'}`, c.ok ? `It would publish ${c.version}${c.previous ? ` (after ${c.previous}${c.bigBecause?.length ? ', a big version' : ''})` : ' (the first version)'}.` : `It would not publish: ${c.blocks?.length === 1 ? 'one thing stops it' : `${c.blocks?.length ?? 0} things stop it`}.`));
|
|
379
|
+
if (c.blocks?.length) lines.push(list(c.blocks, 'err'));
|
|
380
|
+
if (c.bigBecause?.length) lines.push(fold('Why it is big', list(c.bigBecause)));
|
|
381
|
+
if (c.changes?.length) lines.push(fold(`${c.changes.length} change${c.changes.length === 1 ? '' : 's'}`, list(c.changes)));
|
|
382
|
+
if (c.warnings?.length) lines.push(fold(`${c.warnings.length} warning${c.warnings.length === 1 ? '' : 's'}`, list(c.warnings)));
|
|
383
|
+
lines.push(el('div', 'pkg-note', 'Publishing itself is your agent\'s step (or topotopo publish --note "…" in the package folder).'));
|
|
384
|
+
box.append(...lines);
|
|
385
|
+
}
|
|
386
|
+
return box;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
function compareBlock(p, r, running) {
|
|
390
|
+
const b = el('div', 'pkg-compare');
|
|
391
|
+
const t = r?.target ?? { ...running, up: true };
|
|
392
|
+
b.append(el('div', 'pkg-ctitle', `Update ${t.from} → ${t.to} · ${r ? stepText(t) : t.big ? 'a big update' : 'a small update'}`), line);
|
|
393
|
+
if (!r) return b;
|
|
394
|
+
// first the verdict, one line per place; the details folded
|
|
395
|
+
b.append(el('div', `pkg-verdict ${r.places.some((c) => !c.after.ok) ? 'err' : ''}`, shortText(r)));
|
|
396
|
+
for (const c of r.places) b.append(placeRow(r, c));
|
|
397
|
+
if (r.places.length) b.append(el('div', 'pkg-note', 'Click a place to look at it in the view: a with the version in use, b with the new one, or both overlaid.'));
|
|
398
|
+
if (r.stopped) b.append(el('div', 'pkg-sub', `Stopped after ${r.places.length} of ${r.comparisons}: the others are not compared.`));
|
|
399
|
+
const more = el('div', 'pkg-more');
|
|
400
|
+
if (t.between.length) more.append(el('div', 'pkg-sub', t.up ? `The versions after ${t.from}` : 'The versions it goes back over'), versions([...t.between].reverse()));
|
|
401
|
+
if (t.big) {
|
|
402
|
+
const step = t.up ? `${t.to} is a big version` : `Going back to ${t.to} crosses a big version`;
|
|
403
|
+
more.append(el('div', 'pkg-sub', r.interfaceBig.length ? `${step}; what goes away or means something else:` : `${step}: nothing goes away between the two; a version between was marked big by its author (its note says why)`));
|
|
404
|
+
if (r.interfaceBig.length) more.append(list(r.interfaceBig));
|
|
405
|
+
}
|
|
406
|
+
if (r.uses.length) more.append(el('div', 'pkg-sub', 'Where the package uses it:'), list(r.uses.map((u) => `${u.file} · ${u.node}: ${u.type}${u.set ? ` ${u.set}` : ''}`)));
|
|
407
|
+
if (r.problems.length) more.append(list(r.problems, 'err'));
|
|
408
|
+
b.append(fold('Details', more));
|
|
409
|
+
if (r.mustChange.length) {
|
|
410
|
+
b.append(el('div', 'pkg-sub err', `With ${t.to} the package's graphs must change; until they do, they report these errors:`), list(r.mustChange, 'err'));
|
|
411
|
+
b.append(el('div', 'pkg-sub', 'Your agent can make these changes. Give it this line:'), copyBox(agentLine(r, P.package?.id)));
|
|
412
|
+
}
|
|
413
|
+
const acts = el('div', 'pkg-actions');
|
|
414
|
+
if (confirming.has(t.package)) {
|
|
415
|
+
b.append(el('div', 'pkg-sub warn', `Update anyway? The graphs keep reporting these errors until they change.`));
|
|
416
|
+
const yes = button(`Yes, update to ${t.to}`, 'primary danger', `copy ${t.package} ${t.to} into the package and name it in its manifest; the graphs report errors until they change`, () => P.update(r));
|
|
417
|
+
yes.disabled = applying || !!P.running;
|
|
418
|
+
acts.append(yes, button('Cancel', '', 'keep the version in use', () => { confirming.delete(t.package); render(); }));
|
|
419
|
+
} else {
|
|
420
|
+
const update = button(`Update to ${t.to}${t.big ? ' (big)' : ''}`, 'primary', `copy ${t.package} ${t.to} into the package, name it in its manifest and the lock, then cook the scene again`, () => {
|
|
421
|
+
if (r.mustChange.length) { confirming.add(t.package); render(); } else P.update(r);
|
|
422
|
+
});
|
|
423
|
+
update.disabled = applying || !!P.running;
|
|
424
|
+
acts.append(update);
|
|
425
|
+
if (r.stopped) acts.append(button('Compare again', '', 'compare every place again; what was cooked is reused', () => P.compare(t.package, t.to)));
|
|
426
|
+
acts.append(button('Close', '', 'close it; nothing changes', () => P.close()));
|
|
427
|
+
}
|
|
428
|
+
// values tuned over a graph file and not saved (topotopo view) are the viewer's, not the package's
|
|
429
|
+
const tuned = ctx.graph.list.some((g) => g.overrides?.length);
|
|
430
|
+
b.append(acts, el('div', 'hint', `Nothing has changed yet: the package uses ${t.package} ${t.from} until you update.${tuned ? ' Values tuned in this viewer and not saved play no part.' : ''}`));
|
|
431
|
+
return b;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
function placeRow(r, c) {
|
|
435
|
+
const row = el('div', 'pkg-place'), v = placeVerdict(c, r.target);
|
|
436
|
+
row.tabIndex = 0;
|
|
437
|
+
row.append(el('span', 'pkg-pn', `${c.file.replace(/^graphs\//, '').replace(/\.json$/, '')} › ${c.node}`), el('span', `pkg-pv ${v.kind}`, v.text));
|
|
438
|
+
row.title = `${c.file} · ${c.node}\n${c.uses.map((u) => `${u.node}: ${u.type}${u.set ? ` ${u.set}` : ''}`).join('\n')}`;
|
|
439
|
+
row.dataset.id = placeId(r, c);
|
|
440
|
+
row.classList.toggle('sel', ctx.outputs?.active?.id === row.dataset.id);
|
|
441
|
+
row.onclick = () => P.show(r, c);
|
|
442
|
+
row.onkeydown = (e) => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); P.show(r, c); } };
|
|
443
|
+
return row;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
// ---------------------------------------------------------------- a place in the view
|
|
447
|
+
/** The a / b / overlay switch over the view while it shows a place. */
|
|
448
|
+
const viewSwitch = el('div', 'compare-switch');
|
|
449
|
+
viewSwitch.hidden = true;
|
|
450
|
+
document.getElementById('viewport').append(viewSwitch);
|
|
451
|
+
function renderSwitch(r, c, view) {
|
|
452
|
+
const t = r.target, parts = [];
|
|
453
|
+
for (const [k, label, title] of [['a', `a · ${t.from}`, `cooked with ${t.package} ${t.from}, the version in use`], ['b', `b · ${t.to}`, `cooked with ${t.package} ${t.to}`], ['overlay', 'overlay', `both: grey where they are the same, blue only with ${t.to}, orange only with ${t.from}`]]) {
|
|
454
|
+
const b = button(label, k === view ? 'on' : '', c.views[k] ? title : k === 'overlay' ? 'no overlay: it needs points cooked with both versions' : `it does not cook with ${k === 'a' ? t.from : t.to}`, () => P.show(r, c, k));
|
|
455
|
+
b.disabled = !c.views[k];
|
|
456
|
+
parts.push(b);
|
|
457
|
+
}
|
|
458
|
+
const legend = el('span', 'compare-legend');
|
|
459
|
+
if (view === 'overlay') for (const [cls, text] of [['same', 'same'], ['b', `only ${t.to}`], ['a', `only ${t.from}`]]) legend.append(el('span', `sw ${cls}`), el('span', '', text));
|
|
460
|
+
viewSwitch.replaceChildren(el('span', 'compare-what', `${c.node}: ${placeVerdict(c, t).text}`), ...parts, legend);
|
|
461
|
+
viewSwitch.hidden = false;
|
|
462
|
+
}
|
|
463
|
+
const hideSwitch = () => { viewSwitch.hidden = true; };
|
|
464
|
+
ctx.on('output', () => { if (!String(ctx.outputs?.active?.id ?? '').startsWith('compare:')) hideSwitch(); });
|
|
465
|
+
|
|
466
|
+
/** Show a place of a before/after alone in the view, as a (the version in use), b (the new one) or both overlaid. */
|
|
467
|
+
P.show = (r, c, view = views.get(placeId(r, c)) ?? firstView(c)) => {
|
|
468
|
+
if (!c.views[view]) view = firstView(c);
|
|
469
|
+
if (!view) { ctx.message(`${c.file} ${c.node} does not cook with either version: ${c.after.errors[0] ?? c.before.errors[0] ?? 'no geometry'}`, 'err'); return; }
|
|
470
|
+
const id = placeId(r, c), same = ctx.outputs.active?.id === id;
|
|
471
|
+
views.set(id, view);
|
|
472
|
+
const t = r.target, said = { a: `a, with ${t.package} ${t.from}`, b: `b, with ${t.package} ${t.to}`, overlay: `a and b overlaid` }[view];
|
|
473
|
+
// the same place keeps its camera when it switches between a, b and the overlay
|
|
474
|
+
ctx.outputs.isolate({
|
|
475
|
+
id, label: `${c.file} · ${c.node}`, view: 'model', status: 'ready', revision: view, message: `${c.node}: ${said}`, overlay: view === 'overlay',
|
|
476
|
+
load: async () => { const g = await api.compareGeo(r.id, c.index, view); if (!g.ok) throw new Error(g.error); return g.buf; },
|
|
477
|
+
details: (d) => details(d, r, c, view),
|
|
478
|
+
}, same).then(() => { if (ctx.outputs.active?.id === id) renderSwitch(r, c, view); });
|
|
479
|
+
markPlaces();
|
|
480
|
+
};
|
|
481
|
+
|
|
482
|
+
/** A place's details beside the view: its verdict, then what it uses and the whole comparison, folded. */
|
|
483
|
+
function details(d, r, c, view) {
|
|
484
|
+
const t = r.target, v = placeVerdict(c, t);
|
|
485
|
+
d.append(el('p', `pkg-pv ${v.kind}`, v.text));
|
|
486
|
+
if (!c.before.ok) d.append(el('p', 'err', `with ${t.from} it does not cook: ${c.before.errors.join('; ') || 'no geometry'}`));
|
|
487
|
+
if (!c.after.ok) d.append(el('p', 'err', `with ${t.to} it does not cook: ${c.after.errors.join('; ') || 'no geometry'}`));
|
|
488
|
+
d.append(el('p', 'dim', view === 'overlay' ? `Grey: the same · blue: only with ${t.to} · orange: only with ${t.from}` : view === 'a' ? `With ${t.package} ${t.from}, the version in use` : `With ${t.package} ${t.to}`));
|
|
489
|
+
const more = el('div');
|
|
490
|
+
more.append(el('p', 'dim', c.uses.map((u) => `${u.node}: ${u.type}${u.set ? ` ${u.set}` : ''}`).join('\n')));
|
|
491
|
+
if (c.diff) more.append(el('pre', 'summary', c.diff.text.split('\n').slice(1).join('\n')));
|
|
492
|
+
if (c.notes.length) more.append(el('p', 'dim', `(${c.notes.join('; ')})`));
|
|
493
|
+
d.append(fold('Details', more));
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
/** Back to the scene when the view shows a place of a before/after. */
|
|
497
|
+
const leavePlace = () => { hideSwitch(); if (String(ctx.outputs.active?.id ?? '').startsWith('compare:')) ctx.outputs.scene(); };
|
|
498
|
+
|
|
499
|
+
// ---------------------------------------------------------------- what the person does
|
|
500
|
+
P.compare = async (pkg, to) => {
|
|
501
|
+
if (comparing || applying) return;
|
|
502
|
+
const p = P.rows.get(pkg);
|
|
503
|
+
leavePlace();
|
|
504
|
+
comparing = true;
|
|
505
|
+
offers.delete(pkg); updated.delete(pkg); confirming.delete(pkg);
|
|
506
|
+
P.result = null; P.ended = null;
|
|
507
|
+
P.running = { id: '', package: pkg, from: p?.version ?? '', to, big: to === p?.big, done: 0, total: 0, what: 'starting', elapsed: 0, running: true, stopping: false, at: performance.now() };
|
|
508
|
+
render();
|
|
509
|
+
const j = await api.compare(pkg, to);
|
|
510
|
+
comparing = false;
|
|
511
|
+
// a newer before/after took its place: that one answers
|
|
512
|
+
if (j.status === 409) return;
|
|
513
|
+
if (P.running?.package === pkg) P.running = null;
|
|
514
|
+
if (!j.ok) { P.ended = { package: pkg, error: j.error }; ctx.message(j.error, 'err'); render(); return; }
|
|
515
|
+
P.result = j;
|
|
516
|
+
render();
|
|
517
|
+
P.reveal(pkg, false);
|
|
518
|
+
};
|
|
519
|
+
P.stop = async () => {
|
|
520
|
+
if (P.running) { P.running.stopping = true; P.renderLine(); }
|
|
521
|
+
const j = await api.stopCompare();
|
|
522
|
+
if (!j.ok) ctx.message(j.error, 'err');
|
|
523
|
+
};
|
|
524
|
+
/** Close the before/after: the view goes back to the scene, its messages go. */
|
|
525
|
+
P.close = () => { leavePlace(); P.result = null; P.ended = null; confirming.clear(); ctx.message(''); render(); };
|
|
526
|
+
P.update = async (r) => {
|
|
527
|
+
const t = r.target;
|
|
528
|
+
applying = true;
|
|
529
|
+
render();
|
|
530
|
+
const j = await api.updatePackage(t.package, t.from, t.to);
|
|
531
|
+
applying = false;
|
|
532
|
+
confirming.delete(t.package);
|
|
533
|
+
if (!j.ok) { ctx.message(j.error, 'err'); render(); return; }
|
|
534
|
+
// done with the before/after: the scene cooks again with the new version; the box says so
|
|
535
|
+
leavePlace();
|
|
536
|
+
P.result = null; P.ended = null;
|
|
537
|
+
offers.delete(t.package);
|
|
538
|
+
updated.set(t.package, { from: j.from, to: j.to, mustChange: j.mustChange });
|
|
539
|
+
ctx.message('');
|
|
540
|
+
await P.refresh();
|
|
541
|
+
};
|
|
542
|
+
P.follow = async (pkg, on) => {
|
|
543
|
+
offers.delete(pkg);
|
|
544
|
+
const j = await api.followPackage(pkg, on);
|
|
545
|
+
if (!j.ok) ctx.message(j.error, 'err');
|
|
546
|
+
await P.refresh();
|
|
547
|
+
};
|
|
548
|
+
P.dismiss = async (pkg) => {
|
|
549
|
+
const j = await api.dismissPackage(pkg);
|
|
550
|
+
if (!j.ok) ctx.message(j.error, 'err');
|
|
551
|
+
updated.delete(pkg);
|
|
552
|
+
await P.refresh();
|
|
553
|
+
};
|
|
554
|
+
P.checkPublish = async () => {
|
|
555
|
+
if (checking) return;
|
|
556
|
+
checking = true; render();
|
|
557
|
+
const j = await api.checkPublish();
|
|
558
|
+
checking = false;
|
|
559
|
+
if (!j.ok && j.error) ctx.message(j.error, 'err');
|
|
560
|
+
else author = { ...author, check: j.check };
|
|
561
|
+
render();
|
|
562
|
+
};
|
|
563
|
+
|
|
564
|
+
// ---------------------------------------------------------------- the server's news
|
|
565
|
+
P.refresh = ctx.coalesce(async () => {
|
|
566
|
+
const s = await api.packages();
|
|
567
|
+
if (!s) return;
|
|
568
|
+
P.loaded = true;
|
|
569
|
+
P.package = s.package;
|
|
570
|
+
P.problems = s.problems ?? [];
|
|
571
|
+
P.rows = new Map((s.packages ?? []).map((p) => [p.package, p]));
|
|
572
|
+
for (const p of P.rows.values()) if (p.followed) offers.delete(p.package);
|
|
573
|
+
// a before/after another page started (or one running before a reload) shows its progress here too
|
|
574
|
+
if (s.running && !P.running) P.running = { ...s.running, at: performance.now() };
|
|
575
|
+
if (s.package?.package) {
|
|
576
|
+
const a = await api.authorState();
|
|
577
|
+
if (a.ok) author = { ...a, check: author?.check ?? null };
|
|
578
|
+
} else author = null;
|
|
579
|
+
render();
|
|
580
|
+
ctx.emit('packages');
|
|
581
|
+
});
|
|
582
|
+
/** {packages: n, saved?}: what the tab shows changed; `saved`: a working folder the session does not follow was saved. */
|
|
583
|
+
P.onEvent = async (ev) => {
|
|
584
|
+
if (ev.saved) { const p = P.rows.get(ev.saved); if (p?.canFollow && !p.followed) offers.add(ev.saved); }
|
|
585
|
+
await P.refresh();
|
|
586
|
+
};
|
|
587
|
+
/** {compare: progress}: a before/after moved on, or ended. */
|
|
588
|
+
P.onCompare = async (pr) => {
|
|
589
|
+
const start = !P.running || (P.running.id && P.running.id !== pr.id);
|
|
590
|
+
if (pr.running) { P.running = { ...pr, at: performance.now() }; if (start) render(); else P.renderLine(); return; }
|
|
591
|
+
// this page's own before/after ends with its answer (P.compare)
|
|
592
|
+
if (comparing) return;
|
|
593
|
+
if (P.running?.id === pr.id) P.running = null;
|
|
594
|
+
// one another page started: its result is read here
|
|
595
|
+
if (!pr.superseded && !pr.error && P.result?.id !== pr.id) {
|
|
596
|
+
const j = await api.lastCompare();
|
|
597
|
+
if (j.compare?.id === pr.id) P.result = j.compare;
|
|
598
|
+
}
|
|
599
|
+
render();
|
|
600
|
+
};
|
|
601
|
+
|
|
602
|
+
/** The Scene tree's mark of a node (/api/graphs names the packages each node names). */
|
|
603
|
+
P.nodeMark = (n) => nodeMark(n.packages, P.rows);
|
|
604
|
+
/** The Packages tab, at a package's box, highlighted (a click on a node's mark). */
|
|
605
|
+
P.reveal = (pkg, flash = true) => {
|
|
606
|
+
ctx.showTab?.('packages');
|
|
607
|
+
const box = host.querySelector(`.pkg-card[data-package="${CSS.escape(pkg)}"]`);
|
|
608
|
+
if (!box) return;
|
|
609
|
+
box.scrollIntoView({ block: 'nearest' });
|
|
610
|
+
if (flash) { box.classList.remove('flash'); void box.offsetWidth; box.classList.add('flash'); setTimeout(() => box.classList.remove('flash'), 1600); }
|
|
611
|
+
};
|
|
612
|
+
render();
|
|
613
|
+
return P;
|
|
614
|
+
}
|