feat: SVG 图标序列化为图片

SVG 元素(如 Octicons)在 capture 阶段序列化为 SVG data URL,
存储到 backgroundImages,转化时作为图片渲染到 PPT。
This commit is contained in:
李进
2026-07-27 15:34:35 +08:00
parent 197642b410
commit 5ef970337d
+12
View File
@@ -984,6 +984,18 @@
const afterNode = pseudoElementToCaptureNode(element, "::after", clientRect, assetUrls, ownClip, childContext); const afterNode = pseudoElementToCaptureNode(element, "::after", clientRect, assetUrls, ownClip, childContext);
pushCaptureChild(children, afterNode); 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"; const type = element.tagName === "IMG" || backgroundUrls.length ? "RECTANGLE" : "FRAME";
return { return {
id: `node-${++nodeCounter}`, id: `node-${++nodeCounter}`,