@bytechain.cn/colamd-themes 0.3.1 → 0.5.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.
Files changed (100) hide show
  1. package/.claude/skills/colamd-themes-preview.skill.md +333 -0
  2. package/.claude/skills/colamd-themes.skill.md +10 -0
  3. package/.dsh/skills/colamd-themes/SKILL.md +14 -0
  4. package/.github/supported-topics.yml +17 -0
  5. package/.hermes/skills/tools/colamd-themes/SKILL.md +14 -0
  6. package/.openclaw/skills/colamd-themes/SKILL.md +1 -146
  7. package/.opencode/skills/colamd-themes/SKILL.md +17 -0
  8. package/.trae/rules/colamd-themes.md +0 -145
  9. package/CHANGELOG.md +318 -240
  10. package/DSH_SUPPORT_SUMMARY.md +87 -0
  11. package/README.md +414 -384
  12. package/README_CN.md +412 -384
  13. package/RELEASENOTE.md +541 -365
  14. package/bytechain.cn-colamd-themes-0.5.0.tgz +0 -0
  15. package/dist/cli.js +272 -32
  16. package/dist/cli.js.map +1 -1
  17. package/dist/color-utils.d.ts +1 -0
  18. package/dist/color-utils.js +25 -6
  19. package/dist/color-utils.js.map +1 -1
  20. package/dist/extractors/pdf-extractor.js +6 -1
  21. package/dist/extractors/pdf-extractor.js.map +1 -1
  22. package/dist/extractors/url-extractor.d.ts +0 -4
  23. package/dist/extractors/url-extractor.js +13 -126
  24. package/dist/extractors/url-extractor.js.map +1 -1
  25. package/dist/generator.d.ts +1 -1
  26. package/dist/generator.js +32 -11
  27. package/dist/generator.js.map +1 -1
  28. package/dist/models.d.ts +5 -4
  29. package/dist/models.js +2 -3
  30. package/dist/models.js.map +1 -1
  31. package/dist/renderer.d.ts +4 -2
  32. package/dist/renderer.js +68 -25
  33. package/dist/renderer.js.map +1 -1
  34. package/dist/templates/template.css +220 -498
  35. package/dist/templates/theme-paradigm.md +530 -658
  36. package/dist/templates/theme-template.hbs +256 -370
  37. package/dist/theme-store.js +19 -3
  38. package/dist/theme-store.js.map +1 -1
  39. package/dist/utils/document-paradigm.d.ts +12 -0
  40. package/dist/utils/document-paradigm.js +109 -0
  41. package/dist/utils/document-paradigm.js.map +1 -0
  42. package/dist/validators.d.ts +4 -1
  43. package/dist/validators.js +115 -1
  44. package/dist/validators.js.map +1 -1
  45. package/mcp-server/dist/index.d.ts +13 -0
  46. package/mcp-server/dist/index.d.ts.map +1 -0
  47. package/mcp-server/dist/index.js +0 -0
  48. package/mcp-server/dist/index.js.map +1 -0
  49. package/mcp-server/package-lock.json +1759 -0
  50. package/mcp-server/package.json +24 -0
  51. package/mcp-server/src/index.ts +0 -0
  52. package/mcp-server/tsconfig.json +19 -0
  53. package/package.json +54 -36
  54. package/skills/build-skills.sh +30 -5
  55. package/skills/colamd-themes/SKILL.md +180 -148
  56. package/src/cli.ts +474 -217
  57. package/src/color-systems.ts +289 -289
  58. package/src/color-utils.ts +137 -120
  59. package/src/contrast.ts +66 -66
  60. package/src/docx-style-paradigm.ts +811 -811
  61. package/src/export-cli.ts +356 -356
  62. package/src/extractors/base.ts +8 -8
  63. package/src/extractors/docx-extractor.ts +417 -417
  64. package/src/extractors/pdf-extractor.ts +533 -527
  65. package/src/extractors/url-extractor.ts +846 -981
  66. package/src/generator.ts +197 -169
  67. package/src/index.ts +29 -29
  68. package/src/models.ts +212 -212
  69. package/src/renderer.ts +332 -288
  70. package/src/templates/template.css +220 -498
  71. package/src/templates/theme-paradigm.md +530 -658
  72. package/src/templates/theme-template.hbs +256 -370
  73. package/src/theme-store.ts +185 -170
  74. package/src/types/pdf-parse.d.ts +12 -12
  75. package/src/utils/cli-utils.ts +84 -84
  76. package/src/utils/document-paradigm.ts +118 -0
  77. package/src/validators.ts +298 -176
  78. package/themes/academic-paper-pt.css +353 -1805
  79. package/themes/academic-paper.css +350 -1099
  80. package/themes/academic-style.css +342 -2430
  81. package/themes/colly.css +256 -370
  82. package/themes/elegant.css +288 -671
  83. package/themes/forest-ink.css +240 -664
  84. package/themes/guizang.css +250 -732
  85. package/themes/hermes-security.css +279 -0
  86. package/themes/meeting-minutes.css +256 -370
  87. package/themes/pixso-design.css +278 -1261
  88. package/themes/salvator-blog.css +256 -370
  89. package/themes/shimo-theme.css +256 -0
  90. package/themes/swiss-design.css +285 -746
  91. package/themes/template.css +220 -498
  92. package/themes/trae-blue.css +280 -737
  93. package/themes/word-contract.css +249 -0
  94. package/themes-preview/demo-content.md +187 -187
  95. package/tsconfig.json +18 -18
  96. package/src/mermaid-presets.ts +0 -142
  97. package/themes/swiss-design copy.css +0 -746
  98. package/themes-preview/colly-preview.html +0 -623
  99. package/themes-preview/meeting-minutes-preview.html +0 -625
  100. package/themes-preview/salvator-blog-preview.html +0 -623
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@bytechain.cn/colamd-themes-mcp",
3
+ "version": "0.2.0",
4
+ "description": "MCP Server for ColaMD-themes — expose theme extraction, export, and validation as MCP tools",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "bin": {
8
+ "colamd-themes-mcp": "./dist/index.js"
9
+ },
10
+ "scripts": {
11
+ "build": "tsc",
12
+ "dev": "tsx src/index.ts",
13
+ "start": "node dist/index.js"
14
+ },
15
+ "dependencies": {
16
+ "@modelcontextprotocol/sdk": "^1.0.0",
17
+ "zod": "^3.23.0"
18
+ },
19
+ "devDependencies": {
20
+ "@types/node": "^22.0",
21
+ "tsx": "^4.0",
22
+ "typescript": "^5.5"
23
+ }
24
+ }
Binary file
@@ -0,0 +1,19 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "NodeNext",
5
+ "moduleResolution": "NodeNext",
6
+ "lib": ["ES2022"],
7
+ "outDir": "./dist",
8
+ "rootDir": "./src",
9
+ "strict": true,
10
+ "esModuleInterop": true,
11
+ "skipLibCheck": true,
12
+ "forceConsistentCasingInFileNames": true,
13
+ "declaration": true,
14
+ "declarationMap": true,
15
+ "sourceMap": true
16
+ },
17
+ "include": ["src/**/*"],
18
+ "exclude": ["node_modules", "dist"]
19
+ }
package/package.json CHANGED
@@ -1,36 +1,54 @@
1
- {
2
- "name": "@bytechain.cn/colamd-themes",
3
- "version": "0.3.1",
4
- "description": "Theme development & export tool for ColaMD — extract formatting, generate themes, and export Markdown to HTML/PDF",
5
- "type": "module",
6
- "main": "dist/index.js",
7
- "bin": {
8
- "colamd-themes": "./dist/cli.js",
9
- "cthemes": "./dist/cli.js"
10
- },
11
- "scripts": {
12
- "build": "tsc && node --input-type=commonjs -e \"require('fs').cpSync('src/templates','dist/templates',{recursive:true})\"",
13
- "build:skills": "bash skills/build-skills.sh",
14
- "dev": "tsx src/cli.ts",
15
- "start": "node dist/cli.js"
16
- },
17
- "dependencies": {
18
- "@bytechain.cn/colamd": "^1.5.2",
19
- "axios": "^1.7",
20
- "chalk": "^5.3",
21
- "cheerio": "^1.0",
22
- "commander": "^12.0",
23
- "css-tree": "^3.0",
24
- "handlebars": "^4.7",
25
- "mammoth": "^1.8",
26
- "ora": "^8.0",
27
- "pdf-parse": "^1.1",
28
- "puppeteer": "^24.0"
29
- },
30
- "devDependencies": {
31
- "@types/css-tree": "^2.3",
32
- "@types/node": "^22.0",
33
- "tsx": "^4.0",
34
- "typescript": "^5.5"
35
- }
36
- }
1
+ {
2
+ "name": "@bytechain.cn/colamd-themes",
3
+ "version": "0.5.0",
4
+ "description": "Theme development & export tool for ColaMD — extract formatting, generate themes, and export Markdown to HTML/PDF",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "bin": {
8
+ "colamd-themes": "./dist/cli.js",
9
+ "cthemes": "./dist/cli.js",
10
+ "colamd-themes-mcp": "./mcp-server/dist/index.js"
11
+ },
12
+ "scripts": {
13
+ "build": "tsc && node --input-type=commonjs -e \"require('fs').cpSync('src/templates','dist/templates',{recursive:true})\"",
14
+ "build:skills": "bash skills/build-skills.sh",
15
+ "dev": "tsx src/cli.ts",
16
+ "start": "node dist/cli.js",
17
+ "build:mcp": "cd mcp-server && npm run build",
18
+ "build:all": "npm run build && npm run build:mcp",
19
+ "mcp": "node mcp-server/dist/index.js"
20
+ },
21
+ "keywords": [
22
+ "dsh",
23
+ "deepseek-harness",
24
+ "colamd",
25
+ "themes",
26
+ "css",
27
+ "markdown",
28
+ "pdf",
29
+ "html",
30
+ "skill",
31
+ "ai-agent",
32
+ "agent-skill"
33
+ ],
34
+ "dependencies": {
35
+ "@bytechain.cn/colamd": "^1.5.2",
36
+ "axios": "^1.7",
37
+ "chalk": "^5.3",
38
+ "cheerio": "^1.0",
39
+ "commander": "^12.0",
40
+ "css-tree": "^3.0",
41
+ "handlebars": "^4.7",
42
+ "mammoth": "^1.8",
43
+ "ora": "^8.0",
44
+ "pdf-parse": "^1.1",
45
+ "pptxgenjs": "^4.0.1",
46
+ "puppeteer": "^24.0"
47
+ },
48
+ "devDependencies": {
49
+ "@types/css-tree": "^2.3",
50
+ "@types/node": "^22.0",
51
+ "tsx": "^4.0",
52
+ "typescript": "^5.5"
53
+ }
54
+ }
@@ -26,7 +26,7 @@ BODY=$(sed -n '/^$/,$ { /^# ColaMD/!p; }' "$SOURCE" | sed '1{/^$/d;}')
26
26
  FRONT_CLAUDE='---
