@bytechain.cn/colamd-themes 0.6.2 → 0.7.1

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 (77) hide show
  1. package/README.md +57 -4
  2. package/dist/build-info.json +5 -0
  3. package/dist/cli.js +252 -51
  4. package/dist/cli.js.map +1 -1
  5. package/dist/compat.d.ts +14 -0
  6. package/dist/compat.js +43 -7
  7. package/dist/compat.js.map +1 -1
  8. package/dist/export-cli.js +124 -20
  9. package/dist/export-cli.js.map +1 -1
  10. package/dist/extractors/local-html.d.ts +43 -0
  11. package/dist/extractors/local-html.js +338 -0
  12. package/dist/extractors/local-html.js.map +1 -0
  13. package/dist/extractors/url-extractor.d.ts +11 -2
  14. package/dist/extractors/url-extractor.js +11 -0
  15. package/dist/extractors/url-extractor.js.map +1 -1
  16. package/dist/generator.js +2 -2
  17. package/dist/generator.js.map +1 -1
  18. package/dist/models.d.ts +22 -0
  19. package/dist/models.js.map +1 -1
  20. package/dist/pdf-check.d.ts +42 -0
  21. package/dist/pdf-check.js +206 -0
  22. package/dist/pdf-check.js.map +1 -0
  23. package/dist/renderer.d.ts +27 -0
  24. package/dist/renderer.js +155 -10
  25. package/dist/renderer.js.map +1 -1
  26. package/dist/slides-markdown.d.ts +56 -0
  27. package/dist/slides-markdown.js +355 -6
  28. package/dist/slides-markdown.js.map +1 -1
  29. package/dist/slides.d.ts +8 -0
  30. package/dist/slides.js +76 -0
  31. package/dist/slides.js.map +1 -1
  32. package/dist/utils/output.d.ts +51 -0
  33. package/dist/utils/output.js +89 -0
  34. package/dist/utils/output.js.map +1 -0
  35. package/dist/validators.d.ts +5 -0
  36. package/dist/validators.js +29 -1
  37. package/dist/validators.js.map +1 -1
  38. package/mcp-server/dist/index.js +0 -0
  39. package/package.json +9 -5
  40. package/skills/build-skills.sh +15 -14
  41. package/skills/colamd-themes/SKILL.md +109 -13
  42. package/themes/8-bit-orbit.css +1 -0
  43. package/themes/README.md +4 -0
  44. package/themes/biennale-yellow.css +1 -0
  45. package/themes/block-frame.css +1 -0
  46. package/themes/blue-professional.css +1 -0
  47. package/themes/bold-poster.css +1 -0
  48. package/themes/broadside.css +1187 -837
  49. package/themes/capsule.css +1 -0
  50. package/themes/cartesian.css +1 -0
  51. package/themes/cobalt-grid.css +1 -0
  52. package/themes/coral.css +1 -0
  53. package/themes/creative-mode.css +1 -0
  54. package/themes/daisy-days.css +1 -0
  55. package/themes/editorial-forest.css +1 -0
  56. package/themes/editorial-tri-tone.css +1 -0
  57. package/themes/emerald-editorial.css +1 -0
  58. package/themes/grove.css +1 -0
  59. package/themes/long-table.css +1 -0
  60. package/themes/mat.css +1 -0
  61. package/themes/monochrome.css +1 -0
  62. package/themes/neo-grid-bold.css +1 -0
  63. package/themes/peoples-platform.css +1 -0
  64. package/themes/pin-and-paper.css +1 -0
  65. package/themes/pink-script.css +8 -1
  66. package/themes/playful.css +1 -0
  67. package/themes/retro-windows.css +1 -0
  68. package/themes/retro-zine.css +1 -0
  69. package/themes/sakura-chroma.css +1 -0
  70. package/themes/scatterbrain.css +1 -0
  71. package/themes/signal.css +1 -0
  72. package/themes/soft-editorial.css +1 -0
  73. package/themes/stencil-tablet.css +1 -0
  74. package/themes/vellum.css +1 -0
  75. package/dist/mermaid-presets.d.ts +0 -14
  76. package/dist/mermaid-presets.js +0 -122
  77. package/dist/mermaid-presets.js.map +0 -1
package/README.md CHANGED
@@ -43,9 +43,16 @@ After installation, open a `.md` file and run **ColaView MD: Show Preview** from
43
43
  ### Markdown → PPT Markdown (v0.6.0+)
44
44
 
45
45
  - **`to-slides`** — convert a plain Markdown document into slide-deck Markdown: pages split with upstream pagination semantics (`---` via `@lezer/markdown`, the same parser family as the app), all eleven built-in layouts inferred from content structure (cover / section / agenda / kpi / timeline / steps / matrix / two-col / figure / quote / closing), deck chrome and per-page header blocks emitted with chapter tracking
