dsh-ppt 0.26.0 → 0.27.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 (33) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/README.en.md +5 -4
  3. package/README.md +5 -4
  4. package/docs/USAGE.en.md +1 -0
  5. package/docs/USAGE.md +1 -0
  6. package/docs/VALIDATION.md +4 -0
  7. package/docs/assets/intro/workflow-en-dark.svg +1 -1
  8. package/docs/assets/intro/workflow-en-light.svg +1 -1
  9. package/docs/assets/intro/workflow-en-mobile-dark.svg +1 -1
  10. package/docs/assets/intro/workflow-en-mobile-light.svg +1 -1
  11. package/docs/assets/intro/workflow-zh-dark.svg +1 -1
  12. package/docs/assets/intro/workflow-zh-light.svg +1 -1
  13. package/docs/assets/intro/workflow-zh-mobile-dark.svg +1 -1
  14. package/docs/assets/intro/workflow-zh-mobile-light.svg +1 -1
  15. package/lib/client.js +83 -9
  16. package/lib/execution.js +8 -4
  17. package/lib/tools.js +56 -1
  18. package/lib/types.d.ts +64 -0
  19. package/lib/workbench.js +67 -3
  20. package/package.json +1 -1
  21. package/skills/dsh-ppt/SKILL.md +3 -3
  22. package/skills/dsh-ppt/package.json +1 -1
  23. package/skills/dsh-ppt/scripts/build-deck.mjs +15 -3
  24. package/skills/dsh-ppt/scripts/deck-absorb.mjs +114 -1
  25. package/skills/dsh-ppt/scripts/deck-advanced.mjs +106 -15
  26. package/skills/dsh-ppt/scripts/deck-chrome.mjs +114 -6
  27. package/skills/dsh-ppt/scripts/deck-core.mjs +6 -0
  28. package/skills/dsh-ppt/scripts/deck-covers.mjs +804 -0
  29. package/skills/dsh-ppt/scripts/deck-director.mjs +118 -1
  30. package/skills/dsh-ppt/scripts/deck-icons.mjs +469 -0
  31. package/skills/dsh-ppt/scripts/deck-layouts.mjs +519 -92
  32. package/skills/dsh-ppt/scripts/deck-media.mjs +159 -15
  33. package/skills/dsh-ppt/scripts/deck-taste.mjs +347 -0
@@ -1,6 +1,7 @@
1
1
  // Shared geometry, media framing, and publication-grade chart compilers (SVG + OOXML + @office-kit/pptx).
2
2
  import { resolveChromeStyle } from './deck-themes.mjs'
3
3
  import { getChromeConfig, computeBadgePillWidth, roundRectAdj } from './deck-layouts.mjs'
4
+ import { resolveActiveTaste } from './deck-taste.mjs'
4
5
 
5
6
  export const MEDIA_LAYOUTS = new Set(['image', 'image-left', 'image-right', 'chart', 'chart-split'])
