diff --git a/web-to-ppt/capture.js b/web-to-ppt/capture.js index a09d913..922d33e 100644 --- a/web-to-ppt/capture.js +++ b/web-to-ppt/capture.js @@ -985,7 +985,7 @@ pushCaptureChild(children, afterNode); const type = element.tagName === "IMG" || backgroundUrls.length ? "RECTANGLE" : "FRAME"; - return { + const node = { id: `node-${++nodeCounter}`, type, tag: element.tagName, @@ -1005,6 +1005,21 @@ backgroundImages: backgroundUrls, children }; + + // SVG → 序列化为 data URL 图片 + if ((element.tagName === "SVG" || element.tagName === "svg") && !node.backgroundImages.length) { + try { + const svgClone = element.cloneNode(true); + if (!svgClone.getAttribute("xmlns")) svgClone.setAttribute("xmlns", "http://www.w3.org/2000/svg"); + const svgStr = new XMLSerializer().serializeToString(svgClone); + node.backgroundImages = ["data:image/svg+xml;base64," + btoa(unescape(encodeURIComponent(svgStr)))]; + node.type = "RECTANGLE"; + } catch (e) { /* 静默失败 */ } + } + + return node; + + } function normalizeAssetUrl(url) {