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
|
@@ -2,40 +2,37 @@ import { mkdirSync, readFileSync, statSync, openSync, closeSync, rmSync } from '
|
|
|
2
2
|
import { resolve, dirname, extname, basename } from 'node:path'
|
|
3
3
|
import { createHash, randomUUID } from 'node:crypto'
|
|
4
4
|
import { inflateSync } from 'node:zlib'
|
|
5
|
-
import { buildPptx, renderHtml, normalizeBuildOptions, normalizeSlides,
|
|
6
|
-
import {
|
|
5
|
+
import { buildPptx, renderHtml, normalizeBuildOptions, normalizeSlides, resolveLanguage, resolveDeckFileName, commitDeckArtifacts, DECK_VERSION, buildDeck } from './deck-core.mjs'
|
|
6
|
+
import { listThemes, listMasterPresets, resolveTheme, buildThemePreview as buildThemePreviewFromThemes, deriveBrandedTheme, pptxEastAsianFont } from './deck-themes.mjs'
|
|
7
|
+
import { CORE_LAYOUTS, LAYOUT_ALIASES, stripInlineMarkdown } from './deck-layouts.mjs'
|
|
8
|
+
import { MEDIA_LAYOUTS, mediaBoxes, LOGO_BOX, FOOTER_BOX, normalizeChart, buildOfficeKitChartSpec, computeWaterfallGeometry } from './deck-media.mjs'
|
|
7
9
|
import { normalizeDataModel, prepareDataSlides, validateDataSnapshot, previewDataChange, dataNotes, dataReport } from './deck-data.mjs'
|
|
8
10
|
import { normalizeVisual, applyVisualActions } from './deck-visual.mjs'
|
|
11
|
+
import { absorbPptx, CHROME_STYLE_IDS } from './deck-absorb.mjs'
|
|
12
|
+
import { SCENARIO_TEMPLATES, findScenarioTemplate, buildScenarioSlides, listScenarioTemplates, inferThemeFromContent, promoteMarkdownSlides, auditSlideAesthetics } from './deck-director.mjs'
|
|
9
13
|
export { readRenderReceipt } from './deck-render.mjs'
|
|
10
14
|
export { dataNotes, dataReport } from './deck-data.mjs'
|
|
11
|
-
export { buildDeck,
|
|
15
|
+
export { buildDeck, resolveLanguage } from './deck-core.mjs'
|
|
16
|
+
export { listThemes, listMasterPresets, resolveTheme } from './deck-themes.mjs'
|
|
17
|
+
export { absorbPptx } from './deck-absorb.mjs'
|
|
18
|
+
export { inferThemeFromContent } from './deck-director.mjs'
|
|
19
|
+
|
|
20
|
+
export function buildThemePreview(options = {}) {
|
|
21
|
+
return buildThemePreviewFromThemes(options, resolveLanguage, DECK_VERSION)
|
|
22
|
+
}
|
|
12
23
|
|
|
13
24
|
const MAX_IMAGE = 5 * 1024 * 1024, MAX_ASSETS = 32 * 1024 * 1024, MAX_DOCUMENT = 64 * 1024 * 1024
|
|
14
25
|
const MAX_HISTORY = 20
|
|
15
|
-
const
|
|
26
|
+
const canonicalLayouts = new Set([...CORE_LAYOUTS, ...MEDIA_LAYOUTS])
|
|
27
|
+
const layouts = new Set([...canonicalLayouts, ...Object.keys(LAYOUT_ALIASES)])
|
|
16
28
|
const hash = data => createHash('sha256').update(data).digest('hex')
|
|
17
29
|
const clone = value => structuredClone(value)
|
|
18
30
|
function abort(signal) { signal?.throwIfAborted() }
|
|
19
31
|
function fail(message) { throw new Error('dsh-ppt:' + message) }
|
|
20
32
|
|
|
21
|
-
const scenarios = [
|
|
22
|
-
{ id: 'weekly', name: { zh: '工作周报', en: 'Weekly report' }, theme: 'data', sections: [['本周工作', 'This week'], ['完成情况', 'Progress'], ['问题与风险', 'Risks'], ['下周计划', 'Next week']] },
|
|
23
|
-
{ id: 'defense', name: { zh: '论文答辩', en: 'Thesis defense' }, theme: 'soft', sections: [['研究问题', 'Research question'], ['相关研究', 'Related work'], ['研究方法', 'Method'], ['研究结果', 'Results'], ['结论与局限', 'Conclusions and limitations']] },
|
|
24
|
-
{ id: 'project', name: { zh: '项目汇报', en: 'Project update' }, theme: 'swiss', sections: [['目标与范围', 'Goals and scope'], ['进度与交付', 'Progress and delivery'], ['数据与证据', 'Evidence'], ['风险与决策', 'Risks and decisions'], ['下一步', 'Next steps']] },
|
|
25
|
-
{ id: 'pitch', name: { zh: '项目路演', en: 'Pitch deck' }, theme: 'velvet', sections: [['用户问题', 'Customer problem'], ['解决方案', 'Solution'], ['产品与证据', 'Product and evidence'], ['商业模式', 'Business model'], ['计划与需求', 'Plan and ask']] },
|
|
26
|
-
]
|
|
27
|
-
|
|
28
33
|
export function listTemplates(lang = 'zh') {
|
|
29
34
|
const language = resolveLanguage(lang).id === 'en' ? 'en' : 'zh'
|
|
30
|
-
return
|
|
31
|
-
outline: s.sections.map(p => p[language === 'en' ? 1 : 0]),
|
|
32
|
-
slides: templateSlides(s, s.name[language], language) }))
|
|
33
|
-
}
|
|
34
|
-
function templateSlides(scenario, title, lang) {
|
|
35
|
-
const en = lang === 'en'
|
|
36
|
-
return [{ layout: 'cover', title, subtitle: en ? 'To fill: presenter and date' : '待填写:汇报人和日期' },
|
|
37
|
-
...scenario.sections.map(section => ({ layout: 'bullets', title: section[en ? 1 : 0], bullets: [en ? 'To fill: specific facts, evidence and next action' : '待填写:具体事实、依据与下一步行动'] })),
|
|
38
|
-
{ layout: 'closing', title: en ? 'Next action' : '下一步行动', subtitle: en ? 'To fill: owner and deadline' : '待填写:负责人和时间' }]
|
|
35
|
+
return listScenarioTemplates(language)
|
|
39
36
|
}
|
|
40
37
|
|
|
41
38
|
function imageInfo(bytes, page) {
|
|
@@ -98,26 +95,40 @@ function addAsset(image, assets, cwd, page) {
|
|
|
98
95
|
return id
|
|
99
96
|
}
|
|
100
97
|
|
|
98
|
+
const CHROME_STYLE_SET = new Set(CHROME_STYLE_IDS)
|
|
99
|
+
|
|
101
100
|
function normalizeBrand(input, assets, cwd) {
|
|
102
101
|
if (input === undefined || input === null) return undefined
|
|
103
102
|
if (typeof input !== 'object' || Array.isArray(input)) fail('brand 必须是对象')
|
|
104
103
|
const brand = {}
|
|
105
|
-
for (const key of ['primaryColor', 'backgroundColor', 'textColor']) {
|
|
106
|
-
if (input[key] !== undefined && input[key] !== '') {
|
|
104
|
+
for (const key of ['primaryColor', 'secondaryColor', 'backgroundColor', 'textColor', 'coverBg']) {
|
|
105
|
+
if (input[key] !== undefined && input[key] !== null && input[key] !== '') {
|
|
107
106
|
if (!/^#[\da-f]{6}$/i.test(input[key])) fail(`brand.${key} 必须为 #RRGGBB`)
|
|
108
107
|
brand[key] = input[key].toUpperCase()
|
|
109
108
|
}
|
|
110
109
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
110
|
+
for (const fontKey of ['fontFamily', 'headingFont']) {
|
|
111
|
+
if (input[fontKey]) {
|
|
112
|
+
const font = String(input[fontKey]).trim()
|
|
113
|
+
if (font.length > 80 || !/^[\p{L}\p{N} _-]+$/u.test(font)) fail(`brand.${fontKey} 需单个字体名称,最多 80 字符`)
|
|
114
|
+
brand[fontKey] = font
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
if (input.coverMode !== undefined && input.coverMode !== null && input.coverMode !== '') {
|
|
118
|
+
const cm = String(input.coverMode).trim()
|
|
119
|
+
if (!['standard', 'inverted-accent'].includes(cm)) fail('brand.coverMode 仅支持 standard / inverted-accent')
|
|
120
|
+
brand.coverMode = cm
|
|
115
121
|
}
|
|
116
122
|
if (input.name) brand.name = String(input.name).slice(0, 100)
|
|
117
123
|
if (input.footer) {
|
|
118
124
|
if (String(input.footer).length > 100) fail('brand.footer 最多 100 字符')
|
|
119
125
|
brand.footer = String(input.footer)
|
|
120
126
|
}
|
|
127
|
+
if (input.chromeStyle !== undefined && input.chromeStyle !== null && input.chromeStyle !== '') {
|
|
128
|
+
const cs = String(input.chromeStyle).trim().toLowerCase()
|
|
129
|
+
if (!CHROME_STYLE_SET.has(cs)) fail('brand.chromeStyle 需为 ' + CHROME_STYLE_IDS.join(' / '))
|
|
130
|
+
brand.chromeStyle = cs
|
|
131
|
+
}
|
|
121
132
|
if (input.logo) brand.logoAssetId = addAsset({ src: input.logo }, assets, cwd, '品牌 Logo')
|
|
122
133
|
else if (input.logoAssetId) {
|
|
123
134
|
if (!assets[input.logoAssetId]) fail('品牌 Logo 嵌入资产不存在')
|
|
@@ -125,42 +136,70 @@ function normalizeBrand(input, assets, cwd) {
|
|
|
125
136
|
}
|
|
126
137
|
return brand
|
|
127
138
|
}
|
|
139
|
+
|
|
128
140
|
function brandedTheme(manifest) {
|
|
129
|
-
|
|
130
|
-
if (brand?.primaryColor) theme.palette.accent = brand.primaryColor
|
|
131
|
-
if (brand?.backgroundColor) theme.palette.bg = brand.backgroundColor
|
|
132
|
-
if (brand?.textColor) theme.palette.fg = brand.textColor
|
|
133
|
-
if (brand?.fontFamily) theme.fonts = { heading: brand.fontFamily, body: brand.fontFamily }
|
|
134
|
-
return theme
|
|
141
|
+
return deriveBrandedTheme(manifest.theme, manifest.brand)
|
|
135
142
|
}
|
|
143
|
+
|
|
136
144
|
function embedSlides(slides, assets, cwd) {
|
|
137
145
|
return slides.map((slide, index) => {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
146
|
+
const pageLabel = `第 ${index + 1} 页`
|
|
147
|
+
let nextSlide = slide
|
|
148
|
+
if (slide.image) {
|
|
149
|
+
const assetId = addAsset(slide.image, assets, cwd, pageLabel)
|
|
150
|
+
const { src, ...image } = slide.image
|
|
151
|
+
nextSlide = { ...nextSlide, image: { ...image, assetId } }
|
|
152
|
+
}
|
|
153
|
+
if (Array.isArray(slide.images) && slide.images.length > 0) {
|
|
154
|
+
const embeddedImages = slide.images.map((img, gIdx) => {
|
|
155
|
+
const assetId = addAsset(img, assets, cwd, `${pageLabel}图 ${gIdx + 1}`)
|
|
156
|
+
const { src, ...rest } = img
|
|
157
|
+
return { ...rest, assetId }
|
|
158
|
+
})
|
|
159
|
+
nextSlide = { ...nextSlide, images: embeddedImages }
|
|
160
|
+
}
|
|
161
|
+
return nextSlide
|
|
142
162
|
})
|
|
143
163
|
}
|
|
164
|
+
|
|
165
|
+
function effectiveLayout(rawLayout) {
|
|
166
|
+
if (!rawLayout) return undefined
|
|
167
|
+
return LAYOUT_ALIASES[rawLayout]?.layout || rawLayout
|
|
168
|
+
}
|
|
169
|
+
|
|
144
170
|
function validateRawSlides(slides) {
|
|
145
171
|
if (slides === undefined || slides === null) return
|
|
146
172
|
if (!Array.isArray(slides)) fail('slides 必须是数组')
|
|
147
173
|
slides.forEach((s, i) => {
|
|
148
174
|
if (!s || typeof s !== 'object' || Array.isArray(s)) fail(`第 ${i + 1} 页必须是对象`)
|
|
149
175
|
if (s.layout && !layouts.has(s.layout)) fail(`第 ${i + 1} 页未知布局 ${s.layout}`)
|
|
176
|
+
if (s.chrome !== undefined && s.chrome !== null && s.chrome !== '') {
|
|
177
|
+
const ch = String(s.chrome).trim().toLowerCase()
|
|
178
|
+
if (!CHROME_STYLE_SET.has(ch)) fail(`第 ${i + 1} 页未知母版骨架 chrome: ${s.chrome}`)
|
|
179
|
+
}
|
|
150
180
|
normalizeVisual(s.visual)
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
if (s.chart &&
|
|
181
|
+
const eff = effectiveLayout(s.layout)
|
|
182
|
+
const hasImg = Boolean(s.image || (Array.isArray(s.images) && s.images.length > 0))
|
|
183
|
+
if (s.chart && hasImg) fail(`第 ${i + 1} 页不能同时放入 image 和 chart`)
|
|
184
|
+
if (hasImg && eff && !['image', 'image-left', 'image-right'].includes(eff)) fail(`第 ${i + 1} 页图片需使用 image / image-left / image-right / gallery 布局`)
|
|
185
|
+
if (s.chart && eff && !['chart', 'chart-split'].includes(eff)) fail(`第 ${i + 1} 页图表需使用 chart / chart-split / waterfall 布局`)
|
|
154
186
|
})
|
|
155
187
|
}
|
|
188
|
+
|
|
156
189
|
function snapshot(manifest) {
|
|
157
190
|
return clone(Object.fromEntries(['title', 'theme', 'language', 'motion', 'slides', 'brand', 'template', 'dataModel'].filter(k => manifest[k] !== undefined).map(k => [k, manifest[k]])))
|
|
158
191
|
}
|
|
192
|
+
|
|
159
193
|
function collectAssets(manifest) {
|
|
160
194
|
const ids = new Set()
|
|
161
195
|
for (const state of [manifest, ...(manifest.history ?? [])]) {
|
|
162
196
|
if (state.brand?.logoAssetId) ids.add(state.brand.logoAssetId)
|
|
163
|
-
for (const slide of state.slides)
|
|
197
|
+
for (const slide of state.slides) {
|
|
198
|
+
if (slide.image?.assetId) ids.add(slide.image.assetId)
|
|
199
|
+
if (Array.isArray(slide.images)) {
|
|
200
|
+
for (const img of slide.images) if (img?.assetId) ids.add(img.assetId)
|
|
201
|
+
}
|
|
202
|
+
}
|
|
164
203
|
}
|
|
165
204
|
manifest.assets = Object.fromEntries([...ids].map(id => [id, manifest.assets[id]]))
|
|
166
205
|
const size = Object.values(manifest.assets).reduce((sum, asset) => sum + (asset?.data?.length ?? 0), 0)
|
|
@@ -181,7 +220,7 @@ function embeddedAssetError(asset, id) {
|
|
|
181
220
|
}
|
|
182
221
|
|
|
183
222
|
// This is a conservative fit estimate. Fonts and PowerPoint/WPS rendering still need visual inspection.
|
|
184
|
-
function textWidth(text) { return [...String(text ?? '')].reduce((n, c) => n + (/[^\x00-\xff]/.test(c) ? 1 : 0.55), 0) }
|
|
223
|
+
function textWidth(text) { return [...stripInlineMarkdown(String(text ?? ''))].reduce((n, c) => n + (/[^\x00-\xff]/.test(c) ? 1 : 0.55), 0) }
|
|
185
224
|
function contrast(a, b) {
|
|
186
225
|
const lum = color => {
|
|
187
226
|
const rgb = color.slice(1).match(/../g).map(v => parseInt(v, 16) / 255).map(v => v <= .04045 ? v / 12.92 : ((v + .055) / 1.055) ** 2.4)
|
|
@@ -189,6 +228,7 @@ function contrast(a, b) {
|
|
|
189
228
|
}
|
|
190
229
|
const x = lum(a), y = lum(b); return (Math.max(x, y) + .05) / (Math.min(x, y) + .05)
|
|
191
230
|
}
|
|
231
|
+
|
|
192
232
|
export function checkManifest(manifest) {
|
|
193
233
|
const issues = [], theme = brandedTheme(manifest)
|
|
194
234
|
const invalidAssets = new Map()
|
|
@@ -199,21 +239,39 @@ export function checkManifest(manifest) {
|
|
|
199
239
|
const issue = (index, code, message, suggestion, severity = 'warning') => issues.push({ slide: index + 1, slideId: manifest.slides[index]?.id, severity, code, message, suggestion })
|
|
200
240
|
manifest.slides.forEach((slide, i) => {
|
|
201
241
|
if (!slide.title?.trim()) issue(i, 'missing-title', '页面没有标题', '补充能说明本页内容的标题')
|
|
202
|
-
const titleLimit = ['cover', 'closing', 'statement', 'quote', 'section'].includes(slide.layout) ? 40 :
|
|
242
|
+
const titleLimit = ['cover', 'closing', 'statement', 'quote', 'section'].includes(slide.layout) ? 40 : 34
|
|
203
243
|
if (textWidth(slide.title) > titleLimit) issue(i, 'title-overflow', '标题可能换行过多或超过标题区域', '缩短标题,把解释移入正文')
|
|
204
|
-
const mixed = ['image-left', 'image-right'].includes(slide.layout), bullets = slide.bullets ?? []
|
|
244
|
+
const mixed = ['image-left', 'image-right', 'chart-split'].includes(slide.layout), bullets = slide.bullets ?? []
|
|
205
245
|
if (bullets.length > (mixed ? 5 : 8)) issue(i, 'dense-bullets', `本页有 ${bullets.length} 条要点,放映时过密`, '减少要点或拆成多页')
|
|
206
|
-
const width = mixed ?
|
|
246
|
+
const width = mixed ? 24 : 37
|
|
207
247
|
const lines = bullets.reduce((sum, b) => sum + Math.max(1, Math.ceil(textWidth(b) / width)), 0)
|
|
208
248
|
+ (slide.subtitle ? Math.ceil(textWidth(slide.subtitle) / width) : 0)
|
|
209
|
-
if (
|
|
210
|
-
|
|
249
|
+
if (slide.layout === 'bullets' || mixed) {
|
|
250
|
+
if (lines > (mixed ? 9 : 11)) issue(i, 'body-overflow', '正文估计超过可用高度', '先精简文字,再分拆页面,避免继续缩小字体')
|
|
251
|
+
}
|
|
252
|
+
const itemStrings = Array.isArray(slide.items)
|
|
253
|
+
? slide.items.flatMap(it => [it?.title, it?.text, it?.value, ...(it?.bullets ?? [])]).filter(Boolean)
|
|
254
|
+
: []
|
|
255
|
+
if ([slide.title, slide.subtitle, slide.takeaway, ...bullets, ...itemStrings].some(s => /待填写|To fill:/i.test(String(s)))) {
|
|
256
|
+
issue(i, 'template-unfilled', '模板中还有待填写内容', '提供实际事实、依据和行动,填完后重新检查')
|
|
257
|
+
}
|
|
211
258
|
if (slide.layout === 'table') {
|
|
212
|
-
if ((slide.rows?.[0]?.length ?? 0) > 6) issue(i, 'small-font', '表格超过 6
|
|
259
|
+
if ((slide.rows?.[0]?.length ?? 0) > 6) issue(i, 'small-font', '表格超过 6 列,使用较小字号,小屏放映可能难以阅读', '减少列数或把重点数据改成图表,导出后检查可读性')
|
|
213
260
|
if (slide.rows?.some(row => row.some(c => textWidth(c) > 18))) issue(i, 'table-density', '表格单元格文字较长,可能换行拥挤', '精简单元格或减少列数')
|
|
214
261
|
}
|
|
215
|
-
|
|
216
|
-
|
|
262
|
+
const boxes = MEDIA_LAYOUTS.has(slide.layout) ? mediaBoxes(slide.layout, slide.variant, slide) : null
|
|
263
|
+
if (Array.isArray(boxes?.gallery) && Array.isArray(slide.images) && slide.images.length > 1) {
|
|
264
|
+
slide.images.forEach((img, gIdx) => {
|
|
265
|
+
const asset = manifest.assets?.[img?.assetId], gBox = boxes.gallery[gIdx] || boxes.image
|
|
266
|
+
if (!asset) issue(i, 'missing-image', `找不到本页第 ${gIdx + 1} 张嵌入图片`, '重新指定图片路径后编辑本页', 'error')
|
|
267
|
+
else {
|
|
268
|
+
if (assetError(img.assetId)) issue(i, 'invalid-image', assetError(img.assetId), '重新提供本地图片后编辑该页', 'error')
|
|
269
|
+
if (asset.width < gBox.w * 100 || asset.height < gBox.h * 100) issue(i, 'low-resolution', `图片为 ${asset.width}×${asset.height},放大后可能模糊`, '换成更高分辨率图片;Logo 等小图可忽略此提示')
|
|
270
|
+
}
|
|
271
|
+
if (!img?.alt?.trim()) issue(i, 'missing-alt', '图片没有说明文字', '填写 images[].alt,方便读屏及理解图片')
|
|
272
|
+
})
|
|
273
|
+
} else if (slide.image) {
|
|
274
|
+
const asset = manifest.assets?.[slide.image.assetId], box = boxes?.image || mediaBoxes('image').image
|
|
217
275
|
if (!asset) issue(i, 'missing-image', '找不到本页的嵌入图片', '重新指定图片路径后编辑本页', 'error')
|
|
218
276
|
else {
|
|
219
277
|
if (assetError(slide.image.assetId)) issue(i, 'invalid-image', assetError(slide.image.assetId), '重新提供本地图片后编辑该页', 'error')
|
|
@@ -223,21 +281,83 @@ export function checkManifest(manifest) {
|
|
|
223
281
|
}
|
|
224
282
|
if (slide.chart) {
|
|
225
283
|
try { normalizeChart(slide.chart, i + 1) } catch (error) { issue(i, 'invalid-chart', error.message, '修正图表类别和数值', 'error') }
|
|
226
|
-
if (slide.chart.categories?.length > 10 || slide.chart.categories?.some(c => textWidth(c) > 10))
|
|
284
|
+
if (slide.chart.categories?.length > 10 || (slide.chart.kind !== 'bar' && slide.chart.kind !== 'stacked-bar' && slide.chart.kind !== 'percent-bar' && slide.chart.categories?.some(c => textWidth(c) > 10))) {
|
|
285
|
+
issue(i, 'chart-density', '图表类别较多或标签较长,可能相互遮挡', '减少类别,或使用横向条形图 bar')
|
|
286
|
+
}
|
|
227
287
|
if (slide.chart.series?.some(s => textWidth(s.name) > 14)) issue(i, 'chart-legend', '图例名称较长', '精简系列名称并检查渲染')
|
|
228
288
|
}
|
|
229
289
|
if (contrast(theme.palette.bg, theme.palette.fg) < 4.5) issue(i, 'low-contrast', '正文与背景对比度低于 4.5:1', '调整品牌背景色或文字色')
|
|
230
290
|
})
|
|
231
291
|
if (manifest.brand?.logoAssetId && !manifest.assets?.[manifest.brand.logoAssetId]) issue(0, 'missing-logo', '品牌 Logo 资产不存在', '重新提供 Logo', 'error')
|
|
232
292
|
else if (manifest.brand?.logoAssetId && assetError(manifest.brand.logoAssetId)) issue(0, 'invalid-logo', assetError(manifest.brand.logoAssetId), '重新提供 Logo', 'error')
|
|
293
|
+
|
|
294
|
+
// 追加 SLOP-01..10 审美反模式静态诊断
|
|
295
|
+
for (const aestheticIssue of auditSlideAesthetics(manifest, theme, textWidth)) {
|
|
296
|
+
issues.push(aestheticIssue)
|
|
297
|
+
}
|
|
298
|
+
|
|
233
299
|
return { ok: !issues.some(i => i.severity === 'error'), slideCount: manifest.slides.length,
|
|
234
300
|
errorCount: issues.filter(i => i.severity === 'error').length, warningCount: issues.filter(i => i.severity === 'warning').length,
|
|
235
301
|
issues, note: '文字尺寸与溢出为静态估算;最终请检查 HTML 放映和 PowerPoint / WPS 实际显示。页脚和页码的小字号不计入正文检查。' }
|
|
236
302
|
}
|
|
237
303
|
|
|
304
|
+
function drawNativeWaterfallWithKit(lib, slide, chart, boxIn, theme) {
|
|
305
|
+
const emuVal = inches => Math.round(inches * 914400)
|
|
306
|
+
const cb = { x: emuVal(boxIn.x), y: emuVal(boxIn.y), w: emuVal(boxIn.w), h: emuVal(boxIn.h) }
|
|
307
|
+
const plotLeft = cb.x + Math.round(cb.w * 0.085)
|
|
308
|
+
const plotRight = cb.x + Math.round(cb.w * 0.975)
|
|
309
|
+
const plotTop = cb.y + Math.round(cb.h * 0.11)
|
|
310
|
+
const plotBottom = cb.y + Math.round(cb.h * 0.83)
|
|
311
|
+
const geom = computeWaterfallGeometry(chart, { left: plotLeft, right: plotRight, top: plotTop, bottom: plotBottom })
|
|
312
|
+
|
|
313
|
+
const tokens = theme.tokens || {}
|
|
314
|
+
const fg = tokens.inkPrimary || theme.palette.fg
|
|
315
|
+
const muted = tokens.inkMuted || theme.palette.muted
|
|
316
|
+
const hairline = tokens.hairline || theme.palette.panel
|
|
317
|
+
const focalColor = tokens.chartFocal || theme.palette.accent
|
|
318
|
+
const posColor = tokens.positive || '#0D7A4E'
|
|
319
|
+
const negColor = tokens.negative || '#C81E1E'
|
|
320
|
+
const font = pptxEastAsianFont(theme.fonts.body)
|
|
321
|
+
|
|
322
|
+
geom.ticks.forEach((tk, idx) => {
|
|
323
|
+
const grid = lib.addSlideLine(slide, { x1: plotLeft, y1: Math.round(tk.y), x2: plotRight, y2: Math.round(tk.y), name: `Waterfall Grid ${idx}` })
|
|
324
|
+
lib.setShapeStroke(grid, { color: hairline, width: 9525 })
|
|
325
|
+
const lbl = lib.addSlideTextBox(slide, { x: cb.x, y: Math.round(tk.y - 95000), w: Math.max(91440, plotLeft - cb.x - 68000), h: 190000, text: tk.label, name: `Waterfall Tick ${idx}` })
|
|
326
|
+
lib.setShapeTextFormat(lbl, { size: 11, font, color: muted })
|
|
327
|
+
lib.setShapeAlignment(lbl, 'right')
|
|
328
|
+
})
|
|
329
|
+
|
|
330
|
+
geom.connectors.forEach((cn, idx) => {
|
|
331
|
+
const bridge = lib.addSlideLine(slide, { x1: Math.round(cn.x1), y1: Math.round(cn.y1), x2: Math.round(cn.x2), y2: Math.round(cn.y2), name: `Waterfall Bridge ${idx + 1}` })
|
|
332
|
+
lib.setShapeStroke(bridge, { color: muted, width: 11430, dash: 'dash' })
|
|
333
|
+
})
|
|
334
|
+
|
|
335
|
+
geom.bars.forEach((b, idx) => {
|
|
336
|
+
const col = b.role === 'total' ? focalColor : b.role === 'positive' ? posColor : negColor
|
|
337
|
+
const bar = lib.addSlideShape(slide, 'roundRect', { x: Math.round(b.x), y: Math.round(b.y), w: Math.round(b.w), h: Math.max(25400, Math.round(b.h)), name: `Waterfall Bar ${idx + 1}` })
|
|
338
|
+
lib.setShapeFill(bar, col)
|
|
339
|
+
lib.setShapeNoStroke(bar)
|
|
340
|
+
const labelY = b.value >= 0 || b.isTotal ? Math.round(b.y - 220000) : Math.round(b.y + b.h + 25000)
|
|
341
|
+
const valBox = lib.addSlideTextBox(slide, { x: Math.round(b.x - 95000), y: labelY, w: Math.round(b.w + 190000), h: 205000, text: b.label, name: `Waterfall Value ${idx + 1}` })
|
|
342
|
+
lib.setShapeTextFormat(valBox, { size: 11.5, font, color: b.role === 'total' ? fg : col, bold: true })
|
|
343
|
+
lib.setShapeAlignment(valBox, 'center')
|
|
344
|
+
const catBox = lib.addSlideTextBox(slide, { x: Math.round(b.x - 110000), y: plotBottom + 42000, w: Math.round(b.w + 220000), h: 240000, text: b.category, name: `Waterfall Category ${idx + 1}` })
|
|
345
|
+
lib.setShapeTextFormat(catBox, { size: 12, font, color: fg })
|
|
346
|
+
lib.setShapeAlignment(catBox, 'center')
|
|
347
|
+
})
|
|
348
|
+
|
|
349
|
+
const axis = lib.addSlideLine(slide, { x1: plotLeft, y1: Math.round(geom.zeroY), x2: plotRight, y2: Math.round(geom.zeroY), name: 'Waterfall Baseline' })
|
|
350
|
+
lib.setShapeStroke(axis, { color: tokens.inkSecondary || muted, width: 15875 })
|
|
351
|
+
}
|
|
352
|
+
|
|
238
353
|
async function exportPptx(manifest, theme, language, signal) {
|
|
239
|
-
const base = buildPptx({ ...manifest, slides: manifest.slides.map(s => ({ ...s, notes: dataNotes(manifest,s) })) }, theme, language)
|
|
240
|
-
|
|
354
|
+
const base = buildPptx({ ...manifest, slides: manifest.slides.map(s => ({ ...s, notes: dataNotes(manifest, s) })) }, theme, language)
|
|
355
|
+
const hasWaterfall = manifest.slides.some(s => s.chart?.kind === 'waterfall')
|
|
356
|
+
const waterfallMissingInBase = hasWaterfall && !base.includes(Buffer.from('Waterfall Bar 1'))
|
|
357
|
+
const hasOfficeKitChart = manifest.slides.some(s => s.chart && s.chart.kind !== 'waterfall')
|
|
358
|
+
const hasImages = manifest.slides.some(s => s.image || (Array.isArray(s.images) && s.images.length > 0))
|
|
359
|
+
if (!manifest.brand?.logoAssetId && !manifest.brand?.footer && !hasImages && !hasOfficeKitChart && !waterfallMissingInBase) return base
|
|
360
|
+
|
|
241
361
|
abort(signal)
|
|
242
362
|
let lib
|
|
243
363
|
try { lib = await import('@office-kit/pptx') } catch (error) { fail('图片、图表和品牌导出需要 @office-kit/pptx@0.21.0。插件请重新安装;独立技能请在技能目录运行 npm install --ignore-scripts。' + error.message) }
|
|
@@ -256,26 +376,29 @@ async function exportPptx(manifest, theme, language, signal) {
|
|
|
256
376
|
}
|
|
257
377
|
manifest.slides.forEach((source, index) => {
|
|
258
378
|
abort(signal)
|
|
259
|
-
const slide = slides[index]
|
|
260
|
-
|
|
379
|
+
const slide = slides[index]
|
|
380
|
+
const boxes = MEDIA_LAYOUTS.has(source.layout) ? mediaBoxes(source.layout, source.variant, source) : mediaBoxes('image')
|
|
381
|
+
if (Array.isArray(boxes.gallery) && Array.isArray(source.images) && source.images.length > 1) {
|
|
382
|
+
boxes.gallery.forEach((gBox, gIdx) => {
|
|
383
|
+
const img = source.images[gIdx]
|
|
384
|
+
if (img?.assetId) putImage(slide, img.assetId, gBox, img.fit || 'cover', `Gallery image ${gIdx + 1}`, img.alt)
|
|
385
|
+
})
|
|
386
|
+
} else if (source.image) {
|
|
387
|
+
putImage(slide, source.image.assetId, boxes.image, source.image.fit, 'Slide image', source.image.alt)
|
|
388
|
+
}
|
|
261
389
|
if (source.chart) {
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
...(source.chart.kind === 'bar' ? { categoryAxisOrientation: 'maxMin', valueAxisCrosses: 'max' } : {}),
|
|
272
|
-
...(source.chart.kind === 'pie' ? { dataLabels: { showPercent: true, showValue: false, showCategory: false, showSeriesName: false, numberFormat: '0.0%', position: 'bestFit', textStyle: style } } : {}),
|
|
273
|
-
...(source.chart.unit ? { valueAxisTitle: source.chart.unit, valueAxisTitleStyle: style } : {}),
|
|
274
|
-
legend: { position: 'b', textStyle: style },
|
|
275
|
-
} })
|
|
390
|
+
if (source.chart.kind === 'waterfall') {
|
|
391
|
+
if (!lib.findShapeByName(slide, 'Waterfall Bar 1')) {
|
|
392
|
+
drawNativeWaterfallWithKit(lib, slide, source.chart, boxes.chart, theme)
|
|
393
|
+
}
|
|
394
|
+
} else {
|
|
395
|
+
const font = pptxEastAsianFont(theme.fonts.body)
|
|
396
|
+
const spec = buildOfficeKitChartSpec(source.chart, theme, source.visual, font)
|
|
397
|
+
lib.addSlideChart(slide, { ...emu(boxes.chart), name: 'Editable data chart', spec })
|
|
398
|
+
}
|
|
276
399
|
}
|
|
277
400
|
if (manifest.brand?.logoAssetId) putImage(slide, manifest.brand.logoAssetId, LOGO_BOX, 'contain', 'Brand logo', manifest.brand.name)
|
|
278
|
-
if (manifest.brand?.footer) {
|
|
401
|
+
if (manifest.brand?.footer && !lib.findShapeByName(slide, 'Footer source')) {
|
|
279
402
|
const footer = lib.addSlideTextBox(slide, { ...emu(FOOTER_BOX), text: manifest.brand.footer, name: 'Brand footer' })
|
|
280
403
|
lib.setShapeTextFormat(footer, { size: 10, font: pptxEastAsianFont(theme.fonts.body), color: theme.palette.muted })
|
|
281
404
|
}
|
|
@@ -329,25 +452,31 @@ function commit(paths, data) {
|
|
|
329
452
|
commitDeckArtifacts([{ path: paths.json, data: documentBytes(data.manifest), encoding: 'utf8' }, { path: paths.html, data: html, encoding: 'utf8' }, { path: paths.pptx, data: data.pptx }])
|
|
330
453
|
}
|
|
331
454
|
|
|
455
|
+
function validateEmbeddedImgObject(img, assets) {
|
|
456
|
+
if (img.fit !== undefined && !['contain', 'cover'].includes(img.fit)) fail('工程 image.fit 只允许 contain / cover')
|
|
457
|
+
if (img.src !== undefined || !assets[img.assetId]) fail('工程图片必须使用有效的嵌入资产')
|
|
458
|
+
}
|
|
459
|
+
|
|
332
460
|
function validateSnapshot(value, assets) {
|
|
333
461
|
resolveTheme(value.theme); resolveLanguage(value.language)
|
|
334
462
|
validateRawSlides(value.slides)
|
|
335
463
|
validateDataSnapshot(value, normalizeSlides)
|
|
336
464
|
if (value.brand != null) {
|
|
337
465
|
if (Object.hasOwn(value.brand, 'logo')) fail('工程品牌仅支持嵌入的 logoAssetId,不读取本地 logo 路径')
|
|
338
|
-
for (const key of ['primaryColor', 'backgroundColor', 'textColor', 'fontFamily', 'name', 'footer']) {
|
|
466
|
+
for (const key of ['primaryColor', 'secondaryColor', 'backgroundColor', 'textColor', 'fontFamily', 'headingFont', 'coverMode', 'coverBg', 'name', 'footer', 'chromeStyle']) {
|
|
339
467
|
if (value.brand[key] !== undefined && typeof value.brand[key] !== 'string') fail('工程 brand.' + key + ' 必须为字符串')
|
|
340
468
|
}
|
|
341
469
|
normalizeBrand(value.brand, assets, '.')
|
|
342
470
|
}
|
|
343
471
|
for (const slide of value.slides) {
|
|
344
|
-
if (slide.image)
|
|
345
|
-
|
|
346
|
-
|
|
472
|
+
if (slide.image) validateEmbeddedImgObject(slide.image, assets)
|
|
473
|
+
if (Array.isArray(slide.images)) {
|
|
474
|
+
for (const img of slide.images) validateEmbeddedImgObject(img, assets)
|
|
347
475
|
}
|
|
348
476
|
if (slide.chart) normalizeChart(slide.chart)
|
|
349
477
|
}
|
|
350
478
|
}
|
|
479
|
+
|
|
351
480
|
function artifactProblem(manifest, paths) {
|
|
352
481
|
if (!manifest.artifacts) return '旧工程没有成品校验记录,无法确认外部修改;请另存副本,保留原文件。'
|
|
353
482
|
for (const kind of ['html', 'pptx']) {
|
|
@@ -356,25 +485,152 @@ function artifactProblem(manifest, paths) {
|
|
|
356
485
|
}
|
|
357
486
|
}
|
|
358
487
|
|
|
488
|
+
const SKELETON_METRIC_RE = /(?:^|[^\d])[-+]?\d+(?:,\d{3})*(?:\.\d+)?\s*(?:[%%倍xX万亿千百元美元刀kKmMbB+家个席天周月年项次]|pp\b|bps\b|ms\b|pts?\b)/i
|
|
489
|
+
|
|
490
|
+
function mapSlidesToAbsorbedSkeleton(slides, slideSkeleton, langId) {
|
|
491
|
+
if (!Array.isArray(slides) || !Array.isArray(slideSkeleton) || slideSkeleton.length === 0) return slides
|
|
492
|
+
const bodySkeleton = slideSkeleton.filter((entry) => entry && !['cover', 'closing', 'section'].includes(entry.inferredLayout))
|
|
493
|
+
const cyclePool = bodySkeleton.length > 0 ? bodySkeleton : slideSkeleton
|
|
494
|
+
let cursor = 0
|
|
495
|
+
const mapped = slides.map((slide, idx) => {
|
|
496
|
+
if (slide.layout === 'cover' || slide.layout === 'closing' || slide.layout === 'section' || slide.layout === 'agenda') {
|
|
497
|
+
return slide
|
|
498
|
+
}
|
|
499
|
+
const target = cyclePool[cursor % cyclePool.length]
|
|
500
|
+
cursor += 1
|
|
501
|
+
if (!target || !target.inferredLayout) return slide
|
|
502
|
+
const want = target.inferredLayout
|
|
503
|
+
const bullets = Array.isArray(slide.bullets) ? slide.bullets : []
|
|
504
|
+
const n = bullets.length
|
|
505
|
+
const metricHits = bullets.filter((b) => SKELETON_METRIC_RE.test(stripInlineMarkdown(b))).length
|
|
506
|
+
const hasMetrics = n >= 2 && n <= 4 && (metricHits / n) >= 0.75
|
|
507
|
+
// Avoid breaking Markdown-only slides that lack media assets (chart/image) by mapping media slots to visual card equivalents
|
|
508
|
+
if (want === 'chart' || want === 'chart-split' || want === 'waterfall') {
|
|
509
|
+
return { ...slide, layout: hasMetrics ? 'kpi' : 'cards', variant: hasMetrics ? 'grid' : 'bento' }
|
|
510
|
+
}
|
|
511
|
+
if (want === 'image' || want === 'image-left' || want === 'image-right') {
|
|
512
|
+
return { ...slide, layout: n <= 2 ? 'callout' : 'cards', variant: n <= 2 ? 'takeaways' : 'pillars' }
|
|
513
|
+
}
|
|
514
|
+
if (want === 'matrix' && n !== 4) {
|
|
515
|
+
return { ...slide, layout: 'cards', variant: 'bento' }
|
|
516
|
+
}
|
|
517
|
+
if (want === 'kpi' && (!hasMetrics || n < 1 || n > 4)) {
|
|
518
|
+
return { ...slide, layout: 'cards', variant: 'pillars' }
|
|
519
|
+
}
|
|
520
|
+
if (want === 'table' && (!Array.isArray(slide.rows) || slide.rows.length === 0)) {
|
|
521
|
+
return { ...slide, layout: 'cards', variant: 'pillars' }
|
|
522
|
+
}
|
|
523
|
+
if (want === 'harvey' && (!Array.isArray(slide.rows) || slide.rows.length === 0)) {
|
|
524
|
+
return { ...slide, layout: 'comparison', variant: 'versus' }
|
|
525
|
+
}
|
|
526
|
+
if (['cards', 'kpi', 'comparison', 'matrix', 'process', 'callout', 'statement', 'quote', 'bullets', 'gantt', 'architecture', 'tam', 'org'].includes(want)) {
|
|
527
|
+
return {
|
|
528
|
+
...slide,
|
|
529
|
+
layout: want,
|
|
530
|
+
...(target.variant ? { variant: target.variant } : {}),
|
|
531
|
+
...(want === 'gantt' && !Array.isArray(slide.columns) ? { columns: ['Q1', 'Q2', 'Q3', 'Q4'] } : {}),
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
return slide
|
|
535
|
+
})
|
|
536
|
+
return normalizeSlides(mapped, 120, langId)
|
|
537
|
+
}
|
|
538
|
+
|
|
359
539
|
export async function buildDeckAsync(options = {}) {
|
|
360
540
|
abort(options.signal)
|
|
361
541
|
validateRawSlides(options.slides)
|
|
362
|
-
const scenario = options.template ? scenarios.find(s => s.id === options.template) : undefined
|
|
363
|
-
if (options.template && !scenario) fail('未知 template,请使用 weekly / defense / project / pitch')
|
|
364
|
-
const input = { ...options, theme: options.theme || scenario?.theme,
|
|
365
|
-
...(!options.content?.trim() && !options.slides?.length && scenario ? { slides: templateSlides(scenario, String(options.title ?? ''), options.lang) } : {}) }
|
|
366
542
|
const cwd = resolve(options.cwd || '.')
|
|
367
|
-
const
|
|
543
|
+
const scenario = options.template ? findScenarioTemplate(options.template) : undefined
|
|
544
|
+
if (options.template && !scenario) fail('未知 template,请使用 ' + SCENARIO_TEMPLATES.map(s => s.id).join(' / '))
|
|
545
|
+
|
|
546
|
+
let absorbed = null
|
|
547
|
+
if (options.referencePptx !== undefined && options.referencePptx !== null && String(options.referencePptx).trim() !== '') {
|
|
548
|
+
absorbed = await absorbPptx({ pptxPath: String(options.referencePptx).trim(), cwd, extractLogo: true, signal: options.signal })
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
const rawThemeOpt = typeof options.theme === 'string' && options.theme.trim() ? options.theme.trim() : undefined
|
|
552
|
+
let chosenThemeId = rawThemeOpt
|
|
553
|
+
let directorHint = null
|
|
554
|
+
if (chosenThemeId === 'auto' || (!chosenThemeId && (options.persona || absorbed || scenario))) {
|
|
555
|
+
if (absorbed && (!rawThemeOpt || rawThemeOpt === 'auto') && !options.persona && !scenario) {
|
|
556
|
+
chosenThemeId = absorbed.recommendedTheme
|
|
557
|
+
} else {
|
|
558
|
+
directorHint = inferThemeFromContent({
|
|
559
|
+
title: options.title,
|
|
560
|
+
content: options.content,
|
|
561
|
+
slides: options.slides,
|
|
562
|
+
template: scenario?.id,
|
|
563
|
+
persona: options.persona,
|
|
564
|
+
})
|
|
565
|
+
chosenThemeId = directorHint.theme
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
const langId = resolveLanguage(options.lang).id
|
|
570
|
+
const fromMarkdown = !options.slides?.length && !scenario && Boolean(options.content?.trim())
|
|
571
|
+
const input = {
|
|
572
|
+
...options,
|
|
573
|
+
theme: chosenThemeId,
|
|
574
|
+
...(!options.content?.trim() && !options.slides?.length && scenario
|
|
575
|
+
? { slides: buildScenarioSlides(scenario, String(options.title ?? ''), langId === 'en' ? 'en' : 'zh') }
|
|
576
|
+
: {}),
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
const dataModel = options.dataModel ? normalizeDataModel(options.dataModel, { cwd, allowFiles: true }) : undefined
|
|
368
580
|
if (dataModel && (!Array.isArray(input.slides) || !input.slides.length)) fail('数据绑定需使用结构化 slides / Data binding requires structured slides')
|
|
369
|
-
const prepared = dataModel ? prepareDataSlides(input.slides, dataModel, normalizeSlides,
|
|
370
|
-
const normalized = normalizeBuildOptions({ ...input, ...(prepared ? { slides:prepared } : {}) })
|
|
371
|
-
if(prepared) normalized.deck.slides = prepared
|
|
581
|
+
const prepared = dataModel ? prepareDataSlides(input.slides, dataModel, normalizeSlides, langId) : undefined
|
|
582
|
+
const normalized = normalizeBuildOptions({ ...input, ...(prepared ? { slides: prepared } : {}) })
|
|
583
|
+
if (prepared) normalized.deck.slides = prepared
|
|
584
|
+
|
|
585
|
+
if (fromMarkdown) {
|
|
586
|
+
if (absorbed && options.cloneStructure === true && Array.isArray(absorbed.slideSkeleton) && absorbed.slideSkeleton.length > 0) {
|
|
587
|
+
normalized.deck.slides = mapSlidesToAbsorbedSkeleton(normalized.deck.slides, absorbed.slideSkeleton, langId)
|
|
588
|
+
} else {
|
|
589
|
+
const shouldPromote = options.smartLayout === true || (options.smartLayout !== false && (rawThemeOpt === 'auto' || Boolean(options.persona) || Boolean(absorbed)))
|
|
590
|
+
if (shouldPromote) {
|
|
591
|
+
normalized.deck.slides = promoteMarkdownSlides(normalized.deck.slides, { explicitSmartLayout: options.smartLayout === true })
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
if (directorHint?.tableStyle === 'booktabs') {
|
|
596
|
+
normalized.deck.slides = normalized.deck.slides.map(s => s.layout === 'table' && !s.tableStyle ? { ...s, tableStyle: 'booktabs' } : s)
|
|
597
|
+
}
|
|
598
|
+
|
|
372
599
|
const assets = {}
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
600
|
+
let brandInput = options.brand
|
|
601
|
+
if (absorbed) {
|
|
602
|
+
const baseAbsorbedBrand = {
|
|
603
|
+
...absorbed.sanitizedBrand,
|
|
604
|
+
...(options.cloneStructure === true && absorbed.recommendedChrome ? { chromeStyle: absorbed.recommendedChrome } : {}),
|
|
605
|
+
}
|
|
606
|
+
const targetTheme = resolveTheme(normalized.theme.id)
|
|
607
|
+
if (
|
|
608
|
+
absorbed.sanitizedTokens?.coverMode === 'inverted-accent' &&
|
|
609
|
+
targetTheme.tokens?.coverMode === 'inverted-accent' &&
|
|
610
|
+
!options.brand?.backgroundColor
|
|
611
|
+
) {
|
|
612
|
+
delete baseAbsorbedBrand.backgroundColor
|
|
613
|
+
}
|
|
614
|
+
brandInput = options.brand === null ? null : { ...baseAbsorbedBrand, ...(options.brand || {}) }
|
|
615
|
+
}
|
|
616
|
+
const brand = normalizeBrand(brandInput, assets, cwd)
|
|
617
|
+
|
|
618
|
+
const manifest = {
|
|
619
|
+
version: DECK_VERSION,
|
|
620
|
+
schemaVersion: 1,
|
|
621
|
+
deckId: randomUUID(),
|
|
622
|
+
revision: 0,
|
|
623
|
+
title: normalized.title,
|
|
624
|
+
theme: normalized.theme.id,
|
|
625
|
+
language: normalized.language.id,
|
|
626
|
+
motion: normalized.motion,
|
|
627
|
+
...(scenario ? { template: scenario.id } : {}),
|
|
628
|
+
...(brand ? { brand } : {}),
|
|
629
|
+
...(dataModel ? { dataModel } : {}),
|
|
630
|
+
assets,
|
|
631
|
+
history: [],
|
|
632
|
+
slides: embedSlides(normalized.deck.slides, assets, cwd).map(s => ({ ...s, id: randomUUID() })),
|
|
633
|
+
}
|
|
378
634
|
const data = await generate(manifest, options.signal)
|
|
379
635
|
mkdirSync(normalized.outputDir, { recursive: true })
|
|
380
636
|
// Resolve collisions after asynchronous rendering; an earlier call may have committed meanwhile.
|
|
@@ -413,6 +669,7 @@ function readDocument(pathInput, cwd = '.') {
|
|
|
413
669
|
}
|
|
414
670
|
return { manifest: document, path, fingerprint: hash(bytes) }
|
|
415
671
|
}
|
|
672
|
+
|
|
416
673
|
/** Validated project snapshot for the operator workbench; no file is modified. */
|
|
417
674
|
export function readDeckProject(options = {}) {
|
|
418
675
|
abort(options.signal)
|
|
@@ -444,13 +701,30 @@ async function saveRevision(state, next, signal, saveAs = false, preserveUndo =
|
|
|
444
701
|
|
|
445
702
|
export async function editDeck(options = {}) {
|
|
446
703
|
abort(options.signal)
|
|
704
|
+
const cwd = resolve(options.cwd || '.')
|
|
447
705
|
const state = readDocument(options.deckPath, options.cwd), current = state.manifest
|
|
448
706
|
expected(current, options.expectedRevision)
|
|
449
707
|
const next = clone(current)
|
|
450
708
|
if (!Array.isArray(options.edits) || !options.edits.length) {
|
|
451
|
-
if (
|
|
709
|
+
if (
|
|
710
|
+
options.brand === undefined &&
|
|
711
|
+
options.theme === undefined &&
|
|
712
|
+
options.referencePptx === undefined &&
|
|
713
|
+
options.order === undefined &&
|
|
714
|
+
options.duplicate === undefined &&
|
|
715
|
+
options.remove === undefined &&
|
|
716
|
+
options.append === undefined &&
|
|
717
|
+
options.saveAs !== true
|
|
718
|
+
) {
|
|
719
|
+
fail('请提供 edits、theme、referencePptx、order、duplicate、remove、append 或 brand')
|
|
720
|
+
}
|
|
452
721
|
}
|
|
453
|
-
const used = new Set()
|
|
722
|
+
const used = new Set()
|
|
723
|
+
const allowed = new Set([
|
|
724
|
+
'layout', 'variant', 'chrome', 'title', 'subtitle', 'kicker', 'takeaway', 'source',
|
|
725
|
+
'text', 'activeIndex', 'tableStyle', 'bullets', 'items', 'cards', 'metrics',
|
|
726
|
+
'columns', 'steps', 'quadrants', 'rows', 'notes', 'image', 'images', 'chart', 'visual',
|
|
727
|
+
])
|
|
454
728
|
for (const edit of options.edits ?? []) {
|
|
455
729
|
const index = typeof edit.slide === 'number' && Number.isInteger(edit.slide) ? edit.slide - 1 : next.slides.findIndex(s => s.id === edit.slide)
|
|
456
730
|
if (index < 0 || index >= next.slides.length) fail('找不到要修改的页面:' + edit.slide)
|
|
@@ -462,14 +736,28 @@ export async function editDeck(options = {}) {
|
|
|
462
736
|
const changed = { ...next.slides[index], ...next.slides[index].dataTemplate, ...edit.patch }
|
|
463
737
|
delete changed.dataTemplate
|
|
464
738
|
for (const key of Object.keys(changed)) if (changed[key] === null) delete changed[key]
|
|
465
|
-
if (edit.patch.
|
|
466
|
-
|
|
467
|
-
|
|
739
|
+
if (edit.patch.bullets && !edit.patch.items && !edit.patch.cards && !edit.patch.metrics && !edit.patch.steps && !edit.patch.columns && !edit.patch.quadrants && !next.slides[index].dataTemplate?.items) {
|
|
740
|
+
delete changed.items
|
|
741
|
+
}
|
|
742
|
+
if (edit.patch.chart) {
|
|
743
|
+
if (!edit.patch.layout && !['chart', 'chart-split', 'waterfall'].includes(changed.layout)) changed.layout = 'chart'
|
|
744
|
+
if (['chart', 'chart-split', 'waterfall'].includes(changed.layout)) { delete changed.image; delete changed.images }
|
|
745
|
+
}
|
|
746
|
+
if (edit.patch.image || edit.patch.images) {
|
|
747
|
+
if (!edit.patch.layout && !['image', 'image-left', 'image-right', 'gallery'].includes(changed.layout)) {
|
|
748
|
+
changed.layout = Array.isArray(edit.patch.images) && edit.patch.images.length > 1 ? 'image' : 'image-right'
|
|
749
|
+
}
|
|
750
|
+
if (['image', 'image-left', 'image-right', 'gallery'].includes(changed.layout)) delete changed.chart
|
|
751
|
+
}
|
|
752
|
+
if (edit.patch.layout) {
|
|
753
|
+
const eff = effectiveLayout(edit.patch.layout)
|
|
754
|
+
if (!MEDIA_LAYOUTS.has(eff)) { delete changed.image; delete changed.images; delete changed.chart }
|
|
755
|
+
}
|
|
468
756
|
validateRawSlides([changed])
|
|
469
757
|
let slides
|
|
470
758
|
try { slides = next.dataModel ? prepareDataSlides([changed], next.dataModel, normalizeSlides, next.language) : normalizeSlides([changed], 120, next.language) } catch (error) { fail(`第 ${index + 1} 页修改失败:${error.message}`) }
|
|
471
759
|
if (slides.length !== 1) fail(`第 ${index + 1} 页修改会产生分页,请减少表格行数或另建演示文稿`)
|
|
472
|
-
const embedded = embedSlides(slides, next.assets,
|
|
760
|
+
const embedded = embedSlides(slides, next.assets, cwd)[0]
|
|
473
761
|
next.slides[index] = { ...embedded, id: current.slides[index].id }
|
|
474
762
|
}
|
|
475
763
|
if (options.order !== undefined) {
|
|
@@ -501,10 +789,39 @@ export async function editDeck(options = {}) {
|
|
|
501
789
|
validateRawSlides(options.append)
|
|
502
790
|
const added = next.dataModel ? prepareDataSlides(options.append, next.dataModel, normalizeSlides, next.language) : normalizeSlides(options.append, 120, next.language)
|
|
503
791
|
if (next.slides.length + added.length > 120) fail('工程页数超过 120')
|
|
504
|
-
next.slides.push(...embedSlides(added, next.assets,
|
|
792
|
+
next.slides.push(...embedSlides(added, next.assets, cwd).map(slide => ({ ...slide, id: randomUUID() })))
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
if (options.theme !== undefined) {
|
|
796
|
+
const requestedTheme = String(options.theme ?? '').trim()
|
|
797
|
+
if (!requestedTheme) fail('theme 不能为空')
|
|
798
|
+
next.theme = requestedTheme === 'auto'
|
|
799
|
+
? inferThemeFromContent({ title: next.title, slides: next.slides, template: next.template }).theme
|
|
800
|
+
: resolveTheme(requestedTheme).id
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
if (options.referencePptx !== undefined && options.referencePptx !== null && String(options.referencePptx).trim() !== '') {
|
|
804
|
+
const absorbed = await absorbPptx({ pptxPath: String(options.referencePptx).trim(), cwd, extractLogo: true, signal: options.signal })
|
|
805
|
+
if (options.theme === undefined) next.theme = absorbed.recommendedTheme
|
|
806
|
+
const absorbedBrand = {
|
|
807
|
+
...absorbed.sanitizedBrand,
|
|
808
|
+
...(absorbed.recommendedChrome && !next.brand?.chromeStyle && !options.brand?.chromeStyle ? { chromeStyle: absorbed.recommendedChrome } : {}),
|
|
809
|
+
}
|
|
810
|
+
if (
|
|
811
|
+
absorbed.sanitizedTokens?.coverMode === 'inverted-accent' &&
|
|
812
|
+
resolveTheme(next.theme).tokens?.coverMode === 'inverted-accent' &&
|
|
813
|
+
!options.brand?.backgroundColor
|
|
814
|
+
) {
|
|
815
|
+
delete absorbedBrand.backgroundColor
|
|
816
|
+
}
|
|
817
|
+
next.brand = normalizeBrand({ ...next.brand, ...absorbedBrand }, next.assets, cwd)
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
if (options.brand !== undefined) {
|
|
821
|
+
next.brand = normalizeBrand(options.brand === null ? null : { ...next.brand, ...options.brand,
|
|
822
|
+
...(options.brand?.logo === null ? { logo: undefined, logoAssetId: undefined } : {}) }, next.assets, cwd)
|
|
823
|
+
if (next.brand && Object.keys(next.brand).length === 0) delete next.brand
|
|
505
824
|
}
|
|
506
|
-
if (options.brand !== undefined) next.brand = normalizeBrand(options.brand === null ? null : { ...next.brand, ...options.brand,
|
|
507
|
-
...(options.brand?.logo === null ? { logo: undefined, logoAssetId: undefined } : {}) }, next.assets, resolve(options.cwd || '.'))
|
|
508
825
|
if (options.saveAs !== true && JSON.stringify(snapshot(next)) === JSON.stringify(snapshot(current))) return { ...result(current, pathsFor(state.path)), changed: false }
|
|
509
826
|
next.history = [...next.history, snapshot(current)].slice(-MAX_HISTORY)
|
|
510
827
|
return { ...await saveRevision(state, next, options.signal, options.saveAs === true, options.preserveUndo === true), changed: true }
|
|
@@ -537,22 +854,22 @@ export async function undoDeck(options = {}) {
|
|
|
537
854
|
|
|
538
855
|
function dataChange(state, options) {
|
|
539
856
|
expected(state.manifest, options.expectedRevision)
|
|
540
|
-
const packet=options.scenario
|
|
541
|
-
if(packet && (packet.schemaVersion!==1||packet.deckId!==state.manifest.deckId||packet.revision!==state.manifest.revision||packet.fingerprint!==state.manifest.dataModel?.fingerprint))fail('推演参数来自其他工程或旧版本,请重新导出 / Scenario belongs to another project or revision')
|
|
542
|
-
return previewDataChange(state.manifest,{...options
|
|
857
|
+
const packet = options.scenario
|
|
858
|
+
if (packet && (packet.schemaVersion !== 1 || packet.deckId !== state.manifest.deckId || packet.revision !== state.manifest.revision || packet.fingerprint !== state.manifest.dataModel?.fingerprint)) fail('推演参数来自其他工程或旧版本,请重新导出 / Scenario belongs to another project or revision')
|
|
859
|
+
return previewDataChange(state.manifest, { ...options, ...(packet ? { parameters: packet.parameters } : {}) }, normalizeSlides)
|
|
543
860
|
}
|
|
544
861
|
export function previewDeckData(options = {}) {
|
|
545
862
|
abort(options.signal)
|
|
546
|
-
const state=readDocument(options.deckPath, options.cwd)
|
|
547
|
-
return { ok:true, deckId:state.manifest.deckId, revision:state.manifest.revision, ...dataChange(state,options).preview }
|
|
863
|
+
const state = readDocument(options.deckPath, options.cwd)
|
|
864
|
+
return { ok: true, deckId: state.manifest.deckId, revision: state.manifest.revision, ...dataChange(state, options).preview }
|
|
548
865
|
}
|
|
549
866
|
export async function updateDeckData(options = {}) {
|
|
550
867
|
abort(options.signal)
|
|
551
|
-
const state=readDocument(options.deckPath,options.cwd),change=dataChange(state,options)
|
|
552
|
-
if(options.confirmed!==true||options.expectedRevision===undefined||options.previewToken!==change.preview.token)fail('请先预览差异,再携带修订号与预览凭证确认 / Preview changes and confirm with the revision and preview token')
|
|
553
|
-
if(!change.preview.changed)return {...result(state.manifest,pathsFor(state.path)),changed:false}
|
|
554
|
-
const next={...clone(state.manifest),dataModel:change.model,slides:change.slides,history:[...state.manifest.history,snapshot(state.manifest)].slice(-MAX_HISTORY)}
|
|
555
|
-
return {...await saveRevision(state,next,options.signal,options.saveAs!==false,true),changed:true}
|
|
868
|
+
const state = readDocument(options.deckPath, options.cwd), change = dataChange(state, options)
|
|
869
|
+
if (options.confirmed !== true || options.expectedRevision === undefined || options.previewToken !== change.preview.token) fail('请先预览差异,再携带修订号与预览凭证确认 / Preview changes and confirm with the revision and preview token')
|
|
870
|
+
if (!change.preview.changed) return { ...result(state.manifest, pathsFor(state.path)), changed: false }
|
|
871
|
+
const next = { ...clone(state.manifest), dataModel: change.model, slides: change.slides, history: [...state.manifest.history, snapshot(state.manifest)].slice(-MAX_HISTORY) }
|
|
872
|
+
return { ...await saveRevision(state, next, options.signal, options.saveAs !== false, true), changed: true }
|
|
556
873
|
}
|
|
557
874
|
|
|
558
875
|
export function checkDeck(options = {}) {
|