0
Fork 0
mirror of https://github.com/penpot/penpot-exporter-figma-plugin.git synced 2025-01-03 05:10:13 -05:00

add transformChildren

This commit is contained in:
Jordi Sala Morales 2024-04-15 12:06:38 +00:00
parent 590a3f7c62
commit 2609710508
No known key found for this signature in database
GPG key ID: C5127140107F55FD
5 changed files with 21 additions and 13 deletions

View file

@ -1 +1,2 @@
export * from './transformChildren';
export * from './transformDimensionAndPosition'; export * from './transformDimensionAndPosition';

View file

@ -0,0 +1,13 @@
import { Children } from '@ui/lib/types/utils/children';
import { transformSceneNode } from '../transformSceneNode';
export const transformChildren = async (
node: ChildrenMixin,
baseX: number = 0,
baseY: number = 0
): Promise<Children> => {
return {
children: await Promise.all(node.children.map(child => transformSceneNode(child, baseX, baseY)))
};
};

View file

@ -1,10 +1,9 @@
import { transformDimensionAndPosition } from '@plugin/transformers/partials'; import { transformDimensionAndPosition } from '@plugin/transformers/partials';
import { transformChildren } from '@plugin/transformers/partials';
import { translateFills } from '@plugin/translators'; import { translateFills } from '@plugin/translators';
import { FrameShape } from '@ui/lib/types/frame/frameShape'; import { FrameShape } from '@ui/lib/types/frame/frameShape';
import { transformSceneNode } from '.';
export const transformFrameNode = async ( export const transformFrameNode = async (
node: FrameNode, node: FrameNode,
baseX: number, baseX: number,
@ -14,9 +13,7 @@ export const transformFrameNode = async (
type: 'frame', type: 'frame',
name: node.name, name: node.name,
fills: translateFills(node.fills, node.width, node.height), fills: translateFills(node.fills, node.width, node.height),
children: await Promise.all( ...(await transformChildren(node, baseX, baseY)),
node.children.map(child => transformSceneNode(child, baseX + node.x, baseY + node.y))
),
...transformDimensionAndPosition(node, baseX, baseY) ...transformDimensionAndPosition(node, baseX, baseY)
}; };
}; };

View file

@ -1,9 +1,8 @@
import { transformDimensionAndPosition } from '@plugin/transformers/partials'; import { transformDimensionAndPosition } from '@plugin/transformers/partials';
import { transformChildren } from '@plugin/transformers/partials';
import { GroupShape } from '@ui/lib/types/group/groupShape'; import { GroupShape } from '@ui/lib/types/group/groupShape';
import { transformSceneNode } from '.';
export const transformGroupNode = async ( export const transformGroupNode = async (
node: GroupNode, node: GroupNode,
baseX: number, baseX: number,
@ -12,9 +11,7 @@ export const transformGroupNode = async (
return { return {
type: 'group', type: 'group',
name: node.name, name: node.name,
children: await Promise.all( ...(await transformChildren(node, baseX, baseY)),
node.children.map(child => transformSceneNode(child, baseX, baseY))
),
...transformDimensionAndPosition(node, baseX, baseY) ...transformDimensionAndPosition(node, baseX, baseY)
}; };
}; };

View file

@ -1,10 +1,10 @@
import { PenpotPage } from '@ui/lib/types/penpotPage'; import { transformChildren } from '@plugin/transformers/partials';
import { transformSceneNode } from '.'; import { PenpotPage } from '@ui/lib/types/penpotPage';
export const transformPageNode = async (node: PageNode): Promise<PenpotPage> => { export const transformPageNode = async (node: PageNode): Promise<PenpotPage> => {
return { return {
name: node.name, name: node.name,
children: await Promise.all(node.children.map(child => transformSceneNode(child))) ...(await transformChildren(node))
}; };
}; };