@whzxc/agent-design-gallery 0.14.0 → 0.15.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 (64) hide show
  1. package/README.md +26 -16
  2. package/package.json +1 -1
  3. package/public/access.css +15 -2
  4. package/public/app.js +708 -483
  5. package/public/arrangement-worker.js +7 -7
  6. package/public/arrangement.js +35 -30
  7. package/public/assets.js +60 -38
  8. package/public/auth.js +59 -4
  9. package/public/boards.js +124 -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 +26 -2
  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 +2 -0
  19. package/public/index.html +13 -9
  20. package/public/instance-actions.js +9 -2
  21. package/public/layout.js +156 -86
  22. package/public/selection.js +1 -1
  23. package/public/style.css +74 -152
  24. package/public/switcher.css +5 -4
  25. package/public/switcher.js +109 -34
  26. package/public/token-catalog.js +8 -3
  27. package/public/tokens.css +14 -1
  28. package/public/view-route.js +0 -1
  29. package/src/boards/board.mjs +30 -0
  30. package/src/boards/token-board.mjs +196 -0
  31. package/src/cli-output.mjs +8 -5
  32. package/src/cli.mjs +49 -29
  33. package/src/comments.mjs +293 -0
  34. package/src/http.mjs +2 -3
  35. package/src/hub/project-link.mjs +41 -0
  36. package/src/hub/registry.mjs +5 -0
  37. package/src/hub.mjs +14 -10
  38. package/src/link.mjs +13 -1
  39. package/src/server.mjs +57 -93
  40. package/src/service.mjs +46 -12
  41. package/src/toolkit/arch.mjs +3 -2
  42. package/src/toolkit/asset-rules.mjs +24 -1
  43. package/src/toolkit/build-worker.mjs +6 -2
  44. package/src/toolkit/build.mjs +4 -2
  45. package/src/toolkit/commands.mjs +12 -7
  46. package/{public/review.js → src/toolkit/diff-document.mjs} +137 -43
  47. package/src/toolkit/diff-inputs.mjs +66 -30
  48. package/src/toolkit/diff.mjs +181 -39
  49. package/src/toolkit/impact-selection.mjs +25 -10
  50. package/src/toolkit/impact.mjs +32 -12
  51. package/src/toolkit/move-pairing.mjs +140 -0
  52. package/src/toolkit/project-index.mjs +2 -2
  53. package/src/toolkit/results.mjs +1 -1
  54. package/src/toolkit/review-document.mjs +435 -0
  55. package/src/toolkit/review-groups.mjs +29 -0
  56. package/src/toolkit/review-observation.mjs +131 -0
  57. package/src/toolkit/review-sheet.mjs +117 -0
  58. package/src/toolkit/review-specimens.mjs +60 -0
  59. package/src/toolkit/review.mjs +140 -0
  60. package/src/toolkit/runtime.mjs +1 -1
  61. package/src/toolkit/theme.mjs +16 -0
  62. package/public/annotations.js +0 -816
  63. package/public/labels.js +0 -122
  64. package/src/annotations.mjs +0 -238
package/public/layout.js CHANGED
@@ -1,4 +1,4 @@
1
- // Pure Float world geometry. Coordinates and gaps are SVG units.
1
+ // Pure board geometry. Board children use local coordinates; items use world coordinates.
2
2
  export function bounds(boxes) {
3
3
  if (!boxes.length) return { x: 0, y: 0, w: 1, h: 1 };
4
4
  const x = Math.min(...boxes.map(b => b.x)), y = Math.min(...boxes.map(b => b.y));
@@ -13,102 +13,172 @@ export function rows(blocks, limit, gapX, gapY, nextWidth) {
13
13
  return placed;
14
14
  });
