@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
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { layoutWorld
|
|
1
|
+
import { layoutWorld } from './layout.js';
|
|
2
2
|
|
|
3
|
-
self.onmessage = ({data:{id,input,
|
|
3
|
+
self.onmessage = ({ data: { id, input, previousGroups } }) => {
|
|
4
4
|
try {
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
self.postMessage({id,placed,
|
|
8
|
-
} catch(error) {
|
|
9
|
-
self.postMessage({id,error:error.message});
|
|
5
|
+
const start = performance.now();
|
|
6
|
+
const placed = layoutWorld(input, { previousGroups });
|
|
7
|
+
self.postMessage({ id, placed, durationMs: performance.now() - start });
|
|
8
|
+
} catch (error) {
|
|
9
|
+
self.postMessage({ id, error: error.message });
|
|
10
10
|
}
|
|
11
11
|
};
|
package/public/arrangement.js
CHANGED
|
@@ -1,48 +1,53 @@
|
|
|
1
1
|
import { arrangementInput } from './assets.js';
|
|
2
|
-
import { packingSnapshot, restorePacking, layoutWorld } from './layout.js';
|
|
3
2
|
|
|
4
3
|
const aborted = () => new DOMException('Arrangement superseded', 'AbortError');
|
|
5
4
|
|
|
6
5
|
export function createArranger() {
|
|
7
|
-
let worker, nextId=0;
|
|
8
|
-
const pending=new Map();
|
|
9
|
-
function close(failure=aborted()) {
|
|
10
|
-
worker?.terminate();
|
|
11
|
-
|
|
6
|
+
let worker, nextId = 0;
|
|
7
|
+
const pending = new Map();
|
|
8
|
+
function close(failure = aborted()) {
|
|
9
|
+
worker?.terminate();
|
|
10
|
+
worker = undefined;
|
|
11
|
+
for (const task of pending.values()) task.finish(failure);
|
|
12
12
|
pending.clear();
|
|
13
13
|
}
|
|
14
14
|
function start() {
|
|
15
|
-
if(worker)return;
|
|
16
|
-
worker=new Worker(new URL('./arrangement-worker.js',import.meta.url),{type:'module'});
|
|
17
|
-
worker.onmessage=({data})=>{
|
|
18
|
-
const task=pending.get(data.id);
|
|
19
|
-
if(!task)return;
|
|
20
|
-
if(data.error)task.finish(Error(`Cannot arrange designs: ${data.error}`));
|
|
21
|
-
else
|
|
15
|
+
if (worker) return;
|
|
16
|
+
worker = new Worker(new URL('./arrangement-worker.js', import.meta.url), { type: 'module' });
|
|
17
|
+
worker.onmessage = ({ data }) => {
|
|
18
|
+
const task = pending.get(data.id);
|
|
19
|
+
if (!task) return;
|
|
20
|
+
if (data.error) task.finish(Error(`Cannot arrange designs: ${data.error}`));
|
|
21
|
+
else task.finish(null, data);
|
|
22
22
|
};
|
|
23
|
-
worker.onerror=event=>close(Error(`Cannot start arrangement worker: ${event.message}`));
|
|
23
|
+
worker.onerror = event => close(Error(`Cannot start arrangement worker: ${event.message}`));
|
|
24
24
|
}
|
|
25
25
|
return {
|
|
26
26
|
close,
|
|
27
|
-
get pending() {return pending.size;},
|
|
28
|
-
arrange(data,{signal,onPending}={}) {
|
|
27
|
+
get pending() { return pending.size; },
|
|
28
|
+
async arrange(data, { signal, onPending, previousGroups = [] } = {}) {
|
|
29
29
|
signal?.throwIfAborted();
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
const input = arrangementInput(data);
|
|
31
|
+
// Saved geometry is all the worker needs; prepared source and previews stay on the main thread.
|
|
32
|
+
const previous = previousGroups.map(({ key, layer, column, columnCount, columnWidth, w }) =>
|
|
33
|
+
({ key, layer, column, columnCount, columnWidth, w }));
|
|
34
34
|
onPending?.();
|
|
35
35
|
start();
|
|
36
|
-
const id
|
|
37
|
-
return new Promise((resolve,reject)=>{
|
|
38
|
-
const abort=()=>close();
|
|
39
|
-
pending.set(id,{finish(failure,result){
|
|
40
|
-
pending.delete(id);
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
36
|
+
const id = ++nextId, end = globalThis.__adgTiming?.span('arrangement-wait');
|
|
37
|
+
return new Promise((resolve, reject) => {
|
|
38
|
+
const abort = () => close();
|
|
39
|
+
pending.set(id, { finish(failure, result) {
|
|
40
|
+
pending.delete(id);
|
|
41
|
+
signal?.removeEventListener('abort', abort);
|
|
42
|
+
end?.({ workerMs: result?.durationMs });
|
|
43
|
+
failure ? reject(failure) : resolve(result.placed);
|
|
44
|
+
} });
|
|
45
|
+
signal?.addEventListener('abort', abort, { once: true });
|
|
46
|
+
try {
|
|
47
|
+
worker.postMessage({ id, input, previousGroups: previous });
|
|
48
|
+
} catch (error) {
|
|
49
|
+
close(error);
|
|
50
|
+
}
|
|
46
51
|
});
|
|
47
52
|
},
|
|
48
53
|
};
|
package/public/assets.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { dataFetch } from './auth.js';
|
|
2
2
|
import { collectViewerElements } from './frame-identity.js';
|
|
3
|
-
import { blockForAsset, componentWrapWidth, layoutWorld } from "./layout.js";
|
|
3
|
+
import { blockForAsset, componentWrapWidth, layoutWorld, specimenPaintCrop } from "./layout.js";
|
|
4
4
|
// Measure declared SVG content in an isolated, script-disabled document.
|
|
5
|
-
export const metadataContext = () => `
|
|
5
|
+
export const metadataContext = () => `specimen-bleed-v2-comments|${navigator.userAgent}|${devicePixelRatio}`;
|
|
6
6
|
export function measuredMetadata(asset) {
|
|
7
7
|
const {format,full,component,parts,background,imports,frameRanges}=asset;
|
|
8
8
|
return {format,full,component,parts,background,imports,frameRanges};
|
|
@@ -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);
|
|
@@ -187,27 +191,44 @@ export function evictPreviews(cache, activeKeys) {
|
|
|
187
191
|
}
|
|
188
192
|
|
|
189
193
|
export function groupAssets(data) {
|
|
194
|
+
const layerOf = asset => asset.layer ?? (asset.path.includes('/') ? asset.path.split('/')[0] : 'Design');
|
|
190
195
|
const byPath = new Map(data.assets.map(asset => [asset.path, asset]));
|
|
191
|
-
const used = new Set(),
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
const
|
|
195
|
-
const
|
|
196
|
-
if (!
|
|
197
|
-
|
|
198
|
-
|
|
196
|
+
const used = new Set(), grouped = [];
|
|
197
|
+
const add = (group, assets, key) => {
|
|
198
|
+
const layers = new Map();
|
|
199
|
+
for (const asset of assets) {
|
|
200
|
+
const layer = layerOf(asset);
|
|
201
|
+
if (!layers.has(layer)) layers.set(layer, []);
|
|
202
|
+
layers.get(layer).push(asset);
|
|
203
|
+
}
|
|
204
|
+
for (const [layer, members] of layers) grouped.push({ ...group, key: `${key}:${layer}`, layer, assets: members });
|
|
205
|
+
};
|
|
206
|
+
for (const [index, group] of (data.groups ?? []).entries()) {
|
|
207
|
+
const assets = group.assets.flatMap(path => {
|
|
208
|
+
const asset = byPath.get(path);
|
|
209
|
+
if (!asset || used.has(path)) return [];
|
|
210
|
+
used.add(path);
|
|
211
|
+
return [asset];
|
|
199
212
|
});
|
|
200
|
-
|
|
213
|
+
add(group, assets, `group:${index}:${group.title}`);
|
|
201
214
|
}
|
|
202
215
|
const rest = new Map();
|
|
203
|
-
for (const
|
|
204
|
-
if (used.has(
|
|
205
|
-
const parent =
|
|
216
|
+
for (const asset of data.assets) {
|
|
217
|
+
if (used.has(asset.path)) continue;
|
|
218
|
+
const parent = asset.path.split('/').slice(0, -1).join('/') || 'Design';
|
|
206
219
|
if (!rest.has(parent)) rest.set(parent, []);
|
|
207
|
-
rest.get(parent).push(
|
|
220
|
+
rest.get(parent).push(asset);
|
|
208
221
|
}
|
|
209
|
-
for (const [title, assets] of rest)
|
|
210
|
-
|
|
222
|
+
for (const [title, assets] of rest) add({ title }, assets, `directory:${title}`);
|
|
223
|
+
const canonical = ['tokens', 'components', 'modules', 'surfaces', 'studies'];
|
|
224
|
+
const layers = [...new Set([...canonical, ...(data.layers ?? []).map(layer => layer.toLowerCase()), ...grouped.map(group => group.layer.toLowerCase())])];
|
|
225
|
+
grouped.sort((a, b) => layers.indexOf(a.layer.toLowerCase()) - layers.indexOf(b.layer.toLowerCase()));
|
|
226
|
+
const chapters = new Map();
|
|
227
|
+
return grouped.map(group => {
|
|
228
|
+
const chapter = (chapters.get(group.layer) ?? 0) + 1;
|
|
229
|
+
chapters.set(group.layer, chapter);
|
|
230
|
+
return { ...group, chapter };
|
|
231
|
+
});
|
|
211
232
|
}
|
|
212
233
|
|
|
213
234
|
export function scopeKind(scope) {
|
|
@@ -236,8 +257,8 @@ export function resolveScope(data, layers, requested) {
|
|
|
236
257
|
if (layerAssets.has(key)) return result(requested, layerAssets.get(key));
|
|
237
258
|
break;
|
|
238
259
|
case 'group': {
|
|
239
|
-
const
|
|
240
|
-
if (
|
|
260
|
+
const groups = groupAssets(data).filter(item => item.title === key);
|
|
261
|
+
if (groups.length) return result(requested, groups.flatMap(group => group.assets));
|
|
241
262
|
break;
|
|
242
263
|
}
|
|
243
264
|
case 'asset': {
|
|
@@ -252,34 +273,38 @@ export function resolveScope(data, layers, requested) {
|
|
|
252
273
|
|
|
253
274
|
|
|
254
275
|
export function arrangementInput(data) {
|
|
255
|
-
return groupAssets(data).map(group => ({blocks:
|
|
276
|
+
return groupAssets(data).map(({ assets, ...group }) => ({ ...group, blocks: assets.map(blockForAsset) }));
|
|
256
277
|
}
|
|
257
278
|
|
|
258
|
-
export function arrange(data, {
|
|
279
|
+
export function arrange(data, { placed, previousGroups } = {}) {
|
|
259
280
|
const grouped = groupAssets(data);
|
|
260
|
-
const
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
const groups =
|
|
281
|
+
const boards = previousGroups ? layoutWorld(arrangementInput(data), { previousGroups })
|
|
282
|
+
: placed ?? layoutWorld(arrangementInput(data));
|
|
283
|
+
const byKey = new Map(grouped.map(group => [group.key, group]));
|
|
284
|
+
const groups = boards.map(board => ({ ...byKey.get(board.key), ...board, width: board.w, height: board.h }));
|
|
264
285
|
const items = [];
|
|
265
|
-
for (const [group,
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
const
|
|
269
|
-
for (const frame of frames) {
|
|
270
|
-
const crop = { ...frame.crop, width: frame.
|
|
271
|
-
items.push({ ...asset,
|
|
272
|
-
|
|
286
|
+
for (const [group, board] of groups.entries()) {
|
|
287
|
+
const byPath = new Map(board.assets.map(asset => [asset.path, asset]));
|
|
288
|
+
for (const section of board.blocks) {
|
|
289
|
+
const asset = byPath.get(section.asset);
|
|
290
|
+
for (const frame of section.frames) {
|
|
291
|
+
const crop = { ...frame.crop, width: frame.w, height: frame.h, id: frame.id, name: frame.name };
|
|
292
|
+
items.push({ ...asset, name: section.title, sourceComponent: asset.sourceComponent ?? !!asset.component, component: false, id: `${asset.path}#${frame.id}`, kind: 'flow', group,
|
|
293
|
+
x: board.x + section.x + frame.x, y: board.y + section.y + frame.y,
|
|
294
|
+
width: frame.w, height: frame.h, shown: [crop],
|
|
295
|
+
well: {x:board.x+section.x+frame.well.x,y:board.y+section.y+frame.well.y,width:frame.well.w,height:frame.well.h},
|
|
296
|
+
paintCrop: specimenPaintCrop(asset, crop),
|
|
297
|
+
previewCrop: section.previewCrop ?? specimenPaintCrop(asset, crop),
|
|
298
|
+
});
|
|
273
299
|
}
|
|
274
300
|
}
|
|
275
301
|
}
|
|
276
|
-
return { groups, items, world: { x: 0, y: 0, width: Math.max(1, ...groups.map(g => g.x + g.
|
|
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)) } };
|
|
277
303
|
}
|
|
278
304
|
|
|
279
|
-
function
|
|
280
|
-
if(form.document)return form.document;
|
|
305
|
+
function formShell(form) {
|
|
281
306
|
const escape=value=>String(value).replace(/[&<>"']/g,c=>({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c]));
|
|
282
|
-
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>`;
|
|
283
308
|
}
|
|
284
309
|
async function prepareSource(asset, built, theme, signal) {
|
|
285
310
|
const endMeasurement = globalThis.__adgTiming?.span('measurement', asset.path, {frames:built.frames.length});
|
|
@@ -297,15 +322,20 @@ async function prepareSource(asset, built, theme, signal) {
|
|
|
297
322
|
await (globalThis.scheduler?.yield?.()??new Promise(resolve=>setTimeout(resolve,0)));
|
|
298
323
|
sliceStart=performance.now();
|
|
299
324
|
}
|
|
300
|
-
|
|
325
|
+
|
|
301
326
|
frame.style.width=(form.width ?? 1600)+'px'; frame.style.height=(form.height ?? 1200)+'px';
|
|
302
327
|
if (index === 0) {
|
|
303
|
-
|
|
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;});
|
|
304
330
|
} else {
|
|
305
331
|
// Frames from one source share CSS. Keep its sandbox document and viewport,
|
|
306
332
|
// replacing only the specimen instead of navigating for every form.
|
|
307
|
-
|
|
308
|
-
|
|
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
|
+
}
|
|
309
339
|
await Promise.all([...frame.contentDocument.images].map(image => image.decode().catch(() => {})));
|
|
310
340
|
}
|
|
311
341
|
await frame.contentDocument.fonts.ready;
|
|
@@ -320,16 +350,23 @@ async function prepareSource(asset, built, theme, signal) {
|
|
|
320
350
|
const content=frame.contentDocument.createElement('div');
|
|
321
351
|
content.setAttribute('xmlns','http://www.w3.org/1999/xhtml');
|
|
322
352
|
content.setAttribute('style','font:16px/1.5 var(--font-ui);color:var(--text);');
|
|
323
|
-
|
|
324
|
-
|
|
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));
|
|
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)});
|
|
325
362
|
endFrame?.();
|
|
326
363
|
}
|
|
327
364
|
const wrapWidth = built.component ? componentWrapWidth(parts) : Infinity;
|
|
328
365
|
let x=0,y=0,rowHeight=0;
|
|
329
366
|
for (const part of parts) {
|
|
330
|
-
if (x && x+part.width>wrapWidth) { x=0;y+=rowHeight+
|
|
367
|
+
if (x && x+part.width>wrapWidth) { x=0;y+=rowHeight+64;rowHeight=0; }
|
|
331
368
|
Object.assign(part,{x,y});
|
|
332
|
-
x+=part.width+
|
|
369
|
+
x+=part.width+48;rowHeight=Math.max(rowHeight,part.height);
|
|
333
370
|
}
|
|
334
371
|
const width=Math.max(1,...parts.map(p=>p.x+p.width)),height=Math.max(1,...parts.map(p=>p.y+p.height));
|
|
335
372
|
const xml = value => String(value).replace(/[&<>"']/g,c=>({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c]));
|
|
@@ -337,7 +374,7 @@ async function prepareSource(asset, built, theme, signal) {
|
|
|
337
374
|
let offset=header.length;
|
|
338
375
|
const frameRanges=[];
|
|
339
376
|
const markup=parts.map(p=>{
|
|
340
|
-
const value=`<g ${built.component ? 'data-component="source" data-form="'+xml(p.name)+'"' : 'data-part="frame-'+xml(p.name)+'"'}><foreignObject overflow="
|
|
377
|
+
const value=`<g ${built.component ? 'data-component="source" data-form="'+xml(p.name)+'"' : 'data-part="frame-'+xml(p.name)+'"'}><foreignObject overflow="hidden" x="${p.x-24}" y="${p.y-32}" width="${p.width+48}" height="${p.height+64}"><div xmlns="http://www.w3.org/1999/xhtml" style="padding:32px 24px;box-sizing:border-box;width:${p.width+48}px;height:${p.height+64}px">${p.markup}</div></foreignObject></g>`;
|
|
341
378
|
frameRanges.push([offset,offset+value.length]);offset+=value.length;
|
|
342
379
|
return value;
|
|
343
380
|
});
|
package/public/auth.js
CHANGED
|
@@ -2,12 +2,28 @@ import { icon } from './icons.js';
|
|
|
2
2
|
const storageKey = 'adg-key';
|
|
3
3
|
let unauthorized = false;
|
|
4
4
|
|
|
5
|
+
function extractKey(raw) {
|
|
6
|
+
const value = String(raw ?? '').trim();
|
|
7
|
+
if (!value) return '';
|
|
8
|
+
if (/^https?:\/\//i.test(value) || /[?&]key=/.test(value)) {
|
|
9
|
+
try {
|
|
10
|
+
const parsed = new URL(value, window.location.origin).searchParams.get('key')?.trim();
|
|
11
|
+
if (parsed) return parsed;
|
|
12
|
+
} catch {}
|
|
13
|
+
const match = /[?&]key=([^&#\s]+)/.exec(value);
|
|
14
|
+
if (match) {
|
|
15
|
+
try { return decodeURIComponent(match[1]).trim(); } catch { return match[1].trim(); }
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return value;
|
|
19
|
+
}
|
|
20
|
+
|
|
5
21
|
export function captureKey() {
|
|
6
22
|
if (typeof window === 'undefined') return;
|
|
7
23
|
const url = new URL(window.location.href);
|
|
8
24
|
if (!url.searchParams.has('key')) return;
|
|
9
|
-
const key = url.searchParams.get('key');
|
|
10
|
-
window.localStorage.setItem(storageKey, key);
|
|
25
|
+
const key = url.searchParams.get('key')?.trim();
|
|
26
|
+
if (key) window.localStorage.setItem(storageKey, key);
|
|
11
27
|
url.searchParams.delete('key');
|
|
12
28
|
window.history.replaceState(window.history.state, '', url.pathname + url.search + url.hash);
|
|
13
29
|
}
|
|
@@ -23,15 +39,54 @@ export function showUnauthorized() {
|
|
|
23
39
|
if (gallery) gallery.hidden = true;
|
|
24
40
|
const hub = document.querySelector('#hub');
|
|
25
41
|
if (hub) hub.hidden = true;
|
|
42
|
+
const pageError = document.querySelector('#error');
|
|
43
|
+
if (pageError) pageError.hidden = true;
|
|
26
44
|
for (const popover of document.querySelectorAll(':popover-open')) popover.hidePopover();
|
|
27
45
|
for (const dialog of document.querySelectorAll('dialog[open]')) dialog.close();
|
|
28
46
|
const shell = document.createElement('main');
|
|
29
47
|
shell.className = 'access-shell';
|
|
30
48
|
shell.setAttribute('aria-label', 'Hub access');
|
|
31
|
-
shell.innerHTML = `<div class="access-brand">ADG</div><div class="access-center"><section class="access-card" role="alert" aria-labelledby="access-title"><div class="access-code">${icon('key-round', 20)}<span>401</span></div><div class="access-copy"><h1 id="access-title">Key required</h1><p></p></div></section></div>`;
|
|
32
|
-
shell.querySelector('p').textContent = storedKey()
|
|
49
|
+
shell.innerHTML = `<div class="access-brand">ADG</div><div class="access-center"><section class="access-card" role="alert" aria-labelledby="access-title"><div class="access-code">${icon('key-round', 20)}<span>401</span></div><div class="access-copy"><h1 id="access-title">Key required</h1><p></p></div><form class="access-form"><div class="access-field-row"><input type="password" class="access-input" placeholder="adg_… or ?key= URL" aria-label="Access key" autocomplete="off" spellcheck="false"><button type="submit" class="access-submit">Unlock</button></div><p class="access-error" aria-live="polite" hidden></p><code class="access-hint">adg serve --print-key</code></form></section></div>`;
|
|
50
|
+
shell.querySelector('.access-copy p').textContent = storedKey()
|
|
33
51
|
? 'The key saved in this browser was rejected.' : 'This browser needs an access key.';
|
|
52
|
+
const form = shell.querySelector('.access-form');
|
|
53
|
+
const input = shell.querySelector('.access-input');
|
|
54
|
+
const submit = shell.querySelector('.access-submit');
|
|
55
|
+
const errorNode = shell.querySelector('.access-error');
|
|
56
|
+
input.addEventListener('input', () => {
|
|
57
|
+
errorNode.hidden = true;
|
|
58
|
+
input.removeAttribute('aria-invalid');
|
|
59
|
+
});
|
|
60
|
+
form.addEventListener('submit', async event => {
|
|
61
|
+
event.preventDefault();
|
|
62
|
+
const candidate = extractKey(input.value);
|
|
63
|
+
if (!candidate) {
|
|
64
|
+
errorNode.textContent = 'Access key rejected.';
|
|
65
|
+
errorNode.hidden = false;
|
|
66
|
+
input.setAttribute('aria-invalid', 'true');
|
|
67
|
+
input.focus();
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
submit.disabled = true;
|
|
71
|
+
errorNode.hidden = true;
|
|
72
|
+
const probe = location.pathname.startsWith('/p/') || location.pathname.startsWith('/i/') ? 'manifest' : '/api/projects';
|
|
73
|
+
try {
|
|
74
|
+
const response = await fetch(new URL(probe, document.baseURI), { headers: { Authorization: `Bearer ${candidate}` } });
|
|
75
|
+
if (response.status === 200) {
|
|
76
|
+
window.localStorage.setItem(storageKey, candidate);
|
|
77
|
+
window.location.reload();
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
} catch {}
|
|
81
|
+
submit.disabled = false;
|
|
82
|
+
errorNode.textContent = 'Access key rejected.';
|
|
83
|
+
errorNode.hidden = false;
|
|
84
|
+
input.setAttribute('aria-invalid', 'true');
|
|
85
|
+
input.focus();
|
|
86
|
+
input.select();
|
|
87
|
+
});
|
|
34
88
|
document.body.append(shell);
|
|
89
|
+
input.focus({ preventScroll: true });
|
|
35
90
|
window.dispatchEvent(new Event('adg-unauthorized'));
|
|
36
91
|
}
|
|
37
92
|
function storedKey() {
|
package/public/boards.js
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { icon } from './icons.js';
|
|
2
|
+
|
|
3
|
+
// Vector-sharp board typography shares the camera transform with preview pixels.
|
|
4
|
+
const escape = value => String(value ?? '').replace(/[&<>"']/g, c => ({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c]));
|
|
5
|
+
const sourceIcon = '<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>';
|
|
6
|
+
const copyTimers = new WeakMap();
|
|
7
|
+
|
|
8
|
+
function markCopied(node, duration = 1200) {
|
|
9
|
+
node.dataset.copied = 'true';
|
|
10
|
+
clearTimeout(copyTimers.get(node));
|
|
11
|
+
copyTimers.set(node, setTimeout(() => { delete node.dataset.copied; }, duration));
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function createBoardLayer(viewport, onSource, { onSelectFrame, onFocusFrame, onCopyError } = {}) {
|
|
15
|
+
const root = document.createElement('div');
|
|
16
|
+
root.id = 'board-chrome';
|
|
17
|
+
viewport.append(root);
|
|
18
|
+
root.addEventListener('pointerdown', event => {
|
|
19
|
+
if (event.target.closest('button, [data-frame-name], [data-adg-token] code')) event.stopPropagation();
|
|
20
|
+
});
|
|
21
|
+
root.addEventListener('dblclick', event => {
|
|
22
|
+
if (event.target.closest('[data-adg-token] code')) {
|
|
23
|
+
event.stopPropagation();
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const caption = event.target.closest('[data-frame-name]');
|
|
27
|
+
if (caption) {
|
|
28
|
+
event.stopPropagation();
|
|
29
|
+
onFocusFrame?.(caption.dataset.frameSource, caption.dataset.frameName);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
root.addEventListener('click', event => {
|
|
33
|
+
const button = event.target.closest('[data-source]');
|
|
34
|
+
if (button) {
|
|
35
|
+
event.stopPropagation();
|
|
36
|
+
onSource(button.dataset.source, button.dataset.title ?? button.textContent, button);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const caption = event.target.closest('[data-frame-name]');
|
|
40
|
+
if (caption) {
|
|
41
|
+
event.stopPropagation();
|
|
42
|
+
onSelectFrame?.(caption.dataset.frameSource, caption.dataset.frameName);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const tokenCode = event.target.closest('[data-adg-token] code');
|
|
46
|
+
if (tokenCode) {
|
|
47
|
+
event.stopPropagation();
|
|
48
|
+
const text = tokenCode.textContent.trim();
|
|
49
|
+
navigator.clipboard.writeText(text).then(() => {
|
|
50
|
+
markCopied(tokenCode);
|
|
51
|
+
onCopyError?.(null);
|
|
52
|
+
}, failure => onCopyError?.(failure));
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
let tokenNode;
|
|
56
|
+
let measurement;
|
|
57
|
+
const themeStyle = document.createElement('style');
|
|
58
|
+
root.before(themeStyle);
|
|
59
|
+
return {
|
|
60
|
+
update(groups, items, data) {
|
|
61
|
+
cancelAnimationFrame(measurement);
|
|
62
|
+
themeStyle.textContent = data.boardCss ?? "";
|
|
63
|
+
root.replaceChildren(...groups.map((group, index) => {
|
|
64
|
+
const node = document.createElement('article');
|
|
65
|
+
node.className = 'chapter-board';
|
|
66
|
+
node.style.cssText = `left:${group.x}px;top:${group.y}px;width:${group.width}px;height:${group.height}px`;
|
|
67
|
+
const sources = group.assets ?? [];
|
|
68
|
+
node.innerHTML = `<header><div><p class="board-eyebrow"><b>${String(group.chapter ?? index + 1).padStart(2,'0')}</b>${escape(data.label)} · ${escape(group.layer)}</p><h1>${escape(group.title)}</h1></div><p>${sources.length} sources · ${sources.reduce((n,a)=>n+a.parts.length,0)} frames</p></header>`;
|
|
69
|
+
for (const block of group.blocks ?? []) {
|
|
70
|
+
const asset = sources.find(a => a.path === block.asset);
|
|
71
|
+
if (!asset) continue;
|
|
72
|
+
const row = document.createElement('section');
|
|
73
|
+
row.className = 'board-source';
|
|
74
|
+
row.style.cssText = `left:80px;top:${block.y}px;width:${group.width-160}px`;
|
|
75
|
+
const title = asset.path.endsWith('/index.tsx') ? asset.path.split('/').at(-2) : block.title;
|
|
76
|
+
row.innerHTML = `<button type="button" data-source="${escape(asset.path)}" data-title="${escape(title)}">${escape(title)}<span class="board-copy-icon" data-icon="copy" data-size="14">${icon('copy', 14)}</span></button><p class="board-path">${sourceIcon}<span>${escape(asset.projectSource ?? asset.path)}</span></p><p class="board-modified">${escape(asset.modified?.text)}</p>`;
|
|
77
|
+
node.append(row);
|
|
78
|
+
}
|
|
79
|
+
for (const section of group.blocks ?? []) for (const specimen of section.frames) {
|
|
80
|
+
const caption = document.createElement('div');
|
|
81
|
+
caption.className = 'board-caption';
|
|
82
|
+
caption.dataset.frameName = specimen.name;
|
|
83
|
+
caption.dataset.frameSource = section.asset;
|
|
84
|
+
caption.style.cssText = `left:${section.x+specimen.caption.x}px;top:${section.y+specimen.caption.y}px;width:${specimen.caption.w}px`;
|
|
85
|
+
caption.innerHTML = `<span>${escape(specimen.name)}</span><small>${escape(specimen.note)}${specimen.proposal ? ` · Proposed: ${escape(specimen.proposal)}` : ''}</small>`;
|
|
86
|
+
node.append(caption);
|
|
87
|
+
}
|
|
88
|
+
return node;
|
|
89
|
+
}));
|
|
90
|
+
},
|
|
91
|
+
tokens(board, onMeasure) {
|
|
92
|
+
cancelAnimationFrame(measurement);
|
|
93
|
+
tokenNode?.remove();
|
|
94
|
+
tokenNode = null;
|
|
95
|
+
if (!board) return;
|
|
96
|
+
tokenNode = document.createElement('div');
|
|
97
|
+
tokenNode.className = 'token-board-drawing';
|
|
98
|
+
tokenNode.innerHTML = `<style>${board.css}</style>${board.body}`;
|
|
99
|
+
root.prepend(tokenNode);
|
|
100
|
+
const node = tokenNode;
|
|
101
|
+
const measure = () => {
|
|
102
|
+
if (node.isConnected) onMeasure(node.offsetHeight);
|
|
103
|
+
};
|
|
104
|
+
measurement = requestAnimationFrame(measure);
|
|
105
|
+
node.querySelector('[data-motion-unadopted]')?.addEventListener('toggle', measure);
|
|
106
|
+
node.addEventListener('motion-layout-change', measure);
|
|
107
|
+
},
|
|
108
|
+
tokenSection(slug) {
|
|
109
|
+
if (!tokenNode?.isConnected) return null;
|
|
110
|
+
const section = tokenNode.querySelector(`[data-adg-section$="#${CSS.escape(slug)}"]`);
|
|
111
|
+
if (!section) return null;
|
|
112
|
+
const base = tokenNode.getBoundingClientRect(), box = section.getBoundingClientRect();
|
|
113
|
+
const scale = Number(root.dataset.scale) || 1;
|
|
114
|
+
return {
|
|
115
|
+
x: 0,
|
|
116
|
+
y: (box.top - base.top) / scale,
|
|
117
|
+
width: base.width / scale || tokenNode.offsetWidth,
|
|
118
|
+
height: box.height / scale || section.offsetHeight,
|
|
119
|
+
};
|
|
120
|
+
},
|
|
121
|
+
palette() {
|
|
122
|
+
const css = getComputedStyle(root);
|
|
123
|
+
return Object.fromEntries(['surface','canvas','border','radius-card'].map(name => [name,css.getPropertyValue('--'+name).trim()]));
|
|
124
|
+
},
|
|
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})`;},
|
|
128
|
+
};
|
|
129
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
const clamp = (value, size) => Math.min(size, Math.max(0, value ?? 0));
|
|
2
|
+
|
|
3
|
+
export function commentLabel(source, frame) {
|
|
4
|
+
const label = source.replace(/\.[^./]+$/, '');
|
|
5
|
+
return frame ? `${label}#${frame}` : label;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function commentElement(elements, hit, deepest = false) {
|
|
9
|
+
if (!hit || deepest || hit.commentBoundary === hit.id) return hit;
|
|
10
|
+
return elements.find(element => element.id === hit.commentBoundary) ?? null;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function placeComment({ source = null, frame = null, layer = null, chapter = null, box,
|
|
14
|
+
frameBox = null, element = null, owner = null, label }, point) {
|
|
15
|
+
const kind = element ? 'element' : frame ? 'frame' : source ? 'source' : 'chapter';
|
|
16
|
+
const tag = element?.tag ?? null, text = element?.commentText ?? element?.text ?? null;
|
|
17
|
+
const name = element?.commentName || element?.owner?.export || 'Element';
|
|
18
|
+
const displayName = element ? `${name[0].toUpperCase() + name.slice(1)}${text ? ` “${text}”` : ''}` : label;
|
|
19
|
+
return {
|
|
20
|
+
anchor: {
|
|
21
|
+
kind, source, frame, layer, chapter, element: element ? { id: element.id } : null,
|
|
22
|
+
x: clamp(point.x - box.x, box.width), y: clamp(point.y - box.y, box.height),
|
|
23
|
+
frameX: frameBox ? clamp(point.x - frameBox.x, frameBox.width) : null,
|
|
24
|
+
frameY: frameBox ? clamp(point.y - frameBox.y, frameBox.height) : null,
|
|
25
|
+
},
|
|
26
|
+
target: { label, tag, text, owner, displayName },
|
|
27
|
+
hint: displayName,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function attachComment(thread, { chapter, source, frame, elements = [] }) {
|
|
32
|
+
const { anchor, target } = thread;
|
|
33
|
+
if (anchor.kind === 'chapter') {
|
|
34
|
+
return chapter ? attach(chapter, anchor.x, anchor.y, false) : null;
|
|
35
|
+
}
|
|
36
|
+
if (anchor.kind === 'source') return source ? attach(source, anchor.x, anchor.y, false) : null;
|
|
37
|
+
if (!frame) return source ? attach(source, 0, 0, true) : null;
|
|
38
|
+
if (anchor.kind === 'frame') return attach(frame, anchor.x, anchor.y, false);
|
|
39
|
+
const element = elements.find(candidate => {
|
|
40
|
+
const text = target.displayName ? candidate.commentText ?? candidate.text : candidate.text;
|
|
41
|
+
return candidate.id === anchor.element?.id && (!target.tag || !candidate.tag || target.tag === candidate.tag) &&
|
|
42
|
+
(target.text === null || text === undefined || target.text === text);
|
|
43
|
+
});
|
|
44
|
+
return element ? attach({ ...element, x: frame.x + element.x, y: frame.y + element.y }, anchor.x, anchor.y, false)
|
|
45
|
+
: attach(frame, anchor.frameX, anchor.frameY, true);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function attach(box, x, y, changed) {
|
|
49
|
+
return { x: box.x + clamp(x, box.width), y: box.y + clamp(y, box.height), box, changed };
|
|
50
|
+
}
|