topotopo 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (336) hide show
  1. package/NOTICE +10 -10
  2. package/README.md +460 -117
  3. package/dist/cli.js +323 -146
  4. package/dist/config.d.ts +48 -0
  5. package/dist/config.js +170 -0
  6. package/dist/core/bake.d.ts +14 -3
  7. package/dist/core/bake.js +153 -4
  8. package/dist/core/bevel.d.ts +3 -1
  9. package/dist/core/bevel.js +76 -3
  10. package/dist/core/decimate.d.ts +65 -0
  11. package/dist/core/decimate.js +409 -3
  12. package/dist/core/erosion.d.ts +37 -0
  13. package/dist/core/erosion.js +41 -1
  14. package/dist/core/geometry.d.ts +5 -1
  15. package/dist/core/geometry.js +203 -3
  16. package/dist/core/heightfield.d.ts +27 -4
  17. package/dist/core/heightfield.js +54 -16
  18. package/dist/core/intrinsics.d.ts +7 -0
  19. package/dist/core/intrinsics.js +94 -0
  20. package/dist/core/manifold.d.ts +12 -1
  21. package/dist/core/manifold.js +78 -6
  22. package/dist/core/materials.d.ts +7 -0
  23. package/dist/core/materials.js +45 -0
  24. package/dist/core/noise.d.ts +9 -0
  25. package/dist/core/noise.js +10 -1
  26. package/dist/core/polymerge.d.ts +21 -0
  27. package/dist/core/polymerge.js +327 -0
  28. package/dist/core/repair.d.ts +2 -0
  29. package/dist/core/repair.js +2 -0
  30. package/dist/core/report.d.ts +70 -0
  31. package/dist/core/report.js +275 -0
  32. package/dist/core/scene.js +2 -1
  33. package/dist/core/sha256.d.ts +4 -0
  34. package/dist/core/sha256.js +69 -0
  35. package/dist/core/shapes.d.ts +3 -0
  36. package/dist/core/shapes.js +34 -0
  37. package/dist/core/snippet-lib.d.ts +14 -1
  38. package/dist/core/snippet-lib.js +39 -13
  39. package/dist/core/tangents.d.ts +2 -0
  40. package/dist/core/tangents.js +5 -1
  41. package/dist/core/texnoise.d.ts +6 -1
  42. package/dist/core/texnoise.js +6 -2
  43. package/dist/core/texsdf.d.ts +131 -0
  44. package/dist/core/texsdf.js +637 -0
  45. package/dist/core/texture.d.ts +163 -9
  46. package/dist/core/texture.js +844 -20
  47. package/dist/core/topology.d.ts +10 -0
  48. package/dist/core/topology.js +168 -0
  49. package/dist/core/unwrap.d.ts +72 -0
  50. package/dist/core/unwrap.js +800 -0
  51. package/dist/core/usercode.d.ts +27 -0
  52. package/dist/core/usercode.js +87 -0
  53. package/dist/core/uv.d.ts +4 -18
  54. package/dist/core/uv.js +35 -188
  55. package/dist/core/uvislands.d.ts +62 -0
  56. package/dist/core/uvislands.js +574 -0
  57. package/dist/core/uvoverlap.d.ts +58 -0
  58. package/dist/core/uvoverlap.js +220 -0
  59. package/dist/core/uvpack.d.ts +64 -0
  60. package/dist/core/uvpack.js +628 -0
  61. package/dist/core/uvreport.d.ts +61 -0
  62. package/dist/core/uvreport.js +207 -143
  63. package/dist/core/wrangle.d.ts +6 -1
  64. package/dist/core/wrangle.js +27 -16
  65. package/dist/core/xatlas.d.ts +16 -1
  66. package/dist/core/xatlas.js +66 -62
  67. package/dist/engines.d.ts +63 -0
  68. package/dist/engines.js +180 -0
  69. package/dist/explain.d.ts +4 -3
  70. package/dist/explain.js +129 -12
  71. package/dist/graph/engine.d.ts +92 -29
  72. package/dist/graph/engine.js +298 -148
  73. package/dist/graph/expr.d.ts +6 -3
  74. package/dist/graph/expr.js +18 -8
  75. package/dist/graph/outputs.d.ts +23 -0
  76. package/dist/graph/outputs.js +41 -0
  77. package/dist/graph/packages.d.ts +72 -0
  78. package/dist/graph/packages.js +261 -0
  79. package/dist/graph/parallel.d.ts +3 -1
  80. package/dist/graph/parallel.js +4 -1
  81. package/dist/graph/params.d.ts +6 -0
  82. package/dist/graph/params.js +34 -7
  83. package/dist/graph/scope.d.ts +55 -0
  84. package/dist/graph/scope.js +14 -0
  85. package/dist/graph/types.d.ts +75 -12
  86. package/dist/graph/types.js +4 -2
  87. package/dist/graph/vars.d.ts +16 -0
  88. package/dist/graph/vars.js +80 -0
  89. package/dist/host/artifacts.d.ts +10 -1
  90. package/dist/host/artifacts.js +37 -6
  91. package/dist/host/cook.d.ts +241 -0
  92. package/dist/host/cook.js +844 -0
  93. package/dist/host/export-targets.d.ts +42 -5
  94. package/dist/host/export-targets.js +72 -13
  95. package/dist/host/godot-commands.d.ts +4 -0
  96. package/dist/host/godot-commands.js +21 -0
  97. package/dist/host/godot.d.ts +183 -0
  98. package/dist/host/godot.js +916 -0
  99. package/dist/host/node.d.ts +12 -7
  100. package/dist/host/node.js +27 -9
  101. package/dist/host/pool.js +51 -2
  102. package/dist/host/sidecars.d.ts +8 -0
  103. package/dist/host/sidecars.js +50 -0
  104. package/dist/host/types.d.ts +19 -6
  105. package/dist/host/version.d.ts +1 -0
  106. package/dist/host/version.js +3 -0
  107. package/dist/host/worker.js +5 -2
  108. package/dist/index.d.ts +2 -2
  109. package/dist/index.js +1 -1
  110. package/dist/inspect.d.ts +80 -2
  111. package/dist/inspect.js +265 -30
  112. package/dist/io/common.d.ts +25 -5
  113. package/dist/io/export.js +2 -1
  114. package/dist/io/files.d.ts +23 -4
  115. package/dist/io/files.js +60 -8
  116. package/dist/io/gltf.js +134 -47
  117. package/dist/io/heightmap.d.ts +3 -0
  118. package/dist/io/heightmap.js +1 -0
  119. package/dist/io/import.js +10 -0
  120. package/dist/io/inspect-scene.d.ts +55 -0
  121. package/dist/io/inspect-scene.js +155 -0
  122. package/dist/io/kinds.d.ts +81 -0
  123. package/dist/io/kinds.js +163 -0
  124. package/dist/io/points.d.ts +2 -1
  125. package/dist/io/points.js +3 -1
  126. package/dist/io/sidecars.d.ts +24 -0
  127. package/dist/io/sidecars.js +57 -0
  128. package/dist/io/source.d.ts +65 -0
  129. package/dist/io/source.js +112 -0
  130. package/dist/io/targets.d.ts +47 -3
  131. package/dist/io/targets.js +148 -13
  132. package/dist/io/textures.js +21 -1
  133. package/dist/io/unreal.js +5 -1
  134. package/dist/mcp/docs.d.ts +10 -1
  135. package/dist/mcp/docs.js +786 -143
  136. package/dist/mcp/inputs.d.ts +12 -5
  137. package/dist/mcp/inputs.js +50 -13
  138. package/dist/mcp/server.js +56 -27
  139. package/dist/mcp/tools.d.ts +14 -7
  140. package/dist/mcp/tools.js +196 -103
  141. package/dist/mcp/verify.d.ts +2 -2
  142. package/dist/mcp/verify.js +1 -1
  143. package/dist/mcp/workspace.d.ts +15 -0
  144. package/dist/mcp/workspace.js +349 -0
  145. package/dist/nodes/attributes.js +198 -1
  146. package/dist/nodes/bake.js +151 -47
  147. package/dist/nodes/beam.d.ts +1 -0
  148. package/dist/nodes/beam.js +201 -0
  149. package/dist/nodes/bevel.js +51 -3
  150. package/dist/nodes/cloth.js +2 -0
  151. package/dist/nodes/code.js +21 -9
  152. package/dist/nodes/curves.js +433 -93
  153. package/dist/nodes/flow.js +53 -33
  154. package/dist/nodes/generate.js +12 -38
  155. package/dist/nodes/heightfield.js +248 -77
  156. package/dist/nodes/imageops.js +16 -19
  157. package/dist/nodes/index.d.ts +1 -0
  158. package/dist/nodes/index.js +1 -0
  159. package/dist/nodes/material.js +89 -24
  160. package/dist/nodes/measure.js +43 -17
  161. package/dist/nodes/particles.js +2 -0
  162. package/dist/nodes/pcg.js +6 -5
  163. package/dist/nodes/procedural.js +4 -3
  164. package/dist/nodes/remesh.js +71 -15
  165. package/dist/nodes/scene.js +4 -2
  166. package/dist/nodes/sdf.js +10 -5
  167. package/dist/nodes/solid.js +20 -5
  168. package/dist/nodes/splines.d.ts +15 -1
  169. package/dist/nodes/splines.js +112 -105
  170. package/dist/nodes/texture.d.ts +21 -6
  171. package/dist/nodes/texture.js +1318 -185
  172. package/dist/nodes/topology.d.ts +7 -0
  173. package/dist/nodes/topology.js +133 -6
  174. package/dist/nodes/transform.js +6 -2
  175. package/dist/nodes/uv.js +192 -174
  176. package/dist/nodes/wasmcall.js +5 -1
  177. package/dist/open.d.ts +19 -0
  178. package/dist/open.js +12 -0
  179. package/dist/package.d.ts +288 -0
  180. package/dist/package.js +772 -0
  181. package/dist/packages/check.d.ts +32 -0
  182. package/dist/packages/check.js +169 -0
  183. package/dist/packages/commands.d.ts +57 -0
  184. package/dist/packages/commands.js +537 -0
  185. package/dist/packages/registry.d.ts +796 -0
  186. package/dist/packages/registry.js +2998 -0
  187. package/dist/packages/update.d.ts +124 -0
  188. package/dist/packages/update.js +476 -0
  189. package/dist/render/options.d.ts +2 -0
  190. package/dist/render/options.js +44 -5
  191. package/dist/render/preview.d.ts +15 -4
  192. package/dist/render/preview.js +6 -4
  193. package/dist/render/raster.d.ts +66 -5
  194. package/dist/render/raster.js +506 -138
  195. package/dist/render/texview.d.ts +6 -0
  196. package/dist/render/texview.js +27 -0
  197. package/dist/scan.d.ts +61 -0
  198. package/dist/scan.js +228 -0
  199. package/dist/session.d.ts +311 -0
  200. package/dist/session.js +849 -0
  201. package/dist/viewer/app/api.js +48 -6
  202. package/dist/viewer/app/cooking.js +78 -0
  203. package/dist/viewer/app/embed.js +27 -7
  204. package/dist/viewer/app/export-popover.js +118 -16
  205. package/dist/viewer/app/grid.js +5 -1
  206. package/dist/viewer/app/guides.js +122 -0
  207. package/dist/viewer/app/keymap.js +6 -3
  208. package/dist/viewer/app/layers.js +4 -4
  209. package/dist/viewer/app/main.js +185 -52
  210. package/dist/viewer/app/markers.js +60 -0
  211. package/dist/viewer/app/outliner.js +72 -27
  212. package/dist/viewer/app/output-info.js +45 -0
  213. package/dist/viewer/app/outputs.css +147 -8
  214. package/dist/viewer/app/outputs.js +168 -54
  215. package/dist/viewer/app/packages.js +614 -0
  216. package/dist/viewer/app/props.js +176 -52
  217. package/dist/viewer/app/scene.js +30 -5
  218. package/dist/viewer/app/select.js +4 -3
  219. package/dist/viewer/app/status.js +12 -15
  220. package/dist/viewer/app/style.css +65 -7
  221. package/dist/viewer/app/vars.js +47 -0
  222. package/dist/viewer/app/welcome.js +72 -0
  223. package/dist/viewer/graph-file.d.ts +62 -0
  224. package/dist/viewer/graph-file.js +175 -0
  225. package/dist/viewer/index.html +23 -10
  226. package/dist/viewer/json-edit.d.ts +13 -0
  227. package/dist/viewer/json-edit.js +274 -0
  228. package/dist/viewer/outputs.d.ts +49 -5
  229. package/dist/viewer/outputs.js +264 -56
  230. package/dist/viewer/packages.d.ts +121 -0
  231. package/dist/viewer/packages.js +584 -0
  232. package/dist/viewer/server.d.ts +14 -9
  233. package/dist/viewer/server.js +266 -28
  234. package/dist/web/app/web.css +419 -0
  235. package/dist/web/app/web.js +188 -0
  236. package/dist/{gallery → web}/bake.d.ts +4 -4
  237. package/dist/{gallery → web}/bake.js +24 -15
  238. package/dist/web/folder-page.d.ts +101 -0
  239. package/dist/web/folder-page.js +146 -0
  240. package/dist/web/folders.d.ts +280 -0
  241. package/dist/web/folders.js +970 -0
  242. package/dist/web/library.d.ts +91 -0
  243. package/dist/web/library.js +228 -0
  244. package/dist/web/markdown.d.ts +45 -0
  245. package/dist/web/markdown.js +677 -0
  246. package/dist/web/pages.d.ts +258 -0
  247. package/dist/web/pages.js +301 -0
  248. package/dist/web/server.d.ts +24 -0
  249. package/dist/web/server.js +1068 -0
  250. package/dist/workspace.d.ts +88 -118
  251. package/dist/workspace.js +358 -460
  252. package/integrations/godot/addons/topotopo/LICENSE +202 -0
  253. package/integrations/godot/addons/topotopo/README.md +57 -0
  254. package/integrations/godot/addons/topotopo/context_menu.gd +43 -0
  255. package/integrations/godot/addons/topotopo/dock.gd +266 -0
  256. package/integrations/godot/addons/topotopo/dock.tscn +72 -0
  257. package/integrations/godot/addons/topotopo/export_filter.gd +72 -0
  258. package/integrations/godot/addons/topotopo/gltf_instancing.gd +131 -0
  259. package/integrations/godot/addons/topotopo/icons/topotopo.svg +1 -0
  260. package/integrations/godot/addons/topotopo/inspector.gd +38 -0
  261. package/integrations/godot/addons/topotopo/instances_post_import.gd +111 -0
  262. package/integrations/godot/addons/topotopo/package.gd +23 -0
  263. package/integrations/godot/addons/topotopo/package_importer.gd +187 -0
  264. package/integrations/godot/addons/topotopo/plugin.cfg +7 -0
  265. package/integrations/godot/addons/topotopo/plugin.gd +970 -0
  266. package/integrations/godot/addons/topotopo/record.gd +435 -0
  267. package/integrations/godot/addons/topotopo/runner.gd +458 -0
  268. package/integrations/godot/addons/topotopo/tools/check.gd +42 -0
  269. package/integrations/godot/addons/topotopo/watcher.gd +199 -0
  270. package/kernels/pkg/README.md +2 -1
  271. package/kernels/pkg-simd/README.md +2 -1
  272. package/library/architecture/versions/1.0/architecture.topo +12 -0
  273. package/{shelf → library/architecture/versions/1.0/graphs}/arch.json +3 -3
  274. package/{shelf → library/architecture/versions/1.0/graphs}/beam_truss.json +6 -6
  275. package/{shelf → library/architecture/versions/1.0/graphs}/brick_wall.json +8 -8
  276. package/{shelf → library/architecture/versions/1.0/graphs}/door_frame.json +3 -3
  277. package/{shelf → library/architecture/versions/1.0/graphs}/hex_grid_floor.json +3 -2
  278. package/{shelf → library/architecture/versions/1.0/graphs}/house.json +8 -8
  279. package/library/architecture/versions/1.0/graphs/lineup.json +42 -0
  280. package/{shelf → library/architecture/versions/1.0/graphs}/pillar.json +3 -2
  281. package/{shelf → library/architecture/versions/1.0/graphs}/railing.json +5 -5
  282. package/{shelf → library/architecture/versions/1.0/graphs}/roof_gable.json +2 -2
  283. package/{shelf → library/architecture/versions/1.0/graphs}/roof_hip.json +2 -2
  284. package/{shelf → library/architecture/versions/1.0/graphs}/roof_skeleton.json +2 -1
  285. package/{shelf → library/architecture/versions/1.0/graphs}/scaffold.json +4 -4
  286. package/{shelf → library/architecture/versions/1.0/graphs}/spiral_stairs.json +3 -2
  287. package/{shelf → library/architecture/versions/1.0/graphs}/stairs.json +6 -6
  288. package/{shelf → library/architecture/versions/1.0/graphs}/tile_floor.json +3 -2
  289. package/{shelf → library/architecture/versions/1.0/graphs}/wall_segment.json +10 -10
  290. package/{shelf → library/architecture/versions/1.0/graphs}/window_frame.json +2 -2
  291. package/library/architecture/versions/1.0/version.json +1119 -0
  292. package/{shelf → library/nature/versions/1.0/graphs}/bush.json +2 -2
  293. package/{shelf → library/nature/versions/1.0/graphs}/cliff_block.json +4 -3
  294. package/{shelf → library/nature/versions/1.0/graphs}/forest_patch.json +5 -5
  295. package/{shelf → library/nature/versions/1.0/graphs}/grass_clumps.json +2 -2
  296. package/library/nature/versions/1.0/graphs/lineup.json +24 -0
  297. package/{shelf → library/nature/versions/1.0/graphs}/log.json +6 -6
  298. package/{shelf → library/nature/versions/1.0/graphs}/rock.json +5 -4
  299. package/{shelf → library/nature/versions/1.0/graphs}/scatter_rocks.json +5 -5
  300. package/{shelf → library/nature/versions/1.0/graphs}/tree_lowpoly.json +3 -2
  301. package/library/nature/versions/1.0/nature.topo +12 -0
  302. package/library/nature/versions/1.0/version.json +534 -0
  303. package/{shelf → library/props/versions/1.0/graphs}/barrel.json +5 -4
  304. package/{shelf → library/props/versions/1.0/graphs}/crate.json +3 -3
  305. package/library/props/versions/1.0/graphs/lineup.json +18 -0
  306. package/{shelf → library/props/versions/1.0/graphs}/pallet.json +4 -3
  307. package/{shelf → library/props/versions/1.0/graphs}/pipe_run.json +3 -3
  308. package/{shelf → library/props/versions/1.0/graphs}/sandbag_wall.json +5 -5
  309. package/library/props/versions/1.0/props.topo +12 -0
  310. package/library/props/versions/1.0/version.json +336 -0
  311. package/{shelf → library/street/versions/1.0/graphs}/bench.json +5 -5
  312. package/{shelf → library/street/versions/1.0/graphs}/bollard.json +2 -1
  313. package/{shelf → library/street/versions/1.0/graphs}/cable.json +4 -4
  314. package/{shelf → library/street/versions/1.0/graphs}/fence.json +7 -7
  315. package/{shelf → library/street/versions/1.0/graphs}/lamp_post.json +2 -2
  316. package/library/street/versions/1.0/graphs/lineup.json +22 -0
  317. package/{shelf → library/street/versions/1.0/graphs}/road_strip.json +2 -2
  318. package/{shelf → library/street/versions/1.0/graphs}/sign_post.json +1 -1
  319. package/library/street/versions/1.0/street.topo +12 -0
  320. package/library/street/versions/1.0/version.json +421 -0
  321. package/package.json +17 -8
  322. package/dist/gallery/app/gallery.css +0 -100
  323. package/dist/gallery/app/gallery.js +0 -80
  324. package/dist/gallery/cli.d.ts +0 -4
  325. package/dist/gallery/cli.js +0 -157
  326. package/dist/gallery/library.d.ts +0 -124
  327. package/dist/gallery/library.js +0 -366
  328. package/dist/gallery/pages.d.ts +0 -94
  329. package/dist/gallery/pages.js +0 -148
  330. package/dist/gallery/server.d.ts +0 -21
  331. package/dist/gallery/server.js +0 -391
  332. package/dist/graph/migrate.d.ts +0 -23
  333. package/dist/graph/migrate.js +0 -58
  334. package/dist/mcp/library.d.ts +0 -12
  335. package/dist/mcp/library.js +0 -159
  336. package/shelf/index.json +0 -190
