@diagc/cli 1.11.0 → 1.13.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/assets/guide/state-machine.md +4 -4
- package/assets/studio/assets/index-BK_mpx_Q.js +115 -0
- package/assets/studio/assets/{index-C7-EMlhy.css → index-DnTnVIet.css} +1 -1
- package/assets/studio/index.html +2 -2
- package/assets/viewer/index.html +36 -36
- package/assets/viewer/shared/viewer.css +1 -1
- package/assets/viewer/shared/viewer.js +35 -35
- package/dist/commands/diff.js +1 -1
- package/dist/diff/describe.d.ts +27 -0
- package/dist/diff/describe.js +78 -16
- package/dist/diff/index.js +1 -1
- package/dist/diff/overview.d.ts +12 -4
- package/dist/diff/overview.js +88 -9
- package/dist/diff/pages.d.ts +26 -3
- package/dist/diff/pages.js +59 -4
- package/dist/diff/summary.d.ts +2 -5
- package/dist/diff/summary.js +6 -0
- package/dist/text/vocabulary.js +1 -0
- package/package.json +2 -2
- package/assets/studio/assets/index-B-OCe1QU.js +0 -115
package/dist/commands/diff.js
CHANGED
|
@@ -80,7 +80,7 @@ export const diff = {
|
|
|
80
80
|
});
|
|
81
81
|
// stderr, so `--json` output stays parseable on stdout
|
|
82
82
|
io.err(`✓ ${res.pages.length} page(s)${res.images.length > 0 ? `, ${res.images.length} image(s)` : ''} -> ${outDir}`);
|
|
83
|
-
io.err(`✓
|
|
83
|
+
io.err(`✓ overview -> ${res.index}`);
|
|
84
84
|
io.err(`✓ for an ADR -> ${res.summary}`);
|
|
85
85
|
return 0;
|
|
86
86
|
}
|
package/dist/diff/describe.d.ts
CHANGED
|
@@ -1,4 +1,31 @@
|
|
|
1
1
|
import type { DiagramDiff } from './compare.js';
|
|
2
|
+
/** One field of a changed element, in each version. */
|
|
3
|
+
export interface FieldValues {
|
|
4
|
+
field: string;
|
|
5
|
+
before: string;
|
|
6
|
+
after: string;
|
|
7
|
+
}
|
|
8
|
+
/** One line of a diagram's change list, and what it is about. */
|
|
9
|
+
export interface DiffLine {
|
|
10
|
+
sign: '+' | '-' | '~';
|
|
11
|
+
text: string;
|
|
12
|
+
/** the node, relation or plane the line is about, as the combined page knows it */
|
|
13
|
+
target?: {
|
|
14
|
+
node: string;
|
|
15
|
+
} | {
|
|
16
|
+
relation: string;
|
|
17
|
+
} | {
|
|
18
|
+
plane: string;
|
|
19
|
+
};
|
|
20
|
+
/** a changed element's fields, old and new; none for an added or a removed one */
|
|
21
|
+
values?: FieldValues[];
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The change list for one diagram: what each line says and what it points at.
|
|
25
|
+
* `removedIds` are the ids the combined model gives the removed relations, in
|
|
26
|
+
* the diff's order (core's combineDiff renames one whose id is taken).
|
|
27
|
+
*/
|
|
28
|
+
export declare function diffLines(d: DiagramDiff, removedIds?: readonly string[]): DiffLine[];
|
|
2
29
|
/** The change list for one diagram, one line each, `+`/`-`/`~` first. */
|
|
3
30
|
export declare function describeDiff(d: DiagramDiff): string[];
|
|
4
31
|
/** `diff --json`'s text: each diagram's status, with its changes or why it was not
|
package/dist/diff/describe.js
CHANGED
|
@@ -2,43 +2,105 @@ function nameIn(m, id) {
|
|
|
2
2
|
const n = m.nodes.find((x) => x.id === id);
|
|
3
3
|
return n === undefined || n.name === '' ? id : n.name;
|
|
4
4
|
}
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
const MAX_VALUE = 240;
|
|
6
|
+
/** A field's value as a line can show it: text as it is, anything else as JSON, nothing as a dash. */
|
|
7
|
+
function shown(value) {
|
|
8
|
+
if (value === undefined)
|
|
9
|
+
return '—';
|
|
10
|
+
const text = typeof value === 'string' ? value : JSON.stringify(value);
|
|
11
|
+
return text.length > MAX_VALUE ? `${text.slice(0, MAX_VALUE)}…` : text;
|
|
12
|
+
}
|
|
13
|
+
function valuesOf(before, after, fields) {
|
|
14
|
+
const b = (before ?? {});
|
|
15
|
+
const a = (after ?? {});
|
|
16
|
+
// `parent` is not a field of a node: the line says it moved, and the picture shows where.
|
|
17
|
+
return fields.filter((f) => f !== 'parent').map((f) => ({ field: f, before: shown(b[f]), after: shown(a[f]) }));
|
|
18
|
+
}
|
|
19
|
+
/** What a relation says on its arrow: its label, or a transition's trigger and guard. */
|
|
20
|
+
function relationText(r) {
|
|
21
|
+
if (r.label !== undefined && r.label !== '')
|
|
22
|
+
return r.label;
|
|
23
|
+
const guard = r.guard !== undefined && r.guard !== '' ? ` [${r.guard}]` : '';
|
|
24
|
+
return `${r.trigger ?? ''}${guard}`.trim();
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The change list for one diagram: what each line says and what it points at.
|
|
28
|
+
* `removedIds` are the ids the combined model gives the removed relations, in
|
|
29
|
+
* the diff's order (core's combineDiff renames one whose id is taken).
|
|
30
|
+
*/
|
|
31
|
+
export function diffLines(d, removedIds) {
|
|
7
32
|
if (d.status === 'error')
|
|
8
33
|
return [];
|
|
9
34
|
if (d.status === 'added')
|
|
10
35
|
return [
|
|
11
|
-
|
|
36
|
+
{
|
|
37
|
+
sign: '+',
|
|
38
|
+
text: `new diagram: ${d.after.model.name} (${d.diff.nodes.added.length} nodes, ${d.diff.relations.added.length} relations)`,
|
|
39
|
+
},
|
|
12
40
|
];
|
|
13
41
|
if (d.status === 'removed')
|
|
14
|
-
return [
|
|
42
|
+
return [{ sign: '-', text: `diagram removed: ${d.before.model.name}` }];
|
|
15
43
|
const before = d.before.model;
|
|
16
44
|
const after = d.after.model;
|
|
17
|
-
const rel = (m, r) =>
|
|
45
|
+
const rel = (m, r) => {
|
|
46
|
+
const text = relationText(r);
|
|
47
|
+
return `${nameIn(m, r.from)} -> ${nameIn(m, r.to)} (${r.kind}${text !== '' ? `: ${text}` : ''})`;
|
|
48
|
+
};
|
|
49
|
+
const node = (n) => `${n.name !== '' ? n.name : n.id}${n.type !== undefined ? ` [${n.type}]` : ''}`;
|
|
50
|
+
const byId = (list, id) => list.find((x) => x.id === id);
|
|
18
51
|
const x = d.diff;
|
|
19
52
|
return [
|
|
20
|
-
...x.nodes.added.map((n) =>
|
|
21
|
-
...x.nodes.removed.map((n) =>
|
|
53
|
+
...x.nodes.added.map((n) => ({ sign: '+', text: node(n), target: { node: n.id } })),
|
|
54
|
+
...x.nodes.removed.map((n) => ({ sign: '-', text: node(n), target: { node: n.id } })),
|
|
22
55
|
...x.nodes.changed.map((n) => {
|
|
23
56
|
// A rename reads better as the two names than as the word "name".
|
|
24
57
|
const was = nameIn(before, n.id);
|
|
25
58
|
const now = nameIn(after, n.id);
|
|
26
59
|
const rest = n.fields.filter((f) => f !== 'name');
|
|
27
60
|
const head = n.fields.includes('name') ? `${was} -> ${now} (renamed)` : now;
|
|
28
|
-
return
|
|
61
|
+
return {
|
|
62
|
+
sign: '~',
|
|
63
|
+
text: `${head}${rest.length > 0 ? `: ${rest.join(', ')}` : ''}`,
|
|
64
|
+
target: { node: n.id },
|
|
65
|
+
values: valuesOf(byId(before.nodes, n.id), byId(after.nodes, n.id), rest),
|
|
66
|
+
};
|
|
29
67
|
}),
|
|
30
|
-
...x.relations.added.map((r) =>
|
|
31
|
-
...x.relations.removed.map((r) =>
|
|
68
|
+
...x.relations.added.map((r) => ({ sign: '+', text: rel(after, r), target: { relation: r.id } })),
|
|
69
|
+
...x.relations.removed.map((r, i) => ({
|
|
70
|
+
sign: '-',
|
|
71
|
+
text: rel(before, r),
|
|
72
|
+
target: { relation: removedIds?.[i] ?? r.id },
|
|
73
|
+
})),
|
|
32
74
|
...x.relations.changed.map((r) => {
|
|
33
|
-
const now = after.relations
|
|
34
|
-
return
|
|
75
|
+
const now = byId(after.relations, r.after);
|
|
76
|
+
return {
|
|
77
|
+
sign: '~',
|
|
78
|
+
text: `${now !== undefined ? rel(after, now) : r.after}: ${r.fields.join(', ')}`,
|
|
79
|
+
target: { relation: r.after },
|
|
80
|
+
values: valuesOf(byId(before.relations, r.before), now, r.fields),
|
|
81
|
+
};
|
|
35
82
|
}),
|
|
36
|
-
...x.layers.added.map((id) =>
|
|
37
|
-
...x.layers.removed.map((id) =>
|
|
38
|
-
...x.
|
|
39
|
-
|
|
83
|
+
...x.layers.added.map((id) => ({ sign: '+', text: `layer ${id}` })),
|
|
84
|
+
...x.layers.removed.map((id) => ({ sign: '-', text: `layer ${id}` })),
|
|
85
|
+
...x.layers.changed.map((c) => ({
|
|
86
|
+
sign: '~',
|
|
87
|
+
text: `layer ${c.id}: ${c.fields.join(', ')}`,
|
|
88
|
+
values: valuesOf(byId(before.layers, c.id), byId(after.layers, c.id), c.fields),
|
|
89
|
+
})),
|
|
90
|
+
...x.planes.added.map((id) => ({ sign: '+', text: `plane ${id}`, target: { plane: id } })),
|
|
91
|
+
...x.planes.removed.map((id) => ({ sign: '-', text: `plane ${id}`, target: { plane: id } })),
|
|
92
|
+
...x.planes.changed.map((c) => ({
|
|
93
|
+
sign: '~',
|
|
94
|
+
text: `plane ${c.id}: ${c.fields.join(', ')}`,
|
|
95
|
+
target: { plane: c.id },
|
|
96
|
+
values: valuesOf(byId(before.planes, c.id), byId(after.planes, c.id), c.fields),
|
|
97
|
+
})),
|
|
40
98
|
];
|
|
41
99
|
}
|
|
100
|
+
/** The change list for one diagram, one line each, `+`/`-`/`~` first. */
|
|
101
|
+
export function describeDiff(d) {
|
|
102
|
+
return diffLines(d).map((l) => `${l.sign} ${l.text}`);
|
|
103
|
+
}
|
|
42
104
|
/** `diff --json`'s text: each diagram's status, with its changes or why it was not
|
|
43
105
|
* compared. The versions stay out: they are whole models, what the pictures are drawn
|
|
44
106
|
* from, not the change. */
|
package/dist/diff/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// `diagc diff`: load each side's diagrams, compare them by name, describe the changes,
|
|
2
|
-
// and write the pages, the
|
|
2
|
+
// and write the pages, the overview and the summary.
|
|
3
3
|
export { loadDiagramSet } from './load.js';
|
|
4
4
|
export { compareDiagramSets } from './compare.js';
|
|
5
5
|
export { describeDiff, formatDiffJson, formatDiffSummary } from './describe.js';
|
package/dist/diff/overview.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { DiagramDiff } from './compare.js';
|
|
2
2
|
import type { DiagramSet } from './load.js';
|
|
3
|
+
import type { DiagramFiles } from './pages.js';
|
|
3
4
|
/**
|
|
4
5
|
* The colours the pictures outline a change in, which the key's swatches show. The
|
|
5
6
|
* renderer draws with its own copy, `.dg-canvas`'s `--dg-diff-*` in
|
|
@@ -11,7 +12,14 @@ export declare const DIFF_MARK_COLORS: {
|
|
|
11
12
|
readonly removed: "#dc2626";
|
|
12
13
|
readonly changed: "#d97706";
|
|
13
14
|
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
/**
|
|
16
|
+
* The page's behaviour, the same for every section:
|
|
17
|
+
*
|
|
18
|
+
* - the two view buttons show the combined picture or the two sides. The sides
|
|
19
|
+
* load on first use (their frames carry `data-src`), so a page of many diagrams
|
|
20
|
+
* does not lay out three pictures of each;
|
|
21
|
+
* - a change's button asks the combined page to bring that element into view
|
|
22
|
+
* (apps/viewer/src/diff-view.tsx answers the message), switching to it first.
|
|
23
|
+
*/
|
|
24
|
+
export declare const OVERVIEW_SCRIPT = "<script>(function(){\nfunction show(section,view){\n section.querySelectorAll('[data-view]').forEach(function(el){el.hidden=el.dataset.view!==view});\n section.querySelectorAll('[data-show]').forEach(function(b){b.setAttribute('aria-pressed',String(b.dataset.show===view))});\n if(view==='sides')section.querySelectorAll('iframe[data-src]').forEach(function(f){f.src=f.dataset.src;f.removeAttribute('data-src')});\n}\ndocument.addEventListener('click',function(e){\n var el=e.target instanceof Element?e.target:null;\n var section=el&&el.closest('section');\n if(!section)return;\n var view=el.closest('[data-show]');\n if(view){show(section,view.dataset.show);return}\n var change=el.closest('[data-focus]');\n var frame=section.querySelector('.combined iframe');\n if(!change||!frame)return;\n show(section,'combined');\n section.querySelectorAll('li.at').forEach(function(li){li.classList.remove('at')});\n change.closest('li').classList.add('at');\n var message=JSON.parse(change.dataset.focus);\n message.type='diagc-diff-focus';\n frame.contentWindow.postMessage(message,'*');\n});\n})();</script>";
|
|
25
|
+
export declare function indexHtml(diffs: readonly DiagramDiff[], files: Map<string, Omit<DiagramFiles, 'png'>>, before: DiagramSet, after: DiagramSet): string;
|
package/dist/diff/overview.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { THEME_HEAD_SCRIPT, THEME_SWITCH, themeCss } from '../publish/pageTheme.js';
|
|
2
|
-
import {
|
|
2
|
+
import { diffLines } from './describe.js';
|
|
3
3
|
const escapeHtml = (s) => s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
|
4
4
|
/**
|
|
5
5
|
* The colours the pictures outline a change in, which the key's swatches show. The
|
|
@@ -23,6 +23,24 @@ const OVERVIEW_CSS = [
|
|
|
23
23
|
'h3 { font-size: 13px; margin: 0 0 6px; color: var(--muted); }',
|
|
24
24
|
'ul { margin: 0 0 12px; padding-left: 18px; font-family: ui-monospace, monospace; font-size: 12.5px; }',
|
|
25
25
|
'li.add { color: var(--add); } li.del { color: var(--del); } li.chg { color: var(--chg); }',
|
|
26
|
+
// A diagram's section: its change list in a column of its own beside the picture, so
|
|
27
|
+
// a long list scrolls there and never pushes the picture off the screen.
|
|
28
|
+
'.diagram { display: grid; grid-template-columns: minmax(240px, 360px) 1fr; gap: 16px; align-items: start; }',
|
|
29
|
+
'.diagram > ul { max-height: 78vh; overflow: auto; margin: 22px 0 0; padding-left: 0; list-style: none; }',
|
|
30
|
+
'.diagram li { margin-bottom: 4px; padding: 1px 4px; overflow-wrap: anywhere; }',
|
|
31
|
+
'li button { font: inherit; color: inherit; background: none; border: none; padding: 0; text-align: left; ' +
|
|
32
|
+
'cursor: pointer; }',
|
|
33
|
+
'li button:hover, li button:focus-visible { text-decoration: underline; }',
|
|
34
|
+
'li.at { background: color-mix(in srgb, currentColor 12%, transparent); border-radius: 3px; }',
|
|
35
|
+
'li dl { margin: 2px 0 6px; color: var(--muted); display: grid; grid-template-columns: auto 1fr; gap: 0 8px; }',
|
|
36
|
+
'li dt { grid-column: 1 / -1; color: var(--faint); } li dd { margin: 0; grid-column: 1 / -1; }',
|
|
37
|
+
'li dd.was { text-decoration: line-through; text-decoration-color: var(--del); }',
|
|
38
|
+
'.views { display: flex; gap: 4px; margin: 0 0 6px; }',
|
|
39
|
+
'.views button { font: inherit; font-size: 12px; padding: 2px 10px; border: 1px solid var(--border); ' +
|
|
40
|
+
'border-radius: 6px; background: var(--card); color: var(--muted); cursor: pointer; }',
|
|
41
|
+
'.views button[aria-pressed=true] { color: var(--text); font-weight: 600; border-color: var(--muted); }',
|
|
42
|
+
'.combined iframe { width: 100%; height: 78vh; border: 1px solid var(--border); border-radius: 6px; }',
|
|
43
|
+
'[hidden] { display: none !important; }',
|
|
26
44
|
'.key span { display: inline-block; margin-right: 14px; } ' +
|
|
27
45
|
'.key i { display: inline-block; width: 12px; height: 12px; border: 3px solid; border-radius: 3px; ' +
|
|
28
46
|
'vertical-align: -2px; margin-right: 4px; }',
|
|
@@ -30,7 +48,7 @@ const OVERVIEW_CSS = [
|
|
|
30
48
|
'.side iframe { width: 100%; height: 70vh; border: 1px solid var(--border); border-radius: 6px; }',
|
|
31
49
|
'.side.empty p { height: 70vh; margin: 0; display: grid; place-items: center; ' +
|
|
32
50
|
'border: 1px dashed var(--border); border-radius: 6px; color: var(--faint); }',
|
|
33
|
-
'@media (max-width: 900px) { .pair { grid-template-columns: 1fr; } }',
|
|
51
|
+
'@media (max-width: 900px) { .pair, .diagram { grid-template-columns: 1fr; } .diagram > ul { max-height: 40vh; } }',
|
|
34
52
|
]
|
|
35
53
|
.map((line) => ` ${line}`)
|
|
36
54
|
.join('\n');
|
|
@@ -42,17 +60,63 @@ const KEY = `<p class="key">${[
|
|
|
42
60
|
swatch(`border-color:${DIFF_MARK_COLORS.changed}`, 'changed'),
|
|
43
61
|
swatch(`border-color:${DIFF_MARK_COLORS.changed};border-style:dashed`, 'holds a change (folded box, on the linked pages)'),
|
|
44
62
|
].join('')}</p>`;
|
|
63
|
+
/**
|
|
64
|
+
* The page's behaviour, the same for every section:
|
|
65
|
+
*
|
|
66
|
+
* - the two view buttons show the combined picture or the two sides. The sides
|
|
67
|
+
* load on first use (their frames carry `data-src`), so a page of many diagrams
|
|
68
|
+
* does not lay out three pictures of each;
|
|
69
|
+
* - a change's button asks the combined page to bring that element into view
|
|
70
|
+
* (apps/viewer/src/diff-view.tsx answers the message), switching to it first.
|
|
71
|
+
*/
|
|
72
|
+
export const OVERVIEW_SCRIPT = `<script>(function(){
|
|
73
|
+
function show(section,view){
|
|
74
|
+
section.querySelectorAll('[data-view]').forEach(function(el){el.hidden=el.dataset.view!==view});
|
|
75
|
+
section.querySelectorAll('[data-show]').forEach(function(b){b.setAttribute('aria-pressed',String(b.dataset.show===view))});
|
|
76
|
+
if(view==='sides')section.querySelectorAll('iframe[data-src]').forEach(function(f){f.src=f.dataset.src;f.removeAttribute('data-src')});
|
|
77
|
+
}
|
|
78
|
+
document.addEventListener('click',function(e){
|
|
79
|
+
var el=e.target instanceof Element?e.target:null;
|
|
80
|
+
var section=el&&el.closest('section');
|
|
81
|
+
if(!section)return;
|
|
82
|
+
var view=el.closest('[data-show]');
|
|
83
|
+
if(view){show(section,view.dataset.show);return}
|
|
84
|
+
var change=el.closest('[data-focus]');
|
|
85
|
+
var frame=section.querySelector('.combined iframe');
|
|
86
|
+
if(!change||!frame)return;
|
|
87
|
+
show(section,'combined');
|
|
88
|
+
section.querySelectorAll('li.at').forEach(function(li){li.classList.remove('at')});
|
|
89
|
+
change.closest('li').classList.add('at');
|
|
90
|
+
var message=JSON.parse(change.dataset.focus);
|
|
91
|
+
message.type='diagc-diff-focus';
|
|
92
|
+
frame.contentWindow.postMessage(message,'*');
|
|
93
|
+
});
|
|
94
|
+
})();</script>`;
|
|
95
|
+
/** One line of the change list. A line that points at something is a button that
|
|
96
|
+
* brings it into view on the combined picture; a changed field shows old and new. */
|
|
97
|
+
function lineHtml(line, focusable) {
|
|
98
|
+
const text = escapeHtml(`${line.sign} ${line.text}`);
|
|
99
|
+
const head = focusable && line.target !== undefined
|
|
100
|
+
? `<button type="button" data-focus="${escapeHtml(JSON.stringify(line.target))}">${text}</button>`
|
|
101
|
+
: text;
|
|
102
|
+
const values = (line.values ?? [])
|
|
103
|
+
.map((v) => `<dt>${escapeHtml(v.field)}</dt><dd class="was">${escapeHtml(v.before)}</dd><dd>${escapeHtml(v.after)}</dd>`)
|
|
104
|
+
.join('');
|
|
105
|
+
const cls = line.sign === '+' ? 'add' : line.sign === '-' ? 'del' : 'chg';
|
|
106
|
+
return `<li class="${cls}">${head}${values !== '' ? `<dl>${values}</dl>` : ''}</li>`;
|
|
107
|
+
}
|
|
45
108
|
export function indexHtml(diffs, files, before, after) {
|
|
46
109
|
const from = before.label;
|
|
47
110
|
const to = after.label;
|
|
48
|
-
// The frames load each page unfolded (`?export=1`, the PNG's own mode): side by
|
|
111
|
+
// The side frames load each page unfolded (`?export=1`, the PNG's own mode): side by
|
|
49
112
|
// side, the whole picture is the point. The headings link the interactive pages.
|
|
50
|
-
|
|
113
|
+
// Beside a combined picture the sides wait for their button (`lazy`).
|
|
114
|
+
const side = (rel, label, lazy) => {
|
|
51
115
|
const heading = escapeHtml(label);
|
|
52
116
|
if (rel === undefined)
|
|
53
117
|
return `<div class="side empty"><h3>${heading}</h3><p>not present</p></div>`;
|
|
54
118
|
const page = `${escapeHtml(rel)}.html`;
|
|
55
|
-
const frame = `<iframe src="${page}?export=1" title="${heading}"></iframe>`;
|
|
119
|
+
const frame = `<iframe ${lazy ? 'data-src' : 'src'}="${page}?export=1" title="${heading}"></iframe>`;
|
|
56
120
|
return `<div class="side"><h3><a href="${page}">${heading}</a></h3>${frame}</div>`;
|
|
57
121
|
};
|
|
58
122
|
// A diagram that did not compile has no pictures, but is listed as the summary lists it.
|
|
@@ -62,11 +126,25 @@ export function indexHtml(diffs, files, before, after) {
|
|
|
62
126
|
if (d.status === 'error')
|
|
63
127
|
return [`<section><h2>${escapeHtml(d.name)}</h2><p>Not compared: ${escapeHtml(d.error)}</p></section>`];
|
|
64
128
|
const f = files.get(d.name) ?? {};
|
|
65
|
-
const
|
|
66
|
-
|
|
129
|
+
const combined = f.combined;
|
|
130
|
+
const list = diffLines(d, f.removedIds)
|
|
131
|
+
.map((l) => lineHtml(l, combined !== undefined))
|
|
67
132
|
.join('');
|
|
68
|
-
const pair = `<div class="pair"
|
|
69
|
-
|
|
133
|
+
const pair = (lazy) => `<div class="pair"${lazy ? ' data-view="sides" hidden' : ''}>` +
|
|
134
|
+
`${side(f.before, `Before · ${from}`, lazy)}${side(f.after, `After · ${to}`, lazy)}</div>`;
|
|
135
|
+
if (combined === undefined)
|
|
136
|
+
return [
|
|
137
|
+
`<section><h2>${escapeHtml(d.name)}</h2><div class="diagram"><ul>${list}</ul>${pair(false)}</div></section>`,
|
|
138
|
+
];
|
|
139
|
+
const page = `${escapeHtml(combined)}.html`;
|
|
140
|
+
const views = '<div class="views"><button type="button" data-show="combined" aria-pressed="true">Combined</button>' +
|
|
141
|
+
'<button type="button" data-show="sides" aria-pressed="false">Side by side</button></div>';
|
|
142
|
+
const one = `<div class="combined" data-view="combined"><iframe src="${page}" ` +
|
|
143
|
+
`title="${escapeHtml(`${from} → ${to}`)}"></iframe></div>`;
|
|
144
|
+
return [
|
|
145
|
+
`<section><h2>${escapeHtml(d.name)}</h2>` +
|
|
146
|
+
`<div class="diagram"><ul>${list}</ul><div>${views}${one}${pair(true)}</div></div></section>`,
|
|
147
|
+
];
|
|
70
148
|
});
|
|
71
149
|
const warnings = [...before.warnings, ...after.warnings];
|
|
72
150
|
const notes = warnings.length === 0 ? '' : `<ul>${warnings.map((w) => `<li>${escapeHtml(w)}</li>`).join('')}</ul>\n`;
|
|
@@ -81,6 +159,7 @@ ${OVERVIEW_CSS}
|
|
|
81
159
|
<header><h1>Diagram diff · ${escapeHtml(from)} → ${escapeHtml(to)}</h1>${THEME_SWITCH}</header>
|
|
82
160
|
${KEY}
|
|
83
161
|
${notes}${sections.length > 0 ? sections.join('\n') : '<p>No diagram changed.</p>'}
|
|
162
|
+
${OVERVIEW_SCRIPT}
|
|
84
163
|
</body></html>
|
|
85
164
|
`;
|
|
86
165
|
}
|
package/dist/diff/pages.d.ts
CHANGED
|
@@ -6,7 +6,9 @@ export interface DiffPagesOptions {
|
|
|
6
6
|
libraryDir: string;
|
|
7
7
|
before: DiagramSet;
|
|
8
8
|
after: DiagramSet;
|
|
9
|
-
renderPng?: (htmlPath: string, pngPath: string
|
|
9
|
+
renderPng?: (htmlPath: string, pngPath: string, look?: {
|
|
10
|
+
plane?: string;
|
|
11
|
+
}) => Promise<void>;
|
|
10
12
|
/** where `summary.md`'s images will be served from, `{path}` standing for
|
|
11
13
|
* each PNG's path under `outDir` — for a summary posted somewhere else (a PR
|
|
12
14
|
* comment), where the relative links would not resolve */
|
|
@@ -18,10 +20,31 @@ export interface DiffPagesResult {
|
|
|
18
20
|
index: string;
|
|
19
21
|
summary: string;
|
|
20
22
|
}
|
|
23
|
+
/** One picture of a combined page: the plane it shows, and its file without the extension. */
|
|
24
|
+
export interface CombinedPicture {
|
|
25
|
+
/** the plane's name; absent for a model without planes */
|
|
26
|
+
plane?: string;
|
|
27
|
+
rel: string;
|
|
28
|
+
}
|
|
29
|
+
/** The files written for one diagram, as paths under the output directory without
|
|
30
|
+
* the extension. */
|
|
31
|
+
export interface DiagramFiles {
|
|
32
|
+
before?: string;
|
|
33
|
+
after?: string;
|
|
34
|
+
/** both versions in one picture; only a diagram both sides have gets one */
|
|
35
|
+
combined?: string;
|
|
36
|
+
/** the ids the combined page gives the removed relations, in the diff's order */
|
|
37
|
+
removedIds?: string[];
|
|
38
|
+
/** the combined page's pictures, one per plane that shows a change */
|
|
39
|
+
pictures?: CombinedPicture[];
|
|
40
|
+
png: boolean;
|
|
41
|
+
}
|
|
21
42
|
/**
|
|
22
43
|
* A page per side of every diagram that changed — the same single-file viewer
|
|
23
44
|
* `publish` writes, with the changes outlined — plus a PNG of each when
|
|
24
|
-
* `renderPng` is given
|
|
25
|
-
*
|
|
45
|
+
* `renderPng` is given. A diagram both sides have also gets a combined page,
|
|
46
|
+
* `<name>.diff.html`: both versions in one picture, with a PNG per plane that
|
|
47
|
+
* shows a change. Then an `index.html` over all of it, and a `summary.md` laid
|
|
48
|
+
* out to paste into an ADR.
|
|
26
49
|
*/
|
|
27
50
|
export declare function writeDiffPages(diffs: readonly DiagramDiff[], opts: DiffPagesOptions): Promise<DiffPagesResult>;
|
package/dist/diff/pages.js
CHANGED
|
@@ -1,15 +1,45 @@
|
|
|
1
1
|
import { mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
-
import { diffMarks } from '@diagc/core/internal';
|
|
4
|
-
import { inlineAssets } from '../publish/publish.js';
|
|
3
|
+
import { combineDiff, diffMarks, diffMarksByPlane } from '@diagc/core/internal';
|
|
4
|
+
import { inlineAssets, planePictures } from '../publish/publish.js';
|
|
5
5
|
import { stampHtml } from '../publish/html.js';
|
|
6
6
|
import { indexHtml } from './overview.js';
|
|
7
7
|
import { summaryMarkdown } from './summary.js';
|
|
8
|
+
/** How each plane itself changed, for the combined page's plane chips. */
|
|
9
|
+
function planeStatuses(d) {
|
|
10
|
+
const { added, removed, changed } = d.diff.planes;
|
|
11
|
+
return Object.fromEntries([
|
|
12
|
+
...changed.map((c) => [c.id, 'changed']),
|
|
13
|
+
...added.map((id) => [id, 'added']),
|
|
14
|
+
...removed.map((id) => [id, 'removed']),
|
|
15
|
+
]);
|
|
16
|
+
}
|
|
17
|
+
/** The pictures to take of a combined model: each plane that shows a change, named
|
|
18
|
+
* as `publish` names a plane's picture. A plane that shows exactly the changes an
|
|
19
|
+
* earlier one does gets none: planes over one structure repeat its changes, and a
|
|
20
|
+
* summary of eight near-identical pictures hides the two that differ. */
|
|
21
|
+
function combinedPictures(name, model, marks) {
|
|
22
|
+
const shown = diffMarksByPlane(model, marks);
|
|
23
|
+
const changes = (id) => [...(shown.get(id)?.nodes ?? []), '', ...(shown.get(id)?.relations ?? [])];
|
|
24
|
+
if (model.planes.length === 0)
|
|
25
|
+
return changes('').length > 1 ? [{ rel: `${name}.diff` }] : [];
|
|
26
|
+
const seen = new Set();
|
|
27
|
+
return planePictures(model).flatMap((picture, i) => {
|
|
28
|
+
const plane = model.planes[i];
|
|
29
|
+
const key = changes(plane.id).join('\u0000');
|
|
30
|
+
if (changes(plane.id).length === 1 || seen.has(key))
|
|
31
|
+
return [];
|
|
32
|
+
seen.add(key);
|
|
33
|
+
return [{ id: plane.id, plane: plane.name, rel: `${name}.diff${picture.suffix}` }];
|
|
34
|
+
});
|
|
35
|
+
}
|
|
8
36
|
/**
|
|
9
37
|
* A page per side of every diagram that changed — the same single-file viewer
|
|
10
38
|
* `publish` writes, with the changes outlined — plus a PNG of each when
|
|
11
|
-
* `renderPng` is given
|
|
12
|
-
*
|
|
39
|
+
* `renderPng` is given. A diagram both sides have also gets a combined page,
|
|
40
|
+
* `<name>.diff.html`: both versions in one picture, with a PNG per plane that
|
|
41
|
+
* shows a change. Then an `index.html` over all of it, and a `summary.md` laid
|
|
42
|
+
* out to paste into an ADR.
|
|
13
43
|
*/
|
|
14
44
|
export async function writeDiffPages(diffs, opts) {
|
|
15
45
|
const shell = await readFile(opts.shellPath, 'utf8');
|
|
@@ -22,12 +52,14 @@ export async function writeDiffPages(diffs, opts) {
|
|
|
22
52
|
for (const d of shown) {
|
|
23
53
|
const entry = { png: opts.renderPng !== undefined };
|
|
24
54
|
const versions = { before: 'before' in d ? d.before : undefined, after: 'after' in d ? d.after : undefined };
|
|
55
|
+
const inlined = {};
|
|
25
56
|
for (const side of ['before', 'after']) {
|
|
26
57
|
const v = versions[side];
|
|
27
58
|
if (v === undefined)
|
|
28
59
|
continue;
|
|
29
60
|
const set = opts[side];
|
|
30
61
|
const model = await inlineAssets(v.model, { libraryDir: opts.libraryDir, assetsDir: path.join(set.diagramsDir, 'src', 'assets') }, caches[side], `diagram "${d.name}" at ${set.label}`);
|
|
62
|
+
inlined[side] = model;
|
|
31
63
|
const rel = `${d.name}.${side}`;
|
|
32
64
|
const pagePath = path.join(opts.outDir, `${rel}.html`);
|
|
33
65
|
await mkdir(path.dirname(pagePath), { recursive: true });
|
|
@@ -45,6 +77,29 @@ export async function writeDiffPages(diffs, opts) {
|
|
|
45
77
|
images.push(pngPath);
|
|
46
78
|
}
|
|
47
79
|
}
|
|
80
|
+
if (d.status === 'changed' && inlined.before !== undefined && inlined.after !== undefined) {
|
|
81
|
+
const combined = combineDiff(inlined.before, inlined.after, d.diff);
|
|
82
|
+
const rel = `${d.name}.diff`;
|
|
83
|
+
const pagePath = path.join(opts.outDir, `${rel}.html`);
|
|
84
|
+
await writeFile(pagePath, stampHtml(shell, {
|
|
85
|
+
model: combined.model,
|
|
86
|
+
...(d.after.layout !== undefined ? { layout: d.after.layout } : {}),
|
|
87
|
+
...(d.after.drawings !== undefined ? { drawings: d.after.drawings } : {}),
|
|
88
|
+
diff: { marks: combined.marks, combined: { planes: planeStatuses(d) } },
|
|
89
|
+
}));
|
|
90
|
+
pages.push(pagePath);
|
|
91
|
+
entry.combined = rel;
|
|
92
|
+
entry.removedIds = combined.model.relations.slice(inlined.after.relations.length).map((r) => r.id);
|
|
93
|
+
if (opts.renderPng !== undefined) {
|
|
94
|
+
entry.pictures = [];
|
|
95
|
+
for (const { id, ...picture } of combinedPictures(d.name, combined.model, combined.marks)) {
|
|
96
|
+
const pngPath = path.join(opts.outDir, `${picture.rel}.png`);
|
|
97
|
+
await opts.renderPng(pagePath, pngPath, id !== undefined ? { plane: id } : {});
|
|
98
|
+
images.push(pngPath);
|
|
99
|
+
entry.pictures.push(picture);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
48
103
|
files.set(d.name, entry);
|
|
49
104
|
}
|
|
50
105
|
const index = path.join(opts.outDir, 'index.html');
|
package/dist/diff/summary.d.ts
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
import type { DiagramDiff } from './compare.js';
|
|
2
2
|
import type { DiagramSet } from './load.js';
|
|
3
|
+
import type { DiagramFiles } from './pages.js';
|
|
3
4
|
/** What `summary.md` is written from. */
|
|
4
5
|
export interface SummaryOptions {
|
|
5
6
|
diffs: readonly DiagramDiff[];
|
|
6
7
|
/** each shown diagram's pages by side, as paths under the output directory without
|
|
7
8
|
* the extension, and whether a PNG was rendered beside each */
|
|
8
|
-
files: Map<string,
|
|
9
|
-
before?: string;
|
|
10
|
-
after?: string;
|
|
11
|
-
png: boolean;
|
|
12
|
-
}>;
|
|
9
|
+
files: Map<string, DiagramFiles>;
|
|
13
10
|
before: DiagramSet;
|
|
14
11
|
after: DiagramSet;
|
|
15
12
|
/** where the images are served from, as `DiffPagesOptions.imageUrl` */
|
package/dist/diff/summary.js
CHANGED
|
@@ -21,6 +21,12 @@ export function summaryMarkdown({ diffs, files, before, after, imageUrl }) {
|
|
|
21
21
|
for (const l of describeDiff(d))
|
|
22
22
|
out.push(`- \`${l[0]}\` ${l.slice(2)}`);
|
|
23
23
|
out.push('');
|
|
24
|
+
// Both versions in one picture, per plane that shows a change: a change on a
|
|
25
|
+
// later plane is in neither picture of the table above.
|
|
26
|
+
for (const picture of f?.pictures ?? []) {
|
|
27
|
+
const where = picture.plane !== undefined ? `Changes on ${picture.plane}` : 'Changes';
|
|
28
|
+
out.push(`**${where}**`, '', `})`, '');
|
|
29
|
+
}
|
|
24
30
|
}
|
|
25
31
|
return out.join('\n');
|
|
26
32
|
}
|
package/dist/text/vocabulary.js
CHANGED
|
@@ -109,6 +109,7 @@ export const TYPE_LOOKS = {
|
|
|
109
109
|
'sm-machine': box('', open),
|
|
110
110
|
'sm-state': shaped('rounded', ''),
|
|
111
111
|
'sm-region': box('', { ...dashed, ...open }),
|
|
112
|
+
'sm-zone': box('', open),
|
|
112
113
|
'sm-initial': shaped('dot', '', { legend: 'Initial state' }),
|
|
113
114
|
'sm-final': shaped('dot', '', { legend: 'Final state' }),
|
|
114
115
|
'sm-choice': shaped('diamond', '', { legend: 'Choice' }),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@diagc/cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.13.0",
|
|
4
4
|
"description": "Author software-architecture diagrams as code, compile them to a validated model, edit them in a local studio, and publish pages and images.",
|
|
5
5
|
"license": "AGPL-3.0-only",
|
|
6
6
|
"author": "Bogdan Frankovskyi",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"fast-glob": "^3.3.0",
|
|
46
46
|
"jiti": "^2.0.0",
|
|
47
47
|
"playwright-core": "^1.62.0",
|
|
48
|
-
"@diagc/core": "1.
|
|
48
|
+
"@diagc/core": "1.13.0"
|
|
49
49
|
},
|
|
50
50
|
"publishConfig": {
|
|
51
51
|
"access": "public"
|