dsh-ppt 0.21.1 → 0.22.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 (49) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.en.md +18 -18
  3. package/README.md +16 -16
  4. package/docs/COACHING.md +14 -13
  5. package/docs/DATA.md +8 -8
  6. package/docs/REFERENCE.en.md +17 -19
  7. package/docs/REFERENCE.zh.md +16 -18
  8. package/docs/USAGE.en.md +107 -60
  9. package/docs/USAGE.md +115 -84
  10. package/docs/VALIDATION.md +2 -0
  11. package/docs/VISUAL.md +27 -20
  12. package/docs/WORKBENCH.md +17 -6
  13. package/docs/assets/intro/screen-en.webp +0 -0
  14. package/docs/assets/intro/screen-zh.webp +0 -0
  15. package/lib/client.js +905 -46
  16. package/lib/coaching.d.ts +1 -1
  17. package/lib/coaching.js +25 -12
  18. package/lib/config.d.ts +2 -0
  19. package/lib/config.js +30 -2
  20. package/lib/execution.d.ts +2 -1
  21. package/lib/execution.js +21 -1
  22. package/lib/tools.d.ts +1 -1
  23. package/lib/tools.js +151 -24
  24. package/lib/types.d.ts +108 -8
  25. package/lib/visual.d.ts +3 -1
  26. package/lib/visual.js +40 -13
  27. package/lib/workbench-language.js +45 -9
  28. package/lib/workbench.d.ts +5 -0
  29. package/lib/workbench.js +485 -9
  30. package/package.json +8 -3
  31. package/skills/dsh-ppt/SKILL.md +56 -54
  32. package/skills/dsh-ppt/package.json +1 -1
  33. package/skills/dsh-ppt/references/advanced.md +122 -41
  34. package/skills/dsh-ppt/references/copywriting.md +63 -41
  35. package/skills/dsh-ppt/references/data.md +83 -36
  36. package/skills/dsh-ppt/references/syntax.md +157 -28
  37. package/skills/dsh-ppt/references/themes.md +90 -41
  38. package/skills/dsh-ppt/references/troubleshooting.md +21 -16
  39. package/skills/dsh-ppt/scripts/build-deck.mjs +67 -28
  40. package/skills/dsh-ppt/scripts/deck-absorb.mjs +1029 -0
  41. package/skills/dsh-ppt/scripts/deck-advanced.mjs +406 -99
  42. package/skills/dsh-ppt/scripts/deck-core.mjs +568 -717
  43. package/skills/dsh-ppt/scripts/deck-data-view.mjs +30 -11
  44. package/skills/dsh-ppt/scripts/deck-data.mjs +35 -5
  45. package/skills/dsh-ppt/scripts/deck-director.mjs +1717 -0
  46. package/skills/dsh-ppt/scripts/deck-layouts.mjs +4557 -0
  47. package/skills/dsh-ppt/scripts/deck-media.mjs +1408 -86
  48. package/skills/dsh-ppt/scripts/deck-themes.mjs +1503 -0
  49. package/skills/dsh-ppt/scripts/deck-visual.mjs +133 -31
@@ -1,26 +1,107 @@
1
1
  #! /usr/bin/env node
2
2
  /**
3
- * deck-core.mjs —— dsh-ppt 的零依赖演示文稿引擎。
3
+ * deck-core.mjs —— dsh-ppt 的零依赖演示文稿核心协调引擎。
4
4
  *
5
5
  * 这是插件工具与裸 SKILL.md 共用的唯一事实源:
6
6
  * - DSH 内:ppt_create 工具动态加载本文件
7
7
  * - 其他 harness:直接运行同目录的 build-deck.mjs
8
8
  *
9
9
  * 能力:Markdown / 结构化 slides → 三件套
10
- * deck.html 独立网页放映(键盘/触屏/打印,无外链)
11
- * deck.pptx 可编辑 PPTX(16:9,OOXML 由本文件手写,zip 用 node:zlib)
10
+ * deck.html 独立网页放映(键盘/触屏/演讲者视图/缩略图总览/打印,无外链)
11
+ * deck.pptx 可编辑 PPTX(16:9,OOXML 由 deck-layouts 手写,zip 用 node:zlib)
12
12
  * deck.json 结构化 deck manifest
13
13
  *
14
14
  * 零外部运行时依赖,仅使用 Node 内置模块。
15
15
  */
16
16
 
