fix: SVG 图标正确渲染

- collectSlideChildren 保留有 backgroundImages 的 RECTANGLE 节点
- 图片处理:data URL 直接使用,不查找 assets
- Gitea 测试:24 个 SVG 图标成功渲染
This commit is contained in:
李进
2026-07-27 16:44:28 +08:00
parent 7bb5b81fbd
commit b5f4217302
+10 -4
View File
@@ -337,8 +337,8 @@ async function convert(input) {
const nr = node.rect; const nr = node.rect;
const rw = nr.width ?? nr.w; const rw = nr.width ?? nr.w;
const rh = nr.height ?? nr.h; const rh = nr.height ?? nr.h;
// 保留所有非 raster 节点 // 保留所有非 raster 节点RECTANGLE 有 backgroundImages 的也保留,如 SVG 图标)
if (node.type !== 'RECTANGLE' && node.layerGroup !== 'comparison') { if ((node.type !== 'RECTANGLE' || (node.backgroundImages && node.backgroundImages.length > 0)) && node.layerGroup !== 'comparison') {
results.push({ results.push({
id: node.id, type: node.type, name: node.name, tag: node.tag, id: node.id, type: node.type, name: node.name, tag: node.tag,
rect: { x: nr.x - slideX, y: nr.y - slideY, w: rw, h: rh }, rect: { x: nr.x - slideX, y: nr.y - slideY, w: rw, h: rh },
@@ -775,13 +775,19 @@ async function convert(input) {
// ===== 图片节点(IMAGE 类型或有背景图的 RECTANGLE ===== // ===== 图片节点(IMAGE 类型或有背景图的 RECTANGLE =====
if ((n.type === 'IMAGE' || n.type === 'RECTANGLE') && n.backgroundImages && n.backgroundImages.length > 0) { if ((n.type === 'IMAGE' || n.type === 'RECTANGLE') && n.backgroundImages && n.backgroundImages.length > 0) {
var imgKey = n.backgroundImages[0]; var imgKey = n.backgroundImages[0];
var imgData;
if (imgKey.startsWith('data:')) {
imgData = imgKey; // 已经是 data URL(如 SVG 图标)
} else {
var asset = ctx.assets[imgKey]; var asset = ctx.assets[imgKey];
if (asset && asset.data) { if (asset) imgData = asset.data;
}
if (imgData) {
objects.push({ objects.push({
type: 'image', type: 'image',
options: { options: {
x: opts.x, y: opts.y, w: opts.w, h: opts.h, x: opts.x, y: opts.y, w: opts.w, h: opts.h,
data: asset.data data: imgData
} }
}); });
} }