feat: SVG 图标序列化为图片
SVG 元素(如 Octicons)在 capture 阶段序列化为 SVG data URL, 存储到 backgroundImages,转化时作为图片渲染到 PPT。
This commit is contained in:
@@ -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}`,
|
||||
|
||||
Reference in New Issue
Block a user