0
Fork 0
mirror of https://github.com/penpot/penpot-exporter-figma-plugin.git synced 2024-12-23 06:04:01 -05:00
penpot-exporter-figma-plugin/plugin-src/transformers/partials/transformFigmaIds.ts
Alex Sánchez 92167aca42
Fix masks in components (#129)
* fix masks in components

* fixes

* fixes
2024-06-03 09:38:44 +02:00

32 lines
882 B
TypeScript

import { ShapeBaseAttributes } from '@ui/lib/types/shapes/shape';
export const transformFigmaIds = (
node: SceneNode
): Pick<ShapeBaseAttributes, 'figmaId' | 'figmaRelatedId'> => {
return {
figmaId: normalizeNodeId(node.id),
figmaRelatedId: getRelatedNodeId(node.id)
};
};
export const transformMaskFigmaIds = (
node: SceneNode
): Pick<ShapeBaseAttributes, 'figmaId' | 'figmaRelatedId'> => {
const transformedIds = transformFigmaIds(node);
return {
figmaId: `M${transformedIds.figmaId}`,
figmaRelatedId: transformedIds.figmaRelatedId ? `M${transformedIds.figmaRelatedId}` : undefined
};
};
const getRelatedNodeId = (nodeId: string): string | undefined => {
const ids = nodeId.split(';');
if (ids.length > 1) {
return ids.slice(1).join(';');
}
};
const normalizeNodeId = (nodeId: string): string => {
return nodeId.replace('I', '');
};