6
7
  export const CHART_KINDS = Object.freeze([
@@ -11,10 +12,25 @@ export const CANVAS = { w: 13.3333333333, h: 7.5 }
11
12
  export const LOGO_BOX = { x: 11.55, y: 0.18, w: 0.95, h: 0.42 }
12
13
  export const FOOTER_BOX = { x: 0.65, y: 6.98, w: 9.2, h: 0.28 }
13
14
 
14
- export function mediaBoxes(layout, variantInput, slide = {}) {
15
+ function hasChartAnnotationStrip(slide, manifest = {}) {
16
+ if (!slide?.chart || slide.chart.kind === 'waterfall') return false
17
+ if (slide.layout !== 'chart' && slide.layout !== 'chart-split') return false
18
+ const c = slide.chart
19
+ if (c.referenceLine && Number.isFinite(c.referenceLine.value)) return true
20
+ if (c.callout?.label) return true
21
+ const taste = resolveActiveTaste(manifest, slide)
22
+ if ((c.showGrowthCallout || taste.chartGrowthCallout) && ['column', 'bar', 'line', 'area', 'combo'].includes(c.kind)) {
23
+ const vals = c.series?.[0]?.values || []
24
+ if (vals.length >= 2 && Math.abs(vals[0]) > 1e-9) return true
25
+ }
26
+ return false
27
+ }
28
+
29
+ export function mediaBoxes(layout, variantInput, slide = {}, manifest = {}) {
15
30
  const variant = String(variantInput ?? slide?.variant ?? '').trim().toLowerCase()
16
31
  const hasTakeaway = Boolean(slide?.takeaway && String(slide.takeaway).trim())
17
32
  const hasCaption = Boolean((slide?.image?.caption && String(slide.image.caption).trim()) || (slide?.chart?.caption && String(slide.chart.caption).trim()))
33
+ const annotReserve = hasChartAnnotationStrip(slide, manifest) ? 0.36 : 0
18
34
  const bottomLimit = hasTakeaway ? (hasCaption ? 5.80 : 6.04) : 6.42
19
35
  const bodyTop = 1.68
20
36
  const bodyH = +(bottomLimit - bodyTop).toFixed(3)
@@ -52,8 +68,8 @@ export function mediaBoxes(layout, variantInput, slide = {}) {
52
68
  if (layout === 'chart-split') {
53
69
  const chartRight = variant === 'chart-right'
54
70
  const chartBox = chartRight
55
- ? { x: 5.32, y: bodyTop, w: 7.36, h: bodyH }
56
- : { x: 0.65, y: bodyTop, w: 7.36, h: bodyH }
71
+ ? { x: 5.32, y: +(bodyTop + annotReserve).toFixed(3), w: 7.36, h: +(bodyH - annotReserve).toFixed(3) }
72
+ : { x: 0.65, y: +(bodyTop + annotReserve).toFixed(3), w: 7.36, h: +(bodyH - annotReserve).toFixed(3) }
57
73
  const sideBox = chartRight
58
74
  ? { x: 0.65, y: bodyTop, w: 4.35, h: bodyH }
59
75
  : { x: 8.33, y: bodyTop, w: 4.35, h: bodyH }
@@ -91,7 +107,7 @@ export function mediaBoxes(layout, variantInput, slide = {}) {
91
107
  image: { ...imageTarget, h: +(bodyH - 0.14).toFixed(3) },
92
108
  gallery,
93
109
  body: layout === 'image-left' ? right : layout === 'image-right' ? left : null,
94
- chart: { ...full, h: +(bodyH - 0.12).toFixed(3) },
110
+ chart: { ...full, y: +(full.y + annotReserve).toFixed(3), h: +(bodyH - 0.12 - annotReserve).toFixed(3) },
95
111
  caption: captionBox,
96
112
  takeaway,
97
113
  }
@@ -201,12 +217,33 @@ export function normalizeChart(input, page = 1) {
201
217
  const totalIndices = Array.isArray(input.totalIndices)
202
218
  ? input.totalIndices.filter(n => Number.isInteger(n) && n >= 0 && n < categories.length)
203
219
  : undefined
220
+ const rawRef = input.referenceLine && typeof input.referenceLine === 'object' ? input.referenceLine : null
221
+ const refVal = rawRef ? Number(rawRef.value) : NaN
222
+ const referenceLine = Number.isFinite(refVal)
223
+ ? {
224
+ value: refVal,
225
+ ...(rawRef.label ? { label: String(rawRef.label).trim() } : {}),
226
+ ...(rawRef.color ? { color: String(rawRef.color).trim() } : {}),
227
+ }
228
+ : undefined
229
+ const rawCallout = input.callout && typeof input.callout === 'object' ? input.callout : null
230
+ const callout = rawCallout && String(rawCallout.label ?? '').trim()
231
+ ? {
232
+ label: String(rawCallout.label).trim(),
233
+ ...(Number.isInteger(rawCallout.fromIndex) ? { fromIndex: rawCallout.fromIndex } : {}),
234
+ ...(Number.isInteger(rawCallout.toIndex) ? { toIndex: rawCallout.toIndex } : {}),
235
+ }
236
+ : undefined
204
237
 
205
238
  return {
206
239
  kind,
207
240
  categories: categories.map(c => String(c).trim()),
208
241
  series: clean,
209
242
  ...(highlight !== undefined ? { highlight } : {}),
243
+ ...(typeof input.spotlight === 'boolean' ? { spotlight: input.spotlight } : {}),
244
+ ...(typeof input.showGrowthCallout === 'boolean' ? { showGrowthCallout: input.showGrowthCallout } : {}),
245
+ ...(referenceLine ? { referenceLine } : {}),
246
+ ...(callout ? { callout } : {}),
210
247
  ...(typeof input.showValues === 'boolean' ? { showValues: input.showValues } : {}),
211
248
  ...(typeof input.showLegend === 'boolean' ? { showLegend: input.showLegend } : {}),
212
249
  ...(totalIndices?.length ? { totalIndices } : {}),
@@ -589,8 +626,11 @@ export function renderChartSvg(chart, theme) {
589
626
  else shapes += text(left + (i + 0.5) * (right - left) / n, bottom + 28, category, 'middle', fg, 15)
590
627
  })
591
628
 
629
+ const effectiveHighlight = chart.highlight !== undefined
630
+ ? chart.highlight
631
+ : (chart.spotlight === true ? 'max' : undefined)
592
632
  const singleHighlights = chart.series.length === 1 && (kind === 'column' || kind === 'bar')
593
- ? resolveHighlights(chart.series[0].values, chart.highlight)
633
+ ? resolveHighlights(chart.series[0].values, effectiveHighlight)
594
634
  : null
595
635
 
596
636
  if (isStacked || isPercent) {
@@ -652,7 +692,10 @@ export function renderChartSvg(chart, theme) {
652
692
  shapes += rect(bx, by, Math.max(3, w - 3), bh, color, 3)
653
693
  if (showDirectValues && barSeries.length <= 2) {
654
694
  if (kind === 'combo' && bh >= 24 && v >= 0) {
655
- shapes += text(bx + (w - 3) / 2, by + 18, fmtNum(v), 'middle', tokens.inkOnAccent || '#FFFFFF', 13, 700)
695
+ const secYAtI = lineSeries[0] ? (lineSeries[0].secondaryAxis ? ySec : y)(lineSeries[0].values[i]) : -999
696
+ const topLabelY = by + 18
697
+ const safeBarY = Math.abs(secYAtI - topLabelY) < 28 && bh >= 48 ? by + bh - 12 : topLabelY
698
+ shapes += text(bx + (w - 3) / 2, safeBarY, fmtNum(v), 'middle', tokens.inkOnAccent || '#FFFFFF', 13, 700)
656
699
  } else {
657
700
  shapes += text(bx + (w - 3) / 2, v >= 0 ? by - 8 : by + bh + 16, fmtNum(v), 'middle', isFocal ? fg : muted, 14, isFocal && singleHighlights ? 700 : 500)
658
701
  }
@@ -681,6 +724,53 @@ export function renderChartSvg(chart, theme) {
681
724
  })
682
725
  }
683
726
 
727
+ // 基准参考虚线(Target / Average Benchmark Reference Line)
728
+ if (chart.referenceLine && Number.isFinite(chart.referenceLine.value)) {
729
+ const rv = chart.referenceLine.value
730
+ const rCol = chart.referenceLine.color || tokens.accentSecondary || focalColor
731
+ const rLbl = chart.referenceLine.label || `Target ${fmtNum(rv)}`
732
+ if (isHoriz && rv >= min && rv <= max) {
733
+ const rx = x(rv)
734
+ shapes += `<line x1="${rx.toFixed(1)}" y1="${top}" x2="${rx.toFixed(1)}" y2="${bottom}" stroke="${rCol}" stroke-width="1.8" stroke-dasharray="6 4"/>`
735
+ shapes += rect(Math.min(right - 130, rx + 6), top + 4, Math.max(84, rLbl.length * 10 + 18), 22, bg, 11)
736
+ shapes += text(Math.min(right - 122, rx + 14), top + 19, rLbl, 'start', rCol, 12, 700)
737
+ } else if (!isHoriz && rv >= min && rv <= max) {
738
+ const ry = y(rv)
739
+ const pw = Math.min(220, Math.max(82, rLbl.length * 11 + 22))
740
+ shapes += `<line x1="${left}" y1="${ry.toFixed(1)}" x2="${right}" y2="${ry.toFixed(1)}" stroke="${rCol}" stroke-width="1.8" stroke-dasharray="6 4"/>`
741
+ shapes += `<rect x="${(right - pw).toFixed(1)}" y="${(ry - 24).toFixed(1)}" width="${pw.toFixed(1)}" height="20" rx="10" fill="${bg}" stroke="${rCol}" stroke-width="1"/>`
742
+ shapes += text(right - pw / 2, ry - 10, rLbl, 'middle', rCol, 12, 700)
743
+ }
744
+ }
745
+
746
+ // 麦肯锡增长飞线标注箭弧(CAGR / Growth Callout Arc)
747
+ if (!isHoriz && !isStacked && !isPercent && n >= 2 && (chart.callout?.label || chart.showGrowthCallout)) {
748
+ const vals = chart.series[0]?.values || []
749
+ const fromIdx = Number.isInteger(chart.callout?.fromIndex) ? Math.max(0, Math.min(n - 1, chart.callout.fromIndex)) : 0
750
+ const toIdx = Number.isInteger(chart.callout?.toIndex) ? Math.max(0, Math.min(n - 1, chart.callout.toIndex)) : n - 1
751
+ const v0 = vals[fromIdx]
752
+ const v1 = vals[toIdx]
753
+ let badgeLabel = chart.callout?.label || ''
754
+ if (!badgeLabel && Number.isFinite(v0) && Number.isFinite(v1) && Math.abs(v0) > 1e-9 && fromIdx !== toIdx) {
755
+ const pct = ((v1 - v0) / Math.abs(v0)) * 100
756
+ badgeLabel = (pct >= 0 ? '+' : '') + pct.toFixed(1) + '%'
757
+ }
758
+ if (badgeLabel && fromIdx !== toIdx) {
759
+ const x0 = left + (fromIdx + 0.5) * (right - left) / n
760
+ const x1 = left + (toIdx + 0.5) * (right - left) / n
761
+ const y0 = Math.max(top + 24, y(v0) - 24)
762
+ const y1 = Math.max(top + 24, y(v1) - 24)
763
+ const yArc = Math.max(top + 4, Math.min(y0, y1) - 22)
764
+ const midX = (x0 + x1) / 2
765
+ const cCol = v1 >= v0 ? posColor : negColor
766
+ const pw = Math.min(180, Math.max(76, badgeLabel.length * 10 + 24))
767
+ shapes += `<path d="M ${x0.toFixed(1)} ${y0.toFixed(1)} L ${x0.toFixed(1)} ${yArc.toFixed(1)} L ${x1.toFixed(1)} ${yArc.toFixed(1)} L ${x1.toFixed(1)} ${y1.toFixed(1)}" fill="none" stroke="${cCol}" stroke-width="1.8"/>`
768
+ shapes += `<polygon points="${(x1 - 5).toFixed(1)},${(y1 - 7).toFixed(1)} ${(x1 + 5).toFixed(1)},${(y1 - 7).toFixed(1)} ${x1.toFixed(1)},${(y1 + 1).toFixed(1)}" fill="${cCol}"/>`
769
+ shapes += `<rect x="${(midX - pw / 2).toFixed(1)}" y="${(yArc - 11).toFixed(1)}" width="${pw.toFixed(1)}" height="22" rx="11" fill="${bg}" stroke="${cCol}" stroke-width="1.2"/>`
770
+ shapes += text(midX, yArc + 4, badgeLabel, 'middle', cCol, 12.5, 700)
771
+ }
772
+ }
773
+
684
774
  shapes += isHoriz ? line(x(0), top, x(0), bottom, axisColor, 1.5) : line(left, y(0), right, y(0), axisColor, 1.5)
685
775
  }
686
776
 
@@ -737,7 +827,7 @@ function projectInsightCards(slide) {
737
827
  }
738
828
 
739
829
  export function renderMediaHtml(slide, manifest, theme) {
740
- const boxes = mediaBoxes(slide.layout, slide.variant, slide)
830
+ const boxes = mediaBoxes(slide.layout, slide.variant, slide, manifest)
741
831
  const variant = String(slide.variant ?? '').trim().toLowerCase()
742
832
  const chromeStyle = resolveChromeStyle(theme, slide, manifest?.brand)
743
833
  const slidesArr = Array.isArray(manifest?.slides) ? manifest.slides : []
@@ -783,7 +873,13 @@ export function renderMediaHtml(slide, manifest, theme) {
783
873
  }
784
874
 
785
875
  if (slide.layout === 'chart' || slide.layout === 'chart-split') {
786
- body += `<div class="media-chart" style="${position(boxes.chart)}">${renderChartSvg(slide.chart, theme)}</div>`
876
+ const taste = resolveActiveTaste(manifest, slide)
877
+ const chartWithTaste = {
878
+ ...slide.chart,
879
+ ...(slide.chart?.highlight === undefined && slide.chart?.spotlight === undefined && taste.chartSpotlight ? { spotlight: true } : {}),
880
+ ...(slide.chart?.showGrowthCallout === undefined && !slide.chart?.callout && taste.chartGrowthCallout ? { showGrowthCallout: true } : {}),
881
+ }
882
+ body += `<div class="media-chart" style="${position(boxes.chart)}">${renderChartSvg(chartWithTaste, theme)}</div>`
787
883
  if (slide.layout === 'chart-split' && boxes.body) {
788
884
  const cards = projectInsightCards(slide)
789
885
  const cardsHtml = cards.map((card, idx) =>
@@ -955,16 +1051,17 @@ export function buildOfficeKitChartSpec(chart, theme, visual = {}, font = 'Micro
955
1051
  : 'clustered'
956
1052
 
957
1053
  let highlightSet = null
958
- if (chart.series.length === 1 && (kind === 'column' || kind === 'bar') && chart.highlight !== undefined && chart.highlight !== 'none') {
1054
+ const effHighlight = chart.highlight !== undefined ? chart.highlight : (chart.spotlight === true ? 'max' : undefined)
1055
+ if (chart.series.length === 1 && (kind === 'column' || kind === 'bar') && effHighlight !== undefined && effHighlight !== 'none') {
959
1056
  const vals = chart.series[0].values
960
- if (typeof chart.highlight === 'number') highlightSet = new Set([chart.highlight])
961
- else if (Array.isArray(chart.highlight)) highlightSet = new Set(chart.highlight)
962
- else if (chart.highlight === 'last') highlightSet = new Set([vals.length - 1])
963
- else if (chart.highlight === 'max') {
1057
+ if (typeof effHighlight === 'number') highlightSet = new Set([effHighlight])
1058
+ else if (Array.isArray(effHighlight)) highlightSet = new Set(effHighlight)
1059
+ else if (effHighlight === 'last') highlightSet = new Set([vals.length - 1])
1060
+ else if (effHighlight === 'max') {
964
1061
  let best = 0
965
1062
  for (let i = 1; i < vals.length; i++) if (vals[i] > vals[best]) best = i
966
1063
  highlightSet = new Set([best])
967
- } else if (chart.highlight === 'min') {
1064
+ } else if (effHighlight === 'min') {
968
1065
  let best = 0
969
1066
  for (let i = 1; i < vals.length; i++) if (vals[i] < vals[best]) best = i
970
1067
  highlightSet = new Set([best])
@@ -1124,7 +1221,7 @@ export function renderMediaPptxShapes(slide, index, theme, langId = 'zh-CN', fon
1124
1221
 
1125
1222
  const toEmu = v => Math.round(v * 914400)
1126
1223
  const boxEmu = b => ({ x: toEmu(b.x), y: toEmu(b.y), w: toEmu(b.w), h: toEmu(b.h) })
1127
- const boxes = mediaBoxes(slide.layout, slide.variant, slide)
1224
+ const boxes = mediaBoxes(slide.layout, slide.variant, slide, manifest)
1128
1225
  const variant = String(slide.variant ?? '').trim().toLowerCase()
1129
1226
  const isBleed = variant === 'full-bleed' || variant === 'split-bleed'
1130
1227
  let nextId = (index + 1) * 100 + 2
@@ -1351,6 +1448,53 @@ export function renderMediaPptxShapes(slide, index, theme, langId = 'zh-CN', fon
1351
1448
  }
1352
1449
  }
1353
1450
 
1451
+ // 原生图表顶部精修标注徽章(麦肯锡增长飞线结论 / 基准参考线提示,避免遮挡柱体,原生可编辑)
1452
+ if ((slide.layout === 'chart' || slide.layout === 'chart-split') && slide.chart && slide.chart.kind !== 'waterfall') {
1453
+ const taste = resolveActiveTaste(manifest, slide)
1454
+ const chartObj = slide.chart
1455
+ const badges = []
1456
+ if (chartObj.callout?.label || chartObj.showGrowthCallout || taste.chartGrowthCallout) {
1457
+ const vals = chartObj.series?.[0]?.values || []
1458
+ const fromIdx = Number.isInteger(chartObj.callout?.fromIndex) ? Math.max(0, Math.min(vals.length - 1, chartObj.callout.fromIndex)) : 0
1459
+ const toIdx = Number.isInteger(chartObj.callout?.toIndex) ? Math.max(0, Math.min(vals.length - 1, chartObj.callout.toIndex)) : vals.length - 1
1460
+ let gText = chartObj.callout?.label || ''
1461
+ let isPos = true
1462
+ if (vals.length >= 2 && fromIdx !== toIdx) {
1463
+ const v0 = vals[fromIdx]
1464
+ const v1 = vals[toIdx]
1465
+ isPos = v1 >= v0
1466
+ if (!gText && Math.abs(v0) > 1e-9 && ['column', 'bar', 'line', 'area', 'combo'].includes(chartObj.kind)) {
1467
+ const pct = ((v1 - v0) / Math.abs(v0)) * 100
1468
+ gText = `${chartObj.categories[fromIdx]}→${chartObj.categories[toIdx]} ${pct >= 0 ? '+' : ''}${pct.toFixed(1)}%`
1469
+ }
1470
+ }
1471
+ if (gText) badges.push({ text: gText, color: isPos ? posColor : negColor })
1472
+ }
1473
+ if (chartObj.referenceLine && Number.isFinite(chartObj.referenceLine.value)) {
1474
+ const rLbl = chartObj.referenceLine.label || `${isEn ? 'Target' : '基准线'} ${chartObj.referenceLine.value}`
1475
+ badges.push({ text: '┄ ' + rLbl, color: chartObj.referenceLine.color || accent2 })
1476
+ }
1477
+ if (badges.length > 0 && boxes.chart) {
1478
+ let curRight = boxes.chart.x + boxes.chart.w
1479
+ const badgeY = Math.max(1.66, boxes.chart.y - 0.35)
1480
+ badges.forEach((b, bi) => {
1481
+ const bw = computeBadgePillWidth(b.text, 10.5, 3.6, 1.15)
1482
+ curRight -= bw
1483
+ if (curRight >= boxes.chart.x + 0.4) {
1484
+ shapes.push(spText('Chart Annotation ' + (bi + 1), { x: curRight, y: badgeY, w: bw, h: 0.28 }, [paraRich(b.text, { size: 1050, color: b.color, bold: true, align: 'ctr' })], {
1485
+ anchor: 'ctr',
1486
+ fill: t.canvas || p.bg || '#FFFFFF',
1487
+ stroke: b.color,
1488
+ strokeW: 9525,
1489
+ roundAdj: 50000,
1490
+ ins: [45720, 9144, 45720, 9144],
1491
+ }))
1492
+ curRight -= 0.12
1493
+ }
1494
+ })
1495
+ }
1496
+ }
1497
+
1354
1498
  // Caption + Chrome-aware Takeaway coexistence
1355
1499
  const caption = slide.chart?.caption || slide.image?.caption
1356
1500
  if (caption) {
@@ -0,0 +1,347 @@
1
+ /**
2
+ * deck-taste.mjs —— dsh-ppt 大师审美配方系统(Curated Taste Recipes)与标杆 PPTX 品味学习库。
3
+ *
4
+ * 将世界顶级演示流派(麦肯锡合伙人精修、Apple Keynote 暗夜/纯白、瑞士杂志 Monocle、
5
+ * Linear 玻璃工艺、Financial Times 财经研报、Nature 学术顶会、东方宋韵极简)
6
+ * 抽象为结构化、可组合、可由外部真实优质 .pptx 反向吸收并持久化的 Taste Recipe。
7
+ *
8
+ * 零外部运行时依赖,仅使用 Node 内置模块。
9
+ */
10
+
11
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'
12
+ import { dirname, join, resolve } from 'node:path'
13
+
14
+ export const CARD_MATERIALS = Object.freeze(['solid', 'frameless', 'glass', 'editorial-rule'])
15
+ export const COVER_VARIANTS = Object.freeze([
16
+ 'default',
17
+ 'inverted',
18
+ 'monolith',
19
+ 'keynote-glow',
20
+ 'editorial-grid',
21
+ 'architectural',
22
+ 'split-bleed',
23
+ ])
24
+ export const ICON_MODES = Object.freeze(['off', 'explicit', 'auto'])
25
+
26
+ /**
27
+ * 8 套向世界顶级演示流派致敬的精选审美配方(Taste Recipes)。
28
+ * 每份配方同时驱动:主题基调、母版骨架、卡片材质、封面/章节/指标/卡片变体、图标语言、图表聚光灯与增长标注。
29
+ */
30
+ export const CURATED_TASTE_RECIPES = Object.freeze({
31
+ 'mckinsey-partner': Object.freeze({
32
+ id: 'mckinsey-partner',
33
+ name: '麦肯锡合伙人精修',
34
+ enName: 'McKinsey Partner',
35
+ school: 'consulting',
36
+ description: '高白度极克制版面、顶部细线无框指标、议程进度章节页、聚光灯单色图表与 CAGR 增长飞线',
37
+ enDescription: 'Crisp executive daylight, frameless hairline metrics, live agenda chapters, spotlight charts & growth callouts',
38
+ theme: 'consulting',
39
+ chromeStyle: 'consulting-classic',
40
+ tableStyle: 'consulting',
41
+ cardMaterial: 'frameless',
42
+ coverVariant: 'architectural',
43
+ sectionVariant: 'agenda',
44
+ kpiVariant: 'spotlight',
45
+ cardsVariant: 'frameless',
46
+ iconMode: 'explicit',
47
+ iconBadgeStyle: 'ring',
48
+ chartSpotlight: true,
49
+ chartGrowthCallout: true,
50
+ density: 'balanced',
51
+ typeScaleRatio: 1.75,
52
+ swatches: ['#FFFFFF', '#003A70', '#0E7490', '#CBD5E1'],
53
+ }),
54
+ 'apple-keynote-dark': Object.freeze({
55
+ id: 'apple-keynote-dark',
56
+ name: 'Apple 发布会暗夜',
57
+ enName: 'Apple Keynote Dark',
58
+ school: 'keynote',
59
+ description: '深邃双色径向光晕封面、半透明玻璃拟态卡片、超大字号无框指标、非对称 Bento 主次排版与线性图标',
60
+ enDescription: 'Luminous dark gradient glow cover, translucent glass cards, monumental frameless KPIs & asymmetric bento',
61
+ theme: 'aurora-stage',
62
+ chromeStyle: 'keynote-spatial',
63
+ tableStyle: 'minimal',
64
+ cardMaterial: 'glass',
65
+ coverVariant: 'keynote-glow',
66
+ sectionVariant: 'agenda',
67
+ kpiVariant: 'frameless',
68
+ cardsVariant: 'bento-hero',
69
+ iconMode: 'auto',
70
+ iconBadgeStyle: 'soft',
71
+ chartSpotlight: true,
72
+ chartGrowthCallout: true,
73
+ density: 'airy',
74
+ typeScaleRatio: 2.35,
75
+ swatches: ['#070B14', '#2DD4BF', '#818CF8', '#192338'],
76
+ }),
77
+ 'apple-keynote-light': Object.freeze({
78
+ id: 'apple-keynote-light',
79
+ name: 'Apple 极简纯白',
80
+ enName: 'Apple Keynote Light',
81
+ school: 'keynote',
82
+ description: '高透气纯白画布、柔光氛围封面、超大视觉重心指标与非对称 Bento 视觉节奏',
83
+ enDescription: 'Alabaster daylight canvas, soft aura cover, spotlight KPI hero & airy bento rhythm',
84
+ theme: 'keynote-light',
85
+ chromeStyle: 'keynote-spatial',
86
+ tableStyle: 'minimal',
87
+ cardMaterial: 'frameless',
88
+ coverVariant: 'keynote-glow',
89
+ sectionVariant: 'agenda',
90
+ kpiVariant: 'spotlight',
91
+ cardsVariant: 'bento-hero',
92
+ iconMode: 'auto',
93
+ iconBadgeStyle: 'soft',
94
+ chartSpotlight: true,
95
+ chartGrowthCallout: true,
96
+ density: 'airy',
97
+ typeScaleRatio: 2.3,
98
+ swatches: ['#FBFBFD', '#0071E3', '#1D1D1F', '#E5E7EB'],
99
+ }),
100
+ 'swiss-editorial': Object.freeze({
101
+ id: 'swiss-editorial',
102
+ name: '瑞士杂志 · Monocle',
103
+ enName: 'Swiss Editorial',
104
+ school: 'editorial',
105
+ description: '暖米纸张底色、0.5pt 瑞士网格发丝封面、大号衬线序数与双线出版物分栏',
106
+ enDescription: 'Warm archival paper, 0.5pt Swiss hairline grid cover, monumental folio numerals & editorial rules',
107
+ theme: 'economist-brief',
108
+ chromeStyle: 'editorial-folio',
109
+ tableStyle: 'minimal',
110
+ cardMaterial: 'editorial-rule',
111
+ coverVariant: 'editorial-grid',
112
+ sectionVariant: 'agenda',
113
+ kpiVariant: 'spotlight',
114
+ cardsVariant: 'frameless',
115
+ iconMode: 'explicit',
116
+ iconBadgeStyle: 'bare',
117
+ chartSpotlight: true,
118
+ chartGrowthCallout: false,
119
+ density: 'airy',
120
+ typeScaleRatio: 2.1,
121
+ swatches: ['#F9F8F5', '#C8102E', '#141413', '#CFC8BA'],
122
+ }),
123
+ 'linear-craft': Object.freeze({
124
+ id: 'linear-craft',
125
+ name: 'Linear 玻璃工艺',
126
+ enName: 'Linear Craft',
127
+ school: 'tech',
128
+ description: '碳黑高质感暗底、电光紫/青双色微光、精细 1px 玻璃高光卡片、自动语义线性矢量图标',
129
+ enDescription: 'Precision carbon dark canvas, indigo-cyan ambient glow, crisp hairline glass cards & semantic line icons',
130
+ theme: 'linear-dark',
131
+ chromeStyle: 'saas-bento',
132
+ tableStyle: 'minimal',
133
+ cardMaterial: 'glass',
134
+ coverVariant: 'keynote-glow',
135
+ sectionVariant: 'agenda',
136
+ kpiVariant: 'spotlight',
137
+ cardsVariant: 'bento-hero',
138
+ iconMode: 'auto',
139
+ iconBadgeStyle: 'ring',
140
+ chartSpotlight: true,
141
+ chartGrowthCallout: true,
142
+ density: 'balanced',
143
+ typeScaleRatio: 2.0,
144
+ swatches: ['#0B0D14', '#7C6DF0', '#22D3EE', '#1E2436'],
145
+ }),
146
+ 'ft-data-journal': Object.freeze({
147
+ id: 'ft-data-journal',
148
+ name: 'Financial Times 研报',
149
+ enName: 'FT Data Journal',
150
+ school: 'finance',
151
+ description: '经典三文鱼粉纸底、酒红+青黛双色数据叙事、瑞士报刊网格封面与聚光灯增长标注',
152
+ enDescription: 'Iconic salmon paper backdrop, claret & teal financial storytelling, grid cover & spotlight growth charts',
153
+ theme: 'financial-ft',
154
+ chromeStyle: 'editorial-folio',
155
+ tableStyle: 'minimal',
156
+ cardMaterial: 'editorial-rule',
157
+ coverVariant: 'editorial-grid',
158
+ sectionVariant: 'agenda',
159
+ kpiVariant: 'spotlight',
160
+ cardsVariant: 'frameless',
161
+ iconMode: 'explicit',
162
+ iconBadgeStyle: 'bare',
163
+ chartSpotlight: true,
164
+ chartGrowthCallout: true,
165
+ density: 'balanced',
166
+ typeScaleRatio: 1.85,
167
+ swatches: ['#FFF1E5', '#990F3D', '#0D7680', '#1A1816'],
168
+ }),
169
+ 'nature-academic': Object.freeze({
170
+ id: 'nature-academic',
171
+ name: 'Nature / NeurIPS 学术',
172
+ enName: 'Nature Academic',
173
+ school: 'academic',
174
+ description: 'Beamer 学术顶底导航条、标准三线表、高对比无干扰细线结构与章节进度条',
175
+ enDescription: 'Beamer top-bottom running headers, booktabs three-line tables, clean hairline hierarchy & chapter tracker',
176
+ theme: 'academic',
177
+ chromeStyle: 'academic-minimal',
178
+ tableStyle: 'booktabs',
179
+ cardMaterial: 'editorial-rule',
180
+ coverVariant: 'editorial-grid',
181
+ sectionVariant: 'agenda',
182
+ kpiVariant: 'frameless',
183
+ cardsVariant: 'frameless',
184
+ iconMode: 'explicit',
185
+ iconBadgeStyle: 'bare',
186
+ chartSpotlight: true,
187
+ chartGrowthCallout: false,
188
+ density: 'balanced',
189
+ typeScaleRatio: 1.65,
190
+ swatches: ['#FFFFFF', '#0F5257', '#1E293B', '#E2E8F0'],
191
+ }),
192
+ 'oriental-zen': Object.freeze({
193
+ id: 'oriental-zen',
194
+ name: '东方极简 · 宋韵',
195
+ enName: 'Oriental Zen',
196
+ school: 'editorial',
197
+ description: '宣纸暖白留白、朱砂印红与天青黛墨点缀、建筑感不对称封面与大留白无框章节',
198
+ enDescription: 'Xuan paper whitespace, cinnabar & celadon accents, architectural asymmetric cover & serene frameless typography',
199
+ theme: 'exec-palace',
200
+ chromeStyle: 'editorial-folio',
201
+ tableStyle: 'minimal',
202
+ cardMaterial: 'frameless',
203
+ coverVariant: 'architectural',
204
+ sectionVariant: 'agenda',
205
+ kpiVariant: 'spotlight',
206
+ cardsVariant: 'frameless',
207
+ iconMode: 'explicit',
208
+ iconBadgeStyle: 'bare',
209
+ chartSpotlight: true,
210
+ chartGrowthCallout: false,
211
+ density: 'airy',
212
+ typeScaleRatio: 2.05,
213
+ swatches: ['#F9F6F0', '#9E2A2B', '#3D6B5E', '#1C1917'],
214
+ }),
215
+ })
216
+
217
+ export const TASTE_RECIPE_IDS = Object.freeze(Object.keys(CURATED_TASTE_RECIPES))
218
+
219
+ export function listCuratedTasteRecipes() {
220
+ return TASTE_RECIPE_IDS.map((id) => ({ ...CURATED_TASTE_RECIPES[id] }))
221
+ }
222
+
223
+ /**
224
+ * 规范化任意品味配方输入(内置 ID 字符串 或 外部吸收的自定义 StyleRecipe 对象)。
225
+ */
226
+ export function resolveTasteRecipe(input, customRegistry = null) {
227
+ if (!input) return null
228
+ if (typeof input === 'string') {
229
+ const key = input.trim().toLowerCase()
230
+ if (!key) return null
231
+ if (CURATED_TASTE_RECIPES[key]) return { ...CURATED_TASTE_RECIPES[key] }
232
+ if (customRegistry && customRegistry[key]) return sanitizeCustomTasteRecipe(customRegistry[key])
233
+ return null
234
+ }
235
+ if (typeof input === 'object' && !Array.isArray(input)) {
236
+ const base = typeof input.extends === 'string' && CURATED_TASTE_RECIPES[input.extends]
237
+ ? CURATED_TASTE_RECIPES[input.extends]
238
+ : typeof input.id === 'string' && CURATED_TASTE_RECIPES[input.id]
239
+ ? CURATED_TASTE_RECIPES[input.id]
240
+ : null
241
+ return sanitizeCustomTasteRecipe(base ? { ...base, ...input } : input)
242
+ }
243
+ return null
244
+ }
245
+
246
+ export function sanitizeCustomTasteRecipe(raw) {
247
+ if (!raw || typeof raw !== 'object') return null
248
+ const cardMaterial = CARD_MATERIALS.includes(raw.cardMaterial) ? raw.cardMaterial : 'solid'
249
+ const coverVariant = COVER_VARIANTS.includes(raw.coverVariant) ? raw.coverVariant : 'default'
250
+ const iconMode = ICON_MODES.includes(raw.iconMode) ? raw.iconMode : 'explicit'
251
+ const iconBadgeStyle = ['soft', 'ring', 'bare', 'solid'].includes(raw.iconBadgeStyle) ? raw.iconBadgeStyle : 'soft'
252
+ return {
253
+ id: String(raw.id || 'absorbed-custom').trim().slice(0, 64),
254
+ name: String(raw.name || raw.id || '自定义标杆品味').trim().slice(0, 80),
255
+ enName: String(raw.enName || raw.name || raw.id || 'Custom Taste Recipe').trim().slice(0, 80),
256
+ school: String(raw.school || 'custom').trim(),
257
+ description: String(raw.description || '').trim(),
258
+ enDescription: String(raw.enDescription || raw.description || '').trim(),
259
+ ...(raw.theme ? { theme: String(raw.theme).trim() } : {}),
260
+ ...(raw.chromeStyle ? { chromeStyle: String(raw.chromeStyle).trim() } : {}),
261
+ ...(raw.tableStyle ? { tableStyle: String(raw.tableStyle).trim() } : {}),
262
+ cardMaterial,
263
+ coverVariant,
264
+ sectionVariant: raw.sectionVariant === 'agenda' ? 'agenda' : 'default',
265
+ kpiVariant: ['spotlight', 'frameless', 'grid'].includes(raw.kpiVariant) ? raw.kpiVariant : 'grid',
266
+ cardsVariant: ['frameless', 'bento-hero', 'bento', 'pillars'].includes(raw.cardsVariant) ? raw.cardsVariant : 'pillars',
267
+ iconMode,
268
+ iconBadgeStyle,
269
+ chartSpotlight: raw.chartSpotlight === true,
270
+ chartGrowthCallout: raw.chartGrowthCallout === true,
271
+ density: ['airy', 'balanced', 'compact'].includes(raw.density) ? raw.density : 'balanced',
272
+ typeScaleRatio: Number.isFinite(Number(raw.typeScaleRatio)) ? Number(Number(raw.typeScaleRatio).toFixed(2)) : 1.8,
273
+ ...(Number.isFinite(Number(raw.whitespaceRatio)) ? { whitespaceRatio: Number(Number(raw.whitespaceRatio).toFixed(2)) } : {}),
274
+ ...(Number.isFinite(Number(raw.rhythmScore)) ? { rhythmScore: Math.round(Number(raw.rhythmScore)) } : {}),
275
+ ...(raw.brand && typeof raw.brand === 'object' ? { brand: { ...raw.brand } } : {}),
276
+ ...(Array.isArray(raw.swatches) ? { swatches: raw.swatches.slice(0, 4).map(String) } : {}),
277
+ ...(raw.sourceFile ? { sourceFile: String(raw.sourceFile) } : {}),
278
+ ...(raw.absorbedAt ? { absorbedAt: String(raw.absorbedAt) } : {}),
279
+ }
280
+ }
281
+
282
+ /**
283
+ * 读取工作区持久化的用户品味配方库(.dsh-ppt/taste-recipes.json)。
284
+ */
285
+ export function loadWorkspaceTasteRecipes(cwd = process.cwd()) {
286
+ const storePath = resolve(cwd, '.dsh-ppt', 'taste-recipes.json')
287
+ if (!existsSync(storePath)) return {}
288
+ try {
289
+ const parsed = JSON.parse(readFileSync(storePath, 'utf8'))
290
+ const rawMap = parsed && typeof parsed === 'object' && !Array.isArray(parsed)
291
+ ? (parsed.recipes && typeof parsed.recipes === 'object' ? parsed.recipes : parsed)
292
+ : {}
293
+ const out = {}
294
+ for (const [k, v] of Object.entries(rawMap)) {
295
+ const clean = sanitizeCustomTasteRecipe({ id: k, ...v })
296
+ if (clean) out[clean.id.toLowerCase()] = clean
297
+ }
298
+ return out
299
+ } catch {
300
+ return {}
301
+ }
302
+ }
303
+
304
+ /**
305
+ * 将从优质 .pptx 吸收提炼的品味配方持久化到工作区(.dsh-ppt/taste-recipes.json),供后续所有新稿一键复用。
306
+ */
307
+ export function saveWorkspaceTasteRecipe(recipe, cwd = process.cwd()) {
308
+ const clean = sanitizeCustomTasteRecipe(recipe)
309
+ if (!clean) throw new Error('dsh-ppt:无效的品味配方对象')
310
+ const storePath = resolve(cwd, '.dsh-ppt', 'taste-recipes.json')
311
+ const existing = loadWorkspaceTasteRecipes(cwd)
312
+ existing[clean.id.toLowerCase()] = {
313
+ ...clean,
314
+ absorbedAt: clean.absorbedAt || new Date().toISOString(),
315
+ }
316
+ mkdirSync(dirname(storePath), { recursive: true })
317
+ writeFileSync(storePath, JSON.stringify({ version: 1, recipes: existing }, null, 2) + '\n', 'utf8')
318
+ return { path: storePath, recipe: existing[clean.id.toLowerCase()], totalSaved: Object.keys(existing).length }
319
+ }
320
+
321
+ /**
322
+ * 从 manifest / brand / slide 中解析当前页有效的审美材质与品味配置。
323
+ */
324
+ export function resolveActiveTaste(manifest = {}, slide = null) {
325
+ const raw = manifest?.taste ?? manifest?.brand?.tasteRecipe ?? manifest?.brand?.taste ?? null
326
+ const recipe = resolveTasteRecipe(raw)
327
+ const cardMaterial = slide?.cardMaterial || manifest?.brand?.cardMaterial || recipe?.cardMaterial || 'solid'
328
+ const iconMode = slide?.iconMode || manifest?.brand?.iconMode || recipe?.iconMode || 'explicit'
329
+ const iconBadgeStyle = slide?.iconBadgeStyle || recipe?.iconBadgeStyle || (cardMaterial === 'frameless' ? 'bare' : cardMaterial === 'glass' ? 'ring' : 'soft')
330
+ return {
331
+ recipe,
332
+ cardMaterial: CARD_MATERIALS.includes(cardMaterial) ? cardMaterial : 'solid',
333
+ iconMode: ICON_MODES.includes(iconMode) ? iconMode : 'explicit',
334
+ iconBadgeStyle,
335
+ chartSpotlight: slide?.chart?.spotlight ?? recipe?.chartSpotlight ?? false,
336
+ chartGrowthCallout: slide?.chart?.showGrowthCallout ?? recipe?.chartGrowthCallout ?? false,
337
+ }
338
+ }
339
+
340
+ /**
341
+ * 列出所有可用品味配方(内置 8 套 + 工作区已吸收的标杆配方)。
342
+ */
343
+ export function listAllTasteRecipes(cwd = process.cwd()) {
344
+ const curated = listCuratedTasteRecipes().map((r) => ({ ...r, builtin: true }))
345
+ const saved = Object.values(loadWorkspaceTasteRecipes(cwd)).map((r) => ({ ...r, builtin: false }))
346
+ return [...curated, ...saved]
347
+ }