mirror of
https://github.com/penpot/penpot-exporter-figma-plugin.git
synced 2025-01-03 05:10:13 -05:00
zIndex
This commit is contained in:
parent
18d1a5dab7
commit
9f5f05d2a9
17 changed files with 152 additions and 86 deletions
|
@ -6,16 +6,29 @@ const nodeActsAsMask = (node: SceneNode): boolean => {
|
||||||
return 'isMask' in node && node.isMask;
|
return 'isMask' in node && node.isMask;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const nodeIsLayoutWithItemReverseZIndex = (node: ChildrenMixin): boolean => {
|
||||||
|
return !!('itemReverseZIndex' in node && node.itemReverseZIndex);
|
||||||
|
};
|
||||||
|
|
||||||
export const transformChildren = async (
|
export const transformChildren = async (
|
||||||
node: ChildrenMixin,
|
node: ChildrenMixin,
|
||||||
baseX: number = 0,
|
baseX: number = 0,
|
||||||
baseY: number = 0
|
baseY: number = 0,
|
||||||
|
zIndex: number = 0
|
||||||
): Promise<Children> => {
|
): Promise<Children> => {
|
||||||
const maskIndex = node.children.findIndex(nodeActsAsMask);
|
const maskIndex = node.children.findIndex(nodeActsAsMask);
|
||||||
const containsMask = maskIndex !== -1;
|
const containsMask = maskIndex !== -1;
|
||||||
|
const itemReverseZIndex = nodeIsLayoutWithItemReverseZIndex(node);
|
||||||
return {
|
return {
|
||||||
children: containsMask
|
children: containsMask
|
||||||
? await translateMaskChildren(node.children, maskIndex, baseX, baseY)
|
? await translateMaskChildren(
|
||||||
: await translateChildren(node.children, baseX, baseY)
|
node.children,
|
||||||
|
maskIndex,
|
||||||
|
baseX,
|
||||||
|
baseY,
|
||||||
|
zIndex,
|
||||||
|
itemReverseZIndex
|
||||||
|
)
|
||||||
|
: await translateChildren(node.children, baseX, baseY, zIndex, itemReverseZIndex)
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -30,19 +30,23 @@ export const transformAutoLayout = (node: BaseFrameMixin): LayoutAttributes => {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const transformLayoutSizing = (
|
export const transformLayoutAttributes = (
|
||||||
node: LayoutMixin
|
node: LayoutMixin
|
||||||
): Pick<LayoutChildAttributes, 'layoutItemH-Sizing' | 'layoutItemV-Sizing'> => {
|
): Pick<
|
||||||
|
LayoutChildAttributes,
|
||||||
|
'layoutItemH-Sizing' | 'layoutItemV-Sizing' | 'layoutItemAbsolute'
|
||||||
|
> => {
|
||||||
return {
|
return {
|
||||||
'layoutItemH-Sizing': translateLayoutSizing(node.layoutSizingHorizontal),
|
'layoutItemH-Sizing': translateLayoutSizing(node.layoutSizingHorizontal),
|
||||||
'layoutItemV-Sizing': translateLayoutSizing(node.layoutSizingVertical)
|
'layoutItemV-Sizing': translateLayoutSizing(node.layoutSizingVertical),
|
||||||
|
'layoutItemAbsolute': node.layoutPositioning === 'ABSOLUTE'
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const transformAutoLayoutPosition = (
|
export const transformLayoutItemZIndex = (
|
||||||
node: AutoLayoutChildrenMixin
|
zIndex: number
|
||||||
): Pick<LayoutChildAttributes, 'layoutItemAbsolute'> => {
|
): Pick<LayoutChildAttributes, 'layoutItemZ-Index'> => {
|
||||||
return {
|
return {
|
||||||
layoutItemAbsolute: node.layoutPositioning === 'ABSOLUTE'
|
'layoutItemZ-Index': zIndex
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import { parseSVG } from 'svg-path-parser';
|
import { parseSVG } from 'svg-path-parser';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
transformAutoLayoutPosition,
|
|
||||||
transformBlend,
|
transformBlend,
|
||||||
transformDimensionAndPositionFromVectorPath,
|
transformDimensionAndPositionFromVectorPath,
|
||||||
transformEffects,
|
transformEffects,
|
||||||
transformLayoutSizing,
|
transformLayoutAttributes,
|
||||||
|
transformLayoutItemZIndex,
|
||||||
transformProportion,
|
transformProportion,
|
||||||
transformSceneNode,
|
transformSceneNode,
|
||||||
transformStrokesFromVector
|
transformStrokesFromVector
|
||||||
|
@ -35,7 +35,8 @@ export const transformVectorPathsAsContent = (
|
||||||
export const transformVectorPaths = (
|
export const transformVectorPaths = (
|
||||||
node: VectorNode,
|
node: VectorNode,
|
||||||
baseX: number,
|
baseX: number,
|
||||||
baseY: number
|
baseY: number,
|
||||||
|
zIndex: number
|
||||||
): PathShape[] => {
|
): PathShape[] => {
|
||||||
const pathShapes = node.vectorPaths
|
const pathShapes = node.vectorPaths
|
||||||
.filter((vectorPath, index) => {
|
.filter((vectorPath, index) => {
|
||||||
|
@ -45,7 +46,14 @@ export const transformVectorPaths = (
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
.map((vectorPath, index) =>
|
.map((vectorPath, index) =>
|
||||||
transformVectorPath(node, vectorPath, (node.vectorNetwork.regions ?? [])[index], baseX, baseY)
|
transformVectorPath(
|
||||||
|
node,
|
||||||
|
vectorPath,
|
||||||
|
(node.vectorNetwork.regions ?? [])[index],
|
||||||
|
baseX,
|
||||||
|
baseY,
|
||||||
|
zIndex
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
const geometryShapes = node.fillGeometry
|
const geometryShapes = node.fillGeometry
|
||||||
|
@ -55,7 +63,7 @@ export const transformVectorPaths = (
|
||||||
vectorPath => normalizePath(vectorPath.data) === normalizePath(geometry.data)
|
vectorPath => normalizePath(vectorPath.data) === normalizePath(geometry.data)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.map(geometry => transformVectorPath(node, geometry, undefined, baseX, baseY));
|
.map(geometry => transformVectorPath(node, geometry, undefined, baseX, baseY, zIndex));
|
||||||
|
|
||||||
return [...geometryShapes, ...pathShapes];
|
return [...geometryShapes, ...pathShapes];
|
||||||
};
|
};
|
||||||
|
@ -92,7 +100,8 @@ const transformVectorPath = (
|
||||||
vectorPath: VectorPath,
|
vectorPath: VectorPath,
|
||||||
vectorRegion: VectorRegion | undefined,
|
vectorRegion: VectorRegion | undefined,
|
||||||
baseX: number,
|
baseX: number,
|
||||||
baseY: number
|
baseY: number,
|
||||||
|
zIndex: number
|
||||||
): PathShape => {
|
): PathShape => {
|
||||||
const normalizedPaths = parseSVG(vectorPath.data);
|
const normalizedPaths = parseSVG(vectorPath.data);
|
||||||
|
|
||||||
|
@ -107,13 +116,13 @@ const transformVectorPath = (
|
||||||
},
|
},
|
||||||
constraintsH: 'scale',
|
constraintsH: 'scale',
|
||||||
constraintsV: 'scale',
|
constraintsV: 'scale',
|
||||||
|
...transformLayoutItemZIndex(zIndex),
|
||||||
...transformStrokesFromVector(node, normalizedPaths, vectorRegion),
|
...transformStrokesFromVector(node, normalizedPaths, vectorRegion),
|
||||||
...transformEffects(node),
|
...transformEffects(node),
|
||||||
...transformDimensionAndPositionFromVectorPath(vectorPath, baseX, baseY),
|
...transformDimensionAndPositionFromVectorPath(vectorPath, baseX, baseY),
|
||||||
...transformSceneNode(node),
|
...transformSceneNode(node),
|
||||||
...transformBlend(node),
|
...transformBlend(node),
|
||||||
...transformProportion(node),
|
...transformProportion(node),
|
||||||
...transformLayoutSizing(node),
|
...transformLayoutAttributes(node)
|
||||||
...transformAutoLayoutPosition(node)
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
import {
|
import {
|
||||||
transformAutoLayoutPosition,
|
|
||||||
transformBlend,
|
transformBlend,
|
||||||
transformChildren,
|
transformChildren,
|
||||||
transformDimensionAndPosition,
|
transformDimensionAndPosition,
|
||||||
transformEffects,
|
transformEffects,
|
||||||
transformFigmaIds,
|
transformFigmaIds,
|
||||||
transformFills,
|
transformFills,
|
||||||
transformLayoutSizing,
|
transformLayoutAttributes,
|
||||||
|
transformLayoutItemZIndex,
|
||||||
transformProportion,
|
transformProportion,
|
||||||
transformSceneNode,
|
transformSceneNode,
|
||||||
transformStrokes
|
transformStrokes
|
||||||
|
@ -18,12 +18,14 @@ import { BoolShape } from '@ui/lib/types/shapes/boolShape';
|
||||||
export const transformBooleanNode = async (
|
export const transformBooleanNode = async (
|
||||||
node: BooleanOperationNode,
|
node: BooleanOperationNode,
|
||||||
baseX: number,
|
baseX: number,
|
||||||
baseY: number
|
baseY: number,
|
||||||
|
zIndex: number
|
||||||
): Promise<BoolShape> => {
|
): Promise<BoolShape> => {
|
||||||
return {
|
return {
|
||||||
type: 'bool',
|
type: 'bool',
|
||||||
name: node.name,
|
name: node.name,
|
||||||
boolType: translateBoolType(node.booleanOperation),
|
boolType: translateBoolType(node.booleanOperation),
|
||||||
|
...transformLayoutItemZIndex(zIndex),
|
||||||
...transformFigmaIds(node),
|
...transformFigmaIds(node),
|
||||||
...(await transformChildren(node, baseX, baseY)),
|
...(await transformChildren(node, baseX, baseY)),
|
||||||
...transformFills(node),
|
...transformFills(node),
|
||||||
|
@ -33,7 +35,6 @@ export const transformBooleanNode = async (
|
||||||
...transformSceneNode(node),
|
...transformSceneNode(node),
|
||||||
...transformBlend(node),
|
...transformBlend(node),
|
||||||
...transformProportion(node),
|
...transformProportion(node),
|
||||||
...transformLayoutSizing(node),
|
...transformLayoutAttributes(node)
|
||||||
...transformAutoLayoutPosition(node)
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import { componentsLibrary } from '@plugin/ComponentLibrary';
|
import { componentsLibrary } from '@plugin/ComponentLibrary';
|
||||||
import {
|
import {
|
||||||
transformAutoLayout,
|
transformAutoLayout,
|
||||||
transformAutoLayoutPosition,
|
|
||||||
transformBlend,
|
transformBlend,
|
||||||
transformChildren,
|
transformChildren,
|
||||||
transformConstraints,
|
transformConstraints,
|
||||||
|
@ -10,7 +9,8 @@ import {
|
||||||
transformEffects,
|
transformEffects,
|
||||||
transformFigmaIds,
|
transformFigmaIds,
|
||||||
transformFills,
|
transformFills,
|
||||||
transformLayoutSizing,
|
transformLayoutAttributes,
|
||||||
|
transformLayoutItemZIndex,
|
||||||
transformProportion,
|
transformProportion,
|
||||||
transformSceneNode,
|
transformSceneNode,
|
||||||
transformStrokes
|
transformStrokes
|
||||||
|
@ -21,13 +21,15 @@ import { ComponentRoot } from '@ui/types';
|
||||||
export const transformComponentNode = async (
|
export const transformComponentNode = async (
|
||||||
node: ComponentNode,
|
node: ComponentNode,
|
||||||
baseX: number,
|
baseX: number,
|
||||||
baseY: number
|
baseY: number,
|
||||||
|
zIndex: number
|
||||||
): Promise<ComponentRoot> => {
|
): Promise<ComponentRoot> => {
|
||||||
componentsLibrary.register(node.id, {
|
componentsLibrary.register(node.id, {
|
||||||
type: 'component',
|
type: 'component',
|
||||||
name: node.name,
|
name: node.name,
|
||||||
path: node.parent?.type === 'COMPONENT_SET' ? node.parent.name : '',
|
path: node.parent?.type === 'COMPONENT_SET' ? node.parent.name : '',
|
||||||
showContent: !node.clipsContent,
|
showContent: !node.clipsContent,
|
||||||
|
...transformLayoutItemZIndex(zIndex),
|
||||||
...transformFigmaIds(node),
|
...transformFigmaIds(node),
|
||||||
...transformFills(node),
|
...transformFills(node),
|
||||||
...transformEffects(node),
|
...transformEffects(node),
|
||||||
|
@ -35,10 +37,9 @@ export const transformComponentNode = async (
|
||||||
...transformSceneNode(node),
|
...transformSceneNode(node),
|
||||||
...transformBlend(node),
|
...transformBlend(node),
|
||||||
...transformProportion(node),
|
...transformProportion(node),
|
||||||
...transformLayoutSizing(node),
|
...transformLayoutAttributes(node),
|
||||||
...transformAutoLayoutPosition(node),
|
|
||||||
...transformCornerRadius(node),
|
...transformCornerRadius(node),
|
||||||
...(await transformChildren(node, baseX + node.x, baseY + node.y)),
|
...(await transformChildren(node, baseX + node.x, baseY + node.y, zIndex)),
|
||||||
...transformDimensionAndPosition(node, baseX, baseY),
|
...transformDimensionAndPosition(node, baseX, baseY),
|
||||||
...transformConstraints(node),
|
...transformConstraints(node),
|
||||||
...transformAutoLayout(node)
|
...transformAutoLayout(node)
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
import {
|
import {
|
||||||
transformAutoLayoutPosition,
|
|
||||||
transformBlend,
|
transformBlend,
|
||||||
transformConstraints,
|
transformConstraints,
|
||||||
transformDimension,
|
transformDimension,
|
||||||
transformEffects,
|
transformEffects,
|
||||||
transformFigmaIds,
|
transformFigmaIds,
|
||||||
transformFills,
|
transformFills,
|
||||||
transformLayoutSizing,
|
transformLayoutAttributes,
|
||||||
|
transformLayoutItemZIndex,
|
||||||
transformProportion,
|
transformProportion,
|
||||||
transformRotationAndPosition,
|
transformRotationAndPosition,
|
||||||
transformSceneNode,
|
transformSceneNode,
|
||||||
|
@ -18,11 +18,13 @@ import { CircleShape } from '@ui/lib/types/shapes/circleShape';
|
||||||
export const transformEllipseNode = (
|
export const transformEllipseNode = (
|
||||||
node: EllipseNode,
|
node: EllipseNode,
|
||||||
baseX: number,
|
baseX: number,
|
||||||
baseY: number
|
baseY: number,
|
||||||
|
zIndex: number
|
||||||
): CircleShape => {
|
): CircleShape => {
|
||||||
return {
|
return {
|
||||||
type: 'circle',
|
type: 'circle',
|
||||||
name: node.name,
|
name: node.name,
|
||||||
|
...transformLayoutItemZIndex(zIndex),
|
||||||
...transformFigmaIds(node),
|
...transformFigmaIds(node),
|
||||||
...transformFills(node),
|
...transformFills(node),
|
||||||
...transformEffects(node),
|
...transformEffects(node),
|
||||||
|
@ -32,8 +34,7 @@ export const transformEllipseNode = (
|
||||||
...transformSceneNode(node),
|
...transformSceneNode(node),
|
||||||
...transformBlend(node),
|
...transformBlend(node),
|
||||||
...transformProportion(node),
|
...transformProportion(node),
|
||||||
...transformLayoutSizing(node),
|
...transformLayoutAttributes(node),
|
||||||
...transformAutoLayoutPosition(node),
|
|
||||||
...transformConstraints(node)
|
...transformConstraints(node)
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import {
|
import {
|
||||||
transformAutoLayout,
|
transformAutoLayout,
|
||||||
transformAutoLayoutPosition,
|
|
||||||
transformBlend,
|
transformBlend,
|
||||||
transformChildren,
|
transformChildren,
|
||||||
transformConstraints,
|
transformConstraints,
|
||||||
|
@ -9,7 +8,8 @@ import {
|
||||||
transformEffects,
|
transformEffects,
|
||||||
transformFigmaIds,
|
transformFigmaIds,
|
||||||
transformFills,
|
transformFills,
|
||||||
transformLayoutSizing,
|
transformLayoutAttributes,
|
||||||
|
transformLayoutItemZIndex,
|
||||||
transformProportion,
|
transformProportion,
|
||||||
transformSceneNode,
|
transformSceneNode,
|
||||||
transformStrokes
|
transformStrokes
|
||||||
|
@ -24,7 +24,8 @@ const isSectionNode = (node: FrameNode | SectionNode | ComponentSetNode): node i
|
||||||
export const transformFrameNode = async (
|
export const transformFrameNode = async (
|
||||||
node: FrameNode | SectionNode | ComponentSetNode,
|
node: FrameNode | SectionNode | ComponentSetNode,
|
||||||
baseX: number,
|
baseX: number,
|
||||||
baseY: number
|
baseY: number,
|
||||||
|
zIndex: number
|
||||||
): Promise<FrameShape> => {
|
): Promise<FrameShape> => {
|
||||||
let frameSpecificAttributes: Partial<FrameShape> = {};
|
let frameSpecificAttributes: Partial<FrameShape> = {};
|
||||||
|
|
||||||
|
@ -37,8 +38,7 @@ export const transformFrameNode = async (
|
||||||
// @see: https://forum.figma.com/t/add-a-blendmode-property-for-sectionnode/58560
|
// @see: https://forum.figma.com/t/add-a-blendmode-property-for-sectionnode/58560
|
||||||
...transformBlend(node),
|
...transformBlend(node),
|
||||||
...transformProportion(node),
|
...transformProportion(node),
|
||||||
...transformLayoutSizing(node),
|
...transformLayoutAttributes(node),
|
||||||
...transformAutoLayoutPosition(node),
|
|
||||||
...transformCornerRadius(node),
|
...transformCornerRadius(node),
|
||||||
...transformEffects(node),
|
...transformEffects(node),
|
||||||
...transformConstraints(node),
|
...transformConstraints(node),
|
||||||
|
@ -50,10 +50,11 @@ export const transformFrameNode = async (
|
||||||
type: 'frame',
|
type: 'frame',
|
||||||
name: node.name,
|
name: node.name,
|
||||||
showContent: isSectionNode(node) ? true : !node.clipsContent,
|
showContent: isSectionNode(node) ? true : !node.clipsContent,
|
||||||
|
...transformLayoutItemZIndex(zIndex),
|
||||||
...transformFigmaIds(node),
|
...transformFigmaIds(node),
|
||||||
...transformFills(node),
|
...transformFills(node),
|
||||||
...frameSpecificAttributes,
|
...frameSpecificAttributes,
|
||||||
...(await transformChildren(node, baseX + node.x, baseY + node.y)),
|
...(await transformChildren(node, baseX + node.x, baseY + node.y, zIndex)),
|
||||||
...transformDimensionAndPosition(node, baseX, baseY),
|
...transformDimensionAndPosition(node, baseX, baseY),
|
||||||
...transformSceneNode(node)
|
...transformSceneNode(node)
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,6 +3,7 @@ import {
|
||||||
transformDimensionAndPosition,
|
transformDimensionAndPosition,
|
||||||
transformEffects,
|
transformEffects,
|
||||||
transformFigmaIds,
|
transformFigmaIds,
|
||||||
|
transformLayoutItemZIndex,
|
||||||
transformSceneNode
|
transformSceneNode
|
||||||
} from '@plugin/transformers/partials';
|
} from '@plugin/transformers/partials';
|
||||||
import { transformChildren } from '@plugin/transformers/partials';
|
import { transformChildren } from '@plugin/transformers/partials';
|
||||||
|
@ -12,11 +13,12 @@ import { GroupShape } from '@ui/lib/types/shapes/groupShape';
|
||||||
export const transformGroupNode = async (
|
export const transformGroupNode = async (
|
||||||
node: GroupNode,
|
node: GroupNode,
|
||||||
baseX: number,
|
baseX: number,
|
||||||
baseY: number
|
baseY: number,
|
||||||
|
zIndex: number
|
||||||
): Promise<GroupShape> => {
|
): Promise<GroupShape> => {
|
||||||
return {
|
return {
|
||||||
...transformFigmaIds(node),
|
...transformFigmaIds(node),
|
||||||
...transformGroupNodeLike(node, baseX, baseY),
|
...transformGroupNodeLike(node, baseX, baseY, zIndex),
|
||||||
...transformEffects(node),
|
...transformEffects(node),
|
||||||
...transformBlend(node),
|
...transformBlend(node),
|
||||||
...(await transformChildren(node, baseX, baseY))
|
...(await transformChildren(node, baseX, baseY))
|
||||||
|
@ -26,11 +28,13 @@ export const transformGroupNode = async (
|
||||||
export const transformGroupNodeLike = (
|
export const transformGroupNodeLike = (
|
||||||
node: BaseNodeMixin & DimensionAndPositionMixin & SceneNodeMixin,
|
node: BaseNodeMixin & DimensionAndPositionMixin & SceneNodeMixin,
|
||||||
baseX: number,
|
baseX: number,
|
||||||
baseY: number
|
baseY: number,
|
||||||
|
zIndex: number
|
||||||
): GroupShape => {
|
): GroupShape => {
|
||||||
return {
|
return {
|
||||||
type: 'group',
|
type: 'group',
|
||||||
name: node.name,
|
name: node.name,
|
||||||
|
...transformLayoutItemZIndex(zIndex),
|
||||||
...transformDimensionAndPosition(node, baseX, baseY),
|
...transformDimensionAndPosition(node, baseX, baseY),
|
||||||
...transformSceneNode(node)
|
...transformSceneNode(node)
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import { remoteComponentLibrary } from '@plugin/RemoteComponentLibrary';
|
import { remoteComponentLibrary } from '@plugin/RemoteComponentLibrary';
|
||||||
import {
|
import {
|
||||||
transformAutoLayout,
|
transformAutoLayout,
|
||||||
transformAutoLayoutPosition,
|
|
||||||
transformBlend,
|
transformBlend,
|
||||||
transformChildren,
|
transformChildren,
|
||||||
transformConstraints,
|
transformConstraints,
|
||||||
|
@ -10,7 +9,8 @@ import {
|
||||||
transformEffects,
|
transformEffects,
|
||||||
transformFigmaIds,
|
transformFigmaIds,
|
||||||
transformFills,
|
transformFills,
|
||||||
transformLayoutSizing,
|
transformLayoutAttributes,
|
||||||
|
transformLayoutItemZIndex,
|
||||||
transformProportion,
|
transformProportion,
|
||||||
transformSceneNode,
|
transformSceneNode,
|
||||||
transformStrokes
|
transformStrokes
|
||||||
|
@ -21,7 +21,8 @@ import { ComponentInstance } from '@ui/types';
|
||||||
export const transformInstanceNode = async (
|
export const transformInstanceNode = async (
|
||||||
node: InstanceNode,
|
node: InstanceNode,
|
||||||
baseX: number,
|
baseX: number,
|
||||||
baseY: number
|
baseY: number,
|
||||||
|
zIndex: number
|
||||||
): Promise<ComponentInstance | undefined> => {
|
): Promise<ComponentInstance | undefined> => {
|
||||||
const mainComponent = await node.getMainComponentAsync();
|
const mainComponent = await node.getMainComponentAsync();
|
||||||
|
|
||||||
|
@ -39,6 +40,7 @@ export const transformInstanceNode = async (
|
||||||
mainComponentFigmaId: mainComponent.id,
|
mainComponentFigmaId: mainComponent.id,
|
||||||
isComponentRoot: isComponentRoot(node),
|
isComponentRoot: isComponentRoot(node),
|
||||||
showContent: !node.clipsContent,
|
showContent: !node.clipsContent,
|
||||||
|
...transformLayoutItemZIndex(zIndex),
|
||||||
...transformFigmaIds(node),
|
...transformFigmaIds(node),
|
||||||
...transformFills(node),
|
...transformFills(node),
|
||||||
...transformEffects(node),
|
...transformEffects(node),
|
||||||
|
@ -46,13 +48,12 @@ export const transformInstanceNode = async (
|
||||||
...transformSceneNode(node),
|
...transformSceneNode(node),
|
||||||
...transformBlend(node),
|
...transformBlend(node),
|
||||||
...transformProportion(node),
|
...transformProportion(node),
|
||||||
...transformLayoutSizing(node),
|
...transformLayoutAttributes(node),
|
||||||
...transformAutoLayoutPosition(node),
|
|
||||||
...transformCornerRadius(node),
|
...transformCornerRadius(node),
|
||||||
...transformDimensionAndPosition(node, baseX, baseY),
|
...transformDimensionAndPosition(node, baseX, baseY),
|
||||||
...transformConstraints(node),
|
...transformConstraints(node),
|
||||||
...transformAutoLayout(node),
|
...transformAutoLayout(node),
|
||||||
...(await transformChildren(node, baseX + node.x, baseY + node.y))
|
...(await transformChildren(node, baseX + node.x, baseY + node.y, zIndex))
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
import {
|
import {
|
||||||
transformAutoLayoutPosition,
|
|
||||||
transformBlend,
|
transformBlend,
|
||||||
transformConstraints,
|
transformConstraints,
|
||||||
transformDimensionAndPosition,
|
transformDimensionAndPosition,
|
||||||
transformEffects,
|
transformEffects,
|
||||||
transformFigmaIds,
|
transformFigmaIds,
|
||||||
transformFills,
|
transformFills,
|
||||||
transformLayoutSizing,
|
transformLayoutAttributes,
|
||||||
|
transformLayoutItemZIndex,
|
||||||
transformProportion,
|
transformProportion,
|
||||||
transformSceneNode,
|
transformSceneNode,
|
||||||
transformStrokes,
|
transformStrokes,
|
||||||
|
@ -22,11 +22,13 @@ const hasFillGeometry = (node: StarNode | LineNode | PolygonNode): boolean => {
|
||||||
export const transformPathNode = (
|
export const transformPathNode = (
|
||||||
node: StarNode | LineNode | PolygonNode,
|
node: StarNode | LineNode | PolygonNode,
|
||||||
baseX: number,
|
baseX: number,
|
||||||
baseY: number
|
baseY: number,
|
||||||
|
zIndex: number
|
||||||
): PathShape => {
|
): PathShape => {
|
||||||
return {
|
return {
|
||||||
type: 'path',
|
type: 'path',
|
||||||
name: node.name,
|
name: node.name,
|
||||||
|
...transformLayoutItemZIndex(zIndex),
|
||||||
...transformFigmaIds(node),
|
...transformFigmaIds(node),
|
||||||
...(hasFillGeometry(node) ? transformFills(node) : []),
|
...(hasFillGeometry(node) ? transformFills(node) : []),
|
||||||
...transformStrokes(node),
|
...transformStrokes(node),
|
||||||
|
@ -36,8 +38,7 @@ export const transformPathNode = (
|
||||||
...transformSceneNode(node),
|
...transformSceneNode(node),
|
||||||
...transformBlend(node),
|
...transformBlend(node),
|
||||||
...transformProportion(node),
|
...transformProportion(node),
|
||||||
...transformLayoutSizing(node),
|
...transformLayoutAttributes(node),
|
||||||
...transformAutoLayoutPosition(node),
|
|
||||||
...transformConstraints(node)
|
...transformConstraints(node)
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import {
|
import {
|
||||||
transformAutoLayoutPosition,
|
|
||||||
transformBlend,
|
transformBlend,
|
||||||
transformConstraints,
|
transformConstraints,
|
||||||
transformCornerRadius,
|
transformCornerRadius,
|
||||||
|
@ -7,7 +6,8 @@ import {
|
||||||
transformEffects,
|
transformEffects,
|
||||||
transformFigmaIds,
|
transformFigmaIds,
|
||||||
transformFills,
|
transformFills,
|
||||||
transformLayoutSizing,
|
transformLayoutAttributes,
|
||||||
|
transformLayoutItemZIndex,
|
||||||
transformProportion,
|
transformProportion,
|
||||||
transformRotationAndPosition,
|
transformRotationAndPosition,
|
||||||
transformSceneNode,
|
transformSceneNode,
|
||||||
|
@ -19,11 +19,13 @@ import { RectShape } from '@ui/lib/types/shapes/rectShape';
|
||||||
export const transformRectangleNode = (
|
export const transformRectangleNode = (
|
||||||
node: RectangleNode,
|
node: RectangleNode,
|
||||||
baseX: number,
|
baseX: number,
|
||||||
baseY: number
|
baseY: number,
|
||||||
|
zIndex: number
|
||||||
): RectShape => {
|
): RectShape => {
|
||||||
return {
|
return {
|
||||||
type: 'rect',
|
type: 'rect',
|
||||||
name: node.name,
|
name: node.name,
|
||||||
|
...transformLayoutItemZIndex(zIndex),
|
||||||
...transformFigmaIds(node),
|
...transformFigmaIds(node),
|
||||||
...transformFills(node),
|
...transformFills(node),
|
||||||
...transformEffects(node),
|
...transformEffects(node),
|
||||||
|
@ -33,8 +35,7 @@ export const transformRectangleNode = (
|
||||||
...transformSceneNode(node),
|
...transformSceneNode(node),
|
||||||
...transformBlend(node),
|
...transformBlend(node),
|
||||||
...transformProportion(node),
|
...transformProportion(node),
|
||||||
...transformLayoutSizing(node),
|
...transformLayoutAttributes(node),
|
||||||
...transformAutoLayoutPosition(node),
|
|
||||||
...transformCornerRadius(node),
|
...transformCornerRadius(node),
|
||||||
...transformConstraints(node)
|
...transformConstraints(node)
|
||||||
};
|
};
|
||||||
|
|
|
@ -16,7 +16,8 @@ import {
|
||||||
export const transformSceneNode = async (
|
export const transformSceneNode = async (
|
||||||
node: SceneNode,
|
node: SceneNode,
|
||||||
baseX: number = 0,
|
baseX: number = 0,
|
||||||
baseY: number = 0
|
baseY: number = 0,
|
||||||
|
zIndex: number = 0
|
||||||
): Promise<PenpotNode | undefined> => {
|
): Promise<PenpotNode | undefined> => {
|
||||||
let penpotNode: PenpotNode | undefined;
|
let penpotNode: PenpotNode | undefined;
|
||||||
|
|
||||||
|
@ -27,38 +28,38 @@ export const transformSceneNode = async (
|
||||||
|
|
||||||
switch (node.type) {
|
switch (node.type) {
|
||||||
case 'RECTANGLE':
|
case 'RECTANGLE':
|
||||||
penpotNode = transformRectangleNode(node, baseX, baseY);
|
penpotNode = transformRectangleNode(node, baseX, baseY, zIndex);
|
||||||
break;
|
break;
|
||||||
case 'ELLIPSE':
|
case 'ELLIPSE':
|
||||||
penpotNode = transformEllipseNode(node, baseX, baseY);
|
penpotNode = transformEllipseNode(node, baseX, baseY, zIndex);
|
||||||
break;
|
break;
|
||||||
case 'SECTION':
|
case 'SECTION':
|
||||||
case 'FRAME':
|
case 'FRAME':
|
||||||
case 'COMPONENT_SET':
|
case 'COMPONENT_SET':
|
||||||
penpotNode = await transformFrameNode(node, baseX, baseY);
|
penpotNode = await transformFrameNode(node, baseX, baseY, zIndex);
|
||||||
break;
|
break;
|
||||||
case 'GROUP':
|
case 'GROUP':
|
||||||
penpotNode = await transformGroupNode(node, baseX, baseY);
|
penpotNode = await transformGroupNode(node, baseX, baseY, zIndex);
|
||||||
break;
|
break;
|
||||||
case 'TEXT':
|
case 'TEXT':
|
||||||
penpotNode = transformTextNode(node, baseX, baseY);
|
penpotNode = transformTextNode(node, baseX, baseY, zIndex);
|
||||||
break;
|
break;
|
||||||
case 'VECTOR':
|
case 'VECTOR':
|
||||||
penpotNode = transformVectorNode(node, baseX, baseY);
|
penpotNode = transformVectorNode(node, baseX, baseY, zIndex);
|
||||||
break;
|
break;
|
||||||
case 'STAR':
|
case 'STAR':
|
||||||
case 'POLYGON':
|
case 'POLYGON':
|
||||||
case 'LINE':
|
case 'LINE':
|
||||||
penpotNode = transformPathNode(node, baseX, baseY);
|
penpotNode = transformPathNode(node, baseX, baseY, zIndex);
|
||||||
break;
|
break;
|
||||||
case 'BOOLEAN_OPERATION':
|
case 'BOOLEAN_OPERATION':
|
||||||
penpotNode = await transformBooleanNode(node, baseX, baseY);
|
penpotNode = await transformBooleanNode(node, baseX, baseY, zIndex);
|
||||||
break;
|
break;
|
||||||
case 'COMPONENT':
|
case 'COMPONENT':
|
||||||
penpotNode = await transformComponentNode(node, baseX, baseY);
|
penpotNode = await transformComponentNode(node, baseX, baseY, zIndex);
|
||||||
break;
|
break;
|
||||||
case 'INSTANCE':
|
case 'INSTANCE':
|
||||||
penpotNode = await transformInstanceNode(node, baseX, baseY);
|
penpotNode = await transformInstanceNode(node, baseX, baseY, zIndex);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import {
|
import {
|
||||||
transformAutoLayoutPosition,
|
|
||||||
transformBlend,
|
transformBlend,
|
||||||
transformConstraints,
|
transformConstraints,
|
||||||
transformDimensionAndPosition,
|
transformDimensionAndPosition,
|
||||||
transformEffects,
|
transformEffects,
|
||||||
transformFigmaIds,
|
transformFigmaIds,
|
||||||
transformLayoutSizing,
|
transformLayoutAttributes,
|
||||||
|
transformLayoutItemZIndex,
|
||||||
transformProportion,
|
transformProportion,
|
||||||
transformSceneNode,
|
transformSceneNode,
|
||||||
transformStrokes,
|
transformStrokes,
|
||||||
|
@ -14,10 +14,16 @@ import {
|
||||||
|
|
||||||
import { TextShape } from '@ui/lib/types/shapes/textShape';
|
import { TextShape } from '@ui/lib/types/shapes/textShape';
|
||||||
|
|
||||||
export const transformTextNode = (node: TextNode, baseX: number, baseY: number): TextShape => {
|
export const transformTextNode = (
|
||||||
|
node: TextNode,
|
||||||
|
baseX: number,
|
||||||
|
baseY: number,
|
||||||
|
zIndex: number
|
||||||
|
): TextShape => {
|
||||||
return {
|
return {
|
||||||
type: 'text',
|
type: 'text',
|
||||||
name: node.name,
|
name: node.name,
|
||||||
|
...transformLayoutItemZIndex(zIndex),
|
||||||
...transformFigmaIds(node),
|
...transformFigmaIds(node),
|
||||||
...transformText(node),
|
...transformText(node),
|
||||||
...transformDimensionAndPosition(node, baseX, baseY),
|
...transformDimensionAndPosition(node, baseX, baseY),
|
||||||
|
@ -25,8 +31,7 @@ export const transformTextNode = (node: TextNode, baseX: number, baseY: number):
|
||||||
...transformSceneNode(node),
|
...transformSceneNode(node),
|
||||||
...transformBlend(node),
|
...transformBlend(node),
|
||||||
...transformProportion(node),
|
...transformProportion(node),
|
||||||
...transformLayoutSizing(node),
|
...transformLayoutAttributes(node),
|
||||||
...transformAutoLayoutPosition(node),
|
|
||||||
...transformStrokes(node),
|
...transformStrokes(node),
|
||||||
...transformConstraints(node)
|
...transformConstraints(node)
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import {
|
import {
|
||||||
transformConstraints,
|
transformConstraints,
|
||||||
transformFigmaIds,
|
transformFigmaIds,
|
||||||
|
transformLayoutItemZIndex,
|
||||||
transformVectorPaths
|
transformVectorPaths
|
||||||
} from '@plugin/transformers/partials';
|
} from '@plugin/transformers/partials';
|
||||||
|
|
||||||
|
@ -18,21 +19,23 @@ import { transformGroupNodeLike } from '.';
|
||||||
export const transformVectorNode = (
|
export const transformVectorNode = (
|
||||||
node: VectorNode,
|
node: VectorNode,
|
||||||
baseX: number,
|
baseX: number,
|
||||||
baseY: number
|
baseY: number,
|
||||||
|
zIndex: number
|
||||||
): GroupShape | PathShape => {
|
): GroupShape | PathShape => {
|
||||||
const children = transformVectorPaths(node, baseX, baseY);
|
const children = transformVectorPaths(node, baseX, baseY, zIndex);
|
||||||
|
|
||||||
if (children.length === 1) {
|
if (children.length === 1) {
|
||||||
return {
|
return {
|
||||||
...children[0],
|
...children[0],
|
||||||
name: node.name,
|
name: node.name,
|
||||||
|
...transformLayoutItemZIndex(zIndex),
|
||||||
...transformFigmaIds(node),
|
...transformFigmaIds(node),
|
||||||
...transformConstraints(node)
|
...transformConstraints(node)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...transformGroupNodeLike(node, baseX, baseY),
|
...transformGroupNodeLike(node, baseX, baseY, zIndex),
|
||||||
...transformFigmaIds(node),
|
...transformFigmaIds(node),
|
||||||
...transformConstraints(node),
|
...transformConstraints(node),
|
||||||
children
|
children
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { remoteComponentLibrary } from '@plugin/RemoteComponentLibrary';
|
import { remoteComponentLibrary } from '@plugin/RemoteComponentLibrary';
|
||||||
import { transformGroupNodeLike, transformSceneNode } from '@plugin/transformers';
|
import { transformGroupNodeLike, transformSceneNode } from '@plugin/transformers';
|
||||||
import { transformMaskFigmaIds } from '@plugin/transformers/partials';
|
import { transformLayoutItemZIndex, transformMaskFigmaIds } from '@plugin/transformers/partials';
|
||||||
import { sleep } from '@plugin/utils';
|
import { sleep } from '@plugin/utils';
|
||||||
|
|
||||||
import { PenpotNode } from '@ui/types';
|
import { PenpotNode } from '@ui/types';
|
||||||
|
@ -18,15 +18,26 @@ export const translateMaskChildren = async (
|
||||||
children: readonly SceneNode[],
|
children: readonly SceneNode[],
|
||||||
maskIndex: number,
|
maskIndex: number,
|
||||||
baseX: number,
|
baseX: number,
|
||||||
baseY: number
|
baseY: number,
|
||||||
|
zIndex: number,
|
||||||
|
itemReverseZIndex: boolean = false
|
||||||
): Promise<PenpotNode[]> => {
|
): Promise<PenpotNode[]> => {
|
||||||
const maskChild = children[maskIndex];
|
const maskChild = children[maskIndex];
|
||||||
const unmaskedChildren = await translateChildren(children.slice(0, maskIndex), baseX, baseY);
|
const unmaskedChildren = await translateChildren(
|
||||||
|
children.slice(0, maskIndex),
|
||||||
|
baseX,
|
||||||
|
baseY,
|
||||||
|
zIndex,
|
||||||
|
itemReverseZIndex
|
||||||
|
);
|
||||||
const maskedChildren = await translateChildren(children.slice(maskIndex), baseX, baseY);
|
const maskedChildren = await translateChildren(children.slice(maskIndex), baseX, baseY);
|
||||||
|
|
||||||
|
const lastZIndex = itemReverseZIndex ? zIndex - unmaskedChildren.length - 1 : zIndex;
|
||||||
|
|
||||||
const maskGroup = {
|
const maskGroup = {
|
||||||
...transformMaskFigmaIds(maskChild),
|
...transformMaskFigmaIds(maskChild),
|
||||||
...transformGroupNodeLike(maskChild, baseX, baseY),
|
...transformGroupNodeLike(maskChild, baseX, baseY, zIndex),
|
||||||
|
...transformLayoutItemZIndex(lastZIndex),
|
||||||
children: maskedChildren,
|
children: maskedChildren,
|
||||||
maskedGroup: true
|
maskedGroup: true
|
||||||
};
|
};
|
||||||
|
@ -37,12 +48,19 @@ export const translateMaskChildren = async (
|
||||||
export const translateChildren = async (
|
export const translateChildren = async (
|
||||||
children: readonly SceneNode[],
|
children: readonly SceneNode[],
|
||||||
baseX: number = 0,
|
baseX: number = 0,
|
||||||
baseY: number = 0
|
baseY: number = 0,
|
||||||
|
zIndex: number = 0,
|
||||||
|
itemReverseZIndex: boolean = false
|
||||||
): Promise<PenpotNode[]> => {
|
): Promise<PenpotNode[]> => {
|
||||||
const transformedChildren: PenpotNode[] = [];
|
const transformedChildren: PenpotNode[] = [];
|
||||||
|
|
||||||
for (const child of children) {
|
for (const child of children) {
|
||||||
const penpotNode = await transformSceneNode(child, baseX, baseY);
|
const penpotNode = await transformSceneNode(
|
||||||
|
child,
|
||||||
|
baseX,
|
||||||
|
baseY,
|
||||||
|
itemReverseZIndex ? zIndex-- : zIndex
|
||||||
|
);
|
||||||
|
|
||||||
if (penpotNode) transformedChildren.push(penpotNode);
|
if (penpotNode) transformedChildren.push(penpotNode);
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { LayoutChildAttributes } from '@ui/lib/types/shapes/layout';
|
||||||
import {
|
import {
|
||||||
ShapeAttributes,
|
ShapeAttributes,
|
||||||
ShapeBaseAttributes,
|
ShapeBaseAttributes,
|
||||||
|
@ -10,7 +11,8 @@ export type GroupShape = ShapeBaseAttributes &
|
||||||
ShapeGeomAttributes &
|
ShapeGeomAttributes &
|
||||||
ShapeAttributes &
|
ShapeAttributes &
|
||||||
GroupAttributes &
|
GroupAttributes &
|
||||||
Children;
|
Children &
|
||||||
|
LayoutChildAttributes;
|
||||||
|
|
||||||
type GroupAttributes = {
|
type GroupAttributes = {
|
||||||
type?: 'group';
|
type?: 'group';
|
||||||
|
|
|
@ -46,7 +46,7 @@ export type LayoutChildAttributes = {
|
||||||
| typeof ITEM_ALIGN_SELF_CENTER
|
| typeof ITEM_ALIGN_SELF_CENTER
|
||||||
| typeof ITEM_ALIGN_SELF_STRETCH;
|
| typeof ITEM_ALIGN_SELF_STRETCH;
|
||||||
'layoutItemAbsolute'?: boolean;
|
'layoutItemAbsolute'?: boolean;
|
||||||
'layoutItemZIndex'?: number;
|
'layoutItemZ-Index'?: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type JustifyAlignContent =
|
export type JustifyAlignContent =
|
||||||
|
|
Loading…
Reference in a new issue