17
17
  import { existsSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs'
18
- import { resolve as resolvePath, join as joinPath } from 'node:path'
18
+ import { resolve as resolvePath } from 'node:path'
19
19
  import { deflateRawSync } from 'node:zlib'
20
- import { MEDIA_LAYOUTS, MEDIA_CSS, normalizeMediaSlide, renderMediaHtml, mediaBoxes } from './deck-media.mjs'
20
+ import * as deckMedia from './deck-media.mjs'
21
21
  import { renderDelivery } from './deck-delivery.mjs'
22
22
  import { renderDataView } from './deck-data-view.mjs'
23
23
  import { normalizeVisual, visualHtmlStyle, visualShapeXml, VISUAL_CSS } from './deck-visual.mjs'
24
+ import {
25
+ THEMES,
26
+ THEME_IDS,
27
+ CHROME_STYLES,
28
+ DEFAULT_THEME,
29
+ SMART_DEFAULT_THEME,
30
+ resolveTheme,
31
+ resolveChromeStyle,
32
+ listThemes,
33
+ deriveBrandedTheme,
34
+ sanitizeAbsorbedTheme,
35
+ pptxFontName,
36
+ pptxEastAsianFont,
37
+ contrastRatio,
38
+ ensureContrast,
39
+ hexToRgba,
40
+ renderThemeSvg as renderThemeSvgBase,
41
+ renderThemePreviewHtml as renderThemePreviewHtmlBase,
42
+ buildThemePreview as buildThemePreviewBase,
43
+ } from './deck-themes.mjs'
44
+ import {
45
+ CORE_LAYOUTS,
46
+ LAYOUT_ALIASES,
47
+ EMU_W,
48
+ EMU_H,
49
+ escapeXml,
50
+ escapeHtml,
51
+ stripInlineMarkdown,
52
+ cleanRichText,
53
+ parseInlineRuns,
54
+ renderInlineHtml,
55
+ computeTextFit,
56
+ normalizeSlideItems,
57
+ resolveEffectiveItems,
58
+ formatSourceLine,
59
+ computeBadgePillWidth,
60
+ roundRectAdj,
61
+ ooxmlShape,
62
+ ooxmlRichParagraph,
63
+ getChromeConfig,
64
+ parseHarveyValue,
65
+ renderSlideChromePptx,
66
+ renderCoreSlidePptx,
67
+ renderCoreSlideHtml,
68
+ LAYOUT_CSS,
69
+ } from './deck-layouts.mjs'
70
+
71
+ export {
72
+ THEMES,
73
+ THEME_IDS,
74
+ CHROME_STYLES,
75
+ DEFAULT_THEME,
76
+ SMART_DEFAULT_THEME,
77
+ resolveTheme,
78
+ resolveChromeStyle,
79
+ listThemes,
80
+ deriveBrandedTheme,
81
+ sanitizeAbsorbedTheme,
82
+ pptxFontName,
83
+ pptxEastAsianFont,
84
+ contrastRatio,
85
+ ensureContrast,
86
+ hexToRgba,
87
+ CORE_LAYOUTS,
88
+ LAYOUT_ALIASES,
89
+ escapeXml,
90
+ escapeHtml,
91
+ stripInlineMarkdown,
92
+ cleanRichText,
93
+ parseInlineRuns,
94
+ renderInlineHtml,
95
+ computeTextFit,
96
+ normalizeSlideItems,
97
+ resolveEffectiveItems,
98
+ formatSourceLine,
99
+ computeBadgePillWidth,
100
+ roundRectAdj,
101
+ getChromeConfig,
102
+ parseHarveyValue,
103
+ renderSlideChromePptx,
104
+ }
24
105
 
25
106
  /**
26
107
  * manifest 版本跟随发布包 package.json;把 skills/dsh-ppt 独立复制到其他
@@ -41,110 +122,9 @@ function readDeckVersion() {
41
122
  export const DECK_VERSION = readDeckVersion()
42
123
 
43
124
  // ---------------------------------------------------------------------------
44
- // 主题
125
+ // 多语言 UI 文案与参数解析
45
126
  // ---------------------------------------------------------------------------
46
127
 
47
- export const THEMES = {
48
- swiss: {
49
- id: 'swiss',
50
- name: { zh: '瑞士脉冲', en: 'Swiss Pulse' },
51
- mood: { zh: '精准、理性、数据', en: 'Precise, rational, data-driven' },
52
- bestFor: { zh: 'SaaS、数据、开发者工具', en: 'SaaS, data, developer tools' },
53
- dark: true,
54
- palette: {
55
- bg: '#10151B',
56
- panel: '#161D26',
57
- fg: '#F5F7FA',
58
- muted: '#8E9AAA',
59
- accent: '#2F6BFF',
60
- accent2: '#FFB300',
61
- },
62
- fonts: {
63
- heading: '"Helvetica Neue", Inter, "PingFang SC", "Microsoft YaHei", sans-serif',
64
- body: '"Helvetica Neue", Inter, "PingFang SC", "Microsoft YaHei", sans-serif',
65
- },
66
- },
67
- velvet: {
68
- id: 'velvet',
69
- name: { zh: '天鹅绒标准', en: 'Velvet Standard' },
70
- mood: { zh: '高级、克制、可信', en: 'Premium, restrained, trustworthy' },
71
- bestFor: { zh: '高管汇报、品牌、融资路演', en: 'Executive decks, brand, investor pitches' },
72
- dark: true,
73
- palette: {
74
- bg: '#111316',
75
- panel: '#1A1D22',
76
- fg: '#F4EFE6',
77
- muted: '#A79F91',
78
- accent: '#C9A84C',
79
- accent2: '#3D4A63',
80
- },
81
- fonts: {
82
- heading: 'Georgia, "Times New Roman", "Songti SC", "SimSun", serif',
83
- body: '"Helvetica Neue", Inter, "PingFang SC", "Microsoft YaHei", sans-serif',
84
- },
85
- },
86
- data: {
87
- id: 'data',
88
- name: { zh: '数据漂移', en: 'Data Drift' },
89
- mood: { zh: '未来、沉浸、前沿', en: 'Futuristic, immersive, cutting-edge' },
90
- bestFor: { zh: 'AI、数据、研究、技术发布', en: 'AI, data, research, tech launches' },
91
- dark: true,
92
- palette: {
93
- bg: '#070B14',
94
- panel: '#0D1424',
95
- fg: '#E8F1FF',
96
- muted: '#7E8BA8',
97
- accent: '#7C3AED',
98
- accent2: '#06B6D4',
99
- },
100
- fonts: {
101
- heading: '"Space Grotesk", "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif',
102
- body: '"Space Grotesk", "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif',
103
- },
104
- },
105
- soft: {
106
- id: 'soft',
107
- name: { zh: '柔和信号', en: 'Soft Signal' },
108
- mood: { zh: '温暖、亲近、人本', en: 'Warm, intimate, human' },
109
- bestFor: { zh: '品牌故事、培训、个人分享', en: 'Brand stories, training, personal talks' },
110
- dark: false,
111
- palette: {
112
- bg: '#FFF8EC',
113
- panel: '#FFF2DE',
114
- fg: '#3B2F2A',
115
- muted: '#7E6F68',
116
- accent: '#E58A2F',
117
- accent2: '#8FAF8C',
118
- },
119
- fonts: {
120
- heading: '"Avenir Next", "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif',
121
- body: '"Avenir Next", "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif',
122
- },
123
- },
124
- bold: {
125
- id: 'bold',
126
- name: { zh: '极繁大字', en: 'Maximalist Type' },
127
- mood: { zh: '大声、动能、发布', en: 'Loud, kinetic, launch' },
128
- bestFor: { zh: '产品发布、活动、品牌大事件', en: 'Product launches, events, brand moments' },
129
- dark: true,
130
- palette: {
131
- bg: '#0D0D0D',
132
- panel: '#181818',
133
- fg: '#FFFFFF',
134
- muted: '#B8B8B8',
135
- accent: '#E63946',
136
- accent2: '#FFD60A',
137
- },
138
- fonts: {
139
- heading: 'Impact, "Arial Black", "PingFang SC", "Microsoft YaHei", sans-serif',
140
- body: '"Helvetica Neue", Inter, "PingFang SC", "Microsoft YaHei", sans-serif',
141
- },
142
- },
143
- }
144
-
145
- export const THEME_IDS = Object.keys(THEMES)
146
- export const DEFAULT_THEME = 'data'
147
-
148
128
  export const LANGUAGES = {
149
129
  zh: {
150
130
  id: 'zh',
@@ -179,7 +159,7 @@ export const LANGUAGES = {
179
159
  popupBlocked: '浏览器拦截了演讲者窗口,请允许弹出窗口后按 V 重试',
180
160
  fullscreenUnavailable: '当前窗口无法进入全屏,请在浏览器中独立打开演示文件后重试。',
181
161
  notesCloseLabel: '关闭备注',
182
- overviewHint: '点击缩略图跳页,方向键切换,Enter 进入,Esc 退出'
162
+ overviewHint: '点击缩略图跳页,方向键切换,Enter 进入,Esc 退出',
183
163
  },
184
164
  },
185
165
  en: {
@@ -215,7 +195,7 @@ export const LANGUAGES = {
215
195
  popupBlocked: 'The presenter window was blocked. Allow pop-ups and press V to retry.',
216
196
  fullscreenUnavailable: 'Fullscreen is unavailable here. Open the presentation in a browser tab and try again.',
217
197
  notesCloseLabel: 'Close notes',
218
- overviewHint: 'Click a thumbnail to jump; arrows move, Enter opens, Esc exits'
198
+ overviewHint: 'Click a thumbnail to jump; arrows move, Enter opens, Esc exits',
219
199
  },
220
200
  },
221
201
  bilingual: {
@@ -251,129 +231,11 @@ export const LANGUAGES = {
251
231
  popupBlocked: '浏览器拦截了演讲者窗口 · Presenter window blocked; allow pop-ups and press V',
252
232
  fullscreenUnavailable: '当前窗口无法全屏,请独立打开演示文件 · Open this presentation in a browser tab for fullscreen.',
253
233
  notesCloseLabel: '关闭备注 · Close notes',
254
- overviewHint: '点击缩略图跳页 · Click to jump, arrows move, Enter opens, Esc exits'
234
+ overviewHint: '点击缩略图跳页 · Click to jump, arrows move, Enter opens, Esc exits',
255
235
  },
256
236
  },
257
237
  }
258
238
 
259
- // ---------------------------------------------------------------------------
260
- // 主题预览(ppt_themes preview=true / buildThemePreview)
261
- // ---------------------------------------------------------------------------
262
-
263
- function themePages(lang) {
264
- return lang === 'en'
265
- ? { title: 'dsh-ppt theme gallery', hint: 'Pick a theme id for ppt_create', usage: 'theme', dark: 'dark', light: 'light', palette: 'Palette' }
266
- : { title: 'dsh-ppt 主题预览', hint: '把 id 填给 ppt_create 的 theme 参数', usage: 'theme', dark: '深色', light: '浅色', palette: '色板' }
267
- }
268
-
269
- /** 单套主题的 960x540 SVG 色板卡:可直接放进 README / npm 首屏。 */
270
- export function renderThemeSvg(input, lang = 'zh') {
271
- const theme = typeof input === 'string' ? resolveTheme(input) : input
272
- const pick = (pair) => (lang === 'en' ? pair.en : pair.zh)
273
- const p = theme.palette
274
- const L = themePages(lang === 'en' ? 'en' : 'zh')
275
- const font = theme.fonts.heading.replace(/"/g, "'")
276
- const bodyFont = theme.fonts.body.replace(/"/g, "'")
277
- const out = []
278
- out.push('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 960 540" width="960" height="540" role="img" aria-label="' + escapeXml(theme.id + ' ' + pick(theme.name)) + '">')
279
- out.push('<rect width="960" height="540" fill="' + p.bg + '"/>')
280
- out.push('<rect x="0" y="0" width="960" height="6" fill="' + p.accent + '"/><rect x="0" y="534" width="960" height="6" fill="' + p.accent2 + '"/>')
281
- out.push('<rect x="36" y="40" width="560" height="360" rx="16" fill="' + p.panel + '" stroke="' + hexToRgba(p.muted, 0.45) + '"/>')
282
- out.push('<text x="64" y="92" fill="' + p.accent + '" font-family="' + escapeXml(bodyFont) + '" font-size="14" font-weight="700" letter-spacing="3">' + escapeXml(pick(theme.mood).toUpperCase()) + '</text>')
283
- out.push('<text x="64" y="158" fill="' + p.fg + '" font-family="' + escapeXml(font) + '" font-size="42" font-weight="800">' + escapeXml('Aa ' + pick(theme.name)) + '</text>')
284
- out.push('<circle cx="72" cy="206" r="5" fill="' + p.accent + '"/><rect x="92" y="199" width="360" height="12" rx="6" fill="' + hexToRgba(p.fg, 0.75) + '"/>')
285
- out.push('<circle cx="72" cy="240" r="5" fill="' + p.accent + '"/><rect x="92" y="233" width="300" height="12" rx="6" fill="' + hexToRgba(p.fg, 0.55) + '"/>')
286
- out.push('<circle cx="72" cy="274" r="5" fill="' + p.accent + '"/><rect x="92" y="267" width="330" height="12" rx="6" fill="' + hexToRgba(p.fg, 0.55) + '"/>')
287
- out.push('<rect x="64" y="312" width="500" height="34" rx="6" fill="' + p.accent + '"/>')
288
- out.push('<text x="78" y="334" fill="' + p.bg + '" font-family="' + escapeXml(bodyFont) + '" font-size="14" font-weight="700">dsh-ppt</text>')
289
- out.push('<text x="470" y="334" fill="' + p.bg + '" font-family="' + escapeXml(bodyFont) + '" font-size="14" font-weight="700" text-anchor="end">1,234</text>')
290
- out.push('<rect x="64" y="346" width="500" height="2" fill="' + hexToRgba(p.muted, 0.5) + '"/>')
291
- out.push('<text x="64" y="378" fill="' + p.muted + '" font-family="' + escapeXml(bodyFont) + '" font-size="13">' + escapeXml(theme.id + ' · ' + (theme.dark ? L.dark : L.light) + ' · v' + DECK_VERSION) + '</text>')
292
- const swatches = ['bg', 'panel', 'fg', 'muted', 'accent', 'accent2']
293
- const labels = ['bg', 'panel', 'fg', 'muted', 'accent', 'accent2']
294
- out.push('<text x="632" y="76" fill="' + p.muted + '" font-family="' + escapeXml(bodyFont) + '" font-size="13" font-weight="700" letter-spacing="2">' + escapeXml(L.palette.toUpperCase()) + '</text>')
295
- swatches.forEach((key, i) => {
296
- const y = 96 + i * 62
297
- out.push('<rect x="632" y="' + y + '" width="44" height="44" rx="10" fill="' + p[key] + '" stroke="' + hexToRgba(p.muted, 0.45) + '"/>')
298
- out.push('<text x="692" y="' + (y + 20) + '" fill="' + p.fg + '" font-family="' + escapeXml(bodyFont) + '" font-size="14" font-weight="600">' + escapeXml(labels[i]) + '</text>')
299
- out.push('<text x="692" y="' + (y + 38) + '" fill="' + p.muted + '" font-family="' + escapeXml(bodyFont) + '" font-size="13">' + escapeXml(String(p[key]).toUpperCase()) + '</text>')
300
- })
301
- out.push('<text x="632" y="508" fill="' + p.muted + '" font-family="' + escapeXml(bodyFont) + '" font-size="12">' + escapeXml(pick(theme.bestFor)).slice(0, 44) + '</text>')
302
- out.push('</svg>')
303
- return out.join('')
304
- }
305
-
306
- /** 自包含主题对比页:5 套主题并排,含色板与用法。 */
307
- export function renderThemePreviewHtml(lang = 'zh') {
308
- const L = themePages(lang === 'en' ? 'en' : 'zh')
309
- const cards = THEME_IDS.map((id) => {
310
- const theme = THEMES[id]
311
- const pick = (pair) => (lang === 'en' ? pair.en : pair.zh)
312
- const chips = Object.keys(theme.palette).map((key) =>
313
- '<span class="chip"><i style="background:' + theme.palette[key] + '"></i>' + escapeHtml(String(theme.palette[key]).toUpperCase()) + '</span>').join('')
314
- return '<figure class="card" id="theme-' + escapeHtml(id) + '">' +
315
- renderThemeSvg(theme, lang === 'en' ? 'en' : 'zh') +
316
- '<figcaption><div class="row"><strong>' + escapeHtml(id) + '</strong><span class="badge">' + escapeHtml(pick(theme.name)) + '</span></div>' +
317
- '<p class="muted">' + escapeHtml(pick(theme.mood)) + ' · ' + escapeHtml(pick(theme.bestFor)) + '</p>' +
318
- '<p class="chips">' + chips + '</p>' +
319
- '<p class="usage">' + escapeHtml(L.usage) + ': <code>' + escapeHtml(id) + '</code></p></figcaption></figure>'
320
- }).join('')
321
- return '<!DOCTYPE html>' + eolSafe('<html lang="zh-CN">') +
322
- '<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0">' +
323
- '<title>' + escapeHtml(L.title) + '</title><style>' +
324
- 'body{margin:0;background:#0b0f17;color:#e8f1ff;font-family:"Segoe UI","PingFang SC","Microsoft YaHei",sans-serif;padding:28px}' +
325
- 'h1{font-size:26px;margin:0 0 6px}p.sub{color:#8b98ad;margin:0 0 24px;font-size:14px}' +
326
- '.grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(430px,1fr));gap:22px}' +
327
- '.card{margin:0;background:#111827;border:1px solid #263043;border-radius:16px;overflow:hidden}' +
328
- '.card svg{display:block;width:100%;height:auto}' +
329
- 'figcaption{padding:14px 16px 16px}.row{display:flex;align-items:center;gap:10px;font-size:16px}' +
330
- '.badge{color:#8b98ad;font-size:13px}.muted{color:#8b98ad;font-size:13px;margin:6px 0 10px;line-height:1.5}' +
331
- '.chips{display:flex;flex-wrap:wrap;gap:6px;margin:0 0 10px}.chip{display:inline-flex;align-items:center;gap:6px;font-size:12px;color:#aab6c9;background:#0b0f17;border:1px solid #263043;border-radius:99px;padding:3px 9px}' +
332
- '.chip i{width:10px;height:10px;border-radius:3px;display:inline-block}' +
333
- '.usage{margin:0;font-size:13px;color:#aab6c9}code{background:#0b0f17;border:1px solid #263043;border-radius:6px;padding:1px 6px}' +
334
- '@media (prefers-reduced-motion: reduce){*{transition:none!important;animation:none!important}}' +
335
- '</style></head><body><h1>' + escapeHtml(L.title) + '</h1><p class="sub">' + escapeHtml(L.hint) + ' · dsh-ppt v' + escapeHtml(DECK_VERSION) + '</p>' +
336
- '<div class="grid">' + cards + '</div></body></html>'
337
- }
338
-
339
- function eolSafe(text) { return text }
340
-
341
- /** 写主题对比页 + 每套主题 SVG 色板卡;默认不覆盖同名文件。 */
342
- export function buildThemePreview(options = {}) {
343
- const langInput = typeof options.lang === 'string' && options.lang.trim() !== '' ? options.lang.trim() : 'zh'
344
- const language = resolveLanguage(langInput)
345
- const outputDir = resolvePath(String(options.outputDir ?? '.'))
346
- mkdirSync(outputDir, { recursive: true })
347
- const overwrite = options.overwrite === true
348
- const pickPath = (base, ext) => {
349
- const first = resolvePath(joinPath(outputDir, base + ext))
350
- if (overwrite || !existsSync(first)) return first
351
- for (let i = 1; i < 1000; i += 1) {
352
- const candidate = resolvePath(joinPath(outputDir, base + '-' + i + ext))
353
- if (!existsSync(candidate)) return candidate
354
- }
355
- throw new Error('dsh-ppt:找不到可用的预览文件名(同名前缀超过 999 个),请允许 overwrite。')
356
- }
357
- const htmlPath = pickPath('themes-preview', '.html')
358
- writeFileSync(htmlPath, renderThemePreviewHtml(language.id), 'utf8')
359
- const svgs = THEME_IDS.map((id) => {
360
- const svgPath = pickPath('theme-' + id, '.svg')
361
- writeFileSync(svgPath, renderThemeSvg(id, language.id), 'utf8')
362
- return { id, path: svgPath }
363
- })
364
- return { ok: true, outputDir, htmlPath, svgs, themeCount: THEME_IDS.length, language: language.id }
365
- }
366
-
367
-
368
- export function resolveTheme(input) {
369
- const id = String(input ?? DEFAULT_THEME).trim().toLowerCase()
370
- const theme = THEMES[id]
371
- if (!theme) {
372
- throw new Error('dsh-ppt:未知主题 "' + id + '",可选:' + THEME_IDS.join(' / ') + '(默认 ' + DEFAULT_THEME + ')')
373
- }
374
- return theme
375
- }
376
-
377
239
  export function resolveLanguage(input) {
378
240
  const id = String(input ?? 'zh').trim().toLowerCase()
379
241
  const language = LANGUAGES[id]
@@ -390,24 +252,27 @@ export function resolveMotion(input) {
390
252
  throw new Error('dsh-ppt:未知 motion 值 "' + String(input) + '",可选:on / off(默认 on)')
391
253
  }
392
254
 
393
- export function listThemes(lang = 'zh') {
394
- const pick = (pair) => (lang === 'en' ? pair.en : pair.zh)
395
- return THEME_IDS.map((id) => {
396
- const theme = THEMES[id]
397
- return {
398
- id,
399
- name: pick(theme.name),
400
- mood: pick(theme.mood),
401
- bestFor: pick(theme.bestFor),
402
- dark: theme.dark,
403
- palette: { ...theme.palette },
404
- fonts: { ...theme.fonts },
405
- }
406
- })
255
+ // ---------------------------------------------------------------------------
256
+ // 主题预览包装器(注入 DECK_VERSION 与语言校验)
257
+ // ---------------------------------------------------------------------------
258
+
259
+ /** 单套主题的 960x540 SVG 色板卡:可直接放进 README / npm 首屏。 */
260
+ export function renderThemeSvg(input, lang = 'zh') {
261
+ return renderThemeSvgBase(input, lang, DECK_VERSION)
262
+ }
263
+
264
+ /** 自包含主题对比页:14 套主题并排,含色板与用法。 */
265
+ export function renderThemePreviewHtml(lang = 'zh') {
266
+ return renderThemePreviewHtmlBase(lang, DECK_VERSION)
267
+ }
268
+
269
+ /** 写主题对比页 + 每套主题 SVG 色板卡;默认不覆盖同名文件。 */
270
+ export function buildThemePreview(options = {}) {
271
+ return buildThemePreviewBase(options, resolveLanguage, DECK_VERSION)
407
272
  }
408
273
 
409
274
  // ---------------------------------------------------------------------------
410
- // 文本工具
275
+ // 文本与文件名工具
411
276
  // ---------------------------------------------------------------------------
412
277
 
413
278
  export function clampInt(value, fallback, min, max) {
@@ -437,8 +302,6 @@ const DECK_ARTIFACT_EXTENSIONS = ['.html', '.pptx', '.json']
437
302
  * 整组改用 -1/-2… 后缀,避免新旧 deck 被静默混写。
438
303
  */
439
304
  export function resolveDeckFileName(outputDir, requestedFileName, overwrite) {
440
- // 一次 readdir 建集,替代逐个候选 existsSync 探测(最坏 ~3000 次 stat);
441
- // 统一小写比较,避免 Windows 大小写不敏感文件系统把已占用的名字判成可用。
442
305
  const existing = new Set(readdirSync(outputDir).map((name) => name.toLowerCase()))
443
306
  const isAvailable = (candidate) => DECK_ARTIFACT_EXTENSIONS.every((ext) => !existing.has((candidate + ext).toLowerCase()))
444
307
  if (overwrite || isAvailable(requestedFileName)) return requestedFileName
@@ -449,39 +312,6 @@ export function resolveDeckFileName(outputDir, requestedFileName, overwrite) {
449
312
  throw new Error('dsh-ppt:找不到可用的输出文件名(同名前缀超过 999 个),请更换 fileName 或显式允许 overwrite。')
450
313
  }
451
314
 
452
- export function escapeXml(value) {
453
- return String(value ?? '')
454
- .replace(/[\u000B\u000C]/g, '\n')
455
- .replace(/[^\u0009\u000A\u000D\u0020-\uD7FF\uE000-\uFFFD\u{10000}-\u{10FFFF}]/gu, '')
456
- .replace(/&/g, '&amp;')
457
- .replace(/</g, '&lt;')
458
- .replace(/>/g, '&gt;')
459
- .replace(/"/g, '&quot;')
460
- .replace(/'/g, '&apos;')
461
- }
462
-
463
- export function escapeHtml(value) {
464
- return String(value ?? '')
465
- .replace(/&/g, '&amp;')
466
- .replace(/</g, '&lt;')
467
- .replace(/>/g, '&gt;')
468
- .replace(/"/g, '&quot;')
469
- }
470
-
471
- export function stripInlineMarkdown(value) {
472
- return String(value ?? '')
473
- .replace(/!\[[^\]]*\]\([^)]*\)/g, '')
474
- .replace(/\[([^\]]+)\]\([^)]*\)/g, '$1')
475
- .replace(/`([^`]*)`/g, '$1')
476
- .replace(/\*\*([^*]+)\*\*/g, '$1')
477
- .replace(/__([^_]+)__/g, '$1')
478
- .replace(/\*([^*\n]+)\*/g, '$1')
479
- .replace(/_([^_\n]+)_/g, '$1')
480
- .replace(/<[^>]+>/g, '')
481
- .replace(/\s+/g, ' ')
482
- .trim()
483
- }
484
-
485
315
  export function splitSentences(value) {
486
316
  const text = String(value ?? '').trim()
487
317
  if (text === '') return []
@@ -502,11 +332,23 @@ function chunk(items, size) {
502
332
  }
503
333
 
504
334
  // ---------------------------------------------------------------------------
505
- // Markdown → deck
335
+ // Markdown → deck(兼容纯 Markdown,并原生支持 ::: 版式块、[!TAKEAWAY] 与 source 注释)
506
336
  // ---------------------------------------------------------------------------
507
337
 
508
338
  function createSection(heading = '', level = 0, coverOnly = false) {
509
- return { heading, level, coverOnly, bullets: [], paragraphs: [], quote: [], table: null, notes: [] }
339
+ return {
340
+ heading,
341
+ level,
342
+ coverOnly,
343
+ bullets: [],
344
+ paragraphs: [],
345
+ quote: [],
346
+ table: null,
347
+ notes: [],
348
+ directive: null,
349
+ takeaway: '',
350
+ source: '',
351
+ }
510
352
  }
511
353
 
512
354
  function splitTableRow(line) {
@@ -520,7 +362,24 @@ function isTableSeparator(cells) {
520
362
  return cells.length > 0 && cells.every((cell) => /^:?-{2,}:?$/.test(cell) || /^:?-+:?$/.test(cell))
521
363
  }
522
364
 
523
- const NOTES_COMMENT = /^<!--\s*(?:notes?|备注)\s*[::]\s*([\s\S]*?)\s*-->$/
365
+ const NOTES_COMMENT = /^<!--\s*(?:notes?|备注)\s*[::]\s*([\s\S]*?)\s*-->$/i
366
+ const SOURCE_COMMENT = /^<!--\s*(?:source|来源|数据来源)\s*[::]\s*([\s\S]*?)\s*-->$/i
367
+ const TAKEAWAY_COMMENT = /^<!--\s*(?:takeaway|结论|核心结论)\s*[::]\s*([\s\S]*?)\s*-->$/i
368
+ const TAKEAWAY_CALLOUT = /^>\s*\[!(?:TAKEAWAY|结论|KEY)\]\s*(.*)$/i
369
+ const DIRECTIVE_OPEN = /^:::\s*([a-zA-Z][\w-]*)(?:\s+([\w-]+))?\s*$/
370
+ const DIRECTIVE_CLOSE = /^:::\s*$/
371
+
372
+ function resolveDirectiveSpec(rawLayout, rawVariant = '') {
373
+ const key = String(rawLayout ?? '').trim().toLowerCase()
374
+ const alias = LAYOUT_ALIASES[key]
375
+ if (alias && CORE_LAYOUTS.has(alias.layout)) {
376
+ return { layout: alias.layout, variant: rawVariant || alias.variant || '' }
377
+ }
378
+ if (CORE_LAYOUTS.has(key)) {
379
+ return { layout: key, variant: rawVariant || '' }
380
+ }
381
+ return null
382
+ }
524
383
 
525
384
  function quoteSlideFrom(section, ui) {
526
385
  const lines = [...section.quote]
@@ -530,25 +389,35 @@ function quoteSlideFrom(section, ui) {
530
389
  attribution = attrMatch[1]
531
390
  lines.pop()
532
391
  }
533
- return { layout: 'quote', kicker: ui.quoteKicker, title: truncate(lines.join(' '), 220), subtitle: attribution }
392
+ return {
393
+ layout: 'quote',
394
+ kicker: ui.quoteKicker,
395
+ title: truncate(lines.join(' '), 220),
396
+ subtitle: attribution,
397
+ ...(section.source ? { source: section.source } : {}),
398
+ }
534
399
  }
535
400
 
536
401
  function paginateTable(slide, continuation = '(续)') {
537
402
  const rows = slide.rows
538
- const columns = Math.max(...rows.map(row => row.length))
403
+ const columns = Math.max(...rows.map((row) => row.length))
539
404
  if (columns > 8) throw new Error('dsh-ppt:表格最多 8 列,请拆成多个表格后重试 / tables support up to 8 columns')
540
- if (rows.some(row => row.some(cell => [...cell].length > 60))) {
405
+ if (rows.some((row) => row.some((cell) => [...stripInlineMarkdown(cell)].length > 60))) {
541
406
  throw new Error('dsh-ppt:表格单元格最多 60 个字符,请精简或拆分内容后重试 / cells support up to 60 characters')
542
407
  }
543
- const padded = rows.map(row => Array.from({ length: columns }, (_, i) => row[i] ?? ''))
408
+ const padded = rows.map((row) => Array.from({ length: columns }, (_, i) => row[i] ?? ''))
544
409
  const pages = chunk(padded.slice(1), 8)
545
410
  if (pages.length === 0) pages.push([])
546
411
  return pages.map((body, index) => {
547
412
  const { notes, ...rest } = slide
548
413
  const title = slide.title + (index === 0 ? '' : continuation)
549
- // 同名 kicker/title 共用紧凑标题;续页不能凭空多出一行大标题挤压表格。
550
- return { ...rest, title, kicker: slide.kicker === slide.title ? title : slide.kicker, rows: [padded[0], ...body],
551
- ...(index === 0 && notes ? { notes } : {}) }
414
+ return {
415
+ ...rest,
416
+ title,
417
+ kicker: slide.kicker === slide.title ? title : slide.kicker,
418
+ rows: [padded[0], ...body],
419
+ ...(index === 0 && notes ? { notes } : {}),
420
+ }
552
421
  })
553
422
  }
554
423
 
@@ -556,10 +425,20 @@ function tableSlidesFrom(section, ui) {
556
425
  const table = section.table
557
426
  const rows = [table.header, ...table.rows]
558
427
  const heading = section.heading || ui.tableKicker
559
- return paginateTable({ layout: 'table', kicker: heading, title: heading, rows }, ui.continuation)
428
+ const tableStyle = section.directive?.layout === 'table' && section.directive.variant
429
+ ? section.directive.variant
430
+ : undefined
431
+ return paginateTable({
432
+ layout: 'table',
433
+ kicker: heading,
434
+ title: heading,
435
+ rows,
436
+ ...(tableStyle ? { tableStyle } : {}),
437
+ ...(section.takeaway ? { takeaway: section.takeaway } : {}),
438
+ ...(section.source ? { source: section.source } : {}),
439
+ }, ui.continuation)
560
440
  }
561
441
 
562
- /** 把一个 section 里的金句/表格拆成独立页;备注附着到第一张产出页。 */
563
442
  function specialSlidesFor(section, ui) {
564
443
  const out = []
565
444
  if (section.quote.length > 0) out.push(quoteSlideFrom(section, ui))
@@ -568,6 +447,30 @@ function specialSlidesFor(section, ui) {
568
447
  return out
569
448
  }
570
449
 
450
+ function directiveSlideFrom(section, ui, pointIndexRef) {
451
+ const spec = section.directive
452
+ if (!spec || spec.layout === 'table') return null
453
+ const label = section.heading || (ui.pointKicker + ' ' + (++pointIndexRef.count))
454
+ const rawPoints = [
455
+ ...section.bullets,
456
+ ...section.paragraphs.slice(spec.layout === 'callout' ? 1 : 0),
457
+ ]
458
+ const items = normalizeSlideItems(rawPoints, spec.layout)
459
+ const slide = {
460
+ layout: spec.layout,
461
+ ...(spec.variant ? { variant: spec.variant } : {}),
462
+ kicker: label,
463
+ title: label,
464
+ ...(spec.layout === 'callout' && section.paragraphs[0] ? { text: section.paragraphs[0] } : {}),
465
+ ...(rawPoints.length > 0 ? { bullets: rawPoints } : {}),
466
+ ...(items ? { items } : {}),
467
+ ...(section.takeaway ? { takeaway: section.takeaway } : {}),
468
+ ...(section.source ? { source: section.source } : {}),
469
+ }
470
+ if (section.notes.length > 0) slide.notes = section.notes.join('\n')
471
+ return slide
472
+ }
473
+
571
474
  export function parseMarkdownDeck(titleInput, content, lang = 'zh') {
572
475
  const language = resolveLanguage(lang)
573
476
  const ui = language.ui
@@ -579,29 +482,59 @@ export function parseMarkdownDeck(titleInput, content, lang = 'zh') {
579
482
  let body = String(content ?? '')
580
483
  .replace(/^\uFEFF/, '')
581
484
  .replace(/\r\n?/g, '\n')
582
- // 去除文档级 YAML frontmatter(如果有)
583
485
  body = body.replace(/^---[ \t]*\n[\s\S]*?\n---[ \t]*\n?/, '')
584
486
 
585
487
  const sections = []
586
488
  let current = null
587
489
  let firstH1Seen = false
490
+ let inDirective = false
491
+ let awaitingTakeawayLine = false
588
492
 
589
493
  const flush = () => {
590
- if (current !== null && (current.heading !== '' || current.bullets.length > 0 || current.paragraphs.length > 0
591
- || current.table !== null || current.quote.length > 0)) {
494
+ if (
495
+ current !== null &&
496
+ (current.heading !== '' ||
497
+ current.bullets.length > 0 ||
498
+ current.paragraphs.length > 0 ||
499
+ current.table !== null ||
500
+ current.quote.length > 0 ||
501
+ current.directive !== null)
502
+ ) {
592
503
  sections.push(current)
593
504
  }
594
505
  current = null
506
+ inDirective = false
507
+ awaitingTakeawayLine = false
595
508
  }
596
509
 
597
510
  for (const rawLine of body.split('\n')) {
598
511
  const line = rawLine.trim()
599
512
  if (line === '') {
600
- // 无标题分组按空行分段,保证「文档无标题」时按段落生成幻灯片
601
- if (current !== null && current.heading === '') flush()
513
+ awaitingTakeawayLine = false
514
+ if (!inDirective && current !== null && current.heading === '') flush()
515
+ continue
516
+ }
517
+
518
+ if (DIRECTIVE_CLOSE.test(line)) {
519
+ inDirective = false
602
520
  continue
603
521
  }
604
522
 
523
+ const dirOpen = DIRECTIVE_OPEN.exec(line)
524
+ if (dirOpen !== null) {
525
+ const resolved = resolveDirectiveSpec(dirOpen[1], dirOpen[2])
526
+ if (resolved) {
527
+ if (current === null) current = createSection()
528
+ if (current.coverOnly) {
529
+ flush()
530
+ current = createSection()
531
+ }
532
+ current.directive = resolved
533
+ inDirective = true
534
+ continue
535
+ }
536
+ }
537
+
605
538
  const headingMatch = /^(#{1,6})\s+(.+)$/.exec(line)
606
539
  if (headingMatch !== null) {
607
540
  const level = headingMatch[1].length
@@ -618,9 +551,51 @@ export function parseMarkdownDeck(titleInput, content, lang = 'zh') {
618
551
  continue
619
552
  }
620
553
 
554
+ const notesMatch = NOTES_COMMENT.exec(line)
555
+ if (notesMatch !== null && notesMatch[1].trim() !== '') {
556
+ if (current === null) current = createSection()
557
+ current.notes.push(notesMatch[1].trim())
558
+ continue
559
+ }
560
+
561
+ const sourceMatch = SOURCE_COMMENT.exec(line)
562
+ if (sourceMatch !== null && sourceMatch[1].trim() !== '') {
563
+ if (current === null) current = createSection()
564
+ current.source = stripInlineMarkdown(sourceMatch[1])
565
+ continue
566
+ }
567
+
568
+ const takeawayCommentMatch = TAKEAWAY_COMMENT.exec(line)
569
+ if (takeawayCommentMatch !== null && takeawayCommentMatch[1].trim() !== '') {
570
+ if (current === null) current = createSection()
571
+ current.takeaway = cleanRichText(takeawayCommentMatch[1])
572
+ continue
573
+ }
574
+
575
+ const takeawayCalloutMatch = TAKEAWAY_CALLOUT.exec(line)
576
+ if (takeawayCalloutMatch !== null) {
577
+ if (current === null) current = createSection()
578
+ const inlineTakeaway = cleanRichText(takeawayCalloutMatch[1])
579
+ if (inlineTakeaway !== '') {
580
+ current.takeaway = inlineTakeaway
581
+ awaitingTakeawayLine = false
582
+ } else {
583
+ awaitingTakeawayLine = true
584
+ }
585
+ continue
586
+ }
587
+
588
+ if (awaitingTakeawayLine && line.startsWith('>')) {
589
+ const nextTakeaway = cleanRichText(line.replace(/^>\s?/, ''))
590
+ if (nextTakeaway !== '') current.takeaway = nextTakeaway
591
+ awaitingTakeawayLine = false
592
+ continue
593
+ }
594
+ awaitingTakeawayLine = false
595
+
621
596
  const bulletMatch = /^\s*(?:[-*+]|\d+[.)])\s+(.+)$/.exec(line)
622
597
  if (bulletMatch !== null) {
623
- const bullet = stripInlineMarkdown(bulletMatch[1])
598
+ const bullet = cleanRichText(bulletMatch[1])
624
599
  if (bullet !== '') {
625
600
  if (current === null) current = createSection()
626
601
  current.bullets.push(bullet)
@@ -628,31 +603,21 @@ export function parseMarkdownDeck(titleInput, content, lang = 'zh') {
628
603
  continue
629
604
  }
630
605
 
631
- // 演讲者备注:`<!-- 备注: ... -->` / `<!-- note: ... -->` 附到当前页
632
- const notesMatch = NOTES_COMMENT.exec(line)
633
- if (notesMatch !== null && notesMatch[1].trim() !== '') {
634
- if (current === null) current = createSection()
635
- current.notes.push(notesMatch[1].trim())
636
- continue
637
- }
638
-
639
- // Markdown 表格:连续的 | ... | 行,第二行是分隔线
640
606
  const tableCells = splitTableRow(line)
641
607
  if (tableCells !== null) {
642
608
  if (current === null) current = createSection()
643
609
  if (isTableSeparator(tableCells)) continue
644
610
  if (current.table === null) {
645
- current.table = { header: tableCells.map((cell) => stripInlineMarkdown(cell)), rows: [] }
611
+ current.table = { header: tableCells.map((cell) => cleanRichText(cell)), rows: [] }
646
612
  } else {
647
- current.table.rows.push(tableCells.map((cell) => stripInlineMarkdown(cell)))
613
+ current.table.rows.push(tableCells.map((cell) => cleanRichText(cell)))
648
614
  }
649
615
  continue
650
616
  }
651
617
 
652
- // 金句:`>` 引用块(最后一行 `—— 出处` 识别为署名)
653
618
  const quoteMatch = /^>\s?(.*)$/.exec(line)
654
619
  if (quoteMatch !== null) {
655
- const quoted = stripInlineMarkdown(quoteMatch[1])
620
+ const quoted = cleanRichText(quoteMatch[1])
656
621
  if (quoted !== '') {
657
622
  if (current === null) current = createSection()
658
623
  current.quote.push(quoted)
@@ -660,7 +625,7 @@ export function parseMarkdownDeck(titleInput, content, lang = 'zh') {
660
625
  continue
661
626
  }
662
627
 
663
- const paragraph = stripInlineMarkdown(line)
628
+ const paragraph = cleanRichText(line)
664
629
  if (paragraph === '') continue
665
630
  if (current === null) current = createSection()
666
631
  current.paragraphs.push(paragraph)
@@ -672,14 +637,12 @@ export function parseMarkdownDeck(titleInput, content, lang = 'zh') {
672
637
  if (coverSource !== null && coverSource !== undefined) {
673
638
  const coverText = coverSource.paragraphs[0] ?? coverSource.bullets[0] ?? ''
674
639
  if (coverSubtitle === '') {
675
- coverSubtitle = truncate(coverText, 180)
676
- coverSubtitleConsumed = true
677
- }
640
+ coverSubtitle = truncate(stripInlineMarkdown(coverText), 180)
641
+ coverSubtitleConsumed = true
642
+ }
678
643
  }
679
644
 
680
645
  let bodySections = sections.filter((section) => section.coverOnly !== true)
681
- // 首个 H1 既是封面又把所有要点收在封面节里时,把封面副标题之外的剩余要点
682
- // 提升为一个无标题节,走下面的要点页生成逻辑,避免丢掉内容。
683
646
  if (bodySections.length === 0 && coverSource !== null && coverSource !== undefined) {
684
647
  const usedParagraph = coverSource.paragraphs.length > 0
685
648
  const extras = [
@@ -689,25 +652,27 @@ export function parseMarkdownDeck(titleInput, content, lang = 'zh') {
689
652
  if (extras.length > 0) {
690
653
  const synthetic = createSection()
691
654
  synthetic.bullets = extras
655
+ synthetic.takeaway = coverSource.takeaway
656
+ synthetic.source = coverSource.source
692
657
  bodySections = [synthetic]
693
658
  }
694
659
  }
695
660
 
696
- // 表格和引用不能只挂在封面节上,否则首个 H1 后没有 H2 时会丢失。
697
661
  if (coverSource && (coverSource.table !== null || coverSource.quote.length > 0)) {
698
662
  const special = createSection()
699
663
  special.table = coverSource.table
700
664
  special.quote = coverSource.quote
701
665
  special.notes = coverSource.notes
666
+ special.takeaway = coverSource.takeaway
667
+ special.source = coverSource.source
702
668
  bodySections.unshift(special)
703
669
  }
704
670
 
705
671
  if (bodySections.length === 0) {
706
- // 一句话 / 无结构输入:封面 + 核心观点 + 结束页(仍是完整的三页演示文稿)
707
672
  const allText = coverSource !== null && coverSource !== undefined
708
673
  ? [...coverSource.bullets, ...coverSource.paragraphs].join(' ')
709
674
  : String(content ?? '').trim()
710
- if (coverSubtitle === '') coverSubtitle = truncate(splitSentences(allText)[0] ?? '', 180)
675
+ if (coverSubtitle === '') coverSubtitle = truncate(splitSentences(stripInlineMarkdown(allText))[0] ?? '', 180)
711
676
  slides.push({ layout: 'cover', kicker: ui.coverKicker, title: coverTitle || 'Untitled', subtitle: coverSubtitle })
712
677
  if (coverSubtitle !== '') {
713
678
  slides.push({ layout: 'statement', kicker: ui.statementKicker, title: coverSubtitle, subtitle: coverTitle })
@@ -716,16 +681,15 @@ export function parseMarkdownDeck(titleInput, content, lang = 'zh') {
716
681
  return { title: coverTitle || 'Untitled', subtitle: coverSubtitle, slides }
717
682
  }
718
683
 
719
- const hadHeadings = bodySections.some((section) => section.heading !== '')
684
+ const hadHeadings = bodySections.some((section) => section.heading !== '' || section.directive !== null)
720
685
 
721
686
  if (!hadHeadings) {
722
- // 无标题文档:第一段摘要作封面副标题,后续段落拆成要点页
723
687
  const ordered = bodySections.map((section) => ({
724
688
  section,
725
689
  sentences: [...section.bullets, ...section.paragraphs].flatMap((part) => splitSentences(part)),
726
690
  }))
727
691
  const firstSentence = ordered[0]?.sentences[0] ?? ''
728
- if (coverSubtitle === '') coverSubtitle = truncate(firstSentence, 180)
692
+ if (coverSubtitle === '') coverSubtitle = truncate(stripInlineMarkdown(firstSentence), 180)
729
693
  const bodySlides = []
730
694
  let pointIndex = 0
731
695
  ordered.forEach((group, groupIndex) => {
@@ -737,8 +701,10 @@ export function parseMarkdownDeck(titleInput, content, lang = 'zh') {
737
701
  const slide = {
738
702
  layout: 'bullets',
739
703
  kicker: ui.pointKicker + ' ' + pointIndex,
740
- title: truncate(points[0], 40) || ui.pointKicker + ' ' + pointIndex,
704
+ title: truncate(stripInlineMarkdown(points[0]), 40) || ui.pointKicker + ' ' + pointIndex,
741
705
  bullets: points,
706
+ ...(group.section.takeaway ? { takeaway: group.section.takeaway } : {}),
707
+ ...(group.section.source ? { source: group.section.source } : {}),
742
708
  }
743
709
  if (specials.length === 0 && group.section.notes.length > 0) slide.notes = group.section.notes.join('\n')
744
710
  bodySlides.push(slide)
@@ -757,43 +723,62 @@ export function parseMarkdownDeck(titleInput, content, lang = 'zh') {
757
723
  }
758
724
 
759
725
  slides.push({ layout: 'cover', kicker: ui.coverKicker, title: coverTitle || 'Untitled', subtitle: coverSubtitle })
760
- let pointIndex = 0
726
+ const pointRef = { count: 0 }
761
727
  for (const section of bodySections) {
762
728
  const notes = section.notes.join('\n')
763
729
  const specials = specialSlidesFor(section, ui)
764
730
  slides.push(...specials)
731
+
732
+ if (section.directive && section.directive.layout !== 'table') {
733
+ const dirSlide = directiveSlideFrom(section, ui, pointRef)
734
+ if (dirSlide) slides.push(dirSlide)
735
+ continue
736
+ }
737
+
765
738
  if (section.heading === '') {
766
- const points = [...section.bullets, ...section.paragraphs]
767
- .flatMap((part) => splitSentences(part))
768
- // 超过 8 条自动续页,不再静默丢弃;备注只挂在第一页
739
+ const points = [...section.bullets, ...section.paragraphs].flatMap((part) => splitSentences(part))
769
740
  for (const [pageIndex, pagePoints] of chunk(points, 8).entries()) {
770
- pointIndex += 1
741
+ pointRef.count += 1
771
742
  const slide = {
772
743
  layout: 'bullets',
773
- kicker: ui.pointKicker + ' ' + pointIndex,
774
- title: truncate(pagePoints[0], 40) || ui.pointKicker + ' ' + pointIndex,
744
+ kicker: ui.pointKicker + ' ' + pointRef.count,
745
+ title: truncate(stripInlineMarkdown(pagePoints[0]), 40) || ui.pointKicker + ' ' + pointRef.count,
775
746
  bullets: pagePoints,
747
+ ...(section.takeaway ? { takeaway: section.takeaway } : {}),
748
+ ...(section.source ? { source: section.source } : {}),
776
749
  }
777
750
  if (pageIndex === 0 && specials.length === 0 && notes !== '') slide.notes = notes
778
751
  slides.push(slide)
779
752
  }
780
753
  continue
781
754
  }
755
+
782
756
  const points = [
783
757
  ...section.bullets,
784
758
  ...section.paragraphs.flatMap((part) => splitSentences(part)),
785
759
  ]
786
760
  const pages = chunk(points, 8)
787
761
  if (pages.length > 0) {
788
- // 超过 8 条自动续页,不再静默丢弃;备注只挂在第一页
789
762
  pages.forEach((pagePoints, pageIndex) => {
790
763
  const label = pageIndex === 0 ? section.heading : section.heading + ui.continuation
791
- const slide = { layout: 'bullets', kicker: label, title: label, bullets: pagePoints }
764
+ const slide = {
765
+ layout: 'bullets',
766
+ kicker: label,
767
+ title: label,
768
+ bullets: pagePoints,
769
+ ...(section.takeaway ? { takeaway: section.takeaway } : {}),
770
+ ...(section.source ? { source: section.source } : {}),
771
+ }
792
772
  if (pageIndex === 0 && specials.length === 0 && notes !== '') slide.notes = notes
793
773
  slides.push(slide)
794
774
  })
795
775
  } else if (specials.length === 0) {
796
- const slide = { layout: 'section', kicker: section.heading, title: section.heading }
776
+ const slide = {
777
+ layout: 'section',
778
+ kicker: section.heading,
779
+ title: section.heading,
780
+ ...(section.source ? { source: section.source } : {}),
781
+ }
797
782
  if (notes !== '') slide.notes = notes
798
783
  slides.push(slide)
799
784
  }
@@ -802,50 +787,151 @@ export function parseMarkdownDeck(titleInput, content, lang = 'zh') {
802
787
  return { title: coverTitle || 'Untitled', subtitle: coverSubtitle, slides }
803
788
  }
804
789
 
805
- const SLIDE_LAYOUTS = new Set(['cover', 'section', 'bullets', 'statement', 'closing', 'quote', 'table', ...MEDIA_LAYOUTS])
790
+ // ---------------------------------------------------------------------------
791
+ // 结构化幻灯片规范化
792
+ // ---------------------------------------------------------------------------
793
+
794
+ export const SLIDE_LAYOUTS = new Set([
795
+ ...CORE_LAYOUTS,
796
+ ...Object.keys(LAYOUT_ALIASES),
797
+ ...deckMedia.MEDIA_LAYOUTS,
798
+ ])
799
+
800
+ const VALID_TABLE_STYLES = new Set(['consulting', 'booktabs', 'minimal', 'banded', 'harvey'])
801
+ const VALID_CHROME_STYLES = new Set(CHROME_STYLES)
806
802
 
807
803
  function normalizeSlide(raw, index) {
808
- const result = normalizeSlideContent(raw, index), visual = normalizeVisual(raw?.visual)
804
+ const result = normalizeSlideContent(raw, index)
805
+ const visual = normalizeVisual(raw?.visual)
809
806
  return visual ? { ...result, visual } : result
810
807
  }
808
+
811
809
  function normalizeSlideContent(raw, index) {
812
810
  const source = (raw !== null && typeof raw === 'object') ? raw : {}
813
- const layout = SLIDE_LAYOUTS.has(source.layout) ? source.layout : source.chart ? 'chart' : source.image ? 'image-right' : 'bullets'
811
+ const rawLayoutKey = String(source.layout ?? '').trim().toLowerCase()
812
+ const alias = LAYOUT_ALIASES[rawLayoutKey]
813
+ const candidateLayout = alias ? alias.layout : rawLayoutKey
814
+ const layout = (CORE_LAYOUTS.has(candidateLayout) || deckMedia.MEDIA_LAYOUTS.has(candidateLayout))
815
+ ? candidateLayout
816
+ : source.chart
817
+ ? 'chart'
818
+ : (source.image || (Array.isArray(source.images) && source.images.length > 0))
819
+ ? 'image-right'
820
+ : 'bullets'
821
+
822
+ const variant = stripInlineMarkdown(source.variant ?? alias?.variant ?? '')
823
+ const rawChrome = typeof source.chrome === 'string' ? source.chrome.trim() : ''
824
+ const chrome = VALID_CHROME_STYLES.has(rawChrome) ? rawChrome : undefined
814
825
  const title = stripInlineMarkdown(source.title ?? '')
815
- const subtitle = stripInlineMarkdown(source.subtitle ?? '')
826
+ const subtitle = cleanRichText(source.subtitle ?? '')
816
827
  const kicker = stripInlineMarkdown(source.kicker ?? '')
817
- const text = stripInlineMarkdown(source.text ?? '')
818
- // 备注保留换行(放映面板与备注页都按原文显示),只做转义,不做 Markdown 清洗
828
+ const text = cleanRichText(source.text ?? '')
829
+ const takeaway = cleanRichText(source.takeaway ?? '')
830
+ const slideSource = stripInlineMarkdown(source.source ?? '')
819
831
  const notes = String(source.notes ?? '').trim()
832
+ const activeIndex = Number.isInteger(source.activeIndex) && source.activeIndex >= 1 ? source.activeIndex : undefined
833
+ const rawTableStyle = String(source.tableStyle ?? '').trim().toLowerCase()
834
+ const tableStyle = VALID_TABLE_STYLES.has(rawTableStyle) ? rawTableStyle : undefined
835
+ const start = source.start !== undefined && source.start !== null && Number.isFinite(Number(source.start)) ? Number(source.start) : undefined
836
+ const span = source.span !== undefined && source.span !== null && Number.isFinite(Number(source.span)) ? Number(source.span) : undefined
837
+
820
838
  let bullets = []
821
839
  if (Array.isArray(source.bullets)) {
822
- bullets = source.bullets.map((item) => stripInlineMarkdown(String(item))).filter(Boolean)
840
+ bullets = source.bullets.map((item) => cleanRichText(String(item))).filter(Boolean)
823
841
  } else if (typeof source.bullets === 'string' && source.bullets.trim() !== '') {
824
- bullets = splitSentences(source.bullets)
842
+ bullets = splitSentences(cleanRichText(source.bullets))
843
+ }
844
+
845
+ const hasStringColumns = Array.isArray(source.columns) && source.columns.length > 0 && source.columns.every((c) => typeof c === 'string')
846
+ const columns = hasStringColumns
847
+ ? source.columns.map((c) => stripInlineMarkdown(c)).filter(Boolean)
848
+ : undefined
849
+
850
+ const rawItemsInput = source.items
851
+ ?? source.cards
852
+ ?? source.metrics
853
+ ?? (!hasStringColumns ? source.columns : undefined)
854
+ ?? source.steps
855
+ ?? source.quadrants
856
+ const items = normalizeSlideItems(rawItemsInput, layout)
857
+
858
+ const commonExtras = {
859
+ ...(variant !== '' ? { variant } : {}),
860
+ ...(chrome ? { chrome } : {}),
861
+ ...(takeaway !== '' ? { takeaway } : {}),
862
+ ...(slideSource !== '' ? { source: slideSource } : {}),
863
+ ...(activeIndex !== undefined ? { activeIndex } : {}),
864
+ ...(columns?.length ? { columns } : {}),
865
+ ...(start !== undefined ? { start } : {}),
866
+ ...(span !== undefined ? { span } : {}),
867
+ ...(items ? { items } : {}),
868
+ ...(notes !== '' ? { notes } : {}),
825
869
  }
826
- if (MEDIA_LAYOUTS.has(layout)) return normalizeMediaSlide(source, { layout, kicker, title, subtitle, text, bullets, ...(notes !== '' ? { notes } : {}) }, index)
870
+
871
+ if (deckMedia.MEDIA_LAYOUTS.has(layout)) {
872
+ const mediaSource = alias?.chartKind && source.chart
873
+ ? { ...source, variant: variant || source.variant, chart: { ...source.chart, kind: alias.chartKind } }
874
+ : (variant ? { ...source, variant } : source)
875
+ return deckMedia.normalizeMediaSlide(
876
+ mediaSource,
877
+ { layout, kicker, title, subtitle, text, bullets, ...commonExtras },
878
+ index,
879
+ )
880
+ }
881
+
827
882
  if (layout === 'statement' && title === '' && text !== '') {
828
- return { layout, kicker, title: text, subtitle: subtitle || '', bullets, ...(notes !== '' ? { notes } : {}) }
883
+ return { layout, kicker, title: stripInlineMarkdown(text), subtitle: subtitle || '', bullets, ...commonExtras }
829
884
  }
885
+
830
886
  if (layout === 'quote') {
831
- const quoteText = title !== '' ? title : text
832
- if (quoteText === '') return { layout: 'statement', kicker, title: subtitle, subtitle: '', bullets, ...(notes !== '' ? { notes } : {}) }
833
- return { layout, kicker, title: truncate(quoteText, 220), subtitle, ...(notes !== '' ? { notes } : {}) }
887
+ const quoteText = title !== '' ? title : stripInlineMarkdown(text)
888
+ if (quoteText === '') {
889
+ return { layout: 'statement', kicker, title: stripInlineMarkdown(subtitle), subtitle: '', bullets, ...commonExtras }
890
+ }
891
+ return { layout, kicker, title: truncate(quoteText, 220), subtitle, ...commonExtras }
892
+ }
893
+
894
+ if (layout === 'harvey') {
895
+ let rows = []
896
+ if (Array.isArray(source.rows)) {
897
+ rows = source.rows
898
+ .map((row) => (Array.isArray(row) ? row : [row]).map((cell) => cleanRichText(String(cell))))
899
+ .filter((row) => row.some((cell) => cell !== ''))
900
+ }
901
+ return {
902
+ layout,
903
+ kicker: kicker || title,
904
+ title,
905
+ subtitle,
906
+ text,
907
+ bullets,
908
+ ...(rows.length ? { rows } : {}),
909
+ ...(tableStyle ? { tableStyle } : {}),
910
+ ...commonExtras,
911
+ }
834
912
  }
913
+
835
914
  if (layout === 'table') {
836
915
  let rows = []
837
916
  if (Array.isArray(source.rows)) {
838
917
  rows = source.rows
839
- .map((row) => (Array.isArray(row) ? row : [row]).map((cell) => stripInlineMarkdown(String(cell))))
918
+ .map((row) => (Array.isArray(row) ? row : [row]).map((cell) => cleanRichText(String(cell))))
840
919
  .filter((row) => row.some((cell) => cell !== ''))
841
920
  }
842
921
  if (rows.length === 0) {
843
- // 没有表格数据的 table 页退化成要点页,避免产出空白版式
844
- return { layout: 'bullets', kicker, title, subtitle, bullets, ...(notes !== '' ? { notes } : {}) }
922
+ return { layout: 'bullets', kicker, title, subtitle, bullets, ...commonExtras }
923
+ }
924
+ return {
925
+ layout,
926
+ kicker: kicker || title,
927
+ title,
928
+ rows,
929
+ ...(tableStyle ? { tableStyle } : {}),
930
+ ...commonExtras,
845
931
  }
846
- return { layout, kicker: kicker || title, title, rows, ...(notes !== '' ? { notes } : {}) }
847
932
  }
848
- return { layout, kicker, title, subtitle, text, bullets, ...(notes !== '' ? { notes } : {}) }
933
+
934
+ return { layout, kicker, title, subtitle, text, bullets, ...commonExtras }
849
935
  }
850
936
 
851
937
  function checkSlideLimit(slides, limit) {
@@ -861,15 +947,16 @@ export function normalizeSlides(rawSlides, maxSlides = 60, lang = 'zh') {
861
947
  }
862
948
  const limit = clampInt(maxSlides, 60, 1, 120)
863
949
  const ui = resolveLanguage(lang).ui
864
- const slides = rawSlides.map(normalizeSlide).flatMap(slide => slide.layout === 'table'
865
- ? paginateTable(slide, ui.continuation) : [slide])
950
+ const slides = rawSlides
951
+ .map(normalizeSlide)
952
+ .flatMap((slide) => (slide.layout === 'table' ? paginateTable(slide, ui.continuation) : [slide]))
866
953
  checkSlideLimit(slides, limit)
867
954
  if (slides.length === 0) throw new Error('dsh-ppt:slides 规范化后为空')
868
955
  return slides
869
956
  }
870
957
 
871
958
  // ---------------------------------------------------------------------------
872
- // 构建入口
959
+ // 构建入口与原子落盘
873
960
  // ---------------------------------------------------------------------------
874
961
 
875
962
  export function normalizeBuildOptions(options = {}) {
@@ -913,7 +1000,6 @@ export function commitDeckArtifacts(artifacts) {
913
1000
  } catch {}
914
1001
  }
915
1002
 
916
- // 阶段 0:记下已有产物内容用于回滚;读不出来(如被同名目录占用)先报错,不碰任何文件。
917
1003
  const previous = new Map()
918
1004
  for (const item of items) {
919
1005
  if (!existsSync(item.path)) continue
@@ -924,7 +1010,6 @@ export function commitDeckArtifacts(artifacts) {
924
1010
  }
925
1011
  }
926
1012
 
927
- // 阶段 1:全部写临时文件;这一步失败时目标文件尚未被改动。
928
1013
  let written = 0
929
1014
  try {
930
1015
  for (const item of items) {
@@ -936,7 +1021,6 @@ export function commitDeckArtifacts(artifacts) {
936
1021
  throw new Error('dsh-ppt:写入临时文件失败(' + items[written].path + '),原三件套未改动:' + error.message)
937
1022
  }
938
1023
 
939
- // 阶段 2:逐个 rename 提交;中途失败则把已提交的目标回滚成旧内容。
940
1024
  const committed = []
941
1025
  try {
942
1026
  for (const item of items) {
@@ -958,8 +1042,15 @@ export function commitDeckArtifacts(artifacts) {
958
1042
  }
959
1043
 
960
1044
  export function buildDeck(options = {}) {
961
- if(options.dataModel!==undefined)throw new Error('dsh-ppt:数据绑定请使用 deck-advanced.mjs 的 buildDeckAsync / Data models require buildDeckAsync from deck-advanced.mjs')
962
- if (options.brand || options.template || options.slides?.some(slide => MEDIA_LAYOUTS.has(slide.layout) || slide.image || slide.chart)) {
1045
+ if (options.dataModel !== undefined) {
1046
+ throw new Error('dsh-ppt:数据绑定请使用 deck-advanced.mjs 的 buildDeckAsync / Data models require buildDeckAsync from deck-advanced.mjs')
1047
+ }
1048
+ if (
1049
+ options.brand ||
1050
+ options.template ||
1051
+ options.referencePptx ||
1052
+ options.slides?.some((slide) => deckMedia.MEDIA_LAYOUTS.has(slide.layout) || slide.image || slide.images?.length || slide.chart)
1053
+ ) {
963
1054
  throw new Error('dsh-ppt:图片、图表、模板与品牌请使用异步 buildDeckAsync 或 ppt_create / CLI')
964
1055
  }
965
1056
  const normalized = normalizeBuildOptions(options)
@@ -980,7 +1071,6 @@ export function buildDeck(options = {}) {
980
1071
  const htmlPath = resolvePath(outputDir, fileName + '.html')
981
1072
  const pptxPath = resolvePath(outputDir, fileName + '.pptx')
982
1073
 
983
- // 先生成三份内容再统一提交:生成阶段抛错时也不会留下半套文件。
984
1074
  commitDeckArtifacts([
985
1075
  { path: jsonPath, data: JSON.stringify(manifest, null, 2) + '\n', encoding: 'utf8' },
986
1076
  { path: htmlPath, data: renderHtml(manifest, theme, language, { pptx: pptxPath, json: jsonPath }), encoding: 'utf8' },
@@ -1009,9 +1099,10 @@ export function buildDeck(options = {}) {
1009
1099
  // HTML 网页放映
1010
1100
  // ---------------------------------------------------------------------------
1011
1101
 
1012
- export function renderHtml(manifest, theme, language, files = {}) {
1013
- const t = theme
1014
- const lang = language
1102
+ export function renderHtml(manifest, themeInput, languageInput, files = {}) {
1103
+ const t = themeInput?.id ? themeInput : resolveTheme(themeInput)
1104
+ const tk = t.tokens
1105
+ const lang = languageInput?.id ? languageInput : resolveLanguage(languageInput)
1015
1106
  const ui = lang.ui
1016
1107
  const motion = manifest.motion !== false
1017
1108
  const motionCss = motion
@@ -1026,13 +1117,19 @@ body.motion .bullets li{
1026
1117
  const slides = manifest.slides.map((slide, index) => {
1027
1118
  const label = slide.title || slide.kicker || (ui.slide + ' ' + (index + 1))
1028
1119
  return '<div class="slide-frame" data-frame="' + (index + 1) + '" tabindex="-1" role="button" aria-label="' + escapeHtml(String(label)) + '">' +
1029
- renderHtmlSlide(slide, index, ui, lang.id, manifest, theme) + '</div>'
1120
+ renderHtmlSlide(slide, index, ui, lang.id, manifest, t) + '</div>'
1030
1121
  }).join('\n')
1031
1122
  const themeLabel = t.name[lang.id] ?? t.name.en
1032
1123
  const total = manifest.slides.length
1033
1124
  const delivery = renderDelivery(manifest, files, lang.id)
1034
1125
  const dataView = renderDataView(manifest, t)
1035
1126
 
1127
+ const ambientCss = t.dark
1128
+ ? `radial-gradient(42% 34% at 82% 18%, ${hexToRgba(t.palette.accent, 0.16)}, transparent 70%),
1129
+ radial-gradient(36% 30% at 12% 86%, ${hexToRgba(t.palette.accent2, 0.11)}, transparent 70%),
1130
+ radial-gradient(70% 60% at 50% 50%, ${hexToRgba(t.palette.panel, 0.45)}, transparent 100%)`
1131
+ : `radial-gradient(48% 36% at 90% 8%, ${hexToRgba(t.palette.accent, 0.045)}, transparent 72%)`
1132
+
1036
1133
  return `<!DOCTYPE html>
1037
1134
  <html lang="${lang.attr}">
1038
1135
  <head>
@@ -1048,6 +1145,18 @@ body.motion .bullets li{
1048
1145
  --muted:${t.palette.muted};
1049
1146
  --accent:${t.palette.accent};
1050
1147
  --accent2:${t.palette.accent2};
1148
+ --surface1:${tk.surface1};
1149
+ --surface2:${tk.surface2};
1150
+ --hairline:${tk.hairline};
1151
+ --ink-secondary:${tk.inkSecondary};
1152
+ --ink-on-accent:${tk.inkOnAccent};
1153
+ --accent-text:${tk.accentText};
1154
+ --accent-soft:${tk.accentSoft};
1155
+ --positive:${tk.positive};
1156
+ --negative:${tk.negative};
1157
+ --warning:${tk.warning};
1158
+ --cover-bg:${tk.coverBg};
1159
+ --radius:${t.radiusPx ?? 8}px;
1051
1160
  --font-heading:${t.fonts.heading};
1052
1161
  --font-body:${t.fonts.body};
1053
1162
  }
@@ -1063,77 +1172,62 @@ body{
1063
1172
  .slide-frame.is-current,body.overview .slide-frame{pointer-events:auto}
1064
1173
  .slide{
1065
1174
  position:absolute;inset:0;display:none;flex-direction:column;justify-content:center;
1066
- padding:clamp(34px,7vw,110px);overflow:hidden;
1175
+ padding:clamp(30px,4.6vw,68px) clamp(36px,5.4vw,88px);overflow:hidden;
1067
1176
  }
1068
1177
  .slide::before{
1069
1178
  content:"";position:absolute;inset:-20%;pointer-events:none;z-index:-1;
1070
- background:
1071
- radial-gradient(42% 34% at 82% 18%, ${hexToRgba(t.palette.accent, t.dark ? 0.22 : 0.12)}, transparent 70%),
1072
- radial-gradient(36% 30% at 12% 86%, ${hexToRgba(t.palette.accent2, t.dark ? 0.16 : 0.12)}, transparent 70%),
1073
- radial-gradient(70% 60% at 50% 50%, ${hexToRgba(t.palette.panel, 0.55)}, transparent 100%);
1179
+ background:${ambientCss};
1074
1180
  }
1075
1181
  .slide.is-active{display:flex}
1076
1182
  ${motionCss}
1077
- ${MEDIA_CSS}
1183
+ ${LAYOUT_CSS}
1184
+ ${deckMedia.MEDIA_CSS}
1078
1185
  ${VISUAL_CSS}
1079
1186
  .kicker{
1080
- color:var(--accent);font-weight:700;letter-spacing:.18em;text-transform:uppercase;
1081
- font-size:clamp(12px,1.3vw,18px);margin-bottom:22px;
1187
+ color:var(--accent-text);font-weight:700;letter-spacing:.14em;text-transform:uppercase;
1188
+ font-size:clamp(12px,1.15vw,16px);margin-bottom:14px;
1082
1189
  }
1083
- h1,h2,.statement-title{font-family:var(--font-heading);line-height:1.06;letter-spacing:-.015em;margin:0}
1084
- h1{font-size:clamp(44px,7.4vw,118px);max-width:20ch}
1085
- h2{font-size:clamp(34px,5vw,82px);max-width:20ch}
1190
+ h1,h2,.statement-title{font-family:var(--font-heading);line-height:1.12;letter-spacing:-.018em;margin:0}
1191
+ h1{font-size:clamp(40px,5.8vw,86px);max-width:22ch;font-weight:800}
1192
+ h2{font-size:clamp(28px,3.6vw,56px);max-width:28ch;font-weight:750}
1086
1193
  .subtitle{
1087
- color:var(--muted);font-size:clamp(18px,2.3vw,34px);line-height:1.5;
1088
- max-width:46em;margin-top:28px;
1194
+ color:var(--ink-secondary);font-size:clamp(17px,1.9vw,28px);line-height:1.5;
1195
+ max-width:46em;margin-top:18px;
1089
1196
  }
1090
1197
  .meta{
1091
- color:var(--muted);font-size:clamp(12px,1.2vw,16px);margin-top:48px;
1092
- letter-spacing:.06em;
1198
+ color:var(--muted);font-size:clamp(12px,1.1vw,15px);margin-top:32px;
1199
+ letter-spacing:.04em;
1093
1200
  }
1094
- .bullets ul{margin:30px 0 0;padding:0;list-style:none;display:grid;gap:clamp(12px,1.6vw,24px)}
1095
- .bullets li{
1096
- position:relative;padding-left:clamp(28px,2.6vw,44px);
1097
- font-size:clamp(20px,2.6vw,40px);line-height:1.35;max-width:24em;
1098
- }
1099
- .bullets li::before{
1100
- content:"";position:absolute;left:0;top:.58em;width:.5em;height:.5em;
1101
- background:var(--accent);border-radius:2px;box-shadow:.28em .28em 0 color-mix(in srgb, var(--accent2) 78%, transparent);
1102
- }
1103
- .section .kicker{margin-bottom:10px}
1104
- .section .accent-line{width:min(180px,18vw);height:6px;background:var(--accent);margin:28px 0}
1201
+ .section .kicker,.slide--section .kicker{margin-bottom:10px}
1202
+ .section .accent-line,.slide--section .accent-line{width:min(140px,14vw);height:5px;background:var(--accent);margin:18px 0;border-radius:2px}
1105
1203
  .statement-title{
1106
- font-size:clamp(34px,5.4vw,88px);max-width:22ch;font-weight:800;
1107
- border-left:6px solid var(--accent);padding-left:clamp(22px,3vw,48px);
1204
+ font-size:clamp(30px,4.4vw,68px);max-width:24ch;font-weight:800;line-height:1.24;
1108
1205
  }
1109
- .closing{text-align:center;align-items:center}
1110
- .closing h1,.closing .statement-title{font-size:clamp(52px,9vw,148px)}
1111
- .closing .subtitle{color:var(--accent);font-weight:700}
1112
- .cover h1{font-weight:900}
1206
+ .slide--closing .subtitle{color:var(--accent-text);font-weight:600}
1113
1207
  .quote-mark{
1114
- font-family:var(--font-heading);font-size:clamp(90px,13vw,210px);line-height:.62;
1115
- color:var(--accent);margin-bottom:clamp(14px,2vw,30px);
1208
+ font-family:var(--font-heading);font-size:clamp(68px,9vw,132px);line-height:.62;
1209
+ color:var(--accent);margin-bottom:clamp(10px,1.4vw,20px);
1116
1210
  }
1117
1211
  .quote-text{
1118
- font-family:var(--font-heading);font-size:clamp(26px,4.2vw,62px);line-height:1.28;
1119
- font-weight:700;max-width:22ch;margin:0;
1212
+ font-family:var(--font-heading);font-size:clamp(24px,3.4vw,48px);line-height:1.34;
1213
+ font-weight:700;max-width:26ch;margin:0;
1120
1214
  }
1121
- .quote-attr{color:var(--muted);margin-top:clamp(18px,2.6vw,34px);font-size:clamp(15px,1.8vw,26px);letter-spacing:.04em}
1215
+ .quote-attr{color:var(--muted);margin-top:clamp(14px,2vw,24px);font-size:clamp(14px,1.5vw,22px);letter-spacing:.03em}
1122
1216
  table.deck-table{
1123
- border-collapse:collapse;margin-top:clamp(20px,3vw,42px);width:100%;max-width:100%;
1124
- font-size:clamp(14px,1.55vw,23px);
1217
+ border-collapse:collapse;margin-top:clamp(12px,1.8vw,24px);width:100%;max-width:100%;
1218
+ font-size:clamp(14px,1.4vw,20px);
1125
1219
  }
1126
1220
  .deck-table th{
1127
- background:color-mix(in srgb, var(--accent) 26%, var(--bg));color:var(--fg);
1128
- text-align:left;font-weight:700;padding:.6em .9em;letter-spacing:.02em;
1129
- border-bottom:2px solid var(--accent);
1221
+ background:var(--surface2);color:var(--fg);
1222
+ text-align:left;font-weight:700;padding:.62em .9em;letter-spacing:.02em;
1223
+ border-top:1.5px solid var(--accent);border-bottom:1.5px solid var(--accent);
1130
1224
  }
1131
1225
  .deck-table td{
1132
- padding:.55em .9em;border-bottom:1px solid color-mix(in srgb, var(--muted) 55%, transparent);
1226
+ padding:.56em .9em;border-bottom:1px solid var(--hairline);
1133
1227
  color:var(--fg);
1134
1228
  }
1135
1229
  .deck-table .num{text-align:right;font-variant-numeric:tabular-nums}
1136
- .deck-table tbody tr:nth-child(even){background:color-mix(in srgb, var(--panel) 62%, transparent)}
1230
+ .deck-table tbody tr:nth-child(even){background:var(--surface1)}
1137
1231
  #progress{position:fixed;top:0;left:0;height:3px;width:0;background:var(--accent);z-index:30;transition:width .25s}
1138
1232
  #hud{
1139
1233
  position:fixed;left:22px;right:22px;bottom:18px;z-index:50;display:flex;flex-wrap:wrap;justify-content:flex-end;gap:10px;align-items:center;
@@ -1159,7 +1253,7 @@ body.notes-open #notes-panel{display:block}
1159
1253
  }
1160
1254
  #notes-close:hover{color:var(--accent);border-color:var(--accent)}
1161
1255
  #notes-panel .notes-label{
1162
- color:var(--accent);font-weight:700;letter-spacing:.14em;text-transform:uppercase;
1256
+ color:var(--accent-text);font-weight:700;letter-spacing:.14em;text-transform:uppercase;
1163
1257
  font-size:12px;margin-bottom:8px;
1164
1258
  }
1165
1259
  #notes-text{white-space:pre-wrap;line-height:1.65;font-size:clamp(15px,1.5vw,18px);color:var(--fg)}
@@ -1168,7 +1262,7 @@ body.notes-open #notes-panel{display:block}
1168
1262
  position:fixed;right:22px;bottom:64px;z-index:60;max-width:390px;
1169
1263
  background:color-mix(in srgb, var(--panel) 96%, black 4%);color:var(--fg);
1170
1264
  border:1px solid color-mix(in srgb, var(--accent) 55%, transparent);border-radius:14px;
1171
- padding:16px 20px;box-shadow:0 18px 50px rgba(0,0,0,.45);font-size:14px;line-height:1.8;
1265
+ padding:16px 20px;box-shadow:0 18px 50px rgba(0,0,0,.28);font-size:14px;line-height:1.8;
1172
1266
  }
1173
1267
  #help-panel[hidden]{display:none}
1174
1268
  #help-panel kbd{
@@ -1671,328 +1765,84 @@ ${dataView.script}
1671
1765
  </body>
1672
1766
  </html>`
1673
1767
  }
1768
+
1674
1769
  function renderHtmlSlide(slide, index, ui, langId, manifest = {}, theme) {
1675
- const kicker = slide.kicker || (slide.layout === 'cover' ? ui.coverKicker : '')
1676
- const title = slide.title || ''
1677
- const subtitle = slide.subtitle || ''
1678
- const bullets = Array.isArray(slide.bullets) ? slide.bullets : []
1770
+ const layout = slide.layout || 'bullets'
1771
+ const total = manifest.slides?.length ?? 1
1679
1772
  const number = String(index + 1).padStart(2, '0')
1680
- let inner = ''
1681
- switch (slide.layout) {
1682
- case 'image':
1683
- case 'image-left':
1684
- case 'image-right':
1685
- case 'chart':
1686
- inner = renderMediaHtml(slide, manifest, theme)
1687
- break
1688
- case 'cover':
1689
- inner = '<div class="kicker">' + escapeHtml(kicker) + '</div>' +
1690
- '<h1>' + escapeHtml(title) + '</h1>' +
1691
- (subtitle !== '' ? '<div class="subtitle">' + escapeHtml(subtitle) + '</div>' : '') +
1692
- '<div class="meta">' + escapeHtml(ui.generatedBy) + '</div>'
1693
- break
1694
- case 'section':
1695
- inner = '<div class="kicker">' + escapeHtml(kicker) + '</div>' +
1696
- '<h2>' + escapeHtml(title) + '</h2>' +
1697
- '<div class="accent-line"></div>' +
1698
- (subtitle !== '' ? '<div class="subtitle">' + escapeHtml(subtitle) + '</div>' : '')
1699
- break
1700
- case 'statement':
1701
- inner = '<div class="kicker">' + escapeHtml(kicker) + '</div>' +
1702
- '<div class="statement-title">' + escapeHtml(title || slide.text || '') + '</div>' +
1703
- (subtitle !== '' ? '<div class="subtitle">' + escapeHtml(subtitle) + '</div>' : '')
1704
- break
1705
- case 'quote':
1706
- inner = '<div class="kicker">' + escapeHtml(kicker || ui.quoteKicker) + '</div>' +
1707
- '<div class="quote-mark" aria-hidden="true">\u201C</div>' +
1708
- '<blockquote class="quote-text">' + escapeHtml(title || slide.text || '') + '</blockquote>' +
1709
- (subtitle !== '' ? '<div class="quote-attr">\u2014\u2014 ' + escapeHtml(subtitle) + '</div>' : '')
1710
- break
1711
- case 'table': {
1712
- const rows = Array.isArray(slide.rows) ? slide.rows : []
1713
- const head = rows[0] ?? []
1714
- const body = rows.slice(1)
1715
- const isNum = (cell) => /^\s*[+-]?(?:\d{1,3}(?:,\d{3})+|\d+)(?:\.\d+)?\s*(?:%|%|次|页|个|人|元|天|小时|分钟)?\s*$/.test(String(cell ?? ''))
1716
- const headingText = title !== '' ? title : (kicker || ui.tableKicker)
1717
- const showKicker = kicker !== '' && kicker !== headingText
1718
- inner = (showKicker ? '<div class="kicker">' + escapeHtml(kicker) + '</div>' : '') +
1719
- '<h2>' + escapeHtml(headingText) + '</h2>' +
1720
- '<table class="deck-table"><thead><tr>' +
1721
- head.map((cell) => '<th' + (isNum(cell) ? ' class="num"' : '') + '>' + escapeHtml(cell) + '</th>').join('') +
1722
- '</tr></thead><tbody>' +
1723
- body.map((row) => '<tr>' + row.map((cell) => '<td' + (isNum(cell) ? ' class="num"' : '') + '>' + escapeHtml(cell) + '</td>').join('') + '</tr>').join('') +
1724
- '</tbody></table>'
1725
- break
1726
- }
1727
- case 'closing':
1728
- inner = '<h1>' + escapeHtml(title || ui.closingTitle) + '</h1>' +
1729
- (subtitle !== '' ? '<div class="subtitle">' + escapeHtml(subtitle) + '</div>' : '') +
1730
- '<div class="meta">' + escapeHtml(ui.generatedBy) + '</div>'
1731
- break
1732
- case 'bullets':
1733
- default:
1734
- inner = '<div class="kicker">' + escapeHtml(kicker) + '</div>' +
1735
- '<h2>' + escapeHtml(title) + '</h2>' +
1736
- '<ul>' + bullets.map((bullet, bulletIndex) => '<li style="--i:' + bulletIndex + '">' + escapeHtml(bullet) + '</li>').join('') + '</ul>'
1737
- break
1738
- }
1773
+ const chromeStyle = resolveChromeStyle(theme, slide, manifest.brand)
1774
+ const inner = deckMedia.MEDIA_LAYOUTS.has(layout)
1775
+ ? deckMedia.renderMediaHtml(slide, manifest, theme)
1776
+ : renderCoreSlideHtml(slide, index, total, ui, langId, manifest, theme)
1777
+
1739
1778
  const notesAttr = typeof slide.notes === 'string' && slide.notes.trim() !== ''
1740
1779
  ? ' data-notes="' + escapeHtml(slide.notes) + '"'
1741
1780
  : ''
1781
+ const densityAttr = slide.visual?.density
1782
+ ? ' data-density="' + escapeHtml(slide.visual.density) + '"'
1783
+ : ''
1784
+ const tableStyleAttr = (layout === 'table' || layout === 'harvey')
1785
+ ? ' data-table-style="' + escapeHtml(slide.tableStyle || slide.visual?.tableStyle || theme.defaultTableStyle || 'consulting') + '"'
1786
+ : ''
1787
+ const chromeAttr = ' data-chrome="' + escapeHtml(chromeStyle) + '"'
1742
1788
  const visualStyle = visualHtmlStyle(slide.visual)
1743
- return '<section class="slide slide--' + escapeHtml(slide.layout || 'bullets') + '" data-index="' + number + '"' + notesAttr + (visualStyle ? ' style="' + escapeHtml(visualStyle) + '"' : '') + '>' +
1789
+ const slideClasses = 'slide slide--' + escapeHtml(layout) + (layout === 'bullets' ? ' bullets' : '')
1790
+
1791
+ return '<section class="' + slideClasses + '" data-index="' + number + '"' + chromeAttr + notesAttr + densityAttr + tableStyleAttr + (visualStyle ? ' style="' + escapeHtml(visualStyle) + '"' : '') + '>' +
1744
1792
  '<div class="slide-inner">' + inner + '</div>' +
1745
1793
  (manifest.brand?.logoAssetId ? '<img class="brand-logo" src="' + escapeHtml(manifest.assets?.[manifest.brand.logoAssetId]?.data ?? '') + '" alt="' + escapeHtml(manifest.brand.name || 'Logo') + '"/>' : '') +
1746
1794
  (manifest.brand?.footer ? '<div class="brand-footer">' + escapeHtml(manifest.brand.footer) + '</div>' : '') + '</section>'
1747
1795
  }
1748
1796
 
1749
- function hexToRgba(hex, alpha) {
1750
- const value = String(hex).replace('#', '')
1751
- const full = value.length === 3 ? value.split('').map((c) => c + c).join('') : value
1752
- const num = Number.parseInt(full, 16)
1753
- const r = (num >> 16) & 255
1754
- const g = (num >> 8) & 255
1755
- const b = num & 255
1756
- return 'rgba(' + r + ',' + g + ',' + b + ',' + alpha + ')'
1757
- }
1758
-
1759
1797
  // ---------------------------------------------------------------------------
1760
- // PPTX(OOXML 手写 + node:zlib zip)
1798
+ // PPTX(OOXML 组件装配 + node:zlib zip)
1761
1799
  // ---------------------------------------------------------------------------
1762
1800
 
1763
- const EMU_W = 12192000
1764
- const EMU_H = 6858000
1765
-
1766
1801
  function hex(value) {
1767
1802
  return String(value).replace('#', '').toUpperCase()
1768
1803
  }
1769
1804
 
1770
- export function pptxFontName(value) {
1771
- const names = String(value ?? '').split(',').map(name => name.trim().replace(/^["']|["']$/g, '')).filter(Boolean)
1772
- // A CSS stack may start with an optional web font. Office receives one actual
1773
- // family, so select a platform fallback instead of copying the first name.
1774
- if (names.length === 1 && !['serif', 'sans-serif', 'system-ui'].includes(names[0])) return names[0]
1775
- const available = process.platform === 'win32'
1776
- ? ['Segoe UI', 'Arial', 'Arial Black', 'Impact', 'Georgia', 'Times New Roman', 'Microsoft YaHei', 'SimSun']
1777
- : process.platform === 'darwin'
1778
- ? ['Helvetica Neue', 'Arial', 'Impact', 'Georgia', 'Times New Roman', 'Avenir Next', 'PingFang SC', 'Songti SC']
1779
- : ['Liberation Sans', 'Liberation Serif', 'Noto Sans', 'Noto Sans CJK SC', 'Noto Serif CJK SC']
1780
- return names.find(name => available.includes(name)) || (names.includes('serif')
1781
- ? process.platform === 'linux' ? 'Liberation Serif' : 'Georgia'
1782
- : process.platform === 'win32' ? 'Segoe UI' : process.platform === 'darwin' ? 'Helvetica Neue' : 'Liberation Sans')
1783
- }
1784
-
1785
- export function pptxEastAsianFont(value) {
1786
- const font = pptxFontName(value)
1787
- if (/Microsoft YaHei|SimSun|SimHei|PingFang|Songti|Heiti|Noto (Sans|Serif) CJK|[\u3400-\u9fff]/i.test(font)) return font
1788
- const serif = /Georgia|Times New Roman|Cambria|Liberation Serif/i.test(font)
1789
- return process.platform === 'win32' ? serif ? 'SimSun' : 'Microsoft YaHei'
1790
- : process.platform === 'darwin' ? serif ? 'Songti SC' : 'PingFang SC'
1791
- : serif ? 'Noto Serif CJK SC' : 'Noto Sans CJK SC'
1792
- }
1793
-
1794
- function paragraphXml(text, options = {}) {
1795
- const {
1796
- size = 2000,
1797
- color = 'FFFFFF',
1798
- bold = false,
1799
- lang = 'zh-CN',
1800
- align = 'l',
1801
- bullet = false,
1802
- font = 'Arial',
1803
- spaceBefore = 0,
1804
- spaceAfter = 0,
1805
- } = options
1806
- const runFont = pptxFontName(font)
1807
- const spacing = (spaceBefore > 0 ? '<a:spcBef><a:spcPts val="' + spaceBefore + '"/></a:spcBef>' : '') +
1808
- (spaceAfter > 0 ? '<a:spcAft><a:spcPts val="' + spaceAfter + '"/></a:spcAft>' : '')
1809
- const pPr = '<a:pPr' + (bullet ? ' marL="285750" indent="-285750"' : align !== 'l' ? ' algn="' + align + '"' : '') + '>' + spacing +
1810
- (bullet ? '<a:buFont typeface="Arial" panose="020B0604020202020204"/><a:buChar char="•"/>' : '<a:buNone/>') + '</a:pPr>'
1811
- return '<a:p>' + pPr +
1812
- '<a:r><a:rPr lang="' + lang + '" sz="' + size + '" b="' + (bold ? 1 : 0) + '" dirty="0">' +
1813
- '<a:solidFill><a:srgbClr val="' + hex(color) + '"/></a:solidFill>' +
1814
- '<a:latin typeface="' + escapeXml(runFont) + '"/><a:ea typeface="' + escapeXml(pptxEastAsianFont(font)) + '"/></a:rPr>' +
1815
- '<a:t>' + escapeXml(text) + '</a:t></a:r></a:p>'
1816
- }
1817
-
1818
- function textShapeXml(id, name, box, paragraphs, options = {}) {
1819
- const { x = 0, y = 0, w = EMU_W, h = EMU_H } = box
1820
- return '<p:sp>' +
1821
- '<p:nvSpPr><p:cNvPr id="' + id + '" name="' + escapeXml(name) + '"/><p:cNvSpPr txBox="1"/><p:nvPr/></p:nvSpPr>' +
1822
- '<p:spPr><a:xfrm><a:off x="' + x + '" y="' + y + '"/><a:ext cx="' + w + '" cy="' + h + '"/></a:xfrm>' +
1823
- '<a:prstGeom prst="rect"><a:avLst/></a:prstGeom><a:noFill/><a:ln/></p:spPr>' +
1824
- '<p:txBody><a:bodyPr wrap="square" rtlCol="0"><a:normAutofit/></a:bodyPr><a:lstStyle/>' +
1825
- paragraphs.join('') + '</p:txBody></p:sp>'
1826
- }
1827
-
1828
- function accentBarXml(id, name, box, color) {
1829
- const { x = 0, y = 0, w = EMU_W, h = EMU_H } = box
1830
- return '<p:sp>' +
1831
- '<p:nvSpPr><p:cNvPr id="' + id + '" name="' + escapeXml(name) + '"/><p:cNvSpPr/><p:nvPr/></p:nvSpPr>' +
1832
- '<p:spPr><a:xfrm><a:off x="' + x + '" y="' + y + '"/><a:ext cx="' + w + '" cy="' + h + '"/></a:xfrm>' +
1833
- '<a:prstGeom prst="rect"><a:avLst/></a:prstGeom>' +
1834
- '<a:solidFill><a:srgbClr val="' + hex(color) + '"/></a:solidFill><a:ln/></p:spPr>' +
1835
- '<p:txBody><a:bodyPr/><a:lstStyle/><a:p/></p:txBody></p:sp>'
1836
- }
1837
-
1838
- /** 原生 OOXML 表格(graphicFrame + a:tbl):首行主题色表头,隔行面板色。 */
1839
- function tableGraphicXml(id, name, box, rows, theme, langId) {
1840
- const p = theme.palette
1841
- const lang = langId || 'zh-CN'
1842
- const font = pptxFontName(theme.fonts.body)
1843
- const safeRows = rows.length > 0 ? rows : [['']]
1844
- const cols = Math.max(1, safeRows[0].length)
1845
- const fontSize = cols <= 6 ? 1700 : 1400
1846
- const colW = Math.floor(box.w / cols)
1847
- const grid = Array.from({ length: cols }, () => '<a:gridCol w="' + colW + '"/>').join('')
1848
- const rowH = 420000
1849
- const cellXml = (text, fill, color, bold) =>
1850
- '<a:tc><a:txBody><a:bodyPr anchor="ctr"/><a:lstStyle/><a:p><a:pPr algn="l"><a:buNone/></a:pPr>' +
1851
- '<a:r><a:rPr lang="' + lang + '" sz="' + fontSize + '" b="' + (bold ? 1 : 0) + '" dirty="0">' +
1852
- '<a:solidFill><a:srgbClr val="' + hex(color) + '"/></a:solidFill>' +
1853
- '<a:latin typeface="' + escapeXml(font) + '"/><a:ea typeface="' + escapeXml(pptxEastAsianFont(theme.fonts.body)) + '"/></a:rPr>' +
1854
- '<a:t>' + escapeXml(text) + '</a:t></a:r></a:p></a:txBody>' +
1855
- '<a:tcPr marL="91440" marR="91440" anchor="ctr">' +
1856
- (fill !== '' ? '<a:solidFill><a:srgbClr val="' + hex(fill) + '"/></a:solidFill>' : '<a:noFill/>') +
1857
- '</a:tcPr></a:tc>'
1858
- const trs = safeRows.map((row, rowIndex) => {
1859
- const padded = Array.from({ length: cols }, (_, i) => row[i] ?? '')
1860
- const cells = rowIndex === 0
1861
- ? padded.map((c) => cellXml(c, p.accent, p.bg, true)).join('')
1862
- : padded.map((c) => cellXml(c, rowIndex % 2 === 1 ? p.panel : '', p.fg, false)).join('')
1863
- return '<a:tr h="' + rowH + '">' + cells + '</a:tr>'
1864
- }).join('')
1865
- const height = Math.max(1, safeRows.length) * rowH
1866
- return '<p:graphicFrame>' +
1867
- '<p:nvGraphicFramePr><p:cNvPr id="' + id + '" name="' + escapeXml(name) + '"/>' +
1868
- '<p:cNvGraphicFramePr><a:graphicFrameLocks noGrp="1"/></p:cNvGraphicFramePr><p:nvPr/></p:nvGraphicFramePr>' +
1869
- '<p:xfrm><a:off x="' + box.x + '" y="' + box.y + '"/><a:ext cx="' + box.w + '" cy="' + height + '"/></p:xfrm>' +
1870
- '<a:graphic><a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/table">' +
1871
- '<a:tbl><a:tblPr firstRow="1" bandRow="1"/>' +
1872
- '<a:tblGrid>' + grid + '</a:tblGrid>' + trs + '</a:tbl>' +
1873
- '</a:graphicData></a:graphic></p:graphicFrame>'
1874
- }
1875
-
1876
- function slideShapeList(slide, index, total, theme, langId) {
1877
- const p = theme.palette
1878
- const font = pptxFontName(theme.fonts.heading)
1879
- const bodyFont = pptxFontName(theme.fonts.body) // 保留:v0.1 后续用于统一正文字体
1805
+ function slideShapeList(slide, index, total, theme, langId, manifest = {}) {
1880
1806
  const lang = langId || 'zh-CN'
1881
- // PPTX 每个文本 run 的语言跟随 deck.lang(zh-CN / en-US),不再写死中文
1882
- const para = (content, options = {}) => paragraphXml(content, { lang, ...options })
1883
- const shapes = []
1884
- const kicker = slide.kicker || ''
1885
- const title = slide.title || ''
1886
- const subtitle = slide.subtitle || ''
1887
- const bullets = Array.isArray(slide.bullets) ? slide.bullets : []
1888
1807
  const idBase = (index + 1) * 10
1889
- const footer = String(index + 1).padStart(2, '0') + ' / ' + String(total).padStart(2, '0')
1890
-
1891
- if (MEDIA_LAYOUTS.has(slide.layout)) {
1892
- const boxes = mediaBoxes(slide.layout)
1893
- const emu = box => Object.fromEntries(Object.entries(box).map(([key, value]) => [key, Math.round(value * 914400)]))
1894
- shapes.push(textShapeXml(idBase + 2, 'Title', emu(boxes.title), [para(title, { size: 3400, color: p.fg, bold: true, font })]))
1895
- if (boxes.body) shapes.push(textShapeXml(idBase + 3, 'Body', emu(boxes.body), [
1896
- ...(subtitle ? [para(subtitle, { size: 2000, color: p.fg, font: bodyFont })] : []),
1897
- ...bullets.map(bullet => para(bullet, { size: 2000, color: p.fg, bullet: true, font: bodyFont, spaceAfter: 600 })),
1898
- ]))
1899
- const caption = slide.chart?.caption || slide.image?.caption
1900
- if (caption) shapes.push(textShapeXml(idBase + 4, 'Caption', emu(boxes.caption), [para(caption, { size: 1400, color: p.muted, font: bodyFont })]))
1901
- } else if (slide.layout === 'cover') {
1902
- shapes.push(accentBarXml(idBase + 1, 'Accent bar', { x: 914400, y: 2250000, w: 240000, h: 1600000 }, p.accent))
1903
- shapes.push(textShapeXml(idBase + 2, 'Title', { x: 1550000, y: 2160000, w: 9250000, h: 1800000 }, [
1904
- para(title, { size: 4400, color: p.fg, bold: true, font }),
1905
- ]))
1906
- if (subtitle !== '') {
1907
- shapes.push(textShapeXml(idBase + 3, 'Subtitle', { x: 1570000, y: 4150000, w: 9000000, h: 1200000 }, [
1908
- para(subtitle, { size: 2200, color: p.muted, font: theme.fonts.body }),
1909
- ]))
1910
- }
1911
- if (kicker !== '') {
1912
- shapes.push(textShapeXml(idBase + 4, 'Kicker', { x: 1570000, y: 5800000, w: 7000000, h: 500000 }, [
1913
- para(kicker, { size: 1400, color: p.accent, bold: true, font: theme.fonts.body }),
1914
- ]))
1915
- }
1916
- } else if (slide.layout === 'section') {
1917
- if (kicker !== '') {
1918
- shapes.push(textShapeXml(idBase + 1, 'Kicker', { x: 1050000, y: 2250000, w: 9000000, h: 500000 }, [
1919
- para(kicker, { size: 1600, color: p.accent, bold: true, font: theme.fonts.body }),
1920
- ]))
1921
- }
1922
- shapes.push(accentBarXml(idBase + 2, 'Accent bar', { x: 1050000, y: 2850000, w: 1600000, h: 160000 }, p.accent2))
1923
- shapes.push(textShapeXml(idBase + 3, 'Title', { x: 1050000, y: 3150000, w: 10200000, h: 1400000 }, [
1924
- para(title, { size: 4000, color: p.fg, bold: true, font }),
1925
- ]))
1926
- if (subtitle !== '') {
1927
- shapes.push(textShapeXml(idBase + 4, 'Subtitle', { x: 1070000, y: 4750000, w: 9000000, h: 900000 }, [
1928
- para(subtitle, { size: 1800, color: p.muted, font: theme.fonts.body }),
1929
- ]))
1930
- }
1931
- } else if (slide.layout === 'statement') {
1932
- shapes.push(accentBarXml(idBase + 1, 'Accent bar', { x: 914400, y: 1900000, w: 200000, h: 2800000 }, p.accent))
1933
- shapes.push(textShapeXml(idBase + 2, 'Statement', { x: 1500000, y: 1950000, w: 9400000, h: 2700000 }, [
1934
- para(title || slide.text || '', { size: 3600, color: p.fg, bold: true, font }),
1935
- ]))
1936
- if (subtitle !== '') {
1937
- shapes.push(textShapeXml(idBase + 3, 'Subtitle', { x: 1520000, y: 4900000, w: 9000000, h: 800000 }, [
1938
- para(subtitle, { size: 1800, color: p.muted, font: theme.fonts.body }),
1939
- ]))
1940
- }
1941
- } else if (slide.layout === 'quote') {
1942
- shapes.push(textShapeXml(idBase + 1, 'Quote mark', { x: 900000, y: 1050000, w: 1700000, h: 1900000 }, [
1943
- para('\u201C', { size: 9600, color: p.accent, bold: true, font }),
1944
- ]))
1945
- shapes.push(textShapeXml(idBase + 2, 'Quote', { x: 1050000, y: 2550000, w: 10100000, h: 2600000 }, [
1946
- para(title || slide.text || '', { size: 3000, color: p.fg, bold: true, font }),
1947
- ]))
1948
- if (subtitle !== '') {
1949
- shapes.push(textShapeXml(idBase + 3, 'Attribution', { x: 1070000, y: 5300000, w: 9000000, h: 600000 }, [
1950
- para('\u2014\u2014 ' + subtitle, { size: 1600, color: p.muted, font: theme.fonts.body }),
1951
- ]))
1808
+ let xml = ''
1809
+
1810
+ if (deckMedia.MEDIA_LAYOUTS.has(slide.layout)) {
1811
+ const fontHelpers = {
1812
+ latinHeading: pptxFontName(theme.fonts.heading),
1813
+ eaHeading: pptxEastAsianFont(theme.fonts.heading),
1814
+ latinBody: pptxFontName(theme.fonts.body),
1815
+ eaBody: pptxEastAsianFont(theme.fonts.body),
1952
1816
  }
1953
- } else if (slide.layout === 'table') {
1954
- const hasTitle = title !== ''
1955
- if (kicker !== '' && kicker !== title) {
1956
- shapes.push(textShapeXml(idBase + 1, 'Kicker', { x: 900000, y: 420000, w: 10000000, h: 420000 }, [
1957
- para(kicker, { size: 1400, color: p.accent, bold: true, font: theme.fonts.body }),
1958
- ]))
1959
- }
1960
- if (hasTitle) {
1961
- shapes.push(textShapeXml(idBase + 2, 'Title', { x: 900000, y: 920000, w: 10300000, h: 800000 }, [
1962
- para(title, { size: 3400, color: p.fg, bold: true, font }),
1963
- ]))
1964
- }
1965
- shapes.push(tableGraphicXml(idBase + 3, 'Table', { x: 900000, y: hasTitle ? 1950000 : 900000, w: 10300000 }, Array.isArray(slide.rows) ? slide.rows : [], theme, lang))
1966
- } else if (slide.layout === 'closing') {
1967
- shapes.push(textShapeXml(idBase + 1, 'Title', { x: 1050000, y: 2300000, w: 10200000, h: 1700000 }, [
1968
- para(title || '谢谢', { size: 5200, color: p.fg, bold: true, align: 'ctr', font }),
1969
- ]))
1970
- if (subtitle !== '') {
1971
- shapes.push(textShapeXml(idBase + 2, 'Subtitle', { x: 1050000, y: 4200000, w: 10200000, h: 900000 }, [
1972
- para(subtitle, { size: 2000, color: p.accent, bold: true, align: 'ctr', font: theme.fonts.body }),
1973
- ]))
1817
+ const mediaShapes = typeof deckMedia.renderMediaPptxShapes === 'function'
1818
+ ? deckMedia.renderMediaPptxShapes(slide, index, theme, lang, fontHelpers, total, manifest)
1819
+ : ''
1820
+ if (mediaShapes.includes('name="Page number"')) {
1821
+ xml = mediaShapes
1822
+ } else {
1823
+ const folio = String(index + 1).padStart(2, '0') + ' / ' + String(total).padStart(2, '0')
1824
+ const folioShape = ooxmlShape(idBase + 9, 'Page number', { x: 10.65, y: 6.95, w: 2.06, h: 0.32 }, {
1825
+ txBox: true,
1826
+ anchor: 'ctr',
1827
+ marginsIn: { l: 0, r: 0, t: 0, b: 0 },
1828
+ paragraphs: [
1829
+ ooxmlRichParagraph(folio, {
1830
+ sizePt: 9.5,
1831
+ color: theme.tokens.inkMuted,
1832
+ lang,
1833
+ align: 'r',
1834
+ font: theme.fonts.body,
1835
+ lineHeight: 1.15,
1836
+ }),
1837
+ ],
1838
+ })
1839
+ xml = mediaShapes + folioShape
1974
1840
  }
1975
1841
  } else {
1976
- // bullets(默认布局)
1977
- if (kicker !== '') {
1978
- shapes.push(textShapeXml(idBase + 1, 'Kicker', { x: 900000, y: 420000, w: 10000000, h: 420000 }, [
1979
- para(kicker, { size: 1400, color: p.accent, bold: true, font: theme.fonts.body }),
1980
- ]))
1981
- }
1982
- shapes.push(textShapeXml(idBase + 2, 'Title', { x: 900000, y: 920000, w: 10300000, h: 800000 }, [
1983
- para(title, { size: 3400, color: p.fg, bold: true, font }),
1984
- ]))
1985
- const bodyParagraphs = bullets.length > 0
1986
- ? bullets.map((bullet) => para(bullet, { size: 2000, color: p.fg, bullet: true, font: theme.fonts.body, spaceAfter: 600 }))
1987
- : [para(subtitle || '', { size: 2000, color: p.fg, font: theme.fonts.body })]
1988
- shapes.push(textShapeXml(idBase + 3, 'Body', { x: 1050000, y: 1850000, w: 10100000, h: 4500000 }, bodyParagraphs))
1842
+ xml = renderCoreSlidePptx(slide, index, total, theme, lang, manifest)
1989
1843
  }
1990
1844
 
1991
- shapes.push(textShapeXml(idBase + 9, 'Page number', { x: 10600000, y: 6250000, w: 1200000, h: 400000 }, [
1992
- para(footer, { size: 1000, color: p.muted, align: 'r', font: theme.fonts.body }),
1993
- ]))
1994
-
1995
- return visualShapeXml(shapes.join(''), slide.visual)
1845
+ return visualShapeXml(xml, slide.visual)
1996
1846
  }
1997
1847
 
1998
1848
  /**
@@ -2027,7 +1877,7 @@ function bulletTimingXml(spid, clicks) {
2027
1877
  '<p:bldLst><p:bldP spid="' + spid + '" grpId="0"/></p:bldLst></p:timing>'
2028
1878
  }
2029
1879
 
2030
- function slideXml(slide, index, total, theme, langId, motion) {
1880
+ function slideXml(slide, index, total, theme, langId, motion, manifest = {}) {
2031
1881
  const p = theme.palette
2032
1882
  let motionXml = ''
2033
1883
  if (motion) {
@@ -2044,7 +1894,7 @@ function slideXml(slide, index, total, theme, langId, motion) {
2044
1894
  '<p:cSld><p:bg><p:bgPr><a:solidFill><a:srgbClr val="' + hex(p.bg) + '"/></a:solidFill><a:effectLst/></p:bgPr></p:bg>' +
2045
1895
  '<p:spTree><p:nvGrpSpPr><p:cNvPr id="1" name=""/><p:cNvGrpSpPr/><p:nvPr/></p:nvGrpSpPr>' +
2046
1896
  '<p:grpSpPr><a:xfrm><a:off x="0" y="0"/><a:ext cx="0" cy="0"/><a:chOff x="0" y="0"/><a:chExt cx="0" cy="0"/></a:xfrm></p:grpSpPr>' +
2047
- slideShapeList(slide, index, total, theme, langId) +
1897
+ slideShapeList(slide, index, total, theme, langId, manifest) +
2048
1898
  '</p:spTree></p:cSld>' +
2049
1899
  '<p:clrMapOvr><a:overrideClrMapping bg1="lt1" tx1="dk1" bg2="lt2" tx2="dk2" accent1="accent1" accent2="accent2" accent3="accent3" accent4="accent4" accent5="accent5" accent6="accent6" hlink="hlink" folHlink="folHlink"/></p:clrMapOvr>' +
2050
1900
  motionXml +
@@ -2146,7 +1996,7 @@ function slideMasterXml(theme) {
2146
1996
  const p = theme.palette
2147
1997
  const levels = Array.from({ length: 9 }, (_, i) => {
2148
1998
  const sz = Math.max(1100, 2000 - i * 100)
2149
- return '<a:lvl' + (i + 1) + 'pPr marL="' + (342900 + i * 342900) + '" indent="' + (-342900 - i * 0) + '">' +
1999
+ return '<a:lvl' + (i + 1) + 'pPr marL="' + (342900 + i * 342900) + '" indent="' + (-342900) + '">' +
2150
2000
  '<a:defRPr sz="' + sz + '"><a:solidFill><a:srgbClr val="' + hex(p.fg) + '"/></a:solidFill><a:latin typeface="' + escapeXml(pptxFontName(theme.fonts.body)) + '"/><a:ea typeface="' + escapeXml(pptxEastAsianFont(theme.fonts.body)) + '"/></a:defRPr></a:lvl' + (i + 1) + 'pPr>'
2151
2001
  }).join('')
2152
2002
  return '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' +
@@ -2170,7 +2020,7 @@ function slideMasterRelXml() {
2170
2020
  '</Relationships>'
2171
2021
  }
2172
2022
 
2173
- function slideLayoutXml(theme) {
2023
+ function slideLayoutXml() {
2174
2024
  return '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' +
2175
2025
  '<p:sldLayout xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" ' +
2176
2026
  'xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" ' +
@@ -2191,14 +2041,15 @@ function slideLayoutRelXml() {
2191
2041
 
2192
2042
  function themeXml(theme) {
2193
2043
  const p = theme.palette
2044
+ const series = theme.tokens?.chartSeries ?? [p.accent, p.accent2, p.fg, p.muted, p.accent, p.accent2]
2194
2045
  const color = (name, value) => '<a:' + name + '><a:srgbClr val="' + hex(value) + '"/></a:' + name + '>'
2195
2046
  return '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' +
2196
- '<a:theme xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" name="dsh-ppt ' + escapeXml(theme.name.en) + '">' +
2047
+ '<a:theme xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" name="dsh-ppt ' + escapeXml(theme.name?.en ?? theme.id ?? 'Theme') + '">' +
2197
2048
  '<a:themeElements>' +
2198
2049
  '<a:clrScheme name="dsh-ppt">' +
2199
2050
  color('dk1', p.fg) + color('lt1', p.bg) + color('dk2', p.muted) + color('lt2', p.panel) +
2200
- color('accent1', p.accent) + color('accent2', p.accent2) + color('accent3', p.fg) +
2201
- color('accent4', p.muted) + color('accent5', p.accent) + color('accent6', p.accent2) +
2051
+ color('accent1', series[0] ?? p.accent) + color('accent2', series[1] ?? p.accent2) + color('accent3', series[2] ?? p.fg) +
2052
+ color('accent4', series[3] ?? p.muted) + color('accent5', series[4] ?? p.accent) + color('accent6', series[5] ?? p.accent2) +
2202
2053
  color('hlink', p.accent) + color('folHlink', p.accent2) +
2203
2054
  '</a:clrScheme>' +
2204
2055
  '<a:fontScheme name="dsh-ppt">' +
@@ -2288,10 +2139,10 @@ function buildZip(entries) {
2288
2139
  const localHeader = Buffer.alloc(30)
2289
2140
  localHeader.writeUInt32LE(0x04034b50, 0)
2290
2141
  localHeader.writeUInt16LE(20, 4)
2291
- localHeader.writeUInt16LE(0x0800, 6) // UTF-8 文件名
2142
+ localHeader.writeUInt16LE(0x0800, 6)
2292
2143
  localHeader.writeUInt16LE(method, 8)
2293
- localHeader.writeUInt16LE(0, 10) // DOS time
2294
- localHeader.writeUInt16LE(0x21, 12) // DOS date 1980-01-01
2144
+ localHeader.writeUInt16LE(0, 10)
2145
+ localHeader.writeUInt16LE(0x21, 12)
2295
2146
  localHeader.writeUInt32LE(crc, 14)
2296
2147
  localHeader.writeUInt32LE(compressed.length, 18)
2297
2148
  localHeader.writeUInt32LE(data.length, 22)
@@ -2384,7 +2235,7 @@ export function buildPptx(manifest, themeInput, languageInput) {
2384
2235
  }
2385
2236
  slides.forEach((slide, index) => {
2386
2237
  const hasNotes = noteIndexes.includes(index)
2387
- entries.push({ name: 'ppt/slides/slide' + (index + 1) + '.xml', data: slideXml(slide, index, slides.length, theme, language.attr, motion) })
2238
+ entries.push({ name: 'ppt/slides/slide' + (index + 1) + '.xml', data: slideXml(slide, index, slides.length, theme, language.attr, motion, manifest) })
2388
2239
  entries.push({ name: 'ppt/slides/_rels/slide' + (index + 1) + '.xml.rels', data: slideRelXml(hasNotes, index + 1) })
2389
2240
  if (hasNotes) {
2390
2241
  entries.push({ name: 'ppt/notesSlides/notesSlide' + (index + 1) + '.xml', data: notesSlideXml(slide.notes, language.attr) })