concept-atlas-dense-explain 3.0.2 → 4.0.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 CHANGED
@@ -31,13 +31,13 @@ a no-op. `--mode` defaults to `scroll`. Use `-o` to choose the output path (a
31
31
  directory when passing several inputs). Validation errors abort the build; `--no-validate` forces a knowingly
32
32
  broken build.
33
33
 
34
- Mermaid loads from a CDN at runtime by default (fast builds, needs network);
35
- `--inline-mermaid` bakes it into the HTML for a fully offline single file, and
36
- `--mermaid-cdn` overrides the CDN URL. Appearance defaults can be baked with
37
- `--skin`, `--default-mode` and `--style`; readers can still switch in the UI.
38
- Local figures link by default (small HTML, ship `assets/` beside the output);
39
- `--inline-assets` bakes them in as base64 for a self-contained file, and a
40
- per-figure `inline={true|false}` overrides that choice.
34
+ Mermaid-syntax diagrams are rendered by Pele, which ships inline: a page with
35
+ `<Mermaid>` is a fully offline single file with no CDN call, and a document
36
+ without `<Mermaid>` drops the renderer entirely. Appearance defaults can be
37
+ baked with `--skin`, `--default-mode` and `--style`; readers can still switch in
38
+ the UI. Local figures link by default (small HTML, ship `assets/` beside the
39
+ output); `--inline-assets` bakes them in as base64 for a self-contained file,
40
+ and a per-figure `inline={true|false}` overrides that choice.
41
41
 
42
42
  Run `npx concept-atlas-dense-explain help` for the full flag list.
43
43
 