46
- - **Self-checked output** — the generated deck is validated against the directive contract (page-first placement, layout-name syntax, field-key whitelists, `slide-css` safety subset) before writing
46
+ - **Content adaptation (v0.7.0+, default on; `--no-adapt` off)** — the generator fits each page to its layout contract: adds `**row titles**`, downgrades kpi without numbers / timeline without dates to matrix, splits over-capacity lists into continuation pages (`label: 标题(续)`), splits oversized paragraphs at sentence boundaries, and gives a trailing quote its own page
47
+ - **Self-checked output** — the generated deck is validated against the directive contract (page-first placement, layout-name syntax, field-key whitelists, `slide-css` safety subset) plus the layout content contract (SLIDES-07) and an overflow estimate (SLIDES-08) before writing
47
48
  - Full slide directive syntax and layout table: see [`skills/colamd-themes/SKILL.md`](skills/colamd-themes/SKILL.md) (幻灯片版式 chapter)
48
49
 
50
+ ### PPT PDF (v0.7.0+)
51
+
52
+ - **`ppt <input>`** — one-shot: markdown → deck markdown → contract check → **16:9 slide PDF** → PDF-01…05 content check. Stops on the first failure with an actionable reason; `--md-only` stops after the deck
53
+ - **`export-slides <deck.md>`** — print an existing deck on the platform's slide sheets (deck chrome, hero centering, page breaks) at 960×540pt. Pages that would overflow are fitted by a small sheet-type scale-down so PDF page count always equals deck page count
54
+ - Requires `@bytechain.cn/colamd@^2.7.13` whose lib entry exposes the slide export API; older platforms fail with the exact upgrade command
55
+
49
56
  ### HTML / PDF Export
50
57
 
51
58
  - **`export-html`** — render Markdown to a standalone HTML document with theme CSS embedded, Mermaid diagrams and KaTeX math fully rendered
@@ -112,10 +119,13 @@ Full MCP server for AI-native integration — connect ColaMD-themes to Chatbox,
112
119
  | | `check_fonts` | Check font availability |
113
120
  | | `set_theme` | Register custom theme |
114
121
  | Color | `list_color_systems` | 15 built-in palettes |
115
- | | `list_mermaid_presets` | 3 Mermaid presets |
116
122
  | Export | `export_html` | Markdown to HTML |
117
123
  | | `export_pdf` | Markdown to PDF |
118
124
  | | `export_batch` | Batch export |
125
+ | Slides | `ppt` | One-shot: Markdown → deck → 16:9 PDF |
126
+ | | `to_slides` | Markdown → deck markdown |
127
+ | | `export_slides` | Deck markdown → 16:9 PDF |
128
+ | | `check_pdf` | PDF content checks (PDF-01…05) |
119
129
 
120
130
  ### Multi-Agent Skill
121
131
 
@@ -172,10 +182,10 @@ The package is also a **DSH (DeepSeek Harness) plugin bundle** installable from
172
182
  - **Plugin contract** — `package.json` declares `dsh.bundle.patch` pointing to [`cordis.patch.yml`](cordis.patch.yml), which inserts the `colamd-themes` Cordis entry into the profile's composition
173
183
  - **Host entry** — [`src/dsh-plugin.ts`](src/dsh-plugin.ts) exports the Cordis protocol (`name` / `inject: ["skills"]` / `apply`) and registers the bundled `skills/colamd-themes/SKILL.md` with the Harness `skills` service via `ctx.skills.registerProvider` (same provider protocol as the bundled dsh-ppt plugin)
174
184
  - **CLI bins** — `colamd-themes` / `cthemes` ship with the package and become available to profile agents after install
