mirror of
https://github.com/penpot/penpot-exporter-figma-plugin.git
synced 2024-12-21 21:23:06 -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:
parent
47c3e52016
commit
c464ff9bda
7 changed files with 45 additions and 3 deletions
5
.changeset/perfect-masks-kneel.md
Normal file
5
.changeset/perfect-masks-kneel.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
"penpot-exporter": minor
|
||||||
|
---
|
||||||
|
|
||||||
|
Added support for corner radius
|
|
@ -3,3 +3,4 @@ node_modules
|
||||||
dist
|
dist
|
||||||
ui-src/lib/penpot.js
|
ui-src/lib/penpot.js
|
||||||
LICENSE
|
LICENSE
|
||||||
|
CHANGELOG.md
|
||||||
|
|
|
@ -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';
|
||||||
|
|
26
plugin-src/transformers/partials/transformCornerRadius.ts
Normal file
26
plugin-src/transformers/partials/transformCornerRadius.ts
Normal 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
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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))
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -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)
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue