@whzxc/agent-design-gallery 0.14.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -16
- package/package.json +1 -1
- package/public/access.css +15 -2
- package/public/app.js +708 -483
- package/public/arrangement-worker.js +7 -7
- package/public/arrangement.js +35 -30
- package/public/assets.js +60 -38
- package/public/auth.js +59 -4
- package/public/boards.js +124 -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 +26 -2
- package/public/hub.css +25 -3
- package/public/hub.html +10 -2
- package/public/hub.js +127 -23
- package/public/icons.js +2 -0
- package/public/index.html +13 -9
- package/public/instance-actions.js +9 -2
- package/public/layout.js +156 -86
- package/public/selection.js +1 -1
- package/public/style.css +74 -152
- package/public/switcher.css +5 -4
- package/public/switcher.js +109 -34
- package/public/token-catalog.js +8 -3
- package/public/tokens.css +14 -1
- package/public/view-route.js +0 -1
- package/src/boards/board.mjs +30 -0
- package/src/boards/token-board.mjs +196 -0
- package/src/cli-output.mjs +8 -5
- package/src/cli.mjs +49 -29
- package/src/comments.mjs +293 -0
- package/src/http.mjs +2 -3
- 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/server.mjs +57 -93
- package/src/service.mjs +46 -12
- package/src/toolkit/arch.mjs +3 -2
- package/src/toolkit/asset-rules.mjs +24 -1
- package/src/toolkit/build-worker.mjs +6 -2
- package/src/toolkit/build.mjs +4 -2
- package/src/toolkit/commands.mjs +12 -7
- package/{public/review.js → src/toolkit/diff-document.mjs} +137 -43
- package/src/toolkit/diff-inputs.mjs +66 -30
- package/src/toolkit/diff.mjs +181 -39
- package/src/toolkit/impact-selection.mjs +25 -10
- package/src/toolkit/impact.mjs +32 -12
- package/src/toolkit/move-pairing.mjs +140 -0
- package/src/toolkit/project-index.mjs +2 -2
- package/src/toolkit/results.mjs +1 -1
- package/src/toolkit/review-document.mjs +435 -0
- package/src/toolkit/review-groups.mjs +29 -0
- package/src/toolkit/review-observation.mjs +131 -0
- package/src/toolkit/review-sheet.mjs +117 -0
- package/src/toolkit/review-specimens.mjs +60 -0
- package/src/toolkit/review.mjs +140 -0
- package/src/toolkit/runtime.mjs +1 -1
- package/src/toolkit/theme.mjs +16 -0
- 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};
|
|
@@ -187,27 +187,44 @@ export function evictPreviews(cache, activeKeys) {
|
|
|
187
187
|
}
|
|
188
188
|
|
|
189
189
|
export function groupAssets(data) {
|
|
190
|
+
const layerOf = asset => asset.layer ?? (asset.path.includes('/') ? asset.path.split('/')[0] : 'Design');
|
|
190
191
|
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
|
-
|
|
192
|
+
const used = new Set(), grouped = [];
|
|
193
|
+
const add = (group, assets, key) => {
|
|
194
|
+
const layers = new Map();
|
|
195
|
+
for (const asset of assets) {
|
|
196
|
+
const layer = layerOf(asset);
|
|
197
|
+
if (!layers.has(layer)) layers.set(layer, []);
|
|
198
|
+
layers.get(layer).push(asset);
|
|
199
|
+
}
|
|
200
|
+
for (const [layer, members] of layers) grouped.push({ ...group, key: `${key}:${layer}`, layer, assets: members });
|
|
201
|
+
};
|
|
202
|
+
for (const [index, group] of (data.groups ?? []).entries()) {
|
|
203
|
+
const assets = group.assets.flatMap(path => {
|
|
204
|
+
const asset = byPath.get(path);
|
|
205
|
+
if (!asset || used.has(path)) return [];
|
|
206
|
+
used.add(path);
|
|
207
|
+
return [asset];
|
|
199
208
|
});
|
|
200
|
-
|
|
209
|
+
add(group, assets, `group:${index}:${group.title}`);
|
|
201
210
|
}
|
|
202
211
|
const rest = new Map();
|
|
203
|
-
for (const
|
|
204
|
-
if (used.has(
|
|
205
|
-
const parent =
|
|
212
|
+
for (const asset of data.assets) {
|
|
213
|
+
if (used.has(asset.path)) continue;
|
|
214
|
+
const parent = asset.path.split('/').slice(0, -1).join('/') || 'Design';
|
|
206
215
|
if (!rest.has(parent)) rest.set(parent, []);
|
|
207
|
-
rest.get(parent).push(
|
|
216
|
+
rest.get(parent).push(asset);
|
|
208
217
|
}
|
|
209
|
-
for (const [title, assets] of rest)
|
|
210
|
-
|
|
218
|
+
for (const [title, assets] of rest) add({ title }, assets, `directory:${title}`);
|
|
219
|
+
const canonical = ['tokens', 'components', 'modules', 'surfaces', 'studies'];
|
|
220
|
+
const layers = [...new Set([...canonical, ...(data.layers ?? []).map(layer => layer.toLowerCase()), ...grouped.map(group => group.layer.toLowerCase())])];
|
|
221
|
+
grouped.sort((a, b) => layers.indexOf(a.layer.toLowerCase()) - layers.indexOf(b.layer.toLowerCase()));
|
|
222
|
+
const chapters = new Map();
|
|
223
|
+
return grouped.map(group => {
|
|
224
|
+
const chapter = (chapters.get(group.layer) ?? 0) + 1;
|
|
225
|
+
chapters.set(group.layer, chapter);
|
|
226
|
+
return { ...group, chapter };
|
|
227
|
+
});
|
|
211
228
|
}
|
|
212
229
|
|
|
213
230
|
export function scopeKind(scope) {
|
|
@@ -236,8 +253,8 @@ export function resolveScope(data, layers, requested) {
|
|
|
236
253
|
if (layerAssets.has(key)) return result(requested, layerAssets.get(key));
|
|
237
254
|
break;
|
|
238
255
|
case 'group': {
|
|
239
|
-
const
|
|
240
|
-
if (
|
|
256
|
+
const groups = groupAssets(data).filter(item => item.title === key);
|
|
257
|
+
if (groups.length) return result(requested, groups.flatMap(group => group.assets));
|
|
241
258
|
break;
|
|
242
259
|
}
|
|
243
260
|
case 'asset': {
|
|
@@ -252,28 +269,33 @@ export function resolveScope(data, layers, requested) {
|
|
|
252
269
|
|
|
253
270
|
|
|
254
271
|
export function arrangementInput(data) {
|
|
255
|
-
return groupAssets(data).map(group => ({blocks:
|
|
272
|
+
return groupAssets(data).map(({ assets, ...group }) => ({ ...group, blocks: assets.map(blockForAsset) }));
|
|
256
273
|
}
|
|
257
274
|
|
|
258
|
-
export function arrange(data, {
|
|
275
|
+
export function arrange(data, { placed, previousGroups } = {}) {
|
|
259
276
|
const grouped = groupAssets(data);
|
|
260
|
-
const
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
const groups =
|
|
277
|
+
const boards = previousGroups ? layoutWorld(arrangementInput(data), { previousGroups })
|
|
278
|
+
: placed ?? layoutWorld(arrangementInput(data));
|
|
279
|
+
const byKey = new Map(grouped.map(group => [group.key, group]));
|
|
280
|
+
const groups = boards.map(board => ({ ...byKey.get(board.key), ...board, width: board.w, height: board.h }));
|
|
264
281
|
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
|
-
|
|
282
|
+
for (const [group, board] of groups.entries()) {
|
|
283
|
+
const byPath = new Map(board.assets.map(asset => [asset.path, asset]));
|
|
284
|
+
for (const section of board.blocks) {
|
|
285
|
+
const asset = byPath.get(section.asset);
|
|
286
|
+
for (const frame of section.frames) {
|
|
287
|
+
const crop = { ...frame.crop, width: frame.w, height: frame.h, id: frame.id, name: frame.name };
|
|
288
|
+
items.push({ ...asset, name: section.title, sourceComponent: asset.sourceComponent ?? !!asset.component, component: false, id: `${asset.path}#${frame.id}`, kind: 'flow', group,
|
|
289
|
+
x: board.x + section.x + frame.x, y: board.y + section.y + frame.y,
|
|
290
|
+
width: frame.w, height: frame.h, shown: [crop],
|
|
291
|
+
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},
|
|
292
|
+
paintCrop: specimenPaintCrop(asset, crop),
|
|
293
|
+
previewCrop: section.previewCrop ?? specimenPaintCrop(asset, crop),
|
|
294
|
+
});
|
|
273
295
|
}
|
|
274
296
|
}
|
|
275
297
|
}
|
|
276
|
-
return { groups, items, world: { x: 0, y: 0, width: Math.max(1, ...groups.map(g => g.x + g.
|
|
298
|
+
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
299
|
}
|
|
278
300
|
|
|
279
301
|
function formDocument(form,css,theme) {
|
|
@@ -321,15 +343,15 @@ async function prepareSource(asset, built, theme, signal) {
|
|
|
321
343
|
content.setAttribute('xmlns','http://www.w3.org/1999/xhtml');
|
|
322
344
|
content.setAttribute('style','font:16px/1.5 var(--font-ui);color:var(--text);');
|
|
323
345
|
content.append(frame.contentDocument.querySelector('style').cloneNode(true),shell.cloneNode(true));
|
|
324
|
-
parts.push({id:String(index),name:form.name,note:form.note,width:box.width,height:box.height,elements,markup:new XMLSerializer().serializeToString(content)});
|
|
346
|
+
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
347
|
endFrame?.();
|
|
326
348
|
}
|
|
327
349
|
const wrapWidth = built.component ? componentWrapWidth(parts) : Infinity;
|
|
328
350
|
let x=0,y=0,rowHeight=0;
|
|
329
351
|
for (const part of parts) {
|
|
330
|
-
if (x && x+part.width>wrapWidth) { x=0;y+=rowHeight+
|
|
352
|
+
if (x && x+part.width>wrapWidth) { x=0;y+=rowHeight+64;rowHeight=0; }
|
|
331
353
|
Object.assign(part,{x,y});
|
|
332
|
-
x+=part.width+
|
|
354
|
+
x+=part.width+48;rowHeight=Math.max(rowHeight,part.height);
|
|
333
355
|
}
|
|
334
356
|
const width=Math.max(1,...parts.map(p=>p.x+p.width)),height=Math.max(1,...parts.map(p=>p.y+p.height));
|
|
335
357
|
const xml = value => String(value).replace(/[&<>"']/g,c=>({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c]));
|
|
@@ -337,7 +359,7 @@ async function prepareSource(asset, built, theme, signal) {
|
|
|
337
359
|
let offset=header.length;
|
|
338
360
|
const frameRanges=[];
|
|
339
361
|
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="
|
|
362
|
+
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
363
|
frameRanges.push([offset,offset+value.length]);offset+=value.length;
|
|
342
364
|
return value;
|
|
343
365
|
});
|
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,124 @@
|
|
|
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
|
+
measurement = requestAnimationFrame(() => {
|
|
102
|
+
if (node.isConnected) onMeasure(node.offsetHeight);
|
|
103
|
+
});
|
|
104
|
+
},
|
|
105
|
+
tokenSection(slug) {
|
|
106
|
+
if (!tokenNode?.isConnected) return null;
|
|
107
|
+
const section = tokenNode.querySelector(`[data-adg-section$="#${CSS.escape(slug)}"]`);
|
|
108
|
+
if (!section) return null;
|
|
109
|
+
const base = tokenNode.getBoundingClientRect(), box = section.getBoundingClientRect();
|
|
110
|
+
const scale = Number(root.dataset.scale) || 1;
|
|
111
|
+
return {
|
|
112
|
+
x: 0,
|
|
113
|
+
y: (box.top - base.top) / scale,
|
|
114
|
+
width: base.width / scale || tokenNode.offsetWidth,
|
|
115
|
+
height: box.height / scale || section.offsetHeight,
|
|
116
|
+
};
|
|
117
|
+
},
|
|
118
|
+
palette() {
|
|
119
|
+
const css = getComputedStyle(root);
|
|
120
|
+
return Object.fromEntries(['surface','canvas','border','radius-card'].map(name => [name,css.getPropertyValue('--'+name).trim()]));
|
|
121
|
+
},
|
|
122
|
+
camera(view, hidden) {root.hidden = hidden;root.dataset.scale=view.scale;root.style.transform=`translate(${view.x}px,${view.y}px) scale(${view.scale})`;},
|
|
123
|
+
};
|
|
124
|
+
}
|
|
@@ -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
|
+
}
|