concept-atlas-dense-explain 4.0.0 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "concept-atlas-dense-explain",
3
- "version": "4.0.0",
3
+ "version": "4.1.0",
4
4
  "description": "Portable dense-explanation skill and MDX concept atlas template",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: concept-atlas-dense-explain
3
- description: Turn a topic or an existing document into an interactive Concept Atlas explainer. Generate AI-editable MDX with the concept-atlas-dense-explain CLI, validate its structure, and compile standalone HTML with concept nodes, relation graphs, math (KaTeX), charts, figures, citations, and reading aids. Use when a technical explanation, concept map, layered knowledge page, dense explainer, or interactive teaching page is requested.
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 from the bundled reference before authoring.** The only reference you need is the guide that ships with this skill:
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).
@@ -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 families
45
+ ## Component and prop reference
48
46
 
49
- - Node semantics: `Overview`, `Definition`, `Mechanism`, `Implementation`, `CodeBlock`, `Boundary`, `Example`, `Counterexample`, `Prerequisite`, `Input`, `Output`, `Glossary`
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,21 +54,14 @@ 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
- - **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.
66
- - **Chart**: `type` is `bar` | `line` | `pie`; use `data` for bar/pie and `labels` + `series={[{name, values}]}` for line. Charts follow theme colors.
67
- - **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.
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 these `error`s before building: `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`. Warnings worth fixing: `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`; `NO_ROOT_LEVEL`, `MULTIPLE_ROOT_LEVEL`, `MECHANISM_KIND_UNVERIFIED` and `FAILURE_KIND_UNSTRUCTURED` are warnings that `--strict` promotes to errors.
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
 
@@ -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.
@@ -2,7 +2,7 @@ import React from 'react';
2
2
  import { createPortal } from 'react-dom';
3
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';
@@ -1123,7 +1123,7 @@ function ReadingProgress() {
1123
1123
  );
1124
1124
  }
1125
1125
 
1126
- export function ScrollToc({ items = [], activeId = null, title = '目录' }) {
1126
+ export function ScrollToc({ items = [], activeId = null, title = '目录', onNavigate }) {
1127
1127
  if (items.length < 2) return null;
1128
1128
  return (
1129
1129
  <nav className="scroll-toc" aria-label="目录">
@@ -1131,7 +1131,9 @@ export function ScrollToc({ items = [], activeId = null, title = '目录' }) {
1131
1131
  <ol className="scroll-toc-list">
1132
1132
  {items.map(item => (
1133
1133
  <li key={item.id} className={item.id === activeId ? 'active' : undefined}>
1134
- <a href={`#${item.id}`}>{item.title}</a>
1134
+ <a href={`#${item.id}`} onClick={onNavigate}>
1135
+ {item.title}
1136
+ </a>
1135
1137
  </li>
1136
1138
  ))}
1137
1139
  </ol>
@@ -1196,6 +1198,64 @@ export function ScrollDocument({
1196
1198
 
1197
1199
  const showToc = toc && items.length >= 2;
1198
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
+
1199
1259
  return (
1200
1260
  <article
1201
1261
  className={`continuous-document continuous-spacing-${safeSpacing}${showToc ? ' has-toc' : ''}`}
@@ -1204,7 +1264,42 @@ export function ScrollDocument({
1204
1264
  >
1205
1265
  {progress && <ReadingProgress />}
1206
1266
  <ScrollOutlineContext.Provider value={outline}>
1207
- {showToc && <ScrollToc items={items} activeId={activeId} />}
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
+ )}
1208
1303
  <div className="continuous-content">{children}</div>
1209
1304
  </ScrollOutlineContext.Provider>
1210
1305
  </article>
@@ -3170,7 +3170,11 @@ html[data-carrier='scroll'] #root {
3170
3170
  }
3171
3171
 
3172
3172
  .continuous-document {
3173
- width: min(1120px, 100%);
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
- max-width: 76ch;
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 (sticky sidebar) ---- */
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
- display: none;
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
- @media (min-width: 1080px) {
3550
- .continuous-document.has-toc {
3551
- display: grid;
3552
- grid-template-columns: 208px minmax(0, 1fr);
3553
- column-gap: 44px;
3554
- align-items: start;
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
- .continuous-document.has-toc > .scroll-toc {
3558
- position: sticky;
3559
- top: 24px;
3560
- display: block;
3561
- grid-column: 1;
3562
- align-self: start;
3563
- max-height: calc(100vh - 48px);
3564
- overflow-y: auto;
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
- .continuous-document.has-toc > .continuous-content {
3569
- grid-column: 2;
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 {