zcode-app-cli 3.3.5-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 (169) hide show
  1. package/LICENSE +24 -0
  2. package/README.md +642 -0
  3. package/bin/zcode.js +848 -0
  4. package/config.example.json +110 -0
  5. package/package.json +81 -0
  6. package/vendor/.node-bundle-meta.json +6 -0
  7. package/vendor/extraction.json +11 -0
  8. package/vendor/node_modules/@zcode/tui/dist/index.js +161875 -0
  9. package/vendor/node_modules/@zcode/tui/package.json +14 -0
  10. package/vendor/packages/android-emulator-plugin/.mcp.json +19 -0
  11. package/vendor/packages/android-emulator-plugin/.zcode-plugin/plugin.json +63 -0
  12. package/vendor/packages/android-emulator-plugin/README.md +134 -0
  13. package/vendor/packages/android-emulator-plugin/commands/android-dev.md +11 -0
  14. package/vendor/packages/android-emulator-plugin/dist/lib/path.d.ts +4 -0
  15. package/vendor/packages/android-emulator-plugin/dist/lib/path.js +17 -0
  16. package/vendor/packages/android-emulator-plugin/dist/lib/result.d.ts +5 -0
  17. package/vendor/packages/android-emulator-plugin/dist/lib/result.js +22 -0
  18. package/vendor/packages/android-emulator-plugin/dist/lib/run.d.ts +18 -0
  19. package/vendor/packages/android-emulator-plugin/dist/lib/run.js +99 -0
  20. package/vendor/packages/android-emulator-plugin/dist/mcp/server.d.ts +3 -0
  21. package/vendor/packages/android-emulator-plugin/dist/mcp/server.js +47607 -0
  22. package/vendor/packages/android-emulator-plugin/dist/providers/app.d.ts +39 -0
  23. package/vendor/packages/android-emulator-plugin/dist/providers/app.js +50 -0
  24. package/vendor/packages/android-emulator-plugin/dist/providers/avd.d.ts +37 -0
  25. package/vendor/packages/android-emulator-plugin/dist/providers/avd.js +185 -0
  26. package/vendor/packages/android-emulator-plugin/dist/providers/build.d.ts +68 -0
  27. package/vendor/packages/android-emulator-plugin/dist/providers/build.js +131 -0
  28. package/vendor/packages/android-emulator-plugin/dist/providers/config.d.ts +7 -0
  29. package/vendor/packages/android-emulator-plugin/dist/providers/config.js +29 -0
  30. package/vendor/packages/android-emulator-plugin/dist/providers/device.d.ts +20 -0
  31. package/vendor/packages/android-emulator-plugin/dist/providers/device.js +91 -0
  32. package/vendor/packages/android-emulator-plugin/dist/providers/logs.d.ts +15 -0
  33. package/vendor/packages/android-emulator-plugin/dist/providers/logs.js +31 -0
  34. package/vendor/packages/android-emulator-plugin/dist/providers/preflight.d.ts +15 -0
  35. package/vendor/packages/android-emulator-plugin/dist/providers/preflight.js +123 -0
  36. package/vendor/packages/android-emulator-plugin/dist/providers/project-template.d.ts +13 -0
  37. package/vendor/packages/android-emulator-plugin/dist/providers/project-template.js +211 -0
  38. package/vendor/packages/android-emulator-plugin/dist/providers/project.d.ts +33 -0
  39. package/vendor/packages/android-emulator-plugin/dist/providers/project.js +195 -0
  40. package/vendor/packages/android-emulator-plugin/dist/providers/screenshot.d.ts +14 -0
  41. package/vendor/packages/android-emulator-plugin/dist/providers/screenshot.js +73 -0
  42. package/vendor/packages/android-emulator-plugin/dist/providers/sdk.d.ts +14 -0
  43. package/vendor/packages/android-emulator-plugin/dist/providers/sdk.js +185 -0
  44. package/vendor/packages/android-emulator-plugin/dist/providers/ui.d.ts +92 -0
  45. package/vendor/packages/android-emulator-plugin/dist/providers/ui.js +146 -0
  46. package/vendor/packages/android-emulator-plugin/hooks/hooks.json +3 -0
  47. package/vendor/packages/android-emulator-plugin/package.json +35 -0
  48. package/vendor/packages/android-emulator-plugin/skills/android-dev/INSTALL_ENVIRONMENT.md +357 -0
  49. package/vendor/packages/android-emulator-plugin/skills/android-dev/SKILL.md +73 -0
  50. package/vendor/packages/android-emulator-plugin/templates/compose-app/README.md +5 -0
  51. package/vendor/packages/document-skills-plugin/.zcode-plugin/plugin.json +8 -0
  52. package/vendor/packages/document-skills-plugin/package.json +8 -0
  53. package/vendor/packages/document-skills-plugin/skills/docx/LICENSE.txt +13 -0
  54. package/vendor/packages/document-skills-plugin/skills/docx/SKILL.md +201 -0
  55. package/vendor/packages/document-skills-plugin/skills/docx/references/chart-templates.md +386 -0
  56. package/vendor/packages/document-skills-plugin/skills/docx/references/common-rules.md +419 -0
  57. package/vendor/packages/document-skills-plugin/skills/docx/references/decorations.md +537 -0
  58. package/vendor/packages/document-skills-plugin/skills/docx/references/design-system.md +1797 -0
  59. package/vendor/packages/document-skills-plugin/skills/docx/references/docx-js-advanced.md +257 -0
  60. package/vendor/packages/document-skills-plugin/skills/docx/references/docx-js-core.md +332 -0
  61. package/vendor/packages/document-skills-plugin/skills/docx/references/faq.md +323 -0
  62. package/vendor/packages/document-skills-plugin/skills/docx/references/math-formulas.md +276 -0
  63. package/vendor/packages/document-skills-plugin/skills/docx/references/ooxml.md +222 -0
  64. package/vendor/packages/document-skills-plugin/skills/docx/references/toc.md +264 -0
  65. package/vendor/packages/document-skills-plugin/skills/docx/routes/comment.md +88 -0
  66. package/vendor/packages/document-skills-plugin/skills/docx/routes/create.md +207 -0
  67. package/vendor/packages/document-skills-plugin/skills/docx/routes/edit.md +115 -0
  68. package/vendor/packages/document-skills-plugin/skills/docx/routes/format.md +120 -0
  69. package/vendor/packages/document-skills-plugin/skills/docx/routes/read.md +114 -0
  70. package/vendor/packages/document-skills-plugin/skills/docx/scenes/academic.md +783 -0
  71. package/vendor/packages/document-skills-plugin/skills/docx/scenes/contract.md +463 -0
  72. package/vendor/packages/document-skills-plugin/skills/docx/scenes/copywriting.md +139 -0
  73. package/vendor/packages/document-skills-plugin/skills/docx/scenes/exam.md +698 -0
  74. package/vendor/packages/document-skills-plugin/skills/docx/scenes/official-doc.md +411 -0
  75. package/vendor/packages/document-skills-plugin/skills/docx/scenes/report.md +340 -0
  76. package/vendor/packages/document-skills-plugin/skills/docx/scenes/resume.md +534 -0
  77. package/vendor/packages/document-skills-plugin/skills/docx/scripts/__init__.py +1 -0
  78. package/vendor/packages/document-skills-plugin/skills/docx/scripts/add_toc_placeholders.py +749 -0
  79. package/vendor/packages/document-skills-plugin/skills/docx/scripts/document.py +1333 -0
  80. package/vendor/packages/document-skills-plugin/skills/docx/scripts/postcheck.py +807 -0
  81. package/vendor/packages/document-skills-plugin/skills/docx/scripts/templates/comments.xml +3 -0
  82. package/vendor/packages/document-skills-plugin/skills/docx/scripts/templates/commentsExtended.xml +3 -0
  83. package/vendor/packages/document-skills-plugin/skills/docx/scripts/templates/commentsExtensible.xml +3 -0
  84. package/vendor/packages/document-skills-plugin/skills/docx/scripts/templates/commentsIds.xml +3 -0
  85. package/vendor/packages/document-skills-plugin/skills/docx/scripts/templates/people.xml +3 -0
  86. package/vendor/packages/document-skills-plugin/skills/docx/scripts/utilities.py +374 -0
  87. package/vendor/packages/document-skills-plugin/skills/docx/setup.sh +177 -0
  88. package/vendor/packages/document-skills-plugin/skills/pdf/LICENSE.txt +13 -0
  89. package/vendor/packages/document-skills-plugin/skills/pdf/SKILL.md +919 -0
  90. package/vendor/packages/document-skills-plugin/skills/pdf/briefs/academic.md +1058 -0
  91. package/vendor/packages/document-skills-plugin/skills/pdf/briefs/creative.md +770 -0
  92. package/vendor/packages/document-skills-plugin/skills/pdf/briefs/poster.md +702 -0
  93. package/vendor/packages/document-skills-plugin/skills/pdf/briefs/process-advanced.md +284 -0
  94. package/vendor/packages/document-skills-plugin/skills/pdf/briefs/process.md +319 -0
  95. package/vendor/packages/document-skills-plugin/skills/pdf/briefs/report.md +1659 -0
  96. package/vendor/packages/document-skills-plugin/skills/pdf/configs/components.md +153 -0
  97. package/vendor/packages/document-skills-plugin/skills/pdf/configs/fonts.md +93 -0
  98. package/vendor/packages/document-skills-plugin/skills/pdf/configs/visual_framework.md +263 -0
  99. package/vendor/packages/document-skills-plugin/skills/pdf/references/resume-academic.tex +130 -0
  100. package/vendor/packages/document-skills-plugin/skills/pdf/references/resume-altacv.tex +190 -0
  101. package/vendor/packages/document-skills-plugin/skills/pdf/scripts/cover_validate.js +367 -0
  102. package/vendor/packages/document-skills-plugin/skills/pdf/scripts/design_engine.py +2816 -0
  103. package/vendor/packages/document-skills-plugin/skills/pdf/scripts/html2pdf-next.js +754 -0
  104. package/vendor/packages/document-skills-plugin/skills/pdf/scripts/html2poster.js +256 -0
  105. package/vendor/packages/document-skills-plugin/skills/pdf/scripts/pdf.py +2959 -0
  106. package/vendor/packages/document-skills-plugin/skills/pdf/scripts/pdf_qa.py +901 -0
  107. package/vendor/packages/document-skills-plugin/skills/pdf/scripts/poster_validate.py +1337 -0
  108. package/vendor/packages/document-skills-plugin/skills/pdf/scripts/setup.sh +269 -0
  109. package/vendor/packages/document-skills-plugin/skills/pdf/scripts/toc_validate.py +2075 -0
  110. package/vendor/packages/document-skills-plugin/skills/pdf/typesetting/charts.md +320 -0
  111. package/vendor/packages/document-skills-plugin/skills/pdf/typesetting/cover-backgrounds.md +384 -0
  112. package/vendor/packages/document-skills-plugin/skills/pdf/typesetting/cover.md +1442 -0
  113. package/vendor/packages/document-skills-plugin/skills/pdf/typesetting/fill-engine.md +527 -0
  114. package/vendor/packages/document-skills-plugin/skills/pdf/typesetting/geometry.md +142 -0
  115. package/vendor/packages/document-skills-plugin/skills/pdf/typesetting/overflow.md +630 -0
  116. package/vendor/packages/document-skills-plugin/skills/pdf/typesetting/pagination.md +367 -0
  117. package/vendor/packages/document-skills-plugin/skills/pdf/typesetting/palette.md +217 -0
  118. package/vendor/packages/document-skills-plugin/skills/pdf/typesetting/typography.md +20 -0
  119. package/vendor/packages/ios-simulator-plugin/.mcp.json +15 -0
  120. package/vendor/packages/ios-simulator-plugin/.zcode-plugin/plugin.json +34 -0
  121. package/vendor/packages/ios-simulator-plugin/README.md +111 -0
  122. package/vendor/packages/ios-simulator-plugin/commands/ios-dev.md +11 -0
  123. package/vendor/packages/ios-simulator-plugin/dist/lib/path.d.ts +4 -0
  124. package/vendor/packages/ios-simulator-plugin/dist/lib/path.js +18 -0
  125. package/vendor/packages/ios-simulator-plugin/dist/lib/result.d.ts +5 -0
  126. package/vendor/packages/ios-simulator-plugin/dist/lib/result.js +20 -0
  127. package/vendor/packages/ios-simulator-plugin/dist/lib/run.d.ts +17 -0
  128. package/vendor/packages/ios-simulator-plugin/dist/lib/run.js +83 -0
  129. package/vendor/packages/ios-simulator-plugin/dist/mcp/server.d.ts +3 -0
  130. package/vendor/packages/ios-simulator-plugin/dist/mcp/server.js +46833 -0
  131. package/vendor/packages/ios-simulator-plugin/dist/providers/build.d.ts +112 -0
  132. package/vendor/packages/ios-simulator-plugin/dist/providers/build.js +99 -0
  133. package/vendor/packages/ios-simulator-plugin/dist/providers/logs.d.ts +21 -0
  134. package/vendor/packages/ios-simulator-plugin/dist/providers/logs.js +26 -0
  135. package/vendor/packages/ios-simulator-plugin/dist/providers/preflight.d.ts +12 -0
  136. package/vendor/packages/ios-simulator-plugin/dist/providers/preflight.js +62 -0
  137. package/vendor/packages/ios-simulator-plugin/dist/providers/project.d.ts +35 -0
  138. package/vendor/packages/ios-simulator-plugin/dist/providers/project.js +288 -0
  139. package/vendor/packages/ios-simulator-plugin/dist/providers/screenshot.d.ts +22 -0
  140. package/vendor/packages/ios-simulator-plugin/dist/providers/screenshot.js +30 -0
  141. package/vendor/packages/ios-simulator-plugin/dist/providers/sim.d.ts +60 -0
  142. package/vendor/packages/ios-simulator-plugin/dist/providers/sim.js +116 -0
  143. package/vendor/packages/ios-simulator-plugin/dist/providers/ui.d.ts +57 -0
  144. package/vendor/packages/ios-simulator-plugin/dist/providers/ui.js +67 -0
  145. package/vendor/packages/ios-simulator-plugin/hooks/hooks.json +3 -0
  146. package/vendor/packages/ios-simulator-plugin/package.json +35 -0
  147. package/vendor/packages/ios-simulator-plugin/skills/ios-dev/SKILL.md +45 -0
  148. package/vendor/packages/ios-simulator-plugin/templates/swiftui-app/README.md +5 -0
  149. package/vendor/packages/restore-legacy-sessions-plugin/.zcode-plugin/plugin.json +9 -0
  150. package/vendor/packages/restore-legacy-sessions-plugin/README.md +35 -0
  151. package/vendor/packages/restore-legacy-sessions-plugin/commands/restore-legacy-sessions.md +11 -0
  152. package/vendor/packages/restore-legacy-sessions-plugin/package.json +8 -0
  153. package/vendor/packages/restore-legacy-sessions-plugin/skills/restore-legacy-sessions/SKILL.md +92 -0
  154. package/vendor/packages/restore-legacy-sessions-plugin/skills/restore-legacy-sessions/scripts/restore-conversation.mjs +648 -0
  155. package/vendor/packages/restore-legacy-sessions-plugin/skills/restore-legacy-sessions/scripts/scan-legacy-sessions.mjs +422 -0
  156. package/vendor/packages/skill-creator-plugin/.zcode-plugin/plugin.json +8 -0
  157. package/vendor/packages/skill-creator-plugin/package.json +8 -0
  158. package/vendor/packages/skill-creator-plugin/skills/skill-creator/SKILL.md +159 -0
  159. package/vendor/packages/zcode-guide-plugin/.zcode-plugin/plugin.json +8 -0
  160. package/vendor/packages/zcode-guide-plugin/README.md +22 -0
  161. package/vendor/packages/zcode-guide-plugin/package.json +8 -0
  162. package/vendor/packages/zcode-guide-plugin/skills/diagnosing-commands/SKILL.md +66 -0
  163. package/vendor/packages/zcode-guide-plugin/skills/diagnosing-hooks/SKILL.md +66 -0
  164. package/vendor/packages/zcode-guide-plugin/skills/diagnosing-mcp/SKILL.md +97 -0
  165. package/vendor/packages/zcode-guide-plugin/skills/diagnosing-plugins/SKILL.md +59 -0
  166. package/vendor/packages/zcode-guide-plugin/skills/diagnosing-skills/SKILL.md +61 -0
  167. package/vendor/packages/zcode-guide-plugin/skills/zcode-configuration-guide/SKILL.md +99 -0
  168. package/vendor/zcode.cjs +2926 -0
  169. package/zcode-runtime.lock.json +8 -0
