Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/extractors/built-in.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,8 @@ export function collapseSvgContainers(

if (
(node.type === "FRAME" || node.type === "GROUP" || node.type === "INSTANCE") &&
allChildrenAreSvgEligible
allChildrenAreSvgEligible &&
!hasImageFillInChildren(node)
) {
// Collapse to IMAGE-SVG and omit children
result.type = "IMAGE-SVG";
Expand All @@ -249,3 +250,22 @@ export function collapseSvgContainers(
// Include all children normally
return children;
}

/**
* Check whether a node or its direct children have image fills.
*
* Only direct children need checking because afterChildren runs bottom-up:
* if a deeper descendant has image fills, its parent won't collapse (stays FRAME),
* and FRAME isn't SVG-eligible, so the chain breaks naturally at each level.
*/
function hasImageFillInChildren(node: FigmaDocumentNode): boolean {
if (hasValue("fills", node) && node.fills.some((fill) => fill.type === "IMAGE")) {
return true;
}
if (hasValue("children", node)) {
return node.children.some(
(child) => hasValue("fills", child) && child.fills.some((fill) => fill.type === "IMAGE"),
);
}
return false;
}
12 changes: 12 additions & 0 deletions src/utils/image-processing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,18 @@ export async function downloadAndProcessImage(
const originalPath = await downloadFigmaImage(fileName, localPath, imageUrl);
Logger.log(`Downloaded original image: ${originalPath}`);

// SVGs are vector — jimp can't read them and cropping/dimensions don't apply
const isSvg = fileName.toLowerCase().endsWith(".svg");
if (isSvg) {
return {
filePath: originalPath,
originalDimensions: { width: 0, height: 0 },
finalDimensions: { width: 0, height: 0 },
wasCropped: false,
processingLog,
};
}

// Get original dimensions before any processing
const originalDimensions = await getImageDimensions(originalPath);
Logger.log(`Original dimensions: ${originalDimensions.width}x${originalDimensions.height}`);
Expand Down
Loading