dsh-ppt 0.21.1 → 0.22.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/README.en.md +18 -18
- package/README.md +16 -16
- package/docs/COACHING.md +14 -13
- package/docs/DATA.md +8 -8
- package/docs/REFERENCE.en.md +17 -19
- package/docs/REFERENCE.zh.md +16 -18
- package/docs/USAGE.en.md +107 -60
- package/docs/USAGE.md +115 -84
- package/docs/VALIDATION.md +2 -0
- package/docs/VISUAL.md +27 -20
- package/docs/WORKBENCH.md +17 -6
- package/docs/assets/intro/screen-en.webp +0 -0
- package/docs/assets/intro/screen-zh.webp +0 -0
- package/lib/client.js +905 -46
- package/lib/coaching.d.ts +1 -1
- package/lib/coaching.js +25 -12
- package/lib/config.d.ts +2 -0
- package/lib/config.js +30 -2
- package/lib/execution.d.ts +2 -1
- package/lib/execution.js +21 -1
- package/lib/tools.d.ts +1 -1
- package/lib/tools.js +151 -24
- package/lib/types.d.ts +108 -8
- package/lib/visual.d.ts +3 -1
- package/lib/visual.js +40 -13
- package/lib/workbench-language.js +45 -9
- package/lib/workbench.d.ts +5 -0
- package/lib/workbench.js +485 -9
- package/package.json +8 -3
- package/skills/dsh-ppt/SKILL.md +56 -54
- package/skills/dsh-ppt/package.json +1 -1
- package/skills/dsh-ppt/references/advanced.md +122 -41
- package/skills/dsh-ppt/references/copywriting.md +63 -41
- package/skills/dsh-ppt/references/data.md +83 -36
- package/skills/dsh-ppt/references/syntax.md +157 -28
- package/skills/dsh-ppt/references/themes.md +90 -41
- package/skills/dsh-ppt/references/troubleshooting.md +21 -16
- package/skills/dsh-ppt/scripts/build-deck.mjs +67 -28
- package/skills/dsh-ppt/scripts/deck-absorb.mjs +1029 -0
- package/skills/dsh-ppt/scripts/deck-advanced.mjs +406 -99
- package/skills/dsh-ppt/scripts/deck-core.mjs +568 -717
- package/skills/dsh-ppt/scripts/deck-data-view.mjs +30 -11
- package/skills/dsh-ppt/scripts/deck-data.mjs +35 -5
- package/skills/dsh-ppt/scripts/deck-director.mjs +1717 -0
- package/skills/dsh-ppt/scripts/deck-layouts.mjs +4557 -0
- package/skills/dsh-ppt/scripts/deck-media.mjs +1408 -86
- package/skills/dsh-ppt/scripts/deck-themes.mjs +1503 -0
- package/skills/dsh-ppt/scripts/deck-visual.mjs +133 -31
|
@@ -1,17 +1,108 @@
|
|
|
1
|
-
// Shared geometry
|
|
2
|
-
|
|
1
|
+
// Shared geometry, media framing, and publication-grade chart compilers (SVG + OOXML + @office-kit/pptx).
|
|
2
|
+
import { resolveChromeStyle } from './deck-themes.mjs'
|
|
3
|
+
import { getChromeConfig, computeBadgePillWidth, roundRectAdj } from './deck-layouts.mjs'
|
|
4
|
+
|
|
5
|
+
export const MEDIA_LAYOUTS = new Set(['image', 'image-left', 'image-right', 'chart', 'chart-split'])
|
|
6
|
+
export const CHART_KINDS = Object.freeze([
|
|
7
|
+
'column', 'bar', 'stacked-column', 'stacked-bar', 'percent-column', 'percent-bar',
|
|
8
|
+
'line', 'area', 'pie', 'doughnut', 'scatter', 'combo', 'waterfall',
|
|
9
|
+
])
|
|
3
10
|
export const CANVAS = { w: 13.3333333333, h: 7.5 }
|
|
4
|
-
export const LOGO_BOX = { x: 11.55, y: 0.
|
|
5
|
-
export const FOOTER_BOX = { x: 0.
|
|
6
|
-
|
|
7
|
-
export function mediaBoxes(layout) {
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
|
|
11
|
+
export const LOGO_BOX = { x: 11.55, y: 0.18, w: 0.95, h: 0.42 }
|
|
12
|
+
export const FOOTER_BOX = { x: 0.65, y: 6.98, w: 9.2, h: 0.28 }
|
|
13
|
+
|
|
14
|
+
export function mediaBoxes(layout, variantInput, slide = {}) {
|
|
15
|
+
const variant = String(variantInput ?? slide?.variant ?? '').trim().toLowerCase()
|
|
16
|
+
const hasTakeaway = Boolean(slide?.takeaway && String(slide.takeaway).trim())
|
|
17
|
+
const hasCaption = Boolean((slide?.image?.caption && String(slide.image.caption).trim()) || (slide?.chart?.caption && String(slide.chart.caption).trim()))
|
|
18
|
+
const bottomLimit = hasTakeaway ? (hasCaption ? 5.80 : 6.04) : 6.42
|
|
19
|
+
const bodyTop = 1.68
|
|
20
|
+
const bodyH = +(bottomLimit - bodyTop).toFixed(3)
|
|
21
|
+
const title = { x: 0.65, y: 0.52, w: 12.03, h: 0.88 }
|
|
22
|
+
const kicker = { x: 0.65, y: 0.28, w: 10.5, h: 0.24 }
|
|
23
|
+
const takeaway = { x: 0.62, y: 6.26, w: 12.09, h: 0.54 }
|
|
24
|
+
const fullCaption = { x: 0.65, y: hasTakeaway ? 5.86 : 6.46, w: 12.03, h: 0.30 }
|
|
25
|
+
|
|
26
|
+
if (layout === 'image' && variant === 'full-bleed') {
|
|
27
|
+
return {
|
|
28
|
+
kicker,
|
|
29
|
+
title: { x: 0.65, y: hasTakeaway ? 4.95 : 5.35, w: 10.6, h: 1.02 },
|
|
30
|
+
image: { x: 0, y: 0, w: CANVAS.w, h: CANVAS.h },
|
|
31
|
+
body: null,
|
|
32
|
+
chart: { x: 0.65, y: bodyTop, w: 12.03, h: bodyH },
|
|
33
|
+
caption: { x: 0.65, y: hasTakeaway ? 5.98 : 6.52, w: 10.6, h: 0.26 },
|
|
34
|
+
takeaway,
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if ((layout === 'image-left' || layout === 'image-right') && variant === 'split-bleed') {
|
|
39
|
+
const imgLeft = layout === 'image-left'
|
|
40
|
+
const colX = imgLeft ? 6.85 : 0.65
|
|
41
|
+
return {
|
|
42
|
+
kicker: { x: colX, y: 0.44, w: 5.8, h: 0.26 },
|
|
43
|
+
title: { x: colX, y: 0.76, w: 5.8, h: 1.05 },
|
|
44
|
+
image: imgLeft ? { x: 0, y: 0, w: 6.25, h: CANVAS.h } : { x: 7.08, y: 0, w: 6.253, h: CANVAS.h },
|
|
45
|
+
body: { x: colX, y: 2.02, w: 5.8, h: hasTakeaway ? (hasCaption ? 3.62 : 3.98) : 4.42 },
|
|
46
|
+
chart: { x: 0.65, y: bodyTop, w: 12.03, h: bodyH },
|
|
47
|
+
caption: { x: colX, y: hasTakeaway ? 5.76 : 6.52, w: 5.8, h: 0.28 },
|
|
48
|
+
takeaway: { x: colX, y: 6.14, w: 5.8, h: 0.54 },
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (layout === 'chart-split') {
|
|
53
|
+
const chartRight = variant === 'chart-right'
|
|
54
|
+
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 }
|
|
57
|
+
const sideBox = chartRight
|
|
58
|
+
? { x: 0.65, y: bodyTop, w: 4.35, h: bodyH }
|
|
59
|
+
: { x: 8.33, y: bodyTop, w: 4.35, h: bodyH }
|
|
60
|
+
return {
|
|
61
|
+
kicker,
|
|
62
|
+
title,
|
|
63
|
+
image: chartBox,
|
|
64
|
+
body: sideBox,
|
|
65
|
+
chart: chartBox,
|
|
66
|
+
caption: { x: chartBox.x, y: hasTakeaway ? 5.86 : 6.46, w: chartBox.w, h: 0.30 },
|
|
67
|
+
takeaway,
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const left = { x: 0.65, y: bodyTop, w: 5.76, h: bodyH }
|
|
72
|
+
const right = { x: 6.92, y: bodyTop, w: 5.76, h: bodyH }
|
|
73
|
+
const full = { x: 0.65, y: bodyTop, w: 12.03, h: bodyH }
|
|
74
|
+
const imageTarget = layout === 'image-left' ? left : layout === 'image-right' ? right : full
|
|
75
|
+
const galleryCount = Array.isArray(slide?.images) && slide.images.length > 1 ? Math.min(4, slide.images.length) : 0
|
|
76
|
+
const gallery = galleryCount > 1
|
|
77
|
+
? Array.from({ length: galleryCount }, (_, idx) => {
|
|
78
|
+
const gap = 0.24
|
|
79
|
+
const cellW = (full.w - gap * (galleryCount - 1)) / galleryCount
|
|
80
|
+
return { x: +(full.x + idx * (cellW + gap)).toFixed(4), y: full.y, w: +cellW.toFixed(4), h: +(bodyH - 0.25).toFixed(4) }
|
|
81
|
+
})
|
|
82
|
+
: null
|
|
83
|
+
|
|
84
|
+
const captionBox = (layout === 'image-left' || layout === 'image-right')
|
|
85
|
+
? { x: imageTarget.x, y: hasTakeaway ? 5.86 : 6.46, w: imageTarget.w, h: 0.30 }
|
|
86
|
+
: fullCaption
|
|
87
|
+
|
|
88
|
+
return {
|
|
89
|
+
kicker,
|
|
90
|
+
title,
|
|
91
|
+
image: { ...imageTarget, h: +(bodyH - 0.14).toFixed(3) },
|
|
92
|
+
gallery,
|
|
13
93
|
body: layout === 'image-left' ? right : layout === 'image-right' ? left : null,
|
|
14
|
-
chart: { ...full, h:
|
|
94
|
+
chart: { ...full, h: +(bodyH - 0.12).toFixed(3) },
|
|
95
|
+
caption: captionBox,
|
|
96
|
+
takeaway,
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function textUnits(text) {
|
|
101
|
+
let units = 0
|
|
102
|
+
for (const ch of String(text ?? '')) {
|
|
103
|
+
units += /[\u2E80-\u9FFF\uF900-\uFAFF\uFF00-\uFFEF]/.test(ch) ? 1 : 0.55
|
|
104
|
+
}
|
|
105
|
+
return units
|
|
15
106
|
}
|
|
16
107
|
|
|
17
108
|
function numeric(value, page) {
|
|
@@ -23,10 +114,27 @@ function numeric(value, page) {
|
|
|
23
114
|
return result
|
|
24
115
|
}
|
|
25
116
|
|
|
117
|
+
function normalizeHighlight(highlight, categoryCount) {
|
|
118
|
+
if (highlight === undefined || highlight === null || highlight === '' || highlight === 'none') return undefined
|
|
119
|
+
if (highlight === 'max' || highlight === 'last' || highlight === 'min') return highlight
|
|
120
|
+
if (typeof highlight === 'number') {
|
|
121
|
+
if (!Number.isInteger(highlight) || highlight < 0 || highlight >= categoryCount) return undefined
|
|
122
|
+
return highlight
|
|
123
|
+
}
|
|
124
|
+
if (Array.isArray(highlight)) {
|
|
125
|
+
const valid = highlight.filter(n => Number.isInteger(n) && n >= 0 && n < categoryCount)
|
|
126
|
+
return valid.length ? [...new Set(valid)] : undefined
|
|
127
|
+
}
|
|
128
|
+
return undefined
|
|
129
|
+
}
|
|
130
|
+
|
|
26
131
|
export function normalizeChart(input, page = 1) {
|
|
27
132
|
if (!input || typeof input !== 'object' || Array.isArray(input)) throw new Error(`dsh-ppt:第 ${page} 页缺少 chart 对象`)
|
|
28
|
-
|
|
29
|
-
if (
|
|
133
|
+
let kind = String(input.kind ?? 'column').trim().toLowerCase()
|
|
134
|
+
if (kind === 'percent-stacked') kind = 'percent-column'
|
|
135
|
+
if (kind === 'donut') kind = 'doughnut'
|
|
136
|
+
if (!CHART_KINDS.includes(kind)) throw new Error(`dsh-ppt:第 ${page} 页未知图表类型 ${kind}`)
|
|
137
|
+
|
|
30
138
|
let categories = input.categories
|
|
31
139
|
let series = input.series
|
|
32
140
|
if (input.rows !== undefined) {
|
|
@@ -38,123 +146,1337 @@ export function normalizeChart(input, page = 1) {
|
|
|
38
146
|
categories = rows.slice(1).map(row => row[0])
|
|
39
147
|
series = rows[0].slice(1).map((name, column) => ({ name, values: rows.slice(1).map(row => row[column + 1]) }))
|
|
40
148
|
}
|
|
149
|
+
|
|
150
|
+
if (kind === 'scatter' && (!Array.isArray(categories) || categories.length === 0) && Array.isArray(series) && series[0]?.values?.length) {
|
|
151
|
+
categories = series[0].values.map((_, idx) => String(series[0].xValues?.[idx] ?? idx + 1))
|
|
152
|
+
}
|
|
153
|
+
|
|
41
154
|
if (!Array.isArray(categories) || categories.length < 1 || categories.length > 24 || categories.some(c => String(c ?? '').trim() === '')) {
|
|
42
155
|
throw new Error(`dsh-ppt:第 ${page} 页图表需 1–24 个非空类别`)
|
|
43
156
|
}
|
|
44
|
-
if (!Array.isArray(series) || series.length < 1 || series.length > 6)
|
|
157
|
+
if (!Array.isArray(series) || series.length < 1 || series.length > 6) {
|
|
158
|
+
throw new Error(`dsh-ppt:第 ${page} 页图表需 1–6 个数据系列`)
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// Auto horizontal bar orientation for very long category labels unless caller explicitly locked vertical
|
|
162
|
+
if (kind === 'column' && input.keepVertical !== true && categories.some(c => textUnits(c) > 9.5)) {
|
|
163
|
+
kind = 'bar'
|
|
164
|
+
}
|
|
165
|
+
|
|
45
166
|
const clean = series.map((s, i) => {
|
|
46
|
-
if (!s || !Array.isArray(s.values) || s.values.length !== categories.length)
|
|
47
|
-
|
|
167
|
+
if (!s || !Array.isArray(s.values) || s.values.length !== categories.length) {
|
|
168
|
+
throw new Error(`dsh-ppt:第 ${page} 页图表第 ${i + 1} 个系列与类别数量不一致`)
|
|
169
|
+
}
|
|
170
|
+
const item = {
|
|
171
|
+
name: String(s.name ?? `系列 ${i + 1}`).trim() || `系列 ${i + 1}`,
|
|
172
|
+
values: s.values.map(v => numeric(v, page)),
|
|
173
|
+
}
|
|
174
|
+
if (kind === 'scatter') {
|
|
175
|
+
const rawX = Array.isArray(s.xValues) && s.xValues.length === categories.length
|
|
176
|
+
? s.xValues.map(v => numeric(v, page))
|
|
177
|
+
: categories.map((cat, idx) => {
|
|
178
|
+
const parsed = Number(String(cat).trim())
|
|
179
|
+
return Number.isFinite(parsed) ? parsed : idx + 1
|
|
180
|
+
})
|
|
181
|
+
item.xValues = rawX
|
|
182
|
+
}
|
|
183
|
+
if (kind === 'combo') {
|
|
184
|
+
const sub = s.chartKind && ['column', 'line', 'area', 'bar'].includes(s.chartKind)
|
|
185
|
+
? s.chartKind
|
|
186
|
+
: (i === 0 ? 'column' : 'line')
|
|
187
|
+
item.chartKind = sub
|
|
188
|
+
if (s.secondaryAxis === true && i > 0) item.secondaryAxis = true
|
|
189
|
+
}
|
|
190
|
+
return item
|
|
48
191
|
})
|
|
49
|
-
|
|
192
|
+
|
|
193
|
+
if ((kind === 'pie' || kind === 'doughnut') && (clean.length !== 1 || categories.length > 12 || clean[0].values.some(v => v < 0) || clean[0].values.reduce((a, b) => a + b, 0) <= 0)) {
|
|
50
194
|
throw new Error(`dsh-ppt:第 ${page} 页饼图只支持一个系列、最多 12 个类别,数值需非负且总和大于零`)
|
|
51
195
|
}
|
|
52
|
-
|
|
53
|
-
|
|
196
|
+
if (kind === 'waterfall' && clean.length !== 1) {
|
|
197
|
+
throw new Error(`dsh-ppt:第 ${page} 页瀑布图只支持单个数据系列`)
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const highlight = normalizeHighlight(input.highlight, categories.length)
|
|
201
|
+
const totalIndices = Array.isArray(input.totalIndices)
|
|
202
|
+
? input.totalIndices.filter(n => Number.isInteger(n) && n >= 0 && n < categories.length)
|
|
203
|
+
: undefined
|
|
204
|
+
|
|
205
|
+
return {
|
|
206
|
+
kind,
|
|
207
|
+
categories: categories.map(c => String(c).trim()),
|
|
208
|
+
series: clean,
|
|
209
|
+
...(highlight !== undefined ? { highlight } : {}),
|
|
210
|
+
...(typeof input.showValues === 'boolean' ? { showValues: input.showValues } : {}),
|
|
211
|
+
...(typeof input.showLegend === 'boolean' ? { showLegend: input.showLegend } : {}),
|
|
212
|
+
...(totalIndices?.length ? { totalIndices } : {}),
|
|
213
|
+
...(input.unit ? { unit: String(input.unit).trim() } : {}),
|
|
214
|
+
...(input.caption ? { caption: String(input.caption).trim() } : {}),
|
|
215
|
+
...(input.source ? { source: String(input.source).trim() } : {}),
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function normalizeSingleImage(raw, fallbackAlt, page, defaultFit = 'contain') {
|
|
220
|
+
const image = typeof raw === 'string' ? { src: raw } : raw
|
|
221
|
+
if (!image || typeof image !== 'object' || (!image.src && !image.assetId)) {
|
|
222
|
+
throw new Error(`dsh-ppt:第 ${page} 页缺少 image.src`)
|
|
223
|
+
}
|
|
224
|
+
const fit = image.fit ?? defaultFit
|
|
225
|
+
if (!['contain', 'cover'].includes(fit)) {
|
|
226
|
+
throw new Error(`dsh-ppt:第 ${page} 页 image.fit 仅支持 contain / cover`)
|
|
227
|
+
}
|
|
228
|
+
return {
|
|
229
|
+
...(image.src ? { src: String(image.src) } : {}),
|
|
230
|
+
...(image.assetId ? { assetId: String(image.assetId) } : {}),
|
|
231
|
+
alt: String(image.alt ?? fallbackAlt ?? ''),
|
|
232
|
+
fit,
|
|
233
|
+
...(image.caption ? { caption: String(image.caption) } : {}),
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function normalizeItemsAlias(source) {
|
|
238
|
+
const rawList = source.items ?? source.cards ?? source.metrics ?? source.steps ?? source.columns ?? source.quadrants
|
|
239
|
+
if (!Array.isArray(rawList) || rawList.length === 0) return undefined
|
|
240
|
+
return rawList
|
|
241
|
+
.filter(item => item && typeof item === 'object')
|
|
242
|
+
.slice(0, 8)
|
|
243
|
+
.map(item => ({
|
|
244
|
+
...(item.tag || item.badge ? { tag: String(item.tag ?? item.badge).trim() } : {}),
|
|
245
|
+
...(item.title ? { title: String(item.title).trim() } : {}),
|
|
246
|
+
...(item.text || item.body ? { text: String(item.text ?? item.body).trim() } : {}),
|
|
247
|
+
...(item.value !== undefined && item.value !== null && String(item.value).trim() !== '' ? { value: String(item.value).trim() } : {}),
|
|
248
|
+
...(item.unit ? { unit: String(item.unit).trim() } : {}),
|
|
249
|
+
...(item.delta ? { delta: String(item.delta).trim() } : {}),
|
|
250
|
+
...(item.status || item.tone ? { status: String(item.status ?? item.tone).trim() } : {}),
|
|
251
|
+
...(Array.isArray(item.bullets) ? { bullets: item.bullets.map(b => String(b).trim()).filter(Boolean) } : {}),
|
|
252
|
+
}))
|
|
54
253
|
}
|
|
55
254
|
|
|
56
255
|
export function normalizeMediaSlide(source, normalized, index) {
|
|
57
256
|
if (!MEDIA_LAYOUTS.has(normalized.layout)) return normalized
|
|
58
|
-
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
257
|
+
const page = index + 1
|
|
258
|
+
const variant = source.variant ? String(source.variant).trim() : undefined
|
|
259
|
+
const takeaway = source.takeaway ? String(source.takeaway).trim() : undefined
|
|
260
|
+
const slideSource = source.source ? String(source.source).trim() : undefined
|
|
261
|
+
const items = normalized.items ?? normalizeItemsAlias(source)
|
|
262
|
+
const extras = {
|
|
263
|
+
...(variant ? { variant } : {}),
|
|
264
|
+
...(takeaway ? { takeaway } : {}),
|
|
265
|
+
...(slideSource ? { source: slideSource } : {}),
|
|
266
|
+
...(items ? { items } : {}),
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
if (normalized.layout === 'chart' || normalized.layout === 'chart-split') {
|
|
270
|
+
const chartInput = source.layout === 'waterfall' && source.chart
|
|
271
|
+
? { ...source.chart, kind: 'waterfall' }
|
|
272
|
+
: source.chart
|
|
273
|
+
const chart = normalizeChart(chartInput, page)
|
|
274
|
+
return { ...normalized, ...extras, chart }
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
const defaultFit = variant === 'split-bleed' || variant === 'full-bleed' || variant === 'gallery' ? 'cover' : 'contain'
|
|
278
|
+
if (Array.isArray(source.images) && source.images.length > 0) {
|
|
279
|
+
const images = source.images.slice(0, 4).map(img => normalizeSingleImage(img, normalized.title, page, defaultFit))
|
|
280
|
+
return {
|
|
281
|
+
...normalized,
|
|
282
|
+
...extras,
|
|
283
|
+
variant: variant || (images.length > 1 ? 'gallery' : undefined),
|
|
284
|
+
image: source.image ? normalizeSingleImage(source.image, normalized.title, page, defaultFit) : images[0],
|
|
285
|
+
images,
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
return {
|
|
290
|
+
...normalized,
|
|
291
|
+
...extras,
|
|
292
|
+
image: normalizeSingleImage(source.image, normalized.title, page, defaultFit),
|
|
293
|
+
}
|
|
65
294
|
}
|
|
66
295
|
|
|
67
296
|
const esc = value => String(value ?? '').replaceAll('&', '&').replaceAll('<', '<').replaceAll('>', '>').replaceAll('"', '"').replaceAll("'", ''')
|
|
68
|
-
const position = box => `left:${box.x / CANVAS.w * 100}%;top:${box.y / CANVAS.h * 100}%;width:${box.w / CANVAS.w * 100}%;height:${box.h / CANVAS.h * 100}%`
|
|
69
|
-
|
|
297
|
+
const position = box => `left:${(box.x / CANVAS.w * 100).toFixed(4)}%;top:${(box.y / CANVAS.h * 100).toFixed(4)}%;width:${(box.w / CANVAS.w * 100).toFixed(4)}%;height:${(box.h / CANVAS.h * 100).toFixed(4)}%`
|
|
298
|
+
|
|
299
|
+
export function chartColors(theme) {
|
|
300
|
+
if (Array.isArray(theme?.tokens?.chartSeries) && theme.tokens.chartSeries.length >= 6) {
|
|
301
|
+
return [...theme.tokens.chartSeries]
|
|
302
|
+
}
|
|
303
|
+
const accent = theme?.palette?.accent || '#0057B8'
|
|
304
|
+
const accent2 = theme?.palette?.accent2 || '#0E7490'
|
|
305
|
+
return [accent, accent2, '#0D7A4E', '#4F46E5', '#D97706', '#64748B']
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Pure-math waterfall geometry solver shared between SVG and native OOXML shapes.
|
|
310
|
+
*/
|
|
311
|
+
function niceAxisScale(rawMin, rawMax, targetIntervals = 4) {
|
|
312
|
+
const lo = rawMin < 0 ? rawMin * 1.08 : 0
|
|
313
|
+
const hi = rawMax > 0 ? rawMax * 1.08 : (lo === 0 ? 1 : 0)
|
|
314
|
+
const roughSpan = hi - lo || 1
|
|
315
|
+
const pickStep = (span) => {
|
|
316
|
+
const rawStep = span / targetIntervals
|
|
317
|
+
const mag = 10 ** Math.floor(Math.log10(Math.max(1e-9, rawStep)))
|
|
318
|
+
const res = rawStep / mag
|
|
319
|
+
const mult = [1, 2, 2.5, 4, 5, 10].find(m => m >= res - 1e-9) ?? 10
|
|
320
|
+
return mult * mag
|
|
321
|
+
}
|
|
322
|
+
let step = pickStep(roughSpan)
|
|
323
|
+
let min = lo < 0 ? Math.floor(lo / step) * step : 0
|
|
324
|
+
let max = hi > 0 ? Math.ceil(hi / step) * step : 0
|
|
325
|
+
if (max === min) max = min + step
|
|
326
|
+
if (Math.round((max - min) / step) > 5) {
|
|
327
|
+
step = pickStep((max - min) * 1.15)
|
|
328
|
+
min = lo < 0 ? Math.floor(lo / step) * step : 0
|
|
329
|
+
max = hi > 0 ? Math.ceil(hi / step) * step : 0
|
|
330
|
+
}
|
|
331
|
+
const count = Math.max(1, Math.round((max - min) / step))
|
|
332
|
+
const tickValues = Array.from({ length: count + 1 }, (_, i) => {
|
|
333
|
+
const v = min + i * step
|
|
334
|
+
return Math.abs(v) < 1e-12 ? 0 : Number(v.toFixed(8))
|
|
335
|
+
})
|
|
336
|
+
return { min, max, span: max - min || 1, step, tickValues }
|
|
337
|
+
}
|
|
70
338
|
|
|
339
|
+
export function computeWaterfallGeometry(chart, bounds = { left: 86, right: 1088, top: 34, bottom: 342 }) {
|
|
340
|
+
const values = chart.series[0]?.values ?? []
|
|
341
|
+
const categories = chart.categories ?? []
|
|
342
|
+
const n = categories.length
|
|
343
|
+
const explicitTotals = new Set(Array.isArray(chart.totalIndices) ? chart.totalIndices : [])
|
|
344
|
+
if (explicitTotals.size === 0 && n >= 1) {
|
|
345
|
+
explicitTotals.add(0)
|
|
346
|
+
if (n >= 3) {
|
|
347
|
+
const priorSum = values.slice(0, -1).reduce((a, b) => a + b, 0)
|
|
348
|
+
const lastLabel = String(categories[n - 1] ?? '')
|
|
349
|
+
if (/(?:^(?:合计|总计|总和|期末|净\S*|最终|Total|Sum|Net|End|Ending|Final|Target)|(?:合计|总计|净额|净值|净利|利润|总和)$)/i.test(lastLabel) && Math.abs(values[n - 1] - priorSum) <= Math.max(1e-6, Math.abs(priorSum) * 1e-4)) {
|
|
350
|
+
explicitTotals.add(n - 1)
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
let running = 0
|
|
356
|
+
const bars = values.map((val, idx) => {
|
|
357
|
+
const isTotal = explicitTotals.has(idx)
|
|
358
|
+
const start = isTotal ? 0 : running
|
|
359
|
+
const end = isTotal ? val : running + val
|
|
360
|
+
running = end
|
|
361
|
+
const role = isTotal ? 'total' : val >= 0 ? 'positive' : 'negative'
|
|
362
|
+
return { index: idx, category: categories[idx], value: val, start, end, isTotal, role }
|
|
363
|
+
})
|
|
364
|
+
|
|
365
|
+
const allPoints = [0, ...bars.flatMap(b => [b.start, b.end])]
|
|
366
|
+
const { min, max, span, tickValues } = niceAxisScale(Math.min(...allPoints), Math.max(...allPoints), 4)
|
|
367
|
+
const { left, right, top, bottom } = bounds
|
|
368
|
+
const yOf = v => bottom - ((v - min) / span) * (bottom - top)
|
|
369
|
+
const groupW = (right - left) / Math.max(1, n)
|
|
370
|
+
const barW = Math.max(8, groupW * 0.58)
|
|
371
|
+
|
|
372
|
+
const positioned = bars.map((b, idx) => {
|
|
373
|
+
const x = left + idx * groupW + (groupW - barW) / 2
|
|
374
|
+
const yTop = yOf(Math.max(b.start, b.end))
|
|
375
|
+
const yBottom = yOf(Math.min(b.start, b.end))
|
|
376
|
+
const h = Math.max(2, yBottom - yTop)
|
|
377
|
+
const formatted = (!b.isTotal && b.value > 0 ? '+' : '') + Number(b.value.toPrecision(6)).toLocaleString('en-US')
|
|
378
|
+
return { ...b, x, w: barW, y: yTop, h, yEnd: yOf(b.end), label: formatted }
|
|
379
|
+
})
|
|
380
|
+
|
|
381
|
+
const connectors = []
|
|
382
|
+
for (let i = 0; i < positioned.length - 1; i++) {
|
|
383
|
+
connectors.push({
|
|
384
|
+
x1: positioned[i].x + positioned[i].w,
|
|
385
|
+
y1: positioned[i].yEnd,
|
|
386
|
+
x2: positioned[i + 1].x,
|
|
387
|
+
y2: positioned[i].yEnd,
|
|
388
|
+
})
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
const ticks = tickValues.map((v) => ({
|
|
392
|
+
value: v,
|
|
393
|
+
y: yOf(v),
|
|
394
|
+
label: Number(v.toFixed(6)).toLocaleString('en-US'),
|
|
395
|
+
}))
|
|
396
|
+
|
|
397
|
+
return { min, max, span, zeroY: yOf(0), bars: positioned, connectors, ticks, bounds }
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* Self-contained SVG chart renderer (safe to serialize via .toString() in deck-data-view.mjs).
|
|
402
|
+
*/
|
|
71
403
|
export function renderChartSvg(chart, theme) {
|
|
72
|
-
const colors = chartColors(theme)
|
|
404
|
+
const colors = chartColors(theme)
|
|
405
|
+
const tokens = theme?.tokens || {}
|
|
406
|
+
const bg = tokens.canvas || theme?.palette?.bg || '#FFFFFF'
|
|
407
|
+
const fg = tokens.inkPrimary || theme?.palette?.fg || '#0F172A'
|
|
408
|
+
const muted = tokens.inkMuted || theme?.palette?.muted || '#64748B'
|
|
409
|
+
const gridColor = tokens.hairline || (theme?.dark ? '#263554' : '#D5DFEC')
|
|
410
|
+
const axisColor = tokens.inkSecondary || muted
|
|
411
|
+
const focalColor = tokens.chartFocal || colors[0]
|
|
412
|
+
const neutralColor = tokens.chartNeutral || (theme?.dark ? '#2B354D' : '#CBD5E1')
|
|
413
|
+
const posColor = tokens.positive || (theme?.dark ? '#34D399' : '#0D7A4E')
|
|
414
|
+
const negColor = tokens.negative || (theme?.dark ? '#F87171' : '#C81E1E')
|
|
415
|
+
|
|
73
416
|
const width = 1120, height = 430, n = chart.categories.length
|
|
74
|
-
const
|
|
75
|
-
const
|
|
76
|
-
|
|
417
|
+
const fmtNum = v => Number(Math.abs(v) < 1e-12 ? 0 : Number(Number(v).toPrecision(5))).toLocaleString('en-US')
|
|
418
|
+
const niceBounds = (rMin, rMax) => {
|
|
419
|
+
const lo = rMin < 0 ? rMin * 1.08 : 0, hi = rMax > 0 ? rMax * 1.08 : (lo === 0 ? 1 : 0)
|
|
420
|
+
const pick = sp => { const rs = sp / 4, m = 10 ** Math.floor(Math.log10(Math.max(1e-9, rs))), r = rs / m; return ([1, 2, 2.5, 4, 5, 10].find(k => k >= r - 1e-9) ?? 10) * m }
|
|
421
|
+
let st = pick(hi - lo || 1), mn = lo < 0 ? Math.floor(lo / st) * st : 0, mx = hi > 0 ? Math.ceil(hi / st) * st : 0
|
|
422
|
+
if (mx === mn) mx = mn + st
|
|
423
|
+
if (Math.round((mx - mn) / st) > 5) { st = pick((mx - mn) * 1.15); mn = lo < 0 ? Math.floor(lo / st) * st : 0; mx = hi > 0 ? Math.ceil(hi / st) * st : 0 }
|
|
424
|
+
const cnt = Math.max(1, Math.round((mx - mn) / st))
|
|
425
|
+
return { min: mn, max: mx, span: mx - mn || 1, ticks: Array.from({ length: cnt + 1 }, (_, i) => Number((mn + i * st).toFixed(8))) }
|
|
426
|
+
}
|
|
427
|
+
const rect = (x, y, w, h, color, rx = 3) => `<rect x="${x.toFixed(1)}" y="${y.toFixed(1)}" width="${Math.max(0, w).toFixed(1)}" height="${Math.max(0, h).toFixed(1)}" rx="${rx}" fill="${color}"/>`
|
|
428
|
+
const text = (x, y, content, anchor = 'start', color = fg, size = 16, weight = 400) => `<text x="${x.toFixed(1)}" y="${y.toFixed(1)}" text-anchor="${anchor}" fill="${color}" font-size="${size}" font-weight="${weight}">${esc(content)}</text>`
|
|
429
|
+
const line = (x1, y1, x2, y2, color = gridColor, sw = 1, dash = '') => `<line x1="${x1.toFixed(1)}" y1="${y1.toFixed(1)}" x2="${x2.toFixed(1)}" y2="${y2.toFixed(1)}" stroke="${color}" stroke-width="${sw}"${dash ? ` stroke-dasharray="${dash}"` : ''}/>`
|
|
430
|
+
|
|
431
|
+
const resolveHighlights = (vals, hl) => {
|
|
432
|
+
if (hl === undefined || hl === null || hl === 'none') return null
|
|
433
|
+
if (typeof hl === 'number') return new Set([hl])
|
|
434
|
+
if (Array.isArray(hl)) return new Set(hl)
|
|
435
|
+
if (hl === 'last') return new Set([vals.length - 1])
|
|
436
|
+
if (hl === 'max') {
|
|
437
|
+
let best = 0
|
|
438
|
+
for (let i = 1; i < vals.length; i++) if (vals[i] > vals[best]) best = i
|
|
439
|
+
return new Set([best])
|
|
440
|
+
}
|
|
441
|
+
if (hl === 'min') {
|
|
442
|
+
let best = 0
|
|
443
|
+
for (let i = 1; i < vals.length; i++) if (vals[i] < vals[best]) best = i
|
|
444
|
+
return new Set([best])
|
|
445
|
+
}
|
|
446
|
+
return null
|
|
447
|
+
}
|
|
448
|
+
|
|
77
449
|
let shapes = ''
|
|
78
|
-
|
|
450
|
+
const kind = chart.kind || 'column'
|
|
451
|
+
const showLegend = chart.showLegend === true || (chart.showLegend !== false && chart.series.length > 1 && kind !== 'pie' && kind !== 'doughnut' && kind !== 'waterfall')
|
|
452
|
+
const showDirectValues = chart.showValues === true || (chart.showValues !== false && n <= 8)
|
|
453
|
+
|
|
454
|
+
if (kind === 'pie' || kind === 'doughnut') {
|
|
79
455
|
const values = chart.series[0].values, sum = values.reduce((a, b) => a + b, 0)
|
|
456
|
+
const cx = 330, cy = 212, r = 164, innerR = kind === 'doughnut' ? r * 0.62 : (chart.holeSizePct ? r * (chart.holeSizePct / 100) : r * 0.56)
|
|
457
|
+
const useDonut = kind === 'doughnut'
|
|
80
458
|
let angle = -Math.PI / 2
|
|
81
459
|
values.forEach((value, i) => {
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
460
|
+
const sliceColor = colors[i % colors.length]
|
|
461
|
+
const sweep = (value / sum) * Math.PI * 2
|
|
462
|
+
const next = angle + sweep
|
|
463
|
+
if (value === sum) {
|
|
464
|
+
shapes += `<circle cx="${cx}" cy="${cy}" r="${r}" fill="${sliceColor}"/>`
|
|
465
|
+
if (useDonut) shapes += `<circle cx="${cx}" cy="${cy}" r="${innerR}" fill="${bg}"/>`
|
|
466
|
+
} else if (value > 0) {
|
|
467
|
+
const large = sweep > Math.PI ? 1 : 0
|
|
468
|
+
const x1 = cx + Math.cos(angle) * r, y1 = cy + Math.sin(angle) * r
|
|
469
|
+
const x2 = cx + Math.cos(next) * r, y2 = cy + Math.sin(next) * r
|
|
470
|
+
if (useDonut) {
|
|
471
|
+
const ix1 = cx + Math.cos(next) * innerR, iy1 = cy + Math.sin(next) * innerR
|
|
472
|
+
const ix2 = cx + Math.cos(angle) * innerR, iy2 = cy + Math.sin(angle) * innerR
|
|
473
|
+
shapes += `<path d="M ${x1.toFixed(2)} ${y1.toFixed(2)} A ${r} ${r} 0 ${large} 1 ${x2.toFixed(2)} ${y2.toFixed(2)} L ${ix1.toFixed(2)} ${iy1.toFixed(2)} A ${innerR} ${innerR} 0 ${large} 0 ${ix2.toFixed(2)} ${iy2.toFixed(2)} Z" fill="${sliceColor}" stroke="${bg}" stroke-width="2"/>`
|
|
474
|
+
} else {
|
|
475
|
+
shapes += `<path d="M ${cx} ${cy} L ${x1.toFixed(2)} ${y1.toFixed(2)} A ${r} ${r} 0 ${large} 1 ${x2.toFixed(2)} ${y2.toFixed(2)} Z" fill="${sliceColor}" stroke="${bg}" stroke-width="2"/>`
|
|
476
|
+
}
|
|
477
|
+
}
|
|
85
478
|
angle = next
|
|
86
|
-
const
|
|
87
|
-
shapes += rect(
|
|
88
|
-
|
|
479
|
+
const rowY = 58 + i * 31
|
|
480
|
+
shapes += rect(590, rowY - 13, 14, 14, sliceColor, 3)
|
|
481
|
+
shapes += text(616, rowY, chart.categories[i], 'start', fg, 16, i === 0 ? 600 : 400)
|
|
482
|
+
shapes += text(1080, rowY, `${fmtNum(value)} (${(value / sum * 100).toFixed(1)}%)`, 'end', muted, 15, 600)
|
|
483
|
+
})
|
|
484
|
+
if (useDonut) {
|
|
485
|
+
shapes += text(cx, cy - 4, fmtNum(sum), 'middle', fg, 28, 700)
|
|
486
|
+
shapes += text(cx, cy + 22, chart.unit || chart.series[0].name, 'middle', muted, 14, 500)
|
|
487
|
+
}
|
|
488
|
+
} else if (kind === 'waterfall') {
|
|
489
|
+
const vals = chart.series[0].values
|
|
490
|
+
const explicit = new Set(Array.isArray(chart.totalIndices) ? chart.totalIndices : [])
|
|
491
|
+
if (explicit.size === 0 && n >= 1) {
|
|
492
|
+
explicit.add(0)
|
|
493
|
+
if (n >= 3) {
|
|
494
|
+
const prior = vals.slice(0, -1).reduce((a, b) => a + b, 0)
|
|
495
|
+
if (/(?:^(?:合计|总计|总和|期末|净\S*|最终|Total|Sum|Net|End|Ending|Final|Target)|(?:合计|总计|净额|净值|净利|利润|总和)$)/i.test(String(chart.categories[n - 1] ?? '')) && Math.abs(vals[n - 1] - prior) <= Math.max(1e-6, Math.abs(prior) * 1e-4)) {
|
|
496
|
+
explicit.add(n - 1)
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
let running = 0
|
|
501
|
+
const rawBars = vals.map((v, idx) => {
|
|
502
|
+
const isTotal = explicit.has(idx)
|
|
503
|
+
const s = isTotal ? 0 : running
|
|
504
|
+
const e = isTotal ? v : running + v
|
|
505
|
+
running = e
|
|
506
|
+
return { value: v, start: s, end: e, isTotal }
|
|
507
|
+
})
|
|
508
|
+
const pts = [0, ...rawBars.flatMap(b => [b.start, b.end])]
|
|
509
|
+
const { min, max, span, ticks: wfTicks } = niceBounds(Math.min(...pts), Math.max(...pts))
|
|
510
|
+
const left = 88, right = 1088, top = 32, bottom = 348
|
|
511
|
+
const y = v => bottom - ((v - min) / span) * (bottom - top)
|
|
512
|
+
for (const tv of wfTicks) {
|
|
513
|
+
shapes += line(left, y(tv), right, y(tv), gridColor, 1) + text(left - 12, y(tv) + 5, fmtNum(tv), 'end', muted, 14)
|
|
514
|
+
}
|
|
515
|
+
const gw = (right - left) / n, bw = Math.max(10, gw * 0.56)
|
|
516
|
+
const coords = rawBars.map((b, idx) => {
|
|
517
|
+
const bx = left + idx * gw + (gw - bw) / 2
|
|
518
|
+
const yt = y(Math.max(b.start, b.end)), yb = y(Math.min(b.start, b.end))
|
|
519
|
+
const col = b.isTotal ? focalColor : b.value >= 0 ? posColor : negColor
|
|
520
|
+
shapes += rect(bx, yt, bw, Math.max(2, yb - yt), col, 4)
|
|
521
|
+
const lbl = (!b.isTotal && b.value > 0 ? '+' : '') + fmtNum(b.value)
|
|
522
|
+
const ly = b.value >= 0 || b.isTotal ? yt - 8 : yb + 18
|
|
523
|
+
shapes += text(bx + bw / 2, ly, lbl, 'middle', b.isTotal ? fg : col, 14, 700)
|
|
524
|
+
shapes += text(bx + bw / 2, bottom + 28, chart.categories[idx], 'middle', fg, 15)
|
|
525
|
+
return { x: bx, w: bw, yEnd: y(b.end) }
|
|
526
|
+
})
|
|
527
|
+
for (let i = 0; i < coords.length - 1; i++) {
|
|
528
|
+
shapes += line(coords[i].x + coords[i].w, coords[i].yEnd, coords[i + 1].x, coords[i].yEnd, muted, 1.2, '4 3')
|
|
529
|
+
}
|
|
530
|
+
shapes += line(left, y(0), right, y(0), axisColor, 1.5)
|
|
531
|
+
} else if (kind === 'scatter') {
|
|
532
|
+
const left = 88, right = 1088, top = showLegend ? 46 : 24, bottom = 346
|
|
533
|
+
const allX = chart.series.flatMap((s, si) => s.xValues ?? s.values.map((_, i) => i + 1 + si * 0))
|
|
534
|
+
const allY = chart.series.flatMap(s => s.values)
|
|
535
|
+
const minX = Math.min(...allX), maxX = Math.max(...allX), spanX = maxX - minX || 1
|
|
536
|
+
const minY = Math.min(0, ...allY), maxY = Math.max(...allY), spanY = maxY - minY || 1
|
|
537
|
+
const sx = v => left + ((v - minX) / spanX) * (right - left)
|
|
538
|
+
const sy = v => bottom - ((v - minY) / spanY) * (bottom - top)
|
|
539
|
+
for (let t = 0; t <= 4; t++) {
|
|
540
|
+
const vy = minY + (spanY * t) / 4, vx = minX + (spanX * t) / 4
|
|
541
|
+
shapes += line(left, sy(vy), right, sy(vy), gridColor, 1) + text(left - 12, sy(vy) + 5, fmtNum(vy), 'end', muted, 14)
|
|
542
|
+
shapes += line(sx(vx), top, sx(vx), bottom, gridColor, 0.75, '3 3') + text(sx(vx), bottom + 26, fmtNum(vx), 'middle', muted, 14)
|
|
543
|
+
}
|
|
544
|
+
shapes += line(left, bottom, right, bottom, axisColor, 1.4) + line(left, top, left, bottom, axisColor, 1.4)
|
|
545
|
+
chart.series.forEach((s, si) => {
|
|
546
|
+
const col = colors[si % colors.length]
|
|
547
|
+
const xs = s.xValues ?? s.values.map((_, i) => i + 1)
|
|
548
|
+
s.values.forEach((vy, i) => {
|
|
549
|
+
const px = sx(xs[i]), py = sy(vy)
|
|
550
|
+
shapes += `<circle cx="${px.toFixed(1)}" cy="${py.toFixed(1)}" r="6.5" fill="${col}" fill-opacity="0.86" stroke="${bg}" stroke-width="1.5"/>`
|
|
551
|
+
if (showDirectValues && chart.series.length === 1) shapes += text(px, py - 11, chart.categories[i] || fmtNum(vy), 'middle', muted, 13)
|
|
552
|
+
})
|
|
89
553
|
})
|
|
90
554
|
} else {
|
|
91
|
-
const
|
|
92
|
-
const
|
|
93
|
-
const
|
|
94
|
-
const
|
|
555
|
+
const isHoriz = kind === 'bar' || kind === 'stacked-bar' || kind === 'percent-bar'
|
|
556
|
+
const isStacked = kind === 'stacked-column' || kind === 'stacked-bar'
|
|
557
|
+
const isPercent = kind === 'percent-column' || kind === 'percent-bar'
|
|
558
|
+
const left = isHoriz ? 186 : 86, right = kind === 'combo' && chart.series.some(s => s.secondaryAxis) ? 1028 : 1088
|
|
559
|
+
const top = showLegend ? 50 : 28, bottom = 348
|
|
560
|
+
|
|
561
|
+
let min = 0, max = 1
|
|
562
|
+
if (isPercent) {
|
|
563
|
+
min = 0; max = 100
|
|
564
|
+
} else if (isStacked) {
|
|
565
|
+
const posSums = chart.categories.map((_, i) => chart.series.reduce((acc, s) => acc + Math.max(0, s.values[i]), 0))
|
|
566
|
+
const negSums = chart.categories.map((_, i) => chart.series.reduce((acc, s) => acc + Math.min(0, s.values[i]), 0))
|
|
567
|
+
min = Math.min(0, ...negSums)
|
|
568
|
+
max = Math.max(0, ...posSums) * 1.1 || 1
|
|
569
|
+
} else {
|
|
570
|
+
const primarySeries = kind === 'combo' ? chart.series.filter(s => !s.secondaryAxis) : chart.series
|
|
571
|
+
const values = (primarySeries.length ? primarySeries : chart.series).flatMap(s => s.values)
|
|
572
|
+
const rMin = Math.min(0, ...values), rMax = Math.max(0, ...values)
|
|
573
|
+
min = rMin < 0 ? rMin * 1.12 : 0
|
|
574
|
+
max = rMax > 0 ? rMax * 1.14 : (rMin === 0 ? 1 : 0)
|
|
575
|
+
}
|
|
576
|
+
const span = max - min || 1
|
|
577
|
+
const y = value => bottom - ((value - min) / span) * (bottom - top)
|
|
578
|
+
const x = value => left + ((value - min) / span) * (right - left)
|
|
579
|
+
|
|
95
580
|
for (let tick = 0; tick <= 4; tick++) {
|
|
96
|
-
const value = min + span * tick / 4
|
|
97
|
-
|
|
98
|
-
|
|
581
|
+
const value = min + (span * tick) / 4
|
|
582
|
+
const label = isPercent ? `${Math.round(value)}%` : fmtNum(value)
|
|
583
|
+
if (isHoriz) shapes += line(x(value), top, x(value), bottom, gridColor, 1) + text(x(value), bottom + 26, label, 'middle', muted, 14)
|
|
584
|
+
else shapes += line(left, y(value), right, y(value), gridColor, 1) + text(left - 12, y(value) + 5, label, 'end', muted, 14)
|
|
99
585
|
}
|
|
586
|
+
|
|
100
587
|
chart.categories.forEach((category, i) => {
|
|
101
|
-
if (
|
|
102
|
-
else shapes += text(left + (i + 0.5) * (right - left) / n, bottom +
|
|
588
|
+
if (isHoriz) shapes += text(left - 14, top + (i + 0.5) * (bottom - top) / n + 5, category, 'end', fg, 15)
|
|
589
|
+
else shapes += text(left + (i + 0.5) * (right - left) / n, bottom + 28, category, 'middle', fg, 15)
|
|
103
590
|
})
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
const
|
|
116
|
-
|
|
591
|
+
|
|
592
|
+
const singleHighlights = chart.series.length === 1 && (kind === 'column' || kind === 'bar')
|
|
593
|
+
? resolveHighlights(chart.series[0].values, chart.highlight)
|
|
594
|
+
: null
|
|
595
|
+
|
|
596
|
+
if (isStacked || isPercent) {
|
|
597
|
+
chart.categories.forEach((_, i) => {
|
|
598
|
+
const totalAbs = chart.series.reduce((acc, s) => acc + Math.max(0, s.values[i]), 0) || 1
|
|
599
|
+
let posRun = 0, negRun = 0
|
|
600
|
+
chart.series.forEach((s, si) => {
|
|
601
|
+
const rawV = s.values[i]
|
|
602
|
+
const v = isPercent ? (Math.max(0, rawV) / totalAbs) * 100 : rawV
|
|
603
|
+
const start = v >= 0 ? posRun : negRun
|
|
604
|
+
const end = start + v
|
|
605
|
+
if (v >= 0) posRun = end; else negRun = end
|
|
606
|
+
const color = colors[si % colors.length]
|
|
607
|
+
if (isHoriz) {
|
|
608
|
+
const group = (bottom - top) / n, h = Math.max(4, group * 0.62)
|
|
609
|
+
shapes += rect(Math.min(x(start), x(end)), top + i * group + (group - h) / 2, Math.abs(x(end) - x(start)), h, color, 2)
|
|
610
|
+
} else {
|
|
611
|
+
const group = (right - left) / n, w = Math.max(6, group * 0.58)
|
|
612
|
+
shapes += rect(left + i * group + (group - w) / 2, Math.min(y(start), y(end)), w, Math.abs(y(end) - y(start)), color, 2)
|
|
613
|
+
}
|
|
614
|
+
})
|
|
615
|
+
})
|
|
616
|
+
} else {
|
|
617
|
+
const barSeries = chart.series.filter((s, si) => kind === 'combo' ? (s.chartKind || (si === 0 ? 'column' : 'line')) === 'column' || s.chartKind === 'bar' : (kind === 'column' || kind === 'bar'))
|
|
618
|
+
const lineSeries = chart.series.filter((s, si) => kind === 'combo' ? ['line', 'area'].includes(s.chartKind || (si === 0 ? 'column' : 'line')) : (kind === 'line' || kind === 'area'))
|
|
619
|
+
|
|
620
|
+
// Secondary axis scale for combo charts if needed
|
|
621
|
+
const secSeries = chart.series.filter(s => s.secondaryAxis)
|
|
622
|
+
const secVals = secSeries.flatMap(s => s.values)
|
|
623
|
+
const secMin = secVals.length ? Math.min(0, ...secVals) : 0
|
|
624
|
+
const secMax = secVals.length ? (Math.max(0, ...secVals) * 1.15 || 1) : 1
|
|
625
|
+
const secSpan = secMax - secMin || 1
|
|
626
|
+
const ySec = v => bottom - ((v - secMin) / secSpan) * (bottom - top)
|
|
627
|
+
if (secSeries.length) {
|
|
628
|
+
for (let t = 0; t <= 4; t++) {
|
|
629
|
+
const sv = secMin + (secSpan * t) / 4
|
|
630
|
+
shapes += text(right + 10, ySec(sv) + 5, fmtNum(sv), 'start', colors[chart.series.indexOf(secSeries[0]) % colors.length], 13)
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
barSeries.forEach((series, bIdx) => {
|
|
635
|
+
const origIdx = chart.series.indexOf(series)
|
|
636
|
+
series.values.forEach((v, i) => {
|
|
637
|
+
const isFocal = singleHighlights ? singleHighlights.has(i) : true
|
|
638
|
+
const color = singleHighlights ? (isFocal ? focalColor : neutralColor) : colors[origIdx % colors.length]
|
|
639
|
+
const mapY = series.secondaryAxis ? ySec : y
|
|
640
|
+
if (isHoriz) {
|
|
641
|
+
const group = (bottom - top) / n, h = (group * 0.66) / Math.max(1, barSeries.length)
|
|
642
|
+
const by = top + i * group + group * 0.17 + bIdx * h
|
|
643
|
+
const bx = Math.min(x(0), x(v)), bw = Math.abs(x(v) - x(0))
|
|
644
|
+
shapes += rect(bx, by, bw, Math.max(2, h - 2), color, 3)
|
|
645
|
+
if (showDirectValues && barSeries.length <= 2) {
|
|
646
|
+
shapes += text(v >= 0 ? bx + bw + 8 : bx - 8, by + h / 2 + 4, fmtNum(v), v >= 0 ? 'start' : 'end', isFocal ? fg : muted, 14, isFocal && singleHighlights ? 700 : 500)
|
|
647
|
+
}
|
|
648
|
+
} else {
|
|
649
|
+
const group = (right - left) / n, w = (group * 0.62) / Math.max(1, barSeries.length)
|
|
650
|
+
const bx = left + i * group + group * 0.19 + bIdx * w
|
|
651
|
+
const by = Math.min(mapY(0), mapY(v)), bh = Math.abs(mapY(v) - mapY(0))
|
|
652
|
+
shapes += rect(bx, by, Math.max(3, w - 3), bh, color, 3)
|
|
653
|
+
if (showDirectValues && barSeries.length <= 2) {
|
|
654
|
+
if (kind === 'combo' && bh >= 24 && v >= 0) {
|
|
655
|
+
shapes += text(bx + (w - 3) / 2, by + 18, fmtNum(v), 'middle', tokens.inkOnAccent || '#FFFFFF', 13, 700)
|
|
656
|
+
} else {
|
|
657
|
+
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
|
+
}
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
})
|
|
662
|
+
})
|
|
663
|
+
|
|
664
|
+
lineSeries.forEach((series) => {
|
|
665
|
+
const origIdx = chart.series.indexOf(series)
|
|
666
|
+
const color = colors[origIdx % colors.length]
|
|
667
|
+
const mapY = series.secondaryAxis ? ySec : y
|
|
668
|
+
const pts = series.values.map((v, i) => [left + (i + 0.5) * (right - left) / n, mapY(v)])
|
|
669
|
+
const isArea = kind === 'area' || series.chartKind === 'area'
|
|
670
|
+
if (isArea && pts.length >= 2) {
|
|
671
|
+
const poly = `M ${pts[0][0].toFixed(1)} ${mapY(0).toFixed(1)} ` + pts.map(p => `L ${p[0].toFixed(1)} ${p[1].toFixed(1)}`).join(' ') + ` L ${pts.at(-1)[0].toFixed(1)} ${mapY(0).toFixed(1)} Z`
|
|
672
|
+
shapes += `<path d="${poly}" fill="${color}" fill-opacity="0.18"/>`
|
|
117
673
|
}
|
|
674
|
+
shapes += `<polyline points="${pts.map(p => `${p[0].toFixed(1)},${p[1].toFixed(1)}`).join(' ')}" fill="none" stroke="${color}" stroke-width="3.5" stroke-linecap="round" stroke-linejoin="round"/>`
|
|
675
|
+
pts.forEach(([px, py], i) => {
|
|
676
|
+
shapes += `<circle cx="${px.toFixed(1)}" cy="${py.toFixed(1)}" r="5" fill="${color}" stroke="${bg}" stroke-width="2"/>`
|
|
677
|
+
if (showDirectValues && lineSeries.length === 1 && (barSeries.length === 0 || kind === 'combo')) {
|
|
678
|
+
shapes += text(px, py - 12, fmtNum(series.values[i]), 'middle', kind === 'combo' ? color : fg, 14, 700)
|
|
679
|
+
}
|
|
680
|
+
})
|
|
118
681
|
})
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
shapes += isHoriz ? line(x(0), top, x(0), bottom, axisColor, 1.5) : line(left, y(0), right, y(0), axisColor, 1.5)
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
if (showLegend) {
|
|
688
|
+
chart.series.forEach((s, i) => {
|
|
689
|
+
const lx = 86 + i * 172
|
|
690
|
+
shapes += rect(lx, 8, 12, 12, colors[i % colors.length], 3) + text(lx + 19, 19, s.name, 'start', fg, 15, 600)
|
|
119
691
|
})
|
|
120
|
-
shapes += chart.kind === 'bar' ? line(x(0), top, x(0), bottom, fg) : line(left, y(0), right, y(0), fg)
|
|
121
|
-
chart.series.forEach((s, i) => { shapes += rect(left + i * 175, 397, 14, 14, colors[i % colors.length]) + text(left + 22 + i * 175, 410, s.name, 'start', fg, 17) })
|
|
122
692
|
}
|
|
123
|
-
if (chart.unit) shapes += text(
|
|
124
|
-
|
|
693
|
+
if (chart.unit) shapes += text(1088, showLegend ? 20 : 18, `${chart.unit}`, 'end', muted, 14, 500)
|
|
694
|
+
|
|
125
695
|
const table = '<table class="chart-data"><caption>' + esc(chart.caption || 'Chart data') + '</caption><thead><tr><th></th>' + chart.series.map(s => `<th>${esc(s.name)}</th>`).join('') + '</tr></thead><tbody>'
|
|
126
696
|
+ chart.categories.map((c, i) => `<tr><th>${esc(c)}</th>${chart.series.map(s => `<td>${s.values[i]}</td>`).join('')}</tr>`).join('') + '</tbody></table>'
|
|
127
|
-
return `<svg class="native-chart" viewBox="0 0 ${width} ${height}" role="img" aria-label="${esc(chart.caption ||
|
|
697
|
+
return `<svg class="native-chart" viewBox="0 0 ${width} ${height}" role="img" aria-label="${esc(chart.caption || kind + ' chart')}"><title>${esc(chart.caption || kind)}</title>${shapes}</svg>${table}`
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
function formatInlineHtml(rawText) {
|
|
701
|
+
const str = String(rawText ?? '')
|
|
702
|
+
if (!/[*`]/.test(str)) {
|
|
703
|
+
const colonMatch = /^([^::]{1,12})([::]\s*)([\s\S]+)$/.exec(str)
|
|
704
|
+
if (colonMatch) return `<strong>${esc(colonMatch[1] + colonMatch[2])}</strong>${esc(colonMatch[3])}`
|
|
705
|
+
return esc(str)
|
|
706
|
+
}
|
|
707
|
+
const tokenRe = /\*\*([^*]+)\*\*|\*([^*\n]+)\*|`([^`]+)`/g
|
|
708
|
+
let out = '', last = 0
|
|
709
|
+
for (const m of str.matchAll(tokenRe)) {
|
|
710
|
+
out += esc(str.slice(last, m.index))
|
|
711
|
+
if (m[1] !== undefined) out += `<strong>${esc(m[1])}</strong>`
|
|
712
|
+
else if (m[2] !== undefined) out += `<em>${esc(m[2])}</em>`
|
|
713
|
+
else if (m[3] !== undefined) out += `<code class="media-code">${esc(m[3])}</code>`
|
|
714
|
+
last = m.index + m[0].length
|
|
715
|
+
}
|
|
716
|
+
out += esc(str.slice(last))
|
|
717
|
+
return out
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
function projectInsightCards(slide) {
|
|
721
|
+
if (Array.isArray(slide.items) && slide.items.length > 0) return slide.items.slice(0, 4)
|
|
722
|
+
const bullets = Array.isArray(slide.bullets) ? slide.bullets : []
|
|
723
|
+
if (bullets.length > 0) {
|
|
724
|
+
return bullets.slice(0, 4).map((b, idx) => {
|
|
725
|
+
const cleaned = b.replace(/^\*\*([^*]+)\*\*\s*[::—-]?\s*/, (_, lead) => `${lead}\u0000`)
|
|
726
|
+
if (cleaned.includes('\u0000')) {
|
|
727
|
+
const [title, text] = cleaned.split('\u0000')
|
|
728
|
+
return { tag: `0${idx + 1}`, title: title.trim(), text: text.trim() }
|
|
729
|
+
}
|
|
730
|
+
const colon = /^([^::]{1,14})[::]\s*(.+)$/.exec(b)
|
|
731
|
+
if (colon) return { tag: `0${idx + 1}`, title: colon[1].trim(), text: colon[2].trim() }
|
|
732
|
+
return { tag: `0${idx + 1}`, text: b }
|
|
733
|
+
})
|
|
734
|
+
}
|
|
735
|
+
if (slide.subtitle) return [{ tag: 'INSIGHT', title: '', text: slide.subtitle }]
|
|
736
|
+
return []
|
|
128
737
|
}
|
|
129
738
|
|
|
130
739
|
export function renderMediaHtml(slide, manifest, theme) {
|
|
131
|
-
const boxes = mediaBoxes(slide.layout)
|
|
132
|
-
|
|
133
|
-
|
|
740
|
+
const boxes = mediaBoxes(slide.layout, slide.variant, slide)
|
|
741
|
+
const variant = String(slide.variant ?? '').trim().toLowerCase()
|
|
742
|
+
const chromeStyle = resolveChromeStyle(theme, slide, manifest?.brand)
|
|
743
|
+
const slidesArr = Array.isArray(manifest?.slides) ? manifest.slides : []
|
|
744
|
+
const foundIdx = slidesArr.findIndex((s) => s === slide || (slide?.id && s?.id === slide.id))
|
|
745
|
+
const slideIndex = foundIdx >= 0 ? foundIdx : 0
|
|
746
|
+
const totalSlides = Math.max(1, slidesArr.length)
|
|
747
|
+
const folioText = String(slideIndex + 1).padStart(2, '0') + ' / ' + String(totalSlides).padStart(2, '0')
|
|
748
|
+
const langEn = manifest?.language === 'en'
|
|
749
|
+
const isBleed = variant === 'full-bleed' || variant === 'split-bleed'
|
|
750
|
+
|
|
751
|
+
let body = ''
|
|
752
|
+
if (!isBleed && chromeStyle === 'academic-minimal') {
|
|
753
|
+
body += `<div class="media-beamer-band">` +
|
|
754
|
+
(slide.kicker && slide.kicker !== slide.title ? `<div class="kicker media-kicker-band">${esc(slide.kicker)}</div>` : '') +
|
|
755
|
+
`<h2 class="media-title-band">${esc(slide.title)}</h2>` +
|
|
756
|
+
`</div>`
|
|
757
|
+
} else if (!isBleed && chromeStyle === 'editorial-folio') {
|
|
758
|
+
body += `<div class="media-editorial-bar">` +
|
|
759
|
+
(slide.kicker && slide.kicker !== slide.title ? `<span class="kicker media-kicker-inline">${esc(slide.kicker)}</span>` : '<span class="kicker media-kicker-inline"></span>') +
|
|
760
|
+
`<span class="slide-folio">${folioText}</span>` +
|
|
761
|
+
`</div>` +
|
|
762
|
+
`<h2 class="media-title media-title--editorial" style="${position(boxes.title)}">${esc(slide.title)}</h2>`
|
|
763
|
+
} else if (!isBleed && chromeStyle === 'consulting-classic') {
|
|
764
|
+
if (slide.kicker && slide.kicker !== slide.title) {
|
|
765
|
+
body += `<div class="kicker media-consulting-tracker">${esc(slide.kicker)}</div>`
|
|
766
|
+
}
|
|
767
|
+
body += `<h2 class="media-title media-title--ruled" style="${position({ ...boxes.title, w: slide.kicker && slide.kicker !== slide.title ? 9.4 : boxes.title.w })}">${esc(slide.title)}</h2>`
|
|
768
|
+
} else if (!isBleed && chromeStyle === 'gov-ceremonial') {
|
|
769
|
+
if (slide.kicker && slide.kicker !== slide.title) {
|
|
770
|
+
const gk = /^【/.test(slide.kicker.trim()) ? slide.kicker.trim() : '【' + slide.kicker.trim() + '】'
|
|
771
|
+
body += `<div class="kicker media-kicker" style="${position(boxes.kicker)}">${esc(gk)}</div>`
|
|
772
|
+
}
|
|
773
|
+
body += `<h2 class="media-title media-title--gov" style="${position(boxes.title)}">${esc(slide.title)}</h2>`
|
|
774
|
+
} else {
|
|
775
|
+
if (slide.kicker && slide.kicker !== slide.title && variant !== 'full-bleed') {
|
|
776
|
+
const kickerCls = chromeStyle === 'keynote-spatial' ? 'kicker media-kicker media-kicker--pill' : 'kicker media-kicker'
|
|
777
|
+
body += `<div class="${kickerCls}" style="${position(boxes.kicker)}">${esc(slide.kicker)}</div>`
|
|
778
|
+
}
|
|
779
|
+
const titleCls = variant === 'full-bleed'
|
|
780
|
+
? 'media-title media-title--bleed'
|
|
781
|
+
: (chromeStyle === 'keynote-spatial' ? 'media-title' : 'media-title media-title--ruled')
|
|
782
|
+
body += `<h2 class="${titleCls}" style="${position(boxes.title)}">${esc(slide.title)}</h2>`
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
if (slide.layout === 'chart' || slide.layout === 'chart-split') {
|
|
134
786
|
body += `<div class="media-chart" style="${position(boxes.chart)}">${renderChartSvg(slide.chart, theme)}</div>`
|
|
135
|
-
if (slide.
|
|
787
|
+
if (slide.layout === 'chart-split' && boxes.body) {
|
|
788
|
+
const cards = projectInsightCards(slide)
|
|
789
|
+
const cardsHtml = cards.map((card, idx) =>
|
|
790
|
+
`<div class="media-insight-card" data-item-index="${idx}">` +
|
|
791
|
+
(card.value ? `<div class="media-insight-val" data-item-field="value">${esc(card.value)}${card.unit ? `<small>${esc(card.unit)}</small>` : ''}</div>` : (card.tag ? `<span class="media-insight-tag" data-item-field="tag">${esc(card.tag)}</span>` : '')) +
|
|
792
|
+
(card.title ? `<strong class="media-insight-head" data-item-field="title">${formatInlineHtml(card.title)}</strong>` : '') +
|
|
793
|
+
(card.text ? `<p class="media-insight-text" data-item-field="text">${formatInlineHtml(card.text)}</p>` : '') +
|
|
794
|
+
`</div>`
|
|
795
|
+
).join('')
|
|
796
|
+
body += `<div class="media-body media-insights" style="${position(boxes.body)}">${cardsHtml}</div>`
|
|
797
|
+
}
|
|
798
|
+
const cap = slide.chart?.caption
|
|
799
|
+
if (cap) body += `<div class="media-caption" style="${position(boxes.caption)}">${esc(cap)}</div>`
|
|
136
800
|
} else {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
801
|
+
if (Array.isArray(boxes.gallery) && Array.isArray(slide.images) && slide.images.length > 1) {
|
|
802
|
+
boxes.gallery.forEach((gBox, idx) => {
|
|
803
|
+
const img = slide.images[idx]
|
|
804
|
+
const asset = manifest.assets?.[img?.assetId]
|
|
805
|
+
body += `<figure class="media-image media-image--framed" style="${position(gBox)}"><img src="${esc(asset?.data ?? '')}" alt="${esc(img?.alt)}" style="object-fit:${img?.fit || 'cover'}"/>${img?.caption ? `<figcaption>${esc(img.caption)}</figcaption>` : ''}</figure>`
|
|
806
|
+
})
|
|
807
|
+
} else {
|
|
808
|
+
const image = slide.image, asset = manifest.assets?.[image?.assetId]
|
|
809
|
+
const frameClass = variant === 'split-bleed' || variant === 'full-bleed' ? 'media-image--bleed' : 'media-image--framed'
|
|
810
|
+
body += `<figure class="media-image ${frameClass}" style="${position(boxes.image)}"><img src="${esc(asset?.data ?? '')}" alt="${esc(image?.alt)}" style="object-fit:${image?.fit || 'contain'}"/></figure>`
|
|
811
|
+
}
|
|
812
|
+
if (boxes.body) {
|
|
813
|
+
const lead = slide.subtitle ? `<p class="media-lead">${formatInlineHtml(slide.subtitle)}</p>` : ''
|
|
814
|
+
const list = slide.bullets?.length ? `<ul class="media-list">${slide.bullets.map(b => `<li>${formatInlineHtml(b)}</li>`).join('')}</ul>` : ''
|
|
815
|
+
body += `<div class="media-body" style="${position(boxes.body)}">${lead}${list}</div>`
|
|
816
|
+
}
|
|
817
|
+
if (slide.image?.caption) {
|
|
818
|
+
body += `<div class="media-caption" style="${position(boxes.caption)}">${esc(slide.image.caption)}</div>`
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
if (slide.takeaway) {
|
|
823
|
+
const arrowChar = chromeStyle === 'editorial-folio' ? '—' : '▸'
|
|
824
|
+
const prefix = chromeStyle === 'consulting-classic' || chromeStyle === 'academic-minimal'
|
|
825
|
+
? `<strong class="takeaway-prefix">${langEn ? 'Key Takeaway:' : '核心结论:'}</strong>`
|
|
826
|
+
: ''
|
|
827
|
+
body += `<div class="media-takeaway takeaway-bar" style="${position(boxes.takeaway)}"><span class="takeaway-arrow" aria-hidden="true">${arrowChar}</span>${prefix}<span class="takeaway-text">${formatInlineHtml(slide.takeaway)}</span></div>`
|
|
828
|
+
}
|
|
829
|
+
const srcText = slide.source || slide.chart?.source
|
|
830
|
+
if (chromeStyle === 'academic-minimal') {
|
|
831
|
+
const zLeft = srcText || manifest?.brand?.footer || manifest?.title || ''
|
|
832
|
+
const zMid = (slide.kicker || slide.title || '').trim()
|
|
833
|
+
body += `<footer class="media-beamer-status"><span class="media-beamer-left">${esc(zLeft)}</span><span class="media-beamer-mid">${esc(zMid)}</span><span class="media-beamer-right">${folioText}</span></footer>`
|
|
834
|
+
} else if (srcText) {
|
|
835
|
+
body += `<div class="media-source">${esc(srcText)}</div>`
|
|
141
836
|
}
|
|
142
837
|
return `<div class="media-canvas">${body}</div>`
|
|
143
838
|
}
|
|
144
839
|
|
|
840
|
+
/**
|
|
841
|
+
* Compile publication-grade ChartSpec for @office-kit/pptx (all non-waterfall chart types).
|
|
842
|
+
*/
|
|
843
|
+
export function buildOfficeKitChartSpec(chart, theme, visual = {}, font = 'Microsoft YaHei') {
|
|
844
|
+
const colors = chartColors(theme)
|
|
845
|
+
const tokens = theme?.tokens || {}
|
|
846
|
+
const bg = tokens.canvas || theme?.palette?.bg || '#FFFFFF'
|
|
847
|
+
const fg = tokens.inkPrimary || theme?.palette?.fg || '#0F172A'
|
|
848
|
+
const muted = tokens.inkMuted || theme?.palette?.muted || '#64748B'
|
|
849
|
+
const hairline = tokens.hairline || (theme?.dark ? '#263554' : '#D5DFEC')
|
|
850
|
+
const axisLine = tokens.inkSecondary || muted
|
|
851
|
+
const focalColor = tokens.chartFocal || colors[0]
|
|
852
|
+
const neutralColor = tokens.chartNeutral || (theme?.dark ? '#2B354D' : '#CBD5E1')
|
|
853
|
+
|
|
854
|
+
const sizePt = visual?.chartLabelSize ?? 14
|
|
855
|
+
const labelStyle = { font, sizePt, color: fg }
|
|
856
|
+
const axisLabelStyle = { font, sizePt: Math.max(11, sizePt - 2), color: muted }
|
|
857
|
+
const n = chart.categories.length
|
|
858
|
+
const kind = chart.kind
|
|
859
|
+
const showDirectValues = chart.showValues === true || (chart.showValues !== false && n <= 8)
|
|
860
|
+
|
|
861
|
+
if (kind === 'pie' || kind === 'doughnut') {
|
|
862
|
+
const sliceColors = chart.categories.map((_, j) => colors[j % colors.length])
|
|
863
|
+
const hexLum = (hex) => {
|
|
864
|
+
const c = String(hex ?? '#000000').replace('#', '').slice(0, 6)
|
|
865
|
+
const rgb = [0, 2, 4].map(k => parseInt(c.slice(k, k + 2), 16) / 255).map(v => v <= 0.04045 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4)
|
|
866
|
+
return rgb[0] * 0.2126 + rgb[1] * 0.7152 + rgb[2] * 0.0722
|
|
867
|
+
}
|
|
868
|
+
const doughnutPointLabels = kind === 'doughnut'
|
|
869
|
+
? sliceColors.map(sc => ({
|
|
870
|
+
showPercent: true,
|
|
871
|
+
showValue: false,
|
|
872
|
+
showCategory: false,
|
|
873
|
+
showSeriesName: false,
|
|
874
|
+
numberFormat: '0.0%',
|
|
875
|
+
textStyle: { font, sizePt: Math.max(12, sizePt - 1), bold: true, color: hexLum(sc) > 0.44 ? '#0F172A' : '#FFFFFF' },
|
|
876
|
+
}))
|
|
877
|
+
: undefined
|
|
878
|
+
return {
|
|
879
|
+
kind,
|
|
880
|
+
categories: chart.categories,
|
|
881
|
+
series: [{
|
|
882
|
+
name: chart.series[0].name,
|
|
883
|
+
values: chart.series[0].values,
|
|
884
|
+
color: colors[0],
|
|
885
|
+
lineColor: bg,
|
|
886
|
+
pointColors: sliceColors,
|
|
887
|
+
...(kind === 'doughnut' ? {
|
|
888
|
+
dataLabels: {
|
|
889
|
+
showPercent: true,
|
|
890
|
+
showValue: false,
|
|
891
|
+
showCategory: false,
|
|
892
|
+
showSeriesName: false,
|
|
893
|
+
numberFormat: '0.0%',
|
|
894
|
+
textStyle: { font, sizePt: Math.max(12, sizePt - 1), bold: true, color: '#FFFFFF' },
|
|
895
|
+
},
|
|
896
|
+
pointDataLabels: doughnutPointLabels,
|
|
897
|
+
} : {}),
|
|
898
|
+
}],
|
|
899
|
+
...(kind === 'doughnut' ? { holeSizePct: 60 } : {}),
|
|
900
|
+
chartAreaFill: bg,
|
|
901
|
+
chartAreaStrokeColor: bg,
|
|
902
|
+
plotAreaFill: bg,
|
|
903
|
+
...(kind === 'pie' ? {
|
|
904
|
+
dataLabels: {
|
|
905
|
+
showPercent: true,
|
|
906
|
+
showValue: false,
|
|
907
|
+
showCategory: false,
|
|
908
|
+
showSeriesName: false,
|
|
909
|
+
numberFormat: '0.0%',
|
|
910
|
+
position: 'outEnd',
|
|
911
|
+
showLeaderLines: true,
|
|
912
|
+
textStyle: { font, sizePt: Math.max(12, sizePt - 1), bold: true, color: fg },
|
|
913
|
+
},
|
|
914
|
+
} : {}),
|
|
915
|
+
legend: { position: 'r', textStyle: labelStyle },
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
if (kind === 'scatter') {
|
|
920
|
+
return {
|
|
921
|
+
kind: 'scatter',
|
|
922
|
+
scatterStyle: 'marker',
|
|
923
|
+
categories: chart.categories,
|
|
924
|
+
series: chart.series.map((s, i) => ({
|
|
925
|
+
name: s.name,
|
|
926
|
+
values: s.values,
|
|
927
|
+
xValues: s.xValues ?? s.values.map((_, idx) => idx + 1),
|
|
928
|
+
color: colors[i % colors.length],
|
|
929
|
+
markerSymbol: 'circle',
|
|
930
|
+
markerSizePt: 8,
|
|
931
|
+
markerColor: colors[i % colors.length],
|
|
932
|
+
})),
|
|
933
|
+
chartAreaFill: bg,
|
|
934
|
+
chartAreaStrokeColor: bg,
|
|
935
|
+
plotAreaFill: bg,
|
|
936
|
+
valueAxisLabelStyle: axisLabelStyle,
|
|
937
|
+
categoryAxisLabelStyle: axisLabelStyle,
|
|
938
|
+
valueAxisMajorGridlines: true,
|
|
939
|
+
valueAxisMajorGridlineColor: hairline,
|
|
940
|
+
valueAxisMajorGridlineWidthEmu: 9525,
|
|
941
|
+
categoryAxisMajorGridlines: true,
|
|
942
|
+
categoryAxisMajorGridlineColor: hairline,
|
|
943
|
+
categoryAxisMajorGridlineWidthEmu: 6350,
|
|
944
|
+
valueAxisMajorTickMark: 'none',
|
|
945
|
+
categoryAxisMajorTickMark: 'none',
|
|
946
|
+
legend: { position: chart.series.length > 1 || chart.showLegend === true ? 't' : null, textStyle: labelStyle },
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
const baseKind = kind === 'stacked-column' || kind === 'percent-column' || kind === 'combo' ? 'column'
|
|
951
|
+
: kind === 'stacked-bar' || kind === 'percent-bar' ? 'bar'
|
|
952
|
+
: kind
|
|
953
|
+
const grouping = kind === 'stacked-column' || kind === 'stacked-bar' ? 'stacked'
|
|
954
|
+
: kind === 'percent-column' || kind === 'percent-bar' ? 'percentStacked'
|
|
955
|
+
: 'clustered'
|
|
956
|
+
|
|
957
|
+
let highlightSet = null
|
|
958
|
+
if (chart.series.length === 1 && (kind === 'column' || kind === 'bar') && chart.highlight !== undefined && chart.highlight !== 'none') {
|
|
959
|
+
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') {
|
|
964
|
+
let best = 0
|
|
965
|
+
for (let i = 1; i < vals.length; i++) if (vals[i] > vals[best]) best = i
|
|
966
|
+
highlightSet = new Set([best])
|
|
967
|
+
} else if (chart.highlight === 'min') {
|
|
968
|
+
let best = 0
|
|
969
|
+
for (let i = 1; i < vals.length; i++) if (vals[i] < vals[best]) best = i
|
|
970
|
+
highlightSet = new Set([best])
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
const hasSecondary = kind === 'combo' && chart.series.some(s => s.secondaryAxis)
|
|
975
|
+
const seriesSpec = chart.series.map((s, i) => {
|
|
976
|
+
const col = colors[i % colors.length]
|
|
977
|
+
const effKind = kind === 'combo' ? (s.chartKind || (i === 0 ? 'column' : 'line')) : baseKind
|
|
978
|
+
const isLineLike = effKind === 'line' || effKind === 'area'
|
|
979
|
+
const comboLabels = kind === 'combo' && showDirectValues
|
|
980
|
+
? {
|
|
981
|
+
showValue: true,
|
|
982
|
+
showCategory: false,
|
|
983
|
+
showSeriesName: false,
|
|
984
|
+
showPercent: false,
|
|
985
|
+
position: isLineLike ? 't' : 'inEnd',
|
|
986
|
+
textStyle: {
|
|
987
|
+
font,
|
|
988
|
+
sizePt: Math.max(11, sizePt - 2),
|
|
989
|
+
bold: true,
|
|
990
|
+
color: isLineLike ? col : (tokens.inkOnAccent || '#FFFFFF'),
|
|
991
|
+
},
|
|
992
|
+
}
|
|
993
|
+
: undefined
|
|
994
|
+
return {
|
|
995
|
+
name: s.name,
|
|
996
|
+
values: s.values,
|
|
997
|
+
color: highlightSet ? focalColor : col,
|
|
998
|
+
...(highlightSet ? { pointColors: s.values.map((_, idx) => highlightSet.has(idx) ? focalColor : neutralColor) } : {}),
|
|
999
|
+
...(kind === 'combo' ? { chartKind: effKind } : {}),
|
|
1000
|
+
...(s.secondaryAxis ? { secondaryAxis: true } : {}),
|
|
1001
|
+
...(isLineLike ? { lineWidthEmu: 31750, lineColor: col, markerSymbol: 'circle', markerSizePt: 6, markerColor: col } : {}),
|
|
1002
|
+
...(effKind === 'area' ? { fillOpacity: 0.24 } : {}),
|
|
1003
|
+
...(comboLabels ? { dataLabels: comboLabels } : {}),
|
|
1004
|
+
}
|
|
1005
|
+
})
|
|
1006
|
+
|
|
1007
|
+
const showLegend = chart.showLegend === true || (chart.showLegend !== false && chart.series.length > 1)
|
|
1008
|
+
const dataLabelPos = baseKind === 'bar' || baseKind === 'column'
|
|
1009
|
+
? (grouping === 'clustered' ? 'outEnd' : 'ctr')
|
|
1010
|
+
: 't'
|
|
1011
|
+
|
|
1012
|
+
return {
|
|
1013
|
+
kind: baseKind,
|
|
1014
|
+
categories: chart.categories,
|
|
1015
|
+
series: seriesSpec,
|
|
1016
|
+
...(baseKind === 'column' || baseKind === 'bar' || baseKind === 'area' ? { grouping } : {}),
|
|
1017
|
+
...(baseKind === 'column' || baseKind === 'bar' ? { gapWidthPct: 85 } : {}),
|
|
1018
|
+
...(baseKind === 'line' ? { lineMarkers: true } : {}),
|
|
1019
|
+
chartAreaFill: bg,
|
|
1020
|
+
chartAreaStrokeColor: bg,
|
|
1021
|
+
plotAreaFill: bg,
|
|
1022
|
+
categoryAxisLabelStyle: labelStyle,
|
|
1023
|
+
valueAxisLabelStyle: axisLabelStyle,
|
|
1024
|
+
valueAxisMinorTickMark: 'none',
|
|
1025
|
+
categoryAxisMinorTickMark: 'none',
|
|
1026
|
+
valueAxisMajorTickMark: 'none',
|
|
1027
|
+
categoryAxisMajorTickMark: 'none',
|
|
1028
|
+
valueAxisLineHidden: true,
|
|
1029
|
+
categoryAxisLineColor: axisLine,
|
|
1030
|
+
categoryAxisLineWidthEmu: 12700,
|
|
1031
|
+
valueAxisMajorGridlines: true,
|
|
1032
|
+
valueAxisMajorGridlineColor: hairline,
|
|
1033
|
+
valueAxisMajorGridlineWidthEmu: 9525,
|
|
1034
|
+
...(grouping === 'percentStacked' ? { valueAxis: { min: 0, max: 1, numberFormat: '0%' } } : {}),
|
|
1035
|
+
...(baseKind === 'bar' ? { categoryAxisOrientation: 'maxMin', valueAxisCrosses: 'max' } : {}),
|
|
1036
|
+
...(kind !== 'combo' && showDirectValues && grouping === 'clustered' && chart.series.length <= 2 ? {
|
|
1037
|
+
dataLabels: {
|
|
1038
|
+
showValue: true,
|
|
1039
|
+
showCategory: false,
|
|
1040
|
+
showSeriesName: false,
|
|
1041
|
+
showPercent: false,
|
|
1042
|
+
position: dataLabelPos,
|
|
1043
|
+
textStyle: { font, sizePt: Math.max(11, sizePt - 2), bold: Boolean(highlightSet), color: fg },
|
|
1044
|
+
},
|
|
1045
|
+
} : {}),
|
|
1046
|
+
...(chart.unit ? { valueAxisTitle: chart.unit, valueAxisTitleStyle: axisLabelStyle } : {}),
|
|
1047
|
+
...(hasSecondary ? {
|
|
1048
|
+
secondaryValueAxis: {
|
|
1049
|
+
labelStyle: axisLabelStyle,
|
|
1050
|
+
majorGridlines: false,
|
|
1051
|
+
majorTickMark: 'none',
|
|
1052
|
+
minorTickMark: 'none',
|
|
1053
|
+
},
|
|
1054
|
+
} : {}),
|
|
1055
|
+
legend: { position: showLegend ? 't' : null, textStyle: labelStyle },
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
function xmlEscape(value) {
|
|
1060
|
+
return String(value ?? '')
|
|
1061
|
+
.replace(/[\u000B\u000C]/g, '\n')
|
|
1062
|
+
.replace(/[^\u0009\u000A\u000D\u0020-\uD7FF\uE000-\uFFFD\u{10000}-\u{10FFFF}]/gu, '')
|
|
1063
|
+
.replace(/&/g, '&')
|
|
1064
|
+
.replace(/</g, '<')
|
|
1065
|
+
.replace(/>/g, '>')
|
|
1066
|
+
.replace(/"/g, '"')
|
|
1067
|
+
.replace(/'/g, ''')
|
|
1068
|
+
}
|
|
1069
|
+
|
|
1070
|
+
function hex6(color, fallback = '0057B8') {
|
|
1071
|
+
const clean = String(color ?? '').replace('#', '').trim().toUpperCase()
|
|
1072
|
+
if (/^[0-9A-F]{6}$/.test(clean)) return clean
|
|
1073
|
+
if (/^[0-9A-F]{3}$/.test(clean)) return clean.split('').map(c => c + c).join('')
|
|
1074
|
+
return fallback
|
|
1075
|
+
}
|
|
1076
|
+
|
|
1077
|
+
function parseRichRuns(text, defaultBold = false) {
|
|
1078
|
+
const str = String(text ?? '')
|
|
1079
|
+
if (!/[*`]/.test(str)) {
|
|
1080
|
+
const colon = !defaultBold && /^([^::]{1,12})([::]\s*)([\s\S]+)$/.exec(str)
|
|
1081
|
+
if (colon) return [{ text: colon[1] + colon[2], bold: true }, { text: colon[3], bold: false, secondary: true }]
|
|
1082
|
+
return [{ text: str, bold: defaultBold }]
|
|
1083
|
+
}
|
|
1084
|
+
const re = /\*\*([^*]+)\*\*|\*([^*\n]+)\*|`([^`]+)`/g
|
|
1085
|
+
const runs = []
|
|
1086
|
+
let last = 0
|
|
1087
|
+
for (const m of str.matchAll(re)) {
|
|
1088
|
+
if (m.index > last) runs.push({ text: str.slice(last, m.index), bold: defaultBold })
|
|
1089
|
+
if (m[1] !== undefined) runs.push({ text: m[1], bold: true })
|
|
1090
|
+
else if (m[2] !== undefined) runs.push({ text: m[2], bold: defaultBold, italic: true })
|
|
1091
|
+
else if (m[3] !== undefined) runs.push({ text: m[3], bold: true, code: true })
|
|
1092
|
+
last = m.index + m[0].length
|
|
1093
|
+
}
|
|
1094
|
+
if (last < str.length) runs.push({ text: str.slice(last), bold: defaultBold })
|
|
1095
|
+
return runs.length ? runs : [{ text: str, bold: defaultBold }]
|
|
1096
|
+
}
|
|
1097
|
+
|
|
1098
|
+
/**
|
|
1099
|
+
* Native DrawingML shape compiler for media/chart slides (including 100% vector waterfall bridges,
|
|
1100
|
+
* framed image mattes, vertically centered rich-text columns, and chart-split insight cards).
|
|
1101
|
+
*/
|
|
1102
|
+
export function renderMediaPptxShapes(slide, index, theme, langId = 'zh-CN', fontHelpers = {}, total = 1, manifest = {}) {
|
|
1103
|
+
const p = theme.palette || {}
|
|
1104
|
+
const t = theme.tokens || {}
|
|
1105
|
+
const fg = t.inkPrimary || p.fg || '#0F172A'
|
|
1106
|
+
const secondary = t.inkSecondary || p.muted || '#334155'
|
|
1107
|
+
const muted = t.inkMuted || p.muted || '#64748B'
|
|
1108
|
+
const accent = p.accent || t.accentPrimary || '#0057B8'
|
|
1109
|
+
const accent2 = p.accent2 || t.accentSecondary || accent
|
|
1110
|
+
const accentText = t.accentText || accent
|
|
1111
|
+
const surface1 = t.surface1 || p.panel || (theme.dark ? '#141B29' : '#F4F6F9')
|
|
1112
|
+
const hairline = t.hairline || (theme.dark ? '#263554' : '#D5DFEC')
|
|
1113
|
+
const posColor = t.positive || (theme.dark ? '#34D399' : '#0D7A4E')
|
|
1114
|
+
const negColor = t.negative || (theme.dark ? '#F87171' : '#C81E1E')
|
|
1115
|
+
const focalColor = t.chartFocal || accent
|
|
1116
|
+
const chromeStyle = resolveChromeStyle(theme, slide, manifest?.brand)
|
|
1117
|
+
const chromeCfg = getChromeConfig(chromeStyle, theme)
|
|
1118
|
+
const isEn = langId === 'en-US'
|
|
1119
|
+
|
|
1120
|
+
const headingFont = fontHelpers.latinHeading || 'Segoe UI'
|
|
1121
|
+
const headingEa = fontHelpers.eaHeading || 'Microsoft YaHei'
|
|
1122
|
+
const bodyFont = fontHelpers.latinBody || 'Segoe UI'
|
|
1123
|
+
const bodyEa = fontHelpers.eaBody || 'Microsoft YaHei'
|
|
1124
|
+
|
|
1125
|
+
const toEmu = v => Math.round(v * 914400)
|
|
1126
|
+
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)
|
|
1128
|
+
const variant = String(slide.variant ?? '').trim().toLowerCase()
|
|
1129
|
+
const isBleed = variant === 'full-bleed' || variant === 'split-bleed'
|
|
1130
|
+
let nextId = (index + 1) * 100 + 2
|
|
1131
|
+
const allocId = () => nextId++
|
|
1132
|
+
const shapes = []
|
|
1133
|
+
|
|
1134
|
+
const runXml = (r, sizeHundredths, baseColor, latin, ea, extraAttrs = '') => {
|
|
1135
|
+
const col = r.secondary ? secondary : baseColor
|
|
1136
|
+
return `<a:r><a:rPr lang="${langId}" sz="${sizeHundredths}" b="${r.bold ? 1 : 0}"${r.italic ? ' i="1"' : ''}${extraAttrs} dirty="0"><a:solidFill><a:srgbClr val="${hex6(col)}"/></a:solidFill><a:latin typeface="${xmlEscape(latin)}"/><a:ea typeface="${xmlEscape(ea)}"/></a:rPr><a:t>${xmlEscape(r.text)}</a:t></a:r>`
|
|
1137
|
+
}
|
|
1138
|
+
|
|
1139
|
+
const paraRich = (content, opts = {}) => {
|
|
1140
|
+
const { size = 1600, color = fg, bold = false, align = 'l', bullet = false, bulletChar = '▪', bulletColor = accent, latin = bodyFont, ea = bodyEa, spaceBefore = 0, spaceAfter = 0, linePct = 135000, spc = 0 } = opts
|
|
1141
|
+
const runs = parseRichRuns(content, bold)
|
|
1142
|
+
const spacing = `<a:lnSpc><a:spcPct val="${linePct}"/></a:lnSpc>` +
|
|
1143
|
+
(spaceBefore > 0 ? `<a:spcBef><a:spcPts val="${spaceBefore}"/></a:spcBef>` : '') +
|
|
1144
|
+
(spaceAfter > 0 ? `<a:spcAft><a:spcPts val="${spaceAfter}"/></a:spcAft>` : '')
|
|
1145
|
+
const pPr = `<a:pPr${bullet ? ' marL="247650" indent="-247650"' : ''}${align !== 'l' ? ` algn="${align}"` : ''}>${spacing}` +
|
|
1146
|
+
(bullet ? `<a:buClr><a:srgbClr val="${hex6(bulletColor)}"/></a:buClr><a:buFont typeface="${xmlEscape(latin)}"/><a:buChar char="${bulletChar}"/>` : '<a:buNone/>') +
|
|
1147
|
+
`</a:pPr>`
|
|
1148
|
+
const extra = spc ? ` spc="${spc}"` : ''
|
|
1149
|
+
return `<a:p>${pPr}${runs.map(r => runXml(r, size, color, latin, ea, extra)).join('')}</a:p>`
|
|
1150
|
+
}
|
|
1151
|
+
|
|
1152
|
+
const spText = (name, b, paragraphs, opts = {}) => {
|
|
1153
|
+
const { anchor = 't', fill = null, stroke = null, strokeW = 12700, roundAdj = 0, ins = [91440, 45720, 91440, 45720], fontScale = 100000 } = opts
|
|
1154
|
+
const eb = b.x > 1000 ? b : boxEmu(b)
|
|
1155
|
+
const geom = roundAdj > 0
|
|
1156
|
+
? `<a:prstGeom prst="roundRect"><a:avLst><a:gd name="adj" fmla="val ${roundAdj}"/></a:avLst></a:prstGeom>`
|
|
1157
|
+
: `<a:prstGeom prst="rect"><a:avLst/></a:prstGeom>`
|
|
1158
|
+
const fillXml = fill ? `<a:solidFill><a:srgbClr val="${hex6(fill)}"/></a:solidFill>` : '<a:noFill/>'
|
|
1159
|
+
const lnXml = stroke ? `<a:ln w="${strokeW}"><a:solidFill><a:srgbClr val="${hex6(stroke)}"/></a:solidFill></a:ln>` : '<a:ln/>'
|
|
1160
|
+
return `<p:sp><p:nvSpPr><p:cNvPr id="${allocId()}" name="${xmlEscape(name)}"/><p:cNvSpPr txBox="1"/><p:nvPr/></p:nvSpPr>` +
|
|
1161
|
+
`<p:spPr><a:xfrm><a:off x="${eb.x}" y="${eb.y}"/><a:ext cx="${eb.w}" cy="${eb.h}"/></a:xfrm>${geom}${fillXml}${lnXml}</p:spPr>` +
|
|
1162
|
+
`<p:txBody><a:bodyPr wrap="square" rtlCol="0" anchor="${anchor}" lIns="${ins[0]}" tIns="${ins[1]}" rIns="${ins[2]}" bIns="${ins[3]}"><a:normAutofit${fontScale < 100000 ? ` fontScale="${fontScale}"` : ''}/></a:bodyPr><a:lstStyle/>${paragraphs.join('')}</p:txBody></p:sp>`
|
|
1163
|
+
}
|
|
1164
|
+
|
|
1165
|
+
const spRect = (name, eb, fill, stroke = null, strokeW = 12700, roundAdj = 3500) => {
|
|
1166
|
+
const geom = roundAdj > 0
|
|
1167
|
+
? `<a:prstGeom prst="roundRect"><a:avLst><a:gd name="adj" fmla="val ${roundAdj}"/></a:avLst></a:prstGeom>`
|
|
1168
|
+
: `<a:prstGeom prst="rect"><a:avLst/></a:prstGeom>`
|
|
1169
|
+
const lnXml = stroke ? `<a:ln w="${strokeW}"><a:solidFill><a:srgbClr val="${hex6(stroke)}"/></a:solidFill></a:ln>` : '<a:ln><a:noFill/></a:ln>'
|
|
1170
|
+
return `<p:sp><p:nvSpPr><p:cNvPr id="${allocId()}" name="${xmlEscape(name)}"/><p:cNvSpPr/><p:nvPr/></p:nvSpPr>` +
|
|
1171
|
+
`<p:spPr><a:xfrm><a:off x="${eb.x}" y="${eb.y}"/><a:ext cx="${eb.w}" cy="${eb.h}"/></a:xfrm>${geom}<a:solidFill><a:srgbClr val="${hex6(fill)}"/></a:solidFill>${lnXml}</p:spPr>` +
|
|
1172
|
+
`<p:txBody><a:bodyPr/><a:lstStyle/><a:p/></p:txBody></p:sp>`
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1175
|
+
const spLine = (name, x1, y1, x2, y2, color, widthEmu = 12700, dash = 'solid') => {
|
|
1176
|
+
const ox = Math.min(x1, x2), oy = Math.min(y1, y2)
|
|
1177
|
+
const cx = Math.abs(x2 - x1), cy = Math.abs(y2 - y1)
|
|
1178
|
+
const flipH = x2 < x1 ? ' flipH="1"' : '', flipV = y2 < y1 ? ' flipV="1"' : ''
|
|
1179
|
+
return `<p:cxnSp><p:nvCxnSpPr><p:cNvPr id="${allocId()}" name="${xmlEscape(name)}"/><p:cNvCxnSpPr/><p:nvPr/></p:nvCxnSpPr>` +
|
|
1180
|
+
`<p:spPr><a:xfrm${flipH}${flipV}><a:off x="${ox}" y="${oy}"/><a:ext cx="${cx}" cy="${cy}"/></a:xfrm><a:prstGeom prst="line"><a:avLst/></a:prstGeom>` +
|
|
1181
|
+
`<a:ln w="${widthEmu}"><a:solidFill><a:srgbClr val="${hex6(color)}"/></a:solidFill><a:prstDash val="${dash}"/></a:ln></p:spPr></p:cxnSp>`
|
|
1182
|
+
}
|
|
1183
|
+
|
|
1184
|
+
// Kicker & Action Title (aligned with 6 Chrome Skeletons)
|
|
1185
|
+
const titleUnits = textUnits(slide.title)
|
|
1186
|
+
const titlePt = slide.visual?.titleSize ?? (titleUnits > 26 ? 22 : titleUnits > 18 ? 25 : 28)
|
|
1187
|
+
const hasKicker = Boolean(slide.kicker && slide.kicker !== slide.title)
|
|
1188
|
+
const cardAdj = chromeCfg.cardRadiusPx > 0 ? (chromeStyle === 'keynote-spatial' ? 6000 : 3500) : 0
|
|
1189
|
+
const cardStroke = chromeCfg.cardBorderless ? null : hairline
|
|
1190
|
+
const cardStrokeW = Math.round(chromeCfg.cardStrokePt * 12700)
|
|
1191
|
+
|
|
1192
|
+
if (!isBleed && chromeStyle === 'academic-minimal') {
|
|
1193
|
+
// Beamer Metropolis full-width tinted header band + 1.5pt accent bottom rule
|
|
1194
|
+
shapes.push(spRect('Beamer header band', boxEmu({ x: 0, y: 0, w: CANVAS.w, h: 1.28 }), surface1, null, 0, 0))
|
|
1195
|
+
shapes.push(spLine('Beamer header rule', 0, toEmu(1.28), toEmu(CANVAS.w), toEmu(1.28), accent, 19050, 'solid'))
|
|
1196
|
+
if (hasKicker) {
|
|
1197
|
+
shapes.push(spText('Kicker', { x: 0.65, y: 0.14, w: 12.03, h: 0.24 }, [paraRich(slide.kicker.toUpperCase(), { size: 1000, color: accentText, bold: true, spc: 140 })], { ins: [0, 0, 0, 0] }))
|
|
1198
|
+
}
|
|
1199
|
+
shapes.push(spText('Title', { x: 0.65, y: hasKicker ? 0.38 : 0.24, w: 12.03, h: 0.80 }, [paraRich(slide.title || '', { size: Math.min(25, titlePt) * 100, color: fg, bold: true, latin: headingFont, ea: headingEa, linePct: 118000 })], { anchor: 'ctr', ins: [0, 0, 0, 0] }))
|
|
1200
|
+
} else if (!isBleed && chromeStyle === 'editorial-folio') {
|
|
1201
|
+
if (hasKicker) {
|
|
1202
|
+
shapes.push(spText('Kicker', { x: 0.65, y: 0.22, w: 8.8, h: 0.26 }, [paraRich(slide.kicker.toUpperCase(), { size: 1000, color: accentText, bold: true, spc: 180 })], { ins: [0, 0, 0, 0] }))
|
|
1203
|
+
}
|
|
1204
|
+
shapes.push(spLine('Editorial folio rule', toEmu(0.65), toEmu(0.54), toEmu(12.68), toEmu(0.54), hairline, 6350, 'solid'))
|
|
1205
|
+
shapes.push(spText('Title', { x: 0.65, y: 0.64, w: 12.03, h: 0.82 }, [paraRich(slide.title || '', { size: titlePt * 100, color: fg, bold: true, latin: headingFont, ea: headingEa, linePct: 118000 })], { anchor: 'ctr', ins: [0, 0, 0, 0] }))
|
|
1206
|
+
shapes.push(spLine('Header rule', toEmu(0.65), toEmu(1.56), toEmu(12.68), toEmu(1.56), hairline, 6350, 'solid'))
|
|
1207
|
+
} else if (!isBleed && chromeStyle === 'consulting-classic') {
|
|
1208
|
+
let trackerW = 0
|
|
1209
|
+
if (hasKicker) {
|
|
1210
|
+
trackerW = computeBadgePillWidth(slide.kicker.toUpperCase(), 10, 3.6, 1.15)
|
|
1211
|
+
shapes.push(spText('Kicker', { x: 12.68 - trackerW, y: 0.42, w: trackerW, h: 0.32 }, [paraRich(slide.kicker.toUpperCase(), { size: 1000, color: accentText, bold: true, align: 'ctr', spc: 80 })], {
|
|
1212
|
+
anchor: 'ctr',
|
|
1213
|
+
fill: t.accentSoft || surface1,
|
|
1214
|
+
stroke: accent,
|
|
1215
|
+
strokeW: 9525,
|
|
1216
|
+
roundAdj: 0,
|
|
1217
|
+
ins: [45720, 18288, 45720, 18288],
|
|
1218
|
+
}))
|
|
1219
|
+
}
|
|
1220
|
+
const titleW = trackerW > 0 ? 12.03 - trackerW - 0.30 : 12.03
|
|
1221
|
+
shapes.push(spText('Title', { x: 0.65, y: 0.42, w: titleW, h: 1.02 }, [paraRich(slide.title || '', { size: titlePt * 100, color: fg, bold: true, latin: headingFont, ea: headingEa, linePct: 118000 })], { anchor: 'ctr', ins: [0, 0, 0, 0] }))
|
|
1222
|
+
shapes.push(spLine('Header rule', toEmu(0.65), toEmu(1.56), toEmu(12.68), toEmu(1.56), hairline, 9525, 'solid'))
|
|
1223
|
+
} else if (!isBleed && chromeStyle === 'gov-ceremonial') {
|
|
1224
|
+
if (hasKicker) {
|
|
1225
|
+
const gk = /^【/.test(slide.kicker.trim()) ? slide.kicker.trim() : '【' + slide.kicker.trim() + '】'
|
|
1226
|
+
shapes.push(spText('Kicker', boxes.kicker, [paraRich(gk, { size: 1150, color: accentText, bold: true, spc: 80 })], { ins: [0, 0, 0, 0] }))
|
|
1227
|
+
}
|
|
1228
|
+
shapes.push(spText('Title', boxes.title, [paraRich(slide.title || '', { size: titlePt * 100, color: fg, bold: true, latin: headingFont, ea: headingEa, linePct: 118000 })], { anchor: 'ctr', ins: [0, 0, 0, 0] }))
|
|
1229
|
+
shapes.push(spLine('Header rule', toEmu(0.65), toEmu(1.50), toEmu(12.68), toEmu(1.50), accent, 19050, 'solid'))
|
|
1230
|
+
shapes.push(spLine('Header secondary rule', toEmu(0.65), toEmu(1.57), toEmu(12.68), toEmu(1.57), accent2, 6350, 'solid'))
|
|
1231
|
+
} else if (!isBleed && chromeStyle === 'keynote-spatial') {
|
|
1232
|
+
if (hasKicker) {
|
|
1233
|
+
const pillW = computeBadgePillWidth(slide.kicker.toUpperCase(), 10, 4.2, 1.05)
|
|
1234
|
+
shapes.push(spText('Kicker', { x: 0.65, y: 0.30, w: pillW, h: 0.28 }, [paraRich(slide.kicker.toUpperCase(), { size: 1000, color: accentText, bold: true, align: 'ctr', spc: 100 })], {
|
|
1235
|
+
anchor: 'ctr',
|
|
1236
|
+
fill: t.accentSoft || surface1,
|
|
1237
|
+
roundAdj: 50000,
|
|
1238
|
+
ins: [45720, 12000, 45720, 12000],
|
|
1239
|
+
}))
|
|
1240
|
+
}
|
|
1241
|
+
shapes.push(spText('Title', { x: 0.65, y: hasKicker ? 0.62 : 0.44, w: 12.03, h: 0.88 }, [paraRich(slide.title || '', { size: titlePt * 100, color: fg, bold: true, latin: headingFont, ea: headingEa, linePct: 118000 })], { anchor: 'ctr', ins: [0, 0, 0, 0] }))
|
|
1242
|
+
// Zero horizontal divider line in keynote-spatial!
|
|
1243
|
+
} else {
|
|
1244
|
+
if (hasKicker && variant !== 'full-bleed') {
|
|
1245
|
+
shapes.push(spText('Kicker', boxes.kicker, [paraRich(slide.kicker.toUpperCase(), { size: 1100, color: accentText, bold: true, spc: 140 })], { ins: [0, 0, 0, 0] }))
|
|
1246
|
+
}
|
|
1247
|
+
if (variant === 'full-bleed') {
|
|
1248
|
+
const scrim = boxEmu({ x: 0.45, y: 5.15, w: 11.2, h: 1.75 })
|
|
1249
|
+
shapes.push(spRect('Title Scrim', scrim, theme.dark ? '#090B10' : '#FFFFFF', hairline, 9525, 3500))
|
|
1250
|
+
}
|
|
1251
|
+
shapes.push(spText('Title', boxes.title, [paraRich(slide.title || '', { size: titlePt * 100, color: fg, bold: true, latin: headingFont, ea: headingEa, linePct: 118000 })], { anchor: 'ctr', ins: [0, 0, 0, 0] }))
|
|
1252
|
+
if (!isBleed) {
|
|
1253
|
+
shapes.push(spLine('Header rule', toEmu(0.65), toEmu(1.56), toEmu(12.68), toEmu(1.56), hairline, 9525, 'solid'))
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
1256
|
+
|
|
1257
|
+
// Framed matte container behind non-bleed images
|
|
1258
|
+
if (['image', 'image-left', 'image-right'].includes(slide.layout) && !isBleed) {
|
|
1259
|
+
if (Array.isArray(boxes.gallery) && Array.isArray(slide.images) && slide.images.length > 1) {
|
|
1260
|
+
boxes.gallery.forEach((gBox, gIdx) => {
|
|
1261
|
+
const pad = 0.06
|
|
1262
|
+
shapes.push(spRect(`Gallery Frame ${gIdx + 1}`, boxEmu({ x: gBox.x - pad, y: gBox.y - pad, w: gBox.w + pad * 2, h: gBox.h + pad * 2 }), surface1, cardStroke, cardStrokeW || 9525, cardAdj))
|
|
1263
|
+
if (slide.images[gIdx]?.caption) {
|
|
1264
|
+
shapes.push(spText(`Gallery Caption ${gIdx + 1}`, { x: gBox.x, y: gBox.y + gBox.h + 0.08, w: gBox.w, h: 0.28 }, [paraRich(slide.images[gIdx].caption, { size: 1150, color: muted, align: 'ctr' })], { ins: [0, 0, 0, 0] }))
|
|
1265
|
+
}
|
|
1266
|
+
})
|
|
1267
|
+
} else {
|
|
1268
|
+
const ib = boxes.image, pad = 0.06
|
|
1269
|
+
shapes.push(spRect('Image Matte', boxEmu({ x: ib.x - pad, y: ib.y - pad, w: ib.w + pad * 2, h: ib.h + pad * 2 }), surface1, cardStroke, cardStrokeW || 9525, cardAdj))
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
1272
|
+
|
|
1273
|
+
// Body column for image-left / image-right (vertically centered + distinct subtitle hierarchy!)
|
|
1274
|
+
if (boxes.body && (slide.layout === 'image-left' || slide.layout === 'image-right')) {
|
|
1275
|
+
const bullets = Array.isArray(slide.bullets) ? slide.bullets : []
|
|
1276
|
+
const bodyPt = slide.visual?.bodySize ?? (bullets.length > 4 ? 15 : 16.5)
|
|
1277
|
+
const paras = []
|
|
1278
|
+
if (slide.subtitle) {
|
|
1279
|
+
paras.push(paraRich(slide.subtitle, { size: Math.round((bodyPt + 1.5) * 100), color: secondary, bold: false, spaceAfter: bullets.length ? 900 : 0, linePct: 140000 }))
|
|
1280
|
+
}
|
|
1281
|
+
bullets.forEach((b, idx) => {
|
|
1282
|
+
paras.push(paraRich(b, { size: Math.round(bodyPt * 100), color: fg, bullet: true, bulletChar: '▪', bulletColor: accent, spaceAfter: idx < bullets.length - 1 ? 550 : 0, linePct: 142000 }))
|
|
1283
|
+
})
|
|
1284
|
+
if (paras.length) {
|
|
1285
|
+
shapes.push(spText('Body', boxes.body, paras, { anchor: 'ctr', ins: [45720, 45720, 45720, 45720] }))
|
|
1286
|
+
}
|
|
1287
|
+
}
|
|
1288
|
+
|
|
1289
|
+
// Structured insight cards for chart-split (chrome-aware card geometry)
|
|
1290
|
+
if (slide.layout === 'chart-split' && boxes.body) {
|
|
1291
|
+
const cards = projectInsightCards(slide)
|
|
1292
|
+
const count = Math.max(1, cards.length)
|
|
1293
|
+
const gap = 0.16
|
|
1294
|
+
const cardH = (boxes.body.h - gap * (count - 1)) / count
|
|
1295
|
+
cards.forEach((card, idx) => {
|
|
1296
|
+
const cy = boxes.body.y + idx * (cardH + gap)
|
|
1297
|
+
const cardBox = { x: boxes.body.x, y: cy, w: boxes.body.w, h: cardH }
|
|
1298
|
+
const paras = []
|
|
1299
|
+
if (card.value) {
|
|
1300
|
+
paras.push(paraRich(card.value + (card.unit ? ` ${card.unit}` : ''), { size: 2200, color: accentText, bold: true, spaceAfter: 180 }))
|
|
1301
|
+
} else if (card.tag) {
|
|
1302
|
+
paras.push(paraRich(card.tag, { size: 1000, color: accentText, bold: true, spc: 120, spaceAfter: 140 }))
|
|
1303
|
+
}
|
|
1304
|
+
if (card.title) paras.push(paraRich(card.title, { size: 1450, color: fg, bold: true, spaceAfter: card.text ? 160 : 0 }))
|
|
1305
|
+
if (card.text) paras.push(paraRich(card.text, { size: 1350, color: secondary, linePct: 132000 }))
|
|
1306
|
+
shapes.push(spText(`Insight Card ${idx + 1}`, cardBox, paras.length ? paras : [paraRich('', { size: 1350 })], {
|
|
1307
|
+
anchor: 'ctr',
|
|
1308
|
+
fill: surface1,
|
|
1309
|
+
stroke: cardStroke,
|
|
1310
|
+
strokeW: cardStrokeW || 9525,
|
|
1311
|
+
roundAdj: chromeStyle === 'keynote-spatial' ? 6000 : (chromeCfg.cardRadiusPx > 0 ? roundRectAdj(cardBox.w, cardBox.h, chromeCfg.cardRadiusPx) : 0),
|
|
1312
|
+
ins: [128000, 76200, 128000, 76200],
|
|
1313
|
+
}))
|
|
1314
|
+
if (chromeCfg.cardLeftBar) {
|
|
1315
|
+
shapes.push(spRect(`Insight Stripe ${idx + 1}`, boxEmu({ x: cardBox.x, y: cardBox.y, w: 0.04, h: cardBox.h }), accent, null, 0, 0))
|
|
1316
|
+
} else if (chromeCfg.cardTopBar && idx === 0) {
|
|
1317
|
+
shapes.push(spRect(`Insight Top ${idx + 1}`, boxEmu({ x: cardBox.x, y: cardBox.y, w: cardBox.w, h: 0.045 }), accent, null, 0, 0))
|
|
1318
|
+
}
|
|
1319
|
+
})
|
|
1320
|
+
}
|
|
1321
|
+
|
|
1322
|
+
// Native editable OOXML vector Waterfall bridge chart
|
|
1323
|
+
if ((slide.layout === 'chart' || slide.layout === 'chart-split') && slide.chart?.kind === 'waterfall') {
|
|
1324
|
+
const cb = boxEmu(boxes.chart)
|
|
1325
|
+
const plotLeft = cb.x + Math.round(cb.w * 0.085)
|
|
1326
|
+
const plotRight = cb.x + Math.round(cb.w * 0.975)
|
|
1327
|
+
const plotTop = cb.y + Math.round(cb.h * 0.11)
|
|
1328
|
+
const plotBottom = cb.y + Math.round(cb.h * 0.83)
|
|
1329
|
+
const geom = computeWaterfallGeometry(slide.chart, { left: plotLeft, right: plotRight, top: plotTop, bottom: plotBottom })
|
|
1330
|
+
|
|
1331
|
+
geom.ticks.forEach((tk, tIdx) => {
|
|
1332
|
+
shapes.push(spLine(`Waterfall Grid ${tIdx}`, plotLeft, Math.round(tk.y), plotRight, Math.round(tk.y), hairline, 9525, 'solid'))
|
|
1333
|
+
shapes.push(spText(`Waterfall Tick ${tIdx}`, { x: cb.x, y: Math.round(tk.y - 95000), w: plotLeft - cb.x - 68000, h: 190000 }, [paraRich(tk.label, { size: 1100, color: muted, align: 'r' })], { anchor: 'ctr', ins: [0, 0, 0, 0] }))
|
|
1334
|
+
})
|
|
1335
|
+
|
|
1336
|
+
geom.connectors.forEach((cn, cIdx) => {
|
|
1337
|
+
shapes.push(spLine(`Waterfall Bridge ${cIdx + 1}`, Math.round(cn.x1), Math.round(cn.y1), Math.round(cn.x2), Math.round(cn.y2), muted, 11430, 'dash'))
|
|
1338
|
+
})
|
|
1339
|
+
|
|
1340
|
+
geom.bars.forEach((b, bIdx) => {
|
|
1341
|
+
const col = b.role === 'total' ? focalColor : b.role === 'positive' ? posColor : negColor
|
|
1342
|
+
shapes.push(spRect(`Waterfall Bar ${bIdx + 1}`, { x: Math.round(b.x), y: Math.round(b.y), w: Math.round(b.w), h: Math.max(25400, Math.round(b.h)) }, col, null, 0, chromeCfg.cardRadiusPx > 0 ? 3500 : 0))
|
|
1343
|
+
const labelY = b.value >= 0 || b.isTotal ? Math.round(b.y - 220000) : Math.round(b.y + b.h + 25000)
|
|
1344
|
+
shapes.push(spText(`Waterfall Value ${bIdx + 1}`, { x: Math.round(b.x - 95000), y: labelY, w: Math.round(b.w + 190000), h: 205000 }, [paraRich(b.label, { size: 1150, color: b.role === 'total' ? fg : col, bold: true, align: 'ctr' })], { anchor: 'ctr', ins: [0, 0, 0, 0] }))
|
|
1345
|
+
shapes.push(spText(`Waterfall Category ${bIdx + 1}`, { x: Math.round(b.x - 110000), y: plotBottom + 42000, w: Math.round(b.w + 220000), h: 240000 }, [paraRich(b.category, { size: 1200, color: fg, align: 'ctr' })], { anchor: 't', ins: [0, 0, 0, 0] }))
|
|
1346
|
+
})
|
|
1347
|
+
|
|
1348
|
+
shapes.push(spLine('Waterfall Baseline', plotLeft, Math.round(geom.zeroY), plotRight, Math.round(geom.zeroY), secondary, 15875, 'solid'))
|
|
1349
|
+
if (slide.chart.unit) {
|
|
1350
|
+
shapes.push(spText('Waterfall Unit', { x: plotRight - 1400000, y: cb.y, w: 1400000, h: 200000 }, [paraRich(slide.chart.unit, { size: 1100, color: muted, align: 'r' })], { ins: [0, 0, 0, 0] }))
|
|
1351
|
+
}
|
|
1352
|
+
}
|
|
1353
|
+
|
|
1354
|
+
// Caption + Chrome-aware Takeaway coexistence
|
|
1355
|
+
const caption = slide.chart?.caption || slide.image?.caption
|
|
1356
|
+
if (caption) {
|
|
1357
|
+
shapes.push(spText('Caption', boxes.caption, [paraRich(caption, { size: 1150, color: muted })], { ins: [0, 0, 0, 0] }))
|
|
1358
|
+
}
|
|
1359
|
+
if (slide.takeaway) {
|
|
1360
|
+
const tkText = slide.takeaway.trim()
|
|
1361
|
+
if (chromeCfg.takeawayStyle === 'caption') {
|
|
1362
|
+
shapes.push(spText('Takeaway', boxes.takeaway, [paraRich(tkText, { size: 1350, color: secondary, align: 'ctr' })], {
|
|
1363
|
+
anchor: 'ctr',
|
|
1364
|
+
ins: [180000, 24000, 180000, 24000],
|
|
1365
|
+
}))
|
|
1366
|
+
} else if (chromeCfg.takeawayStyle === 'top-rule' || chromeCfg.takeawayStyle === 'editorial-rule') {
|
|
1367
|
+
const prefix = chromeCfg.takeawayStyle === 'editorial-rule'
|
|
1368
|
+
? '**—** '
|
|
1369
|
+
: (isEn ? '**Key Takeaway:** ' : '**核心结论:**')
|
|
1370
|
+
shapes.push(spRect('Takeaway accent', boxEmu({ x: boxes.takeaway.x, y: boxes.takeaway.y, w: boxes.takeaway.w, h: 0.02 }), chromeCfg.takeawayStyle === 'editorial-rule' ? hairline : accent, null, 0, 0))
|
|
1371
|
+
shapes.push(spText('Takeaway', { x: boxes.takeaway.x, y: boxes.takeaway.y + 0.05, w: boxes.takeaway.w, h: boxes.takeaway.h - 0.05 }, [paraRich(prefix + tkText, { size: 1350, color: fg })], {
|
|
1372
|
+
anchor: 'ctr',
|
|
1373
|
+
ins: [0, 20000, 0, 20000],
|
|
1374
|
+
}))
|
|
1375
|
+
} else {
|
|
1376
|
+
const accentSoft = theme?.tokens?.accentSoft || surface1
|
|
1377
|
+
shapes.push(spText('Takeaway', boxes.takeaway, [paraRich('▸ ' + tkText, { size: 1350, color: fg, bold: true })], {
|
|
1378
|
+
anchor: 'ctr',
|
|
1379
|
+
fill: accentSoft,
|
|
1380
|
+
stroke: hairline,
|
|
1381
|
+
strokeW: 9525,
|
|
1382
|
+
roundAdj: chromeCfg.cardRadiusPx > 0 ? 4000 : 0,
|
|
1383
|
+
ins: [201168, 36576, 146304, 36576],
|
|
1384
|
+
}))
|
|
1385
|
+
shapes.push(spRect('Takeaway accent', boxEmu({ x: boxes.takeaway.x, y: boxes.takeaway.y, w: 0.06, h: boxes.takeaway.h }), accent, null, 0, 0))
|
|
1386
|
+
}
|
|
1387
|
+
}
|
|
1388
|
+
|
|
1389
|
+
// Footer source & chrome-aware Page number
|
|
1390
|
+
const rawSourceLine = slide.source || slide.chart?.source
|
|
1391
|
+
const formattedSource = rawSourceLine
|
|
1392
|
+
? (/^(?:数据来源|来源|出处|测算口径|实验环境|统计口径|Source|Note)\s*[::]/i.test(rawSourceLine.trim())
|
|
1393
|
+
? rawSourceLine.trim()
|
|
1394
|
+
: (isEn ? 'Source: ' : '数据来源:') + rawSourceLine.trim())
|
|
1395
|
+
: ''
|
|
1396
|
+
const folio = String(index + 1).padStart(2, '0') + ' / ' + String(Math.max(1, total)).padStart(2, '0')
|
|
1397
|
+
|
|
1398
|
+
if (chromeCfg.folioPos === 'beamer-bar') {
|
|
1399
|
+
shapes.push(spRect('Beamer footer band', boxEmu({ x: 0, y: 7.04, w: CANVAS.w, h: 0.46 }), surface1, null, 0, 0))
|
|
1400
|
+
shapes.push(spLine('Beamer footer rule', 0, toEmu(7.04), toEmu(CANVAS.w), toEmu(7.04), hairline, 6350, 'solid'))
|
|
1401
|
+
const leftText = formattedSource || manifest?.brand?.footer || manifest?.title || ''
|
|
1402
|
+
if (leftText) {
|
|
1403
|
+
shapes.push(spText(formattedSource ? 'Source' : 'Beamer zone left', { x: 0.65, y: 7.10, w: 4.4, h: 0.32 }, [paraRich(leftText, { size: 950, color: muted })], { anchor: 'ctr', ins: [0, 0, 0, 0] }))
|
|
1404
|
+
}
|
|
1405
|
+
const centerText = (slide.kicker || slide.title || '').trim()
|
|
1406
|
+
if (centerText) {
|
|
1407
|
+
shapes.push(spText('Beamer zone chapter', { x: 5.1, y: 7.10, w: 3.13, h: 0.32 }, [paraRich(centerText, { size: 950, color: secondary, bold: true, align: 'ctr' })], { anchor: 'ctr', ins: [0, 0, 0, 0] }))
|
|
1408
|
+
}
|
|
1409
|
+
shapes.push(spText('Page number', { x: 10.65, y: 7.10, w: 2.03, h: 0.32 }, [paraRich(folio, { size: 950, color: accentText, bold: true, align: 'r' })], { anchor: 'ctr', ins: [0, 0, 0, 0] }))
|
|
1410
|
+
} else {
|
|
1411
|
+
if (formattedSource && !manifest?.brand?.footer) {
|
|
1412
|
+
shapes.push(spText('Source', FOOTER_BOX, [paraRich(formattedSource, { size: 950, color: muted })], { ins: [0, 0, 0, 0] }))
|
|
1413
|
+
} else if (formattedSource && manifest?.brand?.footer) {
|
|
1414
|
+
shapes.push(spText('Source', { x: 5.4, y: 6.95, w: 5.0, h: 0.32 }, [paraRich(formattedSource, { size: 950, color: muted, align: 'r' })], { ins: [0, 0, 0, 0] }))
|
|
1415
|
+
}
|
|
1416
|
+
const folioBox = chromeCfg.folioPos === 'top-right'
|
|
1417
|
+
? { x: 10.65, y: 0.22, w: 2.03, h: 0.28 }
|
|
1418
|
+
: { x: 10.65, y: 6.95, w: 2.03, h: 0.32 }
|
|
1419
|
+
shapes.push(spText('Page number', folioBox, [paraRich(folio, { size: chromeCfg.folioPos === 'top-right' ? 1000 : 950, color: muted, align: 'r' })], { anchor: 'ctr', ins: [0, 0, 0, 0] }))
|
|
1420
|
+
}
|
|
1421
|
+
|
|
1422
|
+
return shapes.join('')
|
|
1423
|
+
}
|
|
1424
|
+
|
|
145
1425
|
export const MEDIA_CSS = `
|
|
146
|
-
.slide--image,.slide--image-left,.slide--image-right,.slide--chart{padding:0;align-items:center}
|
|
147
|
-
.slide--image .slide-inner,.slide--image-left .slide-inner,.slide--image-right .slide-inner,.slide--chart .slide-inner{width:100%;display:flex;justify-content:center}
|
|
1426
|
+
.slide--image,.slide--image-left,.slide--image-right,.slide--chart,.slide--chart-split{padding:0;align-items:center}
|
|
1427
|
+
.slide--image .slide-inner,.slide--image-left .slide-inner,.slide--image-right .slide-inner,.slide--chart .slide-inner,.slide--chart-split .slide-inner{width:100%;display:flex;justify-content:center}
|
|
148
1428
|
.media-canvas{position:relative;width:min(100vw,177.7778vh);height:min(100vh,56.25vw);container-type:inline-size}
|
|
149
|
-
.media-title,.media-image,.media-body,.media-chart,.media-caption{position:absolute;margin:0;max-width:none;box-sizing:border-box}
|
|
150
|
-
.media-
|
|
1429
|
+
.media-kicker,.media-title,.media-image,.media-body,.media-chart,.media-caption,.media-takeaway{position:absolute;margin:0;max-width:none;box-sizing:border-box}
|
|
1430
|
+
.media-kicker{font-size:1.05cqw;line-height:1.2;margin:0}
|
|
1431
|
+
.media-title{font-size:2.95cqw;font-weight:750;line-height:1.18;letter-spacing:-.015em;display:flex;align-items:center;overflow-wrap:anywhere}
|
|
1432
|
+
.media-title--bleed{background:color-mix(in srgb, var(--bg) 88%, transparent);backdrop-filter:blur(10px);padding:1.1cqw 1.6cqw;border-radius:12px;border:1px solid color-mix(in srgb, var(--muted) 32%, transparent);z-index:2}
|
|
1433
|
+
.media-image{overflow:hidden}
|
|
1434
|
+
.media-image--framed{border-radius:12px;background:var(--surface1,var(--panel));border:1px solid var(--hairline,color-mix(in srgb, var(--muted) 28%, transparent));padding:.45cqw}
|
|
1435
|
+
.media-image--framed img{border-radius:8px}
|
|
1436
|
+
.media-image--bleed{border-radius:0}
|
|
151
1437
|
.media-image img{width:100%;height:100%;display:block}
|
|
152
|
-
.media-
|
|
153
|
-
.media-body
|
|
154
|
-
.media-
|
|
155
|
-
.
|
|
1438
|
+
.media-image figcaption{position:absolute;left:.8cqw;right:.8cqw;bottom:.7cqw;padding:.35cqw .7cqw;border-radius:6px;background:color-mix(in srgb, var(--bg) 84%, transparent);color:var(--fg);font-size:1.05cqw}
|
|
1439
|
+
.media-body{display:flex;flex-direction:column;justify-content:center;gap:.9cqw;font-size:1.68cqw;line-height:1.5;overflow-wrap:anywhere}
|
|
1440
|
+
.media-lead{margin:0;font-size:1.82cqw;line-height:1.45;color:var(--ink-secondary,var(--muted));border-left:3px solid var(--accent);padding-left:.85cqw}
|
|
1441
|
+
.media-list{margin:0;padding:0;list-style:none;display:flex;flex-direction:column;gap:.68cqw}
|
|
1442
|
+
.media-list li{position:relative;padding-left:1.5cqw;margin:0}
|
|
1443
|
+
.media-list li::before{content:"";position:absolute;left:0;top:.55em;width:.44em;height:.44em;border-radius:2px;background:var(--accent)}
|
|
1444
|
+
.media-code{font-family:ui-monospace,SFMono-Regular,Consolas,monospace;font-size:.9em;padding:.08em .36em;border-radius:4px;background:var(--surface2,var(--panel))}
|
|
1445
|
+
.media-insights{display:flex;flex-direction:column;justify-content:space-between;gap:.8cqw}
|
|
1446
|
+
.media-insight-card{flex:1;min-height:0;display:flex;flex-direction:column;justify-content:center;gap:.25cqw;padding:.85cqw 1.1cqw;border-radius:10px;background:var(--surface1,var(--panel));border:1px solid var(--hairline,color-mix(in srgb, var(--muted) 28%, transparent))}
|
|
1447
|
+
.media-insight-tag{font-size:.92cqw;font-weight:700;letter-spacing:.1em;text-transform:uppercase;color:var(--accent-text,var(--accent))}
|
|
1448
|
+
.media-insight-val{font-size:2.25cqw;font-weight:800;line-height:1.05;font-variant-numeric:tabular-nums;color:var(--accent-text,var(--accent))}
|
|
1449
|
+
.media-insight-val small{font-size:.52em;font-weight:600;margin-left:.22em;color:var(--muted)}
|
|
1450
|
+
.media-insight-head{font-size:1.36cqw;font-weight:700;line-height:1.25;color:var(--fg)}
|
|
1451
|
+
.media-insight-text{margin:0;font-size:1.22cqw;line-height:1.38;color:var(--ink-secondary,var(--muted))}
|
|
1452
|
+
.media-caption{color:var(--muted);font-size:1.12cqw;line-height:1.3}
|
|
1453
|
+
.media-takeaway{display:flex;align-items:center;gap:.65cqw;padding:.45cqw 1.15cqw;border-radius:var(--radius-sm,8px);background:var(--accent-soft,var(--surface1,var(--panel)));border:1px solid var(--hairline,color-mix(in srgb, var(--muted) 28%, transparent));border-left:5px solid var(--accent);font-size:1.28cqw;font-weight:700;color:var(--fg)}
|
|
1454
|
+
.media-takeaway .takeaway-arrow{color:var(--accent-text,var(--accent));font-size:1.1em;line-height:1}
|
|
1455
|
+
.media-source{position:absolute;left:4.65%;bottom:2.6%;max-width:65%;font-size:clamp(10px,.95cqw,13px);color:var(--muted)}
|
|
1456
|
+
.native-chart{width:100%;height:100%;font-family:var(--font-body);font-variant-numeric:tabular-nums}
|
|
156
1457
|
.chart-data{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%)}
|
|
157
|
-
.brand-logo{position:absolute;right:
|
|
158
|
-
.brand-footer{position:absolute;left:
|
|
159
|
-
body.printing .brand-footer{display:block}
|
|
1458
|
+
.brand-logo{position:absolute;right:5.2%;top:2.2%;width:7.1%;height:5.4%;object-fit:contain;pointer-events:none;z-index:4}
|
|
1459
|
+
.brand-footer{position:absolute;left:4.875%;bottom:2.8%;max-width:65%;font-size:clamp(10px,.95cqw,14px);color:var(--muted)}
|
|
1460
|
+
body.printing .brand-footer,body.printing .media-source{display:block}
|
|
1461
|
+
.media-title--ruled{border-bottom:1px solid var(--hairline);padding-bottom:.4cqw}
|
|
1462
|
+
.media-title--editorial{border-bottom:1px solid var(--hairline);padding-bottom:.3cqw}
|
|
1463
|
+
.media-title--gov{border-bottom:2px solid var(--accent);box-shadow:0 4px 0 0 var(--bg),0 5.5px 0 0 var(--accent2);padding-bottom:.4cqw}
|
|
1464
|
+
.media-kicker--pill{display:inline-flex;align-items:center;width:auto!important;height:auto!important;background:var(--accent-soft);padding:.28cqw 1cqw;border-radius:99px}
|
|
1465
|
+
.media-consulting-tracker{position:absolute;right:4.875%;top:5.4%;background:var(--accent-soft);border:1px solid var(--accent);padding:.28cqw .9cqw;font-size:.92cqw;margin:0}
|
|
1466
|
+
.media-editorial-bar{position:absolute;left:4.875%;right:4.875%;top:2.8%;display:flex;justify-content:space-between;align-items:center;border-bottom:1px solid var(--hairline);padding-bottom:.35cqw;font-size:.95cqw;color:var(--muted)}
|
|
1467
|
+
.media-kicker-inline{margin:0!important;font-size:.95cqw}
|
|
1468
|
+
.media-beamer-band{position:absolute;left:0;right:0;top:0;height:17%;background:var(--surface1,var(--panel));border-bottom:2.5px solid var(--accent);padding:1.2cqw 4.875%;display:flex;flex-direction:column;justify-content:center;gap:.3cqw;box-sizing:border-box}
|
|
1469
|
+
.media-kicker-band{margin:0!important;font-size:.92cqw}
|
|
1470
|
+
.media-title-band{margin:0;font-size:2.45cqw;font-weight:750;line-height:1.15;color:var(--fg)}
|
|
1471
|
+
.media-beamer-status{position:absolute;left:0;right:0;bottom:0;height:6%;background:var(--surface1,var(--panel));border-top:1px solid var(--hairline);padding:0 4.875%;display:grid;grid-template-columns:1fr auto 1fr;align-items:center;font-size:.92cqw;color:var(--muted);font-variant-numeric:tabular-nums}
|
|
1472
|
+
.media-beamer-mid{text-align:center;font-weight:600;color:var(--ink-secondary)}
|
|
1473
|
+
.media-beamer-right{text-align:right;font-weight:700;color:var(--accent-text)}
|
|
1474
|
+
.slide[data-chrome="consulting-classic"] .media-image--framed,.slide[data-chrome="consulting-classic"] .media-insight-card{border-radius:0;border-left:3.5px solid var(--accent)}
|
|
1475
|
+
.slide[data-chrome="consulting-classic"] .media-takeaway{background:transparent;border:0;border-top:1.5px solid var(--accent);border-radius:0;padding:.45cqw 0 0}
|
|
1476
|
+
.slide[data-chrome="keynote-spatial"] .media-image--framed,.slide[data-chrome="keynote-spatial"] .media-insight-card{border:0;border-radius:18px}
|
|
1477
|
+
.slide[data-chrome="keynote-spatial"] .media-takeaway{background:transparent;border:0;justify-content:center;text-align:center;color:var(--ink-secondary);font-weight:500}
|
|
1478
|
+
.slide[data-chrome="editorial-folio"] .media-image--framed,.slide[data-chrome="editorial-folio"] .media-insight-card{border-radius:0}
|
|
1479
|
+
.slide[data-chrome="editorial-folio"] .media-takeaway{background:transparent;border:0;border-top:1px solid var(--hairline);border-radius:0;padding:.45cqw 0 0}
|
|
1480
|
+
.slide[data-chrome="academic-minimal"] .media-takeaway{background:transparent;border:0;border-top:1px solid var(--accent);border-bottom:1px solid var(--hairline);border-radius:0;padding:.35cqw 0}
|
|
1481
|
+
.slide[data-chrome="academic-minimal"] .media-canvas .slide-folio{display:none}
|
|
160
1482
|
`
|