@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
|
@@ -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
|
+
}
|
package/public/view-route.js
CHANGED
|
@@ -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 {
|
|
@@ -43,7 +43,6 @@ export function viewURL(base, scope, target = {}, { isolated = false, onlyFrame
|
|
|
43
43
|
const url = new URL(base);
|
|
44
44
|
url.pathname = viewerBase(url.pathname);
|
|
45
45
|
for (const key of locatorKeys) url.searchParams.delete(key);
|
|
46
|
-
if (scope === 'review') return url;
|
|
47
46
|
const { path, group, form, element } = target;
|
|
48
47
|
if (onlyFrame) {
|
|
49
48
|
url.searchParams.set('asset', path);
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { escape } from '../toolkit/html.mjs';
|
|
2
|
+
|
|
3
|
+
export const boardWidth = 1680;
|
|
4
|
+
export const specimenWidth = 1184;
|
|
5
|
+
export const boardCss = `
|
|
6
|
+
[data-adg-board]{--adg-surface:var(--surface,#fff);--adg-canvas:var(--canvas,#f2f2f0);--adg-text:var(--text,#202020);--adg-muted:var(--text-tertiary,var(--text-secondary,#737373));--adg-border:var(--border,#dededb);box-sizing:border-box;width:1680px;padding:64px 80px 80px;background:var(--adg-surface);color:var(--adg-text);font:16px/normal var(--font-ui,system-ui,sans-serif)}
|
|
7
|
+
[data-adg-board] *,[data-adg-board] *::before,[data-adg-board] *::after{box-sizing:border-box}
|
|
8
|
+
[data-adg-header]{display:grid;grid-template-columns:1fr 440px;align-items:end;gap:64px;padding-bottom:56px}
|
|
9
|
+
[data-adg-header] h1{margin:16px 0 0;font-size:48px;line-height:56px;font-weight:600;letter-spacing:-.02em}
|
|
10
|
+
[data-adg-eyebrow]{display:flex;align-items:center;gap:12px;margin:0;font-size:var(--text-caption,11px);font-weight:600;letter-spacing:.16em;text-transform:uppercase;color:var(--adg-muted)}
|
|
11
|
+
[data-adg-number]{display:grid;place-items:center;min-width:28px;height:28px;padding:0 6px;border-radius:var(--radius-pill,999px);background:var(--action,var(--adg-text));color:var(--on-action,var(--surface,#fff));font-family:var(--font-mono,monospace);letter-spacing:0}
|
|
12
|
+
[data-adg-counts]{margin:0;font-size:var(--text-body,var(--text-small,13px));line-height:1.6;color:var(--text-secondary,#666)}
|
|
13
|
+
[data-adg-section]{display:grid;grid-template-columns:280px minmax(0,1fr);gap:56px;border-top:1px solid var(--adg-border);padding:48px 0}
|
|
14
|
+
[data-adg-section-label] h2{margin:0;font-size:22px;line-height:28px;font-weight:600;letter-spacing:-.01em;overflow-wrap:anywhere}
|
|
15
|
+
[data-adg-source]{display:flex;align-items:flex-start;gap:6px;margin-top:20px;color:var(--adg-muted);font:var(--text-caption,11px)/1.6 var(--font-mono,monospace);overflow-wrap:anywhere}
|
|
16
|
+
[data-adg-source] svg{flex-shrink:0;margin-top:2px}
|
|
17
|
+
[data-adg-section-content]{min-width:0}
|
|
18
|
+
[data-adg-specimens]{display:grid;grid-template-columns:repeat(12,minmax(0,1fr));gap:32px 24px;align-items:start}
|
|
19
|
+
[data-adg-specimens]>figure{margin:0;min-width:0;display:flex;flex-direction:column;gap:12px;grid-column:span var(--adg-span,12)}
|
|
20
|
+
[data-adg-well]{display:flex;align-items:center;justify-content:center;min-height:96px;padding:32px 24px;border-radius:var(--radius-card,var(--radius-menu,12px));background:var(--adg-canvas);overflow:hidden}
|
|
21
|
+
[data-adg-well]>[data-adg-frame]{flex-shrink:0}
|
|
22
|
+
[data-adg-specimens] figcaption{display:flex;flex-direction:column;gap:2px;font:var(--text-meta,12px)/17px var(--font-mono,monospace);overflow-wrap:anywhere}
|
|
23
|
+
[data-adg-specimens] figcaption small{font:var(--text-meta,12px)/17px var(--font-ui,system-ui,sans-serif);color:var(--adg-muted)}
|
|
24
|
+
`;
|
|
25
|
+
export function boardHeader({title, projectName, layer, number=1, sourceCount, frameCount, countLabel='frames'}) {
|
|
26
|
+
return `<header data-adg-header><div><p data-adg-eyebrow><span data-adg-number>${String(number).padStart(2,'0')}</span>${escape(projectName)} · ${escape(layer)}</p><h1>${escape(title)}</h1></div><p data-adg-counts>${sourceCount} ${sourceCount === 1 ? 'source' : 'sources'} · ${frameCount} ${countLabel}</p></header>`;
|
|
27
|
+
}
|
|
28
|
+
export function sectionMarkup({title, source, content}) {
|
|
29
|
+
return `<section data-adg-section="${escape(source)}"><div data-adg-section-label><h2>${escape(title)}</h2><div data-adg-source><svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" aria-hidden="true"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8zM14 2v6h6M9 13l-2 2 2 2m6-4 2 2-2 2"/></svg><span>${escape(source)}</span></div></div><div data-adg-section-content>${content}</div></section>`;
|
|
30
|
+
}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { escape } from '../toolkit/html.mjs';
|
|
2
|
+
import { patternParameters } from '../toolkit/motion-patterns.mjs';
|
|
3
|
+
import { milliseconds, tokenValue } from '../toolkit/motion-primitives.mjs';
|
|
4
|
+
|
|
5
|
+
export const motionBoardCss = `
|
|
6
|
+
[data-motion-patterns]{--motion-columns:3;display:grid;grid-template-columns:repeat(var(--motion-columns),minmax(0,1fr));gap:16px;align-items:start;margin-bottom:32px}
|
|
7
|
+
[data-motion-pattern],[data-motion-detail]{min-width:0;border:1px solid var(--adg-border);border-radius:var(--radius-card,12px);background:var(--adg-surface)}
|
|
8
|
+
[data-motion-pattern]{height:192px;display:grid;grid-template-rows:34px minmax(0,1fr) 18px 22px;gap:8px;padding:12px 14px;cursor:pointer;pointer-events:auto}
|
|
9
|
+
[data-motion-pattern]:is(:hover,:focus-within,[data-expanded]){border-color:var(--border-strong,var(--adg-text))}
|
|
10
|
+
[data-motion-pattern] h3,[data-motion-detail] h3,[data-motion-detail] h4,[data-motion-pattern] p,[data-motion-detail] p{margin:0}
|
|
11
|
+
[data-motion-pattern] h3{font-size:15px;line-height:19px}
|
|
12
|
+
[data-motion-pattern] [data-motion-toggle]{display:block;max-width:100%;padding:0;border:0;background:none;color:inherit;font:inherit;text-align:left;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;cursor:pointer}
|
|
13
|
+
[data-motion-pattern] p,[data-motion-detail] p,[data-motion-detail] dl{font:13px/1.45 var(--font-ui,system-ui);color:var(--adg-muted)}
|
|
14
|
+
[data-motion-pattern] header p{font-size:12px;line-height:15px}
|
|
15
|
+
[data-motion-summary]{font:12px/18px var(--font-mono,monospace);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
16
|
+
[data-motion-timing=dark]{display:none}
|
|
17
|
+
:where([data-theme="dark"]) [data-motion-timing=light]{display:none}
|
|
18
|
+
:where([data-theme="dark"]) [data-motion-timing=dark]{display:inline}
|
|
19
|
+
[data-motion-card-foot]{display:flex;align-items:center;justify-content:space-between;gap:8px;font-size:12px;color:var(--adg-muted)}
|
|
20
|
+
[data-motion-variant-count]{padding:3px 7px;border-radius:var(--radius-pill,999px);background:var(--adg-canvas);color:var(--adg-text);white-space:nowrap}
|
|
21
|
+
[data-motion-detail]{grid-column:1/-1;pointer-events:auto;padding:20px;display:grid;gap:20px}
|
|
22
|
+
[data-motion-detail-header],[data-motion-detail-actions]{display:flex;align-items:center;justify-content:space-between;gap:12px;flex-wrap:wrap}
|
|
23
|
+
[data-motion-detail-header] h3{font-size:20px}
|
|
24
|
+
[data-motion-detail-actions] a{color:inherit;font-size:13px;text-underline-offset:3px}
|
|
25
|
+
[data-motion-detail] button{padding:5px 9px;border:1px solid var(--adg-border);border-radius:var(--radius-row,6px);background:var(--adg-surface);color:inherit;cursor:pointer}
|
|
26
|
+
[data-motion-detail-main]{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr);gap:20px;align-items:start}
|
|
27
|
+
[data-motion-detail-specimen]{display:grid;gap:8px;justify-items:start}
|
|
28
|
+
[data-motion-detail-specimen] [data-motion-stage]{height:168px;width:100%}
|
|
29
|
+
[data-motion-detail] dl{display:grid;grid-template-columns:auto minmax(0,1fr);gap:4px 12px;margin:0}
|
|
30
|
+
[data-motion-detail] dd{margin:0;overflow-wrap:anywhere}
|
|
31
|
+
[data-motion-detail] code{font:12px/1.5 var(--font-mono,monospace)}
|
|
32
|
+
[data-motion-detail] h4{font-size:14px;line-height:1.4}
|
|
33
|
+
[data-motion-variants]{display:grid;grid-template-columns:repeat(auto-fit,minmax(min(220px,100%),1fr));gap:12px}
|
|
34
|
+
[data-motion-variant]{display:grid;gap:6px;align-content:start;padding:12px;border:1px solid var(--adg-border);border-radius:8px}
|
|
35
|
+
[data-motion-page]{width:min(860px,calc(100vw - 32px));max-height:calc(100dvh - 48px);padding:0;border:0;border-radius:var(--radius-card,12px);background:var(--adg-surface);color:var(--adg-text);pointer-events:auto}
|
|
36
|
+
[data-motion-page] [data-motion-stage]{height:220px}
|
|
37
|
+
[data-motion-page] [data-motion-page-link]{display:none}
|
|
38
|
+
[data-motion-page]::backdrop{background:#0007}
|
|
39
|
+
@media(max-width:600px){[data-motion-page] [data-motion-detail-main]{grid-template-columns:minmax(0,1fr)}}
|
|
40
|
+
[data-motion-default]{font:11px/1.5 var(--font-ui,system-ui);white-space:nowrap;color:var(--adg-text)}
|
|
41
|
+
[data-motion-unadopted]{margin-top:24px;border-top:1px solid var(--adg-border)}
|
|
42
|
+
[data-motion-unadopted] summary{padding:16px 0;pointer-events:auto;cursor:pointer;font-size:14px;font-weight:600}
|
|
43
|
+
[data-motion-unadopted] summary span{margin-left:8px;color:var(--adg-muted);font-weight:400}
|
|
44
|
+
[data-motion-stage]{display:grid;place-items:center;position:relative;min-width:0;overflow:hidden;border-radius:8px;background:var(--adg-canvas);color:var(--action,var(--adg-text))}
|
|
45
|
+
[data-motion-stage][data-effect=follow]{touch-action:none;cursor:crosshair}
|
|
46
|
+
[data-motion-stage][data-effect=avoid]{display:flex;flex-direction:column;justify-content:center;gap:6px}
|
|
47
|
+
[data-motion-shape]{width:52px;height:34px;border-radius:8px;background:currentColor}
|
|
48
|
+
[data-effect=expand] [data-motion-shape]{height:58px;width:86px;transform-origin:top}
|
|
49
|
+
[data-effect=avoid] [data-motion-shape]{height:18px;width:54%}
|
|
50
|
+
[data-motion-sibling]{opacity:.38}
|
|
51
|
+
[data-motion-sibling][hidden]{display:none}
|
|
52
|
+
[data-effect=follow] [data-motion-shape]{width:20px;height:20px;border-radius:50%;pointer-events:none}
|
|
53
|
+
[data-effect=crossfade] [data-motion-shape]{position:absolute;display:grid;place-items:center;color:var(--on-action,var(--adg-surface));background:var(--action,var(--adg-text));font-size:13px}
|
|
54
|
+
[data-effect=crossfade] [data-motion-shape]:nth-child(2){opacity:0}
|
|
55
|
+
[data-effect=spin] [data-motion-shape]{width:32px;height:32px;border-radius:50%;background:none;border:3px solid var(--adg-border);border-top-color:currentColor}
|
|
56
|
+
[data-effect=stagger]{grid-auto-flow:column;justify-content:center;gap:8px}
|
|
57
|
+
[data-effect=stagger] [data-motion-shape]{width:22px;height:34px}
|
|
58
|
+
[data-effect=aurora] [data-motion-shape]{position:relative;overflow:hidden;width:104px;height:52px;background:var(--adg-surface);isolation:isolate}
|
|
59
|
+
[data-motion-aurora]{position:absolute;inset:-100%;z-index:-1;background:conic-gradient(#576de8,#71c9ad,#e8b279,#ac71ce,#576de8)}
|
|
60
|
+
[data-effect=aurora] [data-motion-shape]::after{content:"";position:absolute;inset:3px;border-radius:6px;background:var(--adg-surface)}
|
|
61
|
+
[data-effect=shimmer] [data-motion-shape]{width:100px;background:linear-gradient(105deg,currentColor 28%,var(--adg-surface) 50%,currentColor 72%);background-size:250% 100%}
|
|
62
|
+
[data-motion-reduced]{display:none!important}
|
|
63
|
+
[data-motion-stage]>[data-motion-reduced]{position:absolute;right:6px;bottom:4px;color:var(--adg-muted);font:11px/1.3 var(--font-ui,system-ui)}
|
|
64
|
+
@media(prefers-reduced-motion:reduce){[data-motion-reduced]{display:block!important}}
|
|
65
|
+
`;
|
|
66
|
+
|
|
67
|
+
const shape = '<span data-motion-shape></span>';
|
|
68
|
+
const stageShapes = {
|
|
69
|
+
crossfade: '<span data-motion-shape>A</span><span data-motion-shape>B</span>',
|
|
70
|
+
avoid: '<span data-motion-shape data-motion-sibling hidden></span>' + shape + shape,
|
|
71
|
+
stagger: shape.repeat(3),
|
|
72
|
+
aurora: '<span data-motion-shape><span data-motion-aurora></span></span>',
|
|
73
|
+
};
|
|
74
|
+
const title = id => id.replaceAll('-', ' ').replace(/^./, c => c.toUpperCase());
|
|
75
|
+
const json = value => escape(JSON.stringify(value));
|
|
76
|
+
const pair = (name, value) => '<dt>' + escape(name) + '</dt><dd>' + value + '</dd>';
|
|
77
|
+
|
|
78
|
+
export function motionCards(catalog, inventory, source, prefix) {
|
|
79
|
+
const asset = name => prefix && name.startsWith(prefix + '/') ? name.slice(prefix.length + 1) : name;
|
|
80
|
+
const frameLink = ref => '?' + new URLSearchParams({ asset: asset(ref.source), frame: ref.frame });
|
|
81
|
+
const codeLink = (file, line, label) =>
|
|
82
|
+
'<a data-motion-code href="' + escape('api/motion-code?' + new URLSearchParams({ source: file, line })) + '">' + escape(label) + '</a>';
|
|
83
|
+
const listConsumer = ref => {
|
|
84
|
+
if (ref.type === 'code') return codeLink(ref.source, ref.line, ref.source + ':' + ref.line);
|
|
85
|
+
const frame = '<a href="' + escape(frameLink(ref)) + '">' + escape(ref.frame + ' · ' + ref.source) + '</a>';
|
|
86
|
+
return ref.type === 'edge' ? codeLink(ref.sidecar, ref.line, ref.id) + ' · ' + frame : frame;
|
|
87
|
+
};
|
|
88
|
+
const countLabel = count => 'Used in ' + count + (count === 1 ? ' place' : ' places');
|
|
89
|
+
const uses = id => inventory.consumers.get(id) ?? [];
|
|
90
|
+
const usage = (id, refs, prefix = '') => refs.length
|
|
91
|
+
? '<button type="button" data-motion-consumers="' + escape(title(id)) + '" aria-label="' +
|
|
92
|
+
escape(title(id) + ' · ' + countLabel(refs.length)) + '">' + prefix + countLabel(refs.length) +
|
|
93
|
+
'</button><template><ul>' + refs.map(ref => '<li>' + listConsumer(ref) + '</li>').join('') + '</ul></template>'
|
|
94
|
+
: '<p>' + countLabel(0) + '</p>';
|
|
95
|
+
const isDefault = value => catalog.defaultTokens.has(value) ||
|
|
96
|
+
(Object.hasOwn(catalog.springs.light, value) && ['-duration','-bounce'].some(suffix => catalog.defaultTokens.has(value + suffix)));
|
|
97
|
+
const defaultLabel = ' <span data-motion-default>ADG default</span>';
|
|
98
|
+
const describe = params => Object.entries(params).map(([key,value]) => {
|
|
99
|
+
const spring = catalog.springs.light[value];
|
|
100
|
+
const light = tokenValue(catalog.tokens, 'light', value);
|
|
101
|
+
const dark = tokenValue(catalog.tokens, 'dark', value);
|
|
102
|
+
const label = spring ? spring.duration + ' ms / bounce ' + spring.bounce : light;
|
|
103
|
+
const darkSpring = catalog.springs.dark[value];
|
|
104
|
+
const themeLabel = darkSpring ? darkSpring.duration + ' ms / bounce ' + darkSpring.bounce : dark;
|
|
105
|
+
return escape(key) + ' <code>' + escape(value) + '</code>' +
|
|
106
|
+
(label === undefined ? '' : ' · ' + escape(label)) + (label === themeLabel ? '' : ' / dark ' + escape(themeLabel)) +
|
|
107
|
+
(isDefault(value) ? defaultLabel : '');
|
|
108
|
+
}).join('<br>');
|
|
109
|
+
const equal = (left, right) => Object.keys(left).length === Object.keys(right).length &&
|
|
110
|
+
Object.entries(left).every(([key, value]) => right[key] === value);
|
|
111
|
+
const deltas = (base, variant, phase) => {
|
|
112
|
+
const inherited = patternParameters(base, phase);
|
|
113
|
+
return Object.fromEntries(Object.entries(patternParameters(variant, phase)).filter(([key, value]) => inherited[key] !== value));
|
|
114
|
+
};
|
|
115
|
+
const variantRow = (base, id) => {
|
|
116
|
+
const variant = catalog.patterns.get(id);
|
|
117
|
+
const enter = deltas(base, variant, 'enter'), exit = deltas(base, variant, 'exit');
|
|
118
|
+
const overrides = equal(enter, exit)
|
|
119
|
+
? (Object.keys(enter).length ? pair('Overrides', describe(enter)) : '')
|
|
120
|
+
: (Object.keys(enter).length ? pair('Enter', describe(enter)) : '') +
|
|
121
|
+
(Object.keys(exit).length ? pair('Exit', describe(exit)) : '');
|
|
122
|
+
return '<div data-motion-variant="' + escape(id) + '"><h4>' + title(id) + '</h4>' +
|
|
123
|
+
(overrides ? '<dl>' + overrides + '</dl>' : '<p>Inherits base parameters</p>') +
|
|
124
|
+
'<div>' + usage(id, uses(id)) + '</div></div>';
|
|
125
|
+
};
|
|
126
|
+
const render = (id, pattern) => {
|
|
127
|
+
const directions = ['enter','exit'];
|
|
128
|
+
const themeValues = (theme, direction) => {
|
|
129
|
+
const params = patternParameters(pattern, direction);
|
|
130
|
+
const value = key => tokenValue(catalog.tokens, theme, params[key]);
|
|
131
|
+
const spring = catalog.springs[theme][params.spring];
|
|
132
|
+
return {
|
|
133
|
+
duration: spring?.duration ?? milliseconds(value('duration')), easing: spring?.easing ?? value('easing'),
|
|
134
|
+
distance: value('distance'), scale: Number(value('scale') ?? .85), stagger: milliseconds(value('stagger')) || 0,
|
|
135
|
+
opacity: params.fromOpacity ?? 0,
|
|
136
|
+
};
|
|
137
|
+
};
|
|
138
|
+
const preview = Object.fromEntries(['light','dark'].map(theme =>
|
|
139
|
+
[theme, Object.fromEntries(directions.map(direction => [direction, themeValues(theme, direction)]))]));
|
|
140
|
+
const primary = pattern.action === 'exit' ? 'exit' : 'enter';
|
|
141
|
+
const alternate = primary === 'enter' ? 'exit' : 'enter';
|
|
142
|
+
const main = patternParameters(pattern, primary), other = patternParameters(pattern, alternate);
|
|
143
|
+
const asymmetric = !equal(main, other);
|
|
144
|
+
const variants = catalog.variants.get(id) ?? [];
|
|
145
|
+
const direct = uses(id);
|
|
146
|
+
const total = new Set([id, ...variants].flatMap(uses).map(ref =>
|
|
147
|
+
JSON.stringify([ref.type, ref.source, ref.frame, ref.id, ref.line, ref.match]))).size;
|
|
148
|
+
const adoption = variants.length
|
|
149
|
+
? '<p data-motion-family-count>' + countLabel(total) + '</p>' +
|
|
150
|
+
(direct.length ? '<div>' + usage(id, direct, 'Base · ') + '</div>' : '') +
|
|
151
|
+
'<div data-motion-variants>' + variants.map(child => variantRow(pattern, child)).join('') + '</div>'
|
|
152
|
+
: usage(id, direct);
|
|
153
|
+
const name = title(id);
|
|
154
|
+
const reducedLabel = escape('Reduced motion · ' + pattern.reduced);
|
|
155
|
+
const kind = escape(pattern.kind + ' · ' + pattern.action);
|
|
156
|
+
const stage = compact => '<div data-motion-stage data-effect="' + escape(pattern.effect) + '" data-action="' +
|
|
157
|
+
escape(pattern.action) + '" data-preview="' + json(preview) + '"' +
|
|
158
|
+
(pattern.effect === 'follow' ? ' role="group" tabindex="0" aria-label="Follow specimen. Move the pointer or use the arrow keys."' : '') +
|
|
159
|
+
'>' + (stageShapes[pattern.effect] ?? shape).replaceAll('<span ', '<span aria-hidden="true" ') +
|
|
160
|
+
(compact ? '<span data-motion-reduced>' + reducedLabel + '</span>' : '') + '</div>';
|
|
161
|
+
const timing = theme => {
|
|
162
|
+
const spring = catalog.springs[theme][main.spring];
|
|
163
|
+
const summary = preview[theme][primary].duration + ' ms · ' +
|
|
164
|
+
(spring ? 'bounce ' + spring.bounce : main.easing.slice(2));
|
|
165
|
+
return escape(summary) + ([main.spring, main.duration, main.easing].some(isDefault) ? ' ·' + defaultLabel : '');
|
|
166
|
+
};
|
|
167
|
+
const link = '?' + new URLSearchParams({scope: 'tokens', section: 'motion', pattern: id});
|
|
168
|
+
const detailId = 'motion-detail-' + id;
|
|
169
|
+
const detail = '<section data-motion-detail id="' + detailId + '" aria-labelledby="' + detailId + '-heading">' +
|
|
170
|
+
'<header data-motion-detail-header><div><h3 id="' + detailId + '-heading">' + name + '</h3><p>' + kind + '</p></div>' +
|
|
171
|
+
'<div data-motion-detail-actions><a data-motion-page-link href="' + escape(link) + '">Open detail view</a>' +
|
|
172
|
+
'<button type="button" data-motion-close aria-label="Close ' + name + ' details">Close</button></div></header>' +
|
|
173
|
+
'<div data-motion-detail-main><div data-motion-detail-specimen>' + stage(false) +
|
|
174
|
+
'<div data-motion-detail-actions><button type="button" data-motion-replay>Replay</button>' +
|
|
175
|
+
(pattern.effect === 'avoid' ? '<button type="button" data-motion-avoid aria-pressed="false">Insert sibling</button>' : '') +
|
|
176
|
+
'</div><p data-motion-reduced>' + reducedLabel + '</p></div><dl>' +
|
|
177
|
+
pair('Properties', escape(pattern.properties.join(', '))) +
|
|
178
|
+
pair(asymmetric ? title(primary) : 'Parameters', describe(main)) +
|
|
179
|
+
(asymmetric ? pair(title(alternate), describe(other)) : '') +
|
|
180
|
+
pair('Interrupt', escape(pattern.interrupt)) + pair('Reduced motion', escape(pattern.reduced)) +
|
|
181
|
+
'</dl></div>' + adoption + '</section>';
|
|
182
|
+
return '<article data-motion-pattern="' + escape(id) + '" data-specimen="' + escape(source + '#' + id) + '">' +
|
|
183
|
+
'<header><h3><button type="button" data-motion-toggle aria-expanded="false">' + name + '</button></h3><p>' + kind + '</p></header>' +
|
|
184
|
+
stage(true) + '<div data-motion-summary><span data-motion-timing="light">' + timing('light') +
|
|
185
|
+
'</span><span data-motion-timing="dark">' + timing('dark') + '</span></div>' +
|
|
186
|
+
'<div data-motion-card-foot><span>' + countLabel(total) + '</span>' +
|
|
187
|
+
(variants.length ? '<span data-motion-variant-count>' + variants.length + (variants.length === 1 ? ' variant' : ' variants') + '</span>' : '') +
|
|
188
|
+
'</div><template data-motion-template>' + detail + '</template></article>';
|
|
189
|
+
};
|
|
190
|
+
const grid = cards => '<div data-motion-patterns>' + cards.join('') + '</div>';
|
|
191
|
+
const adopted = [], notAdopted = [];
|
|
192
|
+
for (const [id, pattern] of catalog.patterns) {
|
|
193
|
+
if (pattern.extends) continue;
|
|
194
|
+
const unused = catalog.variants.has(id) && ![id, ...catalog.variants.get(id)].some(key => uses(key).length);
|
|
195
|
+
(unused ? notAdopted : adopted).push(render(id, pattern));
|
|
196
|
+
}
|
|
197
|
+
return {
|
|
198
|
+
adopted: adopted.length ? grid(adopted) : '',
|
|
199
|
+
notAdopted: notAdopted.length ? '<details data-motion-unadopted><summary>Not adopted <span>' +
|
|
200
|
+
notAdopted.length + '</span></summary>' + grid(notAdopted) + '</details>' : '',
|
|
201
|
+
};
|
|
202
|
+
}
|