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