dsh-ppt 0.4.3 → 0.4.4

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.
@@ -1,1739 +1,1771 @@
1
- #! /usr/bin/env node
2
- /**
3
- * deck-core.mjs —— dsh-ppt 的零依赖演示文稿引擎。
4
- *
5
- * 这是插件工具与裸 SKILL.md 共用的唯一事实源:
6
- * - DSH 内:ppt_create 工具动态加载本文件
7
- * - 其他 harness:直接运行同目录的 build-deck.mjs
8
- *
9
- * 能力:Markdown / 结构化 slides → 三件套
10
- * deck.html 独立网页放映(键盘/触屏/打印,无外链)
11
- * deck.pptx 可编辑 PPTX(16:9,OOXML 由本文件手写,zip 用 node:zlib)
12
- * deck.json 结构化 deck manifest
13
- *
14
- * 零运行时依赖,仅使用 node:fs / node:path / node:zlib。
15
- */
16
-
17
- import { existsSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs'
18
- import { resolve as resolvePath } from 'node:path'
19
- import { deflateRawSync } from 'node:zlib'
20
-
21
- /**
22
- * manifest 版本跟随发布包 package.json;把 skills/dsh-ppt 独立复制到其他
23
- * harness(没有 package.json)时回退为 0.0.0,避免版本号悄悄漂移。
24
- */
25
- function readDeckVersion() {
26
- try {
27
- const pkg = JSON.parse(readFileSync(new URL('../../../package.json', import.meta.url), 'utf8'))
28
- const version = String(pkg.version ?? '').trim()
29
- return version !== '' ? version : '0.0.0'
30
- } catch {
31
- return '0.0.0'
32
- }
33
- }
34
-
35
- export const DECK_VERSION = readDeckVersion()
36
-
37
- // ---------------------------------------------------------------------------
38
- // 主题
39
- // ---------------------------------------------------------------------------
40
-
41
- export const THEMES = {
42
- swiss: {
43
- id: 'swiss',
44
- name: { zh: '瑞士脉冲', en: 'Swiss Pulse' },
45
- mood: { zh: '精准、理性、数据', en: 'Precise, rational, data-driven' },
46
- bestFor: { zh: 'SaaS、数据、开发者工具', en: 'SaaS, data, developer tools' },
47
- dark: true,
48
- palette: {
49
- bg: '#10151B',
50
- panel: '#161D26',
51
- fg: '#F5F7FA',
52
- muted: '#8E9AAA',
53
- accent: '#2F6BFF',
54
- accent2: '#FFB300',
55
- },
56
- fonts: {
57
- heading: '"Helvetica Neue", Inter, "PingFang SC", "Microsoft YaHei", sans-serif',
58
- body: '"Helvetica Neue", Inter, "PingFang SC", "Microsoft YaHei", sans-serif',
59
- },
60
- },
61
- velvet: {
62
- id: 'velvet',
63
- name: { zh: '天鹅绒标准', en: 'Velvet Standard' },
64
- mood: { zh: '高级、克制、可信', en: 'Premium, restrained, trustworthy' },
65
- bestFor: { zh: '高管汇报、品牌、融资路演', en: 'Executive decks, brand, investor pitches' },
66
- dark: true,
67
- palette: {
68
- bg: '#111316',
69
- panel: '#1A1D22',
70
- fg: '#F4EFE6',
71
- muted: '#A79F91',
72
- accent: '#C9A84C',
73
- accent2: '#3D4A63',
74
- },
75
- fonts: {
76
- heading: 'Georgia, "Times New Roman", "Songti SC", "SimSun", serif',
77
- body: '"Helvetica Neue", Inter, "PingFang SC", "Microsoft YaHei", sans-serif',
78
- },
79
- },
80
- data: {
81
- id: 'data',
82
- name: { zh: '数据漂移', en: 'Data Drift' },
83
- mood: { zh: '未来、沉浸、前沿', en: 'Futuristic, immersive, cutting-edge' },
84
- bestFor: { zh: 'AI、数据、研究、技术发布', en: 'AI, data, research, tech launches' },
85
- dark: true,
86
- palette: {
87
- bg: '#070B14',
88
- panel: '#0D1424',
89
- fg: '#E8F1FF',
90
- muted: '#7E8BA8',
91
- accent: '#7C3AED',
92
- accent2: '#06B6D4',
93
- },
94
- fonts: {
95
- heading: '"Space Grotesk", "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif',
96
- body: '"Space Grotesk", "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif',
97
- },
98
- },
99
- soft: {
100
- id: 'soft',
101
- name: { zh: '柔和信号', en: 'Soft Signal' },
102
- mood: { zh: '温暖、亲近、人本', en: 'Warm, intimate, human' },
103
- bestFor: { zh: '品牌故事、培训、个人分享', en: 'Brand stories, training, personal talks' },
104
- dark: false,
105
- palette: {
106
- bg: '#FFF8EC',
107
- panel: '#FFF2DE',
108
- fg: '#3B2F2A',
109
- muted: '#7E6F68',
110
- accent: '#E58A2F',
111
- accent2: '#8FAF8C',
112
- },
113
- fonts: {
114
- heading: '"Avenir Next", "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif',
115
- body: '"Avenir Next", "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif',
116
- },
117
- },
118
- bold: {
119
- id: 'bold',
120
- name: { zh: '极繁大字', en: 'Maximalist Type' },
121
- mood: { zh: '大声、动能、发布', en: 'Loud, kinetic, launch' },
122
- bestFor: { zh: '产品发布、活动、品牌大事件', en: 'Product launches, events, brand moments' },
123
- dark: true,
124
- palette: {
125
- bg: '#0D0D0D',
126
- panel: '#181818',
127
- fg: '#FFFFFF',
128
- muted: '#B8B8B8',
129
- accent: '#E63946',
130
- accent2: '#FFD60A',
131
- },
132
- fonts: {
133
- heading: 'Impact, "Arial Black", "PingFang SC", "Microsoft YaHei", sans-serif',
134
- body: '"Helvetica Neue", Inter, "PingFang SC", "Microsoft YaHei", sans-serif',
135
- },
136
- },
137
- }
138
-
139
- export const THEME_IDS = Object.keys(THEMES)
140
- export const DEFAULT_THEME = 'data'
141
-
142
- export const LANGUAGES = {
143
- zh: {
144
- id: 'zh',
145
- attr: 'zh-CN',
146
- ui: {
147
- slide: '第',
148
- of: '/ 共',
149
- theme: '主题',
150
- help: '← → 翻页 · F 全屏 · G 总览 · S 备注 · P 打印',
151
- coverKicker: '开场',
152
- pointKicker: '要点',
153
- statementKicker: '核心观点',
154
- quoteKicker: '金句',
1
+ #! /usr/bin/env node
2
+ /**
3
+ * deck-core.mjs —— dsh-ppt 的零依赖演示文稿引擎。
4
+ *
5
+ * 这是插件工具与裸 SKILL.md 共用的唯一事实源:
6
+ * - DSH 内:ppt_create 工具动态加载本文件
7
+ * - 其他 harness:直接运行同目录的 build-deck.mjs
8
+ *
9
+ * 能力:Markdown / 结构化 slides → 三件套
10
+ * deck.html 独立网页放映(键盘/触屏/打印,无外链)
11
+ * deck.pptx 可编辑 PPTX(16:9,OOXML 由本文件手写,zip 用 node:zlib)
12
+ * deck.json 结构化 deck manifest
13
+ *
14
+ * 零运行时依赖,仅使用 node:fs / node:path / node:zlib。
15
+ */
16
+
17
+ import { existsSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs'
18
+ import { resolve as resolvePath } from 'node:path'
19
+ import { deflateRawSync } from 'node:zlib'
20
+
21
+ /**
22
+ * manifest 版本跟随发布包 package.json;把 skills/dsh-ppt 独立复制到其他
23
+ * harness(没有 package.json)时回退为 0.0.0,避免版本号悄悄漂移。
24
+ */
25
+ function readDeckVersion() {
26
+ try {
27
+ const pkg = JSON.parse(readFileSync(new URL('../../../package.json', import.meta.url), 'utf8'))
28
+ const version = String(pkg.version ?? '').trim()
29
+ return version !== '' ? version : '0.0.0'
30
+ } catch {
31
+ return '0.0.0'
32
+ }
33
+ }
34
+
35
+ export const DECK_VERSION = readDeckVersion()
36
+
37
+ // ---------------------------------------------------------------------------
38
+ // 主题
39
+ // ---------------------------------------------------------------------------
40
+
41
+ export const THEMES = {
42
+ swiss: {
43
+ id: 'swiss',
44
+ name: { zh: '瑞士脉冲', en: 'Swiss Pulse' },
45
+ mood: { zh: '精准、理性、数据', en: 'Precise, rational, data-driven' },
46
+ bestFor: { zh: 'SaaS、数据、开发者工具', en: 'SaaS, data, developer tools' },
47
+ dark: true,
48
+ palette: {
49
+ bg: '#10151B',
50
+ panel: '#161D26',
51
+ fg: '#F5F7FA',
52
+ muted: '#8E9AAA',
53
+ accent: '#2F6BFF',
54
+ accent2: '#FFB300',
55
+ },
56
+ fonts: {
57
+ heading: '"Helvetica Neue", Inter, "PingFang SC", "Microsoft YaHei", sans-serif',
58
+ body: '"Helvetica Neue", Inter, "PingFang SC", "Microsoft YaHei", sans-serif',
59
+ },
60
+ },
61
+ velvet: {
62
+ id: 'velvet',
63
+ name: { zh: '天鹅绒标准', en: 'Velvet Standard' },
64
+ mood: { zh: '高级、克制、可信', en: 'Premium, restrained, trustworthy' },
65
+ bestFor: { zh: '高管汇报、品牌、融资路演', en: 'Executive decks, brand, investor pitches' },
66
+ dark: true,
67
+ palette: {
68
+ bg: '#111316',
69
+ panel: '#1A1D22',
70
+ fg: '#F4EFE6',
71
+ muted: '#A79F91',
72
+ accent: '#C9A84C',
73
+ accent2: '#3D4A63',
74
+ },
75
+ fonts: {
76
+ heading: 'Georgia, "Times New Roman", "Songti SC", "SimSun", serif',
77
+ body: '"Helvetica Neue", Inter, "PingFang SC", "Microsoft YaHei", sans-serif',
78
+ },
79
+ },
80
+ data: {
81
+ id: 'data',
82
+ name: { zh: '数据漂移', en: 'Data Drift' },
83
+ mood: { zh: '未来、沉浸、前沿', en: 'Futuristic, immersive, cutting-edge' },
84
+ bestFor: { zh: 'AI、数据、研究、技术发布', en: 'AI, data, research, tech launches' },
85
+ dark: true,
86
+ palette: {
87
+ bg: '#070B14',
88
+ panel: '#0D1424',
89
+ fg: '#E8F1FF',
90
+ muted: '#7E8BA8',
91
+ accent: '#7C3AED',
92
+ accent2: '#06B6D4',
93
+ },
94
+ fonts: {
95
+ heading: '"Space Grotesk", "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif',
96
+ body: '"Space Grotesk", "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif',
97
+ },
98
+ },
99
+ soft: {
100
+ id: 'soft',
101
+ name: { zh: '柔和信号', en: 'Soft Signal' },
102
+ mood: { zh: '温暖、亲近、人本', en: 'Warm, intimate, human' },
103
+ bestFor: { zh: '品牌故事、培训、个人分享', en: 'Brand stories, training, personal talks' },
104
+ dark: false,
105
+ palette: {
106
+ bg: '#FFF8EC',
107
+ panel: '#FFF2DE',
108
+ fg: '#3B2F2A',
109
+ muted: '#7E6F68',
110
+ accent: '#E58A2F',
111
+ accent2: '#8FAF8C',
112
+ },
113
+ fonts: {
114
+ heading: '"Avenir Next", "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif',
115
+ body: '"Avenir Next", "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif',
116
+ },
117
+ },
118
+ bold: {
119
+ id: 'bold',
120
+ name: { zh: '极繁大字', en: 'Maximalist Type' },
121
+ mood: { zh: '大声、动能、发布', en: 'Loud, kinetic, launch' },
122
+ bestFor: { zh: '产品发布、活动、品牌大事件', en: 'Product launches, events, brand moments' },
123
+ dark: true,
124
+ palette: {
125
+ bg: '#0D0D0D',
126
+ panel: '#181818',
127
+ fg: '#FFFFFF',
128
+ muted: '#B8B8B8',
129
+ accent: '#E63946',
130
+ accent2: '#FFD60A',
131
+ },
132
+ fonts: {
133
+ heading: 'Impact, "Arial Black", "PingFang SC", "Microsoft YaHei", sans-serif',
134
+ body: '"Helvetica Neue", Inter, "PingFang SC", "Microsoft YaHei", sans-serif',
135
+ },
136
+ },
137
+ }
138
+
139
+ export const THEME_IDS = Object.keys(THEMES)
140
+ export const DEFAULT_THEME = 'data'
141
+
142
+ export const LANGUAGES = {
143
+ zh: {
144
+ id: 'zh',
145
+ attr: 'zh-CN',
146
+ ui: {
147
+ slide: '第',
148
+ of: '/ 共',
149
+ theme: '主题',
150
+ help: '← → 翻页 · F 全屏 · G 总览 · S 备注 · P 打印',
151
+ coverKicker: '开场',
152
+ pointKicker: '要点',
153
+ statementKicker: '核心观点',
154
+ quoteKicker: '金句',
155
155
  tableKicker: '数据',
156
- notesLabel: '演讲者备注',
157
- notesToggle: '备注',
158
- closingTitle: '谢谢',
159
- closingSubtitle: '讨论与问答',
160
- generatedBy: '由 dsh-ppt 生成',
161
- },
162
- },
163
- en: {
164
- id: 'en',
165
- attr: 'en-US',
166
- ui: {
167
- slide: 'Slide',
168
- of: '/',
169
- theme: 'Theme',
170
- help: '← → navigate · F fullscreen · G overview · S notes · P print',
171
- coverKicker: 'Opening',
172
- pointKicker: 'Key point',
173
- statementKicker: 'Core idea',
174
- quoteKicker: 'Quote',
156
+ continuation: '(续)',
157
+ notesLabel: '演讲者备注',
158
+ notesToggle: '备注',
159
+ closingTitle: '谢谢',
160
+ closingSubtitle: '讨论与问答',
161
+ generatedBy: '由 dsh-ppt 生成',
162
+ },
163
+ },
164
+ en: {
165
+ id: 'en',
166
+ attr: 'en-US',
167
+ ui: {
168
+ slide: 'Slide',
169
+ of: '/',
170
+ theme: 'Theme',
171
+ help: '← → navigate · F fullscreen · G overview · S notes · P print',
172
+ coverKicker: 'Opening',
173
+ pointKicker: 'Key point',
174
+ statementKicker: 'Core idea',
175
+ quoteKicker: 'Quote',
175
176
  tableKicker: 'Data',
176
- notesLabel: 'Speaker notes',
177
- notesToggle: 'Notes',
178
- closingTitle: 'Thank You',
179
- closingSubtitle: 'Discussion & Q&A',
180
- generatedBy: 'Generated with dsh-ppt',
181
- },
182
- },
183
- bilingual: {
184
- id: 'bilingual',
185
- attr: 'zh-CN',
186
- ui: {
187
- slide: '第',
188
- of: '/ 共',
189
- theme: '主题 · Theme',
190
- help: ' → 翻页 · F 全屏 · G 总览 · S 备注 · P 打印',
191
- coverKicker: '开场 · Opening',
192
- pointKicker: '要点 · Key point',
193
- statementKicker: '核心观点 · Core Idea',
194
- quoteKicker: '金句 · Quote',
177
+ continuation: ' (continued)',
178
+ notesLabel: 'Speaker notes',
179
+ notesToggle: 'Notes',
180
+ closingTitle: 'Thank You',
181
+ closingSubtitle: 'Discussion & Q&A',
182
+ generatedBy: 'Generated with dsh-ppt',
183
+ },
184
+ },
185
+ bilingual: {
186
+ id: 'bilingual',
187
+ attr: 'zh-CN',
188
+ ui: {
189
+ slide: '',
190
+ of: '/ ',
191
+ theme: '主题 · Theme',
192
+ help: ' → 翻页 · F 全屏 · G 总览 · S 备注 · P 打印',
193
+ coverKicker: '开场 · Opening',
194
+ pointKicker: '要点 · Key point',
195
+ statementKicker: '核心观点 · Core Idea',
196
+ quoteKicker: '金句 · Quote',
195
197
  tableKicker: '数据 · Data',
196
- notesLabel: '演讲者备注 · Speaker notes',
197
- notesToggle: '备注 · Notes',
198
- closingTitle: '谢谢 · Thank You',
199
- closingSubtitle: '讨论与问答 · Q&A',
200
- generatedBy: ' dsh-ppt 生成 · Generated with dsh-ppt',
201
- },
202
- },
203
- }
204
-
205
- export function resolveTheme(input) {
206
- const id = String(input ?? DEFAULT_THEME).trim().toLowerCase()
207
- const theme = THEMES[id]
208
- if (!theme) {
209
- throw new Error('dsh-ppt:未知主题 "' + id + '",可选:' + THEME_IDS.join(' / ') + '(默认 ' + DEFAULT_THEME + ')')
198
+ continuation: '(续 · continued)',
199
+ notesLabel: '演讲者备注 · Speaker notes',
200
+ notesToggle: '备注 · Notes',
201
+ closingTitle: '谢谢 · Thank You',
202
+ closingSubtitle: '讨论与问答 · Q&A',
203
+ generatedBy: '由 dsh-ppt 生成 · Generated with dsh-ppt',
204
+ },
205
+ },
206
+ }
207
+
208
+ export function resolveTheme(input) {
209
+ const id = String(input ?? DEFAULT_THEME).trim().toLowerCase()
210
+ const theme = THEMES[id]
211
+ if (!theme) {
212
+ throw new Error('dsh-ppt:未知主题 "' + id + '",可选:' + THEME_IDS.join(' / ') + '(默认 ' + DEFAULT_THEME + ')')
213
+ }
214
+ return theme
215
+ }
216
+
217
+ export function resolveLanguage(input) {
218
+ const id = String(input ?? 'zh').trim().toLowerCase()
219
+ const language = LANGUAGES[id]
220
+ if (!language) {
221
+ throw new Error('dsh-ppt:未知语言 "' + id + '",可选:zh / en / bilingual')
222
+ }
223
+ return language
224
+ }
225
+
226
+ export function resolveMotion(input) {
227
+ if (input === undefined || input === null || input === '') return true
228
+ if (input === true || input === 'on') return true
229
+ if (input === false || input === 'off') return false
230
+ throw new Error('dsh-ppt:未知 motion 值 "' + String(input) + '",可选:on / off(默认 on)')
231
+ }
232
+
233
+ export function listThemes(lang = 'zh') {
234
+ const pick = (pair) => (lang === 'en' ? pair.en : pair.zh)
235
+ return THEME_IDS.map((id) => {
236
+ const theme = THEMES[id]
237
+ return {
238
+ id,
239
+ name: pick(theme.name),
240
+ mood: pick(theme.mood),
241
+ bestFor: pick(theme.bestFor),
242
+ dark: theme.dark,
243
+ palette: { ...theme.palette },
244
+ fonts: { ...theme.fonts },
245
+ }
246
+ })
247
+ }
248
+
249
+ // ---------------------------------------------------------------------------
250
+ // 文本工具
251
+ // ---------------------------------------------------------------------------
252
+
253
+ export function clampInt(value, fallback, min, max) {
254
+ const n = typeof value === 'number' ? Math.trunc(value) : fallback
255
+ if (!Number.isFinite(n)) return fallback
256
+ return Math.min(max, Math.max(min, n))
257
+ }
258
+
259
+ // Windows 保留设备名:首个点之前的主名命中即不可用(NUL、com1、aux.report.html 都算)。
260
+ const WINDOWS_RESERVED_FILE_NAME = /^(con|prn|aux|nul|com[1-9]|lpt[1-9])(\.|$)/i
261
+
262
+ export function sanitizeFileName(input) {
263
+ const base = String(input ?? 'deck').trim().replace(/\.(html?|pptx|json)$/i, '')
264
+ let cleaned = base
265
+ .replace(/[<>:"/\\|?*\u0000-\u001F]/g, '-')
266
+ .replace(/\s+/g, '-')
267
+ .replace(/-+/g, '-')
268
+ .replace(/^-+|-+$/g, '')
269
+ if (WINDOWS_RESERVED_FILE_NAME.test(cleaned)) cleaned = 'deck-' + cleaned
270
+ return cleaned.slice(0, 120) || 'deck'
271
+ }
272
+
273
+ const DECK_ARTIFACT_EXTENSIONS = ['.html', '.pptx', '.json']
274
+
275
+ /**
276
+ * 为三件套选择同一个可用文件名前缀。默认不覆盖:任一产物已存在时,
277
+ * 整组改用 -1/-2… 后缀,避免新旧 deck 被静默混写。
278
+ */
279
+ function resolveDeckFileName(outputDir, requestedFileName, overwrite) {
280
+ // 一次 readdir 建集,替代逐个候选 existsSync 探测(最坏 ~3000 次 stat);
281
+ // 统一小写比较,避免 Windows 大小写不敏感文件系统把已占用的名字判成可用。
282
+ const existing = new Set(readdirSync(outputDir).map((name) => name.toLowerCase()))
283
+ const isAvailable = (candidate) => DECK_ARTIFACT_EXTENSIONS.every((ext) => !existing.has((candidate + ext).toLowerCase()))
284
+ if (overwrite || isAvailable(requestedFileName)) return requestedFileName
285
+ for (let index = 1; index < 1000; index += 1) {
286
+ const candidate = requestedFileName + '-' + index
287
+ if (isAvailable(candidate)) return candidate
288
+ }
289
+ throw new Error('dsh-ppt:找不到可用的输出文件名(同名前缀超过 999 个),请更换 fileName 或显式允许 overwrite。')
290
+ }
291
+
292
+ export function escapeXml(value) {
293
+ return String(value ?? '')
294
+ .replace(/&/g, '&amp;')
295
+ .replace(/</g, '&lt;')
296
+ .replace(/>/g, '&gt;')
297
+ .replace(/"/g, '&quot;')
298
+ .replace(/'/g, '&apos;')
299
+ }
300
+
301
+ export function escapeHtml(value) {
302
+ return String(value ?? '')
303
+ .replace(/&/g, '&amp;')
304
+ .replace(/</g, '&lt;')
305
+ .replace(/>/g, '&gt;')
306
+ .replace(/"/g, '&quot;')
307
+ }
308
+
309
+ export function stripInlineMarkdown(value) {
310
+ return String(value ?? '')
311
+ .replace(/!\[[^\]]*\]\([^)]*\)/g, '')
312
+ .replace(/\[([^\]]+)\]\([^)]*\)/g, '$1')
313
+ .replace(/`([^`]*)`/g, '$1')
314
+ .replace(/\*\*([^*]+)\*\*/g, '$1')
315
+ .replace(/__([^_]+)__/g, '$1')
316
+ .replace(/\*([^*\n]+)\*/g, '$1')
317
+ .replace(/_([^_\n]+)_/g, '$1')
318
+ .replace(/<[^>]+>/g, '')
319
+ .replace(/\s+/g, ' ')
320
+ .trim()
321
+ }
322
+
323
+ export function splitSentences(value) {
324
+ const text = String(value ?? '').trim()
325
+ if (text === '') return []
326
+ const parts = text.split(/(?<=[。!?])|(?<=[.!?…])\s+/).map((part) => part.trim()).filter(Boolean)
327
+ return parts.length > 0 ? parts : [text]
328
+ }
329
+
330
+ export function truncate(value, max) {
331
+ const text = String(value ?? '').trim()
332
+ if (text.length <= max) return text
333
+ return text.slice(0, max - 1).replace(/\s+\S*$/, '') + '…'
334
+ }
335
+
336
+ function chunk(items, size) {
337
+ const out = []
338
+ for (let i = 0; i < items.length; i += size) out.push(items.slice(i, i + size))
339
+ return out
340
+ }
341
+
342
+ // ---------------------------------------------------------------------------
343
+ // Markdown → deck
344
+ // ---------------------------------------------------------------------------
345
+
346
+ function createSection(heading = '', level = 0, coverOnly = false) {
347
+ return { heading, level, coverOnly, bullets: [], paragraphs: [], quote: [], table: null, notes: [] }
348
+ }
349
+
350
+ function splitTableRow(line) {
351
+ const trimmed = line.trim()
352
+ const match = /^\|(.+)\|$/.exec(trimmed)
353
+ if (match === null) return null
354
+ return match[1].split('|').map((cell) => cell.trim())
355
+ }
356
+
357
+ function isTableSeparator(cells) {
358
+ return cells.length > 0 && cells.every((cell) => /^:?-{2,}:?$/.test(cell) || /^:?-+:?$/.test(cell))
359
+ }
360
+
361
+ const NOTES_COMMENT = /^<!--\s*(?:notes?|备注)\s*[::]\s*([\s\S]*?)\s*-->$/
362
+
363
+ function quoteSlideFrom(section, ui) {
364
+ const lines = [...section.quote]
365
+ let attribution = ''
366
+ const attrMatch = /^(?:——|—|--|-)\s*(.+)$/.exec(lines[lines.length - 1] ?? '')
367
+ if (attrMatch !== null && lines.length > 1) {
368
+ attribution = attrMatch[1]
369
+ lines.pop()
370
+ }
371
+ return { layout: 'quote', kicker: ui.quoteKicker, title: truncate(lines.join(' '), 220), subtitle: attribution }
372
+ }
373
+
374
+ function paginateTable(slide, continuation = '(续)') {
375
+ const rows = slide.rows
376
+ const columns = Math.max(...rows.map(row => row.length))
377
+ if (columns > 8) throw new Error('dsh-ppt:表格最多 8 列,请拆成多个表格后重试 / tables support up to 8 columns')
378
+ if (rows.some(row => row.some(cell => [...cell].length > 60))) {
379
+ throw new Error('dsh-ppt:表格单元格最多 60 个字符,请精简或拆分内容后重试 / cells support up to 60 characters')
210
380
  }
211
- return theme
212
- }
213
-
214
- export function resolveLanguage(input) {
215
- const id = String(input ?? 'zh').trim().toLowerCase()
216
- const language = LANGUAGES[id]
217
- if (!language) {
218
- throw new Error('dsh-ppt:未知语言 "' + id + '",可选:zh / en / bilingual')
219
- }
220
- return language
221
- }
222
-
223
- export function resolveMotion(input) {
224
- if (input === undefined || input === null || input === '') return true
225
- if (input === true || input === 'on') return true
226
- if (input === false || input === 'off') return false
227
- throw new Error('dsh-ppt:未知 motion 值 "' + String(input) + '",可选:on / off(默认 on)')
228
- }
229
-
230
- export function listThemes(lang = 'zh') {
231
- const pick = (pair) => (lang === 'en' ? pair.en : pair.zh)
232
- return THEME_IDS.map((id) => {
233
- const theme = THEMES[id]
234
- return {
235
- id,
236
- name: pick(theme.name),
237
- mood: pick(theme.mood),
238
- bestFor: pick(theme.bestFor),
239
- dark: theme.dark,
240
- palette: { ...theme.palette },
241
- fonts: { ...theme.fonts },
242
- }
381
+ const padded = rows.map(row => Array.from({ length: columns }, (_, i) => row[i] ?? ''))
382
+ const pages = chunk(padded.slice(1), 8)
383
+ if (pages.length === 0) pages.push([])
384
+ return pages.map((body, index) => {
385
+ const { notes, ...rest } = slide
386
+ const title = slide.title + (index === 0 ? '' : continuation)
387
+ // 同名 kicker/title 共用紧凑标题;续页不能凭空多出一行大标题挤压表格。
388
+ return { ...rest, title, kicker: slide.kicker === slide.title ? title : slide.kicker, rows: [padded[0], ...body],
389
+ ...(index === 0 && notes ? { notes } : {}) }
243
390
  })
244
391
  }
245
392
 
246
- // ---------------------------------------------------------------------------
247
- // 文本工具
248
- // ---------------------------------------------------------------------------
249
-
250
- export function clampInt(value, fallback, min, max) {
251
- const n = typeof value === 'number' ? Math.trunc(value) : fallback
252
- if (!Number.isFinite(n)) return fallback
253
- return Math.min(max, Math.max(min, n))
254
- }
255
-
256
- // Windows 保留设备名:首个点之前的主名命中即不可用(NUL、com1、aux.report.html 都算)。
257
- const WINDOWS_RESERVED_FILE_NAME = /^(con|prn|aux|nul|com[1-9]|lpt[1-9])(\.|$)/i
258
-
259
- export function sanitizeFileName(input) {
260
- const base = String(input ?? 'deck').trim().replace(/\.(html?|pptx|json)$/i, '')
261
- let cleaned = base
262
- .replace(/[<>:"/\\|?*\u0000-\u001F]/g, '-')
263
- .replace(/\s+/g, '-')
264
- .replace(/-+/g, '-')
265
- .replace(/^-+|-+$/g, '')
266
- if (WINDOWS_RESERVED_FILE_NAME.test(cleaned)) cleaned = 'deck-' + cleaned
267
- return cleaned.slice(0, 120) || 'deck'
268
- }
269
-
270
- const DECK_ARTIFACT_EXTENSIONS = ['.html', '.pptx', '.json']
271
-
272
- /**
273
- * 为三件套选择同一个可用文件名前缀。默认不覆盖:任一产物已存在时,
274
- * 整组改用 -1/-2… 后缀,避免新旧 deck 被静默混写。
275
- */
276
- function resolveDeckFileName(outputDir, requestedFileName, overwrite) {
277
- // 一次 readdir 建集,替代逐个候选 existsSync 探测(最坏 ~3000 次 stat);
278
- // 统一小写比较,避免 Windows 大小写不敏感文件系统把已占用的名字判成可用。
279
- const existing = new Set(readdirSync(outputDir).map((name) => name.toLowerCase()))
280
- const isAvailable = (candidate) => DECK_ARTIFACT_EXTENSIONS.every((ext) => !existing.has((candidate + ext).toLowerCase()))
281
- if (overwrite || isAvailable(requestedFileName)) return requestedFileName
282
- for (let index = 1; index < 1000; index += 1) {
283
- const candidate = requestedFileName + '-' + index
284
- if (isAvailable(candidate)) return candidate
285
- }
286
- throw new Error('dsh-ppt:找不到可用的输出文件名(同名前缀超过 999 个),请更换 fileName 或显式允许 overwrite。')
287
- }
288
-
289
- export function escapeXml(value) {
290
- return String(value ?? '')
291
- .replace(/&/g, '&amp;')
292
- .replace(/</g, '&lt;')
293
- .replace(/>/g, '&gt;')
294
- .replace(/"/g, '&quot;')
295
- .replace(/'/g, '&apos;')
296
- }
297
-
298
- export function escapeHtml(value) {
299
- return String(value ?? '')
300
- .replace(/&/g, '&amp;')
301
- .replace(/</g, '&lt;')
302
- .replace(/>/g, '&gt;')
303
- .replace(/"/g, '&quot;')
304
- }
305
-
306
- export function stripInlineMarkdown(value) {
307
- return String(value ?? '')
308
- .replace(/!\[[^\]]*\]\([^)]*\)/g, '')
309
- .replace(/\[([^\]]+)\]\([^)]*\)/g, '$1')
310
- .replace(/`([^`]*)`/g, '$1')
311
- .replace(/\*\*([^*]+)\*\*/g, '$1')
312
- .replace(/__([^_]+)__/g, '$1')
313
- .replace(/\*([^*\n]+)\*/g, '$1')
314
- .replace(/_([^_\n]+)_/g, '$1')
315
- .replace(/<[^>]+>/g, '')
316
- .replace(/\s+/g, ' ')
317
- .trim()
318
- }
319
-
320
- export function splitSentences(value) {
321
- const text = String(value ?? '').trim()
322
- if (text === '') return []
323
- const parts = text.split(/(?<=[。!?])|(?<=[.!?…])\s+/).map((part) => part.trim()).filter(Boolean)
324
- return parts.length > 0 ? parts : [text]
325
- }
326
-
327
- export function truncate(value, max) {
328
- const text = String(value ?? '').trim()
329
- if (text.length <= max) return text
330
- return text.slice(0, max - 1).replace(/\s+\S*$/, '') + '…'
331
- }
332
-
333
- function chunk(items, size) {
334
- const out = []
335
- for (let i = 0; i < items.length; i += size) out.push(items.slice(i, i + size))
336
- return out
337
- }
338
-
339
- // ---------------------------------------------------------------------------
340
- // Markdown → deck
341
- // ---------------------------------------------------------------------------
342
-
343
- function createSection(heading = '', level = 0, coverOnly = false) {
344
- return { heading, level, coverOnly, bullets: [], paragraphs: [], quote: [], table: null, notes: [] }
345
- }
346
-
347
- function splitTableRow(line) {
348
- const trimmed = line.trim()
349
- const match = /^\|(.+)\|$/.exec(trimmed)
350
- if (match === null) return null
351
- return match[1].split('|').map((cell) => cell.trim())
352
- }
353
-
354
- function isTableSeparator(cells) {
355
- return cells.length > 0 && cells.every((cell) => /^:?-{2,}:?$/.test(cell) || /^:?-+:?$/.test(cell))
356
- }
357
-
358
- const NOTES_COMMENT = /^<!--\s*(?:notes?|备注)\s*[::]\s*([\s\S]*?)\s*-->$/
359
-
360
- function quoteSlideFrom(section, ui) {
361
- const lines = [...section.quote]
362
- let attribution = ''
363
- const attrMatch = /^(?:——|—|--|-)\s*(.+)$/.exec(lines[lines.length - 1] ?? '')
364
- if (attrMatch !== null && lines.length > 1) {
365
- attribution = attrMatch[1]
366
- lines.pop()
367
- }
368
- return { layout: 'quote', kicker: ui.quoteKicker, title: truncate(lines.join(' '), 220), subtitle: attribution }
369
- }
370
-
371
- function tableSlideFrom(section, ui) {
393
+ function tableSlidesFrom(section, ui) {
372
394
  const table = section.table
373
395
  const rows = [table.header, ...table.rows]
374
- .slice(0, 9)
375
- .map((row) => row.slice(0, 8).map((cell) => truncate(cell, 60)))
376
396
  const heading = section.heading || ui.tableKicker
377
- return { layout: 'table', kicker: heading, title: heading, rows }
378
- }
379
-
380
- /** 把一个 section 里的金句/表格拆成独立页;备注附着到第一张产出页。 */
381
- function specialSlidesFor(section, ui) {
382
- const out = []
383
- if (section.quote.length > 0) out.push(quoteSlideFrom(section, ui))
384
- if (section.table !== null) out.push(tableSlideFrom(section, ui))
385
- if (out.length > 0 && section.notes.length > 0) out[0].notes = section.notes.join('\n')
386
- return out
387
- }
388
-
389
- export function parseMarkdownDeck(titleInput, content, lang = 'zh') {
390
- const language = resolveLanguage(lang)
391
- const ui = language.ui
392
- const title = String(titleInput ?? '').trim()
393
- let coverTitle = title
394
- let coverSubtitle = ''
395
- let coverSubtitleConsumed = false
396
-
397
- let body = String(content ?? '')
398
- .replace(/^\uFEFF/, '')
399
- .replace(/\r\n?/g, '\n')
400
- // 去除文档级 YAML frontmatter(如果有)
401
- body = body.replace(/^---[ \t]*\n[\s\S]*?\n---[ \t]*\n?/, '')
402
-
403
- const sections = []
404
- let current = null
405
- let firstH1Seen = false
406
-
407
- const flush = () => {
408
- if (current !== null && (current.heading !== '' || current.bullets.length > 0 || current.paragraphs.length > 0)) {
409
- sections.push(current)
410
- }
411
- current = null
412
- }
413
-
414
- for (const rawLine of body.split('\n')) {
415
- const line = rawLine.trim()
416
- if (line === '') {
417
- // 无标题分组按空行分段,保证「文档无标题」时按段落生成幻灯片
418
- if (current !== null && current.heading === '') flush()
419
- continue
420
- }
421
-
422
- const headingMatch = /^(#{1,6})\s+(.+)$/.exec(line)
423
- if (headingMatch !== null) {
424
- const level = headingMatch[1].length
425
- const heading = stripInlineMarkdown(headingMatch[2])
426
- if (level === 1 && !firstH1Seen) {
427
- firstH1Seen = true
428
- if (coverTitle === '') coverTitle = heading
429
- flush()
430
- current = createSection(heading, level, true)
431
- continue
432
- }
433
- flush()
434
- current = createSection(heading, level, false)
435
- continue
436
- }
437
-
438
- const bulletMatch = /^\s*(?:[-*+]|\d+[.)])\s+(.+)$/.exec(line)
439
- if (bulletMatch !== null) {
440
- const bullet = stripInlineMarkdown(bulletMatch[1])
441
- if (bullet !== '') {
442
- if (current === null) current = createSection()
443
- current.bullets.push(bullet)
444
- }
445
- continue
446
- }
447
-
448
- // 演讲者备注:`<!-- 备注: ... -->` / `<!-- note: ... -->` 附到当前页
449
- const notesMatch = NOTES_COMMENT.exec(line)
450
- if (notesMatch !== null && notesMatch[1].trim() !== '') {
451
- if (current === null) current = createSection()
452
- current.notes.push(notesMatch[1].trim())
453
- continue
454
- }
455
-
456
- // Markdown 表格:连续的 | ... | 行,第二行是分隔线
457
- const tableCells = splitTableRow(line)
458
- if (tableCells !== null) {
459
- if (current === null) current = createSection()
460
- if (isTableSeparator(tableCells)) continue
461
- if (current.table === null) {
462
- current.table = { header: tableCells.map((cell) => stripInlineMarkdown(cell)), rows: [] }
463
- } else if (current.table.rows.length < 12) {
464
- current.table.rows.push(tableCells.map((cell) => stripInlineMarkdown(cell)))
465
- }
466
- continue
467
- }
468
-
469
- // 金句:`>` 引用块(最后一行 `—— 出处` 识别为署名)
470
- const quoteMatch = /^>\s?(.*)$/.exec(line)
471
- if (quoteMatch !== null) {
472
- const quoted = stripInlineMarkdown(quoteMatch[1])
473
- if (quoted !== '') {
474
- if (current === null) current = createSection()
475
- current.quote.push(quoted)
476
- }
477
- continue
478
- }
479
-
480
- const paragraph = stripInlineMarkdown(line)
481
- if (paragraph === '') continue
482
- if (current === null) current = createSection()
483
- current.paragraphs.push(paragraph)
484
- }
485
- flush()
486
-
487
- const slides = []
488
- const coverSource = sections.find((section) => section.coverOnly === true)
489
- if (coverSource !== null && coverSource !== undefined) {
490
- const coverText = coverSource.paragraphs[0] ?? coverSource.bullets[0] ?? ''
491
- if (coverSubtitle === '') {
492
- coverSubtitle = truncate(coverText, 180)
493
- coverSubtitleConsumed = true
494
- }
495
- }
496
-
397
+ return paginateTable({ layout: 'table', kicker: heading, title: heading, rows }, ui.continuation)
398
+ }
399
+
400
+ /** 把一个 section 里的金句/表格拆成独立页;备注附着到第一张产出页。 */
401
+ function specialSlidesFor(section, ui) {
402
+ const out = []
403
+ if (section.quote.length > 0) out.push(quoteSlideFrom(section, ui))
404
+ if (section.table !== null) out.push(...tableSlidesFrom(section, ui))
405
+ if (out.length > 0 && section.notes.length > 0) out[0].notes = section.notes.join('\n')
406
+ return out
407
+ }
408
+
409
+ export function parseMarkdownDeck(titleInput, content, lang = 'zh') {
410
+ const language = resolveLanguage(lang)
411
+ const ui = language.ui
412
+ const title = String(titleInput ?? '').trim()
413
+ let coverTitle = title
414
+ let coverSubtitle = ''
415
+ let coverSubtitleConsumed = false
416
+
417
+ let body = String(content ?? '')
418
+ .replace(/^\uFEFF/, '')
419
+ .replace(/\r\n?/g, '\n')
420
+ // 去除文档级 YAML frontmatter(如果有)
421
+ body = body.replace(/^---[ \t]*\n[\s\S]*?\n---[ \t]*\n?/, '')
422
+
423
+ const sections = []
424
+ let current = null
425
+ let firstH1Seen = false
426
+
427
+ const flush = () => {
428
+ if (current !== null && (current.heading !== '' || current.bullets.length > 0 || current.paragraphs.length > 0
429
+ || current.table !== null || current.quote.length > 0)) {
430
+ sections.push(current)
431
+ }
432
+ current = null
433
+ }
434
+
435
+ for (const rawLine of body.split('\n')) {
436
+ const line = rawLine.trim()
437
+ if (line === '') {
438
+ // 无标题分组按空行分段,保证「文档无标题」时按段落生成幻灯片
439
+ if (current !== null && current.heading === '') flush()
440
+ continue
441
+ }
442
+
443
+ const headingMatch = /^(#{1,6})\s+(.+)$/.exec(line)
444
+ if (headingMatch !== null) {
445
+ const level = headingMatch[1].length
446
+ const heading = stripInlineMarkdown(headingMatch[2])
447
+ if (level === 1 && !firstH1Seen) {
448
+ firstH1Seen = true
449
+ if (coverTitle === '') coverTitle = heading
450
+ flush()
451
+ current = createSection(heading, level, true)
452
+ continue
453
+ }
454
+ flush()
455
+ current = createSection(heading, level, false)
456
+ continue
457
+ }
458
+
459
+ const bulletMatch = /^\s*(?:[-*+]|\d+[.)])\s+(.+)$/.exec(line)
460
+ if (bulletMatch !== null) {
461
+ const bullet = stripInlineMarkdown(bulletMatch[1])
462
+ if (bullet !== '') {
463
+ if (current === null) current = createSection()
464
+ current.bullets.push(bullet)
465
+ }
466
+ continue
467
+ }
468
+
469
+ // 演讲者备注:`<!-- 备注: ... -->` / `<!-- note: ... -->` 附到当前页
470
+ const notesMatch = NOTES_COMMENT.exec(line)
471
+ if (notesMatch !== null && notesMatch[1].trim() !== '') {
472
+ if (current === null) current = createSection()
473
+ current.notes.push(notesMatch[1].trim())
474
+ continue
475
+ }
476
+
477
+ // Markdown 表格:连续的 | ... | 行,第二行是分隔线
478
+ const tableCells = splitTableRow(line)
479
+ if (tableCells !== null) {
480
+ if (current === null) current = createSection()
481
+ if (isTableSeparator(tableCells)) continue
482
+ if (current.table === null) {
483
+ current.table = { header: tableCells.map((cell) => stripInlineMarkdown(cell)), rows: [] }
484
+ } else {
485
+ current.table.rows.push(tableCells.map((cell) => stripInlineMarkdown(cell)))
486
+ }
487
+ continue
488
+ }
489
+
490
+ // 金句:`>` 引用块(最后一行 `—— 出处` 识别为署名)
491
+ const quoteMatch = /^>\s?(.*)$/.exec(line)
492
+ if (quoteMatch !== null) {
493
+ const quoted = stripInlineMarkdown(quoteMatch[1])
494
+ if (quoted !== '') {
495
+ if (current === null) current = createSection()
496
+ current.quote.push(quoted)
497
+ }
498
+ continue
499
+ }
500
+
501
+ const paragraph = stripInlineMarkdown(line)
502
+ if (paragraph === '') continue
503
+ if (current === null) current = createSection()
504
+ current.paragraphs.push(paragraph)
505
+ }
506
+ flush()
507
+
508
+ const slides = []
509
+ const coverSource = sections.find((section) => section.coverOnly === true)
510
+ if (coverSource !== null && coverSource !== undefined) {
511
+ const coverText = coverSource.paragraphs[0] ?? coverSource.bullets[0] ?? ''
512
+ if (coverSubtitle === '') {
513
+ coverSubtitle = truncate(coverText, 180)
514
+ coverSubtitleConsumed = true
515
+ }
516
+ }
517
+
497
518
  let bodySections = sections.filter((section) => section.coverOnly !== true)
498
- // 首个 H1 既是封面又把所有要点收在封面节里时,把封面副标题之外的剩余要点
499
- // 提升为一个无标题节,走下面的要点页生成逻辑,避免丢掉内容。
500
- if (bodySections.length === 0 && coverSource !== null && coverSource !== undefined) {
501
- const usedParagraph = coverSource.paragraphs.length > 0
502
- const extras = [
503
- ...(usedParagraph ? coverSource.bullets : coverSource.bullets.slice(1)),
504
- ...coverSource.paragraphs.slice(usedParagraph ? 1 : 0),
505
- ]
506
- if (extras.length > 0) {
507
- const synthetic = createSection()
508
- synthetic.bullets = extras
519
+ // 首个 H1 既是封面又把所有要点收在封面节里时,把封面副标题之外的剩余要点
520
+ // 提升为一个无标题节,走下面的要点页生成逻辑,避免丢掉内容。
521
+ if (bodySections.length === 0 && coverSource !== null && coverSource !== undefined) {
522
+ const usedParagraph = coverSource.paragraphs.length > 0
523
+ const extras = [
524
+ ...(usedParagraph ? coverSource.bullets : coverSource.bullets.slice(1)),
525
+ ...coverSource.paragraphs.slice(usedParagraph ? 1 : 0),
526
+ ]
527
+ if (extras.length > 0) {
528
+ const synthetic = createSection()
529
+ synthetic.bullets = extras
509
530
  bodySections = [synthetic]
510
531
  }
511
532
  }
512
533
 
513
- if (bodySections.length === 0) {
514
- // 一句话 / 无结构输入:封面 + 核心观点 + 结束页(仍是完整的三页演示文稿)
515
- const allText = coverSource !== null && coverSource !== undefined
516
- ? [...coverSource.bullets, ...coverSource.paragraphs].join(' ')
517
- : String(content ?? '').trim()
518
- if (coverSubtitle === '') coverSubtitle = truncate(splitSentences(allText)[0] ?? '', 180)
519
- slides.push({ layout: 'cover', kicker: ui.coverKicker, title: coverTitle || 'Untitled', subtitle: coverSubtitle })
520
- if (coverSubtitle !== '') {
521
- slides.push({ layout: 'statement', kicker: ui.statementKicker, title: coverSubtitle, subtitle: coverTitle })
522
- }
523
- slides.push({ layout: 'closing', title: ui.closingTitle, subtitle: coverTitle || 'Untitled' })
524
- return { title: coverTitle || 'Untitled', subtitle: coverSubtitle, slides }
525
- }
526
-
527
- const hadHeadings = bodySections.some((section) => section.heading !== '')
528
-
529
- if (!hadHeadings) {
530
- // 无标题文档:第一段摘要作封面副标题,后续段落拆成要点页
531
- const ordered = bodySections.map((section) => ({
532
- section,
533
- sentences: [...section.bullets, ...section.paragraphs].flatMap((part) => splitSentences(part)),
534
- }))
535
- const firstSentence = ordered[0]?.sentences[0] ?? ''
536
- if (coverSubtitle === '') coverSubtitle = truncate(firstSentence, 180)
537
- const bodySlides = []
538
- let pointIndex = 0
539
- ordered.forEach((group, groupIndex) => {
540
- const specials = specialSlidesFor(group.section, ui)
541
- bodySlides.push(...specials)
542
- const sentences = (groupIndex === 0 && !coverSubtitleConsumed) ? group.sentences.slice(1) : group.sentences
543
- for (const points of chunk(sentences, 5)) {
544
- pointIndex += 1
545
- const slide = {
546
- layout: 'bullets',
547
- kicker: ui.pointKicker + ' ' + pointIndex,
548
- title: truncate(points[0], 40) || ui.pointKicker + ' ' + pointIndex,
549
- bullets: points,
550
- }
551
- if (specials.length === 0 && group.section.notes.length > 0) slide.notes = group.section.notes.join('\n')
552
- bodySlides.push(slide)
553
- }
554
- })
555
- slides.push({ layout: 'cover', kicker: ui.coverKicker, title: coverTitle || 'Untitled', subtitle: coverSubtitle })
556
- if (bodySlides.length === 0) {
557
- if (coverSubtitle !== '') {
558
- slides.push({ layout: 'statement', kicker: ui.statementKicker, title: coverSubtitle, subtitle: coverTitle || 'Untitled' })
559
- }
560
- } else {
561
- slides.push(...bodySlides)
562
- }
563
- slides.push({ layout: 'closing', title: ui.closingTitle, subtitle: coverTitle || 'Untitled' })
564
- return { title: coverTitle || 'Untitled', subtitle: coverSubtitle, slides }
565
- }
566
-
567
- slides.push({ layout: 'cover', kicker: ui.coverKicker, title: coverTitle || 'Untitled', subtitle: coverSubtitle })
568
- let pointIndex = 0
569
- for (const section of bodySections) {
570
- const notes = section.notes.join('\n')
571
- const specials = specialSlidesFor(section, ui)
572
- slides.push(...specials)
573
- if (section.heading === '') {
574
- const points = [...section.bullets, ...section.paragraphs]
575
- .flatMap((part) => splitSentences(part))
576
- // 超过 8 条自动续页,不再静默丢弃;备注只挂在第一页
577
- for (const [pageIndex, pagePoints] of chunk(points, 8).entries()) {
578
- pointIndex += 1
579
- const slide = {
580
- layout: 'bullets',
581
- kicker: ui.pointKicker + ' ' + pointIndex,
582
- title: truncate(pagePoints[0], 40) || ui.pointKicker + ' ' + pointIndex,
583
- bullets: pagePoints,
584
- }
585
- if (pageIndex === 0 && specials.length === 0 && notes !== '') slide.notes = notes
586
- slides.push(slide)
587
- }
588
- continue
589
- }
590
- const points = [
591
- ...section.bullets,
592
- ...section.paragraphs.flatMap((part) => splitSentences(part)),
593
- ]
594
- const pages = chunk(points, 8)
595
- if (pages.length > 0) {
596
- // 超过 8 条自动续页,不再静默丢弃;备注只挂在第一页
597
- pages.forEach((pagePoints, pageIndex) => {
598
- const label = pageIndex === 0 ? section.heading : section.heading + '(续)'
599
- const slide = { layout: 'bullets', kicker: label, title: label, bullets: pagePoints }
600
- if (pageIndex === 0 && specials.length === 0 && notes !== '') slide.notes = notes
601
- slides.push(slide)
602
- })
603
- } else if (specials.length === 0) {
604
- const slide = { layout: 'section', kicker: section.heading, title: section.heading }
605
- if (notes !== '') slide.notes = notes
606
- slides.push(slide)
607
- }
608
- }
609
- slides.push({ layout: 'closing', title: ui.closingTitle, subtitle: coverTitle || 'Untitled' })
610
- return { title: coverTitle || 'Untitled', subtitle: coverSubtitle, slides }
611
- }
612
-
613
- const SLIDE_LAYOUTS = new Set(['cover', 'section', 'bullets', 'statement', 'closing', 'quote', 'table'])
614
-
615
- function normalizeSlide(raw, index) {
616
- const source = (raw !== null && typeof raw === 'object') ? raw : {}
617
- const layout = SLIDE_LAYOUTS.has(source.layout) ? source.layout : 'bullets'
618
- const title = stripInlineMarkdown(source.title ?? '')
619
- const subtitle = stripInlineMarkdown(source.subtitle ?? '')
620
- const kicker = stripInlineMarkdown(source.kicker ?? '')
621
- const text = stripInlineMarkdown(source.text ?? '')
622
- // 备注保留换行(放映面板与备注页都按原文显示),只做转义,不做 Markdown 清洗
623
- const notes = String(source.notes ?? '').trim()
624
- let bullets = []
625
- if (Array.isArray(source.bullets)) {
626
- bullets = source.bullets.map((item) => stripInlineMarkdown(String(item))).filter(Boolean)
627
- } else if (typeof source.bullets === 'string' && source.bullets.trim() !== '') {
628
- bullets = splitSentences(source.bullets)
534
+ // 表格和引用不能只挂在封面节上,否则首个 H1 后没有 H2 时会丢失。
535
+ if (coverSource && (coverSource.table !== null || coverSource.quote.length > 0)) {
536
+ const special = createSection()
537
+ special.table = coverSource.table
538
+ special.quote = coverSource.quote
539
+ special.notes = coverSource.notes
540
+ bodySections.unshift(special)
629
541
  }
630
- if (layout === 'statement' && title === '' && text !== '') {
631
- return { layout, kicker, title: text, subtitle: subtitle || '', bullets, ...(notes !== '' ? { notes } : {}) }
632
- }
633
- if (layout === 'quote') {
634
- const quoteText = title !== '' ? title : text
635
- if (quoteText === '') return { layout: 'statement', kicker, title: subtitle, subtitle: '', bullets, ...(notes !== '' ? { notes } : {}) }
636
- return { layout, kicker, title: truncate(quoteText, 220), subtitle, ...(notes !== '' ? { notes } : {}) }
637
- }
638
- if (layout === 'table') {
639
- let rows = []
640
- if (Array.isArray(source.rows)) {
641
- rows = source.rows
542
+
543
+ if (bodySections.length === 0) {
544
+ // 一句话 / 无结构输入:封面 + 核心观点 + 结束页(仍是完整的三页演示文稿)
545
+ const allText = coverSource !== null && coverSource !== undefined
546
+ ? [...coverSource.bullets, ...coverSource.paragraphs].join(' ')
547
+ : String(content ?? '').trim()
548
+ if (coverSubtitle === '') coverSubtitle = truncate(splitSentences(allText)[0] ?? '', 180)
549
+ slides.push({ layout: 'cover', kicker: ui.coverKicker, title: coverTitle || 'Untitled', subtitle: coverSubtitle })
550
+ if (coverSubtitle !== '') {
551
+ slides.push({ layout: 'statement', kicker: ui.statementKicker, title: coverSubtitle, subtitle: coverTitle })
552
+ }
553
+ slides.push({ layout: 'closing', title: ui.closingTitle, subtitle: coverTitle || 'Untitled' })
554
+ return { title: coverTitle || 'Untitled', subtitle: coverSubtitle, slides }
555
+ }
556
+
557
+ const hadHeadings = bodySections.some((section) => section.heading !== '')
558
+
559
+ if (!hadHeadings) {
560
+ // 无标题文档:第一段摘要作封面副标题,后续段落拆成要点页
561
+ const ordered = bodySections.map((section) => ({
562
+ section,
563
+ sentences: [...section.bullets, ...section.paragraphs].flatMap((part) => splitSentences(part)),
564
+ }))
565
+ const firstSentence = ordered[0]?.sentences[0] ?? ''
566
+ if (coverSubtitle === '') coverSubtitle = truncate(firstSentence, 180)
567
+ const bodySlides = []
568
+ let pointIndex = 0
569
+ ordered.forEach((group, groupIndex) => {
570
+ const specials = specialSlidesFor(group.section, ui)
571
+ bodySlides.push(...specials)
572
+ const sentences = (groupIndex === 0 && !coverSubtitleConsumed) ? group.sentences.slice(1) : group.sentences
573
+ for (const points of chunk(sentences, 5)) {
574
+ pointIndex += 1
575
+ const slide = {
576
+ layout: 'bullets',
577
+ kicker: ui.pointKicker + ' ' + pointIndex,
578
+ title: truncate(points[0], 40) || ui.pointKicker + ' ' + pointIndex,
579
+ bullets: points,
580
+ }
581
+ if (specials.length === 0 && group.section.notes.length > 0) slide.notes = group.section.notes.join('\n')
582
+ bodySlides.push(slide)
583
+ }
584
+ })
585
+ slides.push({ layout: 'cover', kicker: ui.coverKicker, title: coverTitle || 'Untitled', subtitle: coverSubtitle })
586
+ if (bodySlides.length === 0) {
587
+ if (coverSubtitle !== '') {
588
+ slides.push({ layout: 'statement', kicker: ui.statementKicker, title: coverSubtitle, subtitle: coverTitle || 'Untitled' })
589
+ }
590
+ } else {
591
+ slides.push(...bodySlides)
592
+ }
593
+ slides.push({ layout: 'closing', title: ui.closingTitle, subtitle: coverTitle || 'Untitled' })
594
+ return { title: coverTitle || 'Untitled', subtitle: coverSubtitle, slides }
595
+ }
596
+
597
+ slides.push({ layout: 'cover', kicker: ui.coverKicker, title: coverTitle || 'Untitled', subtitle: coverSubtitle })
598
+ let pointIndex = 0
599
+ for (const section of bodySections) {
600
+ const notes = section.notes.join('\n')
601
+ const specials = specialSlidesFor(section, ui)
602
+ slides.push(...specials)
603
+ if (section.heading === '') {
604
+ const points = [...section.bullets, ...section.paragraphs]
605
+ .flatMap((part) => splitSentences(part))
606
+ // 超过 8 条自动续页,不再静默丢弃;备注只挂在第一页
607
+ for (const [pageIndex, pagePoints] of chunk(points, 8).entries()) {
608
+ pointIndex += 1
609
+ const slide = {
610
+ layout: 'bullets',
611
+ kicker: ui.pointKicker + ' ' + pointIndex,
612
+ title: truncate(pagePoints[0], 40) || ui.pointKicker + ' ' + pointIndex,
613
+ bullets: pagePoints,
614
+ }
615
+ if (pageIndex === 0 && specials.length === 0 && notes !== '') slide.notes = notes
616
+ slides.push(slide)
617
+ }
618
+ continue
619
+ }
620
+ const points = [
621
+ ...section.bullets,
622
+ ...section.paragraphs.flatMap((part) => splitSentences(part)),
623
+ ]
624
+ const pages = chunk(points, 8)
625
+ if (pages.length > 0) {
626
+ // 超过 8 条自动续页,不再静默丢弃;备注只挂在第一页
627
+ pages.forEach((pagePoints, pageIndex) => {
628
+ const label = pageIndex === 0 ? section.heading : section.heading + ui.continuation
629
+ const slide = { layout: 'bullets', kicker: label, title: label, bullets: pagePoints }
630
+ if (pageIndex === 0 && specials.length === 0 && notes !== '') slide.notes = notes
631
+ slides.push(slide)
632
+ })
633
+ } else if (specials.length === 0) {
634
+ const slide = { layout: 'section', kicker: section.heading, title: section.heading }
635
+ if (notes !== '') slide.notes = notes
636
+ slides.push(slide)
637
+ }
638
+ }
639
+ slides.push({ layout: 'closing', title: ui.closingTitle, subtitle: coverTitle || 'Untitled' })
640
+ return { title: coverTitle || 'Untitled', subtitle: coverSubtitle, slides }
641
+ }
642
+
643
+ const SLIDE_LAYOUTS = new Set(['cover', 'section', 'bullets', 'statement', 'closing', 'quote', 'table'])
644
+
645
+ function normalizeSlide(raw, index) {
646
+ const source = (raw !== null && typeof raw === 'object') ? raw : {}
647
+ const layout = SLIDE_LAYOUTS.has(source.layout) ? source.layout : 'bullets'
648
+ const title = stripInlineMarkdown(source.title ?? '')
649
+ const subtitle = stripInlineMarkdown(source.subtitle ?? '')
650
+ const kicker = stripInlineMarkdown(source.kicker ?? '')
651
+ const text = stripInlineMarkdown(source.text ?? '')
652
+ // 备注保留换行(放映面板与备注页都按原文显示),只做转义,不做 Markdown 清洗
653
+ const notes = String(source.notes ?? '').trim()
654
+ let bullets = []
655
+ if (Array.isArray(source.bullets)) {
656
+ bullets = source.bullets.map((item) => stripInlineMarkdown(String(item))).filter(Boolean)
657
+ } else if (typeof source.bullets === 'string' && source.bullets.trim() !== '') {
658
+ bullets = splitSentences(source.bullets)
659
+ }
660
+ if (layout === 'statement' && title === '' && text !== '') {
661
+ return { layout, kicker, title: text, subtitle: subtitle || '', bullets, ...(notes !== '' ? { notes } : {}) }
662
+ }
663
+ if (layout === 'quote') {
664
+ const quoteText = title !== '' ? title : text
665
+ if (quoteText === '') return { layout: 'statement', kicker, title: subtitle, subtitle: '', bullets, ...(notes !== '' ? { notes } : {}) }
666
+ return { layout, kicker, title: truncate(quoteText, 220), subtitle, ...(notes !== '' ? { notes } : {}) }
667
+ }
668
+ if (layout === 'table') {
669
+ let rows = []
670
+ if (Array.isArray(source.rows)) {
671
+ rows = source.rows
642
672
  .map((row) => (Array.isArray(row) ? row : [row]).map((cell) => stripInlineMarkdown(String(cell))))
643
673
  .filter((row) => row.some((cell) => cell !== ''))
644
- .slice(0, 9)
645
- .map((row) => row.slice(0, 8).map((cell) => truncate(cell, 60)))
646
- }
647
- if (rows.length === 0) {
648
- // 没有表格数据的 table 页退化成要点页,避免产出空白版式
649
- return { layout: 'bullets', kicker, title, subtitle, bullets, ...(notes !== '' ? { notes } : {}) }
650
- }
651
- return { layout, kicker: kicker || title, title, rows, ...(notes !== '' ? { notes } : {}) }
674
+ }
675
+ if (rows.length === 0) {
676
+ // 没有表格数据的 table 页退化成要点页,避免产出空白版式
677
+ return { layout: 'bullets', kicker, title, subtitle, bullets, ...(notes !== '' ? { notes } : {}) }
678
+ }
679
+ return { layout, kicker: kicker || title, title, rows, ...(notes !== '' ? { notes } : {}) }
680
+ }
681
+ return { layout, kicker, title, subtitle, text, bullets, ...(notes !== '' ? { notes } : {}) }
682
+ }
683
+
684
+ function checkSlideLimit(slides, limit) {
685
+ if (slides.length > limit) {
686
+ throw new Error('dsh-ppt:生成后共 ' + slides.length + ' 页,超过 maxSlides=' + limit
687
+ + ',请提高 maxSlides(最多 120)或拆分内容 / generated ' + slides.length + ' slides; raise maxSlides or split the deck')
652
688
  }
653
- return { layout, kicker, title, subtitle, text, bullets, ...(notes !== '' ? { notes } : {}) }
654
689
  }
655
690
 
656
- export function normalizeSlides(rawSlides, maxSlides = 60) {
657
- if (!Array.isArray(rawSlides) || rawSlides.length === 0) {
658
- throw new Error('dsh-ppt:slides 必须是非空数组(每个元素是 { layout, title, subtitle, kicker, bullets } 对象)')
659
- }
660
- const limit = clampInt(maxSlides, 60, 1, 120)
661
- const bounded = rawSlides.length > limit && limit >= 3
662
- ? [rawSlides[0], ...rawSlides.slice(1, limit - 1), rawSlides[rawSlides.length - 1]]
663
- : rawSlides.slice(0, limit)
664
- const slides = bounded.map(normalizeSlide)
665
- if (slides.length === 0) throw new Error('dsh-ppt:slides 规范化后为空')
666
- return slides
667
- }
668
-
669
- // ---------------------------------------------------------------------------
670
- // 构建入口
671
- // ---------------------------------------------------------------------------
672
-
673
- export function normalizeBuildOptions(options = {}) {
674
- const title = String(options.title ?? '').trim()
675
- if (title === '') throw new Error('dsh-ppt:title 不能为空')
676
- const theme = resolveTheme(options.theme)
677
- const language = resolveLanguage(options.lang)
678
- const motion = resolveMotion(options.motion)
679
- const maxSlides = clampInt(options.maxSlides, 60, 3, 120)
680
- let deck
681
- if (Array.isArray(options.slides) && options.slides.length > 0) {
682
- deck = {
683
- title,
684
- subtitle: stripInlineMarkdown(options.subtitle ?? ''),
685
- slides: normalizeSlides(options.slides, maxSlides),
686
- }
687
- } else {
688
- const content = String(options.content ?? '').trim()
689
- if (content === '') throw new Error('dsh-ppt:content 不能为空(或用 slides 传结构化幻灯片)')
690
- deck = parseMarkdownDeck(title, content, language.id)
691
- const slideLimit = clampInt(maxSlides, 60, 3, 120)
692
- if (deck.slides.length > slideLimit) {
693
- deck.slides = [deck.slides[0], ...deck.slides.slice(1, slideLimit - 1), deck.slides[deck.slides.length - 1]]
694
- }
695
- }
696
- if (deck.slides.length < 1) throw new Error('dsh-ppt:没有可生成的幻灯片')
697
- const outputDir = resolvePath(String(options.outputDir ?? '.').trim() || '.')
698
- const fileName = sanitizeFileName(options.fileName ?? title)
699
- const overwrite = options.overwrite === true
700
- return { title, theme, language, motion, deck, outputDir, fileName, overwrite }
701
- }
702
-
703
- /**
704
- * 三件套落盘:三份内容全部先写同目录临时文件,再逐个 rename 提交。
705
- * 任一步失败都清理临时文件,并把已提交的目标恢复为调用前的内容,
706
- * 避免出现「json/html 已更新、pptx 还是旧的」这类混版状态。
707
- */
708
- function commitDeckArtifacts(artifacts) {
709
- const stamp = process.pid.toString(36) + '-' + Date.now().toString(36) + '-' + Math.random().toString(36).slice(2, 8)
710
- const items = artifacts.map((item, index) => ({ ...item, tempPath: item.path + '.' + stamp + '-' + index + '.tmp' }))
711
- const removeTemp = (item) => {
712
- try {
713
- rmSync(item.tempPath, { force: true })
714
- } catch {}
715
- }
716
-
717
- // 阶段 0:记下已有产物内容用于回滚;读不出来(如被同名目录占用)先报错,不碰任何文件。
718
- const previous = new Map()
719
- for (const item of items) {
720
- if (!existsSync(item.path)) continue
721
- try {
722
- previous.set(item.path, readFileSync(item.path))
723
- } catch (error) {
724
- throw new Error('dsh-ppt:三件套写入失败(' + item.path + ' 已存在但无法读取),原文件未改动:' + error.message)
725
- }
726
- }
727
-
728
- // 阶段 1:全部写临时文件;这一步失败时目标文件尚未被改动。
729
- let written = 0
730
- try {
731
- for (const item of items) {
732
- writeFileSync(item.tempPath, item.data, item.encoding)
733
- written += 1
734
- }
735
- } catch (error) {
736
- for (const item of items.slice(0, written + 1)) removeTemp(item)
737
- throw new Error('dsh-ppt:写入临时文件失败(' + items[written].path + '),原三件套未改动:' + error.message)
738
- }
739
-
740
- // 阶段 2:逐个 rename 提交;中途失败则把已提交的目标回滚成旧内容。
741
- const committed = []
742
- try {
743
- for (const item of items) {
744
- renameSync(item.tempPath, item.path)
745
- committed.push(item)
746
- }
747
- } catch (error) {
748
- const failedPath = items[committed.length].path
749
- for (const item of items) removeTemp(item)
750
- for (const item of committed) {
751
- try {
752
- const previousData = previous.get(item.path)
753
- if (previousData === undefined) rmSync(item.path, { force: true })
754
- else writeFileSync(item.path, previousData)
755
- } catch {}
756
- }
757
- throw new Error('dsh-ppt:提交三件套失败(' + failedPath + '),已回滚为原文件:' + error.message)
758
- }
759
- }
760
-
761
- export function buildDeck(options = {}) {
762
- const normalized = normalizeBuildOptions(options)
763
- const { title, theme, language, motion, deck, outputDir, overwrite } = normalized
764
- mkdirSync(outputDir, { recursive: true })
765
- const fileName = resolveDeckFileName(outputDir, normalized.fileName, overwrite)
766
-
767
- const manifest = {
768
- version: DECK_VERSION,
769
- title,
770
- theme: theme.id,
771
- language: language.id,
772
- motion,
773
- slideCount: deck.slides.length,
774
- slides: deck.slides,
775
- }
776
- const jsonPath = resolvePath(outputDir, fileName + '.json')
777
- const htmlPath = resolvePath(outputDir, fileName + '.html')
778
- const pptxPath = resolvePath(outputDir, fileName + '.pptx')
779
-
780
- // 先生成三份内容再统一提交:生成阶段抛错时也不会留下半套文件。
781
- commitDeckArtifacts([
782
- { path: jsonPath, data: JSON.stringify(manifest, null, 2) + '\n', encoding: 'utf8' },
783
- { path: htmlPath, data: renderHtml(manifest, theme, language), encoding: 'utf8' },
784
- { path: pptxPath, data: buildPptx(manifest, theme, language) },
785
- ])
786
-
787
- return {
788
- ok: true,
789
- title,
790
- theme: theme.id,
791
- language: language.id,
792
- slideCount: deck.slides.length,
793
- outputDir,
794
- files: {
795
- html: htmlPath,
796
- pptx: pptxPath,
797
- json: jsonPath,
798
- },
799
- htmlPath,
800
- pptxPath,
801
- jsonPath,
802
- }
803
- }
804
-
805
- // ---------------------------------------------------------------------------
806
- // HTML 网页放映
807
- // ---------------------------------------------------------------------------
808
-
809
- export function renderHtml(manifest, theme, language) {
810
- const t = theme
811
- const lang = language
812
- const ui = lang.ui
813
- const motion = manifest.motion !== false
814
- const motionCss = motion
815
- ? `body.motion .slide.is-active{animation:slide-in .45s cubic-bezier(.22,.8,.36,1)}
816
- @keyframes slide-in{from{opacity:0;transform:translateY(24px)}to{opacity:1;transform:none}}
817
- body.motion .bullets li{
818
- opacity:0;animation:bullet-in .55s cubic-bezier(.22,.8,.36,1) forwards;
819
- animation-delay:calc(var(--i, 0)*90ms + .12s);
820
- }
821
- @keyframes bullet-in{from{opacity:0;transform:translateY(14px)}to{opacity:1;transform:none}}`
822
- : ''
823
- const slides = manifest.slides.map((slide, index) => renderHtmlSlide(slide, index, ui, lang.id)).join('\n')
824
- const themeLabel = t.name[lang.id] ?? t.name.en
825
- const total = manifest.slides.length
826
-
827
- return `<!DOCTYPE html>
828
- <html lang="${lang.attr}">
829
- <head>
830
- <meta charset="UTF-8">
831
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
832
- <title>${escapeHtml(manifest.title)}</title>
833
- <style>
834
- :root{
835
- --bg:${t.palette.bg};
836
- --panel:${t.palette.panel};
837
- --fg:${t.palette.fg};
838
- --muted:${t.palette.muted};
839
- --accent:${t.palette.accent};
840
- --accent2:${t.palette.accent2};
841
- --font-heading:${t.fonts.heading};
842
- --font-body:${t.fonts.body};
843
- }
844
- *{box-sizing:border-box}
845
- html,body{height:100%}
846
- body{
847
- margin:0;background:var(--bg);color:var(--fg);
848
- font-family:var(--font-body);overflow:hidden;
849
- -webkit-font-smoothing:antialiased;text-rendering:optimizeLegibility;
850
- }
851
- .slide{
852
- position:fixed;inset:0;display:none;flex-direction:column;justify-content:center;
853
- padding:clamp(34px,7vw,110px);overflow:hidden;
854
- }
855
- .slide::before{
856
- content:"";position:absolute;inset:-20%;pointer-events:none;z-index:-1;
857
- background:
858
- radial-gradient(42% 34% at 82% 18%, ${hexToRgba(t.palette.accent, t.dark ? 0.22 : 0.12)}, transparent 70%),
859
- radial-gradient(36% 30% at 12% 86%, ${hexToRgba(t.palette.accent2, t.dark ? 0.16 : 0.12)}, transparent 70%),
860
- radial-gradient(70% 60% at 50% 50%, ${hexToRgba(t.palette.panel, 0.55)}, transparent 100%);
861
- }
862
- .slide.is-active{display:flex}
863
- ${motionCss}
864
- .kicker{
865
- color:var(--accent);font-weight:700;letter-spacing:.18em;text-transform:uppercase;
866
- font-size:clamp(12px,1.3vw,18px);margin-bottom:22px;
867
- }
868
- h1,h2,.statement-title{font-family:var(--font-heading);line-height:1.06;letter-spacing:-.015em;margin:0}
869
- h1{font-size:clamp(44px,7.4vw,118px);max-width:20ch}
870
- h2{font-size:clamp(34px,5vw,82px);max-width:20ch}
871
- .subtitle{
872
- color:var(--muted);font-size:clamp(18px,2.3vw,34px);line-height:1.5;
873
- max-width:46em;margin-top:28px;
874
- }
875
- .meta{
876
- color:var(--muted);font-size:clamp(12px,1.2vw,16px);margin-top:48px;
877
- letter-spacing:.06em;
878
- }
879
- .bullets ul{margin:30px 0 0;padding:0;list-style:none;display:grid;gap:clamp(12px,1.6vw,24px)}
880
- .bullets li{
881
- position:relative;padding-left:clamp(28px,2.6vw,44px);
882
- font-size:clamp(20px,2.6vw,40px);line-height:1.35;max-width:24em;
883
- }
884
- .bullets li::before{
885
- content:"";position:absolute;left:0;top:.58em;width:.5em;height:.5em;
886
- background:var(--accent);border-radius:2px;box-shadow:.28em .28em 0 color-mix(in srgb, var(--accent2) 78%, transparent);
887
- }
888
- .section .kicker{margin-bottom:10px}
889
- .section .accent-line{width:min(180px,18vw);height:6px;background:var(--accent);margin:28px 0}
890
- .statement-title{
891
- font-size:clamp(34px,5.4vw,88px);max-width:22ch;font-weight:800;
892
- border-left:6px solid var(--accent);padding-left:clamp(22px,3vw,48px);
893
- }
894
- .closing{text-align:center;align-items:center}
895
- .closing h1,.closing .statement-title{font-size:clamp(52px,9vw,148px)}
896
- .closing .subtitle{color:var(--accent);font-weight:700}
897
- .cover h1{font-weight:900}
898
- .quote-mark{
899
- font-family:var(--font-heading);font-size:clamp(90px,13vw,210px);line-height:.62;
900
- color:var(--accent);margin-bottom:clamp(14px,2vw,30px);
901
- }
902
- .quote-text{
903
- font-family:var(--font-heading);font-size:clamp(26px,4.2vw,62px);line-height:1.28;
904
- font-weight:700;max-width:22ch;margin:0;
905
- }
906
- .quote-attr{color:var(--muted);margin-top:clamp(18px,2.6vw,34px);font-size:clamp(15px,1.8vw,26px);letter-spacing:.04em}
907
- table.deck-table{
908
- border-collapse:collapse;margin-top:clamp(20px,3vw,42px);width:100%;max-width:1120px;
909
- font-size:clamp(13px,1.55vw,23px);
910
- }
911
- .deck-table th{
912
- background:var(--accent);color:var(--bg);text-align:left;font-weight:700;
913
- padding:.6em .9em;letter-spacing:.02em;
914
- }
915
- .deck-table td{
916
- padding:.55em .9em;border-bottom:1px solid color-mix(in srgb, var(--muted) 34%, transparent);
917
- color:var(--fg);
918
- }
919
- .deck-table tbody tr:nth-child(even){background:color-mix(in srgb, var(--panel) 62%, transparent)}
920
- #progress{position:fixed;top:0;left:0;height:3px;width:0;background:var(--accent);z-index:30;transition:width .25s}
921
- #hud{
922
- position:fixed;right:22px;bottom:18px;z-index:30;display:flex;gap:14px;align-items:center;
923
- color:var(--muted);font-size:13px;letter-spacing:.08em;font-variant-numeric:tabular-nums;
924
- }
925
- #hud button{
926
- background:color-mix(in srgb, var(--panel) 88%, transparent);color:var(--fg);
927
- border:1px solid color-mix(in srgb, var(--muted) 45%, transparent);border-radius:99px;
928
- padding:7px 13px;font:inherit;cursor:pointer;
929
- }
930
- #hud button:hover{border-color:var(--accent);color:var(--accent)}
931
- #notes-panel{
932
- position:fixed;left:0;right:0;bottom:0;z-index:40;display:none;
933
- background:color-mix(in srgb, var(--panel) 96%, black 4%);
934
- border-top:2px solid var(--accent);
935
- padding:16px clamp(22px,4vw,64px) 20px;max-height:38vh;overflow:auto;
936
- }
937
- body.notes-open #notes-panel.has-notes{display:block}
938
- #notes-panel .notes-label{
939
- color:var(--accent);font-weight:700;letter-spacing:.14em;text-transform:uppercase;
940
- font-size:12px;margin-bottom:8px;
941
- }
942
- #notes-text{white-space:pre-wrap;line-height:1.65;font-size:15px;color:var(--fg)}
943
- body.overview .slide{display:flex !important;position:relative;inset:auto;width:100%;height:100vh}
944
- body.overview{overflow:auto}
945
- body.overview #progress,body.overview #hud{position:fixed}
946
- body.overview #notes-panel{display:none !important}
947
- @media (max-width:640px){
948
- #hud{right:12px;bottom:10px;gap:8px;font-size:11px}
949
- }
950
- @media print{
951
- html,body{height:auto;overflow:visible;background:#fff}
952
- .slide{position:relative;display:block !important;height:100vh;page-break-after:always;padding:48px}
953
- ${motion ? 'body.motion .bullets li{opacity:1 !important;animation:none !important}' : ''}
954
- #progress,#hud,#notes-panel{display:none !important}
955
- }
956
- </style>
957
- </head>
958
- <body class="${motion ? 'motion' : 'no-motion'}">
959
- <div id="progress" aria-hidden="true"></div>
960
- ${slides}
961
- <div id="hud" aria-live="polite">
962
- <span id="counter">${ui.slide} 1 ${ui.of} ${total}</span>
963
- <span id="theme-label">${ui.theme} · ${escapeHtml(themeLabel)}</span>
964
- <button id="notes-toggle" title="S">${escapeHtml(ui.notesToggle)}</button>
965
- <button id="fullscreen" title="F">⛶</button>
966
- </div>
967
- <div id="notes-panel" aria-live="polite">
968
- <div class="notes-label">${escapeHtml(ui.notesLabel)}</div>
969
- <div id="notes-text"></div>
970
- </div>
971
- <script>
972
- (() => {
973
- const slides = Array.from(document.querySelectorAll('.slide'));
974
- const counter = document.getElementById('counter');
975
- const progress = document.getElementById('progress');
976
- const fullscreenBtn = document.getElementById('fullscreen');
977
- const notesPanel = document.getElementById('notes-panel');
978
- const notesText = document.getElementById('notes-text');
979
- const notesBtn = document.getElementById('notes-toggle');
980
- let index = 0;
981
- const total = slides.length;
982
- const ui = ${JSON.stringify(ui).replace(/</g, '\\u003c')};
983
-
984
- function refreshNotes() {
985
- const notes = slides[index]?.dataset.notes || '';
986
- notesPanel.classList.toggle('has-notes', notes !== '');
987
- notesText.textContent = notes;
988
- }
989
-
990
- function go(next) {
991
- index = (next + total) % total;
992
- slides.forEach((slide, i) => slide.classList.toggle('is-active', i === index));
993
- counter.textContent = ui.slide + ' ' + (index + 1) + ' ' + ui.of + ' ' + total;
994
- progress.style.width = ((index + 1) / total * 100) + '%';
995
- refreshNotes();
996
- document.title = (index + 1) + ' / ' + total + ' · ' + ${JSON.stringify(manifest.title).replace(/</g, '\\u003c')};
997
- try { history.replaceState?.(null, '', '#slide-' + (index + 1)); } catch { /* file:// 下个别浏览器可能拒绝 */ }
998
- }
999
-
1000
- document.addEventListener('keydown', (event) => {
1001
- if (event.key === 'ArrowRight' || event.key === 'PageDown' || event.key === ' ') {
1002
- event.preventDefault(); go(index + 1);
1003
- } else if (event.key === 'ArrowLeft' || event.key === 'PageUp') {
1004
- event.preventDefault(); go(index - 1);
1005
- } else if (event.key === 'Home') {
1006
- event.preventDefault(); go(0);
1007
- } else if (event.key === 'End') {
1008
- event.preventDefault(); go(total - 1);
1009
- } else if (event.key.toLowerCase() === 'f') {
1010
- if (!document.fullscreenElement) document.documentElement.requestFullscreen?.();
1011
- else document.exitFullscreen?.();
1012
- } else if (event.key.toLowerCase() === 'g') {
1013
- document.body.classList.toggle('overview');
1014
- go(index);
1015
- } else if (event.key.toLowerCase() === 's') {
1016
- document.body.classList.toggle('notes-open');
1017
- } else if (event.key.toLowerCase() === 'p') {
1018
- window.print();
1019
- }
1020
- });
1021
-
1022
- let wheelLock = 0;
1023
- document.addEventListener('wheel', (event) => {
1024
- const now = Date.now();
1025
- if (now - wheelLock < 550 || document.body.classList.contains('overview')) return;
1026
- wheelLock = now;
1027
- if (Math.abs(event.deltaY) > 12) go(index + (event.deltaY > 0 ? 1 : -1));
1028
- }, { passive: true });
1029
-
1030
- let touchStartY = 0;
1031
- document.addEventListener('touchstart', (event) => { touchStartY = event.touches[0].clientY; }, { passive: true });
1032
- document.addEventListener('touchend', (event) => {
1033
- const delta = event.changedTouches[0].clientY - touchStartY;
1034
- if (Math.abs(delta) > 48) go(index + (delta < 0 ? 1 : -1));
1035
- }, { passive: true });
1036
-
1037
- fullscreenBtn.addEventListener('click', () => {
1038
- if (!document.fullscreenElement) document.documentElement.requestFullscreen?.();
1039
- else document.exitFullscreen?.();
1040
- });
1041
-
1042
- notesBtn.addEventListener('click', () => {
1043
- document.body.classList.toggle('notes-open');
1044
- });
1045
-
1046
- const start = Number.parseInt(location.hash?.replace('#slide-', ''), 10);
1047
- go(Number.isInteger(start) ? start - 1 : 0);
1048
- })();
1049
- </script>
1050
- </body>
1051
- </html>`
1052
- }
1053
-
1054
- function renderHtmlSlide(slide, index, ui, langId) {
1055
- const kicker = slide.kicker || (slide.layout === 'cover' ? ui.coverKicker : '')
1056
- const title = slide.title || ''
1057
- const subtitle = slide.subtitle || ''
1058
- const bullets = Array.isArray(slide.bullets) ? slide.bullets : []
1059
- const number = String(index + 1).padStart(2, '0')
1060
- let inner = ''
1061
- switch (slide.layout) {
1062
- case 'cover':
1063
- inner = '<div class="kicker">' + escapeHtml(kicker) + '</div>' +
1064
- '<h1>' + escapeHtml(title) + '</h1>' +
1065
- (subtitle !== '' ? '<div class="subtitle">' + escapeHtml(subtitle) + '</div>' : '') +
1066
- '<div class="meta">' + escapeHtml(ui.generatedBy) + '</div>'
1067
- break
1068
- case 'section':
1069
- inner = '<div class="kicker">' + escapeHtml(kicker) + '</div>' +
1070
- '<h2>' + escapeHtml(title) + '</h2>' +
1071
- '<div class="accent-line"></div>' +
1072
- (subtitle !== '' ? '<div class="subtitle">' + escapeHtml(subtitle) + '</div>' : '')
1073
- break
1074
- case 'statement':
1075
- inner = '<div class="kicker">' + escapeHtml(kicker) + '</div>' +
1076
- '<div class="statement-title">' + escapeHtml(title || slide.text || '') + '</div>' +
1077
- (subtitle !== '' ? '<div class="subtitle">' + escapeHtml(subtitle) + '</div>' : '')
1078
- break
1079
- case 'quote':
1080
- inner = '<div class="kicker">' + escapeHtml(kicker || ui.quoteKicker) + '</div>' +
1081
- '<div class="quote-mark" aria-hidden="true">\u201C</div>' +
1082
- '<blockquote class="quote-text">' + escapeHtml(title || slide.text || '') + '</blockquote>' +
1083
- (subtitle !== '' ? '<div class="quote-attr">\u2014\u2014 ' + escapeHtml(subtitle) + '</div>' : '')
1084
- break
1085
- case 'table': {
1086
- const rows = Array.isArray(slide.rows) ? slide.rows : []
1087
- const head = rows[0] ?? []
1088
- const body = rows.slice(1)
1089
- inner = '<div class="kicker">' + escapeHtml(kicker || ui.tableKicker) + '</div>' +
1090
- (title !== '' && title !== kicker ? '<h2>' + escapeHtml(title) + '</h2>' : '') +
1091
- '<table class="deck-table"><thead><tr>' +
1092
- head.map((cell) => '<th>' + escapeHtml(cell) + '</th>').join('') +
1093
- '</tr></thead><tbody>' +
1094
- body.map((row) => '<tr>' + row.map((cell) => '<td>' + escapeHtml(cell) + '</td>').join('') + '</tr>').join('') +
1095
- '</tbody></table>'
1096
- break
1097
- }
1098
- case 'closing':
1099
- inner = '<h1>' + escapeHtml(title || ui.closingTitle) + '</h1>' +
1100
- (subtitle !== '' ? '<div class="subtitle">' + escapeHtml(subtitle) + '</div>' : '') +
1101
- '<div class="meta">' + escapeHtml(ui.generatedBy) + '</div>'
1102
- break
1103
- case 'bullets':
1104
- default:
1105
- inner = '<div class="kicker">' + escapeHtml(kicker) + '</div>' +
1106
- '<h2>' + escapeHtml(title) + '</h2>' +
1107
- '<ul>' + bullets.map((bullet, bulletIndex) => '<li style="--i:' + bulletIndex + '">' + escapeHtml(bullet) + '</li>').join('') + '</ul>'
1108
- break
1109
- }
1110
- const notesAttr = typeof slide.notes === 'string' && slide.notes.trim() !== ''
1111
- ? ' data-notes="' + escapeHtml(slide.notes) + '"'
1112
- : ''
1113
- return '<section class="slide slide--' + escapeHtml(slide.layout || 'bullets') + '" data-index="' + number + '"' + notesAttr + '>' +
1114
- '<div class="slide-inner">' + inner + '</div></section>'
1115
- }
1116
-
1117
- function hexToRgba(hex, alpha) {
1118
- const value = String(hex).replace('#', '')
1119
- const full = value.length === 3 ? value.split('').map((c) => c + c).join('') : value
1120
- const num = Number.parseInt(full, 16)
1121
- const r = (num >> 16) & 255
1122
- const g = (num >> 8) & 255
1123
- const b = num & 255
1124
- return 'rgba(' + r + ',' + g + ',' + b + ',' + alpha + ')'
1125
- }
1126
-
1127
- // ---------------------------------------------------------------------------
1128
- // PPTX(OOXML 手写 + node:zlib zip)
1129
- // ---------------------------------------------------------------------------
1130
-
1131
- const EMU_W = 12192000
1132
- const EMU_H = 6858000
1133
-
1134
- function hex(value) {
1135
- return String(value).replace('#', '').toUpperCase()
1136
- }
1137
-
1138
- function pptxFontName(value) {
1139
- const match = /"?([^",]+)"?/.exec(String(value ?? ''))
1140
- return match?.[1]?.trim() || 'Arial'
1141
- }
1142
-
1143
- function paragraphXml(text, options = {}) {
1144
- const {
1145
- size = 2000,
1146
- color = 'FFFFFF',
1147
- bold = false,
1148
- lang = 'zh-CN',
1149
- align = 'l',
1150
- bullet = false,
1151
- font = 'Arial',
1152
- spaceBefore = 0,
1153
- spaceAfter = 0,
1154
- } = options
1155
- const runFont = pptxFontName(font)
1156
- let pPr = ''
1157
- if (bullet) {
1158
- pPr = '<a:pPr marL="285750" indent="-285750"><a:buFont typeface="Arial" panose="020B0604020202020204"/><a:buChar char="•"/></a:pPr>'
1159
- } else {
1160
- const parts = [] // align spacing 二选一
1161
- if (align !== 'l') parts.push('algn="' + align + '"')
1162
- if (spaceBefore > 0) parts.push('<a:spcBef><a:spcPts val="' + (spaceBefore / 100) + '"/></a:spcBef>')
1163
- if (spaceAfter > 0) parts.push('<a:spcAft><a:spcPts val="' + (spaceAfter / 100) + '"/></a:spcAft>')
1164
- pPr = '<a:pPr' + (parts.length > 0 ? ' ' + parts.join(' ') : '') + '><a:buNone/></a:pPr>'
1165
- }
1166
- return '<a:p>' + pPr +
1167
- '<a:r><a:rPr lang="' + lang + '" sz="' + size + '" b="' + (bold ? 1 : 0) + '" dirty="0">' +
1168
- '<a:solidFill><a:srgbClr val="' + hex(color) + '"/></a:solidFill>' +
1169
- '<a:latin typeface="' + escapeXml(runFont) + '"/><a:ea typeface="' + escapeXml(runFont) + '"/></a:rPr>' +
1170
- '<a:t>' + escapeXml(text) + '</a:t></a:r></a:p>'
1171
- }
1172
-
1173
- function textShapeXml(id, name, box, paragraphs, options = {}) {
1174
- const { x = 0, y = 0, w = EMU_W, h = EMU_H } = box
1175
- return '<p:sp>' +
1176
- '<p:nvSpPr><p:cNvPr id="' + id + '" name="' + escapeXml(name) + '"/><p:cNvSpPr txBox="1"/><p:nvPr/></p:nvSpPr>' +
1177
- '<p:spPr><a:xfrm><a:off x="' + x + '" y="' + y + '"/><a:ext cx="' + w + '" cy="' + h + '"/></a:xfrm>' +
1178
- '<a:prstGeom prst="rect"><a:avLst/></a:prstGeom><a:noFill/><a:ln/></p:spPr>' +
1179
- '<p:txBody><a:bodyPr wrap="square" rtlCol="0"><a:normAutofit/></a:bodyPr><a:lstStyle/>' +
1180
- paragraphs.join('') + '</p:txBody></p:sp>'
1181
- }
1182
-
1183
- function accentBarXml(id, name, box, color) {
1184
- const { x = 0, y = 0, w = EMU_W, h = EMU_H } = box
1185
- return '<p:sp>' +
1186
- '<p:nvSpPr><p:cNvPr id="' + id + '" name="' + escapeXml(name) + '"/><p:cNvSpPr/><p:nvPr/></p:nvSpPr>' +
1187
- '<p:spPr><a:xfrm><a:off x="' + x + '" y="' + y + '"/><a:ext cx="' + w + '" cy="' + h + '"/></a:xfrm>' +
1188
- '<a:prstGeom prst="rect"><a:avLst/></a:prstGeom>' +
1189
- '<a:solidFill><a:srgbClr val="' + hex(color) + '"/></a:solidFill><a:ln/></p:spPr>' +
1190
- '<p:txBody><a:bodyPr/><a:lstStyle/><a:p/></p:txBody></p:sp>'
1191
- }
1192
-
1193
- /** 原生 OOXML 表格(graphicFrame + a:tbl):首行主题色表头,隔行面板色。 */
1194
- function tableGraphicXml(id, name, box, rows, theme, langId) {
1195
- const p = theme.palette
1196
- const lang = langId || 'zh-CN'
1197
- const font = pptxFontName(theme.fonts.body)
1198
- const safeRows = rows.length > 0 ? rows : [['']]
1199
- const cols = Math.max(1, safeRows[0].length)
1200
- const colW = Math.floor(box.w / cols)
1201
- const grid = Array.from({ length: cols }, () => '<a:gridCol w="' + colW + '"/>').join('')
1202
- const rowH = 420000
1203
- const cellXml = (text, fill, color, bold) =>
1204
- '<a:tc><a:txBody><a:bodyPr anchor="ctr"/><a:lstStyle/><a:p><a:pPr algn="l"><a:buNone/></a:pPr>' +
1205
- '<a:r><a:rPr lang="' + lang + '" sz="1400" b="' + (bold ? 1 : 0) + '" dirty="0">' +
1206
- '<a:solidFill><a:srgbClr val="' + hex(color) + '"/></a:solidFill>' +
1207
- '<a:latin typeface="' + escapeXml(font) + '"/><a:ea typeface="' + escapeXml(font) + '"/></a:rPr>' +
1208
- '<a:t>' + escapeXml(text) + '</a:t></a:r></a:p></a:txBody>' +
1209
- '<a:tcPr marL="91440" marR="91440" anchor="ctr">' +
1210
- (fill !== '' ? '<a:solidFill><a:srgbClr val="' + hex(fill) + '"/></a:solidFill>' : '<a:noFill/>') +
1211
- '</a:tcPr></a:tc>'
1212
- const trs = safeRows.map((row, rowIndex) => {
1213
- const padded = Array.from({ length: cols }, (_, i) => row[i] ?? '')
1214
- const cells = rowIndex === 0
1215
- ? padded.map((c) => cellXml(c, p.accent, p.bg, true)).join('')
1216
- : padded.map((c) => cellXml(c, rowIndex % 2 === 1 ? p.panel : '', p.fg, false)).join('')
1217
- return '<a:tr h="' + rowH + '">' + cells + '</a:tr>'
1218
- }).join('')
1219
- const height = Math.max(1, safeRows.length) * rowH
1220
- return '<p:graphicFrame>' +
1221
- '<p:nvGraphicFramePr><p:cNvPr id="' + id + '" name="' + escapeXml(name) + '"/>' +
1222
- '<p:cNvGraphicFramePr><a:graphicFrameLocks noGrp="1"/></p:cNvGraphicFramePr><p:nvPr/></p:nvGraphicFramePr>' +
1223
- '<p:xfrm><a:off x="' + box.x + '" y="' + box.y + '"/><a:ext cx="' + box.w + '" cy="' + height + '"/></p:xfrm>' +
1224
- '<a:graphic><a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/table">' +
1225
- '<a:tbl><a:tblPr firstRow="1" bandRow="1"/>' +
1226
- '<a:tblGrid>' + grid + '</a:tblGrid>' + trs + '</a:tbl>' +
1227
- '</a:graphicData></a:graphic></p:graphicFrame>'
1228
- }
1229
-
1230
- function slideShapeList(slide, index, total, theme, langId) {
1231
- const p = theme.palette
1232
- const font = pptxFontName(theme.fonts.heading)
1233
- const bodyFont = pptxFontName(theme.fonts.body) // 保留:v0.1 后续用于统一正文字体
1234
- const lang = langId || 'zh-CN'
1235
- // PPTX 每个文本 run 的语言跟随 deck.lang(zh-CN / en-US),不再写死中文
1236
- const para = (content, options = {}) => paragraphXml(content, { lang, ...options })
1237
- const shapes = []
1238
- const kicker = slide.kicker || ''
1239
- const title = slide.title || ''
1240
- const subtitle = slide.subtitle || ''
1241
- const bullets = Array.isArray(slide.bullets) ? slide.bullets : []
1242
- const idBase = (index + 1) * 10
1243
- const footer = String(index + 1).padStart(2, '0') + ' / ' + String(total).padStart(2, '0')
1244
-
1245
- if (slide.layout === 'cover') {
1246
- shapes.push(accentBarXml(idBase + 1, 'Accent bar', { x: 914400, y: 2250000, w: 240000, h: 1600000 }, p.accent))
1247
- shapes.push(textShapeXml(idBase + 2, 'Title', { x: 1550000, y: 2160000, w: 9250000, h: 1800000 }, [
1248
- para(title, { size: 4400, color: p.fg, bold: true, font }),
1249
- ]))
1250
- if (subtitle !== '') {
1251
- shapes.push(textShapeXml(idBase + 3, 'Subtitle', { x: 1570000, y: 4150000, w: 9000000, h: 1200000 }, [
1252
- para(subtitle, { size: 2200, color: p.muted, font: theme.fonts.body }),
1253
- ]))
1254
- }
1255
- if (kicker !== '') {
1256
- shapes.push(textShapeXml(idBase + 4, 'Kicker', { x: 1570000, y: 5800000, w: 7000000, h: 500000 }, [
1257
- para(kicker, { size: 1400, color: p.accent, bold: true, font: theme.fonts.body }),
1258
- ]))
1259
- }
1260
- } else if (slide.layout === 'section') {
1261
- if (kicker !== '') {
1262
- shapes.push(textShapeXml(idBase + 1, 'Kicker', { x: 1050000, y: 2250000, w: 9000000, h: 500000 }, [
1263
- para(kicker, { size: 1600, color: p.accent, bold: true, font: theme.fonts.body }),
1264
- ]))
1265
- }
1266
- shapes.push(accentBarXml(idBase + 2, 'Accent bar', { x: 1050000, y: 2850000, w: 1600000, h: 160000 }, p.accent2))
1267
- shapes.push(textShapeXml(idBase + 3, 'Title', { x: 1050000, y: 3150000, w: 10200000, h: 1400000 }, [
1268
- para(title, { size: 4000, color: p.fg, bold: true, font }),
1269
- ]))
1270
- if (subtitle !== '') {
1271
- shapes.push(textShapeXml(idBase + 4, 'Subtitle', { x: 1070000, y: 4750000, w: 9000000, h: 900000 }, [
1272
- para(subtitle, { size: 1800, color: p.muted, font: theme.fonts.body }),
1273
- ]))
1274
- }
1275
- } else if (slide.layout === 'statement') {
1276
- shapes.push(accentBarXml(idBase + 1, 'Accent bar', { x: 914400, y: 1900000, w: 200000, h: 2800000 }, p.accent))
1277
- shapes.push(textShapeXml(idBase + 2, 'Statement', { x: 1500000, y: 1950000, w: 9400000, h: 2700000 }, [
1278
- para(title || slide.text || '', { size: 3600, color: p.fg, bold: true, font }),
1279
- ]))
1280
- if (subtitle !== '') {
1281
- shapes.push(textShapeXml(idBase + 3, 'Subtitle', { x: 1520000, y: 4900000, w: 9000000, h: 800000 }, [
1282
- para(subtitle, { size: 1800, color: p.muted, font: theme.fonts.body }),
1283
- ]))
1284
- }
1285
- } else if (slide.layout === 'quote') {
1286
- shapes.push(textShapeXml(idBase + 1, 'Quote mark', { x: 900000, y: 1050000, w: 1700000, h: 1900000 }, [
1287
- para('\u201C', { size: 9600, color: p.accent, bold: true, font }),
1288
- ]))
1289
- shapes.push(textShapeXml(idBase + 2, 'Quote', { x: 1050000, y: 2550000, w: 10100000, h: 2600000 }, [
1290
- para(title || slide.text || '', { size: 3000, color: p.fg, bold: true, font }),
1291
- ]))
1292
- if (subtitle !== '') {
1293
- shapes.push(textShapeXml(idBase + 3, 'Attribution', { x: 1070000, y: 5300000, w: 9000000, h: 600000 }, [
1294
- para('\u2014\u2014 ' + subtitle, { size: 1600, color: p.muted, font: theme.fonts.body }),
1295
- ]))
1296
- }
1297
- } else if (slide.layout === 'table') {
1298
- const hasTitle = title !== '' && title !== kicker
1299
- if (kicker !== '') {
1300
- shapes.push(textShapeXml(idBase + 1, 'Kicker', { x: 900000, y: 420000, w: 10000000, h: 420000 }, [
1301
- para(kicker, { size: 1400, color: p.accent, bold: true, font: theme.fonts.body }),
1302
- ]))
1303
- }
1304
- if (hasTitle) {
1305
- shapes.push(textShapeXml(idBase + 2, 'Title', { x: 900000, y: 920000, w: 10300000, h: 800000 }, [
1306
- para(title, { size: 3400, color: p.fg, bold: true, font }),
1307
- ]))
1308
- }
1309
- shapes.push(tableGraphicXml(idBase + 3, 'Table', { x: 900000, y: hasTitle ? 1950000 : 900000, w: 10300000 }, Array.isArray(slide.rows) ? slide.rows : [], theme, lang))
1310
- } else if (slide.layout === 'closing') {
1311
- shapes.push(textShapeXml(idBase + 1, 'Title', { x: 1050000, y: 2300000, w: 10200000, h: 1700000 }, [
1312
- para(title || '谢谢', { size: 5200, color: p.fg, bold: true, align: 'ctr', font }),
1313
- ]))
1314
- if (subtitle !== '') {
1315
- shapes.push(textShapeXml(idBase + 2, 'Subtitle', { x: 1050000, y: 4200000, w: 10200000, h: 900000 }, [
1316
- para(subtitle, { size: 2000, color: p.accent, bold: true, align: 'ctr', font: theme.fonts.body }),
1317
- ]))
1318
- }
1319
- } else {
1320
- // bullets(默认布局)
1321
- if (kicker !== '') {
1322
- shapes.push(textShapeXml(idBase + 1, 'Kicker', { x: 900000, y: 420000, w: 10000000, h: 420000 }, [
1323
- para(kicker, { size: 1400, color: p.accent, bold: true, font: theme.fonts.body }),
1324
- ]))
1325
- }
1326
- shapes.push(textShapeXml(idBase + 2, 'Title', { x: 900000, y: 920000, w: 10300000, h: 800000 }, [
1327
- para(title, { size: 3400, color: p.fg, bold: true, font }),
1328
- ]))
1329
- const bodyParagraphs = bullets.length > 0
1330
- ? bullets.map((bullet) => para(bullet, { size: 2000, color: p.fg, bullet: true, font: theme.fonts.body, spaceAfter: 600 }))
1331
- : [para(subtitle || '', { size: 2000, color: p.fg, font: theme.fonts.body })]
1332
- shapes.push(textShapeXml(idBase + 3, 'Body', { x: 1050000, y: 1850000, w: 10100000, h: 4500000 }, bodyParagraphs))
1333
- }
1334
-
1335
- shapes.push(textShapeXml(idBase + 9, 'Page number', { x: 10600000, y: 6250000, w: 1200000, h: 400000 }, [
1336
- para(footer, { size: 1000, color: p.muted, align: 'r', font: theme.fonts.body }),
1337
- ]))
1338
-
1339
- return shapes.join('')
1340
- }
1341
-
1342
- /**
1343
- * 原生逐条点击显现动画(PowerPoint「出现,按段落」的标准时序树):
1344
- * bldP 把正文文本框标记为按段落构建,主序列里每条要点一个点击节点。
1345
- */
1346
- function bulletTimingXml(spid, clicks) {
1347
- let id = 2
1348
- const nextId = () => { id += 1; return String(id) }
1349
- const clickPars = []
1350
- for (let i = 0; i < clicks; i += 1) {
1351
- clickPars.push(
1352
- '<p:par><p:cTn id="' + nextId() + '" fill="hold"><p:stCondLst><p:cond delay="indefinite"/></p:stCondLst><p:childTnLst>' +
1353
- '<p:par><p:cTn id="' + nextId() + '" presetID="1" presetClass="entr" presetSubtype="0" fill="hold" grpId="0" nodeType="clickEffect">' +
1354
- '<p:stCondLst><p:cond delay="0"/></p:stCondLst><p:childTnLst>' +
1355
- '<p:set><p:cBhvr><p:cTn id="' + nextId() + '" dur="1" fill="hold"><p:stCondLst><p:cond delay="0"/></p:stCondLst></p:cTn>' +
1356
- '<p:tgtEl><p:spTgt spid="' + spid + '"/></p:tgtEl>' +
1357
- '<p:attrNameLst><p:attrName>style.visibility</p:attrName></p:attrNameLst></p:cBhvr>' +
1358
- '<p:to><p:strVal val="visible"/></p:to></p:set>' +
1359
- '</p:childTnLst></p:cTn></p:par>' +
1360
- '</p:childTnLst></p:cTn></p:par>',
1361
- )
1362
- }
1363
- return '<p:timing><p:tnLst><p:par>' +
1364
- '<p:cTn id="1" dur="indefinite" restart="never" nodeType="tmRoot"><p:childTnLst>' +
1365
- '<p:seq concurrent="1" nextAc="seek"><p:cTn id="2" dur="indefinite" nodeType="mainSeq"><p:childTnLst>' +
1366
- clickPars.join('') +
1367
- '</p:childTnLst></p:cTn>' +
1368
- '<p:prevCondLst><p:cond evt="onPrev" delay="0"><p:tgtEl><p:sldTgt/></p:tgtEl></p:cond></p:prevCondLst>' +
1369
- '<p:nextCondLst><p:cond evt="onNext" delay="0"><p:tgtEl><p:sldTgt/></p:tgtEl></p:cond></p:nextCondLst>' +
1370
- '</p:seq></p:childTnLst></p:cTn></p:par></p:tnLst>' +
1371
- '<p:bldLst><p:bldP spid="' + spid + '" grpId="0"/></p:bldLst></p:timing>'
1372
- }
1373
-
1374
- function slideXml(slide, index, total, theme, langId, motion) {
1375
- const p = theme.palette
1376
- let motionXml = ''
1377
- if (motion) {
1378
- motionXml = '<p:transition spd="med"><p:fade/></p:transition>'
1379
- const bullets = Array.isArray(slide.bullets) ? slide.bullets : []
1380
- if (slide.layout === 'bullets' && bullets.length >= 2) {
1381
- motionXml += bulletTimingXml((index + 1) * 10 + 3, bullets.length)
1382
- }
1383
- }
1384
- return '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' +
1385
- '<p:sld xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" ' +
1386
- 'xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" ' +
1387
- 'xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main">' +
1388
- '<p:cSld><p:bg><p:bgPr><a:solidFill><a:srgbClr val="' + hex(p.bg) + '"/></a:solidFill><a:effectLst/></p:bgPr></p:bg>' +
1389
- '<p:spTree><p:nvGrpSpPr><p:cNvPr id="1" name=""/><p:cNvGrpSpPr/><p:nvPr/></p:nvGrpSpPr>' +
1390
- '<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>' +
1391
- slideShapeList(slide, index, total, theme, langId) +
1392
- '</p:spTree></p:cSld>' +
1393
- '<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>' +
1394
- motionXml +
1395
- '</p:sld>'
1396
- }
1397
-
1398
- function slideRelXml(hasNotes, slideIndex) {
1399
- const notesRel = hasNotes
1400
- ? '<Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/notesSlide" Target="../notesSlides/notesSlide' + slideIndex + '.xml"/>'
1401
- : ''
1402
- return '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' +
1403
- '<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">' +
1404
- '<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideLayout" Target="../slideLayouts/slideLayout1.xml"/>' +
1405
- notesRel +
1406
- '</Relationships>'
1407
- }
1408
-
1409
- function presentationXml(slideCount, hasNotesMaster) {
1410
- const slideIds = Array.from({ length: slideCount }, (_, i) =>
1411
- '<p:sldId id="' + (256 + i) + '" r:id="rId' + (i + 2) + '"/>').join('')
1412
- const notesMasterId = hasNotesMaster
1413
- ? '<p:notesMasterIdLst><p:notesMasterId id="2147483649" r:id="rId' + (slideCount + 2) + '"/></p:notesMasterIdLst>'
1414
- : ''
1415
- return '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' +
1416
- '<p:presentation xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" ' +
1417
- 'xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" ' +
1418
- 'xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main">' +
1419
- '<p:sldMasterIdLst><p:sldMasterId id="2147483648" r:id="rId1"/></p:sldMasterIdLst>' +
1420
- '<p:sldIdLst>' + slideIds + '</p:sldIdLst>' +
1421
- notesMasterId +
1422
- '<p:sldSz cx="' + EMU_W + '" cy="' + EMU_H + '" type="screen16x9"/>' +
1423
- '<p:notesSz cx="6858000" cy="9144000"/>' +
1424
- '</p:presentation>'
1425
- }
1426
-
1427
- function presentationRelXml(slideCount, hasNotesMaster) {
1428
- const slideRels = Array.from({ length: slideCount }, (_, i) =>
1429
- '<Relationship Id="rId' + (i + 2) + '" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide" Target="slides/slide' + (i + 1) + '.xml"/>').join('')
1430
- const notesMasterRel = hasNotesMaster
1431
- ? '<Relationship Id="rId' + (slideCount + 2) + '" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/notesMaster" Target="notesMasters/notesMaster1.xml"/>'
1432
- : ''
1433
- return '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' +
1434
- '<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">' +
1435
- '<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideMaster" Target="slideMasters/slideMaster1.xml"/>' +
1436
- slideRels +
1437
- notesMasterRel +
1438
- '</Relationships>'
1439
- }
1440
-
1441
- function notesMasterXml() {
1442
- return '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' +
1443
- '<p:notesMaster xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" ' +
1444
- 'xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" ' +
1445
- 'xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main">' +
1446
- '<p:cSld><p:spTree><p:nvGrpSpPr><p:cNvPr id="1" name=""/><p:cNvGrpSpPr/><p:nvPr/></p:nvGrpSpPr>' +
1447
- '<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>' +
1448
- '</p:spTree></p:cSld>' +
1449
- '<p:clrMap bg1="lt1" tx1="dk1" bg2="lt2" tx2="dk2" accent1="accent1" accent2="accent2" accent3="accent3" accent4="accent4" accent5="accent5" accent6="accent6" hlink="hlink" folHlink="folHlink"/>' +
1450
- '<p:notesStyle><a:lvl1pPr><a:defRPr sz="1200"/></a:lvl1pPr></p:notesStyle>' +
1451
- '</p:notesMaster>'
1452
- }
1453
-
1454
- function notesMasterRelXml() {
1455
- return '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' +
1456
- '<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">' +
1457
- '<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme" Target="../theme/theme1.xml"/>' +
1458
- '</Relationships>'
1459
- }
1460
-
1461
- function notesSlideXml(notes, langId) {
1462
- const lang = langId || 'zh-CN'
1463
- const paragraphs = String(notes ?? '').split('\n')
1464
- .filter((line) => line.trim() !== '')
1465
- .map((line) => '<a:p><a:r><a:rPr lang="' + lang + '" sz="1200" dirty="0"/><a:t>' + escapeXml(line) + '</a:t></a:r></a:p>')
1466
- .join('')
1467
- return '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' +
1468
- '<p:notes xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" ' +
1469
- 'xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" ' +
1470
- 'xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main">' +
1471
- '<p:cSld><p:spTree><p:nvGrpSpPr><p:cNvPr id="1" name=""/><p:cNvGrpSpPr/><p:nvPr/></p:nvGrpSpPr>' +
1472
- '<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>' +
1473
- '<p:sp><p:nvSpPr><p:cNvPr id="2" name="Slide Image Placeholder 1"/><p:cNvSpPr/><p:nvPr><p:ph type="sldImg"/></p:nvPr></p:nvSpPr><p:spPr/></p:sp>' +
1474
- '<p:sp><p:nvSpPr><p:cNvPr id="3" name="Notes Placeholder 2"/><p:cNvSpPr/><p:nvPr><p:ph type="body" idx="1"/></p:nvPr></p:nvSpPr><p:spPr/>' +
1475
- '<p:txBody><a:bodyPr/><a:lstStyle/>' + paragraphs + '</p:txBody></p:sp>' +
1476
- '</p:spTree></p:cSld>' +
1477
- '<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>' +
1478
- '</p:notes>'
1479
- }
1480
-
1481
- function notesSlideRelXml(slideIndex) {
1482
- return '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' +
1483
- '<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">' +
1484
- '<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide" Target="../slides/slide' + slideIndex + '.xml"/>' +
1485
- '<Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/notesMaster" Target="../notesMasters/notesMaster1.xml"/>' +
1486
- '</Relationships>'
1487
- }
1488
-
1489
- function slideMasterXml(theme) {
1490
- const p = theme.palette
1491
- const levels = Array.from({ length: 9 }, (_, i) => {
1492
- const sz = Math.max(1100, 2000 - i * 100)
1493
- return '<a:lvl' + (i + 1) + 'pPr marL="' + (342900 + i * 342900) + '" indent="' + (-342900 - i * 0) + '">' +
1494
- '<a:defRPr sz="' + sz + '"><a:solidFill><a:srgbClr val="' + hex(p.fg) + '"/></a:solidFill><a:latin typeface="' + escapeXml(pptxFontName(theme.fonts.body)) + '"/></a:defRPr></a:lvl' + (i + 1) + 'pPr>'
1495
- }).join('')
1496
- return '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' +
1497
- '<p:sldMaster xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" ' +
1498
- 'xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" ' +
1499
- 'xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main">' +
1500
- '<p:cSld><p:spTree><p:nvGrpSpPr><p:cNvPr id="1" name=""/><p:cNvGrpSpPr/><p:nvPr/></p:nvGrpSpPr>' +
1501
- '<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>' +
1502
- '</p:spTree></p:cSld>' +
1503
- '<p:clrMap bg1="lt1" tx1="dk1" bg2="lt2" tx2="dk2" accent1="accent1" accent2="accent2" accent3="accent3" accent4="accent4" accent5="accent5" accent6="accent6" hlink="hlink" folHlink="folHlink"/>' +
1504
- '<p:sldLayoutIdLst><p:sldLayoutId id="2147483649" r:id="rId1"/></p:sldLayoutIdLst>' +
1505
- '<p:txStyles><p:titleStyle>' + levels + '</p:titleStyle><p:bodyStyle>' + levels + '</p:bodyStyle><p:otherStyle>' + levels + '</p:otherStyle></p:txStyles>' +
1506
- '</p:sldMaster>'
1507
- }
1508
-
1509
- function slideMasterRelXml() {
1510
- return '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' +
1511
- '<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">' +
1512
- '<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideLayout" Target="../slideLayouts/slideLayout1.xml"/>' +
1513
- '<Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme" Target="../theme/theme1.xml"/>' +
1514
- '</Relationships>'
1515
- }
1516
-
1517
- function slideLayoutXml(theme) {
1518
- return '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' +
1519
- '<p:sldLayout xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" ' +
1520
- 'xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" ' +
1521
- 'xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main" type="blank" preserve="1">' +
1522
- '<p:cSld name="Blank"><p:spTree><p:nvGrpSpPr><p:cNvPr id="1" name=""/><p:cNvGrpSpPr/><p:nvPr/></p:nvGrpSpPr>' +
1523
- '<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>' +
1524
- '</p:spTree></p:cSld>' +
1525
- '<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>' +
1526
- '</p:sldLayout>'
1527
- }
1528
-
1529
- function slideLayoutRelXml() {
1530
- return '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' +
1531
- '<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">' +
1532
- '<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideMaster" Target="../slideMasters/slideMaster1.xml"/>' +
1533
- '</Relationships>'
1534
- }
1535
-
1536
- function themeXml(theme) {
1537
- const p = theme.palette
1538
- const color = (name, value) => '<a:' + name + '><a:srgbClr val="' + hex(value) + '"/></a:' + name + '>'
1539
- return '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' +
1540
- '<a:theme xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" name="dsh-ppt ' + escapeXml(theme.name.en) + '">' +
1541
- '<a:themeElements>' +
1542
- '<a:clrScheme name="dsh-ppt">' +
1543
- color('dk1', p.fg) + color('lt1', p.bg) + color('dk2', p.muted) + color('lt2', p.panel) +
1544
- color('accent1', p.accent) + color('accent2', p.accent2) + color('accent3', p.fg) +
1545
- color('accent4', p.muted) + color('accent5', p.accent) + color('accent6', p.accent2) +
1546
- color('hlink', p.accent) + color('folHlink', p.accent2) +
1547
- '</a:clrScheme>' +
1548
- '<a:fontScheme name="dsh-ppt">' +
1549
- '<a:majorFont><a:latin typeface="' + escapeXml(pptxFontName(theme.fonts.heading)) + '"/><a:ea typeface=""/><a:cs typeface=""/></a:majorFont>' +
1550
- '<a:minorFont><a:latin typeface="' + escapeXml(pptxFontName(theme.fonts.body)) + '"/><a:ea typeface=""/><a:cs typeface=""/></a:minorFont>' +
1551
- '</a:fontScheme>' +
1552
- '<a:fmtScheme name="dsh-ppt">' +
1553
- '<a:fillStyleLst>' +
1554
- '<a:solidFill><a:schemeClr val="phClr"/></a:solidFill>' +
1555
- '<a:solidFill><a:schemeClr val="phClr"/></a:solidFill>' +
1556
- '<a:solidFill><a:schemeClr val="phClr"/></a:solidFill>' +
1557
- '</a:fillStyleLst>' +
1558
- '<a:lnStyleLst><a:ln w="6350" cap="flat" cmpd="sng" algn="ctr"><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:prstDash val="solid"/></a:ln><a:ln w="12700" cap="flat" cmpd="sng" algn="ctr"><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:prstDash val="solid"/></a:ln><a:ln w="19050" cap="flat" cmpd="sng" algn="ctr"><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:prstDash val="solid"/></a:ln></a:lnStyleLst>' +
1559
- '<a:effectStyleLst><a:effectStyle><a:effectLst/></a:effectStyle><a:effectStyle><a:effectLst/></a:effectStyle><a:effectStyle><a:effectLst/></a:effectStyle></a:effectStyleLst>' +
1560
- '<a:bgFillStyleLst><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:solidFill><a:schemeClr val="phClr"/></a:solidFill></a:bgFillStyleLst>' +
1561
- '</a:fmtScheme>' +
1562
- '</a:themeElements>' +
1563
- '<a:objectDefaults/><a:extraClrSchemeLst/>' +
1564
- '</a:theme>'
1565
- }
1566
-
1567
- function contentTypesXml(slideCount, noteIndexes) {
1568
- const overrides = Array.from({ length: slideCount }, (_, i) =>
1569
- '<Override PartName="/ppt/slides/slide' + (i + 1) + '.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.slide+xml"/>').join('')
1570
- const notesOverrides = noteIndexes.map((index) =>
1571
- '<Override PartName="/ppt/notesSlides/notesSlide' + (index + 1) + '.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.notesSlide+xml"/>').join('')
1572
- const notesMasterOverride = noteIndexes.length > 0
1573
- ? '<Override PartName="/ppt/notesMasters/notesMaster1.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.notesMaster+xml"/>'
1574
- : ''
1575
- return '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' +
1576
- '<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">' +
1577
- '<Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>' +
1578
- '<Default Extension="xml" ContentType="application/xml"/>' +
1579
- '<Override PartName="/ppt/presentation.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.presentation.main+xml"/>' +
1580
- '<Override PartName="/ppt/slideMasters/slideMaster1.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.slideMaster+xml"/>' +
1581
- '<Override PartName="/ppt/slideLayouts/slideLayout1.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.slideLayout+xml"/>' +
1582
- '<Override PartName="/ppt/theme/theme1.xml" ContentType="application/vnd.openxmlformats-officedocument.theme+xml"/>' +
1583
- '<Override PartName="/docProps/core.xml" ContentType="application/vnd.openxmlformats-package.core-properties+xml"/>' +
1584
- '<Override PartName="/docProps/app.xml" ContentType="application/vnd.openxmlformats-officedocument.extended-properties+xml"/>' +
1585
- notesMasterOverride +
1586
- overrides +
1587
- notesOverrides +
1588
- '</Types>'
1589
- }
1590
-
1591
- function rootRelXml() {
1592
- return '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' +
1593
- '<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">' +
1594
- '<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="ppt/presentation.xml"/>' +
1595
- '<Relationship Id="rId2" Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties" Target="docProps/core.xml"/>' +
1596
- '<Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties" Target="docProps/app.xml"/>' +
1597
- '</Relationships>'
1598
- }
1599
-
1600
- function coreXml(title) {
1601
- return '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' +
1602
- '<cp:coreProperties xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties" ' +
1603
- 'xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" ' +
1604
- 'xmlns:dcmitype="http://purl.org/dc/dcmitype/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">' +
1605
- '<dc:title>' + escapeXml(title) + '</dc:title><dc:creator>dsh-ppt</dc:creator>' +
1606
- '<cp:lastModifiedBy>dsh-ppt</cp:lastModifiedBy>' +
1607
- '</cp:coreProperties>'
1608
- }
1609
-
1610
- function appXml(slideCount, notesCount) {
1611
- return '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' +
1612
- '<Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/extended-properties" ' +
1613
- 'xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes">' +
1614
- '<Application>dsh-ppt</Application><PresentationFormat>Widescreen</PresentationFormat>' +
1615
- '<Slides>' + slideCount + '</Slides><Notes>' + notesCount + '</Notes><HiddenSlides>0</HiddenSlides>' +
1616
- '</Properties>'
1617
- }
1618
-
1619
- function buildZip(entries) {
1620
- const chunks = []
1621
- const central = []
1622
- let offset = 0
1623
-
1624
- for (const entry of entries) {
1625
- const entryOffset = offset
1626
- const name = Buffer.from(entry.name, 'utf8')
1627
- const data = Buffer.isBuffer(entry.data) ? entry.data : Buffer.from(String(entry.data), 'utf8')
1628
- const crc = crc32(data)
1629
- const compressed = deflateRawSync(data)
1630
- const method = 8
1631
- const nameLength = name.length
1632
- const localHeader = Buffer.alloc(30)
1633
- localHeader.writeUInt32LE(0x04034b50, 0)
1634
- localHeader.writeUInt16LE(20, 4)
1635
- localHeader.writeUInt16LE(0x0800, 6) // UTF-8 文件名
1636
- localHeader.writeUInt16LE(method, 8)
1637
- localHeader.writeUInt16LE(0, 10) // DOS time
1638
- localHeader.writeUInt16LE(0x21, 12) // DOS date 1980-01-01
1639
- localHeader.writeUInt32LE(crc, 14)
1640
- localHeader.writeUInt32LE(compressed.length, 18)
1641
- localHeader.writeUInt32LE(data.length, 22)
1642
- localHeader.writeUInt16LE(nameLength, 26)
1643
- localHeader.writeUInt16LE(0, 28)
1644
-
1645
- chunks.push(localHeader, name, compressed)
1646
- offset += 30 + nameLength + compressed.length
1647
-
1648
- const centralHeader = Buffer.alloc(46)
1649
- centralHeader.writeUInt32LE(0x02014b50, 0)
1650
- centralHeader.writeUInt16LE(20, 4)
1651
- centralHeader.writeUInt16LE(20, 6)
1652
- centralHeader.writeUInt16LE(0x0800, 8)
1653
- centralHeader.writeUInt16LE(method, 10)
1654
- centralHeader.writeUInt16LE(0, 12)
1655
- centralHeader.writeUInt16LE(0x21, 14)
1656
- centralHeader.writeUInt32LE(crc, 16)
1657
- centralHeader.writeUInt32LE(compressed.length, 20)
1658
- centralHeader.writeUInt32LE(data.length, 24)
1659
- centralHeader.writeUInt16LE(nameLength, 28)
1660
- centralHeader.writeUInt16LE(0, 30)
1661
- centralHeader.writeUInt16LE(0, 32)
1662
- centralHeader.writeUInt16LE(0, 34)
1663
- centralHeader.writeUInt16LE(0, 36)
1664
- centralHeader.writeUInt32LE(0, 38)
1665
- centralHeader.writeUInt32LE(entryOffset, 42)
1666
- central.push(centralHeader, name)
1667
- }
1668
-
1669
- const centralOffset = offset
1670
- const centralSize = central.reduce((sum, part) => sum + part.length, 0)
1671
- const end = Buffer.alloc(22)
1672
- end.writeUInt32LE(0x06054b50, 0)
1673
- end.writeUInt16LE(0, 4)
1674
- end.writeUInt16LE(0, 6)
1675
- end.writeUInt16LE(entries.length, 8)
1676
- end.writeUInt16LE(entries.length, 10)
1677
- end.writeUInt32LE(centralSize, 12)
1678
- end.writeUInt32LE(centralOffset, 16)
1679
- end.writeUInt16LE(0, 20)
1680
-
1681
- chunks.push(...central, end)
1682
- return Buffer.concat(chunks)
1683
- }
1684
-
1685
- let CRC_TABLE = null
1686
- function crc32(buffer) {
1687
- if (CRC_TABLE === null) {
1688
- CRC_TABLE = new Int32Array(256)
1689
- for (let n = 0; n < 256; n += 1) {
1690
- let c = n
1691
- for (let k = 0; k < 8; k += 1) c = (c & 1) ? (0xedb88320 ^ (c >>> 1)) : (c >>> 1)
1692
- CRC_TABLE[n] = c
1693
- }
1694
- }
1695
- let crc = 0xffffffff
1696
- for (let i = 0; i < buffer.length; i += 1) {
1697
- crc = CRC_TABLE[(crc ^ buffer[i]) & 0xff] ^ (crc >>> 8)
1698
- }
1699
- return (crc ^ 0xffffffff) >>> 0
1700
- }
1701
-
1702
- export function buildPptx(manifest, themeInput, languageInput) {
1703
- const theme = themeInput?.id ? themeInput : resolveTheme(themeInput)
1704
- const language = languageInput?.id ? languageInput : resolveLanguage(languageInput)
1705
- const motion = manifest.motion !== false
1706
- const slides = manifest.slides
1707
- const noteIndexes = []
1708
- slides.forEach((slide, index) => {
1709
- if (typeof slide.notes === 'string' && slide.notes.trim() !== '') noteIndexes.push(index)
1710
- })
1711
- const hasNotesMaster = noteIndexes.length > 0
1712
- const entries = [
1713
- { name: '[Content_Types].xml', data: contentTypesXml(slides.length, noteIndexes) },
1714
- { name: '_rels/.rels', data: rootRelXml() },
1715
- { name: 'docProps/app.xml', data: appXml(slides.length, noteIndexes.length) },
1716
- { name: 'docProps/core.xml', data: coreXml(manifest.title) },
1717
- { name: 'ppt/presentation.xml', data: presentationXml(slides.length, hasNotesMaster) },
1718
- { name: 'ppt/_rels/presentation.xml.rels', data: presentationRelXml(slides.length, hasNotesMaster) },
1719
- { name: 'ppt/slideMasters/slideMaster1.xml', data: slideMasterXml(theme) },
1720
- { name: 'ppt/slideMasters/_rels/slideMaster1.xml.rels', data: slideMasterRelXml() },
1721
- { name: 'ppt/slideLayouts/slideLayout1.xml', data: slideLayoutXml(theme) },
1722
- { name: 'ppt/slideLayouts/_rels/slideLayout1.xml.rels', data: slideLayoutRelXml() },
1723
- { name: 'ppt/theme/theme1.xml', data: themeXml(theme) },
1724
- ]
1725
- if (hasNotesMaster) {
1726
- entries.push({ name: 'ppt/notesMasters/notesMaster1.xml', data: notesMasterXml() })
1727
- entries.push({ name: 'ppt/notesMasters/_rels/notesMaster1.xml.rels', data: notesMasterRelXml() })
1728
- }
1729
- slides.forEach((slide, index) => {
1730
- const hasNotes = noteIndexes.includes(index)
1731
- entries.push({ name: 'ppt/slides/slide' + (index + 1) + '.xml', data: slideXml(slide, index, slides.length, theme, language.attr, motion) })
1732
- entries.push({ name: 'ppt/slides/_rels/slide' + (index + 1) + '.xml.rels', data: slideRelXml(hasNotes, index + 1) })
1733
- if (hasNotes) {
1734
- entries.push({ name: 'ppt/notesSlides/notesSlide' + (index + 1) + '.xml', data: notesSlideXml(slide.notes, language.attr) })
1735
- entries.push({ name: 'ppt/notesSlides/_rels/notesSlide' + (index + 1) + '.xml.rels', data: notesSlideRelXml(index + 1) })
1736
- }
1737
- })
1738
- return buildZip(entries)
1739
- }
691
+ export function normalizeSlides(rawSlides, maxSlides = 60, lang = 'zh') {
692
+ if (!Array.isArray(rawSlides) || rawSlides.length === 0) {
693
+ throw new Error('dsh-ppt:slides 必须是非空数组(每个元素是 { layout, title, subtitle, kicker, bullets } 对象)')
694
+ }
695
+ const limit = clampInt(maxSlides, 60, 1, 120)
696
+ const ui = resolveLanguage(lang).ui
697
+ const slides = rawSlides.map(normalizeSlide).flatMap(slide => slide.layout === 'table'
698
+ ? paginateTable(slide, ui.continuation) : [slide])
699
+ checkSlideLimit(slides, limit)
700
+ if (slides.length === 0) throw new Error('dsh-ppt:slides 规范化后为空')
701
+ return slides
702
+ }
703
+
704
+ // ---------------------------------------------------------------------------
705
+ // 构建入口
706
+ // ---------------------------------------------------------------------------
707
+
708
+ export function normalizeBuildOptions(options = {}) {
709
+ const title = String(options.title ?? '').trim()
710
+ if (title === '') throw new Error('dsh-ppt:title 不能为空')
711
+ const theme = resolveTheme(options.theme)
712
+ const language = resolveLanguage(options.lang)
713
+ const motion = resolveMotion(options.motion)
714
+ const maxSlides = clampInt(options.maxSlides, 60, 3, 120)
715
+ let deck
716
+ if (Array.isArray(options.slides) && options.slides.length > 0) {
717
+ deck = {
718
+ title,
719
+ subtitle: stripInlineMarkdown(options.subtitle ?? ''),
720
+ slides: normalizeSlides(options.slides, maxSlides, language.id),
721
+ }
722
+ } else {
723
+ const content = String(options.content ?? '').trim()
724
+ if (content === '') throw new Error('dsh-ppt:content 不能为空(或用 slides 传结构化幻灯片)')
725
+ deck = parseMarkdownDeck(title, content, language.id)
726
+ checkSlideLimit(deck.slides, maxSlides)
727
+ }
728
+ if (deck.slides.length < 1) throw new Error('dsh-ppt:没有可生成的幻灯片')
729
+ const outputDir = resolvePath(String(options.outputDir ?? '.').trim() || '.')
730
+ const fileName = sanitizeFileName(options.fileName ?? title)
731
+ const overwrite = options.overwrite === true
732
+ return { title, theme, language, motion, deck, outputDir, fileName, overwrite }
733
+ }
734
+
735
+ /**
736
+ * 三件套落盘:三份内容全部先写同目录临时文件,再逐个 rename 提交。
737
+ * 任一步失败都清理临时文件,并把已提交的目标恢复为调用前的内容,
738
+ * 避免出现「json/html 已更新、pptx 还是旧的」这类混版状态。
739
+ */
740
+ function commitDeckArtifacts(artifacts) {
741
+ const stamp = process.pid.toString(36) + '-' + Date.now().toString(36) + '-' + Math.random().toString(36).slice(2, 8)
742
+ const items = artifacts.map((item, index) => ({ ...item, tempPath: item.path + '.' + stamp + '-' + index + '.tmp' }))
743
+ const removeTemp = (item) => {
744
+ try {
745
+ rmSync(item.tempPath, { force: true })
746
+ } catch {}
747
+ }
748
+
749
+ // 阶段 0:记下已有产物内容用于回滚;读不出来(如被同名目录占用)先报错,不碰任何文件。
750
+ const previous = new Map()
751
+ for (const item of items) {
752
+ if (!existsSync(item.path)) continue
753
+ try {
754
+ previous.set(item.path, readFileSync(item.path))
755
+ } catch (error) {
756
+ throw new Error('dsh-ppt:三件套写入失败(' + item.path + ' 已存在但无法读取),原文件未改动:' + error.message)
757
+ }
758
+ }
759
+
760
+ // 阶段 1:全部写临时文件;这一步失败时目标文件尚未被改动。
761
+ let written = 0
762
+ try {
763
+ for (const item of items) {
764
+ writeFileSync(item.tempPath, item.data, item.encoding)
765
+ written += 1
766
+ }
767
+ } catch (error) {
768
+ for (const item of items.slice(0, written + 1)) removeTemp(item)
769
+ throw new Error('dsh-ppt:写入临时文件失败(' + items[written].path + '),原三件套未改动:' + error.message)
770
+ }
771
+
772
+ // 阶段 2:逐个 rename 提交;中途失败则把已提交的目标回滚成旧内容。
773
+ const committed = []
774
+ try {
775
+ for (const item of items) {
776
+ renameSync(item.tempPath, item.path)
777
+ committed.push(item)
778
+ }
779
+ } catch (error) {
780
+ const failedPath = items[committed.length].path
781
+ for (const item of items) removeTemp(item)
782
+ for (const item of committed) {
783
+ try {
784
+ const previousData = previous.get(item.path)
785
+ if (previousData === undefined) rmSync(item.path, { force: true })
786
+ else writeFileSync(item.path, previousData)
787
+ } catch {}
788
+ }
789
+ throw new Error('dsh-ppt:提交三件套失败(' + failedPath + '),已回滚为原文件:' + error.message)
790
+ }
791
+ }
792
+
793
+ export function buildDeck(options = {}) {
794
+ const normalized = normalizeBuildOptions(options)
795
+ const { title, theme, language, motion, deck, outputDir, overwrite } = normalized
796
+ mkdirSync(outputDir, { recursive: true })
797
+ const fileName = resolveDeckFileName(outputDir, normalized.fileName, overwrite)
798
+
799
+ const manifest = {
800
+ version: DECK_VERSION,
801
+ title,
802
+ theme: theme.id,
803
+ language: language.id,
804
+ motion,
805
+ slideCount: deck.slides.length,
806
+ slides: deck.slides,
807
+ }
808
+ const jsonPath = resolvePath(outputDir, fileName + '.json')
809
+ const htmlPath = resolvePath(outputDir, fileName + '.html')
810
+ const pptxPath = resolvePath(outputDir, fileName + '.pptx')
811
+
812
+ // 先生成三份内容再统一提交:生成阶段抛错时也不会留下半套文件。
813
+ commitDeckArtifacts([
814
+ { path: jsonPath, data: JSON.stringify(manifest, null, 2) + '\n', encoding: 'utf8' },
815
+ { path: htmlPath, data: renderHtml(manifest, theme, language), encoding: 'utf8' },
816
+ { path: pptxPath, data: buildPptx(manifest, theme, language) },
817
+ ])
818
+
819
+ return {
820
+ ok: true,
821
+ title,
822
+ theme: theme.id,
823
+ language: language.id,
824
+ slideCount: deck.slides.length,
825
+ outputDir,
826
+ files: {
827
+ html: htmlPath,
828
+ pptx: pptxPath,
829
+ json: jsonPath,
830
+ },
831
+ htmlPath,
832
+ pptxPath,
833
+ jsonPath,
834
+ }
835
+ }
836
+
837
+ // ---------------------------------------------------------------------------
838
+ // HTML 网页放映
839
+ // ---------------------------------------------------------------------------
840
+
841
+ export function renderHtml(manifest, theme, language) {
842
+ const t = theme
843
+ const lang = language
844
+ const ui = lang.ui
845
+ const motion = manifest.motion !== false
846
+ const motionCss = motion
847
+ ? `body.motion .slide.is-active{animation:slide-in .45s cubic-bezier(.22,.8,.36,1)}
848
+ @keyframes slide-in{from{opacity:0;transform:translateY(24px)}to{opacity:1;transform:none}}
849
+ body.motion .bullets li{
850
+ opacity:0;animation:bullet-in .55s cubic-bezier(.22,.8,.36,1) forwards;
851
+ animation-delay:calc(var(--i, 0)*90ms + .12s);
852
+ }
853
+ @keyframes bullet-in{from{opacity:0;transform:translateY(14px)}to{opacity:1;transform:none}}`
854
+ : ''
855
+ const slides = manifest.slides.map((slide, index) => renderHtmlSlide(slide, index, ui, lang.id)).join('\n')
856
+ const themeLabel = t.name[lang.id] ?? t.name.en
857
+ const total = manifest.slides.length
858
+
859
+ return `<!DOCTYPE html>
860
+ <html lang="${lang.attr}">
861
+ <head>
862
+ <meta charset="UTF-8">
863
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
864
+ <title>${escapeHtml(manifest.title)}</title>
865
+ <style>
866
+ :root{
867
+ --bg:${t.palette.bg};
868
+ --panel:${t.palette.panel};
869
+ --fg:${t.palette.fg};
870
+ --muted:${t.palette.muted};
871
+ --accent:${t.palette.accent};
872
+ --accent2:${t.palette.accent2};
873
+ --font-heading:${t.fonts.heading};
874
+ --font-body:${t.fonts.body};
875
+ }
876
+ *{box-sizing:border-box}
877
+ html,body{height:100%}
878
+ body{
879
+ margin:0;background:var(--bg);color:var(--fg);
880
+ font-family:var(--font-body);overflow:hidden;
881
+ -webkit-font-smoothing:antialiased;text-rendering:optimizeLegibility;
882
+ }
883
+ .slide{
884
+ position:fixed;inset:0;display:none;flex-direction:column;justify-content:center;
885
+ padding:clamp(34px,7vw,110px);overflow:hidden;
886
+ }
887
+ .slide::before{
888
+ content:"";position:absolute;inset:-20%;pointer-events:none;z-index:-1;
889
+ background:
890
+ radial-gradient(42% 34% at 82% 18%, ${hexToRgba(t.palette.accent, t.dark ? 0.22 : 0.12)}, transparent 70%),
891
+ radial-gradient(36% 30% at 12% 86%, ${hexToRgba(t.palette.accent2, t.dark ? 0.16 : 0.12)}, transparent 70%),
892
+ radial-gradient(70% 60% at 50% 50%, ${hexToRgba(t.palette.panel, 0.55)}, transparent 100%);
893
+ }
894
+ .slide.is-active{display:flex}
895
+ ${motionCss}
896
+ .kicker{
897
+ color:var(--accent);font-weight:700;letter-spacing:.18em;text-transform:uppercase;
898
+ font-size:clamp(12px,1.3vw,18px);margin-bottom:22px;
899
+ }
900
+ h1,h2,.statement-title{font-family:var(--font-heading);line-height:1.06;letter-spacing:-.015em;margin:0}
901
+ h1{font-size:clamp(44px,7.4vw,118px);max-width:20ch}
902
+ h2{font-size:clamp(34px,5vw,82px);max-width:20ch}
903
+ .subtitle{
904
+ color:var(--muted);font-size:clamp(18px,2.3vw,34px);line-height:1.5;
905
+ max-width:46em;margin-top:28px;
906
+ }
907
+ .meta{
908
+ color:var(--muted);font-size:clamp(12px,1.2vw,16px);margin-top:48px;
909
+ letter-spacing:.06em;
910
+ }
911
+ .bullets ul{margin:30px 0 0;padding:0;list-style:none;display:grid;gap:clamp(12px,1.6vw,24px)}
912
+ .bullets li{
913
+ position:relative;padding-left:clamp(28px,2.6vw,44px);
914
+ font-size:clamp(20px,2.6vw,40px);line-height:1.35;max-width:24em;
915
+ }
916
+ .bullets li::before{
917
+ content:"";position:absolute;left:0;top:.58em;width:.5em;height:.5em;
918
+ background:var(--accent);border-radius:2px;box-shadow:.28em .28em 0 color-mix(in srgb, var(--accent2) 78%, transparent);
919
+ }
920
+ .section .kicker{margin-bottom:10px}
921
+ .section .accent-line{width:min(180px,18vw);height:6px;background:var(--accent);margin:28px 0}
922
+ .statement-title{
923
+ font-size:clamp(34px,5.4vw,88px);max-width:22ch;font-weight:800;
924
+ border-left:6px solid var(--accent);padding-left:clamp(22px,3vw,48px);
925
+ }
926
+ .closing{text-align:center;align-items:center}
927
+ .closing h1,.closing .statement-title{font-size:clamp(52px,9vw,148px)}
928
+ .closing .subtitle{color:var(--accent);font-weight:700}
929
+ .cover h1{font-weight:900}
930
+ .quote-mark{
931
+ font-family:var(--font-heading);font-size:clamp(90px,13vw,210px);line-height:.62;
932
+ color:var(--accent);margin-bottom:clamp(14px,2vw,30px);
933
+ }
934
+ .quote-text{
935
+ font-family:var(--font-heading);font-size:clamp(26px,4.2vw,62px);line-height:1.28;
936
+ font-weight:700;max-width:22ch;margin:0;
937
+ }
938
+ .quote-attr{color:var(--muted);margin-top:clamp(18px,2.6vw,34px);font-size:clamp(15px,1.8vw,26px);letter-spacing:.04em}
939
+ table.deck-table{
940
+ border-collapse:collapse;margin-top:clamp(20px,3vw,42px);width:100%;max-width:1120px;
941
+ font-size:clamp(13px,1.55vw,23px);
942
+ }
943
+ .deck-table th{
944
+ background:var(--accent);color:var(--bg);text-align:left;font-weight:700;
945
+ padding:.6em .9em;letter-spacing:.02em;
946
+ }
947
+ .deck-table td{
948
+ padding:.55em .9em;border-bottom:1px solid color-mix(in srgb, var(--muted) 34%, transparent);
949
+ color:var(--fg);
950
+ }
951
+ .deck-table tbody tr:nth-child(even){background:color-mix(in srgb, var(--panel) 62%, transparent)}
952
+ #progress{position:fixed;top:0;left:0;height:3px;width:0;background:var(--accent);z-index:30;transition:width .25s}
953
+ #hud{
954
+ position:fixed;right:22px;bottom:18px;z-index:30;display:flex;gap:14px;align-items:center;
955
+ color:var(--muted);font-size:13px;letter-spacing:.08em;font-variant-numeric:tabular-nums;
956
+ }
957
+ #hud button{
958
+ background:color-mix(in srgb, var(--panel) 88%, transparent);color:var(--fg);
959
+ border:1px solid color-mix(in srgb, var(--muted) 45%, transparent);border-radius:99px;
960
+ padding:7px 13px;font:inherit;cursor:pointer;
961
+ }
962
+ #hud button:hover{border-color:var(--accent);color:var(--accent)}
963
+ #notes-panel{
964
+ position:fixed;left:0;right:0;bottom:0;z-index:40;display:none;
965
+ background:color-mix(in srgb, var(--panel) 96%, black 4%);
966
+ border-top:2px solid var(--accent);
967
+ padding:16px clamp(22px,4vw,64px) 20px;max-height:38vh;overflow:auto;
968
+ }
969
+ body.notes-open #notes-panel.has-notes{display:block}
970
+ #notes-panel .notes-label{
971
+ color:var(--accent);font-weight:700;letter-spacing:.14em;text-transform:uppercase;
972
+ font-size:12px;margin-bottom:8px;
973
+ }
974
+ #notes-text{white-space:pre-wrap;line-height:1.65;font-size:15px;color:var(--fg)}
975
+ body.overview .slide{display:flex !important;position:relative;inset:auto;width:100%;height:100vh}
976
+ body.overview{overflow:auto}
977
+ body.overview #progress,body.overview #hud{position:fixed}
978
+ body.overview #notes-panel{display:none !important}
979
+ @media (max-width:640px){
980
+ #hud{right:12px;bottom:10px;gap:8px;font-size:11px}
981
+ }
982
+ @media print{
983
+ html,body{height:auto;overflow:visible;background:#fff}
984
+ .slide{position:relative;display:block !important;height:100vh;page-break-after:always;padding:48px}
985
+ ${motion ? 'body.motion .bullets li{opacity:1 !important;animation:none !important}' : ''}
986
+ #progress,#hud,#notes-panel{display:none !important}
987
+ }
988
+ </style>
989
+ </head>
990
+ <body class="${motion ? 'motion' : 'no-motion'}">
991
+ <div id="progress" aria-hidden="true"></div>
992
+ ${slides}
993
+ <div id="hud" aria-live="polite">
994
+ <span id="counter">${ui.slide} 1 ${ui.of} ${total}</span>
995
+ <span id="theme-label">${ui.theme} · ${escapeHtml(themeLabel)}</span>
996
+ <button id="notes-toggle" title="S">${escapeHtml(ui.notesToggle)}</button>
997
+ <button id="fullscreen" title="F">⛶</button>
998
+ </div>
999
+ <div id="notes-panel" aria-live="polite">
1000
+ <div class="notes-label">${escapeHtml(ui.notesLabel)}</div>
1001
+ <div id="notes-text"></div>
1002
+ </div>
1003
+ <script>
1004
+ (() => {
1005
+ const slides = Array.from(document.querySelectorAll('.slide'));
1006
+ const counter = document.getElementById('counter');
1007
+ const progress = document.getElementById('progress');
1008
+ const fullscreenBtn = document.getElementById('fullscreen');
1009
+ const notesPanel = document.getElementById('notes-panel');
1010
+ const notesText = document.getElementById('notes-text');
1011
+ const notesBtn = document.getElementById('notes-toggle');
1012
+ let index = 0;
1013
+ const total = slides.length;
1014
+ const ui = ${JSON.stringify(ui).replace(/</g, '\\u003c')};
1015
+
1016
+ function refreshNotes() {
1017
+ const notes = slides[index]?.dataset.notes || '';
1018
+ notesPanel.classList.toggle('has-notes', notes !== '');
1019
+ notesText.textContent = notes;
1020
+ }
1021
+
1022
+ function go(next) {
1023
+ index = (next + total) % total;
1024
+ slides.forEach((slide, i) => slide.classList.toggle('is-active', i === index));
1025
+ counter.textContent = ui.slide + ' ' + (index + 1) + ' ' + ui.of + ' ' + total;
1026
+ progress.style.width = ((index + 1) / total * 100) + '%';
1027
+ refreshNotes();
1028
+ document.title = (index + 1) + ' / ' + total + ' · ' + ${JSON.stringify(manifest.title).replace(/</g, '\\u003c')};
1029
+ try { history.replaceState?.(null, '', '#slide-' + (index + 1)); } catch { /* file:// 下个别浏览器可能拒绝 */ }
1030
+ }
1031
+
1032
+ document.addEventListener('keydown', (event) => {
1033
+ if (event.key === 'ArrowRight' || event.key === 'PageDown' || event.key === ' ') {
1034
+ event.preventDefault(); go(index + 1);
1035
+ } else if (event.key === 'ArrowLeft' || event.key === 'PageUp') {
1036
+ event.preventDefault(); go(index - 1);
1037
+ } else if (event.key === 'Home') {
1038
+ event.preventDefault(); go(0);
1039
+ } else if (event.key === 'End') {
1040
+ event.preventDefault(); go(total - 1);
1041
+ } else if (event.key.toLowerCase() === 'f') {
1042
+ if (!document.fullscreenElement) document.documentElement.requestFullscreen?.();
1043
+ else document.exitFullscreen?.();
1044
+ } else if (event.key.toLowerCase() === 'g') {
1045
+ document.body.classList.toggle('overview');
1046
+ go(index);
1047
+ } else if (event.key.toLowerCase() === 's') {
1048
+ document.body.classList.toggle('notes-open');
1049
+ } else if (event.key.toLowerCase() === 'p') {
1050
+ window.print();
1051
+ }
1052
+ });
1053
+
1054
+ let wheelLock = 0;
1055
+ document.addEventListener('wheel', (event) => {
1056
+ const now = Date.now();
1057
+ if (now - wheelLock < 550 || document.body.classList.contains('overview')) return;
1058
+ wheelLock = now;
1059
+ if (Math.abs(event.deltaY) > 12) go(index + (event.deltaY > 0 ? 1 : -1));
1060
+ }, { passive: true });
1061
+
1062
+ let touchStartY = 0;
1063
+ document.addEventListener('touchstart', (event) => { touchStartY = event.touches[0].clientY; }, { passive: true });
1064
+ document.addEventListener('touchend', (event) => {
1065
+ const delta = event.changedTouches[0].clientY - touchStartY;
1066
+ if (Math.abs(delta) > 48) go(index + (delta < 0 ? 1 : -1));
1067
+ }, { passive: true });
1068
+
1069
+ fullscreenBtn.addEventListener('click', () => {
1070
+ if (!document.fullscreenElement) document.documentElement.requestFullscreen?.();
1071
+ else document.exitFullscreen?.();
1072
+ });
1073
+
1074
+ notesBtn.addEventListener('click', () => {
1075
+ document.body.classList.toggle('notes-open');
1076
+ });
1077
+
1078
+ const start = Number.parseInt(location.hash?.replace('#slide-', ''), 10);
1079
+ go(Number.isInteger(start) ? start - 1 : 0);
1080
+ })();
1081
+ </script>
1082
+ </body>
1083
+ </html>`
1084
+ }
1085
+
1086
+ function renderHtmlSlide(slide, index, ui, langId) {
1087
+ const kicker = slide.kicker || (slide.layout === 'cover' ? ui.coverKicker : '')
1088
+ const title = slide.title || ''
1089
+ const subtitle = slide.subtitle || ''
1090
+ const bullets = Array.isArray(slide.bullets) ? slide.bullets : []
1091
+ const number = String(index + 1).padStart(2, '0')
1092
+ let inner = ''
1093
+ switch (slide.layout) {
1094
+ case 'cover':
1095
+ inner = '<div class="kicker">' + escapeHtml(kicker) + '</div>' +
1096
+ '<h1>' + escapeHtml(title) + '</h1>' +
1097
+ (subtitle !== '' ? '<div class="subtitle">' + escapeHtml(subtitle) + '</div>' : '') +
1098
+ '<div class="meta">' + escapeHtml(ui.generatedBy) + '</div>'
1099
+ break
1100
+ case 'section':
1101
+ inner = '<div class="kicker">' + escapeHtml(kicker) + '</div>' +
1102
+ '<h2>' + escapeHtml(title) + '</h2>' +
1103
+ '<div class="accent-line"></div>' +
1104
+ (subtitle !== '' ? '<div class="subtitle">' + escapeHtml(subtitle) + '</div>' : '')
1105
+ break
1106
+ case 'statement':
1107
+ inner = '<div class="kicker">' + escapeHtml(kicker) + '</div>' +
1108
+ '<div class="statement-title">' + escapeHtml(title || slide.text || '') + '</div>' +
1109
+ (subtitle !== '' ? '<div class="subtitle">' + escapeHtml(subtitle) + '</div>' : '')
1110
+ break
1111
+ case 'quote':
1112
+ inner = '<div class="kicker">' + escapeHtml(kicker || ui.quoteKicker) + '</div>' +
1113
+ '<div class="quote-mark" aria-hidden="true">\u201C</div>' +
1114
+ '<blockquote class="quote-text">' + escapeHtml(title || slide.text || '') + '</blockquote>' +
1115
+ (subtitle !== '' ? '<div class="quote-attr">\u2014\u2014 ' + escapeHtml(subtitle) + '</div>' : '')
1116
+ break
1117
+ case 'table': {
1118
+ const rows = Array.isArray(slide.rows) ? slide.rows : []
1119
+ const head = rows[0] ?? []
1120
+ const body = rows.slice(1)
1121
+ inner = '<div class="kicker">' + escapeHtml(kicker || ui.tableKicker) + '</div>' +
1122
+ (title !== '' && title !== kicker ? '<h2>' + escapeHtml(title) + '</h2>' : '') +
1123
+ '<table class="deck-table"><thead><tr>' +
1124
+ head.map((cell) => '<th>' + escapeHtml(cell) + '</th>').join('') +
1125
+ '</tr></thead><tbody>' +
1126
+ body.map((row) => '<tr>' + row.map((cell) => '<td>' + escapeHtml(cell) + '</td>').join('') + '</tr>').join('') +
1127
+ '</tbody></table>'
1128
+ break
1129
+ }
1130
+ case 'closing':
1131
+ inner = '<h1>' + escapeHtml(title || ui.closingTitle) + '</h1>' +
1132
+ (subtitle !== '' ? '<div class="subtitle">' + escapeHtml(subtitle) + '</div>' : '') +
1133
+ '<div class="meta">' + escapeHtml(ui.generatedBy) + '</div>'
1134
+ break
1135
+ case 'bullets':
1136
+ default:
1137
+ inner = '<div class="kicker">' + escapeHtml(kicker) + '</div>' +
1138
+ '<h2>' + escapeHtml(title) + '</h2>' +
1139
+ '<ul>' + bullets.map((bullet, bulletIndex) => '<li style="--i:' + bulletIndex + '">' + escapeHtml(bullet) + '</li>').join('') + '</ul>'
1140
+ break
1141
+ }
1142
+ const notesAttr = typeof slide.notes === 'string' && slide.notes.trim() !== ''
1143
+ ? ' data-notes="' + escapeHtml(slide.notes) + '"'
1144
+ : ''
1145
+ return '<section class="slide slide--' + escapeHtml(slide.layout || 'bullets') + '" data-index="' + number + '"' + notesAttr + '>' +
1146
+ '<div class="slide-inner">' + inner + '</div></section>'
1147
+ }
1148
+
1149
+ function hexToRgba(hex, alpha) {
1150
+ const value = String(hex).replace('#', '')
1151
+ const full = value.length === 3 ? value.split('').map((c) => c + c).join('') : value
1152
+ const num = Number.parseInt(full, 16)
1153
+ const r = (num >> 16) & 255
1154
+ const g = (num >> 8) & 255
1155
+ const b = num & 255
1156
+ return 'rgba(' + r + ',' + g + ',' + b + ',' + alpha + ')'
1157
+ }
1158
+
1159
+ // ---------------------------------------------------------------------------
1160
+ // PPTX(OOXML 手写 + node:zlib zip)
1161
+ // ---------------------------------------------------------------------------
1162
+
1163
+ const EMU_W = 12192000
1164
+ const EMU_H = 6858000
1165
+
1166
+ function hex(value) {
1167
+ return String(value).replace('#', '').toUpperCase()
1168
+ }
1169
+
1170
+ function pptxFontName(value) {
1171
+ const match = /"?([^",]+)"?/.exec(String(value ?? ''))
1172
+ return match?.[1]?.trim() || 'Arial'
1173
+ }
1174
+
1175
+ function paragraphXml(text, options = {}) {
1176
+ const {
1177
+ size = 2000,
1178
+ color = 'FFFFFF',
1179
+ bold = false,
1180
+ lang = 'zh-CN',
1181
+ align = 'l',
1182
+ bullet = false,
1183
+ font = 'Arial',
1184
+ spaceBefore = 0,
1185
+ spaceAfter = 0,
1186
+ } = options
1187
+ const runFont = pptxFontName(font)
1188
+ let pPr = ''
1189
+ if (bullet) {
1190
+ pPr = '<a:pPr marL="285750" indent="-285750"><a:buFont typeface="Arial" panose="020B0604020202020204"/><a:buChar char="•"/></a:pPr>'
1191
+ } else {
1192
+ const parts = [] // align 与 spacing 二选一
1193
+ if (align !== 'l') parts.push('algn="' + align + '"')
1194
+ if (spaceBefore > 0) parts.push('<a:spcBef><a:spcPts val="' + (spaceBefore / 100) + '"/></a:spcBef>')
1195
+ if (spaceAfter > 0) parts.push('<a:spcAft><a:spcPts val="' + (spaceAfter / 100) + '"/></a:spcAft>')
1196
+ pPr = '<a:pPr' + (parts.length > 0 ? ' ' + parts.join(' ') : '') + '><a:buNone/></a:pPr>'
1197
+ }
1198
+ return '<a:p>' + pPr +
1199
+ '<a:r><a:rPr lang="' + lang + '" sz="' + size + '" b="' + (bold ? 1 : 0) + '" dirty="0">' +
1200
+ '<a:solidFill><a:srgbClr val="' + hex(color) + '"/></a:solidFill>' +
1201
+ '<a:latin typeface="' + escapeXml(runFont) + '"/><a:ea typeface="' + escapeXml(runFont) + '"/></a:rPr>' +
1202
+ '<a:t>' + escapeXml(text) + '</a:t></a:r></a:p>'
1203
+ }
1204
+
1205
+ function textShapeXml(id, name, box, paragraphs, options = {}) {
1206
+ const { x = 0, y = 0, w = EMU_W, h = EMU_H } = box
1207
+ return '<p:sp>' +
1208
+ '<p:nvSpPr><p:cNvPr id="' + id + '" name="' + escapeXml(name) + '"/><p:cNvSpPr txBox="1"/><p:nvPr/></p:nvSpPr>' +
1209
+ '<p:spPr><a:xfrm><a:off x="' + x + '" y="' + y + '"/><a:ext cx="' + w + '" cy="' + h + '"/></a:xfrm>' +
1210
+ '<a:prstGeom prst="rect"><a:avLst/></a:prstGeom><a:noFill/><a:ln/></p:spPr>' +
1211
+ '<p:txBody><a:bodyPr wrap="square" rtlCol="0"><a:normAutofit/></a:bodyPr><a:lstStyle/>' +
1212
+ paragraphs.join('') + '</p:txBody></p:sp>'
1213
+ }
1214
+
1215
+ function accentBarXml(id, name, box, color) {
1216
+ const { x = 0, y = 0, w = EMU_W, h = EMU_H } = box
1217
+ return '<p:sp>' +
1218
+ '<p:nvSpPr><p:cNvPr id="' + id + '" name="' + escapeXml(name) + '"/><p:cNvSpPr/><p:nvPr/></p:nvSpPr>' +
1219
+ '<p:spPr><a:xfrm><a:off x="' + x + '" y="' + y + '"/><a:ext cx="' + w + '" cy="' + h + '"/></a:xfrm>' +
1220
+ '<a:prstGeom prst="rect"><a:avLst/></a:prstGeom>' +
1221
+ '<a:solidFill><a:srgbClr val="' + hex(color) + '"/></a:solidFill><a:ln/></p:spPr>' +
1222
+ '<p:txBody><a:bodyPr/><a:lstStyle/><a:p/></p:txBody></p:sp>'
1223
+ }
1224
+
1225
+ /** 原生 OOXML 表格(graphicFrame + a:tbl):首行主题色表头,隔行面板色。 */
1226
+ function tableGraphicXml(id, name, box, rows, theme, langId) {
1227
+ const p = theme.palette
1228
+ const lang = langId || 'zh-CN'
1229
+ const font = pptxFontName(theme.fonts.body)
1230
+ const safeRows = rows.length > 0 ? rows : [['']]
1231
+ const cols = Math.max(1, safeRows[0].length)
1232
+ const colW = Math.floor(box.w / cols)
1233
+ const grid = Array.from({ length: cols }, () => '<a:gridCol w="' + colW + '"/>').join('')
1234
+ const rowH = 420000
1235
+ const cellXml = (text, fill, color, bold) =>
1236
+ '<a:tc><a:txBody><a:bodyPr anchor="ctr"/><a:lstStyle/><a:p><a:pPr algn="l"><a:buNone/></a:pPr>' +
1237
+ '<a:r><a:rPr lang="' + lang + '" sz="1400" b="' + (bold ? 1 : 0) + '" dirty="0">' +
1238
+ '<a:solidFill><a:srgbClr val="' + hex(color) + '"/></a:solidFill>' +
1239
+ '<a:latin typeface="' + escapeXml(font) + '"/><a:ea typeface="' + escapeXml(font) + '"/></a:rPr>' +
1240
+ '<a:t>' + escapeXml(text) + '</a:t></a:r></a:p></a:txBody>' +
1241
+ '<a:tcPr marL="91440" marR="91440" anchor="ctr">' +
1242
+ (fill !== '' ? '<a:solidFill><a:srgbClr val="' + hex(fill) + '"/></a:solidFill>' : '<a:noFill/>') +
1243
+ '</a:tcPr></a:tc>'
1244
+ const trs = safeRows.map((row, rowIndex) => {
1245
+ const padded = Array.from({ length: cols }, (_, i) => row[i] ?? '')
1246
+ const cells = rowIndex === 0
1247
+ ? padded.map((c) => cellXml(c, p.accent, p.bg, true)).join('')
1248
+ : padded.map((c) => cellXml(c, rowIndex % 2 === 1 ? p.panel : '', p.fg, false)).join('')
1249
+ return '<a:tr h="' + rowH + '">' + cells + '</a:tr>'
1250
+ }).join('')
1251
+ const height = Math.max(1, safeRows.length) * rowH
1252
+ return '<p:graphicFrame>' +
1253
+ '<p:nvGraphicFramePr><p:cNvPr id="' + id + '" name="' + escapeXml(name) + '"/>' +
1254
+ '<p:cNvGraphicFramePr><a:graphicFrameLocks noGrp="1"/></p:cNvGraphicFramePr><p:nvPr/></p:nvGraphicFramePr>' +
1255
+ '<p:xfrm><a:off x="' + box.x + '" y="' + box.y + '"/><a:ext cx="' + box.w + '" cy="' + height + '"/></p:xfrm>' +
1256
+ '<a:graphic><a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/table">' +
1257
+ '<a:tbl><a:tblPr firstRow="1" bandRow="1"/>' +
1258
+ '<a:tblGrid>' + grid + '</a:tblGrid>' + trs + '</a:tbl>' +
1259
+ '</a:graphicData></a:graphic></p:graphicFrame>'
1260
+ }
1261
+
1262
+ function slideShapeList(slide, index, total, theme, langId) {
1263
+ const p = theme.palette
1264
+ const font = pptxFontName(theme.fonts.heading)
1265
+ const bodyFont = pptxFontName(theme.fonts.body) // 保留:v0.1 后续用于统一正文字体
1266
+ const lang = langId || 'zh-CN'
1267
+ // PPTX 每个文本 run 的语言跟随 deck.lang(zh-CN / en-US),不再写死中文
1268
+ const para = (content, options = {}) => paragraphXml(content, { lang, ...options })
1269
+ const shapes = []
1270
+ const kicker = slide.kicker || ''
1271
+ const title = slide.title || ''
1272
+ const subtitle = slide.subtitle || ''
1273
+ const bullets = Array.isArray(slide.bullets) ? slide.bullets : []
1274
+ const idBase = (index + 1) * 10
1275
+ const footer = String(index + 1).padStart(2, '0') + ' / ' + String(total).padStart(2, '0')
1276
+
1277
+ if (slide.layout === 'cover') {
1278
+ shapes.push(accentBarXml(idBase + 1, 'Accent bar', { x: 914400, y: 2250000, w: 240000, h: 1600000 }, p.accent))
1279
+ shapes.push(textShapeXml(idBase + 2, 'Title', { x: 1550000, y: 2160000, w: 9250000, h: 1800000 }, [
1280
+ para(title, { size: 4400, color: p.fg, bold: true, font }),
1281
+ ]))
1282
+ if (subtitle !== '') {
1283
+ shapes.push(textShapeXml(idBase + 3, 'Subtitle', { x: 1570000, y: 4150000, w: 9000000, h: 1200000 }, [
1284
+ para(subtitle, { size: 2200, color: p.muted, font: theme.fonts.body }),
1285
+ ]))
1286
+ }
1287
+ if (kicker !== '') {
1288
+ shapes.push(textShapeXml(idBase + 4, 'Kicker', { x: 1570000, y: 5800000, w: 7000000, h: 500000 }, [
1289
+ para(kicker, { size: 1400, color: p.accent, bold: true, font: theme.fonts.body }),
1290
+ ]))
1291
+ }
1292
+ } else if (slide.layout === 'section') {
1293
+ if (kicker !== '') {
1294
+ shapes.push(textShapeXml(idBase + 1, 'Kicker', { x: 1050000, y: 2250000, w: 9000000, h: 500000 }, [
1295
+ para(kicker, { size: 1600, color: p.accent, bold: true, font: theme.fonts.body }),
1296
+ ]))
1297
+ }
1298
+ shapes.push(accentBarXml(idBase + 2, 'Accent bar', { x: 1050000, y: 2850000, w: 1600000, h: 160000 }, p.accent2))
1299
+ shapes.push(textShapeXml(idBase + 3, 'Title', { x: 1050000, y: 3150000, w: 10200000, h: 1400000 }, [
1300
+ para(title, { size: 4000, color: p.fg, bold: true, font }),
1301
+ ]))
1302
+ if (subtitle !== '') {
1303
+ shapes.push(textShapeXml(idBase + 4, 'Subtitle', { x: 1070000, y: 4750000, w: 9000000, h: 900000 }, [
1304
+ para(subtitle, { size: 1800, color: p.muted, font: theme.fonts.body }),
1305
+ ]))
1306
+ }
1307
+ } else if (slide.layout === 'statement') {
1308
+ shapes.push(accentBarXml(idBase + 1, 'Accent bar', { x: 914400, y: 1900000, w: 200000, h: 2800000 }, p.accent))
1309
+ shapes.push(textShapeXml(idBase + 2, 'Statement', { x: 1500000, y: 1950000, w: 9400000, h: 2700000 }, [
1310
+ para(title || slide.text || '', { size: 3600, color: p.fg, bold: true, font }),
1311
+ ]))
1312
+ if (subtitle !== '') {
1313
+ shapes.push(textShapeXml(idBase + 3, 'Subtitle', { x: 1520000, y: 4900000, w: 9000000, h: 800000 }, [
1314
+ para(subtitle, { size: 1800, color: p.muted, font: theme.fonts.body }),
1315
+ ]))
1316
+ }
1317
+ } else if (slide.layout === 'quote') {
1318
+ shapes.push(textShapeXml(idBase + 1, 'Quote mark', { x: 900000, y: 1050000, w: 1700000, h: 1900000 }, [
1319
+ para('\u201C', { size: 9600, color: p.accent, bold: true, font }),
1320
+ ]))
1321
+ shapes.push(textShapeXml(idBase + 2, 'Quote', { x: 1050000, y: 2550000, w: 10100000, h: 2600000 }, [
1322
+ para(title || slide.text || '', { size: 3000, color: p.fg, bold: true, font }),
1323
+ ]))
1324
+ if (subtitle !== '') {
1325
+ shapes.push(textShapeXml(idBase + 3, 'Attribution', { x: 1070000, y: 5300000, w: 9000000, h: 600000 }, [
1326
+ para('\u2014\u2014 ' + subtitle, { size: 1600, color: p.muted, font: theme.fonts.body }),
1327
+ ]))
1328
+ }
1329
+ } else if (slide.layout === 'table') {
1330
+ const hasTitle = title !== '' && title !== kicker
1331
+ if (kicker !== '') {
1332
+ shapes.push(textShapeXml(idBase + 1, 'Kicker', { x: 900000, y: 420000, w: 10000000, h: 420000 }, [
1333
+ para(kicker, { size: 1400, color: p.accent, bold: true, font: theme.fonts.body }),
1334
+ ]))
1335
+ }
1336
+ if (hasTitle) {
1337
+ shapes.push(textShapeXml(idBase + 2, 'Title', { x: 900000, y: 920000, w: 10300000, h: 800000 }, [
1338
+ para(title, { size: 3400, color: p.fg, bold: true, font }),
1339
+ ]))
1340
+ }
1341
+ shapes.push(tableGraphicXml(idBase + 3, 'Table', { x: 900000, y: hasTitle ? 1950000 : 900000, w: 10300000 }, Array.isArray(slide.rows) ? slide.rows : [], theme, lang))
1342
+ } else if (slide.layout === 'closing') {
1343
+ shapes.push(textShapeXml(idBase + 1, 'Title', { x: 1050000, y: 2300000, w: 10200000, h: 1700000 }, [
1344
+ para(title || '谢谢', { size: 5200, color: p.fg, bold: true, align: 'ctr', font }),
1345
+ ]))
1346
+ if (subtitle !== '') {
1347
+ shapes.push(textShapeXml(idBase + 2, 'Subtitle', { x: 1050000, y: 4200000, w: 10200000, h: 900000 }, [
1348
+ para(subtitle, { size: 2000, color: p.accent, bold: true, align: 'ctr', font: theme.fonts.body }),
1349
+ ]))
1350
+ }
1351
+ } else {
1352
+ // bullets(默认布局)
1353
+ if (kicker !== '') {
1354
+ shapes.push(textShapeXml(idBase + 1, 'Kicker', { x: 900000, y: 420000, w: 10000000, h: 420000 }, [
1355
+ para(kicker, { size: 1400, color: p.accent, bold: true, font: theme.fonts.body }),
1356
+ ]))
1357
+ }
1358
+ shapes.push(textShapeXml(idBase + 2, 'Title', { x: 900000, y: 920000, w: 10300000, h: 800000 }, [
1359
+ para(title, { size: 3400, color: p.fg, bold: true, font }),
1360
+ ]))
1361
+ const bodyParagraphs = bullets.length > 0
1362
+ ? bullets.map((bullet) => para(bullet, { size: 2000, color: p.fg, bullet: true, font: theme.fonts.body, spaceAfter: 600 }))
1363
+ : [para(subtitle || '', { size: 2000, color: p.fg, font: theme.fonts.body })]
1364
+ shapes.push(textShapeXml(idBase + 3, 'Body', { x: 1050000, y: 1850000, w: 10100000, h: 4500000 }, bodyParagraphs))
1365
+ }
1366
+
1367
+ shapes.push(textShapeXml(idBase + 9, 'Page number', { x: 10600000, y: 6250000, w: 1200000, h: 400000 }, [
1368
+ para(footer, { size: 1000, color: p.muted, align: 'r', font: theme.fonts.body }),
1369
+ ]))
1370
+
1371
+ return shapes.join('')
1372
+ }
1373
+
1374
+ /**
1375
+ * 原生逐条点击显现动画(PowerPoint「出现,按段落」的标准时序树):
1376
+ * bldP 把正文文本框标记为按段落构建,主序列里每条要点一个点击节点。
1377
+ */
1378
+ function bulletTimingXml(spid, clicks) {
1379
+ let id = 2
1380
+ const nextId = () => { id += 1; return String(id) }
1381
+ const clickPars = []
1382
+ for (let i = 0; i < clicks; i += 1) {
1383
+ clickPars.push(
1384
+ '<p:par><p:cTn id="' + nextId() + '" fill="hold"><p:stCondLst><p:cond delay="indefinite"/></p:stCondLst><p:childTnLst>' +
1385
+ '<p:par><p:cTn id="' + nextId() + '" presetID="1" presetClass="entr" presetSubtype="0" fill="hold" grpId="0" nodeType="clickEffect">' +
1386
+ '<p:stCondLst><p:cond delay="0"/></p:stCondLst><p:childTnLst>' +
1387
+ '<p:set><p:cBhvr><p:cTn id="' + nextId() + '" dur="1" fill="hold"><p:stCondLst><p:cond delay="0"/></p:stCondLst></p:cTn>' +
1388
+ '<p:tgtEl><p:spTgt spid="' + spid + '"/></p:tgtEl>' +
1389
+ '<p:attrNameLst><p:attrName>style.visibility</p:attrName></p:attrNameLst></p:cBhvr>' +
1390
+ '<p:to><p:strVal val="visible"/></p:to></p:set>' +
1391
+ '</p:childTnLst></p:cTn></p:par>' +
1392
+ '</p:childTnLst></p:cTn></p:par>',
1393
+ )
1394
+ }
1395
+ return '<p:timing><p:tnLst><p:par>' +
1396
+ '<p:cTn id="1" dur="indefinite" restart="never" nodeType="tmRoot"><p:childTnLst>' +
1397
+ '<p:seq concurrent="1" nextAc="seek"><p:cTn id="2" dur="indefinite" nodeType="mainSeq"><p:childTnLst>' +
1398
+ clickPars.join('') +
1399
+ '</p:childTnLst></p:cTn>' +
1400
+ '<p:prevCondLst><p:cond evt="onPrev" delay="0"><p:tgtEl><p:sldTgt/></p:tgtEl></p:cond></p:prevCondLst>' +
1401
+ '<p:nextCondLst><p:cond evt="onNext" delay="0"><p:tgtEl><p:sldTgt/></p:tgtEl></p:cond></p:nextCondLst>' +
1402
+ '</p:seq></p:childTnLst></p:cTn></p:par></p:tnLst>' +
1403
+ '<p:bldLst><p:bldP spid="' + spid + '" grpId="0"/></p:bldLst></p:timing>'
1404
+ }
1405
+
1406
+ function slideXml(slide, index, total, theme, langId, motion) {
1407
+ const p = theme.palette
1408
+ let motionXml = ''
1409
+ if (motion) {
1410
+ motionXml = '<p:transition spd="med"><p:fade/></p:transition>'
1411
+ const bullets = Array.isArray(slide.bullets) ? slide.bullets : []
1412
+ if (slide.layout === 'bullets' && bullets.length >= 2) {
1413
+ motionXml += bulletTimingXml((index + 1) * 10 + 3, bullets.length)
1414
+ }
1415
+ }
1416
+ return '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' +
1417
+ '<p:sld xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" ' +
1418
+ 'xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" ' +
1419
+ 'xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main">' +
1420
+ '<p:cSld><p:bg><p:bgPr><a:solidFill><a:srgbClr val="' + hex(p.bg) + '"/></a:solidFill><a:effectLst/></p:bgPr></p:bg>' +
1421
+ '<p:spTree><p:nvGrpSpPr><p:cNvPr id="1" name=""/><p:cNvGrpSpPr/><p:nvPr/></p:nvGrpSpPr>' +
1422
+ '<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>' +
1423
+ slideShapeList(slide, index, total, theme, langId) +
1424
+ '</p:spTree></p:cSld>' +
1425
+ '<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>' +
1426
+ motionXml +
1427
+ '</p:sld>'
1428
+ }
1429
+
1430
+ function slideRelXml(hasNotes, slideIndex) {
1431
+ const notesRel = hasNotes
1432
+ ? '<Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/notesSlide" Target="../notesSlides/notesSlide' + slideIndex + '.xml"/>'
1433
+ : ''
1434
+ return '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' +
1435
+ '<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">' +
1436
+ '<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideLayout" Target="../slideLayouts/slideLayout1.xml"/>' +
1437
+ notesRel +
1438
+ '</Relationships>'
1439
+ }
1440
+
1441
+ function presentationXml(slideCount, hasNotesMaster) {
1442
+ const slideIds = Array.from({ length: slideCount }, (_, i) =>
1443
+ '<p:sldId id="' + (256 + i) + '" r:id="rId' + (i + 2) + '"/>').join('')
1444
+ const notesMasterId = hasNotesMaster
1445
+ ? '<p:notesMasterIdLst><p:notesMasterId id="2147483649" r:id="rId' + (slideCount + 2) + '"/></p:notesMasterIdLst>'
1446
+ : ''
1447
+ return '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' +
1448
+ '<p:presentation xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" ' +
1449
+ 'xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" ' +
1450
+ 'xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main">' +
1451
+ '<p:sldMasterIdLst><p:sldMasterId id="2147483648" r:id="rId1"/></p:sldMasterIdLst>' +
1452
+ '<p:sldIdLst>' + slideIds + '</p:sldIdLst>' +
1453
+ notesMasterId +
1454
+ '<p:sldSz cx="' + EMU_W + '" cy="' + EMU_H + '" type="screen16x9"/>' +
1455
+ '<p:notesSz cx="6858000" cy="9144000"/>' +
1456
+ '</p:presentation>'
1457
+ }
1458
+
1459
+ function presentationRelXml(slideCount, hasNotesMaster) {
1460
+ const slideRels = Array.from({ length: slideCount }, (_, i) =>
1461
+ '<Relationship Id="rId' + (i + 2) + '" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide" Target="slides/slide' + (i + 1) + '.xml"/>').join('')
1462
+ const notesMasterRel = hasNotesMaster
1463
+ ? '<Relationship Id="rId' + (slideCount + 2) + '" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/notesMaster" Target="notesMasters/notesMaster1.xml"/>'
1464
+ : ''
1465
+ return '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' +
1466
+ '<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">' +
1467
+ '<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideMaster" Target="slideMasters/slideMaster1.xml"/>' +
1468
+ slideRels +
1469
+ notesMasterRel +
1470
+ '</Relationships>'
1471
+ }
1472
+
1473
+ function notesMasterXml() {
1474
+ return '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' +
1475
+ '<p:notesMaster xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" ' +
1476
+ 'xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" ' +
1477
+ 'xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main">' +
1478
+ '<p:cSld><p:spTree><p:nvGrpSpPr><p:cNvPr id="1" name=""/><p:cNvGrpSpPr/><p:nvPr/></p:nvGrpSpPr>' +
1479
+ '<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>' +
1480
+ '</p:spTree></p:cSld>' +
1481
+ '<p:clrMap bg1="lt1" tx1="dk1" bg2="lt2" tx2="dk2" accent1="accent1" accent2="accent2" accent3="accent3" accent4="accent4" accent5="accent5" accent6="accent6" hlink="hlink" folHlink="folHlink"/>' +
1482
+ '<p:notesStyle><a:lvl1pPr><a:defRPr sz="1200"/></a:lvl1pPr></p:notesStyle>' +
1483
+ '</p:notesMaster>'
1484
+ }
1485
+
1486
+ function notesMasterRelXml() {
1487
+ return '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' +
1488
+ '<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">' +
1489
+ '<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme" Target="../theme/theme1.xml"/>' +
1490
+ '</Relationships>'
1491
+ }
1492
+
1493
+ function notesSlideXml(notes, langId) {
1494
+ const lang = langId || 'zh-CN'
1495
+ const paragraphs = String(notes ?? '').split('\n')
1496
+ .filter((line) => line.trim() !== '')
1497
+ .map((line) => '<a:p><a:r><a:rPr lang="' + lang + '" sz="1200" dirty="0"/><a:t>' + escapeXml(line) + '</a:t></a:r></a:p>')
1498
+ .join('')
1499
+ return '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' +
1500
+ '<p:notes xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" ' +
1501
+ 'xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" ' +
1502
+ 'xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main">' +
1503
+ '<p:cSld><p:spTree><p:nvGrpSpPr><p:cNvPr id="1" name=""/><p:cNvGrpSpPr/><p:nvPr/></p:nvGrpSpPr>' +
1504
+ '<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>' +
1505
+ '<p:sp><p:nvSpPr><p:cNvPr id="2" name="Slide Image Placeholder 1"/><p:cNvSpPr/><p:nvPr><p:ph type="sldImg"/></p:nvPr></p:nvSpPr><p:spPr/></p:sp>' +
1506
+ '<p:sp><p:nvSpPr><p:cNvPr id="3" name="Notes Placeholder 2"/><p:cNvSpPr/><p:nvPr><p:ph type="body" idx="1"/></p:nvPr></p:nvSpPr><p:spPr/>' +
1507
+ '<p:txBody><a:bodyPr/><a:lstStyle/>' + paragraphs + '</p:txBody></p:sp>' +
1508
+ '</p:spTree></p:cSld>' +
1509
+ '<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>' +
1510
+ '</p:notes>'
1511
+ }
1512
+
1513
+ function notesSlideRelXml(slideIndex) {
1514
+ return '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' +
1515
+ '<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">' +
1516
+ '<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide" Target="../slides/slide' + slideIndex + '.xml"/>' +
1517
+ '<Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/notesMaster" Target="../notesMasters/notesMaster1.xml"/>' +
1518
+ '</Relationships>'
1519
+ }
1520
+
1521
+ function slideMasterXml(theme) {
1522
+ const p = theme.palette
1523
+ const levels = Array.from({ length: 9 }, (_, i) => {
1524
+ const sz = Math.max(1100, 2000 - i * 100)
1525
+ return '<a:lvl' + (i + 1) + 'pPr marL="' + (342900 + i * 342900) + '" indent="' + (-342900 - i * 0) + '">' +
1526
+ '<a:defRPr sz="' + sz + '"><a:solidFill><a:srgbClr val="' + hex(p.fg) + '"/></a:solidFill><a:latin typeface="' + escapeXml(pptxFontName(theme.fonts.body)) + '"/></a:defRPr></a:lvl' + (i + 1) + 'pPr>'
1527
+ }).join('')
1528
+ return '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' +
1529
+ '<p:sldMaster xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" ' +
1530
+ 'xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" ' +
1531
+ 'xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main">' +
1532
+ '<p:cSld><p:spTree><p:nvGrpSpPr><p:cNvPr id="1" name=""/><p:cNvGrpSpPr/><p:nvPr/></p:nvGrpSpPr>' +
1533
+ '<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>' +
1534
+ '</p:spTree></p:cSld>' +
1535
+ '<p:clrMap bg1="lt1" tx1="dk1" bg2="lt2" tx2="dk2" accent1="accent1" accent2="accent2" accent3="accent3" accent4="accent4" accent5="accent5" accent6="accent6" hlink="hlink" folHlink="folHlink"/>' +
1536
+ '<p:sldLayoutIdLst><p:sldLayoutId id="2147483649" r:id="rId1"/></p:sldLayoutIdLst>' +
1537
+ '<p:txStyles><p:titleStyle>' + levels + '</p:titleStyle><p:bodyStyle>' + levels + '</p:bodyStyle><p:otherStyle>' + levels + '</p:otherStyle></p:txStyles>' +
1538
+ '</p:sldMaster>'
1539
+ }
1540
+
1541
+ function slideMasterRelXml() {
1542
+ return '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' +
1543
+ '<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">' +
1544
+ '<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideLayout" Target="../slideLayouts/slideLayout1.xml"/>' +
1545
+ '<Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme" Target="../theme/theme1.xml"/>' +
1546
+ '</Relationships>'
1547
+ }
1548
+
1549
+ function slideLayoutXml(theme) {
1550
+ return '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' +
1551
+ '<p:sldLayout xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" ' +
1552
+ 'xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" ' +
1553
+ 'xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main" type="blank" preserve="1">' +
1554
+ '<p:cSld name="Blank"><p:spTree><p:nvGrpSpPr><p:cNvPr id="1" name=""/><p:cNvGrpSpPr/><p:nvPr/></p:nvGrpSpPr>' +
1555
+ '<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>' +
1556
+ '</p:spTree></p:cSld>' +
1557
+ '<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>' +
1558
+ '</p:sldLayout>'
1559
+ }
1560
+
1561
+ function slideLayoutRelXml() {
1562
+ return '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' +
1563
+ '<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">' +
1564
+ '<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideMaster" Target="../slideMasters/slideMaster1.xml"/>' +
1565
+ '</Relationships>'
1566
+ }
1567
+
1568
+ function themeXml(theme) {
1569
+ const p = theme.palette
1570
+ const color = (name, value) => '<a:' + name + '><a:srgbClr val="' + hex(value) + '"/></a:' + name + '>'
1571
+ return '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' +
1572
+ '<a:theme xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" name="dsh-ppt ' + escapeXml(theme.name.en) + '">' +
1573
+ '<a:themeElements>' +
1574
+ '<a:clrScheme name="dsh-ppt">' +
1575
+ color('dk1', p.fg) + color('lt1', p.bg) + color('dk2', p.muted) + color('lt2', p.panel) +
1576
+ color('accent1', p.accent) + color('accent2', p.accent2) + color('accent3', p.fg) +
1577
+ color('accent4', p.muted) + color('accent5', p.accent) + color('accent6', p.accent2) +
1578
+ color('hlink', p.accent) + color('folHlink', p.accent2) +
1579
+ '</a:clrScheme>' +
1580
+ '<a:fontScheme name="dsh-ppt">' +
1581
+ '<a:majorFont><a:latin typeface="' + escapeXml(pptxFontName(theme.fonts.heading)) + '"/><a:ea typeface=""/><a:cs typeface=""/></a:majorFont>' +
1582
+ '<a:minorFont><a:latin typeface="' + escapeXml(pptxFontName(theme.fonts.body)) + '"/><a:ea typeface=""/><a:cs typeface=""/></a:minorFont>' +
1583
+ '</a:fontScheme>' +
1584
+ '<a:fmtScheme name="dsh-ppt">' +
1585
+ '<a:fillStyleLst>' +
1586
+ '<a:solidFill><a:schemeClr val="phClr"/></a:solidFill>' +
1587
+ '<a:solidFill><a:schemeClr val="phClr"/></a:solidFill>' +
1588
+ '<a:solidFill><a:schemeClr val="phClr"/></a:solidFill>' +
1589
+ '</a:fillStyleLst>' +
1590
+ '<a:lnStyleLst><a:ln w="6350" cap="flat" cmpd="sng" algn="ctr"><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:prstDash val="solid"/></a:ln><a:ln w="12700" cap="flat" cmpd="sng" algn="ctr"><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:prstDash val="solid"/></a:ln><a:ln w="19050" cap="flat" cmpd="sng" algn="ctr"><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:prstDash val="solid"/></a:ln></a:lnStyleLst>' +
1591
+ '<a:effectStyleLst><a:effectStyle><a:effectLst/></a:effectStyle><a:effectStyle><a:effectLst/></a:effectStyle><a:effectStyle><a:effectLst/></a:effectStyle></a:effectStyleLst>' +
1592
+ '<a:bgFillStyleLst><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:solidFill><a:schemeClr val="phClr"/></a:solidFill></a:bgFillStyleLst>' +
1593
+ '</a:fmtScheme>' +
1594
+ '</a:themeElements>' +
1595
+ '<a:objectDefaults/><a:extraClrSchemeLst/>' +
1596
+ '</a:theme>'
1597
+ }
1598
+
1599
+ function contentTypesXml(slideCount, noteIndexes) {
1600
+ const overrides = Array.from({ length: slideCount }, (_, i) =>
1601
+ '<Override PartName="/ppt/slides/slide' + (i + 1) + '.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.slide+xml"/>').join('')
1602
+ const notesOverrides = noteIndexes.map((index) =>
1603
+ '<Override PartName="/ppt/notesSlides/notesSlide' + (index + 1) + '.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.notesSlide+xml"/>').join('')
1604
+ const notesMasterOverride = noteIndexes.length > 0
1605
+ ? '<Override PartName="/ppt/notesMasters/notesMaster1.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.notesMaster+xml"/>'
1606
+ : ''
1607
+ return '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' +
1608
+ '<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">' +
1609
+ '<Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>' +
1610
+ '<Default Extension="xml" ContentType="application/xml"/>' +
1611
+ '<Override PartName="/ppt/presentation.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.presentation.main+xml"/>' +
1612
+ '<Override PartName="/ppt/slideMasters/slideMaster1.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.slideMaster+xml"/>' +
1613
+ '<Override PartName="/ppt/slideLayouts/slideLayout1.xml" ContentType="application/vnd.openxmlformats-officedocument.presentationml.slideLayout+xml"/>' +
1614
+ '<Override PartName="/ppt/theme/theme1.xml" ContentType="application/vnd.openxmlformats-officedocument.theme+xml"/>' +
1615
+ '<Override PartName="/docProps/core.xml" ContentType="application/vnd.openxmlformats-package.core-properties+xml"/>' +
1616
+ '<Override PartName="/docProps/app.xml" ContentType="application/vnd.openxmlformats-officedocument.extended-properties+xml"/>' +
1617
+ notesMasterOverride +
1618
+ overrides +
1619
+ notesOverrides +
1620
+ '</Types>'
1621
+ }
1622
+
1623
+ function rootRelXml() {
1624
+ return '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' +
1625
+ '<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">' +
1626
+ '<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="ppt/presentation.xml"/>' +
1627
+ '<Relationship Id="rId2" Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties" Target="docProps/core.xml"/>' +
1628
+ '<Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties" Target="docProps/app.xml"/>' +
1629
+ '</Relationships>'
1630
+ }
1631
+
1632
+ function coreXml(title) {
1633
+ return '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' +
1634
+ '<cp:coreProperties xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties" ' +
1635
+ 'xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" ' +
1636
+ 'xmlns:dcmitype="http://purl.org/dc/dcmitype/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">' +
1637
+ '<dc:title>' + escapeXml(title) + '</dc:title><dc:creator>dsh-ppt</dc:creator>' +
1638
+ '<cp:lastModifiedBy>dsh-ppt</cp:lastModifiedBy>' +
1639
+ '</cp:coreProperties>'
1640
+ }
1641
+
1642
+ function appXml(slideCount, notesCount) {
1643
+ return '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' +
1644
+ '<Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/extended-properties" ' +
1645
+ 'xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes">' +
1646
+ '<Application>dsh-ppt</Application><PresentationFormat>Widescreen</PresentationFormat>' +
1647
+ '<Slides>' + slideCount + '</Slides><Notes>' + notesCount + '</Notes><HiddenSlides>0</HiddenSlides>' +
1648
+ '</Properties>'
1649
+ }
1650
+
1651
+ function buildZip(entries) {
1652
+ const chunks = []
1653
+ const central = []
1654
+ let offset = 0
1655
+
1656
+ for (const entry of entries) {
1657
+ const entryOffset = offset
1658
+ const name = Buffer.from(entry.name, 'utf8')
1659
+ const data = Buffer.isBuffer(entry.data) ? entry.data : Buffer.from(String(entry.data), 'utf8')
1660
+ const crc = crc32(data)
1661
+ const compressed = deflateRawSync(data)
1662
+ const method = 8
1663
+ const nameLength = name.length
1664
+ const localHeader = Buffer.alloc(30)
1665
+ localHeader.writeUInt32LE(0x04034b50, 0)
1666
+ localHeader.writeUInt16LE(20, 4)
1667
+ localHeader.writeUInt16LE(0x0800, 6) // UTF-8 文件名
1668
+ localHeader.writeUInt16LE(method, 8)
1669
+ localHeader.writeUInt16LE(0, 10) // DOS time
1670
+ localHeader.writeUInt16LE(0x21, 12) // DOS date 1980-01-01
1671
+ localHeader.writeUInt32LE(crc, 14)
1672
+ localHeader.writeUInt32LE(compressed.length, 18)
1673
+ localHeader.writeUInt32LE(data.length, 22)
1674
+ localHeader.writeUInt16LE(nameLength, 26)
1675
+ localHeader.writeUInt16LE(0, 28)
1676
+
1677
+ chunks.push(localHeader, name, compressed)
1678
+ offset += 30 + nameLength + compressed.length
1679
+
1680
+ const centralHeader = Buffer.alloc(46)
1681
+ centralHeader.writeUInt32LE(0x02014b50, 0)
1682
+ centralHeader.writeUInt16LE(20, 4)
1683
+ centralHeader.writeUInt16LE(20, 6)
1684
+ centralHeader.writeUInt16LE(0x0800, 8)
1685
+ centralHeader.writeUInt16LE(method, 10)
1686
+ centralHeader.writeUInt16LE(0, 12)
1687
+ centralHeader.writeUInt16LE(0x21, 14)
1688
+ centralHeader.writeUInt32LE(crc, 16)
1689
+ centralHeader.writeUInt32LE(compressed.length, 20)
1690
+ centralHeader.writeUInt32LE(data.length, 24)
1691
+ centralHeader.writeUInt16LE(nameLength, 28)
1692
+ centralHeader.writeUInt16LE(0, 30)
1693
+ centralHeader.writeUInt16LE(0, 32)
1694
+ centralHeader.writeUInt16LE(0, 34)
1695
+ centralHeader.writeUInt16LE(0, 36)
1696
+ centralHeader.writeUInt32LE(0, 38)
1697
+ centralHeader.writeUInt32LE(entryOffset, 42)
1698
+ central.push(centralHeader, name)
1699
+ }
1700
+
1701
+ const centralOffset = offset
1702
+ const centralSize = central.reduce((sum, part) => sum + part.length, 0)
1703
+ const end = Buffer.alloc(22)
1704
+ end.writeUInt32LE(0x06054b50, 0)
1705
+ end.writeUInt16LE(0, 4)
1706
+ end.writeUInt16LE(0, 6)
1707
+ end.writeUInt16LE(entries.length, 8)
1708
+ end.writeUInt16LE(entries.length, 10)
1709
+ end.writeUInt32LE(centralSize, 12)
1710
+ end.writeUInt32LE(centralOffset, 16)
1711
+ end.writeUInt16LE(0, 20)
1712
+
1713
+ chunks.push(...central, end)
1714
+ return Buffer.concat(chunks)
1715
+ }
1716
+
1717
+ let CRC_TABLE = null
1718
+ function crc32(buffer) {
1719
+ if (CRC_TABLE === null) {
1720
+ CRC_TABLE = new Int32Array(256)
1721
+ for (let n = 0; n < 256; n += 1) {
1722
+ let c = n
1723
+ for (let k = 0; k < 8; k += 1) c = (c & 1) ? (0xedb88320 ^ (c >>> 1)) : (c >>> 1)
1724
+ CRC_TABLE[n] = c
1725
+ }
1726
+ }
1727
+ let crc = 0xffffffff
1728
+ for (let i = 0; i < buffer.length; i += 1) {
1729
+ crc = CRC_TABLE[(crc ^ buffer[i]) & 0xff] ^ (crc >>> 8)
1730
+ }
1731
+ return (crc ^ 0xffffffff) >>> 0
1732
+ }
1733
+
1734
+ export function buildPptx(manifest, themeInput, languageInput) {
1735
+ const theme = themeInput?.id ? themeInput : resolveTheme(themeInput)
1736
+ const language = languageInput?.id ? languageInput : resolveLanguage(languageInput)
1737
+ const motion = manifest.motion !== false
1738
+ const slides = manifest.slides
1739
+ const noteIndexes = []
1740
+ slides.forEach((slide, index) => {
1741
+ if (typeof slide.notes === 'string' && slide.notes.trim() !== '') noteIndexes.push(index)
1742
+ })
1743
+ const hasNotesMaster = noteIndexes.length > 0
1744
+ const entries = [
1745
+ { name: '[Content_Types].xml', data: contentTypesXml(slides.length, noteIndexes) },
1746
+ { name: '_rels/.rels', data: rootRelXml() },
1747
+ { name: 'docProps/app.xml', data: appXml(slides.length, noteIndexes.length) },
1748
+ { name: 'docProps/core.xml', data: coreXml(manifest.title) },
1749
+ { name: 'ppt/presentation.xml', data: presentationXml(slides.length, hasNotesMaster) },
1750
+ { name: 'ppt/_rels/presentation.xml.rels', data: presentationRelXml(slides.length, hasNotesMaster) },
1751
+ { name: 'ppt/slideMasters/slideMaster1.xml', data: slideMasterXml(theme) },
1752
+ { name: 'ppt/slideMasters/_rels/slideMaster1.xml.rels', data: slideMasterRelXml() },
1753
+ { name: 'ppt/slideLayouts/slideLayout1.xml', data: slideLayoutXml(theme) },
1754
+ { name: 'ppt/slideLayouts/_rels/slideLayout1.xml.rels', data: slideLayoutRelXml() },
1755
+ { name: 'ppt/theme/theme1.xml', data: themeXml(theme) },
1756
+ ]
1757
+ if (hasNotesMaster) {
1758
+ entries.push({ name: 'ppt/notesMasters/notesMaster1.xml', data: notesMasterXml() })
1759
+ entries.push({ name: 'ppt/notesMasters/_rels/notesMaster1.xml.rels', data: notesMasterRelXml() })
1760
+ }
1761
+ slides.forEach((slide, index) => {
1762
+ const hasNotes = noteIndexes.includes(index)
1763
+ entries.push({ name: 'ppt/slides/slide' + (index + 1) + '.xml', data: slideXml(slide, index, slides.length, theme, language.attr, motion) })
1764
+ entries.push({ name: 'ppt/slides/_rels/slide' + (index + 1) + '.xml.rels', data: slideRelXml(hasNotes, index + 1) })
1765
+ if (hasNotes) {
1766
+ entries.push({ name: 'ppt/notesSlides/notesSlide' + (index + 1) + '.xml', data: notesSlideXml(slide.notes, language.attr) })
1767
+ entries.push({ name: 'ppt/notesSlides/_rels/notesSlide' + (index + 1) + '.xml.rels', data: notesSlideRelXml(index + 1) })
1768
+ }
1769
+ })
1770
+ return buildZip(entries)
1771
+ }