@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.
Files changed (111) hide show
  1. package/README.md +29 -16
  2. package/package.json +2 -1
  3. package/public/access.css +15 -2
  4. package/public/app.js +1284 -521
  5. package/public/arrangement-worker.js +7 -7
  6. package/public/arrangement.js +35 -30
  7. package/public/assets.js +85 -48
  8. package/public/auth.js +59 -4
  9. package/public/boards.js +129 -0
  10. package/public/comment-anchors.js +50 -0
  11. package/public/comments.css +400 -0
  12. package/public/comments.js +1106 -0
  13. package/public/context-menu.js +97 -0
  14. package/public/frame-identity.js +51 -14
  15. package/public/hub.css +25 -3
  16. package/public/hub.html +10 -2
  17. package/public/hub.js +127 -23
  18. package/public/icons.js +9 -0
  19. package/public/index.html +26 -10
  20. package/public/instance-actions.js +9 -2
  21. package/public/layout.js +156 -86
  22. package/public/motion-flow.js +28 -0
  23. package/public/motion-identity.js +100 -0
  24. package/public/motion-paint.js +332 -0
  25. package/public/motion-scene.js +165 -0
  26. package/public/motion-specimens.js +335 -0
  27. package/public/player.css +270 -0
  28. package/public/player.js +753 -0
  29. package/public/recent-updates.js +535 -0
  30. package/public/selection.js +1 -1
  31. package/public/style.css +91 -154
  32. package/public/switcher.css +5 -4
  33. package/public/switcher.js +109 -34
  34. package/public/token-catalog.js +8 -3
  35. package/public/tokens.css +20 -1
  36. package/public/view-boards.css +131 -0
  37. package/public/view-boards.js +350 -0
  38. package/public/view-route.js +1 -2
  39. package/src/boards/board.mjs +30 -0
  40. package/src/boards/motion-board.mjs +202 -0
  41. package/src/boards/token-board.mjs +200 -0
  42. package/src/cli-output.mjs +10 -5
  43. package/src/cli.mjs +89 -35
  44. package/src/comments.mjs +293 -0
  45. package/src/http.mjs +7 -5
  46. package/src/hub/project-link.mjs +41 -0
  47. package/src/hub/registry.mjs +5 -0
  48. package/src/hub.mjs +14 -10
  49. package/src/link.mjs +13 -1
  50. package/src/recent-frames.mjs +295 -0
  51. package/src/recent-history.mjs +100 -0
  52. package/src/recent-job.mjs +63 -0
  53. package/src/recent-worker.mjs +171 -0
  54. package/src/server.mjs +285 -110
  55. package/src/service.mjs +46 -12
  56. package/src/toolkit/arch-git.mjs +8 -14
  57. package/src/toolkit/arch.mjs +3 -2
  58. package/src/toolkit/asset-rules.mjs +24 -1
  59. package/src/toolkit/browser.mjs +1 -13
  60. package/src/toolkit/build-store.mjs +9 -1
  61. package/src/toolkit/build-worker.mjs +6 -0
  62. package/src/toolkit/build.mjs +22 -16
  63. package/src/toolkit/commands.mjs +105 -9
  64. package/src/toolkit/compare.mjs +13 -11
  65. package/src/toolkit/config.mjs +2 -2
  66. package/{public/review.js → src/toolkit/diff-document.mjs} +137 -43
  67. package/src/toolkit/diff-inputs.mjs +97 -52
  68. package/src/toolkit/diff.mjs +198 -43
  69. package/src/toolkit/frame-declarations.mjs +36 -0
  70. package/src/toolkit/git-blobs.mjs +50 -0
  71. package/src/toolkit/impact-inputs.mjs +11 -19
  72. package/src/toolkit/impact-selection.mjs +27 -12
  73. package/src/toolkit/impact.mjs +49 -15
  74. package/src/toolkit/implementation-map.mjs +17 -6
  75. package/src/toolkit/input-generation.mjs +15 -0
  76. package/src/toolkit/inspect-output.mjs +1 -1
  77. package/src/toolkit/inspect.d.ts +9 -1
  78. package/src/toolkit/inspect.mjs +25 -1
  79. package/src/toolkit/motion-check.mjs +382 -0
  80. package/src/toolkit/motion-css.mjs +105 -0
  81. package/src/toolkit/motion-flows.mjs +95 -0
  82. package/src/toolkit/motion-impact.mjs +87 -0
  83. package/src/toolkit/motion-inventory.mjs +202 -0
  84. package/src/toolkit/motion-label.mjs +111 -0
  85. package/src/toolkit/motion-patterns.mjs +216 -0
  86. package/src/toolkit/motion-primitives.mjs +94 -0
  87. package/src/toolkit/motion-queries.mjs +169 -0
  88. package/src/toolkit/motion.mjs +300 -0
  89. package/src/toolkit/move-pairing.mjs +140 -0
  90. package/src/toolkit/owner.mjs +19 -6
  91. package/src/toolkit/play-endpoint.mjs +66 -0
  92. package/src/toolkit/project-index.mjs +4 -4
  93. package/src/toolkit/recent-structure.mjs +201 -0
  94. package/src/toolkit/results.mjs +3 -3
  95. package/src/toolkit/review-document.mjs +440 -0
  96. package/src/toolkit/review-embed-document.mjs +671 -0
  97. package/src/toolkit/review-filmstrip.mjs +76 -0
  98. package/src/toolkit/review-groups.mjs +29 -0
  99. package/src/toolkit/review-motion-card.mjs +51 -0
  100. package/src/toolkit/review-motion.mjs +159 -0
  101. package/src/toolkit/review-observation.mjs +131 -0
  102. package/src/toolkit/review-playback.js +123 -0
  103. package/src/toolkit/review-sheet.mjs +125 -0
  104. package/src/toolkit/review-specimens.mjs +60 -0
  105. package/src/toolkit/review.mjs +240 -0
  106. package/src/toolkit/runtime.mjs +8 -2
  107. package/src/toolkit/theme.mjs +16 -0
  108. package/src/viewer-cache.mjs +48 -12
  109. package/public/annotations.js +0 -816
  110. package/public/labels.js +0 -122
  111. package/src/annotations.mjs +0 -238
