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,323 @@
1
+ # FAQ — Common Bugs and Fixes
2
+
3
+ ## Bug: Table text touching cell borders
4
+
5
+ **Symptom**: Text is cramped against table cell edges, no padding.
6
+
7
+ **Fix**: Set `margins` at the TableCell level:
8
+ ```js
9
+ new TableCell({
10
+ margins: { top: 60, bottom: 60, left: 120, right: 120 },
11
+ children: [/* ... */],
12
+ })
13
+ ```
14
+
15
+ ---
16
+
17
+ ## Bug: Numbered list doesn't restart
18
+
19
+ **Symptom**: Second numbered list continues from where the first left off (e.g., starts at 4 instead of 1).
20
+
21
+ **Fix**: Each separate numbered list MUST use a unique `reference` name in numbering config:
22
+ ```js
23
+ numbering: { config: [
24
+ { reference: "list-A", levels: [{ level: 0, format: LevelFormat.DECIMAL, text: "%1." }] },
25
+ { reference: "list-B", levels: [{ level: 0, format: LevelFormat.DECIMAL, text: "%1." }] },
26
+ ]}
27
+ ```
28
+
29
+ ---
30
+
31
+ ## Bug: Cover and content on same page
32
+
33
+ **Symptom**: Cover page content flows directly into main content without page break.
34
+
35
+ **Fix**: Add a PageBreak paragraph at the end of cover content:
36
+ ```js
37
+ coverChildren.push(new Paragraph({ children: [new PageBreak()] }));
38
+ ```
39
+
40
+ ---
41
+
42
+ ## Bug: Three-line table shows all borders
43
+
44
+ **Symptom**: Table intended to be three-line shows full grid borders.
45
+
46
+ **Fix**: Set table-level borders to NONE, then override only specific cell borders:
47
+ ```js
48
+ // Table level: all borders NONE
49
+ borders: { top: { style: BorderStyle.SINGLE, size: 4 }, bottom: { style: BorderStyle.SINGLE, size: 4 },
50
+ left: { style: BorderStyle.NONE }, right: { style: BorderStyle.NONE },
51
+ insideHorizontal: { style: BorderStyle.NONE }, insideVertical: { style: BorderStyle.NONE } }
52
+ // Header cells: bottom border only
53
+ headerCell.borders = { bottom: { style: BorderStyle.SINGLE, size: 2, color: "000000" } }
54
+ ```
55
+
56
+ ---
57
+
58
+ ## Bug: User requests Chinese font size name (e.g. Wu Hao) but output is wrong
59
+
60
+ **Symptom**: Font size doesn't match expected Chinese size name.
61
+
62
+ **Fix**: Use the correct half-point value. `size` in docx-js is in half-points:
63
+ - Wu Hao 五号 = 10.5pt → `size: 21`
64
+ - Xiao Si 小四 = 12pt → `size: 24`
65
+ - Si Hao 四号 = 14pt → `size: 28`
66
+
67
+ See SKILL.md for complete conversion table.
68
+
69
+ ---
70
+
71
+ ## Bug: Black table cells
72
+
73
+ **Symptom**: Table cells appear solid black in Word.
74
+
75
+ **Fix**: Use `ShadingType.CLEAR` not `ShadingType.SOLID`:
76
+ ```js
77
+ // ❌ WRONG
78
+ shading: { type: ShadingType.SOLID, fill: "F1F5F9" }
79
+ // ✅ CORRECT
80
+ shading: { type: ShadingType.CLEAR, fill: "F1F5F9" }
81
+ ```
82
+
83
+ ---
84
+
85
+ ## Bug: Chinese characters garbled in matplotlib charts
86
+
87
+ **Symptom**: Chinese text shows as empty boxes □□□ in generated PNG charts.
88
+
89
+ **Fix**: Configure SimHei font before plotting:
90
+ ```python
91
+ from matplotlib.font_manager import FontProperties
92
+ zh_font = FontProperties(fname="/path/to/SimHei.ttf")
93
+ plt.title("中文标题", fontproperties=zh_font)
94
+ plt.rcParams["axes.unicode_minus"] = False
95
+ ```
96
+
97
+ ---
98
+
99
+ ## Bug: Image stretched/squashed in document
100
+
101
+ **Symptom**: Embedded image appears distorted.
102
+
103
+ **Fix**: Calculate display height from width using original aspect ratio:
104
+ ```js
105
+ const aspectRatio = originalHeight / originalWidth;
106
+ const displayWidth = 500;
107
+ const displayHeight = Math.round(displayWidth * aspectRatio);
108
+ new ImageRun({ data: buf, transformation: { width: displayWidth, height: displayHeight }, type: "png" });
109
+ ```
110
+
111
+ ---
112
+
113
+ ## Bug: TOC shows empty in generated document
114
+
115
+ → See `references/toc.md` — "5 Common TOC Bugs" section for diagnosis and fixes.
116
+
117
+ ---
118
+
119
+ ## Bug: PageBreak standalone crashes Word
120
+
121
+ **Symptom**: Document fails to open or renders incorrectly.
122
+
123
+ **Fix**: PageBreak must always be wrapped in a Paragraph:
124
+ ```js
125
+ // ❌ WRONG — standalone
126
+ children: [new PageBreak()]
127
+ // ✅ CORRECT — inside Paragraph
128
+ children: [new Paragraph({ children: [new PageBreak()] })]
129
+ ```
130
+
131
+ ---
132
+
133
+ ## Bug: Quotation marks break JavaScript syntax — ⚠️ #1 MOST COMMON BUG
134
+
135
+ **This is the single most frequent code generation error.** Chinese text routinely uses curly quotes `""` for emphasis, proper nouns, and event names (e.g., "双11", "前低后高", "618"大促). These MUST be Unicode-escaped — bare curly quotes silently break JS syntax.
136
+
137
+ **Rule: scan ALL Chinese text for `""''` and replace with `\u201c \u201d \u2018 \u2019` BEFORE writing the string.**
138
+
139
+ ```js
140
+ // ❌ WRONG — curly quotes in Chinese text break syntax (extremely common)
141
+ para("行业增速呈现"前低后高"的态势,在"618"大促拉动下增长。")
142
+ "他说"你好"" // \u201c \u201d
143
+ 'It's a test' // \u2019
144
+
145
+ // ✅ CORRECT — Unicode escapes for ALL curly quotes
146
+ para("行业增速呈现\u201c前低后高\u201d的态势,在\u201c618\u201d大促拉动下增长。")
147
+ "他说\u201c你好\u201d"
148
+ "It\u2019s a test"
149
+
150
+ // ✅ Straight quotes: escape or use alternate delimiters
151
+ "He said \"hello\""
152
+ 'He said "hello"'
153
+ ```
154
+
155
+ ---
156
+
157
+ ## Bug: Unwanted blank pages in document
158
+
159
+ **Common causes:**
160
+
161
+ 1. **Trailing PageBreak at end of last section** — pagination should use section breaks or be at the start of the next section
162
+ 2. **Empty Paragraph overflow** — empty paragraphs at page bottom push to a new page
163
+ 3. **PageBreak right after Table** — Table already at page bottom, PageBreak creates extra page
164
+
165
+ **Fix:**
166
+ ```js
167
+ // Post-generation check: last section's children should not end with PageBreak
168
+ function removeTrailingPageBreak(section) {
169
+ const children = section.children;
170
+ if (!children.length) return;
171
+ const last = children[children.length - 1];
172
+ // If last element is a Paragraph containing only PageBreak, remove it
173
+ if (last instanceof Paragraph) {
174
+ const runs = last.root?.filter(c => c instanceof PageBreak);
175
+ if (runs?.length && !last.root?.some(c => c instanceof TextRun)) {
176
+ children.pop();
177
+ }
178
+ }
179
+ }
180
+ ```
181
+
182
+ **Prevention rules:**
183
+ - Place PageBreak at the **start of the next section**, not the end of the previous one
184
+ - Or use separate sections for pagination (no PageBreak needed)
185
+ - The last section of a document must NEVER end with a PageBreak
186
+
187
+ ---
188
+
189
+ ## Bug: Different rendering in WPS vs Microsoft Word
190
+
191
+ **Symptom**: Document looks correct in Word but renders differently in WPS (or vice versa) — misaligned tables, shifted content, clipped text in cells, black cells, or broken covers.
192
+
193
+ **Root causes and fixes:**
194
+
195
+ ### 1. `ShadingType.SOLID` shows black in WPS
196
+ ```js
197
+ // ❌ WPS shows solid black
198
+ shading: { type: ShadingType.SOLID, fill: "F1F5F9" }
199
+ // ✅ Both renderers show correct color
200
+ shading: { type: ShadingType.CLEAR, fill: "F1F5F9" }
201
+ ```
202
+
203
+ ### 2. `verticalAlign: "center"` in exact-height rows shifts content
204
+ WPS ignores vertical centering in `rule: "exact"` rows — content stays at top, creating visual mismatch.
205
+ ```js
206
+ // ❌ Inconsistent between Word and WPS
207
+ new TableRow({ height: { value: 800, rule: "exact" },
208
+ children: [new TableCell({ verticalAlign: VerticalAlign.CENTER, ... })] })
209
+ // ✅ Use top alignment + margins/spacing for positioning
210
+ new TableRow({ height: { value: 800, rule: "exact" },
211
+ children: [new TableCell({ verticalAlign: VerticalAlign.TOP,
212
+ margins: { top: 200 }, ... })] })
213
+ ```
214
+
215
+ ### 3. Tab stops misalign in WPS
216
+ Tab widths differ between Word and WPS. Never use tabs for alignment.
217
+ ```js
218
+ // ❌ Tab-based alignment — breaks in WPS
219
+ new Paragraph({ tabStops: [{ type: TabStopType.RIGHT, position: 8000 }],
220
+ children: [new TextRun({ text: "Party A:\tCompany Name" })] })
221
+ // ✅ Borderless table for alignment — consistent everywhere
222
+ new Table({ borders: allNoBorders, rows: [new TableRow({ children: [
223
+ new TableCell({ children: [new Paragraph({ children: [new TextRun({ text: "Party A:" })] })] }),
224
+ new TableCell({ children: [new Paragraph({ children: [new TextRun({ text: "Company Name" })] })] }),
225
+ ] })] })
226
+ ```
227
+
228
+ ### 4. Nested tables in exact-height cells overflow differently
229
+ Word calculates nested table heights more accurately than WPS. Use stacked tables instead.
230
+ ```js
231
+ // ❌ Nested table inside exact-height cell
232
+ new TableRow({ height: { value: 16838, rule: "exact" },
233
+ children: [new TableCell({ children: [nestedTable1, nestedTable2] })] })
234
+ // ✅ Stacked approach — content table + filler table
235
+ [contentTable, fillerTable] // both at top level, heights sum to 16838
236
+ ```
237
+
238
+ ### 5. `characterSpacing` renders differently
239
+ Large `characterSpacing` values cause inconsistent letter spacing. Keep ≤ 80.
240
+
241
+ ### 6. `titlePage: true` header/footer suppression
242
+ WPS may not correctly hide first-page headers when using `titlePage: true`. Use a separate section for the cover instead.
243
+
244
+ ---
245
+
246
+ ## Bug: Cover spills to second page
247
+
248
+ **Symptom**: Cover content overflows, with some elements (date, footer, accent strip) appearing on page 2.
249
+
250
+ **Root cause**: Total content height exceeds 16838 twips (A4 page height). Common when:
251
+ - Title is very long (3+ lines at large font size)
252
+ - Fixed spacing values assume short title
253
+ - Multiple meta lines + subtitle + English label
254
+
255
+ **Fix**: Always use `calcTitleLayout()` + `calcCoverSpacing()` from `design-system.md`. These dynamically adjust font sizes and spacing to fit within the page. See `design-system.md § Cover Content Overflow Prevention` for the complete checklist.
256
+
257
+ ---
258
+
259
+ ## Bug: Blank page 2 after cover in MS Office (but not WPS)
260
+
261
+ **Symptom**: Cover displays correctly in WPS but produces a blank second page in MS Office Word.
262
+
263
+ **Root cause**: The cover wrapper table uses **default docx-js table borders** (`single/auto/sz=4`) instead of explicitly setting `allNoBorders`. Default borders add ~8 twips per edge. MS Office includes border thickness in the exact-height row calculation, pushing total height past 16838 twips → overflow to page 2. WPS is more lenient and absorbs the extra pixels.
264
+
265
+ **Fix**: Every cover wrapper table MUST explicitly set `borders: allNoBorders`:
266
+ ```js
267
+ const NB = { style: BorderStyle.NONE, size: 0, color: "FFFFFF" };
268
+ const allNoBorders = { top: NB, bottom: NB, left: NB, right: NB,
269
+ insideHorizontal: NB, insideVertical: NB };
270
+
271
+ new Table({
272
+ borders: allNoBorders, // ← MANDATORY
273
+ rows: [new TableRow({
274
+ height: { value: 16838, rule: "exact" },
275
+ // ...
276
+ })],
277
+ });
278
+ ```
279
+
280
+ **Prevention**: Add to post-generation check — search for any `new Table` in cover code that does not explicitly set `borders`.
281
+
282
+ ---
283
+
284
+ ## Bug: Cover decorative lines appear truncated or misaligned
285
+
286
+ **Symptom**: Horizontal decorative lines on the cover (accent strips, divider rules) display at different widths in MS Office vs WPS, or appear truncated / not spanning the intended width.
287
+
288
+ **Root cause**: Lines were implemented using text characters (`───`, `━━━`, `═══`, `——————`) instead of paragraph borders. Character-drawn lines depend on font metrics (character width × count), which vary across rendering engines.
289
+
290
+ **Fix**: Always use **paragraph borders** for decorative lines:
291
+ ```js
292
+ // ✅ Paragraph border — renders consistently in both MS Office and WPS
293
+ new Paragraph({
294
+ indent: { left: 1000, right: 1000 },
295
+ border: { top: { style: BorderStyle.SINGLE, size: 18, color: accentColor, space: 20 } },
296
+ children: [],
297
+ })
298
+
299
+ // ❌ NEVER use text characters for decorative lines
300
+ new TextRun({ text: "───────────────" }) // width varies across engines
301
+ ```
302
+
303
+ **Note**: This applies to ALL cover recipes (R1–R5). Recipe R2 uses `border.top` and `border.bottom` for its double-rule frame — follow this pattern.
304
+
305
+ ---
306
+
307
+ ## Bug: "undefined" appears in document text
308
+
309
+ **Symptom**: Fields like "Contact: undefined" or "Location: undefined" in generated documents.
310
+
311
+ **Root cause**: JavaScript outputs the string `"undefined"` when accessing a property that doesn't exist on the config object.
312
+
313
+ **Fix**: Use `safeText()` helper for ALL user-facing text values:
314
+ ```js
315
+ function safeText(value, placeholder) {
316
+ if (value === undefined || value === null || value === "" ||
317
+ String(value) === "NaN" || String(value) === "undefined") {
318
+ return placeholder || "【Please fill in】";
319
+ }
320
+ return String(value);
321
+ }
322
+ // Usage: new TextRun({ text: safeText(config.contact, "【Contact person】") })
323
+ ```
@@ -0,0 +1,276 @@
1
+ # Math Formulas — LaTeX → docx-js Mapping
2
+
3
+ ## Design Philosophy
4
+
5
+ GLM uses **LaTeX as the formula input syntax**, internally converting to docx-js Math objects.
6
+
7
+ **Why not write OMML directly?**
8
+ - Models are naturally proficient in LaTeX (abundant in training data)
9
+ - LaTeX is semantically clear and highly readable
10
+ - Conversion layer is encapsulated internally, transparent to the user
11
+
12
+ ## Quick Start
13
+
14
+ ```js
15
+ const { Math: OoxmlMath, MathRun, MathFraction, MathSuperScript,
16
+ MathSubScript, MathRadical, MathSum, MathSubSuperScript } = require("docx");
17
+
18
+ // Embed formula in paragraph
19
+ new Paragraph({
20
+ alignment: AlignmentType.CENTER,
21
+ children: [
22
+ new OoxmlMath({
23
+ children: [/* Math components */]
24
+ })
25
+ ]
26
+ })
27
+ ```
28
+
29
+ ## LaTeX → docx-js Conversion Table
30
+
31
+ ### Basic Operations
32
+
33
+ | LaTeX | Meaning | docx-js Implementation |
34
+ |-------|---------|----------------------|
35
+ | `x + y` | Addition | `new MathRun("x + y")` |
36
+ | `x - y` | Subtraction | `new MathRun("x − y")` (use Unicode minus `−`) |
37
+ | `x \times y` | Multiplication | `new MathRun("x × y")` |
38
+ | `x \div y` | Division | `new MathRun("x ÷ y")` |
39
+ | `x \pm y` | Plus-minus | `new MathRun("x ± y")` |
40
+ | `x \neq y` | Not equal | `new MathRun("x ≠ y")` |
41
+ | `x \leq y` | Less or equal | `new MathRun("x ≤ y")` |
42
+ | `x \geq y` | Greater or equal | `new MathRun("x ≥ y")` |
43
+
44
+ ### Fractions
45
+
46
+ | LaTeX | docx-js |
47
+ |-------|---------|
48
+ | `\frac{a}{b}` | `new MathFraction({ numerator: [new MathRun("a")], denominator: [new MathRun("b")] })` |
49
+ | `\frac{x+1}{x-1}` | `new MathFraction({ numerator: [new MathRun("x+1")], denominator: [new MathRun("x−1")] })` |
50
+
51
+ ### Superscripts & Subscripts
52
+
53
+ | LaTeX | docx-js |
54
+ |-------|---------|
55
+ | `x^2` | `new MathSuperScript({ children: [new MathRun("x")], superScript: [new MathRun("2")] })` |
56
+ | `x_i` | `new MathSubScript({ children: [new MathRun("x")], subScript: [new MathRun("i")] })` |
57
+ | `x_i^2` | `new MathSubSuperScript({ children: [new MathRun("x")], subScript: [new MathRun("i")], superScript: [new MathRun("2")] })` |
58
+
59
+ ### Radicals
60
+
61
+ | LaTeX | docx-js |
62
+ |-------|---------|
63
+ | `\sqrt{x}` | `new MathRadical({ children: [new MathRun("x")] })` |
64
+ | `\sqrt[3]{x}` | `new MathRadical({ children: [new MathRun("x")], degree: [new MathRun("3")] })` |
65
+
66
+ ### Summation & Integrals
67
+
68
+ | LaTeX | docx-js |
69
+ |-------|---------|
70
+ | `\sum_{i=1}^{n}` | `new MathSum({ subScript: [new MathRun("i=1")], superScript: [new MathRun("n")], children: [new MathRun("aᵢ")] })` |
71
+
72
+ ### Greek Letters
73
+
74
+ Use Unicode characters directly:
75
+
76
+ ```js
77
+ // LaTeX → Unicode mapping
78
+ const GREEK = {
79
+ "\\alpha": "α", "\\beta": "β", "\\gamma": "γ", "\\delta": "δ",
80
+ "\\epsilon": "ε", "\\zeta": "ζ", "\\eta": "η", "\\theta": "θ",
81
+ "\\iota": "ι", "\\kappa": "κ", "\\lambda": "λ", "\\mu": "μ",
82
+ "\\nu": "ν", "\\xi": "ξ", "\\pi": "π", "\\rho": "ρ",
83
+ "\\sigma": "σ", "\\tau": "τ", "\\phi": "φ", "\\chi": "χ",
84
+ "\\psi": "ψ", "\\omega": "ω",
85
+ "\\Alpha": "Α", "\\Beta": "Β", "\\Gamma": "Γ", "\\Delta": "Δ",
86
+ "\\Theta": "Θ", "\\Lambda": "Λ", "\\Pi": "Π", "\\Sigma": "Σ",
87
+ "\\Phi": "Φ", "\\Psi": "Ψ", "\\Omega": "Ω",
88
+ };
89
+ ```
90
+
91
+ ## Complete Formula Examples
92
+
93
+ ### Quadratic Formula
94
+
95
+ LaTeX: `x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}`
96
+
97
+ ```js
98
+ new OoxmlMath({
99
+ children: [
100
+ new MathRun("x = "),
101
+ new MathFraction({
102
+ numerator: [
103
+ new MathRun("−b ± "),
104
+ new MathRadical({
105
+ children: [
106
+ new MathSuperScript({
107
+ children: [new MathRun("b")],
108
+ superScript: [new MathRun("2")],
109
+ }),
110
+ new MathRun(" − 4ac"),
111
+ ],
112
+ }),
113
+ ],
114
+ denominator: [new MathRun("2a")],
115
+ }),
116
+ ],
117
+ })
118
+ ```
119
+
120
+ ### Pythagorean Theorem
121
+
122
+ LaTeX: `a^2 + b^2 = c^2`
123
+
124
+ ```js
125
+ new OoxmlMath({
126
+ children: [
127
+ new MathSuperScript({ children: [new MathRun("a")], superScript: [new MathRun("2")] }),
128
+ new MathRun(" + "),
129
+ new MathSuperScript({ children: [new MathRun("b")], superScript: [new MathRun("2")] }),
130
+ new MathRun(" = "),
131
+ new MathSuperScript({ children: [new MathRun("c")], superScript: [new MathRun("2")] }),
132
+ ],
133
+ })
134
+ ```
135
+
136
+ ### Trigonometric Identity
137
+
138
+ LaTeX: `\sin^2\theta + \cos^2\theta = 1`
139
+
140
+ ```js
141
+ new OoxmlMath({
142
+ children: [
143
+ new MathSuperScript({ children: [new MathRun("sin")], superScript: [new MathRun("2")] }),
144
+ new MathRun("θ + "),
145
+ new MathSuperScript({ children: [new MathRun("cos")], superScript: [new MathRun("2")] }),
146
+ new MathRun("θ = 1"),
147
+ ],
148
+ })
149
+ ```
150
+
151
+ ## Common Exam Formula Templates
152
+
153
+ ### Middle School Math
154
+
155
+ ```js
156
+ // Quadratic discriminant
157
+ const discriminant = new OoxmlMath({
158
+ children: [
159
+ new MathRun("Δ = "),
160
+ new MathSuperScript({ children: [new MathRun("b")], superScript: [new MathRun("2")] }),
161
+ new MathRun(" − 4ac"),
162
+ ],
163
+ });
164
+
165
+ // Circle area
166
+ const circleArea = new OoxmlMath({
167
+ children: [
168
+ new MathRun("S = π"),
169
+ new MathSuperScript({ children: [new MathRun("r")], superScript: [new MathRun("2")] }),
170
+ ],
171
+ });
172
+ ```
173
+
174
+ ### High School Math
175
+
176
+ ```js
177
+ // Logarithm change of base
178
+ const logChange = new OoxmlMath({
179
+ children: [
180
+ new MathSubScript({ children: [new MathRun("log")], subScript: [new MathRun("a")] }),
181
+ new MathRun("b = "),
182
+ new MathFraction({
183
+ numerator: [new MathRun("ln b")],
184
+ denominator: [new MathRun("ln a")],
185
+ }),
186
+ ],
187
+ });
188
+
189
+ // Arithmetic series sum
190
+ const arithmeticSum = new OoxmlMath({
191
+ children: [
192
+ new MathSubScript({ children: [new MathRun("S")], subScript: [new MathRun("n")] }),
193
+ new MathRun(" = "),
194
+ new MathFraction({
195
+ numerator: [
196
+ new MathRun("n("),
197
+ new MathSubScript({ children: [new MathRun("a")], subScript: [new MathRun("1")] }),
198
+ new MathRun(" + "),
199
+ new MathSubScript({ children: [new MathRun("a")], subScript: [new MathRun("n")] }),
200
+ new MathRun(")"),
201
+ ],
202
+ denominator: [new MathRun("2")],
203
+ }),
204
+ ],
205
+ });
206
+ ```
207
+
208
+ ### Physics
209
+
210
+ ```js
211
+ // Newton's second law
212
+ const newton2 = new OoxmlMath({
213
+ children: [new MathRun("F = ma")],
214
+ });
215
+
216
+ // Kinetic energy
217
+ const kineticEnergy = new OoxmlMath({
218
+ children: [
219
+ new MathSubScript({ children: [new MathRun("E")], subScript: [new MathRun("k")] }),
220
+ new MathRun(" = "),
221
+ new MathFraction({
222
+ numerator: [new MathRun("1")],
223
+ denominator: [new MathRun("2")],
224
+ }),
225
+ new MathRun("m"),
226
+ new MathSuperScript({ children: [new MathRun("v")], superScript: [new MathRun("2")] }),
227
+ ],
228
+ });
229
+ ```
230
+
231
+ ## Complexity Fallback Strategy
232
+
233
+ When formulas are too complex (nesting >3 levels) for docx-js Math, **fall back to matplotlib PNG rendering:**
234
+
235
+ ```python
236
+ import matplotlib
237
+ matplotlib.use("Agg")
238
+ import matplotlib.pyplot as plt
239
+
240
+ def latex_to_png(latex_str: str, output_path: str, fontsize: int = 14, dpi: int = 200):
241
+ """Render LaTeX formula as PNG image"""
242
+ fig, ax = plt.subplots(figsize=(0.1, 0.1))
243
+ ax.axis("off")
244
+ text = ax.text(0, 0.5, f"${latex_str}$", fontsize=fontsize,
245
+ transform=ax.transAxes, verticalalignment="center")
246
+
247
+ fig.canvas.draw()
248
+ bbox = text.get_window_extent(fig.canvas.get_renderer())
249
+ fig.set_size_inches(bbox.width / dpi + 0.2, bbox.height / dpi + 0.2)
250
+
251
+ plt.savefig(output_path, dpi=dpi, bbox_inches="tight",
252
+ pad_inches=0.05, transparent=True)
253
+ plt.close()
254
+ return output_path
255
+ ```
256
+
257
+ Then embed the PNG in the document:
258
+
259
+ ```js
260
+ const formulaImg = fs.readFileSync("formula.png");
261
+ new Paragraph({
262
+ alignment: AlignmentType.CENTER,
263
+ children: [new ImageRun({
264
+ data: formulaImg,
265
+ transformation: { width: 300, height: 40 }, // adjust based on actual size
266
+ type: "png",
267
+ })],
268
+ })
269
+ ```
270
+
271
+ **Fallback rules:**
272
+ - Nested fractions >2 levels → fallback
273
+ - Matrices/determinants → fallback
274
+ - Complex integrals (multiple integrals + limits + integrand) → fallback
275
+ - Piecewise functions → fallback
276
+ - All other cases → prefer docx-js Math