mirror of
https://github.com/penpot/penpot-exporter-figma-plugin.git
synced 2025-01-18 05:22:28 -05:00
303cc833a0
* wip * wip * wip * wip * wip * fixes * fixes * fixes * fixes * fixes * fixes * fixes * fixes * fixes
64 lines
1.8 KiB
TypeScript
64 lines
1.8 KiB
TypeScript
import { componentProperties, components } from '@plugin/libraries';
|
|
import {
|
|
transformAutoLayout,
|
|
transformBlend,
|
|
transformChildren,
|
|
transformConstraints,
|
|
transformCornerRadius,
|
|
transformDimension,
|
|
transformEffects,
|
|
transformFigmaIds,
|
|
transformFills,
|
|
transformLayoutAttributes,
|
|
transformProportion,
|
|
transformRotationAndPosition,
|
|
transformSceneNode,
|
|
transformStrokes
|
|
} from '@plugin/transformers/partials';
|
|
|
|
import { ComponentRoot } from '@ui/types';
|
|
|
|
const isNonVariantComponentNode = (node: ComponentNode): boolean => {
|
|
return node.parent?.type !== 'COMPONENT_SET';
|
|
};
|
|
|
|
export const transformComponentNode = async (node: ComponentNode): Promise<ComponentRoot> => {
|
|
components.set(node.id, {
|
|
type: 'component',
|
|
name: node.name,
|
|
path: node.parent?.type === 'COMPONENT_SET' ? node.parent.name : '',
|
|
showContent: !node.clipsContent,
|
|
...transformFigmaIds(node),
|
|
...transformFills(node),
|
|
...transformEffects(node),
|
|
...transformStrokes(node),
|
|
...transformSceneNode(node),
|
|
...transformBlend(node),
|
|
...transformProportion(node),
|
|
...transformLayoutAttributes(node, true),
|
|
...transformCornerRadius(node),
|
|
...(await transformChildren(node)),
|
|
...transformDimension(node),
|
|
...transformRotationAndPosition(node),
|
|
...transformConstraints(node),
|
|
...transformAutoLayout(node)
|
|
});
|
|
|
|
if (isNonVariantComponentNode(node)) {
|
|
try {
|
|
Object.entries(node.componentPropertyDefinitions).forEach(([key, value]) => {
|
|
if (value.type === 'TEXT' || value.type === 'BOOLEAN') {
|
|
componentProperties.set(key, value);
|
|
}
|
|
});
|
|
} catch (error) {
|
|
console.error('Error registering component properties', error);
|
|
}
|
|
}
|
|
|
|
return {
|
|
figmaId: node.id,
|
|
type: 'component',
|
|
name: node.name
|
|
};
|
|
};
|