@@ -0,0 +1,66 @@
1
+ import { edgePresentation } from './motion-label.mjs';
2
+ import path from 'node:path';
3
+ import { existsSync } from 'node:fs';
4
+ import { frameKey, motionFlows } from './motion-flows.mjs';
5
+ import { readMotion, resolveMotionToken, timingRefs } from './motion.mjs';
6
+ import { relative, loadTokens } from './project.mjs';
7
+ import { CliError } from '../cli-output.mjs';
8
+
9
+ // The server has already resolved the requested name against its current TSX inventory.
10
+ export function sourceMotion(config, root, source) {
11
+ const owner = relative(config, path.join(root, source));
12
+ const sidecar = path.join(root, source.replace(/\.tsx$/, '.motion.json'));
13
+ const graph = readMotion(config, existsSync(sidecar) ? [sidecar] : []);
14
+ return {
15
+ records: graph.records.filter(r => r.valid && r.edge.from.source === owner),
16
+ declarations: graph.declarations
17
+ };
18
+ }
19
+ export function playbackGraph(config, root, owners, inventory) {
20
+ const records = [], declarations = [];
21
+ for (const source of [...owners.keys()].sort()) {
22
+ const indexed = owners.get(source);
23
+ if (indexed.error) continue;
24
+ try {
25
+ indexed.motion ??= sourceMotion(config, root, source);
26
+ records.push(...indexed.motion.records);
27
+ declarations.push(...indexed.motion.declarations);
28
+ } catch (error) {
29
+ indexed.error = error;
30
+ }
31
+ }
32
+ const design = relative(config, root);
33
+ const prefix = design ? design + '/' : '';
34
+ const available = (ref) => ref.source.startsWith(prefix) && inventory.has(ref.source.slice(prefix.length));
35
+ const playable = records.filter(({ edge }) => available(edge.from) && available(edge.to));
36
+ return { records, flows: motionFlows(playable, declarations).byFrame };
37
+ }
38
+
39
+ export async function playEndpoint(config, root, source, frame, theme, build, graph) {
40
+ const ref = { source: relative(config, path.join(root, source)), frame };
41
+ const records = graph.records.filter(r => r.edge.from.source === ref.source && r.edge.from.frame === frame);
42
+ const built = await build(source),
43
+ endpoint = built.frames.find((f) => f.name === frame);
44
+ if (!endpoint) throw new CliError('FRAME_NOT_FOUND', 'Unknown playback frame.');
45
+ const tokens = loadTokens(config),
46
+ design = relative(config, root);
47
+ const edges = records.map(({ edge }) => playbackEdge(edge, endpoint, tokens, theme, design));
48
+ return {
49
+ design,
50
+ source,
51
+ frame,
52
+ html: endpoint.html,
53
+ css: built.css,
54
+ width: endpoint.width,
55
+ height: endpoint.height,
56
+ edges,
57
+ flow: graph.flows.get(frameKey(ref)) ?? null
58
+ };
59
+ }
60
+
61
+ export function playbackEdge(edge, endpoint, tokens, theme, design) {
62
+ const timings = Object.fromEntries(timingRefs(edge).map(({ pointer, name, kind }) =>
63
+ [pointer, resolveMotionToken(tokens, theme, name, kind).value]));
64
+ if (Object.values(timings).includes(null)) throw Error('Unresolved timing on ' + edge.id + '. Run adg check.');
65
+ return { ...edge, ...edgePresentation(edge, endpoint.html, design), authoredLabel: !!edge.label, timings };
66
+ }
@@ -47,7 +47,7 @@ async function resolutionFiles(config, artifactDirectory) {
47
47
  return files.sort();
48
48
  }
