diff --git a/convert-w2p.js b/convert-w2p.js index 411e204..bf3261f 100644 --- a/convert-w2p.js +++ b/convert-w2p.js @@ -458,15 +458,25 @@ function convert(input) { if (hex) slideBg = { color: hex }; } } - // fallback:从 slide name 推断背景(CSS class 设置的背景 web-to-pixso 没提取) - if (!slideBg) { - const name = sg.name.toLowerCase(); - if (name.includes('dark')) { - slideBg = { color: '1A1A1A' }; - } else if (name.includes('light')) { - slideBg = { color: 'FAFAFA' }; + // fallback:从 slide 容器的文字颜色反推背景 + if (!slideBg && slideContainer && slideContainer.styles) { + const textColor = slideContainer.styles.color; + if (textColor) { + const tc = rgbaToHex(textColor); + if (tc) { + const r = parseInt(tc.slice(0,2), 16); + const g = parseInt(tc.slice(2,4), 16); + const b = parseInt(tc.slice(4,6), 16); + const lum = (r * 299 + g * 587 + b * 114) / 1000; + slideBg = lum > 128 ? { color: '1A1A1A' } : { color: 'FAFAFA' }; + } } } + // fallback:从 canvas 背景色兜底(最后手段) + if (!slideBg && canvas.backgroundColor && canvas.backgroundColor !== 'rgba(0, 0, 0, 0)') { + const hex = rgbaToHex(canvas.backgroundColor); + if (hex) slideBg = { color: hex }; + } console.log('处理 ' + sg.name + ': ' + sg.children.length + ' 个节点');