dsh-ppt 0.21.1 → 0.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -0
- package/README.en.md +37 -23
- package/README.md +37 -22
- package/docs/COACHING.md +14 -13
- package/docs/DATA.md +8 -8
- package/docs/REFERENCE.en.md +17 -19
- package/docs/REFERENCE.zh.md +16 -18
- package/docs/USAGE.en.md +107 -60
- package/docs/USAGE.md +115 -84
- package/docs/VALIDATION.md +2 -0
- package/docs/VISUAL.md +27 -20
- package/docs/WORKBENCH.md +17 -6
- package/docs/assets/intro/screen-en.webp +0 -0
- package/docs/assets/intro/screen-zh.webp +0 -0
- package/lib/client.js +1286 -52
- package/lib/coaching.d.ts +1 -1
- package/lib/coaching.js +25 -12
- package/lib/config.d.ts +2 -0
- package/lib/config.js +36 -2
- package/lib/execution.d.ts +2 -1
- package/lib/execution.js +21 -1
- package/lib/tools.d.ts +1 -1
- package/lib/tools.js +160 -25
- package/lib/types.d.ts +115 -8
- package/lib/visual.d.ts +3 -1
- package/lib/visual.js +40 -13
- package/lib/workbench-language.js +49 -9
- package/lib/workbench.d.ts +5 -0
- package/lib/workbench.js +603 -12
- package/package.json +8 -3
- package/skills/dsh-ppt/SKILL.md +56 -54
- package/skills/dsh-ppt/package.json +17 -5
- package/skills/dsh-ppt/references/advanced.md +123 -41
- package/skills/dsh-ppt/references/copywriting.md +63 -41
- package/skills/dsh-ppt/references/data.md +83 -36
- package/skills/dsh-ppt/references/syntax.md +157 -28
- package/skills/dsh-ppt/references/themes.md +113 -58
- package/skills/dsh-ppt/references/troubleshooting.md +21 -16
- package/skills/dsh-ppt/scripts/build-deck.mjs +67 -28
- package/skills/dsh-ppt/scripts/deck-absorb.mjs +1338 -0
- package/skills/dsh-ppt/scripts/deck-advanced.mjs +422 -105
- package/skills/dsh-ppt/scripts/deck-core.mjs +572 -717
- package/skills/dsh-ppt/scripts/deck-data-view.mjs +30 -11
- package/skills/dsh-ppt/scripts/deck-data.mjs +35 -5
- package/skills/dsh-ppt/scripts/deck-director.mjs +2057 -0
- package/skills/dsh-ppt/scripts/deck-layouts.mjs +4673 -0
- package/skills/dsh-ppt/scripts/deck-media.mjs +1408 -86
- package/skills/dsh-ppt/scripts/deck-themes.mjs +1854 -0
- package/skills/dsh-ppt/scripts/deck-visual.mjs +133 -31
|
@@ -0,0 +1,1338 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* deck-absorb.mjs —— 外部参考 .pptx 母版、主题、字体、Logo 与骨架版式只读提取与审美净化器。
|
|
3
|
+
*
|
|
4
|
+
* Phase 3 深度增强:
|
|
5
|
+
* - 解析 OOXML <a:schemeClr> / <a:srgbClr> 子变换(lumMod, lumOff, tint, shade, satMod, satOff)
|
|
6
|
+
* - 提取母版骨架特征 extractedSkeleton: { cornerStyle: 'sharp'|'rounded'|'soft', hasTopBanner, hasSideSpine, masterShapeCount }
|
|
7
|
+
* - 推荐 6 种母版骨架 chromeStyle (recommendedChrome)
|
|
8
|
+
* - 逐页推理版式骨架 slideSkeleton: Array<{ slideNumber, inferredLayout, variant?, titleSample? }>
|
|
9
|
+
*
|
|
10
|
+
* 严格约束:
|
|
11
|
+
* - 仅使用 Node 内置模块 + 动态加载的 @office-kit/pptx
|
|
12
|
+
* - 绝不直接导入 saxes 或 fflate,保证技能目录独立复制到任意 Agent 环境均可运行
|
|
13
|
+
* - 提取出的原始配色与字体统一经由 deck-themes.mjs 的 sanitizeAbsorbedTheme 进行 WCAG 对比度与高饱和底色净化
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { lstatSync, readFileSync } from 'node:fs'
|
|
17
|
+
import { resolve } from 'node:path'
|
|
18
|
+
import { inflateSync } from 'node:zlib'
|
|
19
|
+
import { sanitizeAbsorbedTheme, normalizeHex, hexToHsl, relativeLuminance } from './deck-themes.mjs'
|
|
20
|
+
|
|
21
|
+
const MAX_PPTX_BYTES = 64 * 1024 * 1024
|
|
22
|
+
const MAX_LOGO_BYTES = 2 * 1024 * 1024
|
|
23
|
+
const EMU_PER_INCH = 914400
|
|
24
|
+
|
|
25
|
+
const OFFICE_DEFAULT_ACCENTS = new Set(['#4F81BD', '#4472C4', '#156082', '#0F9ED5'])
|
|
26
|
+
|
|
27
|
+
/** 6 Chrome Style IDs matching deck-themes.mjs / deck-layouts.mjs */
|
|
28
|
+
export const CHROME_STYLE_IDS = Object.freeze([
|
|
29
|
+
'consulting-classic',
|
|
30
|
+
'keynote-spatial',
|
|
31
|
+
'editorial-folio',
|
|
32
|
+
'saas-bento',
|
|
33
|
+
'academic-minimal',
|
|
34
|
+
'gov-ceremonial',
|
|
35
|
+
])
|
|
36
|
+
|
|
37
|
+
const SCHEME_PROP_MAP = {
|
|
38
|
+
dk1: 'dark1',
|
|
39
|
+
lt1: 'light1',
|
|
40
|
+
dk2: 'dark2',
|
|
41
|
+
lt2: 'light2',
|
|
42
|
+
bg1: 'light1',
|
|
43
|
+
tx1: 'dark1',
|
|
44
|
+
bg2: 'light2',
|
|
45
|
+
tx2: 'dark2',
|
|
46
|
+
dark1: 'dark1',
|
|
47
|
+
light1: 'light1',
|
|
48
|
+
dark2: 'dark2',
|
|
49
|
+
light2: 'light2',
|
|
50
|
+
accent1: 'accent1',
|
|
51
|
+
accent2: 'accent2',
|
|
52
|
+
accent3: 'accent3',
|
|
53
|
+
accent4: 'accent4',
|
|
54
|
+
accent5: 'accent5',
|
|
55
|
+
accent6: 'accent6',
|
|
56
|
+
hlink: 'hyperlink',
|
|
57
|
+
folHlink: 'followedHyperlink',
|
|
58
|
+
hyperlink: 'hyperlink',
|
|
59
|
+
followedHyperlink: 'followedHyperlink',
|
|
60
|
+
phClr: 'accent1',
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function fail(zh, en) {
|
|
64
|
+
throw new Error('dsh-ppt:' + zh + (en ? ' / ' + en : ''))
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// ---------------------------------------------------------------------------
|
|
68
|
+
// OOXML DrawingML Color Modifier Resolver (ISO/IEC 29500)
|
|
69
|
+
// ---------------------------------------------------------------------------
|
|
70
|
+
|
|
71
|
+
function clamp01(v) {
|
|
72
|
+
return Math.max(0, Math.min(1, v))
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function srgbToLinear(c) {
|
|
76
|
+
return c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function linearToSrgb(c) {
|
|
80
|
+
const v = clamp01(c)
|
|
81
|
+
return v <= 0.0031308 ? v * 12.92 : 1.055 * v ** (1 / 2.4) - 0.055
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function rgbToHsl01(r, g, b) {
|
|
85
|
+
const max = Math.max(r, g, b)
|
|
86
|
+
const min = Math.min(r, g, b)
|
|
87
|
+
const l = (max + min) / 2
|
|
88
|
+
if (max === min) return [0, 0, l]
|
|
89
|
+
const d = max - min
|
|
90
|
+
const s = l > 0.5 ? d / (2 - max - min) : d / (max + min)
|
|
91
|
+
let h
|
|
92
|
+
if (max === r) h = (g - b) / d + (g < b ? 6 : 0)
|
|
93
|
+
else if (max === g) h = (b - r) / d + 2
|
|
94
|
+
else h = (r - g) / d + 4
|
|
95
|
+
return [h / 6, s, l]
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function hueToRgb(p, q, t) {
|
|
99
|
+
let u = t
|
|
100
|
+
if (u < 0) u += 1
|
|
101
|
+
if (u > 1) u -= 1
|
|
102
|
+
if (u < 1 / 6) return p + (q - p) * 6 * u
|
|
103
|
+
if (u < 1 / 2) return q
|
|
104
|
+
if (u < 2 / 3) return p + (q - p) * (2 / 3 - u) * 6
|
|
105
|
+
return p
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function hslToRgb01(h, s, l) {
|
|
109
|
+
if (s === 0) return [l, l, l]
|
|
110
|
+
const q = l < 0.5 ? l * (1 + s) : l + s - l * s
|
|
111
|
+
const p = 2 * l - q
|
|
112
|
+
return [
|
|
113
|
+
hueToRgb(p, q, h + 1 / 3),
|
|
114
|
+
hueToRgb(p, q, h),
|
|
115
|
+
hueToRgb(p, q, h - 1 / 3),
|
|
116
|
+
]
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Resolve OOXML DrawingML color child modifiers (`lumMod`, `lumOff`, `tint`, `shade`, `satMod`, `satOff`)
|
|
121
|
+
* on a base `#RRGGBB` color string. Values are OOXML percentage units (`100000` = 100%).
|
|
122
|
+
*/
|
|
123
|
+
export function resolveColorModifiers(baseHex, mods) {
|
|
124
|
+
const norm = normalizeHex(baseHex, '')
|
|
125
|
+
if (!norm) return baseHex
|
|
126
|
+
if (!mods || (Array.isArray(mods) && mods.length === 0) || (typeof mods === 'object' && Object.keys(mods).length === 0)) {
|
|
127
|
+
return norm
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
let r = parseInt(norm.slice(1, 3), 16) / 255
|
|
131
|
+
let g = parseInt(norm.slice(3, 5), 16) / 255
|
|
132
|
+
let b = parseInt(norm.slice(5, 7), 16) / 255
|
|
133
|
+
|
|
134
|
+
const steps = Array.isArray(mods)
|
|
135
|
+
? mods
|
|
136
|
+
: Object.entries(mods).map(([kind, val]) => ({ kind, val }))
|
|
137
|
+
|
|
138
|
+
for (const step of steps) {
|
|
139
|
+
if (!step || typeof step.val !== 'number' || !Number.isFinite(step.val)) continue
|
|
140
|
+
const ratio = step.val / 100000
|
|
141
|
+
if (step.kind === 'tint') {
|
|
142
|
+
r = linearToSrgb(srgbToLinear(r) * ratio + (1 - ratio))
|
|
143
|
+
g = linearToSrgb(srgbToLinear(g) * ratio + (1 - ratio))
|
|
144
|
+
b = linearToSrgb(srgbToLinear(b) * ratio + (1 - ratio))
|
|
145
|
+
} else if (step.kind === 'shade') {
|
|
146
|
+
r = linearToSrgb(srgbToLinear(r) * ratio)
|
|
147
|
+
g = linearToSrgb(srgbToLinear(g) * ratio)
|
|
148
|
+
b = linearToSrgb(srgbToLinear(b) * ratio)
|
|
149
|
+
} else if (step.kind === 'lumMod' || step.kind === 'lumOff') {
|
|
150
|
+
const [h, s, l] = rgbToHsl01(r, g, b)
|
|
151
|
+
const nextL = clamp01(step.kind === 'lumMod' ? l * ratio : l + ratio)
|
|
152
|
+
;[r, g, b] = hslToRgb01(h, s, nextL)
|
|
153
|
+
} else if (step.kind === 'satMod' || step.kind === 'satOff') {
|
|
154
|
+
const [h, s, l] = rgbToHsl01(r, g, b)
|
|
155
|
+
const nextS = clamp01(step.kind === 'satMod' ? s * ratio : s + ratio)
|
|
156
|
+
;[r, g, b] = hslToRgb01(h, nextS, l)
|
|
157
|
+
} else if (step.kind === 'hueMod' || step.kind === 'hueOff') {
|
|
158
|
+
const [h, s, l] = rgbToHsl01(r, g, b)
|
|
159
|
+
// OOXML hueOff uses 1/60000 deg (21600000 = 360 deg); hueMod uses 1/100000 ratio
|
|
160
|
+
const nextH = step.kind === 'hueMod'
|
|
161
|
+
? ((h * ratio) % 1 + 1) % 1
|
|
162
|
+
: (((h + step.val / 21600000) % 1) + 1) % 1
|
|
163
|
+
;[r, g, b] = hslToRgb01(nextH, s, l)
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const toHex = (v) => Math.round(clamp01(v) * 255).toString(16).padStart(2, '0').toUpperCase()
|
|
168
|
+
return '#' + toHex(r) + toHex(g) + toHex(b)
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function parseXmlModifiers(innerXml) {
|
|
172
|
+
if (!innerXml) return []
|
|
173
|
+
const mods = []
|
|
174
|
+
const modRe = /<a:(lumMod|lumOff|tint|shade|satMod|satOff|hueMod|hueOff)\b[^>]*\bval=["'](-?\d+)["'][^>]*\/?>/g
|
|
175
|
+
for (const m of innerXml.matchAll(modRe)) {
|
|
176
|
+
mods.push({ kind: m[1], val: Number(m[2]) })
|
|
177
|
+
}
|
|
178
|
+
return mods
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const PRESET_COLOR_HEX = {
|
|
182
|
+
black: '#000000',
|
|
183
|
+
white: '#FFFFFF',
|
|
184
|
+
navy: '#000080',
|
|
185
|
+
darkblue: '#00008B',
|
|
186
|
+
midnightblue: '#191970',
|
|
187
|
+
royalblue: '#4169E1',
|
|
188
|
+
teal: '#008080',
|
|
189
|
+
darkgreen: '#006400',
|
|
190
|
+
seagreen: '#2E8B57',
|
|
191
|
+
darkred: '#8B0000',
|
|
192
|
+
crimson: '#DC143C',
|
|
193
|
+
firebrick: '#B22222',
|
|
194
|
+
gold: '#FFD700',
|
|
195
|
+
orange: '#FFA500',
|
|
196
|
+
darkslategray: '#2F4F4F',
|
|
197
|
+
slategray: '#708090',
|
|
198
|
+
gray: '#808080',
|
|
199
|
+
lightgray: '#D3D3D3',
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function lookupSchemeHex(slot, themeScheme, colorMap) {
|
|
203
|
+
if (!slot || !themeScheme) return null
|
|
204
|
+
const mapped = (colorMap && colorMap[slot]) || slot
|
|
205
|
+
const prop = SCHEME_PROP_MAP[mapped] || SCHEME_PROP_MAP[slot] || mapped
|
|
206
|
+
const candidate = themeScheme[prop]
|
|
207
|
+
if (candidate && /^#?[\da-f]{6}$/i.test(String(candidate))) {
|
|
208
|
+
return normalizeHex(candidate, '') || null
|
|
209
|
+
}
|
|
210
|
+
return null
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Parse <a:srgbClr>, <a:schemeClr>, <a:sysClr>, or <a:prstClr> (including child modifiers) from an XML fragment.
|
|
215
|
+
*/
|
|
216
|
+
export function resolveXmlColorElement(xmlFragment, themeScheme, colorMap) {
|
|
217
|
+
if (!xmlFragment || typeof xmlFragment !== 'string') return null
|
|
218
|
+
const match = /<a:(srgbClr|schemeClr|sysClr|prstClr)\b([^>]*)(?:\/>|>([\s\S]*?)<\/a:\1>)/.exec(xmlFragment)
|
|
219
|
+
if (!match) return null
|
|
220
|
+
const [, tag, attrs, inner] = match
|
|
221
|
+
const valMatch = /\bval=["']([^"']+)["']/.exec(attrs)
|
|
222
|
+
const lastClrMatch = /\blastClr=["']([^"']+)["']/.exec(attrs)
|
|
223
|
+
const val = valMatch ? valMatch[1].trim() : ''
|
|
224
|
+
let baseHex = null
|
|
225
|
+
if (tag === 'srgbClr') {
|
|
226
|
+
baseHex = normalizeHex(val, '') || null
|
|
227
|
+
} else if (tag === 'sysClr') {
|
|
228
|
+
if (lastClrMatch && /^#?[\da-f]{6}$/i.test(lastClrMatch[1].trim())) {
|
|
229
|
+
baseHex = normalizeHex(lastClrMatch[1].trim(), '') || null
|
|
230
|
+
} else if (/windowtext|buttontext|menutext/i.test(val)) {
|
|
231
|
+
baseHex = '#000000'
|
|
232
|
+
} else if (/window|highlighttext/i.test(val)) {
|
|
233
|
+
baseHex = '#FFFFFF'
|
|
234
|
+
}
|
|
235
|
+
} else if (tag === 'prstClr') {
|
|
236
|
+
baseHex = PRESET_COLOR_HEX[val.toLowerCase()] ?? null
|
|
237
|
+
} else if (val) {
|
|
238
|
+
baseHex = lookupSchemeHex(val, themeScheme, colorMap)
|
|
239
|
+
}
|
|
240
|
+
if (!baseHex) return null
|
|
241
|
+
const mods = parseXmlModifiers(inner)
|
|
242
|
+
return mods.length ? resolveColorModifiers(baseHex, mods) : baseHex
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
function resolveBackgroundFromXml(xmlStr, themeScheme, colorMap) {
|
|
246
|
+
if (!xmlStr) return null
|
|
247
|
+
const bgMatch = /<p:bg\b[^>]*>([\s\S]*?)<\/p:bg>/.exec(xmlStr)
|
|
248
|
+
if (!bgMatch) return null
|
|
249
|
+
const bgInner = bgMatch[1]
|
|
250
|
+
// Direct solidFill or gradFill stop inside p:bgPr
|
|
251
|
+
const solidMatch = /<a:solidFill\b[^>]*>([\s\S]*?)<\/a:solidFill>/.exec(bgInner)
|
|
252
|
+
if (solidMatch) {
|
|
253
|
+
const resolved = resolveXmlColorElement(solidMatch[1], themeScheme, colorMap)
|
|
254
|
+
if (resolved) return resolved
|
|
255
|
+
}
|
|
256
|
+
// bgRef referencing style matrix (e.g. <p:bgRef idx="1001"><a:schemeClr val="bg1">...</a:schemeClr></p:bgRef>)
|
|
257
|
+
const refMatch = /<p:bgRef\b[^>]*>([\s\S]*?)<\/p:bgRef>/.exec(bgInner)
|
|
258
|
+
if (refMatch) {
|
|
259
|
+
const resolved = resolveXmlColorElement(refMatch[1], themeScheme, colorMap)
|
|
260
|
+
if (resolved) return resolved
|
|
261
|
+
}
|
|
262
|
+
const gradMatch = /<a:gs\b[^>]*>([\s\S]*?)<\/a:gs>/.exec(bgInner)
|
|
263
|
+
if (gradMatch) {
|
|
264
|
+
const resolved = resolveXmlColorElement(gradMatch[1], themeScheme, colorMap)
|
|
265
|
+
if (resolved) return resolved
|
|
266
|
+
}
|
|
267
|
+
return null
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
function resolveShapeFillSafe(lib, pres, shape, themeScheme, colorMap) {
|
|
271
|
+
try {
|
|
272
|
+
const hex = lib.getShapeFillColorResolved(pres, shape)
|
|
273
|
+
if (hex && /^#[\da-f]{6}$/i.test(hex)) return hex.toUpperCase()
|
|
274
|
+
} catch { /* fallback to XML */ }
|
|
275
|
+
try {
|
|
276
|
+
const xml = lib.getShapeXmlString?.(shape)
|
|
277
|
+
if (xml) {
|
|
278
|
+
const spPrMatch = /<p:spPr\b[^>]*>([\s\S]*?)<\/p:spPr>/.exec(xml)
|
|
279
|
+
const solid = spPrMatch && /<a:solidFill\b[^>]*>([\s\S]*?)<\/a:solidFill>/.exec(spPrMatch[1])
|
|
280
|
+
if (solid) {
|
|
281
|
+
return resolveXmlColorElement(solid[1], themeScheme, colorMap)
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
} catch { /* ignore */ }
|
|
285
|
+
return null
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// ---------------------------------------------------------------------------
|
|
289
|
+
// Master Slide Skeleton Extraction
|
|
290
|
+
// ---------------------------------------------------------------------------
|
|
291
|
+
|
|
292
|
+
function getBoundsSafe(lib, shape) {
|
|
293
|
+
try {
|
|
294
|
+
const resolved = lib.getShapeBoundsResolved?.(shape)
|
|
295
|
+
if (resolved && Number.isFinite(resolved.w) && Number.isFinite(resolved.h)) return resolved
|
|
296
|
+
} catch { /* fallback */ }
|
|
297
|
+
try {
|
|
298
|
+
return lib.getShapeBounds(shape)
|
|
299
|
+
} catch {
|
|
300
|
+
return null
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
function flattenShapes(lib, shapes, depth = 0) {
|
|
305
|
+
if (!Array.isArray(shapes) || depth > 4) return []
|
|
306
|
+
const out = []
|
|
307
|
+
for (const shape of shapes) {
|
|
308
|
+
if (!shape) continue
|
|
309
|
+
let children = null
|
|
310
|
+
try {
|
|
311
|
+
children = lib.getGroupChildren?.(shape)
|
|
312
|
+
} catch { /* ignore */ }
|
|
313
|
+
if (Array.isArray(children) && children.length > 0) {
|
|
314
|
+
out.push(...flattenShapes(lib, children, depth + 1))
|
|
315
|
+
} else {
|
|
316
|
+
out.push(shape)
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
return out
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
function classifyCornerFromShapes(lib, shapes, slideW) {
|
|
323
|
+
let hasRounded = false
|
|
324
|
+
let hasSoft = false
|
|
325
|
+
let hasSharpRect = false
|
|
326
|
+
for (const shape of flattenShapes(lib, shapes)) {
|
|
327
|
+
try {
|
|
328
|
+
const bounds = getBoundsSafe(lib, shape)
|
|
329
|
+
if (!bounds) continue
|
|
330
|
+
const relW = bounds.w / slideW
|
|
331
|
+
if (relW < 0.08) continue
|
|
332
|
+
const preset = String(lib.getShapePreset?.(shape) ?? '').toLowerCase()
|
|
333
|
+
const name = String(lib.getShapeName?.(shape) ?? '').toLowerCase()
|
|
334
|
+
if (preset === 'roundrect' || preset === 'round2samerect' || preset === 'round1rect' || name.includes('round')) {
|
|
335
|
+
let adjVal = 0
|
|
336
|
+
try {
|
|
337
|
+
const adjs = lib.getShapeAdjustValues?.(shape)
|
|
338
|
+
if (adjs && typeof adjs.adj === 'number') adjVal = adjs.adj
|
|
339
|
+
else if (Array.isArray(adjs)) {
|
|
340
|
+
const adjItem = adjs.find((a) => a?.name === 'adj')
|
|
341
|
+
if (adjItem && typeof adjItem.val === 'number') adjVal = adjItem.val
|
|
342
|
+
}
|
|
343
|
+
} catch { /* ignore */ }
|
|
344
|
+
if (adjVal >= 10000) hasSoft = true
|
|
345
|
+
else hasRounded = true
|
|
346
|
+
} else if (preset === 'ellipse' && relW > 0.12) {
|
|
347
|
+
hasSoft = true
|
|
348
|
+
} else if (preset === 'rect') {
|
|
349
|
+
hasSharpRect = true
|
|
350
|
+
}
|
|
351
|
+
} catch { /* ignore */ }
|
|
352
|
+
}
|
|
353
|
+
if (hasSoft) return 'soft'
|
|
354
|
+
if (hasRounded) return 'rounded'
|
|
355
|
+
if (hasSharpRect) return 'sharp'
|
|
356
|
+
return 'sharp'
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
function extractSkeletonFromShapes(lib, masterShapes, layoutShapes, sampleSlideShapes, slideW, slideH) {
|
|
360
|
+
const mShapes = flattenShapes(lib, masterShapes)
|
|
361
|
+
const lShapes = flattenShapes(lib, layoutShapes)
|
|
362
|
+
const sShapes = flattenShapes(lib, sampleSlideShapes)
|
|
363
|
+
const inspectShapes = [...mShapes, ...lShapes, ...(mShapes.length + lShapes.length === 0 ? sShapes : [])]
|
|
364
|
+
|
|
365
|
+
let hasTopBanner = false
|
|
366
|
+
let hasSideSpine = false
|
|
367
|
+
let hasFooterRule = false
|
|
368
|
+
let doubleHeaderLines = 0
|
|
369
|
+
|
|
370
|
+
for (const shape of inspectShapes) {
|
|
371
|
+
try {
|
|
372
|
+
if (lib.hasShapeImage(shape)) continue
|
|
373
|
+
const bounds = getBoundsSafe(lib, shape)
|
|
374
|
+
if (!bounds) continue
|
|
375
|
+
const relW = bounds.w / slideW
|
|
376
|
+
const relH = bounds.h / slideH
|
|
377
|
+
const relX = bounds.x / slideW
|
|
378
|
+
const relY = bounds.y / slideH
|
|
379
|
+
const name = String(lib.getShapeName?.(shape) ?? '').toLowerCase()
|
|
380
|
+
|
|
381
|
+
if (relY <= 0.08 && relW >= 0.65 && relH <= 0.22) {
|
|
382
|
+
hasTopBanner = true
|
|
383
|
+
if (relH <= 0.025) doubleHeaderLines += 1
|
|
384
|
+
}
|
|
385
|
+
if ((relX <= 0.06 || relX >= 0.90) && relW <= 0.10 && relH >= 0.45) {
|
|
386
|
+
hasSideSpine = true
|
|
387
|
+
}
|
|
388
|
+
if (relY >= 0.85 && relW >= 0.5 && relH <= 0.03) {
|
|
389
|
+
hasFooterRule = true
|
|
390
|
+
}
|
|
391
|
+
if (name.includes('header') && relW >= 0.6) {
|
|
392
|
+
hasTopBanner = true
|
|
393
|
+
}
|
|
394
|
+
} catch { /* ignore malformed shape */ }
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
const cornerStyle = classifyCornerFromShapes(lib, [...mShapes, ...lShapes, ...sShapes], slideW)
|
|
398
|
+
return {
|
|
399
|
+
cornerStyle,
|
|
400
|
+
hasTopBanner,
|
|
401
|
+
hasSideSpine,
|
|
402
|
+
masterShapeCount: Array.isArray(masterShapes) ? masterShapes.length : mShapes.length,
|
|
403
|
+
_hasFooterRule: hasFooterRule,
|
|
404
|
+
_doubleHeaderLines: doubleHeaderLines,
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
function inferChromeStyle(skeleton, palette, fonts, dark, recommendedTheme) {
|
|
409
|
+
const fontText = [fonts.majorLatin, fonts.majorEastAsian, fonts.minorLatin, fonts.minorEastAsian].filter(Boolean).join(' ')
|
|
410
|
+
const isSerif = /(?:times|georgia|garamond|cambria|palatino|宋体|SimSun|Songti|Source\s*Serif|Noto\s*Serif)/i.test(fontText)
|
|
411
|
+
|
|
412
|
+
if (
|
|
413
|
+
recommendedTheme === 'exec-palace' ||
|
|
414
|
+
recommendedTheme === 'exec-jilan' ||
|
|
415
|
+
skeleton._doubleHeaderLines >= 2 ||
|
|
416
|
+
(palette.accent1 && /^#[89AB][0-9A-F]0{3}$/i.test(palette.accent1))
|
|
417
|
+
) {
|
|
418
|
+
return 'gov-ceremonial'
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
if (
|
|
422
|
+
recommendedTheme === 'academic' ||
|
|
423
|
+
recommendedTheme === 'course-sage' ||
|
|
424
|
+
recommendedTheme === 'medical-clean' ||
|
|
425
|
+
(isSerif && !dark && (skeleton.hasTopBanner || skeleton._hasFooterRule))
|
|
426
|
+
) {
|
|
427
|
+
return 'academic-minimal'
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
if (
|
|
431
|
+
recommendedTheme === 'keynote-light' ||
|
|
432
|
+
recommendedTheme === 'venture-daylight' ||
|
|
433
|
+
recommendedTheme === 'aurora-stage' ||
|
|
434
|
+
recommendedTheme === 'bold' ||
|
|
435
|
+
skeleton.cornerStyle === 'soft' ||
|
|
436
|
+
(!skeleton.hasTopBanner && !skeleton.hasSideSpine && !skeleton._hasFooterRule && skeleton.cornerStyle !== 'sharp' && !dark)
|
|
437
|
+
) {
|
|
438
|
+
return 'keynote-spatial'
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
if (
|
|
442
|
+
skeleton.hasSideSpine ||
|
|
443
|
+
recommendedTheme === 'editorial-forest' ||
|
|
444
|
+
recommendedTheme === 'economist-brief' ||
|
|
445
|
+
recommendedTheme === 'cartesian' ||
|
|
446
|
+
recommendedTheme === 'velvet' ||
|
|
447
|
+
recommendedTheme === 'luxury-noir'
|
|
448
|
+
) {
|
|
449
|
+
return 'editorial-folio'
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
if (
|
|
453
|
+
recommendedTheme === 'linear-dark' ||
|
|
454
|
+
recommendedTheme === 'stripe-craft' ||
|
|
455
|
+
recommendedTheme === 'swiss' ||
|
|
456
|
+
recommendedTheme === 'data' ||
|
|
457
|
+
recommendedTheme === 'soft' ||
|
|
458
|
+
(skeleton.cornerStyle === 'rounded' && dark)
|
|
459
|
+
) {
|
|
460
|
+
return 'saas-bento'
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
return 'consulting-classic'
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
// ---------------------------------------------------------------------------
|
|
467
|
+
// Per-Slide Layout Classification (Full 24-Archetype + Variant Recognition)
|
|
468
|
+
// ---------------------------------------------------------------------------
|
|
469
|
+
|
|
470
|
+
function inspectTableForHarveyAndStyle(lib, tables) {
|
|
471
|
+
let hasHarvey = false
|
|
472
|
+
let styleHint = null
|
|
473
|
+
for (const tbl of tables ?? []) {
|
|
474
|
+
try {
|
|
475
|
+
const dims = lib.getTableDimensions?.(tbl)
|
|
476
|
+
const rows = dims?.rows ?? 0
|
|
477
|
+
const cols = dims?.cols ?? 0
|
|
478
|
+
let harveyHits = 0
|
|
479
|
+
for (let r = 0; r < Math.min(rows, 15); r += 1) {
|
|
480
|
+
for (let c = 0; c < Math.min(cols, 10); c += 1) {
|
|
481
|
+
const txt = String(lib.getTableCellText?.(tbl, r, c) ?? '').trim()
|
|
482
|
+
if (/[●◕◑◔○]/.test(txt)) harveyHits += 1
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
if (harveyHits >= 2) hasHarvey = true
|
|
486
|
+
const flags = lib.getTableStyleFlags?.(tbl)
|
|
487
|
+
if (flags && flags.bandRow === false && flags.bandCol === false && flags.firstRow === true) {
|
|
488
|
+
styleHint ||= 'booktabs'
|
|
489
|
+
} else if (flags?.bandRow === true) {
|
|
490
|
+
styleHint ||= 'banded'
|
|
491
|
+
}
|
|
492
|
+
} catch { /* ignore table inspection error */ }
|
|
493
|
+
}
|
|
494
|
+
return { hasHarvey, styleHint }
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
function analyzeSlideLayout(lib, slide, slideIndex, totalSlides, slideW, slideH) {
|
|
498
|
+
const result = { slideNumber: slideIndex + 1, inferredLayout: 'bullets' }
|
|
499
|
+
try {
|
|
500
|
+
const rawShapes = lib.getSlideShapes(slide) ?? []
|
|
501
|
+
const shapes = flattenShapes(lib, rawShapes)
|
|
502
|
+
let layoutType = ''
|
|
503
|
+
let layoutName = ''
|
|
504
|
+
try {
|
|
505
|
+
const sLayout = lib.getSlideLayout(slide)
|
|
506
|
+
if (sLayout) {
|
|
507
|
+
layoutType = String(lib.getSlideLayoutType(sLayout) ?? '').toLowerCase()
|
|
508
|
+
layoutName = String(lib.getSlideLayoutName?.(sLayout) ?? '').toLowerCase()
|
|
509
|
+
}
|
|
510
|
+
} catch { /* ignore */ }
|
|
511
|
+
|
|
512
|
+
let hasChart = false
|
|
513
|
+
let isWaterfallChart = false
|
|
514
|
+
let hasTable = false
|
|
515
|
+
let slideTables = []
|
|
516
|
+
try {
|
|
517
|
+
const charts = lib.getSlideCharts?.(slide)
|
|
518
|
+
if (Array.isArray(charts) && charts.length > 0) hasChart = true
|
|
519
|
+
} catch { /* ignore */ }
|
|
520
|
+
try {
|
|
521
|
+
const tables = lib.getSlideTables?.(slide)
|
|
522
|
+
if (Array.isArray(tables) && tables.length > 0) {
|
|
523
|
+
hasTable = true
|
|
524
|
+
slideTables = tables
|
|
525
|
+
}
|
|
526
|
+
} catch { /* ignore */ }
|
|
527
|
+
|
|
528
|
+
const tableMeta = hasTable ? inspectTableForHarveyAndStyle(lib, slideTables) : { hasHarvey: false, styleHint: null }
|
|
529
|
+
|
|
530
|
+
let titleText = ''
|
|
531
|
+
let titleFound = false
|
|
532
|
+
let imageCount = 0
|
|
533
|
+
let hasLeftHalfImage = false
|
|
534
|
+
let hasRightHalfImage = false
|
|
535
|
+
let nonTitleTextShapes = 0
|
|
536
|
+
let largeCardShapes = 0
|
|
537
|
+
let numericKpiShapes = 0
|
|
538
|
+
let harveyCells = tableMeta.hasHarvey
|
|
539
|
+
let harveyPieOrCircles = 0
|
|
540
|
+
let waterfallBars = 0
|
|
541
|
+
let chevronShapes = 0
|
|
542
|
+
let ellipseCircles = 0
|
|
543
|
+
let diamondShapes = 0
|
|
544
|
+
let connectorShapes = 0
|
|
545
|
+
let horizontalAxisLines = 0
|
|
546
|
+
let roleBioHits = 0
|
|
547
|
+
let quoteSignal = false
|
|
548
|
+
let tamTextHits = 0
|
|
549
|
+
const cardRects = []
|
|
550
|
+
const ganttBars = []
|
|
551
|
+
const layerBands = []
|
|
552
|
+
const shapeCenters = []
|
|
553
|
+
const allBodyTexts = []
|
|
554
|
+
|
|
555
|
+
for (const shape of shapes) {
|
|
556
|
+
try {
|
|
557
|
+
if (lib.isChartShape?.(shape)) {
|
|
558
|
+
hasChart = true
|
|
559
|
+
try {
|
|
560
|
+
if (String(lib.getShapeChartKind?.(shape) ?? '').toLowerCase() === 'waterfall') isWaterfallChart = true
|
|
561
|
+
} catch { /* ignore */ }
|
|
562
|
+
}
|
|
563
|
+
if (lib.isTableShape?.(shape)) hasTable = true
|
|
564
|
+
|
|
565
|
+
const name = String(lib.getShapeName?.(shape) ?? '').toLowerCase()
|
|
566
|
+
const phType = String(lib.getShapePlaceholderType?.(shape) ?? '').toLowerCase()
|
|
567
|
+
const preset = String(lib.getShapePreset?.(shape) ?? '').toLowerCase()
|
|
568
|
+
const kind = String(lib.getShapeKind?.(shape) ?? '').toLowerCase()
|
|
569
|
+
const bounds = getBoundsSafe(lib, shape)
|
|
570
|
+
const text = String(lib.getShapeText?.(shape) ?? '').trim()
|
|
571
|
+
|
|
572
|
+
if (name.startsWith('waterfall bar') || name.startsWith('waterfall bridge')) {
|
|
573
|
+
waterfallBars += 1
|
|
574
|
+
}
|
|
575
|
+
if (name.startsWith('harvey ')) {
|
|
576
|
+
harveyCells = true
|
|
577
|
+
} else if (bounds && (preset === 'pie' || preset === 'ellipse') && (bounds.w / slideW) >= 0.01 && (bounds.w / slideW) <= 0.045 && Math.abs(bounds.w - bounds.h) <= bounds.w * 0.18) {
|
|
578
|
+
harveyPieOrCircles += 1
|
|
579
|
+
if (harveyPieOrCircles >= 4) harveyCells = true
|
|
580
|
+
}
|
|
581
|
+
if (kind === 'connector' || preset.includes('connector') || preset === 'line') {
|
|
582
|
+
const inBodyZone = bounds && (bounds.y / slideH) > 0.22 && (bounds.y / slideH) < 0.86 && !/rule|folio|divider|header|footer|takeaway/i.test(name)
|
|
583
|
+
if (inBodyZone) {
|
|
584
|
+
connectorShapes += 1
|
|
585
|
+
if (bounds.w / slideW >= 0.52 && bounds.h / slideH <= 0.025) {
|
|
586
|
+
horizontalAxisLines += 1
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
if (!hasChart && (name.includes('chart') || (name.includes('diagram') && !name.includes('arch')))) hasChart = true
|
|
591
|
+
if (!hasTable && name.includes('table')) hasTable = true
|
|
592
|
+
|
|
593
|
+
if (phType === 'title' || phType === 'ctrtitle' || name.startsWith('title') || name.includes('标题')) {
|
|
594
|
+
titleFound = true
|
|
595
|
+
if (!titleText && text) titleText = text.replace(/\s+/g, ' ').slice(0, 80)
|
|
596
|
+
continue
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
if (lib.hasShapeImage(shape)) {
|
|
600
|
+
// Ignore tiny corner brand logos during content layout classification
|
|
601
|
+
if (bounds && bounds.w <= slideW * 0.16 && bounds.h <= slideH * 0.14 && (bounds.y <= slideH * 0.16 || bounds.y + bounds.h >= slideH * 0.84)) {
|
|
602
|
+
continue
|
|
603
|
+
}
|
|
604
|
+
imageCount += 1
|
|
605
|
+
if (bounds) {
|
|
606
|
+
const relW = bounds.w / slideW
|
|
607
|
+
const relH = bounds.h / slideH
|
|
608
|
+
const relX = bounds.x / slideW
|
|
609
|
+
if (relW > 0.25 && relH > 0.3) {
|
|
610
|
+
if (relX < 0.35) hasLeftHalfImage = true
|
|
611
|
+
else if (relX >= 0.35) hasRightHalfImage = true
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
continue
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
if (!bounds) {
|
|
618
|
+
if (text) nonTitleTextShapes += 1
|
|
619
|
+
continue
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
const relW = bounds.w / slideW
|
|
623
|
+
const relH = bounds.h / slideH
|
|
624
|
+
const relX = bounds.x / slideW
|
|
625
|
+
const relY = bounds.y / slideH
|
|
626
|
+
|
|
627
|
+
// Skip full-bleed background canvas shapes
|
|
628
|
+
if (relW >= 0.78 && relH >= 0.78 && relX <= 0.12 && relY <= 0.12) continue
|
|
629
|
+
|
|
630
|
+
if (!titleFound && relY < 0.22 && relW > 0.45 && relH < 0.22 && text) {
|
|
631
|
+
titleFound = true
|
|
632
|
+
titleText = text.replace(/\s+/g, ' ').slice(0, 80)
|
|
633
|
+
continue
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
const isChromeShape =
|
|
637
|
+
relY >= 0.88 ||
|
|
638
|
+
(relY <= 0.12 && relH <= 0.12) ||
|
|
639
|
+
/^(?:page number|footer|source|kicker|folio|beamer|header rule|takeaway)/i.test(name) ||
|
|
640
|
+
phType === 'ftr' || phType === 'sldnum' || phType === 'dt'
|
|
641
|
+
if (isChromeShape) continue
|
|
642
|
+
|
|
643
|
+
if (preset === 'chevron' || preset === 'homeplate' || preset === 'pentagon') {
|
|
644
|
+
chevronShapes += 1
|
|
645
|
+
} else if (preset === 'ellipse' && relW >= 0.12 && relH >= 0.16 && Math.abs(bounds.w - bounds.h) <= Math.max(bounds.w, bounds.h) * 0.45) {
|
|
646
|
+
ellipseCircles += 1
|
|
647
|
+
} else if (preset === 'diamond' && relW <= 0.08 && relH <= 0.12) {
|
|
648
|
+
diamondShapes += 1
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
if (text) {
|
|
652
|
+
nonTitleTextShapes += 1
|
|
653
|
+
allBodyTexts.push(text)
|
|
654
|
+
const firstLine = text.split('\n')[0]?.trim() ?? ''
|
|
655
|
+
if (/^[+-]?[$¥€£]?\s*\d[\d.,]*\s*[%%倍xX万亿千百kKmMbBtT+]*$/.test(firstLine)) {
|
|
656
|
+
numericKpiShapes += 1
|
|
657
|
+
}
|
|
658
|
+
if (/[●◕◑◔○]/.test(text)) harveyCells = true
|
|
659
|
+
if (/\b(?:TAM|SAM|SOM)\b/i.test(text)) tamTextHits += 1
|
|
660
|
+
if (/\b(?:CEO|CTO|CFO|COO|CMO|VP|SVP|Director|Founder|Partner)\b|负责人|总监|合伙人|首席|院长|组长/.test(text)) {
|
|
661
|
+
roleBioHits += 1
|
|
662
|
+
}
|
|
663
|
+
if (/^[“"「『][\s\S]{10,}[”"」』]?/.test(text) || /——\s*\S+/.test(text)) {
|
|
664
|
+
quoteSignal = true
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
if (!lib.isChartShape?.(shape) && !lib.isTableShape?.(shape)) {
|
|
669
|
+
if (relW >= 0.52 && relH >= 0.065 && relH <= 0.22 && relY >= 0.16 && relY <= 0.86) {
|
|
670
|
+
layerBands.push({ x: relX, y: relY, w: relW, h: relH })
|
|
671
|
+
}
|
|
672
|
+
if (relW >= 0.10 && relW <= 0.68 && relH >= 0.025 && relH <= 0.105 && relY >= 0.20 && relY <= 0.85 && relX >= 0.14) {
|
|
673
|
+
ganttBars.push({ x: relX, y: relY, w: relW, h: relH })
|
|
674
|
+
}
|
|
675
|
+
if (relW > 0.16 && relW < 0.88 && relH > 0.14) {
|
|
676
|
+
cardRects.push({ x: relX, y: relY, w: relW, h: relH, cx: relX + relW / 2, cy: relY + relH / 2 })
|
|
677
|
+
if (relW > 0.18 && relW < 0.65 && relH > 0.18) {
|
|
678
|
+
largeCardShapes += 1
|
|
679
|
+
shapeCenters.push({ x: relX + relW / 2, y: relY + relH / 2 })
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
} catch { /* ignore shape */ }
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
const combinedSignal = (titleText + ' ' + layoutName + ' ' + allBodyTexts.join(' ')).trim()
|
|
687
|
+
const distinctGanttStarts = new Set(ganttBars.map((b) => Math.round(b.x * 20))).size
|
|
688
|
+
const distinctLayerYs = new Set(layerBands.map((b) => Math.round(b.y * 20))).size
|
|
689
|
+
const isFunnelBands = layerBands.length >= 3 && (() => {
|
|
690
|
+
const sorted = [...layerBands].sort((a, b) => a.y - b.y)
|
|
691
|
+
return sorted[0].w > sorted[sorted.length - 1].w * 1.18 && sorted.every((b, idx) => idx === 0 || b.w <= sorted[idx - 1].w * 1.03)
|
|
692
|
+
})()
|
|
693
|
+
const hasTopSummaryBanner = cardRects.some((r) => r.w >= 0.68 && r.h <= 0.26 && r.y <= 0.38)
|
|
694
|
+
const lowerPillars = cardRects.filter((r) => r.w <= 0.42 && r.y >= 0.34)
|
|
695
|
+
|
|
696
|
+
// Priority order: rich native charts/tables/diagrams -> media -> framing -> structured layouts
|
|
697
|
+
if (waterfallBars >= 3 || isWaterfallChart) {
|
|
698
|
+
result.inferredLayout = 'waterfall'
|
|
699
|
+
} else if (harveyCells) {
|
|
700
|
+
result.inferredLayout = 'harvey'
|
|
701
|
+
} else if (hasChart) {
|
|
702
|
+
result.inferredLayout = nonTitleTextShapes >= 1 || largeCardShapes >= 1 ? 'chart-split' : 'chart'
|
|
703
|
+
} else if (hasTable) {
|
|
704
|
+
result.inferredLayout = 'table'
|
|
705
|
+
if (tableMeta.styleHint) result.tableStyle = tableMeta.styleHint
|
|
706
|
+
} else if (ellipseCircles >= 2 && (ellipseCircles >= 3 || tamTextHits >= 2 || /市场规模|市场空间|\bTAM\b/i.test(combinedSignal))) {
|
|
707
|
+
result.inferredLayout = 'tam'
|
|
708
|
+
result.variant = 'concentric'
|
|
709
|
+
} else if (chevronShapes >= 3) {
|
|
710
|
+
result.inferredLayout = 'process'
|
|
711
|
+
result.variant = 'chevron'
|
|
712
|
+
} else if (
|
|
713
|
+
ganttBars.length >= 3 &&
|
|
714
|
+
(distinctGanttStarts >= 2 || diamondShapes >= 1 || /\bQ[1-4]\b|\bW[1-9]\b|甘特|排期|路线图|里程碑|roadmap|gantt/i.test(combinedSignal)) &&
|
|
715
|
+
distinctLayerYs >= 2 &&
|
|
716
|
+
ganttBars.every((b) => b.w < 0.62)
|
|
717
|
+
) {
|
|
718
|
+
result.inferredLayout = 'gantt'
|
|
719
|
+
result.variant = /\bM1\b|1月|月份|month/i.test(combinedSignal) ? 'months' : 'quarters'
|
|
720
|
+
} else if (isFunnelBands) {
|
|
721
|
+
result.inferredLayout = 'process'
|
|
722
|
+
result.variant = 'funnel'
|
|
723
|
+
} else if (
|
|
724
|
+
layerBands.length >= 3 &&
|
|
725
|
+
distinctLayerYs >= 3 &&
|
|
726
|
+
(/架构|分层|中台|底座|平台层|应用层|接入层|architecture|layer|platform|stack|infra/i.test(combinedSignal) || layerBands.length >= 4)
|
|
727
|
+
) {
|
|
728
|
+
result.inferredLayout = 'architecture'
|
|
729
|
+
result.variant = 'layered'
|
|
730
|
+
} else if (
|
|
731
|
+
largeCardShapes >= 3 &&
|
|
732
|
+
numericKpiShapes < 2 &&
|
|
733
|
+
(connectorShapes >= 2 || /组织架构|汇报线|治理架构|核心团队|管理团队|org\s*chart|leadership|team/i.test(titleText))
|
|
734
|
+
) {
|
|
735
|
+
const ys = shapeCenters.map((c) => c.y).sort((a, b) => a - b)
|
|
736
|
+
const hasTopRoot = ys.length >= 3 && (ys[1] - ys[0] >= 0.14)
|
|
737
|
+
result.inferredLayout = 'org'
|
|
738
|
+
result.variant = hasTopRoot || (!roleBioHits && connectorShapes >= 2) ? 'tree' : 'team'
|
|
739
|
+
} else if (imageCount >= 2) {
|
|
740
|
+
result.inferredLayout = 'image'
|
|
741
|
+
result.variant = 'gallery'
|
|
742
|
+
} else if (imageCount === 1) {
|
|
743
|
+
if (hasLeftHalfImage && nonTitleTextShapes >= 1) result.inferredLayout = 'image-left'
|
|
744
|
+
else if (hasRightHalfImage && nonTitleTextShapes >= 1) result.inferredLayout = 'image-right'
|
|
745
|
+
else if (hasLeftHalfImage) result.inferredLayout = 'image-left'
|
|
746
|
+
else if (hasRightHalfImage) result.inferredLayout = 'image-right'
|
|
747
|
+
else result.inferredLayout = 'image'
|
|
748
|
+
} else if (
|
|
749
|
+
slideIndex === 0 &&
|
|
750
|
+
(layoutType === 'title' || (titleFound && nonTitleTextShapes <= 2 && largeCardShapes <= 1) || (nonTitleTextShapes <= 1 && shapes.length <= 3))
|
|
751
|
+
) {
|
|
752
|
+
result.inferredLayout = 'cover'
|
|
753
|
+
} else if (
|
|
754
|
+
slideIndex === totalSlides - 1 &&
|
|
755
|
+
totalSlides >= 3 &&
|
|
756
|
+
(nonTitleTextShapes <= 1 && /谢谢|感谢|Q\s*&\s*A|Thank|Contact|Next/i.test(titleText))
|
|
757
|
+
) {
|
|
758
|
+
result.inferredLayout = 'closing'
|
|
759
|
+
} else if (slideIndex > 0 && slideIndex <= 2 && /^(?:目录|汇报目录|议程|大纲|章节导航|Agenda|Contents|Table\s+of\s+Contents|Outline)$/i.test(titleText.trim())) {
|
|
760
|
+
result.inferredLayout = 'agenda'
|
|
761
|
+
result.variant = largeCardShapes >= 3 ? 'cards' : 'list'
|
|
762
|
+
} else if (slideIndex > 0 && (layoutType === 'sechdr' || (nonTitleTextShapes === 0 && shapes.length <= 2))) {
|
|
763
|
+
result.inferredLayout = 'section'
|
|
764
|
+
} else if (quoteSignal && largeCardShapes <= 1 && nonTitleTextShapes <= 2) {
|
|
765
|
+
result.inferredLayout = 'quote'
|
|
766
|
+
result.variant = 'editorial'
|
|
767
|
+
} else if (numericKpiShapes >= 2) {
|
|
768
|
+
result.inferredLayout = 'kpi'
|
|
769
|
+
result.variant = 'grid'
|
|
770
|
+
} else if (hasTopSummaryBanner && lowerPillars.length >= 2 && lowerPillars.length <= 4) {
|
|
771
|
+
result.inferredLayout = 'cards'
|
|
772
|
+
result.variant = 'exec-summary'
|
|
773
|
+
} else if (ellipseCircles >= 1 && largeCardShapes >= 3 && largeCardShapes <= 5) {
|
|
774
|
+
result.inferredLayout = 'process'
|
|
775
|
+
result.variant = 'flywheel'
|
|
776
|
+
} else if (largeCardShapes === 4 && shapeCenters.length === 4) {
|
|
777
|
+
const xs = shapeCenters.map((c) => c.x).sort((a, b) => a - b)
|
|
778
|
+
const ys = shapeCenters.map((c) => c.y).sort((a, b) => a - b)
|
|
779
|
+
const is2x2 = xs[2] - xs[1] > 0.15 && ys[2] - ys[1] > 0.15
|
|
780
|
+
result.inferredLayout = is2x2 ? 'matrix' : 'cards'
|
|
781
|
+
result.variant = is2x2 ? '2x2' : 'bento'
|
|
782
|
+
} else if (largeCardShapes >= 3) {
|
|
783
|
+
const ySpread = Math.max(...shapeCenters.map((c) => c.y)) - Math.min(...shapeCenters.map((c) => c.y))
|
|
784
|
+
if (ySpread < 0.12) {
|
|
785
|
+
const avgH = cardRects.reduce((s, r) => s + r.h, 0) / Math.max(1, cardRects.length)
|
|
786
|
+
if (horizontalAxisLines >= 1 || /\bQ[1-4]\b|20\d{2}|阶段|里程碑|timeline|phase/i.test(combinedSignal)) {
|
|
787
|
+
result.inferredLayout = 'process'
|
|
788
|
+
result.variant = horizontalAxisLines >= 1 ? 'timeline' : 'steps'
|
|
789
|
+
} else if (avgH >= 0.36) {
|
|
790
|
+
result.inferredLayout = 'cards'
|
|
791
|
+
result.variant = 'pillars'
|
|
792
|
+
} else {
|
|
793
|
+
result.inferredLayout = 'process'
|
|
794
|
+
result.variant = 'steps'
|
|
795
|
+
}
|
|
796
|
+
} else {
|
|
797
|
+
result.inferredLayout = 'cards'
|
|
798
|
+
result.variant = 'bento'
|
|
799
|
+
}
|
|
800
|
+
} else if (largeCardShapes === 2) {
|
|
801
|
+
result.inferredLayout = 'comparison'
|
|
802
|
+
result.variant = /问题|痛点|风险|整改|应对|issue|mitigation/i.test(combinedSignal) ? 'issue-action' : 'versus'
|
|
803
|
+
} else if (titleFound && nonTitleTextShapes === 0 && titleText.length >= 16) {
|
|
804
|
+
result.inferredLayout = 'statement'
|
|
805
|
+
} else {
|
|
806
|
+
result.inferredLayout = 'bullets'
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
if (titleText) result.titleSample = titleText
|
|
810
|
+
} catch { /* ignore slide analysis error */ }
|
|
811
|
+
|
|
812
|
+
return result
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
// ---------------------------------------------------------------------------
|
|
816
|
+
// Background, Logo, Theme & Palette Extraction
|
|
817
|
+
// ---------------------------------------------------------------------------
|
|
818
|
+
|
|
819
|
+
function resolveBackgroundHex(bg, pres, slideOrLayout, themeScheme, colorMap, getGradFn, xmlStr = '') {
|
|
820
|
+
if (bg && typeof bg === 'object') {
|
|
821
|
+
let rawColor = null
|
|
822
|
+
if (bg.kind === 'solid' && typeof bg.color === 'string') {
|
|
823
|
+
rawColor = bg.color
|
|
824
|
+
} else if (bg.kind === 'gradient' && typeof getGradFn === 'function') {
|
|
825
|
+
try {
|
|
826
|
+
const grad = slideOrLayout !== undefined ? getGradFn(pres, slideOrLayout) : null
|
|
827
|
+
rawColor = grad?.stops?.[0]?.color ?? null
|
|
828
|
+
} catch {
|
|
829
|
+
try {
|
|
830
|
+
const grad = getGradFn(slideOrLayout)
|
|
831
|
+
rawColor = grad?.stops?.[0]?.color ?? null
|
|
832
|
+
} catch { /* ignore */ }
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
if (rawColor && typeof rawColor === 'string') {
|
|
836
|
+
if (/^#?[\da-f]{6}$/i.test(rawColor.trim())) {
|
|
837
|
+
return normalizeHex(rawColor.trim(), '') || null
|
|
838
|
+
}
|
|
839
|
+
if (rawColor.startsWith('scheme:') && themeScheme) {
|
|
840
|
+
const slot = rawColor.slice(7).trim()
|
|
841
|
+
const resolved = lookupSchemeHex(slot, themeScheme, colorMap)
|
|
842
|
+
if (resolved) return resolved
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
if (xmlStr) {
|
|
847
|
+
return resolveBackgroundFromXml(xmlStr, themeScheme, colorMap)
|
|
848
|
+
}
|
|
849
|
+
return null
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
function isValidRasterLogo(bytes, format) {
|
|
853
|
+
if (!bytes || bytes.byteLength < 24 || bytes.byteLength > MAX_LOGO_BYTES) return false
|
|
854
|
+
const buf = Buffer.isBuffer(bytes) ? bytes : Buffer.from(bytes)
|
|
855
|
+
if (format === 'png') {
|
|
856
|
+
if (!buf.subarray(0, 8).equals(Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]))) return false
|
|
857
|
+
if (buf.length < 45 || buf.toString('ascii', 12, 16) !== 'IHDR') return false
|
|
858
|
+
const width = buf.readUInt32BE(16)
|
|
859
|
+
const height = buf.readUInt32BE(20)
|
|
860
|
+
if (!width || !height || width > 8000 || height > 8000) return false
|
|
861
|
+
let offset = 8
|
|
862
|
+
let ended = false
|
|
863
|
+
const compressed = []
|
|
864
|
+
while (offset + 12 <= buf.length) {
|
|
865
|
+
const length = buf.readUInt32BE(offset)
|
|
866
|
+
const type = buf.toString('ascii', offset + 4, offset + 8)
|
|
867
|
+
if (offset + length + 12 > buf.length) return false
|
|
868
|
+
if (type === 'IDAT') compressed.push(buf.subarray(offset + 8, offset + 8 + length))
|
|
869
|
+
if (type === 'IEND') { ended = true; break }
|
|
870
|
+
offset += length + 12
|
|
871
|
+
}
|
|
872
|
+
if (!ended || compressed.length === 0) return false
|
|
873
|
+
try {
|
|
874
|
+
inflateSync(Buffer.concat(compressed), { maxOutputLength: 32 * 1024 * 1024 })
|
|
875
|
+
return true
|
|
876
|
+
} catch {
|
|
877
|
+
return false
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
if (format === 'jpeg') {
|
|
881
|
+
if (buf[0] !== 0xff || buf[1] !== 0xd8) return false
|
|
882
|
+
if (!buf.subarray(-2).equals(Buffer.from([0xff, 0xd9]))) return false
|
|
883
|
+
return true
|
|
884
|
+
}
|
|
885
|
+
return false
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
function aspectLabel(widthEmu, heightEmu) {
|
|
889
|
+
if (!widthEmu || !heightEmu) return '16:9'
|
|
890
|
+
const ratio = widthEmu / heightEmu
|
|
891
|
+
if (Math.abs(ratio - 16 / 9) < 0.04) return '16:9'
|
|
892
|
+
if (Math.abs(ratio - 16 / 10) < 0.04) return '16:10'
|
|
893
|
+
if (Math.abs(ratio - 4 / 3) < 0.04) return '4:3'
|
|
894
|
+
return ratio.toFixed(2) + ':1'
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
function detectFullBleedShapeBg(lib, pres, shapes, slideW, slideH, themeScheme, colorMap) {
|
|
898
|
+
if (!Array.isArray(shapes) || !slideW || !slideH) return null
|
|
899
|
+
for (const shape of shapes) {
|
|
900
|
+
try {
|
|
901
|
+
if (lib.hasShapeImage(shape)) continue
|
|
902
|
+
const bounds = lib.getShapeBounds(shape)
|
|
903
|
+
if (!bounds) continue
|
|
904
|
+
if (bounds.w >= slideW * 0.78 && bounds.h >= slideH * 0.78 && bounds.x <= slideW * 0.12 && bounds.y <= slideH * 0.12) {
|
|
905
|
+
const fill = resolveShapeFillSafe(lib, pres, shape, themeScheme, colorMap)
|
|
906
|
+
if (fill && /^#[\da-f]{6}$/i.test(fill)) return fill.toUpperCase()
|
|
907
|
+
}
|
|
908
|
+
} catch { /* ignore individual malformed shape */ }
|
|
909
|
+
}
|
|
910
|
+
return null
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
function extractCandidateLogo(lib, pres, slides, layouts, slideW, slideH) {
|
|
914
|
+
const pools = []
|
|
915
|
+
for (const layout of layouts.slice(0, 6)) {
|
|
916
|
+
try { pools.push({ source: 'master', shapes: flattenShapes(lib, lib.getSlideMasterShapes(pres, layout)) }) } catch { /* ignore */ }
|
|
917
|
+
try { pools.push({ source: 'layout', shapes: flattenShapes(lib, lib.getSlideLayoutShapes(pres, layout)) }) } catch { /* ignore */ }
|
|
918
|
+
}
|
|
919
|
+
if (slides[1]) {
|
|
920
|
+
try { pools.push({ source: 'content-slide', shapes: flattenShapes(lib, lib.getSlideShapes(slides[1])) }) } catch { /* ignore */ }
|
|
921
|
+
}
|
|
922
|
+
if (slides[0]) {
|
|
923
|
+
try { pools.push({ source: 'cover-slide', shapes: flattenShapes(lib, lib.getSlideShapes(slides[0])) }) } catch { /* ignore */ }
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
let best = null
|
|
927
|
+
for (const pool of pools) {
|
|
928
|
+
for (const shape of pool.shapes ?? []) {
|
|
929
|
+
try {
|
|
930
|
+
if (!lib.hasShapeImage(shape)) continue
|
|
931
|
+
const rawFmt = String(lib.getShapeImageFormat(shape) ?? '').toLowerCase()
|
|
932
|
+
const fmt = rawFmt === 'jpg' ? 'jpeg' : rawFmt
|
|
933
|
+
if (fmt !== 'png' && fmt !== 'jpeg') continue
|
|
934
|
+
const bounds = getBoundsSafe(lib, shape)
|
|
935
|
+
if (!bounds || bounds.w <= 0 || bounds.h <= 0) continue
|
|
936
|
+
|
|
937
|
+
const nameText = [
|
|
938
|
+
lib.getShapeName?.(shape),
|
|
939
|
+
lib.getShapeDescription?.(shape),
|
|
940
|
+
lib.getShapeAltTitle?.(shape),
|
|
941
|
+
].filter(Boolean).join(' ')
|
|
942
|
+
const namedLogo = /logo|brand|徽|标|院徽|校徽|台标/i.test(nameText)
|
|
943
|
+
const maxW = namedLogo ? slideW * 0.45 : slideW * 0.28
|
|
944
|
+
const maxH = namedLogo ? slideH * 0.35 : slideH * 0.20
|
|
945
|
+
if (bounds.w > maxW || bounds.h > maxH) continue
|
|
946
|
+
|
|
947
|
+
const nearCornerBand = bounds.y <= slideH * 0.24 || (bounds.y + bounds.h) >= slideH * 0.76
|
|
948
|
+
if (!namedLogo && (pool.source === 'cover-slide' || pool.source === 'content-slide') && !nearCornerBand) continue
|
|
949
|
+
|
|
950
|
+
const bytes = lib.getShapeImageBytes(shape)
|
|
951
|
+
if (!isValidRasterLogo(bytes, fmt)) continue
|
|
952
|
+
|
|
953
|
+
const originWeight = pool.source === 'master' ? 45 : pool.source === 'layout' ? 30 : pool.source === 'content-slide' ? 20 : 12
|
|
954
|
+
const score = (namedLogo ? 100 : 0) + originWeight + (nearCornerBand ? 15 : 0)
|
|
955
|
+
if (!best || score > best.score) {
|
|
956
|
+
const b64 = Buffer.from(bytes).toString('base64')
|
|
957
|
+
best = { score, source: pool.source, dataUri: `data:image/${fmt};base64,${b64}` }
|
|
958
|
+
}
|
|
959
|
+
} catch { /* ignore shape read error */ }
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
return best ?? null
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
function safeReadXmlPart(lib, pres, partName) {
|
|
966
|
+
if (!partName) return ''
|
|
967
|
+
try {
|
|
968
|
+
const raw = lib.readPackagePart?.(pres, partName)
|
|
969
|
+
return raw ? Buffer.from(raw).toString('utf8') : ''
|
|
970
|
+
} catch {
|
|
971
|
+
return ''
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
function resolveAnySlideBg(lib, pres, slide, widthEmu, heightEmu, rawTheme, fallbackColorMap) {
|
|
976
|
+
if (!slide) return null
|
|
977
|
+
const sColorMap = (() => { try { return lib.getEffectiveColorMap(slide) } catch { return fallbackColorMap } })() ?? fallbackColorMap
|
|
978
|
+
const slideXml = (() => { try { return lib.getSlideXmlString?.(slide) ?? '' } catch { return '' } })()
|
|
979
|
+
let bg = null
|
|
980
|
+
try {
|
|
981
|
+
bg = resolveBackgroundHex(
|
|
982
|
+
lib.getSlideBackground(slide),
|
|
983
|
+
pres,
|
|
984
|
+
slide,
|
|
985
|
+
rawTheme,
|
|
986
|
+
sColorMap,
|
|
987
|
+
lib.getSlideBackgroundGradientFill,
|
|
988
|
+
slideXml,
|
|
989
|
+
)
|
|
990
|
+
} catch { /* ignore */ }
|
|
991
|
+
if (!bg) {
|
|
992
|
+
try {
|
|
993
|
+
const sLayout = lib.getSlideLayout(slide)
|
|
994
|
+
if (sLayout) {
|
|
995
|
+
const layoutXml = safeReadXmlPart(lib, pres, lib.getSlideLayoutPartName?.(sLayout))
|
|
996
|
+
bg = resolveBackgroundHex(
|
|
997
|
+
lib.getSlideLayoutBackground(sLayout),
|
|
998
|
+
pres,
|
|
999
|
+
sLayout,
|
|
1000
|
+
rawTheme,
|
|
1001
|
+
sColorMap,
|
|
1002
|
+
lib.getSlideLayoutBackgroundGradientFill,
|
|
1003
|
+
layoutXml,
|
|
1004
|
+
) || detectFullBleedShapeBg(lib, pres, lib.getSlideLayoutShapes(pres, sLayout), widthEmu, heightEmu, rawTheme, sColorMap)
|
|
1005
|
+
}
|
|
1006
|
+
} catch { /* ignore */ }
|
|
1007
|
+
}
|
|
1008
|
+
if (!bg) {
|
|
1009
|
+
try {
|
|
1010
|
+
bg = detectFullBleedShapeBg(lib, pres, lib.getSlideShapes(slide), widthEmu, heightEmu, rawTheme, sColorMap)
|
|
1011
|
+
} catch { /* ignore */ }
|
|
1012
|
+
}
|
|
1013
|
+
return bg
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
/**
|
|
1017
|
+
* 只读解析外部 .pptx 文件或字节流,提取并净化主题色板、中英文字体、母版 Logo、骨架特征与逐页版式分布。
|
|
1018
|
+
*/
|
|
1019
|
+
export async function absorbPptx(options = {}) {
|
|
1020
|
+
options.signal?.throwIfAborted()
|
|
1021
|
+
const cwd = resolve(String(options.cwd ?? '.'))
|
|
1022
|
+
const extractLogo = options.extractLogo !== false
|
|
1023
|
+
|
|
1024
|
+
let bytes
|
|
1025
|
+
let resolvedPath
|
|
1026
|
+
if (options.bytes instanceof Uint8Array) {
|
|
1027
|
+
bytes = options.bytes
|
|
1028
|
+
if (typeof options.pptxPath === 'string' && options.pptxPath.trim()) {
|
|
1029
|
+
resolvedPath = resolve(cwd, options.pptxPath.trim())
|
|
1030
|
+
}
|
|
1031
|
+
} else {
|
|
1032
|
+
if (typeof options.pptxPath !== 'string' || !options.pptxPath.trim()) {
|
|
1033
|
+
fail('请提供参考 .pptx 文件路径 pptxPath', 'pptxPath is required')
|
|
1034
|
+
}
|
|
1035
|
+
resolvedPath = resolve(cwd, options.pptxPath.trim())
|
|
1036
|
+
let stat
|
|
1037
|
+
try {
|
|
1038
|
+
stat = lstatSync(resolvedPath)
|
|
1039
|
+
} catch {
|
|
1040
|
+
fail('找不到参考 PPTX 文件:' + resolvedPath, 'Reference PPTX file not found: ' + resolvedPath)
|
|
1041
|
+
}
|
|
1042
|
+
if (!stat.isFile() || stat.isSymbolicLink()) {
|
|
1043
|
+
fail('参考 PPTX 必须是普通文件(不支持目录或符号链接)', 'Reference PPTX must be a regular file')
|
|
1044
|
+
}
|
|
1045
|
+
if (stat.size < 22 || stat.size > MAX_PPTX_BYTES) {
|
|
1046
|
+
fail('参考 PPTX 文件大小需在 64 MiB 以内', 'Reference PPTX must be up to 64 MiB')
|
|
1047
|
+
}
|
|
1048
|
+
bytes = readFileSync(resolvedPath)
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
if (!bytes || bytes.byteLength < 22 || bytes.byteLength > MAX_PPTX_BYTES || bytes[0] !== 0x50 || bytes[1] !== 0x4b) {
|
|
1052
|
+
fail('文件不是有效的 .pptx 压缩包', 'Invalid .pptx archive')
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
options.signal?.throwIfAborted()
|
|
1056
|
+
let lib
|
|
1057
|
+
try {
|
|
1058
|
+
lib = await import('@office-kit/pptx')
|
|
1059
|
+
} catch (error) {
|
|
1060
|
+
fail('解析参考 PPTX 需要 @office-kit/pptx@0.21.0。独立技能请在技能目录运行 npm install --ignore-scripts。' + error.message)
|
|
1061
|
+
}
|
|
1062
|
+
options.signal?.throwIfAborted()
|
|
1063
|
+
|
|
1064
|
+
let pres
|
|
1065
|
+
try {
|
|
1066
|
+
pres = await lib.loadPresentation(bytes)
|
|
1067
|
+
} catch (error) {
|
|
1068
|
+
fail('无法解析参考 PPTX 结构:' + error.message, 'Failed to parse PPTX: ' + error.message)
|
|
1069
|
+
}
|
|
1070
|
+
options.signal?.throwIfAborted()
|
|
1071
|
+
|
|
1072
|
+
const slides = lib.getSlides(pres)
|
|
1073
|
+
const slideCount = slides.length
|
|
1074
|
+
const rawSize = lib.getSlideSize(pres)
|
|
1075
|
+
const widthEmu = rawSize?.width ?? 12192000
|
|
1076
|
+
const heightEmu = rawSize?.height ?? 6858000
|
|
1077
|
+
const slideSize = {
|
|
1078
|
+
width: Number((widthEmu / EMU_PER_INCH).toFixed(3)),
|
|
1079
|
+
height: Number((heightEmu / EMU_PER_INCH).toFixed(3)),
|
|
1080
|
+
widthEmu,
|
|
1081
|
+
heightEmu,
|
|
1082
|
+
aspect: aspectLabel(widthEmu, heightEmu),
|
|
1083
|
+
}
|
|
1084
|
+
|
|
1085
|
+
const rawTheme = lib.getPresentationTheme(pres) ?? {}
|
|
1086
|
+
const rawFonts = lib.getPresentationFonts(pres) ?? {}
|
|
1087
|
+
const layouts = lib.getSlideLayouts(pres) ?? []
|
|
1088
|
+
const sampleSlide = slides[1] ?? slides[0] ?? null
|
|
1089
|
+
const colorMap = sampleSlide ? lib.getEffectiveColorMap(sampleSlide) : null
|
|
1090
|
+
|
|
1091
|
+
let sampleLayout = null
|
|
1092
|
+
if (sampleSlide) {
|
|
1093
|
+
try { sampleLayout = lib.getSlideLayout(sampleSlide) } catch { /* ignore */ }
|
|
1094
|
+
}
|
|
1095
|
+
const firstLayout = sampleLayout ?? layouts[0] ?? null
|
|
1096
|
+
let masterPartName = null
|
|
1097
|
+
if (sampleSlide) {
|
|
1098
|
+
try { masterPartName = lib.getSlideMasterPartName?.(sampleSlide) } catch { /* ignore */ }
|
|
1099
|
+
}
|
|
1100
|
+
if (!masterPartName) {
|
|
1101
|
+
try { masterPartName = lib.getSlideMasterPartNames?.(pres)?.[0] ?? null } catch { /* ignore */ }
|
|
1102
|
+
}
|
|
1103
|
+
const masterXml = safeReadXmlPart(lib, pres, masterPartName)
|
|
1104
|
+
|
|
1105
|
+
let masterBg = null
|
|
1106
|
+
if (firstLayout) {
|
|
1107
|
+
try {
|
|
1108
|
+
masterBg = resolveBackgroundHex(
|
|
1109
|
+
lib.getSlideMasterBackground(pres, firstLayout),
|
|
1110
|
+
pres,
|
|
1111
|
+
firstLayout,
|
|
1112
|
+
rawTheme,
|
|
1113
|
+
colorMap,
|
|
1114
|
+
lib.getSlideMasterBackgroundGradientFill,
|
|
1115
|
+
masterXml,
|
|
1116
|
+
)
|
|
1117
|
+
} catch { /* ignore */ }
|
|
1118
|
+
if (!masterBg) {
|
|
1119
|
+
try {
|
|
1120
|
+
masterBg = detectFullBleedShapeBg(lib, pres, lib.getSlideMasterShapes(pres, firstLayout), widthEmu, heightEmu, rawTheme, colorMap)
|
|
1121
|
+
} catch { /* ignore */ }
|
|
1122
|
+
}
|
|
1123
|
+
} else if (masterXml) {
|
|
1124
|
+
masterBg = resolveBackgroundFromXml(masterXml, rawTheme, colorMap)
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1127
|
+
const coverSlideBg = slides[0] ? resolveAnySlideBg(lib, pres, slides[0], widthEmu, heightEmu, rawTheme, colorMap) : null
|
|
1128
|
+
let contentSlideBg = sampleSlide ? resolveAnySlideBg(lib, pres, sampleSlide, widthEmu, heightEmu, rawTheme, colorMap) : null
|
|
1129
|
+
if (!contentSlideBg && coverSlideBg && slides.length === 1) {
|
|
1130
|
+
contentSlideBg = coverSlideBg
|
|
1131
|
+
}
|
|
1132
|
+
|
|
1133
|
+
let bodyTextColor = null
|
|
1134
|
+
if (sampleSlide) {
|
|
1135
|
+
try { bodyTextColor = lib.resolveDeckBodyTextColor(sampleSlide) } catch { /* ignore */ }
|
|
1136
|
+
}
|
|
1137
|
+
|
|
1138
|
+
// Scan shape fills across master + up to 8 slides to discover real chromatic brand accents
|
|
1139
|
+
// (covers Office default #4472C4/#156082 AND corporate templates where accent1 is charcoal/navy while brand color lives on shapes)
|
|
1140
|
+
let shapeAccentCandidate = null
|
|
1141
|
+
let shapeSecondaryCandidate = null
|
|
1142
|
+
const rawAccent1 = rawTheme.accent1 ? normalizeHex(rawTheme.accent1, '') : ''
|
|
1143
|
+
const accent1IsWeakOrDefault = !rawAccent1 || OFFICE_DEFAULT_ACCENTS.has(rawAccent1) || hexToHsl(rawAccent1).s < 0.14
|
|
1144
|
+
{
|
|
1145
|
+
const colorCounts = new Map()
|
|
1146
|
+
const inspectPool = []
|
|
1147
|
+
if (firstLayout) {
|
|
1148
|
+
try { inspectPool.push(...flattenShapes(lib, lib.getSlideMasterShapes(pres, firstLayout))) } catch { /* ignore */ }
|
|
1149
|
+
}
|
|
1150
|
+
for (const slide of slides.slice(0, 8)) {
|
|
1151
|
+
try { inspectPool.push(...flattenShapes(lib, lib.getSlideShapes(slide))) } catch { /* ignore */ }
|
|
1152
|
+
}
|
|
1153
|
+
const effectiveBg = (contentSlideBg ?? masterBg ?? '#FFFFFF').toUpperCase()
|
|
1154
|
+
for (const shape of inspectPool) {
|
|
1155
|
+
try {
|
|
1156
|
+
const b = getBoundsSafe(lib, shape)
|
|
1157
|
+
if (b && b.w >= widthEmu * 0.78 && b.h >= heightEmu * 0.78) continue
|
|
1158
|
+
const hex = resolveShapeFillSafe(lib, pres, shape, rawTheme, colorMap)
|
|
1159
|
+
if (!hex || !/^#[\da-f]{6}$/i.test(hex)) continue
|
|
1160
|
+
const norm = hex.toUpperCase()
|
|
1161
|
+
if (norm === '#FFFFFF' || norm === '#000000' || norm === effectiveBg || norm === coverSlideBg) continue
|
|
1162
|
+
const hsl = hexToHsl(norm)
|
|
1163
|
+
// Ignore very pale surface tints (L > 0.90) and near-neutral greys (S < 0.10) when hunting brand accents
|
|
1164
|
+
if (hsl.l > 0.90 || hsl.s < 0.10) continue
|
|
1165
|
+
colorCounts.set(norm, (colorCounts.get(norm) ?? 0) + 1)
|
|
1166
|
+
} catch { /* ignore */ }
|
|
1167
|
+
}
|
|
1168
|
+
const ranked = [...colorCounts.entries()].sort((a, b) => b[1] - a[1])
|
|
1169
|
+
if (accent1IsWeakOrDefault && ranked[0]) {
|
|
1170
|
+
shapeAccentCandidate = ranked[0][0]
|
|
1171
|
+
}
|
|
1172
|
+
const primaryRef = shapeAccentCandidate || rawAccent1
|
|
1173
|
+
if (primaryRef && ranked.length > 0) {
|
|
1174
|
+
const pH = hexToHsl(primaryRef).h
|
|
1175
|
+
const secHit = ranked.find(([hex]) => {
|
|
1176
|
+
const d = Math.abs(hexToHsl(hex).h - pH) % 360
|
|
1177
|
+
return (d > 180 ? 360 - d : d) >= 26
|
|
1178
|
+
})
|
|
1179
|
+
if (secHit) shapeSecondaryCandidate = secHit[0]
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
|
|
1183
|
+
const extractedPalette = {}
|
|
1184
|
+
for (const key of ['dark1', 'light1', 'dark2', 'light2', 'accent1', 'accent2', 'accent3', 'accent4', 'accent5', 'accent6', 'hyperlink', 'followedHyperlink']) {
|
|
1185
|
+
if (typeof rawTheme[key] === 'string' && rawTheme[key]) {
|
|
1186
|
+
extractedPalette[key] = normalizeHex(rawTheme[key], rawTheme[key])
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
if (masterBg) extractedPalette.masterBg = masterBg
|
|
1190
|
+
if (coverSlideBg) extractedPalette.coverSlideBg = coverSlideBg
|
|
1191
|
+
if (contentSlideBg) extractedPalette.contentSlideBg = contentSlideBg
|
|
1192
|
+
if (bodyTextColor) extractedPalette.bodyTextColor = normalizeHex(bodyTextColor, bodyTextColor)
|
|
1193
|
+
|
|
1194
|
+
const extractedFonts = {}
|
|
1195
|
+
for (const key of ['majorLatin', 'majorEastAsian', 'minorLatin', 'minorEastAsian']) {
|
|
1196
|
+
if (typeof rawFonts[key] === 'string' && rawFonts[key].trim()) {
|
|
1197
|
+
extractedFonts[key] = rawFonts[key].trim()
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1200
|
+
|
|
1201
|
+
const sanitized = sanitizeAbsorbedTheme({
|
|
1202
|
+
palette: extractedPalette,
|
|
1203
|
+
fonts: extractedFonts,
|
|
1204
|
+
masterBg: masterBg ?? undefined,
|
|
1205
|
+
coverSlideBg: coverSlideBg ?? undefined,
|
|
1206
|
+
contentSlideBg: contentSlideBg ?? masterBg ?? undefined,
|
|
1207
|
+
textColor: bodyTextColor ?? undefined,
|
|
1208
|
+
...(shapeAccentCandidate ? { brandPrimary: shapeAccentCandidate } : {}),
|
|
1209
|
+
...(shapeSecondaryCandidate ? { brandSecondary: shapeSecondaryCandidate } : {}),
|
|
1210
|
+
})
|
|
1211
|
+
|
|
1212
|
+
const logoMatch = extractLogo ? extractCandidateLogo(lib, pres, slides, layouts, widthEmu, heightEmu) : null
|
|
1213
|
+
const logoDataUri = logoMatch?.dataUri ?? null
|
|
1214
|
+
if (
|
|
1215
|
+
logoMatch?.source === 'cover-slide' &&
|
|
1216
|
+
!sanitized.dark &&
|
|
1217
|
+
coverSlideBg &&
|
|
1218
|
+
relativeLuminance(coverSlideBg) < 0.25
|
|
1219
|
+
) {
|
|
1220
|
+
sanitized.warnings.push('母版 Logo 提取自深色封面页;若为反白透明图标,应用后建议核对浅色正文页右上角可见度。')
|
|
1221
|
+
}
|
|
1222
|
+
|
|
1223
|
+
let coreTitle = ''
|
|
1224
|
+
try {
|
|
1225
|
+
const props = lib.getCoreProperties(pres)
|
|
1226
|
+
if (typeof props?.title === 'string' && props.title.trim() && !/^PowerPoint 演示文稿$|^Presentation\d*$/i.test(props.title.trim())) {
|
|
1227
|
+
coreTitle = props.title.trim().slice(0, 100)
|
|
1228
|
+
}
|
|
1229
|
+
} catch { /* ignore */ }
|
|
1230
|
+
|
|
1231
|
+
const sanitizedBrand = {
|
|
1232
|
+
...sanitized.sanitizedBrand,
|
|
1233
|
+
...(coreTitle ? { name: coreTitle } : {}),
|
|
1234
|
+
...(logoDataUri ? { logo: logoDataUri } : {}),
|
|
1235
|
+
}
|
|
1236
|
+
const isOfficeDefaultFont = (f) =>
|
|
1237
|
+
/^(?:SimSun|NSimSun|宋体|新宋体|FangSong|仿宋|Impact|Comic Sans MS)$/i.test(f) ||
|
|
1238
|
+
(/^(?:Calibri|Calibri Light|Aptos|Aptos Display)$/i.test(f) &&
|
|
1239
|
+
!extractedFonts.majorEastAsian &&
|
|
1240
|
+
!extractedFonts.minorEastAsian)
|
|
1241
|
+
|
|
1242
|
+
if (sanitizedBrand.fontFamily && isOfficeDefaultFont(sanitizedBrand.fontFamily)) {
|
|
1243
|
+
delete sanitizedBrand.fontFamily
|
|
1244
|
+
}
|
|
1245
|
+
if (sanitizedBrand.headingFont && isOfficeDefaultFont(sanitizedBrand.headingFont)) {
|
|
1246
|
+
delete sanitizedBrand.headingFont
|
|
1247
|
+
}
|
|
1248
|
+
|
|
1249
|
+
const layoutTypes = {}
|
|
1250
|
+
for (const layout of layouts) {
|
|
1251
|
+
try {
|
|
1252
|
+
const t = lib.getSlideLayoutType(layout) || lib.getSlideLayoutName(layout) || 'custom'
|
|
1253
|
+
layoutTypes[t] = (layoutTypes[t] ?? 0) + 1
|
|
1254
|
+
} catch { /* ignore */ }
|
|
1255
|
+
}
|
|
1256
|
+
let chartCount = 0
|
|
1257
|
+
let tableCount = 0
|
|
1258
|
+
let mediaPartCount = 0
|
|
1259
|
+
try { chartCount = lib.getAllCharts(pres).length } catch { /* ignore */ }
|
|
1260
|
+
try { tableCount = lib.getAllTables(pres).length } catch { /* ignore */ }
|
|
1261
|
+
try { mediaPartCount = lib.getMediaParts(pres).length } catch { /* ignore */ }
|
|
1262
|
+
|
|
1263
|
+
const layoutSummary = {
|
|
1264
|
+
layoutCount: layouts.length,
|
|
1265
|
+
slideCount,
|
|
1266
|
+
chartCount,
|
|
1267
|
+
tableCount,
|
|
1268
|
+
mediaPartCount,
|
|
1269
|
+
hasLogo: Boolean(logoDataUri),
|
|
1270
|
+
layoutTypes,
|
|
1271
|
+
}
|
|
1272
|
+
|
|
1273
|
+
// Deep Skeleton Extraction
|
|
1274
|
+
let masterShapes = []
|
|
1275
|
+
let layoutShapes = []
|
|
1276
|
+
let sampleSlideShapes = []
|
|
1277
|
+
if (firstLayout) {
|
|
1278
|
+
try { masterShapes = lib.getSlideMasterShapes(pres, firstLayout) ?? [] } catch { /* ignore */ }
|
|
1279
|
+
try { layoutShapes = lib.getSlideLayoutShapes(pres, firstLayout) ?? [] } catch { /* ignore */ }
|
|
1280
|
+
}
|
|
1281
|
+
if (sampleSlide) {
|
|
1282
|
+
try { sampleSlideShapes = lib.getSlideShapes(sampleSlide) ?? [] } catch { /* ignore */ }
|
|
1283
|
+
}
|
|
1284
|
+
|
|
1285
|
+
const rawSkeleton = extractSkeletonFromShapes(lib, masterShapes, layoutShapes, sampleSlideShapes, widthEmu, heightEmu)
|
|
1286
|
+
const recommendedChrome = inferChromeStyle(rawSkeleton, extractedPalette, extractedFonts, sanitized.dark, sanitized.recommendedTheme)
|
|
1287
|
+
const extractedSkeleton = {
|
|
1288
|
+
cornerStyle: rawSkeleton.cornerStyle,
|
|
1289
|
+
hasTopBanner: rawSkeleton.hasTopBanner,
|
|
1290
|
+
hasSideSpine: rawSkeleton.hasSideSpine,
|
|
1291
|
+
masterShapeCount: rawSkeleton.masterShapeCount,
|
|
1292
|
+
}
|
|
1293
|
+
|
|
1294
|
+
const slideSkeleton = slides.slice(0, 60).map((slide, idx) =>
|
|
1295
|
+
analyzeSlideLayout(lib, slide, idx, slides.length, widthEmu, heightEmu)
|
|
1296
|
+
)
|
|
1297
|
+
|
|
1298
|
+
// Synthesize human-readable Narrative & Style Recipe Profile
|
|
1299
|
+
const archetypeCounts = {}
|
|
1300
|
+
let diagramSlideCount = 0
|
|
1301
|
+
let detectedTableStyle = null
|
|
1302
|
+
for (const entry of slideSkeleton) {
|
|
1303
|
+
const key = entry.variant ? `${entry.inferredLayout}:${entry.variant}` : entry.inferredLayout
|
|
1304
|
+
archetypeCounts[key] = (archetypeCounts[key] ?? 0) + 1
|
|
1305
|
+
if (['kpi', 'cards', 'comparison', 'matrix', 'process', 'gantt', 'architecture', 'harvey', 'tam', 'org', 'chart', 'chart-split', 'waterfall', 'table'].includes(entry.inferredLayout)) {
|
|
1306
|
+
diagramSlideCount += 1
|
|
1307
|
+
}
|
|
1308
|
+
if (!detectedTableStyle && entry.tableStyle) detectedTableStyle = entry.tableStyle
|
|
1309
|
+
}
|
|
1310
|
+
const recommendedTableStyle = detectedTableStyle || (recommendedChrome === 'academic-minimal' ? 'booktabs' : 'consulting')
|
|
1311
|
+
const narrativeProfile = {
|
|
1312
|
+
rhythmSummary: slideSkeleton.slice(0, 10).map((s) => `P${s.slideNumber}:${s.inferredLayout}${s.variant ? `[${s.variant}]` : ''}`).join(' → '),
|
|
1313
|
+
archetypeCounts,
|
|
1314
|
+
diagramRatio: slideCount > 0 ? Number((diagramSlideCount / slideCount).toFixed(2)) : 0,
|
|
1315
|
+
hasInvertedCover: sanitized.sanitizedTokens.coverMode === 'inverted-accent',
|
|
1316
|
+
recommendedTableStyle,
|
|
1317
|
+
}
|
|
1318
|
+
|
|
1319
|
+
return {
|
|
1320
|
+
ok: true,
|
|
1321
|
+
...(resolvedPath ? { pptxPath: resolvedPath } : {}),
|
|
1322
|
+
slideCount,
|
|
1323
|
+
slideSize,
|
|
1324
|
+
extractedPalette,
|
|
1325
|
+
extractedFonts,
|
|
1326
|
+
sanitizedBrand,
|
|
1327
|
+
sanitizedTokens: sanitized.sanitizedTokens,
|
|
1328
|
+
recommendedTheme: sanitized.recommendedTheme,
|
|
1329
|
+
recommendedChrome,
|
|
1330
|
+
recommendedTableStyle,
|
|
1331
|
+
narrativeProfile,
|
|
1332
|
+
dark: sanitized.dark,
|
|
1333
|
+
warnings: sanitized.warnings,
|
|
1334
|
+
layoutSummary,
|
|
1335
|
+
extractedSkeleton,
|
|
1336
|
+
slideSkeleton,
|
|
1337
|
+
}
|
|
1338
|
+
}
|