@whzxc/agent-design-gallery 0.14.1 → 0.16.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 +29 -16
- package/package.json +2 -1
- package/public/access.css +15 -2
- package/public/app.js +1284 -521
- package/public/arrangement-worker.js +7 -7
- package/public/arrangement.js +35 -30
- package/public/assets.js +85 -48
- package/public/auth.js +59 -4
- package/public/boards.js +129 -0
- package/public/comment-anchors.js +50 -0
- package/public/comments.css +400 -0
- package/public/comments.js +1106 -0
- package/public/context-menu.js +97 -0
- package/public/frame-identity.js +51 -14
- package/public/hub.css +25 -3
- package/public/hub.html +10 -2
- package/public/hub.js +127 -23
- package/public/icons.js +9 -0
- package/public/index.html +26 -10
- package/public/instance-actions.js +9 -2
- package/public/layout.js +156 -86
- package/public/motion-flow.js +28 -0
- package/public/motion-identity.js +100 -0
- package/public/motion-paint.js +332 -0
- package/public/motion-scene.js +165 -0
- package/public/motion-specimens.js +335 -0
- package/public/player.css +270 -0
- package/public/player.js +753 -0
- package/public/recent-updates.js +535 -0
- package/public/selection.js +1 -1
- package/public/style.css +91 -154
- package/public/switcher.css +5 -4
- package/public/switcher.js +109 -34
- package/public/token-catalog.js +8 -3
- package/public/tokens.css +20 -1
- package/public/view-boards.css +131 -0
- package/public/view-boards.js +350 -0
- package/public/view-route.js +1 -2
- package/src/boards/board.mjs +30 -0
- package/src/boards/motion-board.mjs +202 -0
- package/src/boards/token-board.mjs +200 -0
- package/src/cli-output.mjs +10 -5
- package/src/cli.mjs +89 -35
- package/src/comments.mjs +293 -0
- package/src/http.mjs +7 -5
- package/src/hub/project-link.mjs +41 -0
- package/src/hub/registry.mjs +5 -0
- package/src/hub.mjs +14 -10
- package/src/link.mjs +13 -1
- package/src/recent-frames.mjs +295 -0
- package/src/recent-history.mjs +100 -0
- package/src/recent-job.mjs +63 -0
- package/src/recent-worker.mjs +171 -0
- package/src/server.mjs +285 -110
- package/src/service.mjs +46 -12
- package/src/toolkit/arch-git.mjs +8 -14
- package/src/toolkit/arch.mjs +3 -2
- package/src/toolkit/asset-rules.mjs +24 -1
- package/src/toolkit/browser.mjs +1 -13
- package/src/toolkit/build-store.mjs +9 -1
- package/src/toolkit/build-worker.mjs +6 -0
- package/src/toolkit/build.mjs +22 -16
- package/src/toolkit/commands.mjs +105 -9
- package/src/toolkit/compare.mjs +13 -11
- package/src/toolkit/config.mjs +2 -2
- package/{public/review.js → src/toolkit/diff-document.mjs} +137 -43
- package/src/toolkit/diff-inputs.mjs +97 -52
- package/src/toolkit/diff.mjs +198 -43
- package/src/toolkit/frame-declarations.mjs +36 -0
- package/src/toolkit/git-blobs.mjs +50 -0
- package/src/toolkit/impact-inputs.mjs +11 -19
- package/src/toolkit/impact-selection.mjs +27 -12
- package/src/toolkit/impact.mjs +49 -15
- package/src/toolkit/implementation-map.mjs +17 -6
- package/src/toolkit/input-generation.mjs +15 -0
- package/src/toolkit/inspect-output.mjs +1 -1
- package/src/toolkit/inspect.d.ts +9 -1
- package/src/toolkit/inspect.mjs +25 -1
- package/src/toolkit/motion-check.mjs +382 -0
- package/src/toolkit/motion-css.mjs +105 -0
- package/src/toolkit/motion-flows.mjs +95 -0
- package/src/toolkit/motion-impact.mjs +87 -0
- package/src/toolkit/motion-inventory.mjs +202 -0
- package/src/toolkit/motion-label.mjs +111 -0
- package/src/toolkit/motion-patterns.mjs +216 -0
- package/src/toolkit/motion-primitives.mjs +94 -0
- package/src/toolkit/motion-queries.mjs +169 -0
- package/src/toolkit/motion.mjs +300 -0
- package/src/toolkit/move-pairing.mjs +140 -0
- package/src/toolkit/owner.mjs +19 -6
- package/src/toolkit/play-endpoint.mjs +66 -0
- package/src/toolkit/project-index.mjs +4 -4
- package/src/toolkit/recent-structure.mjs +201 -0
- package/src/toolkit/results.mjs +3 -3
- package/src/toolkit/review-document.mjs +440 -0
- package/src/toolkit/review-embed-document.mjs +671 -0
- package/src/toolkit/review-filmstrip.mjs +76 -0
- package/src/toolkit/review-groups.mjs +29 -0
- package/src/toolkit/review-motion-card.mjs +51 -0
- package/src/toolkit/review-motion.mjs +159 -0
- package/src/toolkit/review-observation.mjs +131 -0
- package/src/toolkit/review-playback.js +123 -0
- package/src/toolkit/review-sheet.mjs +125 -0
- package/src/toolkit/review-specimens.mjs +60 -0
- package/src/toolkit/review.mjs +240 -0
- package/src/toolkit/runtime.mjs +8 -2
- package/src/toolkit/theme.mjs +16 -0
- package/src/viewer-cache.mjs +48 -12
- package/public/annotations.js +0 -816
- package/public/labels.js +0 -122
- package/src/annotations.mjs +0 -238
package/src/service.mjs
CHANGED
|
@@ -4,7 +4,9 @@ import { homedir } from 'node:os';
|
|
|
4
4
|
import path from 'node:path';
|
|
5
5
|
import { fileURLToPath } from 'node:url';
|
|
6
6
|
import { promisify } from 'node:util';
|
|
7
|
+
import { setTimeout as delay } from 'node:timers/promises';
|
|
7
8
|
import { defaultStateDirectory } from './hub/registry.mjs';
|
|
9
|
+
import { hubPublicOrigin } from './hub/project-link.mjs';
|
|
8
10
|
import { CliError } from './cli-output.mjs';
|
|
9
11
|
import { commandFailure } from './toolkit/results.mjs';
|
|
10
12
|
|
|
@@ -17,13 +19,14 @@ const unxml = value => value.replace(/&(amp|lt|gt|quot|apos);/g, (_, entity) =>
|
|
|
17
19
|
amp: '&', lt: '<', gt: '>', quot: '"', apos: "'",
|
|
18
20
|
})[entity]);
|
|
19
21
|
|
|
20
|
-
export function renderLaunchAgent({ nodePath, cliPath, stateDirectory, port = 4310 }) {
|
|
22
|
+
export function renderLaunchAgent({ nodePath, cliPath, stateDirectory, port = 4310, publicOrigin }) {
|
|
21
23
|
const args = [nodePath, cliPath, 'serve', '--port', String(port), '--state-dir', stateDirectory];
|
|
24
|
+
const environment = publicOrigin ? `\n <key>EnvironmentVariables</key><dict>\n <key>ADG_PUBLIC_ORIGIN</key><string>${xml(publicOrigin)}</string>\n </dict>` : '';
|
|
22
25
|
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
23
26
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
24
27
|
<plist version="1.0"><dict>
|
|
25
28
|
<key>Label</key><string>${SERVICE_LABEL}</string>
|
|
26
|
-
<key>ProgramArguments</key><array>${args.map(arg => `<string>${xml(arg)}</string>`).join('')}</array
|
|
29
|
+
<key>ProgramArguments</key><array>${args.map(arg => `<string>${xml(arg)}</string>`).join('')}</array>${environment}
|
|
27
30
|
<key>RunAtLoad</key><true/>
|
|
28
31
|
<key>KeepAlive</key><true/>
|
|
29
32
|
<key>StandardOutPath</key><string>${xml(path.join(stateDirectory, 'service.stdout.log'))}</string>
|
|
@@ -36,6 +39,11 @@ function launchArguments(plist) {
|
|
|
36
39
|
const array = plist?.match(/<key>ProgramArguments<\/key>\s*<array>([\s\S]*?)<\/array>/)?.[1] ?? '';
|
|
37
40
|
return [...array.matchAll(/<string>([\s\S]*?)<\/string>/g)].map(match => unxml(match[1]));
|
|
38
41
|
}
|
|
42
|
+
function launchPublicOrigin(plist) {
|
|
43
|
+
const environment = plist?.match(/<key>EnvironmentVariables<\/key>\s*<dict>([\s\S]*?)<\/dict>/)?.[1];
|
|
44
|
+
const value = environment?.match(/<key>ADG_PUBLIC_ORIGIN<\/key>\s*<string>([\s\S]*?)<\/string>/)?.[1];
|
|
45
|
+
return value === undefined ? undefined : unxml(value);
|
|
46
|
+
}
|
|
39
47
|
const readOptional = async file => {
|
|
40
48
|
try { return await readFile(file, 'utf8'); }
|
|
41
49
|
catch (error) { if (error.code !== 'ENOENT') throw error; return null; }
|
|
@@ -56,7 +64,7 @@ function statusData(status, installedPlist, agentFile, stateDirectory) {
|
|
|
56
64
|
return { label: SERVICE_LABEL, installed: installedPlist !== null, loaded: status !== null,
|
|
57
65
|
state: status?.match(/^\s*state = (.+)$/m)?.[1] ?? null,
|
|
58
66
|
pid: Number(status?.match(/^\s*pid = (\d+)$/m)?.[1]) || null,
|
|
59
|
-
plist: agentFile, stateDirectory,
|
|
67
|
+
plist: agentFile, stateDirectory, publicOrigin: launchPublicOrigin(installedPlist) ?? null,
|
|
60
68
|
logs: { stdout: path.join(stateDirectory, 'service.stdout.log'), stderr: path.join(stateDirectory, 'service.stderr.log') } };
|
|
61
69
|
}
|
|
62
70
|
|
|
@@ -142,8 +150,9 @@ export async function service(action, values = {}, {
|
|
|
142
150
|
if (!['install','uninstall','status','logs','migrate'].includes(action)) throw new CliError('USAGE_INVALID','Expected adg service install|uninstall|status|logs|migrate; run adg service --help.');
|
|
143
151
|
if (action === 'migrate') return migrateService(values,{home,run,nodePath,cliPath,uid,output});
|
|
144
152
|
const agentFile=path.join(home,'Library','LaunchAgents',`${SERVICE_LABEL}.plist`);
|
|
145
|
-
const installedPlist=await readOptional(agentFile),installedArgs=launchArguments(installedPlist)
|
|
146
|
-
const
|
|
153
|
+
const installedPlist=await readOptional(agentFile),installedArgs=launchArguments(installedPlist);
|
|
154
|
+
const argument = flag => installedArgs.includes(flag) ? installedArgs[installedArgs.indexOf(flag) + 1] : undefined;
|
|
155
|
+
const stateDirectory=path.resolve(values['state-dir'] ?? argument('--state-dir') ?? defaultStateDirectory);
|
|
147
156
|
const domain=`gui/${uid}`,target=`${domain}/${SERVICE_LABEL}`;
|
|
148
157
|
const stdout=path.join(stateDirectory,'service.stdout.log'),stderr=path.join(stateDirectory,'service.stderr.log');
|
|
149
158
|
if (action === 'logs') {
|
|
@@ -166,18 +175,43 @@ export async function service(action, values = {}, {
|
|
|
166
175
|
output(`Uninstalled ${SERVICE_LABEL}. State and logs retained in ${stateDirectory}.`);
|
|
167
176
|
return {data:{label:SERVICE_LABEL,plist:agentFile,stateDirectory,retained:true}};
|
|
168
177
|
}
|
|
169
|
-
const port=values.port
|
|
178
|
+
const port=Number(values.port ?? argument('--port') ?? 4310);
|
|
170
179
|
if (!Number.isInteger(port) || port < 1 || port > 65535) throw new CliError('USAGE_INVALID','--port must be an integer from 1 to 65535.');
|
|
171
|
-
|
|
180
|
+
const publicOrigin=hubPublicOrigin(values['public-origin'] ?? launchPublicOrigin(installedPlist),'--public-origin');
|
|
172
181
|
const executable=await realpath(nodePath),entry=await realpath(cliPath);
|
|
182
|
+
const plist=renderLaunchAgent({nodePath:executable,cliPath:entry,stateDirectory,port,publicOrigin});
|
|
183
|
+
const previous=installedPlist === null ? null : await loadedJob(run,target);
|
|
184
|
+
if (previous !== null && installedPlist === plist) {
|
|
185
|
+
output(`${SERVICE_LABEL} is already installed and loaded.`);
|
|
186
|
+
return {data:{service:statusData(previous,plist,agentFile,stateDirectory),port}};
|
|
187
|
+
}
|
|
188
|
+
const bootstrap = async () => {
|
|
189
|
+
for (let attempt = 0;; attempt++) {
|
|
190
|
+
try { return await run('/bin/launchctl',['bootstrap',domain,agentFile]); }
|
|
191
|
+
catch (cause) {
|
|
192
|
+
// launchd can still be releasing the previous job after bootout returns.
|
|
193
|
+
if (previous === null || cause.code !== 5 || attempt === 5) throw cause;
|
|
194
|
+
await delay(100 * 2 ** attempt);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
};
|
|
173
198
|
await mkdir(path.dirname(agentFile),{recursive:true});await mkdir(stateDirectory,{recursive:true});
|
|
174
199
|
await Promise.all([stdout,stderr].map(file=>writeFile(file,'',{flag:'a'})));
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
200
|
+
if (previous !== null) await job(run,['bootout',target]);
|
|
201
|
+
try {
|
|
202
|
+
await writeFile(agentFile,plist);
|
|
203
|
+
await bootstrap();
|
|
204
|
+
}
|
|
178
205
|
catch (cause) {
|
|
179
|
-
|
|
180
|
-
|
|
206
|
+
let message=`Cannot install ${SERVICE_LABEL}: ${cause.stderr?.trim() || cause.message}`;
|
|
207
|
+
try {
|
|
208
|
+
if (installedPlist === null) await rm(agentFile,{force:true});
|
|
209
|
+
else {
|
|
210
|
+
await writeFile(agentFile,installedPlist);
|
|
211
|
+
if (previous !== null) await bootstrap();
|
|
212
|
+
}
|
|
213
|
+
} catch (restore) { message += ` Could not restore the previous service: ${restore.message}`; }
|
|
214
|
+
throw new CliError('SERVICE_FAILED',message,{cause});
|
|
181
215
|
}
|
|
182
216
|
output(`Installed ${SERVICE_LABEL}. Logs: ${stdout} and ${stderr}.`);
|
|
183
217
|
return {data:{service:statusData(await loadedJob(run,target),plist,agentFile,stateDirectory),port}};
|
package/src/toolkit/arch-git.mjs
CHANGED
|
@@ -114,8 +114,8 @@ async function writeBaseBlobs(base, directory, entries) {
|
|
|
114
114
|
}
|
|
115
115
|
|
|
116
116
|
/** Materialize tracked bytes without export attributes or a Git worktree. */
|
|
117
|
-
export async function materializeBase(base) {
|
|
118
|
-
const directory = await realpath(await mkdtemp(path.join(
|
|
117
|
+
export async function materializeBase(base, temporaryDirectory = tmpdir()) {
|
|
118
|
+
const directory = await realpath(await mkdtemp(path.join(temporaryDirectory, 'adg-diff-')));
|
|
119
119
|
const close = async () => {
|
|
120
120
|
try { await cleanup(() => rm(directory, { recursive: true, force: true })); }
|
|
121
121
|
catch (error) { throw revisionError(error, directory, base); }
|
|
@@ -141,19 +141,13 @@ export async function currentHead(base) {
|
|
|
141
141
|
catch (error) { if (error.code === 'GIT_UNAVAILABLE') throw error; return null; }
|
|
142
142
|
}
|
|
143
143
|
|
|
144
|
-
/** Rename hints include staged and unstaged tracked changes against the base. */
|
|
145
|
-
export async function sourceRenames(base) {
|
|
146
|
-
const fields = (await git(base.root, ['diff', '--name-status', '-z', '--find-renames', '--diff-filter=R', base.sha, '--'])).split('\0');
|
|
147
|
-
const renames = [];
|
|
148
|
-
for (let index = 0; index < fields.length - 1; index += 3) {
|
|
149
|
-
renames.push({ before: fields[index + 1], after: fields[index + 2] });
|
|
150
|
-
}
|
|
151
|
-
return renames;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
144
|
/** Actual endpoint changes; working-tree mode includes staged, unstaged and untracked paths. */
|
|
155
145
|
export async function revisionChanges(base, head = null) {
|
|
156
|
-
const
|
|
146
|
+
const [tracked, untracked] = await Promise.all([
|
|
147
|
+
git(base.root, ['diff', '--name-status', '-z', '--find-renames', base.sha, ...(head ? [head.sha] : []), '--']),
|
|
148
|
+
head ? '' : git(base.root, ['ls-files', '--others', '--exclude-standard', '-z'])
|
|
149
|
+
]);
|
|
150
|
+
const fields = tracked.split('\0');
|
|
157
151
|
const changes = [];
|
|
158
152
|
for (let i = 0; i < fields.length - 1;) {
|
|
159
153
|
const code = fields[i++], first = fields[i++];
|
|
@@ -164,7 +158,7 @@ export async function revisionChanges(base, head = null) {
|
|
|
164
158
|
status: code === 'A' ? 'added' : code === 'D' ? 'deleted' : code === 'T' ? 'type_changed' : 'modified' });
|
|
165
159
|
}
|
|
166
160
|
if (!head) {
|
|
167
|
-
const names =
|
|
161
|
+
const names = untracked.split('\0').filter(Boolean);
|
|
168
162
|
for (const name of names) if (!changes.some(change => change.after === name)) changes.push({ before: null, after: name, status: 'added' });
|
|
169
163
|
}
|
|
170
164
|
return changes.sort((a, b) => (a.after ?? a.before) < (b.after ?? b.before) ? -1 : (a.after ?? a.before) > (b.after ?? b.before) ? 1 : 0);
|
package/src/toolkit/arch.mjs
CHANGED
|
@@ -193,11 +193,12 @@ export async function buildArch(config,file,{snapshot,model:overlayModel,browser
|
|
|
193
193
|
const result=await renderArch(overlayModel??checked.model,tokenSource,{browser});
|
|
194
194
|
const legend=checked.classes.length?`<div class="arch-legend">${checked.classes.map(name=>`<span class="arch-key ${name}" style="--arch-color:var(--arch-${name})"><i class="arch-swatch"></i>${name}</span>`).join('')}</div>`:'';
|
|
195
195
|
const html=`<section data-adg-arch>${legend}${result.svg}</section>`;
|
|
196
|
-
const
|
|
196
|
+
const cssAfterTokens='\nhtml,body{margin:0;font-family:var(--font-ui);color:var(--text);background:var(--canvas)}[data-adg-frame]{display:flex;width:max-content}';
|
|
197
|
+
const css=`${archStyles()}\n${tokenSource}${cssAfterTokens}`;
|
|
197
198
|
const note=[metadata.body,metadata.owners.length?`Owners: ${metadata.owners.join(', ')}`:'',metadata.status?`Status: ${metadata.status}`:''].filter(Boolean).join('\n');
|
|
198
199
|
const frame={frame:true,name:'default',html,note};
|
|
199
200
|
frame.document=theme=>`<!doctype html><html data-theme="${theme}"><head><meta charset="utf-8"><style>${css.replace(/<\/style/gi,'<\\/style')}</style></head><body><div data-adg-frame="default">${html}</div></body></html>`;
|
|
200
|
-
return {frames:[frame],css,imports:[],dependencies};
|
|
201
|
+
return {frames:[frame],css,cssAfterTokens,imports:[],dependencies};
|
|
201
202
|
}
|
|
202
203
|
|
|
203
204
|
// Executed in the same Chromium page as ordinary frame checks. Bounds are in
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isFeatureEntry, sourceFeature } from './project.mjs';
|
|
1
|
+
import { isFeatureEntry, isFeatureInternal, sourceFeature } from './project.mjs';
|
|
2
2
|
|
|
3
3
|
// Production sources are ordered from lower to higher layers. Studies are explorations.
|
|
4
4
|
export function importDirectionViolations(graph, sources, { strictLayers = false } = {}) {
|
|
@@ -51,3 +51,26 @@ export function singleConsumerComponents(graph, sources, partsBySource) {
|
|
|
51
51
|
}
|
|
52
52
|
return warnings;
|
|
53
53
|
}
|
|
54
|
+
|
|
55
|
+
/** Chapter guidance never changes the check verdict. Paths are design-relative. */
|
|
56
|
+
export function chapterWarnings(files, groups, sources) {
|
|
57
|
+
const production = sources.filter(source => source !== 'studies');
|
|
58
|
+
const requiredLayers = new Set(production.slice(0, Math.min(2, production.length - 1)));
|
|
59
|
+
files = files.filter(file => !isFeatureInternal(file, sources));
|
|
60
|
+
const inventory = new Set(files);
|
|
61
|
+
const assigned = new Set(groups.flatMap(group => group.assets));
|
|
62
|
+
const missing = files.filter(file => requiredLayers.has(file.split('/')[0]) && !assigned.has(file)).sort();
|
|
63
|
+
const warnings = [];
|
|
64
|
+
if (missing.length) warnings.push({
|
|
65
|
+
code: 'CHAPTER_SOURCES_UNASSIGNED', count: missing.length, paths: missing,
|
|
66
|
+
message: `${missing.length} component/module sources have no gallery.json chapter: ${missing.join(', ')}.`, next: [],
|
|
67
|
+
});
|
|
68
|
+
for (const group of groups) {
|
|
69
|
+
const paths = [...new Set(group.assets.filter(source => inventory.has(source)))];
|
|
70
|
+
if (paths.length > 12) warnings.push({
|
|
71
|
+
code: 'CHAPTER_TOO_LARGE', chapter: group.title, count: paths.length, paths,
|
|
72
|
+
message: `Chapter "${group.title}" has ${paths.length} sources; split it into feature chapters of about 3 to 12 sources.`, next: [],
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
return warnings;
|
|
76
|
+
}
|
package/src/toolkit/browser.mjs
CHANGED
|
@@ -23,19 +23,7 @@ export async function loadFrame(page, frame, theme = 'light') {
|
|
|
23
23
|
});
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
export
|
|
27
|
-
await document.fonts.ready;
|
|
28
|
-
await Promise.all([...document.images].map(image => image.decode()));
|
|
29
|
-
const urls = new Set();
|
|
30
|
-
for (const element of document.querySelectorAll('*')) {
|
|
31
|
-
for (const match of getComputedStyle(element).backgroundImage.matchAll(/url\(["']?(.+?)["']?\)/g)) urls.add(match[1]);
|
|
32
|
-
}
|
|
33
|
-
for (const element of document.querySelectorAll('svg image')) {
|
|
34
|
-
const href = element.getAttribute('href') ?? element.getAttribute('xlink:href');
|
|
35
|
-
if (href) urls.add(href);
|
|
36
|
-
}
|
|
37
|
-
await Promise.all([...urls].map(async url => { const image = new Image(); image.src = url; await image.decode(); }));
|
|
38
|
-
}
|
|
26
|
+
export { readySceneResources as readyResources } from '../../public/motion-scene.js';
|
|
39
27
|
|
|
40
28
|
/** Classify Playwright execution failures where the browser's connection is observable. */
|
|
41
29
|
export async function browserTask(browser, work) {
|
|
@@ -187,7 +187,15 @@ export async function createBuildStore({ config, cacheDirectory }) {
|
|
|
187
187
|
try {
|
|
188
188
|
const saved = JSON.parse(await readFile(indexPath, 'utf8'));
|
|
189
189
|
const startupHashes = new Map();
|
|
190
|
-
|
|
190
|
+
if (saved?.namespace === namespace && Array.isArray(saved.entries)) {
|
|
191
|
+
for (let i = 0; i < saved.entries.length; i += 16) {
|
|
192
|
+
const batch = saved.entries.slice(i, i + 16);
|
|
193
|
+
const verified = await Promise.all(batch.map(entry => valid(entry, startupHashes)));
|
|
194
|
+
batch.forEach((entry, index) => {
|
|
195
|
+
if (verified[index]) { entries.set(entry.path, entry); link(entry); }
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
}
|
|
191
199
|
} catch (error) { if (error.code !== 'ENOENT' && !(error instanceof SyntaxError)) throw error; }
|
|
192
200
|
await trimDisk();
|
|
193
201
|
async function loadPayload(hash) {
|
|
@@ -2,6 +2,7 @@ import { parentPort } from 'node:worker_threads';
|
|
|
2
2
|
import { createHash } from 'node:crypto';
|
|
3
3
|
import { realpathSync } from 'node:fs';
|
|
4
4
|
import path from 'node:path';
|
|
5
|
+
import { captureFrameOrigins } from './runtime.mjs';
|
|
5
6
|
import { buildSource } from './build.mjs';
|
|
6
7
|
import { createArchBrowser } from './arch-browser.mjs';
|
|
7
8
|
|
|
@@ -17,10 +18,15 @@ parentPort.on('message', async ({ id, config, name, type }) => {
|
|
|
17
18
|
}
|
|
18
19
|
if (shuttingDown) return;
|
|
19
20
|
try {
|
|
21
|
+
const origins = config.frameOrigins && captureFrameOrigins();
|
|
20
22
|
const snapshot = new Map();
|
|
21
23
|
const build = async browser => config.overlay && name.endsWith('.mmd') ? (await import('./arch-overlay.mjs')).buildOverlay(config,path.join(config.root,name),{base:config.overlay,browser,snapshot}) : buildSource(config, path.join(name.endsWith('.mmd')?config.root:config.design, name), { write: false, snapshot, browser, allowLegacy: config.allowLegacy ?? true });
|
|
22
24
|
const built = await (name.endsWith('.mmd') ? archBrowser.run(build) : build());
|
|
23
25
|
const frames = JSON.parse(JSON.stringify(built.frames.map(({ document, ...frame }) => frame)));
|
|
26
|
+
if (origins) built.frames.forEach((frame,i) => {
|
|
27
|
+
const origin = origins.get(frame);
|
|
28
|
+
if (origin) frames[i].declaration = {source:path.relative(config.root,path.resolve(origin.fileName)), line:origin.lineNumber,column:origin.columnNumber};
|
|
29
|
+
});
|
|
24
30
|
const designRoot = realpathSync(config.design);
|
|
25
31
|
const dependencies = [...new Set(built.dependencies.map(file => path.relative(file.startsWith(designRoot + path.sep) ? designRoot : config.design, file).split(path.sep).join('/')))].sort();
|
|
26
32
|
const dependencyHashes = Object.fromEntries(dependencies.map(name => {
|
package/src/toolkit/build.mjs
CHANGED
|
@@ -6,6 +6,7 @@ import path from 'node:path';
|
|
|
6
6
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
7
7
|
import { loadTokens, refreshTypes, rejectLegacy, relative, isSourcePath, sourceDirectories, isFeatureInternal } from './project.mjs';
|
|
8
8
|
import { themeCss, parseTokens } from './tokens.mjs';
|
|
9
|
+
import { motionPrimitives, motionTokenCss } from './motion-primitives.mjs';
|
|
9
10
|
import { componentOwner } from './runtime.mjs';
|
|
10
11
|
import { CliError, classifyError } from '../cli-output.mjs';
|
|
11
12
|
import { frameDocument } from './frame-document.mjs';
|
|
@@ -91,17 +92,18 @@ export async function buildSource(config, file, options = {}) {
|
|
|
91
92
|
throw new CliError(code === 'INTERNAL_ERROR' ? 'SOURCE_BUILD_FAILED' : code, error.message, { cause: error });
|
|
92
93
|
}
|
|
93
94
|
}
|
|
94
|
-
async function buildDesignSource(config, file, { write = true, allowLegacy = true, snapshot, browser } = {}) {
|
|
95
|
+
async function buildDesignSource(config, file, { write = true, allowLegacy = true, snapshot, browser, files, framesOnly = false } = {}) {
|
|
95
96
|
if (file.endsWith('.mmd')) return (await import('./arch.mjs')).buildArch(config,file,{snapshot,browser});
|
|
96
97
|
if (write) refreshTypes(config);
|
|
97
98
|
const read = (name, encoding) => {
|
|
99
|
+
if (files) return files.read(name, encoding);
|
|
98
100
|
if (!snapshot) return readFileSync(name, encoding);
|
|
99
101
|
if (!snapshot.has(name)) snapshot.set(name, readFileSync(name));
|
|
100
102
|
const value = snapshot.get(name);
|
|
101
103
|
return encoding ? value.toString(encoding) : value;
|
|
102
104
|
};
|
|
103
|
-
file = realpathSync(file);
|
|
104
|
-
const base = realpathSync(config.design), dependencies = new Set();
|
|
105
|
+
file = files ? path.resolve(file) : realpathSync(file);
|
|
106
|
+
const base = files ? path.resolve(config.design) : realpathSync(config.design), dependencies = new Set();
|
|
105
107
|
const imports = new Set(), sources = sourceDirectories(config);
|
|
106
108
|
const result = await build({ entryPoints: [file], bundle: true, write: false, format: 'esm', platform: 'node', jsx: 'automatic', jsxImportSource: 'adg', jsxDev: true, metafile: true, logLevel: 'silent', plugins: [{ name: 'adg-sources', setup(api) {
|
|
107
109
|
api.onResolve({ filter: /.*/ }, args => {
|
|
@@ -112,9 +114,9 @@ async function buildDesignSource(config, file, { write = true, allowLegacy = tru
|
|
|
112
114
|
const url = args.path.endsWith('?url');
|
|
113
115
|
const requested = url ? args.path.slice(0,-4) : args.path;
|
|
114
116
|
let resolved = args.kind === 'entry-point' ? path.resolve(requested) : path.resolve(args.resolveDir, requested);
|
|
115
|
-
resolved = [resolved, ...['.tsx','.ts','.js','/index.tsx','/index.ts','/index.js'].map(ext => resolved + ext)].find(candidate => statSync(candidate, { throwIfNoEntry: false })?.isFile());
|
|
117
|
+
resolved = [resolved, ...['.tsx','.ts','.js','/index.tsx','/index.ts','/index.js'].map(ext => resolved + ext)].find(candidate => files ? files.has(candidate) : statSync(candidate, { throwIfNoEntry: false })?.isFile());
|
|
116
118
|
if (!resolved) return { errors: [{ text: `Cannot resolve ${args.path}` }] };
|
|
117
|
-
resolved = realpathSync(resolved);
|
|
119
|
+
if (!files) resolved = realpathSync(resolved);
|
|
118
120
|
if (!resolved.startsWith(base + path.sep)) return { errors: [{ text: `Import ${args.path} leaves design/; move it inside design/` }] };
|
|
119
121
|
if (!allowLegacy) rejectLegacy(config, [path.join(config.design, path.relative(base, resolved))]);
|
|
120
122
|
dependencies.add(resolved);
|
|
@@ -123,7 +125,7 @@ async function buildDesignSource(config, file, { write = true, allowLegacy = tru
|
|
|
123
125
|
if (url && !resolved.startsWith(path.join(base,'art')+path.sep)) return {errors:[{text:'?url imports must be under design/art/'}]};
|
|
124
126
|
return { path: resolved, ...(url ? {namespace:'art-url'} : {}) };
|
|
125
127
|
});
|
|
126
|
-
api.onLoad({filter:/.*/,namespace:'art-bytes'}, args => ({contents:read(args.path),loader:'dataurl'}));
|
|
128
|
+
api.onLoad({filter:/.*/,namespace:'art-bytes'}, async args => ({contents:await read(args.path),loader:'dataurl'}));
|
|
127
129
|
const artModule = file => {
|
|
128
130
|
const source=path.relative(base,file).split(path.sep).join('/');
|
|
129
131
|
return {contents:`import data from ${JSON.stringify('adg:art-bytes:'+file)};import {registerArtwork} from 'adg';export default registerArtwork(data,${JSON.stringify(source)});`,loader:'js'};
|
|
@@ -131,14 +133,14 @@ async function buildDesignSource(config, file, { write = true, allowLegacy = tru
|
|
|
131
133
|
api.onLoad({filter:/.*/,namespace:'art-url'}, args => artModule(args.path));
|
|
132
134
|
api.onLoad({filter:/\.tsx$/}, async args => {
|
|
133
135
|
const sourcePath = path.relative(base, args.path).split(path.sep).join('/');
|
|
134
|
-
if (!isSourcePath(sourcePath, sources)) return snapshot ? {contents:read(args.path,'utf8'),loader:'tsx'} : undefined;
|
|
135
|
-
const original=read(args.path,'utf8');
|
|
136
|
+
if (!isSourcePath(sourcePath, sources)) return files || snapshot ? {contents:await read(args.path,'utf8'),loader:'tsx'} : undefined;
|
|
137
|
+
const original=await read(args.path,'utf8');
|
|
136
138
|
return registeredSource(args.path, sourcePath, original);
|
|
137
139
|
});
|
|
138
|
-
if (snapshot) api.onLoad({filter:/\.(?:[cm]?js|jsx|ts|json)$/}, args => ({contents:read(args.path,'utf8'),loader:args.path.endsWith('.ts')?'ts':args.path.endsWith('.jsx')?'jsx':args.path.endsWith('.json')?'json':'js'}));
|
|
140
|
+
if (snapshot || files) api.onLoad({filter:/\.(?:[cm]?js|jsx|ts|json)$/}, async args => ({contents:await read(args.path,'utf8'),loader:args.path.endsWith('.ts')?'ts':args.path.endsWith('.jsx')?'jsx':args.path.endsWith('.json')?'json':'js'}));
|
|
139
141
|
api.onLoad({ filter: /\.(png|jpe?g|webp)$/i }, args => artModule(args.path));
|
|
140
|
-
api.onLoad({ filter: /\.svg$/i }, args => {
|
|
141
|
-
const source = read(args.path,'utf8');
|
|
142
|
+
api.onLoad({ filter: /\.svg$/i }, async args => {
|
|
143
|
+
const source = await read(args.path,'utf8');
|
|
142
144
|
const forbidden = /<(?:style|script)\b|\s(?:on[\w-]+|className)\s*=/i.exec(source);
|
|
143
145
|
if (forbidden) { const before=source.slice(0,forbidden.index); return {errors:[{text:'Forbidden SVG markup; remove styles, scripts and event attributes',location:{file:args.path,line:before.split('\n').length,column:before.length-before.lastIndexOf('\n')-1}}]}; }
|
|
144
146
|
return { contents: `import { artwork } from 'adg'; export default props => artwork(${JSON.stringify(source)}, props, ${JSON.stringify(path.relative(base,args.path).split(path.sep).join('/'))});`, loader:'js' };
|
|
@@ -160,7 +162,7 @@ async function buildDesignSource(config, file, { write = true, allowLegacy = tru
|
|
|
160
162
|
}).sort();
|
|
161
163
|
const internal = isFeatureInternal(sourceName, sources);
|
|
162
164
|
if (internal) {
|
|
163
|
-
const original = read(file, 'utf8');
|
|
165
|
+
const original = await read(file, 'utf8');
|
|
164
166
|
if (/export\s+default[\s\S]*<Frame\b/.test(original)) throw Error(`${relative(config,file)}: feature-internal source must not export Frame defaults; move frames to index.tsx`);
|
|
165
167
|
return { frames: [], parts, dependencies: [...dependencies], imports: [...imports].sort(), css: '', tokenCss: '', cssWithoutTokens: '', cssBeforeTokens: '', cssAfterTokens: '' };
|
|
166
168
|
}
|
|
@@ -172,19 +174,23 @@ async function buildDesignSource(config, file, { write = true, allowLegacy = tru
|
|
|
172
174
|
try { validateFrame(frame); if (names.has(frame.name)) throw Error(`Duplicate frame name ${frame.name}`); names.add(frame.name); }
|
|
173
175
|
catch(error) { throw Error(`${relative(config,file)}: ${frame?.name ?? '-'}: ${error.message}`); }
|
|
174
176
|
}
|
|
177
|
+
if (framesOnly) return { frames };
|
|
175
178
|
const tokenFile = path.join(base, 'tokens.css');
|
|
176
179
|
dependencies.add(tokenFile);
|
|
177
|
-
const tokenSource = read(tokenFile,'utf8'), tokens = snapshot ? parseTokens(tokenSource) : loadTokens(config);
|
|
180
|
+
const tokenSource = await read(tokenFile,'utf8'), tokens = snapshot ? parseTokens(tokenSource) : loadTokens(config);
|
|
178
181
|
const compiler = await compile(`${readFileSync(path.join(tailwind,'theme.css'),'utf8')}\n${themeCss(tokens)}\n${readFileSync(path.join(tailwind,'preflight.css'),'utf8')}\n@custom-variant dark (&:where([data-theme=dark], [data-theme=dark] *));\n@tailwind utilities;`);
|
|
179
182
|
const classes = [...new Set(frames.flatMap(f => [...f.html.matchAll(/\bclass="([^"]*)"/g)].flatMap(m => m[1].split(/\s+/))))];
|
|
180
183
|
const utilities = compiler.build(classes);
|
|
181
184
|
const defaults = 'html,body{margin:0;font-family:var(--font-ui);color:var(--text);background:var(--canvas)}[data-adg-frame]{display:flex;align-items:flex-start;position:relative;background:var(--canvas)}[data-adg-frame]>*,svg{flex-shrink:0} @media(prefers-reduced-motion:reduce){*,*::before,*::after{animation:none!important;transition:none!important}}';
|
|
182
|
-
const
|
|
185
|
+
const hasSprings = [...tokens.light.keys()].some(name => /^--motion-spring-.+-(?:duration|bounce)$/.test(name));
|
|
186
|
+
const generated = hasSprings ? motionTokenCss(motionPrimitives(tokens).generated) : '';
|
|
187
|
+
const cssAfterTokens = `\n${generated}${defaults}`;
|
|
188
|
+
const css = `${utilities}\n${tokenSource}${cssAfterTokens}`;
|
|
183
189
|
for (const frame of frames) {
|
|
184
190
|
frame.document = theme => frameDocument(frame, theme, css);
|
|
185
191
|
if (write) { const destination = path.join(config.output, path.relative(base,file).replace(/\.tsx$/, ''), `${encodeURIComponent(frame.name)}.html`); mkdirSync(path.dirname(destination),{recursive:true}); writeFileSync(destination,frame.document('light')); }
|
|
186
192
|
}
|
|
187
193
|
return { ...(observationDynamic?{observationDynamic:true}:{}), frames, parts, dependencies: [...dependencies], imports: [...imports].sort(), css,
|
|
188
|
-
tokenCss: tokenSource, cssWithoutTokens: `${utilities}
|
|
189
|
-
cssBeforeTokens: `${utilities}\n`, cssAfterTokens
|
|
194
|
+
tokenCss: tokenSource, cssWithoutTokens: `${utilities}${cssAfterTokens}`,
|
|
195
|
+
cssBeforeTokens: `${utilities}\n`, cssAfterTokens };
|
|
190
196
|
}
|
package/src/toolkit/commands.mjs
CHANGED
|
@@ -1,15 +1,23 @@
|
|
|
1
|
+
import { labelResolver } from './motion-label.mjs';
|
|
1
2
|
import { mkdirSync, readFileSync, existsSync } from 'node:fs';
|
|
2
3
|
import path from 'node:path';
|
|
3
4
|
import { availableParallelism } from 'node:os';
|
|
5
|
+
import { motionSummary, motionRows, readMotion } from './motion.mjs';
|
|
6
|
+
import { scanMotion } from './motion-inventory.mjs';
|
|
7
|
+
import { loadMotionPatterns } from './motion-patterns.mjs';
|
|
8
|
+
import { deadEndFindings } from './motion-flows.mjs';
|
|
9
|
+
import { motionEvaluator } from './motion-check.mjs';
|
|
10
|
+
import { sourceMotion } from './motion-css.mjs';
|
|
4
11
|
import { buildSource } from './build.mjs';
|
|
5
|
-
import { selectSources, relative, loadTokens, sourceDirectories, archFiles, featureFolderProblems } from './project.mjs';
|
|
6
|
-
import { importDirectionViolations, singleConsumerComponents } from './asset-rules.mjs';
|
|
12
|
+
import { selectSources, relative, loadTokens, sourceDirectories, archFiles, featureFolderProblems, readGroups, listSources } from './project.mjs';
|
|
13
|
+
import { importDirectionViolations, singleConsumerComponents, chapterWarnings } from './asset-rules.mjs';
|
|
7
14
|
import { launch, loadFrame, browserTask } from './browser.mjs';
|
|
8
15
|
import { CliError, classifyError } from '../cli-output.mjs';
|
|
9
16
|
import { commandFailure, cleanup, emptySelection } from './results.mjs';
|
|
10
17
|
import { loadImplementationMap, validateImplementationMap } from './implementation-map.mjs';
|
|
11
18
|
import { withImpacted } from './impact-selection.mjs';
|
|
12
19
|
import { mappingFacts, frameOwners } from './source-facts.mjs';
|
|
20
|
+
import { resolveThemes, systemTheme } from './theme.mjs';
|
|
13
21
|
|
|
14
22
|
function frameStructure(frame) {
|
|
15
23
|
return frame.html
|
|
@@ -219,12 +227,64 @@ export async function check(config, args = [], options = {}, log = console.log,
|
|
|
219
227
|
if (!primary) primary = failure;
|
|
220
228
|
else warnings.push(classifyError(failure).error);
|
|
221
229
|
};
|
|
230
|
+
const emit = ({source,frame,theme,warning,...problem}) => {
|
|
231
|
+
if (warning) {
|
|
232
|
+
warnings.push({code:problem.code,message:source+': '+(problem.transition??frame??'')+(theme?' ('+theme+')':'')+' '+problem.message,next:[]});
|
|
233
|
+
if (!options.json) log('WARNING '+warnings.at(-1).message);
|
|
234
|
+
} else add(problem,path.join(config.root,source),frame??null,theme??null);
|
|
235
|
+
};
|
|
222
236
|
try {
|
|
237
|
+
const motion = session?.views[1].motion ?? readMotion(config);
|
|
238
|
+
if (!args.length && !session) {
|
|
239
|
+
const inventory = scanMotion(config, loadMotionPatterns(config), motion);
|
|
240
|
+
const issues = options['motion-details'] ? inventory.issues : inventory.issues.slice(0, 16);
|
|
241
|
+
data.motionPatterns = {
|
|
242
|
+
animations: inventory.animations, unmapped: inventory.unmapped, unused: inventory.unused,
|
|
243
|
+
findings: inventory.issues.length, omitted: inventory.issues.length - issues.length,
|
|
244
|
+
};
|
|
245
|
+
for (const { source, ...issue } of issues) {
|
|
246
|
+
if (config.check?.strictMotion) add(issue, path.join(config.root, source));
|
|
247
|
+
else {
|
|
248
|
+
const message = source + (issue.line ? ':' + issue.line : '') + ': ' + issue.message;
|
|
249
|
+
warnings.push({ code: issue.code, message, next: [] });
|
|
250
|
+
if (!options.json) log('WARNING ' + message);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
if (data.motionPatterns.omitted && !options.json)
|
|
254
|
+
log(data.motionPatterns.omitted + ' more motion inventory findings. Use --motion-details for all locations.');
|
|
255
|
+
if (options['motion-only']) {
|
|
256
|
+
for (const finding of motion.findings) emit(finding);
|
|
257
|
+
for (const finding of deadEndFindings(motion, motion.records, config.check?.strictMotion)) emit(finding);
|
|
258
|
+
for (const problem of humanProblems) error(problem);
|
|
259
|
+
data.complete = true;
|
|
260
|
+
const message = 'Motion inventory: ' + inventory.animations + ' animation sites, ' + inventory.unmapped +
|
|
261
|
+
' unmapped, ' + inventory.unused + ' unused patterns.';
|
|
262
|
+
log(message);
|
|
263
|
+
if (data.findings.length) throw new CliError('CHECK_FAILED', message, { data, warnings, humanReported: true });
|
|
264
|
+
return { data, warnings };
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
const directories = sourceDirectories(config);
|
|
268
|
+
const chapterFiles = listSources(config.design, directories).map(file => path.relative(config.design, file).split(path.sep).join('/'));
|
|
269
|
+
const chapters = chapterWarnings(chapterFiles, readGroups(config.design, directories), directories);
|
|
270
|
+
warnings.push(...chapters);
|
|
271
|
+
if (!options.json) for (const warning of chapters) log(`WARNING ${warning.message}`);
|
|
223
272
|
const mapping = await loadImplementationMap(config);
|
|
224
273
|
const files = session ? session.sources.map(source => path.join(config.root, source)).filter(existsSync) : selectSources(config, args, { write });
|
|
225
274
|
data.sources = files.map(file => relative(config, file));
|
|
226
275
|
data.summary.sources = files.length;
|
|
227
276
|
if (config.check?.strictLayers === true) for (const problem of featureFolderProblems(config.design, sourceDirectories(config))) add({ code: problem.code, message: problem.message, line: null, column: null }, problem.file);
|
|
277
|
+
const selectedRecord = r => (!args.length || [r.owner,r.edge?.to?.source].some(src=>data.sources.includes(src))) &&
|
|
278
|
+
(!options.frame || [r.edge?.from,r.edge?.to].some(ref=>ref?.frame===options.frame && data.sources.includes(ref.source))) &&
|
|
279
|
+
(!session || session.motionIds.has(r.edge?.id) || !r.valid);
|
|
280
|
+
const records = motion.records.filter(selectedRecord);
|
|
281
|
+
const cssFindings=new Map();
|
|
282
|
+
const scopeFiles = new Set(records.map(r=>r.source));
|
|
283
|
+
const inScope = sidecar => !args.length || scopeFiles.has(sidecar) || data.sources.includes(sidecar.replace(/\.motion\.json$/,'.tsx'));
|
|
284
|
+
for (const source of motion.files) if (inScope(source) && !chapterFiles.includes(path.relative(config.design,path.resolve(config.root,source)).replace(/\.motion\.json$/,'.tsx')))
|
|
285
|
+
emit({code:'MOTION_SCHEMA',source,pointer:'',message:'Motion sidecar has no owning TSX entry.',line:1,column:1});
|
|
286
|
+
for (const finding of motion.findings) if(inScope(finding.source)) emit(finding);
|
|
287
|
+
for (const finding of deadEndFindings(motion, records, config.check?.strictMotion)) emit(finding);
|
|
228
288
|
const tokens = files.length ? loadTokens(config) : null;
|
|
229
289
|
const arch = files.some(file => file.endsWith('.mmd')) ? await import('./arch.mjs') : null;
|
|
230
290
|
let page;
|
|
@@ -261,6 +321,14 @@ export async function check(config, args = [], options = {}, log = console.log,
|
|
|
261
321
|
if (mapping.present && !architecture) builtSources.set(relative(config, file), mappingFacts(built));
|
|
262
322
|
graph[path.relative(config.design, file).split(path.sep).join('/')] = { uses: built.imports };
|
|
263
323
|
for (const frame of built.frames) for (const theme of session?.themes ?? ['light', 'dark']) {
|
|
324
|
+
if (session && options.frame && frame.name !== options.frame) continue;
|
|
325
|
+
const lintMotion = !session || session.assessments.get(JSON.stringify([relative(config,file),frame.name,theme]))?.candidate ||
|
|
326
|
+
session.views[0].config.check?.strictMotion !== config.check?.strictMotion || !session.views[0].tokenBytes.equals(session.views[1].tokenBytes);
|
|
327
|
+
if (!architecture && lintMotion) for (const message of sourceMotion(built,frame,tokens,theme)) {
|
|
328
|
+
const key=JSON.stringify([file,frame.name,message]);
|
|
329
|
+
if(cssFindings.has(key))cssFindings.get(key).theme=null;
|
|
330
|
+
else cssFindings.set(key,{code:'MOTION_SOURCE_CSS',source:relative(config,file),frame:frame.name,theme,message,line:null,column:null,warning:!config.check?.strictMotion});
|
|
331
|
+
}
|
|
264
332
|
if (session && !session.scheduled({ source: relative(config, file), frame: frame.name }, theme)) continue;
|
|
265
333
|
browser ??= await launchBrowser();
|
|
266
334
|
try {
|
|
@@ -275,20 +343,49 @@ export async function check(config, args = [], options = {}, log = console.log,
|
|
|
275
343
|
}
|
|
276
344
|
}
|
|
277
345
|
}
|
|
346
|
+
for(const finding of cssFindings.values())emit(finding);
|
|
278
347
|
let validatedMap = null;
|
|
279
348
|
if (mapping.present) {
|
|
280
349
|
const { listSources } = await import('./project.mjs');
|
|
281
350
|
validatedMap = await validateImplementationMap(config, mapping, {
|
|
282
351
|
sources: listSources(config.design, sourceDirectories(config)).map(file => relative(config, file)),
|
|
283
|
-
selected: args.length ? data.sources : undefined,
|
|
352
|
+
selected: args.length ? [...new Set([...data.sources,...records.map(r=>r.owner)])] : undefined,
|
|
284
353
|
getBuild: source => {
|
|
285
354
|
if (failedSources.has(source)) throw failedSources.get(source);
|
|
286
355
|
if (!builtSources.has(source)) builtSources.set(source, session?.views[1].built.get(source) ?? buildSource(config, path.join(config.root, source), { write: false, allowLegacy: false }));
|
|
287
356
|
return builtSources.get(source);
|
|
288
357
|
},
|
|
289
|
-
onFinding: ({ code, message, line, column, frame }) => add({ code, message, line, column }, mapping.file, frame),
|
|
358
|
+
onFinding: ({ code, message, line, column, frame, pointer, target }) => add({ code, message, line, column, ...(code==='MOTION_BINDING'?{pointer,transition:target.transition}:{}) }, mapping.file, frame),
|
|
290
359
|
});
|
|
291
360
|
}
|
|
361
|
+
if (records.some(r=>r.valid)) {
|
|
362
|
+
const evaluate=motionEvaluator(config,{flows:motion.flows,themes:session?.themes,bindings:validatedMap?.transitionBindings,hasMap:mapping.present,
|
|
363
|
+
getBuild:source=>allBuilt.get(source)??session?.views[1].built.get(source),
|
|
364
|
+
getPage:async()=>{browser??=await launchBrowser();return page??=await browser.newPage();}});
|
|
365
|
+
// Other edges on this origin can conflict even when a Git or destination filter selects only one edge.
|
|
366
|
+
const origins=new Set(records.filter(r=>r.valid).map(r=>JSON.stringify([r.edge.from.source,r.edge.from.frame])));
|
|
367
|
+
const peers=motion.records.filter(r=>r.valid && !records.includes(r) && origins.has(JSON.stringify([r.edge.from.source,r.edge.from.frame])));
|
|
368
|
+
for(const peer of peers)await evaluate(peer);
|
|
369
|
+
for (const record of records.filter(r=>r.valid)) {
|
|
370
|
+
try { for(const finding of (await evaluate(record)).findings)emit(finding); }
|
|
371
|
+
catch(cause){failed(cause);}
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
const rows = motionRows(records);
|
|
375
|
+
if (options.transitions) {
|
|
376
|
+
const actionName = labelResolver(config, source => {
|
|
377
|
+
const built = allBuilt.get(source) ?? session?.views[1].built.get(source);
|
|
378
|
+
if (built) return built;
|
|
379
|
+
const file = path.join(config.root, source);
|
|
380
|
+
if (chapterFiles.includes(path.relative(config.design, file).split(path.sep).join('/')))
|
|
381
|
+
return buildSource(config, file, { write: false });
|
|
382
|
+
});
|
|
383
|
+
const edges = await Promise.all(rows.map(async record => ({
|
|
384
|
+
id: record.edge.id, label: await actionName(record),
|
|
385
|
+
...(record.edge.proposed ? { proposed: record.edge.proposed } : {})
|
|
386
|
+
})));
|
|
387
|
+
motionSummary(data, edges, true);
|
|
388
|
+
} else motionSummary(data, rows);
|
|
292
389
|
await cleanup(() => browser?.close(), primary);
|
|
293
390
|
browser = null;
|
|
294
391
|
if (config.check?.importDirection !== false) for (const { source, target, from, to, sameLayer, featureBoundary } of importDirectionViolations(graph, sourceDirectories(config), { strictLayers: config.check?.strictLayers === true })) {
|
|
@@ -340,21 +437,20 @@ export async function check(config, args = [], options = {}, log = console.log,
|
|
|
340
437
|
} finally { if (browser) await cleanup(() => browser.close(), primary); }
|
|
341
438
|
}
|
|
342
439
|
|
|
343
|
-
export async function render(config, args = [], options = {}, log = console.log, { launchBrowser = launch, session } = {}) {
|
|
440
|
+
export async function render(config, args = [], options = {}, log = console.log, { launchBrowser = launch, session, readSystemTheme = systemTheme } = {}) {
|
|
441
|
+
const themes = resolveThemes(options.theme, readSystemTheme);
|
|
442
|
+
options = { ...options, theme: themes.length === 2 ? 'both' : themes[0] };
|
|
344
443
|
if (options.impacted && !session) return withImpacted(config, args, options, 'render', selected =>
|
|
345
444
|
render(config, args, options, log, { launchBrowser, session: selected }));
|
|
346
445
|
const output = options['out-dir'] ? path.resolve(config.root, options['out-dir']) : config.output;
|
|
347
446
|
/** @type {import('./results.mjs').RenderData} */
|
|
348
|
-
const data = { project: config.root, outputDirectory: output, complete: false, impact: session?.selection ?? null, base: null, captures: [], deleted: [] };
|
|
447
|
+
const data = { project: config.root, outputDirectory: output, complete: false, impact: session?.selection ?? null, base: null, themes, captures: [], deleted: [] };
|
|
349
448
|
const warnings = [], completed = [], failures = [];
|
|
350
449
|
let browser, primary;
|
|
351
450
|
try {
|
|
352
451
|
const scale = Number(options.scale ?? 2);
|
|
353
452
|
if (!(Number.isFinite(scale) && scale > 0)) throw new CliError('USAGE_INVALID', 'Invalid --scale; use a positive number');
|
|
354
|
-
const themeOption = options.theme ?? 'both';
|
|
355
|
-
if (!['both', 'light', 'dark'].includes(themeOption)) throw new CliError('USAGE_INVALID', 'Choose --theme=both, light, or dark.');
|
|
356
453
|
if (options['out-dir'] === '') throw new CliError('USAGE_INVALID', 'Set --out-dir to a directory.');
|
|
357
|
-
const themes = themeOption === 'both' ? ['light', 'dark'] : [themeOption];
|
|
358
454
|
let base, additional = [];
|
|
359
455
|
if (!session && options.base !== undefined && (!args.length || args.some(arg => arg.endsWith('.mmd')))) {
|
|
360
456
|
const git = await import('./arch-git.mjs');
|