From 5ef970337d19f0cc390274d53936114e58d37ffa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E8=BF=9B?= Date: Mon, 27 Jul 2026 15:34:35 +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?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit SVG 元素(如 Octicons)在 capture 阶段序列化为 SVG data URL, 存储到 backgroundImages,转化时作为图片渲染到 PPT。 --- web-to-ppt/capture.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/web-to-ppt/capture.js b/web-to-ppt/capture.js index a09d913..77043c5 100644 --- a/web-to-ppt/capture.js +++ b/web-to-ppt/capture.js @@ -984,6 +984,18 @@ const afterNode = pseudoElementToCaptureNode(element, "::after", clientRect, assetUrls, ownClip, childContext); pushCaptureChild(children, afterNode); + // SVG → 序列化为 data URL 图片 + if (element.tagName === "SVG" && !backgroundUrls.length) { + try { + const svgClone = element.cloneNode(true); + // 确保有 xmlns + if (!svgClone.getAttribute('xmlns')) svgClone.setAttribute('xmlns', 'http://www.w3.org/2000/svg'); + const svgStr = new XMLSerializer().serializeToString(svgClone); + const svgDataUrl = 'data:image/svg+xml;base64,' + btoa(unescape(encodeURIComponent(svgStr))); + backgroundUrls = [svgDataUrl]; + } catch (e) { /* 静默失败 */ } + } + const type = element.tagName === "IMG" || backgroundUrls.length ? "RECTANGLE" : "FRAME"; return { id: `node-${++nodeCounter}`,