dsh-ppt 0.24.2 → 0.26.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.
Files changed (43) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.en.md +13 -13
  3. package/README.md +13 -13
  4. package/docs/DATA.md +2 -2
  5. package/docs/REFERENCE.en.md +8 -8
  6. package/docs/REFERENCE.zh.md +8 -8
  7. package/docs/USAGE.en.md +11 -7
  8. package/docs/USAGE.md +11 -7
  9. package/docs/VALIDATION.md +4 -0
  10. package/docs/WORKBENCH.md +4 -4
  11. package/docs/assets/intro/workflow-en-dark.svg +1 -1
  12. package/docs/assets/intro/workflow-en-light.svg +1 -1
  13. package/docs/assets/intro/workflow-en-mobile-dark.svg +1 -1
  14. package/docs/assets/intro/workflow-en-mobile-light.svg +1 -1
  15. package/docs/assets/intro/workflow-zh-dark.svg +1 -1
  16. package/docs/assets/intro/workflow-zh-light.svg +1 -1
  17. package/docs/assets/intro/workflow-zh-mobile-dark.svg +1 -1
  18. package/docs/assets/intro/workflow-zh-mobile-light.svg +1 -1
  19. package/lib/client.js +3435 -467
  20. package/lib/ecosystem.d.ts +73 -0
  21. package/lib/ecosystem.js +1352 -0
  22. package/lib/execution.d.ts +6 -1
  23. package/lib/execution.js +69 -0
  24. package/lib/tools.js +77 -0
  25. package/lib/types.d.ts +57 -1
  26. package/lib/workbench-language.js +4 -0
  27. package/lib/workbench.d.ts +2 -0
  28. package/lib/workbench.js +331 -8
  29. package/package.json +1 -1
  30. package/skills/dsh-ppt/SKILL.md +3 -3
  31. package/skills/dsh-ppt/package.json +1 -1
  32. package/skills/dsh-ppt/references/advanced.md +10 -5
  33. package/skills/dsh-ppt/references/syntax.md +1 -0
  34. package/skills/dsh-ppt/scripts/build-deck.mjs +39 -8
  35. package/skills/dsh-ppt/scripts/deck-advanced.mjs +50 -13
  36. package/skills/dsh-ppt/scripts/deck-chrome.mjs +1706 -0
  37. package/skills/dsh-ppt/scripts/deck-core.mjs +116 -6
  38. package/skills/dsh-ppt/scripts/deck-delivery.mjs +636 -41
  39. package/skills/dsh-ppt/scripts/deck-diagrams.mjs +2842 -0
  40. package/skills/dsh-ppt/scripts/deck-director.mjs +49 -3
  41. package/skills/dsh-ppt/scripts/deck-layouts.mjs +482 -5270
  42. package/skills/dsh-ppt/scripts/deck-mermaid.mjs +2737 -0
  43. package/skills/dsh-ppt/scripts/deck-office.mjs +1541 -0
