Skip to content

Commit

Permalink
Added support for corner radius (#57)
Browse files Browse the repository at this point in the history
* added support for corner radius

* added support for corner radius

* minor fix

* added changelog to prettierignore
  • Loading branch information
Cenadros authored Apr 22, 2024
1 parent 47c3e52 commit c464ff9
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/perfect-masks-kneel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"penpot-exporter": minor
---

Added support for corner radius
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ node_modules
dist
ui-src/lib/penpot.js
LICENSE
CHANGELOG.md
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 './transformCornerRadius';
export * from './transformDimensionAndPosition';
export * from './transformFills';
export * from './transformProportion';
Expand Down
26 changes: 26 additions & 0 deletions plugin-src/transformers/partials/transformCornerRadius.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { ShapeAttributes } from '@ui/lib/types/shape/shapeAttributes';

const isRectangleCornerMixin = (
node: CornerMixin | (CornerMixin & RectangleCornerMixin)
): node is CornerMixin & RectangleCornerMixin => {
return 'topLeftRadius' in node && node.cornerRadius === figma.mixed;
};

export const transformCornerRadius = (
node: CornerMixin | (CornerMixin & RectangleCornerMixin)
): Partial<ShapeAttributes> | undefined => {
if (isRectangleCornerMixin(node)) {
return {
r1: node.topLeftRadius,
r2: node.topRightRadius,
r3: node.bottomRightRadius,
r4: node.bottomLeftRadius
};
}

if (node.cornerRadius !== figma.mixed) {
return {
rx: node.cornerRadius
};
}
};
6 changes: 5 additions & 1 deletion plugin-src/transformers/partials/transformVectorPaths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ import { translateVectorPaths } from '@plugin/translators';

import { PathAttributes } from '@ui/lib/types/path/pathAttributes';

const hasFillGeometry = (node: VectorNode | StarNode | LineNode | PolygonNode): boolean => {
return 'fillGeometry' in node && node.fillGeometry.length > 0;
};

const getVectorPaths = (node: VectorNode | StarNode | LineNode | PolygonNode): VectorPaths => {
switch (node.type) {
case 'STAR':
case 'POLYGON':
return node.fillGeometry;
case 'VECTOR':
return node.vectorPaths;
return hasFillGeometry(node) ? node.fillGeometry : node.vectorPaths;
case 'LINE':
return node.strokeGeometry;
}
Expand Down
5 changes: 4 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,
transformCornerRadius,
transformDimensionAndPosition,
transformFills,
transformProportion,
Expand Down Expand Up @@ -36,6 +37,8 @@ export const transformFrameNode = async (
...(isSectionNode(node) ? [] : transformBlend(node)),
...transformSceneNode(node),
// Figma API does not expose constraints proportions for sections
...(isSectionNode(node) ? [] : transformProportion(node))
...(isSectionNode(node) ? [] : transformProportion(node)),
// Figma API does not expose corner radius for sections
...(isSectionNode(node) ? [] : transformCornerRadius(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,
transformCornerRadius,
transformDimensionAndPosition,
transformFills,
transformProportion,
Expand All @@ -22,6 +23,7 @@ export const transformRectangleNode = (
...transformDimensionAndPosition(node, baseX, baseY),
...transformSceneNode(node),
...transformBlend(node),
...transformProportion(node)
...transformProportion(node),
...transformCornerRadius(node)
};
};

0 comments on commit c464ff9

Please sign in to comment.