2024-04-17 03:53:38 -05:00
|
|
|
import {
|
2024-04-17 04:38:13 -05:00
|
|
|
transformBlend,
|
2024-04-17 08:27:53 -05:00
|
|
|
transformChildren,
|
2024-04-22 05:50:38 -05:00
|
|
|
transformCornerRadius,
|
2024-04-17 03:53:38 -05:00
|
|
|
transformDimensionAndPosition,
|
2024-04-22 07:35:59 -05:00
|
|
|
transformEffects,
|
2024-05-30 10:54:37 -05:00
|
|
|
transformFigmaIds,
|
2024-04-17 08:27:53 -05:00
|
|
|
transformFills,
|
2024-04-19 05:18:12 -05:00
|
|
|
transformProportion,
|
2024-04-17 03:53:38 -05:00
|
|
|
transformSceneNode,
|
|
|
|
transformStrokes
|
|
|
|
} from '@plugin/transformers/partials';
|
2024-04-12 09:52:36 -05:00
|
|
|
|
2024-05-06 01:06:14 -05:00
|
|
|
import { FrameShape } from '@ui/lib/types/shapes/frameShape';
|
2024-04-12 09:52:36 -05:00
|
|
|
|
2024-04-17 04:38:13 -05:00
|
|
|
const isSectionNode = (node: FrameNode | SectionNode): node is SectionNode => {
|
|
|
|
return node.type === 'SECTION';
|
|
|
|
};
|
|
|
|
|
2024-04-12 06:55:42 -05:00
|
|
|
export const transformFrameNode = async (
|
2024-04-17 04:38:13 -05:00
|
|
|
node: FrameNode | SectionNode,
|
2024-04-12 06:55:42 -05:00
|
|
|
baseX: number,
|
|
|
|
baseY: number
|
|
|
|
): Promise<FrameShape> => {
|
2024-04-22 07:35:59 -05:00
|
|
|
let frameSpecificAttributes: Partial<FrameShape> = {};
|
|
|
|
|
|
|
|
if (!isSectionNode(node)) {
|
|
|
|
// Figma API does not expose strokes, blend modes, corner radius, or constraint proportions for sections,
|
|
|
|
// they plan to add it in the future. Refactor this when available.
|
|
|
|
frameSpecificAttributes = {
|
|
|
|
// @see: https://forum.figma.com/t/why-are-strokes-not-available-on-section-nodes/41658
|
2024-05-09 09:59:27 -05:00
|
|
|
...(await transformStrokes(node)),
|
2024-04-22 07:35:59 -05:00
|
|
|
// @see: https://forum.figma.com/t/add-a-blendmode-property-for-sectionnode/58560
|
|
|
|
...transformBlend(node),
|
|
|
|
...transformProportion(node),
|
|
|
|
...transformCornerRadius(node),
|
|
|
|
...transformEffects(node)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2024-04-12 06:55:42 -05:00
|
|
|
return {
|
|
|
|
type: 'frame',
|
|
|
|
name: node.name,
|
2024-04-19 04:40:50 -05:00
|
|
|
showContent: isSectionNode(node) ? true : !node.clipsContent,
|
2024-05-30 10:54:37 -05:00
|
|
|
...transformFigmaIds(node),
|
2024-05-09 09:59:27 -05:00
|
|
|
...(await transformFills(node)),
|
2024-04-22 07:35:59 -05:00
|
|
|
...frameSpecificAttributes,
|
2024-04-17 04:38:13 -05:00
|
|
|
...(await transformChildren(node, baseX + node.x, baseY + node.y)),
|
2024-04-15 11:30:51 -05:00
|
|
|
...transformDimensionAndPosition(node, baseX, baseY),
|
2024-04-22 07:35:59 -05:00
|
|
|
...transformSceneNode(node)
|
2024-04-12 06:55:42 -05:00
|
|
|
};
|
|
|
|
};
|