Skill Tracer
Skills › Archify › archify › layout-report.mjs

layout-report.mjs

57 lines · archify/renderers/shared/layout-report.mjs at a406594

1/** Serialize computed layout for dry-run / inspect (#9). */
2
3export function componentBox(c) {
4 return {
5 id: c.id,
6 type: c.type,
7 label: c.label,
8 x: Math.round(c.x),
9 y: Math.round(c.y),
10 width: c.width,
11 height: c.height,
12 ...(Number.isInteger(c.row) ? { row: c.row } : {}),
13 ...(Number.isInteger(c.col) ? { col: c.col } : {}),
14 ...(Array.isArray(c.pos) ? { pos: c.pos.map(Math.round) } : {}),
15 };
18export function entityBox(e) {
19 return {
20 id: e.id,
21 label: e.label,
22 x: Math.round(e.x),
23 y: Math.round(e.y),
24 width: e.width,
25 height: e.height,
26 attributes: (Array.isArray(e.attributes) ? e.attributes : []).map((attribute) => attribute.name),
27 ...(Number.isInteger(e.row) ? { row: e.row } : {}),
28 ...(Number.isInteger(e.col) ? { col: e.col } : {}),
29 ...(Array.isArray(e.pos) ? { pos: e.pos.map(Math.round) } : {}),
30 };
33export function boundaryBox(b) {
34 return {
35 kind: b.kind,
36 label: b.label,
37 x: Math.round(b.x),
38 y: Math.round(b.y),
39 width: Math.round(b.width),
40 height: Math.round(b.height),
41 wraps: b.wraps,
42 };
45export function connectionPath(conn, routed, labelAt) {
46 return {
47 from: conn.from,
48 to: conn.to,
49 label: conn.label ?? null,
50 variant: conn.variant ?? 'default',
51 route: conn.route ?? 'auto',
52 // These points are repair inputs: rounding a fractional port makes a
53 // reused waypoint diagonal relative to the actual endpoint.
54 points: routed.points.map(([x, y]) => [x, y]),
55 ...(labelAt ? { labelAt: labelAt.map(Math.round) } : {}),
56 };