@diagc/cli 0.12.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/dist/cli.d.ts CHANGED
@@ -16,7 +16,7 @@ interface Args {
16
16
  labels?: [string, string];
17
17
  /** init `--type`: which starter to copy */
18
18
  type?: string;
19
- /** init `--agents`: write the coding-agent block */
19
+ /** init `--agents`: write the coding-agent block and the Claude Code skill */
20
20
  agents: boolean;
21
21
  }
22
22
  /** Parse argv into command + flags. Unknown flags (anything `--…` that is not
package/dist/cli.js CHANGED
@@ -43,7 +43,8 @@ const USAGE = `Usage: diagc <init|compile|lint|watch|publish|studio|eject|diff|g
43
43
  Commands:
44
44
  init init [name] [--type <type>] [--agents]: set a repository up — a starter
45
45
  diagram under .diagrams/src (compiled), the .gitignore lines, and with
46
- --agents a pointer to the guide for coding agents (AGENTS.md / CLAUDE.md)
46
+ --agents a pointer to the guide for coding agents (AGENTS.md / CLAUDE.md,
47
+ and a skill where Claude Code is in use)
47
48
  compile Compile *.diagram.{ts,json} sources into overlay artifacts once
48
49
  lint Report suspicious diagrams (typos, duplicates, unused or undrawn parts); exit 1 on any
49
50
  watch Recompile — and live-recompile — a directory of sources
@@ -65,7 +66,8 @@ Options:
65
66
  --image-url t diff: summary.md's image links as t, {path} standing for each PNG
66
67
  --update-includes Refetch remote includes and rewrite the snapshot lock
67
68
  --type <type> init: the starter to copy (default basic; 'diagc guide' lists the types)
68
- --agents init: write the coding-agent block into AGENTS.md / CLAUDE.md
69
+ --agents init: write the coding-agent block into AGENTS.md / CLAUDE.md, and
70
+ the skill into .claude/skills/diagc/ where Claude Code is in use
69
71
  --help, -h Show this help and exit
70
72
  `;
71
73
  /** Parse argv into command + flags. Unknown flags (anything `--…` that is not
@@ -406,6 +408,7 @@ async function main() {
406
408
  ...(args.type !== undefined ? { type: args.type } : {}),
407
409
  agents: args.agents,
408
410
  startersDir: home.startersDir,
411
+ skillFile: home.skillFile,
409
412
  version: cliVersion(home.root),
410
413
  coreEntry: home.coreEntry,
411
414
  resolver: snap.resolver,
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
- body { font: 14px/1.45 system-ui, sans-serif; margin: 0 auto; padding: 16px 24px 48px; max-width: 1800px; color: #1f2328; background: #fff; }
180
- h1 { font-size: 20px; } h2 { font-size: 16px; margin: 32px 0 6px; } h3 { font-size: 13px; margin: 0 0 6px; color: #57606a; }
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: #16a34a; } li.del { color: #dc2626; } li.chg { color: #b45309; }
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 #d0d7de; border-radius: 6px; }
186
- .side.empty p { height: 70vh; margin: 0; display: grid; place-items: center; border: 1px dashed #d0d7de; border-radius: 6px; color: #8c959f; }
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/home.d.ts CHANGED
@@ -21,6 +21,8 @@ export interface HomePaths {
21
21
  guideDir: string;
22
22
  /** `<type>/starter.diagram.ts`, one folder per diagram type */
23
23
  startersDir: string;
24
+ /** the Claude Code skill `diagc init --agents` writes into a repository */
25
+ skillFile: string;
24
26
  }
25
27
  export interface Home {
26
28
  root: string;
package/dist/home.js CHANGED
@@ -64,6 +64,7 @@ export function homePaths(home, coreEntry = resolveCoreEntry) {
64
64
  studioDir,
65
65
  guideDir: path.join(root, 'assets', 'guide'),
66
66
  startersDir: path.join(root, 'assets', 'starters'),
67
+ skillFile: path.join(root, 'assets', 'skill', 'SKILL.md'),
67
68
  };
68
69
  }
