@whzxc/agent-design-gallery 0.15.0 → 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 (76) hide show
  1. package/README.md +5 -2
  2. package/package.json +2 -1
  3. package/public/app.js +602 -64
  4. package/public/assets.js +25 -10
  5. package/public/boards.js +8 -3
  6. package/public/frame-identity.js +25 -12
  7. package/public/icons.js +7 -0
  8. package/public/index.html +14 -2
  9. package/public/motion-flow.js +28 -0
  10. package/public/motion-identity.js +100 -0
  11. package/public/motion-paint.js +332 -0
  12. package/public/motion-scene.js +165 -0
  13. package/public/motion-specimens.js +335 -0
  14. package/public/player.css +270 -0
  15. package/public/player.js +753 -0
  16. package/public/recent-updates.js +535 -0
  17. package/public/style.css +17 -2
  18. package/public/tokens.css +6 -0
  19. package/public/view-boards.css +131 -0
  20. package/public/view-boards.js +350 -0
  21. package/public/view-route.js +1 -1
  22. package/src/boards/motion-board.mjs +202 -0
  23. package/src/boards/token-board.mjs +9 -5
  24. package/src/cli-output.mjs +3 -1
  25. package/src/cli.mjs +52 -18
  26. package/src/http.mjs +5 -2
  27. package/src/recent-frames.mjs +295 -0
  28. package/src/recent-history.mjs +100 -0
  29. package/src/recent-job.mjs +63 -0
  30. package/src/recent-worker.mjs +171 -0
  31. package/src/server.mjs +229 -18
  32. package/src/toolkit/arch-git.mjs +8 -14
  33. package/src/toolkit/browser.mjs +1 -13
  34. package/src/toolkit/build-store.mjs +9 -1
  35. package/src/toolkit/build-worker.mjs +6 -0
  36. package/src/toolkit/build.mjs +22 -16
  37. package/src/toolkit/commands.mjs +93 -2
  38. package/src/toolkit/compare.mjs +13 -11
  39. package/src/toolkit/config.mjs +2 -2
  40. package/src/toolkit/diff-inputs.mjs +35 -26
  41. package/src/toolkit/diff.mjs +24 -11
  42. package/src/toolkit/frame-declarations.mjs +36 -0
  43. package/src/toolkit/git-blobs.mjs +50 -0
  44. package/src/toolkit/impact-inputs.mjs +11 -19
  45. package/src/toolkit/impact-selection.mjs +2 -2
  46. package/src/toolkit/impact.mjs +17 -3
  47. package/src/toolkit/implementation-map.mjs +17 -6
  48. package/src/toolkit/input-generation.mjs +15 -0
  49. package/src/toolkit/inspect-output.mjs +1 -1
  50. package/src/toolkit/inspect.d.ts +9 -1
  51. package/src/toolkit/inspect.mjs +25 -1
  52. package/src/toolkit/motion-check.mjs +382 -0
  53. package/src/toolkit/motion-css.mjs +105 -0
  54. package/src/toolkit/motion-flows.mjs +95 -0
  55. package/src/toolkit/motion-impact.mjs +87 -0
  56. package/src/toolkit/motion-inventory.mjs +202 -0
  57. package/src/toolkit/motion-label.mjs +111 -0
  58. package/src/toolkit/motion-patterns.mjs +216 -0
  59. package/src/toolkit/motion-primitives.mjs +94 -0
  60. package/src/toolkit/motion-queries.mjs +169 -0
  61. package/src/toolkit/motion.mjs +300 -0
  62. package/src/toolkit/owner.mjs +19 -6
  63. package/src/toolkit/play-endpoint.mjs +66 -0
  64. package/src/toolkit/project-index.mjs +2 -2
  65. package/src/toolkit/recent-structure.mjs +201 -0
  66. package/src/toolkit/results.mjs +2 -2
  67. package/src/toolkit/review-document.mjs +9 -4
  68. package/src/toolkit/review-embed-document.mjs +671 -0
  69. package/src/toolkit/review-filmstrip.mjs +76 -0
  70. package/src/toolkit/review-motion-card.mjs +51 -0
  71. package/src/toolkit/review-motion.mjs +159 -0
  72. package/src/toolkit/review-playback.js +123 -0
  73. package/src/toolkit/review-sheet.mjs +36 -28
  74. package/src/toolkit/review.mjs +131 -31
  75. package/src/toolkit/runtime.mjs +7 -1
  76. package/src/viewer-cache.mjs +48 -12
