From 7bb5b81fbde3e5bbcc28a69c2132a540dcd59833 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E8=BF=9B?= Date: Mon, 27 Jul 2026 16:36:02 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20SVG=20=E5=9B=BE=E6=A0=87=E5=BA=8F?= =?UTF-8?q?=E5=88=97=E5=8C=96=E4=B8=BA=E5=9B=BE=E7=89=87=EF=BC=88=E7=AC=AC?= =?UTF-8?q?=E4=B8=89=E7=89=88=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 不修改 backgroundUrls(const) - 节点创建后直接修改 node.backgroundImages - XMLSerializer + btoa 序列化 SVG --- web-to-ppt/capture.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/web-to-ppt/capture.js b/web-to-ppt/capture.js index a09d913..64fb37e 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,19 @@ 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) {