0
Fork 0
mirror of https://github.com/penpot/penpot-exporter-figma-plugin.git synced 2025-01-06 23:00:55 -05:00
penpot-exporter-figma-plugin/plugin-src/transformers/partials/transformChildren.ts
2024-06-11 09:26:38 +02:00

24 lines
779 B
TypeScript

import { translateChildren, translateMaskChildren } from '@plugin/translators';
import { Children } from '@ui/lib/types/utils/children';
const nodeActsAsMask = (node: SceneNode): boolean => {
return 'isMask' in node && node.isMask;
};
export const transformChildren = async (
node: ChildrenMixin,
baseX: number = 0,
baseY: number = 0,
reverseChildrenOrder: boolean = false
): Promise<Children> => {
const maskIndex = node.children.findIndex(nodeActsAsMask);
const containsMask = maskIndex !== -1;
const children = reverseChildrenOrder ? node.children.slice().reverse() : node.children;
return {
children: containsMask
? await translateMaskChildren(children, maskIndex, baseX, baseY)
: await translateChildren(children, baseX, baseY)
};
};