topotopo 0.1.0 → 0.3.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/README.md +61 -12
- package/dist/cli.js +161 -23
- package/dist/graph/engine.js +18 -1
- package/dist/graph/params.d.ts +7 -1
- package/dist/graph/params.js +21 -8
- package/dist/graph/types.d.ts +28 -2
- package/dist/host/artifacts.d.ts +21 -0
- package/dist/host/artifacts.js +58 -0
- package/dist/host/export-targets.d.ts +33 -0
- package/dist/host/export-targets.js +84 -0
- package/dist/host/export_scene.py +200 -0
- package/dist/host/node.d.ts +8 -0
- package/dist/host/node.js +114 -0
- package/dist/host/types.d.ts +5 -0
- package/dist/inspect.js +5 -2
- package/dist/io/common.d.ts +6 -0
- package/dist/io/export.js +7 -4
- package/dist/io/gltf.d.ts +1 -1
- package/dist/io/gltf.js +167 -32
- package/dist/io/heightmap.d.ts +1 -1
- package/dist/io/import.d.ts +2 -2
- package/dist/io/import.js +10 -3
- package/dist/io/png-decode.d.ts +5 -2
- package/dist/io/png-decode.js +10 -3
- package/dist/io/targets.d.ts +31 -0
- package/dist/io/targets.js +75 -0
- package/dist/io/textures.d.ts +31 -2
- package/dist/io/textures.js +66 -18
- package/dist/io/unreal.js +22 -5
- package/dist/mcp/docs.d.ts +9 -2
- package/dist/mcp/docs.js +126 -2
- package/dist/mcp/inputs.d.ts +28 -0
- package/dist/mcp/inputs.js +377 -0
- package/dist/mcp/server.js +4 -1
- package/dist/mcp/tools.d.ts +1 -1
- package/dist/mcp/tools.js +118 -51
- package/dist/nodes/code.js +34 -6
- package/dist/nodes/copy.js +14 -4
- package/dist/nodes/flow.js +136 -35
- package/dist/nodes/heightfield.js +67 -11
- package/dist/nodes/texture.d.ts +1 -1
- package/dist/nodes/texture.js +61 -5
- package/dist/render/options.js +2 -1
- package/dist/render/raster.d.ts +2 -0
- package/dist/render/raster.js +3 -3
- package/dist/render/texview.d.ts +9 -1
- package/dist/render/texview.js +43 -2
- package/dist/viewer/app/api.js +64 -0
- package/dist/viewer/app/camera.js +250 -0
- package/dist/viewer/app/export-popover.js +68 -0
- package/dist/viewer/app/grid.js +217 -0
- package/dist/viewer/app/guides.js +402 -0
- package/dist/viewer/app/image-view.js +114 -0
- package/dist/viewer/app/keymap.js +199 -0
- package/dist/viewer/app/layers.js +244 -0
- package/dist/viewer/app/main.js +646 -0
- package/dist/viewer/app/markers.js +206 -0
- package/dist/viewer/app/mesh.js +172 -0
- package/dist/viewer/app/outliner.js +225 -0
- package/dist/viewer/app/outputs.css +73 -0
- package/dist/viewer/app/outputs.js +240 -0
- package/dist/viewer/app/props.js +432 -0
- package/dist/viewer/app/scene.js +529 -0
- package/dist/viewer/app/select.js +153 -0
- package/dist/viewer/app/selection.js +79 -0
- package/dist/viewer/app/status.js +20 -0
- package/dist/viewer/app/style.css +173 -0
- package/dist/viewer/app/undo.js +49 -0
- package/dist/viewer/app/units.js +51 -0
- package/dist/viewer/app/vars.js +64 -0
- package/dist/viewer/index.html +67 -184
- package/dist/viewer/outputs.d.ts +54 -0
- package/dist/viewer/outputs.js +436 -0
- package/dist/viewer/server.d.ts +47 -1
- package/dist/viewer/server.js +480 -17
- package/dist/workspace.d.ts +60 -4
- package/dist/workspace.js +131 -5
- package/package.json +9 -3
- package/shelf/brick_wall.json +1 -1
- package/shelf/wall_segment.json +2 -2
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/* the left panel's tabs: Scene, Outputs, Inputs */
|
|
2
|
+
.phead.tabs { padding: 0 6px 0 0; gap: 0; align-items: stretch; }
|
|
3
|
+
.phead.tabs [role=tab] { padding: 6px 10px 5px; border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; color: var(--dim); font: inherit; letter-spacing: .06em; text-transform: uppercase; }
|
|
4
|
+
.phead.tabs [role=tab]:hover { color: var(--text); }
|
|
5
|
+
.phead.tabs [role=tab].on { color: var(--text); border-bottom-color: var(--sel); }
|
|
6
|
+
.phead.tabs [role=tab]:focus-visible { outline: 1px solid var(--sel); outline-offset: -1px; }
|
|
7
|
+
.phead.tabs [role=tab] .count { margin-left: 3px; color: var(--faint); letter-spacing: 0; }
|
|
8
|
+
#thumb-size { margin: auto 0 auto auto; font-size: 10px; letter-spacing: 0; min-width: 48px; }
|
|
9
|
+
.tabpane { flex: 1; }
|
|
10
|
+
.tabpane[hidden] { display: none; }
|
|
11
|
+
/* the bars at the top of the Outputs and Inputs tabs stay in view while the cards scroll */
|
|
12
|
+
.outputs-bar, .inputs-bar { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; gap: 8px; padding: 8px; background: var(--panel); border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
|
|
13
|
+
.outputs-bar .primary, .inputs-bar .primary { flex: none; padding: 4px 12px; }
|
|
14
|
+
.outputs-bar .dim, .inputs-bar .dim { font-size: 11px; }
|
|
15
|
+
.primary { border-color: var(--sel); }
|
|
16
|
+
button:disabled { opacity: .45; cursor: default; }
|
|
17
|
+
/* input cards */
|
|
18
|
+
.input-card.row { height: auto; min-height: calc(var(--thumb-size) + 12px); padding: 6px; gap: 8px; }
|
|
19
|
+
.input-thumb, .file-icon { width: var(--thumb-size); height: var(--thumb-size); flex: none; object-fit: contain; background: var(--view); }
|
|
20
|
+
.file-icon { display: inline-flex; align-items: center; justify-content: center; color: var(--dim); font-size: 10px; overflow: hidden; }
|
|
21
|
+
.input-body { min-width: 0; flex: 1; }
|
|
22
|
+
.input-body .nm { display: block; white-space: normal; overflow-wrap: anywhere; }
|
|
23
|
+
.input-controls { display: flex; gap: 3px; align-items: center; margin-top: 6px; flex-wrap: wrap; }
|
|
24
|
+
.input-controls .mt { margin-left: auto; }
|
|
25
|
+
/* output cards: thumbnail, name, what it is, where it exports, and its Export button */
|
|
26
|
+
.output-group { padding: 12px 10px 5px; color: var(--dim); font-size: 11px; overflow-wrap: anywhere; }
|
|
27
|
+
.output-card { display: flex; align-items: center; width: calc(100% - 8px); margin: 3px 4px; padding: 5px; gap: 8px; text-align: left; background: var(--bg); border: 1px solid transparent; min-height: calc(var(--thumb-size) + 12px); cursor: pointer; }
|
|
28
|
+
.output-card:hover { background: var(--hover-bg); }
|
|
29
|
+
.output-card:focus-visible { outline: 1px solid var(--sel); }
|
|
30
|
+
.output-card.selected { border-color: var(--sel); background: var(--sel-bg); }
|
|
31
|
+
.output-card.child { margin-left: 12px; width: calc(100% - 16px); }
|
|
32
|
+
.output-card img { width: var(--thumb-size); height: var(--thumb-size); object-fit: contain; background: var(--view); flex: none; }
|
|
33
|
+
.output-card .output-body { display: flex; flex: 1; flex-direction: column; min-width: 0; justify-content: center; gap: 3px; }
|
|
34
|
+
.output-card .output-label { overflow-wrap: anywhere; }
|
|
35
|
+
.output-card small { overflow: hidden; text-overflow: ellipsis; max-height: 32px; }
|
|
36
|
+
.output-export { flex: none; padding: 3px 10px; }
|
|
37
|
+
.output-target { align-self: flex-start; max-width: 100%; padding: 0; border: 0; background: none; color: var(--dim); font-size: 11px; text-align: left; overflow-wrap: anywhere; cursor: pointer; }
|
|
38
|
+
.output-target:hover { color: var(--text); text-decoration: underline; }
|
|
39
|
+
.output-target.unset { font-style: italic; color: var(--faint); }
|
|
40
|
+
.saved-outputs { border-top: 1px solid var(--line); margin-top: 8px; }
|
|
41
|
+
.saved-outputs > summary { padding: 8px 10px; color: var(--dim); cursor: pointer; }
|
|
42
|
+
.output-menu { position: fixed; z-index: 30; min-width: 190px; padding: 4px; background: var(--panel); border: 1px solid var(--line); box-shadow: 0 6px 20px #0007; border-radius: 4px; }
|
|
43
|
+
.output-menu button { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 7px 12px; }
|
|
44
|
+
.output-menu button:hover, .output-menu button:focus { background: var(--hover-bg); outline: none; }
|
|
45
|
+
/* the export target popover: a format and a file inside exports/ */
|
|
46
|
+
.export-popover { position: fixed; z-index: 40; display: flex; flex-direction: column; gap: 8px; width: 330px; max-width: calc(100vw - 12px); padding: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 4px; box-shadow: 0 6px 20px #0008; }
|
|
47
|
+
.export-title { font-weight: 600; overflow-wrap: anywhere; }
|
|
48
|
+
.export-field { display: grid; grid-template-columns: 48px minmax(0, 1fr); align-items: center; gap: 8px; }
|
|
49
|
+
.export-field select, .export-field input { width: 100%; min-width: 0; padding: 4px 6px; }
|
|
50
|
+
.export-where { font: var(--mono); font-size: 11px; overflow-wrap: anywhere; }
|
|
51
|
+
.export-error { color: var(--err); font-size: 11px; }
|
|
52
|
+
.export-error:empty { display: none; }
|
|
53
|
+
.export-actions { display: flex; justify-content: flex-end; gap: 8px; }
|
|
54
|
+
.export-actions button { padding: 4px 12px; }
|
|
55
|
+
.dim { color: var(--dim); }
|
|
56
|
+
.err { color: var(--err); }
|
|
57
|
+
.empty { padding: 12px; color: var(--dim); }
|
|
58
|
+
#output-details { padding: 12px; border-bottom: 1px solid var(--line); max-height: 36%; overflow: auto; overflow-wrap: anywhere; }
|
|
59
|
+
#output-details p { white-space: pre-wrap; max-height: 120px; overflow: auto; }
|
|
60
|
+
#output-details a { display: block; margin: 6px 0; color: #9dc9ee; }
|
|
61
|
+
#top { gap: 7px; }
|
|
62
|
+
#top .primary { border-color: var(--sel); color: var(--text); }
|
|
63
|
+
#image-view { position: absolute; inset: 0; display: flex; flex-direction: column; z-index: 4; background: var(--view); }
|
|
64
|
+
.image-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 7px; background: var(--panel); border-bottom: 1px solid var(--line); }
|
|
65
|
+
.image-tools label { white-space: nowrap; }
|
|
66
|
+
.image-dim { color: var(--dim); font: var(--mono); }
|
|
67
|
+
.image-stage { position: relative; flex: 1; min-height: 0; background: #303236; overflow: hidden; }
|
|
68
|
+
.image-stage.checker { background-color: #35383c; background-image: conic-gradient(#45484c 25%, transparent 0 50%, #45484c 0 75%, transparent 0); background-size: 24px 24px; }
|
|
69
|
+
.image-stage canvas { width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; }
|
|
70
|
+
.image-stage canvas:active { cursor: grabbing; }
|
|
71
|
+
.image-error { position: absolute; left: 10px; bottom: 10px; padding: 8px; background: var(--bg); color: var(--err); }
|
|
72
|
+
.image-mode > #gl, .image-mode > #views, .image-mode > #boxsel { visibility: hidden; pointer-events: none; }
|
|
73
|
+
@media (max-width: 1100px) { #top .readout { display: none; } #top { gap: 4px; } #top .tb select { max-width: 120px; } }
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
// The Outputs tab: each graph's published outputs as cards (click one to see it alone, its textures below it), one
|
|
2
|
+
// Export button each, Export all for every output with a target, and the files saved in exports/. A first Export
|
|
3
|
+
// asks for a format and file (export-popover.js) and stores that target in the graph; later clicks just write it.
|
|
4
|
+
import { createImageView } from './image-view.js';
|
|
5
|
+
import { fmtBytes } from './units.js';
|
|
6
|
+
import { exportPopover, defaultPath } from './export-popover.js';
|
|
7
|
+
import { inputImageURL } from './layers.js';
|
|
8
|
+
|
|
9
|
+
const url = (route, item, more = {}) => `/api/output/${route}?` + new URLSearchParams({ id: item.id, rev: item.revision, ...more });
|
|
10
|
+
const text = (tag, value, cls) => { const e = document.createElement(tag); e.textContent = value; if (cls) e.className = cls; return e; };
|
|
11
|
+
const post = async (route, body) => {
|
|
12
|
+
const r = await fetch('/api/output/' + route, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(body) });
|
|
13
|
+
const j = await r.json().catch(() => ({ error: `${route} failed (${r.status})` }));
|
|
14
|
+
if (!r.ok || !j.ok) throw new Error(j.error ?? `${route} failed (${r.status})`);
|
|
15
|
+
return j;
|
|
16
|
+
};
|
|
17
|
+
/** "just now", "5 min ago", "3 h ago", else the date */
|
|
18
|
+
export function ago(ms, now = Date.now()) {
|
|
19
|
+
const s = Math.max(0, (now - ms) / 1000);
|
|
20
|
+
if (s < 10) return 'just now';
|
|
21
|
+
if (s < 60) return `${Math.round(s)} s ago`;
|
|
22
|
+
if (s < 3600) return `${Math.round(s / 60)} min ago`;
|
|
23
|
+
if (s < 86400) return `${Math.round(s / 3600)} h ago`;
|
|
24
|
+
return new Date(ms).toLocaleDateString();
|
|
25
|
+
}
|
|
26
|
+
/** A target as the graph stores it: the format alone when the path is the default, else {format, path}. */
|
|
27
|
+
export function targetSpec(item, choice, formats) {
|
|
28
|
+
const stem = item.output ?? item.graph ?? 'output';
|
|
29
|
+
const keep = item.target && item.target.format === choice.format ? item.target.options ?? {} : {};
|
|
30
|
+
const custom = choice.path !== defaultPath(stem, choice.format, formats);
|
|
31
|
+
return !custom && !Object.keys(keep).length ? choice.format : { format: choice.format, ...(custom ? { path: choice.path } : {}), ...keep };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function createOutputPanel(ctx) {
|
|
35
|
+
const host = document.getElementById('outputs'), details = document.getElementById('output-details');
|
|
36
|
+
const image = createImageView(document.getElementById('viewport'), ctx.message);
|
|
37
|
+
let list = [], formats = [], selected = null, directory = '', sequence = 0, lastList = '', initial = true, refreshing = null, refreshAgain = false, busy = false;
|
|
38
|
+
const P = { active: null };
|
|
39
|
+
const bar = document.createElement('div'), all = text('button', 'Export all', 'primary'), barNote = text('span', '', 'dim');
|
|
40
|
+
bar.className = 'outputs-bar'; bar.append(all, barNote);
|
|
41
|
+
const live = document.createElement('div'), saved = document.createElement('details'), savedRows = document.createElement('div');
|
|
42
|
+
saved.className = 'saved-outputs'; saved.open = ctx.store.get('outputs.savedOpen', false);
|
|
43
|
+
saved.append(text('summary', 'Saved files'), savedRows); saved.ontoggle = () => ctx.store.set('outputs.savedOpen', saved.open);
|
|
44
|
+
const empty = text('div', 'Nothing published yet: a graph\'s output shows here once it cooks.', 'empty');
|
|
45
|
+
const cards = new Map(), groups = new Map(); let input = null;
|
|
46
|
+
host.append(bar, empty, live, saved);
|
|
47
|
+
Object.defineProperty(P, 'count', { get: () => list.filter((v) => v.exportable).length });
|
|
48
|
+
|
|
49
|
+
function showDetails(item) {
|
|
50
|
+
details.replaceChildren(); details.hidden = !item;
|
|
51
|
+
if (!item) return;
|
|
52
|
+
details.append(text('strong', item.label), text('p', item.error ?? item.summary ?? `${item.kind}${item.width ? ` · ${item.width} × ${item.height}` : ''}`, item.error ? 'err' : 'dim'));
|
|
53
|
+
if (item.exportable) details.append(text('p', item.target ? `exports to exports/${item.target.path} (${item.target.format})` : 'no export target yet: its Export button sets one', 'dim'));
|
|
54
|
+
if (item.files) for (const f of item.files) {
|
|
55
|
+
const a = text('a', `${f.name} · ${fmtBytes(f.size)}`); a.href = url('file', item, { file: f.id, download: '1' }); a.download = f.name; details.append(a);
|
|
56
|
+
}
|
|
57
|
+
if (item.files?.length > 1) { const a = text('a', 'Download ZIP'); a.href = url('zip', item); a.download = item.label + '.zip'; details.append(a); }
|
|
58
|
+
}
|
|
59
|
+
const targetLine = (item) => !item.target ? 'no export target'
|
|
60
|
+
: `${item.target.path}${item.saved ? ` · saved ${ago(item.saved.at)} · ${fmtBytes(item.saved.size)}` : ' · not exported yet'}`;
|
|
61
|
+
|
|
62
|
+
async function exportItem(item, button, change = false) {
|
|
63
|
+
if (busy) return;
|
|
64
|
+
let choice = null;
|
|
65
|
+
if (change || !item.target) {
|
|
66
|
+
choice = await exportPopover({ anchor: button, item, formats, directory });
|
|
67
|
+
if (!choice) return;
|
|
68
|
+
}
|
|
69
|
+
busy = true; render();
|
|
70
|
+
ctx.message(`exporting ${item.label}…`, 'busy');
|
|
71
|
+
try {
|
|
72
|
+
const j = await post('export', { id: item.id, ...(choice ? { export: targetSpec(item, choice, formats) } : {}) });
|
|
73
|
+
ctx.message(`exported ${item.label} → exports/${j.path}${j.files > 1 ? ` (${j.files} files)` : ''}${j.warnings?.length ? ' · ' + j.warnings.join('; ') : ''}`, j.warnings?.length ? 'err' : 'ok', 7000);
|
|
74
|
+
} catch (e) { ctx.message(e.message, 'err', 10000); }
|
|
75
|
+
finally { busy = false; await P.refresh(); render(); }
|
|
76
|
+
}
|
|
77
|
+
async function clearTarget(item) {
|
|
78
|
+
try { await post('export', { id: item.id, export: null }); ctx.message(`${item.label} has no export target now`); }
|
|
79
|
+
catch (e) { ctx.message(e.message, 'err', 10000); }
|
|
80
|
+
await P.refresh();
|
|
81
|
+
}
|
|
82
|
+
all.onclick = async () => {
|
|
83
|
+
if (busy) return;
|
|
84
|
+
busy = true; render(); ctx.message('exporting all outputs with a target…', 'busy');
|
|
85
|
+
try {
|
|
86
|
+
const j = await post('export-all', {});
|
|
87
|
+
const warnings = j.written.flatMap((w) => w.warnings ?? []);
|
|
88
|
+
ctx.message(`exported ${j.written.length} output${j.written.length === 1 ? '' : 's'}${j.skipped.length ? ` · ${j.skipped.length} without a target (their Export button sets one)` : ''}${warnings.length ? ' · ' + warnings.join('; ') : ''}`, warnings.length ? 'err' : 'ok', 8000);
|
|
89
|
+
} catch (e) { ctx.message(e.message, 'err', 10000); }
|
|
90
|
+
finally { busy = false; await P.refresh(); render(); }
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
function render() {
|
|
94
|
+
const used = new Set(), usedGroups = new Set(), grouped = new Map();
|
|
95
|
+
for (const item of list) {
|
|
96
|
+
const name = item.origin === 'published' ? item.graph ?? 'Outputs' : '__saved';
|
|
97
|
+
if (!grouped.has(name)) grouped.set(name, []); grouped.get(name).push(item);
|
|
98
|
+
}
|
|
99
|
+
const published = list.filter((v) => v.exportable), withTarget = published.filter((v) => v.target);
|
|
100
|
+
all.disabled = busy || !withTarget.length;
|
|
101
|
+
all.textContent = busy ? 'Exporting…' : 'Export all';
|
|
102
|
+
all.title = withTarget.length ? `write every output that has an export target (${withTarget.length}) into exports/` : 'export an output with its button first: that sets its target';
|
|
103
|
+
barNote.textContent = published.length ? `${withTarget.length} of ${published.length} with a target` : '';
|
|
104
|
+
bar.hidden = !published.length; empty.hidden = !!list.length;
|
|
105
|
+
for (const [name, entries] of grouped) {
|
|
106
|
+
let group = groups.get(name);
|
|
107
|
+
if (!group) {
|
|
108
|
+
const box = document.createElement('div'), rows = document.createElement('div');
|
|
109
|
+
if (name !== '__saved') box.append(text('div', name, 'output-group'));
|
|
110
|
+
box.append(rows); group = { box, rows }; groups.set(name, group);
|
|
111
|
+
}
|
|
112
|
+
usedGroups.add(name);
|
|
113
|
+
const parent = name === '__saved' ? savedRows : live;
|
|
114
|
+
if (group.box.parentElement !== parent) parent.append(group.box);
|
|
115
|
+
const ordered = [], seen = new Set(), ids = new Set(entries.map((item) => item.id));
|
|
116
|
+
const visit = (item) => { if (seen.has(item.id)) return; seen.add(item.id); ordered.push(item); for (const child of entries) if (child.parent === item.id) visit(child); };
|
|
117
|
+
for (const item of entries) if (!ids.has(item.parent)) visit(item);
|
|
118
|
+
for (const item of entries) visit(item);
|
|
119
|
+
let previous = null;
|
|
120
|
+
for (const item of ordered) {
|
|
121
|
+
used.add(item.id); let card = cards.get(item.id);
|
|
122
|
+
if (!card) {
|
|
123
|
+
const row = document.createElement('div'); row.className = 'output-card'; row.tabIndex = 0; row.setAttribute('role', 'button'); row.dataset.output = item.id;
|
|
124
|
+
const thumb = document.createElement('img'); thumb.loading = 'lazy'; thumb.alt = '';
|
|
125
|
+
const icon = text('span', 'FILE', 'file-icon'), body = text('span', '', 'output-body'), label = text('span', '', 'output-label'), info = text('small', '', 'dim');
|
|
126
|
+
const target = text('button', '', 'output-target'), go = text('button', 'Export', 'output-export');
|
|
127
|
+
target.title = 'change where this output exports'; go.type = target.type = 'button';
|
|
128
|
+
body.append(label, info, target); row.append(thumb, icon, body, go);
|
|
129
|
+
card = { row, thumb, icon, label, info, target, go, item }; cards.set(item.id, card);
|
|
130
|
+
go.onclick = () => exportItem(card.item, go);
|
|
131
|
+
target.onclick = () => exportItem(card.item, go, true);
|
|
132
|
+
row.onclick = (e) => { if (!e.target.closest('input,button')) P.select(card.item.id); };
|
|
133
|
+
row.onkeydown = (e) => { if (e.target === row && ['Enter', ' '].includes(e.key)) { e.preventDefault(); P.select(card.item.id); } if (e.key === 'ContextMenu' || e.shiftKey && e.key === 'F10') { e.preventDefault(); contextMenu(card.item, row.getBoundingClientRect().left, row.getBoundingClientRect().bottom); } };
|
|
134
|
+
row.oncontextmenu = (e) => { e.preventDefault(); contextMenu(card.item, e.clientX, e.clientY); };
|
|
135
|
+
thumb.onerror = () => { thumb.hidden = true; icon.hidden = false; };
|
|
136
|
+
}
|
|
137
|
+
card.item = item;
|
|
138
|
+
const { row, thumb, icon, label, info, target, go } = card;
|
|
139
|
+
row.classList.toggle('selected', item.id === selected); row.classList.toggle('child', !!item.parent);
|
|
140
|
+
row.setAttribute('aria-label', `${item.label} — ${item.kind}`); row.setAttribute('aria-pressed', String(item.id === selected));
|
|
141
|
+
go.hidden = target.hidden = !item.exportable; go.disabled = busy || item.status === 'loading';
|
|
142
|
+
go.title = item.target ? `write exports/${item.target.path} again (overwrites it)` : 'choose a format and file, then export';
|
|
143
|
+
go.setAttribute('aria-label', `Export ${item.label}`);
|
|
144
|
+
target.textContent = item.exportable ? targetLine(item) : ''; target.classList.toggle('unset', !item.target);
|
|
145
|
+
const src = ['geometry', 'image'].includes(item.kind) && item.status !== 'loading' ? item.kind === 'image' && !item.generated ? url('file', item) : url('thumb', item) : '';
|
|
146
|
+
if (thumb.dataset.source !== src) { thumb.dataset.source = src; thumb.hidden = !src; icon.hidden = !!src; if (src) thumb.src = src; }
|
|
147
|
+
icon.textContent = item.kind === 'geometry' ? '3D' : item.kind === 'image' ? 'IMG' : item.kind.toUpperCase();
|
|
148
|
+
label.textContent = item.label; info.textContent = item.error ?? (item.status === 'loading' ? 'Cooking…' : `${item.kind}${item.width ? ` · ${item.width}×${item.height}` : ''}`); info.className = item.error ? 'err' : 'dim';
|
|
149
|
+
const next = previous ? previous.nextSibling : group.rows.firstChild; if (row !== next) group.rows.insertBefore(row, next); previous = row;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
for (const [id, card] of cards) if (!used.has(id)) { card.row.remove(); cards.delete(id); }
|
|
153
|
+
for (const [name, group] of groups) if (!usedGroups.has(name)) { group.box.remove(); groups.delete(name); }
|
|
154
|
+
const savedCount = list.filter((v) => v.origin === 'saved' && !v.parent).length;
|
|
155
|
+
saved.hidden = !savedCount;
|
|
156
|
+
saved.querySelector('summary').textContent = `Saved files (${savedCount})`;
|
|
157
|
+
}
|
|
158
|
+
// "saved 2 min ago" keeps up without a refresh
|
|
159
|
+
setInterval(() => { for (const card of cards.values()) if (card.item.exportable) card.target.textContent = targetLine(card.item); }, 30000);
|
|
160
|
+
|
|
161
|
+
let menu = null, dismissMenu = () => {};
|
|
162
|
+
function contextMenu(item, x, y) {
|
|
163
|
+
dismissMenu(); const previous = document.activeElement;
|
|
164
|
+
menu = document.createElement('div'); menu.className = 'output-menu'; menu.setAttribute('role', 'menu');
|
|
165
|
+
const close = () => { menu?.remove(); menu = null; removeEventListener('pointerdown', outside, true); removeEventListener('blur', close); previous?.focus(); };
|
|
166
|
+
const outside = (e) => { if (!menu?.contains(e.target)) close(); }; dismissMenu = close;
|
|
167
|
+
const add = (label, action) => { const button = text('button', label); button.setAttribute('role', 'menuitem'); button.onclick = () => { close(); action(); }; menu.append(button); };
|
|
168
|
+
const download = (href, name) => { const a = document.createElement('a'); a.href = href; a.download = name; a.click(); };
|
|
169
|
+
add(item.origin === 'saved' ? 'Open' : 'Preview', () => P.select(item.id));
|
|
170
|
+
if (item.kind === 'geometry') add('Frame', async () => { await P.select(item.id); ctx.frameOutput(); });
|
|
171
|
+
if (item.exportable) {
|
|
172
|
+
const go = cards.get(item.id)?.go;
|
|
173
|
+
add(item.target ? `Export to ${item.target.path}` : 'Export…', () => exportItem(item, go));
|
|
174
|
+
add('Change export target…', () => exportItem(item, go, true));
|
|
175
|
+
if (item.target) add('Remove export target', () => clearTarget(item));
|
|
176
|
+
} else if (item.generated && item.kind === 'image') add('Download PNG', () => download(url('image', item, { mode: 'RGBA', download: '1' }), item.label + '.png'));
|
|
177
|
+
else if (item.files?.length) add(item.files.length > 1 ? 'Download ZIP' : 'Download', () => download(item.files.length > 1 ? url('zip', item) : url('file', item, { download: '1' }), item.label));
|
|
178
|
+
document.body.append(menu); menu.style.left = Math.max(4, Math.min(x, innerWidth - menu.offsetWidth - 4)) + 'px'; menu.style.top = Math.max(4, Math.min(y, innerHeight - menu.offsetHeight - 4)) + 'px';
|
|
179
|
+
menu.onkeydown = (e) => { const buttons = [...menu.children], i = buttons.indexOf(document.activeElement); if (e.key === 'Escape' || e.key === 'Tab') { e.preventDefault(); close(); } else if (['ArrowDown', 'ArrowUp'].includes(e.key)) { e.preventDefault(); buttons[(i + (e.key === 'ArrowDown' ? 1 : buttons.length - 1)) % buttons.length].focus(); } };
|
|
180
|
+
menu.firstChild.focus(); addEventListener('pointerdown', outside, true); addEventListener('blur', close);
|
|
181
|
+
}
|
|
182
|
+
P.select = async (id, update = false) => {
|
|
183
|
+
const item = input?.id === id ? input : list.find((v) => v.id === id); if (!item) return;
|
|
184
|
+
const changedSelection = selected !== id;
|
|
185
|
+
if (!update) ctx.rememberOutputView?.(selected);
|
|
186
|
+
const seq = ++sequence;
|
|
187
|
+
if (changedSelection) { image.hide(); ctx.hideModelPreview(); }
|
|
188
|
+
selected = id; P.active = item; ctx.isolated = true; ctx.guides.setMode(null);
|
|
189
|
+
render(); showDetails(item);
|
|
190
|
+
if (item.status === 'loading') { ctx.message('Preparing ' + item.label, 'busy'); return; }
|
|
191
|
+
if (item.status === 'error') { ctx.message(item.error, 'err'); return; }
|
|
192
|
+
await ctx.outputGraph?.(item);
|
|
193
|
+
if (seq !== sequence) return;
|
|
194
|
+
if (item.kind === 'image') { ctx.hideModelPreview(); image.show(item); ctx.message(item.label); ctx.emit('output'); return; }
|
|
195
|
+
image.hide();
|
|
196
|
+
if (item.kind !== 'geometry') { ctx.hideModelPreview(); return; }
|
|
197
|
+
try {
|
|
198
|
+
const r = await fetch(url('geo', item));
|
|
199
|
+
if (!r.ok) throw new Error((await r.json()).error);
|
|
200
|
+
const bytes = await r.arrayBuffer(); if (seq !== sequence) return;
|
|
201
|
+
await ctx.previewOutput(item, bytes, update);
|
|
202
|
+
ctx.message(item.label);
|
|
203
|
+
} catch (e) { if (seq === sequence) ctx.message(e.message, 'err'); }
|
|
204
|
+
};
|
|
205
|
+
P.scene = () => {
|
|
206
|
+
sequence++; initial = false; ctx.rememberOutputView?.(selected); selected = null; P.active = null;
|
|
207
|
+
image.hide(); ctx.isolated = false; showDetails(null); render(); ctx.restoreScene();
|
|
208
|
+
};
|
|
209
|
+
P.refresh = async () => {
|
|
210
|
+
if (refreshing) { refreshAgain = true; return refreshing; }
|
|
211
|
+
refreshing = (async () => {
|
|
212
|
+
try {
|
|
213
|
+
const response = await fetch('/api/outputs'), j = await response.json(); if (!response.ok) throw new Error(j.error);
|
|
214
|
+
directory = j.directory; formats = j.formats ?? [];
|
|
215
|
+
const signature = JSON.stringify(j.items);
|
|
216
|
+
if (signature === lastList) return;
|
|
217
|
+
lastList = signature; const before = P.active; list = j.items;
|
|
218
|
+
const after = input?.id === selected ? input : list.find((v) => v.id === selected); render(); ctx.emit('outputs');
|
|
219
|
+
if (after && (after.revision !== before?.revision || after.status !== before?.status)) await P.select(after.id, true);
|
|
220
|
+
else if (after) { P.active = after; showDetails(after); }
|
|
221
|
+
else if (selected && !after) P.scene();
|
|
222
|
+
else if (initial && list.length) { initial = false; const main = list.find((v) => v.generated && !v.parent); if (main) await P.select(main.id); }
|
|
223
|
+
} catch (e) { ctx.message(e.message, 'err'); }
|
|
224
|
+
finally { refreshing = null; if (refreshAgain) { refreshAgain = false; void P.refresh(); } }
|
|
225
|
+
})();
|
|
226
|
+
return refreshing;
|
|
227
|
+
};
|
|
228
|
+
document.getElementById('scene-view').onclick = P.scene;
|
|
229
|
+
P.openInput = async (path, update = false) => {
|
|
230
|
+
const f = ctx.layers.list.find((v) => v.path === path); if (!f) return;
|
|
231
|
+
input = { id: 'input:' + path, inputPath: path, label: path, kind: 'image', status: 'ready', revision: `${f.mtime}:${f.size}`, sourceURL: inputImageURL(f), summary: ctx.layers.info.get(path)?.summary ?? ctx.layers.fileText(f) };
|
|
232
|
+
await P.select(input.id, update);
|
|
233
|
+
};
|
|
234
|
+
ctx.on('layers', () => {
|
|
235
|
+
if (!P.active?.inputPath) return;
|
|
236
|
+
const f = ctx.layers.list.find((v) => v.path === P.active.inputPath);
|
|
237
|
+
if (!f) P.scene(); else if (`${f.mtime}:${f.size}` !== P.active.revision) P.openInput(f.path, true);
|
|
238
|
+
});
|
|
239
|
+
return P;
|
|
240
|
+
}
|