2024-05-29 10:33:29 -05:00
|
|
|
import { PenpotNode } from '@ui/types';
|
2024-04-12 09:52:36 -05:00
|
|
|
|
2024-04-12 06:55:42 -05:00
|
|
|
import {
|
2024-05-27 03:05:23 -05:00
|
|
|
transformBooleanNode,
|
2024-05-29 05:52:21 -05:00
|
|
|
transformComponentNode,
|
2024-04-12 06:55:42 -05:00
|
|
|
transformEllipseNode,
|
|
|
|
transformFrameNode,
|
|
|
|
transformGroupNode,
|
2024-05-30 10:54:37 -05:00
|
|
|
transformInstanceNode,
|
2024-04-17 03:53:38 -05:00
|
|
|
transformPathNode,
|
2024-04-12 06:55:42 -05:00
|
|
|
transformRectangleNode,
|
2024-05-13 06:21:46 -05:00
|
|
|
transformTextNode,
|
|
|
|
transformVectorNode
|
2024-04-12 06:55:42 -05:00
|
|
|
} from '.';
|
|
|
|
|
|
|
|
export const transformSceneNode = async (
|
|
|
|
node: SceneNode,
|
|
|
|
baseX: number = 0,
|
|
|
|
baseY: number = 0
|
2024-04-19 02:48:19 -05:00
|
|
|
): Promise<PenpotNode | undefined> => {
|
2024-05-31 04:25:32 -05:00
|
|
|
let penpotNode: PenpotNode | undefined;
|
|
|
|
|
|
|
|
figma.ui.postMessage({
|
|
|
|
type: 'PROGRESS_NODE',
|
|
|
|
data: node.name
|
|
|
|
});
|
|
|
|
|
2024-04-12 06:55:42 -05:00
|
|
|
switch (node.type) {
|
|
|
|
case 'RECTANGLE':
|
2024-05-31 04:25:32 -05:00
|
|
|
penpotNode = await transformRectangleNode(node, baseX, baseY);
|
|
|
|
break;
|
2024-04-12 06:55:42 -05:00
|
|
|
case 'ELLIPSE':
|
2024-05-31 04:25:32 -05:00
|
|
|
penpotNode = await transformEllipseNode(node, baseX, baseY);
|
|
|
|
break;
|
2024-04-17 04:38:13 -05:00
|
|
|
case 'SECTION':
|
2024-04-12 06:55:42 -05:00
|
|
|
case 'FRAME':
|
2024-05-31 04:25:32 -05:00
|
|
|
penpotNode = await transformFrameNode(node, baseX, baseY);
|
|
|
|
break;
|
2024-04-12 06:55:42 -05:00
|
|
|
case 'GROUP':
|
2024-05-31 04:25:32 -05:00
|
|
|
penpotNode = await transformGroupNode(node, baseX, baseY);
|
|
|
|
break;
|
2024-04-12 06:55:42 -05:00
|
|
|
case 'TEXT':
|
2024-05-31 04:25:32 -05:00
|
|
|
penpotNode = await transformTextNode(node, baseX, baseY);
|
|
|
|
break;
|
2024-05-13 06:21:46 -05:00
|
|
|
case 'VECTOR':
|
2024-05-31 04:25:32 -05:00
|
|
|
penpotNode = await transformVectorNode(node, baseX, baseY);
|
|
|
|
break;
|
2024-04-16 09:08:39 -05:00
|
|
|
case 'STAR':
|
|
|
|
case 'POLYGON':
|
2024-04-17 03:53:38 -05:00
|
|
|
case 'LINE':
|
2024-05-31 04:25:32 -05:00
|
|
|
penpotNode = await transformPathNode(node, baseX, baseY);
|
|
|
|
break;
|
2024-05-27 03:05:23 -05:00
|
|
|
case 'BOOLEAN_OPERATION':
|
2024-05-31 04:25:32 -05:00
|
|
|
penpotNode = await transformBooleanNode(node, baseX, baseY);
|
|
|
|
break;
|
2024-05-29 05:52:21 -05:00
|
|
|
case 'COMPONENT':
|
2024-05-31 04:25:32 -05:00
|
|
|
penpotNode = await transformComponentNode(node, baseX, baseY);
|
|
|
|
break;
|
2024-05-30 10:54:37 -05:00
|
|
|
case 'INSTANCE':
|
2024-05-31 04:25:32 -05:00
|
|
|
penpotNode = await transformInstanceNode(node, baseX, baseY);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (penpotNode === undefined) {
|
|
|
|
console.error(`Unsupported node type: ${node.type}`);
|
2024-04-12 06:55:42 -05:00
|
|
|
}
|
|
|
|
|
2024-05-31 04:25:32 -05:00
|
|
|
return penpotNode;
|
2024-04-12 06:55:42 -05:00
|
|
|
};
|