{"_id":"@bytechain.cn/colamd-themes","_rev":"3-80c94b615f05a3d01d96af25d1208d5a","name":"@bytechain.cn/colamd-themes","dist-tags":{"latest":"0.3.2"},"versions":{"0.3.0":{"name":"@bytechain.cn/colamd-themes","version":"0.3.0","_id":"@bytechain.cn/colamd-themes@0.3.0","maintainers":[{"name":"bytechain.cn","email":"byteuser@qq.com"}],"bin":{"cthemes":"dist/cli.js","colamd-themes":"dist/cli.js"},"dist":{"shasum":"2aa68a130427a36d2552eaa076ad6a49a64f0599","tarball":"https://registry.npmjs.org/@bytechain.cn/colamd-themes/-/colamd-themes-0.3.0.tgz","fileCount":108,"integrity":"sha512-YyJ9oK5k+jS/HTH1kkMQtlTvw3ZO1OUOSawf0QxwU0KCMESeqZ6cosxB1mbcY5C0fmZgelp6a46oH9VMPJNdOg==","signatures":[{"sig":"MEUCIHRFHKzJeZGEVUAciFKueND8hlYU6jP9jSUsVu+pVAMZAiEA5b6LRi3HgccC3gzDhfOzI6t27NomVjLgeZfmxTPfFnA=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":1184076},"main":"dist/index.js","type":"module","types":"./dist/index.d.ts","gitHead":"30daaa5087a33fb97009337133f3d2a377be6ff0","scripts":{"dev":"tsx src/cli.ts","build":"tsc && node --input-type=commonjs -e \"require('fs').cpSync('src/templates','dist/templates',{recursive:true})\"","start":"node dist/cli.js","build:skills":"bash skills/build-skills.sh"},"_npmUser":{"name":"bytechain.cn","email":"byteuser@qq.com"},"_npmVersion":"11.9.0","description":"Theme development & export tool for ColaMD — extract formatting, generate themes, and export Markdown to HTML/PDF","directories":{},"_nodeVersion":"25.6.1","dependencies":{"ora":"^8.0","axios":"^1.7","chalk":"^5.3","cheerio":"^1.0","mammoth":"^1.8","css-tree":"^3.0","commander":"^12.0","pdf-parse":"^1.1","puppeteer":"^24.0","handlebars":"^4.7","@bytechain.cn/colamd":"^1.5.2"},"_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.0","typescript":"^5.5","@types/node":"^22.0","@types/css-tree":"^2.3"},"_npmOperationalInternal":{"tmp":"tmp/colamd-themes_0.3.0_1780299974115_0.9224397514865821","host":"s3://npm-registry-packages-npm-production"}},"0.3.1":{"name":"@bytechain.cn/colamd-themes","version":"0.3.1","_id":"@bytechain.cn/colamd-themes@0.3.1","maintainers":[{"name":"bytechain.cn","email":"byteuser@qq.com"}],"bin":{"cthemes":"dist/cli.js","colamd-themes":"dist/cli.js"},"dist":{"shasum":"d6a25ccf3117113dccf63df22fe6c32e7e0bbc4b","tarball":"https://registry.npmjs.org/@bytechain.cn/colamd-themes/-/colamd-themes-0.3.1.tgz","fileCount":108,"integrity":"sha512-3tQ2ZIb7+2PLY84kp/P0GiywuOgjSzl13jUNUcCQDE3E5YvSb7QZsye0KtnQCUK2gk9VYFRv/+Xx0IMVfULvfA==","signatures":[{"sig":"MEUCIF3XP8s8YjFBvsd5b5A85p950cxM45KsstYnNNJzGnduAiEA8A6ZH9mpppqVWPclJ/mcGuzeeem7hshX47Ci9z149+Q=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":1209531},"main":"dist/index.js","type":"module","types":"./dist/index.d.ts","gitHead":"b0185a92f06b5cb0378405455ce243e504122106","scripts":{"dev":"tsx src/cli.ts","build":"tsc && node --input-type=commonjs -e \"require('fs').cpSync('src/templates','dist/templates',{recursive:true})\"","start":"node dist/cli.js","build:skills":"bash skills/build-skills.sh"},"_npmUser":{"name":"bytechain.cn","email":"byteuser@qq.com"},"_npmVersion":"11.9.0","description":"Theme development & export tool for ColaMD — extract formatting, generate themes, and export Markdown to HTML/PDF","directories":{},"_nodeVersion":"25.6.1","dependencies":{"ora":"^8.0","axios":"^1.7","chalk":"^5.3","cheerio":"^1.0","mammoth":"^1.8","css-tree":"^3.0","commander":"^12.0","pdf-parse":"^1.1","puppeteer":"^24.0","handlebars":"^4.7","@bytechain.cn/colamd":"^1.5.2"},"_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.0","typescript":"^5.5","@types/node":"^22.0","@types/css-tree":"^2.3"},"_npmOperationalInternal":{"tmp":"tmp/colamd-themes_0.3.1_1780311694946_0.13376848121035478","host":"s3://npm-registry-packages-npm-production"}},"0.3.2":{"name":"@bytechain.cn/colamd-themes","version":"0.3.2","description":"Theme development & export tool for ColaMD — extract formatting, generate themes, and export Markdown to HTML/PDF","type":"module","main":"dist/index.js","bin":{"colamd-themes":"dist/cli.js","cthemes":"dist/cli.js"},"scripts":{"build":"tsc && node --input-type=commonjs -e \"require('fs').cpSync('src/templates','dist/templates',{recursive:true})\"","build:skills":"bash skills/build-skills.sh","dev":"tsx src/cli.ts","start":"node dist/cli.js"},"dependencies":{"@bytechain.cn/colamd":"^1.5.2","axios":"^1.7","chalk":"^5.3","cheerio":"^1.0","commander":"^12.0","css-tree":"^3.0","handlebars":"^4.7","mammoth":"^1.8","ora":"^8.0","pdf-parse":"^1.1","puppeteer":"^24.0"},"devDependencies":{"@types/css-tree":"^2.3","@types/node":"^22.0","tsx":"^4.0","typescript":"^5.5"},"gitHead":"cda582ddb8c8c8295febcaff16384e75726024f8","types":"./dist/index.d.ts","_id":"@bytechain.cn/colamd-themes@0.3.2","_nodeVersion":"25.6.1","_npmVersion":"11.9.0","dist":{"integrity":"sha512-TBW2oMb1takB2MCJ+w/ju3FIB8pNAq3rlPhhJ8ozG+vellJQg2cFx5e2M0aPPXoJIcIx58el7IAOCPNyRv/1DQ==","shasum":"ddcc5665daf18bfaa27b07a109417aae58491078","tarball":"https://registry.npmjs.org/@bytechain.cn/colamd-themes/-/colamd-themes-0.3.2.tgz","fileCount":108,"unpackedSize":1247906,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQDJKgxWM/VFEaQpLwSNq4fwU9P3RlQwtig4WrXxIVpaDgIgetUNTCKxQOpPTA5H6wqlQy1vcC9GhRIxnb8EKGEVNpk="}]},"_npmUser":{"name":"bytechain.cn","email":"byteuser@qq.com"},"directories":{},"maintainers":[{"name":"bytechain.cn","email":"byteuser@qq.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/colamd-themes_0.3.2_1780376062464_0.9197217442033427"},"_hasShrinkwrap":false}},"time":{"created":"2026-06-01T07:46:13.913Z","modified":"2026-06-02T04:54:22.724Z","0.3.0":"2026-06-01T07:46:14.282Z","0.3.1":"2026-06-01T11:01:35.104Z","0.3.2":"2026-06-02T04:54:22.634Z"},"description":"Theme development & export tool for ColaMD — extract formatting, generate themes, and export Markdown to HTML/PDF","maintainers":[{"name":"bytechain.cn","email":"byteuser@qq.com"}],"readme":"# ColaMD Themes\n\nA 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.\n\n## Features\n\n### Theme Extraction\n\n- **URL** — fetch a web page, parse its CSS rules (via `css-tree`), resolve inline styles with specificity calculation, and derive a coherent theme palette\n- **DOCX** — read Word document styles (H1–H6, tables, code blocks) via mammoth, map to theme variables\n- **PDF** — extract typography metadata from PDF text using multi-layer heuristic analysis\n- **Auto‑detect** — `extract` command automatically routes to the right extractor\n\n### HTML / PDF Export\n\n- **`export-html`** — render Markdown to a standalone HTML document with theme CSS embedded, Mermaid diagrams and KaTeX math fully rendered\n- **`export-pdf`** — render Markdown to PDF via Puppeteer (Chromium), preserving theme colors with `@media print` fidelity\n- **`export`** — batch export multiple files or entire directories to HTML or PDF\n- Powered by `@bytechain.cn/colamd/renderer` — the same Milkdown editor engine used by ColaMD itself\n\n### Theme Management\n\n- **`set-theme`** — configure default export theme, register custom CSS themes, switch between built-in themes\n- Built-in themes: `light`, `dark`, `elegant`, `newsprint`\n- Custom themes: any `.css` file registered by name, referenced in exports\n\n### Validation & Color Systems\n\n- **Contrast Engine** — WCAG 2.1 relative luminance & contrast ratio calculations\n- **Paradigm Validator** — 15+ design constraint rules (CR, HR, SL, NT, BD, MP, FP, FS, SH) with auto-fix suggestions\n- **Color System Library** — 15 predefined seed palettes across 5 families (Morandi, Macaron, Nordic, Vintage, Mint)\n- **Mermaid Presets** — 3 presets (light/dark/elegant) with 20 core variables, auto-selected by luminance and accent warmth\n\n### Security & Performance (v0.3.2+)\n\n- **SSRF Protection** — URL extractor validates against protocol whitelist and blocks private network access to prevent Server-Side Request Forgery attacks\n- **Input Validation** — CSS files validated for extension, size limit (1MB max), and content validity to prevent OOM attacks\n- **Async I/O** — Non-blocking file operations for improved responsiveness during batch exports\n- **Template Caching** — LRU-style cache (max 10 templates) with TTL expiration (30min) and mtime-based auto-invalidation for stable memory usage\n- **Unified Error Handling** — Structured error codes (`CLIError` + `ErrorCode`) across all commands for consistent debugging experience\n- **Resource Cleanup** — Explicit Puppeteer page cleanup prevents zombie processes and resource leaks\n\n### CSS Template Engine\n\nHandlebars-powered template produces v3.0 paradigm CSS (≤300 lines):\n\n| Section | Content |\n|---------|---------|\n| 1 | Design Tokens — seed palette (11 vars), typography (4 font stacks), font sizing, radii & spacing |\n| 2 | Semantic Mapping — auto-derived from seed tokens via `var(--seed-*)` |\n| 3 | Mermaid 20 Core Variables — container, font, nodes, edges, clusters, labels, titles, person, offset |\n| 4 | Fine Tuning |\n| 5 | Selector-Level Micro Adjustments — headings, code, pre, blockquote, table, hr, responsive |\n| 6 | `@media print` — screen-mirror with `!important` + `print-color-adjust: exact` |\n\n### Multi-Agent Skill\n\nUniversal skill definitions for 5 AI coding agents, auto-generated from a single source:\n\n| Agent | Skill Path | Frontmatter |\n|-------|-----------|-------------|\n| **Claude Code** | `.claude/skills/colamd-themes.skill.md` | `name`, `description` |\n| **OpenCode** | `.opencode/skills/colamd-themes/SKILL.md` | `name`, `version`, `user-invocable`, `allowed-tools`, `hooks` |\n| **OpenClaw** | `.openclaw/skills/colamd-themes/SKILL.md` | `id`, `name`, `version`, `icon`, `author`, `homepage`, `metadata.openclaw.os` |\n| **Hermes** | `.hermes/skills/tools/colamd-themes/SKILL.md` | `name`, `version`, `author`, `license`, `metadata.hermes.tags`, `prerequisites` |\n| **Trae** | `.trae/rules/colamd-themes.md` | Plain Markdown (no frontmatter) |\n\n**Architecture:**\n\n```\nskills/colamd-themes/SKILL.md       ← Canonical source (single source of truth)\n        │\n        ▼\nskills/build-skills.sh              ← Build script (bash)\n        │\n        ├──→ .claude/skills/colamd-themes.skill.md\n        ├──→ .opencode/skills/colamd-themes/SKILL.md\n        ├──→ .openclaw/skills/colamd-themes/SKILL.md\n        ├──→ .hermes/skills/tools/colamd-themes/SKILL.md\n        └──→ .trae/rules/colamd-themes.md\n```\n\n**Regenerate all agent skills:**\n\n```bash\nnpm run build:skills            # generate all\nbash skills/build-skills.sh     # same thing\n\n# Or generate for a single agent:\nbash skills/build-skills.sh claude\nbash skills/build-skills.sh opencode\nbash skills/build-skills.sh openclaw\nbash skills/build-skills.sh hermes\nbash skills/build-skills.sh trae\n```\n\nTo customize: edit `skills/colamd-themes/SKILL.md`, then run `npm run build:skills`.\n\n## Installation\n\n```bash\ngit clone git@github.com:byteuser1977/ColaMD-themes.git\ncd ColaMD-themes\nnpm install\nnpm run build\n```\n\nFor development with hot‑reload:\n\n```bash\nnpx tsx src/cli.ts <command>\n```\n\n## Usage\n\nThe package provides two equivalent CLI commands:\n\n- **`colamd-themes`** — full command name\n- **`cthemes`** — short alias (recommended for frequent use)\n\nExamples below use the short alias `cthemes`, but you can substitute `colamd-themes` interchangeably.\n\n### Extract a theme from a URL\n\n```bash\ncthemes from-url \"https://example.com\" --name my-theme\n```\n\n### Extract from a Word document\n\n```bash\ncthemes from-docx report.docx --name corporate-theme\n```\n\n### Extract from a PDF\n\n```bash\ncthemes from-pdf paper.pdf --name academic-theme\n```\n\n### Auto‑detect source type\n\n```bash\ncthemes extract source.docx --name auto-theme\n```\n\n### Validate a theme\n\n```bash\ncthemes validate themes/my-theme.css\n```\n\n### List themes and color systems\n\n```bash\ncthemes list\ncthemes color-systems\ncthemes mermaid-presets\n```\n\n### Export to HTML\n\n```bash\n# Single file with a built-in theme\ncthemes export-html document.md -t elegant -o output.html\n\n# With a custom theme\ncthemes export-html document.md -t my-brand -o output.html\n```\n\n### Export to PDF\n\n```bash\n# Single file\ncthemes export-pdf document.md -t dark -o output.pdf\n\n# With page format\ncthemes export-pdf document.md -t elegant --format Letter -o output.pdf\n```\n\n### Batch export\n\n```bash\n# Multiple files to HTML\ncthemes export docs/*.md --format html -t light -d output/\n\n# Directory of Markdown files to PDF\ncthemes export docs/ --format pdf -t elegant -d output/\n```\n\n### Theme management\n\n```bash\n# Set a built-in theme as default\ncthemes set-theme elegant --default\n\n# Register a custom theme from a CSS file\ncthemes set-theme my-brand --css themes/swiss-design.css\n\n# Register and set as default\ncthemes set-theme my-brand --css themes/swiss-design.css --default\n\n# Unregister a custom theme\ncthemes set-theme my-brand --remove\n```\n\n### All commands\n\n| Command | Description |\n|---------|-------------|\n| `from-url <url>` | Extract theme from a web page URL |\n| `from-docx <file>` | Extract theme from a .docx document |\n| `from-pdf <file>` | Extract theme from a PDF document |\n| `extract <source>` | Auto-detect source type and extract theme |\n| `color-systems` | List 15 built-in color systems |\n| `mermaid-presets` | List Mermaid presets (light/dark/elegant) |\n| `list` | List all generated themes |\n| `validate <file>` | Validate a theme against v3.0 paradigm rules |\n| `set-theme <name>` | Set, register, or remove export themes |\n| `export-html <input>` | Export Markdown → standalone HTML |\n| `export-pdf <input>` | Export Markdown → PDF |\n| `export <inputs...>` | Batch export multiple files or directories |\n\n### Extract options\n\n| Flag | Description |\n|------|-------------|\n| `-n, --name` | Theme name (derived from source by default) |\n| `-o, --output` | Output CSS file path |\n| `-d, --themes-dir` | Themes directory (default: `themes/`) |\n| `-c, --color-system` | Force a color system |\n| `-m, --mermaid-preset` | Force a Mermaid preset |\n| `-A, --auto-match` | Auto-match color system and Mermaid preset |\n\n### Export options\n\n| Flag | Description |\n|------|-------------|\n| `-t, --theme` | Theme name (built-in, custom, or CSS file path) |\n| `-o, --output` | Output file path |\n| `-d, --output-dir` | Output directory for batch export |\n| `--format` | Output format for batch: `html` or `pdf` (default: `html`) |\n| `--format` | PDF page size: `A4`, `Letter`, `A3` (default: `A4`) |\n\n## How It Works\n\n### Theme Extraction Pipeline\n\n```\nSource (URL / .docx / .pdf)\n    │\n    ▼\n┌─────────────────────┐\n│  Extractor          │  Parse → raw ThemeStyle\n└──────────┬──────────┘\n           │\n           ▼\n┌─────────────────────┐\n│  Color System       │  Match → 15 built-in palettes\n│  Mermaid Preset     │  Select light/dark/elegant\n│  Validators         │  WCAG contrast + paradigm rules\n└──────────┬──────────┘\n           │\n           ▼\n┌─────────────────────┐\n│  Template Engine    │  Handlebars → v3.0 CSS (≤300 lines)\n└──────────┬──────────┘\n           │\n           ▼\n  themes/<name>.css\n```\n\n### Export Pipeline\n\n```\nMarkdown file\n    │\n    ▼\n┌─────────────────────────────────────────────┐\n│  Puppeteer (headless Chromium)              │\n│  ┌───────────────────────────────────────┐  │\n│  │  Local HTTP Server                    │  │\n│  │  serves @bytechain.cn/colamd/renderer │  │\n│  │  (same-origin, no CORS)              │  │\n│  └──────────────┬────────────────────────┘  │\n│                 │                            │\n│  createColaMDEditor({ editable: false })     │\n│  applyTheme(name, customCSS?)                │\n│  setMarkdown(content)                        │\n│  ensureAllPluginsRendered()  ← mermaid/KaTeX │\n│                 │                            │\n│  ┌──────────────┴──────────────┐             │\n│  │  buildExportHTML() → .html  │             │\n│  │  page.pdf()        → .pdf   │             │\n│  └─────────────────────────────┘             │\n└─────────────────────────────────────────────┘\n```\n\n## Design Paradigm (v3.0)\n\nFull specification: [`templates/theme-paradigm.md`](src/templates/theme-paradigm.md).\n\n### Core Principles\n\n| Principle | Description |\n|-----------|-------------|\n| **Variable-first** | All colors, fonts, sizes, spacing as CSS custom properties. No raw values in selectors |\n| **Modular** | Theme = variables + minimal selector tweaks. Built-in systems inherit automatically |\n| **Semantic** | `--color-link` not `--color-blue`; `--font-heading` not `--font-sans` |\n| **Derivable** | Full theme from 5 seed colors + 3 font stacks. AI agents modify only Section 1 |\n| **Print-faithful** | `@media print` mirrors screen styles with `!important` + `print-color-adjust` |\n\n### Contrast Requirements (WCAG 2.1)\n\n| Rule ID | Level | Requirement | Threshold |\n|---------|-------|-------------|-----------|\n| CR-01 | MUST | Body text vs background | ≥ 7:1 (AAA) |\n| CR-02 | MUST | Secondary text vs background | ≥ 4.5:1 (AA) |\n| CR-03 | MUST | Dimmed text vs background | ≥ 3:1 (AA large) |\n| CR-04 | MUST | Accent color vs background | ≥ 4.5:1 (AA) |\n| CR-05 | SHOULD | Inline code bg vs background | ≥ 1.5:1 |\n\n## Project Structure\n\n```\nColaMD-themes/\n├── skills/\n│   ├── colamd-themes/SKILL.md              # Canonical skill source\n│   └── build-skills.sh                     # Generate agent-specific files\n├── .claude/skills/colamd-themes.skill.md   # Claude Code skill\n├── .opencode/skills/colamd-themes/SKILL.md # OpenCode skill\n├── .openclaw/skills/colamd-themes/SKILL.md # OpenClaw skill\n├── .hermes/skills/tools/colamd-themes/     # Hermes skill\n├── .trae/rules/colamd-themes.md           # Trae rules\n├── package.json\n├── tsconfig.json\n├── themes/                                  # Generated CSS themes\n├── src/\n│   ├── cli.ts                               # CLI entry point\n│   ├── index.ts                             # Public API exports\n│   ├── models.ts                            # ThemeStyle / SeedPalette types\n│   ├── generator.ts                         # Handlebars → CSS pipeline\n│   ├── renderer.ts                          # Puppeteer HTML/PDF export engine\n│   ├── export-cli.ts                        # Export CLI commands\n│   ├── theme-store.ts                       # Theme config persistence (async API)\n│   ├── utils/\n│   │   └── cli-utils.ts                     # Shared utilities & error handling\n│   ├── color-utils.ts                       # Color manipulation utilities\n│   ├── contrast.ts                          # WCAG 2.1 luminance & contrast\n│   ├── validators.ts                        # Paradigm validation engine\n│   ├── color-systems.ts                     # 15 predefined seed palettes\n│   ├── mermaid-presets.ts                   # Mermaid 20-variable presets\n│   ├── docx-style-paradigm.ts              # Document style specification\n│   ├── extractors/\n│   │   ├── base.ts                          # Extractor interface\n│   │   ├── url-extractor.ts                 # URL → ThemeStyle\n│   │   ├── docx-extractor.ts                # DOCX → ThemeStyle\n│   │   └── pdf-extractor.ts                 # PDF → ThemeStyle\n│   └── templates/\n│       ├── template.css                     # Paradigm companion CSS\n│       ├── theme-paradigm.md               # v3.0 design specification\n│       └── theme-template.hbs              # Handlebars CSS template\n└── tests/\n```\n\n## Tech Stack\n\n| Component | Library | Purpose |\n|-----------|---------|---------|\n| Runtime | Node.js + TypeScript | ESM modules, strict typing |\n| CLI framework | Commander.js | Argument parsing, subcommands |\n| CSS templating | Handlebars | v3.0 paradigm CSS generation |\n| HTML parsing | Cheerio | DOM traversal for URL extraction |\n| CSS parsing | css-tree | CSS rule AST parsing |\n| DOCX parsing | Mammoth | Word → HTML conversion |\n| PDF parsing | pdf-parse | PDF text extraction |\n| HTTP client | Axios | Web page fetching |\n| Browser engine | Puppeteer | Headless Chromium for HTML/PDF export |\n| Editor engine | @bytechain.cn/colamd | Milkdown-based Markdown renderer |\n| Terminal output | Chalk + Ora | Colored text + spinners |\n\n## License\n\nMIT\n","readmeFilename":"README.md"}