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/transformFrameNode.ts

79 lines
2.4 KiB
TypeScript
Raw Permalink Normal View History

import { registerComponentProperties } from '@plugin/registerComponentProperties';
import {
transformAutoLayout,
transformBlend,
transformChildren,
transformConstraints,
transformCornerRadius,
transformDimension,
2024-04-22 07:35:59 -05:00
transformEffects,
transformFigmaIds,
transformFills,
transformLayoutAttributes,
transformOverrides,
transformProportion,
transformRotationAndPosition,
transformSceneNode,
transformStrokes
} from '@plugin/transformers/partials';
2024-05-06 01:06:14 -05:00
import { FrameShape } from '@ui/lib/types/shapes/frameShape';
import { Point } from '@ui/lib/types/utils/point';
2024-05-31 06:32:59 -05:00
const isSectionNode = (node: FrameNode | SectionNode | ComponentSetNode): node is SectionNode => {
return node.type === 'SECTION';
};
const isComponentSetNode = (
node: FrameNode | SectionNode | ComponentSetNode
): node is ComponentSetNode => {
return node.type === 'COMPONENT_SET';
};
export const transformFrameNode = async (
node: FrameNode | SectionNode | ComponentSetNode
): Promise<FrameShape> => {
2024-04-22 07:35:59 -05:00
let frameSpecificAttributes: Partial<FrameShape> = {};
let referencePoint: Point = { x: node.absoluteTransform[0][2], y: node.absoluteTransform[1][2] };
2024-04-22 07:35:59 -05:00
if (isComponentSetNode(node)) {
registerComponentProperties(node);
}
2024-04-22 07:35:59 -05:00
if (!isSectionNode(node)) {
const { x, y, ...transformAndRotation } = transformRotationAndPosition(node);
referencePoint = { x, y };
2024-04-22 07:35:59 -05:00
// 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
...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),
...transformLayoutAttributes(node, true),
2024-04-22 07:35:59 -05:00
...transformCornerRadius(node),
...transformEffects(node),
...transformConstraints(node),
...transformAutoLayout(node),
...transformAndRotation
2024-04-22 07:35:59 -05:00
};
}
return {
type: 'frame',
name: node.name,
2024-04-19 04:40:50 -05:00
showContent: isSectionNode(node) ? true : !node.clipsContent,
...transformFigmaIds(node),
...transformFills(node),
...referencePoint,
2024-04-22 07:35:59 -05:00
...frameSpecificAttributes,
...transformDimension(node),
...(await transformChildren(node)),
...transformSceneNode(node),
...transformOverrides(node)
};
};