175
- - **Runtime compatibility** — `@deepseek-ai/dsh-skill` is declared as an *optional* peer (`^0.1.5-rc.1 || ^0.2.0-rc || ^0.2.1-rc || ^0.3.0-rc || ^0.4.0-rc`; semver's prerelease rule forces per-patch enumeration — append a comparator when a new rc line ships): the market checks it against the DSH runtime version, while standalone `npm install` is unaffected
185
+ - **Runtime compatibility** — `@deepseek-ai/dsh-skill` is declared as an *optional* peer (`^0.2.0-rc || ^0.2.1-rc || ^0.2.2-rc || ^0.2.3-rc || ^0.2.4-rc || ^0.2.5-rc || ^0.2.6-rc || ^0.2.7-rc || ^0.2.8-rc || ^0.2.9-rc`; semver's prerelease rule forces one comparator per rc patch line, so every 0.2.x rc release (0.2.0–0.2.9) is accepted without further edits; 0.1.x and 0.3+ host lines are out of scope): the market checks it against the DSH runtime version, while standalone `npm install` is unaffected
176
186
  - **Backward compatibility** — the runtime consumes only the stable `BUNDLED_SKILL_RANK` constant, and the host entry's `apply()` tolerates skills-service protocol drift (warning instead of a broken profile load)
177
187
  - **Platform compat layer** — [`src/compat.ts`](src/compat.ts) probes the installed `@bytechain.cn/colamd` version and its `themes/contract.json` for contract drift, and the renderer verifies the export API surface at init; platform upgrades are diagnosed clearly at `cthemes validate`/export time instead of failing cryptically
178
- - **Bundle contents** — `dist/` (CLI + host entry), `themes/` (16 contract CSS themes), `skills/` (bundled skill), `cordis.patch.yml`
188
+ - **Bundle contents** — `dist/` (CLI + host entry), `themes/` (58 contract CSS theme files, all passing `validate`), `skills/` (bundled skill), `cordis.patch.yml`
179
189
 
180
190
  Install from a DSH profile (once published to npm): add `@bytechain.cn/colamd-themes` through the dsh-market UI or `dsh plugin --profile <name> add @bytechain.cn/colamd-themes`.
181
191
 
@@ -244,12 +254,29 @@ cthemes from-url "https://example.com" --name my-brand --ppt sans
244
254
  cthemes from-html template.html --ppt
245
255
  ```
246
256
 
257
+ ### Convert Markdown into a 16:9 slide PDF
258
+
259
+ ```bash
260
+ # One-shot: deck markdown + validated 16:9 PDF (recommended)
261
+ cthemes ppt report.md -t elegant
262
+
263
+ # Deck markdown only
264
+ cthemes ppt report.md --md-only
265
+
266
+ # Step-wise: deck → PDF
267
+ cthemes to-slides report.md -o report.slides.md
268
+ cthemes export-slides report.slides.md -t elegant -o report.slides.pdf
269
+ ```
270
+
247
271
  ### Convert Markdown into slide-deck Markdown
248
272
 
249
273
  ```bash
250
274
  # Auto-infer all 11 layouts + deck chrome, self-checked output
251
275
  cthemes to-slides report.md -o report.slides.md
252
276
 
277
+ # Keep author content verbatim (no adaptation)
278
+ cthemes to-slides report.md --no-adapt
279
+
253
280
  # With deck chrome fields
254
281
  cthemes to-slides report.md --deck-brand "ColaMD" --deck-title "Q4 Review" --deck-meta "2026.11"
255
282
 
@@ -273,6 +300,18 @@ cthemes validate themes/my-theme.css
273
300
  cthemes validate report.slides.md
274
301
  ```
275
302
 
303
+ Intentional design-identity deviations (saturation of the paper, a decorative accent
304
+ below text-contrast thresholds) can be declared machine-readably in the theme file so
305
+ `validate` stays green in batch/CI while still reporting them under `waived`:
306
+
307
+ ```css
308
+ /* colamd-allow: SL-01, CR-04 */
309
+ ```
310
+
311
+ Only `SL-` / `CR-` / `NT-` identity rules are waivable — contract rules (`CSS-*`,
312
+ `SLIDE-*`, `SLIDES-*`) can never be waived, and a real contrast problem must be fixed
313
+ by darkening the text color rather than waived.
314
+
276
315
  ### List themes and color systems
277
316
 
278
317
  ```bash
@@ -339,6 +378,8 @@ cthemes set-theme my-brand --remove
339
378
  | `from-pdf <file>` | Extract theme from a PDF document |
340
379
  | `extract <source>` | Auto-detect source type (local HTML / URL / .docx / .pdf) and extract theme |
341
380
  | `to-slides <input>` | Convert a Markdown document into slide-deck Markdown (auto-inferred layouts) |
381
+ | `ppt <input>` | One-shot: deck markdown + validated 16:9 slide PDF (PDF-01…05 checked) |
382
+ | `export-slides <input>` | Export a deck markdown → 16:9 slide PDF (960×540pt) |
342
383
  | `color-systems` | List 15 built-in color systems |
343
384
  | `list` | List all generated themes |
344
385
  | `validate <file>` | Validate a theme CSS (2.7 contract + paradigm + slide token rules) or a slides markdown file (directive contract); with a platform compat report |
@@ -368,6 +409,18 @@ cthemes set-theme my-brand --remove
368
409
  | `--deck-title` | Deck chrome title (overrides frontmatter / first h1) |
369
410
  | `--deck-meta` | Deck chrome meta (chrome-right fallback, e.g. date) |
370
411
  | `--deck-logo` | Deck chrome logo path (relative to the output file) |
412
+ | `--no-adapt` | Keep author content verbatim (default: adapt to the layout contracts) |
413
+
414
+ ### ppt options
415
+
416
+ | Flag | Description |
417
+ |------|-------------|
418
+ | `-t, --theme` | Theme name (built-in, custom, or CSS path) |
419
+ | `-d, --output-dir` | Output directory (default: alongside the input) |
420
+ | `--deck-brand/-title/-meta/-logo` | Deck chrome fields |
421
+ | `--no-adapt` | Keep author content verbatim |
422
+ | `--md-only` | Stop after the deck markdown (skip the PDF) |
423
+ | `--json` / `--verbose` | One-line JSON result / detail lines |
371
424
 
372
425
  ### Export options
373
426
 
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "@bytechain.cn/colamd-themes",
3
+ "version": "0.7.1",
4
+ "builtAt": "2026-11-22T23:05:26.337Z"
5
+ }
package/dist/cli.js CHANGED
@@ -1,21 +1,22 @@
1
1
  #!/usr/bin/env node
2
2
  import { Command } from "commander";
3
- import { existsSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
4
- import { join, isAbsolute, dirname, resolve } from "node:path";
3
+ import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
4
+ import { join, isAbsolute, basename, dirname, resolve } from "node:path";
5
5
  import { fileURLToPath } from "node:url";
6
6
  import { execSync } from "node:child_process";
7
7
  import chalk from "chalk";
8
- import ora from "ora";
9
8
  import { UrlExtractor } from "./extractors/url-extractor.js";
9
+ import { LocalHtmlExtractor } from "./extractors/local-html.js";
10
10
  import { DocxExtractor } from "./extractors/docx-extractor.js";
11
11
  import { PdfExtractor } from "./extractors/pdf-extractor.js";
12
12
  import { writeThemeFile } from "./generator.js";
13
13
  import { COLOR_SYSTEMS, getColorSystem } from "./color-systems.js";
14
- import { validateSeedPalette, validateThemeCss, summarizeIssues } from "./validators.js";
14
+ import { validateSeedPalette, validateThemeCss, summarizeIssues, parseIssueWaivers } from "./validators.js";
15
15
  import { registerExportCommands } from "./export-cli.js";
16
- import { BUILTIN_THEMES } from "./theme-store.js";
16
+ import { BUILTIN_THEMES, resolveTheme } from "./theme-store.js";
17
17
  import { getColamdCompat, formatColamdCompat } from "./compat.js";
18
18
  import { markdownToSlides, validateSlidesMarkdown } from "./slides-markdown.js";
19
+ import { emit, startTask, formatFailures, formatWarnings, hasFailures } from "./utils/output.js";
19
20
  /**
20
21
  * Dynamically read version from package.json to avoid hardcoding.
21
22
  * This ensures CLI --version always matches the published package version.
@@ -214,13 +215,14 @@ function addExtractOptions(cmd) {
214
215
  .option("--ppt [style]", "Also emit PPT --slide-* tokens (ColaMD 2.7.13 slides); optional preset: serif|sans|mono");
215
216
  }
216
217
  async function runExtraction(extractor, source, options) {
217
- const spinner = ora("Extracting styles...").start();
218
+ const spinner = startTask("Extracting styles...", {});
218
219
  try {
219
220
  // --ppt [serif|sans|mono]: validate the preset before running extraction.
221
+ // 显式指定预设时提前校验;无值 flag 则信任提取器自带的 slidePreset(如按模板字体自动判定)。
220
222
  let slidePreset;
221
- if (options.ppt) {
223
+ if (typeof options.ppt === "string") {
222
224
  const { parseSlidePreset } = await import("./slides.js");
223
- const preset = parseSlidePreset(typeof options.ppt === "string" ? options.ppt : undefined);
225
+ const preset = parseSlidePreset(options.ppt);
224
226
  if (!preset) {
225
227
  spinner.fail(chalk.red(`Unknown PPT preset: "${options.ppt}". Valid presets: serif, sans, mono`));
226
228
  process.exit(1);
@@ -232,6 +234,8 @@ async function runExtraction(extractor, source, options) {
232
234
  style.name = options.name;
233
235
  if (slidePreset)
234
236
  style.slidePreset = slidePreset;
237
+ else if (options.ppt && !style.slidePreset)
238
+ style.slidePreset = "serif";
235
239
  if (options.colorSystem) {
236
240
  const cs = getColorSystem(options.colorSystem);
237
241
  if (!cs) {
@@ -243,7 +247,7 @@ async function runExtraction(extractor, source, options) {
243
247
  }
244
248
  if (options.autoMatch)
245
249
  style.colorSystemId = "";
246
- spinner.text = "Generating CSS (2.7.13 contract)...";
250
+ spinner.setText("Generating CSS (2.7.13 contract)...");
247
251
  const outputPath = writeThemeFile(style, options.output || options.themesDir);
248
252
  spinner.succeed(chalk.green(`Theme "${style.name}" generated: ${outputPath}`));
249
253
  printSummary(style);
@@ -279,11 +283,21 @@ addExtractOptions(program.command("from-pdf")
279
283
  }
280
284
  await runExtraction(new PdfExtractor(), file, options);
281
285
  });
286
+ // ── from-html ──
287
+ addExtractOptions(program.command("from-html")
288
+ .description("Extract theme from a local HTML file (uses sibling template.json as metadata when present)")
289
+ .argument("<file>", "Path to the .html file")).action(async (file, options) => {
290
+ if (!existsSync(file)) {
291
+ console.error(chalk.red(`File not found: ${file}`));
292
+ process.exit(1);
293
+ }
294
+ await runExtraction(new LocalHtmlExtractor(), file, options);
295
+ });
282
296
  // ── extract (auto-detect) ──
283
297
  addExtractOptions(program.command("extract")
284
298
  .description("Auto-detect source type and extract theme")
285
- .argument("<source>", "URL, .docx file, or .pdf file")).action(async (source, options) => {
286
- const extractors = [new UrlExtractor(), new DocxExtractor(), new PdfExtractor()];
299
+ .argument("<source>", "URL, .html file, .docx file, or .pdf file")).action(async (source, options) => {
300
+ const extractors = [new LocalHtmlExtractor(), new UrlExtractor(), new DocxExtractor(), new PdfExtractor()];
287
301
  const ext = extractors.find((e) => e.canHandle(source));
288
302
  if (!ext) {
289
303
  console.error(chalk.red(`Cannot detect source type for: ${source}`));
@@ -301,6 +315,9 @@ program
301
315
  .option("--deck-title <text>", "Deck chrome title (overrides frontmatter/first h1)")
302
316
  .option("--deck-meta <text>", "Deck chrome meta (chrome-right fallback, e.g. date)")
303
317
  .option("--deck-logo <path>", "Deck chrome logo path (relative to the output file)")
318
+ .option("--no-adapt", "Do not adapt page content to the layout contracts (default: adapt)")
319
+ .option("--json", "Print a one-line JSON result")
320
+ .option("--verbose", "Print detail lines")
304
321
  .action((input, options) => {
305
322
  if (!existsSync(input)) {
306
323
  console.error(chalk.red(`File not found: ${input}`));
@@ -312,19 +329,176 @@ program
312
329
  title: options.deckTitle,
313
330
  meta: options.deckMeta,
314
331
  logo: options.deckLogo,
332
+ adapt: options.adapt !== false,
315
333
  });
316
- // Self-check the generated deck against the directive contract.
334
+ // Self-check the generated deck against the directive + content contracts.
317
335
  const issues = validateSlidesMarkdown(slides);
318
- const errors = issues.filter((i) => i.level === "MUST" || i.level === "MUST_NOT");
319
- if (issues.length > 0) {
320
- console.log(chalk.yellow(summarizeIssues(issues)));
321
- }
336
+ const failed = hasFailures(issues);
322
337
  const outputPath = options.output || input.replace(/\.md$/i, "") + ".slides.md";
323
338
  writeFileSync(outputPath, slides, "utf-8");
324
339
  const pageCount = slides.split("\n").filter((l) => /^ {0,3}---\s*$/.test(l)).length + 1;
325
- console.log(chalk.green(`Slides deck generated: ${outputPath} (${pageCount} pages)`));
326
- if (errors.length > 0)
340
+ emit({ json: options.json, verbose: options.verbose }, {
341
+ ok: !failed,
342
+ summary: `Slides deck: ${outputPath} (${pageCount} pages)${failed ? " · 契约失败" : ""}`,
343
+ details: [...formatFailures(issues), ...formatWarnings(issues)],
344
+ data: {
345
+ ok: !failed,
346
+ output: outputPath,
347
+ pages: pageCount,
348
+ issues: issues.map((i) => ({ rule: i.ruleId, level: i.level, message: i.message })),
349
+ },
350
+ });
351
+ });
352
+ // ── ppt (one-shot deck generation + 16:9 PDF) ──
353
+ program
354
+ .command("ppt")
355
+ .description("One-shot: markdown → slide-deck markdown → validated 16:9 PDF (ColaMD 2.7.13 slides)")
356
+ .argument("<input>", "Path to the source .md file")
357
+ .option("-t, --theme <name>", "Theme name (built-in, custom, or CSS file path)")
358
+ .option("-d, --output-dir <dir>", "Output directory (default: alongside the input)")
359
+ .option("--deck-brand <text>", "Deck chrome brand")
360
+ .option("--deck-title <text>", "Deck chrome title")
361
+ .option("--deck-meta <text>", "Deck chrome meta (e.g. date)")
362
+ .option("--deck-logo <path>", "Deck chrome logo path")
363
+ .option("--no-adapt", "Do not adapt page content to the layout contracts")
364
+ .option("--md-only", "Stop after writing the deck markdown (skip the PDF)")
365
+ .option("--json", "Print a one-line JSON result")
366
+ .option("--verbose", "Print detail lines")
367
+ .action(async (input, options) => {
368
+ const out = { json: options.json, verbose: options.verbose };
369
+ if (!existsSync(input)) {
370
+ console.error(chalk.red(`File not found: ${input}`));
371
+ process.exit(1);
372
+ }
373
+ try {
374
+ const inputPath = isAbsolute(input) ? input : resolve(process.cwd(), input);
375
+ const base = basename(inputPath, ".md");
376
+ const outDir = options.outputDir ? resolve(process.cwd(), options.outputDir) : dirname(inputPath);
377
+ if (!existsSync(outDir))
378
+ mkdirSync(outDir, { recursive: true });
379
+ const mdPath = join(outDir, `${base}.slides.md`);
380
+ const pdfPath = join(outDir, `${base}.slides.pdf`);
381
+ const task = startTask(`Generating deck from ${base}.md...`, out);
382
+ const source = readFileSync(inputPath, "utf-8");
383
+ const slides = markdownToSlides(source, {
384
+ brand: options.deckBrand,
385
+ title: options.deckTitle,
386
+ meta: options.deckMeta,
387
+ logo: options.deckLogo,
388
+ adapt: options.adapt !== false,
389
+ });
390
+ writeFileSync(mdPath, slides, "utf-8");
391
+ const deckIssues = validateSlidesMarkdown(slides);
392
+ if (hasFailures(deckIssues)) {
393
+ task.fail();
394
+ emit(out, {
395
+ ok: false,
396
+ summary: `Deck 契约失败,已停止导出:${mdPath}`,
397
+ details: [...formatFailures(deckIssues), ...formatWarnings(deckIssues)],
398
+ data: { ok: false, markdown: mdPath, issues: deckIssues.map((i) => ({ rule: i.ruleId, level: i.level, message: i.message })) },
399
+ exitCode: 1,
400
+ });
401
+ return;
402
+ }
403
+ const pages = slides.split("\n").filter((l) => /^ {0,3}---\s*$/.test(l)).length + 1;
404
+ if (options.mdOnly) {
405
+ task.succeed();
406
+ emit(out, {
407
+ ok: true,
408
+ summary: `PPT Markdown: ${mdPath} (${pages} pages)`,
409
+ details: formatWarnings(deckIssues),
410
+ data: { ok: true, markdown: mdPath, pages, issues: deckIssues.map((i) => ({ rule: i.ruleId, level: i.level, message: i.message })) },
411
+ });
412
+ return;
413
+ }
414
+ // Fail fast with an actionable message when the installed platform's lib
415
+ // entry predates the slide export API (2.7.13-rc.1 and older).
416
+ const compat = getColamdCompat();
417
+ if (!compat.slidesExportSupported) {
418
+ task.fail();
419
+ emit(out, {
420
+ ok: false,
421
+ summary: "当前 @bytechain.cn/colamd 不支持幻灯片 PDF 导出",
422
+ details: [
423
+ ` ${formatColamdCompat(compat)}`,
424
+ ` 修复: npm install @bytechain.cn/colamd@^${compat.version ?? "2.7.13"}(需 lib 暴露 enterSlidesPrintLayout/exitSlidesPrintLayout)`,
425
+ ],
426
+ data: { ok: false, markdown: mdPath, error: "slides-export-unsupported", compat: formatColamdCompat(compat) },
427
+ exitCode: 1,
428
+ });
429
+ return;
430
+ }
431
+ const theme = await resolveTheme(options.theme);
432
+ task.setText(`Rendering ${pages} pages → 16:9 PDF (${theme.themeName})...`);
433
+ const { renderSlidesPDF } = await import("./renderer.js");
434
+ const pdfBuffer = await renderSlidesPDF({
435
+ markdown: slides,
436
+ themeName: theme.themeName,
437
+ customCSS: theme.customCSS,
438
+ title: options.deckTitle || base,
439
+ slides: true,
440
+ });
441
+ writeFileSync(pdfPath, pdfBuffer);
442
+ const { checkExportedPdf } = await import("./pdf-check.js");
443
+ const check = await checkExportedPdf(pdfBuffer, { deckMd: slides, slides: true });
444
+ const pdfFailed = hasFailures(check.issues);
445
+ task.succeed();
446
+ emit(out, {
447
+ ok: !pdfFailed,
448
+ summary: `PPT: ${mdPath} + ${pdfPath} · ${check.pageCount} 页 · ${theme.themeName}${pdfFailed ? " · PDF 契约失败" : ""}`,
449
+ details: [...formatFailures(check.issues), ...formatWarnings(check.issues), ...formatWarnings(deckIssues)],
450
+ data: {
451
+ ok: !pdfFailed,
452
+ markdown: mdPath,
453
+ pdf: pdfPath,
454
+ pages,
455
+ pdfPages: check.pageCount,
456
+ paper: check.paperSizes.map((s) => `${s.w.toFixed(0)}×${s.h.toFixed(0)}pt`).join(" / "),
457
+ theme: theme.themeName,
458
+ issues: check.issues.map((i) => ({ rule: i.ruleId, level: i.level, message: i.message })),
459
+ },
460
+ exitCode: pdfFailed ? 1 : 0,
461
+ });
462
+ }
463
+ catch (err) {
464
+ emit(out, {
465
+ ok: false,
466
+ summary: `PPT 导出失败: ${err.message}`,
467
+ exitCode: 1,
468
+ });
469
+ }
470
+ });
471
+ // ── check-pdf ──
472
+ program
473
+ .command("check-pdf")
474
+ .description("Content-check an exported PDF (paper size, page count, blank pages, deck chrome)")
475
+ .argument("<file>", "Path to exported .pdf")
476
+ .option("-d, --deck <md>", "Companion deck markdown (enables page-count & chrome checks)")
477
+ .option("--json", "Print a one-line JSON result")
478
+ .option("--verbose", "Print detail lines")
479
+ .action(async (file, options) => {
480
+ if (!existsSync(file)) {
481
+ console.error(chalk.red(`File not found: ${file}`));
327
482
  process.exit(1);
483
+ }
484
+ const { checkExportedPdf } = await import("./pdf-check.js");
485
+ const buffer = readFileSync(file);
486
+ const deckMd = options.deck && existsSync(options.deck) ? readFileSync(options.deck, "utf-8") : undefined;
487
+ const check = await checkExportedPdf(buffer, { deckMd });
488
+ const failed = hasFailures(check.issues);
489
+ const paper = check.paperSizes.map((s) => `${s.w.toFixed(0)}×${s.h.toFixed(0)}pt`).join(" / ") || "?";
490
+ emit({ json: options.json, verbose: options.verbose }, {
491
+ ok: !failed,
492
+ summary: `${file}: ${failed ? "PDF 内容契约失败" : "PDF-01~05 内容契约通过"} · ${check.pageCount} 页 · ${paper}`,
493
+ details: [...formatFailures(check.issues), ...formatWarnings(check.issues)],
494
+ data: {
495
+ ok: !failed,
496
+ file,
497
+ pages: check.pageCount,
498
+ paper,
499
+ issues: check.issues.map((i) => ({ rule: i.ruleId, level: i.level, message: i.message })),
500
+ },
501
+ });
328
502
  });
329
503
  // ── color-systems ──
330
504
  program
@@ -373,23 +547,36 @@ program
373
547
  // ── validate ──
374
548
  program
375
549
  .command("validate")
376
- .description("Validate a theme CSS (2.7.13 contract + slide tokens) or slides markdown (directive contract)")
550
+ .description("Validate a theme CSS (2.7.13 contract + slide tokens) or slides markdown (directive + content contract)")
377
551
  .argument("<file>", "Path to a .css theme file or a .md slides file")
378
- .action((file) => {
552
+ .option("--json", "Print a one-line JSON result")
553
+ .option("--verbose", "Print the full validation report")
554
+ .action((file, options) => {
379
555
  if (!existsSync(file)) {
380
556
  console.error(chalk.red(`File not found: ${file}`));
381
557
  process.exit(1);
382
558
  }
383
559
  const css = readFileSync(file, "utf-8");
384
- // Slides markdown: directive contract checks.
560
+ // Slides markdown: directive + layout-content contract checks.
385
561
  if (file.toLowerCase().endsWith(".md")) {
386
- console.log(chalk.bold("Slides directives (ColaMD 2.7.13):"));
387
562
  const issues = validateSlidesMarkdown(css);
388
- console.log(issues.length === 0
389
- ? chalk.green(" ✔ 指令语法、页首规则与 slide-css 白名单校验通过")
390
- : summarizeIssues(issues));
391
- if (issues.some((i) => i.level === "MUST" || i.level === "MUST_NOT"))
392
- process.exit(1);
563
+ const failed = hasFailures(issues);
564
+ const compatLine = formatColamdCompat();
565
+ if (options.verbose && !options.json) {
566
+ console.log(chalk.bold("Slides directives (ColaMD 2.7.13):"));
567
+ console.log(issues.length === 0
568
+ ? chalk.green(" ✔ 指令语法、页首规则、内容契约与 slide-css 白名单校验通过")
569
+ : summarizeIssues(issues));
570
+ if (failed)
571
+ process.exitCode = 1;
572
+ return;
573
+ }
574
+ emit({ json: options.json, verbose: options.verbose }, {
575
+ ok: !failed,
576
+ summary: `${file}: ${failed ? `指令/内容契约失败(${issues.filter((i) => i.level === "MUST" || i.level === "MUST_NOT").length} 项)` : "指令与内容契约通过"} · ${compatLine}`,
577
+ details: [...formatFailures(issues), ...formatWarnings(issues)],
578
+ data: { ok: !failed, file, issues: issues.map((i) => ({ rule: i.ruleId, level: i.level, message: i.message })) },
579
+ });
393
580
  return;
394
581
  }
395
582
  const extract = (name) => {
@@ -404,35 +591,49 @@ program
404
591
  inkDim: extract("--seed-ink-dim"), border: extract("--seed-border"),
405
592
  borderStrong: extract("--seed-border-strong"),
406
593
  };
407
- console.log(chalk.bold("CSS contract (ColaMD 2.7.13):"));
408
594
  const cssIssues = validateThemeCss(css);
409
- console.log(cssIssues.length === 0 ? chalk.green(" ✔ :root 根块与选择器契约通过") : summarizeIssues(cssIssues));
410
- // Platform compatibility report — surfaces the installed
411
- // @bytechain.cn/colamd version and contract drift before paradigm checks,
412
- // so a platform upgrade that changes the CSS contract is diagnosed here
413
- // instead of as broken colors at export time.
595
+ const seedIssues = seed.accent ? validateSeedPalette(seed) : [];
596
+ const allIssues = [...cssIssues, ...seedIssues];
597
+ const waivers = parseIssueWaivers(css);
598
+ const issues = allIssues.filter((i) => !waivers.has(i.ruleId));
599
+ const waived = [...new Set(allIssues.filter((i) => waivers.has(i.ruleId)).map((i) => i.ruleId))];
600
+ const failed = hasFailures(issues);
414
601
  const compat = getColamdCompat();
415
602
  const compatLine = formatColamdCompat(compat);
416
- if (compat.status === "exact") {
417
- console.log(chalk.dim(` 平台兼容: ${compatLine}`));
418
- }
419
- else {
420
- console.log(chalk.yellow(` 平台兼容: ${compatLine}`));
421
- }
422
- if (!seed.accent) {
423
- console.log(chalk.yellow("\nNot a seed-palette theme (no --seed-* found); seed checks skipped."));
424
- if (cssIssues.some((i) => i.level === "MUST" || i.level === "MUST_NOT"))
425
- process.exit(1);
603
+ if (options.verbose && !options.json) {
604
+ console.log(chalk.bold("CSS contract (ColaMD 2.7.13):"));
605
+ console.log(cssIssues.filter((i) => !waivers.has(i.ruleId)).length === 0 ? chalk.green(" ✔ :root 根块与选择器契约通过") : summarizeIssues(cssIssues.filter((i) => !waivers.has(i.ruleId))));
606
+ console.log(compat.status === "exact" ? chalk.dim(` 平台兼容: ${compatLine}`) : chalk.yellow(` 平台兼容: ${compatLine}`));
607
+ if (waived.length > 0)
608
+ console.log(chalk.dim(` 已备案豁免: ${waived.join(", ")}(文件头 colamd-allow)`));
609
+ if (!seed.accent) {
610
+ console.log(chalk.yellow("\nNot a seed-palette theme (no --seed-* found); seed checks skipped."));
611
+ if (failed)
612
+ process.exitCode = 1;
613
+ return;
614
+ }
615
+ console.log(chalk.bold("\nSeed palette:"));
616
+ for (const [k, v] of Object.entries(seed))
617
+ console.log(` ${chalk.dim(k.padEnd(18))} ${v}`);
618
+ const activeSeed = seedIssues.filter((i) => !waivers.has(i.ruleId));
619
+ console.log(chalk.bold(`\nParadigm validation (${activeSeed.length} issues):`));
620
+ console.log(summarizeIssues(activeSeed));
621
+ if (failed)
622
+ process.exitCode = 1;
426
623
  return;
427
624
  }
428
- console.log(chalk.bold("\nSeed palette:"));
429
- for (const [k, v] of Object.entries(seed))
430
- console.log(` ${chalk.dim(k.padEnd(18))} ${v}`);
431
- const issues = validateSeedPalette(seed);
432
- console.log(chalk.bold(`\nParadigm validation (${issues.length} issues):`));
433
- console.log(summarizeIssues(issues));
434
- if (issues.filter((i) => i.level === "MUST" || i.level === "MUST_NOT").length > 0)
435
- process.exit(1);
625
+ emit({ json: options.json, verbose: options.verbose }, {
626
+ ok: !failed,
627
+ summary: `${file}: ${failed ? `CSS 契约失败(${issues.filter((i) => i.level === "MUST" || i.level === "MUST_NOT").length} 项)` : "CSS 契约通过"} · ${compatLine}`,
628
+ details: [...formatFailures(issues), ...formatWarnings(issues)],
629
+ data: {
630
+ ok: !failed,
631
+ file,
632
+ compat: compatLine,
633
+ issues: issues.map((i) => ({ rule: i.ruleId, level: i.level, message: i.message })),
634
+ ...(waived.length > 0 ? { waived } : {}),
635
+ },
636
+ });
436
637
  });
437
638
  // ── check-fonts ──
438
639
  program