2024-04-12 09:52:36 -05:00
|
|
|
import { calculateAdjustment } from '@plugin/utils';
|
|
|
|
|
|
|
|
import { PenpotNode } from '@ui/lib/types/penpotNode';
|
|
|
|
|
2024-04-12 06:55:42 -05:00
|
|
|
import {
|
|
|
|
transformEllipseNode,
|
|
|
|
transformFrameNode,
|
|
|
|
transformGroupNode,
|
|
|
|
transformImageNode,
|
2024-04-17 03:53:38 -05:00
|
|
|
transformPathNode,
|
2024-04-12 06:55:42 -05:00
|
|
|
transformRectangleNode,
|
2024-04-17 03:53:38 -05:00
|
|
|
transformTextNode
|
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-04-12 06:55:42 -05:00
|
|
|
// @TODO: when penpot 2.0, manage image as fills for the basic types
|
|
|
|
if (
|
|
|
|
'fills' in node &&
|
|
|
|
node.fills !== figma.mixed &&
|
|
|
|
node.fills.find(fill => fill.type === 'IMAGE')
|
|
|
|
) {
|
|
|
|
// If the nested frames extended the bounds of the rasterized image, we need to
|
|
|
|
// account for this both in position on the canvas and the calculated width and
|
|
|
|
// height of the image.
|
|
|
|
const [adjustedX, adjustedY] = calculateAdjustment(node);
|
|
|
|
return await transformImageNode(node, baseX + adjustedX, baseY + adjustedY);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (node.type) {
|
|
|
|
case 'RECTANGLE':
|
|
|
|
return transformRectangleNode(node, baseX, baseY);
|
|
|
|
case 'ELLIPSE':
|
|
|
|
return transformEllipseNode(node, baseX, baseY);
|
2024-04-17 04:38:13 -05:00
|
|
|
case 'SECTION':
|
2024-04-12 06:55:42 -05:00
|
|
|
case 'FRAME':
|
|
|
|
return await transformFrameNode(node, baseX, baseY);
|
|
|
|
case 'GROUP':
|
|
|
|
return await transformGroupNode(node, baseX, baseY);
|
|
|
|
case 'TEXT':
|
|
|
|
return transformTextNode(node, baseX, baseY);
|
2024-04-16 09:08:39 -05:00
|
|
|
case 'STAR':
|
|
|
|
case 'POLYGON':
|
|
|
|
case 'VECTOR':
|
2024-04-17 03:53:38 -05:00
|
|
|
case 'LINE':
|
|
|
|
return transformPathNode(node, baseX, baseY);
|
2024-04-12 06:55:42 -05:00
|
|
|
}
|
|
|
|
|
2024-04-19 02:48:19 -05:00
|
|
|
console.error(`Unsupported node type: ${node.type}`);
|
2024-04-12 06:55:42 -05:00
|
|
|
};
|