docrev 0.10.1 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (167) hide show
  1. package/.gitattributes +1 -1
  2. package/CHANGELOG.md +184 -173
  3. package/PLAN-tables-and-postprocess.md +850 -850
  4. package/README.md +431 -431
  5. package/bin/rev.js +11 -11
  6. package/bin/rev.ts +145 -145
  7. package/completions/rev.bash +127 -127
  8. package/completions/rev.ps1 +210 -210
  9. package/completions/rev.zsh +207 -207
  10. package/dist/lib/anchor-match.d.ts +4 -2
  11. package/dist/lib/anchor-match.d.ts.map +1 -1
  12. package/dist/lib/anchor-match.js +52 -24
  13. package/dist/lib/anchor-match.js.map +1 -1
  14. package/dist/lib/annotations.d.ts +0 -6
  15. package/dist/lib/annotations.d.ts.map +1 -1
  16. package/dist/lib/annotations.js +26 -8
  17. package/dist/lib/annotations.js.map +1 -1
  18. package/dist/lib/build.d.ts.map +1 -1
  19. package/dist/lib/build.js +13 -10
  20. package/dist/lib/build.js.map +1 -1
  21. package/dist/lib/commands/build.d.ts.map +1 -1
  22. package/dist/lib/commands/build.js +5 -0
  23. package/dist/lib/commands/build.js.map +1 -1
  24. package/dist/lib/commands/doi.d.ts.map +1 -1
  25. package/dist/lib/commands/doi.js +14 -2
  26. package/dist/lib/commands/doi.js.map +1 -1
  27. package/dist/lib/commands/sync.d.ts.map +1 -1
  28. package/dist/lib/commands/sync.js +98 -107
  29. package/dist/lib/commands/sync.js.map +1 -1
  30. package/dist/lib/commands/utilities.js +164 -164
  31. package/dist/lib/commands/word-tools.js +8 -8
  32. package/dist/lib/comment-realign.d.ts +12 -21
  33. package/dist/lib/comment-realign.d.ts.map +1 -1
  34. package/dist/lib/comment-realign.js +40 -348
  35. package/dist/lib/comment-realign.js.map +1 -1
  36. package/dist/lib/dependencies.d.ts +10 -0
  37. package/dist/lib/dependencies.d.ts.map +1 -1
  38. package/dist/lib/dependencies.js +41 -9
  39. package/dist/lib/dependencies.js.map +1 -1
  40. package/dist/lib/doi.d.ts.map +1 -1
  41. package/dist/lib/doi.js +68 -80
  42. package/dist/lib/doi.js.map +1 -1
  43. package/dist/lib/errors.d.ts.map +1 -1
  44. package/dist/lib/errors.js +3 -1
  45. package/dist/lib/errors.js.map +1 -1
  46. package/dist/lib/grammar.js +3 -3
  47. package/dist/lib/import.d.ts +7 -4
  48. package/dist/lib/import.d.ts.map +1 -1
  49. package/dist/lib/import.js +58 -62
  50. package/dist/lib/import.js.map +1 -1
  51. package/dist/lib/macro-filter.lua +201 -201
  52. package/dist/lib/ooxml.d.ts +207 -0
  53. package/dist/lib/ooxml.d.ts.map +1 -0
  54. package/dist/lib/ooxml.js +634 -0
  55. package/dist/lib/ooxml.js.map +1 -0
  56. package/dist/lib/pdf-comments.js +44 -44
  57. package/dist/lib/plugins.js +57 -57
  58. package/dist/lib/pptx-color-filter.lua +37 -37
  59. package/dist/lib/pptx-themes.js +115 -115
  60. package/dist/lib/rate-limiter.d.ts +8 -0
  61. package/dist/lib/rate-limiter.d.ts.map +1 -1
  62. package/dist/lib/rate-limiter.js +41 -4
  63. package/dist/lib/rate-limiter.js.map +1 -1
  64. package/dist/lib/sections.d.ts.map +1 -1
  65. package/dist/lib/sections.js +5 -2
  66. package/dist/lib/sections.js.map +1 -1
  67. package/dist/lib/spelling.js +2 -2
  68. package/dist/lib/templates.js +387 -387
  69. package/dist/lib/themes.js +51 -51
  70. package/dist/lib/types.d.ts +9 -1
  71. package/dist/lib/types.d.ts.map +1 -1
  72. package/dist/lib/word-extraction.d.ts.map +1 -1
  73. package/dist/lib/word-extraction.js +48 -307
  74. package/dist/lib/word-extraction.js.map +1 -1
  75. package/dist/lib/word.d.ts.map +1 -1
  76. package/dist/lib/word.js +80 -175
  77. package/dist/lib/word.js.map +1 -1
  78. package/dist/lib/wordcomments.d.ts.map +1 -1
  79. package/dist/lib/wordcomments.js +53 -92
  80. package/dist/lib/wordcomments.js.map +1 -1
  81. package/docs-src/build.py +113 -113
  82. package/docs-src/extra.css +208 -208
  83. package/docs-src/md-to-html.lua +6 -6
  84. package/docs-src/template.html +116 -116
  85. package/eslint.config.js +27 -27
  86. package/lib/anchor-match.ts +307 -276
  87. package/lib/annotations.ts +664 -644
  88. package/lib/build.ts +1770 -1766
  89. package/lib/citations.ts +160 -160
  90. package/lib/commands/build.ts +860 -855
  91. package/lib/commands/citations.ts +515 -515
  92. package/lib/commands/comments.ts +1050 -1050
  93. package/lib/commands/context.ts +176 -176
  94. package/lib/commands/core.ts +309 -309
  95. package/lib/commands/doi.ts +451 -435
  96. package/lib/commands/file-ops.ts +372 -372
  97. package/lib/commands/history.ts +320 -320
  98. package/lib/commands/index.ts +87 -87
  99. package/lib/commands/init.ts +259 -259
  100. package/lib/commands/merge-resolve.ts +378 -378
  101. package/lib/commands/preview.ts +178 -178
  102. package/lib/commands/project-info.ts +244 -244
  103. package/lib/commands/quality.ts +517 -517
  104. package/lib/commands/response.ts +454 -454
  105. package/lib/commands/section-boundaries.ts +82 -82
  106. package/lib/commands/sections.ts +451 -451
  107. package/lib/commands/sync.ts +689 -709
  108. package/lib/commands/text-ops.ts +449 -449
  109. package/lib/commands/utilities.ts +448 -448
  110. package/lib/commands/verify-anchors.ts +272 -272
  111. package/lib/commands/word-tools.ts +340 -340
  112. package/lib/comment-realign.ts +99 -517
  113. package/lib/config.ts +84 -84
  114. package/lib/crossref.ts +781 -781
  115. package/lib/csl.ts +191 -191
  116. package/lib/dependencies.ts +132 -98
  117. package/lib/diff-engine.ts +465 -465
  118. package/lib/doi-cache.ts +115 -115
  119. package/lib/doi.ts +879 -897
  120. package/lib/equations.ts +506 -506
  121. package/lib/errors.ts +350 -346
  122. package/lib/format.ts +541 -541
  123. package/lib/git.ts +326 -326
  124. package/lib/grammar.ts +303 -303
  125. package/lib/image-registry.ts +180 -180
  126. package/lib/import.ts +906 -911
  127. package/lib/journals.ts +543 -543
  128. package/lib/macro-filter.lua +201 -201
  129. package/lib/macros.ts +273 -273
  130. package/lib/merge.ts +633 -633
  131. package/lib/ooxml.ts +768 -0
  132. package/lib/orcid.ts +144 -144
  133. package/lib/pdf-comments.ts +263 -263
  134. package/lib/pdf-import.ts +524 -524
  135. package/lib/plugins.ts +362 -362
  136. package/lib/postprocess.ts +188 -188
  137. package/lib/pptx-color-filter.lua +37 -37
  138. package/lib/pptx-template.ts +469 -469
  139. package/lib/pptx-themes.ts +483 -483
  140. package/lib/protect-restore.ts +520 -520
  141. package/lib/rate-limiter.ts +127 -94
  142. package/lib/response.ts +197 -197
  143. package/lib/restore-references.ts +240 -240
  144. package/lib/review.ts +327 -327
  145. package/lib/schema.ts +488 -488
  146. package/lib/scientific-words.ts +73 -73
  147. package/lib/sections.ts +428 -425
  148. package/lib/slides.ts +756 -756
  149. package/lib/spelling.ts +334 -334
  150. package/lib/templates.ts +526 -526
  151. package/lib/themes.ts +742 -742
  152. package/lib/trackchanges.ts +247 -247
  153. package/lib/tui.ts +450 -450
  154. package/lib/types.ts +558 -550
  155. package/lib/undo.ts +250 -250
  156. package/lib/utils.ts +69 -69
  157. package/lib/variables.ts +179 -179
  158. package/lib/word-extraction.ts +525 -806
  159. package/lib/word.ts +526 -643
  160. package/lib/wordcomments.ts +789 -840
  161. package/mkdocs.yml +64 -64
  162. package/package.json +137 -137
  163. package/scripts/postbuild.js +47 -47
  164. package/skill/REFERENCE.md +539 -539
  165. package/skill/SKILL.md +295 -295
  166. package/tsconfig.json +26 -26
  167. package/types/index.d.ts +525 -525