15
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;}
16
+
17
+ export const boardGeometry = Object.freeze({
18
+ width: 1680, side: 80, top: 64, bottom: 80,
19
+ label: 280, sectionGap: 56, sectionPadding: 48,
20
+ columns: 12, columnGap: 24, rowGap: 32,
21
+ wellX: 24, wellY: 32, wellMinHeight: 96,
22
+ captionGap: 12, metaLine: 17, boardGap: 240, bandGap: 480,
23
+ });
24
+
25
+ const lineCount = (text, width, characterWidth) => String(text ?? '').split('\n')
26
+ .reduce((count, line) => count + Math.max(1, Math.ceil(line.length * characterWidth / width)), 0);
27
+
28
+ export function blockForAsset(asset) {
29
+ const parts = asset.parts.length ? asset.parts : [{ ...asset.full, id: 'full', name: 'Full sheet' }];
30
+ const box = bounds(parts.map(p => ({ x: p.x, y: p.y, w: p.width, h: p.height })));
31
+ const previewCrop = asset.component ? {
32
+ id: 'overview', name: 'All forms', x: box.x - 24, y: box.y - 32,
33
+ width: box.w + 48, height: box.h + 64,
34
+ } : undefined;
35
+ const filename = asset.path.split('/').at(-1);
36
+ return {
37
+ asset: asset.path, path: asset.path, kind: 'flow',
38
+ title: filename === 'index.tsx' ? asset.path.split('/').at(-2) : filename.replace(/\.(tsx|svg|mmd)$/, ''),
39
+ modified: asset.modified, modifiedAt: asset.modifiedAt, previewCrop,
40
+ frames: parts.map(part => ({
41
+ id: part.id, name: part.name, note: part.note, proposed: part.proposed, proposal: part.proposed,
42
+ w: part.width, h: part.height,
43
+ crop: { x: part.x, y: part.y, w: part.width, h: part.height },
44
+ })),
45
+ };
46
+ }
47
+
48
+ // The paint window is bounded by the well padding and neighbouring legacy frames.
49
+ export function specimenPaintCrop(asset, crop) {
50
+ if (asset.layer?.toLowerCase() === 'surfaces' || asset.path.startsWith('surfaces/')) return crop;
51
+ let left = crop.x - 24, right = crop.x + crop.width + 24;
52
+ let top = crop.y - 32, bottom = crop.y + crop.height + 32;
53
+ if (asset.component && asset.format !== 'tsx') for (const other of asset.parts) {
54
+ if (other.id === crop.id) continue;
55
+ if (other.y < bottom && other.y + other.height > top) {
56
+ if (other.x >= crop.x + crop.width) right = Math.min(right, (crop.x + crop.width + other.x) / 2);
57
+ if (other.x + other.width <= crop.x) left = Math.max(left, (crop.x + other.x + other.width) / 2);
58
+ }
59
+ if (other.x < right && other.x + other.width > left) {
60
+ if (other.y >= crop.y + crop.height) bottom = Math.min(bottom, (crop.y + crop.height + other.y) / 2);
61
+ if (other.y + other.height <= crop.y) top = Math.max(top, (crop.y + other.y + other.height) / 2);
33
62
  }
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
63
  }
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);
64
+ return {...crop, x:left, y:top, width:right-left, height:bottom-top};
47
65
  }
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;
66
+
67
+ function layoutSection(section, width, y, columns = boardGeometry.columns) {
68
+ const g = boardGeometry;
69
+ const areaWidth = width - g.side * 2 - g.label - g.sectionGap;
70
+ const columnWidth = (areaWidth + g.columnGap) / columns;
71
+ let column = 0, rowY = g.sectionPadding + 1, rowHeight = 0;
72
+ const frames = section.frames.map(frame => {
73
+ const span = Math.min(columns, Math.max(1, Math.ceil((frame.w + g.wellX * 2 + g.columnGap) / columnWidth)));
74
+ if (column + span > columns) {
75
+ column = 0;
76
+ rowY += rowHeight + g.rowGap;
77
+ rowHeight = 0;
70
78
  }
79
+ const x = g.label + g.sectionGap + column * columnWidth;
80
+ const wellWidth = span * columnWidth - g.columnGap;
81
+ const wellHeight = Math.max(g.wellMinHeight, frame.h + g.wellY * 2);
82
+ const captionHeight = lineCount(frame.name, wellWidth, 7.2) * g.metaLine +
83
+ (frame.note || frame.proposed ? 2 + lineCount([frame.note, frame.proposed && `Proposed: ${frame.proposed}`].filter(Boolean).join(' · '), wellWidth, 6.5) * g.metaLine : 0);
84
+ const well = { x, y: rowY, w: wellWidth, h: wellHeight };
85
+ const caption = { x, y: rowY + wellHeight + g.captionGap, w: wellWidth, h: captionHeight };
86
+ rowHeight = Math.max(rowHeight, wellHeight + g.captionGap + captionHeight);
87
+ column += span;
88
+ return { ...frame, span, x: x + (wellWidth - frame.w) / 2, y: rowY + (wellHeight - frame.h) / 2, well, caption };
89
+ });
90
+ const labelHeight = lineCount(section.title, g.label, 12) * 28 + 20 +
91
+ lineCount(section.path, g.label - 18, 6.6) * 18 + (section.modified || section.modifiedAt ? 26 : 0);
92
+ const contentHeight = frames.length ? rowY - g.sectionPadding - 1 + rowHeight : 0;
93
+ return { ...section, x: g.side, y, w: width - g.side * 2,
94
+ h: 1 + g.sectionPadding * 2 + Math.max(labelHeight, contentHeight),
95
+ label: { x: 0, y: g.sectionPadding + 1, w: g.label, h: labelHeight },
96
+ specimenArea: { x: g.label + g.sectionGap, y: g.sectionPadding + 1, w: areaWidth, h: contentHeight },
97
+ frames,
98
+ };
99
+ }
100
+
101
+ function layoutBoardAtWidth(board, w, columns) {
102
+ const g = boardGeometry;
103
+ const headerHeight = 28 + 16 + lineCount(board.title, Math.max(1, w - g.side * 2 - 440 - 64), 26) * 56 + 56;
104
+ let y = g.top + headerHeight;
105
+ const blocks = board.blocks.map(section => {
106
+ const placed = layoutSection(section, w, y, columns);
107
+ y += placed.h;
108
+ return placed;
109
+ });
110
+ return { ...board, w, h: y + g.bottom,
111
+ header: { x: g.side, y: g.top, w: w - g.side * 2, h: headerHeight },
112
+ sourceCount: blocks.length, frameCount: blocks.reduce((sum, section) => sum + section.frames.length, 0), blocks,
113
+ };
114
+ }
115
+
116
+ function layoutBoard(board) {
117
+ const g = boardGeometry;
118
+ const baseArea = g.width - g.side * 2 - g.label - g.sectionGap;
119
+ const widest = Math.max(0, ...board.blocks.flatMap(section => section.frames.map(frame => frame.w + g.wellX * 2)));
120
+ const initialWidth = Math.max(g.width, g.side * 2 + g.label + g.sectionGap + widest);
121
+ let result = layoutBoardAtWidth(board, initialWidth, g.columns);
122
+ for (let multiplier = 2; multiplier <= 4 && result.h > 2 * result.w; multiplier++) {
123
+ result = layoutBoardAtWidth(board, initialWidth + (multiplier - 1) * (baseArea + g.columnGap), g.columns * multiplier);
71
124
  }
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;
125
+ return result;
126
+ }
127
+
128
+ function placeColumns(boards, count, previous = []) {
129
+ const g = boardGeometry;
130
+ const heights = Array(count).fill(0), widths = Array(count).fill(0);
131
+ const oldByKey = new Map(previous.map(board => [board.key, board]));
132
+ const placed = boards.map(board => {
133
+ const old = oldByKey.get(board.key);
134
+ const column = Number.isInteger(old?.column) && old.column < count
135
+ ? old.column : heights.indexOf(Math.min(...heights));
136
+ const y = heights[column];
137
+ heights[column] += board.h + g.boardGap;
138
+ widths[column] = Math.max(widths[column], board.w, old?.columnWidth ?? 0);
139
+ return { ...board, column, y };
140
+ });
141
+ // Retain column widths across saves so shrinking a board does not move its neighbours.
142
+ for (const old of previous) if (old.column < count) widths[old.column] = Math.max(widths[old.column], old.columnWidth ?? old.w);
143
+ const lefts = [];
144
+ let x = 0;
145
+ for (const width of widths) { lefts.push(x); x += width + g.boardGap; }
146
+ return placed.map(board => ({ ...board, x: lefts[board.column], columnWidth: widths[board.column], columnCount: count }));
77
147
  }
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 });
148
+
149
+ export function layoutWorld(input, { previousGroups = [] } = {}) {
150
+ const bands = new Map();
151
+ for (const [index, source] of input.entries()) {
152
+ const board = layoutBoard({ ...source, key: source.key ?? `${source.layer ?? ''}:${source.title ?? index}` });
153
+ if (!bands.has(board.layer)) bands.set(board.layer, []);
154
+ bands.get(board.layer).push(board);
155
+ }
156
+ const result = [];
157
+ let bandY = 0;
158
+ for (const [layer, boards] of bands) {
159
+ const previous = previousGroups.filter(board => board.layer === layer && Number.isInteger(board.column));
160
+ let placed;
161
+ if (previous.length) {
162
+ placed = placeColumns(boards, Math.max(...previous.map(board => board.columnCount ?? board.column + 1)), previous);
163
+ } else {
164
+ let distance = Infinity;
165
+ for (let count = 1; count <= boards.length; count++) {
166
+ const candidate = placeColumns(boards, count);
167
+ const box = bounds(candidate);
168
+ const score = Math.abs(box.w / box.h - 16 / 10);
169
+ if (score < distance) { placed = candidate; distance = score; }
170
+ }
171
+ }
172
+ result.push(...placed.map(board => ({ ...board, y: board.y + bandY, bandY })));
173
+ bandY += bounds(placed).h + boardGeometry.bandGap;
89
174
  }
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
- }) }));
175
+ return result;
96
176
  }
