@whzxc/agent-design-gallery 0.0.0-stage → 0.7.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/LICENSE +69 -0
- package/README.md +218 -2
- package/package.json +43 -4
- package/public/access.css +10 -0
- package/public/app.js +1674 -0
- package/public/arrangement-worker.js +11 -0
- package/public/arrangement.js +49 -0
- package/public/assets.js +356 -0
- package/public/auth.js +69 -0
- package/public/favicon.svg +6 -0
- package/public/hub.css +67 -0
- package/public/hub.html +33 -0
- package/public/hub.js +165 -0
- package/public/icons.js +50 -0
- package/public/index.html +70 -0
- package/public/instance-actions.js +27 -0
- package/public/labels.js +122 -0
- package/public/layout.js +119 -0
- package/public/relationships.js +28 -0
- package/public/selection.js +20 -0
- package/public/style.css +194 -0
- package/public/switcher.css +37 -0
- package/public/switcher.js +176 -0
- package/public/token-catalog.js +129 -0
- package/public/tokens.css +61 -0
- package/public/view-route.js +66 -0
- package/src/cli-output.mjs +236 -0
- package/src/cli.mjs +176 -0
- package/src/http.mjs +38 -0
- package/src/hub/auth.mjs +41 -0
- package/src/hub/instances.mjs +99 -0
- package/src/hub/proxy.mjs +30 -0
- package/src/hub/registry.mjs +181 -0
- package/src/hub.mjs +128 -0
- package/src/lifecycle.mjs +109 -0
- package/src/link.mjs +55 -0
- package/src/open.mjs +61 -0
- package/src/perf.mjs +12 -0
- package/src/server.mjs +679 -0
- package/src/service.mjs +184 -0
- package/src/toolkit/arch-browser.mjs +40 -0
- package/src/toolkit/arch-git.mjs +55 -0
- package/src/toolkit/arch-overlay.mjs +225 -0
- package/src/toolkit/arch.mjs +221 -0
- package/src/toolkit/asset-rules.mjs +14 -0
- package/src/toolkit/browser.mjs +33 -0
- package/src/toolkit/build-store.mjs +266 -0
- package/src/toolkit/build-worker.mjs +35 -0
- package/src/toolkit/build.mjs +147 -0
- package/src/toolkit/commands.mjs +345 -0
- package/src/toolkit/compare.mjs +222 -0
- package/src/toolkit/config.mjs +136 -0
- package/src/toolkit/document.mjs +85 -0
- package/src/toolkit/migrate.mjs +85 -0
- package/src/toolkit/project.mjs +172 -0
- package/src/toolkit/results.mjs +44 -0
- package/src/toolkit/runtime.d.ts +14 -0
- package/src/toolkit/runtime.mjs +54 -0
- package/src/toolkit/text.mjs +12 -0
- package/src/toolkit/tokens.mjs +37 -0
- package/src/viewer-cache.mjs +85 -0
package/public/hub.js
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { dataFetch, isUnauthorized } from './auth.js';
|
|
2
|
+
import { icon, hydrateIcons } from './icons.js';
|
|
3
|
+
import { instanceCloseButton } from './instance-actions.js';
|
|
4
|
+
|
|
5
|
+
const projects = document.querySelector('#projects');
|
|
6
|
+
const instances = document.querySelector('#instances');
|
|
7
|
+
const error = document.querySelector('#error');
|
|
8
|
+
const rescan = document.querySelector('#rescan');
|
|
9
|
+
const media = matchMedia('(prefers-color-scheme: dark)');
|
|
10
|
+
function applyTheme() {
|
|
11
|
+
const saved = localStorage.getItem('adg-theme');
|
|
12
|
+
document.documentElement.dataset.theme = saved === 'light' || saved === 'dark' ? saved : media.matches ? 'dark' : 'light';
|
|
13
|
+
}
|
|
14
|
+
applyTheme();
|
|
15
|
+
media.addEventListener('change', applyTheme);
|
|
16
|
+
hydrateIcons();
|
|
17
|
+
|
|
18
|
+
async function api(url, init) {
|
|
19
|
+
const response = await dataFetch(url, init);
|
|
20
|
+
const data = await response.json();
|
|
21
|
+
if (!response.ok) throw new Error(data.error || `HTTP ${response.status}`);
|
|
22
|
+
return data;
|
|
23
|
+
}
|
|
24
|
+
function element(tag, className, text) {
|
|
25
|
+
const node = document.createElement(tag);
|
|
26
|
+
if (className) node.className = className;
|
|
27
|
+
if (text !== undefined) node.textContent = text;
|
|
28
|
+
return node;
|
|
29
|
+
}
|
|
30
|
+
function glyph(name, size = 16) {
|
|
31
|
+
const node = element('span');
|
|
32
|
+
node.innerHTML = icon(name, size);
|
|
33
|
+
return node.firstElementChild;
|
|
34
|
+
}
|
|
35
|
+
function relativeTime(value) {
|
|
36
|
+
if (!value) return '—';
|
|
37
|
+
const seconds = Math.max(0, Math.floor((Date.now() - Date.parse(value)) / 1000));
|
|
38
|
+
if (seconds < 60) return 'just now';
|
|
39
|
+
if (seconds < 3600) return `${Math.floor(seconds / 60)} min ago`;
|
|
40
|
+
if (seconds < 86400) { const hours = Math.floor(seconds / 3600); return `${hours} ${hours === 1 ? 'hour' : 'hours'} ago`; }
|
|
41
|
+
const days = Math.floor(seconds / 86400);
|
|
42
|
+
return `${days} ${days === 1 ? 'day' : 'days'} ago`;
|
|
43
|
+
}
|
|
44
|
+
function change(project, phone = false) {
|
|
45
|
+
const node = element('span', phone ? 'phone-change' : 'hub-change desktop-change');
|
|
46
|
+
if (project.lastDesignChange?.dirty) {
|
|
47
|
+
const dot = element('span', 'hub-dirty');
|
|
48
|
+
dot.setAttribute('role', 'img');
|
|
49
|
+
dot.setAttribute('aria-label', 'Uncommitted design changes');
|
|
50
|
+
dot.title = 'Uncommitted design changes';
|
|
51
|
+
node.append(dot);
|
|
52
|
+
}
|
|
53
|
+
const time = element('span', '', relativeTime(project.lastDesignChange?.committedAt));
|
|
54
|
+
if (project.lastDesignChange?.committedAt) time.title = project.lastDesignChange.committedAt;
|
|
55
|
+
node.append(time);
|
|
56
|
+
return node;
|
|
57
|
+
}
|
|
58
|
+
function git(branch, head) {
|
|
59
|
+
const node = element('div', 'hub-git');
|
|
60
|
+
const label = element('span', '', branch || '—');
|
|
61
|
+
label.title = branch || '';
|
|
62
|
+
node.append(glyph('git-branch', 13), label);
|
|
63
|
+
if (head) node.append(element('code', '', head));
|
|
64
|
+
return node;
|
|
65
|
+
}
|
|
66
|
+
function destination(name, url, kind) {
|
|
67
|
+
const node = element('div', 'hub-name');
|
|
68
|
+
const title = element(url ? 'a' : 'span', 'hub-title', name);
|
|
69
|
+
if (url) title.href = url;
|
|
70
|
+
node.append(glyph(kind), title);
|
|
71
|
+
if (url) { const arrow = glyph('arrow-up-right', 12); arrow.classList.add('hub-external'); node.append(arrow); }
|
|
72
|
+
return node;
|
|
73
|
+
}
|
|
74
|
+
function projectRow(project) {
|
|
75
|
+
const incompatible = project.compatibility?.compatible === false;
|
|
76
|
+
const row = element('div', 'project-row');
|
|
77
|
+
const columns = element('div', 'project-columns');
|
|
78
|
+
const identity = element('div', 'project-identity');
|
|
79
|
+
const name = destination(project.name, incompatible || project.error ? null : project.url, 'folder');
|
|
80
|
+
name.append(change(project, true));
|
|
81
|
+
const path = project.design || project.path;
|
|
82
|
+
const pathNode = element('div', 'hub-path', path);
|
|
83
|
+
pathNode.title = path;
|
|
84
|
+
identity.append(name, pathNode);
|
|
85
|
+
columns.append(identity, change(project), git(project.branch, project.head),
|
|
86
|
+
element('div', 'hub-counts', `${project.sourceCount ?? '—'} sources · ${project.frameCount ?? '—'} frames`));
|
|
87
|
+
row.append(columns);
|
|
88
|
+
if (incompatible || project.error) {
|
|
89
|
+
const warning = element('div', 'hub-warning');
|
|
90
|
+
warning.append(glyph('circle-alert', 14));
|
|
91
|
+
if (incompatible) warning.append(element('span', '', 'Version incompatible'),
|
|
92
|
+
element('span', 'hub-warning-detail', `Requires ADG ${project.compatibility.requires?.replace(/>=/g, '≥')} · hub ${project.compatibility.version}`));
|
|
93
|
+
else warning.append(element('span', '', project.error));
|
|
94
|
+
row.append(warning);
|
|
95
|
+
}
|
|
96
|
+
return row;
|
|
97
|
+
}
|
|
98
|
+
function instanceRow(instance) {
|
|
99
|
+
const row = element('div', 'instance-row');
|
|
100
|
+
const identity = element('div', 'instance-identity');
|
|
101
|
+
identity.append(destination(instance.projectName ?? instance.name ?? instance.id,
|
|
102
|
+
instance.proxyable ? instance.url ?? `/i/${encodeURIComponent(instance.id)}/` : null, 'radio'));
|
|
103
|
+
const branch = git(instance.branch);
|
|
104
|
+
const started = element('span', 'instance-start', `· Started ${relativeTime(instance.startedAt)}`);
|
|
105
|
+
started.title = instance.startedAt || '';
|
|
106
|
+
branch.append(started);
|
|
107
|
+
identity.append(branch);
|
|
108
|
+
row.append(identity);
|
|
109
|
+
if (!instance.proxyable) {
|
|
110
|
+
const warning = element('span', 'instance-warning', 'Proxy unavailable');
|
|
111
|
+
warning.prepend(glyph('circle-alert', 14));
|
|
112
|
+
row.append(warning);
|
|
113
|
+
}
|
|
114
|
+
if (instance.stoppable) {
|
|
115
|
+
row.classList.add('instance-row-closeable');
|
|
116
|
+
row.append(instanceCloseButton(instance, 'instance-close', () => {
|
|
117
|
+
row.remove();
|
|
118
|
+
document.querySelector('.live-section').hidden = !instances.childElementCount;
|
|
119
|
+
(instances.querySelector('a, button') ?? rescan).focus({ preventScroll: true });
|
|
120
|
+
}, report));
|
|
121
|
+
}
|
|
122
|
+
return row;
|
|
123
|
+
}
|
|
124
|
+
function empty(title, detail) {
|
|
125
|
+
const node = element('div', 'hub-list hub-empty');
|
|
126
|
+
const copy = element('div');
|
|
127
|
+
copy.append(element('h2', '', title), element('p', '', detail));
|
|
128
|
+
node.append(glyph('folders', 24), copy);
|
|
129
|
+
return node;
|
|
130
|
+
}
|
|
131
|
+
async function refresh() {
|
|
132
|
+
const [projectData, instanceData, roots] = await Promise.all([api('api/projects'), api('api/instances'), api('api/roots')]);
|
|
133
|
+
if (projectData.length) {
|
|
134
|
+
projects.className = 'hub-list';
|
|
135
|
+
const header = element('div', 'project-columns project-header');
|
|
136
|
+
header.append(...['Projects', 'Design changed', 'Git', 'Designs'].map(label => element('span', '', label)));
|
|
137
|
+
projects.replaceChildren(header, ...projectData.map(projectRow));
|
|
138
|
+
} else {
|
|
139
|
+
projects.className = '';
|
|
140
|
+
projects.replaceChildren(empty(roots.length ? 'No projects found' : 'No roots registered', roots.length
|
|
141
|
+
? `No design sources found in the ${roots.length} registered ${roots.length === 1 ? 'root' : 'roots'}.`
|
|
142
|
+
: 'Register a root in the hub configuration to list projects.'));
|
|
143
|
+
}
|
|
144
|
+
instances.className = 'hub-list';
|
|
145
|
+
instances.replaceChildren(...instanceData.map(instanceRow));
|
|
146
|
+
document.querySelector('.live-section').hidden = !instanceData.length;
|
|
147
|
+
}
|
|
148
|
+
function report(failure) {
|
|
149
|
+
if (isUnauthorized()) return;
|
|
150
|
+
error.textContent = failure.message;
|
|
151
|
+
error.hidden = false;
|
|
152
|
+
}
|
|
153
|
+
function pending(value) {
|
|
154
|
+
rescan.disabled = value;
|
|
155
|
+
rescan.replaceChildren(glyph(value ? 'loader-circle' : 'refresh-cw', 14),
|
|
156
|
+
element('span', '', value ? 'Rescanning…' : 'Rescan'));
|
|
157
|
+
}
|
|
158
|
+
rescan.addEventListener('click', async () => {
|
|
159
|
+
pending(true);
|
|
160
|
+
error.hidden = true;
|
|
161
|
+
try { await api('api/rescan', { method: 'POST' }); await refresh(); }
|
|
162
|
+
catch (failure) { report(failure); }
|
|
163
|
+
finally { pending(false); }
|
|
164
|
+
});
|
|
165
|
+
try { await refresh(); } catch (failure) { report(failure); }
|
package/public/icons.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// Lucide geometry (ISC; see LICENSE). No runtime dependency.
|
|
2
|
+
const geometry = {
|
|
3
|
+
"palette": "<path d=\"M12 22a1 1 0 0 1 0-20 10 9 0 0 1 10 9 5 5 0 0 1-5 5h-2.25a1.75 1.75 0 0 0-1.4 2.8l.3.4a1.75 1.75 0 0 1-1.4 2.8z\"></path><circle cx=\"13.5\" cy=\"6.5\" r=\".5\" fill=\"currentColor\"></circle><circle cx=\"17.5\" cy=\"10.5\" r=\".5\" fill=\"currentColor\"></circle><circle cx=\"6.5\" cy=\"12.5\" r=\".5\" fill=\"currentColor\"></circle><circle cx=\"8.5\" cy=\"7.5\" r=\".5\" fill=\"currentColor\"></circle>",
|
|
4
|
+
"type": "<path d=\"M12 4v16\"></path><path d=\"M4 7V5a1 1 0 0 1 1-1h14a1 1 0 0 1 1 1v2\"></path><path d=\"M9 20h6\"></path>",
|
|
5
|
+
"ruler": "<path d=\"M21.3 15.3a2.4 2.4 0 0 1 0 3.4l-2.6 2.6a2.4 2.4 0 0 1-3.4 0L2.7 8.7a2.41 2.41 0 0 1 0-3.4l2.6-2.6a2.41 2.41 0 0 1 3.4 0Z\"></path><path d=\"m14.5 12.5 2-2\"></path><path d=\"m11.5 9.5 2-2\"></path><path d=\"m8.5 6.5 2-2\"></path><path d=\"m17.5 15.5 2-2\"></path>",
|
|
6
|
+
"corner-up-right": "<path d=\"m15 14 5-5-5-5\"></path><path d=\"M4 20v-7a4 4 0 0 1 4-4h12\"></path>",
|
|
7
|
+
"timer": "<line x1=\"10\" x2=\"14\" y1=\"2\" y2=\"2\"></line><line x1=\"12\" x2=\"15\" y1=\"14\" y2=\"11\"></line><circle cx=\"12\" cy=\"14\" r=\"8\"></circle>",
|
|
8
|
+
"list": "<path d=\"M3 5h.01\"></path><path d=\"M3 12h.01\"></path><path d=\"M3 19h.01\"></path><path d=\"M8 5h13\"></path><path d=\"M8 12h13\"></path><path d=\"M8 19h13\"></path>",
|
|
9
|
+
"layers": "<path d=\"M12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83z\"></path><path d=\"M2 12a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 12\"></path><path d=\"M2 17a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 17\"></path>",
|
|
10
|
+
"square-dashed": "<path d=\"M5 3a2 2 0 0 0-2 2\"></path><path d=\"M19 3a2 2 0 0 1 2 2\"></path><path d=\"M21 19a2 2 0 0 1-2 2\"></path><path d=\"M5 21a2 2 0 0 1-2-2\"></path><path d=\"M9 3h1\"></path><path d=\"M9 21h1\"></path><path d=\"M14 3h1\"></path><path d=\"M14 21h1\"></path><path d=\"M3 9v1\"></path><path d=\"M21 9v1\"></path><path d=\"M3 14v1\"></path><path d=\"M21 14v1\"></path>",
|
|
11
|
+
"refresh-cw": "<path d=\"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8\" /><path d=\"M21 3v5h-5\" /><path d=\"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16\" /><path d=\"M8 16H3v5\" />",
|
|
12
|
+
"loader-circle": "<path d=\"M21 12a9 9 0 1 1-6.219-8.56\" />",
|
|
13
|
+
"git-branch": "<path d=\"M15 6a9 9 0 0 0-9 9V3\" /><circle cx=\"18\" cy=\"6\" r=\"3\" /><circle cx=\"6\" cy=\"18\" r=\"3\" />",
|
|
14
|
+
"radio": "<path d=\"M16.247 7.761a6 6 0 0 1 0 8.478\" /><path d=\"M19.075 4.933a10 10 0 0 1 0 14.134\" /><path d=\"M4.925 19.067a10 10 0 0 1 0-14.134\" /><path d=\"M7.753 16.239a6 6 0 0 1 0-8.478\" /><circle cx=\"12\" cy=\"12\" r=\"2\" />",
|
|
15
|
+
"arrow-up-right": "<path d=\"M7 7h10v10\" /><path d=\"M7 17 17 7\" />",
|
|
16
|
+
"folders": "<path d=\"M20 5a2 2 0 0 1 2 2v7a2 2 0 0 1-2 2H9a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h2.5a1.5 1.5 0 0 1 1.2.6l.6.8a1.5 1.5 0 0 0 1.2.6z\" /><path d=\"M3 8.268a2 2 0 0 0-1 1.738V19a2 2 0 0 0 2 2h11a2 2 0 0 0 1.732-1\" />",
|
|
17
|
+
"key-round": "<path d=\"M2.586 17.414A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814a6.5 6.5 0 1 0-4-4z\" /><circle cx=\"16.5\" cy=\"7.5\" r=\".5\" fill=\"currentColor\" />",
|
|
18
|
+
"arrow-up-left": "<path d=\"M7 17V7h10\" /><path d=\"M17 17 7 7\" />",
|
|
19
|
+
"search": "<path d=\"m21 21-4.34-4.34\" /><circle cx=\"11\" cy=\"11\" r=\"8\" />",
|
|
20
|
+
"x": "<path d=\"M18 6 6 18\" /><path d=\"m6 6 12 12\" />",
|
|
21
|
+
"folder": "<path d=\"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z\" />",
|
|
22
|
+
"chevron-down": "<path d=\"m6 9 6 6 6-6\" />",
|
|
23
|
+
"sun-moon": "<path d=\"M12 2v2\" /><path d=\"M14.837 16.385a6 6 0 1 1-7.223-7.222c.624-.147.97.66.715 1.248a4 4 0 0 0 5.26 5.259c.589-.255 1.396.09 1.248.715\" /><path d=\"M16 12a4 4 0 0 0-4-4\" /><path d=\"m19 5-1.256 1.256\" /><path d=\"M20 12h2\" />",
|
|
24
|
+
"panel-right": "<rect width=\"18\" height=\"18\" x=\"3\" y=\"3\" rx=\"2\" /><path d=\"M15 3v18\" />",
|
|
25
|
+
"maximize": "<path d=\"M8 3H5a2 2 0 0 0-2 2v3\" /><path d=\"M21 8V5a2 2 0 0 0-2-2h-3\" /><path d=\"M3 16v3a2 2 0 0 0 2 2h3\" /><path d=\"M16 21h3a2 2 0 0 0 2-2v-3\" />",
|
|
26
|
+
"ellipsis": "<circle cx=\"12\" cy=\"12\" r=\"1\" /><circle cx=\"19\" cy=\"12\" r=\"1\" /><circle cx=\"5\" cy=\"12\" r=\"1\" />",
|
|
27
|
+
"panel-left": "<rect width=\"18\" height=\"18\" x=\"3\" y=\"3\" rx=\"2\" /><path d=\"M9 3v18\" />",
|
|
28
|
+
"check": "<path d=\"M20 6 9 17l-5-5\" />",
|
|
29
|
+
"layout-grid": "<rect width=\"7\" height=\"7\" x=\"3\" y=\"3\" rx=\"1\" /><rect width=\"7\" height=\"7\" x=\"14\" y=\"3\" rx=\"1\" /><rect width=\"7\" height=\"7\" x=\"14\" y=\"14\" rx=\"1\" /><rect width=\"7\" height=\"7\" x=\"3\" y=\"14\" rx=\"1\" />",
|
|
30
|
+
"chevron-right": "<path d=\"m9 18 6-6-6-6\" />",
|
|
31
|
+
"component": "<path d=\"M15.536 11.293a1 1 0 0 0 0 1.414l2.376 2.377a1 1 0 0 0 1.414 0l2.377-2.377a1 1 0 0 0 0-1.414l-2.377-2.377a1 1 0 0 0-1.414 0z\" /><path d=\"M2.297 11.293a1 1 0 0 0 0 1.414l2.377 2.377a1 1 0 0 0 1.414 0l2.377-2.377a1 1 0 0 0 0-1.414L6.088 8.916a1 1 0 0 0-1.414 0z\" /><path d=\"M8.916 17.912a1 1 0 0 0 0 1.415l2.377 2.376a1 1 0 0 0 1.414 0l2.377-2.376a1 1 0 0 0 0-1.415l-2.377-2.376a1 1 0 0 0-1.414 0z\" /><path d=\"M8.916 4.674a1 1 0 0 0 0 1.414l2.377 2.376a1 1 0 0 0 1.414 0l2.377-2.376a1 1 0 0 0 0-1.414l-2.377-2.377a1 1 0 0 0-1.414 0z\" />",
|
|
32
|
+
"copy": "<rect width=\"14\" height=\"14\" x=\"8\" y=\"8\" rx=\"2\" ry=\"2\" /><path d=\"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2\" />",
|
|
33
|
+
"app-window": "<rect x=\"2\" y=\"4\" width=\"20\" height=\"16\" rx=\"2\" /><path d=\"M10 4v4\" /><path d=\"M2 8h20\" /><path d=\"M6 4v4\" />",
|
|
34
|
+
"circle-alert": "<circle cx=\"12\" cy=\"12\" r=\"10\" /><line x1=\"12\" x2=\"12\" y1=\"8\" y2=\"12\" /><line x1=\"12\" x2=\"12.01\" y1=\"16\" y2=\"16\" />",
|
|
35
|
+
"arrow-left": "<path d=\"m12 19-7-7 7-7\" /><path d=\"M19 12H5\" />",
|
|
36
|
+
"minus": "<path d=\"M5 12h14\" />",
|
|
37
|
+
"plus": "<path d=\"M5 12h14\" /><path d=\"M12 5v14\" />",
|
|
38
|
+
"scan": "<path d=\"M3 7V5a2 2 0 0 1 2-2h2\" /><path d=\"M17 3h2a2 2 0 0 1 2 2v2\" /><path d=\"M21 17v2a2 2 0 0 1-2 2h-2\" /><path d=\"M7 21H5a2 2 0 0 1-2-2v-2\" />",
|
|
39
|
+
"map": "<path d=\"M14.106 5.553a2 2 0 0 0 1.788 0l3.659-1.83A1 1 0 0 1 21 4.619v12.764a1 1 0 0 1-.553.894l-4.553 2.277a2 2 0 0 1-1.788 0l-4.212-2.106a2 2 0 0 0-1.788 0l-3.659 1.83A1 1 0 0 1 3 19.381V6.618a1 1 0 0 1 .553-.894l4.553-2.277a2 2 0 0 1 1.788 0z\" /><path d=\"M15 5.764v15\" /><path d=\"M9 3.236v15\" />",
|
|
40
|
+
"folder-open": "<path d=\"m6 14 1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.54 6a2 2 0 0 1-1.95 1.5H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H18a2 2 0 0 1 2 2v2\" />",
|
|
41
|
+
"file": "<path d=\"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z\" /><path d=\"M14 2v5a1 1 0 0 0 1 1h5\" />"
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export function icon(name, size = 16) {
|
|
45
|
+
if (!geometry[name]) throw new Error(`Unknown icon: ${name}`);
|
|
46
|
+
return `<svg class="icon" width="${size}" height="${size}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="${1.75 * 24 / size}" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${geometry[name]}</svg>`;
|
|
47
|
+
}
|
|
48
|
+
export function hydrateIcons(root = document) {
|
|
49
|
+
for (const element of root.querySelectorAll("[data-icon]")) element.innerHTML = icon(element.dataset.icon, Number(element.dataset.size) || 16);
|
|
50
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en" data-theme="light">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
|
5
|
+
<base href="/">
|
|
6
|
+
<title>Agent Design Gallery</title>
|
|
7
|
+
<link rel="icon" type="image/svg+xml" href="/favicon.svg">
|
|
8
|
+
<link rel="stylesheet" href="tokens.css"><link rel="stylesheet" href="style.css"><link rel="stylesheet" href="switcher.css"><link rel="stylesheet" href="access.css">
|
|
9
|
+
<script type="module" src="app.js"></script>
|
|
10
|
+
</head>
|
|
11
|
+
<body>
|
|
12
|
+
<div class="gallery">
|
|
13
|
+
<main class="gallery-viewport" tabindex="0" aria-label="Design canvas" aria-describedby="controls">
|
|
14
|
+
<canvas id="canvas-background" aria-hidden="true"></canvas><canvas id="drawings" aria-hidden="true"></canvas><div id="hover-outline" hidden></div><div id="selection-outline" hidden></div><div id="labels"></div><div id="asset-access" class="sr"></div>
|
|
15
|
+
<div id="empty" hidden>No SVG files in this directory.</div>
|
|
16
|
+
</main>
|
|
17
|
+
<main id="token-catalog" class="floating" aria-labelledby="token-title" hidden>
|
|
18
|
+
<header><h2 id="token-title">Tokens</h2><code id="token-source"></code></header>
|
|
19
|
+
<div class="token-scroll">
|
|
20
|
+
<table id="token-table">
|
|
21
|
+
<thead><tr><th scope="col">Token</th><th scope="col">Light</th><th scope="col">Dark</th></tr></thead>
|
|
22
|
+
</table>
|
|
23
|
+
<p id="token-status" role="status" hidden></p>
|
|
24
|
+
</div>
|
|
25
|
+
</main>
|
|
26
|
+
<div id="app-bar" class="floating" role="toolbar" aria-label="Gallery navigation" hidden>
|
|
27
|
+
<button id="sidebar-toggle" class="icon-button" aria-label="Contents" aria-controls="sidebar" aria-expanded="false" data-tooltip="Contents"><span data-icon="panel-left"></span></button>
|
|
28
|
+
<button type="button" id="app-directory" class="picker" aria-label="Current project"><span data-icon="folder" data-size="14"></span><span class="directory-name"></span><span class="switcher-chevron" data-icon="chevron-down" data-size="12" hidden></span></button>
|
|
29
|
+
<span class="separator project-divider"></span>
|
|
30
|
+
<div id="scope-tabs" role="tablist" aria-label="Design scope"></div>
|
|
31
|
+
<span class="separator search-divider"></span>
|
|
32
|
+
<div class="search-field"><span data-icon="search" data-size="14"></span><input id="search" type="search" placeholder="Find assets…" aria-label="Find assets" autocomplete="off"><span id="search-key">⌘F</span><button id="search-clear" aria-label="Clear search" hidden><span data-icon="x" data-size="14"></span></button></div>
|
|
33
|
+
</div>
|
|
34
|
+
<aside id="sidebar" class="floating" aria-label="Contents" hidden>
|
|
35
|
+
<nav id="modules" aria-label="Design modules"></nav>
|
|
36
|
+
</aside>
|
|
37
|
+
<div id="tools" class="floating" role="toolbar" aria-label="View controls" hidden>
|
|
38
|
+
<button id="more" class="icon-button" popovertarget="more-menu" aria-label="More" aria-expanded="false" data-tooltip="More"><span data-icon="ellipsis"></span></button>
|
|
39
|
+
<button id="inspect" class="icon-button" aria-label="Inspector" aria-controls="source" aria-expanded="false" data-tooltip="Inspector" disabled><span data-icon="panel-right"></span></button>
|
|
40
|
+
</div>
|
|
41
|
+
<aside id="source" class="floating" hidden aria-label="Inspector">
|
|
42
|
+
<div class="inspector-heading"><h2 id="source-name"></h2><button id="copy-path" class="detail-copy" aria-label="Copy source path"><span id="source-path"></span><span data-icon="copy" data-size="12"></span></button><div id="frame-detail"><button id="copy-frame" class="detail-copy" aria-label="Copy frame name"><span id="frame-name"></span><span data-icon="copy" data-size="12"></span></button><span id="frame-size"></span></div></div>
|
|
43
|
+
<div class="rule"></div><h3 id="forms-heading">Frames</h3><div id="forms"></div>
|
|
44
|
+
<div class="rule"></div><section id="relationships"><h3>Relationships</h3><section aria-labelledby="uses-heading"><h4 id="uses-heading">Uses</h4><div id="uses"></div></section><section aria-labelledby="used-by-heading"><h4 id="used-by-heading">Used by</h4><div id="used-by"></div></section></section>
|
|
45
|
+
</aside>
|
|
46
|
+
<div class="zoom floating" role="toolbar" aria-label="Canvas zoom">
|
|
47
|
+
<button id="back" class="icon-button" aria-label="Back" data-tooltip="Back" disabled><span data-icon="arrow-left"></span></button><span class="separator"></span>
|
|
48
|
+
<button id="minus" class="icon-button" aria-label="Zoom out" data-tooltip="Zoom out"><span data-icon="minus"></span></button>
|
|
49
|
+
<button id="zoom-options" popovertarget="zoom-menu" aria-label="Zoom menu"><span id="zoom-value">100%</span><span data-icon="chevron-down" data-size="12"></span></button><output class="sr" aria-label="Zoom">100%</output>
|
|
50
|
+
<button id="plus" class="icon-button" aria-label="Zoom in" data-tooltip="Zoom in"><span data-icon="plus"></span></button><span class="separator"></span>
|
|
51
|
+
<button id="fit-current" class="icon-button" aria-label="Fit" data-tooltip="Fit"><span data-icon="scan"></span></button>
|
|
52
|
+
<button id="map-toggle" class="icon-button" aria-label="Minimap" aria-pressed="false" data-tooltip="Minimap"><span data-icon="map"></span></button>
|
|
53
|
+
</div>
|
|
54
|
+
<canvas id="minimap" class="floating" hidden aria-label="Minimap"></canvas>
|
|
55
|
+
<div id="more-menu" class="menu" popover aria-label="More">
|
|
56
|
+
<button id="fullscreen">Fullscreen</button><div class="rule"></div>
|
|
57
|
+
<h3>Theme</h3><div id="themes"><button data-theme="system">System</button><button data-theme="light">Light</button><button data-theme="dark">Dark</button></div>
|
|
58
|
+
<div class="rule"></div><h3>Canvas</h3><div id="backgrounds"><button data-background="theme">Match theme</button><button data-background="light">Light</button><button data-background="dark">Dark</button><button data-background="neutral">Neutral</button></div>
|
|
59
|
+
<div id="canvas-actions"><div class="rule"></div><button id="arrange">Arrange current group</button><button id="shortcuts">Keyboard shortcuts<span class="key">?</span></button></div>
|
|
60
|
+
</div>
|
|
61
|
+
<div id="zoom-menu" class="menu" popover aria-label="Zoom"><button id="zoom-fit-all">Fit all<span class="key">0</span></button><button id="zoom-fit-group">Fit group</button><button id="zoom-fit-selection">Fit selection</button><div class="rule"></div><button id="zoom-actual">Zoom to 100%<span class="key">1</span></button></div>
|
|
62
|
+
<div id="tooltip" role="tooltip" hidden></div>
|
|
63
|
+
<dialog id="keys" aria-labelledby="keys-title"><h2 id="keys-title">Keyboard shortcuts</h2><button id="keys-close" class="icon-button dialog-close" aria-label="Close keyboard shortcuts"><span data-icon="x" data-size="14"></span></button><dl>
|
|
64
|
+
<div><dt>Search</dt><dd><kbd>⌘F</kbd></dd></div><div><dt>Fit all</dt><dd><kbd>0</kbd></dd></div><div><dt>Zoom to 100%</dt><dd><kbd>1</kbd></dd></div><div><dt>Zoom in or out</dt><dd><kbd>+</kbd><kbd>−</kbd></dd></div><div><dt>Pan</dt><dd><kbd>←</kbd><kbd>↑</kbd><kbd>→</kbd><kbd>↓</kbd></dd></div><div><dt>Focus selection</dt><dd><kbd>Enter</kbd></dd></div><div><dt>Back or close</dt><dd><kbd>Esc</kbd></dd></div>
|
|
65
|
+
</dl></dialog>
|
|
66
|
+
<div id="error" role="alert" hidden></div>
|
|
67
|
+
<p id="controls" class="sr">Drag or scroll to pan. Pinch or Control or Command scroll to zoom. Arrow keys pan; plus and minus zoom; zero fits all; Escape goes back; one sets 100%. Click to select; double-click or Enter to focus.</p>
|
|
68
|
+
</div>
|
|
69
|
+
</body>
|
|
70
|
+
</html>
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { dataFetch, isUnauthorized } from './auth.js';
|
|
2
|
+
import { icon } from './icons.js';
|
|
3
|
+
|
|
4
|
+
export function instanceCloseButton(instance, className, closed, report) {
|
|
5
|
+
const button = document.createElement('button');
|
|
6
|
+
button.type = 'button';
|
|
7
|
+
button.className = className;
|
|
8
|
+
button.title = `Close instance: ${instance.name ?? instance.id} (:${instance.port})`;
|
|
9
|
+
button.setAttribute('aria-label', button.title);
|
|
10
|
+
button.innerHTML = icon('x');
|
|
11
|
+
button.onclick = async () => {
|
|
12
|
+
button.disabled = true;
|
|
13
|
+
try {
|
|
14
|
+
const response = await dataFetch(`/api/instances/${encodeURIComponent(instance.id)}/stop`, { method: 'POST' });
|
|
15
|
+
if (!response.ok && response.status !== 404) {
|
|
16
|
+
const data = await response.json();
|
|
17
|
+
throw new Error(data.error || `Cannot close instance: HTTP ${response.status}`);
|
|
18
|
+
}
|
|
19
|
+
closed();
|
|
20
|
+
} catch (error) {
|
|
21
|
+
if (!isUnauthorized()) report(error);
|
|
22
|
+
} finally {
|
|
23
|
+
button.disabled = false;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
return button;
|
|
27
|
+
}
|
package/public/labels.js
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { icon } from './icons.js';
|
|
2
|
+
// Retain screen-sized text; pure pans translate one layer until the camera settles.
|
|
3
|
+
export function overlaps(a, b) {
|
|
4
|
+
return a.x < b.x + b.width && a.x + a.width > b.x && a.y < b.y + b.height && a.y + a.height > b.y;
|
|
5
|
+
}
|
|
6
|
+
// Candidate y is a text center; collision bounds include optional caption padding.
|
|
7
|
+
export function placeLabels(candidates, obstacles, width, height, measure) {
|
|
8
|
+
const occupied = [...obstacles], result = [];
|
|
9
|
+
const sized = candidate => {
|
|
10
|
+
const parts = candidate.parts.map(part => ({ ...part, width: measure(part) + (part.copyText === undefined || part.copyIcon === false ? 0 : 16) }));
|
|
11
|
+
const w = parts.reduce((sum, p) => sum + p.width + (p.gap ?? 0), 0) + (candidate.paddingRight ?? 0);
|
|
12
|
+
const h = candidate.height ?? Math.max(...parts.map(p => p.size)) * 1.2;
|
|
13
|
+
return { ...candidate, parts, width: w, height: h, y: candidate.y - h / 2 };
|
|
14
|
+
};
|
|
15
|
+
const fits = label => {
|
|
16
|
+
const box = label.within;
|
|
17
|
+
return label.width <= label.slot && label.x >= 0 && label.y >= 0 && label.x + label.width <= width && label.y + label.height <= height &&
|
|
18
|
+
(!box || (label.x >= box.x && label.y > box.y + 2 && label.x + label.width < box.x + box.width && label.y + label.height <= box.y + box.height)) &&
|
|
19
|
+
!occupied.some(box => overlaps(label, box));
|
|
20
|
+
};
|
|
21
|
+
for (const batch of candidates) {
|
|
22
|
+
const labels = (Array.isArray(batch) ? batch : [batch]).map(candidate => {
|
|
23
|
+
let parts = candidate.parts, label = sized(candidate);
|
|
24
|
+
while (!fits(label) && parts.some(p => p.optional)) {
|
|
25
|
+
const last = parts.findLastIndex(p => p.optional);
|
|
26
|
+
parts = parts.filter((_, i) => i !== last);
|
|
27
|
+
label = sized({...candidate, parts});
|
|
28
|
+
}
|
|
29
|
+
if (!fits(label) && parts.some(p => p.copyText !== undefined)) {
|
|
30
|
+
label = sized({...candidate,parts:parts.map(p => p.copyText === undefined ? p : {...p,copyIcon:false})});
|
|
31
|
+
}
|
|
32
|
+
return label;
|
|
33
|
+
});
|
|
34
|
+
if (labels.some((label, i) => !fits(label) || labels.slice(0, i).some(other => overlaps(label, other)))) continue;
|
|
35
|
+
occupied.push(...labels); result.push(...labels);
|
|
36
|
+
}
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
39
|
+
export class Labels {
|
|
40
|
+
constructor(root, onCopyError, onSelect) {
|
|
41
|
+
this.root = root;
|
|
42
|
+
this.onCopyError = onCopyError;
|
|
43
|
+
this.onSelect = onSelect;
|
|
44
|
+
this.layer = document.createElement('div');
|
|
45
|
+
this.layer.className = 'label-layer';
|
|
46
|
+
root.append(this.layer);
|
|
47
|
+
this.anchor = null;
|
|
48
|
+
this.nodes = new Map();
|
|
49
|
+
this.metrics = new Map();
|
|
50
|
+
this.context = document.createElement('canvas').getContext('2d');
|
|
51
|
+
}
|
|
52
|
+
pan(view) {
|
|
53
|
+
if (!this.anchor || view.scale !== this.anchor.scale ||
|
|
54
|
+
(this.pinned && (view.x !== this.anchor.x || view.y !== this.anchor.y)) ||
|
|
55
|
+
Math.abs(view.x - this.anchor.x) > 32 || Math.abs(view.y - this.anchor.y) > 32) return false;
|
|
56
|
+
this.layer.style.transform = `translate(${view.x - this.anchor.x}px,${view.y - this.anchor.y}px)`;
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
update(candidates, obstacles, width, height, font, view) {
|
|
60
|
+
this.anchor = { ...view };
|
|
61
|
+
this.layer.style.transform = 'translate(0px,0px)';
|
|
62
|
+
const shown = new Set();
|
|
63
|
+
const measure = part => {
|
|
64
|
+
const spec = `${part.weight ?? 400} ${part.size}px ${font}`, key = spec + '|' + part.text;
|
|
65
|
+
if (!this.metrics.has(key)) { this.context.font = spec; this.metrics.set(key, this.context.measureText(part.text).width); }
|
|
66
|
+
return this.metrics.get(key);
|
|
67
|
+
};
|
|
68
|
+
const placed = placeLabels(candidates, obstacles, width, height, measure);
|
|
69
|
+
this.pinned = placed.some(label => label.pinned);
|
|
70
|
+
for (const label of placed) {
|
|
71
|
+
shown.add(label.id);
|
|
72
|
+
let node = this.nodes.get(label.id);
|
|
73
|
+
if (!node) { node = document.createElement('div'); node.className = 'canvas-label'; this.nodes.set(label.id, node); this.layer.append(node); }
|
|
74
|
+
const signature = JSON.stringify(label.parts.map(({color,weight,width,...part})=>part));
|
|
75
|
+
if (node.dataset.signature !== signature) {
|
|
76
|
+
node.replaceChildren(...label.parts.map(part => {
|
|
77
|
+
const span = document.createElement(part.copyText !== undefined ? 'button' : part.timestamp ? 'time' : 'span'); span.textContent = part.text;
|
|
78
|
+
if (part.copyText !== undefined) {
|
|
79
|
+
span.type = 'button';
|
|
80
|
+
span.className = 'label-copy';
|
|
81
|
+
if (part.selection) {
|
|
82
|
+
span.dataset.sourcePath=part.selection.path;
|
|
83
|
+
if (part.selection.form!==undefined) span.dataset.form=part.selection.form;
|
|
84
|
+
}
|
|
85
|
+
const glyph = document.createElement('span'); glyph.className = 'label-copy-icon';
|
|
86
|
+
glyph.hidden = part.copyIcon === false;
|
|
87
|
+
const feedback = copied => {
|
|
88
|
+
span.toggleAttribute('data-copied', copied);
|
|
89
|
+
glyph.innerHTML = icon(copied ? 'check' : 'copy', 12);
|
|
90
|
+
span.setAttribute('aria-label', copied ? `Copied ${part.copyText}` : `Copy ${part.copyText} name`);
|
|
91
|
+
span.title = copied ? 'Copied' : 'Copy name';
|
|
92
|
+
};
|
|
93
|
+
feedback(false); span.append(glyph);
|
|
94
|
+
for (const event of ['pointerdown','pointerup','dblclick']) span.addEventListener(event, e => e.stopPropagation());
|
|
95
|
+
span.onkeydown = e => {if (e.key === 'Enter' || e.key === ' ') e.stopPropagation()};
|
|
96
|
+
let timer;
|
|
97
|
+
span.onclick = async e => {
|
|
98
|
+
e.stopPropagation();
|
|
99
|
+
if (part.selection && !e.target.closest('.label-copy-icon')) this.onSelect?.(part.selection);
|
|
100
|
+
try {
|
|
101
|
+
await navigator.clipboard.writeText(part.copyText);
|
|
102
|
+
this.onCopyError?.(null);
|
|
103
|
+
feedback(true);clearTimeout(timer);timer=setTimeout(()=>feedback(false),1200);
|
|
104
|
+
} catch (error) {this.onCopyError?.(error)}
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
if (part.timestamp) {span.dateTime = part.timestamp;span.title = part.title;span.style.pointerEvents = 'auto'}
|
|
108
|
+
Object.assign(span.style, { fontSize: `${part.size}px`, fontWeight: part.weight ?? 400, color: part.color, marginLeft: `${part.gap ?? 0}px` });
|
|
109
|
+
return span;
|
|
110
|
+
}));
|
|
111
|
+
node.dataset.signature = signature;
|
|
112
|
+
}
|
|
113
|
+
for (const [i,part] of label.parts.entries()) Object.assign(node.children[i].style,{fontSize:`${part.size}px`,fontWeight:part.weight??400,color:part.color,marginLeft:`${part.gap??0}px`});
|
|
114
|
+
if (node.hidden) node.hidden = false;
|
|
115
|
+
node.style.transform = `translate(${label.x}px,${label.y}px)`;
|
|
116
|
+
const height = `${label.height}px`;
|
|
117
|
+
if (node.style.height !== height) node.style.height = height;
|
|
118
|
+
}
|
|
119
|
+
for (const [id, node] of this.nodes) if (!shown.has(id) && !node.hidden) node.hidden = true;
|
|
120
|
+
}
|
|
121
|
+
clear() { this.layer.replaceChildren(); this.nodes.clear(); this.metrics.clear(); this.anchor = null; }
|
|
122
|
+
}
|
package/public/layout.js
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
// Pure Float world geometry. Coordinates and gaps are SVG units.
|
|
2
|
+
export function bounds(boxes) {
|
|
3
|
+
if (!boxes.length) return { x: 0, y: 0, w: 1, h: 1 };
|
|
4
|
+
const x = Math.min(...boxes.map(b => b.x)), y = Math.min(...boxes.map(b => b.y));
|
|
5
|
+
return { x, y, w: Math.max(...boxes.map(b => b.x + b.w)) - x, h: Math.max(...boxes.map(b => b.y + b.h)) - y };
|
|
6
|
+
}
|
|
7
|
+
export function rows(blocks, limit, gapX, gapY, nextWidth) {
|
|
8
|
+
let x = 0, y = 0, height = 0;
|
|
9
|
+
return blocks.map(block => {
|
|
10
|
+
if (x && x + block.w > limit) { nextWidth?.(x + block.w); x = 0; y += height + gapY; height = 0; }
|
|
11
|
+
const placed = { ...block, x, y };
|
|
12
|
+
x += block.w + gapX; height = Math.max(height, block.h);
|
|
13
|
+
return placed;
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
export function skyline(blocks, limit, nextWidth, gapX = 64, gapY = 112) {
|
|
17
|
+
const lefts = [], rights = [], bottoms = [], result = [];
|
|
18
|
+
// Pack tall blocks first, but keep returned identities in source order for
|
|
19
|
+
// navigation, selection and incremental placement across geometry changes.
|
|
20
|
+
// Candidate ties prefer lower y, then lower x. Occupied edges keep exact Float arithmetic.
|
|
21
|
+
const ordered = blocks.map((block, index) => ({ block, index }))
|
|
22
|
+
.sort((a, b) => b.block.h - a.block.h || b.block.w - a.block.w || a.index - b.index);
|
|
23
|
+
for (const { block, index } of ordered) {
|
|
24
|
+
let bestX=Infinity,bestY=Infinity;
|
|
25
|
+
for(let candidate=0;candidate<=lefts.length;candidate++) {
|
|
26
|
+
const x=candidate ? rights[candidate-1] : 0,edge=x+block.w;
|
|
27
|
+
if(edge>limit){nextWidth?.(edge);continue;}
|
|
28
|
+
const right=edge+gapX;
|
|
29
|
+
let y=0;
|
|
30
|
+
for(let i=0;i<lefts.length;i++)
|
|
31
|
+
if(x<rights[i] && right>lefts[i])y=Math.max(y,bottoms[i]);
|
|
32
|
+
if(y<bestY || (y===bestY && x<bestX)){bestX=x;bestY=y;}
|
|
33
|
+
}
|
|
34
|
+
result[index] = { ...block, x:bestX, y:bestY };
|
|
35
|
+
lefts.push(bestX);rights.push(bestX+block.w+gapX);bottoms.push(bestY+block.h+gapY);
|
|
36
|
+
}
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
39
|
+
// Cache only the winning width, never source objects or placed coordinates.
|
|
40
|
+
// Repacking at that width gives fresh metadata after saves with unchanged geometry.
|
|
41
|
+
const widthChoices = new Map();
|
|
42
|
+
export function packingSnapshot() {return [...widthChoices];}
|
|
43
|
+
export function restorePacking(entries=[]) {
|
|
44
|
+
for(const [key,width] of entries.slice(-32))
|
|
45
|
+
if(typeof key==='string'&&key.length<=32768&&Number.isFinite(width)&&width>0)widthChoices.set(key,width);
|
|
46
|
+
while(widthChoices.size>32)widthChoices.delete(widthChoices.keys().next().value);
|
|
47
|
+
}
|
|
48
|
+
const aspectPenalty = 0.6;
|
|
49
|
+
function chooseWidth(blocks, step, ratio, gapX, gapY, cachedOnly = false) {
|
|
50
|
+
if (!blocks.length) return [];
|
|
51
|
+
const pack = (limit, nextWidth) => skyline(blocks, limit, nextWidth, gapX, gapY);
|
|
52
|
+
const key = JSON.stringify(['area-skyline-v1', step, ratio, aspectPenalty, gapX, gapY, blocks.map(b => [b.kind, b.w, b.h])]);
|
|
53
|
+
if (widthChoices.has(key)) return pack(widthChoices.get(key));
|
|
54
|
+
if (cachedOnly) return null;
|
|
55
|
+
const minimum = Math.max(...blocks.map(b => b.w));
|
|
56
|
+
const maximum = blocks.reduce((n, b) => n + b.w, 0) + blocks.length * gapX;
|
|
57
|
+
// Browser layout widths are exact multiples of 1/64px. Skip only on that
|
|
58
|
+
// safe grid; arbitrary SVG float geometry keeps the exhaustive search.
|
|
59
|
+
const skip = Number.isSafeInteger((maximum + step) * 64) &&
|
|
60
|
+
Number.isSafeInteger(step * 64) && blocks.every(b => Number.isSafeInteger(b.w * 64));
|
|
61
|
+
let best, bestLimit, score = Infinity;
|
|
62
|
+
for (let limit = minimum; limit <= maximum + step; limit += step) {
|
|
63
|
+
let threshold = Infinity;
|
|
64
|
+
const placed = pack(limit, width => { threshold = Math.min(threshold, width); }), box = bounds(placed);
|
|
65
|
+
const distance = box.w * box.h * (1 + aspectPenalty * Math.abs(Math.log((box.w / box.h) / ratio)));
|
|
66
|
+
if (distance < score) { best = placed; bestLimit = limit; score = distance; }
|
|
67
|
+
if (skip) {
|
|
68
|
+
if (threshold === Infinity) break;
|
|
69
|
+
limit += Math.max(0, Math.ceil((threshold - limit) / step) - 1) * step;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (key.length <= 32768 && bestLimit !== undefined) {
|
|
73
|
+
widthChoices.set(key, bestLimit);
|
|
74
|
+
if (widthChoices.size > 32) widthChoices.delete(widthChoices.keys().next().value);
|
|
75
|
+
}
|
|
76
|
+
return best;
|
|
77
|
+
}
|
|
78
|
+
export function layoutWorld(input, { provisional = false, cachedOnly = false } = {}) {
|
|
79
|
+
const place = provisional ? (blocks, step, ratio, gapX, gapY) => {
|
|
80
|
+
const area = blocks.reduce((sum, block) => sum + (block.w + gapX) * (block.h + gapY), 0);
|
|
81
|
+
return rows(blocks, Math.max(1, ...blocks.map(block => block.w), Math.sqrt(area * ratio)), gapX, gapY);
|
|
82
|
+
} : (...args) => chooseWidth(...args, cachedOnly);
|
|
83
|
+
const sections = [];
|
|
84
|
+
for (const section of input) {
|
|
85
|
+
const blocks = place(section.blocks, 50, 1.6, 64, 112);
|
|
86
|
+
if (!blocks) return null;
|
|
87
|
+
const box = bounds(blocks);
|
|
88
|
+
sections.push({ ...section, blocks, w: box.w + 128, h: box.h + 168 });
|
|
89
|
+
}
|
|
90
|
+
const placed = place(sections, 100, 1.5, 240, 240);
|
|
91
|
+
if (!placed) return null;
|
|
92
|
+
return placed.map(section => ({ ...section, blocks: section.blocks.map(block => {
|
|
93
|
+
const x = section.x + 64 + block.x, y = section.y + 104 + block.y;
|
|
94
|
+
return { ...block, x, y, ...(block.frames ? { frames: block.frames.map(frame => ({ ...frame, x: x + frame.x, y: y + frame.y })) } : {}) };
|
|
95
|
+
}) }));
|
|
96
|
+
}
|
|
97
|
+
export function componentWrapWidth(parts) {
|
|
98
|
+
const area = parts.reduce((sum, part) => sum + (part.width + 32) * (part.height + 48), 0);
|
|
99
|
+
return Math.min(6400, Math.max(1600, Math.ceil(Math.sqrt(area * 1.6))));
|
|
100
|
+
}
|
|
101
|
+
export function blockForAsset(asset) {
|
|
102
|
+
const parts = asset.parts.length ? asset.parts : [{ ...asset.full, id: 'full', name: 'Full sheet' }];
|
|
103
|
+
if (asset.component || !asset.parts.length) {
|
|
104
|
+
const box = bounds(parts.map(p => ({ x: p.x, y: p.y, w: p.width, h: p.height })));
|
|
105
|
+
const crop = { x: box.x - 24, y: box.y - 36, w: box.w + 48, h: box.h + 60 };
|
|
106
|
+
return { asset: asset.path, kind: 'set', w: crop.w, h: crop.h, crop };
|
|
107
|
+
}
|
|
108
|
+
const frames = rows(parts.map(p => ({ id: p.id, name: p.name, w: p.width + 32, h: p.height + 32, crop: { x: p.x - 16, y: p.y - 16, w: p.width + 32, h: p.height + 32 } })), 3600, 64, 112);
|
|
109
|
+
const box = bounds(frames);
|
|
110
|
+
return { asset: asset.path, kind: 'flow', w: box.w, h: box.h, frames };
|
|
111
|
+
}
|
|
112
|
+
export function fitArea(width, height, sidebar = true, inspector = false) {
|
|
113
|
+
const left = (sidebar ? 272 : 0) + 20, right = width - (inspector ? 312 : 0) - 24;
|
|
114
|
+
return { x: left, y: 100, width: Math.max(1, right - left), height: Math.max(1, height - 184) };
|
|
115
|
+
}
|
|
116
|
+
export function fitView(box, area, padding = 0) {
|
|
117
|
+
const scale = Math.max(.025, Math.min(32, Math.max(1, area.width - padding * 2) / box.width, Math.max(1, area.height - padding * 2) / box.height));
|
|
118
|
+
return { scale, x: area.x + area.width / 2 - (box.x + box.width / 2) * scale, y: area.y + area.height / 2 - (box.y + box.height / 2) * scale };
|
|
119
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Assets carry direct source imports resolved by the toolkit's bundler.
|
|
2
|
+
export function sourceRelationships(assets) {
|
|
3
|
+
const graph = Object.fromEntries(assets.filter(a => /\.(tsx|mmd)$/.test(a.path)).map(a => [a.path, { uses: [], usedBy: [] }]));
|
|
4
|
+
for (const asset of assets) {
|
|
5
|
+
const node = graph[asset.path];
|
|
6
|
+
if (!node) continue;
|
|
7
|
+
node.uses = [...new Set(asset.imports ?? [])].filter(name => Object.hasOwn(graph, name)).sort();
|
|
8
|
+
for (const name of node.uses) graph[name].usedBy.push(asset.path);
|
|
9
|
+
}
|
|
10
|
+
for (const node of Object.values(graph)) node.usedBy.sort();
|
|
11
|
+
return graph;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// Breadth-first traversal keeps one shortest, deterministic route per source.
|
|
15
|
+
export function relatedSources(graph, source, direction = 'uses') {
|
|
16
|
+
const seen = new Set([source]), result = [], queue = [{path:source, via:[]}];
|
|
17
|
+
for (let i = 0; i < queue.length; i++) {
|
|
18
|
+
const current = queue[i];
|
|
19
|
+
for (const name of [...(graph[current.path]?.[direction] ?? [])].sort()) {
|
|
20
|
+
if (seen.has(name)) continue;
|
|
21
|
+
seen.add(name);
|
|
22
|
+
const via = current.path === source ? [] : [...current.via, current.path];
|
|
23
|
+
result.push({path:name, direct:via.length === 0, via});
|
|
24
|
+
queue.push({path:name, via});
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return result.sort((a,b) => Number(b.direct)-Number(a.direct) || a.path.localeCompare(b.path));
|
|
28
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export const contains = (box, x, y) => x >= box.x && x <= box.x + box.width && y >= box.y && y <= box.y + box.height;
|
|
2
|
+
export function frameBox(asset, part) {
|
|
3
|
+
const crop = asset.shown[0];
|
|
4
|
+
return {x:asset.x + part.x - crop.x, y:asset.y + part.y - crop.y, width:part.width, height:part.height};
|
|
5
|
+
}
|
|
6
|
+
export function hitSelection(assets, x, y, elements = true) {
|
|
7
|
+
for (const asset of [...assets].reverse()) {
|
|
8
|
+
if (!contains(asset, x, y)) continue;
|
|
9
|
+
const crop = asset.shown[0];
|
|
10
|
+
const part = asset.parts.find(p => (asset.component || p.id === crop.id) && contains(frameBox(asset,p), x,y));
|
|
11
|
+
if (!part) return {asset, part:asset.component ? null : asset.parts.find(p=>p.id===crop.id)};
|
|
12
|
+
const box = frameBox(asset,part);
|
|
13
|
+
const element = elements ? [...(part.elements ?? [])].reverse().find(e => contains(e,x-box.x,y-box.y)) : null;
|
|
14
|
+
return {asset, part, element};
|
|
15
|
+
}
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
export function exportFrames(asset, owner) {
|
|
19
|
+
return (asset?.parts ?? []).filter(part => part.elements?.some(element => element.owners.some(o => o.source === owner.source && o.export === owner.export)));
|
|
20
|
+
}
|