0
Fork 0
mirror of https://github.com/penpot/penpot-exporter-figma-plugin.git synced 2024-12-22 05:33:02 -05:00

Constraints translation (#142)

* constraints translation

* fix lint

* fixes

* fix vector constraints

* fix lint
This commit is contained in:
Alex Sánchez 2024-06-06 12:17:17 +02:00 committed by GitHub
parent 12be821b97
commit 02fa3363f5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 86 additions and 12 deletions

View file

@ -0,0 +1,5 @@
---
"penpot-exporter": minor
---
Constraints translation

View file

@ -1,5 +1,6 @@
export * from './transformBlend'; export * from './transformBlend';
export * from './transformChildren'; export * from './transformChildren';
export * from './transformConstraints';
export * from './transformCornerRadius'; export * from './transformCornerRadius';
export * from './transformDimensionAndPosition'; export * from './transformDimensionAndPosition';
export * from './transformEffects'; export * from './transformEffects';

View file

@ -0,0 +1,12 @@
import { translateConstraintH, translateConstraintV } from '@plugin/translators';
import { ShapeAttributes } from '@ui/lib/types/shapes/shape';
export const transformConstraints = (
node: ConstraintMixin
): Pick<ShapeAttributes, 'constraintsH' | 'constraintsV'> => {
return {
constraintsH: translateConstraintH(node.constraints.horizontal),
constraintsV: translateConstraintV(node.constraints.vertical)
};
};

View file

@ -16,8 +16,7 @@ import {
translateWindingRule translateWindingRule
} from '@plugin/translators/vectors'; } from '@plugin/translators/vectors';
import { PathAttributes } from '@ui/lib/types/shapes/pathShape'; import { PathAttributes, PathShape } from '@ui/lib/types/shapes/pathShape';
import { PathShape } from '@ui/lib/types/shapes/pathShape';
export const transformVectorPathsAsContent = ( export const transformVectorPathsAsContent = (
node: StarNode | LineNode | PolygonNode, node: StarNode | LineNode | PolygonNode,
@ -104,6 +103,8 @@ const transformVectorPath = (
svgAttrs: { svgAttrs: {
fillRule: translateWindingRule(vectorPath.windingRule) fillRule: translateWindingRule(vectorPath.windingRule)
}, },
constraintsH: 'scale',
constraintsV: 'scale',
...transformStrokesFromVector(node, normalizedPaths, vectorRegion), ...transformStrokesFromVector(node, normalizedPaths, vectorRegion),
...transformEffects(node), ...transformEffects(node),
...transformDimensionAndPositionFromVectorPath(vectorPath, baseX, baseY), ...transformDimensionAndPositionFromVectorPath(vectorPath, baseX, baseY),

View file

@ -2,6 +2,7 @@ import { componentsLibrary } from '@plugin/ComponentLibrary';
import { import {
transformBlend, transformBlend,
transformChildren, transformChildren,
transformConstraints,
transformCornerRadius, transformCornerRadius,
transformDimensionAndPosition, transformDimensionAndPosition,
transformEffects, transformEffects,
@ -33,7 +34,8 @@ export const transformComponentNode = async (
...transformProportion(node), ...transformProportion(node),
...transformCornerRadius(node), ...transformCornerRadius(node),
...(await transformChildren(node, baseX + node.x, baseY + node.y)), ...(await transformChildren(node, baseX + node.x, baseY + node.y)),
...transformDimensionAndPosition(node, baseX, baseY) ...transformDimensionAndPosition(node, baseX, baseY),
...transformConstraints(node)
}); });
return { return {

View file

@ -1,5 +1,6 @@
import { import {
transformBlend, transformBlend,
transformConstraints,
transformDimension, transformDimension,
transformEffects, transformEffects,
transformFigmaIds, transformFigmaIds,
@ -28,6 +29,7 @@ export const transformEllipseNode = (
...transformRotationAndPosition(node, baseX, baseY), ...transformRotationAndPosition(node, baseX, baseY),
...transformSceneNode(node), ...transformSceneNode(node),
...transformBlend(node), ...transformBlend(node),
...transformProportion(node) ...transformProportion(node),
...transformConstraints(node)
}; };
}; };

View file

@ -1,6 +1,7 @@
import { import {
transformBlend, transformBlend,
transformChildren, transformChildren,
transformConstraints,
transformCornerRadius, transformCornerRadius,
transformDimensionAndPosition, transformDimensionAndPosition,
transformEffects, transformEffects,
@ -34,7 +35,8 @@ export const transformFrameNode = async (
...transformBlend(node), ...transformBlend(node),
...transformProportion(node), ...transformProportion(node),
...transformCornerRadius(node), ...transformCornerRadius(node),
...transformEffects(node) ...transformEffects(node),
...transformConstraints(node)
}; };
} }

View file

@ -2,6 +2,7 @@ import { remoteComponentLibrary } from '@plugin/RemoteComponentLibrary';
import { import {
transformBlend, transformBlend,
transformChildren, transformChildren,
transformConstraints,
transformCornerRadius, transformCornerRadius,
transformDimensionAndPosition, transformDimensionAndPosition,
transformEffects, transformEffects,
@ -44,6 +45,7 @@ export const transformInstanceNode = async (
...transformProportion(node), ...transformProportion(node),
...transformCornerRadius(node), ...transformCornerRadius(node),
...transformDimensionAndPosition(node, baseX, baseY), ...transformDimensionAndPosition(node, baseX, baseY),
...transformConstraints(node),
...(await transformChildren(node, baseX + node.x, baseY + node.y)) ...(await transformChildren(node, baseX + node.x, baseY + node.y))
}; };
}; };

View file

@ -1,5 +1,6 @@
import { import {
transformBlend, transformBlend,
transformConstraints,
transformDimensionAndPosition, transformDimensionAndPosition,
transformEffects, transformEffects,
transformFigmaIds, transformFigmaIds,
@ -32,6 +33,7 @@ export const transformPathNode = (
...transformDimensionAndPosition(node, baseX, baseY), ...transformDimensionAndPosition(node, baseX, baseY),
...transformSceneNode(node), ...transformSceneNode(node),
...transformBlend(node), ...transformBlend(node),
...transformProportion(node) ...transformProportion(node),
...transformConstraints(node)
}; };
}; };