@@ -0,0 +1,131 @@
1
+ #view-board {
2
+ position: absolute;
3
+ inset: var(--view-board-top, 64px) 0 0;
4
+ overflow: auto;
5
+ overscroll-behavior: contain;
6
+ outline: none;
7
+ }
8
+ .view-board-page { max-width: 1680px; margin: 0 auto; padding: 28px clamp(16px, 4vw, 64px) 64px; }
9
+ .view-board-heading { display: flex; align-items: center; gap: 18px; margin-bottom: 24px; }
10
+ .view-board-heading h1 { font-size: clamp(23px, 3vw, 34px); letter-spacing: -.025em; }
11
+ #view-board-content { display: grid; gap: 16px; }
12
+ .view-board-section { min-width: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-panel); padding: 20px; }
13
+ .view-section-heading { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
14
+ .view-section-heading > div { min-width: 0; }
15
+ .view-section-heading h2 { overflow-wrap: anywhere; }
16
+ .view-board-status { color: var(--text-secondary); font-size: var(--text-body); }
17
+ .view-board-action {
18
+ display: inline-flex;
19
+ align-items: center;
20
+ gap: 6px;
21
+ min-height: var(--control-size);
22
+ padding: 0 10px;
23
+ background: var(--surface-sunken);
24
+ border-radius: var(--radius-row);
25
+ font-weight: 550;
26
+ }
27
+ .view-board-action:hover { color: var(--accent); }
28
+ .recent-ranges { display: flex; flex-wrap: wrap; gap: 4px; }
29
+ .recent-ranges > button:enabled[aria-pressed="false"]:hover {
30
+ background: color-mix(in srgb, var(--text) 6%, transparent);
31
+ }
32
+ .recent-ranges > button:disabled { background: transparent; }
33
+ .recent-period > header { align-items: start; }
34
+ .recent-period > header > div { flex: 1 1 240px; }
35
+ .recent-global { margin-top: 5px; }
36
+ .recent-global summary { display: flex; align-items: center; white-space: nowrap; cursor: pointer; }
37
+ .recent-global summary::before {
38
+ content: '';
39
+ flex: none;
40
+ width: 5px;
41
+ height: 5px;
42
+ margin: 0 8px 0 2px;
43
+ border: solid currentColor;
44
+ border-width: 0 1px 1px 0;
45
+ transform: rotate(-45deg);
46
+ }
47
+ .recent-global[open] summary::before { transform: translateY(-1px) rotate(45deg); }
48
+ .recent-global-sample { margin-inline-start: .3em; overflow: hidden; text-overflow: ellipsis; }
49
+ .recent-global-list {
50
+ display: grid;
51
+ grid-template-columns: repeat(auto-fit, minmax(min(100%, 190px), 1fr));
52
+ gap: 12px 20px;
53
+ margin-top: 9px;
54
+ overflow-wrap: anywhere;
55
+ }
56
+ .recent-global-list ul { margin: 3px 0 0; padding-inline-start: 18px; color: var(--text-secondary); font-size: var(--text-meta); }
57
+ .recent-source { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border); }
58
+ .view-source-name { font: var(--text-meta)/1.45 var(--font-mono); color: var(--text-secondary); overflow-wrap: anywhere; }
59
+ .recent-source-heading { margin-bottom: 12px; color: var(--text); }
60
+ .recent-frame-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 222px), 1fr)); align-items: start; gap: 12px; }
61
+ .recent-shared { margin-top: 8px; color: var(--text-secondary); font-size: var(--text-meta); }
62
+ .recent-shared summary { width: fit-content; cursor: pointer; padding: 7px 0; overflow-wrap: anywhere; }
63
+ .recent-shared[open] .recent-frame-grid { padding-top: 5px; }
64
+ .recent-removed { margin: 12px 0 0; padding-inline-start: 20px; font: var(--text-meta)/1.65 var(--font-mono); color: var(--text-secondary); }
65
+ .recent-visual { display: block; padding-top: 4px; color: var(--text-secondary); }
66
+ .view-frame { min-width: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); }
67
+ .view-frame-well { position: relative; display: grid; place-items: center; height: 148px; border-radius: var(--radius-card) var(--radius-card) 0 0; background: var(--surface-sunken); }
68
+ .view-frame-well canvas { position: absolute; inset: 0; margin: auto; pointer-events: none; width: auto; height: auto; max-width: calc(100% - 16px); max-height: calc(100% - 16px); }
69
+ .view-frame-well canvas:not([data-preview="ready"]) { visibility: hidden; }
70
+ .view-frame-caption { display: grid; padding: 8px 10px 0; gap: 3px; }
71
+ .view-frame-title, .view-frame-caption small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
72
+ .view-frame-title { font: 600 var(--text-body)/18px var(--font-ui); }
73
+ .view-frame-footer { display: flex; align-items: center; justify-content: space-between; gap: 4px; padding: 4px 8px 7px 10px; }
74
+ .view-badge { padding: 3px 7px; background: var(--surface-sunken); color: var(--text-secondary); border-radius: var(--radius-pill, 999px); font-size: var(--text-caption); }
75
+ .view-show-in-board { min-height: 25px; margin-inline-start: auto; padding: 2px 4px; color: var(--text-secondary); font-size: var(--text-meta); }
76
+ .view-show-in-board:hover { color: var(--text); text-decoration: underline; }
77
+ .prototype-scroll { overflow: auto; margin-top: 12px; }
78
+ .prototype-map { position: relative; }
79
+ .prototype-map > svg { position: absolute; inset: 0; pointer-events: none; }
80
+ .prototype-map > svg > path { fill: none; stroke: var(--text-tertiary); stroke-width: 1.25; }
81
+ .prototype-map marker path { fill: var(--text-tertiary); }
82
+ .prototype-map .view-frame { position: absolute; width: 248px; height: 230px; }
83
+ .prototype-trigger {
84
+ position: absolute;
85
+ translate: -50% -100%;
86
+ max-width: 188px;
87
+ white-space: nowrap;
88
+ overflow: hidden;
89
+ text-overflow: ellipsis;
90
+ padding: 3px 6px;
91
+ border-radius: var(--radius-field);
92
+ background: var(--surface-sunken);
93
+ color: var(--text);
94
+ font-size: var(--text-caption);
95
+ text-align: center;
96
+ }
97
+ .frame-play {
98
+ position: absolute;
99
+ right: 6px;
100
+ top: 6px;
101
+ z-index: 1;
102
+ display: grid;
103
+ place-items: center;
104
+ width: var(--frame-play-size, 26px);
105
+ height: var(--frame-play-size, 26px);
106
+ padding: 0;
107
+ border-radius: var(--radius-field);
108
+ background: var(--surface);
109
+ color: var(--text);
110
+ box-shadow: var(--shadow-float);
111
+ }
112
+ .frame-play svg { width: 55%; height: 55%; }
113
+ .frame-play:hover { background: var(--surface-sunken); }
114
+ .view-frame .frame-play { top: calc(-4px - var(--frame-play-size, 26px)); opacity: 0; pointer-events: none; }
115
+ .view-frame .frame-play[data-outside]::after { content: ''; position: absolute; inset: 100% 0 -5px; }
116
+ .view-frame:is(:hover, :focus-within) .frame-play { opacity: 1; pointer-events: auto; }
117
+ @media (hover: none) { .view-frame .frame-play { opacity: 1; pointer-events: auto; } }
118
+ .derived-mode .gallery-viewport > :not(#canvas-background),
119
+ .derived-mode #minimap,
120
+ .derived-mode #comment-layer,
121
+ .derived-mode #comments-panel { visibility: hidden; }
122
+ .derived-mode #app-bar { right: auto; max-width: calc(100% - 66px); }
123
+ .recent-feed > h2, .recent-impacts > h2 { margin-bottom: 12px; }
124
+ .recent-more, .recent-removed-heading { margin-top: 16px; }
125
+ .recent-change {
126
+ display: grid;
127
+ gap: 2px;
128
+ color: var(--text-secondary);
129
+ font-size: var(--text-meta);
130
+ }
131
+ .recent-change span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@@ -0,0 +1,350 @@
1
+ import { icon } from './icons.js';
2
+
3
+ export const frameKey = (source, frame) => JSON.stringify([source, frame]);
4
+
5
+ export function boardElement(tag, className, text) {
6
+ const node = document.createElement(tag);
7
+ if (className) node.className = className;
8
+ if (text !== undefined) node.textContent = text;
9
+ return node;
10
+ }
11
+
12
+ export function playButton(frame, onPlay) {
13
+ const button = boardElement('button', 'frame-play');
14
+ button.type = 'button';
15
+ button.setAttribute('aria-label', 'Play from ' + frame);
16
+ button.title = button.getAttribute('aria-label');
17
+ button.innerHTML = icon('play', 16);
18
+ button.onclick = onPlay;
19
+ return button;
20
+ }
21
+
22
+ function intersects(a, b) {
23
+ return a.x < b.x + b.width && a.x + a.width > b.x &&
24
+ a.y < b.y + b.height && a.y + a.height > b.y;
25
+ }
26
+
27
+ function nearestPlaySlot(area, anchor, size, blocked) {
28
+ const maxX = area.x + area.width - size, maxY = area.y + area.height - size;
29
+ if (maxX < area.x || maxY < area.y) return;
30
+ // A closest free position is either aligned with the anchor or flush with an edge.
31
+ const xs = [Math.max(area.x, Math.min(anchor.x, maxX)),
32
+ ...blocked.flatMap(box => [box.x - size, box.x + box.width])].filter(x => x >= area.x && x <= maxX);
33
+ const ys = [Math.max(area.y, Math.min(anchor.y, maxY)),
34
+ ...blocked.flatMap(box => [box.y - size, box.y + box.height])].filter(y => y >= area.y && y <= maxY);
35
+ let best, distance = Infinity;
36
+ for (const x of xs) for (const y of ys) {
37
+ const candidate = { x, y, width: size, height: size };
38
+ const score = (x - anchor.x) ** 2 + (y - anchor.y) ** 2;
39
+ if (score >= distance || blocked.some(box => intersects(candidate, box))) continue;
40
+ best = candidate;
41
+ distance = score;
42
+ }
43
+ return best;
44
+ }
45
+
46
+ export function placePlayButton(card, content, size, viewport, toolbars = []) {
47
+ const inset = 4;
48
+ const right = card.x + card.width, bottom = card.y + card.height;
49
+ const visibleRight = viewport ? Math.min(right, viewport.width - inset) : right;
50
+ const visibleTop = viewport ? Math.max(card.y, inset) : card.y;
51
+ const corner = { x: visibleRight - size - inset, y: visibleTop + inset, width: size, height: size };
52
+ const above = { ...corner, x: visibleRight - size, y: card.y - size - inset };
53
+ const beside = { ...corner, x: right + inset, y: visibleTop };
54
+ const inPadding = corner.x >= card.x && corner.y + size <= bottom && !intersects(corner, content);
55
+ if (!viewport) return inPadding ? { ...corner, outside: false } : { ...above, outside: true };
56
+
57
+ const bounds = { x: inset, y: inset, width: viewport.width - 2 * inset, height: viewport.height - 2 * inset };
58
+ if (!intersects(card, bounds)) return;
59
+ const blocked = toolbars.map(box => ({
60
+ x: box.x - inset, y: box.y - inset, width: box.width + 2 * inset, height: box.height + 2 * inset
61
+ }));
62
+ const clear = position => position.x >= bounds.x && position.y >= bounds.y &&
63
+ position.x + size <= bounds.x + bounds.width && position.y + size <= bounds.y + bounds.height &&
64
+ !blocked.some(box => intersects(position, box));
65
+ if (inPadding && clear(corner)) return { ...corner, outside: false };
66
+ const exterior = [above, beside].find(clear);
67
+ if (!inPadding && exterior) return { ...exterior, outside: true };
68
+
69
+ const clip = (left, top, right, bottom) => {
70
+ const x = Math.max(bounds.x, left), y = Math.max(bounds.y, top);
71
+ return { x, y, width: Math.min(bounds.x + bounds.width, right) - x,
72
+ height: Math.min(bounds.y + bounds.height, bottom) - y };
73
+ };
74
+ const safe = nearestPlaySlot(bounds, corner, size, [...blocked, content]);
75
+ if (safe) return { ...safe, outside: !intersects(safe, card) };
76
+
77
+ const visibleContent = clip(content.x, content.y, content.x + content.width, content.y + content.height);
78
+ const overlay = nearestPlaySlot(visibleContent, {
79
+ x: visibleContent.x + visibleContent.width - size - inset, y: visibleContent.y + inset
80
+ }, size, blocked);
81
+ if (overlay) return { ...overlay, outside: false };
82
+ }
83
+
84
+ // Work entirely from the indexed edge summaries and measured frame references.
85
+ export function prototypeFlows(edges, frames, relative) {
86
+ const nodes = new Map();
87
+ const links = [];
88
+ for (const edge of edges) {
89
+ const from = frameKey(relative(edge.from.source), edge.from.frame);
90
+ const to = frameKey(relative(edge.to.source), edge.to.frame);
91
+ if (!frames.has(from)) continue;
92
+ if (!nodes.has(from)) nodes.set(from, { outgoing: [], incoming: [], flow: edge.flow });
93
+ if (!frames.has(to)) continue;
94
+ if (!nodes.has(to)) nodes.set(to, { outgoing: [], incoming: [], flow: edge.flow });
95
+ nodes.get(from).outgoing.push(to);
96
+ nodes.get(to).incoming.push(from);
97
+ links.push({ ...edge, from, to });
98
+ }
99
+ const visited = new Set(), flows = [];
100
+ for (const seed of nodes.keys()) {
101
+ if (visited.has(seed)) continue;
102
+ const members = [seed];
103
+ visited.add(seed);
104
+ for (const id of members) {
105
+ const node = nodes.get(id);
106
+ for (const other of [...node.outgoing, ...node.incoming]) {
107
+ if (visited.has(other)) continue;
108
+ visited.add(other);
109
+ members.push(other);
110
+ }
111
+ }
112
+ const flow = nodes.get(seed).flow;
113
+ const projectedStart = flow && frameKey(relative(flow.start.source), flow.start.frame);
114
+ // A scope can omit the start. Use the first available root, then authored order.
115
+ const start = members.includes(projectedStart) ? projectedStart : members.find(id => !nodes.get(id).incoming.length) ?? seed;
116
+ const ranks = new Map([[start, 0]]);
117
+ const traverse = root => {
118
+ const pending = [root];
119
+ for (const current of pending) for (const other of nodes.get(current).outgoing) {
120
+ if (ranks.has(other)) continue;
121
+ ranks.set(other, ranks.get(current) + 1);
122
+ pending.push(other);
123
+ }
124
+ };
125
+ traverse(start);
126
+ for (const id of members) {
127
+ if (ranks.has(id)) continue;
128
+ ranks.set(id, 0);
129
+ traverse(id);
130
+ }
131
+ flows.push({ start, ranks, links: [], id: flow?.id, key: flow?.id ?? projectedStart ?? start, label: flow?.label });
132
+ }
133
+ const byNode = new Map(flows.flatMap(flow => [...flow.ranks.keys()].map(id => [id, flow])));
134
+ for (const link of links) byNode.get(link.from).links.push(link);
135
+ return flows;
136
+ }
137
+
138
+ function triggerLabel({ trigger, label }) {
139
+ const { on, key, value, target } = trigger;
140
+ const name = typeof target === 'string' ? target.replace(/.*#/, '').replace(/[-_]/g, ' ') : '';
141
+ const action = { click: 'Click', hover: 'Hover over', focus: 'Focus' }[on];
142
+ if (on === 'input') return 'Type ' + (value || name);
143
+ if (on === 'key') return 'Press ' + ({ Escape: 'Esc', ArrowUp: '↑', ArrowDown: '↓', ' ': 'Space' }[key] ?? key);
144
+ return name ? action + ' ' + name : label || action;
145
+ }
146
+
147
+ const cardWidth = 248, cardHeight = 230, rowGap = 24;
148
+ const stepY = cardHeight + rowGap, bendStep = 8;
149
+
150
+ function groupLinks(links, endpoint) {
151
+ const groups = new Map();
152
+ for (const link of links) {
153
+ const key = endpoint(link);
154
+ if (!groups.has(key)) groups.set(key, []);
155
+ groups.get(key).push(link);
156
+ }
157
+ return groups;
158
+ }
159
+
160
+ // Order the side ports and elbows together so neighboring routes do not run
161
+ // along the same card edge or share an arrowhead.
162
+ function placePorts(links, positions, linksByColumn, side) {
163
+ const outgoing = side === 'from';
164
+ for (const [id, endpoints] of groupLinks(links, link => link[side])) {
165
+ const { y } = positions.get(id);
166
+ const gap = Math.min(16, 110 / Math.max(1, endpoints.length - 1));
167
+ endpoints.forEach((link, i) => {
168
+ link[side + 'Y'] = y + 74 + gap * (i - (endpoints.length - 1) / 2);
169
+ });
170
+ }
171
+ for (const endpoints of linksByColumn.values()) {
172
+ endpoints.sort((a, b) => a[side + 'Y'] - b[side + 'Y']);
173
+ endpoints.forEach((link, i) => {
174
+ const { x } = positions.get(link[side]);
175
+ const inset = 14 + i * bendStep;
176
+ link[side + 'Bend'] = x + (outgoing ? cardWidth + inset : -inset);
177
+ });
178
+ }
179
+ }
180
+
181
+ export function renderPrototype(container, flows, frames, { card, play, title }) {
182
+ const groups = flows.map(flow => {
183
+ const start = frames.get(flow.start);
184
+ const section = boardElement('section', 'view-board-section');
185
+ const header = boardElement('header', 'view-section-heading');
186
+ if (flow.id) section.dataset.flowId = flow.id;
187
+ section.dataset.flowKey = flow.key;
188
+ const name = flow.label || title(start.asset.path);
189
+ const heading = boardElement('h2', '', name);
190
+ const launch = boardElement('button', 'view-board-action', 'Play flow');
191
+ launch.insertAdjacentHTML('afterbegin', icon('play', 14));
192
+ launch.setAttribute('aria-label', 'Play flow from ' + start.part.name);
193
+ launch.onclick = () => play(start.asset.path, start.part.name, launch);
194
+ header.append(heading, launch);
195
+ section.append(header);
196
+
197
+ const columns = new Map();
198
+ for (const [id, rank] of flow.ranks) {
199
+ if (!columns.has(rank)) columns.set(rank, []);
200
+ columns.get(rank).push(id);
201
+ }
202
+ const forward = [], tracks = [];
203
+ for (const edges of groupLinks(flow.links, link => frameKey(link.from, link.to)).values()) {
204
+ const { from, to, id } = edges[0];
205
+ const byTrigger = [...edges].sort((a, b) => Number(a.trigger.on === 'key') - Number(b.trigger.on === 'key'));
206
+ const label = [...new Set(byTrigger.map(triggerLabel).filter(Boolean))].join(' · ');
207
+ if (flow.ranks.get(to) === flow.ranks.get(from) + 1) forward.push({ from, to, label });
208
+ else tracks.push({ from, to, id, label, lane: tracks.length });
209
+ }
210
+ const connections = [...tracks, ...forward];
211
+ const fromColumns = groupLinks(tracks, link => flow.ranks.get(link.from));
212
+ const toColumns = groupLinks(tracks, link => flow.ranks.get(link.to));
213
+ const maxBends = groups => Math.max(0, ...[...groups.values()].map(links => links.length));
214
+ const bendRoom = 16 + Math.max(maxBends(fromColumns), maxBends(toColumns)) * bendStep;
215
+ const columnGap = Math.max(202, 2 * bendRoom + 24);
216
+ const stepX = cardWidth + columnGap;
217
+ const firstColumn = Math.max(26, 16 + (toColumns.get(0)?.length ?? 0) * bendStep);
218
+ const lastColumn = Math.max(26, 16 + (fromColumns.get(columns.size - 1)?.length ?? 0) * bendStep);
219
+ const scroll = boardElement('div', 'prototype-scroll');
220
+ const graph = boardElement('div', 'prototype-map');
221
+ const positions = new Map();
222
+ const columnsHeight = Math.max(...[...columns.values()].map(items => items.length)) * stepY - rowGap;
223
+ const trackGap = 28;
224
+ const offset = Math.max(34, tracks.length * trackGap + 14);
225
+ const graphWidth = firstColumn + (columns.size - 1) * stepX + cardWidth + lastColumn;
226
+ const graphHeight = columnsHeight + offset + 8;
227
+ graph.style.cssText = `width:${graphWidth}px;height:${graphHeight}px`;
228
+ const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
229
+ svg.setAttribute('aria-hidden', 'true');
230
+ svg.setAttribute('width', graphWidth);
231
+ svg.setAttribute('height', graphHeight);
232
+ const marker = 'prototype-arrow-' + groupsMarker++;
233
+ svg.innerHTML = `<defs><marker id="${marker}" viewBox="0 0 8 8" refX="7" refY="4" markerWidth="7" markerHeight="7" orient="auto"><path d="M0 0L8 4L0 8Z"/></marker></defs>`;
234
+ graph.append(svg);
235
+ for (const [rank, items] of columns) {
236
+ items.forEach((id, row) => {
237
+ const x = firstColumn + rank * stepX;
238
+ const y = offset + (columnsHeight - (items.length * stepY - rowGap)) / 2 + row * stepY;
239
+ positions.set(id, { x, y });
240
+ const node = card(frames.get(id), { badge: id === flow.start ? 'Start' : '' });
241
+ node.style.left = x + 'px';
242
+ node.style.top = y + 'px';
243
+ graph.append(node);
244
+ });
245
+ }
246
+ placePorts(connections, positions, fromColumns, 'from');
247
+ placePorts(connections, positions, toColumns, 'to');
248
+ for (const link of connections) {
249
+ const x = positions.get(link.from).x + cardWidth;
250
+ const endX = positions.get(link.to).x;
251
+ const { fromY: y, toY: endY, fromBend, toBend } = link;
252
+ const routed = link.lane !== undefined;
253
+ const laneY = offset - (link.lane + 1) * trackGap + 14;
254
+ const mid = (x + endX) / 2;
255
+ const arrow = document.createElementNS(svg.namespaceURI, 'path');
256
+ const path = routed
257
+ ? `M${x} ${y} H${fromBend} V${laneY} H${toBend} V${endY} H${endX}`
258
+ : `M${x} ${y} C${mid} ${y},${mid} ${endY},${endX} ${endY}`;
259
+ arrow.setAttribute('d', path);
260
+ arrow.setAttribute('marker-end', `url(#${marker})`);
261
+ if (routed) arrow.dataset.edge = link.id;
262
+ svg.append(arrow);
263
+ const text = link.label;
264
+ const label = boardElement('span', 'prototype-trigger', text);
265
+ label.style.left = (routed ? (fromBend + toBend) / 2 : mid) + 'px';
266
+ label.style.top = (routed ? laneY - 4 : (y + endY) / 2 - 10) + 'px';
267
+ label.title = text;
268
+ if (routed) label.dataset.edge = link.id;
269
+ label.setAttribute('aria-label', frames.get(link.from).part.name + ' to ' + frames.get(link.to).part.name + ' · ' + text);
270
+ graph.append(label);
271
+ }
272
+ scroll.append(graph);
273
+ section.append(scroll);
274
+ return section;
275
+ });
276
+ container.replaceChildren(...groups);
277
+ }
278
+ let groupsMarker = 0;
279
+
280
+ export function createFrameCards(root, { preview, show, play, playable }) {
281
+ let pending = new WeakMap();
282
+ const resize = new ResizeObserver(entries => {
283
+ for (const { target: well } of entries) {
284
+ const button = well.querySelector('.frame-play');
285
+ const preview = well.querySelector('canvas');
286
+ const outer = well.getBoundingClientRect(), inner = preview.getBoundingClientRect();
287
+ const size = button.offsetWidth;
288
+ const position = placePlayButton(
289
+ { x: 0, y: 0, width: outer.width, height: outer.height },
290
+ { x: inner.x - outer.x, y: inner.y - outer.y, width: inner.width, height: inner.height },
291
+ size
292
+ );
293
+ button.style.left = position.x + 'px';
294
+ button.style.top = position.y + 'px';
295
+ button.style.right = 'auto';
296
+ button.toggleAttribute('data-outside', position.outside);
297
+ }
298
+ });
299
+ const observer = new IntersectionObserver(entries => {
300
+ for (const entry of entries) {
301
+ if (!entry.isIntersecting) continue;
302
+ const canvas = entry.target, ref = pending.get(canvas);
303
+ if (!ref) continue;
304
+ observer.unobserve(canvas);
305
+ pending.delete(canvas);
306
+ void preview(ref, canvas).then(() => {
307
+ const well = canvas.parentElement;
308
+ if (canvas.isConnected && well?.querySelector('.frame-play')) resize.observe(well);
309
+ });
310
+ }
311
+ }, { root, rootMargin: '96px' });
312
+ return {
313
+ reset() {
314
+ observer.disconnect();
315
+ resize.disconnect();
316
+ pending = new WeakMap();
317
+ },
318
+ card(ref, { badge = '', source = true } = {}) {
319
+ const { asset, part } = ref;
320
+ const node = boardElement('article', 'view-frame');
321
+ node.dataset.frameSource = asset.path;
322
+ node.dataset.frameName = part.name;
323
+ const well = boardElement('div', 'view-frame-well');
324
+ const canvas = boardElement('canvas');
325
+ canvas.setAttribute('aria-hidden', 'true');
326
+ canvas.dataset.preview = 'queued';
327
+ well.append(canvas);
328
+ pending.set(canvas, ref);
329
+ observer.observe(canvas);
330
+ if (playable(asset.path, part.name)) {
331
+ const button = playButton(part.name, event => play(asset.path, part.name, event.currentTarget));
332
+ button.setAttribute('data-outside', '');
333
+ well.append(button);
334
+ }
335
+ const heading = boardElement('h4', 'view-frame-title', part.name);
336
+ heading.title = part.name;
337
+ const caption = boardElement('div', 'view-frame-caption');
338
+ caption.append(heading);
339
+ if (source) caption.append(boardElement('small', 'view-source-name', asset.path));
340
+ const footer = boardElement('div', 'view-frame-footer');
341
+ if (badge) footer.append(boardElement('span', 'view-badge', badge));
342
+ const button = boardElement('button', 'view-show-in-board', 'Show in board');
343
+ button.setAttribute('aria-label', 'Show ' + part.name + ' in board');
344
+ button.onclick = () => show(asset.path, part.name);
345
+ footer.append(button);
346
+ node.append(well, caption, footer);
347
+ return node;
348
+ }
349
+ };
350
+ }
@@ -12,7 +12,7 @@ export function readViewRoute(url) {
12
12
  const query = url.searchParams;
13
13
  const base=query.has('base')?{base:query.get('base')}:{};
14
14
  const path = url.pathname.slice(viewerBase(url.pathname).length);
15
- const explicitScope = query.get('scope');
15
+ const explicitScope = query.get('scope') ?? (path === '' && query.has('pattern') ? 'tokens' : null);
16
16
  const asset = query.get('asset'), group = query.get('group');
17
17
  if (explicitScope || asset || group) {
18
18
  return {