From a2a31c328e36d44cdcf8bacc9ddfbaa19f5be8c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E8=BF=9B?= Date: Mon, 27 Jul 2026 15:56:33 +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=E9=87=8D?= =?UTF-8?q?=E6=9E=84=E7=89=88=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 不修改 backgroundUrls 变量 - 在节点创建后、返回前处理 SVG - 用 cloneNode + XMLSerializer + btoa 序列化 - 设置 backgroundImages 和 type=RECTANGLE --- web-to-ppt/capture.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) 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) {