27
27
  name: colamd-themes
28
28
  description: >
29
- Generate, validate, export, and manage ColaMD v3.0 paradigm CSS themes.
29
+ Generate, validate, export, and manage ColaMD 2.7.7 contract CSS themes.
30
30
  Extract formatting from URLs, DOCX, or PDF sources; export Markdown to
31
31
  standalone HTML/PDF with themes applied; batch export; manage theme
32
32
  configuration.
@@ -36,7 +36,7 @@ FRONT_OPENCODE='---
36
36
  name: colamd-themes
37
37
  version: "1.0.0"
38
38
  description: >
39
- Generate, validate, export, and manage ColaMD v3.0 paradigm CSS themes.
39
+ Generate, validate, export, and manage ColaMD 2.7.7 contract CSS themes.
40
40
  Extract from URLs/DOCX/PDF; export Markdown to HTML/PDF; batch export.
41
41
  user-invocable: true
42
42
  allowed-tools:
@@ -52,7 +52,7 @@ FRONT_OPENCLAW='---
52
52
  id: colamd-themes
53
53
  name: ColaMD Themes
54
54
  description: >
55
- Generate, validate, export, and manage ColaMD v3.0 paradigm CSS themes.
55
+ Generate, validate, export, and manage ColaMD 2.7.7 contract CSS themes.
56
56
  Extract from URLs/DOCX/PDF; export Markdown to HTML/PDF; batch export.