69
70
  return {
@@ -77,6 +78,7 @@ export function homePaths(home, coreEntry = resolveCoreEntry) {
77
78
  // A checkout reads the starters where the examples keep them; `stage-assets`
78
79
  // copies only the starter files out, into the same `<type>/` shape.
79
80
  startersDir: path.join(root, '.diagrams', 'src', 'examples'),
81
+ skillFile: path.join(root, 'packages', 'diagc', 'skill', 'SKILL.md'),
80
82
  };
81
83
  }
82
84
  /** The release this CLI is, read from the home's own `package.json`. release-please
package/dist/init.d.ts CHANGED
@@ -8,9 +8,11 @@ export interface InitOptions {
8
8
  name?: string;
9
9
  /** the starter to copy; `basic` when omitted */
10
10
  type?: string;
11
- /** write the coding-agent block into AGENTS.md / CLAUDE.md */
11
+ /** write the coding-agent block into AGENTS.md / CLAUDE.md, and the Claude Code skill */
12
12
  agents: boolean;
13
13
  startersDir: string;
14
+ /** the skill the package ships, copied into a repository that uses Claude Code */
15
+ skillFile: string;
14
16
  /** what the `npm i -D @diagc/core@…` hint names */
15
17
  version: string;
16
18
  coreEntry: string;
@@ -30,10 +32,17 @@ export declare const AGENTS_END = "<!-- diagc:end -->";
30
32
  * this block does not go stale when the DSL grows. The markers let a later run
31
33
  * replace it in place. */
32
34
  export declare const AGENTS_BLOCK = "<!-- diagc:begin -->\n## Diagrams\n\nDiagrams live in `.diagrams/src/*.diagram.ts` and are built with `diagc`.\n\n- Run `diagc guide` before writing or changing one; `diagc guide <type>` covers one diagram type.\n- Run `diagc lint --json` until it reports nothing.\n- Run `diagc publish <name>` and look at `.diagrams/static/<name>.png` to check the picture.\n<!-- diagc:end -->\n";
