@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.
- package/README.md +5 -2
- package/package.json +2 -1
- package/public/app.js +602 -64
- package/public/assets.js +25 -10
- package/public/boards.js +8 -3
- package/public/frame-identity.js +25 -12
- package/public/icons.js +7 -0
- package/public/index.html +14 -2
- 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/style.css +17 -2
- package/public/tokens.css +6 -0
- package/public/view-boards.css +131 -0
- package/public/view-boards.js +350 -0
- package/public/view-route.js +1 -1
- package/src/boards/motion-board.mjs +202 -0
- package/src/boards/token-board.mjs +9 -5
- package/src/cli-output.mjs +3 -1
- package/src/cli.mjs +52 -18
- package/src/http.mjs +5 -2
- 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 +229 -18
- package/src/toolkit/arch-git.mjs +8 -14
- 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 +93 -2
- package/src/toolkit/compare.mjs +13 -11
- package/src/toolkit/config.mjs +2 -2
- package/src/toolkit/diff-inputs.mjs +35 -26
- package/src/toolkit/diff.mjs +24 -11
- 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 +2 -2
- package/src/toolkit/impact.mjs +17 -3
- 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/owner.mjs +19 -6
- package/src/toolkit/play-endpoint.mjs +66 -0
- package/src/toolkit/project-index.mjs +2 -2
- package/src/toolkit/recent-structure.mjs +201 -0
- package/src/toolkit/results.mjs +2 -2
- package/src/toolkit/review-document.mjs +9 -4
- package/src/toolkit/review-embed-document.mjs +671 -0
- package/src/toolkit/review-filmstrip.mjs +76 -0
- package/src/toolkit/review-motion-card.mjs +51 -0
- package/src/toolkit/review-motion.mjs +159 -0
- package/src/toolkit/review-playback.js +123 -0
- package/src/toolkit/review-sheet.mjs +36 -28
- package/src/toolkit/review.mjs +131 -31
- package/src/toolkit/runtime.mjs +7 -1
- package/src/viewer-cache.mjs +48 -12
package/public/assets.js
CHANGED
|
@@ -12,7 +12,7 @@ export function previewAddress(asset,theme,crop) {
|
|
|
12
12
|
return `preview/${asset.hash}?${query}`;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
export async function
|
|
15
|
+
export async function fetchSource(asset, theme, signal) {
|
|
16
16
|
const frameQuery = asset.onlyFrame && /\.(tsx|mmd)$/.test(asset.path) ? `&frame=${encodeURIComponent(asset.onlyFrame)}` : '';
|
|
17
17
|
const response = await dataFetch(
|
|
18
18
|
`asset/${encodeURIComponent(asset.path)}?theme=${theme}&v=${encodeURIComponent(asset.version)}${frameQuery}`,
|
|
@@ -23,7 +23,11 @@ export async function prepare(asset, theme, {signal} = {}) {
|
|
|
23
23
|
const problem = frameQuery && (await response.json().catch(() => null))?.error;
|
|
24
24
|
throw new Error(problem || `Cannot load ${asset.path}`);
|
|
25
25
|
}
|
|
26
|
-
|
|
26
|
+
return response.text();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export async function prepare(asset, theme, {signal, source: prefetched} = {}) {
|
|
30
|
+
const source = await (prefetched ?? fetchSource(asset, theme, signal));
|
|
27
31
|
if (/\.(tsx|mmd)$/.test(asset.path)) {
|
|
28
32
|
const built=JSON.parse(source);
|
|
29
33
|
return prepareSource({...asset,hash:built.hash??asset.hash,version:built.hash??asset.version},built,theme,signal);
|
|
@@ -298,10 +302,9 @@ export function arrange(data, { placed, previousGroups } = {}) {
|
|
|
298
302
|
return { groups, items, world: { x: 0, y: 0, width: Math.max(1, ...groups.map(g => g.x + g.w)), height: Math.max(1, ...groups.map(g => g.y + g.h)) } };
|
|
299
303
|
}
|
|
300
304
|
|
|
301
|
-
function
|
|
302
|
-
if(form.document)return form.document;
|
|
305
|
+
function formShell(form) {
|
|
303
306
|
const escape=value=>String(value).replace(/[&<>"']/g,c=>({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c]));
|
|
304
|
-
return
|
|
307
|
+
return `<div data-adg-frame="${escape(form.name)}" style="${form.width ? `width:${form.width}px;` : 'width:max-content;'}${form.height ? `height:${form.height}px;` : ''}">${form.html}</div>`;
|
|
305
308
|
}
|
|
306
309
|
async function prepareSource(asset, built, theme, signal) {
|
|
307
310
|
const endMeasurement = globalThis.__adgTiming?.span('measurement', asset.path, {frames:built.frames.length});
|
|
@@ -319,15 +322,20 @@ async function prepareSource(asset, built, theme, signal) {
|
|
|
319
322
|
await (globalThis.scheduler?.yield?.()??new Promise(resolve=>setTimeout(resolve,0)));
|
|
320
323
|
sliceStart=performance.now();
|
|
321
324
|
}
|
|
322
|
-
|
|
325
|
+
|
|
323
326
|
frame.style.width=(form.width ?? 1600)+'px'; frame.style.height=(form.height ?? 1200)+'px';
|
|
324
327
|
if (index === 0) {
|
|
325
|
-
|
|
328
|
+
const source = form.document ?? `<!doctype html><html data-theme="${theme}"><head><meta charset="utf-8"><meta name="darkreader-lock"><style data-adg-style>${built.css.replace(/<\/style/gi,'<\\/style')}</style></head><body>${formShell(form)}</body></html>`;
|
|
329
|
+
await new Promise(resolve=>{frame.onload=resolve;frame.srcdoc=source;});
|
|
326
330
|
} else {
|
|
327
331
|
// Frames from one source share CSS. Keep its sandbox document and viewport,
|
|
328
332
|
// replacing only the specimen instead of navigating for every form.
|
|
329
|
-
|
|
330
|
-
|
|
333
|
+
if (form.document) {
|
|
334
|
+
const parsed = new DOMParser().parseFromString(form.document, 'text/html');
|
|
335
|
+
frame.contentDocument.body.replaceChildren(frame.contentDocument.importNode(parsed.querySelector('[data-adg-frame]'), true));
|
|
336
|
+
} else {
|
|
337
|
+
frame.contentDocument.body.innerHTML = formShell(form);
|
|
338
|
+
}
|
|
331
339
|
await Promise.all([...frame.contentDocument.images].map(image => image.decode().catch(() => {})));
|
|
332
340
|
}
|
|
333
341
|
await frame.contentDocument.fonts.ready;
|
|
@@ -342,7 +350,14 @@ async function prepareSource(asset, built, theme, signal) {
|
|
|
342
350
|
const content=frame.contentDocument.createElement('div');
|
|
343
351
|
content.setAttribute('xmlns','http://www.w3.org/1999/xhtml');
|
|
344
352
|
content.setAttribute('style','font:16px/1.5 var(--font-ui);color:var(--text);');
|
|
345
|
-
|
|
353
|
+
const style=frame.contentDocument.createElement('style');
|
|
354
|
+
const sourceStyle=frame.contentDocument.querySelector('style[data-adg-style]')
|
|
355
|
+
?? frame.contentDocument.querySelector('head > style:not([class])')
|
|
356
|
+
?? frame.contentDocument.querySelector('style');
|
|
357
|
+
style.textContent=typeof built.css==='string' && !form.document
|
|
358
|
+
? built.css
|
|
359
|
+
: (sourceStyle?.textContent ?? '');
|
|
360
|
+
content.append(style,shell.cloneNode(true));
|
|
346
361
|
parts.push({id:String(index),name:form.name,note:form.note,proposed:form.proposed,width:box.width,height:box.height,elements,markup:new XMLSerializer().serializeToString(content)});
|
|
347
362
|
endFrame?.();
|
|
348
363
|
}
|
package/public/boards.js
CHANGED
|
@@ -98,9 +98,12 @@ export function createBoardLayer(viewport, onSource, { onSelectFrame, onFocusFra
|
|
|
98
98
|
tokenNode.innerHTML = `<style>${board.css}</style>${board.body}`;
|
|
99
99
|
root.prepend(tokenNode);
|
|
100
100
|
const node = tokenNode;
|
|
101
|
-
|
|
101
|
+
const measure = () => {
|
|
102
102
|
if (node.isConnected) onMeasure(node.offsetHeight);
|
|
103
|
-
}
|
|
103
|
+
};
|
|
104
|
+
measurement = requestAnimationFrame(measure);
|
|
105
|
+
node.querySelector('[data-motion-unadopted]')?.addEventListener('toggle', measure);
|
|
106
|
+
node.addEventListener('motion-layout-change', measure);
|
|
104
107
|
},
|
|
105
108
|
tokenSection(slug) {
|
|
106
109
|
if (!tokenNode?.isConnected) return null;
|
|
@@ -119,6 +122,8 @@ export function createBoardLayer(viewport, onSource, { onSelectFrame, onFocusFra
|
|
|
119
122
|
const css = getComputedStyle(root);
|
|
120
123
|
return Object.fromEntries(['surface','canvas','border','radius-card'].map(name => [name,css.getPropertyValue('--'+name).trim()]));
|
|
121
124
|
},
|
|
122
|
-
camera(view, hidden) {root.hidden = hidden;
|
|
125
|
+
camera(view, hidden) {root.hidden = hidden;
|
|
126
|
+
root.dataset.scale=view.scale;
|
|
127
|
+
root.style.transform=`translate(${view.x}px,${view.y}px) scale(${view.scale})`;},
|
|
123
128
|
};
|
|
124
129
|
}
|
package/public/frame-identity.js
CHANGED
|
@@ -197,11 +197,33 @@ export function collectViewerElements(shell, { projectSource, assetPath, frame,
|
|
|
197
197
|
const clean = n => n === 0 ? 0 : n;
|
|
198
198
|
const elements = [];
|
|
199
199
|
const boundaries = new Map();
|
|
200
|
+
const clips = new Map();
|
|
201
|
+
const clipsOverflow = /^(hidden|clip|scroll|auto)$/;
|
|
200
202
|
for (let i = 0; i < domNodes.length; i++) {
|
|
201
203
|
const node = domNodes[i], input = inputs[i], idRow = assigned[i];
|
|
202
204
|
const parentBoundary = boundaries.get(input.parentPath) ?? null;
|
|
203
205
|
boundaries.set(input.path, parentBoundary);
|
|
204
|
-
|
|
206
|
+
// Ancestor opacity/display and each overflow axis apply to the whole subtree.
|
|
207
|
+
// Visibility can be overridden lower down, so test it on the hit itself.
|
|
208
|
+
const inherited = clips.get(input.parentPath) ?? origin;
|
|
209
|
+
if (inherited === false) { clips.set(input.path, false); continue; }
|
|
210
|
+
const style = styleFor(node);
|
|
211
|
+
if (style.display === 'none' || Number(style.opacity) === 0) {
|
|
212
|
+
clips.set(input.path, false);
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
const clipX = style.display !== 'inline' && clipsOverflow.test(style.overflowX);
|
|
216
|
+
const clipY = style.display !== 'inline' && clipsOverflow.test(style.overflowY);
|
|
217
|
+
if (clipX || clipY) {
|
|
218
|
+
const rect = rectFor(node);
|
|
219
|
+
clips.set(input.path, {
|
|
220
|
+
left: clipX ? Math.max(inherited.left, rect.left) : inherited.left,
|
|
221
|
+
right: clipX ? Math.min(inherited.right, rect.right) : inherited.right,
|
|
222
|
+
top: clipY ? Math.max(inherited.top, rect.top) : inherited.top,
|
|
223
|
+
bottom: clipY ? Math.min(inherited.bottom, rect.bottom) : inherited.bottom,
|
|
224
|
+
});
|
|
225
|
+
} else clips.set(input.path, inherited);
|
|
226
|
+
if (input.neutral || style.visibility !== 'visible') continue;
|
|
205
227
|
const semanticRole = input.role ?? additionalCommentRoles.get(input.tag);
|
|
206
228
|
const role = /^(none|presentation)$/.test(semanticRole) ? null : semanticRole?.trim().split(/\s+/, 1)[0];
|
|
207
229
|
const boundary = Boolean(input.owners.length || input.keys.length || role ||
|
|
@@ -211,17 +233,8 @@ export function collectViewerElements(shell, { projectSource, assetPath, frame,
|
|
|
211
233
|
!node.hasAttribute('role') && containerRoots.has(node.localName);
|
|
212
234
|
if (commentOnly && !boundary) continue;
|
|
213
235
|
const rect = rectFor(node);
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
for (let p = node; p && p !== shell; p = p.parentElement) {
|
|
217
|
-
const s = styleFor(p);
|
|
218
|
-
if (s.display === 'none' || (p === node && s.visibility !== 'visible') || Number(s.opacity) === 0) { left = right; break; }
|
|
219
|
-
if (p !== node && s.display !== 'inline') {
|
|
220
|
-
const clip = rectFor(p);
|
|
221
|
-
if (/(hidden|clip|scroll|auto)/.test(s.overflowX)) { left = Math.max(left, clip.left); right = Math.min(right, clip.right); }
|
|
222
|
-
if (/(hidden|clip|scroll|auto)/.test(s.overflowY)) { top = Math.max(top, clip.top); bottom = Math.min(bottom, clip.bottom); }
|
|
223
|
-
}
|
|
224
|
-
}
|
|
236
|
+
const left = Math.max(rect.left, inherited.left), right = Math.min(rect.right, inherited.right);
|
|
237
|
+
const top = Math.max(rect.top, inherited.top), bottom = Math.min(rect.bottom, inherited.bottom);
|
|
225
238
|
if (right <= left || bottom <= top) continue;
|
|
226
239
|
const owner = idRow.defining.at(-1) ?? { source: assetPath, export: null };
|
|
227
240
|
if (boundary) boundaries.set(input.path, idRow.id);
|
package/public/icons.js
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
// Lucide geometry (ISC; see LICENSE). No runtime dependency.
|
|
2
2
|
const geometry = {
|
|
3
|
+
"route": "<circle cx=\"6\" cy=\"19\" r=\"3\"></circle><path d=\"M9 19h8.5a3.5 3.5 0 0 0 0-7h-11a3.5 3.5 0 0 1 0-7H15\"></path><circle cx=\"18\" cy=\"5\" r=\"3\"></circle>",
|
|
4
|
+
"settings-2": "<path d=\"M14 17H5\"></path><path d=\"M19 7h-9\"></path><circle cx=\"17\" cy=\"17\" r=\"3\"></circle><circle cx=\"7\" cy=\"7\" r=\"3\"></circle>",
|
|
5
|
+
"log-out": "<path d=\"m16 17 5-5-5-5\"></path><path d=\"M21 12H9\"></path><path d=\"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4\"></path>",
|
|
6
|
+
"rotate-ccw": "<path d=\"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8\"></path><path d=\"M3 3v5h5\"></path>",
|
|
7
|
+
"pause": "<rect x=\"14\" y=\"3\" width=\"5\" height=\"18\" rx=\"1\"></rect><rect x=\"5\" y=\"3\" width=\"5\" height=\"18\" rx=\"1\"></rect>",
|
|
8
|
+
"list-filter": '<path d="M3 6h18M6 12h12M9 18h6"/>',
|
|
3
9
|
"message-square": '<path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z" />',
|
|
4
10
|
"message-square-plus": '<path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2zM9 10h6m-3-3v6" />',
|
|
5
11
|
"messages-square": '<path d="M14 9a2 2 0 0 1-2 2H6l-4 4V4a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2zm4-5h2a2 2 0 0 1 2 2v16l-4-4h-7a2 2 0 0 1-2-2v-1" />',
|
|
6
12
|
"palette": "<path d=\"M12 22a1 1 0 0 1 0-20 10 9 0 0 1 10 9 5 5 0 0 1-5 5h-2.25a1.75 1.75 0 0 0-1.4 2.8l.3.4a1.75 1.75 0 0 1-1.4 2.8z\"></path><circle cx=\"13.5\" cy=\"6.5\" r=\".5\" fill=\"currentColor\"></circle><circle cx=\"17.5\" cy=\"10.5\" r=\".5\" fill=\"currentColor\"></circle><circle cx=\"6.5\" cy=\"12.5\" r=\".5\" fill=\"currentColor\"></circle><circle cx=\"8.5\" cy=\"7.5\" r=\".5\" fill=\"currentColor\"></circle>",
|
|
7
13
|
"type": "<path d=\"M12 4v16\"></path><path d=\"M4 7V5a1 1 0 0 1 1-1h14a1 1 0 0 1 1 1v2\"></path><path d=\"M9 20h6\"></path>",
|
|
14
|
+
"play": '<path d="m6 3 15 9-15 9z"/>',
|
|
8
15
|
"ruler": "<path d=\"M21.3 15.3a2.4 2.4 0 0 1 0 3.4l-2.6 2.6a2.4 2.4 0 0 1-3.4 0L2.7 8.7a2.41 2.41 0 0 1 0-3.4l2.6-2.6a2.41 2.41 0 0 1 3.4 0Z\"></path><path d=\"m14.5 12.5 2-2\"></path><path d=\"m11.5 9.5 2-2\"></path><path d=\"m8.5 6.5 2-2\"></path><path d=\"m17.5 15.5 2-2\"></path>",
|
|
9
16
|
"corner-up-right": "<path d=\"m15 14 5-5-5-5\"></path><path d=\"M4 20v-7a4 4 0 0 1 4-4h12\"></path>",
|
|
10
17
|
"timer": "<line x1=\"10\" x2=\"14\" y1=\"2\" y2=\"2\"></line><line x1=\"12\" x2=\"15\" y1=\"14\" y2=\"11\"></line><circle cx=\"12\" cy=\"14\" r=\"8\"></circle>",
|
package/public/index.html
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
<!doctype html>
|
|
2
2
|
<html lang="en" data-theme="light">
|
|
3
3
|
<head>
|
|
4
|
-
<meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
|
4
|
+
<meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="darkreader-lock">
|
|
5
5
|
<base href="/">
|
|
6
6
|
<title>Agent Design Gallery</title>
|
|
7
7
|
<link rel="icon" type="image/svg+xml" href="/favicon.svg">
|
|
8
8
|
<link rel="stylesheet" href="tokens.css"><link rel="stylesheet" href="style.css"><link rel="stylesheet" href="switcher.css"><link rel="stylesheet" href="access.css"><link rel="stylesheet" href="comments.css">
|
|
9
|
+
<link rel="stylesheet" href="view-boards.css">
|
|
9
10
|
<script type="module" src="app.js"></script>
|
|
10
11
|
</head>
|
|
11
12
|
<body>
|
|
@@ -28,11 +29,22 @@
|
|
|
28
29
|
<button type="button" id="app-directory" class="picker" aria-label="Current project"><span data-icon="folder" data-size="14"></span><span class="directory-name"></span><span class="switcher-chevron" data-icon="chevron-down" data-size="12" hidden></span></button>
|
|
29
30
|
<span class="separator project-divider"></span>
|
|
30
31
|
<div id="scope-tabs" role="tablist" aria-label="Design scope"></div>
|
|
32
|
+
<div id="frame-filter"><button id="filter-toggle" class="view-pill" aria-expanded="false" aria-controls="filter-options"><span data-icon="list-filter"></span><span id="filter-label">Filter frames</span><span data-icon="chevron-down" data-size="12"></span></button>
|
|
33
|
+
<div id="filter-options" hidden><button type="button" data-filter="all">All frames</button><button type="button" data-filter="playable">Playable</button><button type="button" data-filter="recent">Recently updated</button></div></div>
|
|
31
34
|
<button type="button" id="scope-isolation" class="isolation-pill" data-tooltip="Show full layer" hidden></button>
|
|
32
35
|
<button type="button" id="token-view-toggle" class="view-pill" hidden></button>
|
|
33
36
|
<span class="separator search-divider"></span>
|
|
34
37
|
<div class="search-field"><span data-icon="search" data-size="14"></span><input id="search" type="search" placeholder="Find assets…" aria-label="Find assets" autocomplete="off"><span id="search-key">⌘F</span><button id="search-clear" aria-label="Clear search" hidden><span data-icon="x" data-size="14"></span></button></div>
|
|
35
38
|
</div>
|
|
39
|
+
<main id="view-board" aria-labelledby="view-board-title" tabindex="-1" hidden>
|
|
40
|
+
<div class="view-board-page">
|
|
41
|
+
<header class="view-board-heading">
|
|
42
|
+
<button id="all-frames" class="view-pill"><span data-icon="arrow-left" data-size="14"></span>All frames</button>
|
|
43
|
+
<h1 id="view-board-title"></h1>
|
|
44
|
+
</header>
|
|
45
|
+
<div id="view-board-content"></div>
|
|
46
|
+
</div>
|
|
47
|
+
</main>
|
|
36
48
|
<aside id="sidebar" class="floating" aria-label="Contents" hidden>
|
|
37
49
|
<nav id="modules" aria-label="Design modules"></nav>
|
|
38
50
|
</aside>
|
|
@@ -69,7 +81,7 @@
|
|
|
69
81
|
<div id="tooltip" role="tooltip" hidden></div>
|
|
70
82
|
<dialog id="keys" aria-labelledby="keys-title"><h2 id="keys-title">Keyboard shortcuts</h2><button id="keys-close" class="icon-button dialog-close" aria-label="Close keyboard shortcuts"><span data-icon="x" data-size="14"></span></button><dl>
|
|
71
83
|
<div><dt>Search</dt><dd><kbd>⌘F</kbd></dd></div><div><dt>Fit all</dt><dd><kbd>0</kbd></dd></div><div><dt>Zoom to 100%</dt><dd><kbd>1</kbd></dd></div><div><dt>Zoom in or out</dt><dd><kbd>+</kbd><kbd>−</kbd></dd></div><div><dt>Pan</dt><dd><kbd>←</kbd><kbd>↑</kbd><kbd>→</kbd><kbd>↓</kbd></dd></div><div><dt>Focus selection</dt><dd><kbd>Enter</kbd></dd></div><div><dt>Back or close</dt><dd><kbd>Esc</kbd></dd></div>
|
|
72
|
-
<div><dt>Comment</dt><dd><kbd>C</kbd></dd></div><div><dt>Hide or show comment pins</dt><dd><kbd>⇧C</kbd></dd></div>
|
|
84
|
+
<div><dt>Play selected frame</dt><dd><kbd>P</kbd></dd></div><div><dt>Comment</dt><dd><kbd>C</kbd></dd></div><div><dt>Hide or show comment pins</dt><dd><kbd>⇧C</kbd></dd></div>
|
|
73
85
|
</dl></dialog>
|
|
74
86
|
<div id="error" role="alert" hidden></div>
|
|
75
87
|
<p id="controls" class="sr">Drag or scroll to pan. Pinch or Control or Command scroll to zoom. Arrow keys pan; plus and minus zoom; zero fits all; Escape goes back; one sets 100%. Click to select; double-click or Enter to focus.</p>
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { candidates } from './motion-identity.js';
|
|
2
|
+
|
|
3
|
+
export function flowAnchor(flow, frames) {
|
|
4
|
+
if (!frames.length) return null;
|
|
5
|
+
const targets = flow.anchor ? [flow.anchor] : flow.triggers;
|
|
6
|
+
for (const target of targets) {
|
|
7
|
+
const boxes = frames.map((frame) => {
|
|
8
|
+
const matches = candidates(frame.rows, target);
|
|
9
|
+
return matches.length === 1 && matches[0].box[2] > 0 && matches[0].box[3] > 0 ? matches[0].box : null;
|
|
10
|
+
});
|
|
11
|
+
if (boxes.every(Boolean)) return { target, boxes };
|
|
12
|
+
}
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function flowLayout(flow, frames) {
|
|
17
|
+
const pin = flowAnchor(flow, frames);
|
|
18
|
+
if (!frames.length) return { pin, offsets: [], width: 0, height: 0 };
|
|
19
|
+
const origins = frames.map(({ box }, i) => pin
|
|
20
|
+
? [box[0] - pin.boxes[i][0], box[1] - pin.boxes[i][1]]
|
|
21
|
+
: [0, 0]);
|
|
22
|
+
const left = Math.min(...origins.map(([x]) => x)),
|
|
23
|
+
top = Math.min(...origins.map(([, y]) => y));
|
|
24
|
+
const offsets = origins.map(([x, y]) => [x - left, y - top]);
|
|
25
|
+
const width = Math.max(...frames.map(({ box }, i) => offsets[i][0] + box[2])),
|
|
26
|
+
height = Math.max(...frames.map(({ box }, i) => offsets[i][1] + box[3]));
|
|
27
|
+
return { pin, offsets, width, height };
|
|
28
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
export function chain(rows, row) {
|
|
2
|
+
const result = [];
|
|
3
|
+
for (let r = row; r; r = rows[r.parent]) result.push(r);
|
|
4
|
+
return result;
|
|
5
|
+
}
|
|
6
|
+
export function matchRoots(from, to, excluded = { from: new Set(), to: new Set() }) {
|
|
7
|
+
function roots(rows, skip) {
|
|
8
|
+
return rows
|
|
9
|
+
.filter((r) => r.parts.length && !skip.has(r.i))
|
|
10
|
+
.map((row) => {
|
|
11
|
+
const scope = chain(rows, row)
|
|
12
|
+
.reverse()
|
|
13
|
+
.flatMap((r) => r.keys.map((k) => [r.parts, k.owner ?? null, k.key, k.root ?? null]));
|
|
14
|
+
return { row, key: JSON.stringify([row.parts, scope]), scope };
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
const left = roots(from, excluded.from),
|
|
18
|
+
right = roots(to, excluded.to),
|
|
19
|
+
a = new Map(),
|
|
20
|
+
b = new Map(),
|
|
21
|
+
pairs = [];
|
|
22
|
+
const matches = (roots, rows, matched) => {
|
|
23
|
+
const groups = new Map();
|
|
24
|
+
for (const root of roots) {
|
|
25
|
+
if (matched.has(root.row.i)) continue;
|
|
26
|
+
const parent = chain(rows, rows[root.row.parent]).find((p) => matched.has(p.i));
|
|
27
|
+
const key = JSON.stringify([root.key, parent ? matched.get(parent.i) : null]);
|
|
28
|
+
if (!groups.has(key)) groups.set(key, []);
|
|
29
|
+
groups.get(key).push(root);
|
|
30
|
+
}
|
|
31
|
+
return groups;
|
|
32
|
+
};
|
|
33
|
+
let ambiguous = [];
|
|
34
|
+
for (;;) {
|
|
35
|
+
const old = matches(left, from, a),
|
|
36
|
+
next = matches(right, to, b);
|
|
37
|
+
const before = pairs.length;
|
|
38
|
+
ambiguous = [];
|
|
39
|
+
for (const [key, group] of old) {
|
|
40
|
+
const other = next.get(key);
|
|
41
|
+
if (!other) continue;
|
|
42
|
+
if (group.length !== 1 || other.length !== 1) {
|
|
43
|
+
ambiguous.push({ part: group[0].row.parts.at(-1), from: group.length, to: other.length });
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
const f = group[0],
|
|
47
|
+
t = other[0],
|
|
48
|
+
id = pairs.length;
|
|
49
|
+
pairs.push({ from: f.row.i, to: t.row.i, parts: f.row.parts, keys: f.scope });
|
|
50
|
+
a.set(f.row.i, id);
|
|
51
|
+
b.set(t.row.i, id);
|
|
52
|
+
}
|
|
53
|
+
if (before === pairs.length) {
|
|
54
|
+
const conflicts = [];
|
|
55
|
+
for (const [side, roots] of [
|
|
56
|
+
['from', left],
|
|
57
|
+
['to', right]
|
|
58
|
+
]) {
|
|
59
|
+
const siblings = new Set();
|
|
60
|
+
for (const { row, key } of roots) {
|
|
61
|
+
if (!row.keys.length) continue;
|
|
62
|
+
const local = JSON.stringify([row.parent, key]);
|
|
63
|
+
if (siblings.has(local)) conflicts.push({ side, part: row.parts.at(-1) });
|
|
64
|
+
siblings.add(local);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
const limitations = pairs.flatMap((p) => {
|
|
68
|
+
const sides = [from[p.from], to[p.to]];
|
|
69
|
+
const reason =
|
|
70
|
+
sides.find((r) => r.limitation)?.limitation ??
|
|
71
|
+
(sides.some((r) => !r.box[2] || !r.box[3]) ? 'empty_box' : null);
|
|
72
|
+
return reason ? [{ from: p.from, to: p.to, reason }] : [];
|
|
73
|
+
});
|
|
74
|
+
return {
|
|
75
|
+
pairs,
|
|
76
|
+
ambiguous,
|
|
77
|
+
conflicts,
|
|
78
|
+
limitations,
|
|
79
|
+
counts: {
|
|
80
|
+
match: pairs.length,
|
|
81
|
+
enter: right.length - b.size,
|
|
82
|
+
exit: left.length - a.size,
|
|
83
|
+
ambiguous: ambiguous.length
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function instanceKeyMatches(ancestors, key) {
|
|
91
|
+
// An explicit instance key shadows the containing list's or slot's key.
|
|
92
|
+
return ancestors.find((row) => row.keys?.length)?.keys.some((k) => k.key === key) ?? false;
|
|
93
|
+
}
|
|
94
|
+
export function candidates(rows, target) {
|
|
95
|
+
if (target.frame) return rows.slice(0, 1);
|
|
96
|
+
if (target.anchor) return rows.filter((r) => r.anchor === target.anchor);
|
|
97
|
+
return rows.filter(
|
|
98
|
+
(r) => r.parts.includes(target.part) && (target.key === undefined || instanceKeyMatches(chain(rows, r), target.key))
|
|
99
|
+
);
|
|
100
|
+
}
|