package/bin/cli.mjs CHANGED
@@ -35,7 +35,7 @@ let buildCounter = 0;
35
35
  function usage() {
36
36
  console.log('Usage:');
37
37
  console.log(
38
- ' npx concept-atlas-dense-explain <input.mdx>... [--mode atlas|scroll] [--skin <id>] [--default-mode dark|light|system] [--style <id>] [-o output.html|dir] [--concurrency N] [--inline-assets] [--inline-mermaid] [--mermaid-cdn <url>] [--json] [--no-validate]'
38
+ ' npx concept-atlas-dense-explain <input.mdx>... [--mode atlas|scroll] [--skin <id>] [--default-mode dark|light|system] [--style <id>] [-o output.html|dir] [--concurrency N] [--inline-assets] [--json] [--no-validate]'
39
39
  );
40
40
  console.log(' npx concept-atlas-dense-explain render <input.mdx>... [-o output.html|dir]');
41
41
  console.log(
@@ -55,7 +55,7 @@ function usage() {
55
55
  ' Figures are kept as relative links by default (small HTML; ship the assets/ dir beside it). --inline-assets bakes every local image into the HTML as base64 instead; a per-tag inline={true|false} on <Figure> overrides that for one image. --link-assets is kept as an explicit alias for the default.'
56
56
  );
57
57
  console.log(
58
- ' Mermaid diagrams load from a CDN at runtime by default (fast builds, needs network); --inline-mermaid bakes Mermaid into the HTML for a fully offline single file; --mermaid-cdn overrides the CDN URL.'
58
+ ' Mermaid-syntax diagrams (<Mermaid>) are rendered by Pele and ship inline, so every page is a fully offline single file. A document without <Mermaid> drops the renderer entirely.'
59
59
  );
60
60
  console.log(
61
61
  ` --skin bakes a default palette (${SKINS.map(skin => skin.id).join(', ')}); --default-mode bakes a default dark/light mode; --style bakes a default component style (${COMPONENT_STYLES.map(style => style.id).join(', ')}). Readers can still switch in the UI.`
@@ -101,8 +101,7 @@ const VALUE_FLAGS = new Set([
101
101
  '--concurrency',
102
102
  '--skin',
103
103
  '--default-mode',
104
- '--style',
105
- '--mermaid-cdn'
104
+ '--style'
106
105
  ]);
107
106
  const BOOLEAN_FLAGS = new Set([
108
107
  '--force',
@@ -111,7 +110,6 @@ const BOOLEAN_FLAGS = new Set([
111
110
  '--no-validate',
112
111
  '--link-assets',
113
112
  '--inline-assets',
114
- '--inline-mermaid',
115
113
  '--help',
116
114
  '-h',
117
115
  '--version',
@@ -341,8 +339,6 @@ const inlineAssets = parsed.flags.has('--inline-assets');
341
339
  if (linkAssets && inlineAssets) {
342
340
  fail('--link-assets and --inline-assets are mutually exclusive (linking is the default).');
343
341
  }
344
- const inlineMermaid = parsed.flags.has('--inline-mermaid');
345
- const mermaidCdn = parsed.values.get('--mermaid-cdn') || null;
346
342
  const modeFlag = parsed.values.get('--mode') || null;
347
343
 
348
344
  // Compile-time appearance defaults. Invalid values fail fast with the valid
@@ -515,10 +511,6 @@ async function buildOne(job) {
515
511
  if (skinFlag) define.__ATLAS_DEFAULT_SKIN__ = JSON.stringify(skinFlag);
516
512
  if (defaultModeFlag) define.__ATLAS_DEFAULT_MODE__ = JSON.stringify(defaultModeFlag);
517
513
  if (styleFlag) define.__ATLAS_DEFAULT_STYLE__ = JSON.stringify(styleFlag);
518
- if (features.mermaid) {
519
- define.__ATLAS_MERMAID_MODE__ = JSON.stringify(inlineMermaid ? 'inline' : 'cdn');
520
- if (mermaidCdn) define.__ATLAS_MERMAID_CDN_URL__ = JSON.stringify(mermaidCdn);
521
- }
522
514
  try {
523
515
  await build({
524
516
  root: templateRoot,
@@ -567,10 +559,10 @@ async function buildOne(job) {
567
559
  }
568
560
  }
569
561
 
570
- /** Saves the mermaid/KaTeX payload when a document never renders them. */
562
+ /** Notes the optional renderers a page carries, or that it dropped them. */
571
563
  function describeFeatures(features) {
572
564
  const tags = [];
573
- if (features.mermaid) tags.push(inlineMermaid ? 'mermaid inline' : 'mermaid cdn');
565
+ if (features.pele) tags.push('Pele');
574
566
  if (features.math) tags.push('KaTeX');
575
567
  return tags.length ? ` [${tags.join(', ')}]` : '';
576
568
  }
@@ -580,12 +572,10 @@ function summarizeFeatures(jobs, results) {
580
572
  const pages = jobs.filter(job => built.has(job.input));
581
573
  if (!pages.length) return '';
582
574
  const droppedMath = pages.filter(job => !job.features.math).length;
583
- const droppedMermaid = pages.filter(job => !job.features.mermaid).length;
584
- const cdnMermaid = pages.filter(job => job.features.mermaid && !inlineMermaid).length;
575
+ const droppedPele = pages.filter(job => !job.features.pele).length;
585
576
  const parts = [];
586
- if (cdnMermaid) parts.push(`Mermaid via CDN on ${cdnMermaid}/${pages.length}`);
587
577
  if (droppedMath) parts.push(`KaTeX dropped on ${droppedMath}/${pages.length}`);
588
- if (droppedMermaid) parts.push(`Mermaid dropped on ${droppedMermaid}/${pages.length}`);
578
+ if (droppedPele) parts.push(`Pele dropped on ${droppedPele}/${pages.length}`);
589
579
  return parts.join(', ');
590
580
  }
591
581
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "concept-atlas-dense-explain",
3
- "version": "3.0.2",
3
+ "version": "4.0.0",
4
4
  "description": "Portable dense-explanation skill and MDX concept atlas template",
5
5
  "type": "module",
6
6
  "bin": {
@@ -21,7 +21,7 @@
21
21
  "d3": "^7.9.0",
22
22
  "katex": "^0.16.47",
23
23
  "lucide-react": "^0.475.0",
24
- "mermaid": "^11.17.2",
24
+ "pele": "^1.6.0",
25
25
  "react": "^18.3.1",
26
26
  "react-dom": "^18.3.1",
27
27
  "vite": "^5.4.14",
@@ -32,9 +32,9 @@ This is the only runner — there is nothing to look for. Do not search for a lo
32
32
  npx concept-atlas-dense-explain validate <file>.mdx --json
33
33
  ```
34
34
  Diagnostics are `CODE line:column message`. Fix all `error`s and re-run; address warnings when cheap.
35
- 6. Compile: `npx concept-atlas-dense-explain <file>.mdx --mode atlas|scroll [-o out.html] [--skin <id>] [--default-mode dark|light|system] [--style <id>] [--mermaid-cdn <url>]`. Output is a standalone HTML beside the MDX unless `-o` is given. Validation errors abort the build (`--no-validate` forces a knowingly broken build). **Mermaid stays on its runtime CDN by default — do not pass `--inline-mermaid` on your own.** Only add `--inline-mermaid` when the user explicitly asks for a fully offline single file, since it bloats the HTML with the whole Mermaid bundle.
35
+ 6. Compile: `npx concept-atlas-dense-explain <file>.mdx --mode atlas|scroll [-o out.html] [--skin <id>] [--default-mode dark|light|system] [--style <id>]`. Output is a standalone HTML beside the MDX unless `-o` is given. Validation errors abort the build (`--no-validate` forces a knowingly broken build). `<Mermaid>` charts are rendered by Pele and inline into the HTML, so the page is a fully offline single file with no CDN call — no flag needed.
36
36
  7. **Appearance (optional)**: pages ship a reader-facing appearance menu — palette (`aurora` indigo, `ember` gold, `verdant` forest, `sakura` pink-plum, `noir` ink), a dark/light toggle, and a component style pack (`manuscript` editorial marginalia, `classic` boxed cards, `shadcn` hairline-bordered minimal UI, `elastic` bordered observability panels). The shipped default is aurora × manuscript × light; choices persist in localStorage across both carriers. Bake different compile-time defaults with `--skin ember --default-mode dark --style classic` (or `CONCEPT_ATLAS_SKIN` / `CONCEPT_ATLAS_DEFAULT_MODE` / `CONCEPT_ATLAS_STYLE` on the repo build); `--default-mode` honors `dark`/`light` and resolves `system` to the carrier default (`light`). Bake a default only when the user asks for one — content MDX never sets appearance.
37
- 8. For several documents, pass them all in one call: `npx concept-atlas-dense-explain a.mdx b.mdx c.mdx -o dist [--concurrency 3]` (`-o` is then a directory; everything validates first, then builds in parallel). Builds bundle only the heavy renderers the content uses: no `<Math>` skips KaTeX's ~1.4MB inlined fonts, and Mermaid stays on a CDN. Never add dummy `<Math>`/`<Mermaid>` nodes to "enable" them.
37
+ 8. For several documents, pass them all in one call: `npx concept-atlas-dense-explain a.mdx b.mdx c.mdx -o dist [--concurrency 3]` (`-o` is then a directory; everything validates first, then builds in parallel). Builds bundle only the renderers the content uses: no `<Math>` skips KaTeX's ~1.4MB inlined fonts, and no `<Mermaid>` drops Pele entirely. Never add dummy `<Math>`/`<Mermaid>` nodes to "enable" them.
38
38
  9. Report the shell, output path, validation result (errors/warnings), and limitations. Do not claim interactions you did not verify.
39
39
 
40
40
  ## Carriers
@@ -83,7 +83,7 @@ This is the only runner — there is nothing to look for. Do not search for a lo
83
83
  - All `error` diagnostics resolved (or `--no-validate` explicitly justified).
84
84
  - All `ConceptRef`, `Relation` endpoints, and `ConceptGraph root` point at existing node ids.
85
85
  - Every node has `title` + `summary`; every `Relation` has a `label`.
86
- - You left Mermaid on its CDN default and did not pass `--inline-mermaid` unless the user explicitly asked for a fully offline single file.
86
+ - Pages with `<Mermaid>` are already fully offline: Pele ships inline, so you never need a CDN flag.
87
87
  - The HTML file exists at the reported path.
88
88
 
89
89
  If `npx` cannot reach the registry, report the blocker. Never copy implementation files into the skill directory.
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import { createPortal } from 'react-dom';
3
- import mermaid from 'mermaid';
3
+ import { render as renderPele } from 'pele';
4
4
  import katex from 'katex';
5
5
  import { ZoomIn } from 'lucide-react';
6
6
  import 'katex/dist/katex.min.css';
@@ -8,81 +8,13 @@ import { registerReferences, subscribeReferences, getReferenceIndex } from '../m
8
8
  import { registerFigure, subscribeFigures, getFigureNumber } from '../model/figures.js';
9
9
  import { useFigureScope } from './FigureScope.jsx';
10
10
 
11
- // Mermaid reads the active skin/mode from CSS variables so diagrams follow
12
- // the current appearance. A MutationObserver re-renders charts when the
13
- // attributes on <html> change.
14
- const appearanceStore = (() => {
15
- const listeners = new Set();
16
- const readKey = () =>
17
- typeof document === 'undefined'
18
- ? ''
19
- : `${document.documentElement.getAttribute('data-skin') || ''}:${document.documentElement.getAttribute('data-theme') || ''}`;
20
- let observer = null;
21
- let lastKey = '';
22
- return {
23
- subscribe(listener) {
24
- listeners.add(listener);
25
- if (!observer && typeof MutationObserver !== 'undefined') {
26
- lastKey = readKey();
27
- observer = new MutationObserver(() => {
28
- const nextKey = readKey();
29
- if (nextKey !== lastKey) {
30
- lastKey = nextKey;
31
- listeners.forEach(fn => fn());
32
- }
33
- });
34
- observer.observe(document.documentElement, {
35
- attributes: true,
36
- attributeFilter: ['data-skin', 'data-theme']
37
- });
38
- }
39
- return () => {
40
- listeners.delete(listener);
41
- if (listeners.size === 0 && observer) {
42
- observer.disconnect();
43
- observer = null;
44
- }
45
- };
46
- },
47
- getKey: readKey
48
- };
49
- })();
50
-
51
- function useAppearanceKey() {
52
- return React.useSyncExternalStore(
53
- appearanceStore.subscribe,
54
- appearanceStore.getKey,
55
- appearanceStore.getKey
56
- );
57
- }
58
-
59
- const MERMAID_FALLBACKS = {
60
- primaryColor: '#172554',
61
- primaryTextColor: '#e0f2fe',
62
- primaryBorderColor: '#38bdf8',
63
- lineColor: '#64748b',
64
- tertiaryColor: '#0f172a'
65
- };
66
-
67
- function configureMermaid() {
11
+ // Pele renders Mermaid-syntax charts to SVG. It themes itself from the
12
+ // `--pele-*` CSS variables (see tokens.css), so a diagram follows the active
13
+ // skin and mode with no re-render; only its font is measured at render time.
14
+ function diagramFontFamily() {
15
+ if (typeof document === 'undefined') return undefined;
68
16
  const styles = getComputedStyle(document.documentElement);
69
- const read = (name, fallback) => styles.getPropertyValue(name).trim() || fallback;
70
- const nodeBg = read('--mermaid-node-bg', MERMAID_FALLBACKS.primaryColor);
71
- mermaid.initialize({
72
- startOnLoad: false,
73
- securityLevel: 'loose',
74
- theme: 'base',
75
- look: 'handDrawn',
76
- themeVariables: {
77
- primaryColor: nodeBg,
78
- primaryTextColor: read('--mermaid-node-text', MERMAID_FALLBACKS.primaryTextColor),
79
- primaryBorderColor: read('--mermaid-node-border', MERMAID_FALLBACKS.primaryBorderColor),
80
- lineColor: read('--mermaid-line', MERMAID_FALLBACKS.lineColor),
81
- secondaryColor: nodeBg,
82
- tertiaryColor: read('--mermaid-canvas', MERMAID_FALLBACKS.tertiaryColor),
83
- fontFamily: read('--font-sans', "'Plus Jakarta Sans', sans-serif")
84
- }
85
- });
17
+ return styles.getPropertyValue('--font-sans').trim() || undefined;
86
18
  }
87
19
 
88
20
  // Shared helpers ------------------------------------------------------------
@@ -1374,27 +1306,24 @@ Tabs.displayName = 'Tabs';
1374
1306
  */
1375
1307
  function MermaidZoom({ chart, title, onClose }) {
1376
1308
  const ref = React.useRef(null);
1377
- const appearanceKey = useAppearanceKey();
1378
1309
  const [error, setError] = React.useState('');
1379
1310
 
1380
1311
  React.useEffect(() => {
1381
- let cancelled = false;
1382
- async function renderZoom() {
1383
- if (!ref.current || !chart.trim()) return;
1384
- try {
1385
- configureMermaid();
1386
- const renderId = `mermaid-zoom-${Math.random().toString(36).slice(2, 10)}`;
1387
- const { svg } = await mermaid.render(renderId, chart.trim());
1388
- if (!cancelled && ref.current) ref.current.innerHTML = svg;
1389
- } catch (err) {
1390
- if (!cancelled) setError(err.message || 'Mermaid 图表语法错误');
1391
- }
1312
+ if (!ref.current) return;
1313
+ const source = chart.trim();
1314
+ if (!source) return;
1315
+ try {
1316
+ const { svg } = renderPele(source, {
1317
+ idPrefix: `pele-zoom-${Math.random().toString(36).slice(2, 10)}`,
1318
+ fontFamily: diagramFontFamily(),
1319
+ responsive: false
1320
+ });
1321
+ ref.current.innerHTML = svg;
1322
+ setError('');
1323
+ } catch (err) {
1324
+ setError(err.message || '图表语法错误');
1392
1325
  }
1393
- renderZoom();
1394
- return () => {
1395
- cancelled = true;
1396
- };
1397
- }, [chart, appearanceKey]);
1326
+ }, [chart]);
1398
1327
 
1399
1328
  return (
1400
1329
  <ZoomOverlay title={title || '关系草图'} caption={title} onClose={onClose}>
@@ -1418,31 +1347,25 @@ export function Mermaid({
1418
1347
  }) {
1419
1348
  const ref = React.useRef(null);
1420
1349
  const id = React.useId().replace(/:/g, '');
1421
- const appearanceKey = useAppearanceKey();
1422
1350
  const [error, setError] = React.useState('');
1423
1351
  const [zoomed, setZoomed] = React.useState(false);
1424
1352
 
1425
1353
  React.useEffect(() => {
1426
- let cancelled = false;
1427
- async function renderChart() {
1428
- if (!ref.current || !chart.trim()) return;
1429
- try {
1430
- configureMermaid();
1431
- const renderId = `mermaid-${id}-${appearanceKey.replace(/[^a-z0-9]/gi, '')}`;
1432
- const { svg } = await mermaid.render(renderId, chart.trim());
1433
- if (!cancelled && ref.current) {
1434
- ref.current.innerHTML = svg;
1435
- setError('');
1436
- }
1437
- } catch (err) {
1438
- if (!cancelled) setError(err.message || 'Mermaid 图表语法错误');
1439
- }
1354
+ if (!ref.current) return;
1355
+ const source = chart.trim();
1356
+ if (!source) return;
1357
+ try {
1358
+ const { svg } = renderPele(source, {
1359
+ idPrefix: `pele-${id}`,
1360
+ fontFamily: diagramFontFamily(),
1361
+ responsive: false
1362
+ });
1363
+ ref.current.innerHTML = svg;
1364
+ setError('');
1365
+ } catch (err) {
1366
+ setError(err.message || '图表语法错误');
1440
1367
  }
1441
- renderChart();
1442
- return () => {
1443
- cancelled = true;
1444
- };
1445
- }, [chart, id, appearanceKey]);
1368
+ }, [chart, id]);
1446
1369
 
1447
1370
  const canZoom = Boolean(chart.trim()) && !error;
1448
1371
  const openZoom = () => {
@@ -1463,7 +1386,7 @@ export function Mermaid({
1463
1386
  <div className="semantic-widget-head">
1464
1387
  <span>{title}</span>
1465
1388
  <div className="mermaid-tools">
1466
- <code>MERMAID</code>
1389
+ <code>PELE</code>
1467
1390
  <button
1468
1391
  type="button"
1469
1392
  onClick={openZoom}
@@ -902,10 +902,11 @@ export function countBySeverity(diagnostics) {
902
902
  /**
903
903
  * Optional renderers a document actually instantiates.
904
904
  *
905
- * Mermaid and KaTeX (plus the ~1.4 MB of woff2 fonts its stylesheet inlines) are
906
- * heavy enough that bundling them into a page which never renders a diagram or a
907
- * formula dominates both build time and output size. The build reads these flags
908
- * and swaps unused renderers for stubs.
905
+ * KaTeX (plus the ~1.4 MB of woff2 fonts its stylesheet inlines) is heavy
906
+ * enough that bundling it into a page which never renders a formula dominates
907
+ * both build time and output size; Pele, the renderer behind <Mermaid>, is
908
+ * smaller but still worth dropping from a page with no diagram. The build reads
909
+ * these flags and swaps unused renderers for stubs.
909
910
  *
910
911
  * Detection runs on the masked source, so `<Math>` inside a fenced block or an
911
912
  * inline code span does not count as usage.
@@ -917,7 +918,7 @@ export function detectFeatures(source) {
917
918
  }
918
919
  return {
919
920
  math: used.has('Math') || used.has('MathBlock'),
920
- mermaid: used.has('Mermaid')
921
+ pele: used.has('Mermaid')
921
922
  };
922
923
  }
923
924
 
@@ -3845,14 +3845,14 @@ html[data-carrier='scroll'] #root {
3845
3845
  .image-zoom-stage.is-dragging .image-zoom-target { transition: none; }
3846
3846
 
3847
3847
  /* A diagram keeps its natural aspect inside the viewer and paints on the
3848
- Mermaid canvas tone, so labels stay legible over the dark scrim. */
3848
+ diagram canvas tone, so labels stay legible over the dark scrim. */
3849
3849
  .mermaid-zoom-canvas svg {
3850
3850
  display: block;
3851
3851
  width: min(94vw, 1800px);
3852
3852
  height: auto;
3853
3853
  max-height: 84vh;
3854
3854
  border-radius: var(--radius-3);
3855
- background: var(--mermaid-canvas);
3855
+ background: var(--pele-bg);
3856
3856
  box-shadow: var(--shadow-modal);
3857
3857
  }
3858
3858
 
@@ -4122,7 +4122,7 @@ a.reference-title:hover { color: var(--text-accent); }
4122
4122
  animation: ca-pop 520ms var(--ease-out) backwards;
4123
4123
  }
4124
4124
 
4125
- /* A rendered diagram fades in once Mermaid inserts it. */
4125
+ /* A rendered diagram fades in once Pele inserts it. */
4126
4126
  .mermaid-canvas svg {
4127
4127
  animation: ca-fade calc(var(--motion-base) + 120ms) var(--ease-standard) backwards;
4128
4128
  }
@@ -61,7 +61,7 @@
61
61
  box-shadow: var(--shadow-sm);
62
62
  }
63
63
 
64
- /* Mermaid / RelationMap inside the explorer grid carry their own chassis rule. */
64
+ /* Mermaid (Pele) / RelationMap inside the explorer grid carry their own chassis rule. */
65
65
  [data-style='shadcn'] .draft-board .semantic-grid > .semantic-mermaid,
66
66
  [data-style='shadcn'] .draft-board .semantic-grid > .semantic-relation-map {
67
67
  margin: 0;
@@ -94,12 +94,6 @@
94
94
  --explorer-grid:
95
95
  linear-gradient(rgba(224, 164, 88, 0.025) 1px, transparent 1px),
96
96
  linear-gradient(90deg, rgba(224, 164, 88, 0.025) 1px, transparent 1px);
97
-
98
- --mermaid-node-bg: #332412;
99
- --mermaid-node-text: #f6efe3;
100
- --mermaid-node-border: #e0a458;
101
- --mermaid-line: #9d9078;
102
- --mermaid-canvas: #1c1812;
103
97
  }
104
98
 
105
99
  [data-skin="ember"][data-theme="light"] {
@@ -185,12 +179,6 @@
185
179
  --explorer-grid:
186
180
  linear-gradient(rgba(154, 90, 32, 0.04) 1px, transparent 1px),
187
181
  linear-gradient(90deg, rgba(154, 90, 32, 0.04) 1px, transparent 1px);
188
-
189
- --mermaid-node-bg: #f0e3cb;
190
- --mermaid-node-text: #2e2519;
191
- --mermaid-node-border: #a5622a;
192
- --mermaid-line: #8a7c65;
193
- --mermaid-canvas: #fdfaf3;
194
182
  }
195
183
 
196
184
  /* --------------------------------------------------------------------------
@@ -281,12 +269,6 @@
281
269
  --explorer-grid:
282
270
  linear-gradient(rgba(16, 185, 129, 0.03) 1px, transparent 1px),
283
271
  linear-gradient(90deg, rgba(16, 185, 129, 0.03) 1px, transparent 1px);
284
-
285
- --mermaid-node-bg: #173a2e;
286
- --mermaid-node-text: #eef7f0;
287
- --mermaid-node-border: #34d399;
288
- --mermaid-line: #86a290;
289
- --mermaid-canvas: #0f1813;
290
272
  }
291
273
 
292
274
  [data-skin="verdant"][data-theme="light"] {
@@ -372,12 +354,6 @@
372
354
  --explorer-grid:
373
355
  linear-gradient(rgba(5, 150, 105, 0.04) 1px, transparent 1px),
374
356
  linear-gradient(90deg, rgba(5, 150, 105, 0.04) 1px, transparent 1px);
375
-
376
- --mermaid-node-bg: #d6efe1;
377
- --mermaid-node-text: #12261a;
378
- --mermaid-node-border: #047857;
379
- --mermaid-line: #67876f;
380
- --mermaid-canvas: #fbfdfa;
381
357
  }
382
358
 
383
359
  /* --------------------------------------------------------------------------
@@ -468,12 +444,6 @@
468
444
  --explorer-grid:
469
445
  linear-gradient(rgba(236, 72, 153, 0.03) 1px, transparent 1px),
470
446
  linear-gradient(90deg, rgba(236, 72, 153, 0.03) 1px, transparent 1px);
471
-
472
- --mermaid-node-bg: #3a1f33;
473
- --mermaid-node-text: #fbeef5;
474
- --mermaid-node-border: #f472b6;
475
- --mermaid-line: #ad8a9e;
476
- --mermaid-canvas: #1e131d;
477
447
  }
478
448
 
479
449
  [data-skin="sakura"][data-theme="light"] {
@@ -559,12 +529,6 @@
559
529
  --explorer-grid:
560
530
  linear-gradient(rgba(219, 39, 119, 0.04) 1px, transparent 1px),
561
531
  linear-gradient(90deg, rgba(219, 39, 119, 0.04) 1px, transparent 1px);
562
-
563
- --mermaid-node-bg: #fadbe9;
564
- --mermaid-node-text: #3a1b2c;
565
- --mermaid-node-border: #be185d;
566
- --mermaid-line: #997488;
567
- --mermaid-canvas: #fffafc;
568
532
  }
569
533
 
570
534
  /* --------------------------------------------------------------------------
@@ -655,12 +619,6 @@
655
619
  --explorer-grid:
656
620
  linear-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px),
657
621
  linear-gradient(90deg, rgba(255, 255, 255, 0.03) 1px, transparent 1px);
658
-
659
- --mermaid-node-bg: #1f1f23;
660
- --mermaid-node-text: #f4f4f5;
661
- --mermaid-node-border: #d4d4d8;
662
- --mermaid-line: #a1a1aa;
663
- --mermaid-canvas: #141416;
664
622
  }
665
623
 
666
624
  [data-skin="noir"][data-theme="light"] {
@@ -746,10 +704,4 @@
746
704
  --explorer-grid:
747
705
  linear-gradient(rgba(24, 24, 27, 0.035) 1px, transparent 1px),
748
706
  linear-gradient(90deg, rgba(24, 24, 27, 0.035) 1px, transparent 1px);
749
-
750
- --mermaid-node-bg: #e8e8e6;
751
- --mermaid-node-text: #121214;
752
- --mermaid-node-border: #18181b;
753
- --mermaid-line: #7a7a85;
754
- --mermaid-canvas: #ffffff;
755
707
  }
@@ -121,13 +121,6 @@
121
121
  --explorer-grid:
122
122
  linear-gradient(rgba(56, 189, 248, 0.025) 1px, transparent 1px),
123
123
  linear-gradient(90deg, rgba(56, 189, 248, 0.025) 1px, transparent 1px);
124
-
125
- /* Mermaid diagram palette (read by JS at render time) */
126
- --mermaid-node-bg: #1b2540;
127
- --mermaid-node-text: #e0f2fe;
128
- --mermaid-node-border: #38bdf8;
129
- --mermaid-line: #6b7c93;
130
- --mermaid-canvas: #0e1421;
131
124
  }
132
125
 
133
126
  [data-theme="light"] {
@@ -241,13 +234,28 @@
241
234
  --explorer-grid:
242
235
  linear-gradient(rgba(37, 99, 235, 0.04) 1px, transparent 1px),
243
236
  linear-gradient(90deg, rgba(37, 99, 235, 0.04) 1px, transparent 1px);
237
+ }
238
+
239
+ /* ==========================================================================
240
+ DIAGRAM PALETTE — Pele renders <Mermaid> charts. Its colors come from the
241
+ `--pele-*` CSS variables, so the aliases below ride on the theme tokens
242
+ above: a diagram follows the active skin and mode with no JS re-render.
243
+ Pele reads them on the root <svg> (class `.pele`), which the widget's
244
+ `.mermaid-canvas` / `.mermaid-zoom-canvas` frames contain.
245
+ ========================================================================== */
244
246
 
245
- /* Mermaid diagram palette */
246
- --mermaid-node-bg: #dbeafe;
247
- --mermaid-node-text: #0f172a;
248
- --mermaid-node-border: #2563eb;
249
- --mermaid-line: #64748b;
250
- --mermaid-canvas: #ffffff;
247
+ :root {
248
+ --pele-bg: var(--bg-surface);
249
+ --pele-fg: var(--text-primary);
250
+ --pele-muted: var(--text-muted);
251
+ --pele-line: var(--text-dim);
252
+ --pele-surface: var(--bg-card-hover);
253
+ --pele-surface-alt: var(--bg-card);
254
+ --pele-border: var(--text-accent);
255
+ --pele-accent: var(--primary);
256
+ --pele-font: var(--font-sans);
257
+ --pele-font-mono: var(--font-mono);
258
+ --pele-radius: var(--radius-2);
251
259
  }
252
260
 
253
261
  /* ==========================================================================
@@ -134,72 +134,31 @@ function inlineMdxAssets() {
134
134
  };
135
135
  }
136
136
 
137
- /**
138
- * Mermaid is the single largest dependency in the bundle (~2100 modules); it is
139
- * pulled in whenever a document uses <Mermaid>. By default it is NOT bundled:
140
- * the `mermaid` import resolves to this virtual module, which lazily injects the
141
- * CDN build at render time and keeps the ~3700-module transform out of the
142
- * build. `--inline-mermaid` (or CONCEPT_ATLAS_INLINE_MERMAID=1) restores the
143
- * fully self-contained/offline bundle.
144
- */
145
- const MERMAID_CDN_DEFAULT = 'https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.min.js';
146
-
147
- function mermaidCdnModule(cdnUrl) {
148
- return `let config = null;
149
- let loader = null;
150
- function loadMermaid() {
151
- if (typeof window === 'undefined') return Promise.reject(new Error('Mermaid CDN 加载需要浏览器环境'));
152
- if (window.mermaid) return Promise.resolve(window.mermaid);
153
- if (loader) return loader;
154
- loader = new Promise((resolve, reject) => {
155
- const script = document.createElement('script');
156
- script.src = ${JSON.stringify(cdnUrl)};
157
- script.async = true;
158
- script.onload = () => (window.mermaid ? resolve(window.mermaid) : reject(new Error('Mermaid CDN 已加载,但未暴露 window.mermaid')));
159
- script.onerror = () => { loader = null; reject(new Error('无法从 CDN 加载 Mermaid;需要离线单文件请用 --inline-mermaid 重新编译。')); };
160
- document.head.appendChild(script);
161
- });
162
- return loader;
163
- }
164
- const mermaid = {
165
- initialize(value) { config = value; },
166
- async render(id, text) {
167
- const lib = await loadMermaid();
168
- lib.initialize(config || {});
169
- return lib.render(id, text);
170
- },
171
- };
172
- export default mermaid;
173
- `;
174
- }
175
-
176
137
  /**
177
138
  * Swaps optional renderers for stubs when the document never uses them.
178
139
  *
179
- * Mermaid and KaTeX are the two dependencies whose transform cost and payload
180
- * dominate a build: KaTeX alone contributes ~60 woff2 files that
181
- * vite-plugin-singlefile base64-inlines into every page (~1.4 MB), and Mermaid
182
- * is a large share of the JS bundle. A page with no <Mermaid> or <Math> should
183
- * not pay for either.
140
+ * KaTeX is the dependency whose transform cost and payload dominate a build:
141
+ * ~60 woff2 files that vite-plugin-singlefile base64-inlines into every page
142
+ * (~1.4 MB). Pele — the Mermaid-syntax renderer behind <Mermaid> — ships inline
143
+ * by default, but a page with no diagram should still not carry it. A page with
144
+ * no <Mermaid> or <Math> pays for neither.
184
145
  *
185
146
  * The CLI computes `detectFeatures(source)` and passes the result as the
186
147
  * `__ATLAS_FEATURES__` define; without it (e.g. the repository's own build) every
187
148
  * feature stays enabled and behaviour is unchanged.
188
149
  */
189
150
  const OPTIONAL_FEATURES = {
190
- mermaid: { feature: 'mermaid', stub: 'mermaid' },
151
+ pele: { feature: 'pele', stub: 'pele' },
191
152
  katex: { feature: 'math', stub: 'katex' },
192
153
  'katex/dist/katex.min.css': { feature: 'math', stub: 'katex-css' }
193
154
  };
194
155
 
195
156
  const FEATURE_STUBS = {
196
- mermaid: `const mermaid = {
197
- initialize() {},
198
- render() {
199
- throw new Error('Mermaid is not bundled in this build: the document has no <Mermaid>.');
200
- },
201
- };
202
- export default mermaid;
157
+ pele: `function render() {
158
+ throw new Error('Pele is not bundled in this build: the document has no <Mermaid>.');
159
+ }
160
+ export { render };
161
+ export default { render };
203
162
  `,
204
163
  katex: `const katex = {
205
164
  renderToString() {
@@ -214,43 +173,29 @@ export default katex;
214
173
  };
215
174
 
216
175
  function optionalFeatures() {
217
- let enabled = { math: true, mermaid: true };
218
- let mermaidMode = 'inline';
219
- let mermaidCdnUrl = MERMAID_CDN_DEFAULT;
176
+ let enabled = { math: true, pele: true };
220
177
  return {
221
178
  name: 'concept-atlas-optional-features',
222
179
  enforce: 'pre',
223
180
  configResolved(config) {
224
181
  // Reset per resolution: one process may run several builds (the CLI's
225
- // batch mode) and each must not inherit the previous build's mode.
226
- enabled = { math: true, mermaid: true };
227
- mermaidMode = 'inline';
228
- mermaidCdnUrl = MERMAID_CDN_DEFAULT;
229
- const define = config.define || {};
230
- const raw = define.__ATLAS_FEATURES__;
182
+ // batch mode) and each must not inherit the previous build's flags.
183
+ enabled = { math: true, pele: true };
184
+ const raw = (config.define || {}).__ATLAS_FEATURES__;
231
185
  if (typeof raw === 'string') {
232
186
  try {
233
- enabled = { math: true, mermaid: true, ...JSON.parse(raw) };
187
+ enabled = { math: true, pele: true, ...JSON.parse(raw) };
234
188
  } catch {
235
- enabled = { math: true, mermaid: true };
189
+ enabled = { math: true, pele: true };
236
190
  }
237
191
  }
238
- const mode = define.__ATLAS_MERMAID_MODE__;
239
- if (mode === 'cdn' || mode === '"cdn"') mermaidMode = 'cdn';
240
- const url = define.__ATLAS_MERMAID_CDN_URL__;
241
- if (typeof url === 'string') mermaidCdnUrl = url.replace(/^"([\s\S]*)"$/, '$1');
242
192
  },
243
193
  resolveId(source) {
244
- if (source === 'mermaid') {
245
- if (enabled.mermaid === false) return '\0atlas-stub:mermaid';
246
- return mermaidMode === 'cdn' ? '\0atlas-mermaid-cdn' : null;
247
- }
248
194
  const entry = OPTIONAL_FEATURES[source];
249
195
  if (!entry || enabled[entry.feature] !== false) return null;
250
196
  return `\0atlas-stub:${entry.stub}`;
251
197
  },
252
198
  load(id) {
253
- if (id === '\0atlas-mermaid-cdn') return mermaidCdnModule(mermaidCdnUrl);
254
199
  if (!id.startsWith('\0atlas-stub:')) return null;
255
200
  const stub = id.slice('\0atlas-stub:'.length);
256
201
  return Object.hasOwn(FEATURE_STUBS, stub) ? FEATURE_STUBS[stub] : null;