57
57
  version: "1.0.0"
58
58
  icon: "\U0001F3A8"
@@ -70,7 +70,7 @@ metadata:
70
70
 
71
71
  FRONT_HERMES='---
72
72
  name: colamd-themes
73
- description: "Generate, validate, export, and manage ColaMD v3.0 paradigm CSS themes."
73
+ description: "Generate, validate, export, and manage ColaMD 2.7.7 contract CSS themes."
74
74
  version: 1.0.0
75
75
  author: bytechain
76
76
  license: MIT
@@ -81,6 +81,19 @@ prerequisites:
81
81
  commands: [node, npm]
82
82
  ---'
83
83
 
84
+ FRONT_DSH='---
85
+ name: colamd-themes
86
+ version: "1.0.0"
87
+ description: >
88
+ Generate, validate, export, and manage ColaMD 2.7.7 contract CSS themes.
89
+ Extract from URLs/DOCX/PDF; export Markdown to HTML/PDF; batch export.
90
+ metadata:
91
+ dsh:
92
+ tags: [colamd, themes, css, markdown, export, pdf, html]
93
+ prerequisites:
94
+ commands: [node, npm]
95
+ ---'
96
+
84
97
  # ── Generator functions ──
85
98
 
86
99
  generate_claude() {
@@ -123,6 +136,16 @@ generate_hermes() {
123
136
  echo " → $file"
124
137
  }
125
138
 
139
+ generate_dsh() {
140
+ local dir=".dsh/skills/colamd-themes"
141
+ mkdir -p "$dir"
142
+ local file="$dir/SKILL.md"
143
+ echo "$FRONT_DSH" > "$file"
144
+ echo "" >> "$file"
145
+ echo "$BODY" >> "$file"
146
+ echo " → $file"
147
+ }
148
+
126
149
  generate_trae() {
127
150
  local dir=".trae/rules"
128
151
  mkdir -p "$dir"
@@ -148,16 +171,18 @@ case "$TARGET" in
148
171
  openclaw) generate_openclaw ;;
149
172
  hermes) generate_hermes ;;
