dsh-ppt 0.21.1 → 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/README.en.md +37 -23
  3. package/README.md +37 -22
  4. package/docs/COACHING.md +14 -13
  5. package/docs/DATA.md +8 -8
  6. package/docs/REFERENCE.en.md +17 -19
  7. package/docs/REFERENCE.zh.md +16 -18
  8. package/docs/USAGE.en.md +107 -60
  9. package/docs/USAGE.md +115 -84
  10. package/docs/VALIDATION.md +2 -0
  11. package/docs/VISUAL.md +27 -20
  12. package/docs/WORKBENCH.md +17 -6
  13. package/docs/assets/intro/screen-en.webp +0 -0
  14. package/docs/assets/intro/screen-zh.webp +0 -0
  15. package/lib/client.js +1286 -52
  16. package/lib/coaching.d.ts +1 -1
  17. package/lib/coaching.js +25 -12
  18. package/lib/config.d.ts +2 -0
  19. package/lib/config.js +36 -2
  20. package/lib/execution.d.ts +2 -1
  21. package/lib/execution.js +21 -1
  22. package/lib/tools.d.ts +1 -1
  23. package/lib/tools.js +160 -25
  24. package/lib/types.d.ts +115 -8
  25. package/lib/visual.d.ts +3 -1
  26. package/lib/visual.js +40 -13
  27. package/lib/workbench-language.js +49 -9
  28. package/lib/workbench.d.ts +5 -0
  29. package/lib/workbench.js +603 -12
  30. package/package.json +8 -3
  31. package/skills/dsh-ppt/SKILL.md +56 -54
  32. package/skills/dsh-ppt/package.json +17 -5
  33. package/skills/dsh-ppt/references/advanced.md +123 -41
  34. package/skills/dsh-ppt/references/copywriting.md +63 -41
  35. package/skills/dsh-ppt/references/data.md +83 -36
  36. package/skills/dsh-ppt/references/syntax.md +157 -28
  37. package/skills/dsh-ppt/references/themes.md +113 -58
  38. package/skills/dsh-ppt/references/troubleshooting.md +21 -16
  39. package/skills/dsh-ppt/scripts/build-deck.mjs +67 -28
  40. package/skills/dsh-ppt/scripts/deck-absorb.mjs +1338 -0
  41. package/skills/dsh-ppt/scripts/deck-advanced.mjs +422 -105
  42. package/skills/dsh-ppt/scripts/deck-core.mjs +572 -717
  43. package/skills/dsh-ppt/scripts/deck-data-view.mjs +30 -11
  44. package/skills/dsh-ppt/scripts/deck-data.mjs +35 -5
  45. package/skills/dsh-ppt/scripts/deck-director.mjs +2057 -0
  46. package/skills/dsh-ppt/scripts/deck-layouts.mjs +4673 -0
  47. package/skills/dsh-ppt/scripts/deck-media.mjs +1408 -86
  48. package/skills/dsh-ppt/scripts/deck-themes.mjs +1854 -0
  49. package/skills/dsh-ppt/scripts/deck-visual.mjs +133 -31
@@ -1,14 +1,38 @@
1
- // Deliberately small formatting vocabulary. Model output never contains text edits.
1
+ // Deliberately small, content-preserving formatting & layout vocabulary.
2
+ // Model output never rewrites text, metrics, or file paths.
2
3
  import { randomUUID } from 'node:crypto'
3
4
 
