Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for corner radius #57

Merged
merged 5 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
};
};