mirror of
https://github.com/penpot/penpot-exporter-figma-plugin.git
synced 2024-12-22 05:33:02 -05:00
Implement partial transformers
This commit is contained in:
parent
e6a86795e6
commit
590a3f7c62
7 changed files with 34 additions and 26 deletions
1
plugin-src/transformers/partials/index.ts
Normal file
1
plugin-src/transformers/partials/index.ts
Normal file
|
@ -0,0 +1 @@
|
|||
export * from './transformDimensionAndPosition';
|
|
@ -0,0 +1,14 @@
|
|||
import { ShapeGeomAttributes } from '@ui/lib/types/shape/shapeGeomAttributes';
|
||||
|
||||
export const transformDimensionAndPosition = (
|
||||
node: DimensionAndPositionMixin,
|
||||
baseX: number,
|
||||
baseY: number
|
||||
): ShapeGeomAttributes => {
|
||||
return {
|
||||
x: node.x + baseX,
|
||||
y: node.y + baseY,
|
||||
width: node.width,
|
||||
height: node.height
|
||||
};
|
||||
};
|
|
@ -1,3 +1,4 @@
|
|||
import { transformDimensionAndPosition } from '@plugin/transformers/partials';
|
||||
import { translateFills } from '@plugin/translators';
|
||||
|
||||
import { CircleShape } from '@ui/lib/types/circle/circleShape';
|
||||
|
@ -10,10 +11,7 @@ export const transformEllipseNode = (
|
|||
return {
|
||||
type: 'circle',
|
||||
name: node.name,
|
||||
x: node.x + baseX,
|
||||
y: node.y + baseY,
|
||||
width: node.width,
|
||||
height: node.height,
|
||||
fills: translateFills(node.fills, node.width, node.height)
|
||||
fills: translateFills(node.fills, node.width, node.height),
|
||||
...transformDimensionAndPosition(node, baseX, baseY)
|
||||
};
|
||||
};
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { transformDimensionAndPosition } from '@plugin/transformers/partials';
|
||||
import { translateFills } from '@plugin/translators';
|
||||
|
||||
import { FrameShape } from '@ui/lib/types/frame/frameShape';
|
||||
|
@ -12,13 +13,10 @@ export const transformFrameNode = async (
|
|||
return {
|
||||
type: 'frame',
|
||||
name: node.name,
|
||||
x: node.x + baseX,
|
||||
y: node.y + baseY,
|
||||
width: node.width,
|
||||
height: node.height,
|
||||
fills: translateFills(node.fills, node.width, node.height),
|
||||
children: await Promise.all(
|
||||
node.children.map(child => transformSceneNode(child, baseX + node.x, baseY + node.y))
|
||||
)
|
||||
),
|
||||
...transformDimensionAndPosition(node, baseX, baseY)
|
||||
};
|
||||
};
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
import { transformDimensionAndPosition } from '@plugin/transformers/partials';
|
||||
|
||||
import { GroupShape } from '@ui/lib/types/group/groupShape';
|
||||
|
||||
import { transformSceneNode } from './transformSceneNode';
|
||||
import { transformSceneNode } from '.';
|
||||
|
||||
export const transformGroupNode = async (
|
||||
node: GroupNode,
|
||||
|
@ -10,10 +12,9 @@ export const transformGroupNode = async (
|
|||
return {
|
||||
type: 'group',
|
||||
name: node.name,
|
||||
x: node.x + baseX,
|
||||
y: node.y + baseY,
|
||||
width: node.width,
|
||||
height: node.height,
|
||||
children: await Promise.all(node.children.map(child => transformSceneNode(child, baseX, baseY)))
|
||||
children: await Promise.all(
|
||||
node.children.map(child => transformSceneNode(child, baseX, baseY))
|
||||
),
|
||||
...transformDimensionAndPosition(node, baseX, baseY)
|
||||
};
|
||||
};
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { transformDimensionAndPosition } from '@plugin/transformers/partials';
|
||||
import { detectMimeType } from '@plugin/utils';
|
||||
|
||||
import { ImageShape } from '@ui/lib/types/image/imageShape';
|
||||
|
@ -17,14 +18,11 @@ export const transformImageNode = async (
|
|||
return {
|
||||
type: 'image',
|
||||
name: node.name,
|
||||
x: node.x + baseX,
|
||||
y: node.y + baseY,
|
||||
width: node.width,
|
||||
height: node.height,
|
||||
metadata: {
|
||||
width: node.width,
|
||||
height: node.height
|
||||
},
|
||||
dataUri: dataUri
|
||||
dataUri: dataUri,
|
||||
...transformDimensionAndPosition(node, baseX, baseY)
|
||||
};
|
||||
};
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { transformDimensionAndPosition } from '@plugin/transformers/partials';
|
||||
import { translateFills } from '@plugin/translators';
|
||||
|
||||
import { RectShape } from '@ui/lib/types/rect/rectShape';
|
||||
|
@ -10,10 +11,7 @@ export const transformRectangleNode = (
|
|||
return {
|
||||
type: 'rect',
|
||||
name: node.name,
|
||||
x: node.x + baseX,
|
||||
y: node.y + baseY,
|
||||
width: node.width,
|
||||
height: node.height,
|
||||
fills: translateFills(node.fills, node.width, node.height)
|
||||
fills: translateFills(node.fills, node.width, node.height),
|
||||
...transformDimensionAndPosition(node, baseX, baseY)
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue