@diagc/cli 0.13.0 → 0.14.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 +8 -2
- package/assets/studio/assets/{index-C0LPHkb1.js → index-uOTBB928.js} +1 -1
- package/assets/studio/index.html +1 -1
- package/assets/viewer/index.html +35 -32
- package/dist/diff.js +14 -6
- package/dist/publish/gallery.js +15 -6
- package/dist/publish/pageTheme.d.ts +21 -0
- package/dist/publish/pageTheme.js +48 -0
- package/dist/publish/snapshot.js +3 -1
- package/package.json +3 -3
package/dist/diff.js
CHANGED
|
@@ -6,6 +6,7 @@ import { diffMarks, diffModels, errMessage, isDrawings, isEmptyDiff, } from '@di
|
|
|
6
6
|
import { loadModel } from './compile.js';
|
|
7
7
|
import { inlineAssets } from './publish/publish.js';
|
|
8
8
|
import { stampHtml } from './publish/html.js';
|
|
9
|
+
import { THEME_HEAD_SCRIPT, THEME_SWITCH, themeCss } from './publish/pageTheme.js';
|
|
9
10
|
const EMPTY = { version: 1, id: '', name: '', nodes: [], containment: [], relations: [], layers: [], planes: [] };
|
|
10
11
|
async function readJson(file) {
|
|
11
12
|
return existsSync(file) ? JSON.parse(await readFile(file, 'utf8')) : undefined;
|
|
@@ -163,6 +164,10 @@ export async function writeDiffPages(diffs, opts) {
|
|
|
163
164
|
}
|
|
164
165
|
// The frames load each page unfolded (`?export=1`, the PNG's own mode): side by
|
|
165
166
|
// side, the whole picture is the point. The headings link the interactive pages.
|
|
167
|
+
// The overview's two palettes. The frames are export renders and stay light in both, and
|
|
168
|
+
// so do the swatches of the key, which show the outline colours drawn in those pictures.
|
|
169
|
+
const OVERVIEW_LIGHT = '--bg:#fff;--card:#fff;--border:#d0d7de;--text:#1f2328;--muted:#57606a;--faint:#8c959f;--add:#16a34a;--del:#dc2626;--chg:#b45309';
|
|
170
|
+
const OVERVIEW_DARK = '--bg:#12161b;--card:#1b222b;--border:#2d3743;--text:#e6ebf0;--muted:#a3afbb;--faint:#8b98a5;--add:#4ade80;--del:#f87171;--chg:#fbbf24';
|
|
166
171
|
function indexHtml(shown, files, from, to) {
|
|
167
172
|
const side = (rel, label) => rel === undefined
|
|
168
173
|
? `<div class="side empty"><h3>${escapeHtml(label)}</h3><p>not present</p></div>`
|
|
@@ -175,18 +180,21 @@ function indexHtml(shown, files, from, to) {
|
|
|
175
180
|
return `<!doctype html>
|
|
176
181
|
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1">
|
|
177
182
|
<title>Diagram diff ${escapeHtml(from)} → ${escapeHtml(to)}</title>
|
|
183
|
+
${THEME_HEAD_SCRIPT}
|
|
178
184
|
<style>
|
|
179
|
-
|
|
180
|
-
|
|
185
|
+
${themeCss(OVERVIEW_LIGHT, OVERVIEW_DARK)}
|
|
186
|
+
body { font: 14px/1.45 system-ui, sans-serif; margin: 0 auto; padding: 16px 24px 48px; max-width: 1800px; color: var(--text); background: var(--bg); }
|
|
187
|
+
header { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; }
|
|
188
|
+
h1 { font-size: 20px; } h2 { font-size: 16px; margin: 32px 0 6px; } h3 { font-size: 13px; margin: 0 0 6px; color: var(--muted); }
|
|
181
189
|
ul { margin: 0 0 12px; padding-left: 18px; font-family: ui-monospace, monospace; font-size: 12.5px; }
|
|
182
|
-
li.add { color:
|
|
190
|
+
li.add { color: var(--add); } li.del { color: var(--del); } li.chg { color: var(--chg); }
|
|
183
191
|
.key span { display: inline-block; margin-right: 14px; } .key i { display: inline-block; width: 12px; height: 12px; border: 3px solid; border-radius: 3px; vertical-align: -2px; margin-right: 4px; }
|
|
184
192
|
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
|
|
185
|
-
.side iframe { width: 100%; height: 70vh; border: 1px solid
|
|
186
|
-
.side.empty p { height: 70vh; margin: 0; display: grid; place-items: center; border: 1px dashed
|
|
193
|
+
.side iframe { width: 100%; height: 70vh; border: 1px solid var(--border); border-radius: 6px; }
|
|
194
|
+
.side.empty p { height: 70vh; margin: 0; display: grid; place-items: center; border: 1px dashed var(--border); border-radius: 6px; color: var(--faint); }
|
|
187
195
|
@media (max-width: 900px) { .pair { grid-template-columns: 1fr; } }
|
|
188
196
|
</style></head><body>
|
|
189
|
-
<h1>Diagram diff · ${escapeHtml(from)} → ${escapeHtml(to)}</h1>
|
|
197
|
+
<header><h1>Diagram diff · ${escapeHtml(from)} → ${escapeHtml(to)}</h1>${THEME_SWITCH}</header>
|
|
190
198
|
<p class="key"><span><i style="border-color:#16a34a"></i>added</span><span><i style="border-color:#dc2626;border-style:dashed"></i>removed</span><span><i style="border-color:#d97706"></i>changed</span><span><i style="border-color:#d97706;border-style:dashed"></i>holds a change (folded box, on the linked pages)</span></p>
|
|
191
199
|
${sections.length > 0 ? sections.join('\n') : '<p>No diagram changed.</p>'}
|
|
192
200
|
</body></html>
|
package/dist/publish/gallery.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { THEME_HEAD_SCRIPT, THEME_SWITCH, themeCss } from './pageTheme.js';
|
|
1
2
|
function esc(s) {
|
|
2
3
|
return s.replace(/&/g, '&').replace(/</g, '<').replace(/"/g, '"');
|
|
3
4
|
}
|
|
@@ -22,6 +23,10 @@ export function galleryLink(raw) {
|
|
|
22
23
|
}
|
|
23
24
|
return { href: url.href, text: `${url.host}${url.pathname}`.replace(/\/$/, '') };
|
|
24
25
|
}
|
|
26
|
+
// The page's two palettes. The dark one is the studio's own dark surface colours
|
|
27
|
+
// (packages/renderer/src/theme.ts), so the index and the pages it links read as one.
|
|
28
|
+
const LIGHT = '--bg:#fafafa;--card:#fff;--border:#ddd;--text:#222;--muted:#555;--faint:#777';
|
|
29
|
+
const DARK = '--bg:#12161b;--card:#1b222b;--border:#2d3743;--text:#e6ebf0;--muted:#a3afbb;--faint:#8b98a5';
|
|
25
30
|
export function buildGallery(entries, opts = {}) {
|
|
26
31
|
// One section per source folder, in path order, root diagrams first and unheaded:
|
|
27
32
|
// a flat grid of sixty path names is not a front page. ('' sorts ahead of every
|
|
@@ -47,19 +52,23 @@ export function buildGallery(entries, opts = {}) {
|
|
|
47
52
|
<html lang="en"><head><meta charset="UTF-8" />
|
|
48
53
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
49
54
|
<title>Diagrams</title>
|
|
55
|
+
${THEME_HEAD_SCRIPT}
|
|
50
56
|
<style>
|
|
51
|
-
|
|
57
|
+
${themeCss(LIGHT, DARK)}
|
|
58
|
+
body{font-family:system-ui,sans-serif;margin:24px;background:var(--bg);color:var(--text)}
|
|
52
59
|
header{display:flex;flex-wrap:wrap;align-items:baseline;justify-content:space-between;gap:0 16px}
|
|
60
|
+
.tools{display:flex;align-items:center;gap:12px}
|
|
53
61
|
h1{font-size:18px}
|
|
54
|
-
.link{font-size:13px;color
|
|
62
|
+
.link{font-size:13px;color:var(--muted);text-decoration:none}
|
|
55
63
|
.link:hover{text-decoration:underline}
|
|
56
|
-
h2{font-size:14px;margin:28px 0 12px;color
|
|
64
|
+
h2{font-size:14px;margin:28px 0 12px;color:var(--muted);font-weight:600}
|
|
57
65
|
.grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(240px,1fr));gap:16px}
|
|
58
|
-
.card{display:flex;flex-direction:column;gap:8px;padding:12px;border:1px solid
|
|
66
|
+
.card{display:flex;flex-direction:column;gap:8px;padding:12px;border:1px solid var(--border);border-radius:8px;text-decoration:none;color:var(--text);background:var(--card)}
|
|
67
|
+
/* a picture is light in both themes, so its tile is too */
|
|
59
68
|
.card img{width:100%;height:140px;object-fit:contain;background:#f4f4f4;border-radius:4px}
|
|
60
|
-
.card .path{font-size:12px;color
|
|
69
|
+
.card .path{font-size:12px;color:var(--faint)}
|
|
61
70
|
</style></head>
|
|
62
|
-
<body><header><h1>Diagrams</h1>${linkHtml}</header>
|
|
71
|
+
<body><header><h1>Diagrams</h1><span class="tools">${linkHtml}${THEME_SWITCH}</span></header>
|
|
63
72
|
${sections}
|
|
64
73
|
</body></html>`;
|
|
65
74
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** Where a reader's choice is remembered: 'light' or 'dark', and no entry means "follow
|
|
2
|
+
* the system". The renderer (packages/renderer/src/theme.ts) and the landing site
|
|
3
|
+
* (site/site.js) use the same key, which is what makes one choice cover every page on a
|
|
4
|
+
* host. None of the three can import another, so themeKey.test.ts pins them together. */
|
|
5
|
+
export declare const THEME_STORAGE_KEY = "diagc-theme";
|
|
6
|
+
/**
|
|
7
|
+
* A page's colour variables in both sets, and the switch's own look. Without JavaScript
|
|
8
|
+
* the page follows the system; `data-theme` on the root, set from the remembered choice,
|
|
9
|
+
* overrides it. The page must define --bg, --card, --border and --text.
|
|
10
|
+
*/
|
|
11
|
+
export declare function themeCss(light: string, dark: string): string;
|
|
12
|
+
/** For the head, ahead of the styles: marks the root before the first paint, so a page
|
|
13
|
+
* remembered as dark does not flash light. */
|
|
14
|
+
export declare const THEME_HEAD_SCRIPT = "<script>try{var t=localStorage.getItem('diagc-theme');if(t==='light'||t==='dark')document.documentElement.dataset.theme=t}catch(e){}</script>";
|
|
15
|
+
/**
|
|
16
|
+
* The switch, with the published page's two states and its rule (nextStored in
|
|
17
|
+
* apps/viewer/src/theme.ts): a click goes to the other theme, and a theme that is the
|
|
18
|
+
* system's own is not kept, so the page is back to following the system. Hidden until
|
|
19
|
+
* its script runs: without JavaScript there is no dead control.
|
|
20
|
+
*/
|
|
21
|
+
export declare const THEME_SWITCH = "<button type=\"button\" id=\"dg-theme\" hidden></button>\n<script>(function(){\nvar KEY='diagc-theme',root=document.documentElement,button=document.getElementById('dg-theme');\nvar mq=window.matchMedia?window.matchMedia('(prefers-color-scheme: dark)'):null;\nfunction system(){return mq&&mq.matches?'dark':'light'}\nfunction current(){return root.dataset.theme||system()}\nfunction mark(t){if(t)root.dataset.theme=t;else delete root.dataset.theme}\nfunction paint(){var dark=current()==='dark';button.textContent=dark?'\u2600':'\u263E';button.title=dark?'Light theme':'Dark theme';button.setAttribute('aria-label',dark?'Switch to light theme':'Switch to dark theme')}\nbutton.addEventListener('click',function(){\nvar next=current()==='dark'?'light':'dark',keep=next===system()?null:next;\nmark(keep);\ntry{if(keep)localStorage.setItem(KEY,keep);else localStorage.removeItem(KEY)}catch(e){}\npaint()});\nwindow.addEventListener('storage',function(e){\nif(e.key!==null&&e.key!==KEY)return;\nvar t=null;try{t=localStorage.getItem(KEY)}catch(x){}\nmark(t==='light'||t==='dark'?t:null);paint()});\nif(mq&&mq.addEventListener)mq.addEventListener('change',paint);\npaint();button.hidden=false})();</script>";
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// The light/dark pieces the index page and the diff overview share. A published diagram
|
|
2
|
+
// page has its own (apps/viewer/src/theme.ts). These two pages are plain HTML with no
|
|
3
|
+
// bundle, so theirs is a few lines of inline script, written for any browser.
|
|
4
|
+
/** Where a reader's choice is remembered: 'light' or 'dark', and no entry means "follow
|
|
5
|
+
* the system". The renderer (packages/renderer/src/theme.ts) and the landing site
|
|
6
|
+
* (site/site.js) use the same key, which is what makes one choice cover every page on a
|
|
7
|
+
* host. None of the three can import another, so themeKey.test.ts pins them together. */
|
|
8
|
+
export const THEME_STORAGE_KEY = 'diagc-theme';
|
|
9
|
+
/**
|
|
10
|
+
* A page's colour variables in both sets, and the switch's own look. Without JavaScript
|
|
11
|
+
* the page follows the system; `data-theme` on the root, set from the remembered choice,
|
|
12
|
+
* overrides it. The page must define --bg, --card, --border and --text.
|
|
13
|
+
*/
|
|
14
|
+
export function themeCss(light, dark) {
|
|
15
|
+
return `:root{color-scheme:light dark;${light}}
|
|
16
|
+
@media (prefers-color-scheme:dark){:root:not([data-theme=light]){${dark}}}
|
|
17
|
+
:root[data-theme=dark]{color-scheme:dark;${dark}}
|
|
18
|
+
:root[data-theme=light]{color-scheme:light}
|
|
19
|
+
#dg-theme{font:inherit;font-size:14px;line-height:1;padding:4px 8px;border:1px solid var(--border);border-radius:6px;background:var(--card);color:var(--text);cursor:pointer}`;
|
|
20
|
+
}
|
|
21
|
+
/** For the head, ahead of the styles: marks the root before the first paint, so a page
|
|
22
|
+
* remembered as dark does not flash light. */
|
|
23
|
+
export const THEME_HEAD_SCRIPT = `<script>try{var t=localStorage.getItem('${THEME_STORAGE_KEY}');if(t==='light'||t==='dark')document.documentElement.dataset.theme=t}catch(e){}</script>`;
|
|
24
|
+
/**
|
|
25
|
+
* The switch, with the published page's two states and its rule (nextStored in
|
|
26
|
+
* apps/viewer/src/theme.ts): a click goes to the other theme, and a theme that is the
|
|
27
|
+
* system's own is not kept, so the page is back to following the system. Hidden until
|
|
28
|
+
* its script runs: without JavaScript there is no dead control.
|
|
29
|
+
*/
|
|
30
|
+
export const THEME_SWITCH = `<button type="button" id="dg-theme" hidden></button>
|
|
31
|
+
<script>(function(){
|
|
32
|
+
var KEY='${THEME_STORAGE_KEY}',root=document.documentElement,button=document.getElementById('dg-theme');
|
|
33
|
+
var mq=window.matchMedia?window.matchMedia('(prefers-color-scheme: dark)'):null;
|
|
34
|
+
function system(){return mq&&mq.matches?'dark':'light'}
|
|
35
|
+
function current(){return root.dataset.theme||system()}
|
|
36
|
+
function mark(t){if(t)root.dataset.theme=t;else delete root.dataset.theme}
|
|
37
|
+
function paint(){var dark=current()==='dark';button.textContent=dark?'☀':'☾';button.title=dark?'Light theme':'Dark theme';button.setAttribute('aria-label',dark?'Switch to light theme':'Switch to dark theme')}
|
|
38
|
+
button.addEventListener('click',function(){
|
|
39
|
+
var next=current()==='dark'?'light':'dark',keep=next===system()?null:next;
|
|
40
|
+
mark(keep);
|
|
41
|
+
try{if(keep)localStorage.setItem(KEY,keep);else localStorage.removeItem(KEY)}catch(e){}
|
|
42
|
+
paint()});
|
|
43
|
+
window.addEventListener('storage',function(e){
|
|
44
|
+
if(e.key!==null&&e.key!==KEY)return;
|
|
45
|
+
var t=null;try{t=localStorage.getItem(KEY)}catch(x){}
|
|
46
|
+
mark(t==='light'||t==='dark'?t:null);paint()});
|
|
47
|
+
if(mq&&mq.addEventListener)mq.addEventListener('change',paint);
|
|
48
|
+
paint();button.hidden=false})();</script>`;
|
package/dist/publish/snapshot.js
CHANGED
|
@@ -24,7 +24,9 @@ export async function renderPng(htmlPath, pngPath) {
|
|
|
24
24
|
}
|
|
25
25
|
const browser = await chromium.launch({ executablePath, headless: true });
|
|
26
26
|
try {
|
|
27
|
-
|
|
27
|
+
// Light, by name: `?export=1` already makes the viewer light whatever the browser
|
|
28
|
+
// prefers, and this says so where the picture is taken.
|
|
29
|
+
const page = await browser.newPage({ viewport: { width: 1600, height: 1000 }, deviceScaleFactor: 2, colorScheme: 'light' });
|
|
28
30
|
// `?export=1` tells the viewer to unfold every group for a full overview.
|
|
29
31
|
await page.goto(`${pathToFileURL(path.resolve(htmlPath)).href}?export=1`);
|
|
30
32
|
await page.waitForFunction(() => window.__DG_READY__ === true, null, { timeout: 15_000 });
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@diagc/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.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",
|
|
7
|
-
"homepage": "https://github.
|
|
7
|
+
"homepage": "https://ferroman.github.io/diagc/",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
10
10
|
"url": "git+https://github.com/Ferroman/diagc.git",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"fast-glob": "^3.3.0",
|
|
45
45
|
"jiti": "^2.0.0",
|
|
46
46
|
"playwright-core": "^1.62.0",
|
|
47
|
-
"@diagc/core": "0.
|
|
47
|
+
"@diagc/core": "0.14.0"
|
|
48
48
|
},
|
|
49
49
|
"publishConfig": {
|
|
50
50
|
"access": "public"
|