dsh-ppt 0.15.0 → 0.16.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/README.en.md +2 -0
- package/README.md +1 -0
- package/docs/COACHING.md +4 -0
- package/docs/USAGE.md +1 -0
- package/docs/VALIDATION.md +2 -0
- package/docs/VISUAL.md +58 -0
- package/docs/validation-0.16.0.md +30 -0
- package/docs/validation-0.16.1.md +29 -0
- package/lib/client.js +106 -7
- package/lib/index.js +6 -1
- package/lib/types.d.ts +8 -0
- package/lib/visual-model.d.ts +13 -0
- package/lib/visual-model.js +104 -0
- package/lib/visual.d.ts +197 -0
- package/lib/visual.js +382 -0
- package/lib/workbench.d.ts +4 -0
- package/lib/workbench.js +37 -4
- package/package.json +2 -2
- package/skills/dsh-ppt/SKILL.md +1 -0
- package/skills/dsh-ppt/package.json +1 -1
- package/skills/dsh-ppt/scripts/deck-advanced.mjs +19 -2
- package/skills/dsh-ppt/scripts/deck-core.mjs +10 -3
- package/skills/dsh-ppt/scripts/deck-visual.mjs +79 -0
package/lib/workbench.js
CHANGED
|
@@ -7,6 +7,7 @@ import { getEngine } from './execution.js';
|
|
|
7
7
|
import { bilingualQuality, englishWorkbenchMessage } from './workbench-language.js';
|
|
8
8
|
import { zipSync, strToU8 } from 'fflate';
|
|
9
9
|
import { PptCoaching } from './coaching.js';
|
|
10
|
+
import { PptVisual } from './visual.js';
|
|
10
11
|
export const PPT_WORKBENCH_ROUTE = '/api/dsh-ppt/workbench';
|
|
11
12
|
export const PPT_DOWNLOAD_ROUTE = '/api/dsh-ppt/download';
|
|
12
13
|
const REQUEST_LIMIT = 12 * 1024 * 1024;
|
|
@@ -54,12 +55,14 @@ function originVerdict(request) {
|
|
|
54
55
|
export class PptWorkbench {
|
|
55
56
|
catalogPath;
|
|
56
57
|
coaching;
|
|
58
|
+
visual;
|
|
57
59
|
loadEngine;
|
|
58
60
|
renders = new Map();
|
|
59
61
|
constructor(options = {}) {
|
|
60
62
|
this.catalogPath = options.catalogPath ?? join(process.env.DSH_HOME || join(homedir(), '.dsh'), 'plugins', 'dsh-ppt', 'projects.jsonl');
|
|
61
63
|
this.loadEngine = options.loadEngine ?? getEngine;
|
|
62
64
|
this.coaching = new PptCoaching(join(dirname(this.catalogPath), 'rehearsals'), options.coachingModel);
|
|
65
|
+
this.visual = new PptVisual(join(dirname(this.catalogPath), 'visual-reviews'), options.visualModel);
|
|
63
66
|
}
|
|
64
67
|
catalog() {
|
|
65
68
|
if (!existsSync(this.catalogPath))
|
|
@@ -171,6 +174,19 @@ export class PptWorkbench {
|
|
|
171
174
|
const { entry, engine, manifest, files } = await this.project(body.id);
|
|
172
175
|
signal?.throwIfAborted();
|
|
173
176
|
const context = { id: entry.id, manifest, ...(manifest.dataModel ? { dataNotes: Object.fromEntries(manifest.slides.map((s) => [s.id, engine.dataNotes(manifest, s)])) } : {}) };
|
|
177
|
+
const visualContext = { id: entry.id, path: entry.path, manifest, engine };
|
|
178
|
+
if (body.operation === 'visual-options')
|
|
179
|
+
return { ok: true, ...await this.visual.options(signal) };
|
|
180
|
+
if (body.operation === 'visual-list')
|
|
181
|
+
return { ok: true, runs: this.visual.list(visualContext) };
|
|
182
|
+
if (body.operation === 'visual-get')
|
|
183
|
+
return { ok: true, run: this.visual.get(visualContext, body.runId) };
|
|
184
|
+
if (body.operation === 'visual-stop')
|
|
185
|
+
return { ok: true, run: this.visual.stop(visualContext, body.runId) };
|
|
186
|
+
if (body.operation === 'visual-delete')
|
|
187
|
+
return { ok: true, ...this.visual.remove(visualContext, body.runId) };
|
|
188
|
+
if (body.operation === 'visual-page')
|
|
189
|
+
return this.visual.page(visualContext, body.runId, body.round, body.slideId);
|
|
174
190
|
if (body.operation === 'coach-options')
|
|
175
191
|
return { ok: true, ...await this.coaching.options(signal) };
|
|
176
192
|
if (body.operation === 'coach-list')
|
|
@@ -201,6 +217,19 @@ export class PptWorkbench {
|
|
|
201
217
|
return { ok: true, data: 'data:image/png;base64,' + bytes.toString('base64') };
|
|
202
218
|
}
|
|
203
219
|
this.revision(body, manifest);
|
|
220
|
+
if (body.operation === 'visual-create')
|
|
221
|
+
return { ok: true, run: await this.visual.create(visualContext, body, signal) };
|
|
222
|
+
if (body.operation === 'visual-step')
|
|
223
|
+
return { ok: true, run: await this.visual.step(visualContext, body.runId, body, signal) };
|
|
224
|
+
if (body.operation === 'visual-adopt') {
|
|
225
|
+
if (body.confirmed !== true)
|
|
226
|
+
throw new Error('请确认采用修复副本 / Confirm adopting the repaired copy');
|
|
227
|
+
const { path, render } = this.visual.adoption(visualContext, body.runId);
|
|
228
|
+
await this.remember({ jsonPath: path }, {}, undefined);
|
|
229
|
+
const copy = await this.project(digest(path));
|
|
230
|
+
this.renders.set(copy.entry.id, { revision: copy.manifest.revision, sourceSha256: render.sourceSha256, pngPaths: render.pngPaths, pngHashes: render.pngPaths.map(p => digest(ordinaryFile(p))), missingFonts: render.missingFonts });
|
|
231
|
+
return { ...await this.view(digest(path)), originalId: entry.id };
|
|
232
|
+
}
|
|
204
233
|
if (body.operation === 'data-preview' || body.operation === 'data-apply') {
|
|
205
234
|
// Always force file reads off, including nested source updates and scenario packets.
|
|
206
235
|
const args = { deckPath: entry.path, expectedRevision: body.expectedRevision, parameters: body.parameters, sourceUpdates: body.sourceUpdates,
|
|
@@ -276,14 +305,18 @@ export class PptWorkbench {
|
|
|
276
305
|
return denied;
|
|
277
306
|
try {
|
|
278
307
|
const params = new URL(request.url).searchParams, kind = params.get('kind');
|
|
279
|
-
if (!['html', 'pptx', 'json', 'bundle', 'notes', 'coaching', 'data'].includes(String(kind)))
|
|
308
|
+
if (!['html', 'pptx', 'json', 'bundle', 'notes', 'coaching', 'data', 'visual'].includes(String(kind)))
|
|
280
309
|
return fail(400, '不支持此文件类型');
|
|
281
310
|
const { entry, manifest, files, engine } = await this.project(params.get('id'));
|
|
282
311
|
if (String(manifest.revision) !== params.get('revision'))
|
|
283
312
|
return fail(409, '项目已被修改,请重新打开后下载');
|
|
284
313
|
request.signal.throwIfAborted();
|
|
285
314
|
let name, bytes;
|
|
286
|
-
if (kind === '
|
|
315
|
+
if (kind === 'visual') {
|
|
316
|
+
bytes = strToU8(this.visual.markdown({ id: entry.id, path: entry.path, manifest, engine }, params.get('run')));
|
|
317
|
+
name = basename(entry.path, '.json') + '-visual-review.md';
|
|
318
|
+
}
|
|
319
|
+
else if (kind === 'data') {
|
|
287
320
|
bytes = strToU8(engine.dataReport(manifest));
|
|
288
321
|
name = basename(entry.path, '.json') + '-data-lineage.md';
|
|
289
322
|
}
|
|
@@ -323,10 +356,10 @@ export class PptWorkbench {
|
|
|
323
356
|
request.signal.throwIfAborted();
|
|
324
357
|
if ((await this.project(entry.id)).manifest.revision !== manifest.revision)
|
|
325
358
|
return fail(409, '项目已被修改,请重新打开后下载');
|
|
326
|
-
const type =
|
|
359
|
+
const type = ['notes', 'coaching', 'data', 'visual'].includes(String(kind)) ? 'text/markdown; charset=utf-8' : kind === 'bundle' ? 'application/zip' : kind === 'pptx' ? 'application/vnd.openxmlformats-officedocument.presentationml.presentation' : kind === 'html' ? 'text/html; charset=utf-8' : 'application/json; charset=utf-8';
|
|
327
360
|
return new Response(new Uint8Array(bytes), { headers: {
|
|
328
361
|
'content-type': type, 'cache-control': 'no-store', 'x-content-type-options': 'nosniff',
|
|
329
|
-
'content-disposition': `attachment; filename="presentation.${kind === 'bundle' ? 'zip' :
|
|
362
|
+
'content-disposition': `attachment; filename="presentation.${kind === 'bundle' ? 'zip' : ['notes', 'coaching', 'data', 'visual'].includes(String(kind)) ? 'md' : kind}"; filename*=UTF-8''${encodeURIComponent(name)}`,
|
|
330
363
|
} });
|
|
331
364
|
}
|
|
332
365
|
catch (error) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-ppt",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "DSH 演示文稿插件:生成 HTML、可编辑 PPTX
|
|
3
|
+
"version": "0.16.1",
|
|
4
|
+
"description": "DSH 演示文稿插件:生成 HTML、可编辑 PPTX 和工程文件,支持数字溯源、现场推演与可选 AI 看图修复。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"types": "lib/index.d.ts",
|
package/skills/dsh-ppt/SKILL.md
CHANGED
|
@@ -16,6 +16,7 @@ allowed-tools: "Bash, Read, Write, Edit"
|
|
|
16
16
|
## 执行纪律(每次都要遵守)
|
|
17
17
|
|
|
18
18
|
- 默认直接交付成品,不自动触发 AI 预审或答辩。用户可在设置页成品下载区主动开启两个可选模式;选择模型、范围与调用上限后再发送材料。AI 演练不等于事实核验,不编造实验、数据或引用;采纳建议另存副本,原件保留。
|
|
19
|
+
- 用户需要 AI 看图检查时,可在 DSH 设置 → 演示文稿 → 视觉检查与修复主动开启。它需要支持图片输入的模型与官方渲染引擎,修复只调整排版、另存副本并复查。AI 未发现问题不等于人工验收;模型调用失败、输出截断、停止和未检查页面必须如实说明,不能声称视觉通过。
|
|
19
20
|
- 数字溯源和现场推演也按需启用。提供 `dataModel` 与结构化 `slides` 的 `{{metricId}}` 绑定;先读 `references/data.md`。源事实必须对应真实材料行或单元格;用户假设用 `kind:input` 标注,禁止虚构来源。修改数据先 `ppt_data(action:preview)`,展示指标与页面差异,得到确认后携带原预览凭证和修订号保存;默认新副本。离线 HTML 参数必须回存确认后才能交付对应静态 PPTX。
|
|
20
21
|
|
|
21
22
|
- 修改工程先 `ppt_check`。外部编辑过的 HTML/PPTX、缺少成品校验记录的旧工程不可覆盖;告知用户 `saveAs:true` 只从 JSON 另存新副本,原件保留,Office 手工修改不会导入。不得绕过校验或自行篡改校验值。
|
|
@@ -5,6 +5,8 @@ import { inflateSync } from 'node:zlib'
|
|
|
5
5
|
import { buildPptx, renderHtml, normalizeBuildOptions, normalizeSlides, resolveTheme, resolveLanguage, resolveDeckFileName, commitDeckArtifacts, DECK_VERSION, pptxEastAsianFont } from './deck-core.mjs'
|
|
6
6
|
import { MEDIA_LAYOUTS, mediaBoxes, LOGO_BOX, FOOTER_BOX, chartColors, normalizeChart } from './deck-media.mjs'
|
|
7
7
|
import { normalizeDataModel, prepareDataSlides, validateDataSnapshot, previewDataChange, dataNotes, dataReport } from './deck-data.mjs'
|
|
8
|
+
import { normalizeVisual, applyVisualActions } from './deck-visual.mjs'
|
|
9
|
+
export { readRenderReceipt } from './deck-render.mjs'
|
|
8
10
|
export { dataNotes, dataReport } from './deck-data.mjs'
|
|
9
11
|
export { buildDeck, buildThemePreview, listThemes, resolveTheme, resolveLanguage } from './deck-core.mjs'
|
|
10
12
|
|
|
@@ -145,6 +147,7 @@ function validateRawSlides(slides) {
|
|
|
145
147
|
slides.forEach((s, i) => {
|
|
146
148
|
if (!s || typeof s !== 'object' || Array.isArray(s)) fail(`第 ${i + 1} 页必须是对象`)
|
|
147
149
|
if (s.layout && !layouts.has(s.layout)) fail(`第 ${i + 1} 页未知布局 ${s.layout}`)
|
|
150
|
+
normalizeVisual(s.visual)
|
|
148
151
|
if (s.chart && s.image) fail(`第 ${i + 1} 页不能同时放入 image 和 chart`)
|
|
149
152
|
if (s.image && s.layout && !['image', 'image-left', 'image-right'].includes(s.layout)) fail(`第 ${i + 1} 页图片需使用 image / image-left / image-right 布局`)
|
|
150
153
|
if (s.chart && s.layout && s.layout !== 'chart') fail(`第 ${i + 1} 页图表需使用 chart 布局`)
|
|
@@ -257,7 +260,7 @@ async function exportPptx(manifest, theme, language, signal) {
|
|
|
257
260
|
if (source.image) putImage(slide, source.image.assetId, boxes.image, source.image.fit, 'Slide image', source.image.alt)
|
|
258
261
|
if (source.chart) {
|
|
259
262
|
const colors = chartColors(theme), font = pptxEastAsianFont(theme.fonts.body)
|
|
260
|
-
const style = { font, sizePt: 17, color: theme.palette.fg }
|
|
263
|
+
const style = { font, sizePt: source.visual?.chartLabelSize ?? 17, color: theme.palette.fg }
|
|
261
264
|
lib.addSlideChart(slide, { ...emu(boxes.chart), name: 'Editable data chart', spec: {
|
|
262
265
|
kind: source.chart.kind, categories: source.chart.categories,
|
|
263
266
|
series: source.chart.series.map((s, i) => ({ ...s, color: colors[i], ...(source.chart.kind === 'pie' ? { pointColors: source.chart.categories.map((_, j) => colors[j % colors.length]) } : {}) })),
|
|
@@ -447,7 +450,7 @@ export async function editDeck(options = {}) {
|
|
|
447
450
|
if (!Array.isArray(options.edits) || !options.edits.length) {
|
|
448
451
|
if (options.brand === undefined && options.order === undefined && options.duplicate === undefined && options.remove === undefined && options.append === undefined && options.saveAs !== true) fail('请提供 edits、order、duplicate、remove、append 或 brand')
|
|
449
452
|
}
|
|
450
|
-
const used = new Set(), allowed = new Set(['layout', 'title', 'subtitle', 'kicker', 'text', 'bullets', 'rows', 'notes', 'image', 'chart'])
|
|
453
|
+
const used = new Set(), allowed = new Set(['layout', 'title', 'subtitle', 'kicker', 'text', 'bullets', 'rows', 'notes', 'image', 'chart', 'visual'])
|
|
451
454
|
for (const edit of options.edits ?? []) {
|
|
452
455
|
const index = typeof edit.slide === 'number' && Number.isInteger(edit.slide) ? edit.slide - 1 : next.slides.findIndex(s => s.id === edit.slide)
|
|
453
456
|
if (index < 0 || index >= next.slides.length) fail('找不到要修改的页面:' + edit.slide)
|
|
@@ -507,6 +510,20 @@ export async function editDeck(options = {}) {
|
|
|
507
510
|
return { ...await saveRevision(state, next, options.signal, options.saveAs === true, options.preserveUndo === true), changed: true }
|
|
508
511
|
}
|
|
509
512
|
|
|
513
|
+
/** An AI-selected, bounded formatting vocabulary; always an undoable new copy. */
|
|
514
|
+
export async function repairDeckVisual(options = {}) {
|
|
515
|
+
abort(options.signal)
|
|
516
|
+
const state = readDocument(options.deckPath, options.cwd)
|
|
517
|
+
expected(state.manifest, options.expectedRevision)
|
|
518
|
+
const next = clone(state.manifest)
|
|
519
|
+
next.slides = applyVisualActions(next, options.actions)
|
|
520
|
+
// Splitting can move the only binding off a continuation page. Rebuild each
|
|
521
|
+
// page's canonical template so plain fields do not remain falsely bound.
|
|
522
|
+
if (next.dataModel) next.slides = next.slides.map(slide => ({ ...prepareDataSlides([slide], next.dataModel, normalizeSlides, next.language)[0], id: slide.id }))
|
|
523
|
+
if (JSON.stringify(next.slides) === JSON.stringify(state.manifest.slides)) fail('排版操作没有变化 / Formatting actions made no changes')
|
|
524
|
+
return saveRevision(state, next, options.signal, true, true)
|
|
525
|
+
}
|
|
526
|
+
|
|
510
527
|
export async function undoDeck(options = {}) {
|
|
511
528
|
abort(options.signal)
|
|
512
529
|
const state = readDocument(options.deckPath, options.cwd)
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* deck.pptx 可编辑 PPTX(16:9,OOXML 由本文件手写,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'
|
|
@@ -20,6 +20,7 @@ import { deflateRawSync } from 'node:zlib'
|
|
|
20
20
|
import { MEDIA_LAYOUTS, MEDIA_CSS, normalizeMediaSlide, renderMediaHtml, mediaBoxes } from './deck-media.mjs'
|
|
21
21
|
import { renderDelivery } from './deck-delivery.mjs'
|
|
22
22
|
import { renderDataView } from './deck-data-view.mjs'
|
|
23
|
+
import { normalizeVisual, visualHtmlStyle, visualShapeXml, VISUAL_CSS } from './deck-visual.mjs'
|
|
23
24
|
|
|
24
25
|
/**
|
|
25
26
|
* manifest 版本跟随发布包 package.json;把 skills/dsh-ppt 独立复制到其他
|
|
@@ -804,6 +805,10 @@ export function parseMarkdownDeck(titleInput, content, lang = 'zh') {
|
|
|
804
805
|
const SLIDE_LAYOUTS = new Set(['cover', 'section', 'bullets', 'statement', 'closing', 'quote', 'table', ...MEDIA_LAYOUTS])
|
|
805
806
|
|
|
806
807
|
function normalizeSlide(raw, index) {
|
|
808
|
+
const result = normalizeSlideContent(raw, index), visual = normalizeVisual(raw?.visual)
|
|
809
|
+
return visual ? { ...result, visual } : result
|
|
810
|
+
}
|
|
811
|
+
function normalizeSlideContent(raw, index) {
|
|
807
812
|
const source = (raw !== null && typeof raw === 'object') ? raw : {}
|
|
808
813
|
const layout = SLIDE_LAYOUTS.has(source.layout) ? source.layout : source.chart ? 'chart' : source.image ? 'image-right' : 'bullets'
|
|
809
814
|
const title = stripInlineMarkdown(source.title ?? '')
|
|
@@ -1070,6 +1075,7 @@ body{
|
|
|
1070
1075
|
.slide.is-active{display:flex}
|
|
1071
1076
|
${motionCss}
|
|
1072
1077
|
${MEDIA_CSS}
|
|
1078
|
+
${VISUAL_CSS}
|
|
1073
1079
|
.kicker{
|
|
1074
1080
|
color:var(--accent);font-weight:700;letter-spacing:.18em;text-transform:uppercase;
|
|
1075
1081
|
font-size:clamp(12px,1.3vw,18px);margin-bottom:22px;
|
|
@@ -1733,7 +1739,8 @@ function renderHtmlSlide(slide, index, ui, langId, manifest = {}, theme) {
|
|
|
1733
1739
|
const notesAttr = typeof slide.notes === 'string' && slide.notes.trim() !== ''
|
|
1734
1740
|
? ' data-notes="' + escapeHtml(slide.notes) + '"'
|
|
1735
1741
|
: ''
|
|
1736
|
-
|
|
1742
|
+
const visualStyle = visualHtmlStyle(slide.visual)
|
|
1743
|
+
return '<section class="slide slide--' + escapeHtml(slide.layout || 'bullets') + '" data-index="' + number + '"' + notesAttr + (visualStyle ? ' style="' + escapeHtml(visualStyle) + '"' : '') + '>' +
|
|
1737
1744
|
'<div class="slide-inner">' + inner + '</div>' +
|
|
1738
1745
|
(manifest.brand?.logoAssetId ? '<img class="brand-logo" src="' + escapeHtml(manifest.assets?.[manifest.brand.logoAssetId]?.data ?? '') + '" alt="' + escapeHtml(manifest.brand.name || 'Logo') + '"/>' : '') +
|
|
1739
1746
|
(manifest.brand?.footer ? '<div class="brand-footer">' + escapeHtml(manifest.brand.footer) + '</div>' : '') + '</section>'
|
|
@@ -1985,7 +1992,7 @@ function slideShapeList(slide, index, total, theme, langId) {
|
|
|
1985
1992
|
para(footer, { size: 1000, color: p.muted, align: 'r', font: theme.fonts.body }),
|
|
1986
1993
|
]))
|
|
1987
1994
|
|
|
1988
|
-
return shapes.join('')
|
|
1995
|
+
return visualShapeXml(shapes.join(''), slide.visual)
|
|
1989
1996
|
}
|
|
1990
1997
|
|
|
1991
1998
|
/**
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// Deliberately small formatting vocabulary. Model output never contains text edits.
|
|
2
|
+
import { randomUUID } from 'node:crypto'
|
|
3
|
+
|
|
4
|
+
export function normalizeVisual(value) {
|
|
5
|
+
if (value == null) return undefined
|
|
6
|
+
if (typeof value !== 'object' || Array.isArray(value)) throw new Error('visual 需为字号设置对象 / Invalid visual settings')
|
|
7
|
+
const ranges = { titleSize: [24, 60], bodySize: [16, 28], chartLabelSize: [14, 24] }, out = {}
|
|
8
|
+
for (const [key, number] of Object.entries(value)) {
|
|
9
|
+
const range = ranges[key]
|
|
10
|
+
if (!range || !Number.isInteger(number) || number < range[0] || number > range[1]) throw new Error('visual 字号超出允许范围 / Invalid visual font size')
|
|
11
|
+
out[key] = number
|
|
12
|
+
}
|
|
13
|
+
return Object.keys(out).length ? out : undefined
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function visualHtmlStyle(value) {
|
|
17
|
+
const v = normalizeVisual(value)
|
|
18
|
+
if (!v) return ''
|
|
19
|
+
return Object.entries(v).map(([key, n]) => '--ppt-' + key + ':' + n).join(';')
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const VISUAL_CSS = `
|
|
23
|
+
.slide[style*="--ppt-titleSize"] h1,.slide[style*="--ppt-titleSize"] h2,.slide[style*="--ppt-titleSize"] .statement-title,.slide[style*="--ppt-titleSize"] .quote-text{font-size:clamp(24px,calc(var(--ppt-titleSize) * .12vw),calc(var(--ppt-titleSize) * 2px))}
|
|
24
|
+
.slide[style*="--ppt-titleSize"] .media-title{font-size:calc(var(--ppt-titleSize) * .104167cqw)}
|
|
25
|
+
.slide[style*="--ppt-bodySize"] li,.slide[style*="--ppt-bodySize"] .subtitle,.slide[style*="--ppt-bodySize"] .quote-attr{font-size:clamp(16px,calc(var(--ppt-bodySize) * .13vw),calc(var(--ppt-bodySize) * 2px))}
|
|
26
|
+
.slide[style*="--ppt-bodySize"] .media-body,.slide[style*="--ppt-bodySize"] .media-body li{font-size:calc(var(--ppt-bodySize) * .104167cqw)}
|
|
27
|
+
.slide[style*="--ppt-bodySize"] .deck-table{font-size:clamp(12px,calc(var(--ppt-bodySize) * .09vw),calc(var(--ppt-bodySize) * 1.35px))}
|
|
28
|
+
.slide[style*="--ppt-chartLabelSize"] .native-chart text{font-size:calc(var(--ppt-chartLabelSize) * 1px)}
|
|
29
|
+
`
|
|
30
|
+
|
|
31
|
+
/** Apply formatting to the generator's known OOXML shapes, never arbitrary XML. */
|
|
32
|
+
export function visualShapeXml(xml, visual) {
|
|
33
|
+
const v = normalizeVisual(visual)
|
|
34
|
+
if (!v) return xml
|
|
35
|
+
return xml.replace(/<p:(sp|graphicFrame)>[\s\S]*?<\/p:\1>/g, shape => {
|
|
36
|
+
const name = shape.match(/<p:cNvPr\b[^>]*\bname="([^"]*)"/)?.[1]
|
|
37
|
+
const pt = ['Title', 'Statement', 'Quote'].includes(name) ? v.titleSize : ['Body', 'Subtitle', 'Attribution', 'Table'].includes(name) ? v.bodySize : undefined
|
|
38
|
+
return pt ? shape.replace(/(<a:(?:rPr|defRPr|endParaRPr)\b[^>]*\bsz=")[0-9]+"/g, '$1' + (pt * 100) + '"') : shape
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Facts, metrics, assets, titles and slide order are preserved by construction. */
|
|
43
|
+
export function applyVisualActions(manifest, actions) {
|
|
44
|
+
if (!Array.isArray(actions) || !actions.length || actions.length > 48) throw new Error('请选择有效的排版修改 / Invalid formatting actions')
|
|
45
|
+
const next = structuredClone(manifest), seen = new Set()
|
|
46
|
+
for (const a of actions) {
|
|
47
|
+
if (!a || typeof a !== 'object' || Object.keys(a).some(k => !['slideId', 'type', 'value'].includes(k))) throw new Error('排版操作包含无效字段 / Invalid formatting action fields')
|
|
48
|
+
const index = next.slides.findIndex(s => s.id === a.slideId), original = manifest.slides.find(s => s.id === a.slideId)
|
|
49
|
+
if (index < 0 || !original) throw new Error('排版操作关联的页面不存在 / Unknown slide')
|
|
50
|
+
const key = a.slideId + ':' + (a.type?.startsWith('split-') ? 'split' : a.type)
|
|
51
|
+
if (seen.has(key)) throw new Error('同一页的排版操作重复 / Duplicate formatting action')
|
|
52
|
+
seen.add(key)
|
|
53
|
+
const slide = next.slides[index]
|
|
54
|
+
const field = { 'title-size': 'titleSize', 'body-size': 'bodySize', 'chart-label-size': 'chartLabelSize' }[a.type]
|
|
55
|
+
if (field) {
|
|
56
|
+
if (field === 'chartLabelSize' && !slide.chart) throw new Error('本页没有图表 / Slide has no chart')
|
|
57
|
+
slide.visual = normalizeVisual({ ...slide.visual, [field]: a.value })
|
|
58
|
+
} else if (a.type === 'chart-horizontal') {
|
|
59
|
+
if (a.value !== undefined || slide.chart?.kind !== 'column') throw new Error('只支持将柱状图改为横向条形图 / Only column-to-bar conversion is supported')
|
|
60
|
+
slide.chart.kind = 'bar'
|
|
61
|
+
if (slide.dataTemplate?.chart) slide.dataTemplate.chart.kind = 'bar'
|
|
62
|
+
} else if (a.type === 'image-contain') {
|
|
63
|
+
if (a.value !== undefined || !slide.image) throw new Error('本页没有图片 / Slide has no image')
|
|
64
|
+
slide.image.fit = 'contain'
|
|
65
|
+
} else if (a.type === 'split-bullets' || a.type === 'split-table') {
|
|
66
|
+
const bullets = a.type === 'split-bullets', field = bullets ? 'bullets' : 'rows'
|
|
67
|
+
if (bullets ? !['bullets','image-left','image-right'].includes(slide.layout) : slide.layout !== 'table') throw new Error('此版式不支持所选拆页操作 / Split is not supported for this layout')
|
|
68
|
+
const data = slide[field], count = bullets ? data?.length : data?.length - 1
|
|
69
|
+
if (!Number.isInteger(a.value) || a.value < 1 || a.value >= count) throw new Error('拆页位置无效 / Invalid split position')
|
|
70
|
+
if (next.slides.length >= 120) throw new Error('拆页后超过 120 页 / Split would exceed 120 slides')
|
|
71
|
+
const added = structuredClone(slide); added.id = randomUUID()
|
|
72
|
+
const split = values => bullets ? [values.slice(0, a.value), values.slice(a.value)] : [values.slice(0, a.value + 1), [values[0], ...values.slice(a.value + 1)]]
|
|
73
|
+
;[slide[field], added[field]] = split(data)
|
|
74
|
+
if (slide.dataTemplate?.[field]) [slide.dataTemplate[field], added.dataTemplate[field]] = split(slide.dataTemplate[field])
|
|
75
|
+
next.slides.splice(index + 1, 0, added)
|
|
76
|
+
} else throw new Error('不支持此排版操作 / Unsupported formatting action')
|
|
77
|
+
}
|
|
78
|
+
return next.slides
|
|
79
|
+
}
|