@@ -1,366 +0,0 @@
1
- // Libraries of projects. A library is a folder listed in the user's config; a project is any
2
- // folder below it holding a project.json, and is itself a TopoTopo workspace (graphs/ assets/ inputs/ exports/) plus
3
- // attachments/ (concept art, references, source files) and .gallery/ (thumb.png, preview.glb, bake.json: derived).
4
- // ~/.topotopo/config.json (or $TOPOTOPO_CONFIG) {libraries: [{name, path}], gallery: {port, cors: [origins]}}
5
- // $TOPOTOPO_LIBRARIES more libraries: name=path entries separated by path.delimiter
6
- // Scanning reads project.json files only: it never creates folders and never cooks.
7
- import fs from 'node:fs';
8
- import os from 'node:os';
9
- import path from 'node:path';
10
- import { createHash } from 'node:crypto';
11
- import { NAME_RE } from '../workspace.js';
12
- /** Bumped when the baked files change shape (render options, GLB options), so every project bakes again. */
13
- export const BAKE_VERSION = 1;
14
- export const DEFAULT_PORT = 7340;
15
- /** a library name or project id: lower-case letters, digits, "-" and "_", starting with a letter or digit */
16
- export const ID_RE = /^[a-z0-9][a-z0-9_-]{0,63}$/;
17
- const MAX_DEPTH = 8;
18
- /** folders a scan never enters (besides dot-folders); a project's own folders are never entered either */
19
- const SKIP = new Set(['node_modules', 'graphs', 'assets', 'inputs', 'exports', 'attachments']);
20
- const PKG_VERSION = (() => {
21
- // package.json sits two levels above both src/gallery/library.ts and dist/gallery/library.js
22
- try {
23
- return String(JSON.parse(fs.readFileSync(new URL('../../package.json', import.meta.url), 'utf8')).version);
24
- }
25
- catch {
26
- return '0';
27
- }
28
- })();
29
- export const slugify = (s) => s.normalize('NFKD').replace(/[\u0300-\u036f]/g, '').toLowerCase().replace(/[^a-z0-9_-]+/g, '-').replace(/^[-_]+|[-_]+$/g, '').slice(0, 64);
30
- // ---------------------------------------------------------------------------------------------------------- config
31
- export function configFile() {
32
- return path.resolve(process.env.TOPOTOPO_CONFIG ?? path.join(os.homedir(), '.topotopo', 'config.json'));
33
- }
34
- /** The user's config with defaults filled in; libraries from $TOPOTOPO_LIBRARIES come after the file's. */
35
- export function loadConfig() {
36
- const file = configFile();
37
- let raw = {};
38
- if (fs.existsSync(file)) {
39
- try {
40
- raw = JSON.parse(fs.readFileSync(file, 'utf8'));
41
- }
42
- catch (e) {
43
- throw new Error(`${file}: ${e.message}`);
44
- }
45
- }
46
- const libraries = [];
47
- const add = (name, p, from) => {
48
- if (!ID_RE.test(name))
49
- throw new Error(`${from}: library name "${name}" must match ${ID_RE}`);
50
- if (libraries.some((l) => l.name === name))
51
- return;
52
- libraries.push({ name, path: path.resolve(path.dirname(file), p) });
53
- };
54
- for (const l of Array.isArray(raw.libraries) ? raw.libraries : []) {
55
- if (!l || typeof l.name !== 'string' || typeof l.path !== 'string')
56
- throw new Error(`${file}: each library is {"name": "...", "path": "..."}`);
57
- add(l.name, l.path, file);
58
- }
59
- for (const entry of (process.env.TOPOTOPO_LIBRARIES ?? '').split(path.delimiter).filter(Boolean)) {
60
- const i = entry.indexOf('=');
61
- // "name=path", or a bare path named after its folder ("C:\x" has no "=" before the drive colon)
62
- if (i > 0)
63
- add(entry.slice(0, i), entry.slice(i + 1), 'TOPOTOPO_LIBRARIES');
64
- else
65
- add(slugify(path.basename(path.resolve(entry))) || 'library', entry, 'TOPOTOPO_LIBRARIES');
66
- }
67
- const g = raw.gallery ?? {};
68
- return {
69
- file, libraries,
70
- gallery: {
71
- port: Number.isInteger(g.port) ? g.port : DEFAULT_PORT,
72
- cors: Array.isArray(g.cors) ? g.cors.filter((o) => typeof o === 'string') : [],
73
- },
74
- };
75
- }
76
- /** Add (or re-point) a library in the config file, keeping its other keys. */
77
- export function addLibrary(name, dir) {
78
- if (!ID_RE.test(name))
79
- throw new Error(`library name "${name}" must match ${ID_RE} (e.g. "${slugify(name) || 'game'}")`);
80
- const file = configFile();
81
- let raw = {};
82
- if (fs.existsSync(file))
83
- raw = JSON.parse(fs.readFileSync(file, 'utf8'));
84
- const libs = (Array.isArray(raw.libraries) ? raw.libraries : []).filter((l) => l?.name !== name);
85
- libs.push({ name, path: path.resolve(dir) });
86
- raw.libraries = libs;
87
- fs.mkdirSync(path.dirname(file), { recursive: true });
88
- fs.mkdirSync(path.resolve(dir), { recursive: true });
89
- fs.writeFileSync(file, JSON.stringify(raw, null, 2) + '\n');
90
- return loadConfig();
91
- }
92
- // ------------------------------------------------------------------------------------------------------- manifests
93
- const str = (v, key, def = '') => {
94
- if (v === undefined || v === null)
95
- return def;
96
- if (typeof v !== 'string')
97
- throw new Error(`"${key}" must be a string`);
98
- return v;
99
- };
100
- /** project.json checked and normalised; throws naming the problem. `fallbackId` is used when it has no id. */
101
- export function parseManifest(raw, fallbackId) {
102
- if (!raw || typeof raw !== 'object' || Array.isArray(raw))
103
- throw new Error('project.json must be an object');
104
- const id = str(raw.id, 'id', fallbackId);
105
- if (!ID_RE.test(id))
106
- throw new Error(`"id" "${id}" must match ${ID_RE}`);
107
- const graph = str(raw.graph, 'graph', 'main');
108
- if (!NAME_RE.test(graph))
109
- throw new Error(`"graph" "${graph}" must be a graph name (${NAME_RE})`);
110
- const tags = raw.tags ?? [];
111
- if (!Array.isArray(tags) || tags.some((t) => typeof t !== 'string'))
112
- throw new Error('"tags" must be a list of strings');
113
- const links = raw.links ?? [];
114
- if (!Array.isArray(links) || links.some((l) => !l || typeof l.url !== 'string'))
115
- throw new Error('"links" must be a list of {"label", "url"}');
116
- const b = raw.bake ?? {};
117
- if (typeof b !== 'object' || Array.isArray(b))
118
- throw new Error('"bake" must be {graph?, node?, frame?}');
119
- const bake = {};
120
- if (b.graph !== undefined) {
121
- bake.graph = str(b.graph, 'bake.graph');
122
- if (!NAME_RE.test(bake.graph))
123
- throw new Error(`"bake.graph" must be a graph name`);
124
- }
125
- if (b.node !== undefined)
126
- bake.node = str(b.node, 'bake.node');
127
- if (b.frame !== undefined) {
128
- if (!Number.isFinite(b.frame))
129
- throw new Error('"bake.frame" must be a number');
130
- bake.frame = b.frame;
131
- }
132
- return {
133
- id, graph, bake,
134
- title: str(raw.title, 'title', id),
135
- description: str(raw.description, 'description'),
136
- tags: [...new Set(tags.map((t) => t.trim()).filter(Boolean))],
137
- links: links.map((l) => ({ label: typeof l.label === 'string' && l.label ? l.label : l.url, url: l.url })),
138
- created: str(raw.created, 'created'),
139
- };
140
- }
141
- export const manifestFile = (dir) => path.join(dir, 'project.json');
142
- export function readManifest(dir) {
143
- const file = manifestFile(dir);
144
- let raw;
145
- try {
146
- raw = JSON.parse(fs.readFileSync(file, 'utf8'));
147
- }
148
- catch (e) {
149
- throw new Error(`${file}: ${e.message}`);
150
- }
151
- try {
152
- return parseManifest(raw, slugify(path.basename(dir)) || 'project');
153
- }
154
- catch (e) {
155
- throw new Error(`${file}: ${e.message}`);
156
- }
157
- }
158
- /** Write a manifest (atomically), keeping keys of the file this version does not know. */
159
- export function writeManifest(dir, m) {
160
- const file = manifestFile(dir);
161
- let raw = {};
162
- try {
163
- raw = JSON.parse(fs.readFileSync(file, 'utf8'));
164
- }
165
- catch { /* new or unreadable: replaced */ }
166
- writeAtomic(file, JSON.stringify({ ...raw, ...m }, null, 2) + '\n');
167
- }
168
- /** Written as a dot-file next to the target and renamed, so readers never see half a file. */
169
- export function writeAtomic(file, data) {
170
- const part = path.join(path.dirname(file), `.${path.basename(file)}.${process.pid}-${Date.now().toString(36)}.part`);
171
- try {
172
- fs.writeFileSync(part, data);
173
- fs.renameSync(part, file);
174
- }
175
- catch (e) {
176
- fs.rmSync(part, { force: true });
177
- throw e;
178
- }
179
- }
180
- // ------------------------------------------------------------------------------------------------------------ scan
181
- const mtime = (p) => fs.statSync(p, { throwIfNoEntry: false })?.mtimeMs ?? 0;
182
- const jsonFiles = (dir) => { try {
183
- return fs.readdirSync(dir).filter((f) => f.endsWith('.json')).sort();
184
- }
185
- catch {
186
- return [];
187
- } };
188
- /** Every project below a library root, sorted by path. Ids used twice: the first path keeps it, the others are problems. */
189
- export function scanLibrary(lib) {
190
- const root = path.resolve(lib.path);
191
- const out = { name: lib.name, root, projects: [], problems: [] };
192
- if (!fs.statSync(root, { throwIfNoEntry: false })?.isDirectory()) {
193
- out.problems.push(`library "${lib.name}": no folder ${root}`);
194
- return out;
195
- }
196
- const seen = new Map();
197
- const walk = (dir, rel, depth) => {
198
- if (fs.existsSync(manifestFile(dir))) {
199
- if (!rel) {
200
- out.problems.push(`${manifestFile(dir)}: the library folder itself is not a project; put projects in folders below it`);
201
- }
202
- else {
203
- try {
204
- const manifest = readManifest(dir);
205
- const prev = seen.get(manifest.id);
206
- if (prev !== undefined)
207
- out.problems.push(`${rel}: id "${manifest.id}" is already used by ${prev} (change "id" in its project.json)`);
208
- else {
209
- seen.set(manifest.id, rel);
210
- const updated = Math.round(Math.max(mtime(manifestFile(dir)), ...['graphs', 'assets'].flatMap((d) => jsonFiles(path.join(dir, d)).map((f) => mtime(path.join(dir, d, f))))));
211
- out.projects.push({ lib: lib.name, id: manifest.id, dir, rel, collection: rel.includes('/') ? rel.slice(0, rel.lastIndexOf('/')) : '', manifest, updated });
212
- }
213
- }
214
- catch (e) {
215
- out.problems.push(e.message);
216
- }
217
- return;
218
- }
219
- }
220
- if (depth >= MAX_DEPTH)
221
- return;
222
- let entries;
223
- try {
224
- entries = fs.readdirSync(dir, { withFileTypes: true });
225
- }
226
- catch {
227
- return;
228
- }
229
- for (const e of entries.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0))) {
230
- if (!e.isDirectory() || e.name.startsWith('.') || SKIP.has(e.name))
231
- continue;
232
- walk(path.join(dir, e.name), rel ? `${rel}/${e.name}` : e.name, depth + 1);
233
- }
234
- };
235
- walk(root, '', 0);
236
- return out;
237
- }
238
- export function scanAll(cfg = loadConfig()) {
239
- return cfg.libraries.map(scanLibrary);
240
- }
241
- /** The project a folder belongs to (the folder itself, or the nearest parent with a project.json), or null. */
242
- export function projectDirOf(start) {
243
- let d = path.resolve(start);
244
- for (;;) {
245
- if (fs.existsSync(manifestFile(d)))
246
- return d;
247
- const up = path.dirname(d);
248
- if (up === d)
249
- return null;
250
- d = up;
251
- }
252
- }
253
- /**
254
- * A new project at `<library root>/<rel>` ("props/lantern"): project.json, the workspace folders, attachments/, and a
255
- * .gitignore for the derived files. `graph` (a graph spec) becomes graphs/main.json. Fails when the folder holds a
256
- * project already or the id is taken in the library.
257
- */
258
- export function createProject(lib, rel, o = {}) {
259
- const parts = rel.replace(/\\/g, '/').split('/').filter(Boolean);
260
- if (!parts.length || parts.some((p) => p === '.' || p === '..' || p.startsWith('.') || SKIP.has(p) || /[<>:"|?*\u0000-\u001f]/.test(p)))
261
- throw new Error(`bad project path "${rel}": give folders below the library, e.g. "props/lantern"`);
262
- const root = path.resolve(lib.path);
263
- const dir = path.join(root, ...parts);
264
- if (fs.existsSync(manifestFile(dir)))
265
- throw new Error(`${dir} is a project already`);
266
- const id = slugify(parts[parts.length - 1]);
267
- if (!ID_RE.test(id))
268
- throw new Error(`"${parts[parts.length - 1]}" gives no usable id: use letters or digits`);
269
- const scan = scanLibrary(lib);
270
- const taken = scan.projects.find((p) => p.id === id);
271
- if (taken)
272
- throw new Error(`id "${id}" is used by ${taken.rel} in library "${lib.name}": pick another folder name`);
273
- if (scan.projects.some((p) => dir.startsWith(p.dir + path.sep)))
274
- throw new Error(`${rel} is inside another project`);
275
- for (const d of ['graphs', 'assets', 'inputs', 'exports', 'attachments'])
276
- fs.mkdirSync(path.join(dir, d), { recursive: true });
277
- const gi = path.join(dir, '.gitignore');
278
- if (!fs.existsSync(gi))
279
- fs.writeFileSync(gi, '.gallery/\n.cache/\n');
280
- const manifest = parseManifest({
281
- id, title: o.title ?? parts[parts.length - 1], description: o.description ?? '', tags: o.tags ?? [], links: o.links ?? [],
282
- graph: 'main', created: new Date().toISOString().slice(0, 10),
283
- }, id);
284
- writeManifest(dir, manifest);
285
- if (o.graph)
286
- fs.writeFileSync(path.join(dir, 'graphs', 'main.json'), JSON.stringify(o.graph, null, 2));
287
- return scanLibrary(lib).projects.find((p) => p.id === id);
288
- }
289
- const IMAGE_RE = /\.(png|jpe?g|webp|gif|avif)$/i;
290
- /** Files under a project subfolder (attachments/, exports/), recursively: posix paths, dot-files skipped. */
291
- export function listFiles(dir) {
292
- const out = [];
293
- const walk = (d, rel, depth) => {
294
- let entries;
295
- try {
296
- entries = fs.readdirSync(d, { withFileTypes: true });
297
- }
298
- catch {
299
- return;
300
- }
301
- for (const e of entries) {
302
- if (e.name.startsWith('.'))
303
- continue;
304
- const abs = path.join(d, e.name), r = rel ? `${rel}/${e.name}` : e.name;
305
- let st;
306
- try {
307
- st = fs.statSync(abs);
308
- }
309
- catch {
310
- continue;
311
- }
312
- if (st.isDirectory()) {
313
- if (depth < 16)
314
- walk(abs, r, depth + 1);
315
- }
316
- else if (st.isFile())
317
- out.push({ path: r, size: st.size, mtime: Math.round(st.mtimeMs), image: IMAGE_RE.test(e.name) });
318
- }
319
- };
320
- walk(dir, '', 0);
321
- return out.sort((a, b) => (a.path < b.path ? -1 : a.path > b.path ? 1 : 0));
322
- }
323
- export const graphNames = (dir) => jsonFiles(path.join(dir, 'graphs')).map((f) => f.slice(0, -5)).filter((n) => NAME_RE.test(n));
324
- /** A project's graph file, parsed (null when missing or unreadable). */
325
- export function readGraph(dir, name) {
326
- try {
327
- return JSON.parse(fs.readFileSync(path.join(dir, 'graphs', name + '.json'), 'utf8'));
328
- }
329
- catch {
330
- return null;
331
- }
332
- }
333
- // ------------------------------------------------------------------------------------------------------------ bake
334
- export const galleryDir = (dir) => path.join(dir, '.gallery');
335
- /**
336
- * What a bake depends on: the bake version, the package version, the manifest's graph and bake choice, every graph
337
- * and asset file's content, and each input file's path, size and time.
338
- */
339
- export function bakeKey(dir, m) {
340
- const h = createHash('sha256');
341
- h.update(`${BAKE_VERSION}|${PKG_VERSION}|${m.graph}|${JSON.stringify(m.bake)}\n`);
342
- for (const d of ['graphs', 'assets'])
343
- for (const f of jsonFiles(path.join(dir, d))) {
344
- h.update(`${d}/${f}\n`);
345
- try {
346
- h.update(fs.readFileSync(path.join(dir, d, f)));
347
- }
348
- catch { /* removed meanwhile */ }
349
- }
350
- for (const f of listFiles(path.join(dir, 'inputs')))
351
- h.update(`inputs/${f.path}|${f.size}|${f.mtime}\n`);
352
- return h.digest('hex').slice(0, 32);
353
- }
354
- export function readBakeState(dir) {
355
- try {
356
- return JSON.parse(fs.readFileSync(path.join(galleryDir(dir), 'bake.json'), 'utf8'));
357
- }
358
- catch {
359
- return null;
360
- }
361
- }
362
- /** The project needs a bake: never baked, or something it depends on changed since. */
363
- export function isStale(p) {
364
- const s = readBakeState(p.dir);
365
- return !s || s.key !== bakeKey(p.dir, p.manifest);
366
- }
@@ -1,94 +0,0 @@
1
- export interface Urls {
2
- home: string;
3
- project(lib: string, id: string): string;
4
- thumb(lib: string, id: string, version?: string | number): string;
5
- glb(lib: string, id: string, version?: string | number): string;
6
- embed(lib: string, id: string): string;
7
- file(lib: string, id: string, rel: string): string;
8
- /** null where there is no editor (a static gallery) */
9
- edit(lib: string, id: string): string | null;
10
- /** the gallery's own files (gallery.css, gallery.js) */
11
- asset(name: string): string;
12
- /** the viewer's modules (embed.js, scene.js) */
13
- app(name: string): string;
14
- /** three.js: the import map's base for build/ and examples/jsm/ */
15
- three: string;
16
- }
17
- export interface CardData {
18
- lib: string;
19
- id: string;
20
- title: string;
21
- collection: string;
22
- tags: string[];
23
- description: string;
24
- updated: number;
25
- /** 'ok' | 'failed' | 'baking' | 'new' */
26
- status: string;
27
- version: string;
28
- }
29
- export interface VarRow {
30
- name: string;
31
- value: unknown;
32
- desc?: string;
33
- min?: number;
34
- max?: number;
35
- }
36
- export interface FileRow {
37
- path: string;
38
- size: number;
39
- image: boolean;
40
- }
41
- export interface ProjectData extends CardData {
42
- rel: string;
43
- links: {
44
- label: string;
45
- url: string;
46
- }[];
47
- graph: string;
48
- graphs: {
49
- name: string;
50
- nodes: number;
51
- vars: VarRow[];
52
- }[];
53
- attachments: FileRow[];
54
- exports: FileRow[];
55
- glb: boolean;
56
- bake: {
57
- at: number;
58
- ok: boolean;
59
- error?: string;
60
- ms?: number;
61
- glb?: boolean;
62
- points?: number;
63
- prims?: number;
64
- warnings?: string[];
65
- } | null;
66
- created: string;
67
- /** absolute URLs for the copy boxes (the board pastes them) */
68
- share: {
69
- link: string;
70
- thumb: string;
71
- embed: string;
72
- };
73
- }
74
- export interface GalleryData {
75
- libraries: {
76
- name: string;
77
- cards: CardData[];
78
- }[];
79
- problems: string[];
80
- }
81
- export declare const esc: (s: unknown) => string;
82
- /** The front page: every library's projects grouped by collection, with search and tag filters. */
83
- export declare function galleryPage(d: GalleryData, u: Urls): string;
84
- /** A project's page: the 3D view, what it is, links, attachments, graphs and their vars, and the snippets for a board. */
85
- export declare function projectPage(p: ProjectData, u: Urls): string;
86
- /** The page a board embeds in an iframe: the baked preview.glb under an orbit camera, or the thumbnail. */
87
- export declare function embedPage(e: {
88
- lib: string;
89
- id: string;
90
- title: string;
91
- glb: boolean;
92
- version: string;
93
- projectUrl: string;
94
- }, u: Urls): string;
@@ -1,148 +0,0 @@
1
- // The gallery's pages as plain HTML strings: the grid of projects, a project's page and the embed page. Pure functions
2
- // of their data and a URL builder, so the local server (src/gallery/server.ts) and a static build can share them.
3
- // Styles and the small page script are files: app/gallery.css and app/gallery.js here, app/embed.js in the viewer.
4
- export const esc = (s) => String(s ?? '').replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' })[c]);
5
- const size = (n) => (n < 1024 ? `${n} B` : n < 1 << 20 ? `${(n / 1024).toFixed(0)} KB` : `${(n / 2 ** 20).toFixed(1)} MB`);
6
- const when = (ms) => (ms ? new Date(ms).toISOString().slice(0, 16).replace('T', ' ') : '');
7
- const STATUS = { ok: '', failed: 'bake failed', baking: 'baking…', new: 'not baked yet' };
8
- function shell(title, u, body, opts) {
9
- return `<!doctype html>
10
- <html lang="en">
11
- <head>
12
- <meta charset="utf-8">
13
- <meta name="viewport" content="width=device-width, initial-scale=1">
14
- <title>${esc(title)}</title>
15
- <link rel="icon" href="data:,">
16
- <link rel="stylesheet" href="${esc(u.asset('gallery.css'))}">
17
- <script type="module" src="${esc(u.asset('gallery.js'))}"></script>
18
- </head>
19
- <body data-page="${opts.page}"${opts.data ? ` data-json="${esc(JSON.stringify(opts.data))}"` : ''}>
20
- ${body}
21
- </body>
22
- </html>
23
- `;
24
- }
25
- function card(c, u) {
26
- const hay = [c.title, c.id, c.collection, c.description, ...c.tags].join(' ').toLowerCase();
27
- return `<a class="card" href="${esc(u.project(c.lib, c.id))}" data-key="${esc(`${c.lib}/${c.id}`)}" data-hay="${esc(hay)}" data-tags="${esc(c.tags.join('\n'))}" data-collection="${esc(c.collection)}">
28
- <span class="thumb"><img src="${esc(u.thumb(c.lib, c.id, c.version))}" alt="" loading="lazy" width="512" height="512"></span>
29
- <span class="meta">
30
- <span class="title">${esc(c.title)}</span>
31
- <span class="sub">${c.collection ? `${esc(c.collection)} · ` : ''}${esc(c.id)}</span>
32
- ${c.tags.length ? `<span class="tags">${c.tags.map((t) => `<span class="tag">${esc(t)}</span>`).join('')}</span>` : ''}
33
- <span class="status s-${esc(c.status)}">${esc(STATUS[c.status] ?? '')}</span>
34
- </span>
35
- </a>`;
36
- }
37
- /** The front page: every library's projects grouped by collection, with search and tag filters. */
38
- export function galleryPage(d, u) {
39
- const tags = [...new Set(d.libraries.flatMap((l) => l.cards.flatMap((c) => c.tags)))].sort();
40
- const total = d.libraries.reduce((n, l) => n + l.cards.length, 0);
41
- const libs = d.libraries.map((l) => {
42
- const groups = new Map();
43
- for (const c of l.cards) {
44
- const g = groups.get(c.collection) ?? [];
45
- g.push(c);
46
- groups.set(c.collection, g);
47
- }
48
- const sections = [...groups].sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)).map(([coll, cards]) => `
49
- <section class="collection" data-collection="${esc(coll)}">
50
- ${coll ? `<h3>${esc(coll)}</h3>` : ''}
51
- <div class="grid">${cards.map((c) => card(c, u)).join('\n')}</div>
52
- </section>`).join('');
53
- return `
54
- <section class="library" id="lib-${esc(l.name)}">
55
- <h2>${esc(l.name)} <span class="count">${l.cards.length}</span></h2>${sections || '<p class="empty">No projects yet. Make one with <code>topotopo library new ' + esc(l.name) + ' &lt;folder/name&gt;</code> or the MCP <code>library</code> tool.</p>'}
56
- </section>`;
57
- }).join('');
58
- const none = d.libraries.length ? '' : `<p class="empty">No libraries yet. Add a folder with <code>topotopo library add &lt;name&gt; &lt;folder&gt;</code>.</p>`;
59
- return shell('TopoTopo Gallery', u, `<header class="bar">
60
- <a class="brand" href="${esc(u.home)}">TopoTopo <b>Gallery</b></a>
61
- <input id="search" type="search" placeholder="Search ${total} projects" autocomplete="off" aria-label="Search projects">
62
- </header>
63
- <main class="wrap">
64
- ${d.problems.length ? `<details class="problems"><summary>${d.problems.length} problem${d.problems.length > 1 ? 's' : ''} in the libraries</summary><ul>${d.problems.map((p) => `<li>${esc(p)}</li>`).join('')}</ul></details>` : ''}
65
- ${tags.length ? `<nav class="chips" aria-label="Tags">${tags.map((t) => `<button class="chip" data-tag="${esc(t)}" aria-pressed="false">${esc(t)}</button>`).join('')}</nav>` : ''}
66
- ${none}${libs}
67
- <p class="empty" id="nomatch" hidden>Nothing matches.</p>
68
- </main>`, { page: 'gallery' });
69
- }
70
- function fileList(rows, lib, id, base, u) {
71
- return `<ul class="files">${rows.map((f) => `<li><a href="${esc(u.file(lib, id, `${base}/${f.path}`))}"${f.image ? '' : ' download'}>${esc(f.path)}</a><span>${size(f.size)}</span></li>`).join('')}</ul>`;
72
- }
73
- /** A project's page: the 3D view, what it is, links, attachments, graphs and their vars, and the snippets for a board. */
74
- export function projectPage(p, u) {
75
- const images = p.attachments.filter((f) => f.image), other = p.attachments.filter((f) => !f.image);
76
- const edit = u.edit(p.lib, p.id);
77
- const snippet = (label, value) => `<label class="copy"><span>${label}</span><input readonly value="${esc(value)}"><button type="button" data-copy>Copy</button></label>`;
78
- const b = p.bake;
79
- const bakeLine = !b ? 'Not baked yet.'
80
- : b.ok ? `Baked ${when(b.at)} in ${((b.ms ?? 0) / 1000).toFixed(1)} s · ${b.points ?? 0} points, ${b.prims ?? 0} prims${b.glb ? '' : ' · no 3D preview (too large)'}`
81
- : `Bake failed ${when(b.at)}`;
82
- const view = p.glb
83
- ? `<iframe class="view" src="${esc(u.embed(p.lib, p.id))}" title="${esc(p.title)} in 3D" allow="fullscreen"></iframe>`
84
- : `<img class="view" src="${esc(u.thumb(p.lib, p.id, p.version))}" alt="${esc(p.title)}">`;
85
- return shell(`${p.title} · TopoTopo Gallery`, u, `<header class="bar">
86
- <a class="brand" href="${esc(u.home)}">TopoTopo <b>Gallery</b></a>
87
- <nav class="crumbs"><a href="${esc(u.home)}#lib-${esc(p.lib)}">${esc(p.lib)}</a>${p.collection ? ` / <span>${esc(p.collection)}</span>` : ''} / <span>${esc(p.id)}</span></nav>
88
- </header>
89
- <main class="wrap project">
90
- <div class="stage">${view}</div>
91
- <aside class="info">
92
- <h1>${esc(p.title)}</h1>
93
- ${p.description ? `<p class="desc">${esc(p.description)}</p>` : ''}
94
- ${p.tags.length ? `<p class="tags">${p.tags.map((t) => `<span class="tag">${esc(t)}</span>`).join('')}</p>` : ''}
95
- ${p.links.length ? `<ul class="links">${p.links.map((l) => `<li><a href="${esc(l.url)}" target="_blank" rel="noopener">${esc(l.label)}</a></li>`).join('')}</ul>` : ''}
96
- <div class="actions">
97
- ${edit ? `<a class="btn primary" href="${esc(edit)}" target="_blank" rel="noopener">Open in editor</a>` : ''}
98
- <button class="btn" type="button" data-post="bake">Re-bake</button>
99
- <button class="btn" type="button" data-post="reveal">Show folder</button>
100
- </div>
101
- <p class="bake ${b && !b.ok ? 'err' : ''}" id="bake">${esc(bakeLine)}</p>
102
- ${b && !b.ok && b.error ? `<pre class="error">${esc(b.error)}</pre>` : ''}
103
- ${b?.warnings?.length ? `<details class="warn"><summary>${b.warnings.length} warning${b.warnings.length > 1 ? 's' : ''}</summary><pre>${esc(b.warnings.join('\n'))}</pre></details>` : ''}
104
- <h2>On your board</h2>
105
- ${snippet('Link', p.share.link)}
106
- ${snippet('Image', `<a href="${p.share.link}"><img src="${p.share.thumb}" alt="${esc(p.title)}" width="256"></a>`)}
107
- ${snippet('3D embed', `<iframe src="${p.share.embed}" width="640" height="480" style="border:0" allow="fullscreen" title="${esc(p.title)}"></iframe>`)}
108
- </aside>
109
- <section class="more">
110
- ${images.length ? `<h2>Attachments</h2><div class="shots">${images.map((f) => `<a href="${esc(u.file(p.lib, p.id, `attachments/${f.path}`))}" target="_blank"><img src="${esc(u.file(p.lib, p.id, `attachments/${f.path}`))}" alt="${esc(f.path)}" loading="lazy"><span>${esc(f.path)}</span></a>`).join('')}</div>` : ''}
111
- ${other.length ? `${images.length ? '' : '<h2>Attachments</h2>'}${fileList(other, p.lib, p.id, 'attachments', u)}` : ''}
112
- <h2>Graphs</h2>
113
- ${p.graphs.length ? p.graphs.map((g) => `<div class="graph"><h3>${esc(g.name)}${g.name === p.graph ? ' <span class="tag">shown</span>' : ''} <span class="count">${g.nodes} nodes</span></h3>${g.vars.length ? `<table class="vars"><tbody>${g.vars.map((v) => `<tr><th>${esc(v.name)}</th><td>${esc(JSON.stringify(v.value))}</td><td class="dim">${esc(v.desc ?? '')}${v.min !== undefined || v.max !== undefined ? ` <span class="range">${esc(v.min ?? '')}…${esc(v.max ?? '')}</span>` : ''}</td></tr>`).join('')}</tbody></table>` : ''}</div>`).join('') : '<p class="dim">No graphs yet: build one with an agent (MCP <code>library {action:"open"}</code>, then <code>build</code>) or open the editor.</p>'}
114
- ${p.exports.length ? `<h2>Exports</h2>${fileList(p.exports, p.lib, p.id, 'exports', u)}` : ''}
115
- <p class="dim small">Folder <code>${esc(p.rel)}</code> in library ${esc(p.lib)}${p.created ? ` · created ${esc(p.created)}` : ''} · updated ${esc(when(p.updated))}</p>
116
- </section>
117
- </main>`, { page: 'project', data: { lib: p.lib, id: p.id } });
118
- }
119
- /** The page a board embeds in an iframe: the baked preview.glb under an orbit camera, or the thumbnail. */
120
- export function embedPage(e, u) {
121
- const thumb = u.thumb(e.lib, e.id, e.version);
122
- return `<!doctype html>
123
- <html lang="en">
124
- <head>
125
- <meta charset="utf-8">
126
- <meta name="viewport" content="width=device-width, initial-scale=1">
127
- <title>${esc(e.title)} · TopoTopo</title>
128
- <link rel="icon" href="data:,">
129
- <style>
130
- html, body { margin: 0; height: 100%; background: #2b2d31; overflow: hidden; font: 12px/1.3 system-ui, -apple-system, "Segoe UI", sans-serif; color: #d6d9dd; }
131
- canvas { display: block; width: 100%; height: 100%; touch-action: none; }
132
- .poster { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
133
- .badge { position: absolute; left: 8px; bottom: 8px; padding: 3px 7px; border-radius: 3px; background: rgba(31, 33, 36, 0.8); color: inherit; text-decoration: none; }
134
- .badge:hover { color: #f0a030; }
135
- .note { position: absolute; right: 8px; bottom: 8px; color: #8c939b; }
136
- </style>
137
- ${e.glb ? `<script type="importmap">${JSON.stringify({ imports: { three: `${u.three}build/three.module.js`, 'three/addons/': `${u.three}examples/jsm/` } })}</script>
138
- <script type="module" src="${esc(u.app('embed.js'))}"></script>` : ''}
139
- </head>
140
- <body>
141
- <img class="poster" id="poster" src="${esc(thumb)}" alt="${esc(e.title)}">
142
- ${e.glb ? `<canvas id="gl" data-src="${esc(u.glb(e.lib, e.id, e.version))}"></canvas>` : ''}
143
- <a class="badge" href="${esc(e.projectUrl)}" target="_blank" rel="noopener">${esc(e.title)} · TopoTopo</a>
144
- <span class="note" id="note"></span>
145
- </body>
146
- </html>
147
- `;
148
- }
@@ -1,21 +0,0 @@
1
- import type { GalleryConfig } from './library.ts';
2
- import { BakeQueue } from './bake.ts';
3
- export interface GalleryOptions {
4
- /** default: the config's gallery.port (7340); 0 picks a free port (tests) */
5
- port?: number;
6
- config?: GalleryConfig;
7
- /** bake projects whose previews are missing or stale (default true) */
8
- bake?: boolean;
9
- log?: (msg: string) => void;
10
- }
11
- export interface Gallery {
12
- url: string;
13
- port: number;
14
- /** read the libraries again (the server does so on file changes and every 5 minutes) */
15
- rescan: () => void;
16
- queue: BakeQueue;
17
- close: () => void;
18
- }
19
- /** A gallery answers here already: its URL, or null. */
20
- export declare function runningGallery(port: number): Promise<string | null>;
21
- export declare function startGallery(o?: GalleryOptions): Promise<Gallery>;