Skip to content

Commit

Permalink
constraints translation
Browse files Browse the repository at this point in the history
  • Loading branch information
Cenadros committed Jun 6, 2024
1 parent be5ff3b commit f38384b
Show file tree
Hide file tree
Showing 15 changed files with 63 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/sixty-elephants-help.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"penpot-exporter": minor
---

Constraints translation
1 change: 1 addition & 0 deletions plugin-src/transformers/partials/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from './transformBlend';
export * from './transformChildren';
export * from './transformConstraints';
export * from './transformCornerRadius';
export * from './transformDimensionAndPosition';
export * from './transformEffects';
Expand Down
12 changes: 12 additions & 0 deletions plugin-src/transformers/partials/transformConstraints.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { translateConstraint } from '@plugin/translators';

import { ShapeAttributes } from '@ui/lib/types/shapes/shape';

export const transformConstraints = (
node: ConstraintMixin
): Pick<ShapeAttributes, 'constraintsH' | 'constraintsV'> => {
return {
constraintsH: translateConstraint(node.constraints.horizontal),
constraintsV: translateConstraint(node.constraints.vertical)
};
};
4 changes: 3 additions & 1 deletion plugin-src/transformers/partials/transformVectorPaths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { parseSVG } from 'svg-path-parser';

import {
transformBlend,
transformConstraints,
transformDimensionAndPositionFromVectorPath,
transformEffects,
transformProportion,
Expand Down Expand Up @@ -109,6 +110,7 @@ const transformVectorPath = (
...transformDimensionAndPositionFromVectorPath(vectorPath, baseX, baseY),
...transformSceneNode(node),
...transformBlend(node),
...transformProportion(node)
...transformProportion(node),
...transformConstraints(node)
};
};
1 change: 1 addition & 0 deletions plugin-src/transformers/transformBooleanNode.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
transformBlend,
transformChildren,
transformConstraints,
transformDimensionAndPosition,
transformEffects,
transformFigmaIds,
Expand Down
4 changes: 3 additions & 1 deletion plugin-src/transformers/transformComponentNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { componentsLibrary } from '@plugin/ComponentLibrary';
import {
transformBlend,
transformChildren,
transformConstraints,
transformCornerRadius,
transformDimensionAndPosition,
transformEffects,
Expand Down Expand Up @@ -33,7 +34,8 @@ export const transformComponentNode = async (
...transformProportion(node),
...transformCornerRadius(node),
...(await transformChildren(node, baseX + node.x, baseY + node.y)),
...transformDimensionAndPosition(node, baseX, baseY)
...transformDimensionAndPosition(node, baseX, baseY),
...transformConstraints(node)
});

return {
Expand Down
4 changes: 3 additions & 1 deletion plugin-src/transformers/transformEllipseNode.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
transformBlend,
transformConstraints,
transformDimension,
transformEffects,
transformFigmaIds,
Expand Down Expand Up @@ -28,6 +29,7 @@ export const transformEllipseNode = (
...transformRotationAndPosition(node, baseX, baseY),
...transformSceneNode(node),
...transformBlend(node),
...transformProportion(node)
...transformProportion(node),
...transformConstraints(node)
};
};
4 changes: 3 additions & 1 deletion plugin-src/transformers/transformFrameNode.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
transformBlend,
transformChildren,
transformConstraints,
transformCornerRadius,
transformDimensionAndPosition,
transformEffects,
Expand Down Expand Up @@ -34,7 +35,8 @@ export const transformFrameNode = async (
...transformBlend(node),
...transformProportion(node),
...transformCornerRadius(node),
...transformEffects(node)
...transformEffects(node),
...transformConstraints(node)
};
}

Expand Down
2 changes: 2 additions & 0 deletions plugin-src/transformers/transformInstanceNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { remoteComponentLibrary } from '@plugin/RemoteComponentLibrary';
import {
transformBlend,
transformChildren,
transformConstraints,
transformCornerRadius,
transformDimensionAndPosition,
transformEffects,
Expand Down Expand Up @@ -44,6 +45,7 @@ export const transformInstanceNode = async (
...transformProportion(node),
...transformCornerRadius(node),
...transformDimensionAndPosition(node, baseX, baseY),
...transformConstraints(node),
...(await transformChildren(node, baseX + node.x, baseY + node.y))
};
};
Expand Down
4 changes: 3 additions & 1 deletion plugin-src/transformers/transformPathNode.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
transformBlend,
transformConstraints,
transformDimensionAndPosition,
transformEffects,
transformFigmaIds,
Expand Down Expand Up @@ -32,6 +33,7 @@ export const transformPathNode = (
...transformDimensionAndPosition(node, baseX, baseY),
...transformSceneNode(node),
...transformBlend(node),
...transformProportion(node)
...transformProportion(node),
...transformConstraints(node)
};
};
4 changes: 3 additions & 1 deletion plugin-src/transformers/transformRectangleNode.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
transformBlend,
transformConstraints,
transformCornerRadius,
transformDimension,
transformEffects,
Expand Down Expand Up @@ -30,6 +31,7 @@ export const transformRectangleNode = (
...transformSceneNode(node),
...transformBlend(node),
...transformProportion(node),
...transformCornerRadius(node)
...transformCornerRadius(node),
...transformConstraints(node)
};
};
4 changes: 3 additions & 1 deletion plugin-src/transformers/transformTextNode.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
transformBlend,
transformConstraints,
transformDimensionAndPosition,
transformEffects,
transformFigmaIds,
Expand All @@ -22,6 +23,7 @@ export const transformTextNode = (node: TextNode, baseX: number, baseY: number):
...transformSceneNode(node),
...transformBlend(node),
...transformProportion(node),
...transformStrokes(node)
...transformStrokes(node),
...transformConstraints(node)
};
};
1 change: 1 addition & 0 deletions plugin-src/translators/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ export * from './translateBlendMode';
export * from './translateBlurEffects';
export * from './translateBoolType';
export * from './translateChildren';
export * from './translateConstraint';
export * from './translateShadowEffects';
export * from './translateStrokes';
16 changes: 16 additions & 0 deletions plugin-src/translators/translateConstraint.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Constraint } from '@ui/lib/types/shapes/shape';

export const translateConstraint = (constraint: ConstraintType): Constraint => {
switch (constraint) {
case 'MAX':
return 'right';
case 'MIN':
return 'left';
case 'CENTER':
return 'center';
case 'SCALE':
return 'scale';
case 'STRETCH':
return 'leftright';
}
};
6 changes: 4 additions & 2 deletions ui-src/lib/types/shapes/shape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ export type ShapeAttributes = {
hideFillOnExport?: boolean;
proportion?: number;
proportionLock?: boolean;
constraintsH?: 'left' | 'right' | 'leftright' | 'center' | 'scale';
constraintsV?: 'top' | 'bottom' | 'topbottom' | 'center' | 'scale';
constraintsH?: Constraint;
constraintsV?: Constraint;
fixedScroll?: boolean;
rx?: number;
ry?: number;
Expand All @@ -84,3 +84,5 @@ export type ShapeGeomAttributes = {
};

export type GrowType = 'auto-width' | 'auto-height' | 'fixed';

export type Constraint = 'left' | 'right' | 'leftright' | 'center' | 'scale';

0 comments on commit f38384b

Please sign in to comment.