debug: SVG 处理日志

This commit is contained in:
李进
2026-07-27 15:45:51 +08:00
parent ecc1a0d77e
commit 5127df5e96
+4 -2
View File
@@ -988,12 +988,14 @@
if ((element.tagName === "SVG" || element.tagName === "svg") && !backgroundUrls.length) { if ((element.tagName === "SVG" || element.tagName === "svg") && !backgroundUrls.length) {
try { try {
const svgClone = element.cloneNode(true); const svgClone = element.cloneNode(true);
// 确保有 xmlns
if (!svgClone.getAttribute('xmlns')) svgClone.setAttribute('xmlns', 'http://www.w3.org/2000/svg'); if (!svgClone.getAttribute('xmlns')) svgClone.setAttribute('xmlns', 'http://www.w3.org/2000/svg');
const svgStr = new XMLSerializer().serializeToString(svgClone); const svgStr = new XMLSerializer().serializeToString(svgClone);
const svgDataUrl = 'data:image/svg+xml;base64,' + btoa(unescape(encodeURIComponent(svgStr))); const svgDataUrl = 'data:image/svg+xml;base64,' + btoa(unescape(encodeURIComponent(svgStr)));
backgroundUrls = [svgDataUrl]; backgroundUrls = [svgDataUrl];
} catch (e) { /* 静默失败 */ } console.log('[WebToPPT] SVG captured:', (element.className || element.id || '').slice(0, 30), 'size:', svgStr.length);
} catch (e) {
console.warn('[WebToPPT] SVG capture failed:', e.message, element.tagName, (element.className || '').slice(0, 30));
}
} }
const type = element.tagName === "IMG" || backgroundUrls.length ? "RECTANGLE" : "FRAME"; const type = element.tagName === "IMG" || backgroundUrls.length ? "RECTANGLE" : "FRAME";