mirror of
https://github.com/penpot/penpot-exporter-figma-plugin.git
synced 2024-12-22 05:33:02 -05:00
c5dd5d011e
* reworked remote components * changeset
63 lines
1.9 KiB
TypeScript
63 lines
1.9 KiB
TypeScript
import { sleep } from '@common/sleep';
|
|
|
|
import { transformGroupNodeLike, transformSceneNode } from '@plugin/transformers';
|
|
import { transformMaskFigmaIds } from '@plugin/transformers/partials';
|
|
|
|
import { PenpotNode } from '@ui/types';
|
|
|
|
/**
|
|
* Translates the children of a node that acts as a mask.
|
|
* We need to split the children into two groups: the ones that are masked and the ones that are not.
|
|
*
|
|
* The masked children will be grouped together in a mask group.
|
|
* The unmasked children will be returned as they are.
|
|
*
|
|
* @maskIndex The index of the mask node in the children array
|
|
*/
|
|
export const translateMaskChildren = async (
|
|
children: readonly SceneNode[],
|
|
maskIndex: number
|
|
): Promise<PenpotNode[]> => {
|
|
const maskChild = children[maskIndex];
|
|
|
|
const unmaskedChildren = await translateChildren(children.slice(0, maskIndex));
|
|
const maskedChildren = await translateChildren(children.slice(maskIndex));
|
|
|
|
if (
|
|
maskChild.type === 'STICKY' ||
|
|
maskChild.type === 'CONNECTOR' ||
|
|
maskChild.type === 'CODE_BLOCK' ||
|
|
maskChild.type === 'WIDGET' ||
|
|
maskChild.type === 'EMBED' ||
|
|
maskChild.type === 'LINK_UNFURL' ||
|
|
maskChild.type === 'MEDIA' ||
|
|
maskChild.type === 'SECTION' ||
|
|
maskChild.type === 'TABLE' ||
|
|
maskChild.type === 'SHAPE_WITH_TEXT'
|
|
) {
|
|
return [...unmaskedChildren, ...maskedChildren];
|
|
}
|
|
|
|
const maskGroup = {
|
|
...transformMaskFigmaIds(maskChild),
|
|
...transformGroupNodeLike(maskChild),
|
|
children: maskedChildren,
|
|
maskedGroup: true
|
|
};
|
|
|
|
return [...unmaskedChildren, maskGroup];
|
|
};
|
|
|
|
export const translateChildren = async (children: readonly SceneNode[]): Promise<PenpotNode[]> => {
|
|
const transformedChildren: PenpotNode[] = [];
|
|
|
|
for (const child of children) {
|
|
const penpotNode = await transformSceneNode(child);
|
|
|
|
if (penpotNode) transformedChildren.push(penpotNode);
|
|
|
|
await sleep(0);
|
|
}
|
|
|
|
return transformedChildren;
|
|
};
|