@bytechain.cn/colamd-themes 0.3.2 → 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 -37
  7. package/.opencode/skills/colamd-themes/SKILL.md +17 -0
  8. package/.trae/rules/colamd-themes.md +0 -36
  9. package/CHANGELOG.md +318 -241
  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 -389
  14. package/bytechain.cn-colamd-themes-0.5.0.tgz +0 -0
  15. package/dist/cli.js +36 -55
  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 +64 -84
  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 -178
  56. package/src/cli.ts +474 -487
  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 -359
  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
package/README.md CHANGED
@@ -1,384 +1,414 @@
1
- # ColaMD Themes
2
-
3
- A theme development & export toolkit for [ColaMD](https://github.com/cola-md/cola-md) — the Agent-native Markdown editor. Extract visual formatting from web pages, Word documents, and PDFs, convert them into validated CSS theme files, and export Markdown to standalone HTML or PDF with any theme applied.
4
-
5
- ## Features
6
-
7
- ### Theme Extraction
8
-
9
- - **URL** — fetch a web page, parse its CSS rules (via `css-tree`), resolve inline styles with specificity calculation, and derive a coherent theme palette
10
- - **DOCX** — read Word document styles (H1–H6, tables, code blocks) via mammoth, map to theme variables
11
- - **PDF** — extract typography metadata from PDF text using multi-layer heuristic analysis
12
- - **Auto‑detect** — `extract` command automatically routes to the right extractor
13
-
14
- ### HTML / PDF Export
15
-
16
- - **`export-html`** — render Markdown to a standalone HTML document with theme CSS embedded, Mermaid diagrams and KaTeX math fully rendered
17
- - **`export-pdf`** — render Markdown to PDF via Puppeteer (Chromium), preserving theme colors with `@media print` fidelity
18
- - **`export`** — batch export multiple files or entire directories to HTML or PDF
19
- - Powered by `@bytechain.cn/colamd/renderer` — the same Milkdown editor engine used by ColaMD itself
20
-
21
- ### Theme Management
22
-
23
- - **`set-theme`** — configure default export theme, register custom CSS themes, switch between built-in themes
24
- - Built-in themes: `light`, `dark`, `elegant`, `newsprint`
25
- - Custom themes: any `.css` file registered by name, referenced in exports
26
-
27
- ### Validation & Color Systems
28
-
29
- - **Contrast Engine** — WCAG 2.1 relative luminance & contrast ratio calculations
30
- - **Paradigm Validator** — 15+ design constraint rules (CR, HR, SL, NT, BD, MP, FP, FS, SH) with auto-fix suggestions
31
- - **Color System Library** — 15 predefined seed palettes across 5 families (Morandi, Macaron, Nordic, Vintage, Mint)
32
- - **Mermaid Presets** — 3 presets (light/dark/elegant) with 20 core variables, auto-selected by luminance and accent warmth
33
-
34
- ### Security & Performance (v0.3.2+)
35
-
36
- - **SSRF Protection** — URL extractor validates against protocol whitelist and blocks private network access to prevent Server-Side Request Forgery attacks
37
- - **Input Validation** — CSS files validated for extension, size limit (1MB max), and content validity to prevent OOM attacks
38
- - **Async I/O** — Non-blocking file operations for improved responsiveness during batch exports
39
- - **Template Caching** — LRU-style cache (max 10 templates) with TTL expiration (30min) and mtime-based auto-invalidation for stable memory usage
40
- - **Unified Error Handling** — Structured error codes (`CLIError` + `ErrorCode`) across all commands for consistent debugging experience
41
- - **Resource Cleanup** — Explicit Puppeteer page cleanup prevents zombie processes and resource leaks
42
-
43
- ### CSS Template Engine
44
-
45
- Handlebars-powered template produces v3.0 paradigm CSS (≤300 lines):
46
-
47
- | Section | Content |
48
- |---------|---------|
49
- | 1 | Design Tokens — seed palette (11 vars), typography (4 font stacks), font sizing, radii & spacing |
50
- | 2 | Semantic Mapping — auto-derived from seed tokens via `var(--seed-*)` |
51
- | 3 | Mermaid 20 Core Variables — container, font, nodes, edges, clusters, labels, titles, person, offset |
52
- | 4 | Fine Tuning |
53
- | 5 | Selector-Level Micro Adjustments — headings, code, pre, blockquote, table, hr, responsive |
54
- | 6 | `@media print` — screen-mirror with `!important` + `print-color-adjust: exact` |
55
-
56
- ### Multi-Agent Skill
57
-
58
- Universal skill definitions for 5 AI coding agents, auto-generated from a single source:
59
-
60
- | Agent | Skill Path | Frontmatter |
61
- |-------|-----------|-------------|
62
- | **Claude Code** | `.claude/skills/colamd-themes.skill.md` | `name`, `description` |
63
- | **OpenCode** | `.opencode/skills/colamd-themes/SKILL.md` | `name`, `version`, `user-invocable`, `allowed-tools`, `hooks` |
64
- | **OpenClaw** | `.openclaw/skills/colamd-themes/SKILL.md` | `id`, `name`, `version`, `icon`, `author`, `homepage`, `metadata.openclaw.os` |
65
- | **Hermes** | `.hermes/skills/tools/colamd-themes/SKILL.md` | `name`, `version`, `author`, `license`, `metadata.hermes.tags`, `prerequisites` |
66
- | **Trae** | `.trae/rules/colamd-themes.md` | Plain Markdown (no frontmatter) |
67
-
68
- **Architecture:**
69
-
70
- ```
71
- skills/colamd-themes/SKILL.md ← Canonical source (single source of truth)
72
- │
73
- ▼
74
- skills/build-skills.sh ← Build script (bash)
75
- │
76
- ├──→ .claude/skills/colamd-themes.skill.md
77
- ├──→ .opencode/skills/colamd-themes/SKILL.md
78
- ├──→ .openclaw/skills/colamd-themes/SKILL.md
79
- ├──→ .hermes/skills/tools/colamd-themes/SKILL.md
80
- └──→ .trae/rules/colamd-themes.md
81
- ```
82
-
83
- **Regenerate all agent skills:**
84
-
85
- ```bash
86
- npm run build:skills # generate all
87
- bash skills/build-skills.sh # same thing
88
-
89
- # Or generate for a single agent:
90
- bash skills/build-skills.sh claude
91
- bash skills/build-skills.sh opencode
92
- bash skills/build-skills.sh openclaw
93
- bash skills/build-skills.sh hermes
94
- bash skills/build-skills.sh trae
95
- ```
96
-
97
- To customize: edit `skills/colamd-themes/SKILL.md`, then run `npm run build:skills`.
98
-
99
- ## Installation
100
-
101
- ```bash
102
- git clone git@github.com:byteuser1977/ColaMD-themes.git
103
- cd ColaMD-themes
104
- npm install
105
- npm run build
106
- ```
107
-
108
- For development with hot‑reload:
109
-
110
- ```bash
111
- npx tsx src/cli.ts <command>
112
- ```
113
-
114
- ## Usage
115
-
116
- The package provides two equivalent CLI commands:
117
-
118
- - **`colamd-themes`** — full command name
119
- - **`cthemes`** — short alias (recommended for frequent use)
120
-
121
- Examples below use the short alias `cthemes`, but you can substitute `colamd-themes` interchangeably.
122
-
123
- ### Extract a theme from a URL
124
-
125
- ```bash
126
- cthemes from-url "https://example.com" --name my-theme
127
- ```
128
-
129
- ### Extract from a Word document
130
-
131
- ```bash
132
- cthemes from-docx report.docx --name corporate-theme
133
- ```
134
-
135
- ### Extract from a PDF
136
-
137
- ```bash
138
- cthemes from-pdf paper.pdf --name academic-theme
139
- ```
140
-
141
- ### Auto‑detect source type
142
-
143
- ```bash
144
- cthemes extract source.docx --name auto-theme
145
- ```
146
-
147
- ### Validate a theme
148
-
149
- ```bash
150
- cthemes validate themes/my-theme.css
151
- ```
152
-
153
- ### List themes and color systems
154
-
155
- ```bash
156
- cthemes list
157
- cthemes color-systems
158
- cthemes mermaid-presets
159
- ```
160
-
161
- ### Export to HTML
162
-
163
- ```bash
164
- # Single file with a built-in theme
165
- cthemes export-html document.md -t elegant -o output.html
166
-
167
- # With a custom theme
168
- cthemes export-html document.md -t my-brand -o output.html
169
- ```
170
-
171
- ### Export to PDF
172
-
173
- ```bash
174
- # Single file
175
- cthemes export-pdf document.md -t dark -o output.pdf
176
-
177
- # With page format
178
- cthemes export-pdf document.md -t elegant --format Letter -o output.pdf
179
- ```
180
-
181
- ### Batch export
182
-
183
- ```bash
184
- # Multiple files to HTML
185
- cthemes export docs/*.md --format html -t light -d output/
186
-
187
- # Directory of Markdown files to PDF
188
- cthemes export docs/ --format pdf -t elegant -d output/
189
- ```
190
-
191
- ### Theme management
192
-
193
- ```bash
194
- # Set a built-in theme as default
195
- cthemes set-theme elegant --default
196
-
197
- # Register a custom theme from a CSS file
198
- cthemes set-theme my-brand --css themes/swiss-design.css
199
-
200
- # Register and set as default
201
- cthemes set-theme my-brand --css themes/swiss-design.css --default
202
-
203
- # Unregister a custom theme
204
- cthemes set-theme my-brand --remove
205
- ```
206
-
207
- ### All commands
208
-
209
- | Command | Description |
210
- |---------|-------------|
211
- | `from-url <url>` | Extract theme from a web page URL |
212
- | `from-docx <file>` | Extract theme from a .docx document |
213
- | `from-pdf <file>` | Extract theme from a PDF document |
214
- | `extract <source>` | Auto-detect source type and extract theme |
215
- | `color-systems` | List 15 built-in color systems |
216
- | `mermaid-presets` | List Mermaid presets (light/dark/elegant) |
217
- | `list` | List all generated themes |
218
- | `validate <file>` | Validate a theme against v3.0 paradigm rules |
219
- | `set-theme <name>` | Set, register, or remove export themes |
220
- | `export-html <input>` | Export Markdown → standalone HTML |
221
- | `export-pdf <input>` | Export Markdown → PDF |
222
- | `export <inputs...>` | Batch export multiple files or directories |
223
-
224
- ### Extract options
225
-
226
- | Flag | Description |
227
- |------|-------------|
228
- | `-n, --name` | Theme name (derived from source by default) |
229
- | `-o, --output` | Output CSS file path |
230
- | `-d, --themes-dir` | Themes directory (default: `themes/`) |
231
- | `-c, --color-system` | Force a color system |
232
- | `-m, --mermaid-preset` | Force a Mermaid preset |
233
- | `-A, --auto-match` | Auto-match color system and Mermaid preset |
234
-
235
- ### Export options
236
-
237
- | Flag | Description |
238
- |------|-------------|
239
- | `-t, --theme` | Theme name (built-in, custom, or CSS file path) |
240
- | `-o, --output` | Output file path |
241
- | `-d, --output-dir` | Output directory for batch export |
242
- | `--format` | Output format for batch: `html` or `pdf` (default: `html`) |
243
- | `--format` | PDF page size: `A4`, `Letter`, `A3` (default: `A4`) |
244
-
245
- ## How It Works
246
-
247
- ### Theme Extraction Pipeline
248
-
249
- ```
250
- Source (URL / .docx / .pdf)
251
- │
252
- ▼
253
- ┌─────────────────────┐
254
- │ Extractor │ Parse → raw ThemeStyle
255
- └──────────┬──────────┘
256
- │
257
- ▼
258
- ┌─────────────────────┐
259
- │ Color System │ Match → 15 built-in palettes
260
- │ Mermaid Preset │ Select light/dark/elegant
261
- │ Validators │ WCAG contrast + paradigm rules
262
- └──────────┬──────────┘
263
- │
264
- ▼
265
- ┌─────────────────────┐
266
- │ Template Engine │ Handlebars → v3.0 CSS (≤300 lines)
267
- └──────────┬──────────┘
268
- │
269
- ▼
270
- themes/<name>.css
271
- ```
272
-
273
- ### Export Pipeline
274
-
275
- ```
276
- Markdown file
277
- │
278
- ▼
279
- ┌─────────────────────────────────────────────┐
280
- │ Puppeteer (headless Chromium) │
281
- │ ┌───────────────────────────────────────┐ │
282
- │ │ Local HTTP Server │ │
283
- │ │ serves @bytechain.cn/colamd/renderer │ │
284
- │ │ (same-origin, no CORS) │ │
285
- │ └──────────────┬────────────────────────┘ │
286
- │ │ │
287
- │ createColaMDEditor({ editable: false }) │
288
- │ applyTheme(name, customCSS?) │
289
- │ setMarkdown(content) │
290
- │ ensureAllPluginsRendered() ← mermaid/KaTeX │
291
- │ │ │
292
- │ ┌──────────────┴──────────────┐ │
293
- │ │ buildExportHTML() → .html │ │
294
- │ │ page.pdf() → .pdf │ │
295
- │ └─────────────────────────────┘ │
296
- └─────────────────────────────────────────────┘
297
- ```
298
-
299
- ## Design Paradigm (v3.0)
300
-
301
- Full specification: [`templates/theme-paradigm.md`](src/templates/theme-paradigm.md).
302
-
303
- ### Core Principles
304
-
305
- | Principle | Description |
306
- |-----------|-------------|
307
- | **Variable-first** | All colors, fonts, sizes, spacing as CSS custom properties. No raw values in selectors |
308
- | **Modular** | Theme = variables + minimal selector tweaks. Built-in systems inherit automatically |
309
- | **Semantic** | `--color-link` not `--color-blue`; `--font-heading` not `--font-sans` |
310
- | **Derivable** | Full theme from 5 seed colors + 3 font stacks. AI agents modify only Section 1 |
311
- | **Print-faithful** | `@media print` mirrors screen styles with `!important` + `print-color-adjust` |
312
-
313
- ### Contrast Requirements (WCAG 2.1)
314
-
315
- | Rule ID | Level | Requirement | Threshold |
316
- |---------|-------|-------------|-----------|
317
- | CR-01 | MUST | Body text vs background | ≥ 7:1 (AAA) |
318
- | CR-02 | MUST | Secondary text vs background | ≥ 4.5:1 (AA) |
319
- | CR-03 | MUST | Dimmed text vs background | ≥ 3:1 (AA large) |
320
- | CR-04 | MUST | Accent color vs background | ≥ 4.5:1 (AA) |
321
- | CR-05 | SHOULD | Inline code bg vs background | ≥ 1.5:1 |
322
-
323
- ## Project Structure
324
-
325
- ```
326
- ColaMD-themes/
327
- ├── skills/
328
- │ ├── colamd-themes/SKILL.md # Canonical skill source
329
- │ └── build-skills.sh # Generate agent-specific files
330
- ├── .claude/skills/colamd-themes.skill.md # Claude Code skill
331
- ├── .opencode/skills/colamd-themes/SKILL.md # OpenCode skill
332
- ├── .openclaw/skills/colamd-themes/SKILL.md # OpenClaw skill
333
- ├── .hermes/skills/tools/colamd-themes/ # Hermes skill
334
- ├── .trae/rules/colamd-themes.md # Trae rules
335
- ├── package.json
336
- ├── tsconfig.json
337
- ├── themes/ # Generated CSS themes
338
- ├── src/
339
- │ ├── cli.ts # CLI entry point
340
- │ ├── index.ts # Public API exports
341
- │ ├── models.ts # ThemeStyle / SeedPalette types
342
- │ ├── generator.ts # Handlebars → CSS pipeline
343
- │ ├── renderer.ts # Puppeteer HTML/PDF export engine
344
- │ ├── export-cli.ts # Export CLI commands
345
- │ ├── theme-store.ts # Theme config persistence (async API)
346
- │ ├── utils/
347
- │ │ └── cli-utils.ts # Shared utilities & error handling
348
- │ ├── color-utils.ts # Color manipulation utilities
349
- │ ├── contrast.ts # WCAG 2.1 luminance & contrast
350
- │ ├── validators.ts # Paradigm validation engine
351
- │ ├── color-systems.ts # 15 predefined seed palettes
352
- │ ├── mermaid-presets.ts # Mermaid 20-variable presets
353
- │ ├── docx-style-paradigm.ts # Document style specification
354
- │ ├── extractors/
355
- │ │ ├── base.ts # Extractor interface
356
- │ │ ├── url-extractor.ts # URL → ThemeStyle
357
- │ │ ├── docx-extractor.ts # DOCX → ThemeStyle
358
- │ │ └── pdf-extractor.ts # PDF → ThemeStyle
359
- │ └── templates/
360
- │ ├── template.css # Paradigm companion CSS
361
- │ ├── theme-paradigm.md # v3.0 design specification
362
- │ └── theme-template.hbs # Handlebars CSS template
363
- └── tests/
364
- ```
365
-
366
- ## Tech Stack
367
-
368
- | Component | Library | Purpose |
369
- |-----------|---------|---------|
370
- | Runtime | Node.js + TypeScript | ESM modules, strict typing |
371
- | CLI framework | Commander.js | Argument parsing, subcommands |
372
- | CSS templating | Handlebars | v3.0 paradigm CSS generation |
373
- | HTML parsing | Cheerio | DOM traversal for URL extraction |
374
- | CSS parsing | css-tree | CSS rule AST parsing |
375
- | DOCX parsing | Mammoth | Word → HTML conversion |
376
- | PDF parsing | pdf-parse | PDF text extraction |
377
- | HTTP client | Axios | Web page fetching |
378
- | Browser engine | Puppeteer | Headless Chromium for HTML/PDF export |
379
- | Editor engine | @bytechain.cn/colamd | Milkdown-based Markdown renderer |
380
- | Terminal output | Chalk + Ora | Colored text + spinners |
381
-
382
- ## License
383
-
384
- MIT
1
+ # ColaMD Themes
2
+
3
+ [![DSH Skill](https://img.shields.io/badge/DSH%20Skill-supported-brightgreen?logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxNiIgaGVpZ2h0PSIxNiIgdmlld0JveD0iMCAwIDI0IDI0Ij48cGF0aCBmaWxsPSJjdXJyZW50Q29sb3IiIGQ9Ik0xMiAyQzYuNDggMiAyIDYuNDggMiAxMnM0LjQ4IDEwIDEwIDEwIDEwLTQuNDggMTAtMTBTMTcuNTIgMiAxMiAyem0tMSAxN2gxMm0tMTItMmgxMm0tMTItMkgxMg=="/>](https://github.com/deepseek-ai/deepseek-harness)
4
+ [![Awesome DSH](https://awesome.re/badge.svg)](https://github.com/Dominic789654/awesome-deepseek-harness)
5
+ [![Awesome DSH Plugin](https://beancookie.github.io/awesome-dsh-plugin/badge.svg)](https://github.com/beancookie/awesome-dsh-plugin)
6
+
7
+ **Topics**: `dsh` `deepseek-harness` `colamd` `themes` `css` `markdown` `pdf` `html` `skill` `ai-agent`
8
+
9
+ A theme development & export toolkit for [ColaMD](https://github.com/cola-md/cola-md) — the Agent-native Markdown editor. Extract visual formatting from web pages, Word documents, and PDFs, convert them into validated CSS theme files, and export Markdown to standalone HTML or PDF with any theme applied.
10
+
11
+ ## Features
12
+
13
+ ### Theme Extraction
14
+
15
+ - **URL** — fetch a web page, parse its CSS rules (via `css-tree`), resolve inline styles with specificity calculation, and derive a coherent theme palette
16
+ - **DOCX** — read Word document styles (H1–H6, tables, code blocks) via mammoth, map to theme variables
17
+ - **PDF** — extract typography metadata from PDF text using multi-layer heuristic analysis
18
+ - **Auto‑detect** — `extract` command automatically routes to the right extractor
19
+
20
+ ### HTML / PDF Export
21
+
22
+ - **`export-html`** — render Markdown to a standalone HTML document with theme CSS embedded, Mermaid diagrams and KaTeX math fully rendered
23
+ - **`export-pdf`** — render Markdown to PDF via Puppeteer (Chromium); theme colors are preserved with `print-color-adjust: exact`
24
+ - **`export`** — batch export multiple files or entire directories to HTML or PDF
25
+ - Powered by `@bytechain.cn/colamd/renderer` (1.5.x, Milkdown) — the npm 2.x package is the Electron app distribution and no longer ships the library build; `renderer.ts` guards against a 2.x install with a clear downgrade hint. Built-in theme names resolve their local 2.7.7 CSS first, and a body-variable bridge keeps the 2.7.7 palette intact through the 1.5.x renderer (theme files stay `:root`-only per contract). Generated themes target the **2.7.7 contract** (verified against `@bytechain.cn/colamd@2.7.7`), so they carry over unchanged.
26
+
27
+ ### Theme Management
28
+
29
+ - **`set-theme`** — configure default export theme, register custom CSS themes, switch between built-in themes
30
+ - Built-in themes: `light`, `dark`, `elegant`, `newsprint`
31
+ - Custom themes: any `.css` file registered by name, referenced in exports
32
+ - **Using themes in the ColaMD 2.7.7 app** — import via *Theme > Import Theme* or drop the `.css` into `~/.colamd/themes/`. The app ships its own built-in `elegant`; rename our `elegant.css` (e.g. `elegant-brick.css`) before importing to avoid a name clash.
33
+
34
+ ### Validation & Color Systems
35
+
36
+ - **Contrast Engine** — WCAG 2.1 relative luminance & contrast ratio calculations
37
+ - **Paradigm Validator** — 15+ design constraint rules (CR, HR, SL, NT, BD, MP, FP, FS, SH) with auto-fix suggestions
38
+ - **Color System Library** — 15 predefined seed palettes across 5 families (Morandi, Macaron, Nordic, Vintage, Mint)
39
+ - **2.7.7 CSS Contract Validator** — flags dead selectors (`#write`, `.ProseMirror`, `body.theme-custom`), dead variables (`--mermaid-*`, `--radius-*`, `--font-size-root`…), `pt` units, and vertical padding on quote/code lines
40
+ - **2.7.7 Verified** — all 16 shipped themes audited against the published `@bytechain.cn/colamd@2.7.7` npm package: zero `.cm-md-*` hook drift, all `:root` live variables and `--pele-*` overrides consumed by the 2.7.7 renderer
41
+ - **Pele Diagram Colors** — 9 `--pele-*` variables derived from `--code-block-bg` / `--code-block-text` / `--link-color`, replacing the 20 Mermaid variables
42
+
43
+ ### Security & Performance (v0.4.0+)
44
+
45
+ - **SSRF Protection** — URL extractor validates against protocol whitelist and blocks private network access to prevent Server-Side Request Forgery attacks
46
+ - **Input Validation** — CSS files validated for extension, size limit (1MB max), and content validity to prevent OOM attacks
47
+ - **Async I/O** — Non-blocking file operations for improved responsiveness during batch exports
48
+ - **Template Caching** — LRU-style cache (max 10 templates) with TTL expiration (30min) and mtime-based auto-invalidation for stable memory usage
49
+ - **Unified Error Handling** — Structured error codes (`CLIError` + `ErrorCode`) across all commands for consistent debugging experience
50
+ - **Resource Cleanup** — Explicit Puppeteer page cleanup prevents zombie processes and resource leaks
51
+
52
+ ### CSS Template Engine
53
+
54
+ Handlebars-powered template produces ColaMD 2.7.7 contract CSS (≤300 lines):
55
+
56
+ | Section | Content |
57
+ |---------|---------|
58
+ | 1 | Design Tokens — `:root` seed palette (11 vars), 14 semantic colors, fonts, metrics, 9 `--pele-*` |
59
+ | 2 | Editor DOM — `#editor .cm-content` + `.cm-md-*` (headings, inline, quote, code block, table, indent) |
60
+ | 3 | Exported HTML — `.colamd-document` color layer for semantic tags |
61
+ | 4 | `@media print` — print-color fidelity only (screen rules already apply) |
62
+
63
+ ### MCP Server (Model Context Protocol)
64
+
65
+ Full MCP server for AI-native integration — connect ColaMD-themes to Chatbox, Cursor, Claude Desktop, Continue, and all MCP-compatible clients.
66
+
67
+ - **14 MCP tools** covering theme extraction, export, validation, and management
68
+ - **Stdio transport** — zero network config, direct process communication
69
+ - **Chinese theme name support** — non-ASCII names handled via smart path resolution
70
+
71
+ | Category | Tool | Description |
72
+ |----------|------|-------------|
73
+ | Extraction | `extract_from_url` | Theme from web page |
74
+ | | `extract_from_docx` | Theme from Word doc |
75
+ | | `extract_from_pdf` | Theme from PDF |
76
+ | | `extract_auto` | Auto-detect source |
77
+ | Management | `list_themes` | List all themes |
78
+ | | `validate_theme` | Validate theme rules |
79
+ | | `check_fonts` | Check font availability |
80
+ | | `set_theme` | Register custom theme |
81
+ | Color | `list_color_systems` | 15 built-in palettes |
82
+ | | `list_mermaid_presets` | 3 Mermaid presets |
83
+ | Export | `export_html` | Markdown to HTML |
84
+ | | `export_pdf` | Markdown to PDF |
85
+ | | `export_batch` | Batch export |
86
+
87
+ ### Multi-Agent Skill
88
+
89
+ Universal skill definitions for 6 AI coding agents, auto-generated from a single source:
90
+
91
+ | Agent | Skill Path | Frontmatter |
92
+ |-------|-----------|-------------|
93
+ | **Claude Code** | `.claude/skills/colamd-themes.skill.md` | `name`, `description` |
94
+ | **OpenCode** | `.opencode/skills/colamd-themes/SKILL.md` | `name`, `version`, `user-invocable`, `allowed-tools`, `hooks` |
95
+ | **OpenClaw** | `.openclaw/skills/colamd-themes/SKILL.md` | `id`, `name`, `version`, `icon`, `author`, `homepage`, `metadata.openclaw.os` |
96
+ | **Hermes** | `.hermes/skills/tools/colamd-themes/SKILL.md` | `name`, `version`, `author`, `license`, `metadata.hermes.tags`, `prerequisites` |
97
+ | **Trae** | `.trae/rules/colamd-themes.md` | Plain Markdown (no frontmatter) |
98
+ | **DeepSeek Harness** | `.dsh/skills/colamd-themes/SKILL.md` | `name`, `version`, `description`, `metadata.dsh.tags`, `prerequisites` |
99
+
100
+ **Architecture:**
101
+
102
+ ```
103
+ skills/colamd-themes/SKILL.md ← Canonical source (single source of truth)
104
+ │
105
+ ▼
106
+ skills/build-skills.sh ← Build script (bash)
107
+ │
108
+ ├──→ .claude/skills/colamd-themes.skill.md
109
+ ├──→ .opencode/skills/colamd-themes/SKILL.md
110
+ ├──→ .openclaw/skills/colamd-themes/SKILL.md
111
+ ├──→ .hermes/skills/tools/colamd-themes/SKILL.md
112
+ ├──→ .trae/rules/colamd-themes.md
113
+ └──→ .dsh/skills/colamd-themes/SKILL.md
114
+ ```
115
+
116
+ **Regenerate all agent skills:**
117
+
118
+ ```bash
119
+ npm run build:skills # generate all
120
+ bash skills/build-skills.sh # same thing
121
+
122
+ # Or generate for a single agent:
123
+ bash skills/build-skills.sh claude
124
+ bash skills/build-skills.sh opencode
125
+ bash skills/build-skills.sh openclaw
126
+ bash skills/build-skills.sh hermes
127
+ bash skills/build-skills.sh trae
128
+ bash skills/build-skills.sh dsh
129
+ ```
130
+
131
+ To customize: edit `skills/colamd-themes/SKILL.md`, then run `npm run build:skills`.
132
+
133
+ ## Installation
134
+
135
+ ```bash
136
+ git clone git@github.com:byteuser1977/ColaMD-themes.git
137
+ cd ColaMD-themes
138
+ npm install
139
+ npm run build
140
+ ```
141
+
142
+ For development with hot‑reload:
143
+
144
+ ```bash
145
+ npx tsx src/cli.ts <command>
146
+ ```
147
+
148
+ ## Usage
149
+
150
+ The package provides two equivalent CLI commands:
151
+
152
+ - **`colamd-themes`** — full command name
153
+ - **`cthemes`** — short alias (recommended for frequent use)
154
+
155
+ Examples below use the short alias `cthemes`, but you can substitute `colamd-themes` interchangeably.
156
+
157
+ ### Extract a theme from a URL
158
+
159
+ ```bash
160
+ cthemes from-url "https://example.com" --name my-theme
161
+ ```
162
+
163
+ ### Extract from a Word document
164
+
165
+ ```bash
166
+ cthemes from-docx report.docx --name corporate-theme
167
+ ```
168
+
169
+ ### Extract from a PDF
170
+
171
+ ```bash
172
+ cthemes from-pdf paper.pdf --name academic-theme
173
+ ```
174
+
175
+ ### Auto‑detect source type
176
+
177
+ ```bash
178
+ cthemes extract source.docx --name auto-theme
179
+ ```
180
+
181
+ ### Validate a theme
182
+
183
+ ```bash
184
+ cthemes validate themes/my-theme.css
185
+ ```
186
+
187
+ ### List themes and color systems
188
+
189
+ ```bash
190
+ cthemes list
191
+ cthemes color-systems
192
+ ```
193
+
194
+ ### Export to HTML
195
+
196
+ ```bash
197
+ # Single file with a built-in theme
198
+ cthemes export-html document.md -t elegant -o output.html
199
+
200
+ # With a custom theme
201
+ cthemes export-html document.md -t my-brand -o output.html
202
+ ```
203
+
204
+ ### Export to PDF
205
+
206
+ ```bash
207
+ # Single file
208
+ cthemes export-pdf document.md -t dark -o output.pdf
209
+
210
+ # With page format
211
+ cthemes export-pdf document.md -t elegant --format Letter -o output.pdf
212
+ ```
213
+
214
+ ### Batch export
215
+
216
+ ```bash
217
+ # Multiple files to HTML
218
+ cthemes export docs/*.md --format html -t light -d output/
219
+
220
+ # Directory of Markdown files to PDF
221
+ cthemes export docs/ --format pdf -t elegant -d output/
222
+ ```
223
+
224
+ ### Theme management
225
+
226
+ ```bash
227
+ # Set a built-in theme as default
228
+ cthemes set-theme elegant --default
229
+
230
+ # Register a custom theme from a CSS file
231
+ cthemes set-theme my-brand --css themes/swiss-design.css
232
+
233
+ # Register and set as default
234
+ cthemes set-theme my-brand --css themes/swiss-design.css --default
235
+
236
+ # Unregister a custom theme
237
+ cthemes set-theme my-brand --remove
238
+ ```
239
+
240
+ ### All commands
241
+
242
+ | Command | Description |
243
+ |---------|-------------|
244
+ | `from-url <url>` | Extract theme from a web page URL |
245
+ | `from-docx <file>` | Extract theme from a .docx document |
246
+ | `from-pdf <file>` | Extract theme from a PDF document |
247
+ | `extract <source>` | Auto-detect source type and extract theme |
248
+ | `color-systems` | List 15 built-in color systems |
249
+ | `list` | List all generated themes |
250
+ | `validate <file>` | Validate a theme against the 2.7.7 contract and paradigm rules |
251
+ | `set-theme <name>` | Set, register, or remove export themes |
252
+ | `export-html <input>` | Export Markdown → standalone HTML |
253
+ | `export-pdf <input>` | Export Markdown → PDF |
254
+ | `export <inputs...>` | Batch export multiple files or directories |
255
+
256
+ ### Extract options
257
+
258
+ | Flag | Description |
259
+ |------|-------------|
260
+ | `-n, --name` | Theme name (derived from source by default) |
261
+ | `-o, --output` | Output CSS file path |
262
+ | `-d, --themes-dir` | Themes directory (default: `themes/`) |
263
+ | `-c, --color-system` | Force a color system |
264
+ | `-A, --auto-match` | Auto-match a color system from the extracted palette |
265
+
266
+ ### Export options
267
+
268
+ | Flag | Description |
269
+ |------|-------------|
270
+ | `-t, --theme` | Theme name (built-in, custom, or CSS file path) |
271
+ | `-o, --output` | Output file path |
272
+ | `-d, --output-dir` | Output directory for batch export |
273
+ | `--format` | Output format for batch: `html` or `pdf` (default: `html`) |
274
+ | `--format` | PDF page size: `A4`, `Letter`, `A3` (default: `A4`) |
275
+
276
+ ## How It Works
277
+
278
+ ### Theme Extraction Pipeline
279
+
280
+ ```
281
+ Source (URL / .docx / .pdf)
282
+ │
283
+ ▼
284
+ ┌─────────────────────┐
285
+ │ Extractor │ Parse → raw ThemeStyle
286
+ └──────────┬──────────┘
287
+ │
288
+ ▼
289
+ ┌─────────────────────┐
290
+ │ Color System │ Match → 15 built-in palettes
291
+ │ Validators │ WCAG contrast + paradigm + 2.7.7 contract
292
+ └──────────┬──────────┘
293
+ │
294
+ ▼
295
+ ┌─────────────────────┐
296
+ │ Template Engine │ Handlebars → 2.7.7 CSS (≤300 lines)
297
+ └──────────┬──────────┘
298
+ │
299
+ ▼
300
+ themes/<name>.css
301
+ ```
302
+
303
+ ### Export Pipeline
304
+
305
+ ```
306
+ Markdown file
307
+ │
308
+ ▼
309
+ ┌─────────────────────────────────────────────┐
310
+ │ Puppeteer (headless Chromium) │
311
+ │ ┌───────────────────────────────────────┐ │
312
+ │ │ Local HTTP Server │ │
313
+ │ │ serves @bytechain.cn/colamd/renderer │ │
314
+ │ │ (same-origin, no CORS) │ │
315
+ │ └──────────────┬────────────────────────┘ │
316
+ │ │ │
317
+ │ createColaMDEditor({ editable: false }) │
318
+ │ applyTheme(name, customCSS?) │
319
+ │ setMarkdown(content) │
320
+ │ ensureAllPluginsRendered() ← mermaid/KaTeX │
321
+ │ │ │
322
+ │ ┌──────────────┴──────────────┐ │
323
+ │ │ buildExportHTML() → .html │ │
324
+ │ │ page.pdf() → .pdf │ │
325
+ │ └─────────────────────────────┘ │
326
+ └─────────────────────────────────────────────┘
327
+ ```
328
+
329
+ ## Design Paradigm (2.7.7 contract)
330
+
331
+ Full specification: [`templates/theme-paradigm.md`](src/templates/theme-paradigm.md).
332
+
333
+ ### Core Principles
334
+
335
+ | Principle | Description |
336
+ |-----------|-------------|
337
+ | **Variable-first** | All colors, fonts, sizes, spacing as CSS custom properties. No raw values in selectors |
338
+ | **Modular** | Theme = variables + minimal selector tweaks. Built-in systems inherit automatically |
339
+ | **Semantic** | `--link-color` not `--color-blue`; `--font-body` not `--font-sans` |
340
+ | **Derivable** | Full theme from 11 seed tokens + 3 font stacks. AI agents modify only Section 1 |
341
+ | **Print-faithful** | Export prints the current window, so screen rules apply as-is; `@media print` only adds `print-color-adjust` |
342
+ | **No dead rules** | CodeMirror 6 has no `#write`, `.ProseMirror`, `<h1>` or `<blockquote>` elements — only `.cm-md-*` line classes |
343
+
344
+ ### Contrast Requirements (WCAG 2.1)
345
+
346
+ | Rule ID | Level | Requirement | Threshold |
347
+ |---------|-------|-------------|-----------|
348
+ | CR-01 | MUST | Body text vs background | ≥ 7:1 (AAA) |
349
+ | CR-02 | MUST | Secondary text vs background | ≥ 4.5:1 (AA) |
350
+ | CR-03 | MUST | Dimmed text vs background | ≥ 3:1 (AA large) |
351
+ | CR-04 | MUST | Accent color vs background | ≥ 4.5:1 (AA) |
352
+ | CR-05 | SHOULD | Inline code bg vs background | ≥ 1.5:1 |
353
+
354
+ ## Project Structure
355
+
356
+ ```
357
+ ColaMD-themes/
358
+ ├── skills/
359
+ │ ├── colamd-themes/SKILL.md # Canonical skill source
360
+ │ └── build-skills.sh # Generate agent-specific files
361
+ ├── .claude/skills/colamd-themes.skill.md # Claude Code skill
362
+ ├── .opencode/skills/colamd-themes/SKILL.md # OpenCode skill
363
+ ├── .openclaw/skills/colamd-themes/SKILL.md # OpenClaw skill
364
+ ├── .hermes/skills/tools/colamd-themes/ # Hermes skill
365
+ ├── .trae/rules/colamd-themes.md # Trae rules
366
+ ├── package.json
367
+ ├── tsconfig.json
368
+ ├── themes/ # Generated CSS themes
369
+ ├── src/
370
+ │ ├── cli.ts # CLI entry point
371
+ │ ├── index.ts # Public API exports
372
+ │ ├── models.ts # ThemeStyle / SeedPalette types
373
+ │ ├── generator.ts # Handlebars → CSS pipeline
374
+ │ ├── renderer.ts # Puppeteer HTML/PDF export engine
375
+ │ ├── export-cli.ts # Export CLI commands
376
+ │ ├── theme-store.ts # Theme config persistence (async API)
377
+ │ ├── utils/
378
+ │ │ └── cli-utils.ts # Shared utilities & error handling
379
+ │ ├── color-utils.ts # Color manipulation utilities
380
+ │ ├── contrast.ts # WCAG 2.1 luminance & contrast
381
+ │ ├── validators.ts # Paradigm validation engine
382
+ │ ├── color-systems.ts # 15 predefined seed palettes
383
+ │ ├── docx-style-paradigm.ts # Document style specification
384
+ │ ├── extractors/
385
+ │ │ ├── base.ts # Extractor interface
386
+ │ │ ├── url-extractor.ts # URL → ThemeStyle
387
+ │ │ ├── docx-extractor.ts # DOCX → ThemeStyle
388
+ │ │ └── pdf-extractor.ts # PDF → ThemeStyle
389
+ │ └── templates/
390
+ │ ├── template.css # Paradigm companion CSS
391
+ │ ├── theme-paradigm.md # v4.0 design specification (2.7.7 contract)
392
+ │ └── theme-template.hbs # Handlebars CSS template
393
+ └── tests/
394
+ ```
395
+
396
+ ## Tech Stack
397
+
398
+ | Component | Library | Purpose |
399
+ |-----------|---------|---------|
400
+ | Runtime | Node.js + TypeScript | ESM modules, strict typing |
401
+ | CLI framework | Commander.js | Argument parsing, subcommands |
402
+ | CSS templating | Handlebars | 2.7 contract CSS generation |
403
+ | HTML parsing | Cheerio | DOM traversal for URL extraction |
404
+ | CSS parsing | css-tree | CSS rule AST parsing |
405
+ | DOCX parsing | Mammoth | Word → HTML conversion |
406
+ | PDF parsing | pdf-parse | PDF text extraction |
407
+ | HTTP client | Axios | Web page fetching |
408
+ | Browser engine | Puppeteer | Headless Chromium for HTML/PDF export |
409
+ | Editor engine | @bytechain.cn/colamd | Milkdown-based Markdown renderer |
410
+ | Terminal output | Chalk + Ora | Colored text + spinners |
411
+
412
+ ## License
413
+
414
+ MIT