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

22 lines
656 B
TypeScript
Raw Normal View History

import { translateChildren, translateMaskChildren } from '@plugin/translators';
2024-04-15 07:06:38 -05:00
2024-04-15 07:09:48 -05:00
import { Children } from '@ui/lib/types/utils/children';
2024-04-15 07:06:38 -05:00
const nodeActsAsMask = (node: SceneNode): boolean => {
return 'isMask' in node && node.isMask;
};
2024-04-15 07:06:38 -05:00
export const transformChildren = async (
node: ChildrenMixin,
baseX: number = 0,
2024-06-11 11:52:03 -05:00
baseY: number = 0
2024-04-15 07:06:38 -05:00
): Promise<Children> => {
const maskIndex = node.children.findIndex(nodeActsAsMask);
const containsMask = maskIndex !== -1;
2024-04-15 07:06:38 -05:00
return {
children: containsMask
2024-06-11 11:52:03 -05:00
? await translateMaskChildren(node.children, maskIndex, baseX, baseY)
: await translateChildren(node.children, baseX, baseY)
2024-04-15 07:06:38 -05:00
};
};