@@ -0,0 +1,1706 @@
1
+ /**
2
+ * deck-chrome.mjs —— dsh-ppt 的 16:9 几何与富文本基元、OOXML 基础图元/附着连接线构建器,
3
+ * 以及 6 套差异化母版骨架(Chrome Skeletons:consulting-classic / keynote-spatial /
4
+ * editorial-folio / academic-minimal / gov-ceremonial / saas-bento)的 OOXML 与 HTML 同构渲染器。
5
+ *
6
+ * 零外部运行时依赖,仅使用 Node 内置模块。
7
+ */
8
+
9
+ import { pptxFontName, pptxEastAsianFont, resolveChromeStyle } from './deck-themes.mjs'
10
+ import {
11
+ containsLatexMath,
12
+ maskMathSpans,
13
+ unmaskMathSpans,
14
+ splitMathSegments,
15
+ parseLatexMath,
16
+ latexToMathMl,
17
+ astToOmml,
18
+ astToOoxmlInlineRuns,
19
+ fitFormulaBoxIn,
20
+ } from './deck-math.mjs'
21
+
22
+ // ---------------------------------------------------------------------------
23
+ // 常量与坐标换算(16:9 画布:13.3333" × 7.5" = 12192000 × 6858000 EMU)
24
+ // ---------------------------------------------------------------------------
25
+
26
+ export const CANVAS_IN = Object.freeze({ w: 13.3333333333, h: 7.5 })
27
+ export const EMU_PER_IN = 914400
28
+ export const EMU_PER_PT = 12700
29
+ export const EMU_W = 12192000
30
+ export const EMU_H = 6858000
31
+
32
+ export function inToEmu(inches) {
33
+ return Math.round(inches * EMU_PER_IN)
34
+ }
35
+
36
+ export function ptToEmu(pts) {
37
+ return Math.round(pts * EMU_PER_PT)
38
+ }
39
+
40
+ export function boxToEmu(box) {
41
+ return {
42
+ x: inToEmu(box.x),
43
+ y: inToEmu(box.y),
44
+ w: inToEmu(box.w),
45
+ h: inToEmu(box.h),
46
+ }
47
+ }
48
+
49
+ export function boxToCssPct(box) {
50
+ return (
51
+ 'left:' + (box.x / CANVAS_IN.w * 100).toFixed(4) + '%;' +
52
+ 'top:' + (box.y / CANVAS_IN.h * 100).toFixed(4) + '%;' +
53
+ 'width:' + (box.w / CANVAS_IN.w * 100).toFixed(4) + '%;' +
54
+ 'height:' + (box.h / CANVAS_IN.h * 100).toFixed(4) + '%'
55
+ )
56
+ }
57
+
58
+ /**
59
+ * 计算 OOXML roundRect 的 adj 参数(0..50000),使物理圆角半径与 HTML border-radius 严格一致。
60
+ */
61
+ export function roundRectAdj(wIn, hIn, radiusPx = 8) {
62
+ if (!radiusPx || radiusPx <= 0) return 0
63
+ const rIn = radiusPx / 96
64
+ const minSide = Math.max(0.05, Math.min(wIn, hIn))
65
+ return Math.max(0, Math.min(50000, Math.round((rIn / minSide) * 100000)))
66
+ }
67
+
68
+ function hex6(color) {
69
+ return String(color ?? '#000000').replace(/^#/, '').slice(0, 6).toUpperCase()
70
+ }
71
+
72
+ export function hexToRgbaSafeHex(fgHex, bgHex, alpha) {
73
+ const f = parseInt(hex6(fgHex), 16)
74
+ const b = parseInt(hex6(bgHex), 16)
75
+ const mix = (fc, bc) => Math.round(fc * alpha + bc * (1 - alpha)).toString(16).padStart(2, '0')
76
+ return '#' + mix((f >> 16) & 255, (b >> 16) & 255) + mix((f >> 8) & 255, (b >> 8) & 255) + mix(f & 255, b & 255)
77
+ }
78
+
79
+ // ---------------------------------------------------------------------------
80
+ // XML / HTML 转义与无损内联富文本解析
81
+ // ---------------------------------------------------------------------------
82
+
83
+ export function escapeXml(value) {
84
+ return String(value ?? '')
85
+ .replace(/[\u000B\u000C]/g, '\n')
86
+ .replace(/[^\u0009\u000A\u000D\u0020-\uD7FF\uE000-\uFFFD\u{10000}-\u{10FFFF}]/gu, '')
87
+ .replace(/&/g, '&amp;')
88
+ .replace(/</g, '&lt;')
89
+ .replace(/>/g, '&gt;')
90
+ .replace(/"/g, '&quot;')
91
+ .replace(/'/g, '&apos;')
92
+ }
93
+
94
+ export function escapeHtml(value) {
95
+ return String(value ?? '')
96
+ .replace(/&/g, '&amp;')
97
+ .replace(/</g, '&lt;')
98
+ .replace(/>/g, '&gt;')
99
+ .replace(/"/g, '&quot;')
100
+ }
101
+
102
+ export function stripInlineMarkdown(value) {
103
+ const { masked, stash } = maskMathSpans(String(value ?? ''))
104
+ const stripped = masked
105
+ .replace(/!\[[^\]]*\]\([^)]*\)/g, '')
106
+ .replace(/\[([^\]]+)\]\([^)]*\)/g, '$1')
107
+ .replace(/`([^`]*)`/g, '$1')
108
+ .replace(/\*\*([^*]+)\*\*/g, '$1')
109
+ .replace(/__([^_]+)__/g, '$1')
110
+ .replace(/\*([^*\n]+)\*/g, '$1')
111
+ .replace(/_([^_\n]+)_/g, '$1')
112
+ .replace(/<[^>]+>/g, '')
113
+ .replace(/\s+/g, ' ')
114
+ .trim()
115
+ return unmaskMathSpans(stripped, stash).replace(/`([^`]*)`/g, '$1')
116
+ }
117
+
118
+ /**
119
+ * 清理不安全标签与链接语法,但保留成对的 **粗体**、*斜体*、`代码` 以及 $...$ / $$...$$ 公式标记。
120
+ * 纯文本输入(无标记)输出与 stripInlineMarkdown 完全一致。
121
+ */
122
+ export function cleanRichText(value) {
123
+ const { masked, stash } = maskMathSpans(String(value ?? ''))
124
+ const cleaned = masked
125
+ .replace(/!\[[^\]]*\]\([^)]*\)/g, '')
126
+ .replace(/\[([^\]]+)\]\([^)]*\)/g, '$1')
127
+ .replace(/<[^>]+>/g, '')
128
+ .replace(/__([^_]+)__/g, '**$1**')
129
+ .replace(/\s+/g, ' ')
130
+ .trim()
131
+ return unmaskMathSpans(cleaned, stash)
132
+ }
133
+
134
+ const INLINE_TOKEN_RE = /(\*\*[^*]+\*\*|`[^`]+`|\*[^*\s][^*]*?\*)/g
135
+
136
+ function parseMarkdownRunsOnly(text, options = {}) {
137
+ if (text === '') return []
138
+ const hasExplicitMarkup = /\*\*[^*]+\*\*|`[^`]+`|\*[^*\s][^*]*?\*/.test(text)
139
+
140
+ if (!hasExplicitMarkup && options.autoLeadBold) {
141
+ const colonMatch = /^([^::]{2,12}[::])\s*(.+)$/.exec(text)
142
+ if (colonMatch && !/^https?:/i.test(text)) {
143
+ return [
144
+ { text: colonMatch[1], bold: true, lead: true },
145
+ { text: (colonMatch[1].endsWith(':') ? ' ' : '') + colonMatch[2], secondary: true },
146
+ ]
147
+ }
148
+ }
149
+
150
+ if (!hasExplicitMarkup) {
151
+ return [{ text }]
152
+ }
153
+
154
+ const runs = []
155
+ let lastIndex = 0
156
+ for (const match of text.matchAll(INLINE_TOKEN_RE)) {
157
+ const idx = match.index ?? 0
158
+ if (idx > lastIndex) {
159
+ runs.push({ text: text.slice(lastIndex, idx) })
160
+ }
161
+ const token = match[0]
162
+ if (token.startsWith('**') && token.endsWith('**')) {
163
+ runs.push({ text: token.slice(2, -2), bold: true })
164
+ } else if (token.startsWith('`') && token.endsWith('`')) {
165
+ runs.push({ text: token.slice(1, -1), code: true })
166
+ } else if (token.startsWith('*') && token.endsWith('*')) {
167
+ runs.push({ text: token.slice(1, -1), italic: true })
168
+ } else {
169
+ runs.push({ text: token })
170
+ }
171
+ lastIndex = idx + token.length
172
+ }
173
+ if (lastIndex < text.length) {
174
+ runs.push({ text: text.slice(lastIndex) })
175
+ }
176
+ return runs.filter((r) => r.text !== '')
177
+ }
178
+
179
+ /**
180
+ * 将单行富文本拆分为结构化 Run 数组,用于 HTML 与 PPTX 多 <a:r> 同构输出。
181
+ * 支持可选 autoLeadBold 与内联 LaTeX 数学符号/上下标编译。
182
+ */
183
+ export function parseInlineRuns(input, options = {}) {
184
+ const text = String(input ?? '')
185
+ if (text === '') return []
186
+ if (!containsLatexMath(text)) {
187
+ return parseMarkdownRunsOnly(text, options)
188
+ }
189
+
190
+ const out = []
191
+ const boldParts = text.split('**')
192
+ const hasBalancedBold = boldParts.length >= 3 && boldParts.length % 2 === 1
193
+ if (hasBalancedBold) {
194
+ boldParts.forEach((chunkText, idx) => {
195
+ const boldActive = idx % 2 === 1
196
+ if (!chunkText) return
197
+ const segs = splitMathSegments(chunkText)
198
+ segs.forEach((seg, sIdx) => {
199
+ if (seg.type === 'math') {
200
+ const mathRuns = astToOoxmlInlineRuns(parseLatexMath(seg.latex))
201
+ out.push(...mathRuns.map((r) => (boldActive ? { ...r, bold: true } : r)))
202
+ } else {
203
+ const mdRuns = parseMarkdownRunsOnly(seg.value, idx === 0 && sIdx === 0 && !boldActive ? options : {})
204
+ out.push(...mdRuns.map((r) => (boldActive ? { ...r, bold: true } : r)))
205
+ }
206
+ })
207
+ })
208
+ return out.filter((r) => r.text !== '')
209
+ }
210
+
211
+ const segs = splitMathSegments(text)
212
+ segs.forEach((seg, sIdx) => {
213
+ if (seg.type === 'math') {
214
+ const mathRuns = astToOoxmlInlineRuns(parseLatexMath(seg.latex))
215
+ out.push(...mathRuns)
216
+ } else {
217
+ const mdRuns = parseMarkdownRunsOnly(seg.value, sIdx === 0 ? options : {})
218
+ out.push(...mdRuns)
219
+ }
220
+ })
221
+ return out.filter((r) => r.text !== '')
222
+ }
223
+
224
+ function renderRunsToHtml(runs) {
225
+ if (runs.length === 1 && !runs[0].bold && !runs[0].italic && !runs[0].code && !runs[0].secondary) {
226
+ return escapeHtml(runs[0].text)
227
+ }
228
+ return runs.map((run) => {
229
+ const escaped = escapeHtml(run.text)
230
+ if (run.code) return '<code class="inline-code">' + escaped + '</code>'
231
+ if (run.bold && run.lead) return '<strong class="lead-in">' + escaped + '</strong>'
232
+ if (run.bold) return '<strong>' + escaped + '</strong>'
233
+ if (run.italic) return '<em>' + escaped + '</em>'
234
+ if (run.secondary) return '<span class="ink-sec">' + escaped + '</span>'
235
+ return escaped
236
+ }).join('')
237
+ }
238
+
239
+ export function renderInlineHtml(input, options = {}) {
240
+ const text = String(input ?? '')
241
+ if (!containsLatexMath(text)) {
242
+ return renderRunsToHtml(parseMarkdownRunsOnly(text, options))
243
+ }
244
+ const boldParts = text.split('**')
245
+ if (boldParts.length >= 3 && boldParts.length % 2 === 1) {
246
+ return boldParts.map((chunkText, idx) => {
247
+ if (!chunkText) return ''
248
+ const innerHtml = splitMathSegments(chunkText).map((seg, sIdx) => {
249
+ if (seg.type === 'math') {
250
+ return latexToMathMl(seg.latex, {
251
+ display: seg.display,
252
+ className: seg.display ? 'deck-math is-block' : 'deck-math is-inline',
253
+ })
254
+ }
255
+ return renderRunsToHtml(parseMarkdownRunsOnly(seg.value, idx === 0 && sIdx === 0 ? options : {}))
256
+ }).join('')
257
+ return idx % 2 === 1 ? '<strong>' + innerHtml + '</strong>' : innerHtml
258
+ }).join('')
259
+ }
260
+ const segs = splitMathSegments(text)
261
+ return segs.map((seg, sIdx) => {
262
+ if (seg.type === 'math') {
263
+ return latexToMathMl(seg.latex, {
264
+ display: seg.display,
265
+ className: seg.display ? 'deck-math is-block' : 'deck-math is-inline',
266
+ })
267
+ }
268
+ return renderRunsToHtml(parseMarkdownRunsOnly(seg.value, sIdx === 0 ? options : {}))
269
+ }).join('')
270
+ }
271
+
272
+ // ---------------------------------------------------------------------------
273
+ // CJK + Latin 视觉宽度与确定性字号拟合算法 computeTextFit()
274
+ // ---------------------------------------------------------------------------
275
+
276
+ export function measureEmWidth(input, bold = false) {
277
+ const plain = stripInlineMarkdown(input)
278
+ let total = 0
279
+ for (const ch of plain) {
280
+ const code = ch.codePointAt(0) ?? 0
281
+ if (
282
+ (code >= 0x2E80 && code <= 0x9FFF) ||
283
+ (code >= 0xF900 && code <= 0xFAFF) ||
284
+ (code >= 0xFF00 && code <= 0xFFEF) ||
285
+ (code >= 0x3000 && code <= 0x303F) ||
286
+ code > 0x1F000
287
+ ) {
288
+ total += 1.02
289
+ } else if (ch >= 'A' && ch <= 'Z') {
290
+ total += 0.66
291
+ } else if (ch >= '0' && ch <= '9') {
292
+ total += 0.58
293
+ } else if (ch === ' ' || ch === '.' || ch === ',' || ch === ':' || ch === ';' || ch === '|' || ch === '!' || ch === 'i' || ch === 'l') {
294
+ total += 0.32
295
+ } else {
296
+ total += 0.54
297
+ }
298
+ }
299
+ return bold ? total * 1.06 : total
300
+ }
301
+
302
+ const ROLE_DEFAULTS = {
303
+ coverTitle: { maxPt: 44, minPt: 28, lineHeight: 1.16, spaceAfterPt: 8, bold: true },
304
+ sectionTitle: { maxPt: 38, minPt: 24, lineHeight: 1.18, spaceAfterPt: 6, bold: true },
305
+ slideTitle: { maxPt: 27, minPt: 20, lineHeight: 1.22, spaceAfterPt: 0, bold: true },
306
+ statement: { maxPt: 34, minPt: 22, lineHeight: 1.26, spaceAfterPt: 8, bold: true },
307
+ quote: { maxPt: 28, minPt: 18, lineHeight: 1.32, spaceAfterPt: 8, bold: true },
308
+ body: { maxPt: 18, minPt: 13.5, lineHeight: 1.48, spaceAfterPt: 8, bold: false },
309
+ cardTitle: { maxPt: 17.5, minPt: 14, lineHeight: 1.28, spaceAfterPt: 4, bold: true },
310
+ cardBody: { maxPt: 15, minPt: 13.5, lineHeight: 1.44, spaceAfterPt: 5, bold: false },
311
+ kpiValue: { maxPt: 46, minPt: 26, lineHeight: 1.06, spaceAfterPt: 2, bold: true },
312
+ tableCell: { maxPt: 15, minPt: 11.5, lineHeight: 1.32, spaceAfterPt: 0, bold: false },
313
+ }
314
+
315
+ export function computeTextFit(linesInput, boxIn, role = 'body', overrides = {}) {
316
+ const cfg = { ...(ROLE_DEFAULTS[role] ?? ROLE_DEFAULTS.body), ...overrides }
317
+ const paragraphs = (Array.isArray(linesInput) ? linesInput : [linesInput])
318
+ .map((line) => String(line ?? ''))
319
+ .filter((line) => line.trim() !== '')
320
+ if (paragraphs.length === 0) {
321
+ return { fontPt: cfg.maxPt, lineHeight: cfg.lineHeight, lines: 0, fontScale: 100000, overflow: false }
322
+ }
323
+
324
+ const padXPt = overrides.padXPt ?? 14
325
+ const padYPt = overrides.padYPt ?? 10
326
+ const innerWPt = Math.max(36, boxIn.w * 72 - padXPt * 2)
327
+ const innerHPt = Math.max(20, boxIn.h * 72 - padYPt * 2)
328
+ const emWidths = paragraphs.map((p) => measureEmWidth(p, cfg.bold))
329
+
330
+ const evalAt = (pt) => {
331
+ const lines = emWidths.reduce((sum, em) => sum + Math.max(1, Math.ceil((em * pt) / innerWPt)), 0)
332
+ const totalHPt = lines * pt * cfg.lineHeight + Math.max(0, paragraphs.length - 1) * cfg.spaceAfterPt
333
+ return { lines, totalHPt }
334
+ }
335
+
336
+ for (let pt = cfg.maxPt; pt >= cfg.minPt - 1e-6; pt -= 0.5) {
337
+ const roundedPt = Math.round(pt * 2) / 2
338
+ const { lines, totalHPt } = evalAt(roundedPt)
339
+ if (totalHPt <= innerHPt * 0.94) {
340
+ const ratio = totalHPt / innerHPt
341
+ const fontScale = ratio > 0.88 ? 94000 : 100000
342
+ return { fontPt: roundedPt, lineHeight: cfg.lineHeight, lines, fontScale, overflow: false }
343
+ }
344
+ }
345
+
346
+ const floorEval = evalAt(cfg.minPt)
347
+ return {
348
+ fontPt: cfg.minPt,
349
+ lineHeight: cfg.lineHeight,
350
+ lines: floorEval.lines,
351
+ fontScale: floorEval.totalHPt > innerHPt ? 90000 : 96000,
352
+ overflow: floorEval.totalHPt > innerHPt * 1.05,
353
+ }
354
+ }
355
+
356
+ // ---------------------------------------------------------------------------
357
+ // 结构化子项 items 规范化与从 bullets 自动投影
358
+ // ---------------------------------------------------------------------------
359
+
360
+ export const VALID_STATUS = new Set(['positive', 'negative', 'warning', 'neutral', 'accent'])
361
+
362
+ function parseBulletToItem(rawBullet, index, layout) {
363
+ const clean = cleanRichText(rawBullet)
364
+ const plain = stripInlineMarkdown(clean)
365
+
366
+ if (layout === 'kpi') {
367
+ const pipeParts = clean.split(/\s*[||]\s*/)
368
+ if (pipeParts.length >= 2) {
369
+ const first = stripInlineMarkdown(pipeParts[0])
370
+ const second = pipeParts.slice(1).join(' · ')
371
+ const colonIdx = second.search(/[::]/)
372
+ const title = colonIdx > 0 ? stripInlineMarkdown(second.slice(0, colonIdx)) : stripInlineMarkdown(second)
373
+ const text = colonIdx > 0 ? cleanRichText(second.slice(colonIdx + 1)) : ''
374
+ const deltaMatch = /([+-]\d+(?:\.\d+)?\s*[%%]|YoY[^\s))]*)/i.exec(text + ' ' + pipeParts.join(' '))
375
+ return {
376
+ value: first,
377
+ title: title || ('指标 ' + (index + 1)),
378
+ ...(text ? { text } : {}),
379
+ ...(deltaMatch ? { delta: deltaMatch[1], status: deltaMatch[1].startsWith('-') ? 'negative' : 'positive' } : {}),
380
+ }
381
+ }
382
+ const metricMatch = /^((?:[¥$€]\s*)?[+-]?\d[\d,.]*\s*(?:[%%倍xX]|万|亿|元|万元|亿元|美元|万美元|亿美元|家|个|人|次|台|套|条|项|席|秒|ms|s|h|天|小时|分钟|k|M|B|\+)?)\s*[::\-—]?\s*(.*)$/i.exec(plain)
383
+ if (metricMatch) {
384
+ const rest = metricMatch[2] || ''
385
+ const colon = rest.search(/[::]/)
386
+ return {
387
+ value: metricMatch[1].trim(),
388
+ title: colon > 0 ? rest.slice(0, colon).trim() : (rest.trim() || ('指标 ' + (index + 1))),
389
+ ...(colon > 0 ? { text: rest.slice(colon + 1).trim() } : {}),
390
+ }
391
+ }
392
+ const inlineMetric = /((?:[¥$€]\s*[+-]?\d[\d,.]*(?:\s*(?:[%%倍xX]|万|亿|万元|亿元|美元|万美元|亿美元|家|个|人|次|台|套|条|项|席|秒|ms|天|小时|分钟|k|M|B|\+))?|[+-]?\d[\d,.]*\s*(?:[%%倍xX]|万|亿|万元|亿元|美元|万美元|亿美元|家|个|人|次|台|套|条|项|席|秒|ms|天|小时|分钟|\+)))/.exec(plain)
393
+ if (inlineMetric) {
394
+ const colon = plain.search(/[::]/)
395
+ return {
396
+ value: inlineMetric[1].trim(),
397
+ title: colon > 0 ? plain.slice(0, colon).trim() : plain.replace(inlineMetric[0], '').trim().slice(0, 18) || ('指标 ' + (index + 1)),
398
+ text: colon > 0 ? plain.slice(colon + 1).trim() : plain,
399
+ }
400
+ }
401
+ }
402
+
403
+ if (layout === 'sankey') {
404
+ const flowMatch = /^(.+?)\s*(?:->|→|=>|──>|——>)\s*([^::||]+?)(?:\s*[::||]\s*(.+))?$/.exec(clean)
405
+ if (flowMatch) {
406
+ const srcNode = stripInlineMarkdown(flowMatch[1])
407
+ const dstNode = stripInlineMarkdown(flowMatch[2])
408
+ const rest = stripInlineMarkdown(flowMatch[3] ?? '')
409
+ const statusTag = /\[(positive|negative|warning|accent|neutral)\]/i.exec(rest)
410
+ const cleanedRest = rest.replace(/\[(positive|negative|warning|accent|neutral)\]/gi, '').trim()
411
+ const deltaMatch = /\(([+-][^)]+)\)/.exec(cleanedRest)
412
+ const valMatch = /^([¥$€£]?\s*[+-]?\d[\d,.]*)\s*([^\s((]*)/.exec(cleanedRest)
413
+ return {
414
+ tag: srcNode,
415
+ title: dstNode,
416
+ ...(valMatch ? { value: valMatch[1].replace(/\s+/g, ''), ...(valMatch[2] ? { unit: valMatch[2] } : {}) } : (cleanedRest ? { value: cleanedRest } : {})),
417
+ ...(deltaMatch ? { delta: deltaMatch[1].trim() } : {}),
418
+ ...(statusTag ? { status: statusTag[1].toLowerCase() } : {}),
419
+ }
420
+ }
421
+ }
422
+
423
+ if (layout === 'marimekko') {
424
+ const mekkoMatch = /^([^::]+?)[::]\s*(.+)$/.exec(clean)
425
+ if (mekkoMatch) {
426
+ const rawHead = stripInlineMarkdown(mekkoMatch[1])
427
+ const sizeInHead = /^(.*?)\s*[((]\s*([¥$€£]?\s*\d[\d,.]*)\s*([^))]*)[))]\s*$/.exec(rawHead)
428
+ const colTitle = sizeInHead ? (sizeInHead[1].trim() || rawHead) : rawHead
429
+ const segs = mekkoMatch[2].split(/\s*[||;;,,]\s*/).map((s) => s.trim()).filter(Boolean)
430
+ return {
431
+ title: colTitle,
432
+ ...(sizeInHead ? { value: sizeInHead[2].replace(/\s+/g, ''), ...(sizeInHead[3].trim() ? { unit: sizeInHead[3].trim() } : {}) } : {}),
433
+ ...(segs.length > 0 ? { bullets: segs } : {}),
434
+ }
435
+ }
436
+ }
437
+
438
+ if (layout === 'comparison') {
439
+ const arrowMatch = /^(.+?)\s*(?:->|→|=>|──>|——>|vs\.?|VS)\s*(.+)$/.exec(clean)
440
+ if (arrowMatch) {
441
+ return {
442
+ tag: String(index + 1).padStart(2, '0'),
443
+ title: stripInlineMarkdown(arrowMatch[1]),
444
+ text: cleanRichText(arrowMatch[2]),
445
+ }
446
+ }
447
+ }
448
+
449
+ const boldLead = /^\*\*([^*]+)\*\*\s*[::—\-]?\s*(.*)$/.exec(clean)
450
+ if (boldLead) {
451
+ return {
452
+ tag: String(index + 1).padStart(2, '0'),
453
+ title: boldLead[1].trim(),
454
+ ...(boldLead[2].trim() ? { text: boldLead[2].trim() } : {}),
455
+ }
456
+ }
457
+
458
+ const colonSplit = /^([^::]{1,18})[::]\s*(.+)$/.exec(clean)
459
+ if (colonSplit && !/^https?$/i.test(colonSplit[1])) {
460
+ return {
461
+ tag: String(index + 1).padStart(2, '0'),
462
+ title: stripInlineMarkdown(colonSplit[1]),
463
+ text: colonSplit[2].trim(),
464
+ }
465
+ }
466
+
467
+ if (layout === 'callout') {
468
+ return {
469
+ tag: String(index + 1).padStart(2, '0'),
470
+ title: '',
471
+ text: clean,
472
+ }
473
+ }
474
+
475
+ return {
476
+ tag: String(index + 1).padStart(2, '0'),
477
+ title: plain.length <= 20 ? plain : plain.slice(0, 16) + '…',
478
+ ...(plain.length > 20 ? { text: clean } : {}),
479
+ }
480
+ }
481
+
482
+ const EXTENDED_ITEM_LAYOUTS = new Set(['sankey', 'value-chain', 'marimekko', 'swot'])
483
+
484
+ export function normalizeSlideItems(rawItems, layout) {
485
+ if (!Array.isArray(rawItems) || rawItems.length === 0) return undefined
486
+ const maxItems = EXTENDED_ITEM_LAYOUTS.has(layout) ? 12 : 8
487
+ const out = rawItems
488
+ .slice(0, maxItems)
489
+ .map((entry, idx) => {
490
+ if (typeof entry === 'string') return parseBulletToItem(entry, idx, layout)
491
+ if (!entry || typeof entry !== 'object' || Array.isArray(entry)) return null
492
+ const tag = stripInlineMarkdown(entry.tag ?? entry.badge ?? entry.step ?? entry.phase ?? entry.source ?? entry.from ?? '')
493
+ const title = stripInlineMarkdown(entry.title ?? entry.label ?? entry.heading ?? entry.name ?? entry.target ?? entry.to ?? '')
494
+ const text = cleanRichText(entry.text ?? entry.body ?? entry.description ?? entry.detail ?? '')
495
+ const value = entry.value !== undefined && entry.value !== null ? stripInlineMarkdown(String(entry.value)) : ''
496
+ const unit = stripInlineMarkdown(entry.unit ?? '')
497
+ const delta = stripInlineMarkdown(entry.delta ?? entry.change ?? '')
498
+ const rawStatus = String(entry.status ?? entry.tone ?? '').trim().toLowerCase()
499
+ const status = VALID_STATUS.has(rawStatus) ? rawStatus : undefined
500
+ const startNum = entry.start !== undefined && entry.start !== null && entry.start !== '' ? Number(entry.start) : NaN
501
+ const start = Number.isFinite(startNum) ? Math.max(0, startNum) : undefined
502
+ const spanNum = entry.span !== undefined && entry.span !== null && entry.span !== '' ? Number(entry.span) : NaN
503
+ const span = Number.isFinite(spanNum) ? Math.max(0, spanNum) : undefined
504
+ const milestone = entry.milestone === true ? true : undefined
505
+ const role = stripInlineMarkdown(entry.role ?? '')
506
+ const conversion = stripInlineMarkdown(entry.conversion ?? '')
507
+ const bullets = Array.isArray(entry.bullets ?? entry.items)
508
+ ? (entry.bullets ?? entry.items).map((b) => cleanRichText(String(b))).filter(Boolean).slice(0, 8)
509
+ : undefined
510
+ if (!title && !text && !value && (!bullets || bullets.length === 0)) return null
511
+ return {
512
+ ...(tag ? { tag } : {}),
513
+ ...(title ? { title } : {}),
514
+ ...(text ? { text } : {}),
515
+ ...(value ? { value } : {}),
516
+ ...(unit ? { unit } : {}),
517
+ ...(delta ? { delta } : {}),
518
+ ...(start !== undefined ? { start } : {}),
519
+ ...(span !== undefined ? { span } : {}),
520
+ ...(milestone ? { milestone } : {}),
521
+ ...(role ? { role } : {}),
522
+ ...(conversion ? { conversion } : {}),
523
+ ...(status ? { status } : {}),
524
+ ...(bullets?.length ? { bullets } : {}),
525
+ }
526
+ })
527
+ .filter(Boolean)
528
+ return out.length > 0 ? out : undefined
529
+ }
530
+
531
+ export function resolveEffectiveItems(slide) {
532
+ if (Array.isArray(slide.items) && slide.items.length > 0) return slide.items
533
+ const maxItems = EXTENDED_ITEM_LAYOUTS.has(slide.layout) ? 12 : 8
534
+ const bullets = Array.isArray(slide.bullets) ? slide.bullets : []
535
+ if (bullets.length > 0) {
536
+ return bullets.slice(0, maxItems).map((b, i) => parseBulletToItem(b, i, slide.layout))
537
+ }
538
+ if (slide.subtitle || slide.text) {
539
+ return [parseBulletToItem(slide.text || slide.subtitle, 0, slide.layout)]
540
+ }
541
+ return []
542
+ }
543
+
544
+ export function statusPalette(status, tk) {
545
+ if (status === 'positive') return { fg: tk.positive, bg: tk.surface2, bar: tk.positive }
546
+ if (status === 'negative') return { fg: tk.negative, bg: tk.surface2, bar: tk.negative }
547
+ if (status === 'warning') return { fg: tk.warning, bg: tk.surface2, bar: tk.warning }
548
+ if (status === 'accent') return { fg: tk.accentText, bg: tk.accentSoft, bar: tk.accentPrimary }
549
+ return { fg: tk.accentText, bg: tk.surface1, bar: tk.accentPrimary }
550
+ }
551
+
552
+ export function isNumericCell(cell) {
553
+ const plain = stripInlineMarkdown(cell)
554
+ return /^\s*[+-]?[$¥€£]?\s*(?:\d{1,3}(?:,\d{3})+|\d+)(?:\.\d+)?\s*(?:[%%xX倍]|万|亿|元|万元|亿元|次|页|个|人|天|小时|分钟|ms|s)?\s*$/.test(plain)
555
+ }
556
+
557
+ // ---------------------------------------------------------------------------
558
+ // OOXML 基础图元与附着连接线构建器(严格遵循 ECMA-376 元素顺序与单页唯一 ID)
559
+ // ---------------------------------------------------------------------------
560
+
561
+ export function ooxmlSolidFill(color, alphaFraction = 1) {
562
+ const alphaXml = alphaFraction < 0.999
563
+ ? '<a:alpha val="' + Math.round(Math.max(0, Math.min(1, alphaFraction)) * 100000) + '"/>'
564
+ : ''
565
+ return '<a:solidFill><a:srgbClr val="' + hex6(color) + '">' + alphaXml + '</a:srgbClr></a:solidFill>'
566
+ }
567
+
568
+ export function ooxmlLinearGradientFill(stops, angleDeg = 135) {
569
+ const gsLst = stops.map((s) => {
570
+ const pos = Math.round(Math.max(0, Math.min(1, s.offset)) * 100000)
571
+ const alpha = s.alpha !== undefined && s.alpha < 0.999
572
+ ? '<a:alpha val="' + Math.round(Math.max(0, Math.min(1, s.alpha)) * 100000) + '"/>'
573
+ : ''
574
+ return '<a:gs pos="' + pos + '"><a:srgbClr val="' + hex6(s.color) + '">' + alpha + '</a:srgbClr></a:gs>'
575
+ }).join('')
576
+ const ang = Math.round((((angleDeg % 360) + 360) % 360) * 60000)
577
+ return '<a:gradFill rotWithShape="1"><a:gsLst>' + gsLst + '</a:gsLst><a:lin ang="' + ang + '" scaled="1"/></a:gradFill>'
578
+ }
579
+
580
+ export function ooxmlRichParagraph(textOrRuns, options = {}) {
581
+ const {
582
+ sizePt = 16,
583
+ color = '#0F172A',
584
+ secondaryColor = color,
585
+ accentColor = color,
586
+ codeHighlight = '',
587
+ bold = false,
588
+ italic = false,
589
+ lang = 'zh-CN',
590
+ align = 'l',
591
+ bullet = false,
592
+ bulletChar = '▪',
593
+ bulletColor = '',
594
+ font = 'Segoe UI',
595
+ lineHeight = 1.35,
596
+ spaceBeforePt = 0,
597
+ spaceAfterPt = 0,
598
+ spc = 0,
599
+ autoLeadBold = false,
600
+ } = options
601
+
602
+ const latinFont = pptxFontName(font)
603
+ const eaFont = pptxEastAsianFont(font)
604
+ const sz = Math.round(sizePt * 100)
605
+ const runs = Array.isArray(textOrRuns)
606
+ ? textOrRuns
607
+ : parseInlineRuns(String(textOrRuns ?? ''), { autoLeadBold })
608
+
609
+ const lnSpcXml = lineHeight > 0
610
+ ? '<a:lnSpc><a:spcPct val="' + Math.round(lineHeight * 100000) + '"/></a:lnSpc>'
611
+ : ''
612
+ const spcBefXml = spaceBeforePt > 0
613
+ ? '<a:spcBef><a:spcPts val="' + Math.round(spaceBeforePt * 100) + '"/></a:spcBef>'
614
+ : ''
615
+ const spcAftXml = spaceAfterPt > 0
616
+ ? '<a:spcAft><a:spcPts val="' + Math.round(spaceAfterPt * 100) + '"/></a:spcAft>'
617
+ : ''
618
+ const bulletXml = bullet
619
+ ? (bulletColor ? '<a:buClr><a:srgbClr val="' + hex6(bulletColor) + '"/></a:buClr>' : '') +
620
+ '<a:buSzPct val="85000"/>' +
621
+ '<a:buFont typeface="' + escapeXml(latinFont) + '"/>' +
622
+ '<a:buChar char="' + escapeXml(bulletChar) + '"/>'
623
+ : '<a:buNone/>'
624
+
625
+ const pPrAttrs = (bullet ? ' marL="247650" indent="-247650"' : '') + (align !== 'l' ? ' algn="' + align + '"' : '')
626
+ const pPr = '<a:pPr' + pPrAttrs + '>' + lnSpcXml + spcBefXml + spcAftXml + bulletXml + '</a:pPr>'
627
+
628
+ if (runs.length === 0) {
629
+ return '<a:p>' + pPr + '<a:endParaRPr lang="' + lang + '" sz="' + sz + '" dirty="0"/></a:p>'
630
+ }
631
+
632
+ const runsXml = runs.map((run) => {
633
+ const runBold = Boolean(bold || run.bold)
634
+ const runItalic = Boolean(italic || run.italic)
635
+ const runColor = run.accent ? accentColor : run.secondary ? secondaryColor : color
636
+ const runSize = run.sizePt ? Math.round(run.sizePt * 100) : sz
637
+ const effSpc = run.spcEm ? Math.round(spc + run.spcEm * (run.sizePt ?? sizePt) * 100) : spc
638
+ const spcAttr = effSpc !== 0 ? ' spc="' + Math.round(effSpc) + '"' : ''
639
+ const baselineAttr = run.baseline ? ' baseline="' + Math.round(run.baseline) + '"' : ''
640
+ const isPureMathNonCjk = Boolean(run.math && !/[\u2E80-\u9FFF\uF900-\uFAFF\uFF00-\uFFEF]/.test(run.text))
641
+ const runLang = isPureMathNonCjk ? 'en-US' : lang
642
+ const runLatin = isPureMathNonCjk ? 'Georgia' : latinFont
643
+ const hlXml = run.code && codeHighlight
644
+ ? '<a:highlight><a:srgbClr val="' + hex6(codeHighlight) + '"/></a:highlight>'
645
+ : ''
646
+ return (
647
+ '<a:r><a:rPr lang="' + runLang + '" sz="' + runSize + '" b="' + (runBold ? 1 : 0) + '"' +
648
+ (runItalic ? ' i="1"' : '') + baselineAttr + spcAttr + ' dirty="0">' +
649
+ ooxmlSolidFill(runColor) +
650
+ hlXml +
651
+ '<a:latin typeface="' + escapeXml(runLatin) + '"/>' +
652
+ '<a:ea typeface="' + escapeXml(isPureMathNonCjk ? runLatin : eaFont) + '"/>' +
653
+ '</a:rPr><a:t>' + escapeXml(run.text) + '</a:t></a:r>'
654
+ )
655
+ }).join('')
656
+
657
+ return '<a:p>' + pPr + runsXml + '</a:p>'
658
+ }
659
+
660
+ export function ooxmlShape(id, name, boxIn, options = {}) {
661
+ const {
662
+ preset = 'rect',
663
+ adj,
664
+ adjs,
665
+ fill = '',
666
+ fillAlpha = 1,
667
+ gradientStops = null,
668
+ gradientAngle = 135,
669
+ stroke = '',
670
+ strokePt = 0.75,
671
+ dash = '',
672
+ shadow = false,
673
+ txBox = false,
674
+ anchor = 't',
675
+ marginsIn = { l: 0.08, r: 0.08, t: 0.05, b: 0.05 },
676
+ fontScale = 100000,
677
+ autofit = true,
678
+ paragraphs = [],
679
+ } = options
680
+
681
+ const b = boxToEmu(boxIn)
682
+ const avLst = adjs && typeof adjs === 'object'
683
+ ? '<a:avLst>' + Object.entries(adjs).map(([k, v]) => '<a:gd name="' + escapeXml(k) + '" fmla="val ' + Math.round(v) + '"/>').join('') + '</a:avLst>'
684
+ : adj !== undefined && preset === 'roundRect'
685
+ ? '<a:avLst><a:gd name="adj" fmla="val ' + Math.round(adj) + '"/></a:avLst>'
686
+ : '<a:avLst/>'
687
+ const fillXml = gradientStops
688
+ ? ooxmlLinearGradientFill(gradientStops, gradientAngle)
689
+ : fill
690
+ ? ooxmlSolidFill(fill, fillAlpha)
691
+ : '<a:noFill/>'
692
+ const lnXml = stroke
693
+ ? '<a:ln w="' + ptToEmu(strokePt) + '" cap="flat">' + ooxmlSolidFill(stroke) + (dash ? '<a:prstDash val="' + dash + '"/>' : '') + '</a:ln>'
694
+ : '<a:ln><a:noFill/></a:ln>'
695
+ const effectXml = shadow
696
+ ? '<a:effectLst><a:outerShdw blurRad="152400" dist="38100" dir="5400000" algn="tl" rotWithShape="0"><a:srgbClr val="0F172A"><a:alpha val="9000"/></a:srgbClr></a:outerShdw></a:effectLst>'
697
+ : ''
698
+
699
+ const lIns = inToEmu(marginsIn.l ?? 0.08)
700
+ const rIns = inToEmu(marginsIn.r ?? 0.08)
701
+ const tIns = inToEmu(marginsIn.t ?? 0.05)
702
+ const bIns = inToEmu(marginsIn.b ?? 0.05)
703
+ const fitXml = autofit
704
+ ? '<a:normAutofit' + (fontScale < 100000 ? ' fontScale="' + fontScale + '"' : '') + '/>'
705
+ : '<a:noAutofit/>'
706
+ const bodyContent = paragraphs.length > 0 ? paragraphs.join('') : '<a:p/>'
707
+
708
+ return (
709
+ '<p:sp>' +
710
+ '<p:nvSpPr><p:cNvPr id="' + id + '" name="' + escapeXml(name) + '"/>' +
711
+ '<p:cNvSpPr' + (txBox ? ' txBox="1"' : '') + '/><p:nvPr/></p:nvSpPr>' +
712
+ '<p:spPr><a:xfrm><a:off x="' + b.x + '" y="' + b.y + '"/><a:ext cx="' + b.w + '" cy="' + b.h + '"/></a:xfrm>' +
713
+ '<a:prstGeom prst="' + preset + '">' + avLst + '</a:prstGeom>' +
714
+ fillXml + lnXml + effectXml + '</p:spPr>' +
715
+ '<p:txBody><a:bodyPr wrap="square" rtlCol="0" lIns="' + lIns + '" tIns="' + tIns + '" rIns="' + rIns + '" bIns="' + bIns + '" anchor="' + anchor + '">' +
716
+ fitXml + '</a:bodyPr><a:lstStyle/>' + bodyContent + '</p:txBody>' +
717
+ '</p:sp>'
718
+ )
719
+ }
720
+
721
+ export function ooxmlCustGeomShape(id, name, boxIn, pathCommandsXml, options = {}) {
722
+ const {
723
+ pathW = 10000,
724
+ pathH = 10000,
725
+ fill = '',
726
+ fillAlpha = 1,
727
+ gradientStops = null,
728
+ gradientAngle = 0,
729
+ stroke = '',
730
+ strokePt = 0.75,
731
+ } = options
732
+ const b = boxToEmu(boxIn)
733
+ const fillXml = gradientStops
734
+ ? ooxmlLinearGradientFill(gradientStops, gradientAngle)
735
+ : fill
736
+ ? ooxmlSolidFill(fill, fillAlpha)
737
+ : '<a:noFill/>'
738
+ const lnXml = stroke
739
+ ? '<a:ln w="' + ptToEmu(strokePt) + '" cap="flat">' + ooxmlSolidFill(stroke) + '</a:ln>'
740
+ : '<a:ln><a:noFill/></a:ln>'
741
+
742
+ return (
743
+ '<p:sp>' +
744
+ '<p:nvSpPr><p:cNvPr id="' + id + '" name="' + escapeXml(name) + '"/><p:cNvSpPr/><p:nvPr/></p:nvSpPr>' +
745
+ '<p:spPr>' +
746
+ '<a:xfrm><a:off x="' + b.x + '" y="' + b.y + '"/><a:ext cx="' + Math.max(12700, b.w) + '" cy="' + Math.max(12700, b.h) + '"/></a:xfrm>' +
747
+ '<a:custGeom><a:avLst/><a:gdLst/><a:ahLst/><a:cxnLst/><a:rect l="l" t="t" r="r" b="b"/>' +
748
+ '<a:pathLst><a:path w="' + Math.round(pathW) + '" h="' + Math.round(pathH) + '">' +
749
+ pathCommandsXml +
750
+ '</a:path></a:pathLst></a:custGeom>' +
751
+ fillXml + lnXml +
752
+ '</p:spPr>' +
753
+ '<p:txBody><a:bodyPr/><a:lstStyle/><a:p/></p:txBody>' +
754
+ '</p:sp>'
755
+ )
756
+ }
757
+
758
+ export function ooxmlMathShape(id, name, boxIn, latex, options = {}) {
759
+ const ast = parseLatexMath(latex)
760
+ const fit = fitFormulaBoxIn(ast, boxIn, {
761
+ padXIn: options.padXIn ?? 0.24,
762
+ padYIn: options.padYIn ?? 0.10,
763
+ emIn: options.emIn ?? 0.30,
764
+ align: options.align ?? 'ctr',
765
+ })
766
+ const b = boxToEmu(fit)
767
+ const ommlXml = astToOmml(ast, {
768
+ wrapDrawingMl: true,
769
+ sizePt: options.sizePt ?? 20,
770
+ color: options.color ?? '#0F172A',
771
+ })
772
+ const algn = options.align === 'l' ? 'l' : 'ctr'
773
+ return (
774
+ '<p:sp>' +
775
+ '<p:nvSpPr><p:cNvPr id="' + id + '" name="' + escapeXml(name) + '"/><p:cNvSpPr txBox="1"/><p:nvPr/></p:nvSpPr>' +
776
+ '<p:spPr><a:xfrm><a:off x="' + b.x + '" y="' + b.y + '"/><a:ext cx="' + b.w + '" cy="' + b.h + '"/></a:xfrm>' +
777
+ '<a:prstGeom prst="rect"><a:avLst/></a:prstGeom><a:noFill/><a:ln><a:noFill/></a:ln></p:spPr>' +
778
+ '<p:txBody><a:bodyPr wrap="none" lIns="0" tIns="0" rIns="0" bIns="0" anchor="ctr"><a:noAutofit/></a:bodyPr><a:lstStyle/>' +
779
+ '<a:p><a:pPr algn="' + algn + '"><a:buNone/></a:pPr>' + ommlXml + '</a:p>' +
780
+ '</p:txBody></p:sp>'
781
+ )
782
+ }
783
+
784
+ export function renderMathCardPptx(namePrefix, boxIn, latex, nextIdFn, chromeCfg, theme, options = {}) {
785
+ const tk = theme.tokens
786
+ const cardPreset = chromeCfg.cardRadiusPx > 0 ? 'roundRect' : 'rect'
787
+ const plateFill = theme.dark ? '#F8FAFC' : tk.surface2
788
+ const out = [
789
+ ooxmlShape(nextIdFn(), namePrefix + ' Surface', boxIn, {
790
+ preset: cardPreset,
791
+ adj: roundRectAdj(boxIn.w, boxIn.h, chromeCfg.cardRadiusPx),
792
+ fill: plateFill,
793
+ stroke: chromeCfg.cardBorderless ? '' : tk.accentPrimary,
794
+ strokePt: 1.0,
795
+ }),
796
+ ooxmlShape(nextIdFn(), namePrefix + ' Accent Rail', { x: boxIn.x, y: boxIn.y, w: 0.07, h: boxIn.h }, {
797
+ preset: 'rect',
798
+ fill: tk.accentPrimary,
799
+ }),
800
+ ooxmlMathShape(nextIdFn(), namePrefix + ' Equation', boxIn, latex, {
801
+ padXIn: 0.34,
802
+ padYIn: 0.14,
803
+ emIn: options.emIn ?? 0.30,
804
+ sizePt: options.sizePt ?? 20,
805
+ color: '#0F172A',
806
+ align: options.align ?? 'ctr',
807
+ }),
808
+ ]
809
+ return out.join('')
810
+ }
811
+
812
+ export function ooxmlLine(id, name, fromIn, toIn, options = {}) {
813
+ const {
814
+ color = '#CBD5E1',
815
+ widthPt = 1,
816
+ dash = '',
817
+ headArrow = false,
818
+ tailArrow = false,
819
+ } = options
820
+ const x = Math.min(fromIn.x, toIn.x)
821
+ const y = Math.min(fromIn.y, toIn.y)
822
+ const w = Math.max(0.001, Math.abs(toIn.x - fromIn.x))
823
+ const h = Math.max(0.001, Math.abs(toIn.y - fromIn.y))
824
+ const flipH = toIn.x < fromIn.x ? ' flipH="1"' : ''
825
+ const flipV = toIn.y < fromIn.y ? ' flipV="1"' : ''
826
+ const headXml = headArrow ? '<a:headEnd type="triangle" w="med" len="med"/>' : ''
827
+ const tailXml = tailArrow ? '<a:tailEnd type="triangle" w="med" len="med"/>' : ''
828
+
829
+ return (
830
+ '<p:cxnSp>' +
831
+ '<p:nvCxnSpPr><p:cNvPr id="' + id + '" name="' + escapeXml(name) + '"/><p:cNvCxnSpPr/><p:nvPr/></p:nvCxnSpPr>' +
832
+ '<p:spPr><a:xfrm' + flipH + flipV + '><a:off x="' + inToEmu(x) + '" y="' + inToEmu(y) + '"/>' +
833
+ '<a:ext cx="' + (Math.abs(toIn.x - fromIn.x) < 0.0005 ? 0 : Math.max(12700, inToEmu(w))) + '" cy="' + (Math.abs(toIn.y - fromIn.y) < 0.0005 ? 0 : inToEmu(h)) + '"/></a:xfrm>' +
834
+ '<a:prstGeom prst="line"><a:avLst/></a:prstGeom>' +
835
+ '<a:ln w="' + ptToEmu(widthPt) + '" cap="rnd">' + ooxmlSolidFill(color) +
836
+ (dash ? '<a:prstDash val="' + dash + '"/>' : '') + headXml + tailXml + '</a:ln>' +
837
+ '</p:spPr></p:cxnSp>'
838
+ )
839
+ }
840
+
841
+ /**
842
+ * 原生可附着连接线构建器(支持 straightConnector1 / bentConnector3 及 <a:stCxn> / <a:endCxn> 锚点绑定)。
843
+ * 锚点编号严格对齐 OOXML 四向连接点:0=top, 1=left, 2=bottom, 3=right。
844
+ */
845
+ export function ooxmlConnector(id, name, fromIn, toIn, options = {}) {
846
+ const {
847
+ preset = 'straightConnector1',
848
+ orientation = 'horizontal',
849
+ adj1 = 50000,
850
+ stCxn = null,
851
+ endCxn = null,
852
+ color = '#64748B',
853
+ widthPt = 1.35,
854
+ dash = '',
855
+ headArrow = false,
856
+ tailArrow = true,
857
+ headEndType = 'triangle',
858
+ tailEndType = 'triangle',
859
+ } = options
860
+
861
+ const dx = toIn.x - fromIn.x
862
+ const dy = toIn.y - fromIn.y
863
+
864
+ let offX = 0
865
+ let offY = 0
866
+ let extCx = 0
867
+ let extCy = 0
868
+ let rotAttr = ''
869
+ let flipHAttr = ''
870
+ let flipVAttr = ''
871
+
872
+ if (preset === 'bentConnector3' && orientation === 'vertical') {
873
+ const mx = (fromIn.x + toIn.x) / 2
874
+ const my = (fromIn.y + toIn.y) / 2
875
+ const cwIn = Math.abs(dy)
876
+ const chIn = Math.abs(dx)
877
+ offX = Math.max(0, inToEmu(mx - cwIn / 2))
878
+ offY = Math.max(0, inToEmu(my - chIn / 2))
879
+ extCx = cwIn < 0.0005 ? 0 : Math.max(12700, inToEmu(cwIn))
880
+ extCy = chIn < 0.0005 ? 0 : Math.max(12700, inToEmu(chIn))
881
+ rotAttr = ' rot="5400000"'
882
+ if (dy < -0.0005) flipHAttr = ' flipH="1"'
883
+ if (dx >= -0.0005) flipVAttr = ' flipV="1"'
884
+ } else {
885
+ const x = Math.min(fromIn.x, toIn.x)
886
+ const y = Math.min(fromIn.y, toIn.y)
887
+ const w = Math.abs(dx)
888
+ const h = Math.abs(dy)
889
+ offX = Math.max(0, inToEmu(x))
890
+ offY = Math.max(0, inToEmu(y))
891
+ extCx = w < 0.0005 ? 0 : Math.max(12700, inToEmu(w))
892
+ extCy = h < 0.0005 ? 0 : Math.max(12700, inToEmu(h))
893
+ if (dx < -0.0005) flipHAttr = ' flipH="1"'
894
+ if (dy < -0.0005) flipVAttr = ' flipV="1"'
895
+ }
896
+
897
+ const cxnChildren = (stCxn ? '<a:stCxn id="' + Math.trunc(stCxn.id) + '" idx="' + Math.trunc(stCxn.idx) + '"/>' : '') +
898
+ (endCxn ? '<a:endCxn id="' + Math.trunc(endCxn.id) + '" idx="' + Math.trunc(endCxn.idx) + '"/>' : '')
899
+ const cNvCxnXml = cxnChildren ? '<p:cNvCxnSpPr>' + cxnChildren + '</p:cNvCxnSpPr>' : '<p:cNvCxnSpPr/>'
900
+ const avLstXml = preset === 'bentConnector3' && adj1 !== undefined && Math.round(adj1) !== 50000
901
+ ? '<a:avLst><a:gd name="adj1" fmla="val ' + Math.max(10000, Math.min(90000, Math.round(adj1))) + '"/></a:avLst>'
902
+ : '<a:avLst/>'
903
+ const headXml = headArrow ? '<a:headEnd type="' + escapeXml(headEndType) + '" w="med" len="med"/>' : ''
904
+ const tailXml = tailArrow ? '<a:tailEnd type="' + escapeXml(tailEndType) + '" w="med" len="med"/>' : ''
905
+
906
+ return (
907
+ '<p:cxnSp>' +
908
+ '<p:nvCxnSpPr><p:cNvPr id="' + id + '" name="' + escapeXml(name) + '"/>' + cNvCxnXml + '<p:nvPr/></p:nvCxnSpPr>' +
909
+ '<p:spPr><a:xfrm' + rotAttr + flipHAttr + flipVAttr + '><a:off x="' + offX + '" y="' + offY + '"/>' +
910
+ '<a:ext cx="' + extCx + '" cy="' + extCy + '"/></a:xfrm>' +
911
+ '<a:prstGeom prst="' + preset + '">' + avLstXml + '</a:prstGeom>' +
912
+ '<a:ln w="' + ptToEmu(widthPt) + '" cap="rnd">' + ooxmlSolidFill(color) +
913
+ (dash ? '<a:prstDash val="' + dash + '"/>' : '') + headXml + tailXml + '</a:ln>' +
914
+ '</p:spPr></p:cxnSp>'
915
+ )
916
+ }
917
+
918
+ // ---------------------------------------------------------------------------
919
+ // 6 套母版骨架(Chrome Skeletons):配置、卡片表面、页眉、底栏结论条与页脚页码
920
+ // ---------------------------------------------------------------------------
921
+
922
+ const SOURCE_PREFIX_RE = /^(?:数据来源|来源|出处|测算口径|实验环境|统计口径|资料来源|Source|Sources|Note|Notes)\s*[::]/i
923
+
924
+ export function formatSourceLine(rawSource, langOrAttr = 'zh') {
925
+ const clean = String(rawSource ?? '').trim()
926
+ if (clean === '') return ''
927
+ if (SOURCE_PREFIX_RE.test(clean)) return clean
928
+ const isEn = langOrAttr === 'en' || langOrAttr === 'en-US'
929
+ return (isEn ? 'Source: ' : '数据来源:') + clean
930
+ }
931
+
932
+ export function computeBadgePillWidth(text, sizePt = 11, maxW = 2.8, minW = 0.54) {
933
+ const rawW = measureEmWidth(String(text ?? ''), true) * (sizePt / 72) * 1.24 + 0.38
934
+ return Math.min(Math.max(minW, maxW), Math.max(minW, +rawW.toFixed(4)))
935
+ }
936
+
937
+ export function getChromeConfig(chromeStyle, theme) {
938
+ const chrome = chromeStyle || resolveChromeStyle(theme)
939
+ if (chrome === 'consulting-classic') {
940
+ return {
941
+ chrome,
942
+ cardRadiusPx: 0,
943
+ cardBorderless: false,
944
+ cardStrokePt: 0.75,
945
+ cardTopBar: false,
946
+ cardLeftBar: true,
947
+ headerStyle: 'consulting-tracker',
948
+ bodyTopY: 1.80,
949
+ takeawayStyle: 'top-rule',
950
+ folioPos: 'bottom-right',
951
+ useDisplayNumeral: false,
952
+ }
953
+ }
954
+ if (chrome === 'keynote-spatial') {
955
+ return {
956
+ chrome,
957
+ cardRadiusPx: 21,
958
+ cardBorderless: true,
959
+ cardStrokePt: 0,
960
+ cardTopBar: false,
961
+ cardLeftBar: false,
962
+ headerStyle: 'keynote-clean',
963
+ bodyTopY: 1.76,
964
+ takeawayStyle: 'caption',
965
+ folioPos: 'bottom-right',
966
+ useDisplayNumeral: false,
967
+ }
968
+ }
969
+ if (chrome === 'editorial-folio') {
970
+ return {
971
+ chrome,
972
+ cardRadiusPx: 0,
973
+ cardBorderless: false,
974
+ cardStrokePt: 0.5,
975
+ cardTopBar: false,
976
+ cardLeftBar: false,
977
+ headerStyle: 'editorial-folio',
978
+ bodyTopY: 1.80,
979
+ takeawayStyle: 'editorial-rule',
980
+ folioPos: 'top-right',
981
+ useDisplayNumeral: true,
982
+ }
983
+ }
984
+ if (chrome === 'academic-minimal') {
985
+ return {
986
+ chrome,
987
+ cardRadiusPx: 8,
988
+ cardBorderless: false,
989
+ cardStrokePt: 0.75,
990
+ cardTopBar: false,
991
+ cardLeftBar: false,
992
+ headerStyle: 'beamer-band',
993
+ bodyTopY: 1.54,
994
+ takeawayStyle: 'top-rule',
995
+ folioPos: 'beamer-bar',
996
+ useDisplayNumeral: false,
997
+ }
998
+ }
999
+ if (chrome === 'gov-ceremonial') {
1000
+ return {
1001
+ chrome,
1002
+ cardRadiusPx: 8,
1003
+ cardBorderless: false,
1004
+ cardStrokePt: 0.75,
1005
+ cardTopBar: true,
1006
+ cardLeftBar: false,
1007
+ headerStyle: 'double-rule',
1008
+ bodyTopY: 1.82,
1009
+ takeawayStyle: 'pill',
1010
+ folioPos: 'bottom-right',
1011
+ useDisplayNumeral: false,
1012
+ }
1013
+ }
1014
+ return {
1015
+ chrome: 'saas-bento',
1016
+ cardRadiusPx: Math.max(10, theme?.radiusPx ?? 13),
1017
+ cardBorderless: false,
1018
+ cardStrokePt: 0.75,
1019
+ cardTopBar: true,
1020
+ cardLeftBar: false,
1021
+ headerStyle: 'standard',
1022
+ bodyTopY: 1.82,
1023
+ takeawayStyle: 'pill',
1024
+ folioPos: 'bottom-right',
1025
+ useDisplayNumeral: false,
1026
+ }
1027
+ }
1028
+
1029
+ export function renderSurfaceCardPptx(name, box, opts, nextIdFn, chromeCfg, theme) {
1030
+ const tk = theme.tokens
1031
+ const {
1032
+ fill = tk.surface1,
1033
+ focal = false,
1034
+ stroke,
1035
+ accentBarColor = tk.accentPrimary,
1036
+ paragraphs = [],
1037
+ anchor = 't',
1038
+ marginsIn = { l: 0.08, r: 0.08, t: 0.05, b: 0.05 },
1039
+ fontScale = 100000,
1040
+ txBox = false,
1041
+ } = opts
1042
+ const radius = chromeCfg.cardRadiusPx
1043
+ const preset = radius > 0 ? 'roundRect' : 'rect'
1044
+ const resolvedFill = chromeCfg.cardBorderless && focal && fill === tk.surface1 ? tk.surface2 : fill
1045
+ const resolvedStroke = stroke !== undefined
1046
+ ? stroke
1047
+ : chromeCfg.cardBorderless
1048
+ ? ''
1049
+ : (focal ? tk.accentPrimary : tk.hairline)
1050
+ const strokePt = focal ? 1.0 : chromeCfg.cardStrokePt
1051
+ const out = [
1052
+ ooxmlShape(nextIdFn(), name, box, {
1053
+ preset,
1054
+ adj: roundRectAdj(box.w, box.h, radius),
1055
+ fill: resolvedFill,
1056
+ stroke: resolvedStroke,
1057
+ strokePt,
1058
+ shadow: theme.shadow && !chromeCfg.cardBorderless,
1059
+ txBox,
1060
+ anchor,
1061
+ marginsIn,
1062
+ fontScale,
1063
+ paragraphs,
1064
+ }),
1065
+ ]
1066
+ if (chromeCfg.cardTopBar) {
1067
+ out.push(ooxmlShape(nextIdFn(), name + ' top bar', { x: box.x, y: box.y, w: box.w, h: 0.05 }, {
1068
+ preset: 'rect',
1069
+ fill: focal ? accentBarColor : tk.hairline,
1070
+ }))
1071
+ }
1072
+ if (chromeCfg.cardLeftBar) {
1073
+ out.push(ooxmlShape(nextIdFn(), name + ' left stripe', { x: box.x, y: box.y, w: 0.04, h: box.h }, {
1074
+ preset: 'rect',
1075
+ fill: focal ? accentBarColor : tk.accentPrimary,
1076
+ }))
1077
+ }
1078
+ return out.join('')
1079
+ }
1080
+
1081
+ export function formatGovKicker(kicker) {
1082
+ const clean = String(kicker ?? '').trim()
1083
+ if (!clean) return ''
1084
+ return /^【/.test(clean) ? clean : '【' + clean + '】'
1085
+ }
1086
+
1087
+ export function renderSlideChromePptx(slide, index, total, theme, langAttr, manifest = {}, nextIdFn) {
1088
+ const tk = theme.tokens
1089
+ const chromeStyle = resolveChromeStyle(theme, slide, manifest.brand)
1090
+ const chromeCfg = getChromeConfig(chromeStyle, theme)
1091
+ const idBase = (index + 1) * 10
1092
+ const shapes = []
1093
+ const isFraming = slide.layout === 'cover' || slide.layout === 'closing'
1094
+ const hasTakeaway = !isFraming && typeof slide.takeaway === 'string' && slide.takeaway.trim() !== ''
1095
+ const isEn = langAttr === 'en-US'
1096
+
1097
+ if (hasTakeaway) {
1098
+ const barBox = { x: 0.62, y: 6.26, w: 12.09, h: 0.54 }
1099
+ const text = slide.takeaway.trim()
1100
+ if (chromeCfg.takeawayStyle === 'caption') {
1101
+ shapes.push(ooxmlShape(nextIdFn(), 'Takeaway box', barBox, {
1102
+ txBox: true,
1103
+ anchor: 'ctr',
1104
+ marginsIn: { l: 0.4, r: 0.4, t: 0.02, b: 0.02 },
1105
+ paragraphs: [
1106
+ ooxmlRichParagraph(text, {
1107
+ sizePt: 13.5,
1108
+ color: tk.inkSecondary,
1109
+ secondaryColor: tk.inkMuted,
1110
+ accentColor: tk.accentText,
1111
+ bold: false,
1112
+ lang: langAttr,
1113
+ align: 'ctr',
1114
+ font: theme.fonts.body,
1115
+ lineHeight: 1.2,
1116
+ }),
1117
+ ],
1118
+ }))
1119
+ } else if (chromeCfg.takeawayStyle === 'top-rule' || chromeCfg.takeawayStyle === 'editorial-rule') {
1120
+ const prefix = chromeCfg.takeawayStyle === 'editorial-rule'
1121
+ ? '**—** '
1122
+ : (isEn ? '**Key Takeaway:** ' : '**核心结论:**')
1123
+ shapes.push(ooxmlLine(nextIdFn(), 'Takeaway rule', { x: 0.62, y: 6.22 }, { x: 12.71, y: 6.22 }, {
1124
+ color: chromeCfg.takeawayStyle === 'editorial-rule' ? tk.hairline : tk.accentPrimary,
1125
+ widthPt: chromeCfg.takeawayStyle === 'editorial-rule' ? 0.75 : 1.0,
1126
+ }))
1127
+ shapes.push(ooxmlShape(nextIdFn(), 'Takeaway box', { x: 0.62, y: 6.28, w: 12.09, h: 0.50 }, {
1128
+ txBox: true,
1129
+ anchor: 'ctr',
1130
+ marginsIn: { l: 0, r: 0, t: 0.02, b: 0.02 },
1131
+ paragraphs: [
1132
+ ooxmlRichParagraph(prefix + text, {
1133
+ sizePt: 13.5,
1134
+ color: tk.inkPrimary,
1135
+ secondaryColor: tk.inkSecondary,
1136
+ accentColor: tk.accentText,
1137
+ bold: false,
1138
+ lang: langAttr,
1139
+ font: theme.fonts.body,
1140
+ lineHeight: 1.22,
1141
+ }),
1142
+ ],
1143
+ }))
1144
+ } else {
1145
+ const preset = chromeCfg.cardRadiusPx > 0 ? 'roundRect' : 'rect'
1146
+ shapes.push(ooxmlShape(nextIdFn(), 'Takeaway box', barBox, {
1147
+ preset,
1148
+ adj: roundRectAdj(barBox.w, barBox.h, Math.min(8, chromeCfg.cardRadiusPx)),
1149
+ fill: tk.accentSoft,
1150
+ stroke: tk.hairline,
1151
+ strokePt: 0.75,
1152
+ anchor: 'ctr',
1153
+ marginsIn: { l: 0.22, r: 0.16, t: 0.04, b: 0.04 },
1154
+ paragraphs: [
1155
+ ooxmlRichParagraph('▸ ' + text, {
1156
+ sizePt: 13.5,
1157
+ color: tk.inkPrimary,
1158
+ secondaryColor: tk.inkSecondary,
1159
+ accentColor: tk.accentText,
1160
+ bold: true,
1161
+ lang: langAttr,
1162
+ font: theme.fonts.body,
1163
+ lineHeight: 1.2,
1164
+ }),
1165
+ ],
1166
+ }))
1167
+ shapes.push(ooxmlShape(nextIdFn(), 'Takeaway accent', { x: 0.62, y: 6.26, w: 0.06, h: 0.54 }, {
1168
+ preset: 'rect',
1169
+ fill: tk.accentPrimary,
1170
+ }))
1171
+ }
1172
+ }
1173
+
1174
+ if (!isFraming) {
1175
+ const folio = String(index + 1).padStart(2, '0') + ' / ' + String(total).padStart(2, '0')
1176
+ if (chromeCfg.folioPos === 'beamer-bar') {
1177
+ shapes.push(ooxmlShape(nextIdFn(), 'Beamer footer band', { x: 0, y: 7.04, w: CANVAS_IN.w, h: 0.46 }, {
1178
+ preset: 'rect',
1179
+ fill: tk.surface1,
1180
+ }))
1181
+ shapes.push(ooxmlLine(nextIdFn(), 'Beamer footer rule', { x: 0, y: 7.04 }, { x: CANVAS_IN.w, y: 7.04 }, {
1182
+ color: tk.hairline,
1183
+ widthPt: 0.5,
1184
+ }))
1185
+ const leftText = slide.source
1186
+ ? formatSourceLine(slide.source, langAttr)
1187
+ : (manifest.brand?.footer || manifest.title || '')
1188
+ if (leftText) {
1189
+ shapes.push(ooxmlShape(nextIdFn(), slide.source ? 'Footer source' : 'Beamer zone left', { x: 0.62, y: 7.10, w: 4.4, h: 0.32 }, {
1190
+ txBox: true,
1191
+ anchor: 'ctr',
1192
+ marginsIn: { l: 0, r: 0, t: 0, b: 0 },
1193
+ paragraphs: [
1194
+ ooxmlRichParagraph(leftText, {
1195
+ sizePt: 9.5,
1196
+ color: tk.inkMuted,
1197
+ lang: langAttr,
1198
+ align: 'l',
1199
+ font: theme.fonts.body,
1200
+ lineHeight: 1.15,
1201
+ }),
1202
+ ],
1203
+ }))
1204
+ }
1205
+ const centerText = (slide.kicker || slide.title || '').trim()
1206
+ if (centerText) {
1207
+ shapes.push(ooxmlShape(nextIdFn(), 'Beamer zone chapter', { x: 5.1, y: 7.10, w: 3.13, h: 0.32 }, {
1208
+ txBox: true,
1209
+ anchor: 'ctr',
1210
+ marginsIn: { l: 0, r: 0, t: 0, b: 0 },
1211
+ paragraphs: [
1212
+ ooxmlRichParagraph(centerText, {
1213
+ sizePt: 9.5,
1214
+ color: tk.inkSecondary,
1215
+ bold: true,
1216
+ lang: langAttr,
1217
+ align: 'ctr',
1218
+ font: theme.fonts.body,
1219
+ lineHeight: 1.15,
1220
+ }),
1221
+ ],
1222
+ }))
1223
+ }
1224
+ shapes.push(ooxmlShape(idBase + 9, 'Page number', { x: 10.65, y: 7.10, w: 2.06, h: 0.32 }, {
1225
+ txBox: true,
1226
+ anchor: 'ctr',
1227
+ marginsIn: { l: 0, r: 0, t: 0, b: 0 },
1228
+ paragraphs: [
1229
+ ooxmlRichParagraph(folio, {
1230
+ sizePt: 9.5,
1231
+ color: tk.accentText,
1232
+ bold: true,
1233
+ lang: langAttr,
1234
+ align: 'r',
1235
+ font: theme.fonts.body,
1236
+ lineHeight: 1.15,
1237
+ }),
1238
+ ],
1239
+ }))
1240
+ } else {
1241
+ if (slide.source) {
1242
+ const hasBrandFooter = Boolean(manifest.brand?.footer)
1243
+ const sourceBox = hasBrandFooter
1244
+ ? { x: 5.4, y: 6.95, w: 5.0, h: 0.32 }
1245
+ : { x: 0.62, y: 6.95, w: 9.2, h: 0.32 }
1246
+ shapes.push(ooxmlShape(nextIdFn(), 'Footer source', sourceBox, {
1247
+ txBox: true,
1248
+ anchor: 'ctr',
1249
+ marginsIn: { l: 0, r: 0, t: 0, b: 0 },
1250
+ paragraphs: [
1251
+ ooxmlRichParagraph(formatSourceLine(slide.source, langAttr), {
1252
+ sizePt: 9.5,
1253
+ color: tk.inkMuted,
1254
+ lang: langAttr,
1255
+ align: hasBrandFooter ? 'r' : 'l',
1256
+ font: theme.fonts.body,
1257
+ lineHeight: 1.15,
1258
+ }),
1259
+ ],
1260
+ }))
1261
+ }
1262
+
1263
+ const folioBox = chromeCfg.folioPos === 'top-right'
1264
+ ? { x: 10.65, y: 0.24, w: 2.06, h: 0.28 }
1265
+ : { x: 10.65, y: 6.95, w: 2.06, h: 0.32 }
1266
+ shapes.push(ooxmlShape(idBase + 9, 'Page number', folioBox, {
1267
+ txBox: true,
1268
+ anchor: 'ctr',
1269
+ marginsIn: { l: 0, r: 0, t: 0, b: 0 },
1270
+ paragraphs: [
1271
+ ooxmlRichParagraph(folio, {
1272
+ sizePt: chromeCfg.folioPos === 'top-right' ? 10 : 9.5,
1273
+ color: tk.inkMuted,
1274
+ lang: langAttr,
1275
+ align: 'r',
1276
+ font: theme.fonts.body,
1277
+ lineHeight: 1.15,
1278
+ }),
1279
+ ],
1280
+ }))
1281
+ }
1282
+ }
1283
+
1284
+ return shapes.join('')
1285
+ }
1286
+
1287
+ export function renderStandardHeaderPptx(slide, idBase, nextIdFn, theme, langAttr, chromeCfg) {
1288
+ const tk = theme.tokens
1289
+ const kicker = (slide.kicker ?? '').trim()
1290
+ const title = (slide.title ?? '').trim()
1291
+ const showKicker = kicker !== '' && kicker !== title
1292
+ const shapes = []
1293
+ const style = chromeCfg?.headerStyle || 'standard'
1294
+
1295
+ if (style === 'beamer-band') {
1296
+ shapes.push(ooxmlShape(nextIdFn(), 'Beamer header band', { x: 0, y: 0, w: CANVAS_IN.w, h: 1.28 }, {
1297
+ preset: 'rect',
1298
+ fill: tk.surface1,
1299
+ }))
1300
+ shapes.push(ooxmlLine(nextIdFn(), 'Beamer header rule', { x: 0, y: 1.28 }, { x: CANVAS_IN.w, y: 1.28 }, {
1301
+ color: tk.accentPrimary,
1302
+ widthPt: 1.5,
1303
+ }))
1304
+ if (showKicker) {
1305
+ shapes.push(ooxmlShape(idBase + 1, 'Kicker', { x: 0.62, y: 0.14, w: 12.09, h: 0.24 }, {
1306
+ txBox: true,
1307
+ anchor: 'ctr',
1308
+ marginsIn: { l: 0, r: 0, t: 0, b: 0 },
1309
+ paragraphs: [
1310
+ ooxmlRichParagraph(kicker.toUpperCase(), {
1311
+ sizePt: 10,
1312
+ color: tk.accentText,
1313
+ bold: true,
1314
+ lang: langAttr,
1315
+ font: theme.fonts.body,
1316
+ lineHeight: 1.1,
1317
+ spc: 140,
1318
+ }),
1319
+ ],
1320
+ }))
1321
+ }
1322
+ if (title !== '') {
1323
+ const titleBox = { x: 0.62, y: showKicker ? 0.40 : 0.24, w: 12.09, h: 0.78 }
1324
+ const fit = computeTextFit(title, titleBox, 'slideTitle', { maxPt: 25, minPt: 20, padXPt: 2, padYPt: 2 })
1325
+ shapes.push(ooxmlShape(idBase + 2, 'Title', titleBox, {
1326
+ txBox: true,
1327
+ anchor: 'ctr',
1328
+ marginsIn: { l: 0, r: 0, t: 0, b: 0 },
1329
+ fontScale: fit.fontScale,
1330
+ paragraphs: [
1331
+ ooxmlRichParagraph(title, {
1332
+ sizePt: fit.fontPt,
1333
+ color: tk.inkPrimary,
1334
+ bold: true,
1335
+ lang: langAttr,
1336
+ font: theme.fonts.heading,
1337
+ lineHeight: fit.lineHeight,
1338
+ }),
1339
+ ],
1340
+ }))
1341
+ }
1342
+ return shapes.join('')
1343
+ }
1344
+
1345
+ if (style === 'editorial-folio') {
1346
+ if (showKicker) {
1347
+ shapes.push(ooxmlShape(idBase + 1, 'Kicker', { x: 0.62, y: 0.24, w: 8.8, h: 0.28 }, {
1348
+ txBox: true,
1349
+ anchor: 'ctr',
1350
+ marginsIn: { l: 0, r: 0, t: 0, b: 0 },
1351
+ paragraphs: [
1352
+ ooxmlRichParagraph(kicker.toUpperCase(), {
1353
+ sizePt: 10,
1354
+ color: tk.accentText,
1355
+ bold: true,
1356
+ lang: langAttr,
1357
+ font: theme.fonts.body,
1358
+ lineHeight: 1.1,
1359
+ spc: 180,
1360
+ }),
1361
+ ],
1362
+ }))
1363
+ }
1364
+ shapes.push(ooxmlLine(nextIdFn(), 'Editorial folio rule', { x: 0.62, y: 0.56 }, { x: 12.71, y: 0.56 }, {
1365
+ color: tk.hairline,
1366
+ widthPt: 0.5,
1367
+ }))
1368
+ if (title !== '') {
1369
+ const titleBox = { x: 0.62, y: 0.70, w: 12.09, h: 0.86 }
1370
+ const fit = computeTextFit(title, titleBox, 'slideTitle', { padXPt: 2, padYPt: 2 })
1371
+ shapes.push(ooxmlShape(idBase + 2, 'Title', titleBox, {
1372
+ txBox: true,
1373
+ anchor: 'ctr',
1374
+ marginsIn: { l: 0, r: 0, t: 0, b: 0 },
1375
+ fontScale: fit.fontScale,
1376
+ paragraphs: [
1377
+ ooxmlRichParagraph(title, {
1378
+ sizePt: fit.fontPt,
1379
+ color: tk.inkPrimary,
1380
+ bold: true,
1381
+ lang: langAttr,
1382
+ font: theme.fonts.heading,
1383
+ lineHeight: fit.lineHeight,
1384
+ }),
1385
+ ],
1386
+ }))
1387
+ }
1388
+ shapes.push(ooxmlLine(nextIdFn(), 'Header rule', { x: 0.62, y: 1.64 }, { x: 12.71, y: 1.64 }, {
1389
+ color: tk.hairline,
1390
+ widthPt: 0.5,
1391
+ }))
1392
+ return shapes.join('')
1393
+ }
1394
+
1395
+ if (style === 'keynote-clean') {
1396
+ if (showKicker) {
1397
+ const pillW = computeBadgePillWidth(kicker.toUpperCase(), 10, 4.2, 1.05)
1398
+ shapes.push(ooxmlShape(idBase + 1, 'Kicker', { x: 0.62, y: 0.38, w: pillW, h: 0.30 }, {
1399
+ preset: 'roundRect',
1400
+ adj: 50000,
1401
+ fill: tk.accentSoft,
1402
+ anchor: 'ctr',
1403
+ marginsIn: { l: 0.08, r: 0.08, t: 0.02, b: 0.02 },
1404
+ paragraphs: [
1405
+ ooxmlRichParagraph(kicker.toUpperCase(), {
1406
+ sizePt: 10,
1407
+ color: tk.accentText,
1408
+ bold: true,
1409
+ lang: langAttr,
1410
+ align: 'ctr',
1411
+ font: theme.fonts.body,
1412
+ lineHeight: 1.1,
1413
+ spc: 100,
1414
+ }),
1415
+ ],
1416
+ }))
1417
+ }
1418
+ if (title !== '') {
1419
+ const titleBox = { x: 0.62, y: showKicker ? 0.76 : 0.48, w: 12.09, h: 0.88 }
1420
+ const fit = computeTextFit(title, titleBox, 'slideTitle', { padXPt: 2, padYPt: 2 })
1421
+ shapes.push(ooxmlShape(idBase + 2, 'Title', titleBox, {
1422
+ txBox: true,
1423
+ anchor: 'ctr',
1424
+ marginsIn: { l: 0, r: 0, t: 0, b: 0 },
1425
+ fontScale: fit.fontScale,
1426
+ paragraphs: [
1427
+ ooxmlRichParagraph(title, {
1428
+ sizePt: fit.fontPt,
1429
+ color: tk.inkPrimary,
1430
+ bold: true,
1431
+ lang: langAttr,
1432
+ font: theme.fonts.heading,
1433
+ lineHeight: fit.lineHeight,
1434
+ }),
1435
+ ],
1436
+ }))
1437
+ }
1438
+ return shapes.join('')
1439
+ }
1440
+
1441
+ if (style === 'consulting-tracker') {
1442
+ let trackerW = 0
1443
+ if (showKicker) {
1444
+ trackerW = computeBadgePillWidth(kicker.toUpperCase(), 10, 3.6, 1.15)
1445
+ shapes.push(ooxmlShape(idBase + 1, 'Kicker', { x: 12.71 - trackerW, y: 0.44, w: trackerW, h: 0.32 }, {
1446
+ preset: 'rect',
1447
+ fill: tk.accentSoft,
1448
+ stroke: tk.accentPrimary,
1449
+ strokePt: 0.75,
1450
+ anchor: 'ctr',
1451
+ marginsIn: { l: 0.08, r: 0.08, t: 0.02, b: 0.02 },
1452
+ paragraphs: [
1453
+ ooxmlRichParagraph(kicker.toUpperCase(), {
1454
+ sizePt: 10,
1455
+ color: tk.accentText,
1456
+ bold: true,
1457
+ lang: langAttr,
1458
+ align: 'ctr',
1459
+ font: theme.fonts.body,
1460
+ lineHeight: 1.1,
1461
+ spc: 80,
1462
+ }),
1463
+ ],
1464
+ }))
1465
+ }
1466
+ if (title !== '') {
1467
+ const titleW = trackerW > 0 ? 12.09 - trackerW - 0.30 : 12.09
1468
+ const titleBox = { x: 0.62, y: 0.44, w: titleW, h: 1.06 }
1469
+ const fit = computeTextFit(title, titleBox, 'slideTitle', { padXPt: 2, padYPt: 2 })
1470
+ shapes.push(ooxmlShape(idBase + 2, 'Title', titleBox, {
1471
+ txBox: true,
1472
+ anchor: 'ctr',
1473
+ marginsIn: { l: 0, r: 0, t: 0, b: 0 },
1474
+ fontScale: fit.fontScale,
1475
+ paragraphs: [
1476
+ ooxmlRichParagraph(title, {
1477
+ sizePt: fit.fontPt,
1478
+ color: tk.inkPrimary,
1479
+ bold: true,
1480
+ lang: langAttr,
1481
+ font: theme.fonts.heading,
1482
+ lineHeight: fit.lineHeight,
1483
+ }),
1484
+ ],
1485
+ }))
1486
+ }
1487
+ shapes.push(ooxmlLine(nextIdFn(), 'Header rule', { x: 0.62, y: 1.64 }, { x: 12.71, y: 1.64 }, {
1488
+ color: tk.hairline,
1489
+ widthPt: 0.75,
1490
+ }))
1491
+ return shapes.join('')
1492
+ }
1493
+
1494
+ if (style === 'double-rule') {
1495
+ if (showKicker) {
1496
+ shapes.push(ooxmlShape(idBase + 1, 'Kicker', { x: 0.62, y: 0.36, w: 11.4, h: 0.30 }, {
1497
+ txBox: true,
1498
+ anchor: 'ctr',
1499
+ marginsIn: { l: 0, r: 0, t: 0, b: 0 },
1500
+ paragraphs: [
1501
+ ooxmlRichParagraph(formatGovKicker(kicker), {
1502
+ sizePt: 11.5,
1503
+ color: tk.accentText,
1504
+ bold: true,
1505
+ lang: langAttr,
1506
+ font: theme.fonts.body,
1507
+ lineHeight: 1.1,
1508
+ spc: 80,
1509
+ }),
1510
+ ],
1511
+ }))
1512
+ }
1513
+ if (title !== '') {
1514
+ const titleBox = { x: 0.62, y: showKicker ? 0.68 : 0.48, w: 12.09, h: 0.84 }
1515
+ const fit = computeTextFit(title, titleBox, 'slideTitle', { padXPt: 2, padYPt: 2 })
1516
+ shapes.push(ooxmlShape(idBase + 2, 'Title', titleBox, {
1517
+ txBox: true,
1518
+ anchor: 'ctr',
1519
+ marginsIn: { l: 0, r: 0, t: 0, b: 0 },
1520
+ fontScale: fit.fontScale,
1521
+ paragraphs: [
1522
+ ooxmlRichParagraph(title, {
1523
+ sizePt: fit.fontPt,
1524
+ color: tk.inkPrimary,
1525
+ bold: true,
1526
+ lang: langAttr,
1527
+ font: theme.fonts.heading,
1528
+ lineHeight: fit.lineHeight,
1529
+ }),
1530
+ ],
1531
+ }))
1532
+ }
1533
+ shapes.push(ooxmlLine(nextIdFn(), 'Header rule', { x: 0.62, y: 1.60 }, { x: 12.71, y: 1.60 }, {
1534
+ color: tk.accentPrimary,
1535
+ widthPt: 1.5,
1536
+ }))
1537
+ shapes.push(ooxmlLine(nextIdFn(), 'Header secondary rule', { x: 0.62, y: 1.67 }, { x: 12.71, y: 1.67 }, {
1538
+ color: tk.accentSecondary,
1539
+ widthPt: 0.5,
1540
+ }))
1541
+ return shapes.join('')
1542
+ }
1543
+
1544
+ if (showKicker) {
1545
+ shapes.push(ooxmlShape(idBase + 1, 'Kicker', { x: 0.62, y: 0.42, w: 11.4, h: 0.28 }, {
1546
+ txBox: true,
1547
+ anchor: 'ctr',
1548
+ marginsIn: { l: 0, r: 0, t: 0, b: 0 },
1549
+ paragraphs: [
1550
+ ooxmlRichParagraph(kicker.toUpperCase(), {
1551
+ sizePt: 11,
1552
+ color: tk.accentText,
1553
+ bold: true,
1554
+ lang: langAttr,
1555
+ font: theme.fonts.body,
1556
+ lineHeight: 1.1,
1557
+ spc: 140,
1558
+ }),
1559
+ ],
1560
+ }))
1561
+ }
1562
+
1563
+ if (title !== '') {
1564
+ const titleBox = { x: 0.62, y: showKicker ? 0.72 : 0.52, w: 12.09, h: 0.86 }
1565
+ const fit = computeTextFit(title, titleBox, 'slideTitle', { padXPt: 2, padYPt: 2 })
1566
+ shapes.push(ooxmlShape(idBase + 2, 'Title', titleBox, {
1567
+ txBox: true,
1568
+ anchor: 'ctr',
1569
+ marginsIn: { l: 0, r: 0, t: 0, b: 0 },
1570
+ fontScale: fit.fontScale,
1571
+ paragraphs: [
1572
+ ooxmlRichParagraph(title, {
1573
+ sizePt: fit.fontPt,
1574
+ color: tk.inkPrimary,
1575
+ bold: true,
1576
+ lang: langAttr,
1577
+ font: theme.fonts.heading,
1578
+ lineHeight: fit.lineHeight,
1579
+ }),
1580
+ ],
1581
+ }))
1582
+ }
1583
+
1584
+ shapes.push(ooxmlLine(nextIdFn(), 'Header rule', { x: 0.62, y: 1.66 }, { x: 12.71, y: 1.66 }, {
1585
+ color: tk.hairline,
1586
+ widthPt: 0.75,
1587
+ }))
1588
+
1589
+ return shapes.join('')
1590
+ }
1591
+
1592
+ export function renderSlideHeaderHtml(slide, chromeStyle, folioText, isFraming, fallbackKicker = '') {
1593
+ const title = slide.title || ''
1594
+ const k = (slide.kicker || fallbackKicker || '').trim()
1595
+ const showK = k !== '' && k !== title
1596
+ if (chromeStyle === 'editorial-folio') {
1597
+ return (
1598
+ '<div class="editorial-folio-bar">' +
1599
+ (showK ? '<span class="kicker">' + escapeHtml(k) + '</span>' : '<span class="kicker"></span>') +
1600
+ (!isFraming ? '<span class="slide-folio">' + folioText + '</span>' : '') +
1601
+ '</div>' +
1602
+ '<header class="slide-header">' +
1603
+ (title !== '' ? '<h2>' + renderInlineHtml(title) + '</h2>' : '') +
1604
+ '</header>'
1605
+ )
1606
+ }
1607
+ if (chromeStyle === 'academic-minimal') {
1608
+ return (
1609
+ '<header class="slide-header beamer-header-band">' +
1610
+ (showK ? '<div class="kicker">' + escapeHtml(k) + '</div>' : '') +
1611
+ (title !== '' ? '<h2>' + renderInlineHtml(title) + '</h2>' : '') +
1612
+ '</header>'
1613
+ )
1614
+ }
1615
+ if (chromeStyle === 'consulting-classic') {
1616
+ return (
1617
+ '<header class="slide-header consulting-header">' +
1618
+ (title !== '' ? '<h2>' + renderInlineHtml(title) + '</h2>' : '') +
1619
+ (showK ? '<span class="consulting-tracker kicker">' + escapeHtml(k) + '</span>' : '') +
1620
+ '</header>'
1621
+ )
1622
+ }
1623
+ if (chromeStyle === 'gov-ceremonial') {
1624
+ return (
1625
+ '<header class="slide-header gov-header">' +
1626
+ (showK ? '<div class="kicker gov-ribbon">' + escapeHtml(formatGovKicker(k)) + '</div>' : '') +
1627
+ (title !== '' ? '<h2>' + renderInlineHtml(title) + '</h2>' : '') +
1628
+ '</header>'
1629
+ )
1630
+ }
1631
+ return (
1632
+ '<header class="slide-header">' +
1633
+ (showK ? '<div class="kicker">' + escapeHtml(k) + '</div>' : '') +
1634
+ (title !== '' ? '<h2>' + renderInlineHtml(title) + '</h2>' : '') +
1635
+ '</header>'
1636
+ )
1637
+ }
1638
+
1639
+ export function renderSlideChromeHtml(slide, chromeStyle, folioText, langId, manifest = {}, isFraming = false) {
1640
+ const takeawayPrefix = chromeStyle === 'consulting-classic'
1641
+ ? '<strong class="takeaway-prefix">' + (langId === 'en' ? 'Key Takeaway:' : '核心结论:') + '</strong>'
1642
+ : '<span class="takeaway-arrow" aria-hidden="true">' + (chromeStyle === 'editorial-folio' ? '—' : '▸') + '</span>'
1643
+ const takeawayHtml = !isFraming && slide.takeaway
1644
+ ? '<div class="slide-takeaway">' + takeawayPrefix + '<span class="takeaway-text">' + renderInlineHtml(slide.takeaway) + '</span></div>'
1645
+ : ''
1646
+
1647
+ let footerStrip = ''
1648
+ if (!isFraming) {
1649
+ const sourceText = slide.source ? formatSourceLine(slide.source, langId) : ''
1650
+ if (chromeStyle === 'academic-minimal') {
1651
+ const zLeft = sourceText || manifest.brand?.footer || manifest.title || ''
1652
+ const zMid = (slide.kicker || slide.title || '').trim()
1653
+ footerStrip =
1654
+ '<footer class="beamer-status-bar">' +
1655
+ '<span class="slide-source beamer-zone-left">' + escapeHtml(zLeft) + '</span>' +
1656
+ '<span class="beamer-zone-mid">' + escapeHtml(zMid) + '</span>' +
1657
+ '<span class="slide-folio beamer-zone-right">' + folioText + '</span>' +
1658
+ '</footer>'
1659
+ } else if (chromeStyle === 'editorial-folio') {
1660
+ footerStrip = sourceText
1661
+ ? '<footer class="slide-footer-strip"><span class="slide-source">' + escapeHtml(sourceText) + '</span></footer>'
1662
+ : ''
1663
+ } else {
1664
+ const folioLeft = sourceText ? '<span class="slide-source">' + escapeHtml(sourceText) + '</span>' : ''
1665
+ const folioRight = '<span class="slide-folio">' + folioText + '</span>'
1666
+ footerStrip = '<footer class="slide-footer-strip">' + folioLeft + folioRight + '</footer>'
1667
+ }
1668
+ }
1669
+
1670
+ return takeawayHtml + footerStrip
1671
+ }
1672
+
1673
+ export const CHROME_CSS = `
1674
+ .slide-takeaway{
1675
+ margin-top:auto;background:var(--accent-soft);border:1px solid var(--hairline);border-left:4px solid var(--accent);
1676
+ border-radius:calc(var(--radius) * .85);padding:10px 18px;display:flex;align-items:center;gap:10px;
1677
+ font-size:clamp(13px,1.25vw,17px);font-weight:600;color:var(--fg);
1678
+ }
1679
+ .takeaway-arrow,.takeaway-prefix{color:var(--accent-text)}
1680
+ .slide-footer-strip{display:flex;justify-content:space-between;align-items:center;gap:16px;font-size:12px;color:var(--muted);padding-top:4px;font-variant-numeric:tabular-nums}
1681
+ .slide-folio{margin-left:auto}
1682
+ /* 6 Chrome Skeleton Differentiation */
1683
+ .slide[data-chrome="consulting-classic"] .consulting-header{display:flex;align-items:flex-start;justify-content:space-between;gap:20px}
1684
+ .slide[data-chrome="consulting-classic"] .consulting-tracker{border:1px solid var(--accent);background:var(--accent-soft);padding:5px 14px;border-radius:0;margin:0;white-space:nowrap}
1685
+ .slide[data-chrome="consulting-classic"] .surface-card,.slide[data-chrome="consulting-classic"] .bullets-list,.slide[data-chrome="consulting-classic"] .statement-card,.slide[data-chrome="consulting-classic"] .quote-card{border-radius:0;border-left:3.5px solid var(--accent)}
1686
+ .slide[data-chrome="consulting-classic"] .slide-takeaway{background:transparent;border:0;border-top:1.5px solid var(--accent);border-radius:0;padding:10px 0 2px}
1687
+ .slide[data-chrome="keynote-spatial"] .slide-header{border-bottom:0;padding-bottom:4px}
1688
+ .slide[data-chrome="keynote-spatial"] .slide-header .kicker{display:inline-block;background:var(--accent-soft);padding:4px 14px;border-radius:99px;letter-spacing:.1em}
1689
+ .slide[data-chrome="keynote-spatial"] .surface-card,.slide[data-chrome="keynote-spatial"] .bullets-list,.slide[data-chrome="keynote-spatial"] .statement-card,.slide[data-chrome="keynote-spatial"] .quote-card{border:0;border-radius:20px;box-shadow:none}
1690
+ .slide[data-chrome="keynote-spatial"] .slide-takeaway{background:transparent;border:0;justify-content:center;text-align:center;color:var(--ink-secondary);font-weight:500}
1691
+ .slide[data-chrome="editorial-folio"] .editorial-folio-bar{display:flex;justify-content:space-between;align-items:center;border-bottom:1px solid var(--hairline);padding-bottom:8px;margin-bottom:-8px;font-size:12px;color:var(--muted)}
1692
+ .slide[data-chrome="editorial-folio"] .editorial-folio-bar .kicker{margin-bottom:0}
1693
+ .slide[data-chrome="editorial-folio"] .slide-header{border-bottom-width:1px}
1694
+ .slide[data-chrome="editorial-folio"] .surface-card,.slide[data-chrome="editorial-folio"] .bullets-list,.slide[data-chrome="editorial-folio"] .statement-card,.slide[data-chrome="editorial-folio"] .quote-card{border-radius:0}
1695
+ .slide[data-chrome="editorial-folio"] .slide-takeaway{background:transparent;border:0;border-top:1px solid var(--hairline);border-radius:0;padding:10px 0 2px}
1696
+ .slide[data-chrome="saas-bento"] .surface-card{border-radius:13px}
1697
+ .slide[data-chrome="saas-bento"] .surface-card.is-hero,.slide[data-chrome="saas-bento"] .surface-card.is-focal,.slide[data-chrome="saas-bento"] .surface-card.is-active{border-top:3px solid var(--accent)}
1698
+ .slide[data-chrome="academic-minimal"]:not(.slide--cover):not(.slide--closing):not(.slide--section){padding-top:clamp(108px,13vw,148px);padding-bottom:clamp(46px,5.5vw,66px)}
1699
+ .slide[data-chrome="academic-minimal"] .beamer-header-band{position:absolute;top:0;left:0;right:0;background:var(--surface1);border-bottom:2.5px solid var(--accent);padding:clamp(14px,1.8vw,22px) clamp(36px,5.4vw,88px)}
1700
+ .slide[data-chrome="academic-minimal"] .beamer-status-bar{position:absolute;bottom:0;left:0;right:0;display:grid;grid-template-columns:1fr auto 1fr;align-items:center;gap:12px;background:var(--surface1);border-top:1px solid var(--hairline);padding:8px clamp(36px,5.4vw,88px);font-size:12px;color:var(--muted);font-variant-numeric:tabular-nums}
1701
+ .slide[data-chrome="academic-minimal"] .beamer-zone-mid{text-align:center;font-weight:600;color:var(--ink-secondary)}
1702
+ .slide[data-chrome="academic-minimal"] .beamer-zone-right{text-align:right;color:var(--accent-text);font-weight:700}
1703
+ .slide[data-chrome="academic-minimal"] .slide-takeaway{background:transparent;border:0;border-top:1px solid var(--accent);border-bottom:1px solid var(--hairline);border-radius:0;padding:8px 0}
1704
+ .slide[data-chrome="gov-ceremonial"] .gov-header{border-bottom:2px solid var(--accent);box-shadow:0 4px 0 0 var(--bg),0 5.5px 0 0 var(--accent2);padding-bottom:12px;margin-bottom:4px}
1705
+ .slide[data-chrome="gov-ceremonial"] .gov-ribbon{letter-spacing:.08em}
1706
+ `