150
173
  trae) generate_trae ;;
174
+ dsh) generate_dsh ;;
151
175
  all)
152
176
  generate_claude
153
177
  generate_opencode
154
178
  generate_openclaw
155
179
  generate_hermes
156
180
  generate_trae
181
+ generate_dsh
157
182
  ;;
158
183
  *)
159
184
  echo "Unknown agent: $TARGET" >&2
160
- echo "Usage: $0 [claude|opencode|openclaw|hermes|trae|all]" >&2
185
+ echo "Usage: $0 [claude|opencode|openclaw|hermes|trae|dsh|all]" >&2
161
186
  exit 1
162
187
  ;;
163
188
  esac
@@ -1,148 +1,180 @@
1
- # ColaMD Themes — Universal AI Agent Skill
2
-
3
- Generate, validate, export, and manage ColaMD v3.0 paradigm CSS themes. Extract formatting from URLs, DOCX, or PDF sources; export Markdown to standalone HTML/PDF with themes applied; batch export; manage theme configuration.
4
-
5
- ## Prerequisites
6
-
7
- - Node.js ≥ 18
8
- - Project root: run `npm install && npm run build` before first use
9
- - Or run directly: `npx tsx src/cli.ts <command>`
10
-
11
- ## Commands
12
-
13
- ### Theme extraction
14
-
15
- ```bash
16
- colamd-themes from-url <URL> [options]
17
- colamd-themes from-docx <file> [options]
18
- colamd-themes from-pdf <file> [options]
19
- colamd-themes extract <source> [options]
20
- ```
21
-
22
- ### Export to HTML / PDF
23
-
24
- ```bash
25
- colamd-themes export-html <input.md> -t <theme> -o <output.html>
26
- colamd-themes export-pdf <input.md> -t <theme> -o <output.pdf>
27
- colamd-themes export <inputs...> --format html|pdf -t <theme> -d <dir>
28
- ```
29
-
30
- ### Theme management
31
-
32
- ```bash
33
- colamd-themes set-theme <name> --default
34
- colamd-themes set-theme <name> --css <file>
35
- colamd-themes set-theme <name> --css <file> --default
36
- colamd-themes set-theme <name> --remove
37
- ```
38
-
39
- ### Inspection
40
-
41
- ```bash
42
- colamd-themes color-systems [-j]
43
- colamd-themes mermaid-presets [-j]
44
- colamd-themes list [-d <dir>]
45
- colamd-themes validate <file.css>
46
- ```
47
-
48
- ## Options
49
-
50
- ### Extract options
51
-
52
- | Flag | Description |
53
- |------|-------------|
54
- | `-n, --name` | Theme name |
55
- | `-o, --output` | Output CSS file path |
56
- | `-d, --themes-dir` | Themes directory (default: `themes/`) |
57
- | `-c, --color-system` | Force a color system |
58
- | `-m, --mermaid-preset` | Force a Mermaid preset (light/dark/elegant) |
59
- | `-A, --auto-match` | Auto-match color system and Mermaid preset |
60
-
61
- ### Export options
62
-
63
- | Flag | Description |
64
- |------|-------------|
65
- | `-t, --theme` | Theme: built-in name, custom name, or `.css` file path |
66
- | `-o, --output` | Output file path |
67
- | `-d, --output-dir` | Output directory for batch export |
68
- | `--format` | Batch: `html` or `pdf`; PDF: `A4`, `Letter`, `A3` |
69
-
70
- ## Theme Resolution
71
-
72
- `-t, --theme` accepts:
73
- 1. **Built-in**: `light`, `dark`, `elegant`, `newsprint`
74
- 2. **Custom registered**: name set via `set-theme --css`
75
- 3. **File path**: any `.css` file on disk
76
-
77
- Config: `~/.colamd-themes/config.json`
78
-
79
- ## Color Systems (15 schemes)
80
-
81
- | Family | Schemes |
82
- |--------|---------|
83
- | 莫兰迪 (Morandi) | misty-rose, sage-green, dusky-blue |
84
- | 马卡龙 (Macaron) | strawberry, mint, lavender |
85
- | 北欧 (Nordic) | fjord-blue, pine-green, cloud-grey |
86
- | 复古 (Vintage) | amber, burgundy, forest |
87
- | 薄荷绿 (Mint) | matcha, spearmint, seafoam |
88
-
89
- ## Mermaid Presets
90
-
91
- `light` — cool accent on light bg | `dark` — dark bg | `elegant` — warm accent on light bg
92
-
93
- ## Workflow Examples
94
-
95
- ### Create theme from source
96
-
97
- ```bash
98
- colamd-themes extract <source> --name "my-theme" --auto-match
99
- ```
100
-
101
- ### Export with theme
102
-
103
- ```bash
104
- colamd-themes export-html doc.md -t elegant -o output.html
105
- colamd-themes export-pdf doc.md -t my-brand -o output.pdf
106
- ```
107
-
108
- ### Batch export
109
-
110
- ```bash
111
- colamd-themes export docs/ --format pdf -t dark -d output/
112
- ```
113
-
114
- ### Validate theme
115
-
116
- ```bash
117
- colamd-themes validate themes/my-theme.css
118
- ```
119
-
120
- ## Rendering Pipeline
121
-
122
- Export uses Puppeteer (headless Chromium) with `@bytechain.cn/colamd/renderer`:
123
-
124
- 1. Local HTTP server serves renderer ESM bundle (avoids CORS)
125
- 2. Puppeteer navigates to server page (same-origin)
126
- 3. `createColaMDEditor({ editable: false })` initializes Milkdown editor
127
- 4. `applyTheme(name, customCSS?)` sets theme
128
- 5. `setMarkdown(content)` loads document
129
- 6. `ensureAllPluginsRendered()` waits for mermaid/KaTeX
130
- 7. `buildExportHTML()` → standalone HTML with embedded CSS
131
- 8. For PDF: `emulateMediaType('screen')` + `page.pdf()`
132
-
133
- ## v3.0 Paradigm Constraints
134
-
135
- - No bare hex colors in selectors — use `var(--seed-*)`
136
- - No bare font sizes — use `var(--font-*)`
137
- - No Mermaid SVG selectors (handled by built-in `variables.css`)
138
- - `!important` only in `@media print`
139
- - Generated CSS ≤ 300 lines
140
- - Font stacks must include CJK fallback and end with generic family
141
-
142
- ## Architecture
143
-
144
- ```
145
- Source → Extractor → ThemeStyle → Color System + Mermaid Preset + Validators → CSS
146
-
147
- Markdown → Puppeteer + ColaMD Renderer → HTML / PDF
148
- ```
1
+ # ColaMD Themes — Universal AI Agent Skill
2
+
3
+ Generate, validate, export, and manage ColaMD **2.7.7 contract** CSS themes. Extract formatting from URLs, DOCX, or PDF sources; export Markdown to standalone HTML/PDF with themes applied; batch export; manage theme configuration.
4
+
5
+ ## Prerequisites
6
+
7
+ - Node.js ≥ 18
8
+ - Project root: run `npm install && npm run build` before first use
9
+ - Or run directly: `npx tsx src/cli.ts <command>`
10
+
11
+ ## Commands
12
+
13
+ ### Theme extraction
14
+
15
+ ```bash
16
+ colamd-themes from-url <URL> [options]
17
+ colamd-themes from-docx <file> [options]
18
+ colamd-themes from-pdf <file> [options]
19
+ colamd-themes extract <source> [options]
20
+ ```
21
+
22
+ ### Export to HTML / PDF
23
+
24
+ ```bash
25
+ colamd-themes export-html <input.md> -t <theme> -o <output.html>
26
+ colamd-themes export-pdf <input.md> -t <theme> -o <output.pdf>
27
+ colamd-themes export <inputs...> --format html|pdf -t <theme> -d <dir>
28
+ ```
29
+
30
+ ### Theme management
31
+
32
+ ```bash
33
+ colamd-themes set-theme <name> --default
34
+ colamd-themes set-theme <name> --css <file>
35
+ colamd-themes set-theme <name> --css <file> --default
36
+ colamd-themes set-theme <name> --remove
37
+ ```
38
+
39
+ ### Inspection
40
+
41
+ ```bash
42
+ colamd-themes color-systems [-j]
43
+ colamd-themes list [-d <dir>]
44
+ colamd-themes validate <file.css>
45
+ ```
46
+
47
+ ## Options
48
+
49
+ ### Extract options
50
+
51
+ | Flag | Description |
52
+ |------|-------------|
53
+ | `-n, --name` | Theme name |
54
+ | `-o, --output` | Output CSS file path |
55
+ | `-d, --themes-dir` | Themes directory (default: `themes/`) |
56
+ | `-c, --color-system` | Force a color system |
57
+ | `-A, --auto-match` | Auto-match a color system from the extracted palette |
58
+
59
+ ### Export options
60
+
61
+ | Flag | Description |
62
+ |------|-------------|
63
+ | `-t, --theme` | Theme: built-in name, custom name, or `.css` file path |
64
+ | `-o, --output` | Output file path |
65
+ | `-d, --output-dir` | Output directory for batch export |
66
+ | `--format` | Batch: `html` or `pdf`; PDF: `A4`, `Letter`, `A3` |
67
+
68
+ ## Theme Resolution
69
+
70
+ `-t, --theme` accepts:
71
+ 1. **Built-in**: `light`, `dark`, `elegant`, `newsprint`
72
+ 2. **Custom registered**: name set via `set-theme --css`
73
+ 3. **File path**: any `.css` file on disk
74
+
75
+ Config: `~/.colamd-themes/config.json`
76
+
77
+ ## Color Systems (15 schemes)
78
+
79
+ | Family | Schemes |
80
+ |--------|---------|
81
+ | 莫兰迪 (Morandi) | misty-rose, sage-green, dusky-blue |
82
+ | 马卡龙 (Macaron) | strawberry, mint, lavender |
83
+ | 北欧 (Nordic) | fjord-blue, pine-green, cloud-grey |
84
+ | 复古 (Vintage) | amber, burgundy, forest |
85
+ | 薄荷绿 (Mint) | matcha, spearmint, seafoam |
86
+
87
+ ## Diagram Colors (Pele)
88
+
89
+ Mermaid 20-variable presets are gone. ColaMD 2.7.7 draws diagrams with Pele, whose SVG embeds `var(--pele-*)` and resolves them in the document. Override the 9 `--pele-*` variables on `:root` if needed; defaults derive from `--code-block-bg` / `--code-block-text` / `--link-color`.
90
+
91
+ ## Workflow Examples
92
+
93
+ ### Create theme from source
94
+
95
+ ```bash
96
+ colamd-themes extract <source> --name "my-theme" --auto-match
97
+ ```
98
+
99
+ ### Export with theme
100
+
101
+ ```bash
102
+ colamd-themes export-html doc.md -t elegant -o output.html
103
+ colamd-themes export-pdf doc.md -t my-brand -o output.pdf
104
+ ```
105
+
106
+ ### Batch export
107
+
108
+ ```bash
109
+ colamd-themes export docs/ --format pdf -t dark -d output/
110
+ ```
111
+
112
+ ### Validate theme
113
+
114
+ ```bash
115
+ colamd-themes validate themes/my-theme.css
116
+ ```
117
+
118
+ ## Rendering Pipeline
119
+
120
+ Export uses Puppeteer (headless Chromium) with `@bytechain.cn/colamd/renderer`:
121
+
122
+ 1. Local HTTP server serves renderer ESM bundle (avoids CORS)
123
+ 2. Puppeteer navigates to server page (same-origin)
124
+ 3. `createColaMDEditor({ editable: false })` initializes Milkdown editor
125
+ 4. `applyTheme(name, customCSS?)` sets theme
126
+ 5. `setMarkdown(content)` loads document
127
+ 6. `ensureAllPluginsRendered()` waits for mermaid/KaTeX
128
+ 7. `buildExportHTML()` → standalone HTML with embedded CSS
129
+ 8. For PDF: `emulateMediaType('screen')` + `page.pdf()`
130
+
131
+ ## 2.7.7 Contract Constraints
132
+
133
+ - Variables live in `:root`; anything in `body.theme-*` is ignored
134
+ - Live variables only: `--bg-color --text-color --text-secondary --text-muted --border-color --link-color --code-bg --code-block-bg --code-block-text --blockquote-border --blockquote-bg --table-header-bg --selection-bg --highlight-bg --font-body --font-mono --editor-font-size --editor-column-width` + `--pele-*`
135
+ - Dead variables are rejected: `--surface-color` `--surface-alt` `--text-dim` `--heading-color` `--accent-*` `--hr-color` `--code-color` `--code-block-color` `--table-border` `--scrollbar-thumb*` `--mermaid-*` `--radius-*` `--content-width` `--font-size-root` `--font-scale-*` `--line-height-*` `--font-heading` `--font-code` `--font-mermaid`
136
+ - Editor selectors only: `#editor .cm-content` + `.cm-md-*` (CodeMirror 6 has no `<h1>` / `<blockquote>` elements)
137
+ - No vertical padding on `.cm-md-blockquote` / `.cm-md-codeblock` (one div per line)
138
+ - No `pt` units; use `px` / `em` / `rem`
139
+ - No `!important` (except `print-color-adjust` in `@media print`)
140
+ - Export DOM styling goes on `.colamd-document` (semantic tags), not `.cm-md-*`
141
+ - Generated CSS ≤ 300 lines
142
+ - Font stacks must include CJK fallback and end with generic family
143
+
144
+ ## CSS Pitfall Quick Reference
145
+
146
+ > When adjusting themes, follow these rules strictly. Reference `themes/template.css` and the upstream examples in `ColaMD-extend/resources/templates/themes/`.
147
+
148
+ ### 1. Root Block
149
+
150
+ **Pitfall:** Declaring variables on `body.theme-custom`. **Correct:** `:root { ... }` — the editor inherits from the document root only.
151
+
152
+ ### 2. Body Text First-Line Indent
153
+
154
+ **Pitfall:** `#write p` matches nothing. **Correct:** `#editor .cm-content .cm-line { text-indent: 2em; }`, then reset `text-indent: 0` on heading / quote / code / list / rule / mermaid lines.
155
+
156
+ ### 3. Indent Exclusion
157
+
158
+ **Pitfall:** Indent leaks into quotes, code and lists because every markdown line is a `.cm-line`. **Correct:** enumerate all `.cm-md-*` line classes in the reset block (template §2.5).
159
+
160
+ ### 4. List Indentation
161
+
162
+ **Pitfall:** Assuming `ul/ol/li` elements exist. **Correct:** CodeMirror marks list depth with `.cm-md-li-0` … `.cm-md-li-6` on the line; style those classes, never `li::before`.
163
+
164
+ ### 5. Quote / Code Block Padding
165
+
166
+ **Pitfall:** Adding `padding: 12px 16px` to `.cm-md-blockquote`. **Correct:** only `padding-left` / `padding-right` — vertical padding is applied once per line.
167
+
168
+ ### 6. Pele Diagram Colors
169
+
170
+ **Pitfall:** Writing `themeVariables` or Mermaid `classDef` in the theme. **Correct:** override `--pele-*` on `:root`; the SVG reads them at render time.
171
+
172
+ ## Architecture
173
+
174
+ ```
175
+ Source → Extractor → ThemeStyle → Color System + Pele + Validators → CSS (2.7.7 contract)
176
+
177
+ Markdown → Puppeteer + ColaMD renderer → HTML / PDF
178
+ ```
179
+
180
+ > Export runs the 1.5.x Milkdown renderer library; the npm 2.x package (`@bytechain.cn/colamd@2.7.7`) is the Electron app distribution and no longer ships `dist/lib/colamd-renderer.js` — `renderer.ts` detects a 2.x install and asks for `@^1.5.2`. Generated CSS targets 2.7.7 (verified against the published 2.7.7 package), so it carries over unchanged.