@@ -1,483 +1,483 @@
1
- /**
2
- * PPTX Theme System
3
- *
4
- * Provides 6 built-in themes for PPTX output, independent of Beamer themes.
5
- * Each theme is a reference PPTX file that defines colors, fonts, and slide layouts.
6
- *
7
- * Uses pandoc's default reference.pptx as the base template and modifies the theme.xml
8
- * to apply custom colors and fonts. This ensures all 11 required slide layouts are present.
9
- *
10
- * Themes:
11
- * - default: Clean white with blue accents (professional)
12
- * - dark: Dark background with light text (modern)
13
- * - academic: Classic serif fonts, muted colors (scholarly)
14
- * - minimal: High contrast black/white (clean)
15
- * - corporate: Navy/gold color scheme (business)
16
- * - plant: Nature-inspired green theme (ecology/biology)
17
- */
18
-
19
- import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
20
- import { join, dirname } from 'node:path';
21
- import { fileURLToPath } from 'node:url';
22
- import { execSync } from 'node:child_process';
23
- import AdmZip from 'adm-zip';
24
-
25
- const __dirname = dirname(fileURLToPath(import.meta.url));
26
-
27
- /**
28
- * Color scheme for a theme
29
- */
30
- interface ThemeColors {
31
- dk1: string;
32
- lt1: string;
33
- dk2: string;
34
- lt2: string;
35
- accent1: string;
36
- accent2: string;
37
- accent3: string;
38
- accent4: string;
39
- accent5: string;
40
- accent6: string;
41
- hlink: string;
42
- folHlink: string;
43
- }
44
-
45
- /**
46
- * Font scheme for a theme
47
- */
48
- interface ThemeFonts {
49
- major: string;
50
- minor: string;
51
- }
52
-
53
- /**
54
- * PPTX theme definition
55
- */
56
- interface PptxTheme {
57
- name: string;
58
- description: string;
59
- colors: ThemeColors;
60
- fonts: ThemeFonts;
61
- background?: string;
62
- }
63
-
64
- /**
65
- * Theme definitions with colors and fonts
66
- */
67
- export const PPTX_THEMES: Record<string, PptxTheme> = {
68
- default: {
69
- name: 'Default',
70
- description: 'Clean white with blue accents',
71
- colors: {
72
- dk1: '000000', // Dark text
73
- lt1: 'FFFFFF', // Light background
74
- dk2: '1F497D', // Dark accent (navy)
75
- lt2: 'EEECE1', // Light accent (cream)
76
- accent1: '4472C4', // Blue
77
- accent2: 'ED7D31', // Orange
78
- accent3: 'A5A5A5', // Gray
79
- accent4: 'FFC000', // Yellow
80
- accent5: '5B9BD5', // Light blue
81
- accent6: '70AD47', // Green
82
- hlink: '0563C1', // Hyperlink blue
83
- folHlink: '954F72', // Followed hyperlink
84
- },
85
- fonts: {
86
- major: 'Calibri Light',
87
- minor: 'Calibri',
88
- },
89
- },
90
- dark: {
91
- name: 'Dark',
92
- description: 'Dark background with light text',
93
- colors: {
94
- dk1: 'FFFFFF', // Light text (inverted)
95
- lt1: '1E1E1E', // Dark background
96
- dk2: 'E0E0E0', // Light gray
97
- lt2: '2D2D2D', // Darker gray
98
- accent1: '00B4D8', // Cyan
99
- accent2: 'FF6B6B', // Coral
100
- accent3: '95E1D3', // Mint
101
- accent4: 'F38181', // Pink
102
- accent5: 'AA96DA', // Lavender
103
- accent6: 'FCBAD3', // Light pink
104
- hlink: '00B4D8',
105
- folHlink: 'AA96DA',
106
- },
107
- fonts: {
108
- major: 'Inter',
109
- minor: 'Inter',
110
- },
111
- background: '1E1E1E',
112
- },
113
- academic: {
114
- name: 'Academic',
115
- description: 'Classic serif fonts, muted colors',
116
- colors: {
117
- dk1: '2C3E50', // Dark blue-gray
118
- lt1: 'FFFEF9', // Warm white
119
- dk2: '34495E', // Slate
120
- lt2: 'F5F5DC', // Beige
121
- accent1: '8B4513', // Saddle brown
122
- accent2: '2E8B57', // Sea green
123
- accent3: '708090', // Slate gray
124
- accent4: 'B8860B', // Dark goldenrod
125
- accent5: '4682B4', // Steel blue
126
- accent6: '6B8E23', // Olive drab
127
- hlink: '8B4513',
128
- folHlink: '708090',
129
- },
130
- fonts: {
131
- major: 'Georgia',
132
- minor: 'Palatino Linotype',
133
- },
134
- },
135
- minimal: {
136
- name: 'Minimal',
137
- description: 'High contrast black and white',
138
- colors: {
139
- dk1: '000000', // Pure black
140
- lt1: 'FFFFFF', // Pure white
141
- dk2: '333333', // Dark gray
142
- lt2: 'F0F0F0', // Light gray
143
- accent1: '000000', // Black accent
144
- accent2: '666666', // Medium gray
145
- accent3: '999999', // Light gray
146
- accent4: 'CCCCCC', // Lighter gray
147
- accent5: '333333', // Dark gray
148
- accent6: '4D4D4D', // Charcoal
149
- hlink: '000000',
150
- folHlink: '666666',
151
- },
152
- fonts: {
153
- major: 'Roboto Light',
154
- minor: 'Roboto',
155
- },
156
- },
157
- corporate: {
158
- name: 'Corporate',
159
- description: 'Navy and gold professional theme',
160
- colors: {
161
- dk1: '0D1B2A', // Very dark navy
162
- lt1: 'FFFFFF', // White
163
- dk2: '1B263B', // Dark navy
164
- lt2: 'E0E1DD', // Light gray
165
- accent1: 'D4AF37', // Gold
166
- accent2: '415A77', // Steel blue
167
- accent3: '778DA9', // Light steel
168
- accent4: 'C5A900', // Darker gold
169
- accent5: '1B4965', // Deep blue
170
- accent6: '5FA8D3', // Sky blue
171
- hlink: 'D4AF37',
172
- folHlink: '778DA9',
173
- },
174
- fonts: {
175
- major: 'Garamond',
176
- minor: 'Garamond',
177
- },
178
- },
179
- plant: {
180
- name: 'Plant',
181
- description: 'Nature-inspired green theme for ecology/biology',
182
- colors: {
183
- dk1: '2D4A22', // Dark forest green
184
- lt1: 'FFFFFF', // White
185
- dk2: '3D5A2E', // Medium forest
186
- lt2: 'F5F7F2', // Light sage
187
- accent1: '608C32', // Primary green (theme accent)
188
- accent2: '8B4513', // Earth brown
189
- accent3: '888888', // Gray (for buildup)
190
- accent4: '7CB342', // Light green
191
- accent5: '4A6B3A', // Olive green
192
- accent6: 'A5D6A7', // Pale green
193
- hlink: '608C32',
194
- folHlink: '4A6B3A',
195
- },
196
- fonts: {
197
- major: 'Aptos Display',
198
- minor: 'Aptos',
199
- },
200
- },
201
- };
202
-
203
- /**
204
- * Get list of available theme names
205
- */
206
- export function getThemeNames(): string[] {
207
- return Object.keys(PPTX_THEMES);
208
- }
209
-
210
- /**
211
- * Get theme definition by name
212
- */
213
- export function getTheme(name: string): PptxTheme | null {
214
- return PPTX_THEMES[name] || null;
215
- }
216
-
217
- /**
218
- * Generate [Content_Types].xml
219
- */
220
- function generateContentTypes(): string {
221
- return `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
222
- <Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
223
- <Default Extension="jpeg" ContentType="image/jpeg"/>
224
- <Default Extension="png" ContentType="image/png"/>
225
- <Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>
226
- <Default Extension="xml" ContentType="application/xml"/>
227
- <Override PartName="/ppt/presentation.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.presentation.main+xml"/>
228
- <Override PartName="/ppt/slideMasters/slideMaster1.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.slideMaster+xml"/>
229
- <Override PartName="/ppt/slideLayouts/slideLayout1.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.slideLayout+xml"/>
230
- <Override PartName="/ppt/slideLayouts/slideLayout2.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.slideLayout+xml"/>
231
- <Override PartName="/ppt/theme/theme1.xml" ContentType="application/vnd.openxmlformats-officedocument.theme+xml"/>
232
- <Override PartName="/docProps/core.xml" ContentType="application/vnd.openxmlformats-package.core-properties+xml"/>
233
- <Override PartName="/docProps/app.xml" ContentType="application/vnd.openxmlformats-officedocument.extended-properties+xml"/>
234
- </Types>`;
235
- }
236
-
237
- /**
238
- * Generate _rels/.rels
239
- */
240
- function generateRels(): string {
241
- return `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
242
- <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
243
- <Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="ppt/presentation.xml"/>
244
- <Relationship Id="rId2" Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties" Target="docProps/core.xml"/>
245
- <Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties" Target="docProps/app.xml"/>
246
- </Relationships>`;
247
- }
248
-
249
- /**
250
- * Generate ppt/_rels/presentation.xml.rels
251
- */
252
- function generatePresentationRels(): string {
253
- return `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
254
- <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
255
- <Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideMaster" Target="slideMasters/slideMaster1.xml"/>
256
- <Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme" Target="theme/theme1.xml"/>
257
- </Relationships>`;
258
- }
259
-
260
- /**
261
- * Generate ppt/presentation.xml
262
- */
263
- function generatePresentation(): string {
264
- return `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
265
- <p:presentation xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main" saveSubsetFonts="1">
266
- <p:sldMasterIdLst>
267
- <p:sldMasterId id="2147483648" r:id="rId1"/>
268
- </p:sldMasterIdLst>
269
- <p:sldSz cx="12192000" cy="6858000"/>
270
- <p:notesSz cx="6858000" cy="9144000"/>
271
- <p:defaultTextStyle>
272
- <a:defPPr>
273
- <a:defRPr lang="en-US"/>
274
- </a:defPPr>
275
- </p:defaultTextStyle>
276
- </p:presentation>`;
277
- }
278
-
279
- /**
280
- * Generate ppt/theme/theme1.xml with theme colors and fonts
281
- */
282
- function generateTheme(theme: PptxTheme): string {
283
- const c = theme.colors;
284
- const f = theme.fonts;
285
-
286
- return `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
287
- <a:theme xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" name="${theme.name}">
288
- <a:themeElements>
289
- <a:clrScheme name="${theme.name}">
290
- <a:dk1><a:srgbClr val="${c.dk1}"/></a:dk1>
291
- <a:lt1><a:srgbClr val="${c.lt1}"/></a:lt1>
292
- <a:dk2><a:srgbClr val="${c.dk2}"/></a:dk2>
293
- <a:lt2><a:srgbClr val="${c.lt2}"/></a:lt2>
294
- <a:accent1><a:srgbClr val="${c.accent1}"/></a:accent1>
295
- <a:accent2><a:srgbClr val="${c.accent2}"/></a:accent2>
296
- <a:accent3><a:srgbClr val="${c.accent3}"/></a:accent3>
297
- <a:accent4><a:srgbClr val="${c.accent4}"/></a:accent4>
298
- <a:accent5><a:srgbClr val="${c.accent5}"/></a:accent5>
299
- <a:accent6><a:srgbClr val="${c.accent6}"/></a:accent6>
300
- <a:hlink><a:srgbClr val="${c.hlink}"/></a:hlink>
301
- <a:folHlink><a:srgbClr val="${c.folHlink}"/></a:folHlink>
302
- </a:clrScheme>
303
- <a:fontScheme name="${theme.name}">
304
- <a:majorFont>
305
- <a:latin typeface="${f.major}"/>
306
- <a:ea typeface=""/>
307
- <a:cs typeface=""/>
308
- </a:majorFont>
309
- <a:minorFont>
310
- <a:latin typeface="${f.minor}"/>
311
- <a:ea typeface=""/>
312
- <a:cs typeface=""/>
313
- </a:minorFont>
314
- </a:fontScheme>
315
- <a:fmtScheme name="${theme.name}">
316
- <a:fillStyleLst>
317
- <a:solidFill><a:schemeClr val="phClr"/></a:solidFill>
318
- <a:gradFill rotWithShape="1">
319
- <a:gsLst>
320
- <a:gs pos="0"><a:schemeClr val="phClr"><a:tint val="50000"/><a:satMod val="300000"/></a:schemeClr></a:gs>
321
- <a:gs pos="35000"><a:schemeClr val="phClr"><a:tint val="37000"/><a:satMod val="300000"/></a:schemeClr></a:gs>
322
- <a:gs pos="100000"><a:schemeClr val="phClr"><a:tint val="15000"/><a:satMod val="350000"/></a:schemeClr></a:gs>
323
- </a:gsLst>
324
- <a:lin ang="16200000" scaled="1"/>
325
- </a:gradFill>
326
- <a:gradFill rotWithShape="1">
327
- <a:gsLst>
328
- <a:gs pos="0"><a:schemeClr val="phClr"><a:shade val="51000"/><a:satMod val="130000"/></a:schemeClr></a:gs>
329
- <a:gs pos="80000"><a:schemeClr val="phClr"><a:shade val="93000"/><a:satMod val="130000"/></a:schemeClr></a:gs>
330
- <a:gs pos="100000"><a:schemeClr val="phClr"><a:shade val="94000"/><a:satMod val="135000"/></a:schemeClr></a:gs>
331
- </a:gsLst>
332
- <a:lin ang="16200000" scaled="0"/>
333
- </a:gradFill>
334
- </a:fillStyleLst>
335
- <a:lnStyleLst>
336
- <a:ln w="9525" cap="flat" cmpd="sng" algn="ctr"><a:solidFill><a:schemeClr val="phClr"><a:shade val="95000"/><a:satMod val="105000"/></a:schemeClr></a:solidFill><a:prstDash val="solid"/></a:ln>
337
- <a:ln w="25400" cap="flat" cmpd="sng" algn="ctr"><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:prstDash val="solid"/></a:ln>
338
- <a:ln w="38100" cap="flat" cmpd="sng" algn="ctr"><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:prstDash val="solid"/></a:ln>
339
- </a:lnStyleLst>
340
- <a:effectStyleLst>
341
- <a:effectStyle><a:effectLst/></a:effectStyle>
342
- <a:effectStyle><a:effectLst/></a:effectStyle>
343
- <a:effectStyle><a:effectLst><a:outerShdw blurRad="40000" dist="23000" dir="5400000" rotWithShape="0"><a:srgbClr val="000000"><a:alpha val="35000"/></a:srgbClr></a:outerShdw></a:effectLst></a:effectStyle>
344
- </a:effectStyleLst>
345
- <a:bgFillStyleLst>
346
- <a:solidFill><a:schemeClr val="phClr"/></a:solidFill>
347
- <a:gradFill rotWithShape="1">
348
- <a:gsLst>
349
- <a:gs pos="0"><a:schemeClr val="phClr"><a:tint val="40000"/><a:satMod val="350000"/></a:schemeClr></a:gs>
350
- <a:gs pos="40000"><a:schemeClr val="phClr"><a:tint val="45000"/><a:shade val="99000"/><a:satMod val="350000"/></a:schemeClr></a:gs>
351
- <a:gs pos="100000"><a:schemeClr val="phClr"><a:shade val="20000"/><a:satMod val="255000"/></a:schemeClr></a:gs>
352
- </a:gsLst>
353
- <a:path path="circle"><a:fillToRect l="50000" t="-80000" r="50000" b="180000"/></a:path>
354
- </a:gradFill>
355
- <a:gradFill rotWithShape="1">
356
- <a:gsLst>
357
- <a:gs pos="0"><a:schemeClr val="phClr"><a:tint val="80000"/><a:satMod val="300000"/></a:schemeClr></a:gs>
358
- <a:gs pos="100000"><a:schemeClr val="phClr"><a:shade val="30000"/><a:satMod val="200000"/></a:schemeClr></a:gs>
359
- </a:gsLst>
360
- <a:path path="circle"><a:fillToRect l="50000" t="50000" r="50000" b="50000"/></a:path>
361
- </a:gradFill>
362
- </a:bgFillStyleLst>
363
- </a:fmtScheme>
364
- </a:themeElements>
365
- <a:objectDefaults/>
366
- <a:extraClrSchemeLst/>
367
- </a:theme>`;
368
- }
369
-
370
- /**
371
- * Get pandoc's default reference.pptx as a base template
372
- */
373
- function getPandocReferenceTemplate(): Buffer {
374
- try {
375
- // Use pandoc to extract the default reference template
376
- const result = execSync('pandoc --print-default-data-file reference.pptx', {
377
- encoding: 'buffer',
378
- maxBuffer: 1024 * 1024, // 1MB should be plenty
379
- });
380
- return result;
381
- } catch (err: unknown) {
382
- const message = err instanceof Error ? err.message : String(err);
383
- throw new Error(`Failed to get pandoc reference template: ${message}`);
384
- }
385
- }
386
-
387
- /**
388
- * Generate a PPTX theme file by modifying pandoc's reference template
389
- */
390
- export function generateThemeFile(themeName: string, outputPath: string): string {
391
- const theme = PPTX_THEMES[themeName];
392
- if (!theme) {
393
- throw new Error(`Unknown theme: ${themeName}`);
394
- }
395
-
396
- // Get pandoc's reference template as base
397
- const templateBuffer = getPandocReferenceTemplate();
398
- const zip = new AdmZip(templateBuffer);
399
-
400
- // Replace theme.xml with our custom theme
401
- zip.updateFile('ppt/theme/theme1.xml', Buffer.from(generateTheme(theme), 'utf-8'));
402
-
403
- // For dark themes, update slide masters and layouts with background color
404
- if (theme.background) {
405
- updateBackgroundColor(zip, theme.background);
406
- }
407
-
408
- // Ensure output directory exists
409
- const dir = dirname(outputPath);
410
- if (!existsSync(dir)) {
411
- mkdirSync(dir, { recursive: true });
412
- }
413
-
414
- zip.writeZip(outputPath);
415
- return outputPath;
416
- }
417
-
418
- /**
419
- * Update background color in slide masters and layouts for dark themes
420
- */
421
- function updateBackgroundColor(zip: AdmZip, bgColor: string): void {
422
- const entries = zip.getEntries();
423
-
424
- for (const entry of entries) {
425
- const name = entry.entryName;
426
-
427
- // Update slide masters and layouts
428
- if (name.includes('slideMasters/') || name.includes('slideLayouts/')) {
429
- if (name.endsWith('.xml') && !name.includes('_rels')) {
430
- let content = entry.getData().toString('utf-8');
431
-
432
- // Replace light background with dark background
433
- // Look for <a:schemeClr val="lt1"/> in bgPr and replace
434
- content = content.replace(
435
- /<p:bg>[\s\S]*?<\/p:bg>/g,
436
- `<p:bg><p:bgPr><a:solidFill><a:srgbClr val="${bgColor}"/></a:solidFill><a:effectLst/></p:bgPr></p:bg>`
437
- );
438
-
439
- zip.updateFile(name, Buffer.from(content, 'utf-8'));
440
- }
441
- }
442
- }
443
- }
444
-
445
- /**
446
- * Get path to bundled theme file, generating if needed
447
- */
448
- export function getThemePath(themeName: string): string | null {
449
- if (!PPTX_THEMES[themeName]) {
450
- return null;
451
- }
452
-
453
- const themesDir = join(__dirname, 'pptx-themes');
454
- const themePath = join(themesDir, `${themeName}.pptx`);
455
-
456
- // Generate if doesn't exist
457
- if (!existsSync(themePath)) {
458
- if (!existsSync(themesDir)) {
459
- mkdirSync(themesDir, { recursive: true });
460
- }
461
- generateThemeFile(themeName, themePath);
462
- }
463
-
464
- return themePath;
465
- }
466
-
467
- /**
468
- * Generate all theme files
469
- */
470
- export function generateAllThemes(outputDir: string): Array<{ theme: string; path: string }> {
471
- if (!existsSync(outputDir)) {
472
- mkdirSync(outputDir, { recursive: true });
473
- }
474
-
475
- const results = [];
476
- for (const themeName of Object.keys(PPTX_THEMES)) {
477
- const outputPath = join(outputDir, `${themeName}.pptx`);
478
- generateThemeFile(themeName, outputPath);
479
- results.push({ theme: themeName, path: outputPath });
480
- }
481
-
482
- return results;
483
- }
1
+ /**
2
+ * PPTX Theme System
3
+ *
4
+ * Provides 6 built-in themes for PPTX output, independent of Beamer themes.
5
+ * Each theme is a reference PPTX file that defines colors, fonts, and slide layouts.
6
+ *
7
+ * Uses pandoc's default reference.pptx as the base template and modifies the theme.xml
8
+ * to apply custom colors and fonts. This ensures all 11 required slide layouts are present.
9
+ *
10
+ * Themes:
11
+ * - default: Clean white with blue accents (professional)
12
+ * - dark: Dark background with light text (modern)
13
+ * - academic: Classic serif fonts, muted colors (scholarly)
14
+ * - minimal: High contrast black/white (clean)
15
+ * - corporate: Navy/gold color scheme (business)
16
+ * - plant: Nature-inspired green theme (ecology/biology)
17
+ */
18
+
19
+ import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
20
+ import { join, dirname } from 'node:path';
21
+ import { fileURLToPath } from 'node:url';
22
+ import { execSync } from 'node:child_process';
23
+ import AdmZip from 'adm-zip';
24
+
25
+ const __dirname = dirname(fileURLToPath(import.meta.url));
26
+
27
+ /**
28
+ * Color scheme for a theme
29
+ */
30
+ interface ThemeColors {
31
+ dk1: string;
32
+ lt1: string;
33
+ dk2: string;
34
+ lt2: string;
35
+ accent1: string;
36
+ accent2: string;
37
+ accent3: string;
38
+ accent4: string;
39
+ accent5: string;
40
+ accent6: string;
41
+ hlink: string;
42
+ folHlink: string;
43
+ }
44
+
45
+ /**
46
+ * Font scheme for a theme
47
+ */
48
+ interface ThemeFonts {
49
+ major: string;
50
+ minor: string;
51
+ }
52
+
53
+ /**
54
+ * PPTX theme definition
55
+ */
56
+ interface PptxTheme {
57
+ name: string;
58
+ description: string;
59
+ colors: ThemeColors;
60
+ fonts: ThemeFonts;
61
+ background?: string;
62
+ }
63
+
64
+ /**
65
+ * Theme definitions with colors and fonts
66
+ */
67
+ export const PPTX_THEMES: Record<string, PptxTheme> = {
68
+ default: {
69
+ name: 'Default',
70
+ description: 'Clean white with blue accents',
71
+ colors: {
72
+ dk1: '000000', // Dark text
73
+ lt1: 'FFFFFF', // Light background
74
+ dk2: '1F497D', // Dark accent (navy)
75
+ lt2: 'EEECE1', // Light accent (cream)
76
+ accent1: '4472C4', // Blue
77
+ accent2: 'ED7D31', // Orange
78
+ accent3: 'A5A5A5', // Gray
79
+ accent4: 'FFC000', // Yellow
80
+ accent5: '5B9BD5', // Light blue
81
+ accent6: '70AD47', // Green
82
+ hlink: '0563C1', // Hyperlink blue
83
+ folHlink: '954F72', // Followed hyperlink
84
+ },
85
+ fonts: {
86
+ major: 'Calibri Light',
87
+ minor: 'Calibri',
88
+ },
89
+ },
90
+ dark: {
91
+ name: 'Dark',
92
+ description: 'Dark background with light text',
93
+ colors: {
94
+ dk1: 'FFFFFF', // Light text (inverted)
95
+ lt1: '1E1E1E', // Dark background
96
+ dk2: 'E0E0E0', // Light gray
97
+ lt2: '2D2D2D', // Darker gray
98
+ accent1: '00B4D8', // Cyan
99
+ accent2: 'FF6B6B', // Coral
100
+ accent3: '95E1D3', // Mint
101
+ accent4: 'F38181', // Pink
102
+ accent5: 'AA96DA', // Lavender
103
+ accent6: 'FCBAD3', // Light pink
104
+ hlink: '00B4D8',
105
+ folHlink: 'AA96DA',
106
+ },
107
+ fonts: {
108
+ major: 'Inter',
109
+ minor: 'Inter',
110
+ },
111
+ background: '1E1E1E',
112
+ },
113
+ academic: {
114
+ name: 'Academic',
115
+ description: 'Classic serif fonts, muted colors',
116
+ colors: {
117
+ dk1: '2C3E50', // Dark blue-gray
118
+ lt1: 'FFFEF9', // Warm white
119
+ dk2: '34495E', // Slate
120
+ lt2: 'F5F5DC', // Beige
121
+ accent1: '8B4513', // Saddle brown
122
+ accent2: '2E8B57', // Sea green
123
+ accent3: '708090', // Slate gray
124
+ accent4: 'B8860B', // Dark goldenrod
125
+ accent5: '4682B4', // Steel blue
126
+ accent6: '6B8E23', // Olive drab
127
+ hlink: '8B4513',
128
+ folHlink: '708090',
129
+ },
130
+ fonts: {
131
+ major: 'Georgia',
132
+ minor: 'Palatino Linotype',
133
+ },
134
+ },
135
+ minimal: {
136
+ name: 'Minimal',
137
+ description: 'High contrast black and white',
138
+ colors: {
139
+ dk1: '000000', // Pure black
140
+ lt1: 'FFFFFF', // Pure white
141
+ dk2: '333333', // Dark gray
142
+ lt2: 'F0F0F0', // Light gray
143
+ accent1: '000000', // Black accent
144
+ accent2: '666666', // Medium gray
145
+ accent3: '999999', // Light gray
146
+ accent4: 'CCCCCC', // Lighter gray
147
+ accent5: '333333', // Dark gray
148
+ accent6: '4D4D4D', // Charcoal
149
+ hlink: '000000',
150
+ folHlink: '666666',
151
+ },
152
+ fonts: {
153
+ major: 'Roboto Light',
154
+ minor: 'Roboto',
155
+ },
156
+ },
157
+ corporate: {
158
+ name: 'Corporate',
159
+ description: 'Navy and gold professional theme',
160
+ colors: {
161
+ dk1: '0D1B2A', // Very dark navy
162
+ lt1: 'FFFFFF', // White
163
+ dk2: '1B263B', // Dark navy
164
+ lt2: 'E0E1DD', // Light gray
165
+ accent1: 'D4AF37', // Gold
166
+ accent2: '415A77', // Steel blue
167
+ accent3: '778DA9', // Light steel
168
+ accent4: 'C5A900', // Darker gold
169
+ accent5: '1B4965', // Deep blue
170
+ accent6: '5FA8D3', // Sky blue
171
+ hlink: 'D4AF37',
172
+ folHlink: '778DA9',
173
+ },
174
+ fonts: {
175
+ major: 'Garamond',
176
+ minor: 'Garamond',
177
+ },
178
+ },
179
+ plant: {
180
+ name: 'Plant',
181
+ description: 'Nature-inspired green theme for ecology/biology',
182
+ colors: {
183
+ dk1: '2D4A22', // Dark forest green
184
+ lt1: 'FFFFFF', // White
185
+ dk2: '3D5A2E', // Medium forest
186
+ lt2: 'F5F7F2', // Light sage
187
+ accent1: '608C32', // Primary green (theme accent)
188
+ accent2: '8B4513', // Earth brown
189
+ accent3: '888888', // Gray (for buildup)
190
+ accent4: '7CB342', // Light green
191
+ accent5: '4A6B3A', // Olive green
192
+ accent6: 'A5D6A7', // Pale green
193
+ hlink: '608C32',
194
+ folHlink: '4A6B3A',
195
+ },
196
+ fonts: {
197
+ major: 'Aptos Display',
198
+ minor: 'Aptos',
199
+ },
200
+ },
201
+ };
202
+
203
+ /**
204
+ * Get list of available theme names
205
+ */
206
+ export function getThemeNames(): string[] {
207
+ return Object.keys(PPTX_THEMES);
208
+ }
209
+
210
+ /**
211
+ * Get theme definition by name
212
+ */
213
+ export function getTheme(name: string): PptxTheme | null {
214
+ return PPTX_THEMES[name] || null;
215
+ }
216
+
217
+ /**
218
+ * Generate [Content_Types].xml
219
+ */
220
+ function generateContentTypes(): string {
221
+ return `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
222
+ <Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
223
+ <Default Extension="jpeg" ContentType="image/jpeg"/>
224
+ <Default Extension="png" ContentType="image/png"/>
225
+ <Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>
226
+ <Default Extension="xml" ContentType="application/xml"/>
227
+ <Override PartName="/ppt/presentation.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.presentation.main+xml"/>
228
+ <Override PartName="/ppt/slideMasters/slideMaster1.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.slideMaster+xml"/>
229
+ <Override PartName="/ppt/slideLayouts/slideLayout1.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.slideLayout+xml"/>
230
+ <Override PartName="/ppt/slideLayouts/slideLayout2.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.slideLayout+xml"/>
231
+ <Override PartName="/ppt/theme/theme1.xml" ContentType="application/vnd.openxmlformats-officedocument.theme+xml"/>
232
+ <Override PartName="/docProps/core.xml" ContentType="application/vnd.openxmlformats-package.core-properties+xml"/>
233
+ <Override PartName="/docProps/app.xml" ContentType="application/vnd.openxmlformats-officedocument.extended-properties+xml"/>
234
+ </Types>`;
235
+ }
236
+
237
+ /**
238
+ * Generate _rels/.rels
239
+ */
240
+ function generateRels(): string {
241
+ return `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
242
+ <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
243
+ <Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="ppt/presentation.xml"/>
244
+ <Relationship Id="rId2" Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties" Target="docProps/core.xml"/>
245
+ <Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties" Target="docProps/app.xml"/>
246
+ </Relationships>`;
247
+ }
248
+
249
+ /**
250
+ * Generate ppt/_rels/presentation.xml.rels
251
+ */
252
+ function generatePresentationRels(): string {
253
+ return `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
254
+ <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
255
+ <Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideMaster" Target="slideMasters/slideMaster1.xml"/>
256
+ <Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme" Target="theme/theme1.xml"/>
257
+ </Relationships>`;
258
+ }
259
+
260
+ /**
261
+ * Generate ppt/presentation.xml
262
+ */
263
+ function generatePresentation(): string {
264
+ return `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
265
+ <p:presentation xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main" saveSubsetFonts="1">
266
+ <p:sldMasterIdLst>
267
+ <p:sldMasterId id="2147483648" r:id="rId1"/>
268
+ </p:sldMasterIdLst>
269
+ <p:sldSz cx="12192000" cy="6858000"/>
270
+ <p:notesSz cx="6858000" cy="9144000"/>
271
+ <p:defaultTextStyle>
272
+ <a:defPPr>
273
+ <a:defRPr lang="en-US"/>
274
+ </a:defPPr>
275
+ </p:defaultTextStyle>
276
+ </p:presentation>`;
277
+ }
278
+
279
+ /**
280
+ * Generate ppt/theme/theme1.xml with theme colors and fonts
281
+ */
282
+ function generateTheme(theme: PptxTheme): string {
283
+ const c = theme.colors;
284
+ const f = theme.fonts;
285
+
286
+ return `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
287
+ <a:theme xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" name="${theme.name}">
288
+ <a:themeElements>
289
+ <a:clrScheme name="${theme.name}">
290
+ <a:dk1><a:srgbClr val="${c.dk1}"/></a:dk1>
291
+ <a:lt1><a:srgbClr val="${c.lt1}"/></a:lt1>
292
+ <a:dk2><a:srgbClr val="${c.dk2}"/></a:dk2>
293
+ <a:lt2><a:srgbClr val="${c.lt2}"/></a:lt2>
294
+ <a:accent1><a:srgbClr val="${c.accent1}"/></a:accent1>
295
+ <a:accent2><a:srgbClr val="${c.accent2}"/></a:accent2>
296
+ <a:accent3><a:srgbClr val="${c.accent3}"/></a:accent3>
297
+ <a:accent4><a:srgbClr val="${c.accent4}"/></a:accent4>
298
+ <a:accent5><a:srgbClr val="${c.accent5}"/></a:accent5>
299
+ <a:accent6><a:srgbClr val="${c.accent6}"/></a:accent6>
300
+ <a:hlink><a:srgbClr val="${c.hlink}"/></a:hlink>
301
+ <a:folHlink><a:srgbClr val="${c.folHlink}"/></a:folHlink>
302
+ </a:clrScheme>
303
+ <a:fontScheme name="${theme.name}">
304
+ <a:majorFont>
305
+ <a:latin typeface="${f.major}"/>
306
+ <a:ea typeface=""/>
307
+ <a:cs typeface=""/>
308
+ </a:majorFont>
309
+ <a:minorFont>
310
+ <a:latin typeface="${f.minor}"/>
311
+ <a:ea typeface=""/>
312
+ <a:cs typeface=""/>
313
+ </a:minorFont>
314
+ </a:fontScheme>
315
+ <a:fmtScheme name="${theme.name}">
316
+ <a:fillStyleLst>
317
+ <a:solidFill><a:schemeClr val="phClr"/></a:solidFill>
318
+ <a:gradFill rotWithShape="1">
319
+ <a:gsLst>
320
+ <a:gs pos="0"><a:schemeClr val="phClr"><a:tint val="50000"/><a:satMod val="300000"/></a:schemeClr></a:gs>
321
+ <a:gs pos="35000"><a:schemeClr val="phClr"><a:tint val="37000"/><a:satMod val="300000"/></a:schemeClr></a:gs>
322
+ <a:gs pos="100000"><a:schemeClr val="phClr"><a:tint val="15000"/><a:satMod val="350000"/></a:schemeClr></a:gs>
323
+ </a:gsLst>
324
+ <a:lin ang="16200000" scaled="1"/>
325
+ </a:gradFill>
326
+ <a:gradFill rotWithShape="1">
327
+ <a:gsLst>
328
+ <a:gs pos="0"><a:schemeClr val="phClr"><a:shade val="51000"/><a:satMod val="130000"/></a:schemeClr></a:gs>
329
+ <a:gs pos="80000"><a:schemeClr val="phClr"><a:shade val="93000"/><a:satMod val="130000"/></a:schemeClr></a:gs>
330
+ <a:gs pos="100000"><a:schemeClr val="phClr"><a:shade val="94000"/><a:satMod val="135000"/></a:schemeClr></a:gs>
331
+ </a:gsLst>
332
+ <a:lin ang="16200000" scaled="0"/>
333
+ </a:gradFill>
334
+ </a:fillStyleLst>
335
+ <a:lnStyleLst>
336
+ <a:ln w="9525" cap="flat" cmpd="sng" algn="ctr"><a:solidFill><a:schemeClr val="phClr"><a:shade val="95000"/><a:satMod val="105000"/></a:schemeClr></a:solidFill><a:prstDash val="solid"/></a:ln>
337
+ <a:ln w="25400" cap="flat" cmpd="sng" algn="ctr"><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:prstDash val="solid"/></a:ln>
338
+ <a:ln w="38100" cap="flat" cmpd="sng" algn="ctr"><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:prstDash val="solid"/></a:ln>
339
+ </a:lnStyleLst>
340
+ <a:effectStyleLst>
341
+ <a:effectStyle><a:effectLst/></a:effectStyle>
342
+ <a:effectStyle><a:effectLst/></a:effectStyle>
343
+ <a:effectStyle><a:effectLst><a:outerShdw blurRad="40000" dist="23000" dir="5400000" rotWithShape="0"><a:srgbClr val="000000"><a:alpha val="35000"/></a:srgbClr></a:outerShdw></a:effectLst></a:effectStyle>
344
+ </a:effectStyleLst>
345
+ <a:bgFillStyleLst>
346
+ <a:solidFill><a:schemeClr val="phClr"/></a:solidFill>
347
+ <a:gradFill rotWithShape="1">
348
+ <a:gsLst>
349
+ <a:gs pos="0"><a:schemeClr val="phClr"><a:tint val="40000"/><a:satMod val="350000"/></a:schemeClr></a:gs>
350
+ <a:gs pos="40000"><a:schemeClr val="phClr"><a:tint val="45000"/><a:shade val="99000"/><a:satMod val="350000"/></a:schemeClr></a:gs>
351
+ <a:gs pos="100000"><a:schemeClr val="phClr"><a:shade val="20000"/><a:satMod val="255000"/></a:schemeClr></a:gs>
352
+ </a:gsLst>
353
+ <a:path path="circle"><a:fillToRect l="50000" t="-80000" r="50000" b="180000"/></a:path>
354
+ </a:gradFill>
355
+ <a:gradFill rotWithShape="1">
356
+ <a:gsLst>
357
+ <a:gs pos="0"><a:schemeClr val="phClr"><a:tint val="80000"/><a:satMod val="300000"/></a:schemeClr></a:gs>
358
+ <a:gs pos="100000"><a:schemeClr val="phClr"><a:shade val="30000"/><a:satMod val="200000"/></a:schemeClr></a:gs>
359
+ </a:gsLst>
360
+ <a:path path="circle"><a:fillToRect l="50000" t="50000" r="50000" b="50000"/></a:path>
361
+ </a:gradFill>
362
+ </a:bgFillStyleLst>
363
+ </a:fmtScheme>
364
+ </a:themeElements>
365
+ <a:objectDefaults/>
366
+ <a:extraClrSchemeLst/>
367
+ </a:theme>`;
368
+ }
369
+
370
+ /**
371
+ * Get pandoc's default reference.pptx as a base template
372
+ */
373
+ function getPandocReferenceTemplate(): Buffer {
374
+ try {
375
+ // Use pandoc to extract the default reference template
376
+ const result = execSync('pandoc --print-default-data-file reference.pptx', {
377
+ encoding: 'buffer',
378
+ maxBuffer: 1024 * 1024, // 1MB should be plenty
379
+ });
380
+ return result;
381
+ } catch (err: unknown) {
382
+ const message = err instanceof Error ? err.message : String(err);
383
+ throw new Error(`Failed to get pandoc reference template: ${message}`);
384
+ }
385
+ }
386
+
387
+ /**
388
+ * Generate a PPTX theme file by modifying pandoc's reference template
389
+ */
390
+ export function generateThemeFile(themeName: string, outputPath: string): string {
391
+ const theme = PPTX_THEMES[themeName];
392
+ if (!theme) {
393
+ throw new Error(`Unknown theme: ${themeName}`);
394
+ }
395
+
396
+ // Get pandoc's reference template as base
397
+ const templateBuffer = getPandocReferenceTemplate();
398
+ const zip = new AdmZip(templateBuffer);
399
+
400
+ // Replace theme.xml with our custom theme
401
+ zip.updateFile('ppt/theme/theme1.xml', Buffer.from(generateTheme(theme), 'utf-8'));
402
+
403
+ // For dark themes, update slide masters and layouts with background color
404
+ if (theme.background) {
405
+ updateBackgroundColor(zip, theme.background);
406
+ }
407
+
408
+ // Ensure output directory exists
409
+ const dir = dirname(outputPath);
410
+ if (!existsSync(dir)) {
411
+ mkdirSync(dir, { recursive: true });
412
+ }
413
+
414
+ zip.writeZip(outputPath);
415
+ return outputPath;
416
+ }
417
+
418
+ /**
419
+ * Update background color in slide masters and layouts for dark themes
420
+ */
421
+ function updateBackgroundColor(zip: AdmZip, bgColor: string): void {
422
+ const entries = zip.getEntries();
423
+
424
+ for (const entry of entries) {
425
+ const name = entry.entryName;
426
+
427
+ // Update slide masters and layouts
428
+ if (name.includes('slideMasters/') || name.includes('slideLayouts/')) {
429
+ if (name.endsWith('.xml') && !name.includes('_rels')) {
430
+ let content = entry.getData().toString('utf-8');
431
+
432
+ // Replace light background with dark background
433
+ // Look for <a:schemeClr val="lt1"/> in bgPr and replace
434
+ content = content.replace(
435
+ /<p:bg>[\s\S]*?<\/p:bg>/g,
436
+ `<p:bg><p:bgPr><a:solidFill><a:srgbClr val="${bgColor}"/></a:solidFill><a:effectLst/></p:bgPr></p:bg>`
437
+ );
438
+
439
+ zip.updateFile(name, Buffer.from(content, 'utf-8'));
440
+ }
441
+ }
442
+ }
443
+ }
444
+
445
+ /**
446
+ * Get path to bundled theme file, generating if needed
447
+ */
448
+ export function getThemePath(themeName: string): string | null {
449
+ if (!PPTX_THEMES[themeName]) {
450
+ return null;
451
+ }
452
+
453
+ const themesDir = join(__dirname, 'pptx-themes');
454
+ const themePath = join(themesDir, `${themeName}.pptx`);
455
+
456
+ // Generate if doesn't exist
457
+ if (!existsSync(themePath)) {
458
+ if (!existsSync(themesDir)) {
459
+ mkdirSync(themesDir, { recursive: true });
460
+ }
461
+ generateThemeFile(themeName, themePath);
462
+ }
463
+
464
+ return themePath;
465
+ }
466
+
467
+ /**
468
+ * Generate all theme files
469
+ */
470
+ export function generateAllThemes(outputDir: string): Array<{ theme: string; path: string }> {
471
+ if (!existsSync(outputDir)) {
472
+ mkdirSync(outputDir, { recursive: true });
473
+ }
474
+
475
+ const results = [];
476
+ for (const themeName of Object.keys(PPTX_THEMES)) {
477
+ const outputPath = join(outputDir, `${themeName}.pptx`);
478
+ generateThemeFile(themeName, outputPath);
479
+ results.push({ theme: themeName, path: outputPath });
480
+ }
481
+
482
+ return results;
483
+ }