dsh-ppt 0.15.0 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/README.en.md +2 -0
- package/README.md +1 -0
- package/docs/USAGE.md +1 -0
- package/docs/VALIDATION.md +2 -0
- package/docs/VISUAL.md +54 -0
- package/docs/validation-0.16.0.md +30 -0
- package/lib/client.js +90 -0
- package/lib/index.js +6 -1
- package/lib/types.d.ts +8 -0
- package/lib/visual-model.d.ts +13 -0
- package/lib/visual-model.js +104 -0
- package/lib/visual.d.ts +197 -0
- package/lib/visual.js +382 -0
- package/lib/workbench.d.ts +4 -0
- package/lib/workbench.js +37 -4
- package/package.json +2 -2
- package/skills/dsh-ppt/SKILL.md +1 -0
- package/skills/dsh-ppt/package.json +1 -1
- package/skills/dsh-ppt/scripts/deck-advanced.mjs +19 -2
- package/skills/dsh-ppt/scripts/deck-core.mjs +10 -3
- package/skills/dsh-ppt/scripts/deck-visual.mjs +79 -0
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* deck.pptx 可编辑 PPTX(16:9,OOXML 由本文件手写,zip 用 node:zlib)
|
|
12
12
|
* deck.json 结构化 deck manifest
|
|
13
13
|
*
|
|
14
|
-
*
|
|
14
|
+
* 零外部运行时依赖,仅使用 Node 内置模块。
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
import { existsSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs'
|
|
@@ -20,6 +20,7 @@ import { deflateRawSync } from 'node:zlib'
|
|
|
20
20
|
import { MEDIA_LAYOUTS, MEDIA_CSS, normalizeMediaSlide, renderMediaHtml, mediaBoxes } from './deck-media.mjs'
|
|
21
21
|
import { renderDelivery } from './deck-delivery.mjs'
|
|
22
22
|
import { renderDataView } from './deck-data-view.mjs'
|
|
23
|
+
import { normalizeVisual, visualHtmlStyle, visualShapeXml, VISUAL_CSS } from './deck-visual.mjs'
|
|
23
24
|
|
|
24
25
|
/**
|
|
25
26
|
* manifest 版本跟随发布包 package.json;把 skills/dsh-ppt 独立复制到其他
|
|
@@ -804,6 +805,10 @@ export function parseMarkdownDeck(titleInput, content, lang = 'zh') {
|
|
|
804
805
|
const SLIDE_LAYOUTS = new Set(['cover', 'section', 'bullets', 'statement', 'closing', 'quote', 'table', ...MEDIA_LAYOUTS])
|
|
805
806
|
|
|
806
807
|
function normalizeSlide(raw, index) {
|
|
808
|
+
const result = normalizeSlideContent(raw, index), visual = normalizeVisual(raw?.visual)
|
|
809
|
+
return visual ? { ...result, visual } : result
|
|
810
|
+
}
|
|
811
|
+
function normalizeSlideContent(raw, index) {
|
|
807
812
|
const source = (raw !== null && typeof raw === 'object') ? raw : {}
|
|
808
813
|
const layout = SLIDE_LAYOUTS.has(source.layout) ? source.layout : source.chart ? 'chart' : source.image ? 'image-right' : 'bullets'
|
|
809
814
|
const title = stripInlineMarkdown(source.title ?? '')
|
|
@@ -1070,6 +1075,7 @@ body{
|
|
|
1070
1075
|
.slide.is-active{display:flex}
|
|
1071
1076
|
${motionCss}
|
|
1072
1077
|
${MEDIA_CSS}
|
|
1078
|
+
${VISUAL_CSS}
|
|
1073
1079
|
.kicker{
|
|
1074
1080
|
color:var(--accent);font-weight:700;letter-spacing:.18em;text-transform:uppercase;
|
|
1075
1081
|
font-size:clamp(12px,1.3vw,18px);margin-bottom:22px;
|
|
@@ -1733,7 +1739,8 @@ function renderHtmlSlide(slide, index, ui, langId, manifest = {}, theme) {
|
|
|
1733
1739
|
const notesAttr = typeof slide.notes === 'string' && slide.notes.trim() !== ''
|
|
1734
1740
|
? ' data-notes="' + escapeHtml(slide.notes) + '"'
|
|
1735
1741
|
: ''
|
|
1736
|
-
|
|
1742
|
+
const visualStyle = visualHtmlStyle(slide.visual)
|
|
1743
|
+
return '<section class="slide slide--' + escapeHtml(slide.layout || 'bullets') + '" data-index="' + number + '"' + notesAttr + (visualStyle ? ' style="' + escapeHtml(visualStyle) + '"' : '') + '>' +
|
|
1737
1744
|
'<div class="slide-inner">' + inner + '</div>' +
|
|
1738
1745
|
(manifest.brand?.logoAssetId ? '<img class="brand-logo" src="' + escapeHtml(manifest.assets?.[manifest.brand.logoAssetId]?.data ?? '') + '" alt="' + escapeHtml(manifest.brand.name || 'Logo') + '"/>' : '') +
|
|
1739
1746
|
(manifest.brand?.footer ? '<div class="brand-footer">' + escapeHtml(manifest.brand.footer) + '</div>' : '') + '</section>'
|
|
@@ -1985,7 +1992,7 @@ function slideShapeList(slide, index, total, theme, langId) {
|
|
|
1985
1992
|
para(footer, { size: 1000, color: p.muted, align: 'r', font: theme.fonts.body }),
|
|
1986
1993
|
]))
|
|
1987
1994
|
|
|
1988
|
-
return shapes.join('')
|
|
1995
|
+
return visualShapeXml(shapes.join(''), slide.visual)
|
|
1989
1996
|
}
|
|
1990
1997
|
|
|
1991
1998
|
/**
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// Deliberately small formatting vocabulary. Model output never contains text edits.
|
|
2
|
+
import { randomUUID } from 'node:crypto'
|
|
3
|
+
|
|
4
|
+
export function normalizeVisual(value) {
|
|
5
|
+
if (value == null) return undefined
|
|
6
|
+
if (typeof value !== 'object' || Array.isArray(value)) throw new Error('visual 需为字号设置对象 / Invalid visual settings')
|
|
7
|
+
const ranges = { titleSize: [24, 60], bodySize: [16, 28], chartLabelSize: [14, 24] }, out = {}
|
|
8
|
+
for (const [key, number] of Object.entries(value)) {
|
|
9
|
+
const range = ranges[key]
|
|
10
|
+
if (!range || !Number.isInteger(number) || number < range[0] || number > range[1]) throw new Error('visual 字号超出允许范围 / Invalid visual font size')
|
|
11
|
+
out[key] = number
|
|
12
|
+
}
|
|
13
|
+
return Object.keys(out).length ? out : undefined
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function visualHtmlStyle(value) {
|
|
17
|
+
const v = normalizeVisual(value)
|
|
18
|
+
if (!v) return ''
|
|
19
|
+
return Object.entries(v).map(([key, n]) => '--ppt-' + key + ':' + n).join(';')
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const VISUAL_CSS = `
|
|
23
|
+
.slide[style*="--ppt-titleSize"] h1,.slide[style*="--ppt-titleSize"] h2,.slide[style*="--ppt-titleSize"] .statement-title,.slide[style*="--ppt-titleSize"] .quote-text{font-size:clamp(24px,calc(var(--ppt-titleSize) * .12vw),calc(var(--ppt-titleSize) * 2px))}
|
|
24
|
+
.slide[style*="--ppt-titleSize"] .media-title{font-size:calc(var(--ppt-titleSize) * .104167cqw)}
|
|
25
|
+
.slide[style*="--ppt-bodySize"] li,.slide[style*="--ppt-bodySize"] .subtitle,.slide[style*="--ppt-bodySize"] .quote-attr{font-size:clamp(16px,calc(var(--ppt-bodySize) * .13vw),calc(var(--ppt-bodySize) * 2px))}
|
|
26
|
+
.slide[style*="--ppt-bodySize"] .media-body,.slide[style*="--ppt-bodySize"] .media-body li{font-size:calc(var(--ppt-bodySize) * .104167cqw)}
|
|
27
|
+
.slide[style*="--ppt-bodySize"] .deck-table{font-size:clamp(12px,calc(var(--ppt-bodySize) * .09vw),calc(var(--ppt-bodySize) * 1.35px))}
|
|
28
|
+
.slide[style*="--ppt-chartLabelSize"] .native-chart text{font-size:calc(var(--ppt-chartLabelSize) * 1px)}
|
|
29
|
+
`
|
|
30
|
+
|
|
31
|
+
/** Apply formatting to the generator's known OOXML shapes, never arbitrary XML. */
|
|
32
|
+
export function visualShapeXml(xml, visual) {
|
|
33
|
+
const v = normalizeVisual(visual)
|
|
34
|
+
if (!v) return xml
|
|
35
|
+
return xml.replace(/<p:(sp|graphicFrame)>[\s\S]*?<\/p:\1>/g, shape => {
|
|
36
|
+
const name = shape.match(/<p:cNvPr\b[^>]*\bname="([^"]*)"/)?.[1]
|
|
37
|
+
const pt = ['Title', 'Statement', 'Quote'].includes(name) ? v.titleSize : ['Body', 'Subtitle', 'Attribution', 'Table'].includes(name) ? v.bodySize : undefined
|
|
38
|
+
return pt ? shape.replace(/(<a:(?:rPr|defRPr|endParaRPr)\b[^>]*\bsz=")[0-9]+"/g, '$1' + (pt * 100) + '"') : shape
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Facts, metrics, assets, titles and slide order are preserved by construction. */
|
|
43
|
+
export function applyVisualActions(manifest, actions) {
|
|
44
|
+
if (!Array.isArray(actions) || !actions.length || actions.length > 48) throw new Error('请选择有效的排版修改 / Invalid formatting actions')
|
|
45
|
+
const next = structuredClone(manifest), seen = new Set()
|
|
46
|
+
for (const a of actions) {
|
|
47
|
+
if (!a || typeof a !== 'object' || Object.keys(a).some(k => !['slideId', 'type', 'value'].includes(k))) throw new Error('排版操作包含无效字段 / Invalid formatting action fields')
|
|
48
|
+
const index = next.slides.findIndex(s => s.id === a.slideId), original = manifest.slides.find(s => s.id === a.slideId)
|
|
49
|
+
if (index < 0 || !original) throw new Error('排版操作关联的页面不存在 / Unknown slide')
|
|
50
|
+
const key = a.slideId + ':' + (a.type?.startsWith('split-') ? 'split' : a.type)
|
|
51
|
+
if (seen.has(key)) throw new Error('同一页的排版操作重复 / Duplicate formatting action')
|
|
52
|
+
seen.add(key)
|
|
53
|
+
const slide = next.slides[index]
|
|
54
|
+
const field = { 'title-size': 'titleSize', 'body-size': 'bodySize', 'chart-label-size': 'chartLabelSize' }[a.type]
|
|
55
|
+
if (field) {
|
|
56
|
+
if (field === 'chartLabelSize' && !slide.chart) throw new Error('本页没有图表 / Slide has no chart')
|
|
57
|
+
slide.visual = normalizeVisual({ ...slide.visual, [field]: a.value })
|
|
58
|
+
} else if (a.type === 'chart-horizontal') {
|
|
59
|
+
if (a.value !== undefined || slide.chart?.kind !== 'column') throw new Error('只支持将柱状图改为横向条形图 / Only column-to-bar conversion is supported')
|
|
60
|
+
slide.chart.kind = 'bar'
|
|
61
|
+
if (slide.dataTemplate?.chart) slide.dataTemplate.chart.kind = 'bar'
|
|
62
|
+
} else if (a.type === 'image-contain') {
|
|
63
|
+
if (a.value !== undefined || !slide.image) throw new Error('本页没有图片 / Slide has no image')
|
|
64
|
+
slide.image.fit = 'contain'
|
|
65
|
+
} else if (a.type === 'split-bullets' || a.type === 'split-table') {
|
|
66
|
+
const bullets = a.type === 'split-bullets', field = bullets ? 'bullets' : 'rows'
|
|
67
|
+
if (bullets ? !['bullets','image-left','image-right'].includes(slide.layout) : slide.layout !== 'table') throw new Error('此版式不支持所选拆页操作 / Split is not supported for this layout')
|
|
68
|
+
const data = slide[field], count = bullets ? data?.length : data?.length - 1
|
|
69
|
+
if (!Number.isInteger(a.value) || a.value < 1 || a.value >= count) throw new Error('拆页位置无效 / Invalid split position')
|
|
70
|
+
if (next.slides.length >= 120) throw new Error('拆页后超过 120 页 / Split would exceed 120 slides')
|
|
71
|
+
const added = structuredClone(slide); added.id = randomUUID()
|
|
72
|
+
const split = values => bullets ? [values.slice(0, a.value), values.slice(a.value)] : [values.slice(0, a.value + 1), [values[0], ...values.slice(a.value + 1)]]
|
|
73
|
+
;[slide[field], added[field]] = split(data)
|
|
74
|
+
if (slide.dataTemplate?.[field]) [slide.dataTemplate[field], added.dataTemplate[field]] = split(slide.dataTemplate[field])
|
|
75
|
+
next.slides.splice(index + 1, 0, added)
|
|
76
|
+
} else throw new Error('不支持此排版操作 / Unsupported formatting action')
|
|
77
|
+
}
|
|
78
|
+
return next.slides
|
|
79
|
+
}
|