@@ -0,0 +1,919 @@
1
+ ---
2
+ name: pdf
3
+ metadata:
4
+ author: Z.AI
5
+ version: "1.0"
6
+ description: >
7
+ Professional PDF toolkit covering four production workflows: reports, creative visuals,
8
+ academic LaTeX, and existing PDF processing. Routes automatically by document type and
9
+ supports reports, posters, papers, resumes, extraction, merging, splitting, form filling,
10
+ and format conversion.
11
+ license: Proprietary. LICENSE.txt has complete terms
12
+ ---
13
+
14
+ # PDF - Document Production Workbench
15
+
16
+ ## Quick Setup
17
+
18
+ ```bash
19
+ bash "$PDF_SKILL_DIR/scripts/setup.sh" # Interactive environment check + install
20
+ python3 "$PDF_SKILL_DIR/scripts/pdf.py" env.check # Detailed dependency status (JSON: add -j)
21
+ python3 "$PDF_SKILL_DIR/scripts/pdf.py" env.fix # Auto-install missing Python packages
22
+ ```
23
+
24
+ ## Triage
25
+
26
+ Determine task weight to control how much context to load:
27
+
28
+ | Weight | Triggers | What to Load |
29
+ |--------|----------|--------------|
30
+ | **Light** | Format conversion, form fill, text extract, merge/split, simple certificate | SKILL.md + `briefs/process.md` only |
31
+ | **Standard** | Multi-page report, poster, academic paper, resume, reformat - any document with design decisions | SKILL.md + matched brief + typesetting assets on demand |
32
+
33
+ Light tasks skip typesetting files entirely. Standard tasks load them on demand per the brief's instructions.
34
+
35
+ ### ⚠️ Pre-Routing Checks (run BEFORE matching brief)
36
+
37
+ 1. **Emoji Check** - Scan user content for intentional emoji (decorative 📊🎯🔥, not OS-level emoji input). If found → **force Creative brief** regardless of document type. ReportLab renders emoji as □ squares; LaTeX drops them entirely.
38
+ 2. **CJK Check** - Chinese/Japanese/Korean content needs font coverage. Report brief must use `UniSong`/`UniHei` registered fonts; Creative brief must load Google Fonts Noto Sans SC with `font-display: swap`; Academic brief must use `\usepackage{ctex}`.
39
+ 3. **Size Check** - Non-standard page sizes (not A4/Letter/A3) → prefer Creative brief (Playwright handles any dimension). ReportLab can do custom sizes but pagination is manual.
40
+ 4. **Character Safety Check** - Before writing any content string, scan for Japanese kana (の、が、は etc.), unusual Unicode symbols, or non-CJK characters that may corrupt during encoding transit ( Especially when code is written via heredoc/base64/LLM output). Replace with plain Chinese equivalents: `の`→`之/的/缔`, `々`→omit or write full character. **If content must preserve Japanese, use only standard CJK Unified Ideographs (U+4E00-U+9FFF) and common kana; avoid rare/private-use codepoints.**
41
+
42
+ ---
43
+
44
+ ## Briefing
45
+
46
+ Match the user's intent to a production brief. Each brief contains the full workflow, tech stack specifics, and references to shared typesetting assets.
47
+
48
+ ```
49
+ User Request
50
+ │
51
+ ├─ Work with existing PDF? ─────────────┬─ Extract/merge/split/fill/convert → briefs/process.md
52
+ │ ├─ Reformat/redesign → briefs/process.md (extract) → delegate to report or creative brief
53
+ │ └─ User provides a PDF template/reference to match style
54
+ │ → briefs/process.md "Template-Guided Reformat" → delegate to matched brief
55
+ │
56
+ ├─ Report / proposal / white paper / contract / analysis?
57
+ │ └─ ────────────────────────────────── → briefs/report.md (ReportLab)
58
+ │
59
+ ├─ Poster / invitation / infographic / dashboard / creative layout?
60
+ │ └─ ────────────────────────────────── → briefs/creative.md (Playwright)
61
+ │
62
+ ├─ Academic paper / thesis / math / IEEE / ACM / LaTeX?
63
+ │ └─ ────────────────────────────────── → briefs/academic.md (Tectonic)
64
+ │
65
+ ├─ Math-heavy doc / TikZ diagram / algorithm pseudocode / Beamer slides?
66
+ │ └─ ────────────────────────────────── → briefs/academic.md (Tectonic, Scenarios A-D)
67
+ │
68
+ ├─ Document needs complex embedded diagrams (flowcharts, architecture, neural nets)?
69
+ │ └─ Route by target brief:
70
+ │ ├─ Report → Playwright+CSS → PNG → ReportLab Image() flowable
71
+ │ ├─ Creative → directly in HTML (CSS flexbox/grid + connectors)
72
+ │ └─ Academic → complexity-based:
73
+ │ ├─ Simple (≤6 nodes, linear/tree) → TikZ native (vector)
74
+ │ └─ Complex (>6 nodes, branches, annotations) → Playwright+CSS → PNG → \includegraphics
75
+ │
76
+ └─ Resume / CV?
77
+ ├─ ATS-safe / corporate ─────────── → briefs/report.md (resume sub-section)
78
+ ├─ Creative / design industry ────── → briefs/creative.md (resume sub-section)
79
+ └─ Academic CV / publications ────── → briefs/academic.md (resume sub-section)
80
+ ```
81
+
82
+ ### Detection Keywords
83
+
84
+ | Brief | Keywords |
85
+ |-------|----------|
86
+ | Report | 报告, report, 分析, analysis, 白皮书, white paper, 提案, proposal, 合同, contract, 方案, 规划, 发票, invoice, 收据, receipt, 试卷, exam, quiz, test paper, 练习, exercise, worksheet, 考试, 测验 |
87
+ | Creative | 海报, poster, 邀请函, invitation, 信息图, infographic, 仪表盘, dashboard, 传单, flyer, 证书, certificate, 菜单, menu, 名片, business card, 奖状, award, 标签, label, 信封, envelope, 贺卡, greeting card |
88
+ | Creative (Poster) | 海报, poster, 传单, flyer, 宣传页, 宣传单 → additionally load `briefs/poster.md` scene layer rules |
89
+ | Academic | 论文, paper, 学术, academic, LaTeX, 数学, math, IEEE, ACM, 毕业, thesis, 研究, research, Beamer, slides, 开题报告, 学位, dissertation, proposal |
90
+ | Process | 提取, extract, 合并, merge, 拆分, split, 填写, fill, 转换, convert, OCR, 重排, reformat, 重新排版, redesign, 模板, template, 参照, 照着这个做, match this style, 压缩, compress, 水印, watermark, 加密, encrypt, 签名, sign |
91
+
92
+ ### Complete Scenario Routing Matrix
93
+
94
+ Below is an exhaustive map of every known PDF request type to its handling strategy. If a scenario is not listed, route to the closest match or ask the user.
95
+
96
+ #### 📄 Creation (Generate PDF from scratch)
97
+
98
+ | Scenario | Route | Notes |
99
+ |----------|-------|-------|
100
+ | Report / white paper / analysis | report.md | ReportLab structured document |
101
+ | Report with emoji | **creative.md** | 🚨 Emoji rule override |
102
+ | Business proposal | report.md | Structured + data tables |
103
+ | Contract / legal document | report.md | Add signature placeholders (dotted line + label) |
104
+ | Invoice / receipt | report.md | Table-heavy, precision alignment |
105
+ | Exam / quiz / test paper / worksheet | report.md | Indented options, answer space reservation, structured numbering (see Exam Paper Rules in report.md) |
106
+ | Math exam / math worksheet (with formulas/equations) | academic.md | LaTeX for proper math typesetting. See §Exam Paper Rules in academic.md |
107
+ | Poster / flyer | creative.md + **poster.md** | Visual design + poster density/sizing rules |
108
+ | Invitation / greeting card | creative.md | Non-standard size, decorative |
109
+ | Certificate / award | creative.md | Single page, centered layout, decorative border |
110
+ | Business card | creative.md | Tiny size (90×54mm), Playwright native support |
111
+ | Envelope / label | creative.md | Non-standard size, simple layout |
112
+ | Menu / price list | creative.md | Visual layout + may contain emoji |
113
+ | Resume (ATS) | report.md | Plain text structure |
114
+ | Resume (creative) | creative.md | Visual design |
115
+ | Resume (academic CV) | academic.md | Publication list + BibTeX |
116
+ | Academic paper | academic.md | LaTeX/Tectonic |
117
+ | Math-heavy document | academic.md | LaTeX typesetting |
118
+ | Presentation / PPT-style | creative.md | Landscape (1280×720), one topic per page |
119
+ | Book / long document | report.md | Add TOC + chapter numbering, validate with toc_validate.py |
120
+ | CJK vertical text | creative.md | HTML `writing-mode: vertical-rl` + `text-orientation: upright` + `white-space: nowrap` + Playwright |
121
+ | RTL document (Arabic/Hebrew) | creative.md | HTML `dir="rtl"` + Playwright |
122
+ | Batch generation (mail merge) | report.md | Python loop + template variable substitution |
123
+ | Infographic | creative.md | Data visualization + design |
124
+ | Calendar / schedule | creative.md | Grid layout + custom dimensions |
125
+
126
+ #### 🔧 Processing (Manipulate existing PDF)
127
+
128
+ | Scenario | Route | Command / Method |
129
+ |----------|-------|------------------|
130
+ | Merge multiple PDFs | process.md | `pages.merge a.pdf b.pdf -o out.pdf` |
131
+ | Split PDF | process.md | `pages.split input.pdf -o ./output/` |
132
+ | Extract text | process.md | `extract.text input.pdf` |
133
+ | Extract tables | process.md | `extract.table input.pdf` |
134
+ | Extract images | process.md | `extract.image input.pdf` |
135
+ | Fill forms | process.md | `form.fill input.pdf` |
136
+ | Office → PDF | process.md | `convert.office input.docx` |
137
+ | HTML → PDF (documents) | process.md | `convert.html input.html` or `node html2pdf-next.js` |
138
+ | HTML → PDF (posters) | poster.md | `node html2poster.js poster.html` |
139
+ | Image → PDF | process.md | pikepdf: one image per page, embed as XObject |
140
+ | PDF → image | process-advanced.md | pypdfium2 render each page to PNG |
141
+ | Encrypt / decrypt | process-advanced.md | pikepdf encryption |
142
+ | Add watermark | process.md | pikepdf overlay: create watermark page → merge onto each page |
143
+ | Compress PDF | process.md | Ghostscript: `gs -sDEVICE=pdfwrite -dPDFSETTINGS=/screen` |
144
+ | OCR scanned PDF | process-advanced.md | ocrmypdf or Tesseract |
145
+ | Rotate pages | process.md | `pages.rotate input.pdf 90 -o out.pdf` |
146
+ | Crop pages | process.md | `pages.crop input.pdf l,b,r,t -o out.pdf` |
147
+ | Remove blank pages | process.md | `pages.clean input.pdf` |
148
+ | Reformat by template | process.md → delegate | Extract content → regenerate via report/creative |
149
+ | PDF diff / compare | process.md | `diff-pdf` CLI or Python per-page text comparison |
150
+ | Digital signature | process.md | `pyhanko` library (requires extra install) |
151
+ | Edit metadata | process.md | `meta.set input.pdf -o out.pdf -d '{...}'` |
152
+
153
+ ### Special Routing Rules
154
+
155
+ **🚨 Emoji rule (CRITICAL - check FIRST)**: Content with intentional emoji (📊🎯🔥💡 etc.) → force **briefs/creative.md** regardless of document type. ReportLab renders emoji as □ squares; LaTeX silently drops them. This rule overrides all other routing. Even if the user says "report" - if the content has emoji, use Creative pipeline.
156
+
157
+ **Non-standard page size rule**: Dimensions other than A4/Letter/A3 → strongly prefer **briefs/creative.md**. Playwright handles any arbitrary page size natively. ReportLab requires manual pagination math.
158
+
159
+ **Academic auto-detect**: Papers, theses, or heavy math → **briefs/academic.md** even without explicit "LaTeX" mention.
160
+
161
+ **Template-guided rule**: When the user uploads a PDF and says "match this template" / "follow this style" / "reformat like this" → **briefs/process.md** Template-Guided Reformat section. This is a Standard triage (not Light), because it involves design decisions.
162
+
163
+ **Resume routing**: Default to Report brief (ATS-safe). Creative industry → Creative brief. Academic CV with publications → Academic brief.
164
+
165
+ ---
166
+
167
+ ## Shared Assets
168
+
169
+ These are referenced by multiple briefs. **Do not load upfront** - each brief tells you when and what to load.
170
+
171
+ | Asset | Path | Used By | Purpose |
172
+ |-------|------|---------|---------|
173
+ | Palette & Typography | `typesetting/palette.md` | Report, Creative | Color system, font rules, anti-patterns, spacing |
174
+ | Cover Layout System V2.1 | `typesetting/cover.md` | **Report + Creative + Academic** | 7 industrial-grade templates with absolute anchor grid, Z-index layers, typography weight system, mandatory Summary Block, code-level safety (5 checks), base unit `U = W*0.05`. **Unified HTML/Playwright cover system for all routes.** |
175
+ | Chart Styling & Anti-Stacking | `typesetting/charts.md` | Report, Creative, Academic | Chart defaults, collision prevention, axis/grid/legend rules |
176
+ | Overflow Prevention | `typesetting/overflow.md` | Report, Creative, Academic | Bounding box system, text/image/table overflow prevention, fallback strategies |
177
+ | **Fill Engine (Anti-Void)** | `typesetting/fill-engine.md` | **Report, Creative, Academic** | **Anti-Void Engine V2.0: font floor enforcement, fill ratio calculation, paragraph inflation, component elevation, Y-axis golden-ratio anchoring** |
178
+ | Pagination & Flow Control | `typesetting/pagination.md` | Report, Creative | Cross-page integrity, orphan/widow control, CJK punctuation rules |
179
+ | Typography System | `typesetting/typography.md` | Report, Creative | Font size scale, line-height, spacing hierarchy |
180
+ | Geometric Anchors | `typesetting/geometry.md` | Creative + Report | Decorative geometric elements, anchor placement rules |
181
+ | Cover Backgrounds | `typesetting/cover-backgrounds.md` | **Report + Creative + Academic** | Cover background rendering, transparency constraints |
182
+ | Visual Framework | `configs/visual_framework.md` | Creative | Palette mode, color harmony, SVG background params |
183
+ | Components Library | `configs/components.md` | Creative | Non-grid composition components (floating cards, oversized text, etc.) |
184
+ | Font Stacks | `configs/fonts.md` | All pipelines | Font families per pipeline (Google Fonts, ReportLab, LaTeX) |
185
+
186
+ ---
187
+
188
+ ## Content Rules
189
+
190
+ - **Language**: Match user's query language. Chinese query → Chinese PDF.
191
+ - **Page/word count**: Respect explicit constraints (±20%). Unspecified → completeness over brevity.
192
+ - **Outline**: User-provided outlines are sacred. No reordering without asking.
193
+ - **Citations**: No fabrication. Chinese → GB/T 7714, English → APA. Search to verify.
194
+ - **Multi-part requests**: Generate ALL parts - never silently drop a component.
195
+
196
+ ### HTML Image Source Path Rules
197
+
198
+ When embedding images in HTML documents (Creative pipeline, Playwright-rendered diagrams, or any HTML→PDF flow):
199
+
200
+ | Image location | `<img src>` value | Example |
201
+ |---|---|---|
202
+ | **Local file** | **Relative path** from the HTML file's directory | `<img src="images/chart.png">` or `<img src="./diagram.png">` |
203
+ | **Remote URL** | Full URL (no change needed) | `<img src="https://example.com/photo.jpg">` |
204
+
205
+ **Iron rules:**
206
+ 1. **NEVER use absolute paths** for local files in HTML `<img>`, `<source>`, CSS `url()`, or any other asset reference (e.g. `/Users/alice/project/img.png`). Absolute paths break portability across machines and environments.
207
+ 2. **Always use relative paths** anchored to the HTML file's own directory. If the image lives in a subdirectory, use `images/foo.png` or `./images/foo.png`.
208
+ 3. **Remote URLs (`http://` / `https://`) are fine as-is** — do not convert them to local paths.
209
+ 4. When generating HTML from a script or blueprint, ensure all referenced assets are either (a) in the same directory as the output HTML, or (b) in a clearly named subdirectory (e.g. `assets/`, `images/`), and referenced with relative paths.
210
+ 5. If a build script needs to resolve paths programmatically, compute relative paths at generation time (e.g. `os.path.relpath(image_path, html_dir)`) rather than embedding absolute filesystem paths.
211
+
212
+ ---
213
+
214
+ ## Figure & Diagram Embedding (All Briefs)
215
+
216
+ ### Iron Rule: Figures Are Block-Level
217
+
218
+ Figures, diagrams, and charts MUST be independent block elements occupying full width. **Never** float/wrap figures alongside body text - this causes the text-diagram overlap badcase.
219
+
220
+ | Brief | Correct embedding | Forbidden |
221
+ |-------|-------------------|-----------|
222
+ | Report (ReportLab) | `story.append(Image(...))` as standalone Flowable | Placing images inside Paragraph text, simulating float |
223
+ | Creative (Playwright) | `<figure style="display:block; width:100%; margin:2em auto">` | `float:right`, `display:flex` with text, `wrapfigure`-style CSS |
224
+ | Academic (LaTeX) | `\begin{figure}[t] ... \end{figure}` | Bare `\includegraphics` in text body (no figure env), bare `tikzpicture` in multi-column |
225
+
226
+ ### Complex Diagram Strategy
227
+
228
+ When a diagram has **>12 nodes, >3 subgroups, or intricate connections**, do NOT try to render it as one giant figure. Instead:
229
+
230
+ 1. **Table for details** - structured data (phases, components, specs) goes into a proper table
231
+ 2. **Simplified overview diagram** - a stripped-down flowchart/Mermaid showing only the top-level flow (≤8 nodes)
232
+ 3. **Cross-reference** - table caption + diagram caption reference each other
233
+
234
+ This "table + simple diagram" pattern prevents:
235
+ - Diagrams overflowing page boundaries
236
+ - Text becoming unreadably small to fit everything
237
+ - Layout engines mishandling oversized graphics
238
+
239
+ ### Diagram Content Quality Rules (Cross-reference: charts)
240
+
241
+ The rules above handle **how** to embed diagrams in PDF. For **what the diagram itself looks like** (node layout, connector routing, color, readability), follow the `charts` skill rules:
242
+
243
+ **Before generating ANY flowchart/diagram for PDF embedding, check these:**
244
+
245
+ 1. **Connectors must not pass through nodes** - If 3+ layers exist, connect adjacent layers only (top→mid, mid→bottom). Never draw top→bottom lines through middle nodes. Use detour paths if cross-layer links are needed.
246
+ 2. **Multiple arrows into one node must not pile up** - Distribute entry points evenly along target edge, or use merge-then-enter pattern (sources converge to a vertical merge line, then single arrow to target).
247
+ 3. **Low-saturation fills only** - Node backgrounds must be pale (`#EFF6FF`, `#F0FDF4`). High-saturation colors (`#3B82F6`, `#10B981`) only for borders or small accents. No children's-art color schemes.
248
+ 4. **Phase titles vs sub-steps must be visually distinct** - Different background color, font size, and font weight. Never same-style boxes for both.
249
+ 5. **Font sizes must be readable at final output size** - Sizes depend on the embedding context:
250
+ | Output context | Node title min | Description min | Label min |
251
+ |---------------|----------------|-----------------|-----------|
252
+ | Standalone PNG (web/presentation, ≥1200px wide) | 14px | 12px | 11px |
253
+ | Embedded in A4 PDF (ReportLab/LaTeX, ~450pt content width) | 10pt | 8pt | 7pt |
254
+ | Embedded in slide deck (landscape, ~720pt wide) | 12pt | 10pt | 9pt |
255
+
256
+ **Principle**: After embedding, the smallest text in the diagram must still be legible when the document is viewed at 100% zoom. If the diagram is scaled down to fit page width, recalculate: `effective_size = original_size × (display_width / canvas_width)`. If effective size drops below the minimum, either increase original font size or reduce diagram complexity.
257
+ 6. **Legend/annotations must not overlap content** - Separate container, ≥ 40px gap from last node, fully within canvas bounds.
258
+
259
+ **For Playwright-rendered diagrams**: Use low-saturation fills (`#EFF6FF`, `#F0FDF4`), CSS flexbox/grid for node layout, SVG `<line>`/`<path>` for connectors, and verify no overlap at final render size.
260
+ **For ReportLab-drawn diagrams**: Same principles apply - use `Drawing()` with explicit coordinates, check node bounding boxes for overlap before finalizing.
261
+
262
+ ### Diagram Generation Strategy (Per-Brief)
263
+
264
+ Diagram rendering depends on the target brief - **NOT** a one-size-fits-all TikZ pipeline.
265
+
266
+ | Target Brief | Diagram Method | Rationale |
267
+ |---|---|---|
268
+ | **Report** (ReportLab) | Playwright+CSS → PNG → `Image()` | No LaTeX compiler in this route; HTML/CSS handles any layout natively |
269
+ | **Creative** (Playwright) | Directly in HTML (CSS flexbox/grid + JS connectors) | Already in browser context |
270
+ | **Academic** (Tectonic) - simple (≤6 nodes) | TikZ native `tikzpicture` | Vector output, font consistency, LaTeX-native |
271
+ | **Academic** (Tectonic) - complex (>6 nodes) | Playwright+CSS → PNG @2× → `\includegraphics` | TikZ branch logic is error-prone for models; 300dpi PNG is publication-ready |
272
+
273
+ **Playwright+CSS diagram pipeline (Report & Academic-complex):**
274
+
275
+ ```bash
276
+ # 1. Write diagram HTML (CSS grid/flexbox + connectors)
277
+ cat > diagram.html << 'EOF'
278
+ <!-- LLM generates: nodes as divs, arrows as SVG/CSS -->
279
+ EOF
280
+
281
+ # 2. Screenshot at 2× for print quality (300dpi equivalent)
282
+ python3 "$PDF_SKILL_DIR/scripts/pdf.py" convert.blueprint diagram.html --device-scale-factor 2 --output diagram.png
283
+ # Or via Playwright directly:
284
+ # page.screenshot(path='diagram.png', scale='device', device_scale_factor=2)
285
+
286
+ # 3a. Embed in ReportLab (Report brief)
287
+ from reportlab.platypus import Image
288
+ img = Image('diagram.png', width=450) # auto height via aspect ratio
289
+ story.append(img)
290
+
291
+ # 3b. Embed in LaTeX (Academic brief, complex diagrams only)
292
+ # \includegraphics[width=\columnwidth]{diagram.png}
293
+ ```
294
+
295
+ **🚫 FORBIDDEN for Report/Creative briefs:** Do NOT use TikZ standalone → compile → pdftoppm → PNG pipeline. This route has no LaTeX compiler and the extra compilation steps are error-prone.
296
+
297
+ **TikZ remains valid ONLY for:**
298
+ - Academic brief with simple diagrams (≤6 nodes, linear/hierarchical)
299
+ - Direct `tikzpicture` embedding in LaTeX documents
300
+ - Math-annotated diagrams where LaTeX math rendering matters
301
+
302
+ See `briefs/academic.md` Scenario B for TikZ templates (simple diagrams only).
303
+
304
+ ---
305
+
306
+ ## Vector Rendering Iron Rule
307
+
308
+ **The final PDF MUST be generated via `page.pdf()` (Playwright) or ReportLab/LaTeX native output - NEVER via screenshot-to-PDF.**
309
+
310
+ | Scenario | Correct Method | Forbidden |
311
+ |----------|---------------|-----------|
312
+ | Creative pipeline (single/multi-page) | `page.pdf()` via `convert.blueprint` or `html2pdf-next.js` | `page.screenshot()` → image → wrap as PDF |
313
+ | Report cover (HTML/Playwright) | `page.pdf()` → merge via pypdf | Screenshot cover → embed as image |
314
+ | Academic cover | `page.pdf()` → merge via pypdf | Screenshot → `\includegraphics` for cover |
315
+ | Full-page posters/infographics | `html2poster.js` (auto overflow:hidden + height measurement + `page.pdf()`) | Any raster pipeline for the final output |
316
+
317
+ **Why:** `page.pdf()` produces vector text + vector shapes. Text remains selectable, sharp at any zoom, and file size is smaller. Screenshot-based PDFs are raster images - blurry when zoomed, unsearchable, and 3-5× larger.
318
+
319
+ **The ONLY place screenshot/PNG embedding is acceptable:**
320
+ - **Diagrams** embedded as sub-elements inside a larger document (e.g., flowcharts in a Report). These use `page.screenshot()` at 2× device scale factor for 300dpi print quality, then embed via `Image()` (ReportLab) or `\includegraphics` (LaTeX).
321
+ - **Chart images** generated by matplotlib/plotly saved as PNG, then embedded.
322
+
323
+ These are sub-elements, not the document itself. The document-level PDF output must always be vector.
324
+
325
+ **Quick test:** Open the generated PDF, zoom to 400%. If text is blurry, you used a screenshot pipeline. Fix it.
326
+
327
+ ### HTML→PDF Engine Selection Rules
328
+
329
+ There are **two dedicated scripts** for HTML→PDF. Choose based on document type:
330
+
331
+ | Document type | Script | Reason |
332
+ |---------------|--------|--------|
333
+ | **Posters, infographics, long-image single-page designs** | `html2poster.js` | Auto overflow:hidden, auto height measurement, zero margin, single-page output |
334
+ | **Cover pages (Report/Academic route)** | `html2poster.js` | Covers are single-page fixed layouts with absolute positioning — same nature as posters. `html2pdf-next.js` would convert absolute→static and destroy the layout |
335
+ | **Multi-page documents, reports, academic papers, resumes** | `html2pdf-next.js` | A4/custom pagination, 20mm margin fallback, cover adaptation, pdf-lib metadata |
336
+ | **Creative pipeline (Blueprint → HTML → PDF)** | `html2pdf-next.js` via `convert.blueprint` | Called internally by design_engine pipeline |
337
+
338
+ #### Poster / Single-Page Long-Image → `html2poster.js`
339
+
340
+ ```bash
341
+ node "$PDF_SKILL_DIR/scripts/html2poster.js" poster.html --output poster.pdf --width 720px
342
+ ```
343
+
344
+ `html2poster.js` automatically:
345
+ - Forces `overflow: hidden` on `.poster` / `.page` containers (clips decorative overflow)
346
+ - Injects `@page { margin: 0 }` (zero margins always)
347
+ - Syncs `html/body` background with poster background color
348
+ - Measures `.poster` scrollHeight and uses it as PDF height
349
+ - Generates a single-page vector PDF with exact content dimensions
350
+
351
+ **Use this for ANY fixed-width, dynamic-height, single-page design.**
352
+
353
+ #### Documents / Multi-Page → `html2pdf-next.js`
354
+
355
+ ```bash
356
+ node "$PDF_SKILL_DIR/scripts/html2pdf-next.js" input.html --output output.pdf --width 210mm --height 297mm
357
+ # Or via pdf.py wrapper:
358
+ python3 "$PDF_SKILL_DIR/scripts/pdf.py" convert.html input.html --output output.pdf
359
+ ```
360
+
361
+ Pre-render hooks auto-handle @page injection, overflow detection, cover adaptation, font loading, and pdf-lib metadata.
362
+
363
+ #### ⚠️ Iron Rule: No Hand-Written Playwright Scripts
364
+
365
+ Common issues with hand-written Python `page.pdf()` (the dedicated scripts handle these automatically):
366
+ 1. **Missing `@page` rule** → browser default margin causes content overflow to second page or white edges
367
+ 2. **Oversized elements not fixed** → large elements with `break-inside: avoid` block pagination, content gets truncated
368
+ 3. **Rendering before fonts are loaded** → Chinese text displays as squares or falls back to wrong font
369
+ 4. **No overflow detection** → content exceeds page boundary without awareness
370
+ 5. **No metadata** → PDF title, author, and other info missing
371
+
372
+ **Iron rule: Posters and cover pages use `html2poster.js`, multi-page documents use `html2pdf-next.js`. Do not write hand-written Python Playwright scripts.**
373
+
374
+ > **⚠️ Cover page gotcha:** Cover HTML uses `position: absolute` for layout. `html2pdf-next.js` pre-render hooks convert absolute-positioned elements to `static` flow (to prevent multi-page overlap), which **destroys** cover layouts. Always use `html2poster.js` for cover pages.
375
+
376
+ ### No overflow:hidden on Fixed-Size Pages (html2pdf-next.js only)
377
+
378
+ When using `html2pdf-next.js` for documents, **NEVER set `overflow: hidden` on `html`, `body`, or the main page container**.
379
+
380
+ > **Note:** This rule does NOT apply to posters rendered via `html2poster.js` — that script automatically adds `overflow: hidden` to `.poster`/`.page` containers to clip decorative overflow. You don't need to add or remove it manually.
381
+
382
+ | Problem | Cause | Fix |
383
+ |---------|-------|-----|
384
+ | Browser preview cuts off bottom content, can't scroll | `overflow: hidden` on container + viewport < design height | Remove `overflow: hidden` |
385
+ | html2pdf-next.js "Fixed vertical overflow" warning, layout may break | Pre-render detects `scrollHeight > clientHeight` + hidden overflow, force-expands container | Remove `overflow: hidden` |
386
+
387
+ **Always pair fixed-size pages with `@media screen` auto-scale** so the full page is visible in any browser window without scrolling. See `briefs/creative.md` § 0.5 for the CSS pattern.
388
+
389
+ ### Full-Bleed Rule (No White Margins)
390
+
391
+ When generating HTML for Playwright `page.pdf()`, the content **MUST fill the entire page** with zero margins. White side margins = broken layout.
392
+
393
+ **Mandatory CSS for any HTML → PDF:**
394
+ ```css
395
+ @page {
396
+ size: <width> <height>; /* e.g., 720px 960px, or A4 */
397
+ margin: 0;
398
+ }
399
+ html, body {
400
+ margin: 0;
401
+ padding: 0;
402
+ }
403
+ ```
404
+
405
+ **Common causes of white margins:**
406
+ 1. Missing `@page { margin: 0 }` - browser default margins kick in (~1cm each side)
407
+ 2. Content width doesn't match page width - e.g., canvas is 720px but page is A4 (794px)
408
+ 3. Missing `@page { size }` declaration in the HTML
409
+ 4. Content has explicit `max-width` that's narrower than the page
410
+
411
+ **For blueprint pipeline:** `design_engine.py` now injects `@page { size: var(--canvas-w) var(--canvas-h); margin: 0; }` automatically.
412
+ **For raw HTML:** YOU must include the `@page` rule. No exceptions.
413
+ **For direct Playwright:** Pass `margin: { top: 0, right: 0, bottom: 0, left: 0 }` to `page.pdf()`.
414
+
415
+ ### Background Color Consistency (No Color Mismatch)
416
+
417
+ **`html` / `body` background color must match the content canvas background color.**
418
+
419
+ Playwright `page.pdf({ printBackground: true })` renders the body background color. If body is white while the content area is gray/colored, color-inconsistent borders/gaps will appear in the PDF.
420
+
421
+ #### Single-color documents (all pages same background)
422
+
423
+ ```css
424
+ /* MANDATORY: body background = content background */
425
+ html, body {
426
+ margin: 0;
427
+ padding: 0;
428
+ background: var(--c-bg); /* Same color as content canvas */
429
+ }
430
+ ```
431
+
432
+ #### Multi-page documents with mixed backgrounds (e.g. dark cover + white body pages)
433
+
434
+ **Root cause:** Playwright resolves `.page { width: 210mm }` and `@page { size: 210mm }` to slightly different sub-pixel values (e.g. 793.688px vs 793.701px). This creates a <1px gap at the right/bottom edge of each `.page` div where `body`'s background shows through. On dark pages, a white `body` background makes this gap visible as a white edge.
435
+
436
+ **Fix — set `body` background to the document's dominant dark color:**
437
+
438
+ ```css
439
+ :root {
440
+ --primary: #0f172a; /* darkest page background */
441
+ }
442
+ html, body {
443
+ margin: 0;
444
+ padding: 0;
445
+ width: 210mm; /* match @page size */
446
+ background: var(--primary); /* fallback for sub-pixel gaps */
447
+ }
448
+ ```
449
+
450
+ **Why this works and doesn't break white pages:**
451
+ - Dark pages: sub-pixel gap reveals dark `body` → gap invisible.
452
+ - White pages: `.page-white { background: #ffffff }` fully covers `body` → dark body never visible.
453
+ - The gap is <1px — even on white pages, the dark body at the extreme pixel edge is imperceptible after anti-aliasing.
454
+
455
+ **Rule: when generating multi-page HTML with mixed backgrounds, always set `html, body { background }` to the darkest page's background color.** If all pages are light/white, use the lightest content background (e.g. `#f8fafc`). Never leave `body` background unset (browser default = white = guaranteed white edges on dark pages).
456
+ ```
457
+
458
+ ### Content Centering (No Left/Right Drift)
459
+
460
+ **After HTML-to-PDF conversion, content must be centered, no left or right drift allowed.**
461
+
462
+ Common drift causes:
463
+ 1. `@page { margin }` not 0 — browser default margin causes drift
464
+ 2. `.safe-zone` or content container `inset` / `padding` left-right asymmetric
465
+ 3. Content container has `max-width` but no `margin: 0 auto`
466
+ 4. Grid components only occupy partial column width (e.g. `1/1 → X/7` only uses left half)
467
+ 5. **Decorative elements overflow page boundary** — elements with `width > 100%` or negative offsets (e.g. glow circles, gradient overlays) inflate `scrollWidth` beyond page width. Playwright shrinks all content to fit, causing left-shift. **Fix: add `overflow: hidden` to `.page` containers.** See `typesetting/overflow.md` §3.5 for horizontal flex overflow rules.
468
+
469
+ ### Anti-Void Edges (No Large Blank Margins)
470
+
471
+ **Content should not have large meaningless whitespace at page edges, top, or bottom.**
472
+
473
+ - Content should make full use of page area; do not cram all content in the top half while leaving the bottom blank
474
+ - For multi-page documents, each page's fill rate should be ≥ 60% (see `pagination.md` last page ≥ 40% rule)
475
+ - For single-page posters/infographics, fill rate should be ≥ 70%
476
+
477
+ ---
478
+
479
+ ## Preflight (Quality Assurance)
480
+
481
+ Every PDF must pass preflight checks before delivery. Each brief specifies the exact commands.
482
+
483
+ ### HTML Pre-Render Validation (MANDATORY for ALL HTML→PDF paths)
484
+
485
+ **Before** calling `html2pdf-next.js`, `html2poster.js`, `convert.blueprint`, or any Playwright `page.pdf()`, run:
486
+
487
+ ```bash
488
+ python3 "$PDF_SKILL_DIR/scripts/poster_validate.py" check-html <your_file>.html
489
+ ```
490
+
491
+ | Result | Action |
492
+ |--------|--------|
493
+ | **PASS** (no errors) | Proceed to PDF generation |
494
+ | **ERROR** items | Must fix before generating PDF. Use `--fix --output <file>.html` for auto-repair |
495
+ | **WARNING** items | Review; non-blocking but should be addressed |
496
+
497
+ **Key checks:**
498
+ - `OVERFLOW_HIDDEN_CONTAINER` (error): `overflow:hidden` on html/body/.page clips content in browser preview and triggers html2pdf-next.js auto-fix that may break layout
499
+ - `FIXED_SIZE_NO_SCREEN_ADAPT` (warning): fixed-size page without `@media screen` auto-scale — browser preview requires scrolling
500
+ - `SCREEN_ADAPT_NO_SCALE` (warning): `@media screen` exists but lacks scale/transform/zoom
501
+ - `FONT_NO_FALLBACK` (error): font-family without generic fallback
502
+ - `COLOR_CONTRAST` (warning): text/background contrast ratio < 3:1
503
+ - Plus: remote images, absolute paths, missing margin reset, tiny fonts, background mismatch, etc.
504
+
505
+ This applies to **all three HTML routes**: Creative blueprint pipeline, Report HTML covers, and bypass/custom HTML.
506
+
507
+ ### Overflow Prevention System
508
+
509
+ **→ Full spec: `typesetting/overflow.md`** - read it for any document with tables, images, or multi-column layouts.
510
+
511
+ Core principles:
512
+ 1. **Measure first, draw second** - never render content without pre-calculating its dimensions
513
+ 2. **Bounding Box constraint** - every element's width ≤ its parent container's `Max_Width`
514
+ 3. **Text: use font metrics**, not character count, for width calculation
515
+ 4. **Images: proportional scaling** - never insert at original size
516
+ 5. **Tables: weight-based column width** + `Paragraph()` wrapping (never plain strings)
517
+ 6. **Fallback ladder**: wrap → shrink font (max -3pt) → reduce padding → split element → log warning
518
+ 7. **Vertical: KeepTogether** for heading+body, chart+caption; `repeatRows=1` for long tables
519
+
520
+ ### Table Overflow Prevention (ReportLab)
521
+ **Most common layout bug: table columns exceed page margins.**
522
+
523
+ Before building any ReportLab Table:
524
+ 1. Calculate `available_width = page_width - left_margin - right_margin`
525
+ 2. Use proportional colWidths (`[0.25, 0.40, 0.20, 0.15]` × available_width) or fixed+flex pattern
526
+ 3. `sum(colWidths)` must be ≤ `available_width` - **verify this in code**
527
+ 4. Long text columns must use `Paragraph()` wrapping, not plain strings (plain strings don't wrap)
528
+ 5. CJK text is wider: budget ~12pt per character at 10pt font size
529
+
530
+ See `briefs/report.md` § "Table Width Management" for code patterns.
531
+
532
+ ### Table Overflow Prevention (LaTeX/Academic)
533
+ **Most common bug in dual-column papers: wide tables overflow single-column width.**
534
+
535
+ Before writing any LaTeX table:
536
+ 1. Count data columns - ≤ 4 fits single column; 5-6 needs `\small`; 7-8 needs `\resizebox`; ≥ 9 use `table*` (full width)
537
+ 2. Use `tabular*{\columnwidth}` or `tabularx{\columnwidth}` instead of plain `tabular` for 5+ columns
538
+ 3. Never use plain `tabular` with 8+ columns in twocolumn layout - guaranteed overflow
539
+ 4. `\resizebox{\columnwidth}{!}` as last resort - verify smallest text ≥ 6pt after scaling
540
+
541
+ See `briefs/academic.md` § "Table width management" for LaTeX patterns.
542
+
543
+ ### Playwright PDF CSS Blacklist
544
+ These CSS properties **silently break** in Playwright's PDF renderer:
545
+ - `backdrop-filter` / `-webkit-backdrop-filter` - **drops entire element content**. Use solid `rgba()` backgrounds.
546
+ - `overflow: hidden` on content containers - clips content. Only safe on small decorative elements (< 200px).
547
+
548
+ After generating any Playwright PDF, **verify every page has content** (pypdf text extraction, check non-empty).
549
+
550
+ ### PDF Metadata (all briefs)
551
+ ALL PDFs must have: Title, Author (default "Z.ai"), Creator, Subject.
552
+
553
+ ### Delivery Summary (all briefs)
554
+ Report to user: file path, size, page count. Academic adds word/image count. Creative adds per-page verification.
555
+
556
+ **HTML→PDF route deliverables (MANDATORY — applies to ALL briefs that use Playwright/HTML to generate PDF):**
557
+ Whenever the HTML→PDF pipeline is used (Creative route, Report cover bypass, Direct HTML Flow posters, or any Playwright `page.pdf()` path), you MUST deliver **both files** to the user:
558
+ 1. **HTML** — the source HTML file, so the user can edit and reuse the design
559
+ 2. **PDF** — the final vector PDF (`page.pdf()` output)
560
+
561
+ Optionally also provide:
562
+ 3. **Image** — a full-page screenshot/preview image (PNG or JPG) for quick sharing on chat/social media
563
+
564
+ All file paths must be reported to the user. **Never deliver only the PDF without the HTML source.**
565
+
566
+ ---
567
+
568
+ ## Tooling Reference
569
+
570
+ ### CLI: `python3 "$PDF_SKILL_DIR/scripts/pdf.py" <command>`
571
+
572
+ ```bash
573
+ # Environment
574
+ env.check # Check deps
575
+ env.fix # Auto-install missing
576
+
577
+ # Quality
578
+ code.sanitize <script> # Sanitize forbidden Unicode
579
+ content.sanitize <file> [--apply] # Fix content issues (CJK, encoding)
580
+ meta.brand <pdf> # Add Z.ai metadata
581
+ font.check <pdf> # Scan for missing glyphs
582
+ toc.check <pdf> # Validate TOC
583
+
584
+ # Conversion
585
+ convert.blueprint <llm_json_response.md> -o final.pdf # CRITICAL FOR CREATIVE: Auto-extracts JSON, compiles, and renders PDF.
586
+ convert.html <html> # HTML → PDF (Playwright)
587
+ convert.latex <tex> # LaTeX → PDF (Tectonic). Bundled binary is macOS arm64 only; see academic.md for other-platform install.
588
+ convert.office <file> # Office → PDF (LibreOffice)
589
+
590
+ # Processing
591
+ extract.text <pdf> # Extract text
592
+ extract.table <pdf> # Extract tables
593
+ extract.image <pdf> # Extract images
594
+ pages.merge a.pdf b.pdf -o out.pdf
595
+ pages.split <pdf>
596
+ pages.clean <pdf> # Remove blank pages
597
+ form.info <pdf> # Inspect form fields
598
+ form.fill <pdf> # Fill form
599
+ form.annotate <pdf> # Fill via annotations
600
+ meta.get <pdf>
601
+ meta.set <pdf> -o out.pdf -d '{"Title": "..."}'
602
+ ```
603
+
604
+ ### Poster/HTML/LaTeX Validator: `python3 "$PDF_SKILL_DIR/scripts/poster_validate.py"`
605
+ ```bash
606
+ check-html <html> # Pre-render validation (overflow:hidden, @media screen, fonts, contrast, etc.)
607
+ check-html <html> --fix --output <fixed.html> # Auto-fix errors (remove overflow:hidden, add font fallback)
608
+ check-pdf <pdf> --source-html <html> # Post-render validation
609
+ check-pdf <pdf> --poster # Poster mode: suppress ORPHAN_PAGE warning
610
+ check-tex <tex> # LaTeX source validation (table overflow, image width, etc.)
611
+ ```
612
+
613
+ **check-html checks include:**
614
+ - `OVERFLOW_HIDDEN_CONTAINER` (error): overflow:hidden on html/body/.page/.poster — clips content
615
+ - `FIXED_SIZE_NO_SCREEN_ADAPT` (warning): fixed-size page without @media screen auto-scale
616
+ - `SCREEN_ADAPT_NO_SCALE` (warning): @media screen exists but lacks scale/transform/zoom
617
+ - `FONT_NO_FALLBACK` (error): font-family without generic fallback (sans-serif/serif)
618
+ - `COLOR_CONTRAST` (warning): text/background contrast ratio < 3:1
619
+ - `BG_COLOR_MISMATCH` (warning): body background differs from .canvas/.poster background
620
+ - `SCREEN_BG_MISMATCH` (warning): @media screen html background differs from body/canvas background
621
+ - `MULTIPAGE_BODY_BG_MISSING` (warning): multi-page document with dark `.page` backgrounds but no `html/body` background color. Sub-pixel gaps at page edges reveal white body, causing visible white edges on dark pages. Resolves `var()` references via `:root` variables.
622
+ - `SCREEN_NO_BG` (warning): fixed-size page's @media screen block lacks html background color
623
+ - `OVERFLOW_DECORATION` (warning): negative position values may cause black edges
624
+ - `NO_PAGE_SIZE` / `MISSING_MARGIN_RESET` / `WHITE_BACKGROUND` / `TINY_FONT` / etc.
625
+
626
+ **check-tex checks include:**
627
+ - `BARE_TABULAR_OVERFLOW` (error): `\begin{tabular}` with 5+ columns in two-column layout, not wrapped in resizebox/adjustbox/table*
628
+ - `RESIZEBOX_TEXTWIDTH` (error): `\resizebox{\textwidth}` used inside single-column float in two-column layout. `\textwidth` = full page width, but `table` float is one column. Fix: use `\resizebox{\columnwidth}` or `table*`
629
+ - `TABULAR_OVERFLOW_RISK` (warning): 4-column tabular in two-column layout without width constraint
630
+ - `TABULAR_WIDE` (warning): 7+ column tabular in single-column layout without width constraint
631
+ - `TABULAR_NO_FLOAT` (warning): tabular not inside table/table* float environment
632
+ - `TABULARX_NOT_LOADED` (warning): document has tabular but tabularx package not loaded
633
+ - `IMAGE_NO_WIDTH` (warning): `\includegraphics` without width/height/scale constraint
634
+ - `EQUATION_DUAL_ON_LINE` (warning): `equation` environment has 2+ equations joined by `\quad` without line breaks. Guaranteed overflow in dual-column
635
+ - `EQUATION_OVERFLOW_RISK` (warning): equation body has >80 math characters. Likely overflows single column
636
+ - `ALGORITHM_NO_SMALL_FONT` (warning): `algorithm` environment in dual-column without `\SetAlFnt{\small}`
637
+ - `ALGORITHM_LONG_IO` (warning): Algorithm Input/Output line >120 chars. Will overflow narrow column
638
+ - `CJK_ASCII_QUOTES` (error): ASCII `"` found adjacent to CJK characters. LaTeX interprets `"` as right double quote, so `"北漂"` renders incorrectly. Skips verbatim/lstlisting/minted environments and `\texttt{}`/`\url{}`/`\href{}{}`/`\verb||` inline commands.
639
+
640
+ ### Design Engine: `python3 "$PDF_SKILL_DIR/scripts/design_engine.py"`
641
+ ```bash
642
+ compile --blueprint <json_file> --output poster.html # CRITICAL: Compile JSON blueprint to HTML
643
+ derive "document title or description" # Auto-derive intent from content
644
+ palette --intent calm --mode dark # Generate HSL-locked palette
645
+ palette-cascade --intent cold --mode minimal # Generate role-based cascade palette (V2, preferred)
646
+ svg --intent flow --dimensions 720x960 # Generate SVG background
647
+ full --intent energy --mode dark --dimensions 720x960 --output-dir ./assets/
648
+ audit --palette-json palette.json # Check palette constraints
649
+ ```
650
+
651
+ ### Palette Generator (for Report route): `python3 "$PDF_SKILL_DIR/scripts/pdf.py" palette.generate`
652
+ ```bash
653
+ palette.generate --title "document title" --mode minimal # Output: ready-to-paste ReportLab Python code
654
+ palette.generate --title "..." --format json # Output: raw JSON
655
+ palette.generate --title "..." --format css # Output: CSS custom properties
656
+ palette.generate --title "..." --mode dark --harmony complementary --seed 42
657
+ ```
658
+
659
+ ### Cascade Palette (V2 - Preferred): `python3 "$PDF_SKILL_DIR/scripts/pdf.py" palette.cascade`
660
+ ```bash
661
+ palette.cascade --title "document title" --mode minimal # Output: summary table with all 12 roles
662
+ palette.cascade --title "..." --format json # Full structured JSON (roles + cover + body + charts + semantic)
663
+ palette.cascade --title "..." --format css # CSS custom properties by tier
664
+ palette.cascade --title "..." --format reportlab # Ready-to-paste ReportLab Python code
665
+ ```
666
+ **⚠️ Cascade palette is the preferred palette system.** It enforces area ∝ 1/saturation (larger areas = lower saturation) and outputs unified color subsets for cover, body, and charts from one base hue. Use `palette.cascade` instead of `palette.generate` for new documents.
667
+
668
+ **⚠️ Report route MUST call `palette.cascade` (or `palette.generate`) before writing any ReportLab code.** The output is copy-paste ready - no manual hex picking allowed.
669
+
670
+ > **Note**: `design_engine.py compile` produces **HTML** from a JSON blueprint. To get a **PDF**, use `pdf.py convert.blueprint` which internally calls `compile` → Playwright render → PDF output. In the Creative pipeline, always use `convert.blueprint` for the final PDF.
671
+
672
+ ### Tech Stack per Brief
673
+
674
+ | Brief | Primary Tool | Secondary | Emoji Support | Custom Page Size |
675
+ |-------|-------------|-----------|---------------|-----------------|
676
+ | Report | ReportLab + pypdf | **Playwright (cover)** | ❌ (tofu □) | Manual pagination |
677
+ | Creative | Playwright | html2pdf-next.js (pdf-lib for post-processing) | ✅ native | ✅ any size |
678
+ | Academic | Tectonic + pypdf | **Playwright (cover)** | ❌ (dropped) | Template-dependent |
679
+ | Process | pikepdf, pdfplumber | LibreOffice (soffice) | N/A | N/A |
680
+
681
+ > **Unified Cover System**: All routes generate covers via HTML/Playwright. Report uses Templates 01–07, Academic uses Templates 08–10 (dark backgrounds, scholarly typography), Creative generates cover + body in one HTML document. Cover PDFs are merged with body PDFs via pypdf.
682
+ >
683
+ > **Fallback**: If Report brief content has emoji → reroute to Creative.
684
+
685
+ ---
686
+
687
+ ## File Map
688
+
689
+ ```
690
+ SKILL.md ← You are here
691
+ briefs/
692
+ report.md ← Report production: ReportLab workflow + API + resume(ATS)
693
+ creative.md ← Creative production: 5-phase generative design workflow
694
+ poster.md ← Poster scene rules: density, font sizing, fill constraints (overlay on creative.md)
695
+ academic.md ← Academic production: LaTeX workflow + templates + resume(CV)
696
+ process.md ← PDF processing: extract/merge/split/form/convert/reformat
697
+ process-advanced.md ← Advanced reference (encrypted/corrupted/OCR/batch/perf) - load on demand
698
+ configs/
699
+ visual_framework.md ← Palette mode, color harmony, SVG background params
700
+ components.md ← Non-grid composition components (floating cards, etc.)
701
+ fonts.md ← Font stacks per pipeline (Creative/Report/Academic)
702
+ typesetting/
703
+ palette.md ← Color system + typography + anti-patterns + spacing
704
+ cover.md ← Cover page layout system (7 layouts × 2-3 variants) + typography scale + color rules
705
+ cover-backgrounds.md ← Cover background rendering rules + transparency constraints
706
+ charts.md ← Chart styling + anti-stacking rules + axis/grid/legend treatment
707
+ overflow.md ← Bounding box system, text/image/table overflow prevention
708
+ pagination.md ← Cross-page integrity, orphan/widow control, CJK punctuation
709
+ typography.md ← Font size scale, line-height, spacing system
710
+ geometry.md ← Geometric anchor system (decorative elements, lines, shapes)
711
+ fill-engine.md ← Adaptive anti-void layout engine V2.0
712
+ scripts/
713
+ pdf.py ← CLI tool (30 subcommands)
714
+ pdf_qa.py ← PDF quality checker (metadata, fonts, overflow, margins, tables, formulas)
715
+ design_engine.py ← Generative SVG + palette engine (palette/svg/compile/derive/audit)
716
+ poster_validate.py ← HTML/PDF validator
717
+ toc_validate.py ← TOC validator
718
+ html2pdf-next.js ← Playwright + pdf-lib HTML→PDF converter for documents (no Paged.js)
719
+ html2poster.js ← Playwright HTML→PDF converter for posters/single-page (auto overflow:hidden, dynamic height)
720
+ cover_validate.js ← Cover-ONLY overlap detection (text vs decorative lines). Do NOT run on posters or documents — only on cover HTML in Report/Academic pipelines.
721
+ references/
722
+ resume-altacv.tex ← AltaCV dual-column resume template (creative/tech)
723
+ resume-academic.tex ← Academic CV template (PhD/academic)
724
+ ```
725
+
726
+ ### Loading Protocol
727
+
728
+ 1. **Always read**: This file (SKILL.md)
729
+ 2. **Read ONE brief**: The matched brief file - it contains the complete workflow
730
+ 3. **Read typesetting on demand**: Only when the brief says to (standard tasks)
731
+ 4. **Never load all files upfront** - briefs reference what they need
732
+
733
+ ### Script Path Setup (MANDATORY before any script call)
734
+
735
+ All paths are relative to `$PDF_SKILL_DIR` — the single root variable for this skill. Resolve it once before calling any script:
736
+
737
+ ```bash
738
+ PDF_SKILL_DIR="<skill_directory>" # ← parent directory of this SKILL.md
739
+
740
+ # Then all commands use $PDF_SKILL_DIR:
741
+ python3 "$PDF_SKILL_DIR/scripts/pdf.py" code.sanitize generate_pdf.py
742
+ python3 "$PDF_SKILL_DIR/scripts/pdf.py" meta.brand output.pdf
743
+ python3 "$PDF_SKILL_DIR/scripts/pdf.py" font.check output.pdf
744
+ python3 "$PDF_SKILL_DIR/scripts/pdf.py" toc.check output.pdf
745
+ python3 "$PDF_SKILL_DIR/scripts/pdf.py" pages.clean output.pdf -o output_clean.pdf
746
+ python3 "$PDF_SKILL_DIR/scripts/pdf_qa.py" output.pdf
747
+ python3 "$PDF_SKILL_DIR/scripts/poster_validate.py" check-html page.html
748
+ python3 "$PDF_SKILL_DIR/scripts/poster_validate.py" check-pdf output.pdf
749
+ ```
750
+
751
+ **For Python imports** (when generation code needs to import skill modules):
752
+
753
+ ```python
754
+ import sys, os
755
+ PDF_SKILL_DIR = "<skill_directory>"
756
+ _scripts = os.path.join(PDF_SKILL_DIR, "scripts")
757
+ if _scripts not in sys.path:
758
+ sys.path.insert(0, _scripts)
759
+ ```
760
+
761
+ **⚠️ NEVER use bare `python3 scripts/pdf.py ...`** - it only works if cwd happens to be the skill directory. Always use `$PDF_SKILL_DIR/scripts/` as the absolute prefix.
762
+
763
+ ---
764
+
765
+ ## 8. Quality Checklist (Mandatory after every PDF generation)
766
+
767
+ > The following checks come from the `typesetting/` spec files and are **mandatory** quality gates.
768
+
769
+ ### Automated Detection (Must Run)
770
+
771
+ ```bash
772
+ python3 "$PDF_SKILL_DIR/scripts/pdf_qa.py" <output.pdf>
773
+ python3 "$PDF_SKILL_DIR/scripts/pdf_qa.py" --poster <output.pdf> # poster mode: skip content fill ratio, check all pages for full-bleed
774
+ python3 "$PDF_SKILL_DIR/scripts/pdf_qa.py" --skip-cover --formulas <output.pdf> # academic mode: skip cover for margin check, enable formula overflow
775
+ python3 "$PDF_SKILL_DIR/scripts/pdf_qa.py" --no-tables <output.pdf> # creative mode: skip table centering check
776
+ ```
777
+
778
+ > **Dependency**: Requires `pymupdf` (`pip install pymupdf`). If not installed, skip automated detection and use the manual checklist below.
779
+
780
+ Run `pdf_qa.py` after generating a PDF. It auto-detects: metadata completeness, page size consistency, blank pages, CJK punctuation placement, color count, font embedding status, content overflow, content fill ratio, cover full-bleed, margin symmetry, table centering, formula overflow.
781
+ - **`--poster` mode**: skips content fill ratio check (poster last page naturally has less content), checks ALL pages for full-bleed (not just cover)
782
+ - **`--skip-cover`**: skips page 1 when checking margin symmetry (for documents with separately-generated covers)
783
+ - **`--no-tables`**: disables table centering check (for creative/poster documents that rarely have traditional tables)
784
+ - **`--formulas`**: enables formula overflow detection (checks if formula-like content extends past right content margin)
785
+ - Result PASS → deliver directly
786
+ - Result WARN → evaluate whether fix is needed, non-blocking
787
+ - Result FAIL → **must fix and regenerate**
788
+
789
+ ### Pagination & Layout (pagination.md)
790
+
791
+ - [ ] **Last page fill ratio ≥ 40%**: No large blank areas on the final page. If insufficient, backtrack to compress spacing/line-height/font-size
792
+ - [ ] **Major section 3/4 threshold**: H1-level headings must NOT start in the bottom 25% of a page. If remaining space < 25%, force page break and start on fresh page. Use `CondPageBreak(available_height * 0.25)` in ReportLab, `\needspace{0.25\textheight}` in LaTeX
793
+ - [ ] **Tables don’t split across pages**: Table header and data rows must stay together. Small tables: `break-inside: avoid`. Large tables: `thead { display: table-header-group }`
794
+ - [ ] **Punctuation placement rules**: Commas, periods, etc. must not appear at line start. Set `line-break: strict` in CSS
795
+ - [ ] **No orphan headings**: Headings must not appear alone at page bottom. Use `break-after: avoid`
796
+ - [ ] **Cards/images not cut**: `break-inside: avoid`
797
+
798
+ ### Overflow Prevention (overflow.md)
799
+
800
+ - [ ] **All table cells use Paragraph() wrapping** (ReportLab): Never plain strings - they don't wrap and overflow
801
+ - [ ] **sum(colWidths) ≤ available_width**: Verified in code, not assumed
802
+ - [ ] **Images/charts proportionally scaled**: Never inserted at original dimensions; always `fit_image()` or `max-width: 100%`
803
+ - [ ] **Long tables have repeatRows=1**: Table header repeats on every page when table breaks across pages
804
+ - [ ] **Heading + first paragraph in KeepTogether**: Prevents orphan headings at page bottom
805
+ - [ ] **Chart + caption in KeepTogether**: Prevents chart on one page, caption on next
806
+ - [ ] **CJK text uses wordWrap='CJK'**: Required for proper line-breaking of Chinese/Japanese/Korean
807
+ - [ ] **URLs/long strings have word-break**: `overflow-wrap: break-word` (HTML) or manual splitting (ReportLab)
808
+ - [ ] **Font degradation fallback**: Tight columns can shrink font by up to 3pt before clipping
809
+
810
+ ### Color (palette.md) - Report & Creative only
811
+
812
+ > **Academic (LaTeX) documents are exempt** from this color system. LaTeX uses template-defined styling.
813
+ - [ ] **Entire document ≤ 5 colors**: Primary + secondary + accent + neutral + background
814
+ - [ ] **All colors traceable to primary**: Secondary and accent derived via lightness/saturation/micro-hue shift
815
+ - [ ] **Sibling elements not differentiated by different hues**: Use opacity/lightness/borders instead
816
+ - [ ] **Gradient endpoints hue difference < 20°**: No warm-to-cool gradients
817
+ - [ ] **No high-saturation color blocks**: Avoid eye strain
818
+
819
+ ### Cover V2 (cover.md)
820
+
821
+ - [ ] **Evaluate whether a cover is needed**: Reports, proposals, analysis, white papers, manuals ≥ 3 pages → **always add cover (default ON)**. Skip cover ONLY for: resumes, CVs, letters, memos, forms, checklists, invoices, internal notes, or documents ≤ 2 pages
822
+ - [ ] **Single PDF output**: Cover is merged into the final PDF as page 1. **Report/Academic**: cover generated via HTML/Playwright → merged as page 0 via pypdf. **Creative**: cover is part of the same HTML document. NEVER deliver a separate cover file
823
+ - [ ] **Page isolation**: Cover NEVER shares a page with TOC or body content. **Report/Academic**: inherent via pypdf merge (separate PDFs). **Creative**: CSS page-break ensures isolation
824
+ - [ ] **Absolute Anchor Grid**: All elements use percentage Y-anchors (Part 0, A0.1). NO flow-based layout
825
+ - [ ] **Z-Index Layers**: Render in strict order: Layer 0 (bg fill) → Layer 1 (decorative, CLIPPED) → Layer 2 (structure lines) → Layer 3 (text)
826
+ - [ ] **Typography Weight System**: Use weight/spacing/opacity hierarchy per A0.2 (Kicker: 16pt+3pt spacing+60% opacity; Hero: 45-65pt Heavy; Meta: 20-22pt; Summary: 16-18pt Regular line-height 1.6)
827
+ - [ ] **Mandatory Summary Block** 🆕: Every cover MUST include a Summary/Description drawer (2-4 lines). If user provides none, auto-generate placeholder text (S3.5)
828
+ - [ ] **Safety checks**: Hero title overflow (max 3 lines, auto-reduce font S3.1); Zone collision detection (S3.2); Uppercase lock for Latin kickers/footers/watermarks (S3.3); Hard width boundary enforcement (S3.4); Summary auto-generation (S3.5); **Background watermark full-display enforcement (S3.6)**
829
+ - [ ] **Background watermark complete** 🆕: All background layer watermark text (year, document type, sidebar text) must be 100% visible within page bounds - auto-shrink font if needed, NEVER clip/truncate
830
+ - [ ] **Data binding correct** 🆕: Hero Title = company/entity name (biggest, heaviest text); Kicker = report type/subtitle (small decorative text). NEVER reverse this mapping
831
+ - [ ] **Fill Engine applied** 🆕: Font floor enforced (body ≥ 14pt single-col / 12pt dual-col, H1 ≥ 32pt, H2 ≥ 24pt, H3 ≥ 18pt); Fill Ratio calculated; inflation triggered when < 65%; Y-axis golden-ratio anchor when < 40%
832
+ - [ ] **Selected one of 7+4 templates**: General templates 01–07 + Academic templates 08–10 + Institutional template 11. Autonomously select the best-fit template by analyzing document intent (Calm/Tension/Energy/Authority/Warmth) and document type per Part 2 Intent × Type matrix. Thesis proposals/dissertations/institutional submissions → **default Template 11**. No global default - every selection must be a deliberate design decision
833
+ - [ ] **Typography weight hierarchy**: Hero 45-65pt Heavy, Meta 20-22pt Regular, Kicker/Footer 16pt with 3pt letter-spacing + 60% opacity, Summary 16-18pt Regular
834
+ - [ ] **Base spacing unit**: `U = W * 0.05` - all spacing should be multiples of U
835
+ - [ ] **Bounding box via absolute anchors**: Each block anchored to fixed Y%, grows only within its own zone, never pushes adjacent blocks
836
+ - [ ] **Safe zone margin**: 8-12% on all sides per template spec (corner marks for Template 04 at 8%)
837
+ - [ ] **Cover whitespace ≥ 60%**: Restraint > clutter (but Summary block fills mid-page void intentionally)
838
+ - [ ] **Cover colors consistent with body**: No independent color scheme; white/light backgrounds only
839
+ - [ ] **Clip-path on Layer 1**: All background decorative elements must be clipped to page bounds
840
+ - [ ] **Clip scope = Layer 1 ONLY** �F: `saveState()`/`clipPath()` must `restoreState()` BEFORE rendering Layer 2 lines and Layer 3 text. Text rendered inside clip scope = text gets cut off
841
+ - [ ] **No page border/frame** �F: Cover page must have `showBoundary=0`, no `canvas.rect(0,0,W,H)`, no CSS border/outline on cover container
842
+ - [ ] **Line-to-text minimum gap** �F: Decorative lines (Layer 2) must be at least `U` (= `W * 0.05`) away from any text content
843
+ - [ ] **No dark/gradient backgrounds**: No dark fills, no gradients, no high-saturation schemes
844
+ - [ ] **Hard width enforcement**: Text wraps vertically at zone boundary, NEVER bleeds horizontally past assigned width
845
+ - [ ] **🚫 NEVER use ReportLab for covers** — ALL covers (Report, Creative, Academic) are generated via HTML/Playwright. See cover.md for the 10-template system. If you catch yourself writing `canvas.setFillColor()` + `canvas.rect()` for a cover background, STOP — switch to HTML/Playwright.
846
+ - [ ] **Line-length alignment (S3.7)**: Vertical lines match text block height (± 1U); horizontal lines ≥ widest text element width (never shorter than text)
847
+ - [ ] **Vertical balance (S3.8)**: No >40% dead whitespace at bottom; sparse content uses centered distribution; CJK titles 15-20% larger than Latin equivalent
848
+ - [ ] **Percentage positioning safety (S3.9)**: Every element with `top: XX%` must have a containing block with deterministic height (`height: 100%`, `inset: 0`, or `top+bottom` pair). Wrappers without explicit height + percentage-positioned children = overlap bug. Prefer px values over percentages
849
+ - [ ] **Cover colors from palette system**: All `:root` CSS variables populated by `palette.cascade` output. Template HTML uses `--c-bg`, `--c-accent`, `--c-text`, `--c-muted` — no hardcoded hex values in generated HTML
850
+
851
+ ### Geometric Anchors (geometry.md)
852
+
853
+ - [ ] **Anchors use only the primary color**: Layer via opacity, don't mix colors
854
+ - [ ] **Strokes over fills**: Solid elements ≤ 30%
855
+ - [ ] **Ultra-thin lines**: stroke-width 0.3-0.8px
856
+ - [ ] **Asymmetric placement**: Offset creates tension
857
+ - [ ] **Elements ≤ 8**: Restraint, don't clutter
858
+
859
+ ### Charts (charts.md)
860
+
861
+ - [ ] **No text stacking/overlap**: All chart labels, values, and legends must be collision-free
862
+ - [ ] **Chart-to-text separation**: Minimum 24pt gap above and below charts; 8pt between chart and caption; 30pt between consecutive charts
863
+ - [ ] **Legend-to-chart non-overlap**: Legend MUST NOT overlap chart data area. Use `bbox_to_anchor` or external placement
864
+ - [ ] **Value label anti-collision**: Adjacent value labels that overlap must be staggered, rotated, or selectively hidden
865
+ - [ ] **Pie charts → Donut by default**: hole_ratio 60-70%, center shows total/core metric
866
+ - [ ] **Small pie slices handled**: Slices < 5% use leader lines, < 3% merge to "Others", or strip labels to rich legend
867
+ - [ ] **Bar chart auto-rotation**: If X-axis labels avg > 5 CJK chars (or 10 Latin), auto-convert to horizontal bars
868
+ - [ ] **Line chart labeling**: Only label start, end, max, min points - NOT every data point
869
+ - [ ] **Axis cleanup**: Top/right spines deleted, grid lines dashed at 0.5pt/20% opacity (or hidden if values labeled)
870
+ - [ ] **Bar micro-rounding**: Top border-radius 2-4px, bar-to-gap ratio 1.5:1 or 2:1
871
+ - [ ] **Legend de-boxed**: No border on legend, horizontal layout, small circle markers
872
+ - [ ] **Chart title hierarchy**: Bold main title left-aligned above chart, lighter subtitle below it
873
+
874
+ ### Global Layout
875
+
876
+ - [ ] **Margin symmetry**: `left_margin == right_margin` - asymmetric margins cause off-center content (ReportLab, LaTeX, HTML all checked)
877
+ - [ ] **Full-bleed enforcement (Playwright)**: HTML includes `@page { size: <w> <h>; margin: 0; }` and `html,body { margin:0; padding:0; }`. No white side margins in the output PDF
878
+ - [ ] **Background color consistency (Playwright)**: `html, body { background }` set explicitly. Single-color docs: match content canvas. Multi-page mixed docs: use the darkest page's background color. Mismatch or missing = sub-pixel white edges on dark pages
879
+ - [ ] **Content centering (Playwright)**: Content is centered in PDF, not drifting left or right. Check: symmetric inset/padding, full-width grid columns, no unbalanced max-width
880
+ - [ ] **Anti-void edges**: No large meaningless blank areas at top, bottom, or sides. Content fills ≥ 60% of page (multi-page) or ≥ 70% (single-page poster/infographic)
881
+ - [ ] **Fill Engine applied**: Pages with < 80% fill ratio trigger the fill engine (see `fill-engine.md`)
882
+ - [ ] **Table centering**: ALL tables must be horizontally centered on the page. ReportLab: use `hAlign='CENTER'` on Table flowable. LaTeX: use `\centering` inside table environment. HTML: use `margin: 0 auto` on table element. NEVER let tables float left with right-side whitespace
883
+ - [ ] **Table column width**: Table total width should be 85-100% of content area width. Avoid narrow tables (< 60% width) that look lost on the page. If table is narrow, expand column widths proportionally or use `colWidths` to fill available space
884
+
885
+ ### Exam / Quiz / Test Paper Rules
886
+
887
+ - [ ] **Question numbering**: Use hierarchical numbering (一、二、三 for sections; 1. 2. 3. for questions; (1)(2)(3) or A B C D for sub-questions/options)
888
+ - [ ] **Option indentation**: Multiple-choice options MUST be indented relative to the question stem. Minimum `leftIndent = 24pt` (2em). Options must NEVER start at the same X position as the question number
889
+ - [ ] **Option layout**: ≤4 short options (≤4 chars each) → 2×2 grid or single row. >4 options or long text → vertical list, one per line. Each option on its own line gets consistent indentation
890
+ - [ ] **Answer space reservation**: MUST reserve blank space for handwritten answers. Calculation: short answer = 2-3 blank lines (40-60pt); paragraph/essay = 8-15 blank lines (160-300pt); math work = 6-10 blank lines (120-200pt); fill-in-the-blank = inline underline (min 80pt width). Use `Spacer(1, height)` in ReportLab
891
+ - [ ] **Answer line style**: Use light gray dashed or dotted horizontal lines for answer areas, NOT solid black lines. Line weight ≤ 0.5pt, color = #cccccc or lighter
892
+ - [ ] **Score marking area**: Each question should have a score indicator in the margin or after the question number, e.g., “(10分)” or “[10 pts]”
893
+ - [ ] **Page density**: Exam papers should NOT be cramped. Minimum `spaceBefore=12pt` between questions. Section headers get `spaceBefore=24pt`
894
+
895
+ ### Design Restraint (Anti-Gaudy)
896
+
897
+ - [ ] **Decorative elements ≤ 3 per page**: Maximum 3 decorative/non-functional visual elements per page (lines, shapes, icons, patterns). Cover page exempt
898
+ - [ ] **No gratuitous icons/emoji in headers**: Section headers should use typography hierarchy (size, weight, color) for emphasis — NOT emoji, icons, or decorative bullets unless the user explicitly requested them
899
+ - [ ] **No rainbow/multi-color schemes**: Stick to the single-family palette system. If you find yourself using 4+ distinct hue families in one document, STOP and simplify
900
+ - [ ] **No decorative borders on body pages**: Body content pages must NOT have decorative borders, corner ornaments, or page frames. Clean margins only. (Cover page Template 11 border is the sole exception)
901
+ - [ ] **No texture/pattern backgrounds on body pages**: Body pages use solid white or ultra-light tinted backgrounds only. No dot grids, crosshatch, diagonal lines, or any pattern fills
902
+ - [ ] **Whitespace is design**: Empty space between elements is intentional and valuable. Do NOT fill every gap with decorative elements, horizontal rules, or filler content
903
+ - [ ] **Typography over decoration**: Create visual hierarchy through font size, weight, spacing, and color — not through adding more visual elements. If a design looks busy, REMOVE elements rather than rearranging them
904
+ - [ ] **2-typeface maximum**: Entire document uses at most 2 font families (one serif, one sans-serif). No mixing 3+ fonts for “variety”
905
+ - [ ] **🚫 NO stock images / clipart / AI-generated decorations**: NEVER embed watercolor flowers, floral borders, gold frames, stock photos, clipart illustrations, or AI-generated artwork for decoration. Use geometric shapes (CSS/SVG from geometry.md) + typography for all visual design. Only user-provided content images (photos, logos, diagrams) are allowed. See `visual_framework.md` Stock Image Ban
906
+
907
+ ### LaTeX-Specific (academic.md)
908
+
909
+ - [ ] **Curly quotes**: No straight `"` quotes - use `` ``text'' `` for double and `` `text' `` for single
910
+ - [ ] **Title page isolation**: `\end{titlepage}` followed by `\newpage`/`\clearpage` - TOC/body NEVER on same page as title
911
+ - [ ] **Resume column overlap**: AltaCV `paracol` entries checked for vertical overflow; max 3-4 bullets per `\cvevent`; explicit `\newpage` for 2-page resumes
912
+ - [ ] **`\geometry` symmetry**: `left=X, right=X` must be equal values
913
+
914
+ ### Output Cleanliness (All Pipelines)
915
+
916
+ - [ ] **No process artifacts in output**: NEVER include version numbers ("V3"), iteration markers, draft labels ("DRAFT"), "CONFIDENTIAL"/"机密" stamps, "Generated by AI"/"本文档由AI生成", or internal comments in the final PDF unless the user explicitly requested them
917
+ - [ ] **No auto-generated boilerplate labels**: Do not add ANY watermarks, generation notices, version numbers, timestamps, or tool names that the user didn't ask for
918
+ - [ ] **No debug output in content**: Console logs, file paths, generation timestamps, tool names, or error messages must never appear in the PDF body
919
+ - [ ] **Clean metadata only**: PDF metadata (author, title, subject) should reflect the document content, not the generation process