0
Fork 0
mirror of https://github.com/penpot/penpot-exporter-figma-plugin.git synced 2024-12-22 13:43:03 -05:00
penpot-exporter-figma-plugin/plugin-src/transformers/transformSceneNode.ts

71 lines
1.7 KiB
TypeScript
Raw Normal View History

import { PenpotNode } from '@ui/types';
import {
transformBooleanNode,
transformComponentNode,
transformEllipseNode,
transformFrameNode,
transformGroupNode,
transformInstanceNode,
transformPathNode,
transformRectangleNode,
transformTextNode,
transformVectorNode
} from '.';
export const transformSceneNode = async (
node: SceneNode,
baseX: number = 0,
baseY: number = 0
): Promise<PenpotNode | undefined> => {
let penpotNode: PenpotNode | undefined;
figma.ui.postMessage({
type: 'PROGRESS_CURRENT_ITEM',
data: node.name
});
switch (node.type) {
case 'RECTANGLE':
penpotNode = transformRectangleNode(node, baseX, baseY);
break;
case 'ELLIPSE':
penpotNode = transformEllipseNode(node, baseX, baseY);
break;
case 'SECTION':
case 'FRAME':
2024-05-31 06:32:59 -05:00
case 'COMPONENT_SET':
penpotNode = await transformFrameNode(node, baseX, baseY);
break;
case 'GROUP':
penpotNode = await transformGroupNode(node, baseX, baseY);
break;
case 'TEXT':
penpotNode = transformTextNode(node, baseX, baseY);
break;
case 'VECTOR':
penpotNode = transformVectorNode(node, baseX, baseY);
break;
case 'STAR':
case 'POLYGON':
case 'LINE':
penpotNode = transformPathNode(node, baseX, baseY);
break;
case 'BOOLEAN_OPERATION':
penpotNode = await transformBooleanNode(node, baseX, baseY);
break;
case 'COMPONENT':
penpotNode = await transformComponentNode(node, baseX, baseY);
break;
case 'INSTANCE':
penpotNode = await transformInstanceNode(node, baseX, baseY);
break;
}
if (penpotNode === undefined) {
console.error(`Unsupported node type: ${node.type}`);
}
return penpotNode;
};