dsh-ppt 0.24.2 → 0.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/README.en.md +13 -13
- package/README.md +13 -13
- package/docs/DATA.md +2 -2
- package/docs/REFERENCE.en.md +8 -8
- package/docs/REFERENCE.zh.md +8 -8
- package/docs/USAGE.en.md +11 -7
- package/docs/USAGE.md +11 -7
- package/docs/VALIDATION.md +4 -0
- package/docs/WORKBENCH.md +4 -4
- package/docs/assets/intro/workflow-en-dark.svg +1 -1
- package/docs/assets/intro/workflow-en-light.svg +1 -1
- package/docs/assets/intro/workflow-en-mobile-dark.svg +1 -1
- package/docs/assets/intro/workflow-en-mobile-light.svg +1 -1
- package/docs/assets/intro/workflow-zh-dark.svg +1 -1
- package/docs/assets/intro/workflow-zh-light.svg +1 -1
- package/docs/assets/intro/workflow-zh-mobile-dark.svg +1 -1
- package/docs/assets/intro/workflow-zh-mobile-light.svg +1 -1
- package/lib/client.js +3435 -467
- package/lib/ecosystem.d.ts +73 -0
- package/lib/ecosystem.js +1352 -0
- package/lib/execution.d.ts +6 -1
- package/lib/execution.js +69 -0
- package/lib/tools.js +77 -0
- package/lib/types.d.ts +57 -1
- package/lib/workbench-language.js +4 -0
- package/lib/workbench.d.ts +2 -0
- package/lib/workbench.js +331 -8
- package/package.json +1 -1
- package/skills/dsh-ppt/SKILL.md +3 -3
- package/skills/dsh-ppt/package.json +1 -1
- package/skills/dsh-ppt/references/advanced.md +10 -5
- package/skills/dsh-ppt/references/syntax.md +1 -0
- package/skills/dsh-ppt/scripts/build-deck.mjs +39 -8
- package/skills/dsh-ppt/scripts/deck-advanced.mjs +50 -13
- package/skills/dsh-ppt/scripts/deck-chrome.mjs +1706 -0
- package/skills/dsh-ppt/scripts/deck-core.mjs +116 -6
- package/skills/dsh-ppt/scripts/deck-delivery.mjs +636 -41
- package/skills/dsh-ppt/scripts/deck-diagrams.mjs +2842 -0
- package/skills/dsh-ppt/scripts/deck-director.mjs +49 -3
- package/skills/dsh-ppt/scripts/deck-layouts.mjs +482 -5270
- package/skills/dsh-ppt/scripts/deck-mermaid.mjs +2737 -0
- package/skills/dsh-ppt/scripts/deck-office.mjs +1541 -0
|
@@ -0,0 +1,2842 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* deck-diagrams.mjs —— dsh-ppt 的 10 套重型咨询与工程图示编译器:
|
|
3
|
+
* gantt / architecture / harvey / tam / org / marimekko / sankey / value-chain / swot / process。
|
|
4
|
+
*
|
|
5
|
+
* 零外部运行时依赖,仅使用 Node 内置模块。
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { relativeLuminance, mixHex } from './deck-themes.mjs'
|
|
9
|
+
import {
|
|
10
|
+
CANVAS_IN,
|
|
11
|
+
roundRectAdj,
|
|
12
|
+
escapeXml,
|
|
13
|
+
escapeHtml,
|
|
14
|
+
stripInlineMarkdown,
|
|
15
|
+
renderInlineHtml,
|
|
16
|
+
computeTextFit,
|
|
17
|
+
resolveEffectiveItems,
|
|
18
|
+
VALID_STATUS,
|
|
19
|
+
statusPalette,
|
|
20
|
+
isNumericCell,
|
|
21
|
+
ooxmlRichParagraph,
|
|
22
|
+
ooxmlShape,
|
|
23
|
+
ooxmlCustGeomShape,
|
|
24
|
+
ooxmlLine,
|
|
25
|
+
computeBadgePillWidth,
|
|
26
|
+
renderSurfaceCardPptx,
|
|
27
|
+
} from './deck-chrome.mjs'
|
|
28
|
+
|
|
29
|
+
const ZERO_MARGINS = Object.freeze({ l: 0, r: 0, t: 0, b: 0 })
|
|
30
|
+
|
|
31
|
+
export const DIAGRAM_LAYOUTS = new Set([
|
|
32
|
+
'gantt',
|
|
33
|
+
'architecture',
|
|
34
|
+
'harvey',
|
|
35
|
+
'tam',
|
|
36
|
+
'org',
|
|
37
|
+
'marimekko',
|
|
38
|
+
'sankey',
|
|
39
|
+
'value-chain',
|
|
40
|
+
'swot',
|
|
41
|
+
'process',
|
|
42
|
+
])
|
|
43
|
+
|
|
44
|
+
export function parseHarveyValue(rawCell) {
|
|
45
|
+
const clean = stripInlineMarkdown(String(rawCell ?? '')).trim()
|
|
46
|
+
const lower = clean.toLowerCase()
|
|
47
|
+
if (lower === 'full' || lower === '100%' || clean === '●') return { kind: 'harvey', pct: 100, label: '100%' }
|
|
48
|
+
if (lower === '75%' || clean === '◕') return { kind: 'harvey', pct: 75, label: '75%' }
|
|
49
|
+
if (lower === '50%' || lower === 'half' || clean === '◑') return { kind: 'harvey', pct: 50, label: '50%' }
|
|
50
|
+
if (lower === '25%' || clean === '◔') return { kind: 'harvey', pct: 25, label: '25%' }
|
|
51
|
+
if (lower === '0%' || lower === 'none' || clean === '○') return { kind: 'harvey', pct: 0, label: '0%' }
|
|
52
|
+
if (lower === 'yes' || clean === '✓') return { kind: 'check', ok: true, label: '✓' }
|
|
53
|
+
if (lower === 'no' || clean === '✗') return { kind: 'check', ok: false, label: '✗' }
|
|
54
|
+
return null
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function findHarveyOursCol(headerRow, cols) {
|
|
58
|
+
const hit = headerRow.findIndex((h) => /ours|本方案|我们|dsh|推荐|self|\bour\b/i.test(stripInlineMarkdown(h)))
|
|
59
|
+
if (hit >= 0) return hit
|
|
60
|
+
return cols >= 3 ? cols - 1 : -1
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function renderHarveyBallPptx(parsed, cx, cy, sizeIn, isOurs, nextIdFn, theme, langAttr) {
|
|
64
|
+
const tk = theme.tokens
|
|
65
|
+
const x = cx - sizeIn / 2
|
|
66
|
+
const y = cy - sizeIn / 2
|
|
67
|
+
const fillCol = isOurs ? tk.accentPrimary : tk.inkPrimary
|
|
68
|
+
const ringCol = isOurs ? tk.accentPrimary : tk.inkMuted
|
|
69
|
+
const bgCol = isOurs ? tk.accentSoft : tk.canvas
|
|
70
|
+
const shapes = []
|
|
71
|
+
|
|
72
|
+
if (parsed.kind === 'check') {
|
|
73
|
+
const badgeFill = parsed.ok ? (isOurs ? tk.accentPrimary : tk.positive) : tk.surface2
|
|
74
|
+
const badgeFg = parsed.ok ? '#FFFFFF' : tk.inkMuted
|
|
75
|
+
shapes.push(ooxmlShape(nextIdFn(), 'Harvey Check', { x, y, w: sizeIn, h: sizeIn }, {
|
|
76
|
+
preset: 'ellipse',
|
|
77
|
+
fill: badgeFill,
|
|
78
|
+
stroke: parsed.ok ? '' : tk.hairline,
|
|
79
|
+
strokePt: 0.75,
|
|
80
|
+
anchor: 'ctr',
|
|
81
|
+
marginsIn: ZERO_MARGINS,
|
|
82
|
+
paragraphs: [ooxmlRichParagraph(parsed.ok ? '✓' : '✗', { sizePt: 11.5, color: badgeFg, bold: true, lang: langAttr, align: 'ctr', font: theme.fonts.body, lineHeight: 1.0 })],
|
|
83
|
+
}))
|
|
84
|
+
return shapes.join('')
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (parsed.pct === 100) {
|
|
88
|
+
shapes.push(ooxmlShape(nextIdFn(), 'Harvey 100', { x, y, w: sizeIn, h: sizeIn }, { preset: 'ellipse', fill: fillCol, stroke: fillCol, strokePt: 1.0 }))
|
|
89
|
+
return shapes.join('')
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Base empty ring
|
|
93
|
+
shapes.push(ooxmlShape(nextIdFn(), 'Harvey Ring', { x, y, w: sizeIn, h: sizeIn }, { preset: 'ellipse', fill: bgCol, stroke: parsed.pct === 0 ? ringCol : fillCol, strokePt: 1.25 }))
|
|
94
|
+
|
|
95
|
+
if (parsed.pct > 0) {
|
|
96
|
+
// 25%: 12 o'clock (270deg) to 3 o'clock (360deg); 50%: 12 to 6 (90deg); 75%: 12 to 9 (180deg)
|
|
97
|
+
const startAng = 16200000
|
|
98
|
+
const endAng = parsed.pct === 25 ? 21600000 : parsed.pct === 50 ? 5400000 : 10800000
|
|
99
|
+
shapes.push(ooxmlShape(nextIdFn(), 'Harvey Slice', { x, y, w: sizeIn, h: sizeIn }, {
|
|
100
|
+
preset: 'pie',
|
|
101
|
+
adjs: { adj1: startAng, adj2: endAng },
|
|
102
|
+
fill: fillCol,
|
|
103
|
+
stroke: '',
|
|
104
|
+
}))
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return shapes.join('')
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export function renderHarveyMatrixPptx(slide, area, nextIdFn, chromeCfg, theme, langAttr) {
|
|
111
|
+
const tk = theme.tokens
|
|
112
|
+
const items = resolveEffectiveItems(slide)
|
|
113
|
+
const rawRows = Array.isArray(slide.rows) && slide.rows.length > 0
|
|
114
|
+
? slide.rows
|
|
115
|
+
: items.length > 0
|
|
116
|
+
? [['评估维度', '行业基线', '本方案 / Ours'], ...items.map((it) => [it.title || '', it.delta || '50%', it.value || (it.status === 'positive' ? 'full' : 'full')])]
|
|
117
|
+
: [['维度', '本方案 / Ours'], ['能力项', 'full']]
|
|
118
|
+
const safeRows = rawRows.slice(0, 9)
|
|
119
|
+
const cols = Math.max(2, ...safeRows.map((r) => r.length))
|
|
120
|
+
const headerRow = Array.from({ length: cols }, (_, c) => String(safeRows[0]?.[c] ?? ''))
|
|
121
|
+
const oursCol = findHarveyOursCol(headerRow, cols)
|
|
122
|
+
|
|
123
|
+
// Compute proportional column widths (first col wider for criteria label)
|
|
124
|
+
const firstColW = Math.min(4.6, Math.max(2.8, area.w * (cols <= 3 ? 0.44 : 0.34)))
|
|
125
|
+
const otherW = (area.w - firstColW) / Math.max(1, cols - 1)
|
|
126
|
+
const colXs = []
|
|
127
|
+
const colWs = []
|
|
128
|
+
let cursorX = area.x
|
|
129
|
+
for (let c = 0; c < cols; c += 1) {
|
|
130
|
+
const w = c === 0 ? firstColW : otherW
|
|
131
|
+
colXs.push(cursorX)
|
|
132
|
+
colWs.push(w)
|
|
133
|
+
cursorX += w
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const rowCount = safeRows.length
|
|
137
|
+
const rowH = Math.min(0.62, Math.max(0.40, area.h / Math.max(1, rowCount)))
|
|
138
|
+
const startY = area.y + Math.max(0, (area.h - rowH * rowCount) / 2)
|
|
139
|
+
const shapes = []
|
|
140
|
+
const cellPreset = chromeCfg.cardRadiusPx > 0 ? 'roundRect' : 'rect'
|
|
141
|
+
|
|
142
|
+
safeRows.forEach((row, rIdx) => {
|
|
143
|
+
const isHeader = rIdx === 0
|
|
144
|
+
const y = startY + rIdx * rowH
|
|
145
|
+
for (let c = 0; c < cols; c += 1) {
|
|
146
|
+
const cellText = String(row[c] ?? '')
|
|
147
|
+
const isOurs = c === oursCol
|
|
148
|
+
const x = colXs[c]
|
|
149
|
+
const w = colWs[c]
|
|
150
|
+
const cellFill = isHeader
|
|
151
|
+
? (isOurs ? tk.accentPrimary : tk.surface2)
|
|
152
|
+
: (isOurs ? tk.accentSoft : (rIdx % 2 === 0 ? tk.surface1 : tk.canvas))
|
|
153
|
+
|
|
154
|
+
shapes.push(ooxmlShape(nextIdFn(), 'Harvey Cell ' + rIdx + '-' + c, { x, y, w, h: rowH }, { preset: isHeader && c === 0 ? cellPreset : 'rect', adj: 0, fill: cellFill, stroke: isOurs ? tk.accentPrimary : tk.hairline, strokePt: isOurs ? 0.75 : 0.5 }))
|
|
155
|
+
|
|
156
|
+
const parsed = !isHeader && c > 0 ? parseHarveyValue(cellText) : null
|
|
157
|
+
if (parsed) {
|
|
158
|
+
const ballSize = Math.min(0.28, rowH * 0.56)
|
|
159
|
+
shapes.push(renderHarveyBallPptx(parsed, x + w / 2, y + rowH / 2, ballSize, isOurs, nextIdFn, theme, langAttr))
|
|
160
|
+
} else {
|
|
161
|
+
shapes.push(ooxmlShape(nextIdFn(), 'Harvey Text ' + rIdx + '-' + c, { x: x + 0.08, y: y + 0.03, w: w - 0.16, h: rowH - 0.06 }, {
|
|
162
|
+
txBox: true,
|
|
163
|
+
anchor: 'ctr',
|
|
164
|
+
marginsIn: { l: 0.04, r: 0.04, t: 0.01, b: 0.01 },
|
|
165
|
+
paragraphs: [
|
|
166
|
+
ooxmlRichParagraph(cellText, {
|
|
167
|
+
sizePt: isHeader ? 13.5 : (cols >= 6 ? 12 : 13.5),
|
|
168
|
+
color: isHeader && isOurs ? tk.inkOnAccent : (isOurs ? tk.accentText : tk.inkPrimary),
|
|
169
|
+
bold: isHeader || isOurs,
|
|
170
|
+
lang: langAttr,
|
|
171
|
+
align: c === 0 ? 'l' : 'ctr',
|
|
172
|
+
font: isHeader ? theme.fonts.heading : theme.fonts.body,
|
|
173
|
+
lineHeight: 1.18,
|
|
174
|
+
}),
|
|
175
|
+
],
|
|
176
|
+
}))
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
})
|
|
180
|
+
|
|
181
|
+
return shapes.join('')
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function monogramLetters(name) {
|
|
185
|
+
const clean = stripInlineMarkdown(String(name ?? ''))
|
|
186
|
+
.replace(/\s*(?:博士|教授|先生|女士|院士|院长|主任|总|Ph\.?D\.?|M\.?D\.?|MBA).*$/i, '')
|
|
187
|
+
.trim()
|
|
188
|
+
if (!clean) return 'T'
|
|
189
|
+
if (/[\u4E00-\u9FFF]/.test(clean)) {
|
|
190
|
+
return clean.replace(/\s+/g, '').slice(0, 1)
|
|
191
|
+
}
|
|
192
|
+
const parts = clean.split(/\s+/).filter(Boolean)
|
|
193
|
+
return parts.length >= 2
|
|
194
|
+
? (parts[0][0] + parts[1][0]).toUpperCase()
|
|
195
|
+
: clean.slice(0, 2).toUpperCase()
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// ---------------------------------------------------------------------------
|
|
199
|
+
// Phase 4 Pinnacle Layouts 1..4(Marimekko / Sankey / Porter Value Chain / SWOT)
|
|
200
|
+
// ---------------------------------------------------------------------------
|
|
201
|
+
|
|
202
|
+
function extractNumberAndUnit(raw) {
|
|
203
|
+
const s = stripInlineMarkdown(String(raw ?? '')).trim()
|
|
204
|
+
if (!s) return { num: 0, unit: '', raw: '' }
|
|
205
|
+
const parenMatch = /[((]\s*([¥$€£]?\s*[+-]?\d[\d,.]*)\s*([^))]*)[))]/.exec(s)
|
|
206
|
+
if (parenMatch) {
|
|
207
|
+
const num = parseFloat(parenMatch[1].replace(/[¥$€£,\s]/g, ''))
|
|
208
|
+
const prefixSym = /^[¥$€£]/.exec(parenMatch[1].trim())?.[0] ?? ''
|
|
209
|
+
const suffixUnit = parenMatch[2].trim()
|
|
210
|
+
return {
|
|
211
|
+
num: Number.isFinite(num) ? Math.abs(num) : 0,
|
|
212
|
+
unit: suffixUnit || prefixSym,
|
|
213
|
+
prefixSym,
|
|
214
|
+
label: parenMatch[1].trim() + (suffixUnit ? suffixUnit : ''),
|
|
215
|
+
cleanTitle: s.replace(parenMatch[0], '').trim(),
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
const direct = /([¥$€£]?\s*[+-]?\d[\d,.]*)\s*([%%万亿元美元BmkMKTb]*)/.exec(s)
|
|
219
|
+
if (direct) {
|
|
220
|
+
const num = parseFloat(direct[1].replace(/[¥$€£,\s]/g, ''))
|
|
221
|
+
const prefixSym = /^[¥$€£]/.exec(direct[1].trim())?.[0] ?? ''
|
|
222
|
+
const suffixUnit = direct[2].trim()
|
|
223
|
+
return {
|
|
224
|
+
num: Number.isFinite(num) ? Math.abs(num) : 0,
|
|
225
|
+
unit: suffixUnit || prefixSym,
|
|
226
|
+
prefixSym,
|
|
227
|
+
label: direct[1].trim() + suffixUnit,
|
|
228
|
+
cleanTitle: s.replace(direct[0], '').replace(/^[·::\-—\s]+|[·::\-—\s]+$/g, '').trim() || s,
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return { num: 0, unit: '', prefixSym: '', label: '', cleanTitle: s }
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
const OURS_SERIES_RE = /本方案|我们|ours|dsh|推荐|自有|\bour\b|\bself\b/i
|
|
235
|
+
|
|
236
|
+
export function computeMarimekkoModel(slide, langOrAttr = 'zh') {
|
|
237
|
+
const isEn = langOrAttr === 'en' || langOrAttr === 'en-US'
|
|
238
|
+
const rawRows = Array.isArray(slide.rows) ? slide.rows.filter((r) => Array.isArray(r) && r.length >= 2) : []
|
|
239
|
+
|
|
240
|
+
if (rawRows.length >= 2) {
|
|
241
|
+
const headerRow = rawRows[0].map((c) => stripInlineMarkdown(c))
|
|
242
|
+
const colCount = Math.min(7, headerRow.length - 1)
|
|
243
|
+
const parsedHeaders = Array.from({ length: colCount }, (_, i) => {
|
|
244
|
+
const cell = headerRow[i + 1] ?? ('S' + (i + 1))
|
|
245
|
+
const ext = extractNumberAndUnit(cell)
|
|
246
|
+
return { title: ext.cleanTitle || cell, weight: ext.num, unit: ext.unit, prefixSym: ext.prefixSym || '', sizeLabel: ext.label }
|
|
247
|
+
})
|
|
248
|
+
|
|
249
|
+
// 判断第 1 行是否为独立市场规模/权重行
|
|
250
|
+
let seriesStartRow = 1
|
|
251
|
+
if (rawRows.length >= 3) {
|
|
252
|
+
const row1Label = stripInlineMarkdown(rawRows[1][0] ?? '')
|
|
253
|
+
const row1Cells = rawRows[1].slice(1, colCount + 1).map((c) => String(c ?? ''))
|
|
254
|
+
const explicitWeightRow = /规模|容量|体量|权重|总额|size|weight|tam|market|volume/i.test(row1Label)
|
|
255
|
+
const headersLackWeights = parsedHeaders.every((h) => h.weight <= 0)
|
|
256
|
+
const row1NoPct = !row1Cells.some((c) => /[%%]/.test(c))
|
|
257
|
+
const row1Nums = row1Cells.map((c) => extractNumberAndUnit(c))
|
|
258
|
+
const row1Sum = row1Nums.reduce((s, x) => s + x.num, 0)
|
|
259
|
+
if (explicitWeightRow || (headersLackWeights && row1NoPct && row1Sum > 105)) {
|
|
260
|
+
seriesStartRow = 2
|
|
261
|
+
row1Nums.forEach((n, idx) => {
|
|
262
|
+
if (n.num > 0) {
|
|
263
|
+
parsedHeaders[idx].weight = n.num
|
|
264
|
+
parsedHeaders[idx].unit = n.unit || parsedHeaders[idx].unit
|
|
265
|
+
parsedHeaders[idx].prefixSym = n.prefixSym || parsedHeaders[idx].prefixSym
|
|
266
|
+
parsedHeaders[idx].sizeLabel = n.label
|
|
267
|
+
}
|
|
268
|
+
})
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
const totalRawWeight = parsedHeaders.reduce((s, h) => s + (h.weight > 0 ? h.weight : 0), 0)
|
|
273
|
+
const effectiveWeights = parsedHeaders.map((h) => (totalRawWeight > 0 ? (h.weight > 0 ? h.weight : totalRawWeight / colCount * 0.35) : 100 / colCount))
|
|
274
|
+
const weightSum = effectiveWeights.reduce((a, b) => a + b, 0) || 1
|
|
275
|
+
const dominantUnit = parsedHeaders.find((h) => h.unit && h.unit !== '%')?.unit ?? ''
|
|
276
|
+
const dominantPrefix = parsedHeaders.find((h) => h.prefixSym)?.prefixSym ?? ''
|
|
277
|
+
|
|
278
|
+
const seriesRows = rawRows.slice(seriesStartRow, seriesStartRow + 6)
|
|
279
|
+
const seriesNames = seriesRows.map((r, idx) => stripInlineMarkdown(r[0] || (isEn ? 'Segment ' + (idx + 1) : '竞争方 ' + (idx + 1))))
|
|
280
|
+
|
|
281
|
+
let cursorX = 0
|
|
282
|
+
const columns = parsedHeaders.map((h, cIdx) => {
|
|
283
|
+
const widthRatio = effectiveWeights[cIdx] / weightSum
|
|
284
|
+
const colStart = cursorX
|
|
285
|
+
cursorX += widthRatio
|
|
286
|
+
|
|
287
|
+
const rawVals = seriesRows.map((r) => {
|
|
288
|
+
const num = extractNumberAndUnit(r[cIdx + 1] ?? '0').num
|
|
289
|
+
return num > 0 ? num : 0
|
|
290
|
+
})
|
|
291
|
+
const colSum = rawVals.reduce((a, b) => a + b, 0) || 1
|
|
292
|
+
let cursorY = 0
|
|
293
|
+
const segments = seriesNames.map((sName, sIdx) => {
|
|
294
|
+
const heightRatio = rawVals[sIdx] / colSum
|
|
295
|
+
const seg = {
|
|
296
|
+
seriesName: sName,
|
|
297
|
+
seriesIndex: sIdx,
|
|
298
|
+
rawVal: rawVals[sIdx],
|
|
299
|
+
heightRatio,
|
|
300
|
+
sharePct: Math.round(heightRatio * 100),
|
|
301
|
+
yRatio: cursorY,
|
|
302
|
+
isOurs: OURS_SERIES_RE.test(sName),
|
|
303
|
+
}
|
|
304
|
+
cursorY += heightRatio
|
|
305
|
+
return seg
|
|
306
|
+
})
|
|
307
|
+
|
|
308
|
+
return {
|
|
309
|
+
title: h.title,
|
|
310
|
+
weight: effectiveWeights[cIdx],
|
|
311
|
+
sizeLabel: h.sizeLabel || (Math.round(widthRatio * 100) + '%'),
|
|
312
|
+
widthRatio,
|
|
313
|
+
xRatio: colStart,
|
|
314
|
+
segments,
|
|
315
|
+
}
|
|
316
|
+
})
|
|
317
|
+
|
|
318
|
+
const seriesSummary = seriesNames.map((name, sIdx) => {
|
|
319
|
+
const weightedShare = columns.reduce((acc, col) => acc + col.widthRatio * (col.segments[sIdx]?.heightRatio ?? 0), 0)
|
|
320
|
+
return { name, index: sIdx, weightedPct: Math.round(weightedShare * 100), isOurs: OURS_SERIES_RE.test(name) }
|
|
321
|
+
})
|
|
322
|
+
|
|
323
|
+
const totalLabel = totalRawWeight > 0
|
|
324
|
+
? (dominantPrefix + (Number.isInteger(totalRawWeight) ? totalRawWeight.toLocaleString('en-US') : totalRawWeight.toFixed(1)) + (dominantUnit && dominantUnit !== dominantPrefix ? ' ' + dominantUnit : ''))
|
|
325
|
+
: '100%'
|
|
326
|
+
|
|
327
|
+
return { columns, seriesSummary, totalLabel, hasExplicitWeights: totalRawWeight > 0 }
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
// 从 items[] / bullets[] 归一构建 Marimekko 模型
|
|
331
|
+
const rawItems = resolveEffectiveItems(slide).slice(0, 7)
|
|
332
|
+
const items = rawItems.length > 0
|
|
333
|
+
? rawItems
|
|
334
|
+
: [
|
|
335
|
+
{ title: isEn ? 'Enterprise' : '政企市场', value: '450', unit: isEn ? 'B' : '亿', bullets: [(isEn ? 'Ours: 42%' : '本方案: 42%'), (isEn ? 'Peer B: 33%' : '厂商B: 33%'), (isEn ? 'Others: 25%' : '其他: 25%')] },
|
|
336
|
+
{ title: isEn ? 'Finance' : '金融信创', value: '320', unit: isEn ? 'B' : '亿', bullets: [(isEn ? 'Ours: 36%' : '本方案: 36%'), (isEn ? 'Peer B: 39%' : '厂商B: 39%'), (isEn ? 'Others: 25%' : '其他: 25%')] },
|
|
337
|
+
]
|
|
338
|
+
|
|
339
|
+
const seriesOrder = []
|
|
340
|
+
const ensureSeries = (name) => {
|
|
341
|
+
const key = name.trim()
|
|
342
|
+
let idx = seriesOrder.indexOf(key)
|
|
343
|
+
if (idx < 0 && seriesOrder.length < 6) {
|
|
344
|
+
idx = seriesOrder.length
|
|
345
|
+
seriesOrder.push(key)
|
|
346
|
+
}
|
|
347
|
+
return idx
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
const parsedCols = items.map((it, idx) => {
|
|
351
|
+
const valInfo = it.value
|
|
352
|
+
? extractNumberAndUnit(it.value + (it.unit ? it.unit : ''))
|
|
353
|
+
: extractNumberAndUnit(it.title || '')
|
|
354
|
+
const rawSegLines = Array.isArray(it.bullets) && it.bullets.length > 0
|
|
355
|
+
? it.bullets
|
|
356
|
+
: (it.text ? it.text.split(/\s*[||;;]\s*/) : [])
|
|
357
|
+
const segPairs = rawSegLines.map((line, lIdx) => {
|
|
358
|
+
const cleanLine = stripInlineMarkdown(line)
|
|
359
|
+
const kv = /^([^::]+?)[::\s]\s*([+-]?\d+(?:\.\d+)?)\s*[%%]?/.exec(cleanLine)
|
|
360
|
+
|| /^(.+?)\s+([+-]?\d+(?:\.\d+)?)\s*[%%]$/.exec(cleanLine)
|
|
361
|
+
if (kv) {
|
|
362
|
+
const sName = kv[1].trim()
|
|
363
|
+
ensureSeries(sName)
|
|
364
|
+
return { name: sName, val: Math.max(0, parseFloat(kv[2]) || 0) }
|
|
365
|
+
}
|
|
366
|
+
const fallbackNum = extractNumberAndUnit(cleanLine)
|
|
367
|
+
const sName = fallbackNum.cleanTitle || (isEn ? 'Tier ' + (lIdx + 1) : '份额 ' + (lIdx + 1))
|
|
368
|
+
ensureSeries(sName)
|
|
369
|
+
return { name: sName, val: fallbackNum.num > 0 ? fallbackNum.num : 100 / Math.max(1, rawSegLines.length) }
|
|
370
|
+
})
|
|
371
|
+
if (segPairs.length === 0) {
|
|
372
|
+
const defaultName = isEn ? 'Ours' : '本方案'
|
|
373
|
+
const restName = isEn ? 'Others' : '其他厂商'
|
|
374
|
+
const pVal = valInfo.num > 0 && valInfo.unit === '%' ? Math.min(100, valInfo.num) : 45
|
|
375
|
+
ensureSeries(defaultName)
|
|
376
|
+
ensureSeries(restName)
|
|
377
|
+
segPairs.push({ name: defaultName, val: pVal }, { name: restName, val: Math.max(0, 100 - pVal) })
|
|
378
|
+
}
|
|
379
|
+
return {
|
|
380
|
+
title: (it.value ? (it.title || ('S' + (idx + 1))) : (valInfo.cleanTitle || it.title || ('S' + (idx + 1)))),
|
|
381
|
+
weight: valInfo.unit !== '%' && valInfo.num > 0 ? valInfo.num : 0,
|
|
382
|
+
unit: it.unit || (valInfo.unit !== '%' ? valInfo.unit : ''),
|
|
383
|
+
prefixSym: valInfo.prefixSym || '',
|
|
384
|
+
sizeLabel: it.value ? (it.value + (it.unit || '')) : (valInfo.unit !== '%' ? valInfo.label : ''),
|
|
385
|
+
segPairs,
|
|
386
|
+
}
|
|
387
|
+
})
|
|
388
|
+
|
|
389
|
+
const totalRawWeight = parsedCols.reduce((s, c) => s + (c.weight > 0 ? c.weight : 0), 0)
|
|
390
|
+
const effWeights = parsedCols.map((c) => (totalRawWeight > 0 ? (c.weight > 0 ? c.weight : totalRawWeight / parsedCols.length * 0.35) : 100 / parsedCols.length))
|
|
391
|
+
const weightSum = effWeights.reduce((a, b) => a + b, 0) || 1
|
|
392
|
+
const domUnit = parsedCols.find((c) => c.unit)?.unit ?? ''
|
|
393
|
+
const domPrefix = parsedCols.find((c) => c.prefixSym)?.prefixSym ?? ''
|
|
394
|
+
|
|
395
|
+
let cursorX = 0
|
|
396
|
+
const columns = parsedCols.map((col, cIdx) => {
|
|
397
|
+
const widthRatio = effWeights[cIdx] / weightSum
|
|
398
|
+
const xRatio = cursorX
|
|
399
|
+
cursorX += widthRatio
|
|
400
|
+
|
|
401
|
+
const valBySeries = seriesOrder.map((sName) => {
|
|
402
|
+
const hit = col.segPairs.find((p) => p.name === sName)
|
|
403
|
+
return hit ? hit.val : 0
|
|
404
|
+
})
|
|
405
|
+
const colSum = valBySeries.reduce((a, b) => a + b, 0) || 1
|
|
406
|
+
let cursorY = 0
|
|
407
|
+
const segments = seriesOrder.map((sName, sIdx) => {
|
|
408
|
+
const heightRatio = valBySeries[sIdx] / colSum
|
|
409
|
+
const seg = {
|
|
410
|
+
seriesName: sName,
|
|
411
|
+
seriesIndex: sIdx,
|
|
412
|
+
rawVal: valBySeries[sIdx],
|
|
413
|
+
heightRatio,
|
|
414
|
+
sharePct: Math.round(heightRatio * 100),
|
|
415
|
+
yRatio: cursorY,
|
|
416
|
+
isOurs: OURS_SERIES_RE.test(sName),
|
|
417
|
+
}
|
|
418
|
+
cursorY += heightRatio
|
|
419
|
+
return seg
|
|
420
|
+
})
|
|
421
|
+
|
|
422
|
+
return {
|
|
423
|
+
title: col.title,
|
|
424
|
+
weight: effWeights[cIdx],
|
|
425
|
+
sizeLabel: col.sizeLabel || (Math.round(widthRatio * 100) + '%'),
|
|
426
|
+
widthRatio,
|
|
427
|
+
xRatio,
|
|
428
|
+
segments,
|
|
429
|
+
}
|
|
430
|
+
})
|
|
431
|
+
|
|
432
|
+
const seriesSummary = seriesOrder.map((name, sIdx) => {
|
|
433
|
+
const weightedShare = columns.reduce((acc, col) => acc + col.widthRatio * (col.segments[sIdx]?.heightRatio ?? 0), 0)
|
|
434
|
+
return { name, index: sIdx, weightedPct: Math.round(weightedShare * 100), isOurs: OURS_SERIES_RE.test(name) }
|
|
435
|
+
})
|
|
436
|
+
|
|
437
|
+
const totalLabel = totalRawWeight > 0
|
|
438
|
+
? (domPrefix + (Number.isInteger(totalRawWeight) ? totalRawWeight.toLocaleString('en-US') : totalRawWeight.toFixed(1)) + (domUnit && domUnit !== domPrefix ? ' ' + domUnit : ''))
|
|
439
|
+
: '100%'
|
|
440
|
+
|
|
441
|
+
return { columns, seriesSummary, totalLabel, hasExplicitWeights: totalRawWeight > 0 }
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
function mekkoSeriesPalette(theme, seriesSummary) {
|
|
445
|
+
const tk = theme.tokens
|
|
446
|
+
const baseColors = [
|
|
447
|
+
tk.accentPrimary,
|
|
448
|
+
tk.accentSecondary,
|
|
449
|
+
mixHex(tk.accentPrimary, theme.dark ? '#94A3B8' : '#475569', 0.48),
|
|
450
|
+
mixHex(tk.accentSecondary, theme.dark ? '#334155' : '#CBD5E1', 0.45),
|
|
451
|
+
theme.dark ? '#334155' : '#CBD5E1',
|
|
452
|
+
theme.dark ? '#1E293B' : '#E2E8F0',
|
|
453
|
+
]
|
|
454
|
+
return seriesSummary.map((s, idx) => {
|
|
455
|
+
const fill = s.isOurs ? tk.accentPrimary : baseColors[(idx + (seriesSummary[0]?.isOurs ? 0 : 1)) % baseColors.length]
|
|
456
|
+
const lum = relativeLuminance(fill)
|
|
457
|
+
const ink = lum < 0.40 ? '#FFFFFF' : '#0F172A'
|
|
458
|
+
return { fill, ink }
|
|
459
|
+
})
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
function renderMarimekkoPptx(slide, area, nextIdFn, chromeCfg, theme, langAttr) {
|
|
463
|
+
const tk = theme.tokens
|
|
464
|
+
const isEn = langAttr === 'en-US'
|
|
465
|
+
const model = computeMarimekkoModel(slide, langAttr)
|
|
466
|
+
const palette = mekkoSeriesPalette(theme, model.seriesSummary)
|
|
467
|
+
const shapes = []
|
|
468
|
+
|
|
469
|
+
const legendW = 2.34
|
|
470
|
+
const gapLegend = 0.26
|
|
471
|
+
const plotX = area.x
|
|
472
|
+
const plotW = area.w - legendW - gapLegend
|
|
473
|
+
const headerH = 0.58
|
|
474
|
+
const axisH = 0.38
|
|
475
|
+
const gridY = area.y + headerH + 0.04
|
|
476
|
+
const gridH = Math.max(2.2, area.h - headerH - axisH - 0.08)
|
|
477
|
+
|
|
478
|
+
// 1. 顶部列宽市场容量标题 + 不等宽 100% 堆叠矩形网格
|
|
479
|
+
model.columns.forEach((col, cIdx) => {
|
|
480
|
+
const cx = plotX + col.xRatio * plotW
|
|
481
|
+
const cw = Math.max(0.28, col.widthRatio * plotW)
|
|
482
|
+
|
|
483
|
+
// 列顶标题 + 规模标签(窄列自动收敛至 8pt 零内边距,确保 5 字区域名如“中东及拉美”单行不折字)
|
|
484
|
+
const isNarrowCol = cw < 0.95
|
|
485
|
+
const headFontPt = cw >= 1.65 ? 11.5 : cw >= 1.15 ? 10 : cw >= 0.95 ? 9 : cw >= 0.60 ? 8 : 7.5
|
|
486
|
+
shapes.push(ooxmlShape(nextIdFn(), 'Mekko Col Header ' + (cIdx + 1), { x: isNarrowCol ? cx : cx + 0.02, y: area.y, w: isNarrowCol ? Math.max(0.28, cw) : Math.max(0.24, cw - 0.04), h: headerH }, {
|
|
487
|
+
txBox: true,
|
|
488
|
+
anchor: 'b',
|
|
489
|
+
marginsIn: { l: isNarrowCol ? 0 : 0.02, r: isNarrowCol ? 0 : 0.02, t: 0, b: 0.03 },
|
|
490
|
+
paragraphs: [
|
|
491
|
+
ooxmlRichParagraph(col.title, { sizePt: headFontPt, color: tk.inkPrimary, bold: true, lang: langAttr, align: 'ctr', font: theme.fonts.heading, lineHeight: 1.12, spaceAfterPt: 1 }),
|
|
492
|
+
ooxmlRichParagraph(col.sizeLabel, { sizePt: isNarrowCol ? 7.5 : Math.max(8.5, headFontPt - 1), color: tk.accentText, bold: true, lang: langAttr, align: 'ctr', font: theme.fonts.body, lineHeight: 1.08 }),
|
|
493
|
+
],
|
|
494
|
+
}))
|
|
495
|
+
|
|
496
|
+
col.segments.forEach((seg, sIdx) => {
|
|
497
|
+
if (seg.heightRatio <= 0.002) return
|
|
498
|
+
const sy = gridY + seg.yRatio * gridH
|
|
499
|
+
const sh = Math.max(0.04, seg.heightRatio * gridH)
|
|
500
|
+
const pal = palette[sIdx] ?? { fill: tk.surface2, ink: tk.inkPrimary }
|
|
501
|
+
const pctText = seg.sharePct + '%'
|
|
502
|
+
const showTwoLines = sh >= 0.50 && cw >= 1.22
|
|
503
|
+
const showPctOnly = !showTwoLines && sh >= 0.25 && cw >= 0.72
|
|
504
|
+
|
|
505
|
+
const paras = showTwoLines
|
|
506
|
+
? [
|
|
507
|
+
ooxmlRichParagraph(seg.seriesName, { sizePt: cw >= 1.6 ? 11 : 10, color: pal.ink, bold: true, lang: langAttr, align: 'ctr', font: theme.fonts.body, lineHeight: 1.1, spaceAfterPt: 1 }),
|
|
508
|
+
ooxmlRichParagraph(pctText, { sizePt: cw >= 1.6 ? 12 : 10.5, color: pal.ink, bold: true, lang: langAttr, align: 'ctr', font: theme.fonts.heading, lineHeight: 1.05 }),
|
|
509
|
+
]
|
|
510
|
+
: showPctOnly
|
|
511
|
+
? [
|
|
512
|
+
ooxmlRichParagraph(pctText, { sizePt: 10, color: pal.ink, bold: true, lang: langAttr, align: 'ctr', font: theme.fonts.heading, lineHeight: 1.0 }),
|
|
513
|
+
]
|
|
514
|
+
: []
|
|
515
|
+
|
|
516
|
+
shapes.push(ooxmlShape(nextIdFn(), 'Mekko Cell ' + (cIdx + 1) + '-' + (sIdx + 1), { x: cx, y: sy, w: cw, h: sh }, {
|
|
517
|
+
preset: 'rect',
|
|
518
|
+
fill: pal.fill,
|
|
519
|
+
stroke: tk.canvas,
|
|
520
|
+
strokePt: 1.5,
|
|
521
|
+
anchor: 'ctr',
|
|
522
|
+
autofit: false,
|
|
523
|
+
marginsIn: { l: 0.04, r: 0.04, t: 0.02, b: 0.02 },
|
|
524
|
+
paragraphs: paras,
|
|
525
|
+
}))
|
|
526
|
+
})
|
|
527
|
+
})
|
|
528
|
+
|
|
529
|
+
// 2. 底部 0%..100% 市场宽度累计坐标轴
|
|
530
|
+
const axisY = gridY + gridH + 0.08
|
|
531
|
+
shapes.push(ooxmlLine(nextIdFn(), 'Mekko Width Axis', { x: plotX, y: axisY }, { x: plotX + plotW, y: axisY }, { color: tk.inkMuted, widthPt: 1.0 }))
|
|
532
|
+
;[0, 25, 50, 75, 100].forEach((tick) => {
|
|
533
|
+
const tx = plotX + (tick / 100) * plotW
|
|
534
|
+
shapes.push(ooxmlLine(nextIdFn(), 'Mekko Tick ' + tick, { x: tx, y: axisY }, { x: tx, y: axisY + 0.06 }, { color: tk.inkMuted, widthPt: 0.75 }))
|
|
535
|
+
const lblW = 0.68
|
|
536
|
+
const lblX = tick === 0 ? tx : tick === 100 ? tx - lblW : tx - lblW / 2
|
|
537
|
+
const algn = tick === 0 ? 'l' : tick === 100 ? 'r' : 'ctr'
|
|
538
|
+
shapes.push(ooxmlShape(nextIdFn(), 'Mekko Tick Label ' + tick, { x: lblX, y: axisY + 0.07, w: lblW, h: 0.24 }, {
|
|
539
|
+
txBox: true,
|
|
540
|
+
anchor: 'ctr',
|
|
541
|
+
marginsIn: ZERO_MARGINS,
|
|
542
|
+
paragraphs: [ooxmlRichParagraph(tick + '%', { sizePt: 9.5, color: tk.inkMuted, lang: langAttr, align: algn, font: theme.fonts.body, lineHeight: 1.0 })],
|
|
543
|
+
}))
|
|
544
|
+
})
|
|
545
|
+
|
|
546
|
+
// 3. 右侧总市场规模 + 系列图例卡片
|
|
547
|
+
const legX = plotX + plotW + gapLegend
|
|
548
|
+
const legBox = { x: legX, y: gridY, w: legendW, h: gridH }
|
|
549
|
+
shapes.push(renderSurfaceCardPptx('Mekko Legend Card', legBox, { fill: tk.surface1, focal: false }, nextIdFn, chromeCfg, theme))
|
|
550
|
+
|
|
551
|
+
shapes.push(ooxmlShape(nextIdFn(), 'Mekko Total Summary', { x: legX + 0.16, y: gridY + 0.14, w: legendW - 0.32, h: 0.78 }, {
|
|
552
|
+
txBox: true,
|
|
553
|
+
anchor: 't',
|
|
554
|
+
marginsIn: ZERO_MARGINS,
|
|
555
|
+
paragraphs: [
|
|
556
|
+
ooxmlRichParagraph(isEn ? 'TOTAL MARKET' : '总市场规模', { sizePt: 9.5, color: tk.inkMuted, bold: true, lang: langAttr, font: theme.fonts.body, spc: 90, spaceAfterPt: 2 }),
|
|
557
|
+
ooxmlRichParagraph(model.totalLabel, { sizePt: 20, color: tk.accentText, bold: true, lang: langAttr, font: theme.fonts.heading, lineHeight: 1.1 }),
|
|
558
|
+
],
|
|
559
|
+
}))
|
|
560
|
+
shapes.push(ooxmlLine(nextIdFn(), 'Mekko Legend Rule', { x: legX + 0.16, y: gridY + 0.98 }, { x: legX + legendW - 0.16, y: gridY + 0.98 }, { color: tk.hairline, widthPt: 0.75 }))
|
|
561
|
+
|
|
562
|
+
const itemStartY = gridY + 1.12
|
|
563
|
+
const availLegH = Math.max(1.0, gridH - 1.24)
|
|
564
|
+
const itemStepY = Math.min(0.46, availLegH / Math.max(1, model.seriesSummary.length))
|
|
565
|
+
model.seriesSummary.forEach((s, idx) => {
|
|
566
|
+
const iy = itemStartY + idx * itemStepY
|
|
567
|
+
const pal = palette[idx] ?? { fill: tk.surface2 }
|
|
568
|
+
shapes.push(ooxmlShape(nextIdFn(), 'Mekko Swatch ' + (idx + 1), { x: legX + 0.18, y: iy + 0.08, w: 0.18, h: 0.18 }, { preset: 'rect', fill: pal.fill, stroke: tk.hairline, strokePt: 0.5 }))
|
|
569
|
+
shapes.push(ooxmlShape(nextIdFn(), 'Mekko Series Label ' + (idx + 1), { x: legX + 0.44, y: iy, w: legendW - 0.58, h: 0.34 }, {
|
|
570
|
+
txBox: true,
|
|
571
|
+
anchor: 'ctr',
|
|
572
|
+
marginsIn: ZERO_MARGINS,
|
|
573
|
+
paragraphs: [ooxmlRichParagraph(s.name + ' **' + s.weightedPct + '%**', { sizePt: 11, color: s.isOurs ? tk.accentText : tk.inkPrimary, bold: s.isOurs, lang: langAttr, font: theme.fonts.body, lineHeight: 1.15 })],
|
|
574
|
+
}))
|
|
575
|
+
})
|
|
576
|
+
|
|
577
|
+
return shapes.join('')
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
function renderMarimekkoHtml(slide, theme, langId) {
|
|
581
|
+
const isEn = langId === 'en'
|
|
582
|
+
const model = computeMarimekkoModel(slide, langId)
|
|
583
|
+
const palette = mekkoSeriesPalette(theme, model.seriesSummary)
|
|
584
|
+
|
|
585
|
+
return (
|
|
586
|
+
'<div class="mekko-board">' +
|
|
587
|
+
'<div class="mekko-main">' +
|
|
588
|
+
'<div class="mekko-headers">' +
|
|
589
|
+
model.columns.map((col) =>
|
|
590
|
+
'<div class="mekko-col-head" style="flex:' + col.widthRatio.toFixed(5) + ' 0 0%">' +
|
|
591
|
+
'<strong class="mekko-col-title">' + escapeHtml(col.title) + '</strong>' +
|
|
592
|
+
'<span class="mekko-col-size">' + escapeHtml(col.sizeLabel) + '</span>' +
|
|
593
|
+
'</div>',
|
|
594
|
+
).join('') +
|
|
595
|
+
'</div>' +
|
|
596
|
+
'<div class="mekko-columns">' +
|
|
597
|
+
model.columns.map((col, cIdx) =>
|
|
598
|
+
'<div class="mekko-col" data-col-index="' + cIdx + '" style="flex:' + col.widthRatio.toFixed(5) + ' 0 0%">' +
|
|
599
|
+
col.segments.filter((s) => s.heightRatio > 0.002).map((seg) => {
|
|
600
|
+
const pal = palette[seg.seriesIndex] ?? { fill: theme.tokens.surface2, ink: theme.tokens.inkPrimary }
|
|
601
|
+
const showFull = seg.heightRatio >= 0.14 && col.widthRatio >= 0.14
|
|
602
|
+
const showPct = seg.heightRatio >= 0.07 && col.widthRatio >= 0.08
|
|
603
|
+
return (
|
|
604
|
+
'<div class="mekko-cell' + (seg.isOurs ? ' is-ours' : '') + '" style="flex:' + seg.heightRatio.toFixed(5) + ' 0 0%;background:' + pal.fill + ';color:' + pal.ink + '">' +
|
|
605
|
+
(showFull ? '<span class="mekko-seg-name">' + escapeHtml(seg.seriesName) + '</span>' : '') +
|
|
606
|
+
(showFull || showPct ? '<strong class="mekko-seg-pct">' + seg.sharePct + '%</strong>' : '') +
|
|
607
|
+
'</div>'
|
|
608
|
+
)
|
|
609
|
+
}).join('') +
|
|
610
|
+
'</div>',
|
|
611
|
+
).join('') +
|
|
612
|
+
'</div>' +
|
|
613
|
+
'<div class="mekko-axis"><span>0%</span><span>25%</span><span>50%</span><span>75%</span><span>100%</span></div>' +
|
|
614
|
+
'</div>' +
|
|
615
|
+
'<aside class="surface-card mekko-legend">' +
|
|
616
|
+
'<div class="mekko-total"><span class="kicker">' + (isEn ? 'TOTAL MARKET' : '总市场规模') + '</span><strong>' + escapeHtml(model.totalLabel) + '</strong></div>' +
|
|
617
|
+
'<ul class="mekko-legend-list">' +
|
|
618
|
+
model.seriesSummary.map((s, idx) => {
|
|
619
|
+
const pal = palette[idx] ?? { fill: theme.tokens.surface2 }
|
|
620
|
+
return (
|
|
621
|
+
'<li class="' + (s.isOurs ? 'is-ours' : '') + '">' +
|
|
622
|
+
'<span class="mekko-swatch" style="background:' + pal.fill + '"></span>' +
|
|
623
|
+
'<span class="mekko-leg-name">' + escapeHtml(s.name) + '</span>' +
|
|
624
|
+
'<strong class="mekko-leg-pct">' + s.weightedPct + '%</strong>' +
|
|
625
|
+
'</li>'
|
|
626
|
+
)
|
|
627
|
+
}).join('') +
|
|
628
|
+
'</ul></aside></div>'
|
|
629
|
+
)
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
function classifySankeyNodeTone(name, explicitStatus) {
|
|
633
|
+
if (explicitStatus && VALID_STATUS.has(explicitStatus)) return explicitStatus
|
|
634
|
+
const s = String(name ?? '')
|
|
635
|
+
if (/成本|费用|支出|损耗|流失|税|折旧|研发投入|营销|管理费|cost|cogs|opex|expense|tax|loss|churn/i.test(s)) return 'negative'
|
|
636
|
+
if (/净利润|营业利润|毛利润|毛利|净利|盈余|自由现金流|留存|profit|income|ebitda|margin|fcf/i.test(s)) return 'positive'
|
|
637
|
+
return 'accent'
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
export function computeSankeyLayout(slide, areaBox = { x: 0.62, y: 1.88, w: 12.09, h: 4.50 }, langOrAttr = 'zh') {
|
|
641
|
+
const isEn = langOrAttr === 'en' || langOrAttr === 'en-US'
|
|
642
|
+
const rawEdges = []
|
|
643
|
+
|
|
644
|
+
const effItems = resolveEffectiveItems(slide)
|
|
645
|
+
if (effItems.length > 0 && effItems.some((it) => it.tag && it.title && !/^\d+$/.test(it.tag))) {
|
|
646
|
+
for (const it of effItems) {
|
|
647
|
+
const src = (it.tag || '').trim()
|
|
648
|
+
const dst = (it.title || '').trim()
|
|
649
|
+
if (!src || !dst || src === dst) continue
|
|
650
|
+
const parsed = extractNumberAndUnit((it.value ?? '') + (it.unit ?? ''))
|
|
651
|
+
const val = parsed.num > 0 ? parsed.num : 10
|
|
652
|
+
const unit = it.unit || parsed.unit || ''
|
|
653
|
+
const valLabel = it.value
|
|
654
|
+
? (it.value + (it.unit && !String(it.value).endsWith(it.unit) ? it.unit : ''))
|
|
655
|
+
: (parsed.label || String(val))
|
|
656
|
+
rawEdges.push({ source: src, target: dst, value: val, unit, valueLabel: valLabel, delta: it.delta || '', status: it.status })
|
|
657
|
+
}
|
|
658
|
+
} else if (Array.isArray(slide.rows) && slide.rows.length >= 2) {
|
|
659
|
+
const startIdx = isNumericCell(slide.rows[0]?.[2] ?? '') ? 0 : 1
|
|
660
|
+
for (const r of slide.rows.slice(startIdx)) {
|
|
661
|
+
const src = stripInlineMarkdown(r[0] ?? '')
|
|
662
|
+
const dst = stripInlineMarkdown(r[1] ?? '')
|
|
663
|
+
if (!src || !dst || src === dst) continue
|
|
664
|
+
const parsed = extractNumberAndUnit(r[2] ?? '10')
|
|
665
|
+
rawEdges.push({
|
|
666
|
+
source: src,
|
|
667
|
+
target: dst,
|
|
668
|
+
value: parsed.num > 0 ? parsed.num : 10,
|
|
669
|
+
unit: parsed.unit,
|
|
670
|
+
valueLabel: parsed.label || stripInlineMarkdown(r[2] ?? ''),
|
|
671
|
+
delta: stripInlineMarkdown(r[3] ?? ''),
|
|
672
|
+
status: undefined,
|
|
673
|
+
})
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
if (rawEdges.length === 0) {
|
|
678
|
+
if (isEn) {
|
|
679
|
+
rawEdges.push(
|
|
680
|
+
{ source: 'Total Revenue', target: 'Gross Profit', value: 68.5, unit: 'B', valueLabel: '$68.5B', status: 'positive' },
|
|
681
|
+
{ source: 'Total Revenue', target: 'Cost of Revenue', value: 31.5, unit: 'B', valueLabel: '$31.5B', status: 'negative' },
|
|
682
|
+
{ source: 'Gross Profit', target: 'Operating Income', value: 34.5, unit: 'B', valueLabel: '$34.5B', status: 'positive' },
|
|
683
|
+
{ source: 'Gross Profit', target: 'R&D', value: 22.0, unit: 'B', valueLabel: '$22.0B', status: 'negative' },
|
|
684
|
+
{ source: 'Gross Profit', target: 'SG&A', value: 12.0, unit: 'B', valueLabel: '$12.0B', status: 'negative' },
|
|
685
|
+
)
|
|
686
|
+
} else {
|
|
687
|
+
rawEdges.push(
|
|
688
|
+
{ source: '总营收', target: '毛利润', value: 68.5, unit: '亿', valueLabel: '68.5亿', status: 'positive' },
|
|
689
|
+
{ source: '总营收', target: '营业成本', value: 31.5, unit: '亿', valueLabel: '31.5亿', status: 'negative' },
|
|
690
|
+
{ source: '毛利润', target: '营业利润', value: 34.5, unit: '亿', valueLabel: '34.5亿', status: 'positive' },
|
|
691
|
+
{ source: '毛利润', target: '研发投入', value: 22.0, unit: '亿', valueLabel: '22.0亿', status: 'negative' },
|
|
692
|
+
{ source: '毛利润', target: '营销及管理', value: 12.0, unit: '亿', valueLabel: '12.0亿', status: 'negative' },
|
|
693
|
+
)
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
const nodeMap = new Map()
|
|
698
|
+
const getOrCreate = (name) => {
|
|
699
|
+
if (!nodeMap.has(name)) {
|
|
700
|
+
nodeMap.set(name, {
|
|
701
|
+
name,
|
|
702
|
+
inEdges: [],
|
|
703
|
+
outEdges: [],
|
|
704
|
+
inSum: 0,
|
|
705
|
+
outSum: 0,
|
|
706
|
+
layer: 0,
|
|
707
|
+
tone: 'accent',
|
|
708
|
+
unit: '',
|
|
709
|
+
delta: '',
|
|
710
|
+
})
|
|
711
|
+
}
|
|
712
|
+
return nodeMap.get(name)
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
const edges = []
|
|
716
|
+
for (const e of rawEdges) {
|
|
717
|
+
const u = getOrCreate(e.source)
|
|
718
|
+
const v = getOrCreate(e.target)
|
|
719
|
+
const edgeObj = { ...e, sourceNode: u, targetNode: v }
|
|
720
|
+
u.outEdges.push(edgeObj)
|
|
721
|
+
v.inEdges.push(edgeObj)
|
|
722
|
+
u.outSum += e.value
|
|
723
|
+
v.inSum += e.value
|
|
724
|
+
if (!v.unit && e.unit) v.unit = e.unit
|
|
725
|
+
if (!u.unit && e.unit) u.unit = e.unit
|
|
726
|
+
if (e.delta && !v.delta) v.delta = e.delta
|
|
727
|
+
if (e.status) v.tone = e.status
|
|
728
|
+
edges.push(edgeObj)
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
const nodes = [...nodeMap.values()]
|
|
732
|
+
// 拓扑分层(防环最多迭代 nodes.length 次,最多 4 列)
|
|
733
|
+
for (let pass = 0; pass < nodes.length; pass += 1) {
|
|
734
|
+
let changed = false
|
|
735
|
+
for (const e of edges) {
|
|
736
|
+
if (e.targetNode.layer <= e.sourceNode.layer && e.sourceNode.layer < 3) {
|
|
737
|
+
const nextL = Math.min(3, e.sourceNode.layer + 1)
|
|
738
|
+
if (nextL > e.targetNode.layer) {
|
|
739
|
+
e.targetNode.layer = nextL
|
|
740
|
+
changed = true
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
if (!changed) break
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
const maxLayer = Math.max(1, ...nodes.map((n) => n.layer))
|
|
748
|
+
const layerCount = maxLayer + 1
|
|
749
|
+
|
|
750
|
+
for (const n of nodes) {
|
|
751
|
+
n.val = Math.max(n.inSum, n.outSum, 0.01)
|
|
752
|
+
n.tone = classifySankeyNodeTone(n.name, n.inEdges[0]?.status)
|
|
753
|
+
const formattedNum = Number.isInteger(n.val) ? String(n.val) : n.val.toFixed(1).replace(/\.0$/, '')
|
|
754
|
+
n.displayValue = (n.inEdges.length === 1 && n.outEdges.length === 0 && n.inEdges[0].valueLabel)
|
|
755
|
+
? n.inEdges[0].valueLabel
|
|
756
|
+
: formattedNum + (n.unit || '')
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
const layers = Array.from({ length: layerCount }, (_, l) => nodes.filter((n) => n.layer === l))
|
|
760
|
+
// 预留顶部浮动标签高度 + 左右标签栏宽度
|
|
761
|
+
const leftLabelW = 2.02
|
|
762
|
+
const rightLabelW = 2.62
|
|
763
|
+
const topPad = 0.46
|
|
764
|
+
const botPad = 0.14
|
|
765
|
+
const plotX = areaBox.x + leftLabelW
|
|
766
|
+
const plotW = Math.max(3.6, areaBox.w - leftLabelW - rightLabelW)
|
|
767
|
+
const plotY = areaBox.y + topPad
|
|
768
|
+
const plotH = Math.max(2.0, areaBox.h - topPad - botPad)
|
|
769
|
+
const barW = 0.24
|
|
770
|
+
const nodeGap = 0.30
|
|
771
|
+
|
|
772
|
+
// 能量守恒全局比例尺 ky(英寸/单位数值)
|
|
773
|
+
let ky = Infinity
|
|
774
|
+
for (const col of layers) {
|
|
775
|
+
if (col.length === 0) continue
|
|
776
|
+
const valSum = col.reduce((s, n) => s + n.val, 0)
|
|
777
|
+
const avail = Math.max(0.8, plotH * 0.84 - Math.max(0, col.length - 1) * nodeGap)
|
|
778
|
+
ky = Math.min(ky, avail / Math.max(valSum, 1e-6))
|
|
779
|
+
}
|
|
780
|
+
if (!Number.isFinite(ky) || ky <= 0) ky = 0.03
|
|
781
|
+
|
|
782
|
+
// 在同层内将正向/主干节点排上方、负向成本节点排下方,减少交叉且符合损益表视觉直觉
|
|
783
|
+
const toneRank = (n) => (n.outEdges.length > 0 ? 0 : n.tone === 'positive' ? 1 : n.tone === 'accent' ? 2 : 3)
|
|
784
|
+
layers[0].sort((a, b) => toneRank(a) - toneRank(b) || b.val - a.val)
|
|
785
|
+
|
|
786
|
+
// Layer 0 垂直居中排布
|
|
787
|
+
{
|
|
788
|
+
const col0 = layers[0]
|
|
789
|
+
col0.forEach((n) => {
|
|
790
|
+
n.x = plotX
|
|
791
|
+
n.w = barW
|
|
792
|
+
n.h = Math.max(0.16, n.val * ky)
|
|
793
|
+
})
|
|
794
|
+
const totalH0 = col0.reduce((s, n) => s + n.h, 0) + Math.max(0, col0.length - 1) * nodeGap
|
|
795
|
+
let cy = plotY + Math.max(0, (plotH - totalH0) / 2)
|
|
796
|
+
for (const n of col0) {
|
|
797
|
+
n.y = cy
|
|
798
|
+
cy += n.h + nodeGap
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
// 逐层计算父节点出港端口,再用父端口加权重心法定位子层节点 Y(使毛利润拆解保持在上半带、营业成本独占下半带!)
|
|
803
|
+
const assignOutPorts = (col) => {
|
|
804
|
+
for (const u of col) {
|
|
805
|
+
u.outEdges.sort((a, b) => toneRank(a.targetNode) - toneRank(b.targetNode) || a.targetNode.layer - b.targetNode.layer)
|
|
806
|
+
const outTotal = u.outEdges.reduce((s, e) => s + e.value, 0) || u.val
|
|
807
|
+
const scale = u.h / Math.max(outTotal, u.val)
|
|
808
|
+
let py = u.y
|
|
809
|
+
for (const e of u.outEdges) {
|
|
810
|
+
const eh = Math.max(0.03, e.value * scale)
|
|
811
|
+
e.sy0 = py
|
|
812
|
+
e.sy1 = py + eh
|
|
813
|
+
py += eh
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
assignOutPorts(layers[0])
|
|
819
|
+
|
|
820
|
+
for (let l = 1; l < layerCount; l += 1) {
|
|
821
|
+
const col = layers[l]
|
|
822
|
+
const colX = plotX + (l / Math.max(1, layerCount - 1)) * (plotW - barW)
|
|
823
|
+
for (const n of col) {
|
|
824
|
+
n.x = colX
|
|
825
|
+
n.w = barW
|
|
826
|
+
n.h = Math.max(0.16, n.val * ky)
|
|
827
|
+
if (n.inEdges.length > 0) {
|
|
828
|
+
const wSum = n.inEdges.reduce((s, e) => s + e.value, 0) || 1
|
|
829
|
+
const targetMid = n.inEdges.reduce((s, e) => s + ((e.sy0 + e.sy1) / 2) * e.value, 0) / wSum
|
|
830
|
+
n.idealY = targetMid - n.h / 2
|
|
831
|
+
} else {
|
|
832
|
+
n.idealY = plotY
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
col.sort((a, b) => a.idealY - b.idealY || toneRank(a) - toneRank(b))
|
|
836
|
+
|
|
837
|
+
// 自顶向下与自底向上碰撞消解,严格守住画布上下界与最小节点间距
|
|
838
|
+
let cursor = plotY
|
|
839
|
+
for (const n of col) {
|
|
840
|
+
n.y = Math.max(cursor, n.idealY)
|
|
841
|
+
cursor = n.y + n.h + nodeGap
|
|
842
|
+
}
|
|
843
|
+
let bottomLimit = plotY + plotH
|
|
844
|
+
for (let i = col.length - 1; i >= 0; i -= 1) {
|
|
845
|
+
const n = col[i]
|
|
846
|
+
if (n.y + n.h > bottomLimit) {
|
|
847
|
+
n.y = Math.max(plotY, bottomLimit - n.h)
|
|
848
|
+
}
|
|
849
|
+
bottomLimit = n.y - nodeGap
|
|
850
|
+
}
|
|
851
|
+
assignOutPorts(col)
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
// 计算每个目标节点的入港端口 [ty0, ty1]
|
|
855
|
+
for (const v of nodes) {
|
|
856
|
+
v.inEdges.sort((a, b) => a.sourceNode.y - b.sourceNode.y)
|
|
857
|
+
const inTotal = v.inEdges.reduce((s, e) => s + e.value, 0) || v.val
|
|
858
|
+
const scale = v.h / Math.max(inTotal, v.val)
|
|
859
|
+
let py = v.y
|
|
860
|
+
for (const e of v.inEdges) {
|
|
861
|
+
const eh = Math.max(0.03, e.value * scale)
|
|
862
|
+
e.ty0 = py
|
|
863
|
+
e.ty1 = py + eh
|
|
864
|
+
py += eh
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
return { nodes, edges, layers, layerCount, areaBox, plotX, plotW, plotY, plotH, leftLabelW, rightLabelW }
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
function sankeyNodeColor(node, theme) {
|
|
872
|
+
const tk = theme.tokens
|
|
873
|
+
if (node.layer === 0) return tk.accentPrimary
|
|
874
|
+
if (node.tone === 'positive') return tk.positive
|
|
875
|
+
if (node.tone === 'negative') return tk.negative
|
|
876
|
+
if (node.tone === 'warning') return tk.warning
|
|
877
|
+
return tk.accentSecondary
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
function renderSankeyPptx(slide, area, nextIdFn, chromeCfg, theme, langAttr) {
|
|
881
|
+
const tk = theme.tokens
|
|
882
|
+
const model = computeSankeyLayout(slide, area, langAttr)
|
|
883
|
+
const shapes = []
|
|
884
|
+
|
|
885
|
+
// 1. 先绘制平滑三次贝塞尔闭合流向丝带 (<a:custGeom>)
|
|
886
|
+
model.edges.forEach((e, idx) => {
|
|
887
|
+
const x0 = e.sourceNode.x + e.sourceNode.w
|
|
888
|
+
const x1 = e.targetNode.x
|
|
889
|
+
const rw = Math.max(0.08, x1 - x0)
|
|
890
|
+
const ry = Math.min(e.sy0, e.ty0)
|
|
891
|
+
const maxBottom = Math.max(e.sy1, e.ty1)
|
|
892
|
+
const rh = Math.max(0.04, maxBottom - ry)
|
|
893
|
+
|
|
894
|
+
const W = 10000
|
|
895
|
+
const H = 10000
|
|
896
|
+
const sy0 = Math.round(((e.sy0 - ry) / rh) * H)
|
|
897
|
+
const sy1 = Math.round(((e.sy1 - ry) / rh) * H)
|
|
898
|
+
const ty0 = Math.round(((e.ty0 - ry) / rh) * H)
|
|
899
|
+
const ty1 = Math.round(((e.ty1 - ry) / rh) * H)
|
|
900
|
+
|
|
901
|
+
const pathXml =
|
|
902
|
+
'<a:moveTo><a:pt x="0" y="' + sy0 + '"/></a:moveTo>' +
|
|
903
|
+
'<a:cubicBezTo><a:pt x="4600" y="' + sy0 + '"/><a:pt x="5400" y="' + ty0 + '"/><a:pt x="' + W + '" y="' + ty0 + '"/></a:cubicBezTo>' +
|
|
904
|
+
'<a:lnTo><a:pt x="' + W + '" y="' + ty1 + '"/></a:lnTo>' +
|
|
905
|
+
'<a:cubicBezTo><a:pt x="5400" y="' + ty1 + '"/><a:pt x="4600" y="' + sy1 + '"/><a:pt x="0" y="' + sy1 + '"/></a:cubicBezTo>' +
|
|
906
|
+
'<a:close/>'
|
|
907
|
+
|
|
908
|
+
const ribbonColor = sankeyNodeColor(e.targetNode, theme)
|
|
909
|
+
shapes.push(ooxmlCustGeomShape(nextIdFn(), 'Sankey Ribbon ' + (idx + 1), { x: x0, y: ry, w: rw, h: rh }, pathXml, { pathW: W, pathH: H, fill: ribbonColor, fillAlpha: theme.dark ? 0.42 : 0.32 }))
|
|
910
|
+
})
|
|
911
|
+
|
|
912
|
+
// 2. 绘制守恒节点立柱 + 零碰撞语义数值标签
|
|
913
|
+
model.nodes.forEach((n, idx) => {
|
|
914
|
+
const barColor = sankeyNodeColor(n, theme)
|
|
915
|
+
shapes.push(ooxmlShape(nextIdFn(), 'Sankey Node ' + (idx + 1), { x: n.x, y: n.y, w: n.w, h: n.h }, { preset: chromeCfg.cardRadiusPx > 0 ? 'roundRect' : 'rect', adj: roundRectAdj(n.w, n.h, Math.min(4, chromeCfg.cardRadiusPx)), fill: barColor }))
|
|
916
|
+
|
|
917
|
+
const valColor = n.tone === 'positive'
|
|
918
|
+
? tk.positive
|
|
919
|
+
: n.tone === 'negative'
|
|
920
|
+
? tk.negative
|
|
921
|
+
: tk.accentText
|
|
922
|
+
const valLine = n.displayValue + (n.delta ? ' (' + n.delta + ')' : '')
|
|
923
|
+
const isLeftRoot = n.layer === 0
|
|
924
|
+
const isLeaf = n.outEdges.length === 0
|
|
925
|
+
|
|
926
|
+
if (isLeftRoot) {
|
|
927
|
+
const lblBox = { x: area.x, y: n.y + n.h / 2 - 0.32, w: Math.max(1.2, n.x - area.x - 0.12), h: 0.64 }
|
|
928
|
+
shapes.push(ooxmlShape(nextIdFn(), 'Sankey Label ' + (idx + 1), lblBox, {
|
|
929
|
+
txBox: true,
|
|
930
|
+
anchor: 'ctr',
|
|
931
|
+
marginsIn: { l: 0, r: 0.02, t: 0, b: 0 },
|
|
932
|
+
paragraphs: [
|
|
933
|
+
ooxmlRichParagraph(n.name, { sizePt: 12.5, color: tk.inkPrimary, bold: true, lang: langAttr, align: 'r', font: theme.fonts.heading, lineHeight: 1.12, spaceAfterPt: 1 }),
|
|
934
|
+
ooxmlRichParagraph(valLine, { sizePt: 13.5, color: tk.accentText, bold: true, lang: langAttr, align: 'r', font: theme.fonts.heading, lineHeight: 1.08 }),
|
|
935
|
+
],
|
|
936
|
+
}))
|
|
937
|
+
} else if (isLeaf) {
|
|
938
|
+
const rightEdge = area.x + area.w
|
|
939
|
+
const lx = n.x + n.w + 0.12
|
|
940
|
+
const maxLeafW = model.layerCount >= 4 && n.layer < model.layerCount - 1 ? 2.02 : 2.6
|
|
941
|
+
const lw = Math.min(maxLeafW, Math.max(1.3, rightEdge - lx))
|
|
942
|
+
const lblBox = { x: lx, y: n.y + n.h / 2 - 0.28, w: lw, h: 0.56 }
|
|
943
|
+
shapes.push(ooxmlShape(nextIdFn(), 'Sankey Label ' + (idx + 1), lblBox, {
|
|
944
|
+
txBox: true,
|
|
945
|
+
anchor: 'ctr',
|
|
946
|
+
marginsIn: { l: 0.02, r: 0, t: 0, b: 0 },
|
|
947
|
+
paragraphs: [
|
|
948
|
+
ooxmlRichParagraph(n.name + ' **' + valLine + '**', {
|
|
949
|
+
sizePt: model.layerCount >= 4 && n.layer < model.layerCount - 1 ? 10.5 : 11.5,
|
|
950
|
+
color: tk.inkPrimary,
|
|
951
|
+
accentColor: valColor,
|
|
952
|
+
bold: false,
|
|
953
|
+
lang: langAttr,
|
|
954
|
+
align: 'l',
|
|
955
|
+
font: theme.fonts.body,
|
|
956
|
+
lineHeight: 1.15,
|
|
957
|
+
}),
|
|
958
|
+
],
|
|
959
|
+
}))
|
|
960
|
+
} else {
|
|
961
|
+
// 中间枢纽节点(既有入流又有出流):置于立柱正上方胶囊标签,彻底避开左右两侧流向丝带!
|
|
962
|
+
const pillFontPt = model.layerCount >= 4 ? 10 : 11
|
|
963
|
+
const pillMaxW = model.layerCount >= 4 ? 2.22 : 2.8
|
|
964
|
+
const pillText = n.name + ' · ' + valLine
|
|
965
|
+
const pillW = computeBadgePillWidth(pillText, pillFontPt, pillMaxW, 1.30)
|
|
966
|
+
const pillBox = { x: n.x + n.w / 2 - pillW / 2, y: Math.max(area.y, n.y - 0.40), w: pillW, h: 0.34 }
|
|
967
|
+
shapes.push(ooxmlShape(nextIdFn(), 'Sankey Label ' + (idx + 1), pillBox, {
|
|
968
|
+
preset: chromeCfg.cardRadiusPx > 0 ? 'roundRect' : 'rect',
|
|
969
|
+
adj: roundRectAdj(pillBox.w, pillBox.h, Math.min(8, chromeCfg.cardRadiusPx)),
|
|
970
|
+
fill: tk.surface2,
|
|
971
|
+
stroke: barColor,
|
|
972
|
+
strokePt: 0.75,
|
|
973
|
+
anchor: 'ctr',
|
|
974
|
+
marginsIn: { l: 0.06, r: 0.06, t: 0.02, b: 0.02 },
|
|
975
|
+
paragraphs: [ooxmlRichParagraph(n.name + ' **' + valLine + '**', { sizePt: pillFontPt, color: tk.inkPrimary, bold: true, lang: langAttr, align: 'ctr', font: theme.fonts.heading, lineHeight: 1.05 })],
|
|
976
|
+
}))
|
|
977
|
+
}
|
|
978
|
+
})
|
|
979
|
+
|
|
980
|
+
return shapes.join('')
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
function renderSankeyHtml(slide, theme, langId) {
|
|
984
|
+
const tk = theme.tokens
|
|
985
|
+
const area = { x: 0, y: 0, w: 12.0, h: 4.5 }
|
|
986
|
+
const model = computeSankeyLayout(slide, area, langId)
|
|
987
|
+
const scale = 100 // 1200 x 450 SVG 视口
|
|
988
|
+
|
|
989
|
+
const ribbonsSvg = model.edges.map((e) => {
|
|
990
|
+
const x0 = (e.sourceNode.x + e.sourceNode.w) * scale
|
|
991
|
+
const x1 = e.targetNode.x * scale
|
|
992
|
+
const cx0 = x0 + (x1 - x0) * 0.46
|
|
993
|
+
const cx1 = x0 + (x1 - x0) * 0.54
|
|
994
|
+
const sy0 = e.sy0 * scale
|
|
995
|
+
const sy1 = e.sy1 * scale
|
|
996
|
+
const ty0 = e.ty0 * scale
|
|
997
|
+
const ty1 = e.ty1 * scale
|
|
998
|
+
const d =
|
|
999
|
+
'M ' + x0.toFixed(1) + ' ' + sy0.toFixed(1) +
|
|
1000
|
+
' C ' + cx0.toFixed(1) + ' ' + sy0.toFixed(1) + ', ' + cx1.toFixed(1) + ' ' + ty0.toFixed(1) + ', ' + x1.toFixed(1) + ' ' + ty0.toFixed(1) +
|
|
1001
|
+
' L ' + x1.toFixed(1) + ' ' + ty1.toFixed(1) +
|
|
1002
|
+
' C ' + cx1.toFixed(1) + ' ' + ty1.toFixed(1) + ', ' + cx0.toFixed(1) + ' ' + sy1.toFixed(1) + ', ' + x0.toFixed(1) + ' ' + sy1.toFixed(1) +
|
|
1003
|
+
' Z'
|
|
1004
|
+
const fill = sankeyNodeColor(e.targetNode, theme)
|
|
1005
|
+
const op = theme.dark ? '0.42' : '0.32'
|
|
1006
|
+
return '<path class="sankey-ribbon" d="' + d + '" fill="' + fill + '" fill-opacity="' + op + '"/>'
|
|
1007
|
+
}).join('')
|
|
1008
|
+
|
|
1009
|
+
const nodesSvg = model.nodes.map((n) => {
|
|
1010
|
+
const barColor = sankeyNodeColor(n, theme)
|
|
1011
|
+
const rx = n.x * scale
|
|
1012
|
+
const ry = n.y * scale
|
|
1013
|
+
const rw = n.w * scale
|
|
1014
|
+
const rh = n.h * scale
|
|
1015
|
+
const valLine = n.displayValue + (n.delta ? ' (' + n.delta + ')' : '')
|
|
1016
|
+
const isLeftRoot = n.layer === 0
|
|
1017
|
+
const isLeaf = n.outEdges.length === 0
|
|
1018
|
+
|
|
1019
|
+
let labelSvg = ''
|
|
1020
|
+
if (isLeftRoot) {
|
|
1021
|
+
const lx = (rx - 12).toFixed(1)
|
|
1022
|
+
const ly = (ry + rh / 2).toFixed(1)
|
|
1023
|
+
labelSvg =
|
|
1024
|
+
'<text x="' + lx + '" y="' + (Number(ly) - 7).toFixed(1) + '" text-anchor="end" fill="' + tk.inkPrimary + '" font-size="15" font-weight="700">' + escapeHtml(n.name) + '</text>' +
|
|
1025
|
+
'<text x="' + lx + '" y="' + (Number(ly) + 14).toFixed(1) + '" text-anchor="end" fill="' + tk.accentText + '" font-size="16" font-weight="800">' + escapeHtml(valLine) + '</text>'
|
|
1026
|
+
} else if (isLeaf) {
|
|
1027
|
+
const lx = (rx + rw + 12).toFixed(1)
|
|
1028
|
+
const ly = (ry + rh / 2 + 5).toFixed(1)
|
|
1029
|
+
labelSvg =
|
|
1030
|
+
'<text x="' + lx + '" y="' + ly + '" text-anchor="start" fill="' + tk.inkPrimary + '" font-size="14" font-weight="600">' +
|
|
1031
|
+
escapeHtml(n.name) + ' <tspan fill="' + barColor + '" font-weight="800">' + escapeHtml(valLine) + '</tspan></text>'
|
|
1032
|
+
} else {
|
|
1033
|
+
const cx = (rx + rw / 2).toFixed(1)
|
|
1034
|
+
const cy = Math.max(20, ry - 12).toFixed(1)
|
|
1035
|
+
labelSvg =
|
|
1036
|
+
'<text x="' + cx + '" y="' + cy + '" text-anchor="middle" fill="' + tk.inkPrimary + '" font-size="14" font-weight="700">' +
|
|
1037
|
+
escapeHtml(n.name + ' · ' + valLine) + '</text>'
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
return (
|
|
1041
|
+
'<g class="sankey-node">' +
|
|
1042
|
+
'<rect x="' + rx.toFixed(1) + '" y="' + ry.toFixed(1) + '" width="' + rw.toFixed(1) + '" height="' + rh.toFixed(1) + '" rx="3" fill="' + barColor + '"/>' +
|
|
1043
|
+
labelSvg +
|
|
1044
|
+
'</g>'
|
|
1045
|
+
)
|
|
1046
|
+
}).join('')
|
|
1047
|
+
|
|
1048
|
+
return (
|
|
1049
|
+
'<div class="sankey-board">' +
|
|
1050
|
+
'<svg class="sankey-svg" viewBox="0 0 1200 450" role="img" aria-label="' + escapeHtml(slide.title || 'Sankey Flow') + '">' +
|
|
1051
|
+
ribbonsSvg +
|
|
1052
|
+
nodesSvg +
|
|
1053
|
+
'</svg></div>'
|
|
1054
|
+
)
|
|
1055
|
+
}
|
|
1056
|
+
|
|
1057
|
+
const SUPPORT_ACTIVITY_RE = /辅助|支撑|基础|治理|平台|人才|人力|采购|财务|法务|support|infra|hr|talent|procure|governance|admin/i
|
|
1058
|
+
|
|
1059
|
+
export function partitionValueChainItems(slide, langOrAttr = 'zh') {
|
|
1060
|
+
const isEn = langOrAttr === 'en' || langOrAttr === 'en-US'
|
|
1061
|
+
const all = resolveEffectiveItems(slide)
|
|
1062
|
+
|
|
1063
|
+
const taggedSupport = all.filter((it) => SUPPORT_ACTIVITY_RE.test(String(it.tag || '')) || SUPPORT_ACTIVITY_RE.test(String(it.role || '')))
|
|
1064
|
+
const taggedPrimary = all.filter((it) => !taggedSupport.includes(it))
|
|
1065
|
+
|
|
1066
|
+
let supportItems = []
|
|
1067
|
+
let primaryItems = []
|
|
1068
|
+
|
|
1069
|
+
if (taggedSupport.length >= 1 && taggedPrimary.length >= 2) {
|
|
1070
|
+
supportItems = taggedSupport.slice(0, 4)
|
|
1071
|
+
primaryItems = taggedPrimary.slice(0, 5)
|
|
1072
|
+
} else if (all.length >= 6) {
|
|
1073
|
+
const k = Math.min(4, Math.max(2, all.length - 5))
|
|
1074
|
+
supportItems = all.slice(0, k)
|
|
1075
|
+
primaryItems = all.slice(k, k + 5)
|
|
1076
|
+
} else if (Array.isArray(slide.columns) && slide.columns.length >= 1 && all.length >= 2) {
|
|
1077
|
+
supportItems = slide.columns.slice(0, 3).map((col, idx) => ({ tag: isEn ? 'SUPPORT ' + (idx + 1) : '辅助 ' + (idx + 1), title: col }))
|
|
1078
|
+
primaryItems = all.slice(0, 5)
|
|
1079
|
+
} else if (all.length >= 4) {
|
|
1080
|
+
// 若用户仅传 4–5 条核心活动,自动保留为底部基本活动并补齐顶部 2 条标准波特辅助支撑横梁
|
|
1081
|
+
primaryItems = all.slice(0, 5)
|
|
1082
|
+
supportItems = isEn
|
|
1083
|
+
? [
|
|
1084
|
+
{ tag: 'SUPPORT', title: 'Firm Infrastructure & Governance', text: 'Unified strategy, compliance & financial control' },
|
|
1085
|
+
{ tag: 'SUPPORT', title: 'Technology R&D & Talent Enablement', text: 'Core platform engineering & organization capability' },
|
|
1086
|
+
]
|
|
1087
|
+
: [
|
|
1088
|
+
{ tag: '辅助活动', title: '企业基础设施与数字化治理', text: '统一战略管控、合规风控与业财一体底座' },
|
|
1089
|
+
{ tag: '辅助活动', title: '核心技术研发与组织人才支撑', text: '共性平台研发复用与复合型人才梯队赋能' },
|
|
1090
|
+
]
|
|
1091
|
+
} else {
|
|
1092
|
+
supportItems = all.length >= 3 ? all.slice(0, 1) : [
|
|
1093
|
+
{ tag: isEn ? 'SUPPORT' : '辅助活动', title: isEn ? 'Platform & Governance' : '平台与治理支撑' },
|
|
1094
|
+
]
|
|
1095
|
+
primaryItems = (all.length >= 3 ? all.slice(1) : all).length > 0
|
|
1096
|
+
? (all.length >= 3 ? all.slice(1) : all)
|
|
1097
|
+
: [
|
|
1098
|
+
{ tag: '01', title: isEn ? 'Inbound' : '供给接入' },
|
|
1099
|
+
{ tag: '02', title: isEn ? 'Operations' : '核心交付' },
|
|
1100
|
+
{ tag: '03', title: isEn ? 'Distribution' : '渠道触达' },
|
|
1101
|
+
{ tag: '04', title: isEn ? 'Service' : '持续增值' },
|
|
1102
|
+
]
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
const rawMargin = (slide.text && slide.text.trim().length <= 22 ? slide.text.trim() : '')
|
|
1106
|
+
|| (slide.subtitle && slide.subtitle.trim().length <= 22 ? slide.subtitle.trim() : '')
|
|
1107
|
+
const marginLabel = rawMargin || (isEn ? 'MARGIN' : '利润池\nMARGIN')
|
|
1108
|
+
|
|
1109
|
+
return { supportItems, primaryItems, marginLabel }
|
|
1110
|
+
}
|
|
1111
|
+
|
|
1112
|
+
function renderPorterValueChainPptx(slide, area, nextIdFn, chromeCfg, theme, langAttr) {
|
|
1113
|
+
const tk = theme.tokens
|
|
1114
|
+
const isEn = langAttr === 'en-US'
|
|
1115
|
+
const { supportItems, primaryItems, marginLabel } = partitionValueChainItems(slide, langAttr)
|
|
1116
|
+
const shapes = []
|
|
1117
|
+
const cardPreset = chromeCfg.cardRadiusPx > 0 ? 'roundRect' : 'rect'
|
|
1118
|
+
|
|
1119
|
+
const marginW = 1.66
|
|
1120
|
+
const marginGap = 0.14
|
|
1121
|
+
const mainW = area.w - marginW - marginGap
|
|
1122
|
+
const mainX = area.x
|
|
1123
|
+
|
|
1124
|
+
// 顶部辅助活动横梁区
|
|
1125
|
+
const nSup = Math.max(1, supportItems.length)
|
|
1126
|
+
const supGap = 0.08
|
|
1127
|
+
const supZoneH = Math.min(1.88, Math.max(1.10, area.h * (nSup >= 3 ? 0.42 : 0.34)))
|
|
1128
|
+
const beamH = (supZoneH - supGap * (nSup - 1)) / nSup
|
|
1129
|
+
|
|
1130
|
+
// 左侧“辅助活动”竖向标签轨(分行独立居中段落,杜绝单段落换行缩进错位)
|
|
1131
|
+
const railW = 0.92
|
|
1132
|
+
const railLines = isEn ? ['SUPPORT'] : ['辅助', '活动']
|
|
1133
|
+
shapes.push(ooxmlShape(nextIdFn(), 'Porter Support Rail', { x: mainX, y: area.y, w: railW, h: supZoneH }, {
|
|
1134
|
+
preset: cardPreset,
|
|
1135
|
+
adj: roundRectAdj(railW, supZoneH, Math.min(6, chromeCfg.cardRadiusPx)),
|
|
1136
|
+
fill: tk.accentSoft,
|
|
1137
|
+
stroke: tk.accentPrimary,
|
|
1138
|
+
strokePt: 0.75,
|
|
1139
|
+
anchor: 'ctr',
|
|
1140
|
+
marginsIn: { l: 0.06, r: 0.06, t: 0.06, b: 0.06 },
|
|
1141
|
+
paragraphs: railLines.map((ln) =>
|
|
1142
|
+
ooxmlRichParagraph(ln, { sizePt: 11.5, color: tk.accentText, bold: true, lang: langAttr, align: 'ctr', font: theme.fonts.heading, lineHeight: 1.16 }),
|
|
1143
|
+
),
|
|
1144
|
+
}))
|
|
1145
|
+
|
|
1146
|
+
const beamX = mainX + railW + 0.10
|
|
1147
|
+
const beamW = mainW - railW - 0.10
|
|
1148
|
+
supportItems.forEach((sup, sIdx) => {
|
|
1149
|
+
const by = area.y + sIdx * (beamH + supGap)
|
|
1150
|
+
const detail = [sup.text, ...(sup.bullets ?? [])].filter(Boolean).join(' · ')
|
|
1151
|
+
const beamCopy = '**' + (sup.title || '') + '**' + (detail ? ' — ' + detail : '')
|
|
1152
|
+
shapes.push(ooxmlShape(nextIdFn(), 'Porter Support Beam ' + (sIdx + 1), { x: beamX, y: by, w: beamW, h: beamH }, {
|
|
1153
|
+
preset: cardPreset,
|
|
1154
|
+
adj: roundRectAdj(beamW, beamH, Math.min(6, chromeCfg.cardRadiusPx)),
|
|
1155
|
+
fill: sIdx % 2 === 0 ? tk.surface2 : tk.surface1,
|
|
1156
|
+
stroke: chromeCfg.cardBorderless ? '' : tk.hairline,
|
|
1157
|
+
strokePt: 0.75,
|
|
1158
|
+
anchor: 'ctr',
|
|
1159
|
+
marginsIn: { l: 0.18, r: 0.16, t: 0.03, b: 0.03 },
|
|
1160
|
+
paragraphs: [ooxmlRichParagraph(beamCopy, { sizePt: nSup >= 3 ? 11.5 : 12.5, color: tk.inkPrimary, secondaryColor: tk.inkSecondary, lang: langAttr, font: theme.fonts.body, lineHeight: 1.18 })],
|
|
1161
|
+
}))
|
|
1162
|
+
shapes.push(ooxmlShape(nextIdFn(), 'Porter Support Stripe ' + (sIdx + 1), { x: beamX, y: by, w: 0.06, h: beamH }, { preset: 'rect', fill: tk.accentSecondary }))
|
|
1163
|
+
})
|
|
1164
|
+
|
|
1165
|
+
// 底部基本活动互锁 Chevron + 支撑明细卡片
|
|
1166
|
+
const primTopY = area.y + supZoneH + 0.16
|
|
1167
|
+
const primZoneH = Math.max(1.85, area.y + area.h - primTopY)
|
|
1168
|
+
const nPrim = Math.max(1, primaryItems.length)
|
|
1169
|
+
const overlap = nPrim > 1 ? 0.07 : 0
|
|
1170
|
+
const chevW = (mainW + (nPrim - 1) * overlap) / nPrim
|
|
1171
|
+
const chevH = Math.min(0.84, primZoneH * 0.36)
|
|
1172
|
+
const detailGap = 0.12
|
|
1173
|
+
const colW = (mainW - detailGap * (nPrim - 1)) / nPrim
|
|
1174
|
+
const detailY = primTopY + chevH + 0.12
|
|
1175
|
+
const detailH = Math.max(0.95, area.y + area.h - detailY)
|
|
1176
|
+
|
|
1177
|
+
primaryItems.forEach((it, idx) => {
|
|
1178
|
+
const isFirst = idx === 0
|
|
1179
|
+
const isLast = idx === nPrim - 1 && nPrim >= 3
|
|
1180
|
+
const cx = mainX + idx * (chevW - overlap)
|
|
1181
|
+
const fillHex = isFirst ? tk.accentPrimary : isLast ? tk.accentSecondary : tk.surface2
|
|
1182
|
+
const inkHex = isFirst
|
|
1183
|
+
? tk.inkOnAccent
|
|
1184
|
+
: isLast
|
|
1185
|
+
? (relativeLuminance(tk.accentSecondary) > 0.38 ? '#0F172A' : '#FFFFFF')
|
|
1186
|
+
: tk.inkPrimary
|
|
1187
|
+
const stageTag = (it.tag && !SUPPORT_ACTIVITY_RE.test(it.tag)) ? it.tag : String(idx + 1).padStart(2, '0')
|
|
1188
|
+
const titleStr = it.title || ''
|
|
1189
|
+
const titlePt = titleStr.length >= 7 ? 11 : nPrim >= 5 ? 11.5 : 12.5
|
|
1190
|
+
const chevParas = [
|
|
1191
|
+
...(stageTag
|
|
1192
|
+
? [ooxmlRichParagraph(stageTag, { sizePt: 9, color: inkHex, bold: true, lang: langAttr, align: 'ctr', font: theme.fonts.heading, lineHeight: 1.05, spaceAfterPt: 1 })]
|
|
1193
|
+
: []),
|
|
1194
|
+
ooxmlRichParagraph(titleStr, { sizePt: titlePt, color: inkHex, bold: true, lang: langAttr, align: 'ctr', font: theme.fonts.heading, lineHeight: 1.12 }),
|
|
1195
|
+
]
|
|
1196
|
+
|
|
1197
|
+
shapes.push(ooxmlShape(nextIdFn(), 'Porter Primary Chevron ' + (idx + 1), { x: cx, y: primTopY, w: chevW, h: chevH }, {
|
|
1198
|
+
preset: isFirst ? 'homePlate' : 'chevron',
|
|
1199
|
+
adjs: { adj: 18000 },
|
|
1200
|
+
fill: fillHex,
|
|
1201
|
+
stroke: tk.canvas,
|
|
1202
|
+
strokePt: 1.75,
|
|
1203
|
+
anchor: 'ctr',
|
|
1204
|
+
marginsIn: { l: isFirst ? 0.10 : 0.22, r: 0.18, t: 0.03, b: 0.03 },
|
|
1205
|
+
paragraphs: chevParas,
|
|
1206
|
+
}))
|
|
1207
|
+
|
|
1208
|
+
const dx = mainX + idx * (colW + detailGap)
|
|
1209
|
+
const cardBox = { x: dx, y: detailY, w: colW, h: detailH }
|
|
1210
|
+
shapes.push(renderSurfaceCardPptx('Porter Detail Surface ' + (idx + 1), cardBox, { fill: isFirst ? tk.accentSoft : tk.surface1, focal: isFirst }, nextIdFn, chromeCfg, theme))
|
|
1211
|
+
|
|
1212
|
+
const metric = it.conversion || it.delta || (it.value ? it.value + (it.unit ? ' ' + it.unit : '') : '')
|
|
1213
|
+
const lines = [
|
|
1214
|
+
...(metric ? ['**' + metric + '**'] : []),
|
|
1215
|
+
...(it.text ? [it.text] : []),
|
|
1216
|
+
...(Array.isArray(it.bullets) ? it.bullets : []),
|
|
1217
|
+
]
|
|
1218
|
+
if (lines.length > 0) {
|
|
1219
|
+
const innerBox = { x: cardBox.x + 0.12, y: cardBox.y + 0.12, w: cardBox.w - 0.24, h: cardBox.h - 0.22 }
|
|
1220
|
+
const fit = computeTextFit(lines, innerBox, 'cardBody', { maxPt: 12.5, minPt: 11 })
|
|
1221
|
+
shapes.push(ooxmlShape(nextIdFn(), 'Porter Detail ' + (idx + 1), innerBox, {
|
|
1222
|
+
txBox: true,
|
|
1223
|
+
anchor: 't',
|
|
1224
|
+
marginsIn: ZERO_MARGINS,
|
|
1225
|
+
fontScale: fit.fontScale,
|
|
1226
|
+
paragraphs: lines.map((line, lIdx) =>
|
|
1227
|
+
ooxmlRichParagraph(line, { sizePt: fit.fontPt, color: lIdx === 0 && metric ? tk.accentText : tk.inkSecondary, lang: langAttr, font: theme.fonts.body, lineHeight: 1.3, spaceAfterPt: 3 }),
|
|
1228
|
+
),
|
|
1229
|
+
}))
|
|
1230
|
+
}
|
|
1231
|
+
})
|
|
1232
|
+
|
|
1233
|
+
// 右侧贯通全高的“利润池 / MARGIN”箭头尖楔
|
|
1234
|
+
const wedgeBox = { x: mainX + mainW + marginGap, y: area.y, w: marginW, h: area.h }
|
|
1235
|
+
shapes.push(ooxmlShape(nextIdFn(), 'Porter Margin Wedge', wedgeBox, {
|
|
1236
|
+
preset: 'homePlate',
|
|
1237
|
+
adjs: { adj: 28000 },
|
|
1238
|
+
fill: tk.accentPrimary,
|
|
1239
|
+
stroke: tk.canvas,
|
|
1240
|
+
strokePt: 2.0,
|
|
1241
|
+
anchor: 'ctr',
|
|
1242
|
+
marginsIn: { l: 0.12, r: 0.26, t: 0.16, b: 0.16 },
|
|
1243
|
+
paragraphs: String(marginLabel).split('\n').map((ln, lIdx) =>
|
|
1244
|
+
ooxmlRichParagraph(ln, { sizePt: lIdx === 0 ? 15.5 : 11.5, color: tk.inkOnAccent, bold: true, lang: langAttr, align: 'ctr', font: theme.fonts.heading, lineHeight: 1.2, spaceAfterPt: 2 }),
|
|
1245
|
+
),
|
|
1246
|
+
}))
|
|
1247
|
+
|
|
1248
|
+
return shapes.join('')
|
|
1249
|
+
}
|
|
1250
|
+
|
|
1251
|
+
function renderPorterValueChainHtml(slide, langId) {
|
|
1252
|
+
const isEn = langId === 'en'
|
|
1253
|
+
const { supportItems, primaryItems, marginLabel } = partitionValueChainItems(slide, langId)
|
|
1254
|
+
|
|
1255
|
+
return (
|
|
1256
|
+
'<div class="porter-board">' +
|
|
1257
|
+
'<div class="porter-main">' +
|
|
1258
|
+
'<div class="porter-support-zone">' +
|
|
1259
|
+
'<div class="porter-support-rail">' + (isEn ? 'SUPPORT' : '辅助活动') + '</div>' +
|
|
1260
|
+
'<div class="porter-support-beams">' +
|
|
1261
|
+
supportItems.map((sup) => {
|
|
1262
|
+
const detail = [sup.text, ...(sup.bullets ?? [])].filter(Boolean).join(' · ')
|
|
1263
|
+
return (
|
|
1264
|
+
'<div class="surface-card porter-beam">' +
|
|
1265
|
+
'<strong>' + renderInlineHtml(sup.title || '') + '</strong>' +
|
|
1266
|
+
(detail ? '<span>' + renderInlineHtml(detail) + '</span>' : '') +
|
|
1267
|
+
'</div>'
|
|
1268
|
+
)
|
|
1269
|
+
}).join('') +
|
|
1270
|
+
'</div></div>' +
|
|
1271
|
+
'<ol class="layout-grid chevron-board porter-primary-zone cols-' + Math.max(1, primaryItems.length) + '">' +
|
|
1272
|
+
primaryItems.map((it, idx) => {
|
|
1273
|
+
const isFirst = idx === 0
|
|
1274
|
+
const isLast = idx === primaryItems.length - 1 && primaryItems.length >= 3
|
|
1275
|
+
const stageTag = (it.tag && !SUPPORT_ACTIVITY_RE.test(it.tag)) ? it.tag : String(idx + 1).padStart(2, '0')
|
|
1276
|
+
const metric = it.conversion || it.delta || (it.value ? it.value + (it.unit ? ' ' + it.unit : '') : '')
|
|
1277
|
+
const lines = [...(it.text ? [it.text] : []), ...(Array.isArray(it.bullets) ? it.bullets : [])]
|
|
1278
|
+
return (
|
|
1279
|
+
'<li class="chevron-col" data-item-index="' + idx + '">' +
|
|
1280
|
+
'<div class="chevron-arrow' + (isFirst ? ' is-first' : isLast ? ' is-last' : '') + '">' +
|
|
1281
|
+
'<span class="chevron-tag">' + escapeHtml(stageTag) + '</span>' +
|
|
1282
|
+
'<span class="chevron-title">' + renderInlineHtml(it.title || '') + '</span>' +
|
|
1283
|
+
'</div>' +
|
|
1284
|
+
'<div class="surface-card chevron-detail' + (isFirst ? ' is-focal' : '') + '">' +
|
|
1285
|
+
(metric ? '<span class="funnel-conversion-badge chevron-metric">' + escapeHtml(metric) + '</span>' : '') +
|
|
1286
|
+
(lines.length ? '<div class="card-body">' + lines.map((l) => renderInlineHtml(l)).join('<br>') + '</div>' : '') +
|
|
1287
|
+
'</div></li>'
|
|
1288
|
+
)
|
|
1289
|
+
}).join('') +
|
|
1290
|
+
'</ol>' +
|
|
1291
|
+
'</div>' +
|
|
1292
|
+
'<aside class="porter-margin-wedge"><span>' + escapeHtml(marginLabel).replace(/\n/g, '<br>') + '</span></aside>' +
|
|
1293
|
+
'</div>'
|
|
1294
|
+
)
|
|
1295
|
+
}
|
|
1296
|
+
|
|
1297
|
+
function formatSwotAnchorText(raw, isEn) {
|
|
1298
|
+
const cleaned = stripInlineMarkdown(String(raw ?? '')).trim()
|
|
1299
|
+
if (!cleaned) return isEn ? 'Strategic\nCore' : '破局核心'
|
|
1300
|
+
const rawLines = String(raw ?? '')
|
|
1301
|
+
.split(/\n+/)
|
|
1302
|
+
.map((ln) => stripInlineMarkdown(ln).trim())
|
|
1303
|
+
.filter(Boolean)
|
|
1304
|
+
if (rawLines.length >= 2) return rawLines.slice(0, 2).join('\n')
|
|
1305
|
+
|
|
1306
|
+
const sepParts = cleaned.split(/\s*[·||//—\-]\s*/).filter(Boolean)
|
|
1307
|
+
if (sepParts.length >= 2) return [sepParts[0], sepParts.slice(1).join('·')].join('\n')
|
|
1308
|
+
|
|
1309
|
+
const hasCjk = /[\u4E00-\u9FFF]/.test(cleaned)
|
|
1310
|
+
if (hasCjk) {
|
|
1311
|
+
const wsParts = cleaned.split(/\s+/).filter(Boolean)
|
|
1312
|
+
if (wsParts.length >= 2) {
|
|
1313
|
+
return [wsParts[0], wsParts.slice(1).join('')].join('\n')
|
|
1314
|
+
}
|
|
1315
|
+
if (cleaned.length > 5) {
|
|
1316
|
+
const mid = Math.ceil(cleaned.length / 2)
|
|
1317
|
+
return cleaned.slice(0, mid) + '\n' + cleaned.slice(mid)
|
|
1318
|
+
}
|
|
1319
|
+
return cleaned
|
|
1320
|
+
}
|
|
1321
|
+
|
|
1322
|
+
const words = cleaned.split(/\s+/).filter(Boolean)
|
|
1323
|
+
if (cleaned.length > 10 && words.length >= 2) {
|
|
1324
|
+
let bestIdx = 1
|
|
1325
|
+
let bestDiff = Infinity
|
|
1326
|
+
for (let i = 1; i < words.length; i += 1) {
|
|
1327
|
+
const l1 = words.slice(0, i).join(' ').length
|
|
1328
|
+
const l2 = words.slice(i).join(' ').length
|
|
1329
|
+
const diff = Math.abs(l1 - l2)
|
|
1330
|
+
if (diff < bestDiff) { bestDiff = diff; bestIdx = i }
|
|
1331
|
+
}
|
|
1332
|
+
return words.slice(0, bestIdx).join(' ') + '\n' + words.slice(bestIdx).join(' ')
|
|
1333
|
+
}
|
|
1334
|
+
return cleaned
|
|
1335
|
+
}
|
|
1336
|
+
|
|
1337
|
+
export function computeSwotModel(slide, langOrAttr = 'zh') {
|
|
1338
|
+
const isEn = langOrAttr === 'en' || langOrAttr === 'en-US'
|
|
1339
|
+
const items = resolveEffectiveItems(slide)
|
|
1340
|
+
|
|
1341
|
+
const quadrantMeta = [
|
|
1342
|
+
{ key: 'S', badge: 'S', header: isEn ? 'S · Core Strengths' : 'S · 核心优势', role: 'positive', match: /^(?:s\b|strength|优势|强项|长板)/i },
|
|
1343
|
+
{ key: 'W', badge: 'W', header: isEn ? 'W · Key Weaknesses' : 'W · 关键短板', role: 'warning', match: /^(?:w\b|weakness|劣势|短板|不足|痛点)/i },
|
|
1344
|
+
{ key: 'O', badge: 'O', header: isEn ? 'O · External Opportunities' : 'O · 外部机遇', role: 'accent', match: /^(?:o\b|opportunit|机遇|机会|红利)/i },
|
|
1345
|
+
{ key: 'T', badge: 'T', header: isEn ? 'T · Potential Threats' : 'T · 潜在威胁', role: 'negative', match: /^(?:t\b|threat|威胁|风险|挑战)/i },
|
|
1346
|
+
]
|
|
1347
|
+
|
|
1348
|
+
const towsMeta = [
|
|
1349
|
+
{ key: 'SO', label: isEn ? 'SO · Growth Offense' : 'SO · 乘势增长', match: /^so\b/i },
|
|
1350
|
+
{ key: 'WO', label: isEn ? 'WO · Capability Turnaround' : 'WO · 借势补短', match: /^wo\b/i },
|
|
1351
|
+
{ key: 'ST', label: isEn ? 'ST · Moat Defense' : 'ST · 壁垒防御', match: /^st\b/i },
|
|
1352
|
+
{ key: 'WT', label: isEn ? 'WT · Risk Containment' : 'WT · 风险收敛', match: /^wt\b/i },
|
|
1353
|
+
]
|
|
1354
|
+
|
|
1355
|
+
// 提取显式 SO/WO/ST/WT 行动策略项与 S/W/O/T 四象限项
|
|
1356
|
+
const towsExplicit = new Map()
|
|
1357
|
+
const quadPool = []
|
|
1358
|
+
for (const it of items) {
|
|
1359
|
+
const probe = ((it.tag || '') + ' ' + (it.title || '')).trim()
|
|
1360
|
+
const hitTows = towsMeta.find((tm) => tm.match.test(probe))
|
|
1361
|
+
if (hitTows && !towsExplicit.has(hitTows.key)) {
|
|
1362
|
+
towsExplicit.set(hitTows.key, it.text || (it.bullets ?? [])[0] || it.title || '')
|
|
1363
|
+
} else {
|
|
1364
|
+
quadPool.push(it)
|
|
1365
|
+
}
|
|
1366
|
+
}
|
|
1367
|
+
|
|
1368
|
+
const used = new Set()
|
|
1369
|
+
const quadrants = quadrantMeta.map((qm, qIdx) => {
|
|
1370
|
+
let hit = quadPool.find((it, idx) => !used.has(idx) && (qm.match.test(it.tag || '') || qm.match.test(it.title || '')))
|
|
1371
|
+
if (hit) {
|
|
1372
|
+
used.add(quadPool.indexOf(hit))
|
|
1373
|
+
} else {
|
|
1374
|
+
const nextIdx = quadPool.findIndex((_, idx) => !used.has(idx))
|
|
1375
|
+
if (nextIdx >= 0) {
|
|
1376
|
+
hit = quadPool[nextIdx]
|
|
1377
|
+
used.add(nextIdx)
|
|
1378
|
+
}
|
|
1379
|
+
}
|
|
1380
|
+
const cleanTitle = hit?.title ? hit.title.replace(/^[SWOT]\s*[·::\-—]\s*/i, '').trim() : ''
|
|
1381
|
+
return {
|
|
1382
|
+
...qm,
|
|
1383
|
+
title: cleanTitle,
|
|
1384
|
+
text: hit?.text || '',
|
|
1385
|
+
bullets: hit?.bullets ?? [],
|
|
1386
|
+
}
|
|
1387
|
+
})
|
|
1388
|
+
|
|
1389
|
+
const rawAnchor = (slide.text && slide.text.trim().length <= 24 ? slide.text.trim() : '')
|
|
1390
|
+
|| (slide.subtitle && slide.subtitle.trim().length <= 24 ? slide.subtitle.trim() : '')
|
|
1391
|
+
const anchorText = formatSwotAnchorText(rawAnchor, isEn)
|
|
1392
|
+
|
|
1393
|
+
// 生成底部 SO / WO / ST / WT 行动策略条(优先采用显式策略或 slide.columns,否则根据四象限标题智能凝练)
|
|
1394
|
+
const shortPhrase = (q, fallbackZh, fallbackEn) => {
|
|
1395
|
+
const cand = q.title || (q.bullets[0] ? stripInlineMarkdown(q.bullets[0]).split(/[::,,;;]/)[0] : '') || stripInlineMarkdown(q.text).split(/[::,,;;]/)[0]
|
|
1396
|
+
if (cand && cand.length <= 14) return cand
|
|
1397
|
+
if (cand) return cand.slice(0, 12) + '…'
|
|
1398
|
+
return isEn ? fallbackEn : fallbackZh
|
|
1399
|
+
}
|
|
1400
|
+
const sShort = shortPhrase(quadrants[0], '核心壁垒', 'core strength')
|
|
1401
|
+
const wShort = shortPhrase(quadrants[1], '关键短板', 'gap')
|
|
1402
|
+
const oShort = shortPhrase(quadrants[2], '市场窗口', 'market window')
|
|
1403
|
+
const tShort = shortPhrase(quadrants[3], '外部冲击', 'headwinds')
|
|
1404
|
+
|
|
1405
|
+
const synthesizedDefaults = isEn
|
|
1406
|
+
? [
|
|
1407
|
+
'Leverage ' + sShort + ' to capture ' + oShort,
|
|
1408
|
+
'Use ' + oShort + ' to close ' + wShort,
|
|
1409
|
+
'Reinforce ' + sShort + ' against ' + tShort,
|
|
1410
|
+
'Hedge ' + wShort + ' & ' + tShort,
|
|
1411
|
+
]
|
|
1412
|
+
: [
|
|
1413
|
+
'以「' + sShort + '」抢占「' + oShort + '」',
|
|
1414
|
+
'借「' + oShort + '」补齐「' + wShort + '」',
|
|
1415
|
+
'凭「' + sShort + '」抵御「' + tShort + '」',
|
|
1416
|
+
'收敛「' + wShort + '」严防「' + tShort + '」',
|
|
1417
|
+
]
|
|
1418
|
+
|
|
1419
|
+
const strategies = towsMeta.map((tm, idx) => {
|
|
1420
|
+
const fromCol = Array.isArray(slide.columns) && slide.columns[idx] ? slide.columns[idx].replace(/^(?:SO|WO|ST|WT)\s*[·::\-—]\s*/i, '') : ''
|
|
1421
|
+
return {
|
|
1422
|
+
key: tm.key,
|
|
1423
|
+
label: tm.label,
|
|
1424
|
+
action: towsExplicit.get(tm.key) || fromCol || synthesizedDefaults[idx],
|
|
1425
|
+
}
|
|
1426
|
+
})
|
|
1427
|
+
|
|
1428
|
+
return { quadrants, anchorText, strategies }
|
|
1429
|
+
}
|
|
1430
|
+
|
|
1431
|
+
function swotRoleColor(role, tk) {
|
|
1432
|
+
if (role === 'positive') return tk.positive
|
|
1433
|
+
if (role === 'warning') return tk.warning
|
|
1434
|
+
if (role === 'negative') return tk.negative
|
|
1435
|
+
return tk.accentPrimary
|
|
1436
|
+
}
|
|
1437
|
+
|
|
1438
|
+
function renderSwotPptx(slide, area, nextIdFn, chromeCfg, theme, langAttr) {
|
|
1439
|
+
const tk = theme.tokens
|
|
1440
|
+
const model = computeSwotModel(slide, langAttr)
|
|
1441
|
+
const shapes = []
|
|
1442
|
+
const cardPreset = chromeCfg.cardRadiusPx > 0 ? 'roundRect' : 'rect'
|
|
1443
|
+
|
|
1444
|
+
const stripH = 0.62
|
|
1445
|
+
const stripGap = 0.14
|
|
1446
|
+
const gridH = Math.max(2.6, area.h - stripH - stripGap)
|
|
1447
|
+
const gapX = 0.24
|
|
1448
|
+
const gapY = 0.20
|
|
1449
|
+
const qW = (area.w - gapX) / 2
|
|
1450
|
+
const qH = (gridH - gapY) / 2
|
|
1451
|
+
|
|
1452
|
+
const anchorW = 2.16
|
|
1453
|
+
const anchorH = 0.92
|
|
1454
|
+
const anchorHalfOverlap = Math.max(0.95, anchorW / 2 - gapX / 2 + 0.10)
|
|
1455
|
+
|
|
1456
|
+
model.quadrants.forEach((q, idx) => {
|
|
1457
|
+
const col = idx % 2
|
|
1458
|
+
const row = Math.floor(idx / 2)
|
|
1459
|
+
const qx = area.x + col * (qW + gapX)
|
|
1460
|
+
const qy = area.y + row * (qH + gapY)
|
|
1461
|
+
const toneColor = swotRoleColor(q.role, tk)
|
|
1462
|
+
|
|
1463
|
+
shapes.push(ooxmlShape(nextIdFn(), 'SWOT Quadrant ' + q.key, { x: qx, y: qy, w: qW, h: qH }, {
|
|
1464
|
+
preset: cardPreset,
|
|
1465
|
+
adj: roundRectAdj(qW, qH, chromeCfg.cardRadiusPx),
|
|
1466
|
+
fill: idx === 2 ? tk.accentSoft : tk.surface1,
|
|
1467
|
+
stroke: chromeCfg.cardBorderless ? '' : (idx === 0 || idx === 2 ? toneColor : tk.hairline),
|
|
1468
|
+
strokePt: idx === 0 || idx === 2 ? 1.0 : 0.75,
|
|
1469
|
+
}))
|
|
1470
|
+
|
|
1471
|
+
// 象限顶部语义色带标题栏(全部左对齐,下排 O/T 自动避让中央战略锚点)
|
|
1472
|
+
const headH = 0.40
|
|
1473
|
+
const headLeftIn = row === 1 && col === 1 ? anchorHalfOverlap : 0.18
|
|
1474
|
+
const headRightIn = row === 1 && col === 0 ? anchorHalfOverlap : 0.18
|
|
1475
|
+
shapes.push(ooxmlShape(nextIdFn(), 'SWOT Header ' + q.key, { x: qx, y: qy, w: qW, h: headH }, {
|
|
1476
|
+
preset: 'rect',
|
|
1477
|
+
fill: toneColor,
|
|
1478
|
+
anchor: 'ctr',
|
|
1479
|
+
marginsIn: { l: headLeftIn, r: headRightIn, t: 0.02, b: 0.02 },
|
|
1480
|
+
paragraphs: [ooxmlRichParagraph(q.header + (q.title && q.title !== q.header ? ' · ' + q.title : ''), { sizePt: 12.5, color: relativeLuminance(toneColor) > 0.42 ? '#0F172A' : '#FFFFFF', bold: true, lang: langAttr, align: 'l', font: theme.fonts.heading, lineHeight: 1.1 })],
|
|
1481
|
+
}))
|
|
1482
|
+
|
|
1483
|
+
// 象限内容框(上排顶对齐且左边缘与标题严格对齐;密集多条要点时内侧避让中央锚点)
|
|
1484
|
+
const lines = [
|
|
1485
|
+
...(q.text ? [q.text] : []),
|
|
1486
|
+
...(q.bullets ?? []),
|
|
1487
|
+
]
|
|
1488
|
+
const needInnerClearance = row === 0 && lines.length >= 4
|
|
1489
|
+
const leftPad = needInnerClearance && col === 1 ? anchorHalfOverlap : 0.18
|
|
1490
|
+
const rightPad = needInnerClearance && col === 0 ? anchorHalfOverlap : 0.22
|
|
1491
|
+
const contentBox = { x: qx + leftPad, y: qy + headH + 0.08, w: Math.max(1.8, qW - leftPad - rightPad), h: Math.max(0.6, qH - headH - 0.14) }
|
|
1492
|
+
if (lines.length > 0) {
|
|
1493
|
+
const fit = computeTextFit(lines, contentBox, 'cardBody', { maxPt: 13.5, minPt: 11.5 })
|
|
1494
|
+
const paras = []
|
|
1495
|
+
if (q.text) {
|
|
1496
|
+
paras.push(ooxmlRichParagraph(q.text, {
|
|
1497
|
+
sizePt: fit.fontPt,
|
|
1498
|
+
color: tk.inkPrimary,
|
|
1499
|
+
secondaryColor: tk.inkSecondary,
|
|
1500
|
+
lang: langAttr,
|
|
1501
|
+
font: theme.fonts.body,
|
|
1502
|
+
lineHeight: 1.32,
|
|
1503
|
+
spaceAfterPt: q.bullets?.length ? 4 : 0,
|
|
1504
|
+
autoLeadBold: true,
|
|
1505
|
+
}))
|
|
1506
|
+
}
|
|
1507
|
+
for (const b of q.bullets ?? []) {
|
|
1508
|
+
paras.push(ooxmlRichParagraph(b, {
|
|
1509
|
+
sizePt: fit.fontPt,
|
|
1510
|
+
color: tk.inkPrimary,
|
|
1511
|
+
secondaryColor: tk.inkSecondary,
|
|
1512
|
+
bullet: true,
|
|
1513
|
+
bulletColor: toneColor,
|
|
1514
|
+
lang: langAttr,
|
|
1515
|
+
font: theme.fonts.body,
|
|
1516
|
+
lineHeight: 1.3,
|
|
1517
|
+
spaceAfterPt: 3,
|
|
1518
|
+
autoLeadBold: true,
|
|
1519
|
+
}))
|
|
1520
|
+
}
|
|
1521
|
+
shapes.push(ooxmlShape(nextIdFn(), 'SWOT Body ' + q.key, contentBox, { txBox: true, anchor: row === 0 ? 't' : 'ctr', marginsIn: ZERO_MARGINS, fontScale: fit.fontScale, paragraphs: paras }))
|
|
1522
|
+
}
|
|
1523
|
+
})
|
|
1524
|
+
|
|
1525
|
+
// 中央十字交汇“破局核心”八角徽章战略锚点(宽阔内切文本框,4~6 字词组绝不半词折行)
|
|
1526
|
+
const midX = area.x + area.w / 2
|
|
1527
|
+
const midY = area.y + gridH / 2
|
|
1528
|
+
const anchorLines = String(model.anchorText).split('\n').filter(Boolean)
|
|
1529
|
+
const maxAnchorLen = Math.max(1, ...anchorLines.map((ln) => ln.length))
|
|
1530
|
+
shapes.push(ooxmlShape(nextIdFn(), 'SWOT Strategic Anchor', { x: midX - anchorW / 2, y: midY - anchorH / 2, w: anchorW, h: anchorH }, {
|
|
1531
|
+
preset: 'octagon',
|
|
1532
|
+
adjs: { adj: 22000 },
|
|
1533
|
+
fill: tk.accentPrimary,
|
|
1534
|
+
stroke: tk.canvas,
|
|
1535
|
+
strokePt: 2.5,
|
|
1536
|
+
shadow: true,
|
|
1537
|
+
anchor: 'ctr',
|
|
1538
|
+
marginsIn: { l: 0.14, r: 0.14, t: 0.06, b: 0.06 },
|
|
1539
|
+
paragraphs: anchorLines.map((ln) =>
|
|
1540
|
+
ooxmlRichParagraph(ln, { sizePt: maxAnchorLen >= 7 ? 10.5 : 11.5, color: tk.inkOnAccent, bold: true, lang: langAttr, align: 'ctr', font: theme.fonts.heading, lineHeight: 1.15 }),
|
|
1541
|
+
),
|
|
1542
|
+
}))
|
|
1543
|
+
|
|
1544
|
+
// 底部 SO / WO / ST / WT 四栏可执行策略合成条
|
|
1545
|
+
const stripY = area.y + gridH + stripGap
|
|
1546
|
+
const stGap = 0.16
|
|
1547
|
+
const stW = (area.w - stGap * 3) / 4
|
|
1548
|
+
model.strategies.forEach((st, idx) => {
|
|
1549
|
+
const sx = area.x + idx * (stW + stGap)
|
|
1550
|
+
shapes.push(ooxmlShape(nextIdFn(), 'SWOT Strategy ' + st.key, { x: sx, y: stripY, w: stW, h: stripH }, {
|
|
1551
|
+
preset: cardPreset,
|
|
1552
|
+
adj: roundRectAdj(stW, stripH, Math.min(8, chromeCfg.cardRadiusPx)),
|
|
1553
|
+
fill: idx === 0 ? tk.accentSoft : tk.surface2,
|
|
1554
|
+
stroke: idx === 0 ? tk.accentPrimary : tk.hairline,
|
|
1555
|
+
strokePt: 0.75,
|
|
1556
|
+
anchor: 'ctr',
|
|
1557
|
+
marginsIn: { l: 0.12, r: 0.12, t: 0.04, b: 0.04 },
|
|
1558
|
+
paragraphs: [ooxmlRichParagraph('**' + st.key + '** · ' + st.action, { sizePt: 11, color: tk.inkPrimary, accentColor: tk.accentText, lang: langAttr, font: theme.fonts.body, lineHeight: 1.2 })],
|
|
1559
|
+
}))
|
|
1560
|
+
})
|
|
1561
|
+
|
|
1562
|
+
return shapes.join('')
|
|
1563
|
+
}
|
|
1564
|
+
|
|
1565
|
+
function renderSwotHtml(slide, langId) {
|
|
1566
|
+
const model = computeSwotModel(slide, langId)
|
|
1567
|
+
|
|
1568
|
+
return (
|
|
1569
|
+
'<div class="swot-board">' +
|
|
1570
|
+
'<div class="swot-cross">' +
|
|
1571
|
+
model.quadrants.map((q, idx) =>
|
|
1572
|
+
'<article class="surface-card swot-quad swot-' + q.key.toLowerCase() + ' tone-' + q.role + '" data-item-index="' + idx + '">' +
|
|
1573
|
+
'<div class="swot-quad-head">' + escapeHtml(q.header + (q.title && q.title !== q.header ? ' · ' + q.title : '')) + '</div>' +
|
|
1574
|
+
'<div class="swot-quad-body">' +
|
|
1575
|
+
(q.text ? '<p class="card-body">' + renderInlineHtml(q.text, { autoLeadBold: true }) + '</p>' : '') +
|
|
1576
|
+
(q.bullets?.length ? '<ul class="card-bullets">' + q.bullets.map((b) => '<li>' + renderInlineHtml(b, { autoLeadBold: true }) + '</li>').join('') + '</ul>' : '') +
|
|
1577
|
+
'</div></article>',
|
|
1578
|
+
).join('') +
|
|
1579
|
+
'<div class="swot-anchor"><span>' + escapeHtml(model.anchorText).replace(/\n/g, '<br>') + '</span></div>' +
|
|
1580
|
+
'</div>' +
|
|
1581
|
+
'<div class="layout-grid cols-4 swot-tows-strip">' +
|
|
1582
|
+
model.strategies.map((st) =>
|
|
1583
|
+
'<div class="surface-card swot-tows-pill">' +
|
|
1584
|
+
'<span class="item-badge">' + escapeHtml(st.key) + '</span>' +
|
|
1585
|
+
'<span class="swot-tows-text">' + renderInlineHtml(st.action) + '</span>' +
|
|
1586
|
+
'</div>',
|
|
1587
|
+
).join('') +
|
|
1588
|
+
'</div></div>'
|
|
1589
|
+
)
|
|
1590
|
+
}
|
|
1591
|
+
|
|
1592
|
+
function renderHarveyCellHtml(cellText, isHeader, cIdx, oursCol) {
|
|
1593
|
+
const isOurs = cIdx === oursCol
|
|
1594
|
+
if (!isHeader && cIdx > 0) {
|
|
1595
|
+
const parsed = parseHarveyValue(cellText)
|
|
1596
|
+
if (parsed) {
|
|
1597
|
+
if (parsed.kind === 'check') {
|
|
1598
|
+
return '<td class="harvey-cell' + (isOurs ? ' is-ours' : '') + '"><span class="harvey-check ' + (parsed.ok ? 'is-yes' : 'is-no') + '" aria-label="' + escapeHtml(parsed.label) + '">' + escapeHtml(parsed.label) + '</span></td>'
|
|
1599
|
+
}
|
|
1600
|
+
return '<td class="harvey-cell' + (isOurs ? ' is-ours' : '') + '"><span class="harvey-ball harvey-' + parsed.pct + '" title="' + escapeHtml(parsed.label) + '" aria-label="' + escapeHtml(parsed.label) + '"></span></td>'
|
|
1601
|
+
}
|
|
1602
|
+
}
|
|
1603
|
+
const tag = isHeader ? 'th' : 'td'
|
|
1604
|
+
return '<' + tag + (isOurs ? ' class="is-ours"' : (isNumericCell(cellText) ? ' class="num"' : '')) + '>' + renderInlineHtml(cellText) + '</' + tag + '>'
|
|
1605
|
+
}
|
|
1606
|
+
|
|
1607
|
+
export function renderHarveyTableHtml(slide) {
|
|
1608
|
+
const items = resolveEffectiveItems(slide)
|
|
1609
|
+
const rows = Array.isArray(slide.rows) && slide.rows.length > 0
|
|
1610
|
+
? slide.rows
|
|
1611
|
+
: items.length > 0
|
|
1612
|
+
? [['评估维度', '行业基线', '本方案 / Ours'], ...items.map((it) => [it.title || '', it.delta || '50%', it.value || 'full'])]
|
|
1613
|
+
: [['维度', '本方案 / Ours'], ['能力项', 'full']]
|
|
1614
|
+
const cols = Math.max(2, ...rows.map((r) => r.length))
|
|
1615
|
+
const head = Array.from({ length: cols }, (_, c) => String(rows[0]?.[c] ?? ''))
|
|
1616
|
+
const oursCol = findHarveyOursCol(head, cols)
|
|
1617
|
+
const body = rows.slice(1)
|
|
1618
|
+
return (
|
|
1619
|
+
'<table class="deck-table harvey-table"><thead><tr>' +
|
|
1620
|
+
head.map((cell, cIdx) => renderHarveyCellHtml(cell, true, cIdx, oursCol)).join('') +
|
|
1621
|
+
'</tr></thead><tbody>' +
|
|
1622
|
+
body.map((row) => '<tr>' + Array.from({ length: cols }, (_, cIdx) => renderHarveyCellHtml(String(row[cIdx] ?? ''), false, cIdx, oursCol)).join('') + '</tr>').join('') +
|
|
1623
|
+
'</tbody></table>'
|
|
1624
|
+
)
|
|
1625
|
+
}
|
|
1626
|
+
|
|
1627
|
+
export function renderDiagramSlideBodyPptx(slide, ctx) {
|
|
1628
|
+
const { theme, langAttr, chromeCfg, nextId, bodyTopY, bodyBottomY, bodyH, cardPreset } = ctx
|
|
1629
|
+
const tk = theme.tokens
|
|
1630
|
+
const layout = slide.layout || 'bullets'
|
|
1631
|
+
const variant = slide.variant || ''
|
|
1632
|
+
const title = slide.title || ''
|
|
1633
|
+
const shapes = []
|
|
1634
|
+
|
|
1635
|
+
if (layout === 'harvey') {
|
|
1636
|
+
return renderHarveyMatrixPptx(slide, { x: 0.62, y: bodyTopY + 0.06, w: 12.09, h: bodyH - 0.14 }, nextId, chromeCfg, theme, langAttr)
|
|
1637
|
+
}
|
|
1638
|
+
if (layout === 'marimekko') {
|
|
1639
|
+
return renderMarimekkoPptx(slide, { x: 0.62, y: bodyTopY + 0.04, w: 12.09, h: bodyH - 0.10 }, nextId, chromeCfg, theme, langAttr)
|
|
1640
|
+
}
|
|
1641
|
+
if (layout === 'sankey') {
|
|
1642
|
+
return renderSankeyPptx(slide, { x: 0.62, y: bodyTopY + 0.04, w: 12.09, h: bodyH - 0.10 }, nextId, chromeCfg, theme, langAttr)
|
|
1643
|
+
}
|
|
1644
|
+
if (layout === 'value-chain') {
|
|
1645
|
+
return renderPorterValueChainPptx(slide, { x: 0.62, y: bodyTopY + 0.04, w: 12.09, h: bodyH - 0.10 }, nextId, chromeCfg, theme, langAttr)
|
|
1646
|
+
}
|
|
1647
|
+
if (layout === 'swot' || (layout === 'matrix' && variant === 'swot')) {
|
|
1648
|
+
return renderSwotPptx(slide, { x: 0.62, y: bodyTopY + 0.04, w: 12.09, h: bodyH - 0.10 }, nextId, chromeCfg, theme, langAttr)
|
|
1649
|
+
}
|
|
1650
|
+
|
|
1651
|
+
if (layout === 'gantt') {
|
|
1652
|
+
const defaultCols = variant === 'months'
|
|
1653
|
+
? ['M1', 'M2', 'M3', 'M4', 'M5', 'M6']
|
|
1654
|
+
: variant === 'weeks'
|
|
1655
|
+
? ['W1', 'W2', 'W3', 'W4', 'W5', 'W6']
|
|
1656
|
+
: ['Q1', 'Q2', 'Q3', 'Q4']
|
|
1657
|
+
const cols = Array.isArray(slide.columns) && slide.columns.length > 0 && slide.columns.every((c) => typeof c === 'string')
|
|
1658
|
+
? slide.columns.slice(0, 8)
|
|
1659
|
+
: defaultCols
|
|
1660
|
+
const colCount = Math.max(2, cols.length)
|
|
1661
|
+
const items = resolveEffectiveItems(slide).slice(0, 7)
|
|
1662
|
+
const rowCount = Math.max(1, items.length)
|
|
1663
|
+
|
|
1664
|
+
const labelW = 3.72
|
|
1665
|
+
const gridX = 0.62 + labelW + 0.14
|
|
1666
|
+
const gridW = 12.71 - gridX
|
|
1667
|
+
const headH = 0.44
|
|
1668
|
+
const rowGap = 0.08
|
|
1669
|
+
const availRowH = bodyH - headH - 0.14
|
|
1670
|
+
const rowH = Math.min(0.66, Math.max(0.42, (availRowH - rowGap * (rowCount - 1)) / rowCount))
|
|
1671
|
+
const colW = gridW / colCount
|
|
1672
|
+
const totalH = headH + rowCount * rowH + Math.max(0, rowCount - 1) * rowGap
|
|
1673
|
+
const topY = bodyTopY + Math.max(0, (bodyH - totalH) / 2)
|
|
1674
|
+
|
|
1675
|
+
// Left corner header + time column headers
|
|
1676
|
+
shapes.push(ooxmlShape(nextId(), 'Gantt Corner', { x: 0.62, y: topY, w: labelW, h: headH }, {
|
|
1677
|
+
preset: cardPreset,
|
|
1678
|
+
adj: roundRectAdj(labelW, headH, Math.min(6, chromeCfg.cardRadiusPx)),
|
|
1679
|
+
fill: tk.surface2,
|
|
1680
|
+
stroke: tk.hairline,
|
|
1681
|
+
strokePt: 0.5,
|
|
1682
|
+
anchor: 'ctr',
|
|
1683
|
+
marginsIn: { l: 0.14, r: 0.08, t: 0.02, b: 0.02 },
|
|
1684
|
+
paragraphs: [ooxmlRichParagraph(variant === 'swimlane' ? (langAttr === 'en-US' ? 'WORKSTREAM / TASK' : '泳道 / 任务项') : (langAttr === 'en-US' ? 'INITIATIVE / MILESTONE' : '任务里程碑'), { sizePt: 11, color: tk.inkMuted, bold: true, lang: langAttr, font: theme.fonts.body })],
|
|
1685
|
+
}))
|
|
1686
|
+
|
|
1687
|
+
cols.forEach((colLabel, cIdx) => {
|
|
1688
|
+
const cx = gridX + cIdx * colW
|
|
1689
|
+
shapes.push(ooxmlShape(nextId(), 'Gantt Col ' + (cIdx + 1), { x: cx, y: topY, w: colW, h: headH }, {
|
|
1690
|
+
preset: 'rect',
|
|
1691
|
+
fill: cIdx % 2 === 0 ? tk.surface2 : tk.surface1,
|
|
1692
|
+
stroke: tk.hairline,
|
|
1693
|
+
strokePt: 0.5,
|
|
1694
|
+
anchor: 'ctr',
|
|
1695
|
+
marginsIn: { l: 0.04, r: 0.04, t: 0.02, b: 0.02 },
|
|
1696
|
+
paragraphs: [ooxmlRichParagraph(colLabel, { sizePt: 12, color: tk.inkPrimary, bold: true, lang: langAttr, align: 'ctr', font: theme.fonts.heading })],
|
|
1697
|
+
}))
|
|
1698
|
+
})
|
|
1699
|
+
|
|
1700
|
+
// Vertical grid lines
|
|
1701
|
+
const gridBottomY = topY + totalH
|
|
1702
|
+
for (let c = 0; c <= colCount; c += 1) {
|
|
1703
|
+
const lx = gridX + c * colW
|
|
1704
|
+
shapes.push(ooxmlLine(nextId(), 'Gantt Grid ' + c, { x: lx, y: topY + headH }, { x: lx, y: gridBottomY }, { color: tk.hairline, widthPt: 0.5, dash: c === 0 || c === colCount ? '' : 'dot' }))
|
|
1705
|
+
}
|
|
1706
|
+
|
|
1707
|
+
const barPalette = [tk.accentPrimary, tk.accentSecondary, tk.positive, tk.accentPrimary]
|
|
1708
|
+
items.forEach((it, idx) => {
|
|
1709
|
+
const ry = topY + headH + 0.06 + idx * (rowH + rowGap)
|
|
1710
|
+
const st = statusPalette(it.status, tk)
|
|
1711
|
+
const barFill = it.status ? st.bar : barPalette[idx % barPalette.length]
|
|
1712
|
+
|
|
1713
|
+
// Row backdrop
|
|
1714
|
+
shapes.push(ooxmlShape(nextId(), 'Gantt Track ' + (idx + 1), { x: gridX, y: ry, w: gridW, h: rowH }, { preset: 'rect', fill: idx % 2 === 0 ? tk.surface1 : tk.canvas, stroke: tk.hairline, strokePt: 0.25 }))
|
|
1715
|
+
|
|
1716
|
+
// Left task label card (optional swimlane tag + title)
|
|
1717
|
+
shapes.push(ooxmlShape(nextId(), 'Gantt Task BG ' + (idx + 1), { x: 0.62, y: ry, w: labelW, h: rowH }, { preset: cardPreset, adj: roundRectAdj(labelW, rowH, Math.min(6, chromeCfg.cardRadiusPx)), fill: tk.surface1, stroke: chromeCfg.cardBorderless ? '' : tk.hairline, strokePt: 0.5 }))
|
|
1718
|
+
if (it.tag) {
|
|
1719
|
+
const tagW = computeBadgePillWidth(it.tag, 9.5, 1.18, 0.52)
|
|
1720
|
+
shapes.push(ooxmlShape(nextId(), 'Gantt Tag ' + (idx + 1), { x: 0.72, y: ry + (rowH - 0.28) / 2, w: tagW, h: 0.28 }, {
|
|
1721
|
+
preset: cardPreset,
|
|
1722
|
+
adj: roundRectAdj(tagW, 0.28, Math.min(6, chromeCfg.cardRadiusPx)),
|
|
1723
|
+
fill: tk.accentSoft,
|
|
1724
|
+
anchor: 'ctr',
|
|
1725
|
+
marginsIn: { l: 0.03, r: 0.03, t: 0.01, b: 0.01 },
|
|
1726
|
+
paragraphs: [ooxmlRichParagraph(it.tag, { sizePt: 9.5, color: tk.accentText, bold: true, lang: langAttr, align: 'ctr', font: theme.fonts.body })],
|
|
1727
|
+
}))
|
|
1728
|
+
shapes.push(ooxmlShape(nextId(), 'Gantt ' + (idx + 1), { x: 0.72 + tagW + 0.10, y: ry + 0.02, w: labelW - tagW - 0.28, h: rowH - 0.04 }, {
|
|
1729
|
+
txBox: true,
|
|
1730
|
+
anchor: 'ctr',
|
|
1731
|
+
marginsIn: ZERO_MARGINS,
|
|
1732
|
+
paragraphs: [ooxmlRichParagraph(it.title || it.text || '', { sizePt: 12.5, color: tk.inkPrimary, bold: true, lang: langAttr, font: theme.fonts.body, lineHeight: 1.15 })],
|
|
1733
|
+
}))
|
|
1734
|
+
} else {
|
|
1735
|
+
shapes.push(ooxmlShape(nextId(), 'Gantt ' + (idx + 1), { x: 0.76, y: ry + 0.02, w: labelW - 0.24, h: rowH - 0.04 }, {
|
|
1736
|
+
txBox: true,
|
|
1737
|
+
anchor: 'ctr',
|
|
1738
|
+
marginsIn: ZERO_MARGINS,
|
|
1739
|
+
paragraphs: [ooxmlRichParagraph(it.title || it.text || '', { sizePt: 13, color: tk.inkPrimary, bold: true, lang: langAttr, font: theme.fonts.body, lineHeight: 1.15 })],
|
|
1740
|
+
}))
|
|
1741
|
+
}
|
|
1742
|
+
|
|
1743
|
+
const startSlot = it.start !== undefined
|
|
1744
|
+
? Math.max(0, Math.min(colCount - 0.25, it.start))
|
|
1745
|
+
: Math.min(colCount - 1, idx % colCount)
|
|
1746
|
+
const isPureMilestone = it.span === 0 || (Boolean(it.milestone) && it.span === undefined)
|
|
1747
|
+
const hasEndMilestone = !isPureMilestone && Boolean(it.milestone)
|
|
1748
|
+
if (isPureMilestone) {
|
|
1749
|
+
const mCenter = gridX + ((startSlot + 0.5) / colCount) * gridW
|
|
1750
|
+
const mSize = Math.min(0.32, rowH * 0.62)
|
|
1751
|
+
shapes.push(ooxmlShape(nextId(), 'Gantt Milestone ' + (idx + 1), { x: mCenter - mSize / 2, y: ry + (rowH - mSize) / 2, w: mSize, h: mSize }, { preset: 'diamond', fill: barFill, stroke: tk.canvas, strokePt: 1.0 }))
|
|
1752
|
+
const mLabel = it.value || it.delta || it.text || ''
|
|
1753
|
+
if (mLabel) {
|
|
1754
|
+
const onRight = startSlot < colCount - 1.2
|
|
1755
|
+
const lblBox = onRight
|
|
1756
|
+
? { x: mCenter + mSize / 2 + 0.10, y: ry + 0.04, w: Math.max(1.2, gridX + gridW - (mCenter + mSize / 2 + 0.14)), h: rowH - 0.08 }
|
|
1757
|
+
: { x: Math.max(gridX + 0.08, mCenter - mSize / 2 - 2.1), y: ry + 0.04, w: 2.0, h: rowH - 0.08 }
|
|
1758
|
+
shapes.push(ooxmlShape(nextId(), 'Gantt Milestone Label ' + (idx + 1), lblBox, {
|
|
1759
|
+
txBox: true,
|
|
1760
|
+
anchor: 'ctr',
|
|
1761
|
+
marginsIn: ZERO_MARGINS,
|
|
1762
|
+
paragraphs: [ooxmlRichParagraph(mLabel, { sizePt: 11, color: tk.accentText, bold: true, lang: langAttr, align: onRight ? 'l' : 'r', font: theme.fonts.body })],
|
|
1763
|
+
}))
|
|
1764
|
+
}
|
|
1765
|
+
} else {
|
|
1766
|
+
const spanSlot = Math.max(0.35, Math.min(colCount - startSlot, it.span !== undefined ? it.span : 1))
|
|
1767
|
+
const barX = gridX + (startSlot / colCount) * gridW + 0.04
|
|
1768
|
+
const barW = Math.max(0.30, (spanSlot / colCount) * gridW - 0.08)
|
|
1769
|
+
const barH = Math.min(0.36, rowH * 0.64)
|
|
1770
|
+
const barY = ry + (rowH - barH) / 2
|
|
1771
|
+
const barText = it.value || it.delta || ''
|
|
1772
|
+
shapes.push(ooxmlShape(nextId(), 'Gantt Bar ' + (idx + 1), { x: barX, y: barY, w: barW, h: barH }, {
|
|
1773
|
+
preset: chromeCfg.cardRadiusPx > 0 ? 'roundRect' : 'rect',
|
|
1774
|
+
adj: roundRectAdj(barW, barH, Math.min(8, chromeCfg.cardRadiusPx)),
|
|
1775
|
+
fill: barFill,
|
|
1776
|
+
anchor: 'ctr',
|
|
1777
|
+
marginsIn: { l: 0.08, r: 0.08, t: 0.01, b: 0.01 },
|
|
1778
|
+
paragraphs: barText
|
|
1779
|
+
? [ooxmlRichParagraph(barText, { sizePt: 11, color: '#FFFFFF', bold: true, lang: langAttr, align: 'ctr', font: theme.fonts.body })]
|
|
1780
|
+
: [],
|
|
1781
|
+
}))
|
|
1782
|
+
if (hasEndMilestone) {
|
|
1783
|
+
const endMSize = Math.min(0.28, rowH * 0.56)
|
|
1784
|
+
shapes.push(ooxmlShape(nextId(), 'Gantt Milestone ' + (idx + 1), { x: barX + barW - endMSize / 2, y: ry + (rowH - endMSize) / 2, w: endMSize, h: endMSize }, { preset: 'diamond', fill: barFill, stroke: tk.canvas, strokePt: 1.5 }))
|
|
1785
|
+
}
|
|
1786
|
+
}
|
|
1787
|
+
})
|
|
1788
|
+
|
|
1789
|
+
return shapes.join('')
|
|
1790
|
+
}
|
|
1791
|
+
|
|
1792
|
+
if (layout === 'architecture') {
|
|
1793
|
+
const allItems = resolveEffectiveItems(slide).slice(0, 6)
|
|
1794
|
+
const isSidecarItem = (it) =>
|
|
1795
|
+
it.status === 'accent' || /^(?:sidecar|governance|security|observability|安全|治理|可观测|监控|合规|运维)$/i.test(String(it.tag || '').trim())
|
|
1796
|
+
const candidateSidecars = allItems.filter(isSidecarItem)
|
|
1797
|
+
const candidateTiers = allItems.filter((it) => !isSidecarItem(it))
|
|
1798
|
+
const hasSidecar = candidateSidecars.length >= 1 && candidateTiers.length >= 2
|
|
1799
|
+
const sidecarItems = hasSidecar ? candidateSidecars : []
|
|
1800
|
+
const tierItems = hasSidecar ? candidateTiers : allItems
|
|
1801
|
+
const nTiers = Math.max(1, tierItems.length)
|
|
1802
|
+
|
|
1803
|
+
const sidecarW = hasSidecar ? 2.38 : 0
|
|
1804
|
+
const sidecarGap = hasSidecar ? 0.24 : 0
|
|
1805
|
+
const tierAreaW = 12.09 - sidecarW - sidecarGap
|
|
1806
|
+
const arrowH = nTiers > 1 ? 0.34 : 0
|
|
1807
|
+
const tierH = Math.min(1.32, (bodyH - arrowH * Math.max(0, nTiers - 1)) / nTiers)
|
|
1808
|
+
const totalArchH = tierH * nTiers + arrowH * Math.max(0, nTiers - 1)
|
|
1809
|
+
const startY = bodyTopY + Math.max(0, (bodyH - totalArchH) / 2)
|
|
1810
|
+
|
|
1811
|
+
tierItems.forEach((it, idx) => {
|
|
1812
|
+
const ty = startY + idx * (tierH + arrowH)
|
|
1813
|
+
const isTopTier = idx === 0
|
|
1814
|
+
shapes.push(renderSurfaceCardPptx('Architecture Tier ' + (idx + 1), { x: 0.62, y: ty, w: tierAreaW, h: tierH }, { fill: isTopTier ? tk.surface2 : tk.surface1, focal: isTopTier }, nextId, chromeCfg, theme))
|
|
1815
|
+
|
|
1816
|
+
// Left tier label block
|
|
1817
|
+
const labelW = Math.min(2.65, tierAreaW * 0.27)
|
|
1818
|
+
shapes.push(ooxmlShape(nextId(), 'Architecture ' + (idx + 1), { x: 0.78, y: ty + 0.08, w: labelW, h: tierH - 0.16 }, {
|
|
1819
|
+
txBox: true,
|
|
1820
|
+
anchor: 'ctr',
|
|
1821
|
+
marginsIn: { l: 0.04, r: 0.06, t: 0.02, b: 0.02 },
|
|
1822
|
+
paragraphs: [
|
|
1823
|
+
...(it.tag ? [ooxmlRichParagraph(it.tag.toUpperCase(), { sizePt: 9.5, color: tk.accentText, bold: true, lang: langAttr, font: theme.fonts.body, spc: 100, spaceAfterPt: 2 })] : []),
|
|
1824
|
+
ooxmlRichParagraph(it.title || '', { sizePt: 14.5, color: tk.inkPrimary, bold: true, lang: langAttr, font: theme.fonts.heading, lineHeight: 1.18 }),
|
|
1825
|
+
],
|
|
1826
|
+
}))
|
|
1827
|
+
|
|
1828
|
+
// Sub-module boxes from bullets[] or text fallback
|
|
1829
|
+
const modsX = 0.62 + labelW + 0.22
|
|
1830
|
+
const modsW = tierAreaW - labelW - 0.38
|
|
1831
|
+
const mods = it.bullets?.length ? it.bullets : (it.text ? [it.text] : [])
|
|
1832
|
+
if (mods.length > 0) {
|
|
1833
|
+
const modGap = 0.14
|
|
1834
|
+
const modW = (modsW - modGap * (mods.length - 1)) / mods.length
|
|
1835
|
+
const modH = Math.max(0.46, tierH - 0.28)
|
|
1836
|
+
mods.forEach((modText, mIdx) => {
|
|
1837
|
+
const mx = modsX + mIdx * (modW + modGap)
|
|
1838
|
+
shapes.push(ooxmlShape(nextId(), 'Arch Module ' + (idx + 1) + '-' + (mIdx + 1), { x: mx, y: ty + 0.14, w: modW, h: modH }, {
|
|
1839
|
+
preset: cardPreset,
|
|
1840
|
+
adj: roundRectAdj(modW, modH, Math.min(8, chromeCfg.cardRadiusPx)),
|
|
1841
|
+
fill: tk.canvas,
|
|
1842
|
+
stroke: tk.hairline,
|
|
1843
|
+
strokePt: 0.75,
|
|
1844
|
+
anchor: 'ctr',
|
|
1845
|
+
marginsIn: { l: 0.08, r: 0.08, t: 0.04, b: 0.04 },
|
|
1846
|
+
paragraphs: [
|
|
1847
|
+
ooxmlRichParagraph(modText, {
|
|
1848
|
+
sizePt: mods.length >= 4 ? 12 : 13,
|
|
1849
|
+
color: tk.inkPrimary,
|
|
1850
|
+
secondaryColor: tk.inkSecondary,
|
|
1851
|
+
bold: false,
|
|
1852
|
+
lang: langAttr,
|
|
1853
|
+
align: 'ctr',
|
|
1854
|
+
font: theme.fonts.body,
|
|
1855
|
+
lineHeight: 1.2,
|
|
1856
|
+
autoLeadBold: true,
|
|
1857
|
+
}),
|
|
1858
|
+
],
|
|
1859
|
+
}))
|
|
1860
|
+
})
|
|
1861
|
+
}
|
|
1862
|
+
|
|
1863
|
+
// Dataflow arrows between tiers
|
|
1864
|
+
if (idx < nTiers - 1) {
|
|
1865
|
+
const ay = ty + tierH + 0.02
|
|
1866
|
+
const ah = arrowH - 0.04
|
|
1867
|
+
const arrowPreset = variant === 'platform' ? 'upDownArrow' : 'downArrow'
|
|
1868
|
+
const positions = [0.62 + tierAreaW * 0.36, 0.62 + tierAreaW * 0.68]
|
|
1869
|
+
positions.forEach((ax, aIdx) => {
|
|
1870
|
+
shapes.push(ooxmlShape(nextId(), 'Arch Arrow ' + (idx + 1) + '-' + (aIdx + 1), { x: ax - 0.09, y: ay, w: 0.18, h: ah }, { preset: arrowPreset, fill: tk.accentPrimary }))
|
|
1871
|
+
})
|
|
1872
|
+
}
|
|
1873
|
+
})
|
|
1874
|
+
|
|
1875
|
+
if (hasSidecar) {
|
|
1876
|
+
const sx = 0.62 + tierAreaW + sidecarGap
|
|
1877
|
+
const sideCount = sidecarItems.length
|
|
1878
|
+
const scGap = 0.16
|
|
1879
|
+
const scH = (totalArchH - scGap * (sideCount - 1)) / sideCount
|
|
1880
|
+
sidecarItems.forEach((sc, sIdx) => {
|
|
1881
|
+
const sy = startY + sIdx * (scH + scGap)
|
|
1882
|
+
shapes.push(renderSurfaceCardPptx('Arch Sidecar ' + (sIdx + 1), { x: sx, y: sy, w: sidecarW, h: scH }, { fill: tk.accentSoft, focal: true }, nextId, chromeCfg, theme))
|
|
1883
|
+
const scLines = [sc.title || '', sc.text || '', ...(sc.bullets ?? [])].filter(Boolean)
|
|
1884
|
+
const scBox = { x: sx + 0.16, y: sy + 0.16, w: sidecarW - 0.32, h: scH - 0.32 }
|
|
1885
|
+
const scFit = computeTextFit(scLines, scBox, 'cardBody', { maxPt: 13.5, minPt: 11.5 })
|
|
1886
|
+
const scParas = []
|
|
1887
|
+
if (sc.tag) {
|
|
1888
|
+
scParas.push(ooxmlRichParagraph(sc.tag.toUpperCase(), { sizePt: 9.5, color: tk.accentText, bold: true, lang: langAttr, font: theme.fonts.body, spc: 100, spaceAfterPt: 4 }))
|
|
1889
|
+
}
|
|
1890
|
+
if (sc.title) {
|
|
1891
|
+
scParas.push(ooxmlRichParagraph(sc.title, { sizePt: 14.5, color: tk.inkPrimary, bold: true, lang: langAttr, font: theme.fonts.heading, spaceAfterPt: 6 }))
|
|
1892
|
+
}
|
|
1893
|
+
if (sc.text) {
|
|
1894
|
+
scParas.push(ooxmlRichParagraph(sc.text, { sizePt: scFit.fontPt, color: tk.inkSecondary, lang: langAttr, font: theme.fonts.body, lineHeight: 1.32, spaceAfterPt: 5 }))
|
|
1895
|
+
}
|
|
1896
|
+
for (const b of sc.bullets ?? []) {
|
|
1897
|
+
scParas.push(ooxmlRichParagraph(b, { sizePt: scFit.fontPt, color: tk.inkPrimary, secondaryColor: tk.inkSecondary, bullet: true, bulletColor: tk.accentPrimary, lang: langAttr, font: theme.fonts.body, lineHeight: 1.3, spaceAfterPt: 4, autoLeadBold: true }))
|
|
1898
|
+
}
|
|
1899
|
+
shapes.push(ooxmlShape(nextId(), 'Architecture Sidecar Text ' + (sIdx + 1), scBox, { txBox: true, anchor: 'ctr', marginsIn: ZERO_MARGINS, fontScale: scFit.fontScale, paragraphs: scParas }))
|
|
1900
|
+
})
|
|
1901
|
+
}
|
|
1902
|
+
|
|
1903
|
+
return shapes.join('')
|
|
1904
|
+
}
|
|
1905
|
+
|
|
1906
|
+
if (layout === 'tam') {
|
|
1907
|
+
const rawItems = resolveEffectiveItems(slide).slice(0, 3)
|
|
1908
|
+
const defaults = ['TAM', 'SAM', 'SOM']
|
|
1909
|
+
const items = Array.from({ length: Math.max(1, rawItems.length) }, (_, idx) => ({
|
|
1910
|
+
...rawItems[idx],
|
|
1911
|
+
tag: rawItems[idx]?.tag || defaults[idx] || ('T' + (idx + 1)),
|
|
1912
|
+
}))
|
|
1913
|
+
const maxDiam = Math.min(4.78, bodyH - 0.12)
|
|
1914
|
+
const cx = 3.12
|
|
1915
|
+
const bottomY = bodyTopY + (bodyH + maxDiam) / 2
|
|
1916
|
+
const ratios = [1.0, 0.68, 0.39]
|
|
1917
|
+
const ringFills = [tk.surface1, tk.accentSoft, tk.accentPrimary]
|
|
1918
|
+
const ringStrokes = [tk.hairline, tk.accentPrimary, tk.accentPrimary]
|
|
1919
|
+
|
|
1920
|
+
// 3 bottom-tangent nested ellipses (drawn outer-to-inner)
|
|
1921
|
+
const ringLabelYs = []
|
|
1922
|
+
items.forEach((it, idx) => {
|
|
1923
|
+
const d = maxDiam * (ratios[idx] ?? Math.max(0.28, 1 - idx * 0.28))
|
|
1924
|
+
const rx = cx - d / 2
|
|
1925
|
+
const ry = bottomY - d
|
|
1926
|
+
const isInner = idx === items.length - 1
|
|
1927
|
+
shapes.push(ooxmlShape(nextId(), 'TAM Circle ' + (idx + 1), { x: rx, y: ry, w: d, h: d }, {
|
|
1928
|
+
preset: 'ellipse',
|
|
1929
|
+
fill: ringFills[idx] ?? tk.surface2,
|
|
1930
|
+
stroke: ringStrokes[idx] ?? tk.accentPrimary,
|
|
1931
|
+
strokePt: idx === 0 ? 1.25 : 1.5,
|
|
1932
|
+
}))
|
|
1933
|
+
const lblY = isInner ? ry + d / 2 - 0.30 : ry + 0.14
|
|
1934
|
+
const lblH = isInner ? 0.60 : 0.44
|
|
1935
|
+
const lblCenterY = lblY + lblH / 2
|
|
1936
|
+
ringLabelYs.push(lblCenterY)
|
|
1937
|
+
const halfChord = Math.sqrt(Math.max(0.04, (d / 2) ** 2 - (lblCenterY - (ry + d / 2)) ** 2))
|
|
1938
|
+
const lblW = Math.max(0.85, Math.min(d * 0.72, 2 * halfChord - 0.24))
|
|
1939
|
+
const ringShortTag = String(it.tag || defaults[idx] || ('T' + (idx + 1))).split(/\s*[·::\-—|]\s*/)[0].trim() || (defaults[idx] || ('T' + (idx + 1)))
|
|
1940
|
+
const ringText = ringShortTag + (it.value ? (isInner ? '\n' : ' ') + it.value + (it.unit ? ' ' + it.unit : '') : '')
|
|
1941
|
+
shapes.push(ooxmlShape(nextId(), 'TAM Label ' + (idx + 1), { x: cx - lblW / 2, y: lblY, w: lblW, h: lblH }, {
|
|
1942
|
+
txBox: true,
|
|
1943
|
+
anchor: 'ctr',
|
|
1944
|
+
marginsIn: ZERO_MARGINS,
|
|
1945
|
+
paragraphs: [ooxmlRichParagraph(ringText, { sizePt: isInner ? 12.5 : 12, color: isInner ? tk.inkOnAccent : tk.accentText, bold: true, lang: langAttr, align: 'ctr', font: theme.fonts.heading })],
|
|
1946
|
+
}))
|
|
1947
|
+
})
|
|
1948
|
+
|
|
1949
|
+
// Right 3 breakdown cards + horizontal leader connectors
|
|
1950
|
+
const cardX = 6.26
|
|
1951
|
+
const cardW = 6.45
|
|
1952
|
+
const cardGap = 0.20
|
|
1953
|
+
const nCards = items.length
|
|
1954
|
+
const cardH = Math.min(1.52, (bodyH - cardGap * (nCards - 1)) / nCards)
|
|
1955
|
+
const cardsStartY = bodyTopY + Math.max(0, (bodyH - (cardH * nCards + cardGap * (nCards - 1))) / 2)
|
|
1956
|
+
|
|
1957
|
+
items.forEach((it, idx) => {
|
|
1958
|
+
const cy = cardsStartY + idx * (cardH + cardGap)
|
|
1959
|
+
const isInner = idx === nCards - 1
|
|
1960
|
+
const d = maxDiam * (ratios[idx] ?? 0.4)
|
|
1961
|
+
const circleTopY = bottomY - d
|
|
1962
|
+
const dy = (ringLabelYs[idx] ?? (circleTopY + 0.3)) - (circleTopY + d / 2)
|
|
1963
|
+
const r = d / 2
|
|
1964
|
+
const dx = Math.sqrt(Math.max(0, r * r - dy * dy))
|
|
1965
|
+
const lineStartX = Math.min(cardX - 0.14, cx + dx * 0.72)
|
|
1966
|
+
const lineY = cy + cardH / 2
|
|
1967
|
+
shapes.push(ooxmlLine(nextId(), 'TAM Connector ' + (idx + 1), { x: lineStartX, y: lineY }, { x: cardX, y: lineY }, { color: isInner ? tk.accentPrimary : tk.hairline, widthPt: 1.0, dash: 'dot' }))
|
|
1968
|
+
|
|
1969
|
+
shapes.push(renderSurfaceCardPptx('TAM Card ' + (idx + 1), { x: cardX, y: cy, w: cardW, h: cardH }, { fill: isInner ? tk.accentSoft : tk.surface1, focal: isInner }, nextId, chromeCfg, theme))
|
|
1970
|
+
|
|
1971
|
+
const tagW = computeBadgePillWidth(it.tag, 10.5, 1.85, 0.72)
|
|
1972
|
+
shapes.push(ooxmlShape(nextId(), 'TAM Tag ' + (idx + 1), { x: cardX + 0.22, y: cy + 0.22, w: tagW, h: 0.32 }, {
|
|
1973
|
+
preset: cardPreset,
|
|
1974
|
+
adj: roundRectAdj(tagW, 0.32, Math.min(6, chromeCfg.cardRadiusPx)),
|
|
1975
|
+
fill: isInner ? tk.accentPrimary : tk.surface2,
|
|
1976
|
+
anchor: 'ctr',
|
|
1977
|
+
marginsIn: { l: 0.04, r: 0.04, t: 0.01, b: 0.01 },
|
|
1978
|
+
paragraphs: [ooxmlRichParagraph(it.tag, { sizePt: 10.5, color: isInner ? tk.inkOnAccent : tk.accentText, bold: true, lang: langAttr, align: 'ctr', font: theme.fonts.heading })],
|
|
1979
|
+
}))
|
|
1980
|
+
|
|
1981
|
+
const metaColW = Math.max(1.85, tagW)
|
|
1982
|
+
if (it.value) {
|
|
1983
|
+
shapes.push(ooxmlShape(nextId(), 'TAM Value ' + (idx + 1), { x: cardX + 0.22, y: cy + 0.62, w: metaColW, h: cardH - 0.76 }, {
|
|
1984
|
+
txBox: true,
|
|
1985
|
+
anchor: 'ctr',
|
|
1986
|
+
marginsIn: ZERO_MARGINS,
|
|
1987
|
+
paragraphs: [ooxmlRichParagraph(it.value + (it.unit ? ' ' + it.unit : ''), { sizePt: 20, color: tk.accentText, bold: true, lang: langAttr, font: theme.fonts.heading })],
|
|
1988
|
+
}))
|
|
1989
|
+
}
|
|
1990
|
+
|
|
1991
|
+
const cardBodyText = [it.text, ...(it.bullets ?? [])].filter(Boolean).join(';')
|
|
1992
|
+
const textLeft = it.value ? cardX + 0.22 + metaColW + 0.16 : cardX + 0.22 + tagW + 0.18
|
|
1993
|
+
const textBox = { x: textLeft, y: cy + 0.16, w: cardX + cardW - textLeft - 0.18, h: cardH - 0.32 }
|
|
1994
|
+
const fit = computeTextFit([it.title || '', cardBodyText], textBox, 'cardBody', { maxPt: 14.5, minPt: 12.5 })
|
|
1995
|
+
shapes.push(ooxmlShape(nextId(), 'TAM ' + (idx + 1), textBox, {
|
|
1996
|
+
txBox: true,
|
|
1997
|
+
anchor: 'ctr',
|
|
1998
|
+
marginsIn: ZERO_MARGINS,
|
|
1999
|
+
fontScale: fit.fontScale,
|
|
2000
|
+
paragraphs: [
|
|
2001
|
+
...(it.title ? [ooxmlRichParagraph(it.title, { sizePt: Math.min(16, fit.fontPt + 1.5), color: tk.inkPrimary, bold: true, lang: langAttr, font: theme.fonts.heading, spaceAfterPt: cardBodyText ? 4 : 0 })] : []),
|
|
2002
|
+
...(cardBodyText ? [ooxmlRichParagraph(cardBodyText, { sizePt: fit.fontPt, color: tk.inkSecondary, lang: langAttr, font: theme.fonts.body, lineHeight: 1.32 })] : []),
|
|
2003
|
+
],
|
|
2004
|
+
}))
|
|
2005
|
+
})
|
|
2006
|
+
|
|
2007
|
+
return shapes.join('')
|
|
2008
|
+
}
|
|
2009
|
+
|
|
2010
|
+
if (layout === 'org') {
|
|
2011
|
+
const items = resolveEffectiveItems(slide)
|
|
2012
|
+
if (variant === 'team') {
|
|
2013
|
+
const members = items.slice(0, 4)
|
|
2014
|
+
const n = Math.max(1, members.length)
|
|
2015
|
+
const gap = 0.28
|
|
2016
|
+
const cardW = (12.09 - gap * (n - 1)) / n
|
|
2017
|
+
const cardH = Math.min(4.35, bodyH - 0.16)
|
|
2018
|
+
const cardY = bodyTopY + (bodyH - cardH) / 2
|
|
2019
|
+
|
|
2020
|
+
members.forEach((it, idx) => {
|
|
2021
|
+
const cx = 0.62 + idx * (cardW + gap)
|
|
2022
|
+
shapes.push(renderSurfaceCardPptx('Team Card ' + (idx + 1), { x: cx, y: cardY, w: cardW, h: cardH }, { fill: tk.surface1, focal: idx === 0 }, nextId, chromeCfg, theme))
|
|
2023
|
+
|
|
2024
|
+
const avatarD = 0.78
|
|
2025
|
+
const avatarX = cx + (cardW - avatarD) / 2
|
|
2026
|
+
const avatarY = cardY + 0.26
|
|
2027
|
+
shapes.push(ooxmlShape(nextId(), 'Team Avatar ' + (idx + 1), { x: avatarX, y: avatarY, w: avatarD, h: avatarD }, {
|
|
2028
|
+
preset: 'ellipse',
|
|
2029
|
+
fill: idx === 0 ? tk.accentPrimary : tk.surface2,
|
|
2030
|
+
stroke: tk.accentPrimary,
|
|
2031
|
+
strokePt: 1.25,
|
|
2032
|
+
anchor: 'ctr',
|
|
2033
|
+
marginsIn: ZERO_MARGINS,
|
|
2034
|
+
paragraphs: [ooxmlRichParagraph(monogramLetters(it.title || it.tag || 'T'), { sizePt: 18, color: idx === 0 ? tk.inkOnAccent : tk.accentText, bold: true, lang: langAttr, align: 'ctr', font: theme.fonts.heading })],
|
|
2035
|
+
}))
|
|
2036
|
+
|
|
2037
|
+
const roleText = it.role || it.tag || ''
|
|
2038
|
+
if (roleText) {
|
|
2039
|
+
const roleW = computeBadgePillWidth(roleText, 10.5, cardW - 0.36, 0.85)
|
|
2040
|
+
shapes.push(ooxmlShape(nextId(), 'Team Role ' + (idx + 1), { x: cx + (cardW - roleW) / 2, y: avatarY + avatarD + 0.14, w: roleW, h: 0.28 }, {
|
|
2041
|
+
preset: 'roundRect',
|
|
2042
|
+
adj: 50000,
|
|
2043
|
+
fill: tk.accentSoft,
|
|
2044
|
+
anchor: 'ctr',
|
|
2045
|
+
marginsIn: { l: 0.04, r: 0.04, t: 0.01, b: 0.01 },
|
|
2046
|
+
paragraphs: [ooxmlRichParagraph(roleText, { sizePt: 10.5, color: tk.accentText, bold: true, lang: langAttr, align: 'ctr', font: theme.fonts.body })],
|
|
2047
|
+
}))
|
|
2048
|
+
}
|
|
2049
|
+
|
|
2050
|
+
const innerY = avatarY + avatarD + (roleText ? 0.52 : 0.20)
|
|
2051
|
+
const innerBox = { x: cx + 0.20, y: innerY, w: cardW - 0.40, h: Math.max(0.8, cardY + cardH - innerY - 0.16) }
|
|
2052
|
+
const bodyLines = [it.text || '', ...(it.bullets ?? [])].filter(Boolean)
|
|
2053
|
+
const fit = computeTextFit([it.title || '', ...bodyLines], innerBox, 'cardBody', { maxPt: 14.5, minPt: 12.5 })
|
|
2054
|
+
const paras = []
|
|
2055
|
+
if (it.title) {
|
|
2056
|
+
paras.push(ooxmlRichParagraph(it.title, { sizePt: 16.5, color: tk.inkPrimary, bold: true, lang: langAttr, align: 'ctr', font: theme.fonts.heading, spaceAfterPt: 6 }))
|
|
2057
|
+
}
|
|
2058
|
+
if (it.text) {
|
|
2059
|
+
paras.push(ooxmlRichParagraph(it.text, { sizePt: fit.fontPt, color: tk.inkSecondary, lang: langAttr, align: 'ctr', font: theme.fonts.body, lineHeight: 1.36, spaceAfterPt: 4 }))
|
|
2060
|
+
}
|
|
2061
|
+
for (const b of it.bullets ?? []) {
|
|
2062
|
+
paras.push(ooxmlRichParagraph(b, { sizePt: fit.fontPt, color: tk.inkSecondary, bullet: true, bulletColor: tk.accentPrimary, lang: langAttr, font: theme.fonts.body, lineHeight: 1.32, spaceAfterPt: 3 }))
|
|
2063
|
+
}
|
|
2064
|
+
shapes.push(ooxmlShape(nextId(), 'Team ' + (idx + 1), innerBox, { txBox: true, anchor: 't', marginsIn: ZERO_MARGINS, fontScale: fit.fontScale, paragraphs: paras }))
|
|
2065
|
+
})
|
|
2066
|
+
} else {
|
|
2067
|
+
// 'tree' hierarchy org chart
|
|
2068
|
+
const rootItem = items[0] ?? { tag: 'CEO', title: title || '组织架构' }
|
|
2069
|
+
const rawChildren = items.length > 1
|
|
2070
|
+
? items.slice(1, 6)
|
|
2071
|
+
: (rootItem.bullets ?? []).slice(0, 5).map((b, i) => ({ tag: 'DEPT ' + (i + 1), title: b }))
|
|
2072
|
+
const children = rawChildren.length > 0 ? rawChildren : [{ title: '核心业务单元' }]
|
|
2073
|
+
const nChild = children.length
|
|
2074
|
+
|
|
2075
|
+
const rootW = 4.4
|
|
2076
|
+
const rootH = 1.18
|
|
2077
|
+
const rootX = (CANVAS_IN.w - rootW) / 2
|
|
2078
|
+
const rootY = bodyTopY + 0.08
|
|
2079
|
+
shapes.push(renderSurfaceCardPptx('Org Root', { x: rootX, y: rootY, w: rootW, h: rootH }, { fill: tk.accentSoft, focal: true }, nextId, chromeCfg, theme))
|
|
2080
|
+
shapes.push(ooxmlShape(nextId(), 'Org 0', { x: rootX + 0.18, y: rootY + 0.10, w: rootW - 0.36, h: rootH - 0.20 }, {
|
|
2081
|
+
txBox: true,
|
|
2082
|
+
anchor: 'ctr',
|
|
2083
|
+
marginsIn: ZERO_MARGINS,
|
|
2084
|
+
paragraphs: [
|
|
2085
|
+
...((rootItem.role || rootItem.tag) ? [ooxmlRichParagraph((rootItem.role || rootItem.tag).toUpperCase(), { sizePt: 10, color: tk.accentText, bold: true, lang: langAttr, align: 'ctr', font: theme.fonts.body, spc: 120, spaceAfterPt: 2 })] : []),
|
|
2086
|
+
ooxmlRichParagraph(rootItem.title || '', { sizePt: 16.5, color: tk.inkPrimary, bold: true, lang: langAttr, align: 'ctr', font: theme.fonts.heading, spaceAfterPt: rootItem.text ? 2 : 0 }),
|
|
2087
|
+
...(rootItem.text ? [ooxmlRichParagraph(rootItem.text, { sizePt: 12.5, color: tk.inkSecondary, lang: langAttr, align: 'ctr', font: theme.fonts.body })] : []),
|
|
2088
|
+
],
|
|
2089
|
+
}))
|
|
2090
|
+
|
|
2091
|
+
const busY = rootY + rootH + 0.38
|
|
2092
|
+
const childTopY = busY + 0.36
|
|
2093
|
+
const childH = Math.max(1.85, bodyBottomY - childTopY - 0.10)
|
|
2094
|
+
const gap = nChild >= 5 ? 0.18 : 0.26
|
|
2095
|
+
const childW = (12.09 - gap * (nChild - 1)) / nChild
|
|
2096
|
+
const rootCx = CANVAS_IN.w / 2
|
|
2097
|
+
|
|
2098
|
+
// Trunk from root bottom to busY
|
|
2099
|
+
shapes.push(ooxmlLine(nextId(), 'Org Trunk', { x: rootCx, y: rootY + rootH }, { x: rootCx, y: busY }, { color: tk.accentPrimary, widthPt: 1.5 }))
|
|
2100
|
+
|
|
2101
|
+
const childCxs = children.map((_, idx) => 0.62 + idx * (childW + gap) + childW / 2)
|
|
2102
|
+
if (childCxs.length >= 2) {
|
|
2103
|
+
shapes.push(ooxmlLine(nextId(), 'Org Bus', { x: childCxs[0], y: busY }, { x: childCxs[childCxs.length - 1], y: busY }, { color: tk.accentPrimary, widthPt: 1.5 }))
|
|
2104
|
+
}
|
|
2105
|
+
|
|
2106
|
+
children.forEach((ch, idx) => {
|
|
2107
|
+
const cx = 0.62 + idx * (childW + gap)
|
|
2108
|
+
const midX = childCxs[idx]
|
|
2109
|
+
shapes.push(ooxmlLine(nextId(), 'Org Branch ' + (idx + 1), { x: midX, y: busY }, { x: midX, y: childTopY }, { color: tk.accentPrimary, widthPt: 1.25 }))
|
|
2110
|
+
shapes.push(renderSurfaceCardPptx('Org Child ' + (idx + 1), { x: cx, y: childTopY, w: childW, h: childH }, { fill: tk.surface1, focal: false }, nextId, chromeCfg, theme))
|
|
2111
|
+
|
|
2112
|
+
const roleLabel = ch.role || ch.tag || ''
|
|
2113
|
+
if (roleLabel) {
|
|
2114
|
+
const rW = computeBadgePillWidth(roleLabel, 10, childW - 0.28, 0.54)
|
|
2115
|
+
shapes.push(ooxmlShape(nextId(), 'Org Tag ' + (idx + 1), { x: cx + 0.16, y: childTopY + 0.16, w: rW, h: 0.28 }, {
|
|
2116
|
+
preset: cardPreset,
|
|
2117
|
+
adj: roundRectAdj(rW, 0.28, Math.min(6, chromeCfg.cardRadiusPx)),
|
|
2118
|
+
fill: tk.accentSoft,
|
|
2119
|
+
anchor: 'ctr',
|
|
2120
|
+
marginsIn: { l: 0.03, r: 0.03, t: 0.01, b: 0.01 },
|
|
2121
|
+
paragraphs: [ooxmlRichParagraph(roleLabel, { sizePt: 10, color: tk.accentText, bold: true, lang: langAttr, align: 'ctr', font: theme.fonts.body })],
|
|
2122
|
+
}))
|
|
2123
|
+
}
|
|
2124
|
+
|
|
2125
|
+
const innerTop = childTopY + (roleLabel ? 0.54 : 0.20)
|
|
2126
|
+
const innerBox = { x: cx + 0.16, y: innerTop, w: childW - 0.32, h: Math.max(0.8, childTopY + childH - innerTop - 0.14) }
|
|
2127
|
+
const bodyLines = [ch.text || '', ...(ch.bullets ?? [])].filter(Boolean)
|
|
2128
|
+
const fit = computeTextFit([ch.title || '', ...bodyLines], innerBox, 'cardBody', { maxPt: 14, minPt: 12 })
|
|
2129
|
+
const paras = []
|
|
2130
|
+
if (ch.title) {
|
|
2131
|
+
paras.push(ooxmlRichParagraph(ch.title, { sizePt: Math.min(16, fit.fontPt + 1.5), color: tk.inkPrimary, bold: true, lang: langAttr, font: theme.fonts.heading, spaceAfterPt: bodyLines.length ? 5 : 0 }))
|
|
2132
|
+
}
|
|
2133
|
+
if (ch.text) {
|
|
2134
|
+
paras.push(ooxmlRichParagraph(ch.text, { sizePt: fit.fontPt, color: tk.inkSecondary, lang: langAttr, font: theme.fonts.body, lineHeight: 1.32, spaceAfterPt: 4 }))
|
|
2135
|
+
}
|
|
2136
|
+
for (const b of ch.bullets ?? []) {
|
|
2137
|
+
paras.push(ooxmlRichParagraph(b, { sizePt: fit.fontPt, color: tk.inkSecondary, bullet: true, bulletColor: tk.accentPrimary, lang: langAttr, font: theme.fonts.body, lineHeight: 1.3, spaceAfterPt: 3 }))
|
|
2138
|
+
}
|
|
2139
|
+
shapes.push(ooxmlShape(nextId(), 'Org ' + (idx + 1), innerBox, { txBox: true, anchor: 't', marginsIn: ZERO_MARGINS, fontScale: fit.fontScale, paragraphs: paras }))
|
|
2140
|
+
})
|
|
2141
|
+
}
|
|
2142
|
+
return shapes.join('')
|
|
2143
|
+
}
|
|
2144
|
+
|
|
2145
|
+
if (layout === 'process') {
|
|
2146
|
+
const items = resolveEffectiveItems(slide).slice(0, 6)
|
|
2147
|
+
const n = Math.max(1, items.length)
|
|
2148
|
+
|
|
2149
|
+
if (variant === 'flywheel') {
|
|
2150
|
+
const centerX = CANVAS_IN.w / 2
|
|
2151
|
+
const centerY = bodyTopY + bodyH / 2
|
|
2152
|
+
const hubD = Math.min(2.28, bodyH * 0.46)
|
|
2153
|
+
const ringD = Math.min(4.25, bodyH * 0.86)
|
|
2154
|
+
// Subtle circular orbital ring behind flywheel
|
|
2155
|
+
shapes.push(ooxmlShape(nextId(), 'Flywheel Orbit', { x: centerX - ringD / 2, y: centerY - ringD / 2, w: ringD, h: ringD }, { preset: 'ellipse', fill: '', stroke: tk.hairline, strokePt: 1.5, dash: 'dash' }))
|
|
2156
|
+
// Central hub
|
|
2157
|
+
shapes.push(ooxmlShape(nextId(), 'Flywheel Hub', { x: centerX - hubD / 2, y: centerY - hubD / 2, w: hubD, h: hubD }, {
|
|
2158
|
+
preset: 'ellipse',
|
|
2159
|
+
fill: tk.accentPrimary,
|
|
2160
|
+
stroke: tk.canvas,
|
|
2161
|
+
strokePt: 2.0,
|
|
2162
|
+
anchor: 'ctr',
|
|
2163
|
+
marginsIn: { l: 0.16, r: 0.16, t: 0.12, b: 0.12 },
|
|
2164
|
+
paragraphs: [
|
|
2165
|
+
ooxmlRichParagraph(
|
|
2166
|
+
(slide.text && slide.text.trim().length <= 18 ? slide.text.trim() : '')
|
|
2167
|
+
|| (slide.subtitle && slide.subtitle.trim().length <= 18 ? slide.subtitle.trim() : '')
|
|
2168
|
+
|| (langAttr === 'en-US' ? 'Growth\nFlywheel' : '增长飞轮'),
|
|
2169
|
+
{ sizePt: 15, color: tk.inkOnAccent, bold: true, lang: langAttr, align: 'ctr', font: theme.fonts.heading, lineHeight: 1.22 },
|
|
2170
|
+
),
|
|
2171
|
+
],
|
|
2172
|
+
}))
|
|
2173
|
+
|
|
2174
|
+
// 4-node corner flywheel (or radial ring for 3/5/6 nodes)
|
|
2175
|
+
const nodes = items.slice(0, 4)
|
|
2176
|
+
const cardW = 4.32
|
|
2177
|
+
const cardH = Math.min(1.88, (bodyH - 0.56) / 2)
|
|
2178
|
+
const corners = [
|
|
2179
|
+
{ x: 0.62, y: bodyTopY + 0.08, w: cardW, h: cardH },
|
|
2180
|
+
{ x: 12.71 - cardW, y: bodyTopY + 0.08, w: cardW, h: cardH },
|
|
2181
|
+
{ x: 12.71 - cardW, y: bodyBottomY - cardH - 0.08, w: cardW, h: cardH },
|
|
2182
|
+
{ x: 0.62, y: bodyBottomY - cardH - 0.08, w: cardW, h: cardH },
|
|
2183
|
+
]
|
|
2184
|
+
nodes.forEach((it, idx) => {
|
|
2185
|
+
const box = corners[idx]
|
|
2186
|
+
shapes.push(renderSurfaceCardPptx('Flywheel Surface ' + (idx + 1), box, { fill: idx === 0 ? tk.accentSoft : tk.surface1, focal: idx === 0 }, nextId, chromeCfg, theme))
|
|
2187
|
+
const tag = it.tag || String(idx + 1).padStart(2, '0')
|
|
2188
|
+
const tagW = computeBadgePillWidth(tag, 10.5, 1.5, 0.48)
|
|
2189
|
+
shapes.push(ooxmlShape(nextId(), 'Flywheel Tag ' + (idx + 1), { x: box.x + 0.18, y: box.y + 0.16, w: tagW, h: 0.28 }, {
|
|
2190
|
+
preset: cardPreset,
|
|
2191
|
+
adj: roundRectAdj(tagW, 0.28, Math.min(6, chromeCfg.cardRadiusPx)),
|
|
2192
|
+
fill: tk.accentPrimary,
|
|
2193
|
+
anchor: 'ctr',
|
|
2194
|
+
marginsIn: { l: 0.03, r: 0.03, t: 0.01, b: 0.01 },
|
|
2195
|
+
paragraphs: [ooxmlRichParagraph(tag, { sizePt: 10.5, color: tk.inkOnAccent, bold: true, lang: langAttr, align: 'ctr', font: theme.fonts.heading })],
|
|
2196
|
+
}))
|
|
2197
|
+
if (it.conversion || it.delta) {
|
|
2198
|
+
const badge = it.conversion || it.delta
|
|
2199
|
+
const bw = computeBadgePillWidth(badge, 10, 1.4, 0.62)
|
|
2200
|
+
shapes.push(ooxmlShape(nextId(), 'Flywheel Delta ' + (idx + 1), { x: box.x + box.w - bw - 0.16, y: box.y + 0.16, w: bw, h: 0.28 }, {
|
|
2201
|
+
preset: 'roundRect',
|
|
2202
|
+
adj: 50000,
|
|
2203
|
+
fill: tk.surface2,
|
|
2204
|
+
stroke: tk.hairline,
|
|
2205
|
+
strokePt: 0.5,
|
|
2206
|
+
anchor: 'ctr',
|
|
2207
|
+
marginsIn: { l: 0.03, r: 0.03, t: 0.01, b: 0.01 },
|
|
2208
|
+
paragraphs: [ooxmlRichParagraph(badge, { sizePt: 10, color: tk.accentText, bold: true, lang: langAttr, align: 'ctr', font: theme.fonts.body })],
|
|
2209
|
+
}))
|
|
2210
|
+
}
|
|
2211
|
+
const innerBox = { x: box.x + 0.18, y: box.y + 0.52, w: box.w - 0.36, h: box.h - 0.64 }
|
|
2212
|
+
const cardBodyText = [it.text, ...(it.bullets ?? [])].filter(Boolean).join(';')
|
|
2213
|
+
const fit = computeTextFit([it.title || '', cardBodyText], innerBox, 'cardBody', { maxPt: 14.5, minPt: 12.5 })
|
|
2214
|
+
shapes.push(ooxmlShape(nextId(), 'Flywheel ' + (idx + 1), innerBox, {
|
|
2215
|
+
txBox: true,
|
|
2216
|
+
anchor: 't',
|
|
2217
|
+
marginsIn: ZERO_MARGINS,
|
|
2218
|
+
fontScale: fit.fontScale,
|
|
2219
|
+
paragraphs: [
|
|
2220
|
+
...(it.title ? [ooxmlRichParagraph(it.title, { sizePt: Math.min(16, fit.fontPt + 1.5), color: tk.inkPrimary, bold: true, lang: langAttr, font: theme.fonts.heading, spaceAfterPt: 4 })] : []),
|
|
2221
|
+
...(cardBodyText ? [ooxmlRichParagraph(cardBodyText, { sizePt: fit.fontPt, color: tk.inkSecondary, lang: langAttr, font: theme.fonts.body, lineHeight: 1.35 })] : []),
|
|
2222
|
+
],
|
|
2223
|
+
}))
|
|
2224
|
+
})
|
|
2225
|
+
|
|
2226
|
+
// Clockwise directional arrows between the 4 nodes
|
|
2227
|
+
shapes.push(ooxmlShape(nextId(), 'Flywheel Arrow Top', { x: centerX - 0.26, y: corners[0].y + cardH / 2 - 0.14, w: 0.52, h: 0.28 }, { preset: 'rightArrow', fill: tk.accentPrimary }))
|
|
2228
|
+
shapes.push(ooxmlShape(nextId(), 'Flywheel Arrow Right', { x: corners[1].x + cardW / 2 - 0.14, y: centerY - 0.22, w: 0.28, h: 0.44 }, { preset: 'downArrow', fill: tk.accentPrimary }))
|
|
2229
|
+
shapes.push(ooxmlShape(nextId(), 'Flywheel Arrow Bottom', { x: centerX - 0.26, y: corners[2].y + cardH / 2 - 0.14, w: 0.52, h: 0.28 }, { preset: 'leftArrow', fill: tk.accentPrimary }))
|
|
2230
|
+
shapes.push(ooxmlShape(nextId(), 'Flywheel Arrow Left', { x: corners[0].x + cardW / 2 - 0.14, y: centerY - 0.22, w: 0.28, h: 0.44 }, { preset: 'upArrow', fill: tk.accentPrimary }))
|
|
2231
|
+
} else if (variant === 'chevron') {
|
|
2232
|
+
// McKinsey / BCG Interlocking Value-Chain Chevrons + Supporting Detail Cards
|
|
2233
|
+
const overlap = n > 1 ? 0.08 : 0
|
|
2234
|
+
const chevW = (12.09 + (n - 1) * overlap) / n
|
|
2235
|
+
const chevY = bodyTopY + 0.08
|
|
2236
|
+
const chevH = 0.88
|
|
2237
|
+
const detailGap = 0.16
|
|
2238
|
+
const colW = (12.09 - detailGap * (n - 1)) / n
|
|
2239
|
+
const detailY = chevY + chevH + 0.20
|
|
2240
|
+
const detailH = Math.max(1.55, bodyBottomY - detailY - 0.06)
|
|
2241
|
+
|
|
2242
|
+
items.forEach((it, idx) => {
|
|
2243
|
+
const isFirst = idx === 0
|
|
2244
|
+
const isLast = idx === n - 1 && n >= 3
|
|
2245
|
+
const cx = 0.62 + idx * (chevW - overlap)
|
|
2246
|
+
const fillHex = isFirst ? tk.accentPrimary : isLast ? tk.accentSecondary : tk.surface2
|
|
2247
|
+
const inkHex = isFirst
|
|
2248
|
+
? tk.inkOnAccent
|
|
2249
|
+
: isLast
|
|
2250
|
+
? (relativeLuminance(tk.accentSecondary) > 0.36 ? '#0F172A' : '#FFFFFF')
|
|
2251
|
+
: tk.inkPrimary
|
|
2252
|
+
const stageTag = it.tag || String(idx + 1).padStart(2, '0')
|
|
2253
|
+
const chevLabel = (stageTag ? stageTag + ' · ' : '') + (it.title || '')
|
|
2254
|
+
|
|
2255
|
+
shapes.push(ooxmlShape(nextId(), 'Chevron Stage ' + (idx + 1), { x: cx, y: chevY, w: chevW, h: chevH }, {
|
|
2256
|
+
preset: isFirst ? 'homePlate' : 'chevron',
|
|
2257
|
+
adjs: { adj: 20000 },
|
|
2258
|
+
fill: fillHex,
|
|
2259
|
+
stroke: tk.canvas,
|
|
2260
|
+
strokePt: 2.0,
|
|
2261
|
+
anchor: 'ctr',
|
|
2262
|
+
marginsIn: { l: isFirst ? 0.14 : 0.28, r: 0.24, t: 0.06, b: 0.06 },
|
|
2263
|
+
paragraphs: [ooxmlRichParagraph(chevLabel, { sizePt: n >= 5 ? 13 : 14.5, color: inkHex, bold: true, lang: langAttr, align: 'ctr', font: theme.fonts.heading, lineHeight: 1.18 })],
|
|
2264
|
+
}))
|
|
2265
|
+
|
|
2266
|
+
const dx = 0.62 + idx * (colW + detailGap)
|
|
2267
|
+
const cardBox = { x: dx, y: detailY, w: colW, h: detailH }
|
|
2268
|
+
shapes.push(renderSurfaceCardPptx('Chevron Detail Surface ' + (idx + 1), cardBox, { fill: isFirst ? tk.accentSoft : tk.surface1, focal: isFirst }, nextId, chromeCfg, theme))
|
|
2269
|
+
|
|
2270
|
+
const convNote = it.conversion || it.delta || (it.value ? it.value + (it.unit ? ' ' + it.unit : '') : '')
|
|
2271
|
+
const detailLines = [
|
|
2272
|
+
...(convNote ? ['**' + convNote + '**'] : []),
|
|
2273
|
+
...(it.text ? [it.text] : []),
|
|
2274
|
+
...(Array.isArray(it.bullets) ? it.bullets : []),
|
|
2275
|
+
]
|
|
2276
|
+
const innerBox = { x: cardBox.x + 0.16, y: cardBox.y + 0.16, w: cardBox.w - 0.32, h: cardBox.h - 0.30 }
|
|
2277
|
+
const fit = computeTextFit(detailLines, innerBox, 'cardBody', { maxPt: 14, minPt: 12.5 })
|
|
2278
|
+
if (detailLines.length > 0) {
|
|
2279
|
+
shapes.push(ooxmlShape(nextId(), 'Chevron Detail ' + (idx + 1), innerBox, {
|
|
2280
|
+
txBox: true,
|
|
2281
|
+
anchor: 't',
|
|
2282
|
+
marginsIn: ZERO_MARGINS,
|
|
2283
|
+
fontScale: fit.fontScale,
|
|
2284
|
+
paragraphs: detailLines.map((line, lIdx) =>
|
|
2285
|
+
ooxmlRichParagraph(line, {
|
|
2286
|
+
sizePt: fit.fontPt,
|
|
2287
|
+
color: lIdx === 0 && convNote ? tk.accentText : tk.inkSecondary,
|
|
2288
|
+
accentColor: tk.accentText,
|
|
2289
|
+
lang: langAttr,
|
|
2290
|
+
font: theme.fonts.body,
|
|
2291
|
+
lineHeight: 1.36,
|
|
2292
|
+
spaceAfterPt: 4,
|
|
2293
|
+
}),
|
|
2294
|
+
),
|
|
2295
|
+
}))
|
|
2296
|
+
}
|
|
2297
|
+
})
|
|
2298
|
+
} else if (variant === 'layers' || variant === 'funnel') {
|
|
2299
|
+
const gapY = 0.14
|
|
2300
|
+
const rowH = Math.min(0.92, (bodyH - gapY * (n - 1)) / n)
|
|
2301
|
+
const startY = bodyTopY + (bodyH - (rowH * n + gapY * (n - 1))) / 2
|
|
2302
|
+
const hasConversions = variant === 'funnel' && items.some((it) => it.conversion || it.delta)
|
|
2303
|
+
const maxBarW = hasConversions ? 10.2 : 12.09
|
|
2304
|
+
|
|
2305
|
+
items.forEach((it, idx) => {
|
|
2306
|
+
const shrink = variant === 'funnel' ? idx * ((maxBarW * 0.34) / Math.max(1, n - 1)) : 0
|
|
2307
|
+
const w = maxBarW - shrink
|
|
2308
|
+
const x = 0.62 + shrink / 2
|
|
2309
|
+
const y = startY + idx * (rowH + gapY)
|
|
2310
|
+
const isFirst = idx === 0
|
|
2311
|
+
const funnelValue = variant === 'funnel' && it.value ? ' · ' + it.value + (it.unit ? ' ' + it.unit : '') : ''
|
|
2312
|
+
|
|
2313
|
+
shapes.push(ooxmlShape(nextId(), 'Layer ' + (idx + 1), { x, y, w, h: rowH }, {
|
|
2314
|
+
preset: cardPreset,
|
|
2315
|
+
adj: roundRectAdj(w, rowH, chromeCfg.cardRadiusPx),
|
|
2316
|
+
fill: isFirst ? tk.accentPrimary : (idx % 2 === 1 ? tk.surface2 : tk.surface1),
|
|
2317
|
+
stroke: chromeCfg.cardBorderless ? '' : (isFirst ? tk.accentPrimary : tk.hairline),
|
|
2318
|
+
strokePt: 0.75,
|
|
2319
|
+
anchor: 'ctr',
|
|
2320
|
+
marginsIn: { l: 0.24, r: 0.24, t: 0.06, b: 0.06 },
|
|
2321
|
+
paragraphs: [
|
|
2322
|
+
ooxmlRichParagraph(
|
|
2323
|
+
(it.tag ? it.tag + ' · ' : '') + (it.title || '') + funnelValue + (it.text ? ' — ' + it.text : ''),
|
|
2324
|
+
{
|
|
2325
|
+
sizePt: 15,
|
|
2326
|
+
color: isFirst ? tk.inkOnAccent : tk.inkPrimary,
|
|
2327
|
+
secondaryColor: isFirst ? tk.inkOnAccent : tk.inkSecondary,
|
|
2328
|
+
bold: isFirst,
|
|
2329
|
+
lang: langAttr,
|
|
2330
|
+
align: variant === 'funnel' ? 'ctr' : 'l',
|
|
2331
|
+
font: theme.fonts.body,
|
|
2332
|
+
autoLeadBold: !isFirst,
|
|
2333
|
+
},
|
|
2334
|
+
),
|
|
2335
|
+
],
|
|
2336
|
+
}))
|
|
2337
|
+
|
|
2338
|
+
const convBadge = variant === 'funnel' ? (it.conversion || it.delta || '') : ''
|
|
2339
|
+
if (convBadge) {
|
|
2340
|
+
const badgeX = 0.62 + maxBarW + 0.24
|
|
2341
|
+
const badgeW = 12.71 - badgeX
|
|
2342
|
+
shapes.push(ooxmlShape(nextId(), 'Funnel Conversion ' + (idx + 1), { x: badgeX, y: y + (rowH - 0.38) / 2, w: badgeW, h: 0.38 }, {
|
|
2343
|
+
preset: 'roundRect',
|
|
2344
|
+
adj: 50000,
|
|
2345
|
+
fill: tk.accentSoft,
|
|
2346
|
+
stroke: tk.accentPrimary,
|
|
2347
|
+
strokePt: 0.75,
|
|
2348
|
+
anchor: 'ctr',
|
|
2349
|
+
marginsIn: { l: 0.06, r: 0.06, t: 0.02, b: 0.02 },
|
|
2350
|
+
paragraphs: [ooxmlRichParagraph('↓ ' + convBadge, { sizePt: 11.5, color: tk.accentText, bold: true, lang: langAttr, align: 'ctr', font: theme.fonts.body })],
|
|
2351
|
+
}))
|
|
2352
|
+
}
|
|
2353
|
+
})
|
|
2354
|
+
} else if (variant === 'timeline') {
|
|
2355
|
+
const spineY = bodyTopY + 0.72
|
|
2356
|
+
shapes.push(ooxmlLine(nextId(), 'Timeline axis', { x: 0.85, y: spineY }, { x: 12.48, y: spineY }, { color: tk.accentPrimary, widthPt: 2.0 }))
|
|
2357
|
+
const gap = 0.20
|
|
2358
|
+
const stepW = (12.09 - gap * (n - 1)) / n
|
|
2359
|
+
items.forEach((it, idx) => {
|
|
2360
|
+
const x = 0.62 + idx * (stepW + gap)
|
|
2361
|
+
const cx = x + stepW / 2
|
|
2362
|
+
shapes.push(ooxmlShape(nextId(), 'Timeline Node ' + (idx + 1), { x: cx - 0.15, y: spineY - 0.15, w: 0.30, h: 0.30 }, { preset: 'ellipse', fill: idx === n - 1 ? tk.accentPrimary : tk.surface1, stroke: tk.accentPrimary, strokePt: 2.0 }))
|
|
2363
|
+
shapes.push(ooxmlShape(nextId(), 'Timeline Tag ' + (idx + 1), { x, y: bodyTopY + 0.10, w: stepW, h: 0.38 }, {
|
|
2364
|
+
txBox: true,
|
|
2365
|
+
anchor: 'ctr',
|
|
2366
|
+
marginsIn: { l: 0.02, r: 0.02, t: 0, b: 0 },
|
|
2367
|
+
paragraphs: [ooxmlRichParagraph(it.tag || ('0' + (idx + 1)), { sizePt: 13, color: tk.accentText, bold: true, lang: langAttr, align: 'ctr', font: theme.fonts.heading })],
|
|
2368
|
+
}))
|
|
2369
|
+
const cardBox = { x, y: spineY + 0.36, w: stepW, h: Math.max(1.8, bodyBottomY - (spineY + 0.42)) }
|
|
2370
|
+
const fit = computeTextFit([it.title || '', it.text || ''], cardBox, 'cardBody', { maxPt: 14.5, minPt: 13.5 })
|
|
2371
|
+
shapes.push(ooxmlShape(nextId(), 'Step ' + (idx + 1), cardBox, {
|
|
2372
|
+
preset: cardPreset,
|
|
2373
|
+
adj: roundRectAdj(cardBox.w, cardBox.h, chromeCfg.cardRadiusPx),
|
|
2374
|
+
fill: tk.surface1,
|
|
2375
|
+
stroke: chromeCfg.cardBorderless ? '' : tk.hairline,
|
|
2376
|
+
strokePt: 0.75,
|
|
2377
|
+
anchor: 't',
|
|
2378
|
+
marginsIn: { l: 0.16, r: 0.16, t: 0.16, b: 0.14 },
|
|
2379
|
+
fontScale: fit.fontScale,
|
|
2380
|
+
paragraphs: [
|
|
2381
|
+
...(it.title ? [ooxmlRichParagraph(it.title, { sizePt: Math.min(16.5, fit.fontPt + 1.5), color: tk.inkPrimary, bold: true, lang: langAttr, font: theme.fonts.heading, spaceAfterPt: 6 })] : []),
|
|
2382
|
+
...(it.text ? [ooxmlRichParagraph(it.text, { sizePt: fit.fontPt, color: tk.inkSecondary, lang: langAttr, font: theme.fonts.body, lineHeight: 1.4 })] : []),
|
|
2383
|
+
],
|
|
2384
|
+
}))
|
|
2385
|
+
})
|
|
2386
|
+
} else {
|
|
2387
|
+
// steps(带箭头连接的横向步骤卡片)
|
|
2388
|
+
const arrowGap = n <= 4 ? 0.36 : 0.24
|
|
2389
|
+
const cardW = (12.09 - arrowGap * (n - 1)) / n
|
|
2390
|
+
const cardH = Math.min(3.55, bodyH - 0.24)
|
|
2391
|
+
const cardY = bodyTopY + (bodyH - cardH) / 2
|
|
2392
|
+
|
|
2393
|
+
items.forEach((it, idx) => {
|
|
2394
|
+
const x = 0.62 + idx * (cardW + arrowGap)
|
|
2395
|
+
const box = { x, y: cardY, w: cardW, h: cardH }
|
|
2396
|
+
shapes.push(renderSurfaceCardPptx('Step Surface ' + (idx + 1), box, { fill: tk.surface1, focal: idx === n - 1 }, nextId, chromeCfg, theme))
|
|
2397
|
+
const stepTag = it.tag || String(idx + 1).padStart(2, '0')
|
|
2398
|
+
if (chromeCfg.useDisplayNumeral) {
|
|
2399
|
+
shapes.push(ooxmlShape(nextId(), 'Step Number ' + (idx + 1), { x: x + 0.18, y: cardY + 0.14, w: cardW - 0.36, h: 0.42 }, {
|
|
2400
|
+
txBox: true,
|
|
2401
|
+
anchor: 'ctr',
|
|
2402
|
+
marginsIn: ZERO_MARGINS,
|
|
2403
|
+
paragraphs: [ooxmlRichParagraph(stepTag, { sizePt: /^\d+$/.test(stepTag) ? 22 : 12, color: tk.accentText, bold: true, lang: langAttr, font: theme.fonts.heading })],
|
|
2404
|
+
}))
|
|
2405
|
+
} else {
|
|
2406
|
+
const stepBadgeW = computeBadgePillWidth(stepTag, 12, cardW - 0.36, 0.50)
|
|
2407
|
+
shapes.push(ooxmlShape(nextId(), 'Step Number ' + (idx + 1), { x: x + 0.18, y: cardY + 0.18, w: stepBadgeW, h: 0.36 }, {
|
|
2408
|
+
preset: cardPreset,
|
|
2409
|
+
adj: roundRectAdj(stepBadgeW, 0.36, Math.min(6, chromeCfg.cardRadiusPx)),
|
|
2410
|
+
fill: tk.accentPrimary,
|
|
2411
|
+
anchor: 'ctr',
|
|
2412
|
+
marginsIn: { l: 0.04, r: 0.04, t: 0.02, b: 0.02 },
|
|
2413
|
+
paragraphs: [ooxmlRichParagraph(stepTag, { sizePt: 12, color: tk.inkOnAccent, bold: true, lang: langAttr, align: 'ctr', font: theme.fonts.heading })],
|
|
2414
|
+
}))
|
|
2415
|
+
}
|
|
2416
|
+
const inner = { x: x + 0.18, y: cardY + 0.66, w: cardW - 0.36, h: cardH - 0.84 }
|
|
2417
|
+
const fit = computeTextFit([it.title || '', it.text || ''], inner, 'cardBody', { maxPt: 15, minPt: 13.5 })
|
|
2418
|
+
shapes.push(ooxmlShape(nextId(), 'Step ' + (idx + 1), inner, {
|
|
2419
|
+
txBox: true,
|
|
2420
|
+
anchor: 't',
|
|
2421
|
+
marginsIn: ZERO_MARGINS,
|
|
2422
|
+
fontScale: fit.fontScale,
|
|
2423
|
+
paragraphs: [
|
|
2424
|
+
...(it.title ? [ooxmlRichParagraph(it.title, { sizePt: Math.min(17, fit.fontPt + 1.5), color: tk.inkPrimary, bold: true, lang: langAttr, font: theme.fonts.heading, spaceAfterPt: 6 })] : []),
|
|
2425
|
+
...(it.text ? [ooxmlRichParagraph(it.text, { sizePt: fit.fontPt, color: tk.inkSecondary, lang: langAttr, font: theme.fonts.body, lineHeight: 1.42 })] : []),
|
|
2426
|
+
],
|
|
2427
|
+
}))
|
|
2428
|
+
|
|
2429
|
+
if (idx < n - 1) {
|
|
2430
|
+
shapes.push(ooxmlShape(nextId(), 'Step Connector ' + (idx + 1), { x: x + cardW + arrowGap * 0.18, y: cardY + cardH / 2 - 0.12, w: arrowGap * 0.64, h: 0.24 }, { preset: 'rightArrow', fill: tk.accentPrimary }))
|
|
2431
|
+
}
|
|
2432
|
+
})
|
|
2433
|
+
}
|
|
2434
|
+
return shapes.join('')
|
|
2435
|
+
}
|
|
2436
|
+
|
|
2437
|
+
return null
|
|
2438
|
+
}
|
|
2439
|
+
|
|
2440
|
+
export function renderDiagramSlideBodyHtml(slide, ctx) {
|
|
2441
|
+
const { theme, langId, chromeStyle } = ctx
|
|
2442
|
+
const layout = slide.layout || 'bullets'
|
|
2443
|
+
const variant = slide.variant || ''
|
|
2444
|
+
const title = slide.title || ''
|
|
2445
|
+
const subtitle = slide.subtitle || ''
|
|
2446
|
+
let inner = ''
|
|
2447
|
+
|
|
2448
|
+
if (layout === 'harvey') {
|
|
2449
|
+
return renderHarveyTableHtml(slide)
|
|
2450
|
+
}
|
|
2451
|
+
if (layout === 'marimekko') {
|
|
2452
|
+
return renderMarimekkoHtml(slide, theme, langId)
|
|
2453
|
+
}
|
|
2454
|
+
if (layout === 'sankey') {
|
|
2455
|
+
return renderSankeyHtml(slide, theme, langId)
|
|
2456
|
+
}
|
|
2457
|
+
if (layout === 'value-chain') {
|
|
2458
|
+
return renderPorterValueChainHtml(slide, langId)
|
|
2459
|
+
}
|
|
2460
|
+
if (layout === 'swot' || (layout === 'matrix' && variant === 'swot')) {
|
|
2461
|
+
return renderSwotHtml(slide, langId)
|
|
2462
|
+
}
|
|
2463
|
+
|
|
2464
|
+
if (layout === 'gantt') {
|
|
2465
|
+
const defaultCols = variant === 'months'
|
|
2466
|
+
? ['M1', 'M2', 'M3', 'M4', 'M5', 'M6']
|
|
2467
|
+
: variant === 'weeks'
|
|
2468
|
+
? ['W1', 'W2', 'W3', 'W4', 'W5', 'W6']
|
|
2469
|
+
: ['Q1', 'Q2', 'Q3', 'Q4']
|
|
2470
|
+
const cols = Array.isArray(slide.columns) && slide.columns.length > 0 && slide.columns.every((c) => typeof c === 'string')
|
|
2471
|
+
? slide.columns.slice(0, 8)
|
|
2472
|
+
: defaultCols
|
|
2473
|
+
const colCount = Math.max(2, cols.length)
|
|
2474
|
+
const items = resolveEffectiveItems(slide).slice(0, 7)
|
|
2475
|
+
const cornerLabel = variant === 'swimlane'
|
|
2476
|
+
? (langId === 'en' ? 'WORKSTREAM / TASK' : '泳道 / 任务项')
|
|
2477
|
+
: (langId === 'en' ? 'INITIATIVE / MILESTONE' : '任务里程碑')
|
|
2478
|
+
inner =
|
|
2479
|
+
'' +
|
|
2480
|
+
'<div class="gantt-board" style="--gantt-cols:' + colCount + '">' +
|
|
2481
|
+
'<div class="gantt-head"><div class="gantt-corner">' + escapeHtml(cornerLabel) + '</div>' +
|
|
2482
|
+
'<div class="gantt-col-heads">' + cols.map((c) => '<div class="gantt-col-head">' + escapeHtml(c) + '</div>').join('') + '</div></div>' +
|
|
2483
|
+
'<div class="gantt-rows">' +
|
|
2484
|
+
items.map((it, idx) => {
|
|
2485
|
+
const startSlot = it.start !== undefined ? Math.max(0, Math.min(colCount - 0.25, it.start)) : Math.min(colCount - 1, idx % colCount)
|
|
2486
|
+
const isPureMilestone = it.span === 0 || (Boolean(it.milestone) && it.span === undefined)
|
|
2487
|
+
const hasEndMilestone = !isPureMilestone && Boolean(it.milestone)
|
|
2488
|
+
const spanSlot = isPureMilestone ? 0 : Math.max(0.35, Math.min(colCount - startSlot, it.span !== undefined ? it.span : 1))
|
|
2489
|
+
const leftPct = ((startSlot / colCount) * 100).toFixed(2)
|
|
2490
|
+
const widthPct = ((spanSlot / colCount) * 100).toFixed(2)
|
|
2491
|
+
const mPct = (((startSlot + 0.5) / colCount) * 100).toFixed(2)
|
|
2492
|
+
const label = it.value || it.delta || ''
|
|
2493
|
+
return (
|
|
2494
|
+
'<div class="gantt-row" data-item-index="' + idx + '">' +
|
|
2495
|
+
'<div class="gantt-label surface-card">' +
|
|
2496
|
+
(it.tag ? '<span class="gantt-tag">' + escapeHtml(it.tag) + '</span>' : '') +
|
|
2497
|
+
'<span class="gantt-task" data-item-field="title">' + renderInlineHtml(it.title || it.text || '') + '</span>' +
|
|
2498
|
+
'</div>' +
|
|
2499
|
+
'<div class="gantt-track">' +
|
|
2500
|
+
(isPureMilestone
|
|
2501
|
+
? '<span class="gantt-milestone" style="left:' + mPct + '%"></span>' +
|
|
2502
|
+
(label || it.text ? '<span class="gantt-m-label" style="left:' + mPct + '%">' + escapeHtml(label || it.text) + '</span>' : '')
|
|
2503
|
+
: '<div class="gantt-bar tone-' + escapeHtml(it.status || 'accent') + '" style="left:' + leftPct + '%;width:' + widthPct + '%">' +
|
|
2504
|
+
(label ? '<span>' + escapeHtml(label) + '</span>' : '') +
|
|
2505
|
+
(hasEndMilestone ? '<span class="gantt-bar-milestone" aria-hidden="true"></span>' : '') +
|
|
2506
|
+
'</div>') +
|
|
2507
|
+
'</div></div>'
|
|
2508
|
+
)
|
|
2509
|
+
}).join('') +
|
|
2510
|
+
'</div></div>'
|
|
2511
|
+
} else if (layout === 'architecture') {
|
|
2512
|
+
const allItems = resolveEffectiveItems(slide).slice(0, 6)
|
|
2513
|
+
const isSidecarItem = (it) =>
|
|
2514
|
+
it.status === 'accent' || /^(?:sidecar|governance|security|observability|安全|治理|可观测|监控|合规|运维)$/i.test(String(it.tag || '').trim())
|
|
2515
|
+
const candidateSidecars = allItems.filter(isSidecarItem)
|
|
2516
|
+
const candidateTiers = allItems.filter((it) => !isSidecarItem(it))
|
|
2517
|
+
const hasSidecar = candidateSidecars.length >= 1 && candidateTiers.length >= 2
|
|
2518
|
+
const sidecarItems = hasSidecar ? candidateSidecars : []
|
|
2519
|
+
const tierItems = hasSidecar ? candidateTiers : allItems
|
|
2520
|
+
const arrowGlyph = variant === 'platform' ? '↕' : '↓'
|
|
2521
|
+
|
|
2522
|
+
inner =
|
|
2523
|
+
'' +
|
|
2524
|
+
'<div class="arch-board' + (hasSidecar ? ' has-sidecar' : '') + '">' +
|
|
2525
|
+
'<div class="arch-tiers">' +
|
|
2526
|
+
tierItems.map((it, idx) => {
|
|
2527
|
+
const mods = it.bullets?.length ? it.bullets : (it.text ? [it.text] : [])
|
|
2528
|
+
return (
|
|
2529
|
+
'<div class="surface-card arch-tier' + (idx === 0 ? ' is-focal' : '') + '" data-item-index="' + allItems.indexOf(it) + '">' +
|
|
2530
|
+
'<div class="arch-tier-head">' +
|
|
2531
|
+
(it.tag ? '<span class="kicker arch-tag">' + escapeHtml(it.tag) + '</span>' : '') +
|
|
2532
|
+
'<div class="card-title" data-item-field="title">' + renderInlineHtml(it.title || '') + '</div>' +
|
|
2533
|
+
'</div>' +
|
|
2534
|
+
'<div class="arch-modules cols-' + Math.max(1, mods.length) + '">' +
|
|
2535
|
+
mods.map((m) => '<div class="arch-module">' + renderInlineHtml(m, { autoLeadBold: true }) + '</div>').join('') +
|
|
2536
|
+
'</div></div>' +
|
|
2537
|
+
(idx < tierItems.length - 1 ? '<div class="arch-flow-arrows" aria-hidden="true"><span>' + arrowGlyph + '</span><span>' + arrowGlyph + '</span></div>' : '')
|
|
2538
|
+
)
|
|
2539
|
+
}).join('') +
|
|
2540
|
+
'</div>' +
|
|
2541
|
+
(hasSidecar
|
|
2542
|
+
? '<aside class="arch-sidecar-col">' +
|
|
2543
|
+
sidecarItems.map((sc) =>
|
|
2544
|
+
'<div class="surface-card arch-sidecar is-focal" data-item-index="' + allItems.indexOf(sc) + '">' +
|
|
2545
|
+
(sc.tag ? '<span class="kicker">' + escapeHtml(sc.tag) + '</span>' : '') +
|
|
2546
|
+
'<div class="card-title" data-item-field="title">' + renderInlineHtml(sc.title || '') + '</div>' +
|
|
2547
|
+
(sc.text ? '<div class="card-body" data-item-field="text">' + renderInlineHtml(sc.text) + '</div>' : '') +
|
|
2548
|
+
(sc.bullets?.length ? '<ul class="card-bullets">' + sc.bullets.map((b) => '<li>' + renderInlineHtml(b, { autoLeadBold: true }) + '</li>').join('') + '</ul>' : '') +
|
|
2549
|
+
'</div>',
|
|
2550
|
+
).join('') +
|
|
2551
|
+
'</aside>'
|
|
2552
|
+
: '') +
|
|
2553
|
+
'</div>'
|
|
2554
|
+
} else if (layout === 'tam') {
|
|
2555
|
+
const rawItems = resolveEffectiveItems(slide).slice(0, 3)
|
|
2556
|
+
const defaults = ['TAM', 'SAM', 'SOM']
|
|
2557
|
+
const items = Array.from({ length: Math.max(1, rawItems.length) }, (_, idx) => ({
|
|
2558
|
+
...rawItems[idx],
|
|
2559
|
+
tag: rawItems[idx]?.tag || defaults[idx] || ('T' + (idx + 1)),
|
|
2560
|
+
}))
|
|
2561
|
+
inner =
|
|
2562
|
+
'' +
|
|
2563
|
+
'<div class="tam-board">' +
|
|
2564
|
+
'<div class="tam-circles">' +
|
|
2565
|
+
items.map((it, idx) => {
|
|
2566
|
+
const shortTag = String(it.tag || defaults[idx] || ('T' + (idx + 1))).split(/\s*[·::\-—|]\s*/)[0].trim() || (defaults[idx] || ('T' + (idx + 1)))
|
|
2567
|
+
return (
|
|
2568
|
+
'<div class="tam-circle tam-ring-' + idx + (idx === items.length - 1 ? ' is-inner' : '') + '">' +
|
|
2569
|
+
'<span class="tam-ring-label">' + escapeHtml(shortTag + (it.value ? ' · ' + it.value + (it.unit ? ' ' + it.unit : '') : '')) + '</span>' +
|
|
2570
|
+
'</div>'
|
|
2571
|
+
)
|
|
2572
|
+
}).join('') +
|
|
2573
|
+
'</div>' +
|
|
2574
|
+
'<div class="tam-cards">' +
|
|
2575
|
+
items.map((it, idx) => {
|
|
2576
|
+
const cardBodyText = [it.text, ...(it.bullets ?? [])].filter(Boolean).join(';')
|
|
2577
|
+
return (
|
|
2578
|
+
'<div class="surface-card tam-card' + (idx === items.length - 1 ? ' is-focal' : '') + '" data-item-index="' + idx + '">' +
|
|
2579
|
+
'<div class="tam-card-meta">' +
|
|
2580
|
+
'<span class="item-badge">' + escapeHtml(it.tag) + '</span>' +
|
|
2581
|
+
(it.value ? '<strong class="tam-card-val" data-item-field="value">' + escapeHtml(it.value + (it.unit ? ' ' + it.unit : '')) + '</strong>' : '') +
|
|
2582
|
+
'</div>' +
|
|
2583
|
+
'<div class="tam-card-copy">' +
|
|
2584
|
+
(it.title ? '<div class="card-title" data-item-field="title">' + renderInlineHtml(it.title) + '</div>' : '') +
|
|
2585
|
+
(cardBodyText ? '<div class="card-body" data-item-field="text">' + renderInlineHtml(cardBodyText) + '</div>' : '') +
|
|
2586
|
+
'</div></div>'
|
|
2587
|
+
)
|
|
2588
|
+
}).join('') +
|
|
2589
|
+
'</div></div>'
|
|
2590
|
+
} else if (layout === 'org') {
|
|
2591
|
+
const items = resolveEffectiveItems(slide)
|
|
2592
|
+
if (variant === 'team') {
|
|
2593
|
+
const members = items.slice(0, 4)
|
|
2594
|
+
inner =
|
|
2595
|
+
'' +
|
|
2596
|
+
'<div class="layout-grid team-grid cols-' + Math.max(1, members.length) + '">' +
|
|
2597
|
+
members.map((it, idx) =>
|
|
2598
|
+
'<article class="surface-card team-card' + (idx === 0 ? ' is-focal' : '') + '" data-item-index="' + idx + '">' +
|
|
2599
|
+
'<div class="team-avatar">' + escapeHtml(monogramLetters(it.title || it.tag || 'T')) + '</div>' +
|
|
2600
|
+
((it.role || it.tag) ? '<span class="team-role">' + escapeHtml(it.role || it.tag) + '</span>' : '') +
|
|
2601
|
+
(it.title ? '<h3 class="card-title" data-item-field="title">' + renderInlineHtml(it.title) + '</h3>' : '') +
|
|
2602
|
+
(it.text ? '<div class="card-body" data-item-field="text">' + renderInlineHtml(it.text) + '</div>' : '') +
|
|
2603
|
+
(it.bullets?.length ? '<ul class="card-bullets">' + it.bullets.map((b) => '<li>' + renderInlineHtml(b, { autoLeadBold: true }) + '</li>').join('') + '</ul>' : '') +
|
|
2604
|
+
'</article>',
|
|
2605
|
+
).join('') +
|
|
2606
|
+
'</div>'
|
|
2607
|
+
} else {
|
|
2608
|
+
const rootItem = items[0] ?? { tag: 'CEO', title: title || '组织架构' }
|
|
2609
|
+
const rawChildren = items.length > 1
|
|
2610
|
+
? items.slice(1, 6)
|
|
2611
|
+
: (rootItem.bullets ?? []).slice(0, 5).map((b, i) => ({ tag: 'DEPT ' + (i + 1), title: b }))
|
|
2612
|
+
const children = rawChildren.length > 0 ? rawChildren : [{ title: '核心业务单元' }]
|
|
2613
|
+
inner =
|
|
2614
|
+
'' +
|
|
2615
|
+
'<div class="org-tree">' +
|
|
2616
|
+
'<div class="org-root-wrap">' +
|
|
2617
|
+
'<div class="surface-card org-root is-focal" data-item-index="0">' +
|
|
2618
|
+
((rootItem.role || rootItem.tag) ? '<span class="kicker">' + escapeHtml(rootItem.role || rootItem.tag) + '</span>' : '') +
|
|
2619
|
+
'<div class="card-title" data-item-field="title">' + renderInlineHtml(rootItem.title || '') + '</div>' +
|
|
2620
|
+
(rootItem.text ? '<div class="card-body" data-item-field="text">' + renderInlineHtml(rootItem.text) + '</div>' : '') +
|
|
2621
|
+
'</div></div>' +
|
|
2622
|
+
'<div class="org-trunk" aria-hidden="true"></div>' +
|
|
2623
|
+
'<div class="org-children cols-' + Math.max(1, children.length) + '">' +
|
|
2624
|
+
children.map((ch, idx) =>
|
|
2625
|
+
'<div class="org-branch">' +
|
|
2626
|
+
'<div class="surface-card org-child" data-item-index="' + (items.length > 1 ? idx + 1 : idx) + '">' +
|
|
2627
|
+
((ch.role || ch.tag) ? '<span class="item-badge">' + escapeHtml(ch.role || ch.tag) + '</span>' : '') +
|
|
2628
|
+
'<div class="card-title" data-item-field="title">' + renderInlineHtml(ch.title || '') + '</div>' +
|
|
2629
|
+
(ch.text ? '<div class="card-body" data-item-field="text">' + renderInlineHtml(ch.text) + '</div>' : '') +
|
|
2630
|
+
(ch.bullets?.length ? '<ul class="card-bullets">' + ch.bullets.map((b) => '<li>' + renderInlineHtml(b, { autoLeadBold: true }) + '</li>').join('') + '</ul>' : '') +
|
|
2631
|
+
'</div></div>',
|
|
2632
|
+
).join('') +
|
|
2633
|
+
'</div></div>'
|
|
2634
|
+
}
|
|
2635
|
+
}
|
|
2636
|
+
if (inner !== '') return inner
|
|
2637
|
+
|
|
2638
|
+
if (layout === 'process') {
|
|
2639
|
+
const items = resolveEffectiveItems(slide).slice(0, 6)
|
|
2640
|
+
const badgeClass = chromeStyle === 'editorial-folio' ? 'item-badge is-editorial-num' : 'item-badge'
|
|
2641
|
+
if (variant === 'flywheel') {
|
|
2642
|
+
const nodes = items.slice(0, 4)
|
|
2643
|
+
const rawHub = (slide.text && slide.text.trim().length <= 18 ? slide.text.trim() : '')
|
|
2644
|
+
|| (slide.subtitle && slide.subtitle.trim().length <= 18 ? slide.subtitle.trim() : '')
|
|
2645
|
+
const hubText = rawHub || (langId === 'en' ? 'Growth Flywheel' : '增长飞轮')
|
|
2646
|
+
inner =
|
|
2647
|
+
'' +
|
|
2648
|
+
'<div class="flywheel-stage">' +
|
|
2649
|
+
'<div class="flywheel-hub">' + escapeHtml(hubText) + '</div>' +
|
|
2650
|
+
nodes.map((it, idx) => {
|
|
2651
|
+
const cardBodyText = [it.text, ...(it.bullets ?? [])].filter(Boolean).join(';')
|
|
2652
|
+
return (
|
|
2653
|
+
'<div class="surface-card flywheel-node node-' + idx + (idx === 0 ? ' is-focal' : '') + '" data-item-index="' + idx + '">' +
|
|
2654
|
+
'<div class="flywheel-node-top">' +
|
|
2655
|
+
'<span class="' + badgeClass + '">' + escapeHtml(it.tag || String(idx + 1).padStart(2, '0')) + '</span>' +
|
|
2656
|
+
((it.conversion || it.delta) ? '<span class="funnel-conversion-badge">' + escapeHtml(it.conversion || it.delta) + '</span>' : '') +
|
|
2657
|
+
'</div>' +
|
|
2658
|
+
(it.title ? '<div class="card-title" data-item-field="title">' + renderInlineHtml(it.title) + '</div>' : '') +
|
|
2659
|
+
(cardBodyText ? '<div class="card-body" data-item-field="text">' + renderInlineHtml(cardBodyText) + '</div>' : '') +
|
|
2660
|
+
'</div>'
|
|
2661
|
+
)
|
|
2662
|
+
}).join('') +
|
|
2663
|
+
'</div>'
|
|
2664
|
+
} else if (variant === 'chevron') {
|
|
2665
|
+
inner =
|
|
2666
|
+
'' +
|
|
2667
|
+
'<ol class="layout-grid chevron-board cols-' + Math.max(1, items.length) + '">' +
|
|
2668
|
+
items.map((it, idx) => {
|
|
2669
|
+
const isFirst = idx === 0
|
|
2670
|
+
const isLast = idx === items.length - 1 && items.length >= 3
|
|
2671
|
+
const conv = it.conversion || it.delta || (it.value ? it.value + (it.unit ? ' ' + it.unit : '') : '')
|
|
2672
|
+
const bodyLines = [
|
|
2673
|
+
...(it.text ? [it.text] : []),
|
|
2674
|
+
...(Array.isArray(it.bullets) ? it.bullets : []),
|
|
2675
|
+
]
|
|
2676
|
+
return (
|
|
2677
|
+
'<li class="chevron-col" data-item-index="' + idx + '">' +
|
|
2678
|
+
'<div class="chevron-arrow' + (isFirst ? ' is-first' : isLast ? ' is-last' : '') + '">' +
|
|
2679
|
+
'<span class="chevron-tag">' + escapeHtml(it.tag || String(idx + 1).padStart(2, '0')) + '</span>' +
|
|
2680
|
+
(it.title ? '<span class="chevron-title" data-item-field="title">' + renderInlineHtml(it.title) + '</span>' : '') +
|
|
2681
|
+
'</div>' +
|
|
2682
|
+
'<div class="surface-card chevron-detail' + (isFirst ? ' is-focal' : '') + '">' +
|
|
2683
|
+
(conv ? '<span class="funnel-conversion-badge chevron-metric">' + escapeHtml(conv) + '</span>' : '') +
|
|
2684
|
+
(bodyLines.length ? '<div class="card-body" data-item-field="text">' + bodyLines.map((ln) => renderInlineHtml(ln)).join('<br>') + '</div>' : '') +
|
|
2685
|
+
'</div>' +
|
|
2686
|
+
'</li>'
|
|
2687
|
+
)
|
|
2688
|
+
}).join('') +
|
|
2689
|
+
'</ol>'
|
|
2690
|
+
} else {
|
|
2691
|
+
const modeClass = variant === 'timeline' ? 'is-timeline' : variant === 'layers' ? 'is-layers' : variant === 'funnel' ? 'is-funnel' : 'is-steps'
|
|
2692
|
+
inner =
|
|
2693
|
+
'' +
|
|
2694
|
+
'<ol class="layout-grid process-grid ' + modeClass + ' cols-' + Math.max(1, items.length) + '">' +
|
|
2695
|
+
items.map((it, idx) => {
|
|
2696
|
+
const conv = variant === 'funnel' ? (it.conversion || it.delta || '') : ''
|
|
2697
|
+
const valSuffix = variant === 'funnel' && it.value ? ' · ' + it.value + (it.unit ? ' ' + it.unit : '') : ''
|
|
2698
|
+
return (
|
|
2699
|
+
'<li class="surface-card process-step" style="--step:' + idx + ';--total:' + items.length + '" data-item-index="' + idx + '">' +
|
|
2700
|
+
'<span class="' + badgeClass + '">' + escapeHtml(it.tag || String(idx + 1).padStart(2, '0')) + '</span>' +
|
|
2701
|
+
'<div class="process-copy">' +
|
|
2702
|
+
(it.title ? '<div class="card-title" data-item-field="title">' + renderInlineHtml(it.title) + (valSuffix ? '<span class="funnel-val">' + escapeHtml(valSuffix) + '</span>' : '') + '</div>' : '') +
|
|
2703
|
+
(it.text ? '<div class="card-body" data-item-field="text">' + renderInlineHtml(it.text) + '</div>' : '') +
|
|
2704
|
+
'</div>' +
|
|
2705
|
+
(conv ? '<span class="funnel-conversion-badge">↓ ' + escapeHtml(conv) + '</span>' : '') +
|
|
2706
|
+
'</li>'
|
|
2707
|
+
)
|
|
2708
|
+
}).join('') +
|
|
2709
|
+
'</ol>'
|
|
2710
|
+
}
|
|
2711
|
+
return inner
|
|
2712
|
+
}
|
|
2713
|
+
|
|
2714
|
+
return null
|
|
2715
|
+
}
|
|
2716
|
+
|
|
2717
|
+
export const DIAGRAMS_CSS = `
|
|
2718
|
+
.process-grid.is-layers,.process-grid.is-funnel{grid-template-columns:1fr;gap:10px}
|
|
2719
|
+
.process-grid.is-layers .process-step,.process-grid.is-funnel .process-step{flex-direction:row;align-items:center;padding:12px 20px}
|
|
2720
|
+
.process-grid.is-funnel .process-step{width:calc(100% - var(--step, 0) * 8%);margin:0 auto;justify-content:center}
|
|
2721
|
+
.funnel-conversion-badge{margin-left:auto;padding:3px 10px;border-radius:99px;background:var(--accent-soft);border:1px solid var(--accent);color:var(--accent-text);font-size:12px;font-weight:700;white-space:nowrap}
|
|
2722
|
+
.flywheel-stage{position:relative;display:grid;grid-template-columns:1fr 1fr;gap:clamp(22px,3vw,42px) clamp(120px,14vw,220px);align-items:center;padding:8px 0}
|
|
2723
|
+
.flywheel-hub{position:absolute;left:50%;top:50%;transform:translate(-50%,-50%);width:clamp(130px,13vw,190px);height:clamp(130px,13vw,190px);border-radius:50%;background:var(--accent);color:var(--ink-on-accent);border:4px solid var(--bg);display:flex;align-items:center;justify-content:center;text-align:center;padding:14px;font-family:var(--font-heading);font-weight:800;font-size:clamp(14px,1.4vw,20px);z-index:2;box-shadow:0 12px 32px rgba(0,0,0,.14)}
|
|
2724
|
+
.flywheel-node-top{display:flex;align-items:center;justify-content:space-between;gap:8px}
|
|
2725
|
+
.chevron-board{gap:12px;align-items:stretch}
|
|
2726
|
+
.chevron-col{display:flex;flex-direction:column;gap:12px;min-width:0;list-style:none}
|
|
2727
|
+
.chevron-arrow{min-height:68px;padding:12px 24px 12px 28px;background:var(--surface2);color:var(--fg);font-family:var(--font-heading);font-weight:700;font-size:clamp(13px,1.2vw,16px);display:flex;flex-direction:column;justify-content:center;align-items:center;text-align:center;gap:3px;clip-path:polygon(0 0,calc(100% - 16px) 0,100% 50%,calc(100% - 16px) 100%,0 100%,16px 50%)}
|
|
2728
|
+
.chevron-arrow.is-first{padding-left:16px;background:var(--accent);color:var(--ink-on-accent);clip-path:polygon(0 0,calc(100% - 16px) 0,100% 50%,calc(100% - 16px) 100%,0 100%)}
|
|
2729
|
+
.chevron-arrow.is-last{background:var(--accent2);color:#FFF}
|
|
2730
|
+
.chevron-tag{font-size:11px;opacity:.86;letter-spacing:.06em}
|
|
2731
|
+
.chevron-detail{flex:1;padding:14px 16px;gap:8px}
|
|
2732
|
+
.chevron-metric{margin-left:0;align-self:flex-start}
|
|
2733
|
+
/* 5 Pro Diagrams CSS */
|
|
2734
|
+
.gantt-board{display:flex;flex-direction:column;gap:8px;width:100%}
|
|
2735
|
+
.gantt-head,.gantt-row{display:grid;grid-template-columns:minmax(220px,31%) 1fr;gap:12px;align-items:center}
|
|
2736
|
+
.gantt-corner{background:var(--surface2);border:1px solid var(--hairline);border-radius:calc(var(--radius) * .6);padding:8px 12px;font-size:12px;font-weight:700;color:var(--muted)}
|
|
2737
|
+
.gantt-col-heads{display:grid;grid-template-columns:repeat(var(--gantt-cols,4),minmax(0,1fr));border:1px solid var(--hairline);overflow:hidden}
|
|
2738
|
+
.gantt-col-head{background:var(--surface2);padding:8px 6px;text-align:center;font-weight:700;font-size:13px;border-right:1px solid var(--hairline)}
|
|
2739
|
+
.gantt-col-head:last-child{border-right:0}
|
|
2740
|
+
.gantt-rows{display:flex;flex-direction:column;gap:8px}
|
|
2741
|
+
.gantt-label{flex-direction:row;align-items:center;gap:10px;padding:8px 12px}
|
|
2742
|
+
.gantt-tag{background:var(--accent-soft);color:var(--accent-text);font-size:11px;font-weight:700;padding:2px 8px;border-radius:4px;white-space:nowrap}
|
|
2743
|
+
.gantt-task{font-weight:600;font-size:14px}
|
|
2744
|
+
.gantt-track{position:relative;height:38px;background:var(--surface1);border:1px solid var(--hairline);overflow:visible;background-image:repeating-linear-gradient(to right,transparent,transparent calc(100% / var(--gantt-cols,4) - 1px),var(--hairline) calc(100% / var(--gantt-cols,4) - 1px),var(--hairline) calc(100% / var(--gantt-cols,4)))}
|
|
2745
|
+
.gantt-bar{position:absolute;top:6px;bottom:6px;border-radius:calc(var(--radius) * .6);background:var(--accent);color:#FFF;font-size:12px;font-weight:700;display:flex;align-items:center;justify-content:center;padding:0 8px}
|
|
2746
|
+
.gantt-bar.tone-positive{background:var(--positive)}.gantt-bar.tone-warning{background:var(--warning)}.gantt-bar.tone-negative{background:var(--negative)}
|
|
2747
|
+
.gantt-milestone{position:absolute;top:50%;width:16px;height:16px;background:var(--accent);border:2px solid var(--bg);transform:translate(-50%,-50%) rotate(45deg)}
|
|
2748
|
+
.gantt-bar-milestone{position:absolute;right:-7px;top:50%;width:14px;height:14px;background:var(--accent);border:2px solid var(--bg);transform:translateY(-50%) rotate(45deg);z-index:2}
|
|
2749
|
+
.gantt-m-label{position:absolute;top:50%;transform:translate(14px,-50%);font-size:12px;font-weight:700;color:var(--accent-text);white-space:nowrap}
|
|
2750
|
+
.arch-board{display:grid;grid-template-columns:1fr;gap:16px;width:100%}
|
|
2751
|
+
.arch-board.has-sidecar{grid-template-columns:1fr minmax(210px,22%)}
|
|
2752
|
+
.arch-tiers{display:flex;flex-direction:column;gap:6px}
|
|
2753
|
+
.arch-tier{display:grid;grid-template-columns:minmax(160px,24%) 1fr;align-items:center;gap:14px;padding:12px 16px}
|
|
2754
|
+
.arch-tier-head .kicker{margin-bottom:2px;font-size:11px}
|
|
2755
|
+
.arch-modules{display:grid;gap:10px}
|
|
2756
|
+
.arch-module{background:var(--bg);border:1px solid var(--hairline);border-radius:calc(var(--radius) * .6);padding:8px 12px;text-align:center;font-size:14px}
|
|
2757
|
+
.arch-flow-arrows{display:flex;justify-content:space-around;color:var(--accent-text);font-weight:800;font-size:18px;line-height:1}
|
|
2758
|
+
.arch-sidecar-col{display:flex;flex-direction:column;gap:12px}
|
|
2759
|
+
.arch-sidecar{height:100%;justify-content:center}
|
|
2760
|
+
.harvey-table th.is-ours{background:var(--accent);color:var(--ink-on-accent);border-color:var(--accent)}
|
|
2761
|
+
.harvey-table td.is-ours{background:var(--accent-soft);font-weight:700}
|
|
2762
|
+
.harvey-cell{text-align:center}
|
|
2763
|
+
.harvey-ball{display:inline-block;width:22px;height:22px;border-radius:50%;border:2px solid var(--fg);vertical-align:middle}
|
|
2764
|
+
.harvey-table td.is-ours .harvey-ball{border-color:var(--accent)}
|
|
2765
|
+
.harvey-100{background:var(--fg)}.harvey-table td.is-ours .harvey-100{background:var(--accent)}
|
|
2766
|
+
.harvey-75{background:conic-gradient(var(--fg) 0 270deg,transparent 270deg 360deg)}.harvey-table td.is-ours .harvey-75{background:conic-gradient(var(--accent) 0 270deg,transparent 270deg 360deg)}
|
|
2767
|
+
.harvey-50{background:conic-gradient(var(--fg) 0 180deg,transparent 180deg 360deg)}.harvey-table td.is-ours .harvey-50{background:conic-gradient(var(--accent) 0 180deg,transparent 180deg 360deg)}
|
|
2768
|
+
.harvey-25{background:conic-gradient(var(--fg) 0 90deg,transparent 90deg 360deg)}.harvey-table td.is-ours .harvey-25{background:conic-gradient(var(--accent) 0 90deg,transparent 90deg 360deg)}
|
|
2769
|
+
.harvey-0{background:transparent;border-color:var(--muted)}
|
|
2770
|
+
.harvey-check{display:inline-flex;align-items:center;justify-content:center;width:24px;height:24px;border-radius:50%;font-weight:800;font-size:13px}
|
|
2771
|
+
.harvey-check.is-yes{background:var(--positive);color:#FFF}
|
|
2772
|
+
.harvey-check.is-no{background:var(--surface2);color:var(--muted)}
|
|
2773
|
+
.tam-board{display:grid;grid-template-columns:minmax(280px,43%) 1fr;gap:28px;align-items:center;width:100%}
|
|
2774
|
+
.tam-circles{position:relative;width:100%;aspect-ratio:1/1;max-height:380px;margin:0 auto}
|
|
2775
|
+
.tam-circle{position:absolute;left:50%;bottom:0;transform:translateX(-50%);border-radius:50%;border:2px solid var(--accent);display:flex;justify-content:center;padding-top:14px;background:var(--surface1)}
|
|
2776
|
+
.tam-ring-0{width:94%;height:94%}.tam-ring-1{width:64%;height:64%;background:var(--accent-soft)}.tam-ring-2{width:37%;height:37%;background:var(--accent);color:var(--ink-on-accent);align-items:center;padding-top:0}
|
|
2777
|
+
.tam-ring-label{font-family:var(--font-heading);font-weight:800;font-size:clamp(12px,1.15vw,15px);color:var(--accent-text);max-width:74%;text-align:center}
|
|
2778
|
+
.tam-ring-2 .tam-ring-label{color:var(--ink-on-accent)}
|
|
2779
|
+
.tam-cards{display:flex;flex-direction:column;gap:14px}
|
|
2780
|
+
.tam-card{flex-direction:row;align-items:center;gap:16px;padding:14px 18px}
|
|
2781
|
+
.tam-card-meta{display:flex;flex-direction:column;gap:4px;min-width:136px}
|
|
2782
|
+
.tam-card-val{font-family:var(--font-heading);font-size:clamp(18px,1.8vw,26px);color:var(--accent-text)}
|
|
2783
|
+
.funnel-val{color:var(--accent-text);font-weight:700}
|
|
2784
|
+
.process-step:first-child .funnel-val{color:inherit}
|
|
2785
|
+
.org-tree{display:flex;flex-direction:column;align-items:center;width:100%}
|
|
2786
|
+
.org-root-wrap{display:flex;justify-content:center;width:100%}
|
|
2787
|
+
.org-root{min-width:min(380px,60%);text-align:center;align-items:center}
|
|
2788
|
+
.org-trunk{width:2px;height:24px;background:var(--accent)}
|
|
2789
|
+
.org-children{display:grid;gap:16px;width:100%;border-top:2px solid var(--accent);padding-top:20px}
|
|
2790
|
+
.org-branch{position:relative}
|
|
2791
|
+
.org-branch::before{content:"";position:absolute;top:-20px;left:50%;width:2px;height:20px;background:var(--accent);transform:translateX(-50%)}
|
|
2792
|
+
.org-child{height:100%}
|
|
2793
|
+
.team-card{align-items:center;text-align:center}
|
|
2794
|
+
.team-avatar{width:62px;height:62px;border-radius:50%;background:var(--accent);color:var(--ink-on-accent);display:flex;align-items:center;justify-content:center;font-family:var(--font-heading);font-weight:800;font-size:20px}
|
|
2795
|
+
.team-role{display:inline-block;padding:3px 12px;border-radius:99px;background:var(--accent-soft);color:var(--accent-text);font-size:12px;font-weight:700}
|
|
2796
|
+
.mekko-board{display:grid;grid-template-columns:1fr minmax(190px,21%);gap:20px;width:100%;min-height:360px;align-items:stretch}
|
|
2797
|
+
.mekko-main{display:flex;flex-direction:column;gap:6px;min-width:0}
|
|
2798
|
+
.mekko-headers{display:flex;width:100%;align-items:flex-end}
|
|
2799
|
+
.mekko-col-head{display:flex;flex-direction:column;align-items:center;text-align:center;padding:0 4px;min-width:0;overflow:hidden}
|
|
2800
|
+
.mekko-col-title{font-family:var(--font-heading);font-size:clamp(11px,1.05vw,14px);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:100%}
|
|
2801
|
+
.mekko-col-size{font-size:11px;font-weight:700;color:var(--accent-text);font-variant-numeric:tabular-nums}
|
|
2802
|
+
.mekko-columns{display:flex;width:100%;flex:1;min-height:290px;border:1px solid var(--hairline)}
|
|
2803
|
+
.mekko-col{display:flex;flex-direction:column;min-width:0}
|
|
2804
|
+
.mekko-cell{display:flex;flex-direction:column;align-items:center;justify-content:center;text-align:center;border:1.5px solid var(--bg);padding:2px 4px;overflow:hidden;font-variant-numeric:tabular-nums}
|
|
2805
|
+
.mekko-seg-name{font-size:12px;font-weight:600;line-height:1.15;max-width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
2806
|
+
.mekko-seg-pct{font-family:var(--font-heading);font-size:13px;font-weight:800}
|
|
2807
|
+
.mekko-axis{display:flex;justify-content:space-between;border-top:1.5px solid var(--muted);padding-top:4px;font-size:11px;color:var(--muted);font-variant-numeric:tabular-nums}
|
|
2808
|
+
.mekko-legend{justify-content:flex-start;gap:14px}
|
|
2809
|
+
.mekko-total{display:flex;flex-direction:column;gap:4px;padding-bottom:12px;border-bottom:1px solid var(--hairline)}
|
|
2810
|
+
.mekko-total strong{font-family:var(--font-heading);font-size:clamp(22px,2.3vw,32px);color:var(--accent-text);font-variant-numeric:tabular-nums}
|
|
2811
|
+
.mekko-legend-list{list-style:none;margin:0;padding:0;display:flex;flex-direction:column;gap:10px}
|
|
2812
|
+
.mekko-legend-list li{display:flex;align-items:center;gap:8px;font-size:13px}
|
|
2813
|
+
.mekko-legend-list li.is-ours{color:var(--accent-text);font-weight:700}
|
|
2814
|
+
.mekko-swatch{width:14px;height:14px;border-radius:3px;flex-shrink:0;border:1px solid var(--hairline)}
|
|
2815
|
+
.mekko-leg-name{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
2816
|
+
.mekko-leg-pct{font-variant-numeric:tabular-nums}
|
|
2817
|
+
.sankey-board{width:100%;display:flex;align-items:center;justify-content:center}
|
|
2818
|
+
.sankey-svg{width:100%;height:auto;max-height:430px;overflow:visible;font-family:var(--font-body)}
|
|
2819
|
+
.porter-board{display:grid;grid-template-columns:1fr minmax(120px,13.5%);gap:12px;width:100%;align-items:stretch}
|
|
2820
|
+
.porter-main{display:flex;flex-direction:column;gap:14px;min-width:0}
|
|
2821
|
+
.porter-support-zone{display:grid;grid-template-columns:84px 1fr;gap:10px;align-items:stretch}
|
|
2822
|
+
.porter-support-rail{background:var(--accent-soft);border:1px solid var(--accent);border-radius:calc(var(--radius) * .7);color:var(--accent-text);font-family:var(--font-heading);font-weight:800;font-size:13px;display:flex;align-items:center;justify-content:center;text-align:center;padding:8px}
|
|
2823
|
+
.porter-support-beams{display:flex;flex-direction:column;gap:8px}
|
|
2824
|
+
.porter-beam{flex-direction:row;align-items:center;gap:12px;padding:10px 16px;border-left:4px solid var(--accent2)}
|
|
2825
|
+
.porter-beam strong{font-family:var(--font-heading);font-size:14px;white-space:nowrap}
|
|
2826
|
+
.porter-beam span{font-size:13px;color:var(--ink-secondary);overflow:hidden;text-overflow:ellipsis}
|
|
2827
|
+
.porter-margin-wedge{background:var(--accent);color:var(--ink-on-accent);font-family:var(--font-heading);font-weight:800;font-size:clamp(15px,1.5vw,21px);display:flex;align-items:center;justify-content:center;text-align:center;padding:16px 24px 16px 12px;clip-path:polygon(0 0,74% 0,100% 50%,74% 100%,0 100%,14% 50%)}
|
|
2828
|
+
.swot-board{display:flex;flex-direction:column;gap:14px;width:100%}
|
|
2829
|
+
.swot-cross{position:relative;display:grid;grid-template-columns:1fr 1fr;gap:16px;width:100%}
|
|
2830
|
+
.swot-quad{padding:0;overflow:hidden;gap:0}
|
|
2831
|
+
.swot-quad-head{padding:9px 18px;font-family:var(--font-heading);font-weight:800;font-size:14px;color:#FFF;background:var(--accent)}
|
|
2832
|
+
.swot-quad.tone-positive .swot-quad-head{background:var(--positive)}
|
|
2833
|
+
.swot-quad.tone-warning .swot-quad-head{background:var(--warning);color:#0F172A}
|
|
2834
|
+
.swot-quad.tone-negative .swot-quad-head{background:var(--negative)}
|
|
2835
|
+
.swot-quad.swot-o .swot-quad-head{padding-right:108px}
|
|
2836
|
+
.swot-quad.swot-t .swot-quad-head{padding-left:108px}
|
|
2837
|
+
.swot-quad-body{padding:14px 18px;display:flex;flex-direction:column;gap:6px}
|
|
2838
|
+
.swot-anchor{position:absolute;left:50%;top:50%;transform:translate(-50%,-50%);z-index:3;background:var(--accent);color:var(--ink-on-accent);border:4px solid var(--bg);border-radius:999px;padding:10px 24px;min-width:168px;font-family:var(--font-heading);font-weight:800;font-size:14px;line-height:1.25;text-align:center;box-shadow:0 10px 26px rgba(0,0,0,.16)}
|
|
2839
|
+
.swot-tows-strip{gap:12px}
|
|
2840
|
+
.swot-tows-pill{flex-direction:row;align-items:center;gap:10px;padding:10px 14px}
|
|
2841
|
+
.swot-tows-text{font-size:13px;color:var(--fg);font-weight:600}
|
|
2842
|
+
`
|