33
- /** `existing` with the block added at the end, or — when both markers are there —
34
- * with the earlier block replaced where it stands, so a second run never
35
- * duplicates it and a run after an upgrade refreshes it. */
36
- export declare function withAgentsBlock(existing: string): {
35
+ /** Where the skill goes: the folder Claude Code reads a repository's skills from. */
36
+ export declare const SKILL_PATH = ".claude/skills/diagc/SKILL.md";
37
+ /** `existing` with `block` added at the end, or — when an earlier block is there —
38
+ * with that block replaced where it stands, so a second run never duplicates it
39
+ * and a run after an upgrade refreshes it. `block` runs from the begin marker to
40
+ * the newline after the end marker. */
41
+ export declare function withBlock(existing: string, block: string): {
42
+ text: string;
43
+ replaced: boolean;
44
+ };
45
+ export declare const withAgentsBlock: (existing: string) => {
37
46
  text: string;
38
47
  replaced: boolean;
39
48
  };
package/dist/init.js CHANGED
@@ -1,4 +1,4 @@
1
- import { existsSync } from 'node:fs';
1
+ import { existsSync, statSync } from 'node:fs';
2
2
  import { mkdir, readFile, writeFile } from 'node:fs/promises';
3
3
  import path from 'node:path';
4
4
  import fg from 'fast-glob';
@@ -27,24 +27,27 @@ Diagrams live in \`.diagrams/src/*.diagram.ts\` and are built with \`diagc\`.
27
27
  - Run \`diagc publish <name>\` and look at \`.diagrams/static/<name>.png\` to check the picture.
28
28
  ${AGENTS_END}
29
29
  `;
30
- /** `existing` with the block added at the end, or — when both markers are there —
31
- * with the earlier block replaced where it stands, so a second run never
32
- * duplicates it and a run after an upgrade refreshes it. */
33
- export function withAgentsBlock(existing) {
34
- const begin = existing.indexOf(AGENTS_BEGIN);
35
- const end = begin === -1 ? -1 : existing.indexOf(AGENTS_END, begin);
36
- if (begin !== -1 && end !== -1) {
37
- let after = end + AGENTS_END.length;
38
- // The block carries its own closing newline; take the old one with the old block.
39
- if (existing.startsWith('\n', after))
40
- after += 1;
41
- return { text: existing.slice(0, begin) + AGENTS_BLOCK + existing.slice(after), replaced: true };
42
- }
30
+ /** Where the skill goes: the folder Claude Code reads a repository's skills from. */
31
+ export const SKILL_PATH = '.claude/skills/diagc/SKILL.md';
32
+ /** An earlier block: a begin marker, its end marker with no second begin between
33
+ * them, and the closing newline the block carries. A begin whose end was deleted
34
+ * by hand is not one — taking it up to the next block's end would delete
35
+ * whatever the user wrote in between. */
36
+ const EARLIER_BLOCK = new RegExp(`${AGENTS_BEGIN}(?:(?!${AGENTS_BEGIN})[\\s\\S])*?${AGENTS_END}\\n?`);
37
+ /** `existing` with `block` added at the end, or — when an earlier block is there —
38
+ * with that block replaced where it stands, so a second run never duplicates it
39
+ * and a run after an upgrade refreshes it. `block` runs from the begin marker to
40
+ * the newline after the end marker. */
41
+ export function withBlock(existing, block) {
42
+ // A function, so a `$&` in the block is text and not a back-reference.
43
+ if (EARLIER_BLOCK.test(existing))
44
+ return { text: existing.replace(EARLIER_BLOCK, () => block), replaced: true };
43
45
  if (existing === '')
44
- return { text: AGENTS_BLOCK, replaced: false };
46
+ return { text: block, replaced: false };
45
47
  const sep = existing.endsWith('\n\n') ? '' : existing.endsWith('\n') ? '\n' : '\n\n';
46
- return { text: `${existing}${sep}${AGENTS_BLOCK}`, replaced: false };
48
+ return { text: `${existing}${sep}${block}`, replaced: false };
47
49
  }
50
+ export const withAgentsBlock = (existing) => withBlock(existing, AGENTS_BLOCK);
48
51
  const COL = 38;
49
52
  const done = (left, right) => `✓ ${left.padEnd(COL)}${right}`;
50
53
  const skipped = (left, right) => `· ${left.padEnd(COL)}${right}`;
@@ -141,7 +144,41 @@ async function agentsStep(cwd, io) {
141
144
  io.out(done(name, replaced ? '(diagc block refreshed)' : '(diagc block added)'));
142
145
  }
143
146
  }
144
- /** Step 4: compile what was written, so the user starts from a diagram that is
147
+ /** `.claude/` is Claude Code's own folder, not neutral ground like `AGENTS.md`, so
148
+ * the skill goes only where the repository already shows that tool in use. */
149
+ const usesClaudeCode = (cwd) => (statSync(path.join(cwd, '.claude'), { throwIfNoEntry: false })?.isDirectory() ?? false) || existsSync(path.join(cwd, 'CLAUDE.md'));
150
+ /** Everything step 4 has to read, read before the first write: an install that
151
+ * lost its skill is a refusal, and a refusal leaves the tree untouched. A new file
152
+ * is the shipped one, frontmatter and all; in a file that is already there only
153
+ * the text between the markers is diagc's, as in AGENTS.md. Undefined where the
154
+ * skill does not go. */
155
+ async function planSkill(opts) {
156
+ if (!opts.agents || !usesClaudeCode(opts.cwd))
157
+ return undefined;
158
+ if (!existsSync(opts.skillFile))
159
+ throw new InitError(`skill file missing from this install (${opts.skillFile}) — reinstall diagc.`);
160
+ const source = await readFile(opts.skillFile, 'utf8');
161
+ const begin = source.indexOf(AGENTS_BEGIN);
162
+ // The shipped file's own shape, held by skillContent.test.ts: a bug, not a refusal.
163
+ if (begin === -1)
164
+ throw new Error(`${opts.skillFile}: no ${AGENTS_BEGIN} marker`);
165
+ const file = path.join(opts.cwd, SKILL_PATH);
166
+ const existing = existsSync(file) ? await readFile(file, 'utf8') : '';
167
+ // An empty file has no frontmatter to keep: it gets the whole skill, as a new one does.
168
+ return existing.trim() === '' ? { text: source, replaced: false } : withBlock(existing, source.slice(begin));
169
+ }
170
+ /** Step 4: the Claude Code skill, with `--agents`. */
171
+ async function skillStep(cwd, plan, io) {
172
+ if (plan === undefined) {
173
+ io.out(skipped(SKILL_PATH, 'no .claude/ or CLAUDE.md here — skill skipped'));
174
+ return;
175
+ }
176
+ const file = path.join(cwd, SKILL_PATH);
177
+ await mkdir(path.dirname(file), { recursive: true });
178
+ await writeFile(file, plan.text);
179
+ io.out(done(SKILL_PATH, plan.replaced ? '(diagc skill refreshed)' : '(diagc skill added)'));
180
+ }
181
+ /** Step 5: compile what was written, so the user starts from a diagram that is
145
182
  * known to build and sees where the artifact went. */
146
183
  async function compileStep(file, opts, io) {
147
184
  let artifact;
@@ -157,7 +194,7 @@ async function compileStep(file, opts, io) {
157
194
  }
158
195
  io.out(done('compiled', `-> ${path.relative(opts.cwd, artifact).split(path.sep).join('/')}`));
159
196
  }
160
- /** Step 5: what to do now. The `--agents` line goes when `--agents` was given; the
197
+ /** Step 6: what to do now. The `--agents` line goes when `--agents` was given; the
161
198
  * install hint only where there is a `package.json` to install into. */
162
199
  function nextSteps(opts) {
163
200
  const lines = [
@@ -165,7 +202,7 @@ function nextSteps(opts) {
165
202
  ['diagc guide', 'how to write diagrams (for you or your agent)'],
166
203
  ];
167
204
  if (!opts.agents)
168
- lines.push(['diagc init --agents', 'point coding agents at the guide (AGENTS.md)']);
205
+ lines.push(['diagc init --agents', 'point coding agents at the guide (AGENTS.md, Claude Code skill)']);
169
206
  if (existsSync(path.join(opts.cwd, 'package.json')))
170
207
  lines.push([`npm i -D @diagc/core@${opts.version}`, 'editor types for .diagram.ts']);
171
208
  return `\nNext:\n${lines.map(([cmd, what]) => ` ${cmd.padEnd(COL)}${what}`).join('\n')}`;
@@ -178,10 +215,13 @@ const stdio = {
178
215
  * line on stderr; anything else is a bug and is left to throw. */
179
216
  export async function runInit(opts, io = stdio) {
180
217
  try {
218
+ const skill = await planSkill(opts);
181
219
  const written = await starterStep(opts, io);
182
220
  await gitignoreStep(opts.cwd, io);
183
- if (opts.agents)
221
+ if (opts.agents) {
184
222
  await agentsStep(opts.cwd, io);
223
+ await skillStep(opts.cwd, skill, io);
224
+ }
185
225
  if (written !== undefined)
186
226
  await compileStep(written, opts, io);
187
227
  io.out(nextSteps(opts));
@@ -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, '&amp;').replace(/</g, '&lt;').replace(/"/g, '&quot;');
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
- body{font-family:system-ui,sans-serif;margin:24px;background:#fafafa}
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:#555;text-decoration:none}
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:#555;font-weight:600}
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 #ddd;border-radius:8px;text-decoration:none;color:#222;background:#fff}
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:#777}
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>`;
@@ -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
- const page = await browser.newPage({ viewport: { width: 1600, height: 1000 }, deviceScaleFactor: 2 });
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.12.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.com/Ferroman/diagc#readme",
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.12.0"
47
+ "@diagc/core": "0.14.0"
48
48
  },
49
49
  "publishConfig": {
50
50
  "access": "public"