177
+
97
178
  export function componentWrapWidth(parts) {
98
- const area = parts.reduce((sum, part) => sum + (part.width + 32) * (part.height + 48), 0);
179
+ const area = parts.reduce((sum, part) => sum + (part.width + 48) * (part.height + 64), 0);
99
180
  return Math.min(6400, Math.max(1600, Math.ceil(Math.sqrt(area * 1.6))));
100
181
  }
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
182
  export function fitArea(width, height, sidebar = true, inspector = false) {
113
183
  const left = (sidebar ? 272 : 0) + 20, right = width - (inspector ? 312 : 0) - 24;
114
184
  return { x: left, y: 100, width: Math.max(1, right - left), height: Math.max(1, height - 184) };
@@ -10,7 +10,7 @@ export function hitSelection(assets, x, y, elements = true) {
10
10
  const part = asset.parts.find(p => (asset.component || p.id === crop.id) && contains(frameBox(asset,p), x,y));
11
11
  if (!part) return {asset, part:asset.component ? null : asset.parts.find(p=>p.id===crop.id)};
12
12
  const box = frameBox(asset,part);
13
- const element = elements ? [...(part.elements ?? [])].reverse().find(e => contains(e,x-box.x,y-box.y)) : null;
13
+ const element = elements ? part.elements?.findLast(e => !e.commentOnly && contains(e,x-box.x,y-box.y)) : null;
14
14
  return {asset, part, element};
15
15
  }
16
16
  return null;