dsh-ppt 0.22.1 → 0.23.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/README.en.md +33 -19
- package/README.md +34 -19
- package/docs/REFERENCE.en.md +3 -3
- package/docs/REFERENCE.zh.md +3 -3
- package/docs/USAGE.en.md +3 -3
- package/docs/USAGE.md +3 -3
- package/docs/WORKBENCH.md +2 -2
- package/docs/assets/intro/screen-en.webp +0 -0
- package/docs/assets/intro/screen-zh.webp +0 -0
- package/lib/client.js +543 -76
- package/lib/config.d.ts +1 -1
- package/lib/config.js +6 -0
- package/lib/tools.js +17 -9
- package/lib/types.d.ts +10 -3
- package/lib/workbench-language.js +4 -0
- package/lib/workbench.js +132 -17
- package/package.json +2 -2
- package/skills/dsh-ppt/SKILL.md +6 -6
- package/skills/dsh-ppt/package.json +17 -5
- package/skills/dsh-ppt/references/advanced.md +4 -3
- package/skills/dsh-ppt/references/syntax.md +1 -1
- package/skills/dsh-ppt/references/themes.md +10 -4
- package/skills/dsh-ppt/scripts/build-deck.mjs +4 -4
- package/skills/dsh-ppt/scripts/deck-absorb.mjs +419 -110
- package/skills/dsh-ppt/scripts/deck-advanced.mjs +22 -12
- package/skills/dsh-ppt/scripts/deck-core.mjs +4 -0
- package/skills/dsh-ppt/scripts/deck-director.mjs +343 -3
- package/skills/dsh-ppt/scripts/deck-layouts.mjs +116 -0
- package/skills/dsh-ppt/scripts/deck-themes.mjs +364 -13
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
import { lstatSync, readFileSync } from 'node:fs'
|
|
17
17
|
import { resolve } from 'node:path'
|
|
18
18
|
import { inflateSync } from 'node:zlib'
|
|
19
|
-
import { sanitizeAbsorbedTheme, normalizeHex, hexToHsl } from './deck-themes.mjs'
|
|
19
|
+
import { sanitizeAbsorbedTheme, normalizeHex, hexToHsl, relativeLuminance } from './deck-themes.mjs'
|
|
20
20
|
|
|
21
21
|
const MAX_PPTX_BYTES = 64 * 1024 * 1024
|
|
22
22
|
const MAX_LOGO_BYTES = 2 * 1024 * 1024
|
|
@@ -154,6 +154,13 @@ export function resolveColorModifiers(baseHex, mods) {
|
|
|
154
154
|
const [h, s, l] = rgbToHsl01(r, g, b)
|
|
155
155
|
const nextS = clamp01(step.kind === 'satMod' ? s * ratio : s + ratio)
|
|
156
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)
|
|
157
164
|
}
|
|
158
165
|
}
|
|
159
166
|
|
|
@@ -164,13 +171,34 @@ export function resolveColorModifiers(baseHex, mods) {
|
|
|
164
171
|
function parseXmlModifiers(innerXml) {
|
|
165
172
|
if (!innerXml) return []
|
|
166
173
|
const mods = []
|
|
167
|
-
const modRe = /<a:(lumMod|lumOff|tint|shade|satMod|satOff)\b[^>]*\bval=["'](-?\d+)["'][^>]*\/?>/g
|
|
174
|
+
const modRe = /<a:(lumMod|lumOff|tint|shade|satMod|satOff|hueMod|hueOff)\b[^>]*\bval=["'](-?\d+)["'][^>]*\/?>/g
|
|
168
175
|
for (const m of innerXml.matchAll(modRe)) {
|
|
169
176
|
mods.push({ kind: m[1], val: Number(m[2]) })
|
|
170
177
|
}
|
|
171
178
|
return mods
|
|
172
179
|
}
|
|
173
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
|
+
|
|
174
202
|
function lookupSchemeHex(slot, themeScheme, colorMap) {
|
|
175
203
|
if (!slot || !themeScheme) return null
|
|
176
204
|
const mapped = (colorMap && colorMap[slot]) || slot
|
|
@@ -183,18 +211,31 @@ function lookupSchemeHex(slot, themeScheme, colorMap) {
|
|
|
183
211
|
}
|
|
184
212
|
|
|
185
213
|
/**
|
|
186
|
-
* Parse <a:srgbClr
|
|
214
|
+
* Parse <a:srgbClr>, <a:schemeClr>, <a:sysClr>, or <a:prstClr> (including child modifiers) from an XML fragment.
|
|
187
215
|
*/
|
|
188
216
|
export function resolveXmlColorElement(xmlFragment, themeScheme, colorMap) {
|
|
189
217
|
if (!xmlFragment || typeof xmlFragment !== 'string') return null
|
|
190
|
-
const match = /<a:(srgbClr|schemeClr)\b
|
|
218
|
+
const match = /<a:(srgbClr|schemeClr|sysClr|prstClr)\b([^>]*)(?:\/>|>([\s\S]*?)<\/a:\1>)/.exec(xmlFragment)
|
|
191
219
|
if (!match) return null
|
|
192
|
-
const [, tag,
|
|
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() : ''
|
|
193
224
|
let baseHex = null
|
|
194
225
|
if (tag === 'srgbClr') {
|
|
195
226
|
baseHex = normalizeHex(val, '') || null
|
|
196
|
-
} else {
|
|
197
|
-
|
|
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)
|
|
198
239
|
}
|
|
199
240
|
if (!baseHex) return null
|
|
200
241
|
const mods = parseXmlModifiers(inner)
|
|
@@ -248,13 +289,43 @@ function resolveShapeFillSafe(lib, pres, shape, themeScheme, colorMap) {
|
|
|
248
289
|
// Master Slide Skeleton Extraction
|
|
249
290
|
// ---------------------------------------------------------------------------
|
|
250
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
|
+
|
|
251
322
|
function classifyCornerFromShapes(lib, shapes, slideW) {
|
|
252
323
|
let hasRounded = false
|
|
253
324
|
let hasSoft = false
|
|
254
325
|
let hasSharpRect = false
|
|
255
|
-
for (const shape of shapes) {
|
|
326
|
+
for (const shape of flattenShapes(lib, shapes)) {
|
|
256
327
|
try {
|
|
257
|
-
const bounds = lib
|
|
328
|
+
const bounds = getBoundsSafe(lib, shape)
|
|
258
329
|
if (!bounds) continue
|
|
259
330
|
const relW = bounds.w / slideW
|
|
260
331
|
if (relW < 0.08) continue
|
|
@@ -286,9 +357,9 @@ function classifyCornerFromShapes(lib, shapes, slideW) {
|
|
|
286
357
|
}
|
|
287
358
|
|
|
288
359
|
function extractSkeletonFromShapes(lib, masterShapes, layoutShapes, sampleSlideShapes, slideW, slideH) {
|
|
289
|
-
const mShapes =
|
|
290
|
-
const lShapes =
|
|
291
|
-
const sShapes =
|
|
360
|
+
const mShapes = flattenShapes(lib, masterShapes)
|
|
361
|
+
const lShapes = flattenShapes(lib, layoutShapes)
|
|
362
|
+
const sShapes = flattenShapes(lib, sampleSlideShapes)
|
|
292
363
|
const inspectShapes = [...mShapes, ...lShapes, ...(mShapes.length + lShapes.length === 0 ? sShapes : [])]
|
|
293
364
|
|
|
294
365
|
let hasTopBanner = false
|
|
@@ -299,7 +370,7 @@ function extractSkeletonFromShapes(lib, masterShapes, layoutShapes, sampleSlideS
|
|
|
299
370
|
for (const shape of inspectShapes) {
|
|
300
371
|
try {
|
|
301
372
|
if (lib.hasShapeImage(shape)) continue
|
|
302
|
-
const bounds = lib
|
|
373
|
+
const bounds = getBoundsSafe(lib, shape)
|
|
303
374
|
if (!bounds) continue
|
|
304
375
|
const relW = bounds.w / slideW
|
|
305
376
|
const relH = bounds.h / slideH
|
|
@@ -328,7 +399,7 @@ function extractSkeletonFromShapes(lib, masterShapes, layoutShapes, sampleSlideS
|
|
|
328
399
|
cornerStyle,
|
|
329
400
|
hasTopBanner,
|
|
330
401
|
hasSideSpine,
|
|
331
|
-
masterShapeCount: mShapes.length,
|
|
402
|
+
masterShapeCount: Array.isArray(masterShapes) ? masterShapes.length : mShapes.length,
|
|
332
403
|
_hasFooterRule: hasFooterRule,
|
|
333
404
|
_doubleHeaderLines: doubleHeaderLines,
|
|
334
405
|
}
|
|
@@ -358,6 +429,8 @@ function inferChromeStyle(skeleton, palette, fonts, dark, recommendedTheme) {
|
|
|
358
429
|
|
|
359
430
|
if (
|
|
360
431
|
recommendedTheme === 'keynote-light' ||
|
|
432
|
+
recommendedTheme === 'venture-daylight' ||
|
|
433
|
+
recommendedTheme === 'aurora-stage' ||
|
|
361
434
|
recommendedTheme === 'bold' ||
|
|
362
435
|
skeleton.cornerStyle === 'soft' ||
|
|
363
436
|
(!skeleton.hasTopBanner && !skeleton.hasSideSpine && !skeleton._hasFooterRule && skeleton.cornerStyle !== 'sharp' && !dark)
|
|
@@ -368,6 +441,7 @@ function inferChromeStyle(skeleton, palette, fonts, dark, recommendedTheme) {
|
|
|
368
441
|
if (
|
|
369
442
|
skeleton.hasSideSpine ||
|
|
370
443
|
recommendedTheme === 'editorial-forest' ||
|
|
444
|
+
recommendedTheme === 'economist-brief' ||
|
|
371
445
|
recommendedTheme === 'cartesian' ||
|
|
372
446
|
recommendedTheme === 'velvet' ||
|
|
373
447
|
recommendedTheme === 'luxury-noir'
|
|
@@ -377,6 +451,7 @@ function inferChromeStyle(skeleton, palette, fonts, dark, recommendedTheme) {
|
|
|
377
451
|
|
|
378
452
|
if (
|
|
379
453
|
recommendedTheme === 'linear-dark' ||
|
|
454
|
+
recommendedTheme === 'stripe-craft' ||
|
|
380
455
|
recommendedTheme === 'swiss' ||
|
|
381
456
|
recommendedTheme === 'data' ||
|
|
382
457
|
recommendedTheme === 'soft' ||
|
|
@@ -389,30 +464,69 @@ function inferChromeStyle(skeleton, palette, fonts, dark, recommendedTheme) {
|
|
|
389
464
|
}
|
|
390
465
|
|
|
391
466
|
// ---------------------------------------------------------------------------
|
|
392
|
-
// Per-Slide Layout Classification
|
|
467
|
+
// Per-Slide Layout Classification (Full 24-Archetype + Variant Recognition)
|
|
393
468
|
// ---------------------------------------------------------------------------
|
|
394
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
|
+
|
|
395
497
|
function analyzeSlideLayout(lib, slide, slideIndex, totalSlides, slideW, slideH) {
|
|
396
498
|
const result = { slideNumber: slideIndex + 1, inferredLayout: 'bullets' }
|
|
397
499
|
try {
|
|
398
|
-
const
|
|
500
|
+
const rawShapes = lib.getSlideShapes(slide) ?? []
|
|
501
|
+
const shapes = flattenShapes(lib, rawShapes)
|
|
399
502
|
let layoutType = ''
|
|
503
|
+
let layoutName = ''
|
|
400
504
|
try {
|
|
401
505
|
const sLayout = lib.getSlideLayout(slide)
|
|
402
|
-
if (sLayout)
|
|
506
|
+
if (sLayout) {
|
|
507
|
+
layoutType = String(lib.getSlideLayoutType(sLayout) ?? '').toLowerCase()
|
|
508
|
+
layoutName = String(lib.getSlideLayoutName?.(sLayout) ?? '').toLowerCase()
|
|
509
|
+
}
|
|
403
510
|
} catch { /* ignore */ }
|
|
404
511
|
|
|
405
512
|
let hasChart = false
|
|
513
|
+
let isWaterfallChart = false
|
|
406
514
|
let hasTable = false
|
|
515
|
+
let slideTables = []
|
|
407
516
|
try {
|
|
408
517
|
const charts = lib.getSlideCharts?.(slide)
|
|
409
518
|
if (Array.isArray(charts) && charts.length > 0) hasChart = true
|
|
410
519
|
} catch { /* ignore */ }
|
|
411
520
|
try {
|
|
412
521
|
const tables = lib.getSlideTables?.(slide)
|
|
413
|
-
if (Array.isArray(tables) && tables.length > 0)
|
|
522
|
+
if (Array.isArray(tables) && tables.length > 0) {
|
|
523
|
+
hasTable = true
|
|
524
|
+
slideTables = tables
|
|
525
|
+
}
|
|
414
526
|
} catch { /* ignore */ }
|
|
415
527
|
|
|
528
|
+
const tableMeta = hasTable ? inspectTableForHarveyAndStyle(lib, slideTables) : { hasHarvey: false, styleHint: null }
|
|
529
|
+
|
|
416
530
|
let titleText = ''
|
|
417
531
|
let titleFound = false
|
|
418
532
|
let imageCount = 0
|
|
@@ -421,20 +535,59 @@ function analyzeSlideLayout(lib, slide, slideIndex, totalSlides, slideW, slideH)
|
|
|
421
535
|
let nonTitleTextShapes = 0
|
|
422
536
|
let largeCardShapes = 0
|
|
423
537
|
let numericKpiShapes = 0
|
|
424
|
-
let harveyCells =
|
|
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 = []
|
|
425
552
|
const shapeCenters = []
|
|
553
|
+
const allBodyTexts = []
|
|
426
554
|
|
|
427
555
|
for (const shape of shapes) {
|
|
428
556
|
try {
|
|
429
|
-
if (lib.isChartShape?.(shape))
|
|
557
|
+
if (lib.isChartShape?.(shape)) {
|
|
558
|
+
hasChart = true
|
|
559
|
+
try {
|
|
560
|
+
if (String(lib.getShapeChartKind?.(shape) ?? '').toLowerCase() === 'waterfall') isWaterfallChart = true
|
|
561
|
+
} catch { /* ignore */ }
|
|
562
|
+
}
|
|
430
563
|
if (lib.isTableShape?.(shape)) hasTable = true
|
|
431
564
|
|
|
432
565
|
const name = String(lib.getShapeName?.(shape) ?? '').toLowerCase()
|
|
433
566
|
const phType = String(lib.getShapePlaceholderType?.(shape) ?? '').toLowerCase()
|
|
434
|
-
const
|
|
567
|
+
const preset = String(lib.getShapePreset?.(shape) ?? '').toLowerCase()
|
|
568
|
+
const kind = String(lib.getShapeKind?.(shape) ?? '').toLowerCase()
|
|
569
|
+
const bounds = getBoundsSafe(lib, shape)
|
|
435
570
|
const text = String(lib.getShapeText?.(shape) ?? '').trim()
|
|
436
571
|
|
|
437
|
-
if (
|
|
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
|
|
438
591
|
if (!hasTable && name.includes('table')) hasTable = true
|
|
439
592
|
|
|
440
593
|
if (phType === 'title' || phType === 'ctrtitle' || name.startsWith('title') || name.includes('标题')) {
|
|
@@ -444,6 +597,10 @@ function analyzeSlideLayout(lib, slide, slideIndex, totalSlides, slideW, slideH)
|
|
|
444
597
|
}
|
|
445
598
|
|
|
446
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
|
+
}
|
|
447
604
|
imageCount += 1
|
|
448
605
|
if (bounds) {
|
|
449
606
|
const relW = bounds.w / slideW
|
|
@@ -467,6 +624,9 @@ function analyzeSlideLayout(lib, slide, slideIndex, totalSlides, slideW, slideH)
|
|
|
467
624
|
const relX = bounds.x / slideW
|
|
468
625
|
const relY = bounds.y / slideH
|
|
469
626
|
|
|
627
|
+
// Skip full-bleed background canvas shapes
|
|
628
|
+
if (relW >= 0.78 && relH >= 0.78 && relX <= 0.12 && relY <= 0.12) continue
|
|
629
|
+
|
|
470
630
|
if (!titleFound && relY < 0.22 && relW > 0.45 && relH < 0.22 && text) {
|
|
471
631
|
titleFound = true
|
|
472
632
|
titleText = text.replace(/\s+/g, ' ').slice(0, 80)
|
|
@@ -480,28 +640,102 @@ function analyzeSlideLayout(lib, slide, slideIndex, totalSlides, slideW, slideH)
|
|
|
480
640
|
phType === 'ftr' || phType === 'sldnum' || phType === 'dt'
|
|
481
641
|
if (isChromeShape) continue
|
|
482
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
|
+
|
|
483
651
|
if (text) {
|
|
484
652
|
nonTitleTextShapes += 1
|
|
485
|
-
|
|
653
|
+
allBodyTexts.push(text)
|
|
654
|
+
const firstLine = text.split('\n')[0]?.trim() ?? ''
|
|
655
|
+
if (/^[+-]?[$¥€£]?\s*\d[\d.,]*\s*[%%倍xX万亿千百kKmMbBtT+]*$/.test(firstLine)) {
|
|
486
656
|
numericKpiShapes += 1
|
|
487
657
|
}
|
|
488
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
|
+
}
|
|
489
666
|
}
|
|
490
667
|
|
|
491
|
-
if (!lib.isChartShape?.(shape) && !lib.isTableShape?.(shape)
|
|
492
|
-
|
|
493
|
-
|
|
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
|
+
}
|
|
494
682
|
}
|
|
495
683
|
} catch { /* ignore shape */ }
|
|
496
684
|
}
|
|
497
685
|
|
|
498
|
-
|
|
499
|
-
|
|
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) {
|
|
500
700
|
result.inferredLayout = 'harvey'
|
|
501
701
|
} else if (hasChart) {
|
|
502
702
|
result.inferredLayout = nonTitleTextShapes >= 1 || largeCardShapes >= 1 ? 'chart-split' : 'chart'
|
|
503
703
|
} else if (hasTable) {
|
|
504
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'
|
|
505
739
|
} else if (imageCount >= 2) {
|
|
506
740
|
result.inferredLayout = 'image'
|
|
507
741
|
result.variant = 'gallery'
|
|
@@ -522,11 +756,23 @@ function analyzeSlideLayout(lib, slide, slideIndex, totalSlides, slideW, slideH)
|
|
|
522
756
|
(nonTitleTextShapes <= 1 && /谢谢|感谢|Q\s*&\s*A|Thank|Contact|Next/i.test(titleText))
|
|
523
757
|
) {
|
|
524
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'
|
|
525
762
|
} else if (slideIndex > 0 && (layoutType === 'sechdr' || (nonTitleTextShapes === 0 && shapes.length <= 2))) {
|
|
526
763
|
result.inferredLayout = 'section'
|
|
764
|
+
} else if (quoteSignal && largeCardShapes <= 1 && nonTitleTextShapes <= 2) {
|
|
765
|
+
result.inferredLayout = 'quote'
|
|
766
|
+
result.variant = 'editorial'
|
|
527
767
|
} else if (numericKpiShapes >= 2) {
|
|
528
768
|
result.inferredLayout = 'kpi'
|
|
529
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'
|
|
530
776
|
} else if (largeCardShapes === 4 && shapeCenters.length === 4) {
|
|
531
777
|
const xs = shapeCenters.map((c) => c.x).sort((a, b) => a - b)
|
|
532
778
|
const ys = shapeCenters.map((c) => c.y).sort((a, b) => a - b)
|
|
@@ -536,15 +782,26 @@ function analyzeSlideLayout(lib, slide, slideIndex, totalSlides, slideW, slideH)
|
|
|
536
782
|
} else if (largeCardShapes >= 3) {
|
|
537
783
|
const ySpread = Math.max(...shapeCenters.map((c) => c.y)) - Math.min(...shapeCenters.map((c) => c.y))
|
|
538
784
|
if (ySpread < 0.12) {
|
|
539
|
-
|
|
540
|
-
|
|
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
|
+
}
|
|
541
796
|
} else {
|
|
542
797
|
result.inferredLayout = 'cards'
|
|
543
798
|
result.variant = 'bento'
|
|
544
799
|
}
|
|
545
800
|
} else if (largeCardShapes === 2) {
|
|
546
801
|
result.inferredLayout = 'comparison'
|
|
547
|
-
result.variant = 'versus'
|
|
802
|
+
result.variant = /问题|痛点|风险|整改|应对|issue|mitigation/i.test(combinedSignal) ? 'issue-action' : 'versus'
|
|
803
|
+
} else if (titleFound && nonTitleTextShapes === 0 && titleText.length >= 16) {
|
|
804
|
+
result.inferredLayout = 'statement'
|
|
548
805
|
} else {
|
|
549
806
|
result.inferredLayout = 'bullets'
|
|
550
807
|
}
|
|
@@ -656,11 +913,14 @@ function detectFullBleedShapeBg(lib, pres, shapes, slideW, slideH, themeScheme,
|
|
|
656
913
|
function extractCandidateLogo(lib, pres, slides, layouts, slideW, slideH) {
|
|
657
914
|
const pools = []
|
|
658
915
|
for (const layout of layouts.slice(0, 6)) {
|
|
659
|
-
try { pools.push({ source: 'master', shapes: lib.getSlideMasterShapes(pres, layout) }) } catch { /* ignore */ }
|
|
660
|
-
try { pools.push({ source: 'layout', shapes: lib.getSlideLayoutShapes(pres, layout) }) } catch { /* ignore */ }
|
|
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 */ }
|
|
661
918
|
}
|
|
662
|
-
|
|
663
|
-
try { pools.push({ source: 'slide', shapes: lib.getSlideShapes(
|
|
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 */ }
|
|
664
924
|
}
|
|
665
925
|
|
|
666
926
|
let best = null
|
|
@@ -671,7 +931,7 @@ function extractCandidateLogo(lib, pres, slides, layouts, slideW, slideH) {
|
|
|
671
931
|
const rawFmt = String(lib.getShapeImageFormat(shape) ?? '').toLowerCase()
|
|
672
932
|
const fmt = rawFmt === 'jpg' ? 'jpeg' : rawFmt
|
|
673
933
|
if (fmt !== 'png' && fmt !== 'jpeg') continue
|
|
674
|
-
const bounds = lib
|
|
934
|
+
const bounds = getBoundsSafe(lib, shape)
|
|
675
935
|
if (!bounds || bounds.w <= 0 || bounds.h <= 0) continue
|
|
676
936
|
|
|
677
937
|
const nameText = [
|
|
@@ -685,20 +945,21 @@ function extractCandidateLogo(lib, pres, slides, layouts, slideW, slideH) {
|
|
|
685
945
|
if (bounds.w > maxW || bounds.h > maxH) continue
|
|
686
946
|
|
|
687
947
|
const nearCornerBand = bounds.y <= slideH * 0.24 || (bounds.y + bounds.h) >= slideH * 0.76
|
|
688
|
-
if (!namedLogo && pool.source === 'slide' && !nearCornerBand) continue
|
|
948
|
+
if (!namedLogo && (pool.source === 'cover-slide' || pool.source === 'content-slide') && !nearCornerBand) continue
|
|
689
949
|
|
|
690
950
|
const bytes = lib.getShapeImageBytes(shape)
|
|
691
951
|
if (!isValidRasterLogo(bytes, fmt)) continue
|
|
692
952
|
|
|
693
|
-
const
|
|
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)
|
|
694
955
|
if (!best || score > best.score) {
|
|
695
956
|
const b64 = Buffer.from(bytes).toString('base64')
|
|
696
|
-
best = { score, dataUri: `data:image/${fmt};base64,${b64}` }
|
|
957
|
+
best = { score, source: pool.source, dataUri: `data:image/${fmt};base64,${b64}` }
|
|
697
958
|
}
|
|
698
959
|
} catch { /* ignore shape read error */ }
|
|
699
960
|
}
|
|
700
961
|
}
|
|
701
|
-
return best
|
|
962
|
+
return best ?? null
|
|
702
963
|
}
|
|
703
964
|
|
|
704
965
|
function safeReadXmlPart(lib, pres, partName) {
|
|
@@ -711,6 +972,47 @@ function safeReadXmlPart(lib, pres, partName) {
|
|
|
711
972
|
}
|
|
712
973
|
}
|
|
713
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
|
+
|
|
714
1016
|
/**
|
|
715
1017
|
* 只读解析外部 .pptx 文件或字节流,提取并净化主题色板、中英文字体、母版 Logo、骨架特征与逐页版式分布。
|
|
716
1018
|
*/
|
|
@@ -822,54 +1124,10 @@ export async function absorbPptx(options = {}) {
|
|
|
822
1124
|
masterBg = resolveBackgroundFromXml(masterXml, rawTheme, colorMap)
|
|
823
1125
|
}
|
|
824
1126
|
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
contentSlideBg = resolveBackgroundHex(
|
|
830
|
-
lib.getSlideBackground(sampleSlide),
|
|
831
|
-
pres,
|
|
832
|
-
sampleSlide,
|
|
833
|
-
rawTheme,
|
|
834
|
-
colorMap,
|
|
835
|
-
lib.getSlideBackgroundGradientFill,
|
|
836
|
-
sampleXml,
|
|
837
|
-
)
|
|
838
|
-
} catch { /* ignore */ }
|
|
839
|
-
if (!contentSlideBg && sampleLayout) {
|
|
840
|
-
const layoutPartName = (() => { try { return lib.getSlideLayoutPartName?.(sampleLayout) } catch { return '' } })()
|
|
841
|
-
const layoutXml = safeReadXmlPart(lib, pres, layoutPartName)
|
|
842
|
-
try {
|
|
843
|
-
contentSlideBg = resolveBackgroundHex(
|
|
844
|
-
lib.getSlideLayoutBackground(sampleLayout),
|
|
845
|
-
pres,
|
|
846
|
-
sampleLayout,
|
|
847
|
-
rawTheme,
|
|
848
|
-
colorMap,
|
|
849
|
-
lib.getSlideLayoutBackgroundGradientFill,
|
|
850
|
-
layoutXml,
|
|
851
|
-
) || detectFullBleedShapeBg(lib, pres, lib.getSlideLayoutShapes(pres, sampleLayout), widthEmu, heightEmu, rawTheme, colorMap)
|
|
852
|
-
} catch { /* ignore */ }
|
|
853
|
-
}
|
|
854
|
-
if (!contentSlideBg) {
|
|
855
|
-
try {
|
|
856
|
-
contentSlideBg = detectFullBleedShapeBg(lib, pres, lib.getSlideShapes(sampleSlide), widthEmu, heightEmu, rawTheme, colorMap)
|
|
857
|
-
} catch { /* ignore */ }
|
|
858
|
-
}
|
|
859
|
-
}
|
|
860
|
-
if (!contentSlideBg && slides[0] && slides[0] !== sampleSlide) {
|
|
861
|
-
const firstXml = (() => { try { return lib.getSlideXmlString?.(slides[0]) ?? '' } catch { return '' } })()
|
|
862
|
-
try {
|
|
863
|
-
contentSlideBg = resolveBackgroundHex(
|
|
864
|
-
lib.getSlideBackground(slides[0]),
|
|
865
|
-
pres,
|
|
866
|
-
slides[0],
|
|
867
|
-
rawTheme,
|
|
868
|
-
colorMap,
|
|
869
|
-
lib.getSlideBackgroundGradientFill,
|
|
870
|
-
firstXml,
|
|
871
|
-
) || detectFullBleedShapeBg(lib, pres, lib.getSlideShapes(slides[0]), widthEmu, heightEmu, rawTheme, colorMap)
|
|
872
|
-
} catch { /* ignore */ }
|
|
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
|
|
873
1131
|
}
|
|
874
1132
|
|
|
875
1133
|
let bodyTextColor = null
|
|
@@ -877,34 +1135,48 @@ export async function absorbPptx(options = {}) {
|
|
|
877
1135
|
try { bodyTextColor = lib.resolveDeckBodyTextColor(sampleSlide) } catch { /* ignore */ }
|
|
878
1136
|
}
|
|
879
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)
|
|
880
1140
|
let shapeAccentCandidate = null
|
|
1141
|
+
let shapeSecondaryCandidate = null
|
|
881
1142
|
const rawAccent1 = rawTheme.accent1 ? normalizeHex(rawTheme.accent1, '') : ''
|
|
882
|
-
|
|
1143
|
+
const accent1IsWeakOrDefault = !rawAccent1 || OFFICE_DEFAULT_ACCENTS.has(rawAccent1) || hexToHsl(rawAccent1).s < 0.14
|
|
1144
|
+
{
|
|
883
1145
|
const colorCounts = new Map()
|
|
884
1146
|
const inspectPool = []
|
|
885
1147
|
if (firstLayout) {
|
|
886
|
-
try { inspectPool.push(...lib.getSlideMasterShapes(pres, firstLayout)) } catch { /* ignore */ }
|
|
1148
|
+
try { inspectPool.push(...flattenShapes(lib, lib.getSlideMasterShapes(pres, firstLayout))) } catch { /* ignore */ }
|
|
887
1149
|
}
|
|
888
|
-
for (const slide of slides.slice(0,
|
|
889
|
-
try { inspectPool.push(...lib.getSlideShapes(slide)) } catch { /* ignore */ }
|
|
1150
|
+
for (const slide of slides.slice(0, 8)) {
|
|
1151
|
+
try { inspectPool.push(...flattenShapes(lib, lib.getSlideShapes(slide))) } catch { /* ignore */ }
|
|
890
1152
|
}
|
|
1153
|
+
const effectiveBg = (contentSlideBg ?? masterBg ?? '#FFFFFF').toUpperCase()
|
|
891
1154
|
for (const shape of inspectPool) {
|
|
892
1155
|
try {
|
|
893
|
-
const b = lib
|
|
1156
|
+
const b = getBoundsSafe(lib, shape)
|
|
894
1157
|
if (b && b.w >= widthEmu * 0.78 && b.h >= heightEmu * 0.78) continue
|
|
895
1158
|
const hex = resolveShapeFillSafe(lib, pres, shape, rawTheme, colorMap)
|
|
896
1159
|
if (!hex || !/^#[\da-f]{6}$/i.test(hex)) continue
|
|
897
1160
|
const norm = hex.toUpperCase()
|
|
898
|
-
if (norm === '#FFFFFF' || norm === '#000000' || norm ===
|
|
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
|
|
899
1165
|
colorCounts.set(norm, (colorCounts.get(norm) ?? 0) + 1)
|
|
900
1166
|
} catch { /* ignore */ }
|
|
901
1167
|
}
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
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]
|
|
908
1180
|
}
|
|
909
1181
|
}
|
|
910
1182
|
|
|
@@ -915,6 +1187,7 @@ export async function absorbPptx(options = {}) {
|
|
|
915
1187
|
}
|
|
916
1188
|
}
|
|
917
1189
|
if (masterBg) extractedPalette.masterBg = masterBg
|
|
1190
|
+
if (coverSlideBg) extractedPalette.coverSlideBg = coverSlideBg
|
|
918
1191
|
if (contentSlideBg) extractedPalette.contentSlideBg = contentSlideBg
|
|
919
1192
|
if (bodyTextColor) extractedPalette.bodyTextColor = normalizeHex(bodyTextColor, bodyTextColor)
|
|
920
1193
|
|
|
@@ -929,12 +1202,24 @@ export async function absorbPptx(options = {}) {
|
|
|
929
1202
|
palette: extractedPalette,
|
|
930
1203
|
fonts: extractedFonts,
|
|
931
1204
|
masterBg: masterBg ?? undefined,
|
|
1205
|
+
coverSlideBg: coverSlideBg ?? undefined,
|
|
932
1206
|
contentSlideBg: contentSlideBg ?? masterBg ?? undefined,
|
|
933
1207
|
textColor: bodyTextColor ?? undefined,
|
|
934
1208
|
...(shapeAccentCandidate ? { brandPrimary: shapeAccentCandidate } : {}),
|
|
1209
|
+
...(shapeSecondaryCandidate ? { brandSecondary: shapeSecondaryCandidate } : {}),
|
|
935
1210
|
})
|
|
936
1211
|
|
|
937
|
-
const
|
|
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
|
+
|
|
938
1223
|
let coreTitle = ''
|
|
939
1224
|
try {
|
|
940
1225
|
const props = lib.getCoreProperties(pres)
|
|
@@ -948,17 +1233,18 @@ export async function absorbPptx(options = {}) {
|
|
|
948
1233
|
...(coreTitle ? { name: coreTitle } : {}),
|
|
949
1234
|
...(logoDataUri ? { logo: logoDataUri } : {}),
|
|
950
1235
|
}
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
(
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
)
|
|
959
|
-
) {
|
|
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)) {
|
|
960
1243
|
delete sanitizedBrand.fontFamily
|
|
961
1244
|
}
|
|
1245
|
+
if (sanitizedBrand.headingFont && isOfficeDefaultFont(sanitizedBrand.headingFont)) {
|
|
1246
|
+
delete sanitizedBrand.headingFont
|
|
1247
|
+
}
|
|
962
1248
|
|
|
963
1249
|
const layoutTypes = {}
|
|
964
1250
|
for (const layout of layouts) {
|
|
@@ -1009,6 +1295,27 @@ export async function absorbPptx(options = {}) {
|
|
|
1009
1295
|
analyzeSlideLayout(lib, slide, idx, slides.length, widthEmu, heightEmu)
|
|
1010
1296
|
)
|
|
1011
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
|
+
|
|
1012
1319
|
return {
|
|
1013
1320
|
ok: true,
|
|
1014
1321
|
...(resolvedPath ? { pptxPath: resolvedPath } : {}),
|
|
@@ -1020,6 +1327,8 @@ export async function absorbPptx(options = {}) {
|
|
|
1020
1327
|
sanitizedTokens: sanitized.sanitizedTokens,
|
|
1021
1328
|
recommendedTheme: sanitized.recommendedTheme,
|
|
1022
1329
|
recommendedChrome,
|
|
1330
|
+
recommendedTableStyle,
|
|
1331
|
+
narrativeProfile,
|
|
1023
1332
|
dark: sanitized.dark,
|
|
1024
1333
|
warnings: sanitized.warnings,
|
|
1025
1334
|
layoutSummary,
|