View file

@ -1,5 +1,6 @@
import { import {
transformBlend, transformBlend,
transformConstraints,
transformCornerRadius, transformCornerRadius,
transformDimension, transformDimension,
transformEffects, transformEffects,
@ -30,6 +31,7 @@ export const transformRectangleNode = (
...transformSceneNode(node), ...transformSceneNode(node),
...transformBlend(node), ...transformBlend(node),
...transformProportion(node), ...transformProportion(node),
...transformCornerRadius(node) ...transformCornerRadius(node),
...transformConstraints(node)
}; };
}; };

View file

@ -1,5 +1,6 @@
import { import {
transformBlend, transformBlend,
transformConstraints,
transformDimensionAndPosition, transformDimensionAndPosition,
transformEffects, transformEffects,
transformFigmaIds, transformFigmaIds,
@ -22,6 +23,7 @@ export const transformTextNode = (node: TextNode, baseX: number, baseY: number):
...transformSceneNode(node), ...transformSceneNode(node),
...transformBlend(node), ...transformBlend(node),
...transformProportion(node), ...transformProportion(node),
...transformStrokes(node) ...transformStrokes(node),
...transformConstraints(node)
}; };
}; };

View file

@ -1,4 +1,8 @@
import { transformFigmaIds, transformVectorPaths } from '@plugin/transformers/partials'; import {
transformConstraints,
transformFigmaIds,
transformVectorPaths
} from '@plugin/transformers/partials';
import { GroupShape } from '@ui/lib/types/shapes/groupShape'; import { GroupShape } from '@ui/lib/types/shapes/groupShape';
import { PathShape } from '@ui/lib/types/shapes/pathShape'; import { PathShape } from '@ui/lib/types/shapes/pathShape';
@ -22,13 +26,15 @@ export const transformVectorNode = (
return { return {
...children[0], ...children[0],
name: node.name, name: node.name,
...transformFigmaIds(node) ...transformFigmaIds(node),
...transformConstraints(node)
}; };
} }
return { return {
...transformGroupNodeLike(node, baseX, baseY), ...transformGroupNodeLike(node, baseX, baseY),
...transformFigmaIds(node), ...transformFigmaIds(node),
...transformConstraints(node),
children children
}; };
}; };

View file

@ -2,5 +2,6 @@ export * from './translateBlendMode';
export * from './translateBlurEffects'; export * from './translateBlurEffects';
export * from './translateBoolType'; export * from './translateBoolType';
export * from './translateChildren'; export * from './translateChildren';
export * from './translateConstraints';
export * from './translateShadowEffects'; export * from './translateShadowEffects';
export * from './translateStrokes'; export * from './translateStrokes';

View file

@ -0,0 +1,31 @@
import { ConstraintH, ConstraintV } from '@ui/lib/types/shapes/shape';
export const translateConstraintH = (constraint: ConstraintType): ConstraintH => {
switch (constraint) {
case 'MAX':
return 'right';
case 'MIN':
return 'left';
case 'CENTER':
return 'center';
case 'SCALE':
return 'scale';
case 'STRETCH':
return 'leftright';
}
};
export const translateConstraintV = (constraint: ConstraintType): ConstraintV => {
switch (constraint) {
case 'MAX':
return 'bottom';
case 'MIN':
return 'top';
case 'CENTER':
return 'center';
case 'SCALE':
return 'scale';
case 'STRETCH':
return 'topbottom';
}
};

View file

@ -56,8 +56,8 @@ export type ShapeAttributes = {
hideFillOnExport?: boolean; hideFillOnExport?: boolean;
proportion?: number; proportion?: number;
proportionLock?: boolean; proportionLock?: boolean;
constraintsH?: 'left' | 'right' | 'leftright' | 'center' | 'scale'; constraintsH?: ConstraintH;
constraintsV?: 'top' | 'bottom' | 'topbottom' | 'center' | 'scale'; constraintsV?: ConstraintV;
fixedScroll?: boolean; fixedScroll?: boolean;
rx?: number; rx?: number;
ry?: number; ry?: number;
@ -84,3 +84,6 @@ export type ShapeGeomAttributes = {
}; };
export type GrowType = 'auto-width' | 'auto-height' | 'fixed'; export type GrowType = 'auto-width' | 'auto-height' | 'fixed';
export type ConstraintH = 'left' | 'right' | 'leftright' | 'center' | 'scale';
export type ConstraintV = 'top' | 'bottom' | 'topbottom' | 'center' | 'scale';