49
49
 
50
- export async function openProjectIndex(config, { stateDirectory = defaultStateDirectory, persist = true, fresh = false, artifactDirectory } = {}) {
50
+ export async function openProjectIndex(config, { stateDirectory = defaultStateDirectory, persist = true, fresh = false, frameOrigins = false, artifactDirectory } = {}) {
51
51
  const inventory = discoverProject(config), root = await realpath(config.root), buildPromises = new Map();
52
52
  const directory = path.join(stateDirectory, 'cache', indexDigest(root), 'index-v1');
53
53
  const shards = await createIndexStore({ directory, persist });
@@ -91,7 +91,7 @@ export async function openProjectIndex(config, { stateDirectory = defaultStateDi
91
91
  if (!materializations.has(source)) {
92
92
  requestedSources.add(source); freshPool ??= new BuildPool();
93
93
  materializations.set(source, freshPool.run({ config: { root, design: physicalDesign ?? config.design, output: config.output,
94
- sources: config.sources, arch: config.arch, check: config.check, allowLegacy: false },
94
+ sources: config.sources, arch: config.arch, check: config.check, allowLegacy: false, frameOrigins },
95
95
  name: path.relative(physicalDesign ?? config.design, path.join(root, source)).split(path.sep).join('/') }, new AbortController().signal).then(built => {
96
96
  observeDependencies(built);
97
97
  for (const frame of built.frames) frame.document = theme => frameDocument(frame, theme, built.css);
@@ -184,8 +184,8 @@ export async function openProjectIndex(config, { stateDirectory = defaultStateDi
184
184
  try { text = await readFile(path.join(config.root, side), 'utf8'); } catch (error) { if (error.code !== 'ENOENT') throw error; }
185
185
  return cached('architecture', { source, text }, () => ({ source, sidecar: side, ...sidecar(text) }));
186
186
  },
187
- async relationships({ facts: supplied, projectPaths = false } = {}) {
188
- const assets = await Promise.all(inventory.tsx.map(async source => {
187
+ async relationships({ facts: supplied, projectPaths = false, sources = inventory.tsx } = {}) {
188
+ const assets = await Promise.all(sources.map(async source => {
189
189
  const facts = supplied?.get(source) ?? await this.source(source);
190
190
  if (projectPaths) return { path: source, imports: facts.imports };
191
191
  const designRelative = file => path.relative(config.design, path.join(config.root, file)).split(path.sep).join('/');
@@ -0,0 +1,201 @@
1
+ import { declarations } from './frame-declarations.mjs';
2
+ import path from 'node:path';
3
+ import { liveDependencies } from './input-generation.mjs';
4
+ import { readFile } from 'node:fs/promises';
5
+ import { prepareImpactInputs } from './impact-inputs.mjs';
6
+ import { canonicalBytes } from './impact-proof.mjs';
7
+ import { impact } from './impact.mjs';
8
+ import { openProjectIndex } from './project-index.mjs';
9
+ import { readGroups, relative, sourceFeature } from './project.mjs';
10
+
11
+ function inventoryMoves(rows, renames, complete) {
12
+ const removed = rows.filter((r) => r.status === 'removed'),
13
+ added = rows.filter((r) => r.status === 'added');
14
+ const paired = new Map(),
15
+ consumed = new Set();
16
+ // Git source rename plus stable frame name wins even when several sources use that name.
17
+ // Otherwise a name must occur only once in each complete endpoint inventory.
18
+ const afterById = new Map(added.map((r) => [JSON.stringify([r.source, r.frame]), r]));
19
+ for (const old of removed) {
20
+ const next = afterById.get(JSON.stringify([renames.get(old.source), old.frame]));
21
+ if (next) {
22
+ paired.set(next, old);
23
+ consumed.add(old);
24
+ }
25
+ }
26
+ if (!complete) return { paired, consumed };
27
+ const before = new Map(),
28
+ after = new Map();
29
+ for (const row of rows) {
30
+ if (row.before) before.set(row.frame, before.has(row.frame) ? null : row);
31
+ if (row.after) after.set(row.frame, after.has(row.frame) ? null : row);
32
+ }
33
+ for (const old of removed) {
34
+ const next = after.get(old.frame);
35
+ if (!consumed.has(old) && before.get(old.frame) === old && next?.status === 'added' && !paired.has(next)) {
36
+ paired.set(next, old);
37
+ consumed.add(old);
38
+ }
39
+ }
40
+ return { paired, consumed };
41
+ }
42
+
43
+ export async function structuralChanges(config, options) {
44
+ const started = performance.now();
45
+ const inputs = await prepareImpactInputs(config, options);
46
+ // An immutable documentation-only range outside both design and architecture trees
47
+ // has identical source inputs. Config imports and the effective capture policy still count.
48
+ const endpoints = [inputs.session.before, inputs.session.after];
49
+ const policy = ({ config: c }) =>
50
+ canonicalBytes({
51
+ sources: c.sources,
52
+ design: relative(c, c.design),
53
+ arch: c.arch && relative(c, c.arch),
54
+ check: c.check,
55
+ diff: c.diff
56
+ });
57
+ if (
58
+ options.head &&
59
+ !inputs.session.globalChanges.length &&
60
+ policy(endpoints[0]) === policy(endpoints[1]) &&
61
+ inputs.session.changes
62
+ .flatMap((c) => [c.before, c.after])
63
+ .filter(Boolean)
64
+ .every(
65
+ (file) =>
66
+ /\.(md|txt)$/i.test(file) &&
67
+ endpoints.every(
68
+ ({ config: c, sources }) =>
69
+ !sources.has(file) &&
70
+ !file.startsWith(relative(c, c.design) + '/') &&
71
+ !(c.arch && file.startsWith(relative(c, c.arch) + '/'))
72
+ )
73
+ )
74
+ ) {
75
+ await inputs.close();
76
+ return {
77
+ rows: [],
78
+ globalCauses: [],
79
+ dependencies: [],
80
+ failures: [],
81
+ complete: true,
82
+ timings: { prepareMs: performance.now() - started }
83
+ };
84
+ }
85
+ let projection;
86
+ const { data } = await impact(
87
+ config,
88
+ { ...options, json: true },
89
+ {
90
+ prepareInputs: async () => inputs,
91
+ tolerateSourceFailures: true,
92
+ openIndex: (config, opts) => openProjectIndex(config, { ...opts, frameOrigins: true }),
93
+ async consume({ views, rows, data, assessments, inputs }) {
94
+ const facts = new Map(data.facts.map((f) => [f.id, f]));
95
+ const globalCauses = [
96
+ ...new Set(
97
+ data.changes.filter((c) => ['config', 'environment'].includes(c.role)).map((c) => c.after ?? c.before)
98
+ )
99
+ ].sort();
100
+ const changed = new Set(
101
+ data.facts.filter((f) => ['source', 'architecture'].includes(f.kind)).map((f) => f.source)
102
+ );
103
+ const sides = await Promise.all(
104
+ views.map(async (view) => {
105
+ const { config } = view,
106
+ code = new Map(),
107
+ chapters = new Map();
108
+ for (const group of readGroups(config.design, config.sources))
109
+ for (const file of group.assets)
110
+ chapters.set(relative(config, path.join(config.design, file)), group.title);
111
+ for (const file of changed) {
112
+ if (!file?.endsWith('.tsx') || !view.index.inventory.tsx.includes(file)) continue;
113
+ if (data.failures.some((f) => f.source === file)) continue;
114
+ code.set(file, declarations(await readFile(path.join(config.root, file), 'utf8')));
115
+ }
116
+ const frames = new Map();
117
+ for (const [source, built] of view.built)
118
+ frames.set(source, new Map(built.frames.map((f) => [f.name, f])));
119
+ const feature = (file) =>
120
+ sourceFeature(path.posix.relative(relative(config, config.design), file), config.sources);
121
+ return { code, chapters, frames, feature };
122
+ })
123
+ );
124
+ const result = [];
125
+ const renames = new Map(inputs.session.renames.map((r) => [r.before, r.after]));
126
+ const { paired, consumed } = inventoryMoves(rows, renames, !data.failures.length);
127
+ const changedPaths = new Set(inputs.session.changes.flatMap((c) => [c.before, c.after]));
128
+ for (const row of rows) {
129
+ if (consumed.has(row)) continue;
130
+ const { source, frame } = row,
131
+ entry = { source, frame, status: row.status };
132
+ const chapter = sides[row.after ? 1 : 0].chapters.get(source);
133
+ if (chapter) entry.chapter = chapter;
134
+ if (row.status !== 'matched') {
135
+ const old = paired.get(row);
136
+ if (old) Object.assign(entry, { status: 'moved', former: { source: old.source, frame: old.frame } });
137
+ result.push(entry);
138
+ continue;
139
+ }
140
+ const causes = new Set();
141
+ const inputsChanged = ['light', 'dark']
142
+ .map((t) => assessments.get(JSON.stringify([source, frame, t])))
143
+ .filter((a) => a && a.disposition !== 'proven_unaffected');
144
+ for (const assessment of inputsChanged)
145
+ for (const reason of assessment.reasons) {
146
+ const fact = facts.get(reason.fact);
147
+ if (!fact?.source || reason.scope === 'support') continue;
148
+ if (
149
+ fact.source !== source &&
150
+ ['token', 'source', 'global_css'].includes(fact.kind) &&
151
+ (fact.kind !== 'global_css' ||
152
+ views.some((v) => v.facts.get(source)?.dependencies.includes(fact.source)))
153
+ )
154
+ causes.add(fact.source);
155
+ if (fact.kind === 'architecture')
156
+ for (const i of fact.pathIndexes) {
157
+ const file = path.posix.relative(
158
+ inputs.projectPrefix || '.',
159
+ data.changes[i].after ?? data.changes[i].before
160
+ );
161
+ if (file !== source) causes.add(file);
162
+ }
163
+ }
164
+ const [old, current] = sides.map((s) => s.frames.get(source)?.get(frame));
165
+ const fragments = sides.map((side, i) => {
166
+ const declared = i ? current : old,
167
+ loc = declared?.declaration;
168
+ return loc && side.code.get(loc.source)?.site(loc);
169
+ });
170
+ let direct = fragments[0] !== fragments[1];
171
+ const owners = [...(row.before.parts ?? []), ...(row.after.parts ?? [])];
172
+ for (const { source: file, part } of owners) {
173
+ if (!changed.has(file)) continue;
174
+ if (sides[0].code.get(file)?.part(part) === sides[1].code.get(file)?.part(part)) continue;
175
+ if (sides[1].feature(file) === sides[1].feature(source)) direct = true;
176
+ }
177
+ // Generated values or a local unexported helper can change the individual
178
+ // frame while the JSX at its call site stays the same. Ignore sheet-wide CSS.
179
+ const ownChanged = changedPaths.has(source);
180
+ if (ownChanged && !causes.size && (source.endsWith('.mmd') || localFrame(old) !== localFrame(current)))
181
+ direct = true;
182
+ if (!direct && !causes.size) continue;
183
+ result.push({ ...entry, status: 'changed', ...(!direct ? { causes: [...causes].sort() } : {}) });
184
+ }
185
+ projection = {
186
+ rows: result,
187
+ globalCauses,
188
+ complete: !data.failures.length,
189
+ failures: data.failures,
190
+ dependencies: await liveDependencies(views, options.temporaryDirectory)
191
+ };
192
+ }
193
+ }
194
+ );
195
+ return { ...projection, timings: { ...data.timings, totalMs: performance.now() - started } };
196
+ }
197
+ function localFrame(frame) {
198
+ if (!frame) return '';
199
+ const { declaration, document, ...props } = frame;
200
+ return JSON.stringify(props);
201
+ }
@@ -3,10 +3,10 @@ import { CliError, classifyError } from '../cli-output.mjs';
3
3
  /** @typedef {'light' | 'dark'} Theme */
4
4
  /** @typedef {{source: string | null, frame: string | null, theme: Theme | null, line: number | null, column: number | null}} Location */
5
5
  /** @typedef {Location & {code: string, message: string}} Finding */
6
- /** @typedef {{project: string, readOnly: boolean, complete: boolean, impact: object | null, sources: string[], summary: {sources: number, frames: number, evaluations: number, problems: number}, findings: Finding[]}} CheckData */
6
+ /** @typedef {{project: string, readOnly: boolean, complete: boolean, impact: object | null, sources: string[], summary: {sources: number, frames: number, evaluations: number, problems: number}, findings: Finding[], motionPatterns?: {animations: number, unmapped: number, unused: number, findings: number, omitted: number}}} CheckData */
7
7
  /** @typedef {{source: string, frame: string, theme: Theme, path: string, scale: number, width: number, height: number, pixelWidth: number, pixelHeight: number}} Capture */
8
- /** @typedef {{project: string, outputDirectory: string, complete: boolean, impact: object | null, base: {rev: string, sha: string} | null, captures: Capture[], deleted: string[]}} RenderData */
9
- /** @typedef {{source: string, frame: string, fixture: string, theme: Theme, settled: boolean, size: {design: [number, number], implementation: [number, number]}, matched: number, offBy2px: {text: string, dx: number, dy: number, dw: number, off: number}[], missing: string[], extra: string[], paths: {design: string, implementation: string, overlay: string, report: string, html: string}}} Comparison */
8
+ /** @typedef {{project: string, outputDirectory: string, complete: boolean, impact: object | null, base: {rev: string, sha: string} | null, themes: Theme[], captures: Capture[], deleted: string[]}} RenderData */
9
+ /** @typedef {{source: string, frame: string, fixture: string, theme: Theme, settled: boolean, size: {design: [number, number], implementation: [number, number]}, matched: number, offBy2px: {text: string, dx: number, dy: number, dw: number, off: number}[], missing: string[], extra: string[], paths: {design?: string, implementation?: string, overlay?: string, report: string, html: string}}} Comparison */
10
10
  /** @typedef {{project: string, complete: boolean, all: boolean, comparisons: Comparison[], skipped: {source: string, frame: string, reason: 'no_fixture'}[], summary: {frames: number, matched: number, offsets: number, missing: number, extra: number}, indexPath: string | null, summaryPath: string | null}} CompareData */
11
11
 
12
12
  /**