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

Added support for corner radius (#57)

* added support for corner radius

* added support for corner radius

* minor fix

* added changelog to prettierignore
This commit is contained in:
Alex Sánchez 2024-04-22 12:50:38 +02:00 committed by GitHub
parent 47c3e52016
commit c464ff9bda
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 45 additions and 3 deletions

View file

@ -0,0 +1,5 @@
---
"penpot-exporter": minor
---
Added support for corner radius

View file

@ -3,3 +3,4 @@ node_modules
dist dist
ui-src/lib/penpot.js ui-src/lib/penpot.js
LICENSE LICENSE
CHANGELOG.md

View file

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

View file

@ -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
};
}
};

View file

@ -2,13 +2,17 @@ import { translateVectorPaths } from '@plugin/translators';
import { PathAttributes } from '@ui/lib/types/path/pathAttributes'; 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 => { const getVectorPaths = (node: VectorNode | StarNode | LineNode | PolygonNode): VectorPaths => {
switch (node.type) { switch (node.type) {
case 'STAR': case 'STAR':
case 'POLYGON': case 'POLYGON':
return node.fillGeometry; return node.fillGeometry;
case 'VECTOR': case 'VECTOR':
return node.vectorPaths; return hasFillGeometry(node) ? node.fillGeometry : node.vectorPaths;
case 'LINE': case 'LINE':
return node.strokeGeometry; return node.strokeGeometry;
} }

View file

@ -1,6 +1,7 @@
import { import {
transformBlend, transformBlend,
transformChildren, transformChildren,
transformCornerRadius,
transformDimensionAndPosition, transformDimensionAndPosition,
transformFills, transformFills,
transformProportion, transformProportion,
@ -36,6 +37,8 @@ export const transformFrameNode = async (
...(isSectionNode(node) ? [] : transformBlend(node)), ...(isSectionNode(node) ? [] : transformBlend(node)),
...transformSceneNode(node), ...transformSceneNode(node),
// Figma API does not expose constraints proportions for sections // 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))
}; };
}; };

View file

@ -1,5 +1,6 @@
import { import {
transformBlend, transformBlend,
transformCornerRadius,
transformDimensionAndPosition, transformDimensionAndPosition,
transformFills, transformFills,
transformProportion, transformProportion,
@ -22,6 +23,7 @@ export const transformRectangleNode = (
...transformDimensionAndPosition(node, baseX, baseY), ...transformDimensionAndPosition(node, baseX, baseY),
...transformSceneNode(node), ...transformSceneNode(node),
...transformBlend(node), ...transformBlend(node),
...transformProportion(node) ...transformProportion(node),
...transformCornerRadius(node)
}; };
}; };