concept-atlas-dense-explain 3.0.2 → 4.1.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 +7 -7
- package/bin/cli.mjs +7 -17
- package/package.json +2 -2
- package/packaged-skill/SKILL.md +11 -26
- package/packaged-skill/references/components.md +26 -0
- package/packaged-skill/references/diagnostics.md +15 -0
- package/template/src/components/MDXComponents.jsx +135 -117
- package/template/src/model/validate-content.js +6 -5
- package/template/src/styles/core.css +115 -32
- package/template/src/styles/packs/shadcn.css +1 -1
- package/template/src/styles/skins.css +0 -48
- package/template/src/styles/tokens.css +21 -13
- package/template/vite.config.js +17 -72
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
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
`--skin`, `--default-mode` and `--style`; readers can still switch in
|
|
38
|
-
Local figures link by default (small HTML, ship `assets/` beside the
|
|
39
|
-
`--inline-assets` bakes them in as base64 for a self-contained file,
|
|
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] [--
|
|
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
|
|
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
|
-
/**
|
|
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.
|
|
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
|
|
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 (
|
|
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
|
+
"version": "4.1.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
|
-
"
|
|
24
|
+
"pele": "^1.6.0",
|
|
25
25
|
"react": "^18.3.1",
|
|
26
26
|
"react-dom": "^18.3.1",
|
|
27
27
|
"vite": "^5.4.14",
|
package/packaged-skill/SKILL.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: concept-atlas-dense-explain
|
|
3
|
-
description: Turn a topic or
|
|
3
|
+
description: Turn a topic or existing document into an interactive Concept Atlas explainer — AI-editable MDX compiled to standalone HTML with concept nodes, relation graphs, math, charts, figures, citations, and reading aids. Use for technical explanations, concept maps, layered knowledge pages, dense explainers, or interactive teaching pages; also 概念图 / 知识地图 / 分层讲解.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# Concept Atlas Dense Explain
|
|
@@ -20,9 +20,7 @@ This is the only runner — there is nothing to look for. Do not search for a lo
|
|
|
20
20
|
## Workflow
|
|
21
21
|
|
|
22
22
|
1. Choose one page shell: `atlas` (concept graph with node navigation) or `scroll` (continuous document). Recommend `atlas` when the reader drills into concepts or follows relations, `scroll` for linear argument, tutorials, and reports. The library is shared. If an `.mdx` already exists, detect its shell and work with it.
|
|
23
|
-
2. **Learn the components
|
|
24
|
-
- `references/atlas-guide.mdx` (atlas) or `references/scroll-guide.mdx` (scroll)
|
|
25
|
-
It is real, compilable MDX showing that shell's components and their exact props; search it for a component name instead of guessing, and do not look for component documentation anywhere else. Do not run `guide` for this.
|
|
23
|
+
2. **Learn the components before authoring.** `references/components.md` is the catalogue — search it by component name for props and shapes rather than guessing. `references/atlas-guide.mdx` (atlas) or `references/scroll-guide.mdx` (scroll) is real, compilable MDX showing how that shell's components compose into a page. Do not look for component documentation anywhere else, and do not run `guide` for this.
|
|
26
24
|
Run `npx concept-atlas-dense-explain guide --mode <mode> -o <file>` only when you specifically need a project-local copy to compile beside the page, and delete that copy when done.
|
|
27
25
|
3. Start from a skeleton when useful: `npx concept-atlas-dense-explain create <file>.mdx --mode atlas|scroll` (`--mode` defaults to `scroll`). `create` and `guide` overwrite their output, so never point them at a file you want to keep.
|
|
28
26
|
4. Write the semantic MDX into the user's `.mdx` file (see Authoring rules).
|
|
@@ -32,9 +30,9 @@ This is the only runner — there is nothing to look for. Do not search for a lo
|
|
|
32
30
|
npx concept-atlas-dense-explain validate <file>.mdx --json
|
|
33
31
|
```
|
|
34
32
|
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>]
|
|
33
|
+
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
34
|
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
|
|
35
|
+
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
36
|
9. Report the shell, output path, validation result (errors/warnings), and limitations. Do not claim interactions you did not verify.
|
|
39
37
|
|
|
40
38
|
## Carriers
|
|
@@ -44,15 +42,9 @@ This is the only runner — there is nothing to look for. Do not search for a lo
|
|
|
44
42
|
- The browser tab comes from the shell, not the build flags: `ExplainPage title` (atlas) or `ScrollHeader title` (scroll) becomes the `<title>`, so give it a real, specific name — never a placeholder like "主题名称". Every page uses a fixed 📃 favicon.
|
|
45
43
|
- Never make one MDX file both shells. When switching shells, convert only the outer structure.
|
|
46
44
|
|
|
47
|
-
## Component
|
|
45
|
+
## Component and prop reference
|
|
48
46
|
|
|
49
|
-
|
|
50
|
-
- Argument and evidence: `Evidence`, `Invariant`, `FailureMode`, `Tradeoff`, `Checklist`, `LearningObjectives`, `KeyQuestion`
|
|
51
|
-
- Learning loop and provenance: `WorkedExample` + `Step`, `Quiz`, `KeyTakeaways`, `Source`, `Confidence`, `LastReviewed`, `Term`
|
|
52
|
-
- Information models: `Flow`, `Timeline`, `Compare`, `DecisionMatrix`, `FrameworkModel`, `MatrixModel`, `FormulaModel`, `PyramidModel`, `FunnelModel`
|
|
53
|
-
- Data and behaviour: `DataTable`, `Metric`, `PropertyList`, `TreeView`, `StateMachine`, `DecisionTree`, `FeedbackLoop`, `CodeDiff`
|
|
54
|
-
- Reading and layout: `Insight`, `Callout`, `Details`, `Quote`, `NoteGrid`, `Tabs`, `Columns`, `Stack`, `Grid`, `Split`, `ScrollGrid`, `ScrollPair`, `ScrollToc`
|
|
55
|
-
- Graphics and extensions: `Mermaid`, `RelationMap`, `RelationPath`, `Math`, `MathBlock`, `Chart`, `CodeTabs`, `AnnotatedCode`, `Figure` (alias `Image`), `FigureRef`, `Cite`, `References`
|
|
47
|
+
The component catalogue, every prop shape, and the syntax traps are in `references/components.md`. Read it before authoring, and search it by component name whenever a tag is new to this page — prop names and shapes are not guessable. Charts, the learning loop, provenance, data/behaviour and structure components are documented there in full; only the rules that must hold on every page are repeated below.
|
|
56
48
|
|
|
57
49
|
## Authoring rules
|
|
58
50
|
|
|
@@ -62,28 +54,21 @@ This is the only runner — there is nothing to look for. Do not search for a lo
|
|
|
62
54
|
- Array props are arrays of objects: `Flow steps={[{title, description}]}`, `Timeline events={[{label, content}]}`, `MatrixModel cells={[{title, description, tone}]}`, `DecisionMatrix headers={[...]} rows={[[...]]}`, `Chart data={[{label, value}]}`, `References items={[{id, authors, year, title, url, source}]}`. The validator warns (`PROP_EXPECTS_ARRAY`) when an array prop gets a string or non-array.
|
|
63
55
|
- `Relation type` must be one of `prerequisite`, `causes`, `produces`, `uses`, `implements`, `contrasts`, `depends-on`, `exception-of`, `precedes`, and each `Relation` needs a `label`. Parent/child hierarchy is implicit (via `parent` and `Children`/`ConceptRef`) — do not express it with a `Relation`.
|
|
64
56
|
- **Math**: MDX parses `{ ... }` in children as expressions, so pass LaTeX with braces or backslashes through `formula`: `<Math formula="r_{\text{ann}} = (1 + r)^{12} - 1" />`, `<MathBlock formula="I(x) = -\log_2 p(x)" variables={[{symbol, description}]} />`. Brace-free children such as `<Math>\log_2 N</Math>` are fine. The validator warns (`MATH_CHILDREN_BRACES`).
|
|
65
|
-
- **
|
|
66
|
-
- **
|
|
67
|
-
- **
|
|
68
|
-
- **Provenance**: `Source kind="spec|rfc|implementation|experiment|experience|reference" label href` marks one claim's origin inline (`reference` is the default); `Confidence level="high|medium|low" basis` wraps a claim with how strongly it is established; `Term name` (or children as the definition) gives an inline hover definition.
|
|
69
|
-
- **Data and behaviour**: `DataTable headers={[...]} rows={[[...]]}` is the neutral table (no comparative stance). `Metric label value unit delta trend note` is one headline number — compose several with `Grid`/`ScrollGrid`. `StateMachine states={[{id,label,terminal}]} transitions={[{from,to,event,guard}]}` expresses cycles and guards. `DecisionTree branches={[{condition,outcome,tone,branches}]}` nests branches. `FeedbackLoop type="reinforcing|balancing" nodes={[{label,description}]}` closes a loop. `CodeDiff before after language` shows a change.
|
|
70
|
-
- **Structure and code extensions**: `Quote author source href` attributes a quotation. `Checklist title items={[{text,status:'pass'|'fail'|'unknown'|'todo',note}]}` is a verification list. `PropertyList title items={[{name,value,note}]}` is a name/value spec ledger. `TreeView title items={[{label,description,children:[…]}]}` nests a hierarchy. `CodeTabs items={[{label,language,code}]} title caption lineNumbers` gives one collapsible listing per variant. `AnnotatedCode code language title notes={[{line,text}]}` numbers a listing and calls out specific lines. `LastReviewed date by note` is a review stamp.
|
|
71
|
-
- **Figure**: a relative `src` (`./assets/diagram.png`) stays a relative link by default; compile with `--inline-assets` to bake every local image in as base64, or set `inline={true}` / `inline={false}` on one figure to override (precedence: per-figure prop > global flag > link). `http(s)` URLs stay links and warn (`ASSET_REMOTE`). Always set `alt`; a missing relative file warns (`ASSET_MISSING`) and shows a placeholder. Readers can click a figure to open it full-screen (zoom, drag, `Esc`) — mention it for diagram-heavy pages.
|
|
72
|
-
- **Figure numbering**: give a figure an `id` and reference it with `<FigureRef id="..." />` to render "图 N". Numbering follows document order (per node in `atlas`, whole document in `scroll`) and reflows automatically, so never hand-write "图 1"; an explicit `label` still wins. A ref with no matching `id` warns (`FIGURE_REF_UNRESOLVED`).
|
|
73
|
-
- **Figure size & cost**: linking keeps the HTML small but requires the output to sit beside the MDX's `assets/` (the CLI warns when `-o` points elsewhere). Inlining is what makes a screenshot-heavy page large (a page with no heavy renderers otherwise lands near 250KB), and an inlined asset over 512KB warns (`ASSET_LARGE`). Decide the trade-off with the user instead of choosing silently.
|
|
74
|
-
- **Cite/References**: `<Cite id="..." />` renders `[n]` from the matching item's position in `<References items={...} />`. In `scroll`, `References` can sit anywhere. In `atlas`, keep the cites and the `References` block in the same node, because node content only renders when that node is open.
|
|
57
|
+
- **Code**: pass code as a string via `code` (or as children) wrapped in a template literal, so MDX does not read it as expressions: `<CodeBlock language="bash" lineNumbers>{`npm run validate`}</CodeBlock>`. Badges, captions and wrapping are documented in `references/components.md`.
|
|
58
|
+
- **Figures**: always set `alt`; number with an `id` plus `<FigureRef>`, never hand-write "图 N"; relative links versus `--inline-assets` is a size trade-off — decide it with the user instead of choosing silently.
|
|
59
|
+
- **Cite/References**: `<Cite id="..." />` renders `[n]` from the matching item's position in `<References items={...} />`. In `atlas`, keep the cites and the `References` block in the same node, because node content only renders when that node is open.
|
|
75
60
|
- Continuous reading is configured on the shell, not with manual CSS: `spacing="compact|comfortable|airy"` for rhythm, `fontSize="compact|normal|large|xlarge"` (or numeric `scale`/`lineHeight`) for text size.
|
|
76
61
|
|
|
77
62
|
## Validation diagnostics
|
|
78
63
|
|
|
79
|
-
`validate` and the build print `CODE line:column message`. Fix
|
|
64
|
+
`validate` and the build print `CODE line:column message`. Fix every `error` before building; `references/diagnostics.md` lists the codes you may meet and separates errors from warnings. `NO_ROOT_LEVEL`, `MULTIPLE_ROOT_LEVEL`, `MECHANISM_KIND_UNVERIFIED` and `FAILURE_KIND_UNSTRUCTURED` are warnings that `--strict` promotes to errors.
|
|
80
65
|
|
|
81
66
|
## Before you report
|
|
82
67
|
|
|
83
68
|
- All `error` diagnostics resolved (or `--no-validate` explicitly justified).
|
|
84
69
|
- All `ConceptRef`, `Relation` endpoints, and `ConceptGraph root` point at existing node ids.
|
|
85
70
|
- Every node has `title` + `summary`; every `Relation` has a `label`.
|
|
86
|
-
-
|
|
71
|
+
- Pages with `<Mermaid>` are already fully offline: Pele ships inline, so you never need a CDN flag.
|
|
87
72
|
- The HTML file exists at the reported path.
|
|
88
73
|
|
|
89
74
|
If `npx` cannot reach the registry, report the blocker. Never copy implementation files into the skill directory.
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Component and prop reference
|
|
2
|
+
|
|
3
|
+
Search this file by component name before writing a tag the page has not used yet. Props are shown in their real shapes; anything not listed here does not exist. The rules that hold for every page — semantic MDX, `kind` contracts, relation types, array-prop shape, math braces, figure numbering, cite scoping — are in `SKILL.md`; this file adds the per-component detail.
|
|
4
|
+
|
|
5
|
+
## Families
|
|
6
|
+
|
|
7
|
+
- Node semantics: `Overview`, `Definition`, `Mechanism`, `Implementation`, `CodeBlock`, `Boundary`, `Example`, `Counterexample`, `Prerequisite`, `Input`, `Output`, `Glossary`
|
|
8
|
+
- Argument and evidence: `Evidence`, `Invariant`, `FailureMode`, `Tradeoff`, `Checklist`, `LearningObjectives`, `KeyQuestion`
|
|
9
|
+
- Learning loop and provenance: `WorkedExample` + `Step`, `Quiz`, `KeyTakeaways`, `Source`, `Confidence`, `LastReviewed`, `Term`
|
|
10
|
+
- Information models: `Flow`, `Timeline`, `Compare`, `DecisionMatrix`, `FrameworkModel`, `MatrixModel`, `FormulaModel`, `PyramidModel`, `FunnelModel`
|
|
11
|
+
- Data and behaviour: `DataTable`, `Metric`, `PropertyList`, `TreeView`, `StateMachine`, `DecisionTree`, `FeedbackLoop`, `CodeDiff`
|
|
12
|
+
- Reading and layout: `Insight`, `Callout`, `Details`, `Quote`, `NoteGrid`, `Tabs`, `Columns`, `Stack`, `Grid`, `Split`, `ScrollGrid`, `ScrollPair`, `ScrollToc`
|
|
13
|
+
- Graphics and extensions: `Mermaid`, `RelationMap`, `RelationPath`, `Math`, `MathBlock`, `Chart`, `CodeTabs`, `AnnotatedCode`, `Figure` (alias `Image`), `FigureRef`, `Cite`, `References`
|
|
14
|
+
|
|
15
|
+
## Props and usage
|
|
16
|
+
|
|
17
|
+
- **CodeBlock**: a general code block usable anywhere; `Implementation` is the node-bound variant. Pass the code as a string via `code` (or as children) wrapped in a template literal so MDX does not read it as expressions: `<CodeBlock language="bash" title="..." lineNumbers>{`npm run validate`}</CodeBlock>`. `language` adds the badge, `title`/`caption` add labels, `lineNumbers` and `wrap` are booleans.
|
|
18
|
+
- **Chart**: `type` is `bar` | `line` | `pie`; use `data` for bar/pie and `labels` + `series={[{name, values}]}` for line. Charts follow theme colors.
|
|
19
|
+
- **Learning loop**: `WorkedExample` holds `Step` children; give each step a `reason` (the justification) so it teaches reasoning, not just the result. `Quiz question answer` reveals the answer on click with children as the explanation. `KeyTakeaways items={[...]}` closes a section.
|
|
20
|
+
- **Provenance**: `Source kind="spec|rfc|implementation|experiment|experience|reference" label href` marks one claim's origin inline (`reference` is the default); `Confidence level="high|medium|low" basis` wraps a claim with how strongly it is established; `Term name` (or children as the definition) gives an inline hover definition.
|
|
21
|
+
- **Data and behaviour**: `DataTable headers={[...]} rows={[[...]]}` is the neutral table (no comparative stance). `Metric label value unit delta trend note` is one headline number — compose several with `Grid`/`ScrollGrid`. `StateMachine states={[{id,label,terminal}]} transitions={[{from,to,event,guard}]}` expresses cycles and guards. `DecisionTree branches={[{condition,outcome,tone,branches}]}` nests branches. `FeedbackLoop type="reinforcing|balancing" nodes={[{label,description}]}` closes a loop. `CodeDiff before after language` shows a change.
|
|
22
|
+
- **Structure and code extensions**: `Quote author source href` attributes a quotation. `Checklist title items={[{text,status:'pass'|'fail'|'unknown'|'todo',note}]}` is a verification list. `PropertyList title items={[{name,value,note}]}` is a name/value spec ledger. `TreeView title items={[{label,description,children:[…]}]}` nests a hierarchy. `CodeTabs items={[{label,language,code}]} title caption lineNumbers` gives one collapsible listing per variant. `AnnotatedCode code language title notes={[{line,text}]}` numbers a listing and calls out specific lines. `LastReviewed date by note` is a review stamp.
|
|
23
|
+
- **Figure**: a relative `src` (`./assets/diagram.png`) stays a relative link by default; compile with `--inline-assets` to bake every local image in as base64, or set `inline={true}` / `inline={false}` on one figure to override (precedence: per-figure prop > global flag > link). `http(s)` URLs stay links and warn (`ASSET_REMOTE`). Always set `alt`; a missing relative file warns (`ASSET_MISSING`) and shows a placeholder. Readers can click a figure to open it full-screen (zoom, drag, `Esc`) — mention it for diagram-heavy pages.
|
|
24
|
+
- **Figure numbering**: give a figure an `id` and reference it with `<FigureRef id="..." />` to render "图 N". Numbering follows document order (per node in `atlas`, whole document in `scroll`) and reflows automatically, so never hand-write "图 1"; an explicit `label` still wins. A ref with no matching `id` warns (`FIGURE_REF_UNRESOLVED`).
|
|
25
|
+
- **Figure size & cost**: linking keeps the HTML small but requires the output to sit beside the MDX's `assets/` (the CLI warns when `-o` points elsewhere). Inlining is what makes a screenshot-heavy page large (a page with no heavy renderers otherwise lands near 250KB), and an inlined asset over 512KB warns (`ASSET_LARGE`). Decide the trade-off with the user instead of choosing silently.
|
|
26
|
+
- **Cite/References**: `<Cite id="..." />` renders `[n]` from the matching item's position in `<References items={...} />`. In `scroll`, `References` can sit anywhere. In `atlas`, keep the cites and the `References` block in the same node, because node content only renders when that node is open.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Validation diagnostics
|
|
2
|
+
|
|
3
|
+
`validate` and the build print `CODE line:column message`. The message names the offending node or prop; this file is the checklist of codes you may meet.
|
|
4
|
+
|
|
5
|
+
## Errors — fix before building
|
|
6
|
+
|
|
7
|
+
`UNKNOWN_COMPONENT`, `CARRIER_MISSING`, `CARRIER_CONFLICT`, `CARRIER_MODE_MISMATCH`, `NODE_MISSING_ID`, `DUPLICATE_NODE_ID`, `NODE_MISSING_TITLE`, `MISSING_PARENT`, `GRAPH_ROOT_UNRESOLVED`, `REF_MISSING_ID`, `REF_UNRESOLVED`, `RELATION_FROM_UNRESOLVED`, `RELATION_TO_UNRESOLVED`.
|
|
8
|
+
|
|
9
|
+
## Warnings — fix when cheap
|
|
10
|
+
|
|
11
|
+
`NODE_MISSING_SUMMARY`, `NODE_NO_CORE_CONTENT`, `UNKNOWN_LEVEL`, `UNKNOWN_KIND`, `MECHANISM_KIND_UNVERIFIED`, `FAILURE_KIND_UNSTRUCTURED`, `FAILURE_MODE_EMPTY`, `UNKNOWN_RELATION_TYPE`, `RELATION_MISSING_LABEL`, `RELATION_SELF`, `PROP_EXPECTS_ARRAY`, `MATH_CHILDREN_BRACES`, `PROSE_EXPRESSION`, `FRONTMATTER_UNSUPPORTED`, `GRAPH_MISSING_ROOT`, `FIGURE_MISSING_SRC`, `ASSET_MISSING`, `ASSET_REMOTE`, `ASSET_LARGE`, `FIGURE_REF_UNRESOLVED`, `FIGURE_REF_MISSING_ID`, `FIGURE_DUPLICATE_ID`, `REF_SELF`.
|
|
12
|
+
|
|
13
|
+
## Promoted by `--strict`
|
|
14
|
+
|
|
15
|
+
`NO_ROOT_LEVEL`, `MULTIPLE_ROOT_LEVEL`, `MECHANISM_KIND_UNVERIFIED` and `FAILURE_KIND_UNSTRUCTURED` are warnings that `--strict` turns into errors.
|
|
@@ -1,88 +1,20 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { createPortal } from 'react-dom';
|
|
3
|
-
import
|
|
3
|
+
import { render as renderPele } from 'pele';
|
|
4
4
|
import katex from 'katex';
|
|
5
|
-
import { ZoomIn } from 'lucide-react';
|
|
5
|
+
import { ZoomIn, X } from 'lucide-react';
|
|
6
6
|
import 'katex/dist/katex.min.css';
|
|
7
7
|
import { registerReferences, subscribeReferences, getReferenceIndex } from '../model/citations.js';
|
|
8
8
|
import { registerFigure, subscribeFigures, getFigureNumber } from '../model/figures.js';
|
|
9
9
|
import { useFigureScope } from './FigureScope.jsx';
|
|
10
10
|
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
//
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
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 ------------------------------------------------------------
|
|
@@ -1191,7 +1123,7 @@ function ReadingProgress() {
|
|
|
1191
1123
|
);
|
|
1192
1124
|
}
|
|
1193
1125
|
|
|
1194
|
-
export function ScrollToc({ items = [], activeId = null, title = '目录' }) {
|
|
1126
|
+
export function ScrollToc({ items = [], activeId = null, title = '目录', onNavigate }) {
|
|
1195
1127
|
if (items.length < 2) return null;
|
|
1196
1128
|
return (
|
|
1197
1129
|
<nav className="scroll-toc" aria-label="目录">
|
|
@@ -1199,7 +1131,9 @@ export function ScrollToc({ items = [], activeId = null, title = '目录' }) {
|
|
|
1199
1131
|
<ol className="scroll-toc-list">
|
|
1200
1132
|
{items.map(item => (
|
|
1201
1133
|
<li key={item.id} className={item.id === activeId ? 'active' : undefined}>
|
|
1202
|
-
<a href={`#${item.id}`}
|
|
1134
|
+
<a href={`#${item.id}`} onClick={onNavigate}>
|
|
1135
|
+
{item.title}
|
|
1136
|
+
</a>
|
|
1203
1137
|
</li>
|
|
1204
1138
|
))}
|
|
1205
1139
|
</ol>
|
|
@@ -1264,6 +1198,64 @@ export function ScrollDocument({
|
|
|
1264
1198
|
|
|
1265
1199
|
const showToc = toc && items.length >= 2;
|
|
1266
1200
|
|
|
1201
|
+
const [tocOpen, setTocOpen] = React.useState(false);
|
|
1202
|
+
const tocTriggerRef = React.useRef(null);
|
|
1203
|
+
const tocPanelRef = React.useRef(null);
|
|
1204
|
+
const closeTimer = React.useRef(0);
|
|
1205
|
+
|
|
1206
|
+
// The outline is a hover panel, not a button you click: parking the pointer on
|
|
1207
|
+
// the edge tab (or moving into the panel) keeps it open, leaving lets it fall
|
|
1208
|
+
// away. Touch and keyboard still get there through tap, focus and Escape.
|
|
1209
|
+
const cancelClose = React.useCallback(() => {
|
|
1210
|
+
window.clearTimeout(closeTimer.current);
|
|
1211
|
+
}, []);
|
|
1212
|
+
|
|
1213
|
+
const openToc = React.useCallback(() => {
|
|
1214
|
+
cancelClose();
|
|
1215
|
+
setTocOpen(true);
|
|
1216
|
+
}, [cancelClose]);
|
|
1217
|
+
|
|
1218
|
+
const scheduleClose = React.useCallback(() => {
|
|
1219
|
+
cancelClose();
|
|
1220
|
+
closeTimer.current = window.setTimeout(() => setTocOpen(false), 340);
|
|
1221
|
+
}, [cancelClose]);
|
|
1222
|
+
|
|
1223
|
+
const closeToc = React.useCallback(() => {
|
|
1224
|
+
cancelClose();
|
|
1225
|
+
setTocOpen(false);
|
|
1226
|
+
}, [cancelClose]);
|
|
1227
|
+
|
|
1228
|
+
React.useEffect(() => cancelClose, [cancelClose]);
|
|
1229
|
+
|
|
1230
|
+
// The panel stays mounted so it can slide both ways; `inert` keeps the hidden
|
|
1231
|
+
// outline out of the tab order and the accessibility tree.
|
|
1232
|
+
React.useEffect(() => {
|
|
1233
|
+
if (tocPanelRef.current) tocPanelRef.current.inert = !tocOpen;
|
|
1234
|
+
}, [tocOpen]);
|
|
1235
|
+
|
|
1236
|
+
React.useEffect(() => {
|
|
1237
|
+
if (!tocOpen) return undefined;
|
|
1238
|
+
const onKeyDown = event => {
|
|
1239
|
+
if (event.key === 'Escape') {
|
|
1240
|
+
closeToc();
|
|
1241
|
+
tocTriggerRef.current?.focus();
|
|
1242
|
+
}
|
|
1243
|
+
};
|
|
1244
|
+
// A tap outside the panel dismisses it on touch screens, where there is no
|
|
1245
|
+
// pointerleave to rely on.
|
|
1246
|
+
const onPointerDown = event => {
|
|
1247
|
+
if (tocPanelRef.current?.contains(event.target)) return;
|
|
1248
|
+
if (tocTriggerRef.current?.contains(event.target)) return;
|
|
1249
|
+
closeToc();
|
|
1250
|
+
};
|
|
1251
|
+
window.addEventListener('keydown', onKeyDown);
|
|
1252
|
+
document.addEventListener('pointerdown', onPointerDown);
|
|
1253
|
+
return () => {
|
|
1254
|
+
window.removeEventListener('keydown', onKeyDown);
|
|
1255
|
+
document.removeEventListener('pointerdown', onPointerDown);
|
|
1256
|
+
};
|
|
1257
|
+
}, [tocOpen, closeToc]);
|
|
1258
|
+
|
|
1267
1259
|
return (
|
|
1268
1260
|
<article
|
|
1269
1261
|
className={`continuous-document continuous-spacing-${safeSpacing}${showToc ? ' has-toc' : ''}`}
|
|
@@ -1272,7 +1264,42 @@ export function ScrollDocument({
|
|
|
1272
1264
|
>
|
|
1273
1265
|
{progress && <ReadingProgress />}
|
|
1274
1266
|
<ScrollOutlineContext.Provider value={outline}>
|
|
1275
|
-
{showToc &&
|
|
1267
|
+
{showToc && (
|
|
1268
|
+
<>
|
|
1269
|
+
<button
|
|
1270
|
+
ref={tocTriggerRef}
|
|
1271
|
+
type="button"
|
|
1272
|
+
className="scroll-toc-trigger"
|
|
1273
|
+
aria-expanded={tocOpen}
|
|
1274
|
+
aria-controls="scroll-toc-panel"
|
|
1275
|
+
aria-label="目录"
|
|
1276
|
+
onPointerEnter={openToc}
|
|
1277
|
+
onPointerLeave={scheduleClose}
|
|
1278
|
+
onFocus={openToc}
|
|
1279
|
+
onClick={openToc}
|
|
1280
|
+
>
|
|
1281
|
+
目录
|
|
1282
|
+
</button>
|
|
1283
|
+
<div
|
|
1284
|
+
id="scroll-toc-panel"
|
|
1285
|
+
className={`scroll-toc-panel${tocOpen ? ' is-open' : ''}`}
|
|
1286
|
+
ref={tocPanelRef}
|
|
1287
|
+
aria-hidden={!tocOpen}
|
|
1288
|
+
onPointerEnter={cancelClose}
|
|
1289
|
+
onPointerLeave={scheduleClose}
|
|
1290
|
+
>
|
|
1291
|
+
<button
|
|
1292
|
+
type="button"
|
|
1293
|
+
className="scroll-toc-close"
|
|
1294
|
+
onClick={closeToc}
|
|
1295
|
+
aria-label="关闭目录"
|
|
1296
|
+
>
|
|
1297
|
+
<X size={15} aria-hidden="true" />
|
|
1298
|
+
</button>
|
|
1299
|
+
<ScrollToc items={items} activeId={activeId} onNavigate={closeToc} />
|
|
1300
|
+
</div>
|
|
1301
|
+
</>
|
|
1302
|
+
)}
|
|
1276
1303
|
<div className="continuous-content">{children}</div>
|
|
1277
1304
|
</ScrollOutlineContext.Provider>
|
|
1278
1305
|
</article>
|
|
@@ -1374,27 +1401,24 @@ Tabs.displayName = 'Tabs';
|
|
|
1374
1401
|
*/
|
|
1375
1402
|
function MermaidZoom({ chart, title, onClose }) {
|
|
1376
1403
|
const ref = React.useRef(null);
|
|
1377
|
-
const appearanceKey = useAppearanceKey();
|
|
1378
1404
|
const [error, setError] = React.useState('');
|
|
1379
1405
|
|
|
1380
1406
|
React.useEffect(() => {
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
}
|
|
1390
|
-
|
|
1391
|
-
|
|
1407
|
+
if (!ref.current) return;
|
|
1408
|
+
const source = chart.trim();
|
|
1409
|
+
if (!source) return;
|
|
1410
|
+
try {
|
|
1411
|
+
const { svg } = renderPele(source, {
|
|
1412
|
+
idPrefix: `pele-zoom-${Math.random().toString(36).slice(2, 10)}`,
|
|
1413
|
+
fontFamily: diagramFontFamily(),
|
|
1414
|
+
responsive: false
|
|
1415
|
+
});
|
|
1416
|
+
ref.current.innerHTML = svg;
|
|
1417
|
+
setError('');
|
|
1418
|
+
} catch (err) {
|
|
1419
|
+
setError(err.message || '图表语法错误');
|
|
1392
1420
|
}
|
|
1393
|
-
|
|
1394
|
-
return () => {
|
|
1395
|
-
cancelled = true;
|
|
1396
|
-
};
|
|
1397
|
-
}, [chart, appearanceKey]);
|
|
1421
|
+
}, [chart]);
|
|
1398
1422
|
|
|
1399
1423
|
return (
|
|
1400
1424
|
<ZoomOverlay title={title || '关系草图'} caption={title} onClose={onClose}>
|
|
@@ -1418,31 +1442,25 @@ export function Mermaid({
|
|
|
1418
1442
|
}) {
|
|
1419
1443
|
const ref = React.useRef(null);
|
|
1420
1444
|
const id = React.useId().replace(/:/g, '');
|
|
1421
|
-
const appearanceKey = useAppearanceKey();
|
|
1422
1445
|
const [error, setError] = React.useState('');
|
|
1423
1446
|
const [zoomed, setZoomed] = React.useState(false);
|
|
1424
1447
|
|
|
1425
1448
|
React.useEffect(() => {
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
}
|
|
1449
|
+
if (!ref.current) return;
|
|
1450
|
+
const source = chart.trim();
|
|
1451
|
+
if (!source) return;
|
|
1452
|
+
try {
|
|
1453
|
+
const { svg } = renderPele(source, {
|
|
1454
|
+
idPrefix: `pele-${id}`,
|
|
1455
|
+
fontFamily: diagramFontFamily(),
|
|
1456
|
+
responsive: false
|
|
1457
|
+
});
|
|
1458
|
+
ref.current.innerHTML = svg;
|
|
1459
|
+
setError('');
|
|
1460
|
+
} catch (err) {
|
|
1461
|
+
setError(err.message || '图表语法错误');
|
|
1440
1462
|
}
|
|
1441
|
-
|
|
1442
|
-
return () => {
|
|
1443
|
-
cancelled = true;
|
|
1444
|
-
};
|
|
1445
|
-
}, [chart, id, appearanceKey]);
|
|
1463
|
+
}, [chart, id]);
|
|
1446
1464
|
|
|
1447
1465
|
const canZoom = Boolean(chart.trim()) && !error;
|
|
1448
1466
|
const openZoom = () => {
|
|
@@ -1463,7 +1481,7 @@ export function Mermaid({
|
|
|
1463
1481
|
<div className="semantic-widget-head">
|
|
1464
1482
|
<span>{title}</span>
|
|
1465
1483
|
<div className="mermaid-tools">
|
|
1466
|
-
<code>
|
|
1484
|
+
<code>PELE</code>
|
|
1467
1485
|
<button
|
|
1468
1486
|
type="button"
|
|
1469
1487
|
onClick={openZoom}
|
|
@@ -902,10 +902,11 @@ export function countBySeverity(diagnostics) {
|
|
|
902
902
|
/**
|
|
903
903
|
* Optional renderers a document actually instantiates.
|
|
904
904
|
*
|
|
905
|
-
*
|
|
906
|
-
*
|
|
907
|
-
*
|
|
908
|
-
*
|
|
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
|
-
|
|
921
|
+
pele: used.has('Mermaid')
|
|
921
922
|
};
|
|
922
923
|
}
|
|
923
924
|
|
|
@@ -3170,7 +3170,11 @@ html[data-carrier='scroll'] #root {
|
|
|
3170
3170
|
}
|
|
3171
3171
|
|
|
3172
3172
|
.continuous-document {
|
|
3173
|
-
|
|
3173
|
+
/* One centred column. The reading carrier used to be 1120px wide with the
|
|
3174
|
+
prose inset from it, which left the title, headings, text and wide blocks
|
|
3175
|
+
on different axes. Everything now shares this single measure, so a section
|
|
3176
|
+
rule, its heading, its paragraphs and its cards line up. */
|
|
3177
|
+
width: min(880px, 100%);
|
|
3174
3178
|
margin: 0 auto;
|
|
3175
3179
|
--scroll-block-gap: 18px;
|
|
3176
3180
|
--scroll-grid-gap: 16px;
|
|
@@ -3181,7 +3185,6 @@ html[data-carrier='scroll'] #root {
|
|
|
3181
3185
|
.continuous-spacing-airy { --scroll-block-gap: 28px; --scroll-grid-gap: 24px; }
|
|
3182
3186
|
|
|
3183
3187
|
.continuous-header {
|
|
3184
|
-
max-width: 820px;
|
|
3185
3188
|
margin: 0 0 56px;
|
|
3186
3189
|
padding: 0 0 24px;
|
|
3187
3190
|
border-bottom: 2px solid var(--primary);
|
|
@@ -3207,7 +3210,6 @@ html[data-carrier='scroll'] #root {
|
|
|
3207
3210
|
}
|
|
3208
3211
|
|
|
3209
3212
|
.continuous-header > div {
|
|
3210
|
-
max-width: 72ch;
|
|
3211
3213
|
color: var(--text-secondary);
|
|
3212
3214
|
font-size: 16px;
|
|
3213
3215
|
line-height: 1.7;
|
|
@@ -3238,8 +3240,7 @@ html[data-carrier='scroll'] #root {
|
|
|
3238
3240
|
}
|
|
3239
3241
|
|
|
3240
3242
|
.continuous-prose {
|
|
3241
|
-
|
|
3242
|
-
margin-bottom: 18px;
|
|
3243
|
+
margin: 0 0 18px;
|
|
3243
3244
|
color: var(--text-secondary);
|
|
3244
3245
|
font-size: 14px;
|
|
3245
3246
|
line-height: 1.72;
|
|
@@ -3475,7 +3476,6 @@ html[data-carrier='scroll'] #root {
|
|
|
3475
3476
|
|
|
3476
3477
|
/* Later rules intentionally override the fixed sizes above. */
|
|
3477
3478
|
.continuous-prose {
|
|
3478
|
-
max-width: 72ch;
|
|
3479
3479
|
font-size: calc(var(--reading-base) * var(--reading-scale));
|
|
3480
3480
|
line-height: var(--reading-line-height);
|
|
3481
3481
|
}
|
|
@@ -3536,38 +3536,121 @@ html[data-carrier='scroll'] #root {
|
|
|
3536
3536
|
transition: transform 80ms linear;
|
|
3537
3537
|
}
|
|
3538
3538
|
|
|
3539
|
-
/* ---- Table of contents (
|
|
3539
|
+
/* ---- Table of contents (hover panel) ----
|
|
3540
|
+
|
|
3541
|
+
The reading column stays centred at every width, so the outline no longer
|
|
3542
|
+
occupies a gutter. It lives in a slim tab pinned to the left edge: hovering
|
|
3543
|
+
(or focusing, or tapping) the tab slides the full outline out, and leaving
|
|
3544
|
+
both the tab and the panel lets it fall away. No permanent chrome, no scrim
|
|
3545
|
+
competing with the page. */
|
|
3540
3546
|
|
|
3541
3547
|
.continuous-content {
|
|
3542
3548
|
min-width: 0;
|
|
3543
3549
|
}
|
|
3544
3550
|
|
|
3545
|
-
.scroll-toc {
|
|
3546
|
-
|
|
3551
|
+
.scroll-toc-trigger {
|
|
3552
|
+
position: fixed;
|
|
3553
|
+
top: 50%;
|
|
3554
|
+
left: 0;
|
|
3555
|
+
z-index: 69;
|
|
3556
|
+
display: grid;
|
|
3557
|
+
width: 20px;
|
|
3558
|
+
height: 76px;
|
|
3559
|
+
margin-top: -38px;
|
|
3560
|
+
padding: 0;
|
|
3561
|
+
place-items: center;
|
|
3562
|
+
border: 1px solid var(--border-medium);
|
|
3563
|
+
border-left: 0;
|
|
3564
|
+
border-radius: 0 var(--radius-2) var(--radius-2) 0;
|
|
3565
|
+
background: var(--bg-surface);
|
|
3566
|
+
color: var(--text-muted);
|
|
3567
|
+
box-shadow: var(--shadow-card);
|
|
3568
|
+
font-family: var(--font-sans);
|
|
3569
|
+
font-size: 11px;
|
|
3570
|
+
font-weight: 600;
|
|
3571
|
+
letter-spacing: 0.24em;
|
|
3572
|
+
writing-mode: vertical-rl;
|
|
3573
|
+
opacity: 0.5;
|
|
3574
|
+
transition:
|
|
3575
|
+
opacity var(--motion-base) var(--ease-standard),
|
|
3576
|
+
color var(--motion-base) var(--ease-standard),
|
|
3577
|
+
transform 240ms var(--ease-out);
|
|
3547
3578
|
}
|
|
3548
3579
|
|
|
3549
|
-
|
|
3550
|
-
|
|
3551
|
-
|
|
3552
|
-
|
|
3553
|
-
|
|
3554
|
-
|
|
3555
|
-
}
|
|
3580
|
+
/* The tab is 20px wide; the hover/focus target around it is not. */
|
|
3581
|
+
.scroll-toc-trigger::before {
|
|
3582
|
+
content: '';
|
|
3583
|
+
position: absolute;
|
|
3584
|
+
inset: -30px -12px -30px -2px;
|
|
3585
|
+
}
|
|
3556
3586
|
|
|
3557
|
-
|
|
3558
|
-
|
|
3559
|
-
|
|
3560
|
-
|
|
3561
|
-
|
|
3562
|
-
|
|
3563
|
-
|
|
3564
|
-
|
|
3565
|
-
padding-right: 6px;
|
|
3566
|
-
}
|
|
3587
|
+
.scroll-toc-trigger:hover,
|
|
3588
|
+
.scroll-toc-trigger:focus-visible,
|
|
3589
|
+
.scroll-toc-trigger[aria-expanded='true'] {
|
|
3590
|
+
opacity: 1;
|
|
3591
|
+
color: var(--text-accent);
|
|
3592
|
+
border-color: var(--border-strong);
|
|
3593
|
+
transform: translateX(2px);
|
|
3594
|
+
}
|
|
3567
3595
|
|
|
3568
|
-
|
|
3569
|
-
|
|
3570
|
-
|
|
3596
|
+
.scroll-toc-panel {
|
|
3597
|
+
position: fixed;
|
|
3598
|
+
top: 0;
|
|
3599
|
+
bottom: 0;
|
|
3600
|
+
left: 0;
|
|
3601
|
+
z-index: 71;
|
|
3602
|
+
/* Keep the panel inside the page margin whenever there is one, so opening it
|
|
3603
|
+
never cuts into the reading column. */
|
|
3604
|
+
width: min(320px, max(240px, calc((100vw - 880px) / 2)));
|
|
3605
|
+
padding: 20px 20px 32px;
|
|
3606
|
+
overflow-y: auto;
|
|
3607
|
+
overscroll-behavior: contain;
|
|
3608
|
+
border-right: 1px solid var(--border-medium);
|
|
3609
|
+
background: var(--bg-surface);
|
|
3610
|
+
box-shadow: var(--shadow-card);
|
|
3611
|
+
/* Stays mounted in both directions so the outline slides out and back in
|
|
3612
|
+
instead of snapping: ease-out travel on the way in, a slower symmetric
|
|
3613
|
+
ease on the way out, and visibility held until the exit finishes. */
|
|
3614
|
+
visibility: hidden;
|
|
3615
|
+
opacity: 0;
|
|
3616
|
+
transform: translateX(-100%);
|
|
3617
|
+
transition:
|
|
3618
|
+
transform 460ms var(--ease-standard),
|
|
3619
|
+
opacity 320ms var(--ease-standard),
|
|
3620
|
+
visibility 0s linear 460ms;
|
|
3621
|
+
will-change: transform;
|
|
3622
|
+
}
|
|
3623
|
+
|
|
3624
|
+
.scroll-toc-panel.is-open {
|
|
3625
|
+
visibility: visible;
|
|
3626
|
+
opacity: 1;
|
|
3627
|
+
transform: translateX(0);
|
|
3628
|
+
transition:
|
|
3629
|
+
transform 300ms var(--ease-out),
|
|
3630
|
+
opacity 180ms var(--ease-standard),
|
|
3631
|
+
visibility 0s;
|
|
3632
|
+
}
|
|
3633
|
+
|
|
3634
|
+
.scroll-toc-panel:focus { outline: none; }
|
|
3635
|
+
|
|
3636
|
+
.scroll-toc-close {
|
|
3637
|
+
position: absolute;
|
|
3638
|
+
top: 14px;
|
|
3639
|
+
right: 14px;
|
|
3640
|
+
display: grid;
|
|
3641
|
+
width: 26px;
|
|
3642
|
+
height: 26px;
|
|
3643
|
+
place-items: center;
|
|
3644
|
+
border: 1px solid transparent;
|
|
3645
|
+
border-radius: var(--radius-2);
|
|
3646
|
+
background: transparent;
|
|
3647
|
+
color: var(--text-muted);
|
|
3648
|
+
}
|
|
3649
|
+
|
|
3650
|
+
.scroll-toc-close:hover {
|
|
3651
|
+
border-color: var(--border-subtle);
|
|
3652
|
+
background: var(--bg-card);
|
|
3653
|
+
color: var(--text-primary);
|
|
3571
3654
|
}
|
|
3572
3655
|
|
|
3573
3656
|
.scroll-toc-title {
|
|
@@ -3845,14 +3928,14 @@ html[data-carrier='scroll'] #root {
|
|
|
3845
3928
|
.image-zoom-stage.is-dragging .image-zoom-target { transition: none; }
|
|
3846
3929
|
|
|
3847
3930
|
/* A diagram keeps its natural aspect inside the viewer and paints on the
|
|
3848
|
-
|
|
3931
|
+
diagram canvas tone, so labels stay legible over the dark scrim. */
|
|
3849
3932
|
.mermaid-zoom-canvas svg {
|
|
3850
3933
|
display: block;
|
|
3851
3934
|
width: min(94vw, 1800px);
|
|
3852
3935
|
height: auto;
|
|
3853
3936
|
max-height: 84vh;
|
|
3854
3937
|
border-radius: var(--radius-3);
|
|
3855
|
-
background: var(--
|
|
3938
|
+
background: var(--pele-bg);
|
|
3856
3939
|
box-shadow: var(--shadow-modal);
|
|
3857
3940
|
}
|
|
3858
3941
|
|
|
@@ -4122,7 +4205,7 @@ a.reference-title:hover { color: var(--text-accent); }
|
|
|
4122
4205
|
animation: ca-pop 520ms var(--ease-out) backwards;
|
|
4123
4206
|
}
|
|
4124
4207
|
|
|
4125
|
-
/* A rendered diagram fades in once
|
|
4208
|
+
/* A rendered diagram fades in once Pele inserts it. */
|
|
4126
4209
|
.mermaid-canvas svg {
|
|
4127
4210
|
animation: ca-fade calc(var(--motion-base) + 120ms) var(--ease-standard) backwards;
|
|
4128
4211
|
}
|
|
@@ -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
|
-
|
|
246
|
-
--
|
|
247
|
-
--
|
|
248
|
-
--
|
|
249
|
-
--
|
|
250
|
-
--
|
|
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
|
/* ==========================================================================
|
package/template/vite.config.js
CHANGED
|
@@ -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
|
-
*
|
|
180
|
-
*
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
*
|
|
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
|
-
|
|
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
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
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,
|
|
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
|
|
226
|
-
enabled = { math: true,
|
|
227
|
-
|
|
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,
|
|
187
|
+
enabled = { math: true, pele: true, ...JSON.parse(raw) };
|
|
234
188
|
} catch {
|
|
235
|
-
enabled = { math: 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;
|