5
+ const NUMERIC_RANGES = {
6
+ titleSize: [24, 60],
7
+ bodySize: [14, 28],
8
+ chartLabelSize: [12, 24],
9
+ }
10
+
11
+ const STRING_ENUMS = {
12
+ density: ['compact', 'balanced', 'airy'],
13
+ tableStyle: ['consulting', 'booktabs', 'minimal', 'banded', 'harvey'],
14
+ }
15
+
4
16
  export function normalizeVisual(value) {
5
17
  if (value == null) return undefined
6
- if (typeof value !== 'object' || Array.isArray(value)) throw new Error('visual 需为字号设置对象 / Invalid visual settings')
7
- const ranges = { titleSize: [24, 60], bodySize: [16, 28], chartLabelSize: [14, 24] }, out = {}
8
- for (const [key, number] of Object.entries(value)) {
9
- const range = ranges[key]
10
- if (!range || !Number.isInteger(number) || number < range[0] || number > range[1]) throw new Error('visual 字号超出允许范围 / Invalid visual font size')
11
- out[key] = number
18
+ if (typeof value !== 'object' || Array.isArray(value)) throw new Error('visual 需为排版设置对象 / Invalid visual settings')
19
+ const out = {}
20
+ for (const [key, val] of Object.entries(value)) {
21
+ if (val === undefined) continue
22
+ if (Object.hasOwn(NUMERIC_RANGES, key)) {
23
+ const range = NUMERIC_RANGES[key]
24
+ if (!Number.isInteger(val) || val < range[0] || val > range[1]) {
25
+ throw new Error('visual 字号超出允许范围 / Invalid visual font size')
26
+ }
27
+ out[key] = val
28
+ } else if (Object.hasOwn(STRING_ENUMS, key)) {
29
+ if (typeof val !== 'string' || !STRING_ENUMS[key].includes(val)) {
30
+ throw new Error('visual 枚举值无效 / Invalid visual option')
31
+ }
32
+ out[key] = val
33
+ } else {
34
+ throw new Error('visual 包含不支持的字段 / Unsupported visual property')
35
+ }
12
36
  }
13
37
  return Object.keys(out).length ? out : undefined
14
38
  }
@@ -16,64 +40,142 @@ export function normalizeVisual(value) {
16
40
  export function visualHtmlStyle(value) {
17
41
  const v = normalizeVisual(value)
18
42
  if (!v) return ''
19
- return Object.entries(v).map(([key, n]) => '--ppt-' + key + ':' + n).join(';')
43
+ return Object.entries(v)
44
+ .filter(([key]) => Object.hasOwn(NUMERIC_RANGES, key))
45
+ .map(([key, n]) => '--ppt-' + key + ':' + n)
46
+ .join(';')
20
47
  }
21
48
 
22
49
  export const VISUAL_CSS = `
23
- .slide[style*="--ppt-titleSize"] h1,.slide[style*="--ppt-titleSize"] h2,.slide[style*="--ppt-titleSize"] .statement-title,.slide[style*="--ppt-titleSize"] .quote-text{font-size:clamp(24px,calc(var(--ppt-titleSize) * .12vw),calc(var(--ppt-titleSize) * 2px))}
50
+ .slide[style*="--ppt-titleSize"] h1,.slide[style*="--ppt-titleSize"] h2,.slide[style*="--ppt-titleSize"] .statement-title,.slide[style*="--ppt-titleSize"] .quote-text{font-size:clamp(22px,calc(var(--ppt-titleSize) * .115vw),calc(var(--ppt-titleSize) * 1.85px))}
24
51
  .slide[style*="--ppt-titleSize"] .media-title{font-size:calc(var(--ppt-titleSize) * .104167cqw)}
25
- .slide[style*="--ppt-bodySize"] li,.slide[style*="--ppt-bodySize"] .subtitle,.slide[style*="--ppt-bodySize"] .quote-attr{font-size:clamp(16px,calc(var(--ppt-bodySize) * .13vw),calc(var(--ppt-bodySize) * 2px))}
52
+ .slide[style*="--ppt-bodySize"] li,.slide[style*="--ppt-bodySize"] .subtitle,.slide[style*="--ppt-bodySize"] .quote-attr,.slide[style*="--ppt-bodySize"] .card-body{font-size:clamp(14px,calc(var(--ppt-bodySize) * .115vw),calc(var(--ppt-bodySize) * 1.65px))}
26
53
  .slide[style*="--ppt-bodySize"] .media-body,.slide[style*="--ppt-bodySize"] .media-body li{font-size:calc(var(--ppt-bodySize) * .104167cqw)}
27
- .slide[style*="--ppt-bodySize"] .deck-table{font-size:clamp(12px,calc(var(--ppt-bodySize) * .09vw),calc(var(--ppt-bodySize) * 1.35px))}
54
+ .slide[style*="--ppt-bodySize"] .deck-table{font-size:clamp(12px,calc(var(--ppt-bodySize) * .088vw),calc(var(--ppt-bodySize) * 1.3px))}
28
55
  .slide[style*="--ppt-chartLabelSize"] .native-chart text{font-size:calc(var(--ppt-chartLabelSize) * 1px)}
56
+ .slide[data-density="compact"] .layout-grid,.slide[data-density="compact"] .bullets ul{gap:12px}
57
+ .slide[data-density="airy"] .layout-grid,.slide[data-density="airy"] .bullets ul{gap:28px}
29
58
  `
30
59
 
31
60
  /** Apply formatting to the generator's known OOXML shapes, never arbitrary XML. */
32
61
  export function visualShapeXml(xml, visual) {
33
62
  const v = normalizeVisual(visual)
34
63
  if (!v) return xml
35
- return xml.replace(/<p:(sp|graphicFrame)>[\s\S]*?<\/p:\1>/g, shape => {
36
- const name = shape.match(/<p:cNvPr\b[^>]*\bname="([^"]*)"/)?.[1]
37
- const pt = ['Title', 'Statement', 'Quote'].includes(name) ? v.titleSize : ['Body', 'Subtitle', 'Attribution', 'Table'].includes(name) ? v.bodySize : undefined
64
+ return xml.replace(/<p:(sp|graphicFrame)>[\s\S]*?<\/p:\1>/g, (shape) => {
65
+ const name = shape.match(/<p:cNvPr\b[^>]*\bname="([^"]*)"/)?.[1] ?? ''
66
+ const isTitle = ['Title', 'Statement', 'Quote'].includes(name)
67
+ const isBody = ['Body', 'Subtitle', 'Attribution', 'Table'].includes(name) || /^(?:Card|Step|Comparison|Matrix|Callout|Gantt|Architecture|TAM|Org|Team|Flywheel)\s+\d+/i.test(name)
68
+ const pt = isTitle ? v.titleSize : isBody ? v.bodySize : undefined
38
69
  return pt ? shape.replace(/(<a:(?:rPr|defRPr|endParaRPr)\b[^>]*\bsz=")[0-9]+"/g, '$1' + (pt * 100) + '"') : shape
39
70
  })
40
71
  }
41
72
 
73
+ const SWITCHABLE_LAYOUTS = ['bullets', 'cards', 'comparison', 'process', 'kpi']
74
+
75
+ function canSwitchSlideLayout(slide, target) {
76
+ if (!SWITCHABLE_LAYOUTS.includes(target) || slide.layout === target) return false
77
+ if (slide.image || slide.images?.length || slide.chart || slide.rows?.length) return false
78
+ if (!SWITCHABLE_LAYOUTS.includes(slide.layout)) return false
79
+ const entries = Array.isArray(slide.items) && slide.items.length
80
+ ? slide.items.map((it) => [it.value, it.title, it.text, ...(it.bullets ?? [])].filter(Boolean).join(' '))
81
+ : Array.isArray(slide.bullets)
82
+ ? slide.bullets
83
+ : []
84
+ const n = entries.length
85
+ if (target === 'bullets') return n >= 1
86
+ if (target === 'cards') return n >= 2 && n <= 6
87
+ if (target === 'process') return n >= 3 && n <= 6
88
+ if (target === 'comparison') return n === 2 || n === 4
89
+ if (target === 'kpi') return n >= 2 && n <= 4 && entries.every((entry) => /\d/.test(String(entry)))
90
+ return false
91
+ }
92
+
42
93
  /** Facts, metrics, assets, titles and slide order are preserved by construction. */
43
94
  export function applyVisualActions(manifest, actions) {
44
- if (!Array.isArray(actions) || !actions.length || actions.length > 48) throw new Error('请选择有效的排版修改 / Invalid formatting actions')
45
- const next = structuredClone(manifest), seen = new Set()
95
+ if (!Array.isArray(actions) || !actions.length || actions.length > 64) {
96
+ throw new Error('请选择有效的排版修改 / Invalid formatting actions')
97
+ }
98
+ const next = structuredClone(manifest)
99
+ const seen = new Set()
46
100
  for (const a of actions) {
47
- if (!a || typeof a !== 'object' || Object.keys(a).some(k => !['slideId', 'type', 'value'].includes(k))) throw new Error('排版操作包含无效字段 / Invalid formatting action fields')
48
- const index = next.slides.findIndex(s => s.id === a.slideId), original = manifest.slides.find(s => s.id === a.slideId)
101
+ if (!a || typeof a !== 'object' || Object.keys(a).some((k) => !['slideId', 'type', 'value'].includes(k))) {
102
+ throw new Error('排版操作包含无效字段 / Invalid formatting action fields')
103
+ }
104
+ const index = next.slides.findIndex((s) => s.id === a.slideId)
105
+ const original = manifest.slides.find((s) => s.id === a.slideId)
49
106
  if (index < 0 || !original) throw new Error('排版操作关联的页面不存在 / Unknown slide')
50
107
  const key = a.slideId + ':' + (a.type?.startsWith('split-') ? 'split' : a.type)
51
108
  if (seen.has(key)) throw new Error('同一页的排版操作重复 / Duplicate formatting action')
52
109
  seen.add(key)
110
+
53
111
  const slide = next.slides[index]
54
- const field = { 'title-size': 'titleSize', 'body-size': 'bodySize', 'chart-label-size': 'chartLabelSize' }[a.type]
55
- if (field) {
56
- if (field === 'chartLabelSize' && !slide.chart) throw new Error('本页没有图表 / Slide has no chart')
57
- slide.visual = normalizeVisual({ ...slide.visual, [field]: a.value })
112
+ const sizeField = { 'title-size': 'titleSize', 'body-size': 'bodySize', 'chart-label-size': 'chartLabelSize' }[a.type]
113
+ if (sizeField) {
114
+ if (sizeField === 'chartLabelSize' && !slide.chart) throw new Error('本页没有图表 / Slide has no chart')
115
+ slide.visual = normalizeVisual({ ...slide.visual, [sizeField]: a.value })
58
116
  } else if (a.type === 'chart-horizontal') {
59
- if (a.value !== undefined || slide.chart?.kind !== 'column') throw new Error('只支持将柱状图改为横向条形图 / Only column-to-bar conversion is supported')
117
+ if (a.value !== undefined || slide.chart?.kind !== 'column') {
118
+ throw new Error('只支持将柱状图改为横向条形图 / Only column-to-bar conversion is supported')
119
+ }
60
120
  slide.chart.kind = 'bar'
61
121
  if (slide.dataTemplate?.chart) slide.dataTemplate.chart.kind = 'bar'
62
122
  } else if (a.type === 'image-contain') {
63
123
  if (a.value !== undefined || !slide.image) throw new Error('本页没有图片 / Slide has no image')
64
124
  slide.image.fit = 'contain'
125
+ } else if (a.type === 'density-mode') {
126
+ if (!['compact', 'balanced', 'airy'].includes(a.value)) throw new Error('密度模式无效 / Invalid density mode')
127
+ slide.visual = normalizeVisual({ ...slide.visual, density: a.value })
128
+ } else if (a.type === 'swap-image-side') {
129
+ if (a.value !== undefined || !['image-left', 'image-right'].includes(slide.layout)) {
130
+ throw new Error('仅左图右文或右图左文支持互换位置 / Only image-left/image-right can swap side')
131
+ }
132
+ slide.layout = slide.layout === 'image-left' ? 'image-right' : 'image-left'
133
+ } else if (a.type === 'switch-layout') {
134
+ if (typeof a.value !== 'string' || !canSwitchSlideLayout(slide, a.value)) {
135
+ throw new Error('当前页面条目不满足目标版式切换条件 / Slide cannot switch to target layout')
136
+ }
137
+ slide.layout = a.value
138
+ } else if (a.type === 'chart-highlight') {
139
+ if (!slide.chart || !['max', 'last', 'none'].includes(a.value)) {
140
+ throw new Error('图表高亮模式无效 / Invalid chart highlight mode')
141
+ }
142
+ if (a.value === 'none') {
143
+ delete slide.chart.highlight
144
+ if (slide.dataTemplate?.chart) delete slide.dataTemplate.chart.highlight
145
+ } else {
146
+ slide.chart.highlight = a.value
147
+ if (slide.dataTemplate?.chart) slide.dataTemplate.chart.highlight = a.value
148
+ }
149
+ } else if (a.type === 'table-style') {
150
+ if (!['table', 'harvey'].includes(slide.layout) || !['consulting', 'booktabs', 'minimal', 'banded', 'harvey'].includes(a.value)) {
151
+ throw new Error('表格样式仅适用于 table 版式 / Table style requires a table slide')
152
+ }
153
+ slide.tableStyle = a.value
65
154
  } else if (a.type === 'split-bullets' || a.type === 'split-table') {
66
- const bullets = a.type === 'split-bullets', field = bullets ? 'bullets' : 'rows'
67
- if (bullets ? !['bullets','image-left','image-right'].includes(slide.layout) : slide.layout !== 'table') throw new Error('此版式不支持所选拆页操作 / Split is not supported for this layout')
68
- const data = slide[field], count = bullets ? data?.length : data?.length - 1
69
- if (!Number.isInteger(a.value) || a.value < 1 || a.value >= count) throw new Error('拆页位置无效 / Invalid split position')
155
+ const bullets = a.type === 'split-bullets'
156
+ const field = bullets ? 'bullets' : 'rows'
157
+ if (bullets ? !['bullets', 'image-left', 'image-right'].includes(slide.layout) : slide.layout !== 'table') {
158
+ throw new Error('此版式不支持所选拆页操作 / Split is not supported for this layout')
159
+ }
160
+ const data = slide[field]
161
+ const count = bullets ? data?.length : data?.length - 1
162
+ if (!Number.isInteger(a.value) || a.value < 1 || a.value >= count) {
163
+ throw new Error('拆页位置无效 / Invalid split position')
164
+ }
70
165
  if (next.slides.length >= 120) throw new Error('拆页后超过 120 页 / Split would exceed 120 slides')
71
- const added = structuredClone(slide); added.id = randomUUID()
72
- const split = values => bullets ? [values.slice(0, a.value), values.slice(a.value)] : [values.slice(0, a.value + 1), [values[0], ...values.slice(a.value + 1)]]
166
+ const added = structuredClone(slide)
167
+ added.id = randomUUID()
168
+ const split = (values) => bullets
169
+ ? [values.slice(0, a.value), values.slice(a.value)]
170
+ : [values.slice(0, a.value + 1), [values[0], ...values.slice(a.value + 1)]]
73
171
  ;[slide[field], added[field]] = split(data)
74
- if (slide.dataTemplate?.[field]) [slide.dataTemplate[field], added.dataTemplate[field]] = split(slide.dataTemplate[field])
172
+ if (slide.dataTemplate?.[field]) {
173
+ ;[slide.dataTemplate[field], added.dataTemplate[field]] = split(slide.dataTemplate[field])
174
+ }
75
175
  next.slides.splice(index + 1, 0, added)
76
- } else throw new Error('不支持此排版操作 / Unsupported formatting action')
176
+ } else {
177
+ throw new Error('不支持此排版操作 / Unsupported formatting action')
178
+ }
77
179
  }
78
180
  return next.slides
79
181
  }